bnx2x_main.c 383 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138
  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: Ariel Elior <ariel.elior@qlogic.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/aer.h>
  29. #include <linux/init.h>
  30. #include <linux/netdevice.h>
  31. #include <linux/etherdevice.h>
  32. #include <linux/skbuff.h>
  33. #include <linux/dma-mapping.h>
  34. #include <linux/bitops.h>
  35. #include <linux/irq.h>
  36. #include <linux/delay.h>
  37. #include <asm/byteorder.h>
  38. #include <linux/time.h>
  39. #include <linux/ethtool.h>
  40. #include <linux/mii.h>
  41. #include <linux/if_vlan.h>
  42. #include <net/ip.h>
  43. #include <net/ipv6.h>
  44. #include <net/tcp.h>
  45. #include <net/checksum.h>
  46. #include <net/ip6_checksum.h>
  47. #include <linux/workqueue.h>
  48. #include <linux/crc32.h>
  49. #include <linux/crc32c.h>
  50. #include <linux/prefetch.h>
  51. #include <linux/zlib.h>
  52. #include <linux/io.h>
  53. #include <linux/semaphore.h>
  54. #include <linux/stringify.h>
  55. #include <linux/vmalloc.h>
  56. #include "bnx2x.h"
  57. #include "bnx2x_init.h"
  58. #include "bnx2x_init_ops.h"
  59. #include "bnx2x_cmn.h"
  60. #include "bnx2x_vfpf.h"
  61. #include "bnx2x_dcb.h"
  62. #include "bnx2x_sp.h"
  63. #include <linux/firmware.h>
  64. #include "bnx2x_fw_file_hdr.h"
  65. /* FW files */
  66. #define FW_FILE_VERSION \
  67. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  68. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  69. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  70. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  71. #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
  72. #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
  73. #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
  74. /* Time in jiffies before concluding the transmitter is hung */
  75. #define TX_TIMEOUT (5*HZ)
  76. static char version[] =
  77. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  78. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  79. MODULE_AUTHOR("Eliezer Tamir");
  80. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  81. "BCM57710/57711/57711E/"
  82. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  83. "57840/57840_MF Driver");
  84. MODULE_LICENSE("GPL");
  85. MODULE_VERSION(DRV_MODULE_VERSION);
  86. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  87. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  88. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  89. int bnx2x_num_queues;
  90. module_param_named(num_queues, bnx2x_num_queues, int, S_IRUGO);
  91. MODULE_PARM_DESC(num_queues,
  92. " Set number of queues (default is as a number of CPUs)");
  93. static int disable_tpa;
  94. module_param(disable_tpa, int, S_IRUGO);
  95. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  96. static int int_mode;
  97. module_param(int_mode, int, S_IRUGO);
  98. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  99. "(1 INT#x; 2 MSI)");
  100. static int dropless_fc;
  101. module_param(dropless_fc, int, S_IRUGO);
  102. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  103. static int mrrs = -1;
  104. module_param(mrrs, int, S_IRUGO);
  105. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  106. static int debug;
  107. module_param(debug, int, S_IRUGO);
  108. MODULE_PARM_DESC(debug, " Default debug msglevel");
  109. static struct workqueue_struct *bnx2x_wq;
  110. struct workqueue_struct *bnx2x_iov_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 const struct pci_device_id 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. /* Forward declaration */
  263. static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  264. static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp);
  265. static int bnx2x_set_storm_rx_mode(struct bnx2x *bp);
  266. /****************************************************************************
  267. * General service functions
  268. ****************************************************************************/
  269. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  270. u32 addr, dma_addr_t mapping)
  271. {
  272. REG_WR(bp, addr, U64_LO(mapping));
  273. REG_WR(bp, addr + 4, U64_HI(mapping));
  274. }
  275. static void storm_memset_spq_addr(struct bnx2x *bp,
  276. dma_addr_t mapping, u16 abs_fid)
  277. {
  278. u32 addr = XSEM_REG_FAST_MEMORY +
  279. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  280. __storm_memset_dma_mapping(bp, addr, mapping);
  281. }
  282. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  283. u16 pf_id)
  284. {
  285. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  286. pf_id);
  287. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  288. pf_id);
  289. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  290. pf_id);
  291. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  292. pf_id);
  293. }
  294. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  295. u8 enable)
  296. {
  297. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  298. enable);
  299. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  300. enable);
  301. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  302. enable);
  303. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  304. enable);
  305. }
  306. static void storm_memset_eq_data(struct bnx2x *bp,
  307. struct event_ring_data *eq_data,
  308. u16 pfid)
  309. {
  310. size_t size = sizeof(struct event_ring_data);
  311. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  312. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  313. }
  314. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  315. u16 pfid)
  316. {
  317. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  318. REG_WR16(bp, addr, eq_prod);
  319. }
  320. /* used only at init
  321. * locking is done by mcp
  322. */
  323. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  324. {
  325. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  326. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  327. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  328. PCICFG_VENDOR_ID_OFFSET);
  329. }
  330. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  331. {
  332. u32 val;
  333. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  334. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  335. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  336. PCICFG_VENDOR_ID_OFFSET);
  337. return val;
  338. }
  339. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  340. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  341. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  342. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  343. #define DMAE_DP_DST_NONE "dst_addr [none]"
  344. static void bnx2x_dp_dmae(struct bnx2x *bp,
  345. struct dmae_command *dmae, int msglvl)
  346. {
  347. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  348. int i;
  349. switch (dmae->opcode & DMAE_COMMAND_DST) {
  350. case DMAE_CMD_DST_PCI:
  351. if (src_type == DMAE_CMD_SRC_PCI)
  352. DP(msglvl, "DMAE: opcode 0x%08x\n"
  353. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  354. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  355. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  356. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  357. dmae->comp_addr_hi, dmae->comp_addr_lo,
  358. dmae->comp_val);
  359. else
  360. DP(msglvl, "DMAE: opcode 0x%08x\n"
  361. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  362. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  363. dmae->opcode, dmae->src_addr_lo >> 2,
  364. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  365. dmae->comp_addr_hi, dmae->comp_addr_lo,
  366. dmae->comp_val);
  367. break;
  368. case DMAE_CMD_DST_GRC:
  369. if (src_type == DMAE_CMD_SRC_PCI)
  370. DP(msglvl, "DMAE: opcode 0x%08x\n"
  371. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  372. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  373. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  374. dmae->len, dmae->dst_addr_lo >> 2,
  375. dmae->comp_addr_hi, dmae->comp_addr_lo,
  376. dmae->comp_val);
  377. else
  378. DP(msglvl, "DMAE: opcode 0x%08x\n"
  379. "src [%08x], len [%d*4], dst [%08x]\n"
  380. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  381. dmae->opcode, dmae->src_addr_lo >> 2,
  382. dmae->len, dmae->dst_addr_lo >> 2,
  383. dmae->comp_addr_hi, dmae->comp_addr_lo,
  384. dmae->comp_val);
  385. break;
  386. default:
  387. if (src_type == DMAE_CMD_SRC_PCI)
  388. DP(msglvl, "DMAE: opcode 0x%08x\n"
  389. "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
  390. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  391. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  392. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  393. dmae->comp_val);
  394. else
  395. DP(msglvl, "DMAE: opcode 0x%08x\n"
  396. "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
  397. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  398. dmae->opcode, dmae->src_addr_lo >> 2,
  399. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  400. dmae->comp_val);
  401. break;
  402. }
  403. for (i = 0; i < (sizeof(struct dmae_command)/4); i++)
  404. DP(msglvl, "DMAE RAW [%02d]: 0x%08x\n",
  405. i, *(((u32 *)dmae) + i));
  406. }
  407. /* copy command into DMAE command memory and set DMAE command go */
  408. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  409. {
  410. u32 cmd_offset;
  411. int i;
  412. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  413. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  414. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  415. }
  416. REG_WR(bp, dmae_reg_go_c[idx], 1);
  417. }
  418. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  419. {
  420. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  421. DMAE_CMD_C_ENABLE);
  422. }
  423. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  424. {
  425. return opcode & ~DMAE_CMD_SRC_RESET;
  426. }
  427. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  428. bool with_comp, u8 comp_type)
  429. {
  430. u32 opcode = 0;
  431. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  432. (dst_type << DMAE_COMMAND_DST_SHIFT));
  433. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  434. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  435. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  436. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  437. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  438. #ifdef __BIG_ENDIAN
  439. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  440. #else
  441. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  442. #endif
  443. if (with_comp)
  444. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  445. return opcode;
  446. }
  447. void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  448. struct dmae_command *dmae,
  449. u8 src_type, u8 dst_type)
  450. {
  451. memset(dmae, 0, sizeof(struct dmae_command));
  452. /* set the opcode */
  453. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  454. true, DMAE_COMP_PCI);
  455. /* fill in the completion parameters */
  456. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  457. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  458. dmae->comp_val = DMAE_COMP_VAL;
  459. }
  460. /* issue a dmae command over the init-channel and wait for completion */
  461. int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae,
  462. u32 *comp)
  463. {
  464. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  465. int rc = 0;
  466. bnx2x_dp_dmae(bp, dmae, BNX2X_MSG_DMAE);
  467. /* Lock the dmae channel. Disable BHs to prevent a dead-lock
  468. * as long as this code is called both from syscall context and
  469. * from ndo_set_rx_mode() flow that may be called from BH.
  470. */
  471. spin_lock_bh(&bp->dmae_lock);
  472. /* reset completion */
  473. *comp = 0;
  474. /* post the command on the channel used for initializations */
  475. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  476. /* wait for completion */
  477. udelay(5);
  478. while ((*comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  479. if (!cnt ||
  480. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  481. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  482. BNX2X_ERR("DMAE timeout!\n");
  483. rc = DMAE_TIMEOUT;
  484. goto unlock;
  485. }
  486. cnt--;
  487. udelay(50);
  488. }
  489. if (*comp & DMAE_PCI_ERR_FLAG) {
  490. BNX2X_ERR("DMAE PCI error!\n");
  491. rc = DMAE_PCI_ERROR;
  492. }
  493. unlock:
  494. spin_unlock_bh(&bp->dmae_lock);
  495. return rc;
  496. }
  497. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  498. u32 len32)
  499. {
  500. int rc;
  501. struct dmae_command dmae;
  502. if (!bp->dmae_ready) {
  503. u32 *data = bnx2x_sp(bp, wb_data[0]);
  504. if (CHIP_IS_E1(bp))
  505. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  506. else
  507. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  508. return;
  509. }
  510. /* set opcode and fixed command fields */
  511. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  512. /* fill in addresses and len */
  513. dmae.src_addr_lo = U64_LO(dma_addr);
  514. dmae.src_addr_hi = U64_HI(dma_addr);
  515. dmae.dst_addr_lo = dst_addr >> 2;
  516. dmae.dst_addr_hi = 0;
  517. dmae.len = len32;
  518. /* issue the command and wait for completion */
  519. rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  520. if (rc) {
  521. BNX2X_ERR("DMAE returned failure %d\n", rc);
  522. #ifdef BNX2X_STOP_ON_ERROR
  523. bnx2x_panic();
  524. #endif
  525. }
  526. }
  527. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  528. {
  529. int rc;
  530. struct dmae_command dmae;
  531. if (!bp->dmae_ready) {
  532. u32 *data = bnx2x_sp(bp, wb_data[0]);
  533. int i;
  534. if (CHIP_IS_E1(bp))
  535. for (i = 0; i < len32; i++)
  536. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  537. else
  538. for (i = 0; i < len32; i++)
  539. data[i] = REG_RD(bp, src_addr + i*4);
  540. return;
  541. }
  542. /* set opcode and fixed command fields */
  543. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  544. /* fill in addresses and len */
  545. dmae.src_addr_lo = src_addr >> 2;
  546. dmae.src_addr_hi = 0;
  547. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  548. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  549. dmae.len = len32;
  550. /* issue the command and wait for completion */
  551. rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  552. if (rc) {
  553. BNX2X_ERR("DMAE returned failure %d\n", rc);
  554. #ifdef BNX2X_STOP_ON_ERROR
  555. bnx2x_panic();
  556. #endif
  557. }
  558. }
  559. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  560. u32 addr, u32 len)
  561. {
  562. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  563. int offset = 0;
  564. while (len > dmae_wr_max) {
  565. bnx2x_write_dmae(bp, phys_addr + offset,
  566. addr + offset, dmae_wr_max);
  567. offset += dmae_wr_max * 4;
  568. len -= dmae_wr_max;
  569. }
  570. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  571. }
  572. static int bnx2x_mc_assert(struct bnx2x *bp)
  573. {
  574. char last_idx;
  575. int i, rc = 0;
  576. u32 row0, row1, row2, row3;
  577. /* XSTORM */
  578. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  579. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  580. if (last_idx)
  581. BNX2X_ERR("XSTORM_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_XSTRORM_INTMEM +
  585. XSTORM_ASSERT_LIST_OFFSET(i));
  586. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  587. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  588. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  589. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  590. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  591. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  592. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  593. BNX2X_ERR("XSTORM_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. /* TSTORM */
  601. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  602. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  603. if (last_idx)
  604. BNX2X_ERR("TSTORM_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_TSTRORM_INTMEM +
  608. TSTORM_ASSERT_LIST_OFFSET(i));
  609. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  610. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  611. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  612. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  613. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  614. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  615. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  616. BNX2X_ERR("TSTORM_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. /* CSTORM */
  624. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  625. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  626. if (last_idx)
  627. BNX2X_ERR("CSTORM_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_CSTRORM_INTMEM +
  631. CSTORM_ASSERT_LIST_OFFSET(i));
  632. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  633. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  634. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  635. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  636. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  637. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  638. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  639. BNX2X_ERR("CSTORM_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. /* USTORM */
  647. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  648. USTORM_ASSERT_LIST_INDEX_OFFSET);
  649. if (last_idx)
  650. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  651. /* print the asserts */
  652. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  653. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  654. USTORM_ASSERT_LIST_OFFSET(i));
  655. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  656. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  657. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  658. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  659. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  660. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  661. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  662. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  663. i, row3, row2, row1, row0);
  664. rc++;
  665. } else {
  666. break;
  667. }
  668. }
  669. return rc;
  670. }
  671. #define MCPR_TRACE_BUFFER_SIZE (0x800)
  672. #define SCRATCH_BUFFER_SIZE(bp) \
  673. (CHIP_IS_E1(bp) ? 0x10000 : (CHIP_IS_E1H(bp) ? 0x20000 : 0x28000))
  674. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  675. {
  676. u32 addr, val;
  677. u32 mark, offset;
  678. __be32 data[9];
  679. int word;
  680. u32 trace_shmem_base;
  681. if (BP_NOMCP(bp)) {
  682. BNX2X_ERR("NO MCP - can not dump\n");
  683. return;
  684. }
  685. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  686. (bp->common.bc_ver & 0xff0000) >> 16,
  687. (bp->common.bc_ver & 0xff00) >> 8,
  688. (bp->common.bc_ver & 0xff));
  689. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  690. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  691. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  692. if (BP_PATH(bp) == 0)
  693. trace_shmem_base = bp->common.shmem_base;
  694. else
  695. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  696. /* sanity */
  697. if (trace_shmem_base < MCPR_SCRATCH_BASE(bp) + MCPR_TRACE_BUFFER_SIZE ||
  698. trace_shmem_base >= MCPR_SCRATCH_BASE(bp) +
  699. SCRATCH_BUFFER_SIZE(bp)) {
  700. BNX2X_ERR("Unable to dump trace buffer (mark %x)\n",
  701. trace_shmem_base);
  702. return;
  703. }
  704. addr = trace_shmem_base - MCPR_TRACE_BUFFER_SIZE;
  705. /* validate TRCB signature */
  706. mark = REG_RD(bp, addr);
  707. if (mark != MFW_TRACE_SIGNATURE) {
  708. BNX2X_ERR("Trace buffer signature is missing.");
  709. return ;
  710. }
  711. /* read cyclic buffer pointer */
  712. addr += 4;
  713. mark = REG_RD(bp, addr);
  714. mark = MCPR_SCRATCH_BASE(bp) + ((mark + 0x3) & ~0x3) - 0x08000000;
  715. if (mark >= trace_shmem_base || mark < addr + 4) {
  716. BNX2X_ERR("Mark doesn't fall inside Trace Buffer\n");
  717. return;
  718. }
  719. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  720. printk("%s", lvl);
  721. /* dump buffer after the mark */
  722. for (offset = mark; offset < trace_shmem_base; offset += 0x8*4) {
  723. for (word = 0; word < 8; word++)
  724. data[word] = htonl(REG_RD(bp, offset + 4*word));
  725. data[8] = 0x0;
  726. pr_cont("%s", (char *)data);
  727. }
  728. /* dump buffer before the mark */
  729. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  730. for (word = 0; word < 8; word++)
  731. data[word] = htonl(REG_RD(bp, offset + 4*word));
  732. data[8] = 0x0;
  733. pr_cont("%s", (char *)data);
  734. }
  735. printk("%s" "end of fw dump\n", lvl);
  736. }
  737. static void bnx2x_fw_dump(struct bnx2x *bp)
  738. {
  739. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  740. }
  741. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  742. {
  743. int port = BP_PORT(bp);
  744. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  745. u32 val = REG_RD(bp, addr);
  746. /* in E1 we must use only PCI configuration space to disable
  747. * MSI/MSIX capability
  748. * It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  749. */
  750. if (CHIP_IS_E1(bp)) {
  751. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  752. * Use mask register to prevent from HC sending interrupts
  753. * after we exit the function
  754. */
  755. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  756. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  757. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  758. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  759. } else
  760. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  761. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  762. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  763. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  764. DP(NETIF_MSG_IFDOWN,
  765. "write %x to HC %d (addr 0x%x)\n",
  766. val, port, addr);
  767. /* flush all outstanding writes */
  768. mmiowb();
  769. REG_WR(bp, addr, val);
  770. if (REG_RD(bp, addr) != val)
  771. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  772. }
  773. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  774. {
  775. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  776. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  777. IGU_PF_CONF_INT_LINE_EN |
  778. IGU_PF_CONF_ATTN_BIT_EN);
  779. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  780. /* flush all outstanding writes */
  781. mmiowb();
  782. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  783. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  784. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  785. }
  786. static void bnx2x_int_disable(struct bnx2x *bp)
  787. {
  788. if (bp->common.int_block == INT_BLOCK_HC)
  789. bnx2x_hc_int_disable(bp);
  790. else
  791. bnx2x_igu_int_disable(bp);
  792. }
  793. void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
  794. {
  795. int i;
  796. u16 j;
  797. struct hc_sp_status_block_data sp_sb_data;
  798. int func = BP_FUNC(bp);
  799. #ifdef BNX2X_STOP_ON_ERROR
  800. u16 start = 0, end = 0;
  801. u8 cos;
  802. #endif
  803. if (IS_PF(bp) && disable_int)
  804. bnx2x_int_disable(bp);
  805. bp->stats_state = STATS_STATE_DISABLED;
  806. bp->eth_stats.unrecoverable_error++;
  807. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  808. BNX2X_ERR("begin crash dump -----------------\n");
  809. /* Indices */
  810. /* Common */
  811. if (IS_PF(bp)) {
  812. struct host_sp_status_block *def_sb = bp->def_status_blk;
  813. int data_size, cstorm_offset;
  814. 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",
  815. bp->def_idx, bp->def_att_idx, bp->attn_state,
  816. bp->spq_prod_idx, bp->stats_counter);
  817. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  818. def_sb->atten_status_block.attn_bits,
  819. def_sb->atten_status_block.attn_bits_ack,
  820. def_sb->atten_status_block.status_block_id,
  821. def_sb->atten_status_block.attn_bits_index);
  822. BNX2X_ERR(" def (");
  823. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  824. pr_cont("0x%x%s",
  825. def_sb->sp_sb.index_values[i],
  826. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  827. data_size = sizeof(struct hc_sp_status_block_data) /
  828. sizeof(u32);
  829. cstorm_offset = CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func);
  830. for (i = 0; i < data_size; i++)
  831. *((u32 *)&sp_sb_data + i) =
  832. REG_RD(bp, BAR_CSTRORM_INTMEM + cstorm_offset +
  833. i * sizeof(u32));
  834. 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",
  835. sp_sb_data.igu_sb_id,
  836. sp_sb_data.igu_seg_id,
  837. sp_sb_data.p_func.pf_id,
  838. sp_sb_data.p_func.vnic_id,
  839. sp_sb_data.p_func.vf_id,
  840. sp_sb_data.p_func.vf_valid,
  841. sp_sb_data.state);
  842. }
  843. for_each_eth_queue(bp, i) {
  844. struct bnx2x_fastpath *fp = &bp->fp[i];
  845. int loop;
  846. struct hc_status_block_data_e2 sb_data_e2;
  847. struct hc_status_block_data_e1x sb_data_e1x;
  848. struct hc_status_block_sm *hc_sm_p =
  849. CHIP_IS_E1x(bp) ?
  850. sb_data_e1x.common.state_machine :
  851. sb_data_e2.common.state_machine;
  852. struct hc_index_data *hc_index_p =
  853. CHIP_IS_E1x(bp) ?
  854. sb_data_e1x.index_data :
  855. sb_data_e2.index_data;
  856. u8 data_size, cos;
  857. u32 *sb_data_p;
  858. struct bnx2x_fp_txdata txdata;
  859. /* Rx */
  860. 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",
  861. i, fp->rx_bd_prod, fp->rx_bd_cons,
  862. fp->rx_comp_prod,
  863. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  864. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  865. fp->rx_sge_prod, fp->last_max_sge,
  866. le16_to_cpu(fp->fp_hc_idx));
  867. /* Tx */
  868. for_each_cos_in_tx_queue(fp, cos)
  869. {
  870. txdata = *fp->txdata_ptr[cos];
  871. 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",
  872. i, txdata.tx_pkt_prod,
  873. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  874. txdata.tx_bd_cons,
  875. le16_to_cpu(*txdata.tx_cons_sb));
  876. }
  877. loop = CHIP_IS_E1x(bp) ?
  878. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  879. /* host sb data */
  880. if (IS_FCOE_FP(fp))
  881. continue;
  882. BNX2X_ERR(" run indexes (");
  883. for (j = 0; j < HC_SB_MAX_SM; j++)
  884. pr_cont("0x%x%s",
  885. fp->sb_running_index[j],
  886. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  887. BNX2X_ERR(" indexes (");
  888. for (j = 0; j < loop; j++)
  889. pr_cont("0x%x%s",
  890. fp->sb_index_values[j],
  891. (j == loop - 1) ? ")" : " ");
  892. /* VF cannot access FW refelection for status block */
  893. if (IS_VF(bp))
  894. continue;
  895. /* fw sb data */
  896. data_size = CHIP_IS_E1x(bp) ?
  897. sizeof(struct hc_status_block_data_e1x) :
  898. sizeof(struct hc_status_block_data_e2);
  899. data_size /= sizeof(u32);
  900. sb_data_p = CHIP_IS_E1x(bp) ?
  901. (u32 *)&sb_data_e1x :
  902. (u32 *)&sb_data_e2;
  903. /* copy sb data in here */
  904. for (j = 0; j < data_size; j++)
  905. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  906. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  907. j * sizeof(u32));
  908. if (!CHIP_IS_E1x(bp)) {
  909. 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",
  910. sb_data_e2.common.p_func.pf_id,
  911. sb_data_e2.common.p_func.vf_id,
  912. sb_data_e2.common.p_func.vf_valid,
  913. sb_data_e2.common.p_func.vnic_id,
  914. sb_data_e2.common.same_igu_sb_1b,
  915. sb_data_e2.common.state);
  916. } else {
  917. 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",
  918. sb_data_e1x.common.p_func.pf_id,
  919. sb_data_e1x.common.p_func.vf_id,
  920. sb_data_e1x.common.p_func.vf_valid,
  921. sb_data_e1x.common.p_func.vnic_id,
  922. sb_data_e1x.common.same_igu_sb_1b,
  923. sb_data_e1x.common.state);
  924. }
  925. /* SB_SMs data */
  926. for (j = 0; j < HC_SB_MAX_SM; j++) {
  927. 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",
  928. j, hc_sm_p[j].__flags,
  929. hc_sm_p[j].igu_sb_id,
  930. hc_sm_p[j].igu_seg_id,
  931. hc_sm_p[j].time_to_expire,
  932. hc_sm_p[j].timer_value);
  933. }
  934. /* Indices data */
  935. for (j = 0; j < loop; j++) {
  936. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  937. hc_index_p[j].flags,
  938. hc_index_p[j].timeout);
  939. }
  940. }
  941. #ifdef BNX2X_STOP_ON_ERROR
  942. if (IS_PF(bp)) {
  943. /* event queue */
  944. BNX2X_ERR("eq cons %x prod %x\n", bp->eq_cons, bp->eq_prod);
  945. for (i = 0; i < NUM_EQ_DESC; i++) {
  946. u32 *data = (u32 *)&bp->eq_ring[i].message.data;
  947. BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
  948. i, bp->eq_ring[i].message.opcode,
  949. bp->eq_ring[i].message.error);
  950. BNX2X_ERR("data: %x %x %x\n",
  951. data[0], data[1], data[2]);
  952. }
  953. }
  954. /* Rings */
  955. /* Rx */
  956. for_each_valid_rx_queue(bp, i) {
  957. struct bnx2x_fastpath *fp = &bp->fp[i];
  958. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  959. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  960. for (j = start; j != end; j = RX_BD(j + 1)) {
  961. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  962. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  963. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  964. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  965. }
  966. start = RX_SGE(fp->rx_sge_prod);
  967. end = RX_SGE(fp->last_max_sge);
  968. for (j = start; j != end; j = RX_SGE(j + 1)) {
  969. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  970. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  971. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  972. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  973. }
  974. start = RCQ_BD(fp->rx_comp_cons - 10);
  975. end = RCQ_BD(fp->rx_comp_cons + 503);
  976. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  977. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  978. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  979. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  980. }
  981. }
  982. /* Tx */
  983. for_each_valid_tx_queue(bp, i) {
  984. struct bnx2x_fastpath *fp = &bp->fp[i];
  985. for_each_cos_in_tx_queue(fp, cos) {
  986. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  987. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  988. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  989. for (j = start; j != end; j = TX_BD(j + 1)) {
  990. struct sw_tx_bd *sw_bd =
  991. &txdata->tx_buf_ring[j];
  992. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  993. i, cos, j, sw_bd->skb,
  994. sw_bd->first_bd);
  995. }
  996. start = TX_BD(txdata->tx_bd_cons - 10);
  997. end = TX_BD(txdata->tx_bd_cons + 254);
  998. for (j = start; j != end; j = TX_BD(j + 1)) {
  999. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  1000. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  1001. i, cos, j, tx_bd[0], tx_bd[1],
  1002. tx_bd[2], tx_bd[3]);
  1003. }
  1004. }
  1005. }
  1006. #endif
  1007. if (IS_PF(bp)) {
  1008. bnx2x_fw_dump(bp);
  1009. bnx2x_mc_assert(bp);
  1010. }
  1011. BNX2X_ERR("end crash dump -----------------\n");
  1012. }
  1013. /*
  1014. * FLR Support for E2
  1015. *
  1016. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  1017. * initialization.
  1018. */
  1019. #define FLR_WAIT_USEC 10000 /* 10 milliseconds */
  1020. #define FLR_WAIT_INTERVAL 50 /* usec */
  1021. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  1022. struct pbf_pN_buf_regs {
  1023. int pN;
  1024. u32 init_crd;
  1025. u32 crd;
  1026. u32 crd_freed;
  1027. };
  1028. struct pbf_pN_cmd_regs {
  1029. int pN;
  1030. u32 lines_occup;
  1031. u32 lines_freed;
  1032. };
  1033. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  1034. struct pbf_pN_buf_regs *regs,
  1035. u32 poll_count)
  1036. {
  1037. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  1038. u32 cur_cnt = poll_count;
  1039. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  1040. crd = crd_start = REG_RD(bp, regs->crd);
  1041. init_crd = REG_RD(bp, regs->init_crd);
  1042. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  1043. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  1044. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  1045. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  1046. (init_crd - crd_start))) {
  1047. if (cur_cnt--) {
  1048. udelay(FLR_WAIT_INTERVAL);
  1049. crd = REG_RD(bp, regs->crd);
  1050. crd_freed = REG_RD(bp, regs->crd_freed);
  1051. } else {
  1052. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  1053. regs->pN);
  1054. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  1055. regs->pN, crd);
  1056. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  1057. regs->pN, crd_freed);
  1058. break;
  1059. }
  1060. }
  1061. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  1062. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1063. }
  1064. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  1065. struct pbf_pN_cmd_regs *regs,
  1066. u32 poll_count)
  1067. {
  1068. u32 occup, to_free, freed, freed_start;
  1069. u32 cur_cnt = poll_count;
  1070. occup = to_free = REG_RD(bp, regs->lines_occup);
  1071. freed = freed_start = REG_RD(bp, regs->lines_freed);
  1072. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  1073. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  1074. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  1075. if (cur_cnt--) {
  1076. udelay(FLR_WAIT_INTERVAL);
  1077. occup = REG_RD(bp, regs->lines_occup);
  1078. freed = REG_RD(bp, regs->lines_freed);
  1079. } else {
  1080. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  1081. regs->pN);
  1082. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  1083. regs->pN, occup);
  1084. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  1085. regs->pN, freed);
  1086. break;
  1087. }
  1088. }
  1089. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  1090. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1091. }
  1092. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  1093. u32 expected, u32 poll_count)
  1094. {
  1095. u32 cur_cnt = poll_count;
  1096. u32 val;
  1097. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  1098. udelay(FLR_WAIT_INTERVAL);
  1099. return val;
  1100. }
  1101. int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  1102. char *msg, u32 poll_cnt)
  1103. {
  1104. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  1105. if (val != 0) {
  1106. BNX2X_ERR("%s usage count=%d\n", msg, val);
  1107. return 1;
  1108. }
  1109. return 0;
  1110. }
  1111. /* Common routines with VF FLR cleanup */
  1112. u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  1113. {
  1114. /* adjust polling timeout */
  1115. if (CHIP_REV_IS_EMUL(bp))
  1116. return FLR_POLL_CNT * 2000;
  1117. if (CHIP_REV_IS_FPGA(bp))
  1118. return FLR_POLL_CNT * 120;
  1119. return FLR_POLL_CNT;
  1120. }
  1121. void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  1122. {
  1123. struct pbf_pN_cmd_regs cmd_regs[] = {
  1124. {0, (CHIP_IS_E3B0(bp)) ?
  1125. PBF_REG_TQ_OCCUPANCY_Q0 :
  1126. PBF_REG_P0_TQ_OCCUPANCY,
  1127. (CHIP_IS_E3B0(bp)) ?
  1128. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  1129. PBF_REG_P0_TQ_LINES_FREED_CNT},
  1130. {1, (CHIP_IS_E3B0(bp)) ?
  1131. PBF_REG_TQ_OCCUPANCY_Q1 :
  1132. PBF_REG_P1_TQ_OCCUPANCY,
  1133. (CHIP_IS_E3B0(bp)) ?
  1134. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  1135. PBF_REG_P1_TQ_LINES_FREED_CNT},
  1136. {4, (CHIP_IS_E3B0(bp)) ?
  1137. PBF_REG_TQ_OCCUPANCY_LB_Q :
  1138. PBF_REG_P4_TQ_OCCUPANCY,
  1139. (CHIP_IS_E3B0(bp)) ?
  1140. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  1141. PBF_REG_P4_TQ_LINES_FREED_CNT}
  1142. };
  1143. struct pbf_pN_buf_regs buf_regs[] = {
  1144. {0, (CHIP_IS_E3B0(bp)) ?
  1145. PBF_REG_INIT_CRD_Q0 :
  1146. PBF_REG_P0_INIT_CRD ,
  1147. (CHIP_IS_E3B0(bp)) ?
  1148. PBF_REG_CREDIT_Q0 :
  1149. PBF_REG_P0_CREDIT,
  1150. (CHIP_IS_E3B0(bp)) ?
  1151. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1152. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1153. {1, (CHIP_IS_E3B0(bp)) ?
  1154. PBF_REG_INIT_CRD_Q1 :
  1155. PBF_REG_P1_INIT_CRD,
  1156. (CHIP_IS_E3B0(bp)) ?
  1157. PBF_REG_CREDIT_Q1 :
  1158. PBF_REG_P1_CREDIT,
  1159. (CHIP_IS_E3B0(bp)) ?
  1160. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1161. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1162. {4, (CHIP_IS_E3B0(bp)) ?
  1163. PBF_REG_INIT_CRD_LB_Q :
  1164. PBF_REG_P4_INIT_CRD,
  1165. (CHIP_IS_E3B0(bp)) ?
  1166. PBF_REG_CREDIT_LB_Q :
  1167. PBF_REG_P4_CREDIT,
  1168. (CHIP_IS_E3B0(bp)) ?
  1169. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1170. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1171. };
  1172. int i;
  1173. /* Verify the command queues are flushed P0, P1, P4 */
  1174. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1175. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1176. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1177. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1178. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1179. }
  1180. #define OP_GEN_PARAM(param) \
  1181. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1182. #define OP_GEN_TYPE(type) \
  1183. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1184. #define OP_GEN_AGG_VECT(index) \
  1185. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1186. int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
  1187. {
  1188. u32 op_gen_command = 0;
  1189. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1190. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1191. int ret = 0;
  1192. if (REG_RD(bp, comp_addr)) {
  1193. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1194. return 1;
  1195. }
  1196. op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1197. op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1198. op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
  1199. op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1200. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1201. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
  1202. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1203. BNX2X_ERR("FW final cleanup did not succeed\n");
  1204. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1205. (REG_RD(bp, comp_addr)));
  1206. bnx2x_panic();
  1207. return 1;
  1208. }
  1209. /* Zero completion for next FLR */
  1210. REG_WR(bp, comp_addr, 0);
  1211. return ret;
  1212. }
  1213. u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1214. {
  1215. u16 status;
  1216. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1217. return status & PCI_EXP_DEVSTA_TRPND;
  1218. }
  1219. /* PF FLR specific routines
  1220. */
  1221. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1222. {
  1223. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1224. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1225. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1226. "CFC PF usage counter timed out",
  1227. poll_cnt))
  1228. return 1;
  1229. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1230. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1231. DORQ_REG_PF_USAGE_CNT,
  1232. "DQ PF usage counter timed out",
  1233. poll_cnt))
  1234. return 1;
  1235. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1236. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1237. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1238. "QM PF usage counter timed out",
  1239. poll_cnt))
  1240. return 1;
  1241. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1242. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1243. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1244. "Timers VNIC usage counter timed out",
  1245. poll_cnt))
  1246. return 1;
  1247. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1248. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1249. "Timers NUM_SCANS usage counter timed out",
  1250. poll_cnt))
  1251. return 1;
  1252. /* Wait DMAE PF usage counter to zero */
  1253. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1254. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1255. "DMAE command register timed out",
  1256. poll_cnt))
  1257. return 1;
  1258. return 0;
  1259. }
  1260. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1261. {
  1262. u32 val;
  1263. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1264. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1265. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1266. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1267. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1268. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1269. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1270. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1271. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1272. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1273. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1274. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1275. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1276. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1277. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1278. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1279. val);
  1280. }
  1281. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1282. {
  1283. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1284. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1285. /* Re-enable PF target read access */
  1286. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1287. /* Poll HW usage counters */
  1288. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1289. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1290. return -EBUSY;
  1291. /* Zero the igu 'trailing edge' and 'leading edge' */
  1292. /* Send the FW cleanup command */
  1293. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1294. return -EBUSY;
  1295. /* ATC cleanup */
  1296. /* Verify TX hw is flushed */
  1297. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1298. /* Wait 100ms (not adjusted according to platform) */
  1299. msleep(100);
  1300. /* Verify no pending pci transactions */
  1301. if (bnx2x_is_pcie_pending(bp->pdev))
  1302. BNX2X_ERR("PCIE Transactions still pending\n");
  1303. /* Debug */
  1304. bnx2x_hw_enable_status(bp);
  1305. /*
  1306. * Master enable - Due to WB DMAE writes performed before this
  1307. * register is re-initialized as part of the regular function init
  1308. */
  1309. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1310. return 0;
  1311. }
  1312. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1313. {
  1314. int port = BP_PORT(bp);
  1315. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1316. u32 val = REG_RD(bp, addr);
  1317. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1318. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1319. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1320. if (msix) {
  1321. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1322. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1323. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1324. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1325. if (single_msix)
  1326. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1327. } else if (msi) {
  1328. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1329. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1330. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1331. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1332. } else {
  1333. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1334. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1335. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1336. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1337. if (!CHIP_IS_E1(bp)) {
  1338. DP(NETIF_MSG_IFUP,
  1339. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1340. REG_WR(bp, addr, val);
  1341. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1342. }
  1343. }
  1344. if (CHIP_IS_E1(bp))
  1345. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1346. DP(NETIF_MSG_IFUP,
  1347. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1348. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1349. REG_WR(bp, addr, val);
  1350. /*
  1351. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1352. */
  1353. mmiowb();
  1354. barrier();
  1355. if (!CHIP_IS_E1(bp)) {
  1356. /* init leading/trailing edge */
  1357. if (IS_MF(bp)) {
  1358. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1359. if (bp->port.pmf)
  1360. /* enable nig and gpio3 attention */
  1361. val |= 0x1100;
  1362. } else
  1363. val = 0xffff;
  1364. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1365. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1366. }
  1367. /* Make sure that interrupts are indeed enabled from here on */
  1368. mmiowb();
  1369. }
  1370. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1371. {
  1372. u32 val;
  1373. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1374. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1375. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1376. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1377. if (msix) {
  1378. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1379. IGU_PF_CONF_SINGLE_ISR_EN);
  1380. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1381. IGU_PF_CONF_ATTN_BIT_EN);
  1382. if (single_msix)
  1383. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1384. } else if (msi) {
  1385. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1386. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1387. IGU_PF_CONF_ATTN_BIT_EN |
  1388. IGU_PF_CONF_SINGLE_ISR_EN);
  1389. } else {
  1390. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1391. val |= (IGU_PF_CONF_INT_LINE_EN |
  1392. IGU_PF_CONF_ATTN_BIT_EN |
  1393. IGU_PF_CONF_SINGLE_ISR_EN);
  1394. }
  1395. /* Clean previous status - need to configure igu prior to ack*/
  1396. if ((!msix) || single_msix) {
  1397. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1398. bnx2x_ack_int(bp);
  1399. }
  1400. val |= IGU_PF_CONF_FUNC_EN;
  1401. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1402. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1403. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1404. if (val & IGU_PF_CONF_INT_LINE_EN)
  1405. pci_intx(bp->pdev, true);
  1406. barrier();
  1407. /* init leading/trailing edge */
  1408. if (IS_MF(bp)) {
  1409. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1410. if (bp->port.pmf)
  1411. /* enable nig and gpio3 attention */
  1412. val |= 0x1100;
  1413. } else
  1414. val = 0xffff;
  1415. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1416. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1417. /* Make sure that interrupts are indeed enabled from here on */
  1418. mmiowb();
  1419. }
  1420. void bnx2x_int_enable(struct bnx2x *bp)
  1421. {
  1422. if (bp->common.int_block == INT_BLOCK_HC)
  1423. bnx2x_hc_int_enable(bp);
  1424. else
  1425. bnx2x_igu_int_enable(bp);
  1426. }
  1427. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1428. {
  1429. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1430. int i, offset;
  1431. if (disable_hw)
  1432. /* prevent the HW from sending interrupts */
  1433. bnx2x_int_disable(bp);
  1434. /* make sure all ISRs are done */
  1435. if (msix) {
  1436. synchronize_irq(bp->msix_table[0].vector);
  1437. offset = 1;
  1438. if (CNIC_SUPPORT(bp))
  1439. offset++;
  1440. for_each_eth_queue(bp, i)
  1441. synchronize_irq(bp->msix_table[offset++].vector);
  1442. } else
  1443. synchronize_irq(bp->pdev->irq);
  1444. /* make sure sp_task is not running */
  1445. cancel_delayed_work(&bp->sp_task);
  1446. cancel_delayed_work(&bp->period_task);
  1447. flush_workqueue(bnx2x_wq);
  1448. }
  1449. /* fast path */
  1450. /*
  1451. * General service functions
  1452. */
  1453. /* Return true if succeeded to acquire the lock */
  1454. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1455. {
  1456. u32 lock_status;
  1457. u32 resource_bit = (1 << resource);
  1458. int func = BP_FUNC(bp);
  1459. u32 hw_lock_control_reg;
  1460. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1461. "Trying to take a lock on resource %d\n", resource);
  1462. /* Validating that the resource is within range */
  1463. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1464. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1465. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1466. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1467. return false;
  1468. }
  1469. if (func <= 5)
  1470. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1471. else
  1472. hw_lock_control_reg =
  1473. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1474. /* Try to acquire the lock */
  1475. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1476. lock_status = REG_RD(bp, hw_lock_control_reg);
  1477. if (lock_status & resource_bit)
  1478. return true;
  1479. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1480. "Failed to get a lock on resource %d\n", resource);
  1481. return false;
  1482. }
  1483. /**
  1484. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1485. *
  1486. * @bp: driver handle
  1487. *
  1488. * Returns the recovery leader resource id according to the engine this function
  1489. * belongs to. Currently only only 2 engines is supported.
  1490. */
  1491. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1492. {
  1493. if (BP_PATH(bp))
  1494. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1495. else
  1496. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1497. }
  1498. /**
  1499. * bnx2x_trylock_leader_lock- try to acquire a leader lock.
  1500. *
  1501. * @bp: driver handle
  1502. *
  1503. * Tries to acquire a leader lock for current engine.
  1504. */
  1505. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1506. {
  1507. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1508. }
  1509. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1510. /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
  1511. static int bnx2x_schedule_sp_task(struct bnx2x *bp)
  1512. {
  1513. /* Set the interrupt occurred bit for the sp-task to recognize it
  1514. * must ack the interrupt and transition according to the IGU
  1515. * state machine.
  1516. */
  1517. atomic_set(&bp->interrupt_occurred, 1);
  1518. /* The sp_task must execute only after this bit
  1519. * is set, otherwise we will get out of sync and miss all
  1520. * further interrupts. Hence, the barrier.
  1521. */
  1522. smp_wmb();
  1523. /* schedule sp_task to workqueue */
  1524. return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1525. }
  1526. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1527. {
  1528. struct bnx2x *bp = fp->bp;
  1529. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1530. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1531. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1532. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1533. DP(BNX2X_MSG_SP,
  1534. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1535. fp->index, cid, command, bp->state,
  1536. rr_cqe->ramrod_cqe.ramrod_type);
  1537. /* If cid is within VF range, replace the slowpath object with the
  1538. * one corresponding to this VF
  1539. */
  1540. if (cid >= BNX2X_FIRST_VF_CID &&
  1541. cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
  1542. bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
  1543. switch (command) {
  1544. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1545. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1546. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1547. break;
  1548. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1549. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1550. drv_cmd = BNX2X_Q_CMD_SETUP;
  1551. break;
  1552. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1553. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1554. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1555. break;
  1556. case (RAMROD_CMD_ID_ETH_HALT):
  1557. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1558. drv_cmd = BNX2X_Q_CMD_HALT;
  1559. break;
  1560. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1561. DP(BNX2X_MSG_SP, "got MULTI[%d] terminate ramrod\n", cid);
  1562. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1563. break;
  1564. case (RAMROD_CMD_ID_ETH_EMPTY):
  1565. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1566. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1567. break;
  1568. case (RAMROD_CMD_ID_ETH_TPA_UPDATE):
  1569. DP(BNX2X_MSG_SP, "got tpa update ramrod CID=%d\n", cid);
  1570. drv_cmd = BNX2X_Q_CMD_UPDATE_TPA;
  1571. break;
  1572. default:
  1573. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1574. command, fp->index);
  1575. return;
  1576. }
  1577. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1578. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1579. /* q_obj->complete_cmd() failure means that this was
  1580. * an unexpected completion.
  1581. *
  1582. * In this case we don't want to increase the bp->spq_left
  1583. * because apparently we haven't sent this command the first
  1584. * place.
  1585. */
  1586. #ifdef BNX2X_STOP_ON_ERROR
  1587. bnx2x_panic();
  1588. #else
  1589. return;
  1590. #endif
  1591. smp_mb__before_atomic();
  1592. atomic_inc(&bp->cq_spq_left);
  1593. /* push the change in bp->spq_left and towards the memory */
  1594. smp_mb__after_atomic();
  1595. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1596. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1597. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1598. /* if Q update ramrod is completed for last Q in AFEX vif set
  1599. * flow, then ACK MCP at the end
  1600. *
  1601. * mark pending ACK to MCP bit.
  1602. * prevent case that both bits are cleared.
  1603. * At the end of load/unload driver checks that
  1604. * sp_state is cleared, and this order prevents
  1605. * races
  1606. */
  1607. smp_mb__before_atomic();
  1608. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1609. wmb();
  1610. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1611. smp_mb__after_atomic();
  1612. /* schedule the sp task as mcp ack is required */
  1613. bnx2x_schedule_sp_task(bp);
  1614. }
  1615. return;
  1616. }
  1617. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1618. {
  1619. struct bnx2x *bp = netdev_priv(dev_instance);
  1620. u16 status = bnx2x_ack_int(bp);
  1621. u16 mask;
  1622. int i;
  1623. u8 cos;
  1624. /* Return here if interrupt is shared and it's not for us */
  1625. if (unlikely(status == 0)) {
  1626. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1627. return IRQ_NONE;
  1628. }
  1629. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1630. #ifdef BNX2X_STOP_ON_ERROR
  1631. if (unlikely(bp->panic))
  1632. return IRQ_HANDLED;
  1633. #endif
  1634. for_each_eth_queue(bp, i) {
  1635. struct bnx2x_fastpath *fp = &bp->fp[i];
  1636. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1637. if (status & mask) {
  1638. /* Handle Rx or Tx according to SB id */
  1639. for_each_cos_in_tx_queue(fp, cos)
  1640. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1641. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1642. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1643. status &= ~mask;
  1644. }
  1645. }
  1646. if (CNIC_SUPPORT(bp)) {
  1647. mask = 0x2;
  1648. if (status & (mask | 0x1)) {
  1649. struct cnic_ops *c_ops = NULL;
  1650. rcu_read_lock();
  1651. c_ops = rcu_dereference(bp->cnic_ops);
  1652. if (c_ops && (bp->cnic_eth_dev.drv_state &
  1653. CNIC_DRV_STATE_HANDLES_IRQ))
  1654. c_ops->cnic_handler(bp->cnic_data, NULL);
  1655. rcu_read_unlock();
  1656. status &= ~mask;
  1657. }
  1658. }
  1659. if (unlikely(status & 0x1)) {
  1660. /* schedule sp task to perform default status block work, ack
  1661. * attentions and enable interrupts.
  1662. */
  1663. bnx2x_schedule_sp_task(bp);
  1664. status &= ~0x1;
  1665. if (!status)
  1666. return IRQ_HANDLED;
  1667. }
  1668. if (unlikely(status))
  1669. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1670. status);
  1671. return IRQ_HANDLED;
  1672. }
  1673. /* Link */
  1674. /*
  1675. * General service functions
  1676. */
  1677. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1678. {
  1679. u32 lock_status;
  1680. u32 resource_bit = (1 << resource);
  1681. int func = BP_FUNC(bp);
  1682. u32 hw_lock_control_reg;
  1683. int cnt;
  1684. /* Validating that the resource is within range */
  1685. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1686. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1687. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1688. return -EINVAL;
  1689. }
  1690. if (func <= 5) {
  1691. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1692. } else {
  1693. hw_lock_control_reg =
  1694. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1695. }
  1696. /* Validating that the resource is not already taken */
  1697. lock_status = REG_RD(bp, hw_lock_control_reg);
  1698. if (lock_status & resource_bit) {
  1699. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1700. lock_status, resource_bit);
  1701. return -EEXIST;
  1702. }
  1703. /* Try for 5 second every 5ms */
  1704. for (cnt = 0; cnt < 1000; cnt++) {
  1705. /* Try to acquire the lock */
  1706. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1707. lock_status = REG_RD(bp, hw_lock_control_reg);
  1708. if (lock_status & resource_bit)
  1709. return 0;
  1710. usleep_range(5000, 10000);
  1711. }
  1712. BNX2X_ERR("Timeout\n");
  1713. return -EAGAIN;
  1714. }
  1715. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1716. {
  1717. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1718. }
  1719. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1720. {
  1721. u32 lock_status;
  1722. u32 resource_bit = (1 << resource);
  1723. int func = BP_FUNC(bp);
  1724. u32 hw_lock_control_reg;
  1725. /* Validating that the resource is within range */
  1726. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1727. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1728. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1729. return -EINVAL;
  1730. }
  1731. if (func <= 5) {
  1732. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1733. } else {
  1734. hw_lock_control_reg =
  1735. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1736. }
  1737. /* Validating that the resource is currently taken */
  1738. lock_status = REG_RD(bp, hw_lock_control_reg);
  1739. if (!(lock_status & resource_bit)) {
  1740. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. Unlock was called but lock wasn't taken!\n",
  1741. lock_status, resource_bit);
  1742. return -EFAULT;
  1743. }
  1744. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1745. return 0;
  1746. }
  1747. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1748. {
  1749. /* The GPIO should be swapped if swap register is set and active */
  1750. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1751. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1752. int gpio_shift = gpio_num +
  1753. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1754. u32 gpio_mask = (1 << gpio_shift);
  1755. u32 gpio_reg;
  1756. int value;
  1757. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1758. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1759. return -EINVAL;
  1760. }
  1761. /* read GPIO value */
  1762. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1763. /* get the requested pin value */
  1764. if ((gpio_reg & gpio_mask) == gpio_mask)
  1765. value = 1;
  1766. else
  1767. value = 0;
  1768. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1769. return value;
  1770. }
  1771. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1772. {
  1773. /* The GPIO should be swapped if swap register is set and active */
  1774. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1775. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1776. int gpio_shift = gpio_num +
  1777. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1778. u32 gpio_mask = (1 << gpio_shift);
  1779. u32 gpio_reg;
  1780. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1781. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1782. return -EINVAL;
  1783. }
  1784. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1785. /* read GPIO and mask except the float bits */
  1786. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1787. switch (mode) {
  1788. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1789. DP(NETIF_MSG_LINK,
  1790. "Set GPIO %d (shift %d) -> output low\n",
  1791. gpio_num, gpio_shift);
  1792. /* clear FLOAT and set CLR */
  1793. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1794. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1795. break;
  1796. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1797. DP(NETIF_MSG_LINK,
  1798. "Set GPIO %d (shift %d) -> output high\n",
  1799. gpio_num, gpio_shift);
  1800. /* clear FLOAT and set SET */
  1801. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1802. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1803. break;
  1804. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1805. DP(NETIF_MSG_LINK,
  1806. "Set GPIO %d (shift %d) -> input\n",
  1807. gpio_num, gpio_shift);
  1808. /* set FLOAT */
  1809. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1810. break;
  1811. default:
  1812. break;
  1813. }
  1814. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1815. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1816. return 0;
  1817. }
  1818. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1819. {
  1820. u32 gpio_reg = 0;
  1821. int rc = 0;
  1822. /* Any port swapping should be handled by caller. */
  1823. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1824. /* read GPIO and mask except the float bits */
  1825. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1826. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1827. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1828. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1829. switch (mode) {
  1830. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1831. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1832. /* set CLR */
  1833. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1834. break;
  1835. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1836. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1837. /* set SET */
  1838. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1839. break;
  1840. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1841. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1842. /* set FLOAT */
  1843. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1844. break;
  1845. default:
  1846. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1847. rc = -EINVAL;
  1848. break;
  1849. }
  1850. if (rc == 0)
  1851. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1852. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1853. return rc;
  1854. }
  1855. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1856. {
  1857. /* The GPIO should be swapped if swap register is set and active */
  1858. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1859. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1860. int gpio_shift = gpio_num +
  1861. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1862. u32 gpio_mask = (1 << gpio_shift);
  1863. u32 gpio_reg;
  1864. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1865. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1866. return -EINVAL;
  1867. }
  1868. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1869. /* read GPIO int */
  1870. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1871. switch (mode) {
  1872. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1873. DP(NETIF_MSG_LINK,
  1874. "Clear GPIO INT %d (shift %d) -> output low\n",
  1875. gpio_num, gpio_shift);
  1876. /* clear SET and set CLR */
  1877. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1878. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1879. break;
  1880. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1881. DP(NETIF_MSG_LINK,
  1882. "Set GPIO INT %d (shift %d) -> output high\n",
  1883. gpio_num, gpio_shift);
  1884. /* clear CLR and set SET */
  1885. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1886. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1887. break;
  1888. default:
  1889. break;
  1890. }
  1891. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1892. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1893. return 0;
  1894. }
  1895. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1896. {
  1897. u32 spio_reg;
  1898. /* Only 2 SPIOs are configurable */
  1899. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1900. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1901. return -EINVAL;
  1902. }
  1903. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1904. /* read SPIO and mask except the float bits */
  1905. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1906. switch (mode) {
  1907. case MISC_SPIO_OUTPUT_LOW:
  1908. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1909. /* clear FLOAT and set CLR */
  1910. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1911. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1912. break;
  1913. case MISC_SPIO_OUTPUT_HIGH:
  1914. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1915. /* clear FLOAT and set SET */
  1916. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1917. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1918. break;
  1919. case MISC_SPIO_INPUT_HI_Z:
  1920. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1921. /* set FLOAT */
  1922. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1923. break;
  1924. default:
  1925. break;
  1926. }
  1927. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1928. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1929. return 0;
  1930. }
  1931. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1932. {
  1933. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1934. switch (bp->link_vars.ieee_fc &
  1935. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1936. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1937. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1938. ADVERTISED_Pause);
  1939. break;
  1940. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1941. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1942. ADVERTISED_Pause);
  1943. break;
  1944. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1945. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1946. break;
  1947. default:
  1948. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1949. ADVERTISED_Pause);
  1950. break;
  1951. }
  1952. }
  1953. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1954. {
  1955. /* Initialize link parameters structure variables
  1956. * It is recommended to turn off RX FC for jumbo frames
  1957. * for better performance
  1958. */
  1959. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1960. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1961. else
  1962. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1963. }
  1964. static void bnx2x_init_dropless_fc(struct bnx2x *bp)
  1965. {
  1966. u32 pause_enabled = 0;
  1967. if (!CHIP_IS_E1(bp) && bp->dropless_fc && bp->link_vars.link_up) {
  1968. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  1969. pause_enabled = 1;
  1970. REG_WR(bp, BAR_USTRORM_INTMEM +
  1971. USTORM_ETH_PAUSE_ENABLED_OFFSET(BP_PORT(bp)),
  1972. pause_enabled);
  1973. }
  1974. DP(NETIF_MSG_IFUP | NETIF_MSG_LINK, "dropless_fc is %s\n",
  1975. pause_enabled ? "enabled" : "disabled");
  1976. }
  1977. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1978. {
  1979. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1980. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1981. if (!BP_NOMCP(bp)) {
  1982. bnx2x_set_requested_fc(bp);
  1983. bnx2x_acquire_phy_lock(bp);
  1984. if (load_mode == LOAD_DIAG) {
  1985. struct link_params *lp = &bp->link_params;
  1986. lp->loopback_mode = LOOPBACK_XGXS;
  1987. /* do PHY loopback at 10G speed, if possible */
  1988. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1989. if (lp->speed_cap_mask[cfx_idx] &
  1990. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1991. lp->req_line_speed[cfx_idx] =
  1992. SPEED_10000;
  1993. else
  1994. lp->req_line_speed[cfx_idx] =
  1995. SPEED_1000;
  1996. }
  1997. }
  1998. if (load_mode == LOAD_LOOPBACK_EXT) {
  1999. struct link_params *lp = &bp->link_params;
  2000. lp->loopback_mode = LOOPBACK_EXT;
  2001. }
  2002. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  2003. bnx2x_release_phy_lock(bp);
  2004. bnx2x_init_dropless_fc(bp);
  2005. bnx2x_calc_fc_adv(bp);
  2006. if (bp->link_vars.link_up) {
  2007. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2008. bnx2x_link_report(bp);
  2009. }
  2010. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2011. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  2012. return rc;
  2013. }
  2014. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  2015. return -EINVAL;
  2016. }
  2017. void bnx2x_link_set(struct bnx2x *bp)
  2018. {
  2019. if (!BP_NOMCP(bp)) {
  2020. bnx2x_acquire_phy_lock(bp);
  2021. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  2022. bnx2x_release_phy_lock(bp);
  2023. bnx2x_init_dropless_fc(bp);
  2024. bnx2x_calc_fc_adv(bp);
  2025. } else
  2026. BNX2X_ERR("Bootcode is missing - can not set link\n");
  2027. }
  2028. static void bnx2x__link_reset(struct bnx2x *bp)
  2029. {
  2030. if (!BP_NOMCP(bp)) {
  2031. bnx2x_acquire_phy_lock(bp);
  2032. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  2033. bnx2x_release_phy_lock(bp);
  2034. } else
  2035. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  2036. }
  2037. void bnx2x_force_link_reset(struct bnx2x *bp)
  2038. {
  2039. bnx2x_acquire_phy_lock(bp);
  2040. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  2041. bnx2x_release_phy_lock(bp);
  2042. }
  2043. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  2044. {
  2045. u8 rc = 0;
  2046. if (!BP_NOMCP(bp)) {
  2047. bnx2x_acquire_phy_lock(bp);
  2048. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  2049. is_serdes);
  2050. bnx2x_release_phy_lock(bp);
  2051. } else
  2052. BNX2X_ERR("Bootcode is missing - can not test link\n");
  2053. return rc;
  2054. }
  2055. /* Calculates the sum of vn_min_rates.
  2056. It's needed for further normalizing of the min_rates.
  2057. Returns:
  2058. sum of vn_min_rates.
  2059. or
  2060. 0 - if all the min_rates are 0.
  2061. In the later case fairness algorithm should be deactivated.
  2062. If not all min_rates are zero then those that are zeroes will be set to 1.
  2063. */
  2064. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  2065. struct cmng_init_input *input)
  2066. {
  2067. int all_zero = 1;
  2068. int vn;
  2069. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2070. u32 vn_cfg = bp->mf_config[vn];
  2071. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  2072. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  2073. /* Skip hidden vns */
  2074. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2075. vn_min_rate = 0;
  2076. /* If min rate is zero - set it to 1 */
  2077. else if (!vn_min_rate)
  2078. vn_min_rate = DEF_MIN_RATE;
  2079. else
  2080. all_zero = 0;
  2081. input->vnic_min_rate[vn] = vn_min_rate;
  2082. }
  2083. /* if ETS or all min rates are zeros - disable fairness */
  2084. if (BNX2X_IS_ETS_ENABLED(bp)) {
  2085. input->flags.cmng_enables &=
  2086. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2087. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  2088. } else if (all_zero) {
  2089. input->flags.cmng_enables &=
  2090. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2091. DP(NETIF_MSG_IFUP,
  2092. "All MIN values are zeroes fairness will be disabled\n");
  2093. } else
  2094. input->flags.cmng_enables |=
  2095. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2096. }
  2097. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  2098. struct cmng_init_input *input)
  2099. {
  2100. u16 vn_max_rate;
  2101. u32 vn_cfg = bp->mf_config[vn];
  2102. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2103. vn_max_rate = 0;
  2104. else {
  2105. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  2106. if (IS_MF_SI(bp)) {
  2107. /* maxCfg in percents of linkspeed */
  2108. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  2109. } else /* SD modes */
  2110. /* maxCfg is absolute in 100Mb units */
  2111. vn_max_rate = maxCfg * 100;
  2112. }
  2113. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  2114. input->vnic_max_rate[vn] = vn_max_rate;
  2115. }
  2116. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2117. {
  2118. if (CHIP_REV_IS_SLOW(bp))
  2119. return CMNG_FNS_NONE;
  2120. if (IS_MF(bp))
  2121. return CMNG_FNS_MINMAX;
  2122. return CMNG_FNS_NONE;
  2123. }
  2124. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2125. {
  2126. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2127. if (BP_NOMCP(bp))
  2128. return; /* what should be the default value in this case */
  2129. /* For 2 port configuration the absolute function number formula
  2130. * is:
  2131. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2132. *
  2133. * and there are 4 functions per port
  2134. *
  2135. * For 4 port configuration it is
  2136. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2137. *
  2138. * and there are 2 functions per port
  2139. */
  2140. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2141. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2142. if (func >= E1H_FUNC_MAX)
  2143. break;
  2144. bp->mf_config[vn] =
  2145. MF_CFG_RD(bp, func_mf_config[func].config);
  2146. }
  2147. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2148. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  2149. bp->flags |= MF_FUNC_DIS;
  2150. } else {
  2151. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2152. bp->flags &= ~MF_FUNC_DIS;
  2153. }
  2154. }
  2155. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2156. {
  2157. struct cmng_init_input input;
  2158. memset(&input, 0, sizeof(struct cmng_init_input));
  2159. input.port_rate = bp->link_vars.line_speed;
  2160. if (cmng_type == CMNG_FNS_MINMAX && input.port_rate) {
  2161. int vn;
  2162. /* read mf conf from shmem */
  2163. if (read_cfg)
  2164. bnx2x_read_mf_cfg(bp);
  2165. /* vn_weight_sum and enable fairness if not 0 */
  2166. bnx2x_calc_vn_min(bp, &input);
  2167. /* calculate and set min-max rate for each vn */
  2168. if (bp->port.pmf)
  2169. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2170. bnx2x_calc_vn_max(bp, vn, &input);
  2171. /* always enable rate shaping and fairness */
  2172. input.flags.cmng_enables |=
  2173. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2174. bnx2x_init_cmng(&input, &bp->cmng);
  2175. return;
  2176. }
  2177. /* rate shaping and fairness are disabled */
  2178. DP(NETIF_MSG_IFUP,
  2179. "rate shaping and fairness are disabled\n");
  2180. }
  2181. static void storm_memset_cmng(struct bnx2x *bp,
  2182. struct cmng_init *cmng,
  2183. u8 port)
  2184. {
  2185. int vn;
  2186. size_t size = sizeof(struct cmng_struct_per_port);
  2187. u32 addr = BAR_XSTRORM_INTMEM +
  2188. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2189. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2190. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2191. int func = func_by_vn(bp, vn);
  2192. addr = BAR_XSTRORM_INTMEM +
  2193. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2194. size = sizeof(struct rate_shaping_vars_per_vn);
  2195. __storm_memset_struct(bp, addr, size,
  2196. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2197. addr = BAR_XSTRORM_INTMEM +
  2198. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2199. size = sizeof(struct fairness_vars_per_vn);
  2200. __storm_memset_struct(bp, addr, size,
  2201. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2202. }
  2203. }
  2204. /* init cmng mode in HW according to local configuration */
  2205. void bnx2x_set_local_cmng(struct bnx2x *bp)
  2206. {
  2207. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2208. if (cmng_fns != CMNG_FNS_NONE) {
  2209. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2210. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2211. } else {
  2212. /* rate shaping and fairness are disabled */
  2213. DP(NETIF_MSG_IFUP,
  2214. "single function mode without fairness\n");
  2215. }
  2216. }
  2217. /* This function is called upon link interrupt */
  2218. static void bnx2x_link_attn(struct bnx2x *bp)
  2219. {
  2220. /* Make sure that we are synced with the current statistics */
  2221. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2222. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2223. bnx2x_init_dropless_fc(bp);
  2224. if (bp->link_vars.link_up) {
  2225. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2226. struct host_port_stats *pstats;
  2227. pstats = bnx2x_sp(bp, port_stats);
  2228. /* reset old mac stats */
  2229. memset(&(pstats->mac_stx[0]), 0,
  2230. sizeof(struct mac_stx));
  2231. }
  2232. if (bp->state == BNX2X_STATE_OPEN)
  2233. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2234. }
  2235. if (bp->link_vars.link_up && bp->link_vars.line_speed)
  2236. bnx2x_set_local_cmng(bp);
  2237. __bnx2x_link_report(bp);
  2238. if (IS_MF(bp))
  2239. bnx2x_link_sync_notify(bp);
  2240. }
  2241. void bnx2x__link_status_update(struct bnx2x *bp)
  2242. {
  2243. if (bp->state != BNX2X_STATE_OPEN)
  2244. return;
  2245. /* read updated dcb configuration */
  2246. if (IS_PF(bp)) {
  2247. bnx2x_dcbx_pmf_update(bp);
  2248. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2249. if (bp->link_vars.link_up)
  2250. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2251. else
  2252. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2253. /* indicate link status */
  2254. bnx2x_link_report(bp);
  2255. } else { /* VF */
  2256. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2257. SUPPORTED_10baseT_Full |
  2258. SUPPORTED_100baseT_Half |
  2259. SUPPORTED_100baseT_Full |
  2260. SUPPORTED_1000baseT_Full |
  2261. SUPPORTED_2500baseX_Full |
  2262. SUPPORTED_10000baseT_Full |
  2263. SUPPORTED_TP |
  2264. SUPPORTED_FIBRE |
  2265. SUPPORTED_Autoneg |
  2266. SUPPORTED_Pause |
  2267. SUPPORTED_Asym_Pause);
  2268. bp->port.advertising[0] = bp->port.supported[0];
  2269. bp->link_params.bp = bp;
  2270. bp->link_params.port = BP_PORT(bp);
  2271. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2272. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2273. bp->link_params.req_line_speed[0] = SPEED_10000;
  2274. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2275. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2276. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2277. bp->link_vars.line_speed = SPEED_10000;
  2278. bp->link_vars.link_status =
  2279. (LINK_STATUS_LINK_UP |
  2280. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2281. bp->link_vars.link_up = 1;
  2282. bp->link_vars.duplex = DUPLEX_FULL;
  2283. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2284. __bnx2x_link_report(bp);
  2285. bnx2x_sample_bulletin(bp);
  2286. /* if bulletin board did not have an update for link status
  2287. * __bnx2x_link_report will report current status
  2288. * but it will NOT duplicate report in case of already reported
  2289. * during sampling bulletin board.
  2290. */
  2291. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2292. }
  2293. }
  2294. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2295. u16 vlan_val, u8 allowed_prio)
  2296. {
  2297. struct bnx2x_func_state_params func_params = {NULL};
  2298. struct bnx2x_func_afex_update_params *f_update_params =
  2299. &func_params.params.afex_update;
  2300. func_params.f_obj = &bp->func_obj;
  2301. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2302. /* no need to wait for RAMROD completion, so don't
  2303. * set RAMROD_COMP_WAIT flag
  2304. */
  2305. f_update_params->vif_id = vifid;
  2306. f_update_params->afex_default_vlan = vlan_val;
  2307. f_update_params->allowed_priorities = allowed_prio;
  2308. /* if ramrod can not be sent, response to MCP immediately */
  2309. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2310. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2311. return 0;
  2312. }
  2313. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2314. u16 vif_index, u8 func_bit_map)
  2315. {
  2316. struct bnx2x_func_state_params func_params = {NULL};
  2317. struct bnx2x_func_afex_viflists_params *update_params =
  2318. &func_params.params.afex_viflists;
  2319. int rc;
  2320. u32 drv_msg_code;
  2321. /* validate only LIST_SET and LIST_GET are received from switch */
  2322. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2323. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2324. cmd_type);
  2325. func_params.f_obj = &bp->func_obj;
  2326. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2327. /* set parameters according to cmd_type */
  2328. update_params->afex_vif_list_command = cmd_type;
  2329. update_params->vif_list_index = vif_index;
  2330. update_params->func_bit_map =
  2331. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2332. update_params->func_to_clear = 0;
  2333. drv_msg_code =
  2334. (cmd_type == VIF_LIST_RULE_GET) ?
  2335. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2336. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2337. /* if ramrod can not be sent, respond to MCP immediately for
  2338. * SET and GET requests (other are not triggered from MCP)
  2339. */
  2340. rc = bnx2x_func_state_change(bp, &func_params);
  2341. if (rc < 0)
  2342. bnx2x_fw_command(bp, drv_msg_code, 0);
  2343. return 0;
  2344. }
  2345. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2346. {
  2347. struct afex_stats afex_stats;
  2348. u32 func = BP_ABS_FUNC(bp);
  2349. u32 mf_config;
  2350. u16 vlan_val;
  2351. u32 vlan_prio;
  2352. u16 vif_id;
  2353. u8 allowed_prio;
  2354. u8 vlan_mode;
  2355. u32 addr_to_write, vifid, addrs, stats_type, i;
  2356. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2357. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2358. DP(BNX2X_MSG_MCP,
  2359. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2360. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2361. }
  2362. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2363. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2364. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2365. DP(BNX2X_MSG_MCP,
  2366. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2367. vifid, addrs);
  2368. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2369. addrs);
  2370. }
  2371. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2372. addr_to_write = SHMEM2_RD(bp,
  2373. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2374. stats_type = SHMEM2_RD(bp,
  2375. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2376. DP(BNX2X_MSG_MCP,
  2377. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2378. addr_to_write);
  2379. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2380. /* write response to scratchpad, for MCP */
  2381. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2382. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2383. *(((u32 *)(&afex_stats))+i));
  2384. /* send ack message to MCP */
  2385. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2386. }
  2387. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2388. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2389. bp->mf_config[BP_VN(bp)] = mf_config;
  2390. DP(BNX2X_MSG_MCP,
  2391. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2392. mf_config);
  2393. /* if VIF_SET is "enabled" */
  2394. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2395. /* set rate limit directly to internal RAM */
  2396. struct cmng_init_input cmng_input;
  2397. struct rate_shaping_vars_per_vn m_rs_vn;
  2398. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2399. u32 addr = BAR_XSTRORM_INTMEM +
  2400. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2401. bp->mf_config[BP_VN(bp)] = mf_config;
  2402. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2403. m_rs_vn.vn_counter.rate =
  2404. cmng_input.vnic_max_rate[BP_VN(bp)];
  2405. m_rs_vn.vn_counter.quota =
  2406. (m_rs_vn.vn_counter.rate *
  2407. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2408. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2409. /* read relevant values from mf_cfg struct in shmem */
  2410. vif_id =
  2411. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2412. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2413. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2414. vlan_val =
  2415. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2416. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2417. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2418. vlan_prio = (mf_config &
  2419. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2420. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2421. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2422. vlan_mode =
  2423. (MF_CFG_RD(bp,
  2424. func_mf_config[func].afex_config) &
  2425. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2426. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2427. allowed_prio =
  2428. (MF_CFG_RD(bp,
  2429. func_mf_config[func].afex_config) &
  2430. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2431. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2432. /* send ramrod to FW, return in case of failure */
  2433. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2434. allowed_prio))
  2435. return;
  2436. bp->afex_def_vlan_tag = vlan_val;
  2437. bp->afex_vlan_mode = vlan_mode;
  2438. } else {
  2439. /* notify link down because BP->flags is disabled */
  2440. bnx2x_link_report(bp);
  2441. /* send INVALID VIF ramrod to FW */
  2442. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2443. /* Reset the default afex VLAN */
  2444. bp->afex_def_vlan_tag = -1;
  2445. }
  2446. }
  2447. }
  2448. static void bnx2x_pmf_update(struct bnx2x *bp)
  2449. {
  2450. int port = BP_PORT(bp);
  2451. u32 val;
  2452. bp->port.pmf = 1;
  2453. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2454. /*
  2455. * We need the mb() to ensure the ordering between the writing to
  2456. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2457. */
  2458. smp_mb();
  2459. /* queue a periodic task */
  2460. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2461. bnx2x_dcbx_pmf_update(bp);
  2462. /* enable nig attention */
  2463. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2464. if (bp->common.int_block == INT_BLOCK_HC) {
  2465. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2466. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2467. } else if (!CHIP_IS_E1x(bp)) {
  2468. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2469. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2470. }
  2471. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2472. }
  2473. /* end of Link */
  2474. /* slow path */
  2475. /*
  2476. * General service functions
  2477. */
  2478. /* send the MCP a request, block until there is a reply */
  2479. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2480. {
  2481. int mb_idx = BP_FW_MB_IDX(bp);
  2482. u32 seq;
  2483. u32 rc = 0;
  2484. u32 cnt = 1;
  2485. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2486. mutex_lock(&bp->fw_mb_mutex);
  2487. seq = ++bp->fw_seq;
  2488. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2489. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2490. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2491. (command | seq), param);
  2492. do {
  2493. /* let the FW do it's magic ... */
  2494. msleep(delay);
  2495. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2496. /* Give the FW up to 5 second (500*10ms) */
  2497. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2498. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2499. cnt*delay, rc, seq);
  2500. /* is this a reply to our command? */
  2501. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2502. rc &= FW_MSG_CODE_MASK;
  2503. else {
  2504. /* FW BUG! */
  2505. BNX2X_ERR("FW failed to respond!\n");
  2506. bnx2x_fw_dump(bp);
  2507. rc = 0;
  2508. }
  2509. mutex_unlock(&bp->fw_mb_mutex);
  2510. return rc;
  2511. }
  2512. static void storm_memset_func_cfg(struct bnx2x *bp,
  2513. struct tstorm_eth_function_common_config *tcfg,
  2514. u16 abs_fid)
  2515. {
  2516. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2517. u32 addr = BAR_TSTRORM_INTMEM +
  2518. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2519. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2520. }
  2521. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2522. {
  2523. if (CHIP_IS_E1x(bp)) {
  2524. struct tstorm_eth_function_common_config tcfg = {0};
  2525. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2526. }
  2527. /* Enable the function in the FW */
  2528. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2529. storm_memset_func_en(bp, p->func_id, 1);
  2530. /* spq */
  2531. if (p->func_flgs & FUNC_FLG_SPQ) {
  2532. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2533. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2534. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2535. }
  2536. }
  2537. /**
  2538. * bnx2x_get_common_flags - Return common flags
  2539. *
  2540. * @bp device handle
  2541. * @fp queue handle
  2542. * @zero_stats TRUE if statistics zeroing is needed
  2543. *
  2544. * Return the flags that are common for the Tx-only and not normal connections.
  2545. */
  2546. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2547. struct bnx2x_fastpath *fp,
  2548. bool zero_stats)
  2549. {
  2550. unsigned long flags = 0;
  2551. /* PF driver will always initialize the Queue to an ACTIVE state */
  2552. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2553. /* tx only connections collect statistics (on the same index as the
  2554. * parent connection). The statistics are zeroed when the parent
  2555. * connection is initialized.
  2556. */
  2557. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2558. if (zero_stats)
  2559. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2560. if (bp->flags & TX_SWITCHING)
  2561. __set_bit(BNX2X_Q_FLG_TX_SWITCH, &flags);
  2562. __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags);
  2563. __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags);
  2564. #ifdef BNX2X_STOP_ON_ERROR
  2565. __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
  2566. #endif
  2567. return flags;
  2568. }
  2569. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2570. struct bnx2x_fastpath *fp,
  2571. bool leading)
  2572. {
  2573. unsigned long flags = 0;
  2574. /* calculate other queue flags */
  2575. if (IS_MF_SD(bp))
  2576. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2577. if (IS_FCOE_FP(fp)) {
  2578. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2579. /* For FCoE - force usage of default priority (for afex) */
  2580. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2581. }
  2582. if (!fp->disable_tpa) {
  2583. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2584. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2585. if (fp->mode == TPA_MODE_GRO)
  2586. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2587. }
  2588. if (leading) {
  2589. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2590. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2591. }
  2592. /* Always set HW VLAN stripping */
  2593. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2594. /* configure silent vlan removal */
  2595. if (IS_MF_AFEX(bp))
  2596. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2597. return flags | bnx2x_get_common_flags(bp, fp, true);
  2598. }
  2599. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2600. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2601. u8 cos)
  2602. {
  2603. gen_init->stat_id = bnx2x_stats_id(fp);
  2604. gen_init->spcl_id = fp->cl_id;
  2605. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2606. if (IS_FCOE_FP(fp))
  2607. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2608. else
  2609. gen_init->mtu = bp->dev->mtu;
  2610. gen_init->cos = cos;
  2611. }
  2612. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2613. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2614. struct bnx2x_rxq_setup_params *rxq_init)
  2615. {
  2616. u8 max_sge = 0;
  2617. u16 sge_sz = 0;
  2618. u16 tpa_agg_size = 0;
  2619. if (!fp->disable_tpa) {
  2620. pause->sge_th_lo = SGE_TH_LO(bp);
  2621. pause->sge_th_hi = SGE_TH_HI(bp);
  2622. /* validate SGE ring has enough to cross high threshold */
  2623. WARN_ON(bp->dropless_fc &&
  2624. pause->sge_th_hi + FW_PREFETCH_CNT >
  2625. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2626. tpa_agg_size = TPA_AGG_SIZE;
  2627. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2628. SGE_PAGE_SHIFT;
  2629. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2630. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2631. sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
  2632. }
  2633. /* pause - not for e1 */
  2634. if (!CHIP_IS_E1(bp)) {
  2635. pause->bd_th_lo = BD_TH_LO(bp);
  2636. pause->bd_th_hi = BD_TH_HI(bp);
  2637. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2638. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2639. /*
  2640. * validate that rings have enough entries to cross
  2641. * high thresholds
  2642. */
  2643. WARN_ON(bp->dropless_fc &&
  2644. pause->bd_th_hi + FW_PREFETCH_CNT >
  2645. bp->rx_ring_size);
  2646. WARN_ON(bp->dropless_fc &&
  2647. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2648. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2649. pause->pri_map = 1;
  2650. }
  2651. /* rxq setup */
  2652. rxq_init->dscr_map = fp->rx_desc_mapping;
  2653. rxq_init->sge_map = fp->rx_sge_mapping;
  2654. rxq_init->rcq_map = fp->rx_comp_mapping;
  2655. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2656. /* This should be a maximum number of data bytes that may be
  2657. * placed on the BD (not including paddings).
  2658. */
  2659. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2660. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2661. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2662. rxq_init->tpa_agg_sz = tpa_agg_size;
  2663. rxq_init->sge_buf_sz = sge_sz;
  2664. rxq_init->max_sges_pkt = max_sge;
  2665. rxq_init->rss_engine_id = BP_FUNC(bp);
  2666. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2667. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2668. *
  2669. * For PF Clients it should be the maximum available number.
  2670. * VF driver(s) may want to define it to a smaller value.
  2671. */
  2672. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2673. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2674. rxq_init->fw_sb_id = fp->fw_sb_id;
  2675. if (IS_FCOE_FP(fp))
  2676. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2677. else
  2678. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2679. /* configure silent vlan removal
  2680. * if multi function mode is afex, then mask default vlan
  2681. */
  2682. if (IS_MF_AFEX(bp)) {
  2683. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2684. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2685. }
  2686. }
  2687. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2688. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2689. u8 cos)
  2690. {
  2691. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2692. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2693. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2694. txq_init->fw_sb_id = fp->fw_sb_id;
  2695. /*
  2696. * set the tss leading client id for TX classification ==
  2697. * leading RSS client id
  2698. */
  2699. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2700. if (IS_FCOE_FP(fp)) {
  2701. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2702. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2703. }
  2704. }
  2705. static void bnx2x_pf_init(struct bnx2x *bp)
  2706. {
  2707. struct bnx2x_func_init_params func_init = {0};
  2708. struct event_ring_data eq_data = { {0} };
  2709. u16 flags;
  2710. if (!CHIP_IS_E1x(bp)) {
  2711. /* reset IGU PF statistics: MSIX + ATTN */
  2712. /* PF */
  2713. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2714. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2715. (CHIP_MODE_IS_4_PORT(bp) ?
  2716. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2717. /* ATTN */
  2718. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2719. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2720. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2721. (CHIP_MODE_IS_4_PORT(bp) ?
  2722. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2723. }
  2724. /* function setup flags */
  2725. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2726. /* This flag is relevant for E1x only.
  2727. * E2 doesn't have a TPA configuration in a function level.
  2728. */
  2729. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2730. func_init.func_flgs = flags;
  2731. func_init.pf_id = BP_FUNC(bp);
  2732. func_init.func_id = BP_FUNC(bp);
  2733. func_init.spq_map = bp->spq_mapping;
  2734. func_init.spq_prod = bp->spq_prod_idx;
  2735. bnx2x_func_init(bp, &func_init);
  2736. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2737. /*
  2738. * Congestion management values depend on the link rate
  2739. * There is no active link so initial link rate is set to 10 Gbps.
  2740. * When the link comes up The congestion management values are
  2741. * re-calculated according to the actual link rate.
  2742. */
  2743. bp->link_vars.line_speed = SPEED_10000;
  2744. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2745. /* Only the PMF sets the HW */
  2746. if (bp->port.pmf)
  2747. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2748. /* init Event Queue - PCI bus guarantees correct endianity*/
  2749. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2750. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2751. eq_data.producer = bp->eq_prod;
  2752. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2753. eq_data.sb_id = DEF_SB_ID;
  2754. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2755. }
  2756. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2757. {
  2758. int port = BP_PORT(bp);
  2759. bnx2x_tx_disable(bp);
  2760. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2761. }
  2762. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2763. {
  2764. int port = BP_PORT(bp);
  2765. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2766. /* Tx queue should be only re-enabled */
  2767. netif_tx_wake_all_queues(bp->dev);
  2768. /*
  2769. * Should not call netif_carrier_on since it will be called if the link
  2770. * is up when checking for link state
  2771. */
  2772. }
  2773. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2774. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2775. {
  2776. struct eth_stats_info *ether_stat =
  2777. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2778. struct bnx2x_vlan_mac_obj *mac_obj =
  2779. &bp->sp_objs->mac_obj;
  2780. int i;
  2781. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2782. ETH_STAT_INFO_VERSION_LEN);
  2783. /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
  2784. * mac_local field in ether_stat struct. The base address is offset by 2
  2785. * bytes to account for the field being 8 bytes but a mac address is
  2786. * only 6 bytes. Likewise, the stride for the get_n_elements function is
  2787. * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes
  2788. * allocated by the ether_stat struct, so the macs will land in their
  2789. * proper positions.
  2790. */
  2791. for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++)
  2792. memset(ether_stat->mac_local + i, 0,
  2793. sizeof(ether_stat->mac_local[0]));
  2794. mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2795. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2796. ether_stat->mac_local + MAC_PAD, MAC_PAD,
  2797. ETH_ALEN);
  2798. ether_stat->mtu_size = bp->dev->mtu;
  2799. if (bp->dev->features & NETIF_F_RXCSUM)
  2800. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2801. if (bp->dev->features & NETIF_F_TSO)
  2802. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2803. ether_stat->feature_flags |= bp->common.boot_mode;
  2804. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2805. ether_stat->txq_size = bp->tx_ring_size;
  2806. ether_stat->rxq_size = bp->rx_ring_size;
  2807. #ifdef CONFIG_BNX2X_SRIOV
  2808. ether_stat->vf_cnt = IS_SRIOV(bp) ? bp->vfdb->sriov.nr_virtfn : 0;
  2809. #endif
  2810. }
  2811. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2812. {
  2813. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2814. struct fcoe_stats_info *fcoe_stat =
  2815. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2816. if (!CNIC_LOADED(bp))
  2817. return;
  2818. memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN);
  2819. fcoe_stat->qos_priority =
  2820. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2821. /* insert FCoE stats from ramrod response */
  2822. if (!NO_FCOE(bp)) {
  2823. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2824. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2825. tstorm_queue_statistics;
  2826. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2827. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2828. xstorm_queue_statistics;
  2829. struct fcoe_statistics_params *fw_fcoe_stat =
  2830. &bp->fw_stats_data->fcoe;
  2831. ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
  2832. fcoe_stat->rx_bytes_lo,
  2833. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2834. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2835. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2836. fcoe_stat->rx_bytes_lo,
  2837. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2838. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2839. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2840. fcoe_stat->rx_bytes_lo,
  2841. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2842. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2843. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2844. fcoe_stat->rx_bytes_lo,
  2845. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2846. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2847. fcoe_stat->rx_frames_lo,
  2848. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2849. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2850. fcoe_stat->rx_frames_lo,
  2851. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2852. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2853. fcoe_stat->rx_frames_lo,
  2854. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2855. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2856. fcoe_stat->rx_frames_lo,
  2857. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2858. ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
  2859. fcoe_stat->tx_bytes_lo,
  2860. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2861. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2862. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2863. fcoe_stat->tx_bytes_lo,
  2864. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2865. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2866. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2867. fcoe_stat->tx_bytes_lo,
  2868. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2869. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2870. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2871. fcoe_stat->tx_bytes_lo,
  2872. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2873. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2874. fcoe_stat->tx_frames_lo,
  2875. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2876. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2877. fcoe_stat->tx_frames_lo,
  2878. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2879. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2880. fcoe_stat->tx_frames_lo,
  2881. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2882. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2883. fcoe_stat->tx_frames_lo,
  2884. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2885. }
  2886. /* ask L5 driver to add data to the struct */
  2887. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2888. }
  2889. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2890. {
  2891. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2892. struct iscsi_stats_info *iscsi_stat =
  2893. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2894. if (!CNIC_LOADED(bp))
  2895. return;
  2896. memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac,
  2897. ETH_ALEN);
  2898. iscsi_stat->qos_priority =
  2899. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2900. /* ask L5 driver to add data to the struct */
  2901. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2902. }
  2903. /* called due to MCP event (on pmf):
  2904. * reread new bandwidth configuration
  2905. * configure FW
  2906. * notify others function about the change
  2907. */
  2908. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2909. {
  2910. if (bp->link_vars.link_up) {
  2911. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2912. bnx2x_link_sync_notify(bp);
  2913. }
  2914. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2915. }
  2916. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2917. {
  2918. bnx2x_config_mf_bw(bp);
  2919. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2920. }
  2921. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2922. {
  2923. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2924. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2925. }
  2926. #define BNX2X_UPDATE_DRV_INFO_IND_LENGTH (20)
  2927. #define BNX2X_UPDATE_DRV_INFO_IND_COUNT (25)
  2928. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2929. {
  2930. enum drv_info_opcode op_code;
  2931. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2932. bool release = false;
  2933. int wait;
  2934. /* if drv_info version supported by MFW doesn't match - send NACK */
  2935. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2936. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2937. return;
  2938. }
  2939. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2940. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2941. /* Must prevent other flows from accessing drv_info_to_mcp */
  2942. mutex_lock(&bp->drv_info_mutex);
  2943. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2944. sizeof(union drv_info_to_mcp));
  2945. switch (op_code) {
  2946. case ETH_STATS_OPCODE:
  2947. bnx2x_drv_info_ether_stat(bp);
  2948. break;
  2949. case FCOE_STATS_OPCODE:
  2950. bnx2x_drv_info_fcoe_stat(bp);
  2951. break;
  2952. case ISCSI_STATS_OPCODE:
  2953. bnx2x_drv_info_iscsi_stat(bp);
  2954. break;
  2955. default:
  2956. /* if op code isn't supported - send NACK */
  2957. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2958. goto out;
  2959. }
  2960. /* if we got drv_info attn from MFW then these fields are defined in
  2961. * shmem2 for sure
  2962. */
  2963. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2964. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2965. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2966. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2967. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2968. /* Since possible management wants both this and get_driver_version
  2969. * need to wait until management notifies us it finished utilizing
  2970. * the buffer.
  2971. */
  2972. if (!SHMEM2_HAS(bp, mfw_drv_indication)) {
  2973. DP(BNX2X_MSG_MCP, "Management does not support indication\n");
  2974. } else if (!bp->drv_info_mng_owner) {
  2975. u32 bit = MFW_DRV_IND_READ_DONE_OFFSET((BP_ABS_FUNC(bp) >> 1));
  2976. for (wait = 0; wait < BNX2X_UPDATE_DRV_INFO_IND_COUNT; wait++) {
  2977. u32 indication = SHMEM2_RD(bp, mfw_drv_indication);
  2978. /* Management is done; need to clear indication */
  2979. if (indication & bit) {
  2980. SHMEM2_WR(bp, mfw_drv_indication,
  2981. indication & ~bit);
  2982. release = true;
  2983. break;
  2984. }
  2985. msleep(BNX2X_UPDATE_DRV_INFO_IND_LENGTH);
  2986. }
  2987. }
  2988. if (!release) {
  2989. DP(BNX2X_MSG_MCP, "Management did not release indication\n");
  2990. bp->drv_info_mng_owner = true;
  2991. }
  2992. out:
  2993. mutex_unlock(&bp->drv_info_mutex);
  2994. }
  2995. static u32 bnx2x_update_mng_version_utility(u8 *version, bool bnx2x_format)
  2996. {
  2997. u8 vals[4];
  2998. int i = 0;
  2999. if (bnx2x_format) {
  3000. i = sscanf(version, "1.%c%hhd.%hhd.%hhd",
  3001. &vals[0], &vals[1], &vals[2], &vals[3]);
  3002. if (i > 0)
  3003. vals[0] -= '0';
  3004. } else {
  3005. i = sscanf(version, "%hhd.%hhd.%hhd.%hhd",
  3006. &vals[0], &vals[1], &vals[2], &vals[3]);
  3007. }
  3008. while (i < 4)
  3009. vals[i++] = 0;
  3010. return (vals[0] << 24) | (vals[1] << 16) | (vals[2] << 8) | vals[3];
  3011. }
  3012. void bnx2x_update_mng_version(struct bnx2x *bp)
  3013. {
  3014. u32 iscsiver = DRV_VER_NOT_LOADED;
  3015. u32 fcoever = DRV_VER_NOT_LOADED;
  3016. u32 ethver = DRV_VER_NOT_LOADED;
  3017. int idx = BP_FW_MB_IDX(bp);
  3018. u8 *version;
  3019. if (!SHMEM2_HAS(bp, func_os_drv_ver))
  3020. return;
  3021. mutex_lock(&bp->drv_info_mutex);
  3022. /* Must not proceed when `bnx2x_handle_drv_info_req' is feasible */
  3023. if (bp->drv_info_mng_owner)
  3024. goto out;
  3025. if (bp->state != BNX2X_STATE_OPEN)
  3026. goto out;
  3027. /* Parse ethernet driver version */
  3028. ethver = bnx2x_update_mng_version_utility(DRV_MODULE_VERSION, true);
  3029. if (!CNIC_LOADED(bp))
  3030. goto out;
  3031. /* Try getting storage driver version via cnic */
  3032. memset(&bp->slowpath->drv_info_to_mcp, 0,
  3033. sizeof(union drv_info_to_mcp));
  3034. bnx2x_drv_info_iscsi_stat(bp);
  3035. version = bp->slowpath->drv_info_to_mcp.iscsi_stat.version;
  3036. iscsiver = bnx2x_update_mng_version_utility(version, false);
  3037. memset(&bp->slowpath->drv_info_to_mcp, 0,
  3038. sizeof(union drv_info_to_mcp));
  3039. bnx2x_drv_info_fcoe_stat(bp);
  3040. version = bp->slowpath->drv_info_to_mcp.fcoe_stat.version;
  3041. fcoever = bnx2x_update_mng_version_utility(version, false);
  3042. out:
  3043. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_ETHERNET], ethver);
  3044. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_ISCSI], iscsiver);
  3045. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_FCOE], fcoever);
  3046. mutex_unlock(&bp->drv_info_mutex);
  3047. DP(BNX2X_MSG_MCP, "Setting driver version: ETH [%08x] iSCSI [%08x] FCoE [%08x]\n",
  3048. ethver, iscsiver, fcoever);
  3049. }
  3050. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  3051. {
  3052. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  3053. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  3054. /*
  3055. * This is the only place besides the function initialization
  3056. * where the bp->flags can change so it is done without any
  3057. * locks
  3058. */
  3059. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  3060. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  3061. bp->flags |= MF_FUNC_DIS;
  3062. bnx2x_e1h_disable(bp);
  3063. } else {
  3064. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  3065. bp->flags &= ~MF_FUNC_DIS;
  3066. bnx2x_e1h_enable(bp);
  3067. }
  3068. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  3069. }
  3070. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  3071. bnx2x_config_mf_bw(bp);
  3072. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  3073. }
  3074. /* Report results to MCP */
  3075. if (dcc_event)
  3076. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  3077. else
  3078. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  3079. }
  3080. /* must be called under the spq lock */
  3081. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  3082. {
  3083. struct eth_spe *next_spe = bp->spq_prod_bd;
  3084. if (bp->spq_prod_bd == bp->spq_last_bd) {
  3085. bp->spq_prod_bd = bp->spq;
  3086. bp->spq_prod_idx = 0;
  3087. DP(BNX2X_MSG_SP, "end of spq\n");
  3088. } else {
  3089. bp->spq_prod_bd++;
  3090. bp->spq_prod_idx++;
  3091. }
  3092. return next_spe;
  3093. }
  3094. /* must be called under the spq lock */
  3095. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  3096. {
  3097. int func = BP_FUNC(bp);
  3098. /*
  3099. * Make sure that BD data is updated before writing the producer:
  3100. * BD data is written to the memory, the producer is read from the
  3101. * memory, thus we need a full memory barrier to ensure the ordering.
  3102. */
  3103. mb();
  3104. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  3105. bp->spq_prod_idx);
  3106. mmiowb();
  3107. }
  3108. /**
  3109. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  3110. *
  3111. * @cmd: command to check
  3112. * @cmd_type: command type
  3113. */
  3114. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  3115. {
  3116. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  3117. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  3118. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  3119. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  3120. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  3121. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  3122. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  3123. return true;
  3124. else
  3125. return false;
  3126. }
  3127. /**
  3128. * bnx2x_sp_post - place a single command on an SP ring
  3129. *
  3130. * @bp: driver handle
  3131. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  3132. * @cid: SW CID the command is related to
  3133. * @data_hi: command private data address (high 32 bits)
  3134. * @data_lo: command private data address (low 32 bits)
  3135. * @cmd_type: command type (e.g. NONE, ETH)
  3136. *
  3137. * SP data is handled as if it's always an address pair, thus data fields are
  3138. * not swapped to little endian in upper functions. Instead this function swaps
  3139. * data as if it's two u32 fields.
  3140. */
  3141. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  3142. u32 data_hi, u32 data_lo, int cmd_type)
  3143. {
  3144. struct eth_spe *spe;
  3145. u16 type;
  3146. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  3147. #ifdef BNX2X_STOP_ON_ERROR
  3148. if (unlikely(bp->panic)) {
  3149. BNX2X_ERR("Can't post SP when there is panic\n");
  3150. return -EIO;
  3151. }
  3152. #endif
  3153. spin_lock_bh(&bp->spq_lock);
  3154. if (common) {
  3155. if (!atomic_read(&bp->eq_spq_left)) {
  3156. BNX2X_ERR("BUG! EQ ring full!\n");
  3157. spin_unlock_bh(&bp->spq_lock);
  3158. bnx2x_panic();
  3159. return -EBUSY;
  3160. }
  3161. } else if (!atomic_read(&bp->cq_spq_left)) {
  3162. BNX2X_ERR("BUG! SPQ ring full!\n");
  3163. spin_unlock_bh(&bp->spq_lock);
  3164. bnx2x_panic();
  3165. return -EBUSY;
  3166. }
  3167. spe = bnx2x_sp_get_next(bp);
  3168. /* CID needs port number to be encoded int it */
  3169. spe->hdr.conn_and_cmd_data =
  3170. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  3171. HW_CID(bp, cid));
  3172. /* In some cases, type may already contain the func-id
  3173. * mainly in SRIOV related use cases, so we add it here only
  3174. * if it's not already set.
  3175. */
  3176. if (!(cmd_type & SPE_HDR_FUNCTION_ID)) {
  3177. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) &
  3178. SPE_HDR_CONN_TYPE;
  3179. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  3180. SPE_HDR_FUNCTION_ID);
  3181. } else {
  3182. type = cmd_type;
  3183. }
  3184. spe->hdr.type = cpu_to_le16(type);
  3185. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  3186. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  3187. /*
  3188. * It's ok if the actual decrement is issued towards the memory
  3189. * somewhere between the spin_lock and spin_unlock. Thus no
  3190. * more explicit memory barrier is needed.
  3191. */
  3192. if (common)
  3193. atomic_dec(&bp->eq_spq_left);
  3194. else
  3195. atomic_dec(&bp->cq_spq_left);
  3196. DP(BNX2X_MSG_SP,
  3197. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  3198. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  3199. (u32)(U64_LO(bp->spq_mapping) +
  3200. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  3201. HW_CID(bp, cid), data_hi, data_lo, type,
  3202. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  3203. bnx2x_sp_prod_update(bp);
  3204. spin_unlock_bh(&bp->spq_lock);
  3205. return 0;
  3206. }
  3207. /* acquire split MCP access lock register */
  3208. static int bnx2x_acquire_alr(struct bnx2x *bp)
  3209. {
  3210. u32 j, val;
  3211. int rc = 0;
  3212. might_sleep();
  3213. for (j = 0; j < 1000; j++) {
  3214. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, MCPR_ACCESS_LOCK_LOCK);
  3215. val = REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK);
  3216. if (val & MCPR_ACCESS_LOCK_LOCK)
  3217. break;
  3218. usleep_range(5000, 10000);
  3219. }
  3220. if (!(val & MCPR_ACCESS_LOCK_LOCK)) {
  3221. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  3222. rc = -EBUSY;
  3223. }
  3224. return rc;
  3225. }
  3226. /* release split MCP access lock register */
  3227. static void bnx2x_release_alr(struct bnx2x *bp)
  3228. {
  3229. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  3230. }
  3231. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  3232. #define BNX2X_DEF_SB_IDX 0x0002
  3233. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  3234. {
  3235. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3236. u16 rc = 0;
  3237. barrier(); /* status block is written to by the chip */
  3238. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3239. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3240. rc |= BNX2X_DEF_SB_ATT_IDX;
  3241. }
  3242. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3243. bp->def_idx = def_sb->sp_sb.running_index;
  3244. rc |= BNX2X_DEF_SB_IDX;
  3245. }
  3246. /* Do not reorder: indices reading should complete before handling */
  3247. barrier();
  3248. return rc;
  3249. }
  3250. /*
  3251. * slow path service functions
  3252. */
  3253. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3254. {
  3255. int port = BP_PORT(bp);
  3256. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3257. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3258. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3259. NIG_REG_MASK_INTERRUPT_PORT0;
  3260. u32 aeu_mask;
  3261. u32 nig_mask = 0;
  3262. u32 reg_addr;
  3263. if (bp->attn_state & asserted)
  3264. BNX2X_ERR("IGU ERROR\n");
  3265. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3266. aeu_mask = REG_RD(bp, aeu_addr);
  3267. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3268. aeu_mask, asserted);
  3269. aeu_mask &= ~(asserted & 0x3ff);
  3270. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3271. REG_WR(bp, aeu_addr, aeu_mask);
  3272. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3273. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3274. bp->attn_state |= asserted;
  3275. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3276. if (asserted & ATTN_HARD_WIRED_MASK) {
  3277. if (asserted & ATTN_NIG_FOR_FUNC) {
  3278. bnx2x_acquire_phy_lock(bp);
  3279. /* save nig interrupt mask */
  3280. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3281. /* If nig_mask is not set, no need to call the update
  3282. * function.
  3283. */
  3284. if (nig_mask) {
  3285. REG_WR(bp, nig_int_mask_addr, 0);
  3286. bnx2x_link_attn(bp);
  3287. }
  3288. /* handle unicore attn? */
  3289. }
  3290. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3291. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3292. if (asserted & GPIO_2_FUNC)
  3293. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3294. if (asserted & GPIO_3_FUNC)
  3295. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3296. if (asserted & GPIO_4_FUNC)
  3297. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3298. if (port == 0) {
  3299. if (asserted & ATTN_GENERAL_ATTN_1) {
  3300. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3301. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3302. }
  3303. if (asserted & ATTN_GENERAL_ATTN_2) {
  3304. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3305. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3306. }
  3307. if (asserted & ATTN_GENERAL_ATTN_3) {
  3308. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3309. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3310. }
  3311. } else {
  3312. if (asserted & ATTN_GENERAL_ATTN_4) {
  3313. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3314. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3315. }
  3316. if (asserted & ATTN_GENERAL_ATTN_5) {
  3317. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3318. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3319. }
  3320. if (asserted & ATTN_GENERAL_ATTN_6) {
  3321. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3322. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3323. }
  3324. }
  3325. } /* if hardwired */
  3326. if (bp->common.int_block == INT_BLOCK_HC)
  3327. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3328. COMMAND_REG_ATTN_BITS_SET);
  3329. else
  3330. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3331. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3332. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3333. REG_WR(bp, reg_addr, asserted);
  3334. /* now set back the mask */
  3335. if (asserted & ATTN_NIG_FOR_FUNC) {
  3336. /* Verify that IGU ack through BAR was written before restoring
  3337. * NIG mask. This loop should exit after 2-3 iterations max.
  3338. */
  3339. if (bp->common.int_block != INT_BLOCK_HC) {
  3340. u32 cnt = 0, igu_acked;
  3341. do {
  3342. igu_acked = REG_RD(bp,
  3343. IGU_REG_ATTENTION_ACK_BITS);
  3344. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3345. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3346. if (!igu_acked)
  3347. DP(NETIF_MSG_HW,
  3348. "Failed to verify IGU ack on time\n");
  3349. barrier();
  3350. }
  3351. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3352. bnx2x_release_phy_lock(bp);
  3353. }
  3354. }
  3355. static void bnx2x_fan_failure(struct bnx2x *bp)
  3356. {
  3357. int port = BP_PORT(bp);
  3358. u32 ext_phy_config;
  3359. /* mark the failure */
  3360. ext_phy_config =
  3361. SHMEM_RD(bp,
  3362. dev_info.port_hw_config[port].external_phy_config);
  3363. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3364. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3365. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3366. ext_phy_config);
  3367. /* log the failure */
  3368. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3369. "Please contact OEM Support for assistance\n");
  3370. /* Schedule device reset (unload)
  3371. * This is due to some boards consuming sufficient power when driver is
  3372. * up to overheat if fan fails.
  3373. */
  3374. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_FAN_FAILURE, 0);
  3375. }
  3376. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3377. {
  3378. int port = BP_PORT(bp);
  3379. int reg_offset;
  3380. u32 val;
  3381. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3382. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3383. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3384. val = REG_RD(bp, reg_offset);
  3385. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3386. REG_WR(bp, reg_offset, val);
  3387. BNX2X_ERR("SPIO5 hw attention\n");
  3388. /* Fan failure attention */
  3389. bnx2x_hw_reset_phy(&bp->link_params);
  3390. bnx2x_fan_failure(bp);
  3391. }
  3392. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3393. bnx2x_acquire_phy_lock(bp);
  3394. bnx2x_handle_module_detect_int(&bp->link_params);
  3395. bnx2x_release_phy_lock(bp);
  3396. }
  3397. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3398. val = REG_RD(bp, reg_offset);
  3399. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3400. REG_WR(bp, reg_offset, val);
  3401. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3402. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3403. bnx2x_panic();
  3404. }
  3405. }
  3406. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3407. {
  3408. u32 val;
  3409. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3410. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3411. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3412. /* DORQ discard attention */
  3413. if (val & 0x2)
  3414. BNX2X_ERR("FATAL error from DORQ\n");
  3415. }
  3416. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3417. int port = BP_PORT(bp);
  3418. int reg_offset;
  3419. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3420. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3421. val = REG_RD(bp, reg_offset);
  3422. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3423. REG_WR(bp, reg_offset, val);
  3424. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3425. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3426. bnx2x_panic();
  3427. }
  3428. }
  3429. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3430. {
  3431. u32 val;
  3432. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3433. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3434. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3435. /* CFC error attention */
  3436. if (val & 0x2)
  3437. BNX2X_ERR("FATAL error from CFC\n");
  3438. }
  3439. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3440. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3441. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3442. /* RQ_USDMDP_FIFO_OVERFLOW */
  3443. if (val & 0x18000)
  3444. BNX2X_ERR("FATAL error from PXP\n");
  3445. if (!CHIP_IS_E1x(bp)) {
  3446. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3447. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3448. }
  3449. }
  3450. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3451. int port = BP_PORT(bp);
  3452. int reg_offset;
  3453. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3454. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3455. val = REG_RD(bp, reg_offset);
  3456. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3457. REG_WR(bp, reg_offset, val);
  3458. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3459. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3460. bnx2x_panic();
  3461. }
  3462. }
  3463. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3464. {
  3465. u32 val;
  3466. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3467. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3468. int func = BP_FUNC(bp);
  3469. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3470. bnx2x_read_mf_cfg(bp);
  3471. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3472. func_mf_config[BP_ABS_FUNC(bp)].config);
  3473. val = SHMEM_RD(bp,
  3474. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3475. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3476. bnx2x_dcc_event(bp,
  3477. (val & DRV_STATUS_DCC_EVENT_MASK));
  3478. if (val & DRV_STATUS_SET_MF_BW)
  3479. bnx2x_set_mf_bw(bp);
  3480. if (val & DRV_STATUS_DRV_INFO_REQ)
  3481. bnx2x_handle_drv_info_req(bp);
  3482. if (val & DRV_STATUS_VF_DISABLED)
  3483. bnx2x_schedule_iov_task(bp,
  3484. BNX2X_IOV_HANDLE_FLR);
  3485. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3486. bnx2x_pmf_update(bp);
  3487. if (bp->port.pmf &&
  3488. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3489. bp->dcbx_enabled > 0)
  3490. /* start dcbx state machine */
  3491. bnx2x_dcbx_set_params(bp,
  3492. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3493. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3494. bnx2x_handle_afex_cmd(bp,
  3495. val & DRV_STATUS_AFEX_EVENT_MASK);
  3496. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3497. bnx2x_handle_eee_event(bp);
  3498. if (bp->link_vars.periodic_flags &
  3499. PERIODIC_FLAGS_LINK_EVENT) {
  3500. /* sync with link */
  3501. bnx2x_acquire_phy_lock(bp);
  3502. bp->link_vars.periodic_flags &=
  3503. ~PERIODIC_FLAGS_LINK_EVENT;
  3504. bnx2x_release_phy_lock(bp);
  3505. if (IS_MF(bp))
  3506. bnx2x_link_sync_notify(bp);
  3507. bnx2x_link_report(bp);
  3508. }
  3509. /* Always call it here: bnx2x_link_report() will
  3510. * prevent the link indication duplication.
  3511. */
  3512. bnx2x__link_status_update(bp);
  3513. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3514. BNX2X_ERR("MC assert!\n");
  3515. bnx2x_mc_assert(bp);
  3516. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3517. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3518. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3519. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3520. bnx2x_panic();
  3521. } else if (attn & BNX2X_MCP_ASSERT) {
  3522. BNX2X_ERR("MCP assert!\n");
  3523. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3524. bnx2x_fw_dump(bp);
  3525. } else
  3526. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3527. }
  3528. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3529. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3530. if (attn & BNX2X_GRC_TIMEOUT) {
  3531. val = CHIP_IS_E1(bp) ? 0 :
  3532. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3533. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3534. }
  3535. if (attn & BNX2X_GRC_RSV) {
  3536. val = CHIP_IS_E1(bp) ? 0 :
  3537. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3538. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3539. }
  3540. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3541. }
  3542. }
  3543. /*
  3544. * Bits map:
  3545. * 0-7 - Engine0 load counter.
  3546. * 8-15 - Engine1 load counter.
  3547. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3548. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3549. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3550. * on the engine
  3551. * 19 - Engine1 ONE_IS_LOADED.
  3552. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3553. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3554. * just the one belonging to its engine).
  3555. *
  3556. */
  3557. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3558. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3559. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3560. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3561. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3562. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3563. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3564. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3565. /*
  3566. * Set the GLOBAL_RESET bit.
  3567. *
  3568. * Should be run under rtnl lock
  3569. */
  3570. void bnx2x_set_reset_global(struct bnx2x *bp)
  3571. {
  3572. u32 val;
  3573. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3574. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3575. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3576. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3577. }
  3578. /*
  3579. * Clear the GLOBAL_RESET bit.
  3580. *
  3581. * Should be run under rtnl lock
  3582. */
  3583. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3584. {
  3585. u32 val;
  3586. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3587. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3588. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3589. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3590. }
  3591. /*
  3592. * Checks the GLOBAL_RESET bit.
  3593. *
  3594. * should be run under rtnl lock
  3595. */
  3596. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3597. {
  3598. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3599. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3600. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3601. }
  3602. /*
  3603. * Clear RESET_IN_PROGRESS bit for the current engine.
  3604. *
  3605. * Should be run under rtnl lock
  3606. */
  3607. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3608. {
  3609. u32 val;
  3610. u32 bit = BP_PATH(bp) ?
  3611. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3612. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3613. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3614. /* Clear the bit */
  3615. val &= ~bit;
  3616. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3617. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3618. }
  3619. /*
  3620. * Set RESET_IN_PROGRESS for the current engine.
  3621. *
  3622. * should be run under rtnl lock
  3623. */
  3624. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3625. {
  3626. u32 val;
  3627. u32 bit = BP_PATH(bp) ?
  3628. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3629. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3630. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3631. /* Set the bit */
  3632. val |= bit;
  3633. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3634. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3635. }
  3636. /*
  3637. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3638. * should be run under rtnl lock
  3639. */
  3640. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3641. {
  3642. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3643. u32 bit = engine ?
  3644. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3645. /* return false if bit is set */
  3646. return (val & bit) ? false : true;
  3647. }
  3648. /*
  3649. * set pf load for the current pf.
  3650. *
  3651. * should be run under rtnl lock
  3652. */
  3653. void bnx2x_set_pf_load(struct bnx2x *bp)
  3654. {
  3655. u32 val1, val;
  3656. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3657. BNX2X_PATH0_LOAD_CNT_MASK;
  3658. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3659. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3660. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3661. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3662. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3663. /* get the current counter value */
  3664. val1 = (val & mask) >> shift;
  3665. /* set bit of that PF */
  3666. val1 |= (1 << bp->pf_num);
  3667. /* clear the old value */
  3668. val &= ~mask;
  3669. /* set the new one */
  3670. val |= ((val1 << shift) & mask);
  3671. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3672. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3673. }
  3674. /**
  3675. * bnx2x_clear_pf_load - clear pf load mark
  3676. *
  3677. * @bp: driver handle
  3678. *
  3679. * Should be run under rtnl lock.
  3680. * Decrements the load counter for the current engine. Returns
  3681. * whether other functions are still loaded
  3682. */
  3683. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3684. {
  3685. u32 val1, val;
  3686. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3687. BNX2X_PATH0_LOAD_CNT_MASK;
  3688. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3689. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3690. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3691. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3692. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3693. /* get the current counter value */
  3694. val1 = (val & mask) >> shift;
  3695. /* clear bit of that PF */
  3696. val1 &= ~(1 << bp->pf_num);
  3697. /* clear the old value */
  3698. val &= ~mask;
  3699. /* set the new one */
  3700. val |= ((val1 << shift) & mask);
  3701. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3702. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3703. return val1 != 0;
  3704. }
  3705. /*
  3706. * Read the load status for the current engine.
  3707. *
  3708. * should be run under rtnl lock
  3709. */
  3710. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3711. {
  3712. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3713. BNX2X_PATH0_LOAD_CNT_MASK);
  3714. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3715. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3716. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3717. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3718. val = (val & mask) >> shift;
  3719. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3720. engine, val);
  3721. return val != 0;
  3722. }
  3723. static void _print_parity(struct bnx2x *bp, u32 reg)
  3724. {
  3725. pr_cont(" [0x%08x] ", REG_RD(bp, reg));
  3726. }
  3727. static void _print_next_block(int idx, const char *blk)
  3728. {
  3729. pr_cont("%s%s", idx ? ", " : "", blk);
  3730. }
  3731. static bool bnx2x_check_blocks_with_parity0(struct bnx2x *bp, u32 sig,
  3732. int *par_num, bool print)
  3733. {
  3734. u32 cur_bit;
  3735. bool res;
  3736. int i;
  3737. res = false;
  3738. for (i = 0; sig; i++) {
  3739. cur_bit = (0x1UL << i);
  3740. if (sig & cur_bit) {
  3741. res |= true; /* Each bit is real error! */
  3742. if (print) {
  3743. switch (cur_bit) {
  3744. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3745. _print_next_block((*par_num)++, "BRB");
  3746. _print_parity(bp,
  3747. BRB1_REG_BRB1_PRTY_STS);
  3748. break;
  3749. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3750. _print_next_block((*par_num)++,
  3751. "PARSER");
  3752. _print_parity(bp, PRS_REG_PRS_PRTY_STS);
  3753. break;
  3754. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3755. _print_next_block((*par_num)++, "TSDM");
  3756. _print_parity(bp,
  3757. TSDM_REG_TSDM_PRTY_STS);
  3758. break;
  3759. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3760. _print_next_block((*par_num)++,
  3761. "SEARCHER");
  3762. _print_parity(bp, SRC_REG_SRC_PRTY_STS);
  3763. break;
  3764. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3765. _print_next_block((*par_num)++, "TCM");
  3766. _print_parity(bp, TCM_REG_TCM_PRTY_STS);
  3767. break;
  3768. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3769. _print_next_block((*par_num)++,
  3770. "TSEMI");
  3771. _print_parity(bp,
  3772. TSEM_REG_TSEM_PRTY_STS_0);
  3773. _print_parity(bp,
  3774. TSEM_REG_TSEM_PRTY_STS_1);
  3775. break;
  3776. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3777. _print_next_block((*par_num)++, "XPB");
  3778. _print_parity(bp, GRCBASE_XPB +
  3779. PB_REG_PB_PRTY_STS);
  3780. break;
  3781. }
  3782. }
  3783. /* Clear the bit */
  3784. sig &= ~cur_bit;
  3785. }
  3786. }
  3787. return res;
  3788. }
  3789. static bool bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
  3790. int *par_num, bool *global,
  3791. bool print)
  3792. {
  3793. u32 cur_bit;
  3794. bool res;
  3795. int i;
  3796. res = false;
  3797. for (i = 0; sig; i++) {
  3798. cur_bit = (0x1UL << i);
  3799. if (sig & cur_bit) {
  3800. res |= true; /* Each bit is real error! */
  3801. switch (cur_bit) {
  3802. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3803. if (print) {
  3804. _print_next_block((*par_num)++, "PBF");
  3805. _print_parity(bp, PBF_REG_PBF_PRTY_STS);
  3806. }
  3807. break;
  3808. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3809. if (print) {
  3810. _print_next_block((*par_num)++, "QM");
  3811. _print_parity(bp, QM_REG_QM_PRTY_STS);
  3812. }
  3813. break;
  3814. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3815. if (print) {
  3816. _print_next_block((*par_num)++, "TM");
  3817. _print_parity(bp, TM_REG_TM_PRTY_STS);
  3818. }
  3819. break;
  3820. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3821. if (print) {
  3822. _print_next_block((*par_num)++, "XSDM");
  3823. _print_parity(bp,
  3824. XSDM_REG_XSDM_PRTY_STS);
  3825. }
  3826. break;
  3827. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3828. if (print) {
  3829. _print_next_block((*par_num)++, "XCM");
  3830. _print_parity(bp, XCM_REG_XCM_PRTY_STS);
  3831. }
  3832. break;
  3833. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3834. if (print) {
  3835. _print_next_block((*par_num)++,
  3836. "XSEMI");
  3837. _print_parity(bp,
  3838. XSEM_REG_XSEM_PRTY_STS_0);
  3839. _print_parity(bp,
  3840. XSEM_REG_XSEM_PRTY_STS_1);
  3841. }
  3842. break;
  3843. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3844. if (print) {
  3845. _print_next_block((*par_num)++,
  3846. "DOORBELLQ");
  3847. _print_parity(bp,
  3848. DORQ_REG_DORQ_PRTY_STS);
  3849. }
  3850. break;
  3851. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3852. if (print) {
  3853. _print_next_block((*par_num)++, "NIG");
  3854. if (CHIP_IS_E1x(bp)) {
  3855. _print_parity(bp,
  3856. NIG_REG_NIG_PRTY_STS);
  3857. } else {
  3858. _print_parity(bp,
  3859. NIG_REG_NIG_PRTY_STS_0);
  3860. _print_parity(bp,
  3861. NIG_REG_NIG_PRTY_STS_1);
  3862. }
  3863. }
  3864. break;
  3865. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3866. if (print)
  3867. _print_next_block((*par_num)++,
  3868. "VAUX PCI CORE");
  3869. *global = true;
  3870. break;
  3871. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3872. if (print) {
  3873. _print_next_block((*par_num)++,
  3874. "DEBUG");
  3875. _print_parity(bp, DBG_REG_DBG_PRTY_STS);
  3876. }
  3877. break;
  3878. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3879. if (print) {
  3880. _print_next_block((*par_num)++, "USDM");
  3881. _print_parity(bp,
  3882. USDM_REG_USDM_PRTY_STS);
  3883. }
  3884. break;
  3885. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3886. if (print) {
  3887. _print_next_block((*par_num)++, "UCM");
  3888. _print_parity(bp, UCM_REG_UCM_PRTY_STS);
  3889. }
  3890. break;
  3891. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3892. if (print) {
  3893. _print_next_block((*par_num)++,
  3894. "USEMI");
  3895. _print_parity(bp,
  3896. USEM_REG_USEM_PRTY_STS_0);
  3897. _print_parity(bp,
  3898. USEM_REG_USEM_PRTY_STS_1);
  3899. }
  3900. break;
  3901. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3902. if (print) {
  3903. _print_next_block((*par_num)++, "UPB");
  3904. _print_parity(bp, GRCBASE_UPB +
  3905. PB_REG_PB_PRTY_STS);
  3906. }
  3907. break;
  3908. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3909. if (print) {
  3910. _print_next_block((*par_num)++, "CSDM");
  3911. _print_parity(bp,
  3912. CSDM_REG_CSDM_PRTY_STS);
  3913. }
  3914. break;
  3915. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3916. if (print) {
  3917. _print_next_block((*par_num)++, "CCM");
  3918. _print_parity(bp, CCM_REG_CCM_PRTY_STS);
  3919. }
  3920. break;
  3921. }
  3922. /* Clear the bit */
  3923. sig &= ~cur_bit;
  3924. }
  3925. }
  3926. return res;
  3927. }
  3928. static bool bnx2x_check_blocks_with_parity2(struct bnx2x *bp, u32 sig,
  3929. int *par_num, bool print)
  3930. {
  3931. u32 cur_bit;
  3932. bool res;
  3933. int i;
  3934. res = false;
  3935. for (i = 0; sig; i++) {
  3936. cur_bit = (0x1UL << i);
  3937. if (sig & cur_bit) {
  3938. res |= true; /* Each bit is real error! */
  3939. if (print) {
  3940. switch (cur_bit) {
  3941. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3942. _print_next_block((*par_num)++,
  3943. "CSEMI");
  3944. _print_parity(bp,
  3945. CSEM_REG_CSEM_PRTY_STS_0);
  3946. _print_parity(bp,
  3947. CSEM_REG_CSEM_PRTY_STS_1);
  3948. break;
  3949. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3950. _print_next_block((*par_num)++, "PXP");
  3951. _print_parity(bp, PXP_REG_PXP_PRTY_STS);
  3952. _print_parity(bp,
  3953. PXP2_REG_PXP2_PRTY_STS_0);
  3954. _print_parity(bp,
  3955. PXP2_REG_PXP2_PRTY_STS_1);
  3956. break;
  3957. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3958. _print_next_block((*par_num)++,
  3959. "PXPPCICLOCKCLIENT");
  3960. break;
  3961. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3962. _print_next_block((*par_num)++, "CFC");
  3963. _print_parity(bp,
  3964. CFC_REG_CFC_PRTY_STS);
  3965. break;
  3966. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3967. _print_next_block((*par_num)++, "CDU");
  3968. _print_parity(bp, CDU_REG_CDU_PRTY_STS);
  3969. break;
  3970. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3971. _print_next_block((*par_num)++, "DMAE");
  3972. _print_parity(bp,
  3973. DMAE_REG_DMAE_PRTY_STS);
  3974. break;
  3975. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3976. _print_next_block((*par_num)++, "IGU");
  3977. if (CHIP_IS_E1x(bp))
  3978. _print_parity(bp,
  3979. HC_REG_HC_PRTY_STS);
  3980. else
  3981. _print_parity(bp,
  3982. IGU_REG_IGU_PRTY_STS);
  3983. break;
  3984. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3985. _print_next_block((*par_num)++, "MISC");
  3986. _print_parity(bp,
  3987. MISC_REG_MISC_PRTY_STS);
  3988. break;
  3989. }
  3990. }
  3991. /* Clear the bit */
  3992. sig &= ~cur_bit;
  3993. }
  3994. }
  3995. return res;
  3996. }
  3997. static bool bnx2x_check_blocks_with_parity3(struct bnx2x *bp, u32 sig,
  3998. int *par_num, bool *global,
  3999. bool print)
  4000. {
  4001. bool res = false;
  4002. u32 cur_bit;
  4003. int i;
  4004. for (i = 0; sig; i++) {
  4005. cur_bit = (0x1UL << i);
  4006. if (sig & cur_bit) {
  4007. switch (cur_bit) {
  4008. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  4009. if (print)
  4010. _print_next_block((*par_num)++,
  4011. "MCP ROM");
  4012. *global = true;
  4013. res |= true;
  4014. break;
  4015. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  4016. if (print)
  4017. _print_next_block((*par_num)++,
  4018. "MCP UMP RX");
  4019. *global = true;
  4020. res |= true;
  4021. break;
  4022. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  4023. if (print)
  4024. _print_next_block((*par_num)++,
  4025. "MCP UMP TX");
  4026. *global = true;
  4027. res |= true;
  4028. break;
  4029. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  4030. if (print)
  4031. _print_next_block((*par_num)++,
  4032. "MCP SCPAD");
  4033. /* clear latched SCPAD PATIRY from MCP */
  4034. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL,
  4035. 1UL << 10);
  4036. break;
  4037. }
  4038. /* Clear the bit */
  4039. sig &= ~cur_bit;
  4040. }
  4041. }
  4042. return res;
  4043. }
  4044. static bool bnx2x_check_blocks_with_parity4(struct bnx2x *bp, u32 sig,
  4045. int *par_num, bool print)
  4046. {
  4047. u32 cur_bit;
  4048. bool res;
  4049. int i;
  4050. res = false;
  4051. for (i = 0; sig; i++) {
  4052. cur_bit = (0x1UL << i);
  4053. if (sig & cur_bit) {
  4054. res |= true; /* Each bit is real error! */
  4055. if (print) {
  4056. switch (cur_bit) {
  4057. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  4058. _print_next_block((*par_num)++,
  4059. "PGLUE_B");
  4060. _print_parity(bp,
  4061. PGLUE_B_REG_PGLUE_B_PRTY_STS);
  4062. break;
  4063. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  4064. _print_next_block((*par_num)++, "ATC");
  4065. _print_parity(bp,
  4066. ATC_REG_ATC_PRTY_STS);
  4067. break;
  4068. }
  4069. }
  4070. /* Clear the bit */
  4071. sig &= ~cur_bit;
  4072. }
  4073. }
  4074. return res;
  4075. }
  4076. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  4077. u32 *sig)
  4078. {
  4079. bool res = false;
  4080. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  4081. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  4082. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  4083. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  4084. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  4085. int par_num = 0;
  4086. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  4087. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  4088. sig[0] & HW_PRTY_ASSERT_SET_0,
  4089. sig[1] & HW_PRTY_ASSERT_SET_1,
  4090. sig[2] & HW_PRTY_ASSERT_SET_2,
  4091. sig[3] & HW_PRTY_ASSERT_SET_3,
  4092. sig[4] & HW_PRTY_ASSERT_SET_4);
  4093. if (print)
  4094. netdev_err(bp->dev,
  4095. "Parity errors detected in blocks: ");
  4096. res |= bnx2x_check_blocks_with_parity0(bp,
  4097. sig[0] & HW_PRTY_ASSERT_SET_0, &par_num, print);
  4098. res |= bnx2x_check_blocks_with_parity1(bp,
  4099. sig[1] & HW_PRTY_ASSERT_SET_1, &par_num, global, print);
  4100. res |= bnx2x_check_blocks_with_parity2(bp,
  4101. sig[2] & HW_PRTY_ASSERT_SET_2, &par_num, print);
  4102. res |= bnx2x_check_blocks_with_parity3(bp,
  4103. sig[3] & HW_PRTY_ASSERT_SET_3, &par_num, global, print);
  4104. res |= bnx2x_check_blocks_with_parity4(bp,
  4105. sig[4] & HW_PRTY_ASSERT_SET_4, &par_num, print);
  4106. if (print)
  4107. pr_cont("\n");
  4108. }
  4109. return res;
  4110. }
  4111. /**
  4112. * bnx2x_chk_parity_attn - checks for parity attentions.
  4113. *
  4114. * @bp: driver handle
  4115. * @global: true if there was a global attention
  4116. * @print: show parity attention in syslog
  4117. */
  4118. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  4119. {
  4120. struct attn_route attn = { {0} };
  4121. int port = BP_PORT(bp);
  4122. attn.sig[0] = REG_RD(bp,
  4123. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  4124. port*4);
  4125. attn.sig[1] = REG_RD(bp,
  4126. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  4127. port*4);
  4128. attn.sig[2] = REG_RD(bp,
  4129. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  4130. port*4);
  4131. attn.sig[3] = REG_RD(bp,
  4132. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  4133. port*4);
  4134. /* Since MCP attentions can't be disabled inside the block, we need to
  4135. * read AEU registers to see whether they're currently disabled
  4136. */
  4137. attn.sig[3] &= ((REG_RD(bp,
  4138. !port ? MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0
  4139. : MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0) &
  4140. MISC_AEU_ENABLE_MCP_PRTY_BITS) |
  4141. ~MISC_AEU_ENABLE_MCP_PRTY_BITS);
  4142. if (!CHIP_IS_E1x(bp))
  4143. attn.sig[4] = REG_RD(bp,
  4144. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  4145. port*4);
  4146. return bnx2x_parity_attn(bp, global, print, attn.sig);
  4147. }
  4148. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  4149. {
  4150. u32 val;
  4151. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  4152. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  4153. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  4154. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  4155. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  4156. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  4157. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  4158. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  4159. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  4160. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  4161. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  4162. if (val &
  4163. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  4164. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  4165. if (val &
  4166. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  4167. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  4168. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  4169. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  4170. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  4171. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  4172. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  4173. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  4174. }
  4175. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  4176. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  4177. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  4178. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  4179. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  4180. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  4181. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  4182. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  4183. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  4184. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  4185. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  4186. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  4187. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  4188. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  4189. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  4190. }
  4191. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4192. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  4193. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  4194. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4195. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  4196. }
  4197. }
  4198. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  4199. {
  4200. struct attn_route attn, *group_mask;
  4201. int port = BP_PORT(bp);
  4202. int index;
  4203. u32 reg_addr;
  4204. u32 val;
  4205. u32 aeu_mask;
  4206. bool global = false;
  4207. /* need to take HW lock because MCP or other port might also
  4208. try to handle this event */
  4209. bnx2x_acquire_alr(bp);
  4210. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  4211. #ifndef BNX2X_STOP_ON_ERROR
  4212. bp->recovery_state = BNX2X_RECOVERY_INIT;
  4213. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4214. /* Disable HW interrupts */
  4215. bnx2x_int_disable(bp);
  4216. /* In case of parity errors don't handle attentions so that
  4217. * other function would "see" parity errors.
  4218. */
  4219. #else
  4220. bnx2x_panic();
  4221. #endif
  4222. bnx2x_release_alr(bp);
  4223. return;
  4224. }
  4225. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  4226. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  4227. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  4228. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  4229. if (!CHIP_IS_E1x(bp))
  4230. attn.sig[4] =
  4231. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  4232. else
  4233. attn.sig[4] = 0;
  4234. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  4235. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  4236. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4237. if (deasserted & (1 << index)) {
  4238. group_mask = &bp->attn_group[index];
  4239. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  4240. index,
  4241. group_mask->sig[0], group_mask->sig[1],
  4242. group_mask->sig[2], group_mask->sig[3],
  4243. group_mask->sig[4]);
  4244. bnx2x_attn_int_deasserted4(bp,
  4245. attn.sig[4] & group_mask->sig[4]);
  4246. bnx2x_attn_int_deasserted3(bp,
  4247. attn.sig[3] & group_mask->sig[3]);
  4248. bnx2x_attn_int_deasserted1(bp,
  4249. attn.sig[1] & group_mask->sig[1]);
  4250. bnx2x_attn_int_deasserted2(bp,
  4251. attn.sig[2] & group_mask->sig[2]);
  4252. bnx2x_attn_int_deasserted0(bp,
  4253. attn.sig[0] & group_mask->sig[0]);
  4254. }
  4255. }
  4256. bnx2x_release_alr(bp);
  4257. if (bp->common.int_block == INT_BLOCK_HC)
  4258. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  4259. COMMAND_REG_ATTN_BITS_CLR);
  4260. else
  4261. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  4262. val = ~deasserted;
  4263. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  4264. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  4265. REG_WR(bp, reg_addr, val);
  4266. if (~bp->attn_state & deasserted)
  4267. BNX2X_ERR("IGU ERROR\n");
  4268. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  4269. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  4270. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4271. aeu_mask = REG_RD(bp, reg_addr);
  4272. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  4273. aeu_mask, deasserted);
  4274. aeu_mask |= (deasserted & 0x3ff);
  4275. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  4276. REG_WR(bp, reg_addr, aeu_mask);
  4277. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4278. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  4279. bp->attn_state &= ~deasserted;
  4280. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  4281. }
  4282. static void bnx2x_attn_int(struct bnx2x *bp)
  4283. {
  4284. /* read local copy of bits */
  4285. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4286. attn_bits);
  4287. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4288. attn_bits_ack);
  4289. u32 attn_state = bp->attn_state;
  4290. /* look for changed bits */
  4291. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  4292. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  4293. DP(NETIF_MSG_HW,
  4294. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  4295. attn_bits, attn_ack, asserted, deasserted);
  4296. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  4297. BNX2X_ERR("BAD attention state\n");
  4298. /* handle bits that were raised */
  4299. if (asserted)
  4300. bnx2x_attn_int_asserted(bp, asserted);
  4301. if (deasserted)
  4302. bnx2x_attn_int_deasserted(bp, deasserted);
  4303. }
  4304. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  4305. u16 index, u8 op, u8 update)
  4306. {
  4307. u32 igu_addr = bp->igu_base_addr;
  4308. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  4309. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  4310. igu_addr);
  4311. }
  4312. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  4313. {
  4314. /* No memory barriers */
  4315. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  4316. mmiowb(); /* keep prod updates ordered */
  4317. }
  4318. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  4319. union event_ring_elem *elem)
  4320. {
  4321. u8 err = elem->message.error;
  4322. if (!bp->cnic_eth_dev.starting_cid ||
  4323. (cid < bp->cnic_eth_dev.starting_cid &&
  4324. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  4325. return 1;
  4326. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  4327. if (unlikely(err)) {
  4328. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  4329. cid);
  4330. bnx2x_panic_dump(bp, false);
  4331. }
  4332. bnx2x_cnic_cfc_comp(bp, cid, err);
  4333. return 0;
  4334. }
  4335. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  4336. {
  4337. struct bnx2x_mcast_ramrod_params rparam;
  4338. int rc;
  4339. memset(&rparam, 0, sizeof(rparam));
  4340. rparam.mcast_obj = &bp->mcast_obj;
  4341. netif_addr_lock_bh(bp->dev);
  4342. /* Clear pending state for the last command */
  4343. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  4344. /* If there are pending mcast commands - send them */
  4345. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  4346. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  4347. if (rc < 0)
  4348. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  4349. rc);
  4350. }
  4351. netif_addr_unlock_bh(bp->dev);
  4352. }
  4353. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4354. union event_ring_elem *elem)
  4355. {
  4356. unsigned long ramrod_flags = 0;
  4357. int rc = 0;
  4358. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  4359. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4360. /* Always push next commands out, don't wait here */
  4361. __set_bit(RAMROD_CONT, &ramrod_flags);
  4362. switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo)
  4363. >> BNX2X_SWCID_SHIFT) {
  4364. case BNX2X_FILTER_MAC_PENDING:
  4365. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4366. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4367. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4368. else
  4369. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4370. break;
  4371. case BNX2X_FILTER_MCAST_PENDING:
  4372. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4373. /* This is only relevant for 57710 where multicast MACs are
  4374. * configured as unicast MACs using the same ramrod.
  4375. */
  4376. bnx2x_handle_mcast_eqe(bp);
  4377. return;
  4378. default:
  4379. BNX2X_ERR("Unsupported classification command: %d\n",
  4380. elem->message.data.eth_event.echo);
  4381. return;
  4382. }
  4383. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4384. if (rc < 0)
  4385. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4386. else if (rc > 0)
  4387. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4388. }
  4389. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4390. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4391. {
  4392. netif_addr_lock_bh(bp->dev);
  4393. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4394. /* Send rx_mode command again if was requested */
  4395. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4396. bnx2x_set_storm_rx_mode(bp);
  4397. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4398. &bp->sp_state))
  4399. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4400. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4401. &bp->sp_state))
  4402. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4403. netif_addr_unlock_bh(bp->dev);
  4404. }
  4405. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4406. union event_ring_elem *elem)
  4407. {
  4408. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4409. DP(BNX2X_MSG_SP,
  4410. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4411. elem->message.data.vif_list_event.func_bit_map);
  4412. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4413. elem->message.data.vif_list_event.func_bit_map);
  4414. } else if (elem->message.data.vif_list_event.echo ==
  4415. VIF_LIST_RULE_SET) {
  4416. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4417. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4418. }
  4419. }
  4420. /* called with rtnl_lock */
  4421. static void bnx2x_after_function_update(struct bnx2x *bp)
  4422. {
  4423. int q, rc;
  4424. struct bnx2x_fastpath *fp;
  4425. struct bnx2x_queue_state_params queue_params = {NULL};
  4426. struct bnx2x_queue_update_params *q_update_params =
  4427. &queue_params.params.update;
  4428. /* Send Q update command with afex vlan removal values for all Qs */
  4429. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4430. /* set silent vlan removal values according to vlan mode */
  4431. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4432. &q_update_params->update_flags);
  4433. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4434. &q_update_params->update_flags);
  4435. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4436. /* in access mode mark mask and value are 0 to strip all vlans */
  4437. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4438. q_update_params->silent_removal_value = 0;
  4439. q_update_params->silent_removal_mask = 0;
  4440. } else {
  4441. q_update_params->silent_removal_value =
  4442. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4443. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4444. }
  4445. for_each_eth_queue(bp, q) {
  4446. /* Set the appropriate Queue object */
  4447. fp = &bp->fp[q];
  4448. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4449. /* send the ramrod */
  4450. rc = bnx2x_queue_state_change(bp, &queue_params);
  4451. if (rc < 0)
  4452. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4453. q);
  4454. }
  4455. if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
  4456. fp = &bp->fp[FCOE_IDX(bp)];
  4457. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4458. /* clear pending completion bit */
  4459. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4460. /* mark latest Q bit */
  4461. smp_mb__before_atomic();
  4462. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4463. smp_mb__after_atomic();
  4464. /* send Q update ramrod for FCoE Q */
  4465. rc = bnx2x_queue_state_change(bp, &queue_params);
  4466. if (rc < 0)
  4467. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4468. q);
  4469. } else {
  4470. /* If no FCoE ring - ACK MCP now */
  4471. bnx2x_link_report(bp);
  4472. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4473. }
  4474. }
  4475. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4476. struct bnx2x *bp, u32 cid)
  4477. {
  4478. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4479. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4480. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4481. else
  4482. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4483. }
  4484. static void bnx2x_eq_int(struct bnx2x *bp)
  4485. {
  4486. u16 hw_cons, sw_cons, sw_prod;
  4487. union event_ring_elem *elem;
  4488. u8 echo;
  4489. u32 cid;
  4490. u8 opcode;
  4491. int rc, spqe_cnt = 0;
  4492. struct bnx2x_queue_sp_obj *q_obj;
  4493. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4494. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4495. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4496. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4497. * when we get the next-page we need to adjust so the loop
  4498. * condition below will be met. The next element is the size of a
  4499. * regular element and hence incrementing by 1
  4500. */
  4501. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4502. hw_cons++;
  4503. /* This function may never run in parallel with itself for a
  4504. * specific bp, thus there is no need in "paired" read memory
  4505. * barrier here.
  4506. */
  4507. sw_cons = bp->eq_cons;
  4508. sw_prod = bp->eq_prod;
  4509. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4510. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4511. for (; sw_cons != hw_cons;
  4512. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4513. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4514. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4515. if (!rc) {
  4516. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4517. rc);
  4518. goto next_spqe;
  4519. }
  4520. /* elem CID originates from FW; actually LE */
  4521. cid = SW_CID((__force __le32)
  4522. elem->message.data.cfc_del_event.cid);
  4523. opcode = elem->message.opcode;
  4524. /* handle eq element */
  4525. switch (opcode) {
  4526. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4527. bnx2x_vf_mbx_schedule(bp,
  4528. &elem->message.data.vf_pf_event);
  4529. continue;
  4530. case EVENT_RING_OPCODE_STAT_QUERY:
  4531. DP_AND((BNX2X_MSG_SP | BNX2X_MSG_STATS),
  4532. "got statistics comp event %d\n",
  4533. bp->stats_comp++);
  4534. /* nothing to do with stats comp */
  4535. goto next_spqe;
  4536. case EVENT_RING_OPCODE_CFC_DEL:
  4537. /* handle according to cid range */
  4538. /*
  4539. * we may want to verify here that the bp state is
  4540. * HALTING
  4541. */
  4542. DP(BNX2X_MSG_SP,
  4543. "got delete ramrod for MULTI[%d]\n", cid);
  4544. if (CNIC_LOADED(bp) &&
  4545. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4546. goto next_spqe;
  4547. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4548. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4549. break;
  4550. goto next_spqe;
  4551. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4552. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4553. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4554. if (f_obj->complete_cmd(bp, f_obj,
  4555. BNX2X_F_CMD_TX_STOP))
  4556. break;
  4557. goto next_spqe;
  4558. case EVENT_RING_OPCODE_START_TRAFFIC:
  4559. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4560. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4561. if (f_obj->complete_cmd(bp, f_obj,
  4562. BNX2X_F_CMD_TX_START))
  4563. break;
  4564. goto next_spqe;
  4565. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4566. echo = elem->message.data.function_update_event.echo;
  4567. if (echo == SWITCH_UPDATE) {
  4568. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4569. "got FUNC_SWITCH_UPDATE ramrod\n");
  4570. if (f_obj->complete_cmd(
  4571. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4572. break;
  4573. } else {
  4574. int cmd = BNX2X_SP_RTNL_AFEX_F_UPDATE;
  4575. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4576. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4577. f_obj->complete_cmd(bp, f_obj,
  4578. BNX2X_F_CMD_AFEX_UPDATE);
  4579. /* We will perform the Queues update from
  4580. * sp_rtnl task as all Queue SP operations
  4581. * should run under rtnl_lock.
  4582. */
  4583. bnx2x_schedule_sp_rtnl(bp, cmd, 0);
  4584. }
  4585. goto next_spqe;
  4586. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4587. f_obj->complete_cmd(bp, f_obj,
  4588. BNX2X_F_CMD_AFEX_VIFLISTS);
  4589. bnx2x_after_afex_vif_lists(bp, elem);
  4590. goto next_spqe;
  4591. case EVENT_RING_OPCODE_FUNCTION_START:
  4592. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4593. "got FUNC_START ramrod\n");
  4594. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4595. break;
  4596. goto next_spqe;
  4597. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4598. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4599. "got FUNC_STOP ramrod\n");
  4600. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4601. break;
  4602. goto next_spqe;
  4603. }
  4604. switch (opcode | bp->state) {
  4605. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4606. BNX2X_STATE_OPEN):
  4607. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4608. BNX2X_STATE_OPENING_WAIT4_PORT):
  4609. cid = elem->message.data.eth_event.echo &
  4610. BNX2X_SWCID_MASK;
  4611. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4612. cid);
  4613. rss_raw->clear_pending(rss_raw);
  4614. break;
  4615. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4616. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4617. case (EVENT_RING_OPCODE_SET_MAC |
  4618. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4619. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4620. BNX2X_STATE_OPEN):
  4621. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4622. BNX2X_STATE_DIAG):
  4623. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4624. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4625. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4626. bnx2x_handle_classification_eqe(bp, elem);
  4627. break;
  4628. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4629. BNX2X_STATE_OPEN):
  4630. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4631. BNX2X_STATE_DIAG):
  4632. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4633. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4634. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4635. bnx2x_handle_mcast_eqe(bp);
  4636. break;
  4637. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4638. BNX2X_STATE_OPEN):
  4639. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4640. BNX2X_STATE_DIAG):
  4641. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4642. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4643. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4644. bnx2x_handle_rx_mode_eqe(bp);
  4645. break;
  4646. default:
  4647. /* unknown event log error and continue */
  4648. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4649. elem->message.opcode, bp->state);
  4650. }
  4651. next_spqe:
  4652. spqe_cnt++;
  4653. } /* for */
  4654. smp_mb__before_atomic();
  4655. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4656. bp->eq_cons = sw_cons;
  4657. bp->eq_prod = sw_prod;
  4658. /* Make sure that above mem writes were issued towards the memory */
  4659. smp_wmb();
  4660. /* update producer */
  4661. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4662. }
  4663. static void bnx2x_sp_task(struct work_struct *work)
  4664. {
  4665. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4666. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4667. /* make sure the atomic interrupt_occurred has been written */
  4668. smp_rmb();
  4669. if (atomic_read(&bp->interrupt_occurred)) {
  4670. /* what work needs to be performed? */
  4671. u16 status = bnx2x_update_dsb_idx(bp);
  4672. DP(BNX2X_MSG_SP, "status %x\n", status);
  4673. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4674. atomic_set(&bp->interrupt_occurred, 0);
  4675. /* HW attentions */
  4676. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4677. bnx2x_attn_int(bp);
  4678. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4679. }
  4680. /* SP events: STAT_QUERY and others */
  4681. if (status & BNX2X_DEF_SB_IDX) {
  4682. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4683. if (FCOE_INIT(bp) &&
  4684. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4685. /* Prevent local bottom-halves from running as
  4686. * we are going to change the local NAPI list.
  4687. */
  4688. local_bh_disable();
  4689. napi_schedule(&bnx2x_fcoe(bp, napi));
  4690. local_bh_enable();
  4691. }
  4692. /* Handle EQ completions */
  4693. bnx2x_eq_int(bp);
  4694. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4695. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4696. status &= ~BNX2X_DEF_SB_IDX;
  4697. }
  4698. /* if status is non zero then perhaps something went wrong */
  4699. if (unlikely(status))
  4700. DP(BNX2X_MSG_SP,
  4701. "got an unknown interrupt! (status 0x%x)\n", status);
  4702. /* ack status block only if something was actually handled */
  4703. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4704. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4705. }
  4706. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4707. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4708. &bp->sp_state)) {
  4709. bnx2x_link_report(bp);
  4710. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4711. }
  4712. }
  4713. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4714. {
  4715. struct net_device *dev = dev_instance;
  4716. struct bnx2x *bp = netdev_priv(dev);
  4717. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4718. IGU_INT_DISABLE, 0);
  4719. #ifdef BNX2X_STOP_ON_ERROR
  4720. if (unlikely(bp->panic))
  4721. return IRQ_HANDLED;
  4722. #endif
  4723. if (CNIC_LOADED(bp)) {
  4724. struct cnic_ops *c_ops;
  4725. rcu_read_lock();
  4726. c_ops = rcu_dereference(bp->cnic_ops);
  4727. if (c_ops)
  4728. c_ops->cnic_handler(bp->cnic_data, NULL);
  4729. rcu_read_unlock();
  4730. }
  4731. /* schedule sp task to perform default status block work, ack
  4732. * attentions and enable interrupts.
  4733. */
  4734. bnx2x_schedule_sp_task(bp);
  4735. return IRQ_HANDLED;
  4736. }
  4737. /* end of slow path */
  4738. void bnx2x_drv_pulse(struct bnx2x *bp)
  4739. {
  4740. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4741. bp->fw_drv_pulse_wr_seq);
  4742. }
  4743. static void bnx2x_timer(unsigned long data)
  4744. {
  4745. struct bnx2x *bp = (struct bnx2x *) data;
  4746. if (!netif_running(bp->dev))
  4747. return;
  4748. if (IS_PF(bp) &&
  4749. !BP_NOMCP(bp)) {
  4750. int mb_idx = BP_FW_MB_IDX(bp);
  4751. u16 drv_pulse;
  4752. u16 mcp_pulse;
  4753. ++bp->fw_drv_pulse_wr_seq;
  4754. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4755. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4756. bnx2x_drv_pulse(bp);
  4757. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4758. MCP_PULSE_SEQ_MASK);
  4759. /* The delta between driver pulse and mcp response
  4760. * should not get too big. If the MFW is more than 5 pulses
  4761. * behind, we should worry about it enough to generate an error
  4762. * log.
  4763. */
  4764. if (((drv_pulse - mcp_pulse) & MCP_PULSE_SEQ_MASK) > 5)
  4765. BNX2X_ERR("MFW seems hanged: drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4766. drv_pulse, mcp_pulse);
  4767. }
  4768. if (bp->state == BNX2X_STATE_OPEN)
  4769. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4770. /* sample pf vf bulletin board for new posts from pf */
  4771. if (IS_VF(bp))
  4772. bnx2x_timer_sriov(bp);
  4773. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4774. }
  4775. /* end of Statistics */
  4776. /* nic init */
  4777. /*
  4778. * nic init service functions
  4779. */
  4780. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4781. {
  4782. u32 i;
  4783. if (!(len%4) && !(addr%4))
  4784. for (i = 0; i < len; i += 4)
  4785. REG_WR(bp, addr + i, fill);
  4786. else
  4787. for (i = 0; i < len; i++)
  4788. REG_WR8(bp, addr + i, fill);
  4789. }
  4790. /* helper: writes FP SP data to FW - data_size in dwords */
  4791. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4792. int fw_sb_id,
  4793. u32 *sb_data_p,
  4794. u32 data_size)
  4795. {
  4796. int index;
  4797. for (index = 0; index < data_size; index++)
  4798. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4799. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4800. sizeof(u32)*index,
  4801. *(sb_data_p + index));
  4802. }
  4803. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4804. {
  4805. u32 *sb_data_p;
  4806. u32 data_size = 0;
  4807. struct hc_status_block_data_e2 sb_data_e2;
  4808. struct hc_status_block_data_e1x sb_data_e1x;
  4809. /* disable the function first */
  4810. if (!CHIP_IS_E1x(bp)) {
  4811. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4812. sb_data_e2.common.state = SB_DISABLED;
  4813. sb_data_e2.common.p_func.vf_valid = false;
  4814. sb_data_p = (u32 *)&sb_data_e2;
  4815. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4816. } else {
  4817. memset(&sb_data_e1x, 0,
  4818. sizeof(struct hc_status_block_data_e1x));
  4819. sb_data_e1x.common.state = SB_DISABLED;
  4820. sb_data_e1x.common.p_func.vf_valid = false;
  4821. sb_data_p = (u32 *)&sb_data_e1x;
  4822. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4823. }
  4824. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4825. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4826. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4827. CSTORM_STATUS_BLOCK_SIZE);
  4828. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4829. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4830. CSTORM_SYNC_BLOCK_SIZE);
  4831. }
  4832. /* helper: writes SP SB data to FW */
  4833. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4834. struct hc_sp_status_block_data *sp_sb_data)
  4835. {
  4836. int func = BP_FUNC(bp);
  4837. int i;
  4838. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4839. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4840. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4841. i*sizeof(u32),
  4842. *((u32 *)sp_sb_data + i));
  4843. }
  4844. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4845. {
  4846. int func = BP_FUNC(bp);
  4847. struct hc_sp_status_block_data sp_sb_data;
  4848. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4849. sp_sb_data.state = SB_DISABLED;
  4850. sp_sb_data.p_func.vf_valid = false;
  4851. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4852. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4853. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4854. CSTORM_SP_STATUS_BLOCK_SIZE);
  4855. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4856. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4857. CSTORM_SP_SYNC_BLOCK_SIZE);
  4858. }
  4859. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4860. int igu_sb_id, int igu_seg_id)
  4861. {
  4862. hc_sm->igu_sb_id = igu_sb_id;
  4863. hc_sm->igu_seg_id = igu_seg_id;
  4864. hc_sm->timer_value = 0xFF;
  4865. hc_sm->time_to_expire = 0xFFFFFFFF;
  4866. }
  4867. /* allocates state machine ids. */
  4868. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4869. {
  4870. /* zero out state machine indices */
  4871. /* rx indices */
  4872. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4873. /* tx indices */
  4874. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4875. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4876. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4877. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4878. /* map indices */
  4879. /* rx indices */
  4880. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4881. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4882. /* tx indices */
  4883. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4884. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4885. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4886. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4887. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4888. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4889. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4890. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4891. }
  4892. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4893. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4894. {
  4895. int igu_seg_id;
  4896. struct hc_status_block_data_e2 sb_data_e2;
  4897. struct hc_status_block_data_e1x sb_data_e1x;
  4898. struct hc_status_block_sm *hc_sm_p;
  4899. int data_size;
  4900. u32 *sb_data_p;
  4901. if (CHIP_INT_MODE_IS_BC(bp))
  4902. igu_seg_id = HC_SEG_ACCESS_NORM;
  4903. else
  4904. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4905. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4906. if (!CHIP_IS_E1x(bp)) {
  4907. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4908. sb_data_e2.common.state = SB_ENABLED;
  4909. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4910. sb_data_e2.common.p_func.vf_id = vfid;
  4911. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4912. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4913. sb_data_e2.common.same_igu_sb_1b = true;
  4914. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4915. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4916. hc_sm_p = sb_data_e2.common.state_machine;
  4917. sb_data_p = (u32 *)&sb_data_e2;
  4918. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4919. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4920. } else {
  4921. memset(&sb_data_e1x, 0,
  4922. sizeof(struct hc_status_block_data_e1x));
  4923. sb_data_e1x.common.state = SB_ENABLED;
  4924. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4925. sb_data_e1x.common.p_func.vf_id = 0xff;
  4926. sb_data_e1x.common.p_func.vf_valid = false;
  4927. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4928. sb_data_e1x.common.same_igu_sb_1b = true;
  4929. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4930. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4931. hc_sm_p = sb_data_e1x.common.state_machine;
  4932. sb_data_p = (u32 *)&sb_data_e1x;
  4933. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4934. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4935. }
  4936. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4937. igu_sb_id, igu_seg_id);
  4938. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4939. igu_sb_id, igu_seg_id);
  4940. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4941. /* write indices to HW - PCI guarantees endianity of regpairs */
  4942. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4943. }
  4944. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4945. u16 tx_usec, u16 rx_usec)
  4946. {
  4947. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4948. false, rx_usec);
  4949. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4950. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4951. tx_usec);
  4952. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4953. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4954. tx_usec);
  4955. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4956. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4957. tx_usec);
  4958. }
  4959. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4960. {
  4961. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4962. dma_addr_t mapping = bp->def_status_blk_mapping;
  4963. int igu_sp_sb_index;
  4964. int igu_seg_id;
  4965. int port = BP_PORT(bp);
  4966. int func = BP_FUNC(bp);
  4967. int reg_offset, reg_offset_en5;
  4968. u64 section;
  4969. int index;
  4970. struct hc_sp_status_block_data sp_sb_data;
  4971. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4972. if (CHIP_INT_MODE_IS_BC(bp)) {
  4973. igu_sp_sb_index = DEF_SB_IGU_ID;
  4974. igu_seg_id = HC_SEG_ACCESS_DEF;
  4975. } else {
  4976. igu_sp_sb_index = bp->igu_dsb_id;
  4977. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4978. }
  4979. /* ATTN */
  4980. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4981. atten_status_block);
  4982. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4983. bp->attn_state = 0;
  4984. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4985. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4986. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4987. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4988. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4989. int sindex;
  4990. /* take care of sig[0]..sig[4] */
  4991. for (sindex = 0; sindex < 4; sindex++)
  4992. bp->attn_group[index].sig[sindex] =
  4993. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4994. if (!CHIP_IS_E1x(bp))
  4995. /*
  4996. * enable5 is separate from the rest of the registers,
  4997. * and therefore the address skip is 4
  4998. * and not 16 between the different groups
  4999. */
  5000. bp->attn_group[index].sig[4] = REG_RD(bp,
  5001. reg_offset_en5 + 0x4*index);
  5002. else
  5003. bp->attn_group[index].sig[4] = 0;
  5004. }
  5005. if (bp->common.int_block == INT_BLOCK_HC) {
  5006. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  5007. HC_REG_ATTN_MSG0_ADDR_L);
  5008. REG_WR(bp, reg_offset, U64_LO(section));
  5009. REG_WR(bp, reg_offset + 4, U64_HI(section));
  5010. } else if (!CHIP_IS_E1x(bp)) {
  5011. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  5012. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  5013. }
  5014. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  5015. sp_sb);
  5016. bnx2x_zero_sp_sb(bp);
  5017. /* PCI guarantees endianity of regpairs */
  5018. sp_sb_data.state = SB_ENABLED;
  5019. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  5020. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  5021. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  5022. sp_sb_data.igu_seg_id = igu_seg_id;
  5023. sp_sb_data.p_func.pf_id = func;
  5024. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  5025. sp_sb_data.p_func.vf_id = 0xff;
  5026. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  5027. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  5028. }
  5029. void bnx2x_update_coalesce(struct bnx2x *bp)
  5030. {
  5031. int i;
  5032. for_each_eth_queue(bp, i)
  5033. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  5034. bp->tx_ticks, bp->rx_ticks);
  5035. }
  5036. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  5037. {
  5038. spin_lock_init(&bp->spq_lock);
  5039. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  5040. bp->spq_prod_idx = 0;
  5041. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  5042. bp->spq_prod_bd = bp->spq;
  5043. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  5044. }
  5045. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  5046. {
  5047. int i;
  5048. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  5049. union event_ring_elem *elem =
  5050. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  5051. elem->next_page.addr.hi =
  5052. cpu_to_le32(U64_HI(bp->eq_mapping +
  5053. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  5054. elem->next_page.addr.lo =
  5055. cpu_to_le32(U64_LO(bp->eq_mapping +
  5056. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  5057. }
  5058. bp->eq_cons = 0;
  5059. bp->eq_prod = NUM_EQ_DESC;
  5060. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  5061. /* we want a warning message before it gets wrought... */
  5062. atomic_set(&bp->eq_spq_left,
  5063. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  5064. }
  5065. /* called with netif_addr_lock_bh() */
  5066. static int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  5067. unsigned long rx_mode_flags,
  5068. unsigned long rx_accept_flags,
  5069. unsigned long tx_accept_flags,
  5070. unsigned long ramrod_flags)
  5071. {
  5072. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  5073. int rc;
  5074. memset(&ramrod_param, 0, sizeof(ramrod_param));
  5075. /* Prepare ramrod parameters */
  5076. ramrod_param.cid = 0;
  5077. ramrod_param.cl_id = cl_id;
  5078. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  5079. ramrod_param.func_id = BP_FUNC(bp);
  5080. ramrod_param.pstate = &bp->sp_state;
  5081. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  5082. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  5083. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  5084. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  5085. ramrod_param.ramrod_flags = ramrod_flags;
  5086. ramrod_param.rx_mode_flags = rx_mode_flags;
  5087. ramrod_param.rx_accept_flags = rx_accept_flags;
  5088. ramrod_param.tx_accept_flags = tx_accept_flags;
  5089. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  5090. if (rc < 0) {
  5091. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  5092. return rc;
  5093. }
  5094. return 0;
  5095. }
  5096. static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
  5097. unsigned long *rx_accept_flags,
  5098. unsigned long *tx_accept_flags)
  5099. {
  5100. /* Clear the flags first */
  5101. *rx_accept_flags = 0;
  5102. *tx_accept_flags = 0;
  5103. switch (rx_mode) {
  5104. case BNX2X_RX_MODE_NONE:
  5105. /*
  5106. * 'drop all' supersedes any accept flags that may have been
  5107. * passed to the function.
  5108. */
  5109. break;
  5110. case BNX2X_RX_MODE_NORMAL:
  5111. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5112. __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
  5113. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5114. /* internal switching mode */
  5115. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5116. __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
  5117. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5118. break;
  5119. case BNX2X_RX_MODE_ALLMULTI:
  5120. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5121. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5122. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5123. /* internal switching mode */
  5124. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5125. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5126. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5127. break;
  5128. case BNX2X_RX_MODE_PROMISC:
  5129. /* According to definition of SI mode, iface in promisc mode
  5130. * should receive matched and unmatched (in resolution of port)
  5131. * unicast packets.
  5132. */
  5133. __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
  5134. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5135. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5136. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5137. /* internal switching mode */
  5138. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5139. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5140. if (IS_MF_SI(bp))
  5141. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
  5142. else
  5143. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5144. break;
  5145. default:
  5146. BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
  5147. return -EINVAL;
  5148. }
  5149. /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
  5150. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  5151. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  5152. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  5153. }
  5154. return 0;
  5155. }
  5156. /* called with netif_addr_lock_bh() */
  5157. static int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  5158. {
  5159. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  5160. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  5161. int rc;
  5162. if (!NO_FCOE(bp))
  5163. /* Configure rx_mode of FCoE Queue */
  5164. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  5165. rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
  5166. &tx_accept_flags);
  5167. if (rc)
  5168. return rc;
  5169. __set_bit(RAMROD_RX, &ramrod_flags);
  5170. __set_bit(RAMROD_TX, &ramrod_flags);
  5171. return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
  5172. rx_accept_flags, tx_accept_flags,
  5173. ramrod_flags);
  5174. }
  5175. static void bnx2x_init_internal_common(struct bnx2x *bp)
  5176. {
  5177. int i;
  5178. /* Zero this manually as its initialization is
  5179. currently missing in the initTool */
  5180. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  5181. REG_WR(bp, BAR_USTRORM_INTMEM +
  5182. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  5183. if (!CHIP_IS_E1x(bp)) {
  5184. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  5185. CHIP_INT_MODE_IS_BC(bp) ?
  5186. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  5187. }
  5188. }
  5189. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  5190. {
  5191. switch (load_code) {
  5192. case FW_MSG_CODE_DRV_LOAD_COMMON:
  5193. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  5194. bnx2x_init_internal_common(bp);
  5195. /* no break */
  5196. case FW_MSG_CODE_DRV_LOAD_PORT:
  5197. /* nothing to do */
  5198. /* no break */
  5199. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  5200. /* internal memory per function is
  5201. initialized inside bnx2x_pf_init */
  5202. break;
  5203. default:
  5204. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  5205. break;
  5206. }
  5207. }
  5208. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  5209. {
  5210. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  5211. }
  5212. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  5213. {
  5214. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  5215. }
  5216. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  5217. {
  5218. if (CHIP_IS_E1x(fp->bp))
  5219. return BP_L_ID(fp->bp) + fp->index;
  5220. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  5221. return bnx2x_fp_igu_sb_id(fp);
  5222. }
  5223. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  5224. {
  5225. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  5226. u8 cos;
  5227. unsigned long q_type = 0;
  5228. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  5229. fp->rx_queue = fp_idx;
  5230. fp->cid = fp_idx;
  5231. fp->cl_id = bnx2x_fp_cl_id(fp);
  5232. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  5233. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  5234. /* qZone id equals to FW (per path) client id */
  5235. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  5236. /* init shortcut */
  5237. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  5238. /* Setup SB indices */
  5239. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  5240. /* Configure Queue State object */
  5241. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5242. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5243. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  5244. /* init tx data */
  5245. for_each_cos_in_tx_queue(fp, cos) {
  5246. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  5247. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  5248. FP_COS_TO_TXQ(fp, cos, bp),
  5249. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  5250. cids[cos] = fp->txdata_ptr[cos]->cid;
  5251. }
  5252. /* nothing more for vf to do here */
  5253. if (IS_VF(bp))
  5254. return;
  5255. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  5256. fp->fw_sb_id, fp->igu_sb_id);
  5257. bnx2x_update_fpsb_idx(fp);
  5258. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  5259. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5260. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5261. /**
  5262. * Configure classification DBs: Always enable Tx switching
  5263. */
  5264. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  5265. DP(NETIF_MSG_IFUP,
  5266. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5267. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5268. fp->igu_sb_id);
  5269. }
  5270. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  5271. {
  5272. int i;
  5273. for (i = 1; i <= NUM_TX_RINGS; i++) {
  5274. struct eth_tx_next_bd *tx_next_bd =
  5275. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  5276. tx_next_bd->addr_hi =
  5277. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  5278. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5279. tx_next_bd->addr_lo =
  5280. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  5281. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5282. }
  5283. *txdata->tx_cons_sb = cpu_to_le16(0);
  5284. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  5285. txdata->tx_db.data.zero_fill1 = 0;
  5286. txdata->tx_db.data.prod = 0;
  5287. txdata->tx_pkt_prod = 0;
  5288. txdata->tx_pkt_cons = 0;
  5289. txdata->tx_bd_prod = 0;
  5290. txdata->tx_bd_cons = 0;
  5291. txdata->tx_pkt = 0;
  5292. }
  5293. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  5294. {
  5295. int i;
  5296. for_each_tx_queue_cnic(bp, i)
  5297. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  5298. }
  5299. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  5300. {
  5301. int i;
  5302. u8 cos;
  5303. for_each_eth_queue(bp, i)
  5304. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  5305. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  5306. }
  5307. static void bnx2x_init_fcoe_fp(struct bnx2x *bp)
  5308. {
  5309. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  5310. unsigned long q_type = 0;
  5311. bnx2x_fcoe(bp, rx_queue) = BNX2X_NUM_ETH_QUEUES(bp);
  5312. bnx2x_fcoe(bp, cl_id) = bnx2x_cnic_eth_cl_id(bp,
  5313. BNX2X_FCOE_ETH_CL_ID_IDX);
  5314. bnx2x_fcoe(bp, cid) = BNX2X_FCOE_ETH_CID(bp);
  5315. bnx2x_fcoe(bp, fw_sb_id) = DEF_SB_ID;
  5316. bnx2x_fcoe(bp, igu_sb_id) = bp->igu_dsb_id;
  5317. bnx2x_fcoe(bp, rx_cons_sb) = BNX2X_FCOE_L2_RX_INDEX;
  5318. bnx2x_init_txdata(bp, bnx2x_fcoe(bp, txdata_ptr[0]),
  5319. fp->cid, FCOE_TXQ_IDX(bp), BNX2X_FCOE_L2_TX_INDEX,
  5320. fp);
  5321. DP(NETIF_MSG_IFUP, "created fcoe tx data (fp index %d)\n", fp->index);
  5322. /* qZone id equals to FW (per path) client id */
  5323. bnx2x_fcoe(bp, cl_qzone_id) = bnx2x_fp_qzone_id(fp);
  5324. /* init shortcut */
  5325. bnx2x_fcoe(bp, ustorm_rx_prods_offset) =
  5326. bnx2x_rx_ustorm_prods_offset(fp);
  5327. /* Configure Queue State object */
  5328. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5329. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5330. /* No multi-CoS for FCoE L2 client */
  5331. BUG_ON(fp->max_cos != 1);
  5332. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id,
  5333. &fp->cid, 1, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5334. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5335. DP(NETIF_MSG_IFUP,
  5336. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5337. fp->index, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5338. fp->igu_sb_id);
  5339. }
  5340. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  5341. {
  5342. if (!NO_FCOE(bp))
  5343. bnx2x_init_fcoe_fp(bp);
  5344. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  5345. BNX2X_VF_ID_INVALID, false,
  5346. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  5347. /* ensure status block indices were read */
  5348. rmb();
  5349. bnx2x_init_rx_rings_cnic(bp);
  5350. bnx2x_init_tx_rings_cnic(bp);
  5351. /* flush all */
  5352. mb();
  5353. mmiowb();
  5354. }
  5355. void bnx2x_pre_irq_nic_init(struct bnx2x *bp)
  5356. {
  5357. int i;
  5358. /* Setup NIC internals and enable interrupts */
  5359. for_each_eth_queue(bp, i)
  5360. bnx2x_init_eth_fp(bp, i);
  5361. /* ensure status block indices were read */
  5362. rmb();
  5363. bnx2x_init_rx_rings(bp);
  5364. bnx2x_init_tx_rings(bp);
  5365. if (IS_PF(bp)) {
  5366. /* Initialize MOD_ABS interrupts */
  5367. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  5368. bp->common.shmem_base,
  5369. bp->common.shmem2_base, BP_PORT(bp));
  5370. /* initialize the default status block and sp ring */
  5371. bnx2x_init_def_sb(bp);
  5372. bnx2x_update_dsb_idx(bp);
  5373. bnx2x_init_sp_ring(bp);
  5374. } else {
  5375. bnx2x_memset_stats(bp);
  5376. }
  5377. }
  5378. void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code)
  5379. {
  5380. bnx2x_init_eq_ring(bp);
  5381. bnx2x_init_internal(bp, load_code);
  5382. bnx2x_pf_init(bp);
  5383. bnx2x_stats_init(bp);
  5384. /* flush all before enabling interrupts */
  5385. mb();
  5386. mmiowb();
  5387. bnx2x_int_enable(bp);
  5388. /* Check for SPIO5 */
  5389. bnx2x_attn_int_deasserted0(bp,
  5390. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  5391. AEU_INPUTS_ATTN_BITS_SPIO5);
  5392. }
  5393. /* gzip service functions */
  5394. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5395. {
  5396. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5397. &bp->gunzip_mapping, GFP_KERNEL);
  5398. if (bp->gunzip_buf == NULL)
  5399. goto gunzip_nomem1;
  5400. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5401. if (bp->strm == NULL)
  5402. goto gunzip_nomem2;
  5403. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5404. if (bp->strm->workspace == NULL)
  5405. goto gunzip_nomem3;
  5406. return 0;
  5407. gunzip_nomem3:
  5408. kfree(bp->strm);
  5409. bp->strm = NULL;
  5410. gunzip_nomem2:
  5411. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5412. bp->gunzip_mapping);
  5413. bp->gunzip_buf = NULL;
  5414. gunzip_nomem1:
  5415. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5416. return -ENOMEM;
  5417. }
  5418. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5419. {
  5420. if (bp->strm) {
  5421. vfree(bp->strm->workspace);
  5422. kfree(bp->strm);
  5423. bp->strm = NULL;
  5424. }
  5425. if (bp->gunzip_buf) {
  5426. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5427. bp->gunzip_mapping);
  5428. bp->gunzip_buf = NULL;
  5429. }
  5430. }
  5431. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5432. {
  5433. int n, rc;
  5434. /* check gzip header */
  5435. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5436. BNX2X_ERR("Bad gzip header\n");
  5437. return -EINVAL;
  5438. }
  5439. n = 10;
  5440. #define FNAME 0x8
  5441. if (zbuf[3] & FNAME)
  5442. while ((zbuf[n++] != 0) && (n < len));
  5443. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5444. bp->strm->avail_in = len - n;
  5445. bp->strm->next_out = bp->gunzip_buf;
  5446. bp->strm->avail_out = FW_BUF_SIZE;
  5447. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5448. if (rc != Z_OK)
  5449. return rc;
  5450. rc = zlib_inflate(bp->strm, Z_FINISH);
  5451. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5452. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5453. bp->strm->msg);
  5454. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5455. if (bp->gunzip_outlen & 0x3)
  5456. netdev_err(bp->dev,
  5457. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5458. bp->gunzip_outlen);
  5459. bp->gunzip_outlen >>= 2;
  5460. zlib_inflateEnd(bp->strm);
  5461. if (rc == Z_STREAM_END)
  5462. return 0;
  5463. return rc;
  5464. }
  5465. /* nic load/unload */
  5466. /*
  5467. * General service functions
  5468. */
  5469. /* send a NIG loopback debug packet */
  5470. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5471. {
  5472. u32 wb_write[3];
  5473. /* Ethernet source and destination addresses */
  5474. wb_write[0] = 0x55555555;
  5475. wb_write[1] = 0x55555555;
  5476. wb_write[2] = 0x20; /* SOP */
  5477. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5478. /* NON-IP protocol */
  5479. wb_write[0] = 0x09000000;
  5480. wb_write[1] = 0x55555555;
  5481. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5482. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5483. }
  5484. /* some of the internal memories
  5485. * are not directly readable from the driver
  5486. * to test them we send debug packets
  5487. */
  5488. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5489. {
  5490. int factor;
  5491. int count, i;
  5492. u32 val = 0;
  5493. if (CHIP_REV_IS_FPGA(bp))
  5494. factor = 120;
  5495. else if (CHIP_REV_IS_EMUL(bp))
  5496. factor = 200;
  5497. else
  5498. factor = 1;
  5499. /* Disable inputs of parser neighbor blocks */
  5500. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5501. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5502. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5503. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5504. /* Write 0 to parser credits for CFC search request */
  5505. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5506. /* send Ethernet packet */
  5507. bnx2x_lb_pckt(bp);
  5508. /* TODO do i reset NIG statistic? */
  5509. /* Wait until NIG register shows 1 packet of size 0x10 */
  5510. count = 1000 * factor;
  5511. while (count) {
  5512. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5513. val = *bnx2x_sp(bp, wb_data[0]);
  5514. if (val == 0x10)
  5515. break;
  5516. usleep_range(10000, 20000);
  5517. count--;
  5518. }
  5519. if (val != 0x10) {
  5520. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5521. return -1;
  5522. }
  5523. /* Wait until PRS register shows 1 packet */
  5524. count = 1000 * factor;
  5525. while (count) {
  5526. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5527. if (val == 1)
  5528. break;
  5529. usleep_range(10000, 20000);
  5530. count--;
  5531. }
  5532. if (val != 0x1) {
  5533. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5534. return -2;
  5535. }
  5536. /* Reset and init BRB, PRS */
  5537. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5538. msleep(50);
  5539. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5540. msleep(50);
  5541. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5542. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5543. DP(NETIF_MSG_HW, "part2\n");
  5544. /* Disable inputs of parser neighbor blocks */
  5545. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5546. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5547. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5548. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5549. /* Write 0 to parser credits for CFC search request */
  5550. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5551. /* send 10 Ethernet packets */
  5552. for (i = 0; i < 10; i++)
  5553. bnx2x_lb_pckt(bp);
  5554. /* Wait until NIG register shows 10 + 1
  5555. packets of size 11*0x10 = 0xb0 */
  5556. count = 1000 * factor;
  5557. while (count) {
  5558. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5559. val = *bnx2x_sp(bp, wb_data[0]);
  5560. if (val == 0xb0)
  5561. break;
  5562. usleep_range(10000, 20000);
  5563. count--;
  5564. }
  5565. if (val != 0xb0) {
  5566. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5567. return -3;
  5568. }
  5569. /* Wait until PRS register shows 2 packets */
  5570. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5571. if (val != 2)
  5572. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5573. /* Write 1 to parser credits for CFC search request */
  5574. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5575. /* Wait until PRS register shows 3 packets */
  5576. msleep(10 * factor);
  5577. /* Wait until NIG register shows 1 packet of size 0x10 */
  5578. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5579. if (val != 3)
  5580. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5581. /* clear NIG EOP FIFO */
  5582. for (i = 0; i < 11; i++)
  5583. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5584. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5585. if (val != 1) {
  5586. BNX2X_ERR("clear of NIG failed\n");
  5587. return -4;
  5588. }
  5589. /* Reset and init BRB, PRS, NIG */
  5590. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5591. msleep(50);
  5592. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5593. msleep(50);
  5594. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5595. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5596. if (!CNIC_SUPPORT(bp))
  5597. /* set NIC mode */
  5598. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5599. /* Enable inputs of parser neighbor blocks */
  5600. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5601. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5602. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5603. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5604. DP(NETIF_MSG_HW, "done\n");
  5605. return 0; /* OK */
  5606. }
  5607. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5608. {
  5609. u32 val;
  5610. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5611. if (!CHIP_IS_E1x(bp))
  5612. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5613. else
  5614. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5615. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5616. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5617. /*
  5618. * mask read length error interrupts in brb for parser
  5619. * (parsing unit and 'checksum and crc' unit)
  5620. * these errors are legal (PU reads fixed length and CAC can cause
  5621. * read length error on truncated packets)
  5622. */
  5623. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5624. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5625. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5626. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5627. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5628. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5629. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5630. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5631. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5632. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5633. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5634. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5635. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5636. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5637. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5638. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5639. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5640. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5641. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5642. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5643. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5644. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5645. if (!CHIP_IS_E1x(bp))
  5646. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5647. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5648. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5649. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5650. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5651. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5652. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5653. if (!CHIP_IS_E1x(bp))
  5654. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5655. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5656. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5657. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5658. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5659. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5660. }
  5661. static void bnx2x_reset_common(struct bnx2x *bp)
  5662. {
  5663. u32 val = 0x1400;
  5664. /* reset_common */
  5665. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5666. 0xd3ffff7f);
  5667. if (CHIP_IS_E3(bp)) {
  5668. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5669. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5670. }
  5671. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5672. }
  5673. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5674. {
  5675. bp->dmae_ready = 0;
  5676. spin_lock_init(&bp->dmae_lock);
  5677. }
  5678. static void bnx2x_init_pxp(struct bnx2x *bp)
  5679. {
  5680. u16 devctl;
  5681. int r_order, w_order;
  5682. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5683. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5684. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5685. if (bp->mrrs == -1)
  5686. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5687. else {
  5688. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5689. r_order = bp->mrrs;
  5690. }
  5691. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5692. }
  5693. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5694. {
  5695. int is_required;
  5696. u32 val;
  5697. int port;
  5698. if (BP_NOMCP(bp))
  5699. return;
  5700. is_required = 0;
  5701. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5702. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5703. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5704. is_required = 1;
  5705. /*
  5706. * The fan failure mechanism is usually related to the PHY type since
  5707. * the power consumption of the board is affected by the PHY. Currently,
  5708. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5709. */
  5710. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5711. for (port = PORT_0; port < PORT_MAX; port++) {
  5712. is_required |=
  5713. bnx2x_fan_failure_det_req(
  5714. bp,
  5715. bp->common.shmem_base,
  5716. bp->common.shmem2_base,
  5717. port);
  5718. }
  5719. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5720. if (is_required == 0)
  5721. return;
  5722. /* Fan failure is indicated by SPIO 5 */
  5723. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5724. /* set to active low mode */
  5725. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5726. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5727. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5728. /* enable interrupt to signal the IGU */
  5729. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5730. val |= MISC_SPIO_SPIO5;
  5731. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5732. }
  5733. void bnx2x_pf_disable(struct bnx2x *bp)
  5734. {
  5735. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5736. val &= ~IGU_PF_CONF_FUNC_EN;
  5737. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5738. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5739. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5740. }
  5741. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5742. {
  5743. u32 shmem_base[2], shmem2_base[2];
  5744. /* Avoid common init in case MFW supports LFA */
  5745. if (SHMEM2_RD(bp, size) >
  5746. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5747. return;
  5748. shmem_base[0] = bp->common.shmem_base;
  5749. shmem2_base[0] = bp->common.shmem2_base;
  5750. if (!CHIP_IS_E1x(bp)) {
  5751. shmem_base[1] =
  5752. SHMEM2_RD(bp, other_shmem_base_addr);
  5753. shmem2_base[1] =
  5754. SHMEM2_RD(bp, other_shmem2_base_addr);
  5755. }
  5756. bnx2x_acquire_phy_lock(bp);
  5757. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5758. bp->common.chip_id);
  5759. bnx2x_release_phy_lock(bp);
  5760. }
  5761. static void bnx2x_config_endianity(struct bnx2x *bp, u32 val)
  5762. {
  5763. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, val);
  5764. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, val);
  5765. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, val);
  5766. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, val);
  5767. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, val);
  5768. /* make sure this value is 0 */
  5769. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5770. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, val);
  5771. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, val);
  5772. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, val);
  5773. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, val);
  5774. }
  5775. static void bnx2x_set_endianity(struct bnx2x *bp)
  5776. {
  5777. #ifdef __BIG_ENDIAN
  5778. bnx2x_config_endianity(bp, 1);
  5779. #else
  5780. bnx2x_config_endianity(bp, 0);
  5781. #endif
  5782. }
  5783. static void bnx2x_reset_endianity(struct bnx2x *bp)
  5784. {
  5785. bnx2x_config_endianity(bp, 0);
  5786. }
  5787. /**
  5788. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5789. *
  5790. * @bp: driver handle
  5791. */
  5792. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5793. {
  5794. u32 val;
  5795. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5796. /*
  5797. * take the RESET lock to protect undi_unload flow from accessing
  5798. * registers while we're resetting the chip
  5799. */
  5800. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5801. bnx2x_reset_common(bp);
  5802. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5803. val = 0xfffc;
  5804. if (CHIP_IS_E3(bp)) {
  5805. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5806. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5807. }
  5808. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5809. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5810. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5811. if (!CHIP_IS_E1x(bp)) {
  5812. u8 abs_func_id;
  5813. /**
  5814. * 4-port mode or 2-port mode we need to turn of master-enable
  5815. * for everyone, after that, turn it back on for self.
  5816. * so, we disregard multi-function or not, and always disable
  5817. * for all functions on the given path, this means 0,2,4,6 for
  5818. * path 0 and 1,3,5,7 for path 1
  5819. */
  5820. for (abs_func_id = BP_PATH(bp);
  5821. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5822. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5823. REG_WR(bp,
  5824. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5825. 1);
  5826. continue;
  5827. }
  5828. bnx2x_pretend_func(bp, abs_func_id);
  5829. /* clear pf enable */
  5830. bnx2x_pf_disable(bp);
  5831. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5832. }
  5833. }
  5834. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5835. if (CHIP_IS_E1(bp)) {
  5836. /* enable HW interrupt from PXP on USDM overflow
  5837. bit 16 on INT_MASK_0 */
  5838. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5839. }
  5840. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5841. bnx2x_init_pxp(bp);
  5842. bnx2x_set_endianity(bp);
  5843. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5844. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5845. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5846. /* let the HW do it's magic ... */
  5847. msleep(100);
  5848. /* finish PXP init */
  5849. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5850. if (val != 1) {
  5851. BNX2X_ERR("PXP2 CFG failed\n");
  5852. return -EBUSY;
  5853. }
  5854. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5855. if (val != 1) {
  5856. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5857. return -EBUSY;
  5858. }
  5859. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5860. * have entries with value "0" and valid bit on.
  5861. * This needs to be done by the first PF that is loaded in a path
  5862. * (i.e. common phase)
  5863. */
  5864. if (!CHIP_IS_E1x(bp)) {
  5865. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5866. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5867. * This occurs when a different function (func2,3) is being marked
  5868. * as "scan-off". Real-life scenario for example: if a driver is being
  5869. * load-unloaded while func6,7 are down. This will cause the timer to access
  5870. * the ilt, translate to a logical address and send a request to read/write.
  5871. * Since the ilt for the function that is down is not valid, this will cause
  5872. * a translation error which is unrecoverable.
  5873. * The Workaround is intended to make sure that when this happens nothing fatal
  5874. * will occur. The workaround:
  5875. * 1. First PF driver which loads on a path will:
  5876. * a. After taking the chip out of reset, by using pretend,
  5877. * it will write "0" to the following registers of
  5878. * the other vnics.
  5879. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5880. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5881. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5882. * And for itself it will write '1' to
  5883. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5884. * dmae-operations (writing to pram for example.)
  5885. * note: can be done for only function 6,7 but cleaner this
  5886. * way.
  5887. * b. Write zero+valid to the entire ILT.
  5888. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5889. * VNIC3 (of that port). The range allocated will be the
  5890. * entire ILT. This is needed to prevent ILT range error.
  5891. * 2. Any PF driver load flow:
  5892. * a. ILT update with the physical addresses of the allocated
  5893. * logical pages.
  5894. * b. Wait 20msec. - note that this timeout is needed to make
  5895. * sure there are no requests in one of the PXP internal
  5896. * queues with "old" ILT addresses.
  5897. * c. PF enable in the PGLC.
  5898. * d. Clear the was_error of the PF in the PGLC. (could have
  5899. * occurred while driver was down)
  5900. * e. PF enable in the CFC (WEAK + STRONG)
  5901. * f. Timers scan enable
  5902. * 3. PF driver unload flow:
  5903. * a. Clear the Timers scan_en.
  5904. * b. Polling for scan_on=0 for that PF.
  5905. * c. Clear the PF enable bit in the PXP.
  5906. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5907. * e. Write zero+valid to all ILT entries (The valid bit must
  5908. * stay set)
  5909. * f. If this is VNIC 3 of a port then also init
  5910. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5911. * to the last entry in the ILT.
  5912. *
  5913. * Notes:
  5914. * Currently the PF error in the PGLC is non recoverable.
  5915. * In the future the there will be a recovery routine for this error.
  5916. * Currently attention is masked.
  5917. * Having an MCP lock on the load/unload process does not guarantee that
  5918. * there is no Timer disable during Func6/7 enable. This is because the
  5919. * Timers scan is currently being cleared by the MCP on FLR.
  5920. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5921. * there is error before clearing it. But the flow above is simpler and
  5922. * more general.
  5923. * All ILT entries are written by zero+valid and not just PF6/7
  5924. * ILT entries since in the future the ILT entries allocation for
  5925. * PF-s might be dynamic.
  5926. */
  5927. struct ilt_client_info ilt_cli;
  5928. struct bnx2x_ilt ilt;
  5929. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5930. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5931. /* initialize dummy TM client */
  5932. ilt_cli.start = 0;
  5933. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5934. ilt_cli.client_num = ILT_CLIENT_TM;
  5935. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5936. * Step 2: set the timers first/last ilt entry to point
  5937. * to the entire range to prevent ILT range error for 3rd/4th
  5938. * vnic (this code assumes existence of the vnic)
  5939. *
  5940. * both steps performed by call to bnx2x_ilt_client_init_op()
  5941. * with dummy TM client
  5942. *
  5943. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5944. * and his brother are split registers
  5945. */
  5946. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5947. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5948. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5949. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5950. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5951. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5952. }
  5953. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5954. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5955. if (!CHIP_IS_E1x(bp)) {
  5956. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5957. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5958. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5959. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5960. /* let the HW do it's magic ... */
  5961. do {
  5962. msleep(200);
  5963. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5964. } while (factor-- && (val != 1));
  5965. if (val != 1) {
  5966. BNX2X_ERR("ATC_INIT failed\n");
  5967. return -EBUSY;
  5968. }
  5969. }
  5970. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5971. bnx2x_iov_init_dmae(bp);
  5972. /* clean the DMAE memory */
  5973. bp->dmae_ready = 1;
  5974. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5975. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5976. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5977. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5978. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5979. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5980. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5981. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5982. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5983. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5984. /* QM queues pointers table */
  5985. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5986. /* soft reset pulse */
  5987. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5988. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5989. if (CNIC_SUPPORT(bp))
  5990. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5991. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5992. if (!CHIP_REV_IS_SLOW(bp))
  5993. /* enable hw interrupt from doorbell Q */
  5994. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5995. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5996. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5997. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5998. if (!CHIP_IS_E1(bp))
  5999. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  6000. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  6001. if (IS_MF_AFEX(bp)) {
  6002. /* configure that VNTag and VLAN headers must be
  6003. * received in afex mode
  6004. */
  6005. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  6006. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  6007. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  6008. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  6009. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  6010. } else {
  6011. /* Bit-map indicating which L2 hdrs may appear
  6012. * after the basic Ethernet header
  6013. */
  6014. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  6015. bp->path_has_ovlan ? 7 : 6);
  6016. }
  6017. }
  6018. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  6019. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  6020. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  6021. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  6022. if (!CHIP_IS_E1x(bp)) {
  6023. /* reset VFC memories */
  6024. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  6025. VFC_MEMORIES_RST_REG_CAM_RST |
  6026. VFC_MEMORIES_RST_REG_RAM_RST);
  6027. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  6028. VFC_MEMORIES_RST_REG_CAM_RST |
  6029. VFC_MEMORIES_RST_REG_RAM_RST);
  6030. msleep(20);
  6031. }
  6032. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  6033. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  6034. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  6035. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  6036. /* sync semi rtc */
  6037. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  6038. 0x80000000);
  6039. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  6040. 0x80000000);
  6041. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  6042. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  6043. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  6044. if (!CHIP_IS_E1x(bp)) {
  6045. if (IS_MF_AFEX(bp)) {
  6046. /* configure that VNTag and VLAN headers must be
  6047. * sent in afex mode
  6048. */
  6049. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  6050. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  6051. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  6052. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  6053. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  6054. } else {
  6055. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  6056. bp->path_has_ovlan ? 7 : 6);
  6057. }
  6058. }
  6059. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  6060. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  6061. if (CNIC_SUPPORT(bp)) {
  6062. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  6063. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  6064. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  6065. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  6066. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  6067. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  6068. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  6069. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  6070. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  6071. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  6072. }
  6073. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  6074. if (sizeof(union cdu_context) != 1024)
  6075. /* we currently assume that a context is 1024 bytes */
  6076. dev_alert(&bp->pdev->dev,
  6077. "please adjust the size of cdu_context(%ld)\n",
  6078. (long)sizeof(union cdu_context));
  6079. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  6080. val = (4 << 24) + (0 << 12) + 1024;
  6081. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  6082. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  6083. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  6084. /* enable context validation interrupt from CFC */
  6085. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  6086. /* set the thresholds to prevent CFC/CDU race */
  6087. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  6088. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  6089. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  6090. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  6091. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  6092. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  6093. /* Reset PCIE errors for debug */
  6094. REG_WR(bp, 0x2814, 0xffffffff);
  6095. REG_WR(bp, 0x3820, 0xffffffff);
  6096. if (!CHIP_IS_E1x(bp)) {
  6097. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  6098. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  6099. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  6100. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  6101. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  6102. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  6103. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  6104. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  6105. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  6106. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  6107. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  6108. }
  6109. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  6110. if (!CHIP_IS_E1(bp)) {
  6111. /* in E3 this done in per-port section */
  6112. if (!CHIP_IS_E3(bp))
  6113. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6114. }
  6115. if (CHIP_IS_E1H(bp))
  6116. /* not applicable for E2 (and above ...) */
  6117. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  6118. if (CHIP_REV_IS_SLOW(bp))
  6119. msleep(200);
  6120. /* finish CFC init */
  6121. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  6122. if (val != 1) {
  6123. BNX2X_ERR("CFC LL_INIT failed\n");
  6124. return -EBUSY;
  6125. }
  6126. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  6127. if (val != 1) {
  6128. BNX2X_ERR("CFC AC_INIT failed\n");
  6129. return -EBUSY;
  6130. }
  6131. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  6132. if (val != 1) {
  6133. BNX2X_ERR("CFC CAM_INIT failed\n");
  6134. return -EBUSY;
  6135. }
  6136. REG_WR(bp, CFC_REG_DEBUG0, 0);
  6137. if (CHIP_IS_E1(bp)) {
  6138. /* read NIG statistic
  6139. to see if this is our first up since powerup */
  6140. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  6141. val = *bnx2x_sp(bp, wb_data[0]);
  6142. /* do internal memory self test */
  6143. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  6144. BNX2X_ERR("internal mem self test failed\n");
  6145. return -EBUSY;
  6146. }
  6147. }
  6148. bnx2x_setup_fan_failure_detection(bp);
  6149. /* clear PXP2 attentions */
  6150. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  6151. bnx2x_enable_blocks_attention(bp);
  6152. bnx2x_enable_blocks_parity(bp);
  6153. if (!BP_NOMCP(bp)) {
  6154. if (CHIP_IS_E1x(bp))
  6155. bnx2x__common_init_phy(bp);
  6156. } else
  6157. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  6158. return 0;
  6159. }
  6160. /**
  6161. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  6162. *
  6163. * @bp: driver handle
  6164. */
  6165. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  6166. {
  6167. int rc = bnx2x_init_hw_common(bp);
  6168. if (rc)
  6169. return rc;
  6170. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  6171. if (!BP_NOMCP(bp))
  6172. bnx2x__common_init_phy(bp);
  6173. return 0;
  6174. }
  6175. static int bnx2x_init_hw_port(struct bnx2x *bp)
  6176. {
  6177. int port = BP_PORT(bp);
  6178. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  6179. u32 low, high;
  6180. u32 val, reg;
  6181. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  6182. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6183. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6184. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6185. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6186. /* Timers bug workaround: disables the pf_master bit in pglue at
  6187. * common phase, we need to enable it here before any dmae access are
  6188. * attempted. Therefore we manually added the enable-master to the
  6189. * port phase (it also happens in the function phase)
  6190. */
  6191. if (!CHIP_IS_E1x(bp))
  6192. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6193. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6194. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6195. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6196. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6197. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6198. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6199. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6200. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6201. /* QM cid (connection) count */
  6202. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  6203. if (CNIC_SUPPORT(bp)) {
  6204. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6205. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  6206. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  6207. }
  6208. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6209. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6210. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  6211. if (IS_MF(bp))
  6212. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  6213. else if (bp->dev->mtu > 4096) {
  6214. if (bp->flags & ONE_PORT_FLAG)
  6215. low = 160;
  6216. else {
  6217. val = bp->dev->mtu;
  6218. /* (24*1024 + val*4)/256 */
  6219. low = 96 + (val/64) +
  6220. ((val % 64) ? 1 : 0);
  6221. }
  6222. } else
  6223. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  6224. high = low + 56; /* 14*1024/256 */
  6225. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  6226. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  6227. }
  6228. if (CHIP_MODE_IS_4_PORT(bp))
  6229. REG_WR(bp, (BP_PORT(bp) ?
  6230. BRB1_REG_MAC_GUARANTIED_1 :
  6231. BRB1_REG_MAC_GUARANTIED_0), 40);
  6232. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6233. if (CHIP_IS_E3B0(bp)) {
  6234. if (IS_MF_AFEX(bp)) {
  6235. /* configure headers for AFEX mode */
  6236. REG_WR(bp, BP_PORT(bp) ?
  6237. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6238. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  6239. REG_WR(bp, BP_PORT(bp) ?
  6240. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  6241. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  6242. REG_WR(bp, BP_PORT(bp) ?
  6243. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  6244. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  6245. } else {
  6246. /* Ovlan exists only if we are in multi-function +
  6247. * switch-dependent mode, in switch-independent there
  6248. * is no ovlan headers
  6249. */
  6250. REG_WR(bp, BP_PORT(bp) ?
  6251. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6252. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  6253. (bp->path_has_ovlan ? 7 : 6));
  6254. }
  6255. }
  6256. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6257. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6258. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6259. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6260. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6261. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6262. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6263. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6264. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6265. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6266. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6267. if (CHIP_IS_E1x(bp)) {
  6268. /* configure PBF to work without PAUSE mtu 9000 */
  6269. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  6270. /* update threshold */
  6271. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  6272. /* update init credit */
  6273. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  6274. /* probe changes */
  6275. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  6276. udelay(50);
  6277. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  6278. }
  6279. if (CNIC_SUPPORT(bp))
  6280. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6281. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6282. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6283. if (CHIP_IS_E1(bp)) {
  6284. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6285. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6286. }
  6287. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6288. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6289. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6290. /* init aeu_mask_attn_func_0/1:
  6291. * - SF mode: bits 3-7 are masked. Only bits 0-2 are in use
  6292. * - MF mode: bit 3 is masked. Bits 0-2 are in use as in SF
  6293. * bits 4-7 are used for "per vn group attention" */
  6294. val = IS_MF(bp) ? 0xF7 : 0x7;
  6295. /* Enable DCBX attention for all but E1 */
  6296. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  6297. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  6298. /* SCPAD_PARITY should NOT trigger close the gates */
  6299. reg = port ? MISC_REG_AEU_ENABLE4_NIG_1 : MISC_REG_AEU_ENABLE4_NIG_0;
  6300. REG_WR(bp, reg,
  6301. REG_RD(bp, reg) &
  6302. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6303. reg = port ? MISC_REG_AEU_ENABLE4_PXP_1 : MISC_REG_AEU_ENABLE4_PXP_0;
  6304. REG_WR(bp, reg,
  6305. REG_RD(bp, reg) &
  6306. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6307. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6308. if (!CHIP_IS_E1x(bp)) {
  6309. /* Bit-map indicating which L2 hdrs may appear after the
  6310. * basic Ethernet header
  6311. */
  6312. if (IS_MF_AFEX(bp))
  6313. REG_WR(bp, BP_PORT(bp) ?
  6314. NIG_REG_P1_HDRS_AFTER_BASIC :
  6315. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  6316. else
  6317. REG_WR(bp, BP_PORT(bp) ?
  6318. NIG_REG_P1_HDRS_AFTER_BASIC :
  6319. NIG_REG_P0_HDRS_AFTER_BASIC,
  6320. IS_MF_SD(bp) ? 7 : 6);
  6321. if (CHIP_IS_E3(bp))
  6322. REG_WR(bp, BP_PORT(bp) ?
  6323. NIG_REG_LLH1_MF_MODE :
  6324. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6325. }
  6326. if (!CHIP_IS_E3(bp))
  6327. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  6328. if (!CHIP_IS_E1(bp)) {
  6329. /* 0x2 disable mf_ov, 0x1 enable */
  6330. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  6331. (IS_MF_SD(bp) ? 0x1 : 0x2));
  6332. if (!CHIP_IS_E1x(bp)) {
  6333. val = 0;
  6334. switch (bp->mf_mode) {
  6335. case MULTI_FUNCTION_SD:
  6336. val = 1;
  6337. break;
  6338. case MULTI_FUNCTION_SI:
  6339. case MULTI_FUNCTION_AFEX:
  6340. val = 2;
  6341. break;
  6342. }
  6343. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  6344. NIG_REG_LLH0_CLS_TYPE), val);
  6345. }
  6346. {
  6347. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  6348. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  6349. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  6350. }
  6351. }
  6352. /* If SPIO5 is set to generate interrupts, enable it for this port */
  6353. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  6354. if (val & MISC_SPIO_SPIO5) {
  6355. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  6356. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  6357. val = REG_RD(bp, reg_addr);
  6358. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  6359. REG_WR(bp, reg_addr, val);
  6360. }
  6361. return 0;
  6362. }
  6363. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  6364. {
  6365. int reg;
  6366. u32 wb_write[2];
  6367. if (CHIP_IS_E1(bp))
  6368. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  6369. else
  6370. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  6371. wb_write[0] = ONCHIP_ADDR1(addr);
  6372. wb_write[1] = ONCHIP_ADDR2(addr);
  6373. REG_WR_DMAE(bp, reg, wb_write, 2);
  6374. }
  6375. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  6376. {
  6377. u32 data, ctl, cnt = 100;
  6378. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  6379. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  6380. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  6381. u32 sb_bit = 1 << (idu_sb_id%32);
  6382. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  6383. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  6384. /* Not supported in BC mode */
  6385. if (CHIP_INT_MODE_IS_BC(bp))
  6386. return;
  6387. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  6388. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  6389. IGU_REGULAR_CLEANUP_SET |
  6390. IGU_REGULAR_BCLEANUP;
  6391. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  6392. func_encode << IGU_CTRL_REG_FID_SHIFT |
  6393. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  6394. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6395. data, igu_addr_data);
  6396. REG_WR(bp, igu_addr_data, data);
  6397. mmiowb();
  6398. barrier();
  6399. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6400. ctl, igu_addr_ctl);
  6401. REG_WR(bp, igu_addr_ctl, ctl);
  6402. mmiowb();
  6403. barrier();
  6404. /* wait for clean up to finish */
  6405. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  6406. msleep(20);
  6407. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  6408. DP(NETIF_MSG_HW,
  6409. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  6410. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  6411. }
  6412. }
  6413. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  6414. {
  6415. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6416. }
  6417. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6418. {
  6419. u32 i, base = FUNC_ILT_BASE(func);
  6420. for (i = base; i < base + ILT_PER_FUNC; i++)
  6421. bnx2x_ilt_wr(bp, i, 0);
  6422. }
  6423. static void bnx2x_init_searcher(struct bnx2x *bp)
  6424. {
  6425. int port = BP_PORT(bp);
  6426. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6427. /* T1 hash bits value determines the T1 number of entries */
  6428. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6429. }
  6430. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6431. {
  6432. int rc;
  6433. struct bnx2x_func_state_params func_params = {NULL};
  6434. struct bnx2x_func_switch_update_params *switch_update_params =
  6435. &func_params.params.switch_update;
  6436. /* Prepare parameters for function state transitions */
  6437. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6438. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6439. func_params.f_obj = &bp->func_obj;
  6440. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6441. /* Function parameters */
  6442. switch_update_params->suspend = suspend;
  6443. rc = bnx2x_func_state_change(bp, &func_params);
  6444. return rc;
  6445. }
  6446. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6447. {
  6448. int rc, i, port = BP_PORT(bp);
  6449. int vlan_en = 0, mac_en[NUM_MACS];
  6450. /* Close input from network */
  6451. if (bp->mf_mode == SINGLE_FUNCTION) {
  6452. bnx2x_set_rx_filter(&bp->link_params, 0);
  6453. } else {
  6454. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6455. NIG_REG_LLH0_FUNC_EN);
  6456. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6457. NIG_REG_LLH0_FUNC_EN, 0);
  6458. for (i = 0; i < NUM_MACS; i++) {
  6459. mac_en[i] = REG_RD(bp, port ?
  6460. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6461. 4 * i) :
  6462. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6463. 4 * i));
  6464. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6465. 4 * i) :
  6466. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6467. }
  6468. }
  6469. /* Close BMC to host */
  6470. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6471. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6472. /* Suspend Tx switching to the PF. Completion of this ramrod
  6473. * further guarantees that all the packets of that PF / child
  6474. * VFs in BRB were processed by the Parser, so it is safe to
  6475. * change the NIC_MODE register.
  6476. */
  6477. rc = bnx2x_func_switch_update(bp, 1);
  6478. if (rc) {
  6479. BNX2X_ERR("Can't suspend tx-switching!\n");
  6480. return rc;
  6481. }
  6482. /* Change NIC_MODE register */
  6483. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6484. /* Open input from network */
  6485. if (bp->mf_mode == SINGLE_FUNCTION) {
  6486. bnx2x_set_rx_filter(&bp->link_params, 1);
  6487. } else {
  6488. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6489. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6490. for (i = 0; i < NUM_MACS; i++) {
  6491. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6492. 4 * i) :
  6493. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6494. mac_en[i]);
  6495. }
  6496. }
  6497. /* Enable BMC to host */
  6498. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6499. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6500. /* Resume Tx switching to the PF */
  6501. rc = bnx2x_func_switch_update(bp, 0);
  6502. if (rc) {
  6503. BNX2X_ERR("Can't resume tx-switching!\n");
  6504. return rc;
  6505. }
  6506. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6507. return 0;
  6508. }
  6509. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6510. {
  6511. int rc;
  6512. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6513. if (CONFIGURE_NIC_MODE(bp)) {
  6514. /* Configure searcher as part of function hw init */
  6515. bnx2x_init_searcher(bp);
  6516. /* Reset NIC mode */
  6517. rc = bnx2x_reset_nic_mode(bp);
  6518. if (rc)
  6519. BNX2X_ERR("Can't change NIC mode!\n");
  6520. return rc;
  6521. }
  6522. return 0;
  6523. }
  6524. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6525. {
  6526. int port = BP_PORT(bp);
  6527. int func = BP_FUNC(bp);
  6528. int init_phase = PHASE_PF0 + func;
  6529. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6530. u16 cdu_ilt_start;
  6531. u32 addr, val;
  6532. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6533. int i, main_mem_width, rc;
  6534. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6535. /* FLR cleanup - hmmm */
  6536. if (!CHIP_IS_E1x(bp)) {
  6537. rc = bnx2x_pf_flr_clnup(bp);
  6538. if (rc) {
  6539. bnx2x_fw_dump(bp);
  6540. return rc;
  6541. }
  6542. }
  6543. /* set MSI reconfigure capability */
  6544. if (bp->common.int_block == INT_BLOCK_HC) {
  6545. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6546. val = REG_RD(bp, addr);
  6547. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6548. REG_WR(bp, addr, val);
  6549. }
  6550. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6551. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6552. ilt = BP_ILT(bp);
  6553. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6554. if (IS_SRIOV(bp))
  6555. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6556. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6557. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6558. * those of the VFs, so start line should be reset
  6559. */
  6560. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6561. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6562. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6563. ilt->lines[cdu_ilt_start + i].page_mapping =
  6564. bp->context[i].cxt_mapping;
  6565. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6566. }
  6567. bnx2x_ilt_init_op(bp, INITOP_SET);
  6568. if (!CONFIGURE_NIC_MODE(bp)) {
  6569. bnx2x_init_searcher(bp);
  6570. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6571. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6572. } else {
  6573. /* Set NIC mode */
  6574. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6575. DP(NETIF_MSG_IFUP, "NIC MODE configured\n");
  6576. }
  6577. if (!CHIP_IS_E1x(bp)) {
  6578. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6579. /* Turn on a single ISR mode in IGU if driver is going to use
  6580. * INT#x or MSI
  6581. */
  6582. if (!(bp->flags & USING_MSIX_FLAG))
  6583. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6584. /*
  6585. * Timers workaround bug: function init part.
  6586. * Need to wait 20msec after initializing ILT,
  6587. * needed to make sure there are no requests in
  6588. * one of the PXP internal queues with "old" ILT addresses
  6589. */
  6590. msleep(20);
  6591. /*
  6592. * Master enable - Due to WB DMAE writes performed before this
  6593. * register is re-initialized as part of the regular function
  6594. * init
  6595. */
  6596. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6597. /* Enable the function in IGU */
  6598. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6599. }
  6600. bp->dmae_ready = 1;
  6601. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6602. if (!CHIP_IS_E1x(bp))
  6603. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  6604. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6605. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6606. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6607. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6608. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6609. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6610. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6611. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6612. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6613. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6614. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6615. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6616. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6617. if (!CHIP_IS_E1x(bp))
  6618. REG_WR(bp, QM_REG_PF_EN, 1);
  6619. if (!CHIP_IS_E1x(bp)) {
  6620. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6621. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6622. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6623. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6624. }
  6625. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6626. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6627. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6628. REG_WR(bp, DORQ_REG_MODE_ACT, 1); /* no dpm */
  6629. bnx2x_iov_init_dq(bp);
  6630. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6631. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6632. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6633. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6634. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6635. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6636. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6637. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6638. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6639. if (!CHIP_IS_E1x(bp))
  6640. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6641. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6642. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6643. if (!CHIP_IS_E1x(bp))
  6644. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6645. if (IS_MF(bp)) {
  6646. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  6647. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  6648. }
  6649. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6650. /* HC init per function */
  6651. if (bp->common.int_block == INT_BLOCK_HC) {
  6652. if (CHIP_IS_E1H(bp)) {
  6653. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6654. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6655. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6656. }
  6657. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6658. } else {
  6659. int num_segs, sb_idx, prod_offset;
  6660. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6661. if (!CHIP_IS_E1x(bp)) {
  6662. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6663. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6664. }
  6665. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6666. if (!CHIP_IS_E1x(bp)) {
  6667. int dsb_idx = 0;
  6668. /**
  6669. * Producer memory:
  6670. * E2 mode: address 0-135 match to the mapping memory;
  6671. * 136 - PF0 default prod; 137 - PF1 default prod;
  6672. * 138 - PF2 default prod; 139 - PF3 default prod;
  6673. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6674. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6675. * 144-147 reserved.
  6676. *
  6677. * E1.5 mode - In backward compatible mode;
  6678. * for non default SB; each even line in the memory
  6679. * holds the U producer and each odd line hold
  6680. * the C producer. The first 128 producers are for
  6681. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6682. * producers are for the DSB for each PF.
  6683. * Each PF has five segments: (the order inside each
  6684. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6685. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6686. * 144-147 attn prods;
  6687. */
  6688. /* non-default-status-blocks */
  6689. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6690. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6691. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6692. prod_offset = (bp->igu_base_sb + sb_idx) *
  6693. num_segs;
  6694. for (i = 0; i < num_segs; i++) {
  6695. addr = IGU_REG_PROD_CONS_MEMORY +
  6696. (prod_offset + i) * 4;
  6697. REG_WR(bp, addr, 0);
  6698. }
  6699. /* send consumer update with value 0 */
  6700. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6701. USTORM_ID, 0, IGU_INT_NOP, 1);
  6702. bnx2x_igu_clear_sb(bp,
  6703. bp->igu_base_sb + sb_idx);
  6704. }
  6705. /* default-status-blocks */
  6706. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6707. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6708. if (CHIP_MODE_IS_4_PORT(bp))
  6709. dsb_idx = BP_FUNC(bp);
  6710. else
  6711. dsb_idx = BP_VN(bp);
  6712. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6713. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6714. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6715. /*
  6716. * igu prods come in chunks of E1HVN_MAX (4) -
  6717. * does not matters what is the current chip mode
  6718. */
  6719. for (i = 0; i < (num_segs * E1HVN_MAX);
  6720. i += E1HVN_MAX) {
  6721. addr = IGU_REG_PROD_CONS_MEMORY +
  6722. (prod_offset + i)*4;
  6723. REG_WR(bp, addr, 0);
  6724. }
  6725. /* send consumer update with 0 */
  6726. if (CHIP_INT_MODE_IS_BC(bp)) {
  6727. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6728. USTORM_ID, 0, IGU_INT_NOP, 1);
  6729. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6730. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6731. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6732. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6733. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6734. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6735. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6736. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6737. } else {
  6738. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6739. USTORM_ID, 0, IGU_INT_NOP, 1);
  6740. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6741. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6742. }
  6743. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6744. /* !!! These should become driver const once
  6745. rf-tool supports split-68 const */
  6746. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6747. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6748. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6749. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6750. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6751. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6752. }
  6753. }
  6754. /* Reset PCIE errors for debug */
  6755. REG_WR(bp, 0x2114, 0xffffffff);
  6756. REG_WR(bp, 0x2120, 0xffffffff);
  6757. if (CHIP_IS_E1x(bp)) {
  6758. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6759. main_mem_base = HC_REG_MAIN_MEMORY +
  6760. BP_PORT(bp) * (main_mem_size * 4);
  6761. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6762. main_mem_width = 8;
  6763. val = REG_RD(bp, main_mem_prty_clr);
  6764. if (val)
  6765. DP(NETIF_MSG_HW,
  6766. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6767. val);
  6768. /* Clear "false" parity errors in MSI-X table */
  6769. for (i = main_mem_base;
  6770. i < main_mem_base + main_mem_size * 4;
  6771. i += main_mem_width) {
  6772. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6773. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6774. i, main_mem_width / 4);
  6775. }
  6776. /* Clear HC parity attention */
  6777. REG_RD(bp, main_mem_prty_clr);
  6778. }
  6779. #ifdef BNX2X_STOP_ON_ERROR
  6780. /* Enable STORMs SP logging */
  6781. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6782. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6783. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6784. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6785. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6786. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6787. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6788. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6789. #endif
  6790. bnx2x_phy_probe(&bp->link_params);
  6791. return 0;
  6792. }
  6793. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6794. {
  6795. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6796. if (!CHIP_IS_E1x(bp))
  6797. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6798. sizeof(struct host_hc_status_block_e2));
  6799. else
  6800. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6801. sizeof(struct host_hc_status_block_e1x));
  6802. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6803. }
  6804. void bnx2x_free_mem(struct bnx2x *bp)
  6805. {
  6806. int i;
  6807. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6808. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6809. if (IS_VF(bp))
  6810. return;
  6811. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6812. sizeof(struct host_sp_status_block));
  6813. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6814. sizeof(struct bnx2x_slowpath));
  6815. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6816. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6817. bp->context[i].size);
  6818. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6819. BNX2X_FREE(bp->ilt->lines);
  6820. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6821. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6822. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6823. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6824. bnx2x_iov_free_mem(bp);
  6825. }
  6826. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6827. {
  6828. if (!CHIP_IS_E1x(bp)) {
  6829. /* size = the status block + ramrod buffers */
  6830. bp->cnic_sb.e2_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
  6831. sizeof(struct host_hc_status_block_e2));
  6832. if (!bp->cnic_sb.e2_sb)
  6833. goto alloc_mem_err;
  6834. } else {
  6835. bp->cnic_sb.e1x_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
  6836. sizeof(struct host_hc_status_block_e1x));
  6837. if (!bp->cnic_sb.e1x_sb)
  6838. goto alloc_mem_err;
  6839. }
  6840. if (CONFIGURE_NIC_MODE(bp) && !bp->t2) {
  6841. /* allocate searcher T2 table, as it wasn't allocated before */
  6842. bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
  6843. if (!bp->t2)
  6844. goto alloc_mem_err;
  6845. }
  6846. /* write address to which L5 should insert its values */
  6847. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6848. &bp->slowpath->drv_info_to_mcp;
  6849. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6850. goto alloc_mem_err;
  6851. return 0;
  6852. alloc_mem_err:
  6853. bnx2x_free_mem_cnic(bp);
  6854. BNX2X_ERR("Can't allocate memory\n");
  6855. return -ENOMEM;
  6856. }
  6857. int bnx2x_alloc_mem(struct bnx2x *bp)
  6858. {
  6859. int i, allocated, context_size;
  6860. if (!CONFIGURE_NIC_MODE(bp) && !bp->t2) {
  6861. /* allocate searcher T2 table */
  6862. bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
  6863. if (!bp->t2)
  6864. goto alloc_mem_err;
  6865. }
  6866. bp->def_status_blk = BNX2X_PCI_ALLOC(&bp->def_status_blk_mapping,
  6867. sizeof(struct host_sp_status_block));
  6868. if (!bp->def_status_blk)
  6869. goto alloc_mem_err;
  6870. bp->slowpath = BNX2X_PCI_ALLOC(&bp->slowpath_mapping,
  6871. sizeof(struct bnx2x_slowpath));
  6872. if (!bp->slowpath)
  6873. goto alloc_mem_err;
  6874. /* Allocate memory for CDU context:
  6875. * This memory is allocated separately and not in the generic ILT
  6876. * functions because CDU differs in few aspects:
  6877. * 1. There are multiple entities allocating memory for context -
  6878. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6879. * its own ILT lines.
  6880. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6881. * for the other ILT clients), to be efficient we want to support
  6882. * allocation of sub-page-size in the last entry.
  6883. * 3. Context pointers are used by the driver to pass to FW / update
  6884. * the context (for the other ILT clients the pointers are used just to
  6885. * free the memory during unload).
  6886. */
  6887. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6888. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6889. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6890. (context_size - allocated));
  6891. bp->context[i].vcxt = BNX2X_PCI_ALLOC(&bp->context[i].cxt_mapping,
  6892. bp->context[i].size);
  6893. if (!bp->context[i].vcxt)
  6894. goto alloc_mem_err;
  6895. allocated += bp->context[i].size;
  6896. }
  6897. bp->ilt->lines = kcalloc(ILT_MAX_LINES, sizeof(struct ilt_line),
  6898. GFP_KERNEL);
  6899. if (!bp->ilt->lines)
  6900. goto alloc_mem_err;
  6901. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6902. goto alloc_mem_err;
  6903. if (bnx2x_iov_alloc_mem(bp))
  6904. goto alloc_mem_err;
  6905. /* Slow path ring */
  6906. bp->spq = BNX2X_PCI_ALLOC(&bp->spq_mapping, BCM_PAGE_SIZE);
  6907. if (!bp->spq)
  6908. goto alloc_mem_err;
  6909. /* EQ */
  6910. bp->eq_ring = BNX2X_PCI_ALLOC(&bp->eq_mapping,
  6911. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6912. if (!bp->eq_ring)
  6913. goto alloc_mem_err;
  6914. return 0;
  6915. alloc_mem_err:
  6916. bnx2x_free_mem(bp);
  6917. BNX2X_ERR("Can't allocate memory\n");
  6918. return -ENOMEM;
  6919. }
  6920. /*
  6921. * Init service functions
  6922. */
  6923. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6924. struct bnx2x_vlan_mac_obj *obj, bool set,
  6925. int mac_type, unsigned long *ramrod_flags)
  6926. {
  6927. int rc;
  6928. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6929. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6930. /* Fill general parameters */
  6931. ramrod_param.vlan_mac_obj = obj;
  6932. ramrod_param.ramrod_flags = *ramrod_flags;
  6933. /* Fill a user request section if needed */
  6934. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6935. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6936. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6937. /* Set the command: ADD or DEL */
  6938. if (set)
  6939. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6940. else
  6941. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6942. }
  6943. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6944. if (rc == -EEXIST) {
  6945. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  6946. /* do not treat adding same MAC as error */
  6947. rc = 0;
  6948. } else if (rc < 0)
  6949. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6950. return rc;
  6951. }
  6952. int bnx2x_del_all_macs(struct bnx2x *bp,
  6953. struct bnx2x_vlan_mac_obj *mac_obj,
  6954. int mac_type, bool wait_for_comp)
  6955. {
  6956. int rc;
  6957. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6958. /* Wait for completion of requested */
  6959. if (wait_for_comp)
  6960. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6961. /* Set the mac type of addresses we want to clear */
  6962. __set_bit(mac_type, &vlan_mac_flags);
  6963. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6964. if (rc < 0)
  6965. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6966. return rc;
  6967. }
  6968. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6969. {
  6970. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6971. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6972. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6973. "Ignoring Zero MAC for STORAGE SD mode\n");
  6974. return 0;
  6975. }
  6976. if (IS_PF(bp)) {
  6977. unsigned long ramrod_flags = 0;
  6978. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6979. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6980. return bnx2x_set_mac_one(bp, bp->dev->dev_addr,
  6981. &bp->sp_objs->mac_obj, set,
  6982. BNX2X_ETH_MAC, &ramrod_flags);
  6983. } else { /* vf */
  6984. return bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr,
  6985. bp->fp->index, true);
  6986. }
  6987. }
  6988. int bnx2x_setup_leading(struct bnx2x *bp)
  6989. {
  6990. if (IS_PF(bp))
  6991. return bnx2x_setup_queue(bp, &bp->fp[0], true);
  6992. else /* VF */
  6993. return bnx2x_vfpf_setup_q(bp, &bp->fp[0], true);
  6994. }
  6995. /**
  6996. * bnx2x_set_int_mode - configure interrupt mode
  6997. *
  6998. * @bp: driver handle
  6999. *
  7000. * In case of MSI-X it will also try to enable MSI-X.
  7001. */
  7002. int bnx2x_set_int_mode(struct bnx2x *bp)
  7003. {
  7004. int rc = 0;
  7005. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX) {
  7006. BNX2X_ERR("VF not loaded since interrupt mode not msix\n");
  7007. return -EINVAL;
  7008. }
  7009. switch (int_mode) {
  7010. case BNX2X_INT_MODE_MSIX:
  7011. /* attempt to enable msix */
  7012. rc = bnx2x_enable_msix(bp);
  7013. /* msix attained */
  7014. if (!rc)
  7015. return 0;
  7016. /* vfs use only msix */
  7017. if (rc && IS_VF(bp))
  7018. return rc;
  7019. /* failed to enable multiple MSI-X */
  7020. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  7021. bp->num_queues,
  7022. 1 + bp->num_cnic_queues);
  7023. /* falling through... */
  7024. case BNX2X_INT_MODE_MSI:
  7025. bnx2x_enable_msi(bp);
  7026. /* falling through... */
  7027. case BNX2X_INT_MODE_INTX:
  7028. bp->num_ethernet_queues = 1;
  7029. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  7030. BNX2X_DEV_INFO("set number of queues to 1\n");
  7031. break;
  7032. default:
  7033. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  7034. return -EINVAL;
  7035. }
  7036. return 0;
  7037. }
  7038. /* must be called prior to any HW initializations */
  7039. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  7040. {
  7041. if (IS_SRIOV(bp))
  7042. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  7043. return L2_ILT_LINES(bp);
  7044. }
  7045. void bnx2x_ilt_set_info(struct bnx2x *bp)
  7046. {
  7047. struct ilt_client_info *ilt_client;
  7048. struct bnx2x_ilt *ilt = BP_ILT(bp);
  7049. u16 line = 0;
  7050. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  7051. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  7052. /* CDU */
  7053. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  7054. ilt_client->client_num = ILT_CLIENT_CDU;
  7055. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  7056. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  7057. ilt_client->start = line;
  7058. line += bnx2x_cid_ilt_lines(bp);
  7059. if (CNIC_SUPPORT(bp))
  7060. line += CNIC_ILT_LINES;
  7061. ilt_client->end = line - 1;
  7062. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7063. ilt_client->start,
  7064. ilt_client->end,
  7065. ilt_client->page_size,
  7066. ilt_client->flags,
  7067. ilog2(ilt_client->page_size >> 12));
  7068. /* QM */
  7069. if (QM_INIT(bp->qm_cid_count)) {
  7070. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  7071. ilt_client->client_num = ILT_CLIENT_QM;
  7072. ilt_client->page_size = QM_ILT_PAGE_SZ;
  7073. ilt_client->flags = 0;
  7074. ilt_client->start = line;
  7075. /* 4 bytes for each cid */
  7076. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  7077. QM_ILT_PAGE_SZ);
  7078. ilt_client->end = line - 1;
  7079. DP(NETIF_MSG_IFUP,
  7080. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7081. ilt_client->start,
  7082. ilt_client->end,
  7083. ilt_client->page_size,
  7084. ilt_client->flags,
  7085. ilog2(ilt_client->page_size >> 12));
  7086. }
  7087. if (CNIC_SUPPORT(bp)) {
  7088. /* SRC */
  7089. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  7090. ilt_client->client_num = ILT_CLIENT_SRC;
  7091. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  7092. ilt_client->flags = 0;
  7093. ilt_client->start = line;
  7094. line += SRC_ILT_LINES;
  7095. ilt_client->end = line - 1;
  7096. DP(NETIF_MSG_IFUP,
  7097. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7098. ilt_client->start,
  7099. ilt_client->end,
  7100. ilt_client->page_size,
  7101. ilt_client->flags,
  7102. ilog2(ilt_client->page_size >> 12));
  7103. /* TM */
  7104. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  7105. ilt_client->client_num = ILT_CLIENT_TM;
  7106. ilt_client->page_size = TM_ILT_PAGE_SZ;
  7107. ilt_client->flags = 0;
  7108. ilt_client->start = line;
  7109. line += TM_ILT_LINES;
  7110. ilt_client->end = line - 1;
  7111. DP(NETIF_MSG_IFUP,
  7112. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7113. ilt_client->start,
  7114. ilt_client->end,
  7115. ilt_client->page_size,
  7116. ilt_client->flags,
  7117. ilog2(ilt_client->page_size >> 12));
  7118. }
  7119. BUG_ON(line > ILT_MAX_LINES);
  7120. }
  7121. /**
  7122. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  7123. *
  7124. * @bp: driver handle
  7125. * @fp: pointer to fastpath
  7126. * @init_params: pointer to parameters structure
  7127. *
  7128. * parameters configured:
  7129. * - HC configuration
  7130. * - Queue's CDU context
  7131. */
  7132. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  7133. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  7134. {
  7135. u8 cos;
  7136. int cxt_index, cxt_offset;
  7137. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  7138. if (!IS_FCOE_FP(fp)) {
  7139. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  7140. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  7141. /* If HC is supported, enable host coalescing in the transition
  7142. * to INIT state.
  7143. */
  7144. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  7145. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  7146. /* HC rate */
  7147. init_params->rx.hc_rate = bp->rx_ticks ?
  7148. (1000000 / bp->rx_ticks) : 0;
  7149. init_params->tx.hc_rate = bp->tx_ticks ?
  7150. (1000000 / bp->tx_ticks) : 0;
  7151. /* FW SB ID */
  7152. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  7153. fp->fw_sb_id;
  7154. /*
  7155. * CQ index among the SB indices: FCoE clients uses the default
  7156. * SB, therefore it's different.
  7157. */
  7158. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  7159. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  7160. }
  7161. /* set maximum number of COSs supported by this queue */
  7162. init_params->max_cos = fp->max_cos;
  7163. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  7164. fp->index, init_params->max_cos);
  7165. /* set the context pointers queue object */
  7166. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  7167. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  7168. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  7169. ILT_PAGE_CIDS);
  7170. init_params->cxts[cos] =
  7171. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  7172. }
  7173. }
  7174. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7175. struct bnx2x_queue_state_params *q_params,
  7176. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  7177. int tx_index, bool leading)
  7178. {
  7179. memset(tx_only_params, 0, sizeof(*tx_only_params));
  7180. /* Set the command */
  7181. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  7182. /* Set tx-only QUEUE flags: don't zero statistics */
  7183. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  7184. /* choose the index of the cid to send the slow path on */
  7185. tx_only_params->cid_index = tx_index;
  7186. /* Set general TX_ONLY_SETUP parameters */
  7187. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  7188. /* Set Tx TX_ONLY_SETUP parameters */
  7189. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  7190. DP(NETIF_MSG_IFUP,
  7191. "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",
  7192. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  7193. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  7194. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  7195. /* send the ramrod */
  7196. return bnx2x_queue_state_change(bp, q_params);
  7197. }
  7198. /**
  7199. * bnx2x_setup_queue - setup queue
  7200. *
  7201. * @bp: driver handle
  7202. * @fp: pointer to fastpath
  7203. * @leading: is leading
  7204. *
  7205. * This function performs 2 steps in a Queue state machine
  7206. * actually: 1) RESET->INIT 2) INIT->SETUP
  7207. */
  7208. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7209. bool leading)
  7210. {
  7211. struct bnx2x_queue_state_params q_params = {NULL};
  7212. struct bnx2x_queue_setup_params *setup_params =
  7213. &q_params.params.setup;
  7214. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  7215. &q_params.params.tx_only;
  7216. int rc;
  7217. u8 tx_index;
  7218. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  7219. /* reset IGU state skip FCoE L2 queue */
  7220. if (!IS_FCOE_FP(fp))
  7221. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  7222. IGU_INT_ENABLE, 0);
  7223. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7224. /* We want to wait for completion in this context */
  7225. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7226. /* Prepare the INIT parameters */
  7227. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  7228. /* Set the command */
  7229. q_params.cmd = BNX2X_Q_CMD_INIT;
  7230. /* Change the state to INIT */
  7231. rc = bnx2x_queue_state_change(bp, &q_params);
  7232. if (rc) {
  7233. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  7234. return rc;
  7235. }
  7236. DP(NETIF_MSG_IFUP, "init complete\n");
  7237. /* Now move the Queue to the SETUP state... */
  7238. memset(setup_params, 0, sizeof(*setup_params));
  7239. /* Set QUEUE flags */
  7240. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  7241. /* Set general SETUP parameters */
  7242. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  7243. FIRST_TX_COS_INDEX);
  7244. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  7245. &setup_params->rxq_params);
  7246. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  7247. FIRST_TX_COS_INDEX);
  7248. /* Set the command */
  7249. q_params.cmd = BNX2X_Q_CMD_SETUP;
  7250. if (IS_FCOE_FP(fp))
  7251. bp->fcoe_init = true;
  7252. /* Change the state to SETUP */
  7253. rc = bnx2x_queue_state_change(bp, &q_params);
  7254. if (rc) {
  7255. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  7256. return rc;
  7257. }
  7258. /* loop through the relevant tx-only indices */
  7259. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7260. tx_index < fp->max_cos;
  7261. tx_index++) {
  7262. /* prepare and send tx-only ramrod*/
  7263. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  7264. tx_only_params, tx_index, leading);
  7265. if (rc) {
  7266. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  7267. fp->index, tx_index);
  7268. return rc;
  7269. }
  7270. }
  7271. return rc;
  7272. }
  7273. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  7274. {
  7275. struct bnx2x_fastpath *fp = &bp->fp[index];
  7276. struct bnx2x_fp_txdata *txdata;
  7277. struct bnx2x_queue_state_params q_params = {NULL};
  7278. int rc, tx_index;
  7279. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  7280. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7281. /* We want to wait for completion in this context */
  7282. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7283. /* close tx-only connections */
  7284. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7285. tx_index < fp->max_cos;
  7286. tx_index++){
  7287. /* ascertain this is a normal queue*/
  7288. txdata = fp->txdata_ptr[tx_index];
  7289. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  7290. txdata->txq_index);
  7291. /* send halt terminate on tx-only connection */
  7292. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7293. memset(&q_params.params.terminate, 0,
  7294. sizeof(q_params.params.terminate));
  7295. q_params.params.terminate.cid_index = tx_index;
  7296. rc = bnx2x_queue_state_change(bp, &q_params);
  7297. if (rc)
  7298. return rc;
  7299. /* send halt terminate on tx-only connection */
  7300. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7301. memset(&q_params.params.cfc_del, 0,
  7302. sizeof(q_params.params.cfc_del));
  7303. q_params.params.cfc_del.cid_index = tx_index;
  7304. rc = bnx2x_queue_state_change(bp, &q_params);
  7305. if (rc)
  7306. return rc;
  7307. }
  7308. /* Stop the primary connection: */
  7309. /* ...halt the connection */
  7310. q_params.cmd = BNX2X_Q_CMD_HALT;
  7311. rc = bnx2x_queue_state_change(bp, &q_params);
  7312. if (rc)
  7313. return rc;
  7314. /* ...terminate the connection */
  7315. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7316. memset(&q_params.params.terminate, 0,
  7317. sizeof(q_params.params.terminate));
  7318. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  7319. rc = bnx2x_queue_state_change(bp, &q_params);
  7320. if (rc)
  7321. return rc;
  7322. /* ...delete cfc entry */
  7323. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7324. memset(&q_params.params.cfc_del, 0,
  7325. sizeof(q_params.params.cfc_del));
  7326. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  7327. return bnx2x_queue_state_change(bp, &q_params);
  7328. }
  7329. static void bnx2x_reset_func(struct bnx2x *bp)
  7330. {
  7331. int port = BP_PORT(bp);
  7332. int func = BP_FUNC(bp);
  7333. int i;
  7334. /* Disable the function in the FW */
  7335. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  7336. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  7337. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  7338. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  7339. /* FP SBs */
  7340. for_each_eth_queue(bp, i) {
  7341. struct bnx2x_fastpath *fp = &bp->fp[i];
  7342. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7343. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  7344. SB_DISABLED);
  7345. }
  7346. if (CNIC_LOADED(bp))
  7347. /* CNIC SB */
  7348. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7349. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  7350. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  7351. /* SP SB */
  7352. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7353. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  7354. SB_DISABLED);
  7355. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  7356. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  7357. 0);
  7358. /* Configure IGU */
  7359. if (bp->common.int_block == INT_BLOCK_HC) {
  7360. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  7361. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  7362. } else {
  7363. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  7364. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  7365. }
  7366. if (CNIC_LOADED(bp)) {
  7367. /* Disable Timer scan */
  7368. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  7369. /*
  7370. * Wait for at least 10ms and up to 2 second for the timers
  7371. * scan to complete
  7372. */
  7373. for (i = 0; i < 200; i++) {
  7374. usleep_range(10000, 20000);
  7375. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  7376. break;
  7377. }
  7378. }
  7379. /* Clear ILT */
  7380. bnx2x_clear_func_ilt(bp, func);
  7381. /* Timers workaround bug for E2: if this is vnic-3,
  7382. * we need to set the entire ilt range for this timers.
  7383. */
  7384. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  7385. struct ilt_client_info ilt_cli;
  7386. /* use dummy TM client */
  7387. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  7388. ilt_cli.start = 0;
  7389. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  7390. ilt_cli.client_num = ILT_CLIENT_TM;
  7391. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  7392. }
  7393. /* this assumes that reset_port() called before reset_func()*/
  7394. if (!CHIP_IS_E1x(bp))
  7395. bnx2x_pf_disable(bp);
  7396. bp->dmae_ready = 0;
  7397. }
  7398. static void bnx2x_reset_port(struct bnx2x *bp)
  7399. {
  7400. int port = BP_PORT(bp);
  7401. u32 val;
  7402. /* Reset physical Link */
  7403. bnx2x__link_reset(bp);
  7404. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  7405. /* Do not rcv packets to BRB */
  7406. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  7407. /* Do not direct rcv packets that are not for MCP to the BRB */
  7408. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7409. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7410. /* Configure AEU */
  7411. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  7412. msleep(100);
  7413. /* Check for BRB port occupancy */
  7414. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7415. if (val)
  7416. DP(NETIF_MSG_IFDOWN,
  7417. "BRB1 is not empty %d blocks are occupied\n", val);
  7418. /* TODO: Close Doorbell port? */
  7419. }
  7420. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7421. {
  7422. struct bnx2x_func_state_params func_params = {NULL};
  7423. /* Prepare parameters for function state transitions */
  7424. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7425. func_params.f_obj = &bp->func_obj;
  7426. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7427. func_params.params.hw_init.load_phase = load_code;
  7428. return bnx2x_func_state_change(bp, &func_params);
  7429. }
  7430. static int bnx2x_func_stop(struct bnx2x *bp)
  7431. {
  7432. struct bnx2x_func_state_params func_params = {NULL};
  7433. int rc;
  7434. /* Prepare parameters for function state transitions */
  7435. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7436. func_params.f_obj = &bp->func_obj;
  7437. func_params.cmd = BNX2X_F_CMD_STOP;
  7438. /*
  7439. * Try to stop the function the 'good way'. If fails (in case
  7440. * of a parity error during bnx2x_chip_cleanup()) and we are
  7441. * not in a debug mode, perform a state transaction in order to
  7442. * enable further HW_RESET transaction.
  7443. */
  7444. rc = bnx2x_func_state_change(bp, &func_params);
  7445. if (rc) {
  7446. #ifdef BNX2X_STOP_ON_ERROR
  7447. return rc;
  7448. #else
  7449. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7450. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7451. return bnx2x_func_state_change(bp, &func_params);
  7452. #endif
  7453. }
  7454. return 0;
  7455. }
  7456. /**
  7457. * bnx2x_send_unload_req - request unload mode from the MCP.
  7458. *
  7459. * @bp: driver handle
  7460. * @unload_mode: requested function's unload mode
  7461. *
  7462. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7463. */
  7464. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7465. {
  7466. u32 reset_code = 0;
  7467. int port = BP_PORT(bp);
  7468. /* Select the UNLOAD request mode */
  7469. if (unload_mode == UNLOAD_NORMAL)
  7470. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7471. else if (bp->flags & NO_WOL_FLAG)
  7472. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7473. else if (bp->wol) {
  7474. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7475. u8 *mac_addr = bp->dev->dev_addr;
  7476. struct pci_dev *pdev = bp->pdev;
  7477. u32 val;
  7478. u16 pmc;
  7479. /* The mac address is written to entries 1-4 to
  7480. * preserve entry 0 which is used by the PMF
  7481. */
  7482. u8 entry = (BP_VN(bp) + 1)*8;
  7483. val = (mac_addr[0] << 8) | mac_addr[1];
  7484. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7485. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7486. (mac_addr[4] << 8) | mac_addr[5];
  7487. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7488. /* Enable the PME and clear the status */
  7489. pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &pmc);
  7490. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7491. pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, pmc);
  7492. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7493. } else
  7494. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7495. /* Send the request to the MCP */
  7496. if (!BP_NOMCP(bp))
  7497. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7498. else {
  7499. int path = BP_PATH(bp);
  7500. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7501. path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
  7502. bnx2x_load_count[path][2]);
  7503. bnx2x_load_count[path][0]--;
  7504. bnx2x_load_count[path][1 + port]--;
  7505. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7506. path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
  7507. bnx2x_load_count[path][2]);
  7508. if (bnx2x_load_count[path][0] == 0)
  7509. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7510. else if (bnx2x_load_count[path][1 + port] == 0)
  7511. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7512. else
  7513. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7514. }
  7515. return reset_code;
  7516. }
  7517. /**
  7518. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7519. *
  7520. * @bp: driver handle
  7521. * @keep_link: true iff link should be kept up
  7522. */
  7523. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7524. {
  7525. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7526. /* Report UNLOAD_DONE to MCP */
  7527. if (!BP_NOMCP(bp))
  7528. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7529. }
  7530. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7531. {
  7532. int tout = 50;
  7533. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7534. if (!bp->port.pmf)
  7535. return 0;
  7536. /*
  7537. * (assumption: No Attention from MCP at this stage)
  7538. * PMF probably in the middle of TX disable/enable transaction
  7539. * 1. Sync IRS for default SB
  7540. * 2. Sync SP queue - this guarantees us that attention handling started
  7541. * 3. Wait, that TX disable/enable transaction completes
  7542. *
  7543. * 1+2 guarantee that if DCBx attention was scheduled it already changed
  7544. * pending bit of transaction from STARTED-->TX_STOPPED, if we already
  7545. * received completion for the transaction the state is TX_STOPPED.
  7546. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7547. * transaction.
  7548. */
  7549. /* make sure default SB ISR is done */
  7550. if (msix)
  7551. synchronize_irq(bp->msix_table[0].vector);
  7552. else
  7553. synchronize_irq(bp->pdev->irq);
  7554. flush_workqueue(bnx2x_wq);
  7555. flush_workqueue(bnx2x_iov_wq);
  7556. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7557. BNX2X_F_STATE_STARTED && tout--)
  7558. msleep(20);
  7559. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7560. BNX2X_F_STATE_STARTED) {
  7561. #ifdef BNX2X_STOP_ON_ERROR
  7562. BNX2X_ERR("Wrong function state\n");
  7563. return -EBUSY;
  7564. #else
  7565. /*
  7566. * Failed to complete the transaction in a "good way"
  7567. * Force both transactions with CLR bit
  7568. */
  7569. struct bnx2x_func_state_params func_params = {NULL};
  7570. DP(NETIF_MSG_IFDOWN,
  7571. "Hmmm... Unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  7572. func_params.f_obj = &bp->func_obj;
  7573. __set_bit(RAMROD_DRV_CLR_ONLY,
  7574. &func_params.ramrod_flags);
  7575. /* STARTED-->TX_ST0PPED */
  7576. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7577. bnx2x_func_state_change(bp, &func_params);
  7578. /* TX_ST0PPED-->STARTED */
  7579. func_params.cmd = BNX2X_F_CMD_TX_START;
  7580. return bnx2x_func_state_change(bp, &func_params);
  7581. #endif
  7582. }
  7583. return 0;
  7584. }
  7585. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7586. {
  7587. int port = BP_PORT(bp);
  7588. int i, rc = 0;
  7589. u8 cos;
  7590. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7591. u32 reset_code;
  7592. /* Wait until tx fastpath tasks complete */
  7593. for_each_tx_queue(bp, i) {
  7594. struct bnx2x_fastpath *fp = &bp->fp[i];
  7595. for_each_cos_in_tx_queue(fp, cos)
  7596. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7597. #ifdef BNX2X_STOP_ON_ERROR
  7598. if (rc)
  7599. return;
  7600. #endif
  7601. }
  7602. /* Give HW time to discard old tx messages */
  7603. usleep_range(1000, 2000);
  7604. /* Clean all ETH MACs */
  7605. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7606. false);
  7607. if (rc < 0)
  7608. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7609. /* Clean up UC list */
  7610. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7611. true);
  7612. if (rc < 0)
  7613. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7614. rc);
  7615. /* Disable LLH */
  7616. if (!CHIP_IS_E1(bp))
  7617. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7618. /* Set "drop all" (stop Rx).
  7619. * We need to take a netif_addr_lock() here in order to prevent
  7620. * a race between the completion code and this code.
  7621. */
  7622. netif_addr_lock_bh(bp->dev);
  7623. /* Schedule the rx_mode command */
  7624. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7625. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7626. else
  7627. bnx2x_set_storm_rx_mode(bp);
  7628. /* Cleanup multicast configuration */
  7629. rparam.mcast_obj = &bp->mcast_obj;
  7630. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7631. if (rc < 0)
  7632. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7633. netif_addr_unlock_bh(bp->dev);
  7634. bnx2x_iov_chip_cleanup(bp);
  7635. /*
  7636. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7637. * this function should perform FUNC, PORT or COMMON HW
  7638. * reset.
  7639. */
  7640. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7641. /*
  7642. * (assumption: No Attention from MCP at this stage)
  7643. * PMF probably in the middle of TX disable/enable transaction
  7644. */
  7645. rc = bnx2x_func_wait_started(bp);
  7646. if (rc) {
  7647. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7648. #ifdef BNX2X_STOP_ON_ERROR
  7649. return;
  7650. #endif
  7651. }
  7652. /* Close multi and leading connections
  7653. * Completions for ramrods are collected in a synchronous way
  7654. */
  7655. for_each_eth_queue(bp, i)
  7656. if (bnx2x_stop_queue(bp, i))
  7657. #ifdef BNX2X_STOP_ON_ERROR
  7658. return;
  7659. #else
  7660. goto unload_error;
  7661. #endif
  7662. if (CNIC_LOADED(bp)) {
  7663. for_each_cnic_queue(bp, i)
  7664. if (bnx2x_stop_queue(bp, i))
  7665. #ifdef BNX2X_STOP_ON_ERROR
  7666. return;
  7667. #else
  7668. goto unload_error;
  7669. #endif
  7670. }
  7671. /* If SP settings didn't get completed so far - something
  7672. * very wrong has happen.
  7673. */
  7674. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7675. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7676. #ifndef BNX2X_STOP_ON_ERROR
  7677. unload_error:
  7678. #endif
  7679. rc = bnx2x_func_stop(bp);
  7680. if (rc) {
  7681. BNX2X_ERR("Function stop failed!\n");
  7682. #ifdef BNX2X_STOP_ON_ERROR
  7683. return;
  7684. #endif
  7685. }
  7686. /* Disable HW interrupts, NAPI */
  7687. bnx2x_netif_stop(bp, 1);
  7688. /* Delete all NAPI objects */
  7689. bnx2x_del_all_napi(bp);
  7690. if (CNIC_LOADED(bp))
  7691. bnx2x_del_all_napi_cnic(bp);
  7692. /* Release IRQs */
  7693. bnx2x_free_irq(bp);
  7694. /* Reset the chip */
  7695. rc = bnx2x_reset_hw(bp, reset_code);
  7696. if (rc)
  7697. BNX2X_ERR("HW_RESET failed\n");
  7698. /* Report UNLOAD_DONE to MCP */
  7699. bnx2x_send_unload_done(bp, keep_link);
  7700. }
  7701. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7702. {
  7703. u32 val;
  7704. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7705. if (CHIP_IS_E1(bp)) {
  7706. int port = BP_PORT(bp);
  7707. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7708. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7709. val = REG_RD(bp, addr);
  7710. val &= ~(0x300);
  7711. REG_WR(bp, addr, val);
  7712. } else {
  7713. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7714. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7715. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7716. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7717. }
  7718. }
  7719. /* Close gates #2, #3 and #4: */
  7720. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7721. {
  7722. u32 val;
  7723. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7724. if (!CHIP_IS_E1(bp)) {
  7725. /* #4 */
  7726. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7727. /* #2 */
  7728. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7729. }
  7730. /* #3 */
  7731. if (CHIP_IS_E1x(bp)) {
  7732. /* Prevent interrupts from HC on both ports */
  7733. val = REG_RD(bp, HC_REG_CONFIG_1);
  7734. REG_WR(bp, HC_REG_CONFIG_1,
  7735. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7736. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7737. val = REG_RD(bp, HC_REG_CONFIG_0);
  7738. REG_WR(bp, HC_REG_CONFIG_0,
  7739. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7740. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7741. } else {
  7742. /* Prevent incoming interrupts in IGU */
  7743. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7744. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7745. (!close) ?
  7746. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7747. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7748. }
  7749. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7750. close ? "closing" : "opening");
  7751. mmiowb();
  7752. }
  7753. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7754. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7755. {
  7756. /* Do some magic... */
  7757. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7758. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7759. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7760. }
  7761. /**
  7762. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7763. *
  7764. * @bp: driver handle
  7765. * @magic_val: old value of the `magic' bit.
  7766. */
  7767. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7768. {
  7769. /* Restore the `magic' bit value... */
  7770. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7771. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7772. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7773. }
  7774. /**
  7775. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7776. *
  7777. * @bp: driver handle
  7778. * @magic_val: old value of 'magic' bit.
  7779. *
  7780. * Takes care of CLP configurations.
  7781. */
  7782. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7783. {
  7784. u32 shmem;
  7785. u32 validity_offset;
  7786. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7787. /* Set `magic' bit in order to save MF config */
  7788. if (!CHIP_IS_E1(bp))
  7789. bnx2x_clp_reset_prep(bp, magic_val);
  7790. /* Get shmem offset */
  7791. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7792. validity_offset =
  7793. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7794. /* Clear validity map flags */
  7795. if (shmem > 0)
  7796. REG_WR(bp, shmem + validity_offset, 0);
  7797. }
  7798. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7799. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7800. /**
  7801. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7802. *
  7803. * @bp: driver handle
  7804. */
  7805. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7806. {
  7807. /* special handling for emulation and FPGA,
  7808. wait 10 times longer */
  7809. if (CHIP_REV_IS_SLOW(bp))
  7810. msleep(MCP_ONE_TIMEOUT*10);
  7811. else
  7812. msleep(MCP_ONE_TIMEOUT);
  7813. }
  7814. /*
  7815. * initializes bp->common.shmem_base and waits for validity signature to appear
  7816. */
  7817. static int bnx2x_init_shmem(struct bnx2x *bp)
  7818. {
  7819. int cnt = 0;
  7820. u32 val = 0;
  7821. do {
  7822. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7823. if (bp->common.shmem_base) {
  7824. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7825. if (val & SHR_MEM_VALIDITY_MB)
  7826. return 0;
  7827. }
  7828. bnx2x_mcp_wait_one(bp);
  7829. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7830. BNX2X_ERR("BAD MCP validity signature\n");
  7831. return -ENODEV;
  7832. }
  7833. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7834. {
  7835. int rc = bnx2x_init_shmem(bp);
  7836. /* Restore the `magic' bit value */
  7837. if (!CHIP_IS_E1(bp))
  7838. bnx2x_clp_reset_done(bp, magic_val);
  7839. return rc;
  7840. }
  7841. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7842. {
  7843. if (!CHIP_IS_E1(bp)) {
  7844. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7845. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7846. mmiowb();
  7847. }
  7848. }
  7849. /*
  7850. * Reset the whole chip except for:
  7851. * - PCIE core
  7852. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7853. * one reset bit)
  7854. * - IGU
  7855. * - MISC (including AEU)
  7856. * - GRC
  7857. * - RBCN, RBCP
  7858. */
  7859. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7860. {
  7861. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7862. u32 global_bits2, stay_reset2;
  7863. /*
  7864. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7865. * (per chip) blocks.
  7866. */
  7867. global_bits2 =
  7868. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7869. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7870. /* Don't reset the following blocks.
  7871. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  7872. * reset, as in 4 port device they might still be owned
  7873. * by the MCP (there is only one leader per path).
  7874. */
  7875. not_reset_mask1 =
  7876. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7877. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7878. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7879. not_reset_mask2 =
  7880. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7881. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7882. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7883. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7884. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7885. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7886. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7887. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7888. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7889. MISC_REGISTERS_RESET_REG_2_PGLC |
  7890. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7891. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7892. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7893. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7894. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7895. MISC_REGISTERS_RESET_REG_2_UMAC1;
  7896. /*
  7897. * Keep the following blocks in reset:
  7898. * - all xxMACs are handled by the bnx2x_link code.
  7899. */
  7900. stay_reset2 =
  7901. MISC_REGISTERS_RESET_REG_2_XMAC |
  7902. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7903. /* Full reset masks according to the chip */
  7904. reset_mask1 = 0xffffffff;
  7905. if (CHIP_IS_E1(bp))
  7906. reset_mask2 = 0xffff;
  7907. else if (CHIP_IS_E1H(bp))
  7908. reset_mask2 = 0x1ffff;
  7909. else if (CHIP_IS_E2(bp))
  7910. reset_mask2 = 0xfffff;
  7911. else /* CHIP_IS_E3 */
  7912. reset_mask2 = 0x3ffffff;
  7913. /* Don't reset global blocks unless we need to */
  7914. if (!global)
  7915. reset_mask2 &= ~global_bits2;
  7916. /*
  7917. * In case of attention in the QM, we need to reset PXP
  7918. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7919. * because otherwise QM reset would release 'close the gates' shortly
  7920. * before resetting the PXP, then the PSWRQ would send a write
  7921. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7922. * read the payload data from PSWWR, but PSWWR would not
  7923. * respond. The write queue in PGLUE would stuck, dmae commands
  7924. * would not return. Therefore it's important to reset the second
  7925. * reset register (containing the
  7926. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7927. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7928. * bit).
  7929. */
  7930. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7931. reset_mask2 & (~not_reset_mask2));
  7932. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7933. reset_mask1 & (~not_reset_mask1));
  7934. barrier();
  7935. mmiowb();
  7936. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7937. reset_mask2 & (~stay_reset2));
  7938. barrier();
  7939. mmiowb();
  7940. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7941. mmiowb();
  7942. }
  7943. /**
  7944. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7945. * It should get cleared in no more than 1s.
  7946. *
  7947. * @bp: driver handle
  7948. *
  7949. * It should get cleared in no more than 1s. Returns 0 if
  7950. * pending writes bit gets cleared.
  7951. */
  7952. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7953. {
  7954. u32 cnt = 1000;
  7955. u32 pend_bits = 0;
  7956. do {
  7957. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7958. if (pend_bits == 0)
  7959. break;
  7960. usleep_range(1000, 2000);
  7961. } while (cnt-- > 0);
  7962. if (cnt <= 0) {
  7963. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7964. pend_bits);
  7965. return -EBUSY;
  7966. }
  7967. return 0;
  7968. }
  7969. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7970. {
  7971. int cnt = 1000;
  7972. u32 val = 0;
  7973. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7974. u32 tags_63_32 = 0;
  7975. /* Empty the Tetris buffer, wait for 1s */
  7976. do {
  7977. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7978. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7979. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7980. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7981. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7982. if (CHIP_IS_E3(bp))
  7983. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  7984. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7985. ((port_is_idle_0 & 0x1) == 0x1) &&
  7986. ((port_is_idle_1 & 0x1) == 0x1) &&
  7987. (pgl_exp_rom2 == 0xffffffff) &&
  7988. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  7989. break;
  7990. usleep_range(1000, 2000);
  7991. } while (cnt-- > 0);
  7992. if (cnt <= 0) {
  7993. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7994. 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",
  7995. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7996. pgl_exp_rom2);
  7997. return -EAGAIN;
  7998. }
  7999. barrier();
  8000. /* Close gates #2, #3 and #4 */
  8001. bnx2x_set_234_gates(bp, true);
  8002. /* Poll for IGU VQs for 57712 and newer chips */
  8003. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  8004. return -EAGAIN;
  8005. /* TBD: Indicate that "process kill" is in progress to MCP */
  8006. /* Clear "unprepared" bit */
  8007. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  8008. barrier();
  8009. /* Make sure all is written to the chip before the reset */
  8010. mmiowb();
  8011. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  8012. * PSWHST, GRC and PSWRD Tetris buffer.
  8013. */
  8014. usleep_range(1000, 2000);
  8015. /* Prepare to chip reset: */
  8016. /* MCP */
  8017. if (global)
  8018. bnx2x_reset_mcp_prep(bp, &val);
  8019. /* PXP */
  8020. bnx2x_pxp_prep(bp);
  8021. barrier();
  8022. /* reset the chip */
  8023. bnx2x_process_kill_chip_reset(bp, global);
  8024. barrier();
  8025. /* clear errors in PGB */
  8026. if (!CHIP_IS_E1x(bp))
  8027. REG_WR(bp, PGLUE_B_REG_LATCHED_ERRORS_CLR, 0x7f);
  8028. /* Recover after reset: */
  8029. /* MCP */
  8030. if (global && bnx2x_reset_mcp_comp(bp, val))
  8031. return -EAGAIN;
  8032. /* TBD: Add resetting the NO_MCP mode DB here */
  8033. /* Open the gates #2, #3 and #4 */
  8034. bnx2x_set_234_gates(bp, false);
  8035. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  8036. * reset state, re-enable attentions. */
  8037. return 0;
  8038. }
  8039. static int bnx2x_leader_reset(struct bnx2x *bp)
  8040. {
  8041. int rc = 0;
  8042. bool global = bnx2x_reset_is_global(bp);
  8043. u32 load_code;
  8044. /* if not going to reset MCP - load "fake" driver to reset HW while
  8045. * driver is owner of the HW
  8046. */
  8047. if (!global && !BP_NOMCP(bp)) {
  8048. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  8049. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  8050. if (!load_code) {
  8051. BNX2X_ERR("MCP response failure, aborting\n");
  8052. rc = -EAGAIN;
  8053. goto exit_leader_reset;
  8054. }
  8055. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  8056. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  8057. BNX2X_ERR("MCP unexpected resp, aborting\n");
  8058. rc = -EAGAIN;
  8059. goto exit_leader_reset2;
  8060. }
  8061. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  8062. if (!load_code) {
  8063. BNX2X_ERR("MCP response failure, aborting\n");
  8064. rc = -EAGAIN;
  8065. goto exit_leader_reset2;
  8066. }
  8067. }
  8068. /* Try to recover after the failure */
  8069. if (bnx2x_process_kill(bp, global)) {
  8070. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  8071. BP_PATH(bp));
  8072. rc = -EAGAIN;
  8073. goto exit_leader_reset2;
  8074. }
  8075. /*
  8076. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  8077. * state.
  8078. */
  8079. bnx2x_set_reset_done(bp);
  8080. if (global)
  8081. bnx2x_clear_reset_global(bp);
  8082. exit_leader_reset2:
  8083. /* unload "fake driver" if it was loaded */
  8084. if (!global && !BP_NOMCP(bp)) {
  8085. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  8086. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  8087. }
  8088. exit_leader_reset:
  8089. bp->is_leader = 0;
  8090. bnx2x_release_leader_lock(bp);
  8091. smp_mb();
  8092. return rc;
  8093. }
  8094. static void bnx2x_recovery_failed(struct bnx2x *bp)
  8095. {
  8096. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  8097. /* Disconnect this device */
  8098. netif_device_detach(bp->dev);
  8099. /*
  8100. * Block ifup for all function on this engine until "process kill"
  8101. * or power cycle.
  8102. */
  8103. bnx2x_set_reset_in_progress(bp);
  8104. /* Shut down the power */
  8105. bnx2x_set_power_state(bp, PCI_D3hot);
  8106. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  8107. smp_mb();
  8108. }
  8109. /*
  8110. * Assumption: runs under rtnl lock. This together with the fact
  8111. * that it's called only from bnx2x_sp_rtnl() ensure that it
  8112. * will never be called when netif_running(bp->dev) is false.
  8113. */
  8114. static void bnx2x_parity_recover(struct bnx2x *bp)
  8115. {
  8116. bool global = false;
  8117. u32 error_recovered, error_unrecovered;
  8118. bool is_parity;
  8119. DP(NETIF_MSG_HW, "Handling parity\n");
  8120. while (1) {
  8121. switch (bp->recovery_state) {
  8122. case BNX2X_RECOVERY_INIT:
  8123. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  8124. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  8125. WARN_ON(!is_parity);
  8126. /* Try to get a LEADER_LOCK HW lock */
  8127. if (bnx2x_trylock_leader_lock(bp)) {
  8128. bnx2x_set_reset_in_progress(bp);
  8129. /*
  8130. * Check if there is a global attention and if
  8131. * there was a global attention, set the global
  8132. * reset bit.
  8133. */
  8134. if (global)
  8135. bnx2x_set_reset_global(bp);
  8136. bp->is_leader = 1;
  8137. }
  8138. /* Stop the driver */
  8139. /* If interface has been removed - break */
  8140. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  8141. return;
  8142. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  8143. /* Ensure "is_leader", MCP command sequence and
  8144. * "recovery_state" update values are seen on other
  8145. * CPUs.
  8146. */
  8147. smp_mb();
  8148. break;
  8149. case BNX2X_RECOVERY_WAIT:
  8150. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  8151. if (bp->is_leader) {
  8152. int other_engine = BP_PATH(bp) ? 0 : 1;
  8153. bool other_load_status =
  8154. bnx2x_get_load_status(bp, other_engine);
  8155. bool load_status =
  8156. bnx2x_get_load_status(bp, BP_PATH(bp));
  8157. global = bnx2x_reset_is_global(bp);
  8158. /*
  8159. * In case of a parity in a global block, let
  8160. * the first leader that performs a
  8161. * leader_reset() reset the global blocks in
  8162. * order to clear global attentions. Otherwise
  8163. * the gates will remain closed for that
  8164. * engine.
  8165. */
  8166. if (load_status ||
  8167. (global && other_load_status)) {
  8168. /* Wait until all other functions get
  8169. * down.
  8170. */
  8171. schedule_delayed_work(&bp->sp_rtnl_task,
  8172. HZ/10);
  8173. return;
  8174. } else {
  8175. /* If all other functions got down -
  8176. * try to bring the chip back to
  8177. * normal. In any case it's an exit
  8178. * point for a leader.
  8179. */
  8180. if (bnx2x_leader_reset(bp)) {
  8181. bnx2x_recovery_failed(bp);
  8182. return;
  8183. }
  8184. /* If we are here, means that the
  8185. * leader has succeeded and doesn't
  8186. * want to be a leader any more. Try
  8187. * to continue as a none-leader.
  8188. */
  8189. break;
  8190. }
  8191. } else { /* non-leader */
  8192. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  8193. /* Try to get a LEADER_LOCK HW lock as
  8194. * long as a former leader may have
  8195. * been unloaded by the user or
  8196. * released a leadership by another
  8197. * reason.
  8198. */
  8199. if (bnx2x_trylock_leader_lock(bp)) {
  8200. /* I'm a leader now! Restart a
  8201. * switch case.
  8202. */
  8203. bp->is_leader = 1;
  8204. break;
  8205. }
  8206. schedule_delayed_work(&bp->sp_rtnl_task,
  8207. HZ/10);
  8208. return;
  8209. } else {
  8210. /*
  8211. * If there was a global attention, wait
  8212. * for it to be cleared.
  8213. */
  8214. if (bnx2x_reset_is_global(bp)) {
  8215. schedule_delayed_work(
  8216. &bp->sp_rtnl_task,
  8217. HZ/10);
  8218. return;
  8219. }
  8220. error_recovered =
  8221. bp->eth_stats.recoverable_error;
  8222. error_unrecovered =
  8223. bp->eth_stats.unrecoverable_error;
  8224. bp->recovery_state =
  8225. BNX2X_RECOVERY_NIC_LOADING;
  8226. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  8227. error_unrecovered++;
  8228. netdev_err(bp->dev,
  8229. "Recovery failed. Power cycle needed\n");
  8230. /* Disconnect this device */
  8231. netif_device_detach(bp->dev);
  8232. /* Shut down the power */
  8233. bnx2x_set_power_state(
  8234. bp, PCI_D3hot);
  8235. smp_mb();
  8236. } else {
  8237. bp->recovery_state =
  8238. BNX2X_RECOVERY_DONE;
  8239. error_recovered++;
  8240. smp_mb();
  8241. }
  8242. bp->eth_stats.recoverable_error =
  8243. error_recovered;
  8244. bp->eth_stats.unrecoverable_error =
  8245. error_unrecovered;
  8246. return;
  8247. }
  8248. }
  8249. default:
  8250. return;
  8251. }
  8252. }
  8253. }
  8254. static int bnx2x_close(struct net_device *dev);
  8255. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  8256. * scheduled on a general queue in order to prevent a dead lock.
  8257. */
  8258. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  8259. {
  8260. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  8261. rtnl_lock();
  8262. if (!netif_running(bp->dev)) {
  8263. rtnl_unlock();
  8264. return;
  8265. }
  8266. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  8267. #ifdef BNX2X_STOP_ON_ERROR
  8268. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8269. "you will need to reboot when done\n");
  8270. goto sp_rtnl_not_reset;
  8271. #endif
  8272. /*
  8273. * Clear all pending SP commands as we are going to reset the
  8274. * function anyway.
  8275. */
  8276. bp->sp_rtnl_state = 0;
  8277. smp_mb();
  8278. bnx2x_parity_recover(bp);
  8279. rtnl_unlock();
  8280. return;
  8281. }
  8282. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  8283. #ifdef BNX2X_STOP_ON_ERROR
  8284. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8285. "you will need to reboot when done\n");
  8286. goto sp_rtnl_not_reset;
  8287. #endif
  8288. /*
  8289. * Clear all pending SP commands as we are going to reset the
  8290. * function anyway.
  8291. */
  8292. bp->sp_rtnl_state = 0;
  8293. smp_mb();
  8294. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  8295. bnx2x_nic_load(bp, LOAD_NORMAL);
  8296. rtnl_unlock();
  8297. return;
  8298. }
  8299. #ifdef BNX2X_STOP_ON_ERROR
  8300. sp_rtnl_not_reset:
  8301. #endif
  8302. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  8303. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  8304. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  8305. bnx2x_after_function_update(bp);
  8306. /*
  8307. * in case of fan failure we need to reset id if the "stop on error"
  8308. * debug flag is set, since we trying to prevent permanent overheating
  8309. * damage
  8310. */
  8311. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  8312. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  8313. netif_device_detach(bp->dev);
  8314. bnx2x_close(bp->dev);
  8315. rtnl_unlock();
  8316. return;
  8317. }
  8318. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  8319. DP(BNX2X_MSG_SP,
  8320. "sending set mcast vf pf channel message from rtnl sp-task\n");
  8321. bnx2x_vfpf_set_mcast(bp->dev);
  8322. }
  8323. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
  8324. &bp->sp_rtnl_state)){
  8325. if (!test_bit(__LINK_STATE_NOCARRIER, &bp->dev->state)) {
  8326. bnx2x_tx_disable(bp);
  8327. BNX2X_ERR("PF indicated channel is not servicable anymore. This means this VF device is no longer operational\n");
  8328. }
  8329. }
  8330. if (test_and_clear_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state)) {
  8331. DP(BNX2X_MSG_SP, "Handling Rx Mode setting\n");
  8332. bnx2x_set_rx_mode_inner(bp);
  8333. }
  8334. if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
  8335. &bp->sp_rtnl_state))
  8336. bnx2x_pf_set_vfs_vlan(bp);
  8337. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_STOP, &bp->sp_rtnl_state)) {
  8338. bnx2x_dcbx_stop_hw_tx(bp);
  8339. bnx2x_dcbx_resume_hw_tx(bp);
  8340. }
  8341. if (test_and_clear_bit(BNX2X_SP_RTNL_GET_DRV_VERSION,
  8342. &bp->sp_rtnl_state))
  8343. bnx2x_update_mng_version(bp);
  8344. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  8345. * can be called from other contexts as well)
  8346. */
  8347. rtnl_unlock();
  8348. /* enable SR-IOV if applicable */
  8349. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  8350. &bp->sp_rtnl_state)) {
  8351. bnx2x_disable_sriov(bp);
  8352. bnx2x_enable_sriov(bp);
  8353. }
  8354. }
  8355. static void bnx2x_period_task(struct work_struct *work)
  8356. {
  8357. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  8358. if (!netif_running(bp->dev))
  8359. goto period_task_exit;
  8360. if (CHIP_REV_IS_SLOW(bp)) {
  8361. BNX2X_ERR("period task called on emulation, ignoring\n");
  8362. goto period_task_exit;
  8363. }
  8364. bnx2x_acquire_phy_lock(bp);
  8365. /*
  8366. * The barrier is needed to ensure the ordering between the writing to
  8367. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  8368. * the reading here.
  8369. */
  8370. smp_mb();
  8371. if (bp->port.pmf) {
  8372. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  8373. /* Re-queue task in 1 sec */
  8374. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  8375. }
  8376. bnx2x_release_phy_lock(bp);
  8377. period_task_exit:
  8378. return;
  8379. }
  8380. /*
  8381. * Init service functions
  8382. */
  8383. static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  8384. {
  8385. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  8386. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  8387. return base + (BP_ABS_FUNC(bp)) * stride;
  8388. }
  8389. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  8390. struct bnx2x_mac_vals *vals)
  8391. {
  8392. u32 val, base_addr, offset, mask, reset_reg;
  8393. bool mac_stopped = false;
  8394. u8 port = BP_PORT(bp);
  8395. /* reset addresses as they also mark which values were changed */
  8396. vals->bmac_addr = 0;
  8397. vals->umac_addr = 0;
  8398. vals->xmac_addr = 0;
  8399. vals->emac_addr = 0;
  8400. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  8401. if (!CHIP_IS_E3(bp)) {
  8402. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  8403. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  8404. if ((mask & reset_reg) && val) {
  8405. u32 wb_data[2];
  8406. BNX2X_DEV_INFO("Disable bmac Rx\n");
  8407. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  8408. : NIG_REG_INGRESS_BMAC0_MEM;
  8409. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  8410. : BIGMAC_REGISTER_BMAC_CONTROL;
  8411. /*
  8412. * use rd/wr since we cannot use dmae. This is safe
  8413. * since MCP won't access the bus due to the request
  8414. * to unload, and no function on the path can be
  8415. * loaded at this time.
  8416. */
  8417. wb_data[0] = REG_RD(bp, base_addr + offset);
  8418. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8419. vals->bmac_addr = base_addr + offset;
  8420. vals->bmac_val[0] = wb_data[0];
  8421. vals->bmac_val[1] = wb_data[1];
  8422. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8423. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8424. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8425. }
  8426. BNX2X_DEV_INFO("Disable emac Rx\n");
  8427. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8428. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8429. REG_WR(bp, vals->emac_addr, 0);
  8430. mac_stopped = true;
  8431. } else {
  8432. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8433. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8434. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8435. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8436. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8437. val & ~(1 << 1));
  8438. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8439. val | (1 << 1));
  8440. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8441. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8442. REG_WR(bp, vals->xmac_addr, 0);
  8443. mac_stopped = true;
  8444. }
  8445. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8446. if (mask & reset_reg) {
  8447. BNX2X_DEV_INFO("Disable umac Rx\n");
  8448. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8449. vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
  8450. vals->umac_val = REG_RD(bp, vals->umac_addr);
  8451. REG_WR(bp, vals->umac_addr, 0);
  8452. mac_stopped = true;
  8453. }
  8454. }
  8455. if (mac_stopped)
  8456. msleep(20);
  8457. }
  8458. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8459. #define BNX2X_PREV_UNDI_PROD_ADDR_H(f) (BAR_TSTRORM_INTMEM + \
  8460. 0x1848 + ((f) << 4))
  8461. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8462. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8463. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8464. #define BCM_5710_UNDI_FW_MF_MAJOR (0x07)
  8465. #define BCM_5710_UNDI_FW_MF_MINOR (0x08)
  8466. #define BCM_5710_UNDI_FW_MF_VERS (0x05)
  8467. static bool bnx2x_prev_is_after_undi(struct bnx2x *bp)
  8468. {
  8469. /* UNDI marks its presence in DORQ -
  8470. * it initializes CID offset for normal bell to 0x7
  8471. */
  8472. if (!(REG_RD(bp, MISC_REG_RESET_REG_1) &
  8473. MISC_REGISTERS_RESET_REG_1_RST_DORQ))
  8474. return false;
  8475. if (REG_RD(bp, DORQ_REG_NORM_CID_OFST) == 0x7) {
  8476. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8477. return true;
  8478. }
  8479. return false;
  8480. }
  8481. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 inc)
  8482. {
  8483. u16 rcq, bd;
  8484. u32 addr, tmp_reg;
  8485. if (BP_FUNC(bp) < 2)
  8486. addr = BNX2X_PREV_UNDI_PROD_ADDR(BP_PORT(bp));
  8487. else
  8488. addr = BNX2X_PREV_UNDI_PROD_ADDR_H(BP_FUNC(bp) - 2);
  8489. tmp_reg = REG_RD(bp, addr);
  8490. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8491. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8492. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8493. REG_WR(bp, addr, tmp_reg);
  8494. BNX2X_DEV_INFO("UNDI producer [%d/%d][%08x] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8495. BP_PORT(bp), BP_FUNC(bp), addr, bd, rcq);
  8496. }
  8497. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8498. {
  8499. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8500. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8501. if (!rc) {
  8502. BNX2X_ERR("MCP response failure, aborting\n");
  8503. return -EBUSY;
  8504. }
  8505. return 0;
  8506. }
  8507. static struct bnx2x_prev_path_list *
  8508. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8509. {
  8510. struct bnx2x_prev_path_list *tmp_list;
  8511. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8512. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8513. bp->pdev->bus->number == tmp_list->bus &&
  8514. BP_PATH(bp) == tmp_list->path)
  8515. return tmp_list;
  8516. return NULL;
  8517. }
  8518. static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
  8519. {
  8520. struct bnx2x_prev_path_list *tmp_list;
  8521. int rc;
  8522. rc = down_interruptible(&bnx2x_prev_sem);
  8523. if (rc) {
  8524. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8525. return rc;
  8526. }
  8527. tmp_list = bnx2x_prev_path_get_entry(bp);
  8528. if (tmp_list) {
  8529. tmp_list->aer = 1;
  8530. rc = 0;
  8531. } else {
  8532. BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
  8533. BP_PATH(bp));
  8534. }
  8535. up(&bnx2x_prev_sem);
  8536. return rc;
  8537. }
  8538. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8539. {
  8540. struct bnx2x_prev_path_list *tmp_list;
  8541. bool rc = false;
  8542. if (down_trylock(&bnx2x_prev_sem))
  8543. return false;
  8544. tmp_list = bnx2x_prev_path_get_entry(bp);
  8545. if (tmp_list) {
  8546. if (tmp_list->aer) {
  8547. DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
  8548. BP_PATH(bp));
  8549. } else {
  8550. rc = true;
  8551. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8552. BP_PATH(bp));
  8553. }
  8554. }
  8555. up(&bnx2x_prev_sem);
  8556. return rc;
  8557. }
  8558. bool bnx2x_port_after_undi(struct bnx2x *bp)
  8559. {
  8560. struct bnx2x_prev_path_list *entry;
  8561. bool val;
  8562. down(&bnx2x_prev_sem);
  8563. entry = bnx2x_prev_path_get_entry(bp);
  8564. val = !!(entry && (entry->undi & (1 << BP_PORT(bp))));
  8565. up(&bnx2x_prev_sem);
  8566. return val;
  8567. }
  8568. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8569. {
  8570. struct bnx2x_prev_path_list *tmp_list;
  8571. int rc;
  8572. rc = down_interruptible(&bnx2x_prev_sem);
  8573. if (rc) {
  8574. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8575. return rc;
  8576. }
  8577. /* Check whether the entry for this path already exists */
  8578. tmp_list = bnx2x_prev_path_get_entry(bp);
  8579. if (tmp_list) {
  8580. if (!tmp_list->aer) {
  8581. BNX2X_ERR("Re-Marking the path.\n");
  8582. } else {
  8583. DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
  8584. BP_PATH(bp));
  8585. tmp_list->aer = 0;
  8586. }
  8587. up(&bnx2x_prev_sem);
  8588. return 0;
  8589. }
  8590. up(&bnx2x_prev_sem);
  8591. /* Create an entry for this path and add it */
  8592. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8593. if (!tmp_list) {
  8594. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8595. return -ENOMEM;
  8596. }
  8597. tmp_list->bus = bp->pdev->bus->number;
  8598. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8599. tmp_list->path = BP_PATH(bp);
  8600. tmp_list->aer = 0;
  8601. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8602. rc = down_interruptible(&bnx2x_prev_sem);
  8603. if (rc) {
  8604. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8605. kfree(tmp_list);
  8606. } else {
  8607. DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
  8608. BP_PATH(bp));
  8609. list_add(&tmp_list->list, &bnx2x_prev_list);
  8610. up(&bnx2x_prev_sem);
  8611. }
  8612. return rc;
  8613. }
  8614. static int bnx2x_do_flr(struct bnx2x *bp)
  8615. {
  8616. struct pci_dev *dev = bp->pdev;
  8617. if (CHIP_IS_E1x(bp)) {
  8618. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8619. return -EINVAL;
  8620. }
  8621. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8622. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8623. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8624. bp->common.bc_ver);
  8625. return -EINVAL;
  8626. }
  8627. if (!pci_wait_for_pending_transaction(dev))
  8628. dev_err(&dev->dev, "transaction is not cleared; proceeding with reset anyway\n");
  8629. BNX2X_DEV_INFO("Initiating FLR\n");
  8630. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8631. return 0;
  8632. }
  8633. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8634. {
  8635. int rc;
  8636. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8637. /* Test if previous unload process was already finished for this path */
  8638. if (bnx2x_prev_is_path_marked(bp))
  8639. return bnx2x_prev_mcp_done(bp);
  8640. BNX2X_DEV_INFO("Path is unmarked\n");
  8641. /* Cannot proceed with FLR if UNDI is loaded, since FW does not match */
  8642. if (bnx2x_prev_is_after_undi(bp))
  8643. goto out;
  8644. /* If function has FLR capabilities, and existing FW version matches
  8645. * the one required, then FLR will be sufficient to clean any residue
  8646. * left by previous driver
  8647. */
  8648. rc = bnx2x_compare_fw_ver(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION, false);
  8649. if (!rc) {
  8650. /* fw version is good */
  8651. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8652. rc = bnx2x_do_flr(bp);
  8653. }
  8654. if (!rc) {
  8655. /* FLR was performed */
  8656. BNX2X_DEV_INFO("FLR successful\n");
  8657. return 0;
  8658. }
  8659. BNX2X_DEV_INFO("Could not FLR\n");
  8660. out:
  8661. /* Close the MCP request, return failure*/
  8662. rc = bnx2x_prev_mcp_done(bp);
  8663. if (!rc)
  8664. rc = BNX2X_PREV_WAIT_NEEDED;
  8665. return rc;
  8666. }
  8667. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  8668. {
  8669. u32 reset_reg, tmp_reg = 0, rc;
  8670. bool prev_undi = false;
  8671. struct bnx2x_mac_vals mac_vals;
  8672. /* It is possible a previous function received 'common' answer,
  8673. * but hasn't loaded yet, therefore creating a scenario of
  8674. * multiple functions receiving 'common' on the same path.
  8675. */
  8676. BNX2X_DEV_INFO("Common unload Flow\n");
  8677. memset(&mac_vals, 0, sizeof(mac_vals));
  8678. if (bnx2x_prev_is_path_marked(bp))
  8679. return bnx2x_prev_mcp_done(bp);
  8680. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8681. /* Reset should be performed after BRB is emptied */
  8682. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8683. u32 timer_count = 1000;
  8684. /* Close the MAC Rx to prevent BRB from filling up */
  8685. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  8686. /* close LLH filters towards the BRB */
  8687. bnx2x_set_rx_filter(&bp->link_params, 0);
  8688. /* Check if the UNDI driver was previously loaded */
  8689. if (bnx2x_prev_is_after_undi(bp)) {
  8690. prev_undi = true;
  8691. /* clear the UNDI indication */
  8692. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8693. /* clear possible idle check errors */
  8694. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  8695. }
  8696. if (!CHIP_IS_E1x(bp))
  8697. /* block FW from writing to host */
  8698. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  8699. /* wait until BRB is empty */
  8700. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8701. while (timer_count) {
  8702. u32 prev_brb = tmp_reg;
  8703. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8704. if (!tmp_reg)
  8705. break;
  8706. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8707. /* reset timer as long as BRB actually gets emptied */
  8708. if (prev_brb > tmp_reg)
  8709. timer_count = 1000;
  8710. else
  8711. timer_count--;
  8712. /* If UNDI resides in memory, manually increment it */
  8713. if (prev_undi)
  8714. bnx2x_prev_unload_undi_inc(bp, 1);
  8715. udelay(10);
  8716. }
  8717. if (!timer_count)
  8718. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8719. }
  8720. /* No packets are in the pipeline, path is ready for reset */
  8721. bnx2x_reset_common(bp);
  8722. if (mac_vals.xmac_addr)
  8723. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  8724. if (mac_vals.umac_addr)
  8725. REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
  8726. if (mac_vals.emac_addr)
  8727. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  8728. if (mac_vals.bmac_addr) {
  8729. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  8730. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  8731. }
  8732. rc = bnx2x_prev_mark_path(bp, prev_undi);
  8733. if (rc) {
  8734. bnx2x_prev_mcp_done(bp);
  8735. return rc;
  8736. }
  8737. return bnx2x_prev_mcp_done(bp);
  8738. }
  8739. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  8740. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  8741. * the addresses of the transaction, resulting in was-error bit set in the pci
  8742. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  8743. * to clear the interrupt which detected this from the pglueb and the was done
  8744. * bit
  8745. */
  8746. static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  8747. {
  8748. if (!CHIP_IS_E1x(bp)) {
  8749. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  8750. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  8751. DP(BNX2X_MSG_SP,
  8752. "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
  8753. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  8754. 1 << BP_FUNC(bp));
  8755. }
  8756. }
  8757. }
  8758. static int bnx2x_prev_unload(struct bnx2x *bp)
  8759. {
  8760. int time_counter = 10;
  8761. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8762. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8763. /* clear hw from errors which may have resulted from an interrupted
  8764. * dmae transaction.
  8765. */
  8766. bnx2x_prev_interrupted_dmae(bp);
  8767. /* Release previously held locks */
  8768. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8769. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8770. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8771. hw_lock_val = REG_RD(bp, hw_lock_reg);
  8772. if (hw_lock_val) {
  8773. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8774. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8775. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8776. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8777. }
  8778. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8779. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8780. } else
  8781. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8782. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8783. BNX2X_DEV_INFO("Release previously held alr\n");
  8784. bnx2x_release_alr(bp);
  8785. }
  8786. do {
  8787. int aer = 0;
  8788. /* Lock MCP using an unload request */
  8789. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8790. if (!fw) {
  8791. BNX2X_ERR("MCP response failure, aborting\n");
  8792. rc = -EBUSY;
  8793. break;
  8794. }
  8795. rc = down_interruptible(&bnx2x_prev_sem);
  8796. if (rc) {
  8797. BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
  8798. rc);
  8799. } else {
  8800. /* If Path is marked by EEH, ignore unload status */
  8801. aer = !!(bnx2x_prev_path_get_entry(bp) &&
  8802. bnx2x_prev_path_get_entry(bp)->aer);
  8803. up(&bnx2x_prev_sem);
  8804. }
  8805. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
  8806. rc = bnx2x_prev_unload_common(bp);
  8807. break;
  8808. }
  8809. /* non-common reply from MCP might require looping */
  8810. rc = bnx2x_prev_unload_uncommon(bp);
  8811. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8812. break;
  8813. msleep(20);
  8814. } while (--time_counter);
  8815. if (!time_counter || rc) {
  8816. BNX2X_DEV_INFO("Unloading previous driver did not occur, Possibly due to MF UNDI\n");
  8817. rc = -EPROBE_DEFER;
  8818. }
  8819. /* Mark function if its port was used to boot from SAN */
  8820. if (bnx2x_port_after_undi(bp))
  8821. bp->link_params.feature_config_flags |=
  8822. FEATURE_CONFIG_BOOT_FROM_SAN;
  8823. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8824. return rc;
  8825. }
  8826. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8827. {
  8828. u32 val, val2, val3, val4, id, boot_mode;
  8829. u16 pmc;
  8830. /* Get the chip revision id and number. */
  8831. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8832. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8833. id = ((val & 0xffff) << 16);
  8834. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8835. id |= ((val & 0xf) << 12);
  8836. /* Metal is read from PCI regs, but we can't access >=0x400 from
  8837. * the configuration space (so we need to reg_rd)
  8838. */
  8839. val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
  8840. id |= (((val >> 24) & 0xf) << 4);
  8841. val = REG_RD(bp, MISC_REG_BOND_ID);
  8842. id |= (val & 0xf);
  8843. bp->common.chip_id = id;
  8844. /* force 57811 according to MISC register */
  8845. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8846. if (CHIP_IS_57810(bp))
  8847. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8848. (bp->common.chip_id & 0x0000FFFF);
  8849. else if (CHIP_IS_57810_MF(bp))
  8850. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8851. (bp->common.chip_id & 0x0000FFFF);
  8852. bp->common.chip_id |= 0x1;
  8853. }
  8854. /* Set doorbell size */
  8855. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8856. if (!CHIP_IS_E1x(bp)) {
  8857. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8858. if ((val & 1) == 0)
  8859. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8860. else
  8861. val = (val >> 1) & 1;
  8862. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8863. "2_PORT_MODE");
  8864. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8865. CHIP_2_PORT_MODE;
  8866. if (CHIP_MODE_IS_4_PORT(bp))
  8867. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8868. else
  8869. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8870. } else {
  8871. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8872. bp->pfid = bp->pf_num; /* 0..7 */
  8873. }
  8874. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8875. bp->link_params.chip_id = bp->common.chip_id;
  8876. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8877. val = (REG_RD(bp, 0x2874) & 0x55);
  8878. if ((bp->common.chip_id & 0x1) ||
  8879. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8880. bp->flags |= ONE_PORT_FLAG;
  8881. BNX2X_DEV_INFO("single port device\n");
  8882. }
  8883. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  8884. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8885. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8886. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8887. bp->common.flash_size, bp->common.flash_size);
  8888. bnx2x_init_shmem(bp);
  8889. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8890. MISC_REG_GENERIC_CR_1 :
  8891. MISC_REG_GENERIC_CR_0));
  8892. bp->link_params.shmem_base = bp->common.shmem_base;
  8893. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8894. if (SHMEM2_RD(bp, size) >
  8895. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  8896. bp->link_params.lfa_base =
  8897. REG_RD(bp, bp->common.shmem2_base +
  8898. (u32)offsetof(struct shmem2_region,
  8899. lfa_host_addr[BP_PORT(bp)]));
  8900. else
  8901. bp->link_params.lfa_base = 0;
  8902. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8903. bp->common.shmem_base, bp->common.shmem2_base);
  8904. if (!bp->common.shmem_base) {
  8905. BNX2X_DEV_INFO("MCP not active\n");
  8906. bp->flags |= NO_MCP_FLAG;
  8907. return;
  8908. }
  8909. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8910. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8911. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8912. SHARED_HW_CFG_LED_MODE_MASK) >>
  8913. SHARED_HW_CFG_LED_MODE_SHIFT);
  8914. bp->link_params.feature_config_flags = 0;
  8915. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8916. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8917. bp->link_params.feature_config_flags |=
  8918. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8919. else
  8920. bp->link_params.feature_config_flags &=
  8921. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8922. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8923. bp->common.bc_ver = val;
  8924. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8925. if (val < BNX2X_BC_VER) {
  8926. /* for now only warn
  8927. * later we might need to enforce this */
  8928. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8929. BNX2X_BC_VER, val);
  8930. }
  8931. bp->link_params.feature_config_flags |=
  8932. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8933. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8934. bp->link_params.feature_config_flags |=
  8935. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8936. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8937. bp->link_params.feature_config_flags |=
  8938. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8939. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8940. bp->link_params.feature_config_flags |=
  8941. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8942. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8943. bp->link_params.feature_config_flags |=
  8944. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  8945. FEATURE_CONFIG_MT_SUPPORT : 0;
  8946. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8947. BC_SUPPORTS_PFC_STATS : 0;
  8948. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  8949. BC_SUPPORTS_FCOE_FEATURES : 0;
  8950. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  8951. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  8952. bp->flags |= (val >= REQ_BC_VER_4_RMMOD_CMD) ?
  8953. BC_SUPPORTS_RMMOD_CMD : 0;
  8954. boot_mode = SHMEM_RD(bp,
  8955. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8956. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8957. switch (boot_mode) {
  8958. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8959. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8960. break;
  8961. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8962. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8963. break;
  8964. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  8965. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  8966. break;
  8967. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  8968. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  8969. break;
  8970. }
  8971. pci_read_config_word(bp->pdev, bp->pdev->pm_cap + PCI_PM_PMC, &pmc);
  8972. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  8973. BNX2X_DEV_INFO("%sWoL capable\n",
  8974. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  8975. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  8976. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  8977. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  8978. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  8979. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  8980. val, val2, val3, val4);
  8981. }
  8982. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  8983. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  8984. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  8985. {
  8986. int pfid = BP_FUNC(bp);
  8987. int igu_sb_id;
  8988. u32 val;
  8989. u8 fid, igu_sb_cnt = 0;
  8990. bp->igu_base_sb = 0xff;
  8991. if (CHIP_INT_MODE_IS_BC(bp)) {
  8992. int vn = BP_VN(bp);
  8993. igu_sb_cnt = bp->igu_sb_cnt;
  8994. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  8995. FP_SB_MAX_E1x;
  8996. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  8997. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  8998. return 0;
  8999. }
  9000. /* IGU in normal mode - read CAM */
  9001. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  9002. igu_sb_id++) {
  9003. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  9004. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  9005. continue;
  9006. fid = IGU_FID(val);
  9007. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  9008. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  9009. continue;
  9010. if (IGU_VEC(val) == 0)
  9011. /* default status block */
  9012. bp->igu_dsb_id = igu_sb_id;
  9013. else {
  9014. if (bp->igu_base_sb == 0xff)
  9015. bp->igu_base_sb = igu_sb_id;
  9016. igu_sb_cnt++;
  9017. }
  9018. }
  9019. }
  9020. #ifdef CONFIG_PCI_MSI
  9021. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  9022. * optional that number of CAM entries will not be equal to the value
  9023. * advertised in PCI.
  9024. * Driver should use the minimal value of both as the actual status
  9025. * block count
  9026. */
  9027. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  9028. #endif
  9029. if (igu_sb_cnt == 0) {
  9030. BNX2X_ERR("CAM configuration error\n");
  9031. return -EINVAL;
  9032. }
  9033. return 0;
  9034. }
  9035. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  9036. {
  9037. int cfg_size = 0, idx, port = BP_PORT(bp);
  9038. /* Aggregation of supported attributes of all external phys */
  9039. bp->port.supported[0] = 0;
  9040. bp->port.supported[1] = 0;
  9041. switch (bp->link_params.num_phys) {
  9042. case 1:
  9043. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  9044. cfg_size = 1;
  9045. break;
  9046. case 2:
  9047. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  9048. cfg_size = 1;
  9049. break;
  9050. case 3:
  9051. if (bp->link_params.multi_phy_config &
  9052. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  9053. bp->port.supported[1] =
  9054. bp->link_params.phy[EXT_PHY1].supported;
  9055. bp->port.supported[0] =
  9056. bp->link_params.phy[EXT_PHY2].supported;
  9057. } else {
  9058. bp->port.supported[0] =
  9059. bp->link_params.phy[EXT_PHY1].supported;
  9060. bp->port.supported[1] =
  9061. bp->link_params.phy[EXT_PHY2].supported;
  9062. }
  9063. cfg_size = 2;
  9064. break;
  9065. }
  9066. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  9067. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  9068. SHMEM_RD(bp,
  9069. dev_info.port_hw_config[port].external_phy_config),
  9070. SHMEM_RD(bp,
  9071. dev_info.port_hw_config[port].external_phy_config2));
  9072. return;
  9073. }
  9074. if (CHIP_IS_E3(bp))
  9075. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  9076. else {
  9077. switch (switch_cfg) {
  9078. case SWITCH_CFG_1G:
  9079. bp->port.phy_addr = REG_RD(
  9080. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  9081. break;
  9082. case SWITCH_CFG_10G:
  9083. bp->port.phy_addr = REG_RD(
  9084. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  9085. break;
  9086. default:
  9087. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  9088. bp->port.link_config[0]);
  9089. return;
  9090. }
  9091. }
  9092. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  9093. /* mask what we support according to speed_cap_mask per configuration */
  9094. for (idx = 0; idx < cfg_size; idx++) {
  9095. if (!(bp->link_params.speed_cap_mask[idx] &
  9096. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  9097. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  9098. if (!(bp->link_params.speed_cap_mask[idx] &
  9099. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  9100. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  9101. if (!(bp->link_params.speed_cap_mask[idx] &
  9102. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  9103. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  9104. if (!(bp->link_params.speed_cap_mask[idx] &
  9105. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  9106. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  9107. if (!(bp->link_params.speed_cap_mask[idx] &
  9108. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  9109. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  9110. SUPPORTED_1000baseT_Full);
  9111. if (!(bp->link_params.speed_cap_mask[idx] &
  9112. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  9113. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  9114. if (!(bp->link_params.speed_cap_mask[idx] &
  9115. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  9116. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  9117. if (!(bp->link_params.speed_cap_mask[idx] &
  9118. PORT_HW_CFG_SPEED_CAPABILITY_D0_20G))
  9119. bp->port.supported[idx] &= ~SUPPORTED_20000baseKR2_Full;
  9120. }
  9121. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  9122. bp->port.supported[1]);
  9123. }
  9124. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  9125. {
  9126. u32 link_config, idx, cfg_size = 0;
  9127. bp->port.advertising[0] = 0;
  9128. bp->port.advertising[1] = 0;
  9129. switch (bp->link_params.num_phys) {
  9130. case 1:
  9131. case 2:
  9132. cfg_size = 1;
  9133. break;
  9134. case 3:
  9135. cfg_size = 2;
  9136. break;
  9137. }
  9138. for (idx = 0; idx < cfg_size; idx++) {
  9139. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  9140. link_config = bp->port.link_config[idx];
  9141. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  9142. case PORT_FEATURE_LINK_SPEED_AUTO:
  9143. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  9144. bp->link_params.req_line_speed[idx] =
  9145. SPEED_AUTO_NEG;
  9146. bp->port.advertising[idx] |=
  9147. bp->port.supported[idx];
  9148. if (bp->link_params.phy[EXT_PHY1].type ==
  9149. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  9150. bp->port.advertising[idx] |=
  9151. (SUPPORTED_100baseT_Half |
  9152. SUPPORTED_100baseT_Full);
  9153. } else {
  9154. /* force 10G, no AN */
  9155. bp->link_params.req_line_speed[idx] =
  9156. SPEED_10000;
  9157. bp->port.advertising[idx] |=
  9158. (ADVERTISED_10000baseT_Full |
  9159. ADVERTISED_FIBRE);
  9160. continue;
  9161. }
  9162. break;
  9163. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  9164. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  9165. bp->link_params.req_line_speed[idx] =
  9166. SPEED_10;
  9167. bp->port.advertising[idx] |=
  9168. (ADVERTISED_10baseT_Full |
  9169. ADVERTISED_TP);
  9170. } else {
  9171. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9172. link_config,
  9173. bp->link_params.speed_cap_mask[idx]);
  9174. return;
  9175. }
  9176. break;
  9177. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  9178. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  9179. bp->link_params.req_line_speed[idx] =
  9180. SPEED_10;
  9181. bp->link_params.req_duplex[idx] =
  9182. DUPLEX_HALF;
  9183. bp->port.advertising[idx] |=
  9184. (ADVERTISED_10baseT_Half |
  9185. ADVERTISED_TP);
  9186. } else {
  9187. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9188. link_config,
  9189. bp->link_params.speed_cap_mask[idx]);
  9190. return;
  9191. }
  9192. break;
  9193. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  9194. if (bp->port.supported[idx] &
  9195. SUPPORTED_100baseT_Full) {
  9196. bp->link_params.req_line_speed[idx] =
  9197. SPEED_100;
  9198. bp->port.advertising[idx] |=
  9199. (ADVERTISED_100baseT_Full |
  9200. ADVERTISED_TP);
  9201. } else {
  9202. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9203. link_config,
  9204. bp->link_params.speed_cap_mask[idx]);
  9205. return;
  9206. }
  9207. break;
  9208. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  9209. if (bp->port.supported[idx] &
  9210. SUPPORTED_100baseT_Half) {
  9211. bp->link_params.req_line_speed[idx] =
  9212. SPEED_100;
  9213. bp->link_params.req_duplex[idx] =
  9214. DUPLEX_HALF;
  9215. bp->port.advertising[idx] |=
  9216. (ADVERTISED_100baseT_Half |
  9217. ADVERTISED_TP);
  9218. } else {
  9219. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9220. link_config,
  9221. bp->link_params.speed_cap_mask[idx]);
  9222. return;
  9223. }
  9224. break;
  9225. case PORT_FEATURE_LINK_SPEED_1G:
  9226. if (bp->port.supported[idx] &
  9227. SUPPORTED_1000baseT_Full) {
  9228. bp->link_params.req_line_speed[idx] =
  9229. SPEED_1000;
  9230. bp->port.advertising[idx] |=
  9231. (ADVERTISED_1000baseT_Full |
  9232. ADVERTISED_TP);
  9233. } else {
  9234. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9235. link_config,
  9236. bp->link_params.speed_cap_mask[idx]);
  9237. return;
  9238. }
  9239. break;
  9240. case PORT_FEATURE_LINK_SPEED_2_5G:
  9241. if (bp->port.supported[idx] &
  9242. SUPPORTED_2500baseX_Full) {
  9243. bp->link_params.req_line_speed[idx] =
  9244. SPEED_2500;
  9245. bp->port.advertising[idx] |=
  9246. (ADVERTISED_2500baseX_Full |
  9247. ADVERTISED_TP);
  9248. } else {
  9249. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9250. link_config,
  9251. bp->link_params.speed_cap_mask[idx]);
  9252. return;
  9253. }
  9254. break;
  9255. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  9256. if (bp->port.supported[idx] &
  9257. SUPPORTED_10000baseT_Full) {
  9258. bp->link_params.req_line_speed[idx] =
  9259. SPEED_10000;
  9260. bp->port.advertising[idx] |=
  9261. (ADVERTISED_10000baseT_Full |
  9262. ADVERTISED_FIBRE);
  9263. } else {
  9264. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9265. link_config,
  9266. bp->link_params.speed_cap_mask[idx]);
  9267. return;
  9268. }
  9269. break;
  9270. case PORT_FEATURE_LINK_SPEED_20G:
  9271. bp->link_params.req_line_speed[idx] = SPEED_20000;
  9272. break;
  9273. default:
  9274. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  9275. link_config);
  9276. bp->link_params.req_line_speed[idx] =
  9277. SPEED_AUTO_NEG;
  9278. bp->port.advertising[idx] =
  9279. bp->port.supported[idx];
  9280. break;
  9281. }
  9282. bp->link_params.req_flow_ctrl[idx] = (link_config &
  9283. PORT_FEATURE_FLOW_CONTROL_MASK);
  9284. if (bp->link_params.req_flow_ctrl[idx] ==
  9285. BNX2X_FLOW_CTRL_AUTO) {
  9286. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  9287. bp->link_params.req_flow_ctrl[idx] =
  9288. BNX2X_FLOW_CTRL_NONE;
  9289. else
  9290. bnx2x_set_requested_fc(bp);
  9291. }
  9292. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  9293. bp->link_params.req_line_speed[idx],
  9294. bp->link_params.req_duplex[idx],
  9295. bp->link_params.req_flow_ctrl[idx],
  9296. bp->port.advertising[idx]);
  9297. }
  9298. }
  9299. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  9300. {
  9301. __be16 mac_hi_be = cpu_to_be16(mac_hi);
  9302. __be32 mac_lo_be = cpu_to_be32(mac_lo);
  9303. memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
  9304. memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
  9305. }
  9306. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  9307. {
  9308. int port = BP_PORT(bp);
  9309. u32 config;
  9310. u32 ext_phy_type, ext_phy_config, eee_mode;
  9311. bp->link_params.bp = bp;
  9312. bp->link_params.port = port;
  9313. bp->link_params.lane_config =
  9314. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  9315. bp->link_params.speed_cap_mask[0] =
  9316. SHMEM_RD(bp,
  9317. dev_info.port_hw_config[port].speed_capability_mask) &
  9318. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9319. bp->link_params.speed_cap_mask[1] =
  9320. SHMEM_RD(bp,
  9321. dev_info.port_hw_config[port].speed_capability_mask2) &
  9322. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9323. bp->port.link_config[0] =
  9324. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  9325. bp->port.link_config[1] =
  9326. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  9327. bp->link_params.multi_phy_config =
  9328. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  9329. /* If the device is capable of WoL, set the default state according
  9330. * to the HW
  9331. */
  9332. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  9333. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  9334. (config & PORT_FEATURE_WOL_ENABLED));
  9335. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9336. PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
  9337. bp->flags |= NO_ISCSI_FLAG;
  9338. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9339. PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
  9340. bp->flags |= NO_FCOE_FLAG;
  9341. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  9342. bp->link_params.lane_config,
  9343. bp->link_params.speed_cap_mask[0],
  9344. bp->port.link_config[0]);
  9345. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  9346. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  9347. bnx2x_phy_probe(&bp->link_params);
  9348. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  9349. bnx2x_link_settings_requested(bp);
  9350. /*
  9351. * If connected directly, work with the internal PHY, otherwise, work
  9352. * with the external PHY
  9353. */
  9354. ext_phy_config =
  9355. SHMEM_RD(bp,
  9356. dev_info.port_hw_config[port].external_phy_config);
  9357. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  9358. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  9359. bp->mdio.prtad = bp->port.phy_addr;
  9360. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  9361. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  9362. bp->mdio.prtad =
  9363. XGXS_EXT_PHY_ADDR(ext_phy_config);
  9364. /* Configure link feature according to nvram value */
  9365. eee_mode = (((SHMEM_RD(bp, dev_info.
  9366. port_feature_config[port].eee_power_mode)) &
  9367. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  9368. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  9369. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  9370. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  9371. EEE_MODE_ENABLE_LPI |
  9372. EEE_MODE_OUTPUT_TIME;
  9373. } else {
  9374. bp->link_params.eee_mode = 0;
  9375. }
  9376. }
  9377. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  9378. {
  9379. u32 no_flags = NO_ISCSI_FLAG;
  9380. int port = BP_PORT(bp);
  9381. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9382. drv_lic_key[port].max_iscsi_conn);
  9383. if (!CNIC_SUPPORT(bp)) {
  9384. bp->flags |= no_flags;
  9385. return;
  9386. }
  9387. /* Get the number of maximum allowed iSCSI connections */
  9388. bp->cnic_eth_dev.max_iscsi_conn =
  9389. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  9390. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  9391. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  9392. bp->cnic_eth_dev.max_iscsi_conn);
  9393. /*
  9394. * If maximum allowed number of connections is zero -
  9395. * disable the feature.
  9396. */
  9397. if (!bp->cnic_eth_dev.max_iscsi_conn)
  9398. bp->flags |= no_flags;
  9399. }
  9400. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  9401. {
  9402. /* Port info */
  9403. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9404. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  9405. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9406. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  9407. /* Node info */
  9408. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9409. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  9410. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9411. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  9412. }
  9413. static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp)
  9414. {
  9415. u8 count = 0;
  9416. if (IS_MF(bp)) {
  9417. u8 fid;
  9418. /* iterate over absolute function ids for this path: */
  9419. for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) {
  9420. if (IS_MF_SD(bp)) {
  9421. u32 cfg = MF_CFG_RD(bp,
  9422. func_mf_config[fid].config);
  9423. if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) &&
  9424. ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) ==
  9425. FUNC_MF_CFG_PROTOCOL_FCOE))
  9426. count++;
  9427. } else {
  9428. u32 cfg = MF_CFG_RD(bp,
  9429. func_ext_config[fid].
  9430. func_cfg);
  9431. if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) &&
  9432. (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
  9433. count++;
  9434. }
  9435. }
  9436. } else { /* SF */
  9437. int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1;
  9438. for (port = 0; port < port_cnt; port++) {
  9439. u32 lic = SHMEM_RD(bp,
  9440. drv_lic_key[port].max_fcoe_conn) ^
  9441. FW_ENCODE_32BIT_PATTERN;
  9442. if (lic)
  9443. count++;
  9444. }
  9445. }
  9446. return count;
  9447. }
  9448. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  9449. {
  9450. int port = BP_PORT(bp);
  9451. int func = BP_ABS_FUNC(bp);
  9452. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9453. drv_lic_key[port].max_fcoe_conn);
  9454. u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp);
  9455. if (!CNIC_SUPPORT(bp)) {
  9456. bp->flags |= NO_FCOE_FLAG;
  9457. return;
  9458. }
  9459. /* Get the number of maximum allowed FCoE connections */
  9460. bp->cnic_eth_dev.max_fcoe_conn =
  9461. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  9462. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  9463. /* Calculate the number of maximum allowed FCoE tasks */
  9464. bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE;
  9465. /* check if FCoE resources must be shared between different functions */
  9466. if (num_fcoe_func)
  9467. bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func;
  9468. /* Read the WWN: */
  9469. if (!IS_MF(bp)) {
  9470. /* Port info */
  9471. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9472. SHMEM_RD(bp,
  9473. dev_info.port_hw_config[port].
  9474. fcoe_wwn_port_name_upper);
  9475. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9476. SHMEM_RD(bp,
  9477. dev_info.port_hw_config[port].
  9478. fcoe_wwn_port_name_lower);
  9479. /* Node info */
  9480. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9481. SHMEM_RD(bp,
  9482. dev_info.port_hw_config[port].
  9483. fcoe_wwn_node_name_upper);
  9484. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9485. SHMEM_RD(bp,
  9486. dev_info.port_hw_config[port].
  9487. fcoe_wwn_node_name_lower);
  9488. } else if (!IS_MF_SD(bp)) {
  9489. /*
  9490. * Read the WWN info only if the FCoE feature is enabled for
  9491. * this function.
  9492. */
  9493. if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  9494. bnx2x_get_ext_wwn_info(bp, func);
  9495. } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
  9496. bnx2x_get_ext_wwn_info(bp, func);
  9497. }
  9498. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  9499. /*
  9500. * If maximum allowed number of connections is zero -
  9501. * disable the feature.
  9502. */
  9503. if (!bp->cnic_eth_dev.max_fcoe_conn)
  9504. bp->flags |= NO_FCOE_FLAG;
  9505. }
  9506. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  9507. {
  9508. /*
  9509. * iSCSI may be dynamically disabled but reading
  9510. * info here we will decrease memory usage by driver
  9511. * if the feature is disabled for good
  9512. */
  9513. bnx2x_get_iscsi_info(bp);
  9514. bnx2x_get_fcoe_info(bp);
  9515. }
  9516. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  9517. {
  9518. u32 val, val2;
  9519. int func = BP_ABS_FUNC(bp);
  9520. int port = BP_PORT(bp);
  9521. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  9522. u8 *fip_mac = bp->fip_mac;
  9523. if (IS_MF(bp)) {
  9524. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  9525. * FCoE MAC then the appropriate feature should be disabled.
  9526. * In non SD mode features configuration comes from struct
  9527. * func_ext_config.
  9528. */
  9529. if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
  9530. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  9531. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  9532. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9533. iscsi_mac_addr_upper);
  9534. val = MF_CFG_RD(bp, func_ext_config[func].
  9535. iscsi_mac_addr_lower);
  9536. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9537. BNX2X_DEV_INFO
  9538. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9539. } else {
  9540. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9541. }
  9542. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  9543. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9544. fcoe_mac_addr_upper);
  9545. val = MF_CFG_RD(bp, func_ext_config[func].
  9546. fcoe_mac_addr_lower);
  9547. bnx2x_set_mac_buf(fip_mac, val, val2);
  9548. BNX2X_DEV_INFO
  9549. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  9550. } else {
  9551. bp->flags |= NO_FCOE_FLAG;
  9552. }
  9553. bp->mf_ext_config = cfg;
  9554. } else { /* SD MODE */
  9555. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9556. /* use primary mac as iscsi mac */
  9557. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9558. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9559. BNX2X_DEV_INFO
  9560. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9561. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9562. /* use primary mac as fip mac */
  9563. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9564. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9565. BNX2X_DEV_INFO
  9566. ("Read FIP MAC: %pM\n", fip_mac);
  9567. }
  9568. }
  9569. /* If this is a storage-only interface, use SAN mac as
  9570. * primary MAC. Notice that for SD this is already the case,
  9571. * as the SAN mac was copied from the primary MAC.
  9572. */
  9573. if (IS_MF_FCOE_AFEX(bp))
  9574. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9575. } else {
  9576. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9577. iscsi_mac_upper);
  9578. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9579. iscsi_mac_lower);
  9580. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9581. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9582. fcoe_fip_mac_upper);
  9583. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9584. fcoe_fip_mac_lower);
  9585. bnx2x_set_mac_buf(fip_mac, val, val2);
  9586. }
  9587. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9588. if (!is_valid_ether_addr(iscsi_mac)) {
  9589. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9590. memset(iscsi_mac, 0, ETH_ALEN);
  9591. }
  9592. /* Disable FCoE if MAC configuration is invalid. */
  9593. if (!is_valid_ether_addr(fip_mac)) {
  9594. bp->flags |= NO_FCOE_FLAG;
  9595. memset(bp->fip_mac, 0, ETH_ALEN);
  9596. }
  9597. }
  9598. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9599. {
  9600. u32 val, val2;
  9601. int func = BP_ABS_FUNC(bp);
  9602. int port = BP_PORT(bp);
  9603. /* Zero primary MAC configuration */
  9604. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9605. if (BP_NOMCP(bp)) {
  9606. BNX2X_ERROR("warning: random MAC workaround active\n");
  9607. eth_hw_addr_random(bp->dev);
  9608. } else if (IS_MF(bp)) {
  9609. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9610. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9611. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9612. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9613. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9614. if (CNIC_SUPPORT(bp))
  9615. bnx2x_get_cnic_mac_hwinfo(bp);
  9616. } else {
  9617. /* in SF read MACs from port configuration */
  9618. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9619. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9620. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9621. if (CNIC_SUPPORT(bp))
  9622. bnx2x_get_cnic_mac_hwinfo(bp);
  9623. }
  9624. if (!BP_NOMCP(bp)) {
  9625. /* Read physical port identifier from shmem */
  9626. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9627. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9628. bnx2x_set_mac_buf(bp->phys_port_id, val, val2);
  9629. bp->flags |= HAS_PHYS_PORT_ID;
  9630. }
  9631. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9632. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  9633. dev_err(&bp->pdev->dev,
  9634. "bad Ethernet MAC address configuration: %pM\n"
  9635. "change it manually before bringing up the appropriate network interface\n",
  9636. bp->dev->dev_addr);
  9637. }
  9638. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9639. {
  9640. int tmp;
  9641. u32 cfg;
  9642. if (IS_VF(bp))
  9643. return 0;
  9644. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  9645. /* Take function: tmp = func */
  9646. tmp = BP_ABS_FUNC(bp);
  9647. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  9648. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  9649. } else {
  9650. /* Take port: tmp = port */
  9651. tmp = BP_PORT(bp);
  9652. cfg = SHMEM_RD(bp,
  9653. dev_info.port_hw_config[tmp].generic_features);
  9654. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  9655. }
  9656. return cfg;
  9657. }
  9658. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  9659. {
  9660. int /*abs*/func = BP_ABS_FUNC(bp);
  9661. int vn;
  9662. u32 val = 0;
  9663. int rc = 0;
  9664. bnx2x_get_common_hwinfo(bp);
  9665. /*
  9666. * initialize IGU parameters
  9667. */
  9668. if (CHIP_IS_E1x(bp)) {
  9669. bp->common.int_block = INT_BLOCK_HC;
  9670. bp->igu_dsb_id = DEF_SB_IGU_ID;
  9671. bp->igu_base_sb = 0;
  9672. } else {
  9673. bp->common.int_block = INT_BLOCK_IGU;
  9674. /* do not allow device reset during IGU info processing */
  9675. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9676. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  9677. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9678. int tout = 5000;
  9679. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  9680. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  9681. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  9682. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  9683. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9684. tout--;
  9685. usleep_range(1000, 2000);
  9686. }
  9687. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9688. dev_err(&bp->pdev->dev,
  9689. "FORCING Normal Mode failed!!!\n");
  9690. bnx2x_release_hw_lock(bp,
  9691. HW_LOCK_RESOURCE_RESET);
  9692. return -EPERM;
  9693. }
  9694. }
  9695. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9696. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  9697. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  9698. } else
  9699. BNX2X_DEV_INFO("IGU Normal Mode\n");
  9700. rc = bnx2x_get_igu_cam_info(bp);
  9701. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9702. if (rc)
  9703. return rc;
  9704. }
  9705. /*
  9706. * set base FW non-default (fast path) status block id, this value is
  9707. * used to initialize the fw_sb_id saved on the fp/queue structure to
  9708. * determine the id used by the FW.
  9709. */
  9710. if (CHIP_IS_E1x(bp))
  9711. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  9712. else /*
  9713. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  9714. * the same queue are indicated on the same IGU SB). So we prefer
  9715. * FW and IGU SBs to be the same value.
  9716. */
  9717. bp->base_fw_ndsb = bp->igu_base_sb;
  9718. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  9719. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  9720. bp->igu_sb_cnt, bp->base_fw_ndsb);
  9721. /*
  9722. * Initialize MF configuration
  9723. */
  9724. bp->mf_ov = 0;
  9725. bp->mf_mode = 0;
  9726. vn = BP_VN(bp);
  9727. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  9728. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  9729. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  9730. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  9731. if (SHMEM2_HAS(bp, mf_cfg_addr))
  9732. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  9733. else
  9734. bp->common.mf_cfg_base = bp->common.shmem_base +
  9735. offsetof(struct shmem_region, func_mb) +
  9736. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  9737. /*
  9738. * get mf configuration:
  9739. * 1. Existence of MF configuration
  9740. * 2. MAC address must be legal (check only upper bytes)
  9741. * for Switch-Independent mode;
  9742. * OVLAN must be legal for Switch-Dependent mode
  9743. * 3. SF_MODE configures specific MF mode
  9744. */
  9745. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9746. /* get mf configuration */
  9747. val = SHMEM_RD(bp,
  9748. dev_info.shared_feature_config.config);
  9749. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  9750. switch (val) {
  9751. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  9752. val = MF_CFG_RD(bp, func_mf_config[func].
  9753. mac_upper);
  9754. /* check for legal mac (upper bytes)*/
  9755. if (val != 0xffff) {
  9756. bp->mf_mode = MULTI_FUNCTION_SI;
  9757. bp->mf_config[vn] = MF_CFG_RD(bp,
  9758. func_mf_config[func].config);
  9759. } else
  9760. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9761. break;
  9762. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9763. if ((!CHIP_IS_E1x(bp)) &&
  9764. (MF_CFG_RD(bp, func_mf_config[func].
  9765. mac_upper) != 0xffff) &&
  9766. (SHMEM2_HAS(bp,
  9767. afex_driver_support))) {
  9768. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9769. bp->mf_config[vn] = MF_CFG_RD(bp,
  9770. func_mf_config[func].config);
  9771. } else {
  9772. BNX2X_DEV_INFO("can not configure afex mode\n");
  9773. }
  9774. break;
  9775. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9776. /* get OV configuration */
  9777. val = MF_CFG_RD(bp,
  9778. func_mf_config[FUNC_0].e1hov_tag);
  9779. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9780. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9781. bp->mf_mode = MULTI_FUNCTION_SD;
  9782. bp->mf_config[vn] = MF_CFG_RD(bp,
  9783. func_mf_config[func].config);
  9784. } else
  9785. BNX2X_DEV_INFO("illegal OV for SD\n");
  9786. break;
  9787. case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
  9788. bp->mf_config[vn] = 0;
  9789. break;
  9790. default:
  9791. /* Unknown configuration: reset mf_config */
  9792. bp->mf_config[vn] = 0;
  9793. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9794. }
  9795. }
  9796. BNX2X_DEV_INFO("%s function mode\n",
  9797. IS_MF(bp) ? "multi" : "single");
  9798. switch (bp->mf_mode) {
  9799. case MULTI_FUNCTION_SD:
  9800. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9801. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9802. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9803. bp->mf_ov = val;
  9804. bp->path_has_ovlan = true;
  9805. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9806. func, bp->mf_ov, bp->mf_ov);
  9807. } else {
  9808. dev_err(&bp->pdev->dev,
  9809. "No valid MF OV for func %d, aborting\n",
  9810. func);
  9811. return -EPERM;
  9812. }
  9813. break;
  9814. case MULTI_FUNCTION_AFEX:
  9815. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9816. break;
  9817. case MULTI_FUNCTION_SI:
  9818. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9819. func);
  9820. break;
  9821. default:
  9822. if (vn) {
  9823. dev_err(&bp->pdev->dev,
  9824. "VN %d is in a single function mode, aborting\n",
  9825. vn);
  9826. return -EPERM;
  9827. }
  9828. break;
  9829. }
  9830. /* check if other port on the path needs ovlan:
  9831. * Since MF configuration is shared between ports
  9832. * Possible mixed modes are only
  9833. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9834. */
  9835. if (CHIP_MODE_IS_4_PORT(bp) &&
  9836. !bp->path_has_ovlan &&
  9837. !IS_MF(bp) &&
  9838. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9839. u8 other_port = !BP_PORT(bp);
  9840. u8 other_func = BP_PATH(bp) + 2*other_port;
  9841. val = MF_CFG_RD(bp,
  9842. func_mf_config[other_func].e1hov_tag);
  9843. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  9844. bp->path_has_ovlan = true;
  9845. }
  9846. }
  9847. /* adjust igu_sb_cnt to MF for E1H */
  9848. if (CHIP_IS_E1H(bp) && IS_MF(bp))
  9849. bp->igu_sb_cnt = min_t(u8, bp->igu_sb_cnt, E1H_MAX_MF_SB_COUNT);
  9850. /* port info */
  9851. bnx2x_get_port_hwinfo(bp);
  9852. /* Get MAC addresses */
  9853. bnx2x_get_mac_hwinfo(bp);
  9854. bnx2x_get_cnic_info(bp);
  9855. return rc;
  9856. }
  9857. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  9858. {
  9859. int cnt, i, block_end, rodi;
  9860. char vpd_start[BNX2X_VPD_LEN+1];
  9861. char str_id_reg[VENDOR_ID_LEN+1];
  9862. char str_id_cap[VENDOR_ID_LEN+1];
  9863. char *vpd_data;
  9864. char *vpd_extended_data = NULL;
  9865. u8 len;
  9866. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  9867. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  9868. if (cnt < BNX2X_VPD_LEN)
  9869. goto out_not_found;
  9870. /* VPD RO tag should be first tag after identifier string, hence
  9871. * we should be able to find it in first BNX2X_VPD_LEN chars
  9872. */
  9873. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  9874. PCI_VPD_LRDT_RO_DATA);
  9875. if (i < 0)
  9876. goto out_not_found;
  9877. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  9878. pci_vpd_lrdt_size(&vpd_start[i]);
  9879. i += PCI_VPD_LRDT_TAG_SIZE;
  9880. if (block_end > BNX2X_VPD_LEN) {
  9881. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  9882. if (vpd_extended_data == NULL)
  9883. goto out_not_found;
  9884. /* read rest of vpd image into vpd_extended_data */
  9885. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  9886. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  9887. block_end - BNX2X_VPD_LEN,
  9888. vpd_extended_data + BNX2X_VPD_LEN);
  9889. if (cnt < (block_end - BNX2X_VPD_LEN))
  9890. goto out_not_found;
  9891. vpd_data = vpd_extended_data;
  9892. } else
  9893. vpd_data = vpd_start;
  9894. /* now vpd_data holds full vpd content in both cases */
  9895. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9896. PCI_VPD_RO_KEYWORD_MFR_ID);
  9897. if (rodi < 0)
  9898. goto out_not_found;
  9899. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9900. if (len != VENDOR_ID_LEN)
  9901. goto out_not_found;
  9902. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9903. /* vendor specific info */
  9904. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  9905. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  9906. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  9907. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  9908. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9909. PCI_VPD_RO_KEYWORD_VENDOR0);
  9910. if (rodi >= 0) {
  9911. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9912. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9913. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  9914. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  9915. bp->fw_ver[len] = ' ';
  9916. }
  9917. }
  9918. kfree(vpd_extended_data);
  9919. return;
  9920. }
  9921. out_not_found:
  9922. kfree(vpd_extended_data);
  9923. return;
  9924. }
  9925. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  9926. {
  9927. u32 flags = 0;
  9928. if (CHIP_REV_IS_FPGA(bp))
  9929. SET_FLAGS(flags, MODE_FPGA);
  9930. else if (CHIP_REV_IS_EMUL(bp))
  9931. SET_FLAGS(flags, MODE_EMUL);
  9932. else
  9933. SET_FLAGS(flags, MODE_ASIC);
  9934. if (CHIP_MODE_IS_4_PORT(bp))
  9935. SET_FLAGS(flags, MODE_PORT4);
  9936. else
  9937. SET_FLAGS(flags, MODE_PORT2);
  9938. if (CHIP_IS_E2(bp))
  9939. SET_FLAGS(flags, MODE_E2);
  9940. else if (CHIP_IS_E3(bp)) {
  9941. SET_FLAGS(flags, MODE_E3);
  9942. if (CHIP_REV(bp) == CHIP_REV_Ax)
  9943. SET_FLAGS(flags, MODE_E3_A0);
  9944. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  9945. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  9946. }
  9947. if (IS_MF(bp)) {
  9948. SET_FLAGS(flags, MODE_MF);
  9949. switch (bp->mf_mode) {
  9950. case MULTI_FUNCTION_SD:
  9951. SET_FLAGS(flags, MODE_MF_SD);
  9952. break;
  9953. case MULTI_FUNCTION_SI:
  9954. SET_FLAGS(flags, MODE_MF_SI);
  9955. break;
  9956. case MULTI_FUNCTION_AFEX:
  9957. SET_FLAGS(flags, MODE_MF_AFEX);
  9958. break;
  9959. }
  9960. } else
  9961. SET_FLAGS(flags, MODE_SF);
  9962. #if defined(__LITTLE_ENDIAN)
  9963. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  9964. #else /*(__BIG_ENDIAN)*/
  9965. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  9966. #endif
  9967. INIT_MODE_FLAGS(bp) = flags;
  9968. }
  9969. static int bnx2x_init_bp(struct bnx2x *bp)
  9970. {
  9971. int func;
  9972. int rc;
  9973. mutex_init(&bp->port.phy_mutex);
  9974. mutex_init(&bp->fw_mb_mutex);
  9975. mutex_init(&bp->drv_info_mutex);
  9976. bp->drv_info_mng_owner = false;
  9977. spin_lock_init(&bp->stats_lock);
  9978. sema_init(&bp->stats_sema, 1);
  9979. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  9980. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  9981. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  9982. INIT_DELAYED_WORK(&bp->iov_task, bnx2x_iov_task);
  9983. if (IS_PF(bp)) {
  9984. rc = bnx2x_get_hwinfo(bp);
  9985. if (rc)
  9986. return rc;
  9987. } else {
  9988. eth_zero_addr(bp->dev->dev_addr);
  9989. }
  9990. bnx2x_set_modes_bitmap(bp);
  9991. rc = bnx2x_alloc_mem_bp(bp);
  9992. if (rc)
  9993. return rc;
  9994. bnx2x_read_fwinfo(bp);
  9995. func = BP_FUNC(bp);
  9996. /* need to reset chip if undi was active */
  9997. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  9998. /* init fw_seq */
  9999. bp->fw_seq =
  10000. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  10001. DRV_MSG_SEQ_NUMBER_MASK;
  10002. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  10003. rc = bnx2x_prev_unload(bp);
  10004. if (rc) {
  10005. bnx2x_free_mem_bp(bp);
  10006. return rc;
  10007. }
  10008. }
  10009. if (CHIP_REV_IS_FPGA(bp))
  10010. dev_err(&bp->pdev->dev, "FPGA detected\n");
  10011. if (BP_NOMCP(bp) && (func == 0))
  10012. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  10013. bp->disable_tpa = disable_tpa;
  10014. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  10015. /* Reduce memory usage in kdump environment by disabling TPA */
  10016. bp->disable_tpa |= reset_devices;
  10017. /* Set TPA flags */
  10018. if (bp->disable_tpa) {
  10019. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  10020. bp->dev->features &= ~NETIF_F_LRO;
  10021. } else {
  10022. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  10023. bp->dev->features |= NETIF_F_LRO;
  10024. }
  10025. if (CHIP_IS_E1(bp))
  10026. bp->dropless_fc = 0;
  10027. else
  10028. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  10029. bp->mrrs = mrrs;
  10030. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  10031. if (IS_VF(bp))
  10032. bp->rx_ring_size = MAX_RX_AVAIL;
  10033. /* make sure that the numbers are in the right granularity */
  10034. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  10035. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  10036. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  10037. init_timer(&bp->timer);
  10038. bp->timer.expires = jiffies + bp->current_interval;
  10039. bp->timer.data = (unsigned long) bp;
  10040. bp->timer.function = bnx2x_timer;
  10041. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  10042. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  10043. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  10044. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
  10045. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  10046. bnx2x_dcbx_init_params(bp);
  10047. } else {
  10048. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  10049. }
  10050. if (CHIP_IS_E1x(bp))
  10051. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  10052. else
  10053. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  10054. /* multiple tx priority */
  10055. if (IS_VF(bp))
  10056. bp->max_cos = 1;
  10057. else if (CHIP_IS_E1x(bp))
  10058. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  10059. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  10060. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  10061. else if (CHIP_IS_E3B0(bp))
  10062. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  10063. else
  10064. BNX2X_ERR("unknown chip %x revision %x\n",
  10065. CHIP_NUM(bp), CHIP_REV(bp));
  10066. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  10067. /* We need at least one default status block for slow-path events,
  10068. * second status block for the L2 queue, and a third status block for
  10069. * CNIC if supported.
  10070. */
  10071. if (IS_VF(bp))
  10072. bp->min_msix_vec_cnt = 1;
  10073. else if (CNIC_SUPPORT(bp))
  10074. bp->min_msix_vec_cnt = 3;
  10075. else /* PF w/o cnic */
  10076. bp->min_msix_vec_cnt = 2;
  10077. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  10078. bp->dump_preset_idx = 1;
  10079. return rc;
  10080. }
  10081. /****************************************************************************
  10082. * General service functions
  10083. ****************************************************************************/
  10084. /*
  10085. * net_device service functions
  10086. */
  10087. /* called with rtnl_lock */
  10088. static int bnx2x_open(struct net_device *dev)
  10089. {
  10090. struct bnx2x *bp = netdev_priv(dev);
  10091. int rc;
  10092. bp->stats_init = true;
  10093. netif_carrier_off(dev);
  10094. bnx2x_set_power_state(bp, PCI_D0);
  10095. /* If parity had happen during the unload, then attentions
  10096. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  10097. * want the first function loaded on the current engine to
  10098. * complete the recovery.
  10099. * Parity recovery is only relevant for PF driver.
  10100. */
  10101. if (IS_PF(bp)) {
  10102. int other_engine = BP_PATH(bp) ? 0 : 1;
  10103. bool other_load_status, load_status;
  10104. bool global = false;
  10105. other_load_status = bnx2x_get_load_status(bp, other_engine);
  10106. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  10107. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  10108. bnx2x_chk_parity_attn(bp, &global, true)) {
  10109. do {
  10110. /* If there are attentions and they are in a
  10111. * global blocks, set the GLOBAL_RESET bit
  10112. * regardless whether it will be this function
  10113. * that will complete the recovery or not.
  10114. */
  10115. if (global)
  10116. bnx2x_set_reset_global(bp);
  10117. /* Only the first function on the current
  10118. * engine should try to recover in open. In case
  10119. * of attentions in global blocks only the first
  10120. * in the chip should try to recover.
  10121. */
  10122. if ((!load_status &&
  10123. (!global || !other_load_status)) &&
  10124. bnx2x_trylock_leader_lock(bp) &&
  10125. !bnx2x_leader_reset(bp)) {
  10126. netdev_info(bp->dev,
  10127. "Recovered in open\n");
  10128. break;
  10129. }
  10130. /* recovery has failed... */
  10131. bnx2x_set_power_state(bp, PCI_D3hot);
  10132. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  10133. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  10134. "If you still see this message after a few retries then power cycle is required.\n");
  10135. return -EAGAIN;
  10136. } while (0);
  10137. }
  10138. }
  10139. bp->recovery_state = BNX2X_RECOVERY_DONE;
  10140. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  10141. if (rc)
  10142. return rc;
  10143. return 0;
  10144. }
  10145. /* called with rtnl_lock */
  10146. static int bnx2x_close(struct net_device *dev)
  10147. {
  10148. struct bnx2x *bp = netdev_priv(dev);
  10149. /* Unload the driver, release IRQs */
  10150. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  10151. return 0;
  10152. }
  10153. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  10154. struct bnx2x_mcast_ramrod_params *p)
  10155. {
  10156. int mc_count = netdev_mc_count(bp->dev);
  10157. struct bnx2x_mcast_list_elem *mc_mac =
  10158. kcalloc(mc_count, sizeof(*mc_mac), GFP_ATOMIC);
  10159. struct netdev_hw_addr *ha;
  10160. if (!mc_mac)
  10161. return -ENOMEM;
  10162. INIT_LIST_HEAD(&p->mcast_list);
  10163. netdev_for_each_mc_addr(ha, bp->dev) {
  10164. mc_mac->mac = bnx2x_mc_addr(ha);
  10165. list_add_tail(&mc_mac->link, &p->mcast_list);
  10166. mc_mac++;
  10167. }
  10168. p->mcast_list_len = mc_count;
  10169. return 0;
  10170. }
  10171. static void bnx2x_free_mcast_macs_list(
  10172. struct bnx2x_mcast_ramrod_params *p)
  10173. {
  10174. struct bnx2x_mcast_list_elem *mc_mac =
  10175. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  10176. link);
  10177. WARN_ON(!mc_mac);
  10178. kfree(mc_mac);
  10179. }
  10180. /**
  10181. * bnx2x_set_uc_list - configure a new unicast MACs list.
  10182. *
  10183. * @bp: driver handle
  10184. *
  10185. * We will use zero (0) as a MAC type for these MACs.
  10186. */
  10187. static int bnx2x_set_uc_list(struct bnx2x *bp)
  10188. {
  10189. int rc;
  10190. struct net_device *dev = bp->dev;
  10191. struct netdev_hw_addr *ha;
  10192. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  10193. unsigned long ramrod_flags = 0;
  10194. /* First schedule a cleanup up of old configuration */
  10195. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  10196. if (rc < 0) {
  10197. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  10198. return rc;
  10199. }
  10200. netdev_for_each_uc_addr(ha, dev) {
  10201. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  10202. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10203. if (rc == -EEXIST) {
  10204. DP(BNX2X_MSG_SP,
  10205. "Failed to schedule ADD operations: %d\n", rc);
  10206. /* do not treat adding same MAC as error */
  10207. rc = 0;
  10208. } else if (rc < 0) {
  10209. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  10210. rc);
  10211. return rc;
  10212. }
  10213. }
  10214. /* Execute the pending commands */
  10215. __set_bit(RAMROD_CONT, &ramrod_flags);
  10216. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  10217. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10218. }
  10219. static int bnx2x_set_mc_list(struct bnx2x *bp)
  10220. {
  10221. struct net_device *dev = bp->dev;
  10222. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  10223. int rc = 0;
  10224. rparam.mcast_obj = &bp->mcast_obj;
  10225. /* first, clear all configured multicast MACs */
  10226. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  10227. if (rc < 0) {
  10228. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  10229. return rc;
  10230. }
  10231. /* then, configure a new MACs list */
  10232. if (netdev_mc_count(dev)) {
  10233. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  10234. if (rc) {
  10235. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  10236. rc);
  10237. return rc;
  10238. }
  10239. /* Now add the new MACs */
  10240. rc = bnx2x_config_mcast(bp, &rparam,
  10241. BNX2X_MCAST_CMD_ADD);
  10242. if (rc < 0)
  10243. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  10244. rc);
  10245. bnx2x_free_mcast_macs_list(&rparam);
  10246. }
  10247. return rc;
  10248. }
  10249. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  10250. static void bnx2x_set_rx_mode(struct net_device *dev)
  10251. {
  10252. struct bnx2x *bp = netdev_priv(dev);
  10253. if (bp->state != BNX2X_STATE_OPEN) {
  10254. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  10255. return;
  10256. } else {
  10257. /* Schedule an SP task to handle rest of change */
  10258. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_RX_MODE,
  10259. NETIF_MSG_IFUP);
  10260. }
  10261. }
  10262. void bnx2x_set_rx_mode_inner(struct bnx2x *bp)
  10263. {
  10264. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  10265. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  10266. netif_addr_lock_bh(bp->dev);
  10267. if (bp->dev->flags & IFF_PROMISC) {
  10268. rx_mode = BNX2X_RX_MODE_PROMISC;
  10269. } else if ((bp->dev->flags & IFF_ALLMULTI) ||
  10270. ((netdev_mc_count(bp->dev) > BNX2X_MAX_MULTICAST) &&
  10271. CHIP_IS_E1(bp))) {
  10272. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10273. } else {
  10274. if (IS_PF(bp)) {
  10275. /* some multicasts */
  10276. if (bnx2x_set_mc_list(bp) < 0)
  10277. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10278. /* release bh lock, as bnx2x_set_uc_list might sleep */
  10279. netif_addr_unlock_bh(bp->dev);
  10280. if (bnx2x_set_uc_list(bp) < 0)
  10281. rx_mode = BNX2X_RX_MODE_PROMISC;
  10282. netif_addr_lock_bh(bp->dev);
  10283. } else {
  10284. /* configuring mcast to a vf involves sleeping (when we
  10285. * wait for the pf's response).
  10286. */
  10287. bnx2x_schedule_sp_rtnl(bp,
  10288. BNX2X_SP_RTNL_VFPF_MCAST, 0);
  10289. }
  10290. }
  10291. bp->rx_mode = rx_mode;
  10292. /* handle ISCSI SD mode */
  10293. if (IS_MF_ISCSI_SD(bp))
  10294. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10295. /* Schedule the rx_mode command */
  10296. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  10297. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  10298. netif_addr_unlock_bh(bp->dev);
  10299. return;
  10300. }
  10301. if (IS_PF(bp)) {
  10302. bnx2x_set_storm_rx_mode(bp);
  10303. netif_addr_unlock_bh(bp->dev);
  10304. } else {
  10305. /* VF will need to request the PF to make this change, and so
  10306. * the VF needs to release the bottom-half lock prior to the
  10307. * request (as it will likely require sleep on the VF side)
  10308. */
  10309. netif_addr_unlock_bh(bp->dev);
  10310. bnx2x_vfpf_storm_rx_mode(bp);
  10311. }
  10312. }
  10313. /* called with rtnl_lock */
  10314. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  10315. int devad, u16 addr)
  10316. {
  10317. struct bnx2x *bp = netdev_priv(netdev);
  10318. u16 value;
  10319. int rc;
  10320. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  10321. prtad, devad, addr);
  10322. /* The HW expects different devad if CL22 is used */
  10323. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10324. bnx2x_acquire_phy_lock(bp);
  10325. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  10326. bnx2x_release_phy_lock(bp);
  10327. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  10328. if (!rc)
  10329. rc = value;
  10330. return rc;
  10331. }
  10332. /* called with rtnl_lock */
  10333. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  10334. u16 addr, u16 value)
  10335. {
  10336. struct bnx2x *bp = netdev_priv(netdev);
  10337. int rc;
  10338. DP(NETIF_MSG_LINK,
  10339. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  10340. prtad, devad, addr, value);
  10341. /* The HW expects different devad if CL22 is used */
  10342. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10343. bnx2x_acquire_phy_lock(bp);
  10344. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  10345. bnx2x_release_phy_lock(bp);
  10346. return rc;
  10347. }
  10348. /* called with rtnl_lock */
  10349. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  10350. {
  10351. struct bnx2x *bp = netdev_priv(dev);
  10352. struct mii_ioctl_data *mdio = if_mii(ifr);
  10353. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  10354. mdio->phy_id, mdio->reg_num, mdio->val_in);
  10355. if (!netif_running(dev))
  10356. return -EAGAIN;
  10357. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  10358. }
  10359. #ifdef CONFIG_NET_POLL_CONTROLLER
  10360. static void poll_bnx2x(struct net_device *dev)
  10361. {
  10362. struct bnx2x *bp = netdev_priv(dev);
  10363. int i;
  10364. for_each_eth_queue(bp, i) {
  10365. struct bnx2x_fastpath *fp = &bp->fp[i];
  10366. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  10367. }
  10368. }
  10369. #endif
  10370. static int bnx2x_validate_addr(struct net_device *dev)
  10371. {
  10372. struct bnx2x *bp = netdev_priv(dev);
  10373. /* query the bulletin board for mac address configured by the PF */
  10374. if (IS_VF(bp))
  10375. bnx2x_sample_bulletin(bp);
  10376. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  10377. BNX2X_ERR("Non-valid Ethernet address\n");
  10378. return -EADDRNOTAVAIL;
  10379. }
  10380. return 0;
  10381. }
  10382. static int bnx2x_get_phys_port_id(struct net_device *netdev,
  10383. struct netdev_phys_port_id *ppid)
  10384. {
  10385. struct bnx2x *bp = netdev_priv(netdev);
  10386. if (!(bp->flags & HAS_PHYS_PORT_ID))
  10387. return -EOPNOTSUPP;
  10388. ppid->id_len = sizeof(bp->phys_port_id);
  10389. memcpy(ppid->id, bp->phys_port_id, ppid->id_len);
  10390. return 0;
  10391. }
  10392. static const struct net_device_ops bnx2x_netdev_ops = {
  10393. .ndo_open = bnx2x_open,
  10394. .ndo_stop = bnx2x_close,
  10395. .ndo_start_xmit = bnx2x_start_xmit,
  10396. .ndo_select_queue = bnx2x_select_queue,
  10397. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  10398. .ndo_set_mac_address = bnx2x_change_mac_addr,
  10399. .ndo_validate_addr = bnx2x_validate_addr,
  10400. .ndo_do_ioctl = bnx2x_ioctl,
  10401. .ndo_change_mtu = bnx2x_change_mtu,
  10402. .ndo_fix_features = bnx2x_fix_features,
  10403. .ndo_set_features = bnx2x_set_features,
  10404. .ndo_tx_timeout = bnx2x_tx_timeout,
  10405. #ifdef CONFIG_NET_POLL_CONTROLLER
  10406. .ndo_poll_controller = poll_bnx2x,
  10407. #endif
  10408. .ndo_setup_tc = bnx2x_setup_tc,
  10409. #ifdef CONFIG_BNX2X_SRIOV
  10410. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  10411. .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
  10412. .ndo_get_vf_config = bnx2x_get_vf_config,
  10413. #endif
  10414. #ifdef NETDEV_FCOE_WWNN
  10415. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  10416. #endif
  10417. #ifdef CONFIG_NET_RX_BUSY_POLL
  10418. .ndo_busy_poll = bnx2x_low_latency_recv,
  10419. #endif
  10420. .ndo_get_phys_port_id = bnx2x_get_phys_port_id,
  10421. .ndo_set_vf_link_state = bnx2x_set_vf_link_state,
  10422. };
  10423. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  10424. {
  10425. struct device *dev = &bp->pdev->dev;
  10426. if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)) != 0 &&
  10427. dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)) != 0) {
  10428. dev_err(dev, "System does not support DMA, aborting\n");
  10429. return -EIO;
  10430. }
  10431. return 0;
  10432. }
  10433. static void bnx2x_disable_pcie_error_reporting(struct bnx2x *bp)
  10434. {
  10435. if (bp->flags & AER_ENABLED) {
  10436. pci_disable_pcie_error_reporting(bp->pdev);
  10437. bp->flags &= ~AER_ENABLED;
  10438. }
  10439. }
  10440. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  10441. struct net_device *dev, unsigned long board_type)
  10442. {
  10443. int rc;
  10444. u32 pci_cfg_dword;
  10445. bool chip_is_e1x = (board_type == BCM57710 ||
  10446. board_type == BCM57711 ||
  10447. board_type == BCM57711E);
  10448. SET_NETDEV_DEV(dev, &pdev->dev);
  10449. bp->dev = dev;
  10450. bp->pdev = pdev;
  10451. rc = pci_enable_device(pdev);
  10452. if (rc) {
  10453. dev_err(&bp->pdev->dev,
  10454. "Cannot enable PCI device, aborting\n");
  10455. goto err_out;
  10456. }
  10457. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  10458. dev_err(&bp->pdev->dev,
  10459. "Cannot find PCI device base address, aborting\n");
  10460. rc = -ENODEV;
  10461. goto err_out_disable;
  10462. }
  10463. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  10464. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  10465. rc = -ENODEV;
  10466. goto err_out_disable;
  10467. }
  10468. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  10469. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  10470. PCICFG_REVESION_ID_ERROR_VAL) {
  10471. pr_err("PCI device error, probably due to fan failure, aborting\n");
  10472. rc = -ENODEV;
  10473. goto err_out_disable;
  10474. }
  10475. if (atomic_read(&pdev->enable_cnt) == 1) {
  10476. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  10477. if (rc) {
  10478. dev_err(&bp->pdev->dev,
  10479. "Cannot obtain PCI resources, aborting\n");
  10480. goto err_out_disable;
  10481. }
  10482. pci_set_master(pdev);
  10483. pci_save_state(pdev);
  10484. }
  10485. if (IS_PF(bp)) {
  10486. if (!pdev->pm_cap) {
  10487. dev_err(&bp->pdev->dev,
  10488. "Cannot find power management capability, aborting\n");
  10489. rc = -EIO;
  10490. goto err_out_release;
  10491. }
  10492. }
  10493. if (!pci_is_pcie(pdev)) {
  10494. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  10495. rc = -EIO;
  10496. goto err_out_release;
  10497. }
  10498. rc = bnx2x_set_coherency_mask(bp);
  10499. if (rc)
  10500. goto err_out_release;
  10501. dev->mem_start = pci_resource_start(pdev, 0);
  10502. dev->base_addr = dev->mem_start;
  10503. dev->mem_end = pci_resource_end(pdev, 0);
  10504. dev->irq = pdev->irq;
  10505. bp->regview = pci_ioremap_bar(pdev, 0);
  10506. if (!bp->regview) {
  10507. dev_err(&bp->pdev->dev,
  10508. "Cannot map register space, aborting\n");
  10509. rc = -ENOMEM;
  10510. goto err_out_release;
  10511. }
  10512. /* In E1/E1H use pci device function given by kernel.
  10513. * In E2/E3 read physical function from ME register since these chips
  10514. * support Physical Device Assignment where kernel BDF maybe arbitrary
  10515. * (depending on hypervisor).
  10516. */
  10517. if (chip_is_e1x) {
  10518. bp->pf_num = PCI_FUNC(pdev->devfn);
  10519. } else {
  10520. /* chip is E2/3*/
  10521. pci_read_config_dword(bp->pdev,
  10522. PCICFG_ME_REGISTER, &pci_cfg_dword);
  10523. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  10524. ME_REG_ABS_PF_NUM_SHIFT);
  10525. }
  10526. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  10527. /* clean indirect addresses */
  10528. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  10529. PCICFG_VENDOR_ID_OFFSET);
  10530. /* AER (Advanced Error reporting) configuration */
  10531. rc = pci_enable_pcie_error_reporting(pdev);
  10532. if (!rc)
  10533. bp->flags |= AER_ENABLED;
  10534. else
  10535. BNX2X_DEV_INFO("Failed To configure PCIe AER [%d]\n", rc);
  10536. /*
  10537. * Clean the following indirect addresses for all functions since it
  10538. * is not used by the driver.
  10539. */
  10540. if (IS_PF(bp)) {
  10541. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  10542. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  10543. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  10544. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  10545. if (chip_is_e1x) {
  10546. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  10547. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  10548. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  10549. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  10550. }
  10551. /* Enable internal target-read (in case we are probed after PF
  10552. * FLR). Must be done prior to any BAR read access. Only for
  10553. * 57712 and up
  10554. */
  10555. if (!chip_is_e1x)
  10556. REG_WR(bp,
  10557. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  10558. }
  10559. dev->watchdog_timeo = TX_TIMEOUT;
  10560. dev->netdev_ops = &bnx2x_netdev_ops;
  10561. bnx2x_set_ethtool_ops(bp, dev);
  10562. dev->priv_flags |= IFF_UNICAST_FLT;
  10563. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10564. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10565. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  10566. NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
  10567. if (!CHIP_IS_E1x(bp)) {
  10568. dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL |
  10569. NETIF_F_GSO_IPIP | NETIF_F_GSO_SIT;
  10570. dev->hw_enc_features =
  10571. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
  10572. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10573. NETIF_F_GSO_IPIP |
  10574. NETIF_F_GSO_SIT |
  10575. NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
  10576. }
  10577. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10578. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  10579. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
  10580. dev->features |= NETIF_F_HIGHDMA;
  10581. /* Add Loopback capability to the device */
  10582. dev->hw_features |= NETIF_F_LOOPBACK;
  10583. #ifdef BCM_DCBNL
  10584. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  10585. #endif
  10586. /* get_port_hwinfo() will set prtad and mmds properly */
  10587. bp->mdio.prtad = MDIO_PRTAD_NONE;
  10588. bp->mdio.mmds = 0;
  10589. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  10590. bp->mdio.dev = dev;
  10591. bp->mdio.mdio_read = bnx2x_mdio_read;
  10592. bp->mdio.mdio_write = bnx2x_mdio_write;
  10593. return 0;
  10594. err_out_release:
  10595. if (atomic_read(&pdev->enable_cnt) == 1)
  10596. pci_release_regions(pdev);
  10597. err_out_disable:
  10598. pci_disable_device(pdev);
  10599. err_out:
  10600. return rc;
  10601. }
  10602. static int bnx2x_check_firmware(struct bnx2x *bp)
  10603. {
  10604. const struct firmware *firmware = bp->firmware;
  10605. struct bnx2x_fw_file_hdr *fw_hdr;
  10606. struct bnx2x_fw_file_section *sections;
  10607. u32 offset, len, num_ops;
  10608. __be16 *ops_offsets;
  10609. int i;
  10610. const u8 *fw_ver;
  10611. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  10612. BNX2X_ERR("Wrong FW size\n");
  10613. return -EINVAL;
  10614. }
  10615. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  10616. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  10617. /* Make sure none of the offsets and sizes make us read beyond
  10618. * the end of the firmware data */
  10619. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  10620. offset = be32_to_cpu(sections[i].offset);
  10621. len = be32_to_cpu(sections[i].len);
  10622. if (offset + len > firmware->size) {
  10623. BNX2X_ERR("Section %d length is out of bounds\n", i);
  10624. return -EINVAL;
  10625. }
  10626. }
  10627. /* Likewise for the init_ops offsets */
  10628. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  10629. ops_offsets = (__force __be16 *)(firmware->data + offset);
  10630. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  10631. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  10632. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  10633. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  10634. return -EINVAL;
  10635. }
  10636. }
  10637. /* Check FW version */
  10638. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  10639. fw_ver = firmware->data + offset;
  10640. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  10641. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  10642. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  10643. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  10644. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  10645. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  10646. BCM_5710_FW_MAJOR_VERSION,
  10647. BCM_5710_FW_MINOR_VERSION,
  10648. BCM_5710_FW_REVISION_VERSION,
  10649. BCM_5710_FW_ENGINEERING_VERSION);
  10650. return -EINVAL;
  10651. }
  10652. return 0;
  10653. }
  10654. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10655. {
  10656. const __be32 *source = (const __be32 *)_source;
  10657. u32 *target = (u32 *)_target;
  10658. u32 i;
  10659. for (i = 0; i < n/4; i++)
  10660. target[i] = be32_to_cpu(source[i]);
  10661. }
  10662. /*
  10663. Ops array is stored in the following format:
  10664. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  10665. */
  10666. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  10667. {
  10668. const __be32 *source = (const __be32 *)_source;
  10669. struct raw_op *target = (struct raw_op *)_target;
  10670. u32 i, j, tmp;
  10671. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  10672. tmp = be32_to_cpu(source[j]);
  10673. target[i].op = (tmp >> 24) & 0xff;
  10674. target[i].offset = tmp & 0xffffff;
  10675. target[i].raw_data = be32_to_cpu(source[j + 1]);
  10676. }
  10677. }
  10678. /* IRO array is stored in the following format:
  10679. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  10680. */
  10681. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  10682. {
  10683. const __be32 *source = (const __be32 *)_source;
  10684. struct iro *target = (struct iro *)_target;
  10685. u32 i, j, tmp;
  10686. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  10687. target[i].base = be32_to_cpu(source[j]);
  10688. j++;
  10689. tmp = be32_to_cpu(source[j]);
  10690. target[i].m1 = (tmp >> 16) & 0xffff;
  10691. target[i].m2 = tmp & 0xffff;
  10692. j++;
  10693. tmp = be32_to_cpu(source[j]);
  10694. target[i].m3 = (tmp >> 16) & 0xffff;
  10695. target[i].size = tmp & 0xffff;
  10696. j++;
  10697. }
  10698. }
  10699. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10700. {
  10701. const __be16 *source = (const __be16 *)_source;
  10702. u16 *target = (u16 *)_target;
  10703. u32 i;
  10704. for (i = 0; i < n/2; i++)
  10705. target[i] = be16_to_cpu(source[i]);
  10706. }
  10707. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  10708. do { \
  10709. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  10710. bp->arr = kmalloc(len, GFP_KERNEL); \
  10711. if (!bp->arr) \
  10712. goto lbl; \
  10713. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  10714. (u8 *)bp->arr, len); \
  10715. } while (0)
  10716. static int bnx2x_init_firmware(struct bnx2x *bp)
  10717. {
  10718. const char *fw_file_name;
  10719. struct bnx2x_fw_file_hdr *fw_hdr;
  10720. int rc;
  10721. if (bp->firmware)
  10722. return 0;
  10723. if (CHIP_IS_E1(bp))
  10724. fw_file_name = FW_FILE_NAME_E1;
  10725. else if (CHIP_IS_E1H(bp))
  10726. fw_file_name = FW_FILE_NAME_E1H;
  10727. else if (!CHIP_IS_E1x(bp))
  10728. fw_file_name = FW_FILE_NAME_E2;
  10729. else {
  10730. BNX2X_ERR("Unsupported chip revision\n");
  10731. return -EINVAL;
  10732. }
  10733. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  10734. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  10735. if (rc) {
  10736. BNX2X_ERR("Can't load firmware file %s\n",
  10737. fw_file_name);
  10738. goto request_firmware_exit;
  10739. }
  10740. rc = bnx2x_check_firmware(bp);
  10741. if (rc) {
  10742. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  10743. goto request_firmware_exit;
  10744. }
  10745. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  10746. /* Initialize the pointers to the init arrays */
  10747. /* Blob */
  10748. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  10749. /* Opcodes */
  10750. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  10751. /* Offsets */
  10752. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  10753. be16_to_cpu_n);
  10754. /* STORMs firmware */
  10755. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10756. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  10757. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  10758. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  10759. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10760. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  10761. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  10762. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  10763. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10764. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  10765. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  10766. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  10767. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10768. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  10769. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  10770. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  10771. /* IRO */
  10772. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  10773. return 0;
  10774. iro_alloc_err:
  10775. kfree(bp->init_ops_offsets);
  10776. init_offsets_alloc_err:
  10777. kfree(bp->init_ops);
  10778. init_ops_alloc_err:
  10779. kfree(bp->init_data);
  10780. request_firmware_exit:
  10781. release_firmware(bp->firmware);
  10782. bp->firmware = NULL;
  10783. return rc;
  10784. }
  10785. static void bnx2x_release_firmware(struct bnx2x *bp)
  10786. {
  10787. kfree(bp->init_ops_offsets);
  10788. kfree(bp->init_ops);
  10789. kfree(bp->init_data);
  10790. release_firmware(bp->firmware);
  10791. bp->firmware = NULL;
  10792. }
  10793. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  10794. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  10795. .init_hw_cmn = bnx2x_init_hw_common,
  10796. .init_hw_port = bnx2x_init_hw_port,
  10797. .init_hw_func = bnx2x_init_hw_func,
  10798. .reset_hw_cmn = bnx2x_reset_common,
  10799. .reset_hw_port = bnx2x_reset_port,
  10800. .reset_hw_func = bnx2x_reset_func,
  10801. .gunzip_init = bnx2x_gunzip_init,
  10802. .gunzip_end = bnx2x_gunzip_end,
  10803. .init_fw = bnx2x_init_firmware,
  10804. .release_fw = bnx2x_release_firmware,
  10805. };
  10806. void bnx2x__init_func_obj(struct bnx2x *bp)
  10807. {
  10808. /* Prepare DMAE related driver resources */
  10809. bnx2x_setup_dmae(bp);
  10810. bnx2x_init_func_obj(bp, &bp->func_obj,
  10811. bnx2x_sp(bp, func_rdata),
  10812. bnx2x_sp_mapping(bp, func_rdata),
  10813. bnx2x_sp(bp, func_afex_rdata),
  10814. bnx2x_sp_mapping(bp, func_afex_rdata),
  10815. &bnx2x_func_sp_drv);
  10816. }
  10817. /* must be called after sriov-enable */
  10818. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  10819. {
  10820. int cid_count = BNX2X_L2_MAX_CID(bp);
  10821. if (IS_SRIOV(bp))
  10822. cid_count += BNX2X_VF_CIDS;
  10823. if (CNIC_SUPPORT(bp))
  10824. cid_count += CNIC_CID_MAX;
  10825. return roundup(cid_count, QM_CID_ROUND);
  10826. }
  10827. /**
  10828. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  10829. *
  10830. * @dev: pci device
  10831. *
  10832. */
  10833. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev, int cnic_cnt)
  10834. {
  10835. int index;
  10836. u16 control = 0;
  10837. /*
  10838. * If MSI-X is not supported - return number of SBs needed to support
  10839. * one fast path queue: one FP queue + SB for CNIC
  10840. */
  10841. if (!pdev->msix_cap) {
  10842. dev_info(&pdev->dev, "no msix capability found\n");
  10843. return 1 + cnic_cnt;
  10844. }
  10845. dev_info(&pdev->dev, "msix capability found\n");
  10846. /*
  10847. * The value in the PCI configuration space is the index of the last
  10848. * entry, namely one less than the actual size of the table, which is
  10849. * exactly what we want to return from this function: number of all SBs
  10850. * without the default SB.
  10851. * For VFs there is no default SB, then we return (index+1).
  10852. */
  10853. pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &control);
  10854. index = control & PCI_MSIX_FLAGS_QSIZE;
  10855. return index;
  10856. }
  10857. static int set_max_cos_est(int chip_id)
  10858. {
  10859. switch (chip_id) {
  10860. case BCM57710:
  10861. case BCM57711:
  10862. case BCM57711E:
  10863. return BNX2X_MULTI_TX_COS_E1X;
  10864. case BCM57712:
  10865. case BCM57712_MF:
  10866. return BNX2X_MULTI_TX_COS_E2_E3A0;
  10867. case BCM57800:
  10868. case BCM57800_MF:
  10869. case BCM57810:
  10870. case BCM57810_MF:
  10871. case BCM57840_4_10:
  10872. case BCM57840_2_20:
  10873. case BCM57840_O:
  10874. case BCM57840_MFO:
  10875. case BCM57840_MF:
  10876. case BCM57811:
  10877. case BCM57811_MF:
  10878. return BNX2X_MULTI_TX_COS_E3B0;
  10879. case BCM57712_VF:
  10880. case BCM57800_VF:
  10881. case BCM57810_VF:
  10882. case BCM57840_VF:
  10883. case BCM57811_VF:
  10884. return 1;
  10885. default:
  10886. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  10887. return -ENODEV;
  10888. }
  10889. }
  10890. static int set_is_vf(int chip_id)
  10891. {
  10892. switch (chip_id) {
  10893. case BCM57712_VF:
  10894. case BCM57800_VF:
  10895. case BCM57810_VF:
  10896. case BCM57840_VF:
  10897. case BCM57811_VF:
  10898. return true;
  10899. default:
  10900. return false;
  10901. }
  10902. }
  10903. static int bnx2x_init_one(struct pci_dev *pdev,
  10904. const struct pci_device_id *ent)
  10905. {
  10906. struct net_device *dev = NULL;
  10907. struct bnx2x *bp;
  10908. enum pcie_link_width pcie_width;
  10909. enum pci_bus_speed pcie_speed;
  10910. int rc, max_non_def_sbs;
  10911. int rx_count, tx_count, rss_count, doorbell_size;
  10912. int max_cos_est;
  10913. bool is_vf;
  10914. int cnic_cnt;
  10915. /* An estimated maximum supported CoS number according to the chip
  10916. * version.
  10917. * We will try to roughly estimate the maximum number of CoSes this chip
  10918. * may support in order to minimize the memory allocated for Tx
  10919. * netdev_queue's. This number will be accurately calculated during the
  10920. * initialization of bp->max_cos based on the chip versions AND chip
  10921. * revision in the bnx2x_init_bp().
  10922. */
  10923. max_cos_est = set_max_cos_est(ent->driver_data);
  10924. if (max_cos_est < 0)
  10925. return max_cos_est;
  10926. is_vf = set_is_vf(ent->driver_data);
  10927. cnic_cnt = is_vf ? 0 : 1;
  10928. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt);
  10929. /* add another SB for VF as it has no default SB */
  10930. max_non_def_sbs += is_vf ? 1 : 0;
  10931. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  10932. rss_count = max_non_def_sbs - cnic_cnt;
  10933. if (rss_count < 1)
  10934. return -EINVAL;
  10935. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  10936. rx_count = rss_count + cnic_cnt;
  10937. /* Maximum number of netdev Tx queues:
  10938. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  10939. */
  10940. tx_count = rss_count * max_cos_est + cnic_cnt;
  10941. /* dev zeroed in init_etherdev */
  10942. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  10943. if (!dev)
  10944. return -ENOMEM;
  10945. bp = netdev_priv(dev);
  10946. bp->flags = 0;
  10947. if (is_vf)
  10948. bp->flags |= IS_VF_FLAG;
  10949. bp->igu_sb_cnt = max_non_def_sbs;
  10950. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  10951. bp->msg_enable = debug;
  10952. bp->cnic_support = cnic_cnt;
  10953. bp->cnic_probe = bnx2x_cnic_probe;
  10954. pci_set_drvdata(pdev, dev);
  10955. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  10956. if (rc < 0) {
  10957. free_netdev(dev);
  10958. return rc;
  10959. }
  10960. BNX2X_DEV_INFO("This is a %s function\n",
  10961. IS_PF(bp) ? "physical" : "virtual");
  10962. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  10963. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  10964. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  10965. tx_count, rx_count);
  10966. rc = bnx2x_init_bp(bp);
  10967. if (rc)
  10968. goto init_one_exit;
  10969. /* Map doorbells here as we need the real value of bp->max_cos which
  10970. * is initialized in bnx2x_init_bp() to determine the number of
  10971. * l2 connections.
  10972. */
  10973. if (IS_VF(bp)) {
  10974. bp->doorbells = bnx2x_vf_doorbells(bp);
  10975. rc = bnx2x_vf_pci_alloc(bp);
  10976. if (rc)
  10977. goto init_one_exit;
  10978. } else {
  10979. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  10980. if (doorbell_size > pci_resource_len(pdev, 2)) {
  10981. dev_err(&bp->pdev->dev,
  10982. "Cannot map doorbells, bar size too small, aborting\n");
  10983. rc = -ENOMEM;
  10984. goto init_one_exit;
  10985. }
  10986. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  10987. doorbell_size);
  10988. }
  10989. if (!bp->doorbells) {
  10990. dev_err(&bp->pdev->dev,
  10991. "Cannot map doorbell space, aborting\n");
  10992. rc = -ENOMEM;
  10993. goto init_one_exit;
  10994. }
  10995. if (IS_VF(bp)) {
  10996. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  10997. if (rc)
  10998. goto init_one_exit;
  10999. }
  11000. /* Enable SRIOV if capability found in configuration space */
  11001. rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
  11002. if (rc)
  11003. goto init_one_exit;
  11004. /* calc qm_cid_count */
  11005. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  11006. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  11007. /* disable FCOE L2 queue for E1x*/
  11008. if (CHIP_IS_E1x(bp))
  11009. bp->flags |= NO_FCOE_FLAG;
  11010. /* Set bp->num_queues for MSI-X mode*/
  11011. bnx2x_set_num_queues(bp);
  11012. /* Configure interrupt mode: try to enable MSI-X/MSI if
  11013. * needed.
  11014. */
  11015. rc = bnx2x_set_int_mode(bp);
  11016. if (rc) {
  11017. dev_err(&pdev->dev, "Cannot set interrupts\n");
  11018. goto init_one_exit;
  11019. }
  11020. BNX2X_DEV_INFO("set interrupts successfully\n");
  11021. /* register the net device */
  11022. rc = register_netdev(dev);
  11023. if (rc) {
  11024. dev_err(&pdev->dev, "Cannot register net device\n");
  11025. goto init_one_exit;
  11026. }
  11027. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  11028. if (!NO_FCOE(bp)) {
  11029. /* Add storage MAC address */
  11030. rtnl_lock();
  11031. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  11032. rtnl_unlock();
  11033. }
  11034. if (pcie_get_minimum_link(bp->pdev, &pcie_speed, &pcie_width) ||
  11035. pcie_speed == PCI_SPEED_UNKNOWN ||
  11036. pcie_width == PCIE_LNK_WIDTH_UNKNOWN)
  11037. BNX2X_DEV_INFO("Failed to determine PCI Express Bandwidth\n");
  11038. else
  11039. BNX2X_DEV_INFO(
  11040. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  11041. board_info[ent->driver_data].name,
  11042. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  11043. pcie_width,
  11044. pcie_speed == PCIE_SPEED_2_5GT ? "2.5GHz" :
  11045. pcie_speed == PCIE_SPEED_5_0GT ? "5.0GHz" :
  11046. pcie_speed == PCIE_SPEED_8_0GT ? "8.0GHz" :
  11047. "Unknown",
  11048. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  11049. return 0;
  11050. init_one_exit:
  11051. bnx2x_disable_pcie_error_reporting(bp);
  11052. if (bp->regview)
  11053. iounmap(bp->regview);
  11054. if (IS_PF(bp) && bp->doorbells)
  11055. iounmap(bp->doorbells);
  11056. free_netdev(dev);
  11057. if (atomic_read(&pdev->enable_cnt) == 1)
  11058. pci_release_regions(pdev);
  11059. pci_disable_device(pdev);
  11060. return rc;
  11061. }
  11062. static void __bnx2x_remove(struct pci_dev *pdev,
  11063. struct net_device *dev,
  11064. struct bnx2x *bp,
  11065. bool remove_netdev)
  11066. {
  11067. /* Delete storage MAC address */
  11068. if (!NO_FCOE(bp)) {
  11069. rtnl_lock();
  11070. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  11071. rtnl_unlock();
  11072. }
  11073. #ifdef BCM_DCBNL
  11074. /* Delete app tlvs from dcbnl */
  11075. bnx2x_dcbnl_update_applist(bp, true);
  11076. #endif
  11077. if (IS_PF(bp) &&
  11078. !BP_NOMCP(bp) &&
  11079. (bp->flags & BC_SUPPORTS_RMMOD_CMD))
  11080. bnx2x_fw_command(bp, DRV_MSG_CODE_RMMOD, 0);
  11081. /* Close the interface - either directly or implicitly */
  11082. if (remove_netdev) {
  11083. unregister_netdev(dev);
  11084. } else {
  11085. rtnl_lock();
  11086. dev_close(dev);
  11087. rtnl_unlock();
  11088. }
  11089. bnx2x_iov_remove_one(bp);
  11090. /* Power on: we can't let PCI layer write to us while we are in D3 */
  11091. if (IS_PF(bp)) {
  11092. bnx2x_set_power_state(bp, PCI_D0);
  11093. /* Set endianity registers to reset values in case next driver
  11094. * boots in different endianty environment.
  11095. */
  11096. bnx2x_reset_endianity(bp);
  11097. }
  11098. /* Disable MSI/MSI-X */
  11099. bnx2x_disable_msi(bp);
  11100. /* Power off */
  11101. if (IS_PF(bp))
  11102. bnx2x_set_power_state(bp, PCI_D3hot);
  11103. /* Make sure RESET task is not scheduled before continuing */
  11104. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  11105. /* send message via vfpf channel to release the resources of this vf */
  11106. if (IS_VF(bp))
  11107. bnx2x_vfpf_release(bp);
  11108. /* Assumes no further PCIe PM changes will occur */
  11109. if (system_state == SYSTEM_POWER_OFF) {
  11110. pci_wake_from_d3(pdev, bp->wol);
  11111. pci_set_power_state(pdev, PCI_D3hot);
  11112. }
  11113. bnx2x_disable_pcie_error_reporting(bp);
  11114. if (remove_netdev) {
  11115. if (bp->regview)
  11116. iounmap(bp->regview);
  11117. /* For vfs, doorbells are part of the regview and were unmapped
  11118. * along with it. FW is only loaded by PF.
  11119. */
  11120. if (IS_PF(bp)) {
  11121. if (bp->doorbells)
  11122. iounmap(bp->doorbells);
  11123. bnx2x_release_firmware(bp);
  11124. } else {
  11125. bnx2x_vf_pci_dealloc(bp);
  11126. }
  11127. bnx2x_free_mem_bp(bp);
  11128. free_netdev(dev);
  11129. if (atomic_read(&pdev->enable_cnt) == 1)
  11130. pci_release_regions(pdev);
  11131. pci_disable_device(pdev);
  11132. }
  11133. }
  11134. static void bnx2x_remove_one(struct pci_dev *pdev)
  11135. {
  11136. struct net_device *dev = pci_get_drvdata(pdev);
  11137. struct bnx2x *bp;
  11138. if (!dev) {
  11139. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  11140. return;
  11141. }
  11142. bp = netdev_priv(dev);
  11143. __bnx2x_remove(pdev, dev, bp, true);
  11144. }
  11145. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  11146. {
  11147. bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
  11148. bp->rx_mode = BNX2X_RX_MODE_NONE;
  11149. if (CNIC_LOADED(bp))
  11150. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  11151. /* Stop Tx */
  11152. bnx2x_tx_disable(bp);
  11153. /* Delete all NAPI objects */
  11154. bnx2x_del_all_napi(bp);
  11155. if (CNIC_LOADED(bp))
  11156. bnx2x_del_all_napi_cnic(bp);
  11157. netdev_reset_tc(bp->dev);
  11158. del_timer_sync(&bp->timer);
  11159. cancel_delayed_work_sync(&bp->sp_task);
  11160. cancel_delayed_work_sync(&bp->period_task);
  11161. spin_lock_bh(&bp->stats_lock);
  11162. bp->stats_state = STATS_STATE_DISABLED;
  11163. spin_unlock_bh(&bp->stats_lock);
  11164. bnx2x_save_statistics(bp);
  11165. netif_carrier_off(bp->dev);
  11166. return 0;
  11167. }
  11168. /**
  11169. * bnx2x_io_error_detected - called when PCI error is detected
  11170. * @pdev: Pointer to PCI device
  11171. * @state: The current pci connection state
  11172. *
  11173. * This function is called after a PCI bus error affecting
  11174. * this device has been detected.
  11175. */
  11176. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  11177. pci_channel_state_t state)
  11178. {
  11179. struct net_device *dev = pci_get_drvdata(pdev);
  11180. struct bnx2x *bp = netdev_priv(dev);
  11181. rtnl_lock();
  11182. BNX2X_ERR("IO error detected\n");
  11183. netif_device_detach(dev);
  11184. if (state == pci_channel_io_perm_failure) {
  11185. rtnl_unlock();
  11186. return PCI_ERS_RESULT_DISCONNECT;
  11187. }
  11188. if (netif_running(dev))
  11189. bnx2x_eeh_nic_unload(bp);
  11190. bnx2x_prev_path_mark_eeh(bp);
  11191. pci_disable_device(pdev);
  11192. rtnl_unlock();
  11193. /* Request a slot reset */
  11194. return PCI_ERS_RESULT_NEED_RESET;
  11195. }
  11196. /**
  11197. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  11198. * @pdev: Pointer to PCI device
  11199. *
  11200. * Restart the card from scratch, as if from a cold-boot.
  11201. */
  11202. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  11203. {
  11204. struct net_device *dev = pci_get_drvdata(pdev);
  11205. struct bnx2x *bp = netdev_priv(dev);
  11206. int i;
  11207. rtnl_lock();
  11208. BNX2X_ERR("IO slot reset initializing...\n");
  11209. if (pci_enable_device(pdev)) {
  11210. dev_err(&pdev->dev,
  11211. "Cannot re-enable PCI device after reset\n");
  11212. rtnl_unlock();
  11213. return PCI_ERS_RESULT_DISCONNECT;
  11214. }
  11215. pci_set_master(pdev);
  11216. pci_restore_state(pdev);
  11217. pci_save_state(pdev);
  11218. if (netif_running(dev))
  11219. bnx2x_set_power_state(bp, PCI_D0);
  11220. if (netif_running(dev)) {
  11221. BNX2X_ERR("IO slot reset --> driver unload\n");
  11222. /* MCP should have been reset; Need to wait for validity */
  11223. bnx2x_init_shmem(bp);
  11224. if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
  11225. u32 v;
  11226. v = SHMEM2_RD(bp,
  11227. drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
  11228. SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
  11229. v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
  11230. }
  11231. bnx2x_drain_tx_queues(bp);
  11232. bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
  11233. bnx2x_netif_stop(bp, 1);
  11234. bnx2x_free_irq(bp);
  11235. /* Report UNLOAD_DONE to MCP */
  11236. bnx2x_send_unload_done(bp, true);
  11237. bp->sp_state = 0;
  11238. bp->port.pmf = 0;
  11239. bnx2x_prev_unload(bp);
  11240. /* We should have reseted the engine, so It's fair to
  11241. * assume the FW will no longer write to the bnx2x driver.
  11242. */
  11243. bnx2x_squeeze_objects(bp);
  11244. bnx2x_free_skbs(bp);
  11245. for_each_rx_queue(bp, i)
  11246. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  11247. bnx2x_free_fp_mem(bp);
  11248. bnx2x_free_mem(bp);
  11249. bp->state = BNX2X_STATE_CLOSED;
  11250. }
  11251. rtnl_unlock();
  11252. /* If AER, perform cleanup of the PCIe registers */
  11253. if (bp->flags & AER_ENABLED) {
  11254. if (pci_cleanup_aer_uncorrect_error_status(pdev))
  11255. BNX2X_ERR("pci_cleanup_aer_uncorrect_error_status failed\n");
  11256. else
  11257. DP(NETIF_MSG_HW, "pci_cleanup_aer_uncorrect_error_status succeeded\n");
  11258. }
  11259. return PCI_ERS_RESULT_RECOVERED;
  11260. }
  11261. /**
  11262. * bnx2x_io_resume - called when traffic can start flowing again
  11263. * @pdev: Pointer to PCI device
  11264. *
  11265. * This callback is called when the error recovery driver tells us that
  11266. * its OK to resume normal operation.
  11267. */
  11268. static void bnx2x_io_resume(struct pci_dev *pdev)
  11269. {
  11270. struct net_device *dev = pci_get_drvdata(pdev);
  11271. struct bnx2x *bp = netdev_priv(dev);
  11272. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  11273. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  11274. return;
  11275. }
  11276. rtnl_lock();
  11277. bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  11278. DRV_MSG_SEQ_NUMBER_MASK;
  11279. if (netif_running(dev))
  11280. bnx2x_nic_load(bp, LOAD_NORMAL);
  11281. netif_device_attach(dev);
  11282. rtnl_unlock();
  11283. }
  11284. static const struct pci_error_handlers bnx2x_err_handler = {
  11285. .error_detected = bnx2x_io_error_detected,
  11286. .slot_reset = bnx2x_io_slot_reset,
  11287. .resume = bnx2x_io_resume,
  11288. };
  11289. static void bnx2x_shutdown(struct pci_dev *pdev)
  11290. {
  11291. struct net_device *dev = pci_get_drvdata(pdev);
  11292. struct bnx2x *bp;
  11293. if (!dev)
  11294. return;
  11295. bp = netdev_priv(dev);
  11296. if (!bp)
  11297. return;
  11298. rtnl_lock();
  11299. netif_device_detach(dev);
  11300. rtnl_unlock();
  11301. /* Don't remove the netdevice, as there are scenarios which will cause
  11302. * the kernel to hang, e.g., when trying to remove bnx2i while the
  11303. * rootfs is mounted from SAN.
  11304. */
  11305. __bnx2x_remove(pdev, dev, bp, false);
  11306. }
  11307. static struct pci_driver bnx2x_pci_driver = {
  11308. .name = DRV_MODULE_NAME,
  11309. .id_table = bnx2x_pci_tbl,
  11310. .probe = bnx2x_init_one,
  11311. .remove = bnx2x_remove_one,
  11312. .suspend = bnx2x_suspend,
  11313. .resume = bnx2x_resume,
  11314. .err_handler = &bnx2x_err_handler,
  11315. #ifdef CONFIG_BNX2X_SRIOV
  11316. .sriov_configure = bnx2x_sriov_configure,
  11317. #endif
  11318. .shutdown = bnx2x_shutdown,
  11319. };
  11320. static int __init bnx2x_init(void)
  11321. {
  11322. int ret;
  11323. pr_info("%s", version);
  11324. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  11325. if (bnx2x_wq == NULL) {
  11326. pr_err("Cannot create workqueue\n");
  11327. return -ENOMEM;
  11328. }
  11329. bnx2x_iov_wq = create_singlethread_workqueue("bnx2x_iov");
  11330. if (!bnx2x_iov_wq) {
  11331. pr_err("Cannot create iov workqueue\n");
  11332. destroy_workqueue(bnx2x_wq);
  11333. return -ENOMEM;
  11334. }
  11335. ret = pci_register_driver(&bnx2x_pci_driver);
  11336. if (ret) {
  11337. pr_err("Cannot register driver\n");
  11338. destroy_workqueue(bnx2x_wq);
  11339. destroy_workqueue(bnx2x_iov_wq);
  11340. }
  11341. return ret;
  11342. }
  11343. static void __exit bnx2x_cleanup(void)
  11344. {
  11345. struct list_head *pos, *q;
  11346. pci_unregister_driver(&bnx2x_pci_driver);
  11347. destroy_workqueue(bnx2x_wq);
  11348. destroy_workqueue(bnx2x_iov_wq);
  11349. /* Free globally allocated resources */
  11350. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  11351. struct bnx2x_prev_path_list *tmp =
  11352. list_entry(pos, struct bnx2x_prev_path_list, list);
  11353. list_del(pos);
  11354. kfree(tmp);
  11355. }
  11356. }
  11357. void bnx2x_notify_link_changed(struct bnx2x *bp)
  11358. {
  11359. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  11360. }
  11361. module_init(bnx2x_init);
  11362. module_exit(bnx2x_cleanup);
  11363. /**
  11364. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  11365. *
  11366. * @bp: driver handle
  11367. * @set: set or clear the CAM entry
  11368. *
  11369. * This function will wait until the ramrod completion returns.
  11370. * Return 0 if success, -ENODEV if ramrod doesn't return.
  11371. */
  11372. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  11373. {
  11374. unsigned long ramrod_flags = 0;
  11375. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  11376. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  11377. &bp->iscsi_l2_mac_obj, true,
  11378. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  11379. }
  11380. /* count denotes the number of new completions we have seen */
  11381. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  11382. {
  11383. struct eth_spe *spe;
  11384. int cxt_index, cxt_offset;
  11385. #ifdef BNX2X_STOP_ON_ERROR
  11386. if (unlikely(bp->panic))
  11387. return;
  11388. #endif
  11389. spin_lock_bh(&bp->spq_lock);
  11390. BUG_ON(bp->cnic_spq_pending < count);
  11391. bp->cnic_spq_pending -= count;
  11392. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  11393. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  11394. & SPE_HDR_CONN_TYPE) >>
  11395. SPE_HDR_CONN_TYPE_SHIFT;
  11396. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  11397. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  11398. /* Set validation for iSCSI L2 client before sending SETUP
  11399. * ramrod
  11400. */
  11401. if (type == ETH_CONNECTION_TYPE) {
  11402. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  11403. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  11404. ILT_PAGE_CIDS;
  11405. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  11406. (cxt_index * ILT_PAGE_CIDS);
  11407. bnx2x_set_ctx_validation(bp,
  11408. &bp->context[cxt_index].
  11409. vcxt[cxt_offset].eth,
  11410. BNX2X_ISCSI_ETH_CID(bp));
  11411. }
  11412. }
  11413. /*
  11414. * There may be not more than 8 L2, not more than 8 L5 SPEs
  11415. * and in the air. We also check that number of outstanding
  11416. * COMMON ramrods is not more than the EQ and SPQ can
  11417. * accommodate.
  11418. */
  11419. if (type == ETH_CONNECTION_TYPE) {
  11420. if (!atomic_read(&bp->cq_spq_left))
  11421. break;
  11422. else
  11423. atomic_dec(&bp->cq_spq_left);
  11424. } else if (type == NONE_CONNECTION_TYPE) {
  11425. if (!atomic_read(&bp->eq_spq_left))
  11426. break;
  11427. else
  11428. atomic_dec(&bp->eq_spq_left);
  11429. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  11430. (type == FCOE_CONNECTION_TYPE)) {
  11431. if (bp->cnic_spq_pending >=
  11432. bp->cnic_eth_dev.max_kwqe_pending)
  11433. break;
  11434. else
  11435. bp->cnic_spq_pending++;
  11436. } else {
  11437. BNX2X_ERR("Unknown SPE type: %d\n", type);
  11438. bnx2x_panic();
  11439. break;
  11440. }
  11441. spe = bnx2x_sp_get_next(bp);
  11442. *spe = *bp->cnic_kwq_cons;
  11443. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  11444. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  11445. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  11446. bp->cnic_kwq_cons = bp->cnic_kwq;
  11447. else
  11448. bp->cnic_kwq_cons++;
  11449. }
  11450. bnx2x_sp_prod_update(bp);
  11451. spin_unlock_bh(&bp->spq_lock);
  11452. }
  11453. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  11454. struct kwqe_16 *kwqes[], u32 count)
  11455. {
  11456. struct bnx2x *bp = netdev_priv(dev);
  11457. int i;
  11458. #ifdef BNX2X_STOP_ON_ERROR
  11459. if (unlikely(bp->panic)) {
  11460. BNX2X_ERR("Can't post to SP queue while panic\n");
  11461. return -EIO;
  11462. }
  11463. #endif
  11464. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  11465. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  11466. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  11467. return -EAGAIN;
  11468. }
  11469. spin_lock_bh(&bp->spq_lock);
  11470. for (i = 0; i < count; i++) {
  11471. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  11472. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  11473. break;
  11474. *bp->cnic_kwq_prod = *spe;
  11475. bp->cnic_kwq_pending++;
  11476. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  11477. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  11478. spe->data.update_data_addr.hi,
  11479. spe->data.update_data_addr.lo,
  11480. bp->cnic_kwq_pending);
  11481. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  11482. bp->cnic_kwq_prod = bp->cnic_kwq;
  11483. else
  11484. bp->cnic_kwq_prod++;
  11485. }
  11486. spin_unlock_bh(&bp->spq_lock);
  11487. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  11488. bnx2x_cnic_sp_post(bp, 0);
  11489. return i;
  11490. }
  11491. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11492. {
  11493. struct cnic_ops *c_ops;
  11494. int rc = 0;
  11495. mutex_lock(&bp->cnic_mutex);
  11496. c_ops = rcu_dereference_protected(bp->cnic_ops,
  11497. lockdep_is_held(&bp->cnic_mutex));
  11498. if (c_ops)
  11499. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11500. mutex_unlock(&bp->cnic_mutex);
  11501. return rc;
  11502. }
  11503. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11504. {
  11505. struct cnic_ops *c_ops;
  11506. int rc = 0;
  11507. rcu_read_lock();
  11508. c_ops = rcu_dereference(bp->cnic_ops);
  11509. if (c_ops)
  11510. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11511. rcu_read_unlock();
  11512. return rc;
  11513. }
  11514. /*
  11515. * for commands that have no data
  11516. */
  11517. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  11518. {
  11519. struct cnic_ctl_info ctl = {0};
  11520. ctl.cmd = cmd;
  11521. return bnx2x_cnic_ctl_send(bp, &ctl);
  11522. }
  11523. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  11524. {
  11525. struct cnic_ctl_info ctl = {0};
  11526. /* first we tell CNIC and only then we count this as a completion */
  11527. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  11528. ctl.data.comp.cid = cid;
  11529. ctl.data.comp.error = err;
  11530. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  11531. bnx2x_cnic_sp_post(bp, 0);
  11532. }
  11533. /* Called with netif_addr_lock_bh() taken.
  11534. * Sets an rx_mode config for an iSCSI ETH client.
  11535. * Doesn't block.
  11536. * Completion should be checked outside.
  11537. */
  11538. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  11539. {
  11540. unsigned long accept_flags = 0, ramrod_flags = 0;
  11541. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11542. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  11543. if (start) {
  11544. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  11545. * because it's the only way for UIO Queue to accept
  11546. * multicasts (in non-promiscuous mode only one Queue per
  11547. * function will receive multicast packets (leading in our
  11548. * case).
  11549. */
  11550. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  11551. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  11552. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  11553. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  11554. /* Clear STOP_PENDING bit if START is requested */
  11555. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  11556. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  11557. } else
  11558. /* Clear START_PENDING bit if STOP is requested */
  11559. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  11560. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  11561. set_bit(sched_state, &bp->sp_state);
  11562. else {
  11563. __set_bit(RAMROD_RX, &ramrod_flags);
  11564. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  11565. ramrod_flags);
  11566. }
  11567. }
  11568. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  11569. {
  11570. struct bnx2x *bp = netdev_priv(dev);
  11571. int rc = 0;
  11572. switch (ctl->cmd) {
  11573. case DRV_CTL_CTXTBL_WR_CMD: {
  11574. u32 index = ctl->data.io.offset;
  11575. dma_addr_t addr = ctl->data.io.dma_addr;
  11576. bnx2x_ilt_wr(bp, index, addr);
  11577. break;
  11578. }
  11579. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  11580. int count = ctl->data.credit.credit_count;
  11581. bnx2x_cnic_sp_post(bp, count);
  11582. break;
  11583. }
  11584. /* rtnl_lock is held. */
  11585. case DRV_CTL_START_L2_CMD: {
  11586. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11587. unsigned long sp_bits = 0;
  11588. /* Configure the iSCSI classification object */
  11589. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  11590. cp->iscsi_l2_client_id,
  11591. cp->iscsi_l2_cid, BP_FUNC(bp),
  11592. bnx2x_sp(bp, mac_rdata),
  11593. bnx2x_sp_mapping(bp, mac_rdata),
  11594. BNX2X_FILTER_MAC_PENDING,
  11595. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  11596. &bp->macs_pool);
  11597. /* Set iSCSI MAC address */
  11598. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  11599. if (rc)
  11600. break;
  11601. mmiowb();
  11602. barrier();
  11603. /* Start accepting on iSCSI L2 ring */
  11604. netif_addr_lock_bh(dev);
  11605. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  11606. netif_addr_unlock_bh(dev);
  11607. /* bits to wait on */
  11608. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11609. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  11610. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11611. BNX2X_ERR("rx_mode completion timed out!\n");
  11612. break;
  11613. }
  11614. /* rtnl_lock is held. */
  11615. case DRV_CTL_STOP_L2_CMD: {
  11616. unsigned long sp_bits = 0;
  11617. /* Stop accepting on iSCSI L2 ring */
  11618. netif_addr_lock_bh(dev);
  11619. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  11620. netif_addr_unlock_bh(dev);
  11621. /* bits to wait on */
  11622. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11623. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  11624. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11625. BNX2X_ERR("rx_mode completion timed out!\n");
  11626. mmiowb();
  11627. barrier();
  11628. /* Unset iSCSI L2 MAC */
  11629. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  11630. BNX2X_ISCSI_ETH_MAC, true);
  11631. break;
  11632. }
  11633. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  11634. int count = ctl->data.credit.credit_count;
  11635. smp_mb__before_atomic();
  11636. atomic_add(count, &bp->cq_spq_left);
  11637. smp_mb__after_atomic();
  11638. break;
  11639. }
  11640. case DRV_CTL_ULP_REGISTER_CMD: {
  11641. int ulp_type = ctl->data.register_data.ulp_type;
  11642. if (CHIP_IS_E3(bp)) {
  11643. int idx = BP_FW_MB_IDX(bp);
  11644. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11645. int path = BP_PATH(bp);
  11646. int port = BP_PORT(bp);
  11647. int i;
  11648. u32 scratch_offset;
  11649. u32 *host_addr;
  11650. /* first write capability to shmem2 */
  11651. if (ulp_type == CNIC_ULP_ISCSI)
  11652. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11653. else if (ulp_type == CNIC_ULP_FCOE)
  11654. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11655. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11656. if ((ulp_type != CNIC_ULP_FCOE) ||
  11657. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  11658. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  11659. break;
  11660. /* if reached here - should write fcoe capabilities */
  11661. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  11662. if (!scratch_offset)
  11663. break;
  11664. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  11665. fcoe_features[path][port]);
  11666. host_addr = (u32 *) &(ctl->data.register_data.
  11667. fcoe_features);
  11668. for (i = 0; i < sizeof(struct fcoe_capabilities);
  11669. i += 4)
  11670. REG_WR(bp, scratch_offset + i,
  11671. *(host_addr + i/4));
  11672. }
  11673. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  11674. break;
  11675. }
  11676. case DRV_CTL_ULP_UNREGISTER_CMD: {
  11677. int ulp_type = ctl->data.ulp_type;
  11678. if (CHIP_IS_E3(bp)) {
  11679. int idx = BP_FW_MB_IDX(bp);
  11680. u32 cap;
  11681. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11682. if (ulp_type == CNIC_ULP_ISCSI)
  11683. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11684. else if (ulp_type == CNIC_ULP_FCOE)
  11685. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11686. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11687. }
  11688. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  11689. break;
  11690. }
  11691. default:
  11692. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  11693. rc = -EINVAL;
  11694. }
  11695. return rc;
  11696. }
  11697. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  11698. {
  11699. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11700. if (bp->flags & USING_MSIX_FLAG) {
  11701. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  11702. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  11703. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  11704. } else {
  11705. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  11706. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  11707. }
  11708. if (!CHIP_IS_E1x(bp))
  11709. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  11710. else
  11711. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  11712. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  11713. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  11714. cp->irq_arr[1].status_blk = bp->def_status_blk;
  11715. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  11716. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  11717. cp->num_irq = 2;
  11718. }
  11719. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  11720. {
  11721. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11722. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11723. bnx2x_cid_ilt_lines(bp);
  11724. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11725. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11726. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11727. DP(NETIF_MSG_IFUP, "BNX2X_1st_NON_L2_ETH_CID(bp) %x, cp->starting_cid %x, cp->fcoe_init_cid %x, cp->iscsi_l2_cid %x\n",
  11728. BNX2X_1st_NON_L2_ETH_CID(bp), cp->starting_cid, cp->fcoe_init_cid,
  11729. cp->iscsi_l2_cid);
  11730. if (NO_ISCSI_OOO(bp))
  11731. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11732. }
  11733. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  11734. void *data)
  11735. {
  11736. struct bnx2x *bp = netdev_priv(dev);
  11737. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11738. int rc;
  11739. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  11740. if (ops == NULL) {
  11741. BNX2X_ERR("NULL ops received\n");
  11742. return -EINVAL;
  11743. }
  11744. if (!CNIC_SUPPORT(bp)) {
  11745. BNX2X_ERR("Can't register CNIC when not supported\n");
  11746. return -EOPNOTSUPP;
  11747. }
  11748. if (!CNIC_LOADED(bp)) {
  11749. rc = bnx2x_load_cnic(bp);
  11750. if (rc) {
  11751. BNX2X_ERR("CNIC-related load failed\n");
  11752. return rc;
  11753. }
  11754. }
  11755. bp->cnic_enabled = true;
  11756. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  11757. if (!bp->cnic_kwq)
  11758. return -ENOMEM;
  11759. bp->cnic_kwq_cons = bp->cnic_kwq;
  11760. bp->cnic_kwq_prod = bp->cnic_kwq;
  11761. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  11762. bp->cnic_spq_pending = 0;
  11763. bp->cnic_kwq_pending = 0;
  11764. bp->cnic_data = data;
  11765. cp->num_irq = 0;
  11766. cp->drv_state |= CNIC_DRV_STATE_REGD;
  11767. cp->iro_arr = bp->iro_arr;
  11768. bnx2x_setup_cnic_irq_info(bp);
  11769. rcu_assign_pointer(bp->cnic_ops, ops);
  11770. /* Schedule driver to read CNIC driver versions */
  11771. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  11772. return 0;
  11773. }
  11774. static int bnx2x_unregister_cnic(struct net_device *dev)
  11775. {
  11776. struct bnx2x *bp = netdev_priv(dev);
  11777. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11778. mutex_lock(&bp->cnic_mutex);
  11779. cp->drv_state = 0;
  11780. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  11781. mutex_unlock(&bp->cnic_mutex);
  11782. synchronize_rcu();
  11783. bp->cnic_enabled = false;
  11784. kfree(bp->cnic_kwq);
  11785. bp->cnic_kwq = NULL;
  11786. return 0;
  11787. }
  11788. static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  11789. {
  11790. struct bnx2x *bp = netdev_priv(dev);
  11791. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11792. /* If both iSCSI and FCoE are disabled - return NULL in
  11793. * order to indicate CNIC that it should not try to work
  11794. * with this device.
  11795. */
  11796. if (NO_ISCSI(bp) && NO_FCOE(bp))
  11797. return NULL;
  11798. cp->drv_owner = THIS_MODULE;
  11799. cp->chip_id = CHIP_ID(bp);
  11800. cp->pdev = bp->pdev;
  11801. cp->io_base = bp->regview;
  11802. cp->io_base2 = bp->doorbells;
  11803. cp->max_kwqe_pending = 8;
  11804. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  11805. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11806. bnx2x_cid_ilt_lines(bp);
  11807. cp->ctx_tbl_len = CNIC_ILT_LINES;
  11808. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11809. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  11810. cp->drv_ctl = bnx2x_drv_ctl;
  11811. cp->drv_register_cnic = bnx2x_register_cnic;
  11812. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  11813. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11814. cp->iscsi_l2_client_id =
  11815. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11816. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11817. if (NO_ISCSI_OOO(bp))
  11818. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11819. if (NO_ISCSI(bp))
  11820. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  11821. if (NO_FCOE(bp))
  11822. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  11823. BNX2X_DEV_INFO(
  11824. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  11825. cp->ctx_blk_size,
  11826. cp->ctx_tbl_offset,
  11827. cp->ctx_tbl_len,
  11828. cp->starting_cid);
  11829. return cp;
  11830. }
  11831. static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  11832. {
  11833. struct bnx2x *bp = fp->bp;
  11834. u32 offset = BAR_USTRORM_INTMEM;
  11835. if (IS_VF(bp))
  11836. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  11837. else if (!CHIP_IS_E1x(bp))
  11838. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  11839. else
  11840. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  11841. return offset;
  11842. }
  11843. /* called only on E1H or E2.
  11844. * When pretending to be PF, the pretend value is the function number 0...7
  11845. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  11846. * combination
  11847. */
  11848. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  11849. {
  11850. u32 pretend_reg;
  11851. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  11852. return -1;
  11853. /* get my own pretend register */
  11854. pretend_reg = bnx2x_get_pretend_reg(bp);
  11855. REG_WR(bp, pretend_reg, pretend_func_val);
  11856. REG_RD(bp, pretend_reg);
  11857. return 0;
  11858. }