bnx2x_main.c 363 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445
  1. /* bnx2x_main.c: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2013 Broadcom Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. *
  9. * Maintained by: Eilon Greenstein <eilong@broadcom.com>
  10. * Written by: Eliezer Tamir
  11. * Based on code from Michael Chan's bnx2 driver
  12. * UDP CSUM errata workaround by Arik Gendelman
  13. * Slowpath and fastpath rework by Vladislav Zolotarov
  14. * Statistics and Link management by Yitchak Gertner
  15. *
  16. */
  17. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  18. #include <linux/module.h>
  19. #include <linux/moduleparam.h>
  20. #include <linux/kernel.h>
  21. #include <linux/device.h> /* for dev_info() */
  22. #include <linux/timer.h>
  23. #include <linux/errno.h>
  24. #include <linux/ioport.h>
  25. #include <linux/slab.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/pci.h>
  28. #include <linux/init.h>
  29. #include <linux/netdevice.h>
  30. #include <linux/etherdevice.h>
  31. #include <linux/skbuff.h>
  32. #include <linux/dma-mapping.h>
  33. #include <linux/bitops.h>
  34. #include <linux/irq.h>
  35. #include <linux/delay.h>
  36. #include <asm/byteorder.h>
  37. #include <linux/time.h>
  38. #include <linux/ethtool.h>
  39. #include <linux/mii.h>
  40. #include <linux/if_vlan.h>
  41. #include <net/ip.h>
  42. #include <net/ipv6.h>
  43. #include <net/tcp.h>
  44. #include <net/checksum.h>
  45. #include <net/ip6_checksum.h>
  46. #include <linux/workqueue.h>
  47. #include <linux/crc32.h>
  48. #include <linux/crc32c.h>
  49. #include <linux/prefetch.h>
  50. #include <linux/zlib.h>
  51. #include <linux/io.h>
  52. #include <linux/semaphore.h>
  53. #include <linux/stringify.h>
  54. #include <linux/vmalloc.h>
  55. #include "bnx2x.h"
  56. #include "bnx2x_init.h"
  57. #include "bnx2x_init_ops.h"
  58. #include "bnx2x_cmn.h"
  59. #include "bnx2x_vfpf.h"
  60. #include "bnx2x_dcb.h"
  61. #include "bnx2x_sp.h"
  62. #include <linux/firmware.h>
  63. #include "bnx2x_fw_file_hdr.h"
  64. /* FW files */
  65. #define FW_FILE_VERSION \
  66. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  67. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  68. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  69. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  70. #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
  71. #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
  72. #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
  73. #define MAC_LEADING_ZERO_CNT (ALIGN(ETH_ALEN, sizeof(u32)) - ETH_ALEN)
  74. /* Time in jiffies before concluding the transmitter is hung */
  75. #define TX_TIMEOUT (5*HZ)
  76. static char version[] =
  77. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  78. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  79. MODULE_AUTHOR("Eliezer Tamir");
  80. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  81. "BCM57710/57711/57711E/"
  82. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  83. "57840/57840_MF Driver");
  84. MODULE_LICENSE("GPL");
  85. MODULE_VERSION(DRV_MODULE_VERSION);
  86. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  87. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  88. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  89. int num_queues;
  90. module_param(num_queues, int, 0);
  91. MODULE_PARM_DESC(num_queues,
  92. " Set number of queues (default is as a number of CPUs)");
  93. static int disable_tpa;
  94. module_param(disable_tpa, int, 0);
  95. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  96. #define INT_MODE_INTx 1
  97. #define INT_MODE_MSI 2
  98. int int_mode;
  99. module_param(int_mode, int, 0);
  100. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  101. "(1 INT#x; 2 MSI)");
  102. static int dropless_fc;
  103. module_param(dropless_fc, int, 0);
  104. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  105. static int mrrs = -1;
  106. module_param(mrrs, int, 0);
  107. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  108. static int debug;
  109. module_param(debug, int, 0);
  110. MODULE_PARM_DESC(debug, " Default debug msglevel");
  111. struct workqueue_struct *bnx2x_wq;
  112. struct bnx2x_mac_vals {
  113. u32 xmac_addr;
  114. u32 xmac_val;
  115. u32 emac_addr;
  116. u32 emac_val;
  117. u32 umac_addr;
  118. u32 umac_val;
  119. u32 bmac_addr;
  120. u32 bmac_val[2];
  121. };
  122. enum bnx2x_board_type {
  123. BCM57710 = 0,
  124. BCM57711,
  125. BCM57711E,
  126. BCM57712,
  127. BCM57712_MF,
  128. BCM57712_VF,
  129. BCM57800,
  130. BCM57800_MF,
  131. BCM57800_VF,
  132. BCM57810,
  133. BCM57810_MF,
  134. BCM57810_VF,
  135. BCM57840_4_10,
  136. BCM57840_2_20,
  137. BCM57840_MF,
  138. BCM57840_VF,
  139. BCM57811,
  140. BCM57811_MF,
  141. BCM57840_O,
  142. BCM57840_MFO,
  143. BCM57811_VF
  144. };
  145. /* indexed by board_type, above */
  146. static struct {
  147. char *name;
  148. } board_info[] = {
  149. [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  150. [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  151. [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  152. [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  153. [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  154. [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
  155. [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  156. [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  157. [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
  158. [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  159. [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  160. [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
  161. [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
  162. [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
  163. [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  164. [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
  165. [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
  166. [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
  167. [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  168. [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  169. [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
  170. };
  171. #ifndef PCI_DEVICE_ID_NX2_57710
  172. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  173. #endif
  174. #ifndef PCI_DEVICE_ID_NX2_57711
  175. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  176. #endif
  177. #ifndef PCI_DEVICE_ID_NX2_57711E
  178. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  179. #endif
  180. #ifndef PCI_DEVICE_ID_NX2_57712
  181. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  182. #endif
  183. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  184. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  185. #endif
  186. #ifndef PCI_DEVICE_ID_NX2_57712_VF
  187. #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
  188. #endif
  189. #ifndef PCI_DEVICE_ID_NX2_57800
  190. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  191. #endif
  192. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  193. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  194. #endif
  195. #ifndef PCI_DEVICE_ID_NX2_57800_VF
  196. #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
  197. #endif
  198. #ifndef PCI_DEVICE_ID_NX2_57810
  199. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  200. #endif
  201. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  202. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  203. #endif
  204. #ifndef PCI_DEVICE_ID_NX2_57840_O
  205. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  206. #endif
  207. #ifndef PCI_DEVICE_ID_NX2_57810_VF
  208. #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
  209. #endif
  210. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  211. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  212. #endif
  213. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  214. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  215. #endif
  216. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  217. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  218. #endif
  219. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  220. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  221. #endif
  222. #ifndef PCI_DEVICE_ID_NX2_57840_VF
  223. #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
  224. #endif
  225. #ifndef PCI_DEVICE_ID_NX2_57811
  226. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  227. #endif
  228. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  229. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  230. #endif
  231. #ifndef PCI_DEVICE_ID_NX2_57811_VF
  232. #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
  233. #endif
  234. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  235. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  236. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  237. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  238. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  239. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  240. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
  241. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  242. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  243. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
  244. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  245. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  246. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  247. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  248. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  249. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
  250. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  251. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  252. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  253. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  254. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  255. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
  256. { 0 }
  257. };
  258. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  259. /* Global resources for unloading a previously loaded device */
  260. #define BNX2X_PREV_WAIT_NEEDED 1
  261. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  262. static LIST_HEAD(bnx2x_prev_list);
  263. /****************************************************************************
  264. * General service functions
  265. ****************************************************************************/
  266. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  267. u32 addr, dma_addr_t mapping)
  268. {
  269. REG_WR(bp, addr, U64_LO(mapping));
  270. REG_WR(bp, addr + 4, U64_HI(mapping));
  271. }
  272. static void storm_memset_spq_addr(struct bnx2x *bp,
  273. dma_addr_t mapping, u16 abs_fid)
  274. {
  275. u32 addr = XSEM_REG_FAST_MEMORY +
  276. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  277. __storm_memset_dma_mapping(bp, addr, mapping);
  278. }
  279. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  280. u16 pf_id)
  281. {
  282. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  283. pf_id);
  284. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  285. pf_id);
  286. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  287. pf_id);
  288. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  289. pf_id);
  290. }
  291. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  292. u8 enable)
  293. {
  294. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  295. enable);
  296. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  297. enable);
  298. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  299. enable);
  300. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  301. enable);
  302. }
  303. static void storm_memset_eq_data(struct bnx2x *bp,
  304. struct event_ring_data *eq_data,
  305. u16 pfid)
  306. {
  307. size_t size = sizeof(struct event_ring_data);
  308. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  309. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  310. }
  311. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  312. u16 pfid)
  313. {
  314. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  315. REG_WR16(bp, addr, eq_prod);
  316. }
  317. /* used only at init
  318. * locking is done by mcp
  319. */
  320. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  321. {
  322. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  323. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  324. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  325. PCICFG_VENDOR_ID_OFFSET);
  326. }
  327. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  328. {
  329. u32 val;
  330. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  331. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  332. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  333. PCICFG_VENDOR_ID_OFFSET);
  334. return val;
  335. }
  336. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  337. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  338. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  339. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  340. #define DMAE_DP_DST_NONE "dst_addr [none]"
  341. void bnx2x_dp_dmae(struct bnx2x *bp, struct dmae_command *dmae, int msglvl)
  342. {
  343. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  344. switch (dmae->opcode & DMAE_COMMAND_DST) {
  345. case DMAE_CMD_DST_PCI:
  346. if (src_type == DMAE_CMD_SRC_PCI)
  347. DP(msglvl, "DMAE: opcode 0x%08x\n"
  348. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  349. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  350. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  351. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  352. dmae->comp_addr_hi, dmae->comp_addr_lo,
  353. dmae->comp_val);
  354. else
  355. DP(msglvl, "DMAE: opcode 0x%08x\n"
  356. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  357. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  358. dmae->opcode, dmae->src_addr_lo >> 2,
  359. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  360. dmae->comp_addr_hi, dmae->comp_addr_lo,
  361. dmae->comp_val);
  362. break;
  363. case DMAE_CMD_DST_GRC:
  364. if (src_type == DMAE_CMD_SRC_PCI)
  365. DP(msglvl, "DMAE: opcode 0x%08x\n"
  366. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  367. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  368. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  369. dmae->len, dmae->dst_addr_lo >> 2,
  370. dmae->comp_addr_hi, dmae->comp_addr_lo,
  371. dmae->comp_val);
  372. else
  373. DP(msglvl, "DMAE: opcode 0x%08x\n"
  374. "src [%08x], len [%d*4], dst [%08x]\n"
  375. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  376. dmae->opcode, dmae->src_addr_lo >> 2,
  377. dmae->len, dmae->dst_addr_lo >> 2,
  378. dmae->comp_addr_hi, dmae->comp_addr_lo,
  379. dmae->comp_val);
  380. break;
  381. default:
  382. if (src_type == DMAE_CMD_SRC_PCI)
  383. DP(msglvl, "DMAE: opcode 0x%08x\n"
  384. "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
  385. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  386. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  387. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  388. dmae->comp_val);
  389. else
  390. DP(msglvl, "DMAE: opcode 0x%08x\n"
  391. "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
  392. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  393. dmae->opcode, dmae->src_addr_lo >> 2,
  394. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  395. dmae->comp_val);
  396. break;
  397. }
  398. }
  399. /* copy command into DMAE command memory and set DMAE command go */
  400. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  401. {
  402. u32 cmd_offset;
  403. int i;
  404. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  405. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  406. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  407. }
  408. REG_WR(bp, dmae_reg_go_c[idx], 1);
  409. }
  410. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  411. {
  412. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  413. DMAE_CMD_C_ENABLE);
  414. }
  415. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  416. {
  417. return opcode & ~DMAE_CMD_SRC_RESET;
  418. }
  419. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  420. bool with_comp, u8 comp_type)
  421. {
  422. u32 opcode = 0;
  423. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  424. (dst_type << DMAE_COMMAND_DST_SHIFT));
  425. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  426. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  427. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  428. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  429. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  430. #ifdef __BIG_ENDIAN
  431. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  432. #else
  433. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  434. #endif
  435. if (with_comp)
  436. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  437. return opcode;
  438. }
  439. void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  440. struct dmae_command *dmae,
  441. u8 src_type, u8 dst_type)
  442. {
  443. memset(dmae, 0, sizeof(struct dmae_command));
  444. /* set the opcode */
  445. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  446. true, DMAE_COMP_PCI);
  447. /* fill in the completion parameters */
  448. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  449. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  450. dmae->comp_val = DMAE_COMP_VAL;
  451. }
  452. /* issue a dmae command over the init-channel and wait for completion */
  453. int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae)
  454. {
  455. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  456. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  457. int rc = 0;
  458. /*
  459. * Lock the dmae channel. Disable BHs to prevent a dead-lock
  460. * as long as this code is called both from syscall context and
  461. * from ndo_set_rx_mode() flow that may be called from BH.
  462. */
  463. spin_lock_bh(&bp->dmae_lock);
  464. /* reset completion */
  465. *wb_comp = 0;
  466. /* post the command on the channel used for initializations */
  467. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  468. /* wait for completion */
  469. udelay(5);
  470. while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  471. if (!cnt ||
  472. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  473. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  474. BNX2X_ERR("DMAE timeout!\n");
  475. rc = DMAE_TIMEOUT;
  476. goto unlock;
  477. }
  478. cnt--;
  479. udelay(50);
  480. }
  481. if (*wb_comp & DMAE_PCI_ERR_FLAG) {
  482. BNX2X_ERR("DMAE PCI error!\n");
  483. rc = DMAE_PCI_ERROR;
  484. }
  485. unlock:
  486. spin_unlock_bh(&bp->dmae_lock);
  487. return rc;
  488. }
  489. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  490. u32 len32)
  491. {
  492. struct dmae_command dmae;
  493. if (!bp->dmae_ready) {
  494. u32 *data = bnx2x_sp(bp, wb_data[0]);
  495. if (CHIP_IS_E1(bp))
  496. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  497. else
  498. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  499. return;
  500. }
  501. /* set opcode and fixed command fields */
  502. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  503. /* fill in addresses and len */
  504. dmae.src_addr_lo = U64_LO(dma_addr);
  505. dmae.src_addr_hi = U64_HI(dma_addr);
  506. dmae.dst_addr_lo = dst_addr >> 2;
  507. dmae.dst_addr_hi = 0;
  508. dmae.len = len32;
  509. /* issue the command and wait for completion */
  510. bnx2x_issue_dmae_with_comp(bp, &dmae);
  511. }
  512. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  513. {
  514. struct dmae_command dmae;
  515. if (!bp->dmae_ready) {
  516. u32 *data = bnx2x_sp(bp, wb_data[0]);
  517. int i;
  518. if (CHIP_IS_E1(bp))
  519. for (i = 0; i < len32; i++)
  520. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  521. else
  522. for (i = 0; i < len32; i++)
  523. data[i] = REG_RD(bp, src_addr + i*4);
  524. return;
  525. }
  526. /* set opcode and fixed command fields */
  527. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  528. /* fill in addresses and len */
  529. dmae.src_addr_lo = src_addr >> 2;
  530. dmae.src_addr_hi = 0;
  531. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  532. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  533. dmae.len = len32;
  534. /* issue the command and wait for completion */
  535. bnx2x_issue_dmae_with_comp(bp, &dmae);
  536. }
  537. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  538. u32 addr, u32 len)
  539. {
  540. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  541. int offset = 0;
  542. while (len > dmae_wr_max) {
  543. bnx2x_write_dmae(bp, phys_addr + offset,
  544. addr + offset, dmae_wr_max);
  545. offset += dmae_wr_max * 4;
  546. len -= dmae_wr_max;
  547. }
  548. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  549. }
  550. static int bnx2x_mc_assert(struct bnx2x *bp)
  551. {
  552. char last_idx;
  553. int i, rc = 0;
  554. u32 row0, row1, row2, row3;
  555. /* XSTORM */
  556. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  557. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  558. if (last_idx)
  559. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  560. /* print the asserts */
  561. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  562. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  563. XSTORM_ASSERT_LIST_OFFSET(i));
  564. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  565. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  566. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  567. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  568. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  569. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  570. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  571. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  572. i, row3, row2, row1, row0);
  573. rc++;
  574. } else {
  575. break;
  576. }
  577. }
  578. /* TSTORM */
  579. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  580. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  581. if (last_idx)
  582. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  583. /* print the asserts */
  584. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  585. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  586. TSTORM_ASSERT_LIST_OFFSET(i));
  587. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  588. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  589. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  590. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  591. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  592. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  593. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  594. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  595. i, row3, row2, row1, row0);
  596. rc++;
  597. } else {
  598. break;
  599. }
  600. }
  601. /* CSTORM */
  602. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  603. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  604. if (last_idx)
  605. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  606. /* print the asserts */
  607. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  608. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  609. CSTORM_ASSERT_LIST_OFFSET(i));
  610. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  611. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  612. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  613. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  614. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  615. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  616. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  617. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  618. i, row3, row2, row1, row0);
  619. rc++;
  620. } else {
  621. break;
  622. }
  623. }
  624. /* USTORM */
  625. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  626. USTORM_ASSERT_LIST_INDEX_OFFSET);
  627. if (last_idx)
  628. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  629. /* print the asserts */
  630. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  631. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  632. USTORM_ASSERT_LIST_OFFSET(i));
  633. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  634. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  635. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  636. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  637. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  638. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  639. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  640. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  641. i, row3, row2, row1, row0);
  642. rc++;
  643. } else {
  644. break;
  645. }
  646. }
  647. return rc;
  648. }
  649. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  650. {
  651. u32 addr, val;
  652. u32 mark, offset;
  653. __be32 data[9];
  654. int word;
  655. u32 trace_shmem_base;
  656. if (BP_NOMCP(bp)) {
  657. BNX2X_ERR("NO MCP - can not dump\n");
  658. return;
  659. }
  660. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  661. (bp->common.bc_ver & 0xff0000) >> 16,
  662. (bp->common.bc_ver & 0xff00) >> 8,
  663. (bp->common.bc_ver & 0xff));
  664. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  665. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  666. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  667. if (BP_PATH(bp) == 0)
  668. trace_shmem_base = bp->common.shmem_base;
  669. else
  670. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  671. addr = trace_shmem_base - 0x800;
  672. /* validate TRCB signature */
  673. mark = REG_RD(bp, addr);
  674. if (mark != MFW_TRACE_SIGNATURE) {
  675. BNX2X_ERR("Trace buffer signature is missing.");
  676. return ;
  677. }
  678. /* read cyclic buffer pointer */
  679. addr += 4;
  680. mark = REG_RD(bp, addr);
  681. mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
  682. + ((mark + 0x3) & ~0x3) - 0x08000000;
  683. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  684. printk("%s", lvl);
  685. /* dump buffer after the mark */
  686. for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
  687. for (word = 0; word < 8; word++)
  688. data[word] = htonl(REG_RD(bp, offset + 4*word));
  689. data[8] = 0x0;
  690. pr_cont("%s", (char *)data);
  691. }
  692. /* dump buffer before the mark */
  693. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  694. for (word = 0; word < 8; word++)
  695. data[word] = htonl(REG_RD(bp, offset + 4*word));
  696. data[8] = 0x0;
  697. pr_cont("%s", (char *)data);
  698. }
  699. printk("%s" "end of fw dump\n", lvl);
  700. }
  701. static void bnx2x_fw_dump(struct bnx2x *bp)
  702. {
  703. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  704. }
  705. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  706. {
  707. int port = BP_PORT(bp);
  708. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  709. u32 val = REG_RD(bp, addr);
  710. /* in E1 we must use only PCI configuration space to disable
  711. * MSI/MSIX capablility
  712. * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  713. */
  714. if (CHIP_IS_E1(bp)) {
  715. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  716. * Use mask register to prevent from HC sending interrupts
  717. * after we exit the function
  718. */
  719. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  720. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  721. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  722. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  723. } else
  724. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  725. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  726. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  727. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  728. DP(NETIF_MSG_IFDOWN,
  729. "write %x to HC %d (addr 0x%x)\n",
  730. val, port, addr);
  731. /* flush all outstanding writes */
  732. mmiowb();
  733. REG_WR(bp, addr, val);
  734. if (REG_RD(bp, addr) != val)
  735. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  736. }
  737. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  738. {
  739. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  740. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  741. IGU_PF_CONF_INT_LINE_EN |
  742. IGU_PF_CONF_ATTN_BIT_EN);
  743. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  744. /* flush all outstanding writes */
  745. mmiowb();
  746. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  747. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  748. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  749. }
  750. static void bnx2x_int_disable(struct bnx2x *bp)
  751. {
  752. if (bp->common.int_block == INT_BLOCK_HC)
  753. bnx2x_hc_int_disable(bp);
  754. else
  755. bnx2x_igu_int_disable(bp);
  756. }
  757. void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
  758. {
  759. int i;
  760. u16 j;
  761. struct hc_sp_status_block_data sp_sb_data;
  762. int func = BP_FUNC(bp);
  763. #ifdef BNX2X_STOP_ON_ERROR
  764. u16 start = 0, end = 0;
  765. u8 cos;
  766. #endif
  767. if (disable_int)
  768. bnx2x_int_disable(bp);
  769. bp->stats_state = STATS_STATE_DISABLED;
  770. bp->eth_stats.unrecoverable_error++;
  771. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  772. BNX2X_ERR("begin crash dump -----------------\n");
  773. /* Indices */
  774. /* Common */
  775. BNX2X_ERR("def_idx(0x%x) def_att_idx(0x%x) attn_state(0x%x) spq_prod_idx(0x%x) next_stats_cnt(0x%x)\n",
  776. bp->def_idx, bp->def_att_idx, bp->attn_state,
  777. bp->spq_prod_idx, bp->stats_counter);
  778. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  779. bp->def_status_blk->atten_status_block.attn_bits,
  780. bp->def_status_blk->atten_status_block.attn_bits_ack,
  781. bp->def_status_blk->atten_status_block.status_block_id,
  782. bp->def_status_blk->atten_status_block.attn_bits_index);
  783. BNX2X_ERR(" def (");
  784. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  785. pr_cont("0x%x%s",
  786. bp->def_status_blk->sp_sb.index_values[i],
  787. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  788. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  789. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  790. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  791. i*sizeof(u32));
  792. pr_cont("igu_sb_id(0x%x) igu_seg_id(0x%x) pf_id(0x%x) vnic_id(0x%x) vf_id(0x%x) vf_valid (0x%x) state(0x%x)\n",
  793. sp_sb_data.igu_sb_id,
  794. sp_sb_data.igu_seg_id,
  795. sp_sb_data.p_func.pf_id,
  796. sp_sb_data.p_func.vnic_id,
  797. sp_sb_data.p_func.vf_id,
  798. sp_sb_data.p_func.vf_valid,
  799. sp_sb_data.state);
  800. for_each_eth_queue(bp, i) {
  801. struct bnx2x_fastpath *fp = &bp->fp[i];
  802. int loop;
  803. struct hc_status_block_data_e2 sb_data_e2;
  804. struct hc_status_block_data_e1x sb_data_e1x;
  805. struct hc_status_block_sm *hc_sm_p =
  806. CHIP_IS_E1x(bp) ?
  807. sb_data_e1x.common.state_machine :
  808. sb_data_e2.common.state_machine;
  809. struct hc_index_data *hc_index_p =
  810. CHIP_IS_E1x(bp) ?
  811. sb_data_e1x.index_data :
  812. sb_data_e2.index_data;
  813. u8 data_size, cos;
  814. u32 *sb_data_p;
  815. struct bnx2x_fp_txdata txdata;
  816. /* Rx */
  817. BNX2X_ERR("fp%d: rx_bd_prod(0x%x) rx_bd_cons(0x%x) rx_comp_prod(0x%x) rx_comp_cons(0x%x) *rx_cons_sb(0x%x)\n",
  818. i, fp->rx_bd_prod, fp->rx_bd_cons,
  819. fp->rx_comp_prod,
  820. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  821. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  822. fp->rx_sge_prod, fp->last_max_sge,
  823. le16_to_cpu(fp->fp_hc_idx));
  824. /* Tx */
  825. for_each_cos_in_tx_queue(fp, cos)
  826. {
  827. txdata = *fp->txdata_ptr[cos];
  828. BNX2X_ERR("fp%d: tx_pkt_prod(0x%x) tx_pkt_cons(0x%x) tx_bd_prod(0x%x) tx_bd_cons(0x%x) *tx_cons_sb(0x%x)\n",
  829. i, txdata.tx_pkt_prod,
  830. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  831. txdata.tx_bd_cons,
  832. le16_to_cpu(*txdata.tx_cons_sb));
  833. }
  834. loop = CHIP_IS_E1x(bp) ?
  835. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  836. /* host sb data */
  837. if (IS_FCOE_FP(fp))
  838. continue;
  839. BNX2X_ERR(" run indexes (");
  840. for (j = 0; j < HC_SB_MAX_SM; j++)
  841. pr_cont("0x%x%s",
  842. fp->sb_running_index[j],
  843. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  844. BNX2X_ERR(" indexes (");
  845. for (j = 0; j < loop; j++)
  846. pr_cont("0x%x%s",
  847. fp->sb_index_values[j],
  848. (j == loop - 1) ? ")" : " ");
  849. /* fw sb data */
  850. data_size = CHIP_IS_E1x(bp) ?
  851. sizeof(struct hc_status_block_data_e1x) :
  852. sizeof(struct hc_status_block_data_e2);
  853. data_size /= sizeof(u32);
  854. sb_data_p = CHIP_IS_E1x(bp) ?
  855. (u32 *)&sb_data_e1x :
  856. (u32 *)&sb_data_e2;
  857. /* copy sb data in here */
  858. for (j = 0; j < data_size; j++)
  859. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  860. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  861. j * sizeof(u32));
  862. if (!CHIP_IS_E1x(bp)) {
  863. pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) vnic_id(0x%x) same_igu_sb_1b(0x%x) state(0x%x)\n",
  864. sb_data_e2.common.p_func.pf_id,
  865. sb_data_e2.common.p_func.vf_id,
  866. sb_data_e2.common.p_func.vf_valid,
  867. sb_data_e2.common.p_func.vnic_id,
  868. sb_data_e2.common.same_igu_sb_1b,
  869. sb_data_e2.common.state);
  870. } else {
  871. pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) vnic_id(0x%x) same_igu_sb_1b(0x%x) state(0x%x)\n",
  872. sb_data_e1x.common.p_func.pf_id,
  873. sb_data_e1x.common.p_func.vf_id,
  874. sb_data_e1x.common.p_func.vf_valid,
  875. sb_data_e1x.common.p_func.vnic_id,
  876. sb_data_e1x.common.same_igu_sb_1b,
  877. sb_data_e1x.common.state);
  878. }
  879. /* SB_SMs data */
  880. for (j = 0; j < HC_SB_MAX_SM; j++) {
  881. pr_cont("SM[%d] __flags (0x%x) igu_sb_id (0x%x) igu_seg_id(0x%x) time_to_expire (0x%x) timer_value(0x%x)\n",
  882. j, hc_sm_p[j].__flags,
  883. hc_sm_p[j].igu_sb_id,
  884. hc_sm_p[j].igu_seg_id,
  885. hc_sm_p[j].time_to_expire,
  886. hc_sm_p[j].timer_value);
  887. }
  888. /* Indecies data */
  889. for (j = 0; j < loop; j++) {
  890. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  891. hc_index_p[j].flags,
  892. hc_index_p[j].timeout);
  893. }
  894. }
  895. #ifdef BNX2X_STOP_ON_ERROR
  896. /* event queue */
  897. for (i = 0; i < NUM_EQ_DESC; i++) {
  898. u32 *data = (u32 *)&bp->eq_ring[i].message.data;
  899. BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
  900. i, bp->eq_ring[i].message.opcode,
  901. bp->eq_ring[i].message.error);
  902. BNX2X_ERR("data: %x %x %x\n", data[0], data[1], data[2]);
  903. }
  904. /* Rings */
  905. /* Rx */
  906. for_each_valid_rx_queue(bp, i) {
  907. struct bnx2x_fastpath *fp = &bp->fp[i];
  908. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  909. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  910. for (j = start; j != end; j = RX_BD(j + 1)) {
  911. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  912. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  913. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  914. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  915. }
  916. start = RX_SGE(fp->rx_sge_prod);
  917. end = RX_SGE(fp->last_max_sge);
  918. for (j = start; j != end; j = RX_SGE(j + 1)) {
  919. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  920. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  921. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  922. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  923. }
  924. start = RCQ_BD(fp->rx_comp_cons - 10);
  925. end = RCQ_BD(fp->rx_comp_cons + 503);
  926. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  927. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  928. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  929. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  930. }
  931. }
  932. /* Tx */
  933. for_each_valid_tx_queue(bp, i) {
  934. struct bnx2x_fastpath *fp = &bp->fp[i];
  935. for_each_cos_in_tx_queue(fp, cos) {
  936. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  937. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  938. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  939. for (j = start; j != end; j = TX_BD(j + 1)) {
  940. struct sw_tx_bd *sw_bd =
  941. &txdata->tx_buf_ring[j];
  942. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  943. i, cos, j, sw_bd->skb,
  944. sw_bd->first_bd);
  945. }
  946. start = TX_BD(txdata->tx_bd_cons - 10);
  947. end = TX_BD(txdata->tx_bd_cons + 254);
  948. for (j = start; j != end; j = TX_BD(j + 1)) {
  949. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  950. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  951. i, cos, j, tx_bd[0], tx_bd[1],
  952. tx_bd[2], tx_bd[3]);
  953. }
  954. }
  955. }
  956. #endif
  957. bnx2x_fw_dump(bp);
  958. bnx2x_mc_assert(bp);
  959. BNX2X_ERR("end crash dump -----------------\n");
  960. }
  961. /*
  962. * FLR Support for E2
  963. *
  964. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  965. * initialization.
  966. */
  967. #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
  968. #define FLR_WAIT_INTERVAL 50 /* usec */
  969. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  970. struct pbf_pN_buf_regs {
  971. int pN;
  972. u32 init_crd;
  973. u32 crd;
  974. u32 crd_freed;
  975. };
  976. struct pbf_pN_cmd_regs {
  977. int pN;
  978. u32 lines_occup;
  979. u32 lines_freed;
  980. };
  981. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  982. struct pbf_pN_buf_regs *regs,
  983. u32 poll_count)
  984. {
  985. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  986. u32 cur_cnt = poll_count;
  987. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  988. crd = crd_start = REG_RD(bp, regs->crd);
  989. init_crd = REG_RD(bp, regs->init_crd);
  990. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  991. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  992. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  993. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  994. (init_crd - crd_start))) {
  995. if (cur_cnt--) {
  996. udelay(FLR_WAIT_INTERVAL);
  997. crd = REG_RD(bp, regs->crd);
  998. crd_freed = REG_RD(bp, regs->crd_freed);
  999. } else {
  1000. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  1001. regs->pN);
  1002. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  1003. regs->pN, crd);
  1004. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  1005. regs->pN, crd_freed);
  1006. break;
  1007. }
  1008. }
  1009. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  1010. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1011. }
  1012. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  1013. struct pbf_pN_cmd_regs *regs,
  1014. u32 poll_count)
  1015. {
  1016. u32 occup, to_free, freed, freed_start;
  1017. u32 cur_cnt = poll_count;
  1018. occup = to_free = REG_RD(bp, regs->lines_occup);
  1019. freed = freed_start = REG_RD(bp, regs->lines_freed);
  1020. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  1021. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  1022. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  1023. if (cur_cnt--) {
  1024. udelay(FLR_WAIT_INTERVAL);
  1025. occup = REG_RD(bp, regs->lines_occup);
  1026. freed = REG_RD(bp, regs->lines_freed);
  1027. } else {
  1028. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  1029. regs->pN);
  1030. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  1031. regs->pN, occup);
  1032. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  1033. regs->pN, freed);
  1034. break;
  1035. }
  1036. }
  1037. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  1038. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1039. }
  1040. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  1041. u32 expected, u32 poll_count)
  1042. {
  1043. u32 cur_cnt = poll_count;
  1044. u32 val;
  1045. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  1046. udelay(FLR_WAIT_INTERVAL);
  1047. return val;
  1048. }
  1049. int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  1050. char *msg, u32 poll_cnt)
  1051. {
  1052. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  1053. if (val != 0) {
  1054. BNX2X_ERR("%s usage count=%d\n", msg, val);
  1055. return 1;
  1056. }
  1057. return 0;
  1058. }
  1059. /* Common routines with VF FLR cleanup */
  1060. u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  1061. {
  1062. /* adjust polling timeout */
  1063. if (CHIP_REV_IS_EMUL(bp))
  1064. return FLR_POLL_CNT * 2000;
  1065. if (CHIP_REV_IS_FPGA(bp))
  1066. return FLR_POLL_CNT * 120;
  1067. return FLR_POLL_CNT;
  1068. }
  1069. void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  1070. {
  1071. struct pbf_pN_cmd_regs cmd_regs[] = {
  1072. {0, (CHIP_IS_E3B0(bp)) ?
  1073. PBF_REG_TQ_OCCUPANCY_Q0 :
  1074. PBF_REG_P0_TQ_OCCUPANCY,
  1075. (CHIP_IS_E3B0(bp)) ?
  1076. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  1077. PBF_REG_P0_TQ_LINES_FREED_CNT},
  1078. {1, (CHIP_IS_E3B0(bp)) ?
  1079. PBF_REG_TQ_OCCUPANCY_Q1 :
  1080. PBF_REG_P1_TQ_OCCUPANCY,
  1081. (CHIP_IS_E3B0(bp)) ?
  1082. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  1083. PBF_REG_P1_TQ_LINES_FREED_CNT},
  1084. {4, (CHIP_IS_E3B0(bp)) ?
  1085. PBF_REG_TQ_OCCUPANCY_LB_Q :
  1086. PBF_REG_P4_TQ_OCCUPANCY,
  1087. (CHIP_IS_E3B0(bp)) ?
  1088. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  1089. PBF_REG_P4_TQ_LINES_FREED_CNT}
  1090. };
  1091. struct pbf_pN_buf_regs buf_regs[] = {
  1092. {0, (CHIP_IS_E3B0(bp)) ?
  1093. PBF_REG_INIT_CRD_Q0 :
  1094. PBF_REG_P0_INIT_CRD ,
  1095. (CHIP_IS_E3B0(bp)) ?
  1096. PBF_REG_CREDIT_Q0 :
  1097. PBF_REG_P0_CREDIT,
  1098. (CHIP_IS_E3B0(bp)) ?
  1099. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1100. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1101. {1, (CHIP_IS_E3B0(bp)) ?
  1102. PBF_REG_INIT_CRD_Q1 :
  1103. PBF_REG_P1_INIT_CRD,
  1104. (CHIP_IS_E3B0(bp)) ?
  1105. PBF_REG_CREDIT_Q1 :
  1106. PBF_REG_P1_CREDIT,
  1107. (CHIP_IS_E3B0(bp)) ?
  1108. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1109. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1110. {4, (CHIP_IS_E3B0(bp)) ?
  1111. PBF_REG_INIT_CRD_LB_Q :
  1112. PBF_REG_P4_INIT_CRD,
  1113. (CHIP_IS_E3B0(bp)) ?
  1114. PBF_REG_CREDIT_LB_Q :
  1115. PBF_REG_P4_CREDIT,
  1116. (CHIP_IS_E3B0(bp)) ?
  1117. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1118. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1119. };
  1120. int i;
  1121. /* Verify the command queues are flushed P0, P1, P4 */
  1122. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1123. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1124. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1125. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1126. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1127. }
  1128. #define OP_GEN_PARAM(param) \
  1129. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1130. #define OP_GEN_TYPE(type) \
  1131. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1132. #define OP_GEN_AGG_VECT(index) \
  1133. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1134. int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
  1135. {
  1136. u32 op_gen_command = 0;
  1137. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1138. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1139. int ret = 0;
  1140. if (REG_RD(bp, comp_addr)) {
  1141. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1142. return 1;
  1143. }
  1144. op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1145. op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1146. op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
  1147. op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1148. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1149. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
  1150. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1151. BNX2X_ERR("FW final cleanup did not succeed\n");
  1152. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1153. (REG_RD(bp, comp_addr)));
  1154. bnx2x_panic();
  1155. return 1;
  1156. }
  1157. /* Zero completion for nxt FLR */
  1158. REG_WR(bp, comp_addr, 0);
  1159. return ret;
  1160. }
  1161. u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1162. {
  1163. u16 status;
  1164. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1165. return status & PCI_EXP_DEVSTA_TRPND;
  1166. }
  1167. /* PF FLR specific routines
  1168. */
  1169. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1170. {
  1171. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1172. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1173. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1174. "CFC PF usage counter timed out",
  1175. poll_cnt))
  1176. return 1;
  1177. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1178. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1179. DORQ_REG_PF_USAGE_CNT,
  1180. "DQ PF usage counter timed out",
  1181. poll_cnt))
  1182. return 1;
  1183. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1184. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1185. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1186. "QM PF usage counter timed out",
  1187. poll_cnt))
  1188. return 1;
  1189. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1190. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1191. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1192. "Timers VNIC usage counter timed out",
  1193. poll_cnt))
  1194. return 1;
  1195. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1196. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1197. "Timers NUM_SCANS usage counter timed out",
  1198. poll_cnt))
  1199. return 1;
  1200. /* Wait DMAE PF usage counter to zero */
  1201. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1202. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1203. "DMAE dommand register timed out",
  1204. poll_cnt))
  1205. return 1;
  1206. return 0;
  1207. }
  1208. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1209. {
  1210. u32 val;
  1211. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1212. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1213. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1214. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1215. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1216. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1217. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1218. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1219. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1220. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1221. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1222. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1223. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1224. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1225. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1226. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1227. val);
  1228. }
  1229. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1230. {
  1231. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1232. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1233. /* Re-enable PF target read access */
  1234. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1235. /* Poll HW usage counters */
  1236. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1237. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1238. return -EBUSY;
  1239. /* Zero the igu 'trailing edge' and 'leading edge' */
  1240. /* Send the FW cleanup command */
  1241. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1242. return -EBUSY;
  1243. /* ATC cleanup */
  1244. /* Verify TX hw is flushed */
  1245. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1246. /* Wait 100ms (not adjusted according to platform) */
  1247. msleep(100);
  1248. /* Verify no pending pci transactions */
  1249. if (bnx2x_is_pcie_pending(bp->pdev))
  1250. BNX2X_ERR("PCIE Transactions still pending\n");
  1251. /* Debug */
  1252. bnx2x_hw_enable_status(bp);
  1253. /*
  1254. * Master enable - Due to WB DMAE writes performed before this
  1255. * register is re-initialized as part of the regular function init
  1256. */
  1257. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1258. return 0;
  1259. }
  1260. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1261. {
  1262. int port = BP_PORT(bp);
  1263. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1264. u32 val = REG_RD(bp, addr);
  1265. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1266. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1267. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1268. if (msix) {
  1269. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1270. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1271. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1272. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1273. if (single_msix)
  1274. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1275. } else if (msi) {
  1276. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1277. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1278. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1279. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1280. } else {
  1281. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1282. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1283. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1284. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1285. if (!CHIP_IS_E1(bp)) {
  1286. DP(NETIF_MSG_IFUP,
  1287. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1288. REG_WR(bp, addr, val);
  1289. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1290. }
  1291. }
  1292. if (CHIP_IS_E1(bp))
  1293. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1294. DP(NETIF_MSG_IFUP,
  1295. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1296. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1297. REG_WR(bp, addr, val);
  1298. /*
  1299. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1300. */
  1301. mmiowb();
  1302. barrier();
  1303. if (!CHIP_IS_E1(bp)) {
  1304. /* init leading/trailing edge */
  1305. if (IS_MF(bp)) {
  1306. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1307. if (bp->port.pmf)
  1308. /* enable nig and gpio3 attention */
  1309. val |= 0x1100;
  1310. } else
  1311. val = 0xffff;
  1312. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1313. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1314. }
  1315. /* Make sure that interrupts are indeed enabled from here on */
  1316. mmiowb();
  1317. }
  1318. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1319. {
  1320. u32 val;
  1321. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1322. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1323. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1324. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1325. if (msix) {
  1326. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1327. IGU_PF_CONF_SINGLE_ISR_EN);
  1328. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1329. IGU_PF_CONF_ATTN_BIT_EN);
  1330. if (single_msix)
  1331. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1332. } else if (msi) {
  1333. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1334. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1335. IGU_PF_CONF_ATTN_BIT_EN |
  1336. IGU_PF_CONF_SINGLE_ISR_EN);
  1337. } else {
  1338. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1339. val |= (IGU_PF_CONF_INT_LINE_EN |
  1340. IGU_PF_CONF_ATTN_BIT_EN |
  1341. IGU_PF_CONF_SINGLE_ISR_EN);
  1342. }
  1343. /* Clean previous status - need to configure igu prior to ack*/
  1344. if ((!msix) || single_msix) {
  1345. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1346. bnx2x_ack_int(bp);
  1347. }
  1348. val |= IGU_PF_CONF_FUNC_EN;
  1349. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1350. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1351. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1352. if (val & IGU_PF_CONF_INT_LINE_EN)
  1353. pci_intx(bp->pdev, true);
  1354. barrier();
  1355. /* init leading/trailing edge */
  1356. if (IS_MF(bp)) {
  1357. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1358. if (bp->port.pmf)
  1359. /* enable nig and gpio3 attention */
  1360. val |= 0x1100;
  1361. } else
  1362. val = 0xffff;
  1363. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1364. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1365. /* Make sure that interrupts are indeed enabled from here on */
  1366. mmiowb();
  1367. }
  1368. void bnx2x_int_enable(struct bnx2x *bp)
  1369. {
  1370. if (bp->common.int_block == INT_BLOCK_HC)
  1371. bnx2x_hc_int_enable(bp);
  1372. else
  1373. bnx2x_igu_int_enable(bp);
  1374. }
  1375. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1376. {
  1377. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1378. int i, offset;
  1379. if (disable_hw)
  1380. /* prevent the HW from sending interrupts */
  1381. bnx2x_int_disable(bp);
  1382. /* make sure all ISRs are done */
  1383. if (msix) {
  1384. synchronize_irq(bp->msix_table[0].vector);
  1385. offset = 1;
  1386. if (CNIC_SUPPORT(bp))
  1387. offset++;
  1388. for_each_eth_queue(bp, i)
  1389. synchronize_irq(bp->msix_table[offset++].vector);
  1390. } else
  1391. synchronize_irq(bp->pdev->irq);
  1392. /* make sure sp_task is not running */
  1393. cancel_delayed_work(&bp->sp_task);
  1394. cancel_delayed_work(&bp->period_task);
  1395. flush_workqueue(bnx2x_wq);
  1396. }
  1397. /* fast path */
  1398. /*
  1399. * General service functions
  1400. */
  1401. /* Return true if succeeded to acquire the lock */
  1402. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1403. {
  1404. u32 lock_status;
  1405. u32 resource_bit = (1 << resource);
  1406. int func = BP_FUNC(bp);
  1407. u32 hw_lock_control_reg;
  1408. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1409. "Trying to take a lock on resource %d\n", resource);
  1410. /* Validating that the resource is within range */
  1411. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1412. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1413. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1414. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1415. return false;
  1416. }
  1417. if (func <= 5)
  1418. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1419. else
  1420. hw_lock_control_reg =
  1421. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1422. /* Try to acquire the lock */
  1423. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1424. lock_status = REG_RD(bp, hw_lock_control_reg);
  1425. if (lock_status & resource_bit)
  1426. return true;
  1427. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1428. "Failed to get a lock on resource %d\n", resource);
  1429. return false;
  1430. }
  1431. /**
  1432. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1433. *
  1434. * @bp: driver handle
  1435. *
  1436. * Returns the recovery leader resource id according to the engine this function
  1437. * belongs to. Currently only only 2 engines is supported.
  1438. */
  1439. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1440. {
  1441. if (BP_PATH(bp))
  1442. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1443. else
  1444. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1445. }
  1446. /**
  1447. * bnx2x_trylock_leader_lock- try to acquire a leader lock.
  1448. *
  1449. * @bp: driver handle
  1450. *
  1451. * Tries to acquire a leader lock for current engine.
  1452. */
  1453. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1454. {
  1455. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1456. }
  1457. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1458. /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
  1459. static int bnx2x_schedule_sp_task(struct bnx2x *bp)
  1460. {
  1461. /* Set the interrupt occurred bit for the sp-task to recognize it
  1462. * must ack the interrupt and transition according to the IGU
  1463. * state machine.
  1464. */
  1465. atomic_set(&bp->interrupt_occurred, 1);
  1466. /* The sp_task must execute only after this bit
  1467. * is set, otherwise we will get out of sync and miss all
  1468. * further interrupts. Hence, the barrier.
  1469. */
  1470. smp_wmb();
  1471. /* schedule sp_task to workqueue */
  1472. return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1473. }
  1474. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1475. {
  1476. struct bnx2x *bp = fp->bp;
  1477. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1478. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1479. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1480. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1481. DP(BNX2X_MSG_SP,
  1482. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1483. fp->index, cid, command, bp->state,
  1484. rr_cqe->ramrod_cqe.ramrod_type);
  1485. /* If cid is within VF range, replace the slowpath object with the
  1486. * one corresponding to this VF
  1487. */
  1488. if (cid >= BNX2X_FIRST_VF_CID &&
  1489. cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
  1490. bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
  1491. switch (command) {
  1492. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1493. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1494. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1495. break;
  1496. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1497. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1498. drv_cmd = BNX2X_Q_CMD_SETUP;
  1499. break;
  1500. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1501. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1502. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1503. break;
  1504. case (RAMROD_CMD_ID_ETH_HALT):
  1505. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1506. drv_cmd = BNX2X_Q_CMD_HALT;
  1507. break;
  1508. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1509. DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
  1510. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1511. break;
  1512. case (RAMROD_CMD_ID_ETH_EMPTY):
  1513. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1514. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1515. break;
  1516. default:
  1517. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1518. command, fp->index);
  1519. return;
  1520. }
  1521. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1522. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1523. /* q_obj->complete_cmd() failure means that this was
  1524. * an unexpected completion.
  1525. *
  1526. * In this case we don't want to increase the bp->spq_left
  1527. * because apparently we haven't sent this command the first
  1528. * place.
  1529. */
  1530. #ifdef BNX2X_STOP_ON_ERROR
  1531. bnx2x_panic();
  1532. #else
  1533. return;
  1534. #endif
  1535. /* SRIOV: reschedule any 'in_progress' operations */
  1536. bnx2x_iov_sp_event(bp, cid, true);
  1537. smp_mb__before_atomic_inc();
  1538. atomic_inc(&bp->cq_spq_left);
  1539. /* push the change in bp->spq_left and towards the memory */
  1540. smp_mb__after_atomic_inc();
  1541. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1542. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1543. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1544. /* if Q update ramrod is completed for last Q in AFEX vif set
  1545. * flow, then ACK MCP at the end
  1546. *
  1547. * mark pending ACK to MCP bit.
  1548. * prevent case that both bits are cleared.
  1549. * At the end of load/unload driver checks that
  1550. * sp_state is cleared, and this order prevents
  1551. * races
  1552. */
  1553. smp_mb__before_clear_bit();
  1554. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1555. wmb();
  1556. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1557. smp_mb__after_clear_bit();
  1558. /* schedule the sp task as mcp ack is required */
  1559. bnx2x_schedule_sp_task(bp);
  1560. }
  1561. return;
  1562. }
  1563. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1564. {
  1565. struct bnx2x *bp = netdev_priv(dev_instance);
  1566. u16 status = bnx2x_ack_int(bp);
  1567. u16 mask;
  1568. int i;
  1569. u8 cos;
  1570. /* Return here if interrupt is shared and it's not for us */
  1571. if (unlikely(status == 0)) {
  1572. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1573. return IRQ_NONE;
  1574. }
  1575. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1576. #ifdef BNX2X_STOP_ON_ERROR
  1577. if (unlikely(bp->panic))
  1578. return IRQ_HANDLED;
  1579. #endif
  1580. for_each_eth_queue(bp, i) {
  1581. struct bnx2x_fastpath *fp = &bp->fp[i];
  1582. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1583. if (status & mask) {
  1584. /* Handle Rx or Tx according to SB id */
  1585. prefetch(fp->rx_cons_sb);
  1586. for_each_cos_in_tx_queue(fp, cos)
  1587. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1588. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1589. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1590. status &= ~mask;
  1591. }
  1592. }
  1593. if (CNIC_SUPPORT(bp)) {
  1594. mask = 0x2;
  1595. if (status & (mask | 0x1)) {
  1596. struct cnic_ops *c_ops = NULL;
  1597. rcu_read_lock();
  1598. c_ops = rcu_dereference(bp->cnic_ops);
  1599. if (c_ops && (bp->cnic_eth_dev.drv_state &
  1600. CNIC_DRV_STATE_HANDLES_IRQ))
  1601. c_ops->cnic_handler(bp->cnic_data, NULL);
  1602. rcu_read_unlock();
  1603. status &= ~mask;
  1604. }
  1605. }
  1606. if (unlikely(status & 0x1)) {
  1607. /* schedule sp task to perform default status block work, ack
  1608. * attentions and enable interrupts.
  1609. */
  1610. bnx2x_schedule_sp_task(bp);
  1611. status &= ~0x1;
  1612. if (!status)
  1613. return IRQ_HANDLED;
  1614. }
  1615. if (unlikely(status))
  1616. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1617. status);
  1618. return IRQ_HANDLED;
  1619. }
  1620. /* Link */
  1621. /*
  1622. * General service functions
  1623. */
  1624. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1625. {
  1626. u32 lock_status;
  1627. u32 resource_bit = (1 << resource);
  1628. int func = BP_FUNC(bp);
  1629. u32 hw_lock_control_reg;
  1630. int cnt;
  1631. /* Validating that the resource is within range */
  1632. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1633. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1634. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1635. return -EINVAL;
  1636. }
  1637. if (func <= 5) {
  1638. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1639. } else {
  1640. hw_lock_control_reg =
  1641. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1642. }
  1643. /* Validating that the resource is not already taken */
  1644. lock_status = REG_RD(bp, hw_lock_control_reg);
  1645. if (lock_status & resource_bit) {
  1646. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1647. lock_status, resource_bit);
  1648. return -EEXIST;
  1649. }
  1650. /* Try for 5 second every 5ms */
  1651. for (cnt = 0; cnt < 1000; cnt++) {
  1652. /* Try to acquire the lock */
  1653. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1654. lock_status = REG_RD(bp, hw_lock_control_reg);
  1655. if (lock_status & resource_bit)
  1656. return 0;
  1657. msleep(5);
  1658. }
  1659. BNX2X_ERR("Timeout\n");
  1660. return -EAGAIN;
  1661. }
  1662. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1663. {
  1664. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1665. }
  1666. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1667. {
  1668. u32 lock_status;
  1669. u32 resource_bit = (1 << resource);
  1670. int func = BP_FUNC(bp);
  1671. u32 hw_lock_control_reg;
  1672. /* Validating that the resource is within range */
  1673. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1674. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1675. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1676. return -EINVAL;
  1677. }
  1678. if (func <= 5) {
  1679. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1680. } else {
  1681. hw_lock_control_reg =
  1682. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1683. }
  1684. /* Validating that the resource is currently taken */
  1685. lock_status = REG_RD(bp, hw_lock_control_reg);
  1686. if (!(lock_status & resource_bit)) {
  1687. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
  1688. lock_status, resource_bit);
  1689. return -EFAULT;
  1690. }
  1691. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1692. return 0;
  1693. }
  1694. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1695. {
  1696. /* The GPIO should be swapped if swap register is set and active */
  1697. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1698. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1699. int gpio_shift = gpio_num +
  1700. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1701. u32 gpio_mask = (1 << gpio_shift);
  1702. u32 gpio_reg;
  1703. int value;
  1704. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1705. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1706. return -EINVAL;
  1707. }
  1708. /* read GPIO value */
  1709. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1710. /* get the requested pin value */
  1711. if ((gpio_reg & gpio_mask) == gpio_mask)
  1712. value = 1;
  1713. else
  1714. value = 0;
  1715. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1716. return value;
  1717. }
  1718. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1719. {
  1720. /* The GPIO should be swapped if swap register is set and active */
  1721. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1722. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1723. int gpio_shift = gpio_num +
  1724. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1725. u32 gpio_mask = (1 << gpio_shift);
  1726. u32 gpio_reg;
  1727. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1728. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1729. return -EINVAL;
  1730. }
  1731. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1732. /* read GPIO and mask except the float bits */
  1733. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1734. switch (mode) {
  1735. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1736. DP(NETIF_MSG_LINK,
  1737. "Set GPIO %d (shift %d) -> output low\n",
  1738. gpio_num, gpio_shift);
  1739. /* clear FLOAT and set CLR */
  1740. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1741. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1742. break;
  1743. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1744. DP(NETIF_MSG_LINK,
  1745. "Set GPIO %d (shift %d) -> output high\n",
  1746. gpio_num, gpio_shift);
  1747. /* clear FLOAT and set SET */
  1748. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1749. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1750. break;
  1751. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1752. DP(NETIF_MSG_LINK,
  1753. "Set GPIO %d (shift %d) -> input\n",
  1754. gpio_num, gpio_shift);
  1755. /* set FLOAT */
  1756. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1757. break;
  1758. default:
  1759. break;
  1760. }
  1761. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1762. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1763. return 0;
  1764. }
  1765. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1766. {
  1767. u32 gpio_reg = 0;
  1768. int rc = 0;
  1769. /* Any port swapping should be handled by caller. */
  1770. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1771. /* read GPIO and mask except the float bits */
  1772. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1773. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1774. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1775. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1776. switch (mode) {
  1777. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1778. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1779. /* set CLR */
  1780. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1781. break;
  1782. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1783. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1784. /* set SET */
  1785. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1786. break;
  1787. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1788. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1789. /* set FLOAT */
  1790. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1791. break;
  1792. default:
  1793. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1794. rc = -EINVAL;
  1795. break;
  1796. }
  1797. if (rc == 0)
  1798. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1799. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1800. return rc;
  1801. }
  1802. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1803. {
  1804. /* The GPIO should be swapped if swap register is set and active */
  1805. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1806. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1807. int gpio_shift = gpio_num +
  1808. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1809. u32 gpio_mask = (1 << gpio_shift);
  1810. u32 gpio_reg;
  1811. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1812. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1813. return -EINVAL;
  1814. }
  1815. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1816. /* read GPIO int */
  1817. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1818. switch (mode) {
  1819. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1820. DP(NETIF_MSG_LINK,
  1821. "Clear GPIO INT %d (shift %d) -> output low\n",
  1822. gpio_num, gpio_shift);
  1823. /* clear SET and set CLR */
  1824. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1825. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1826. break;
  1827. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1828. DP(NETIF_MSG_LINK,
  1829. "Set GPIO INT %d (shift %d) -> output high\n",
  1830. gpio_num, gpio_shift);
  1831. /* clear CLR and set SET */
  1832. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1833. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1834. break;
  1835. default:
  1836. break;
  1837. }
  1838. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1839. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1840. return 0;
  1841. }
  1842. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1843. {
  1844. u32 spio_reg;
  1845. /* Only 2 SPIOs are configurable */
  1846. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1847. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1848. return -EINVAL;
  1849. }
  1850. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1851. /* read SPIO and mask except the float bits */
  1852. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1853. switch (mode) {
  1854. case MISC_SPIO_OUTPUT_LOW:
  1855. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1856. /* clear FLOAT and set CLR */
  1857. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1858. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1859. break;
  1860. case MISC_SPIO_OUTPUT_HIGH:
  1861. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1862. /* clear FLOAT and set SET */
  1863. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1864. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1865. break;
  1866. case MISC_SPIO_INPUT_HI_Z:
  1867. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1868. /* set FLOAT */
  1869. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1870. break;
  1871. default:
  1872. break;
  1873. }
  1874. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1875. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1876. return 0;
  1877. }
  1878. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1879. {
  1880. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1881. switch (bp->link_vars.ieee_fc &
  1882. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1883. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1884. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1885. ADVERTISED_Pause);
  1886. break;
  1887. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1888. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1889. ADVERTISED_Pause);
  1890. break;
  1891. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1892. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1893. break;
  1894. default:
  1895. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1896. ADVERTISED_Pause);
  1897. break;
  1898. }
  1899. }
  1900. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1901. {
  1902. /* Initialize link parameters structure variables
  1903. * It is recommended to turn off RX FC for jumbo frames
  1904. * for better performance
  1905. */
  1906. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1907. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1908. else
  1909. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1910. }
  1911. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1912. {
  1913. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1914. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1915. if (!BP_NOMCP(bp)) {
  1916. bnx2x_set_requested_fc(bp);
  1917. bnx2x_acquire_phy_lock(bp);
  1918. if (load_mode == LOAD_DIAG) {
  1919. struct link_params *lp = &bp->link_params;
  1920. lp->loopback_mode = LOOPBACK_XGXS;
  1921. /* do PHY loopback at 10G speed, if possible */
  1922. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1923. if (lp->speed_cap_mask[cfx_idx] &
  1924. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1925. lp->req_line_speed[cfx_idx] =
  1926. SPEED_10000;
  1927. else
  1928. lp->req_line_speed[cfx_idx] =
  1929. SPEED_1000;
  1930. }
  1931. }
  1932. if (load_mode == LOAD_LOOPBACK_EXT) {
  1933. struct link_params *lp = &bp->link_params;
  1934. lp->loopback_mode = LOOPBACK_EXT;
  1935. }
  1936. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1937. bnx2x_release_phy_lock(bp);
  1938. bnx2x_calc_fc_adv(bp);
  1939. if (bp->link_vars.link_up) {
  1940. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1941. bnx2x_link_report(bp);
  1942. }
  1943. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1944. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1945. return rc;
  1946. }
  1947. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1948. return -EINVAL;
  1949. }
  1950. void bnx2x_link_set(struct bnx2x *bp)
  1951. {
  1952. if (!BP_NOMCP(bp)) {
  1953. bnx2x_acquire_phy_lock(bp);
  1954. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1955. bnx2x_release_phy_lock(bp);
  1956. bnx2x_calc_fc_adv(bp);
  1957. } else
  1958. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1959. }
  1960. static void bnx2x__link_reset(struct bnx2x *bp)
  1961. {
  1962. if (!BP_NOMCP(bp)) {
  1963. bnx2x_acquire_phy_lock(bp);
  1964. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  1965. bnx2x_release_phy_lock(bp);
  1966. } else
  1967. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1968. }
  1969. void bnx2x_force_link_reset(struct bnx2x *bp)
  1970. {
  1971. bnx2x_acquire_phy_lock(bp);
  1972. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1973. bnx2x_release_phy_lock(bp);
  1974. }
  1975. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  1976. {
  1977. u8 rc = 0;
  1978. if (!BP_NOMCP(bp)) {
  1979. bnx2x_acquire_phy_lock(bp);
  1980. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  1981. is_serdes);
  1982. bnx2x_release_phy_lock(bp);
  1983. } else
  1984. BNX2X_ERR("Bootcode is missing - can not test link\n");
  1985. return rc;
  1986. }
  1987. /* Calculates the sum of vn_min_rates.
  1988. It's needed for further normalizing of the min_rates.
  1989. Returns:
  1990. sum of vn_min_rates.
  1991. or
  1992. 0 - if all the min_rates are 0.
  1993. In the later case fainess algorithm should be deactivated.
  1994. If not all min_rates are zero then those that are zeroes will be set to 1.
  1995. */
  1996. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  1997. struct cmng_init_input *input)
  1998. {
  1999. int all_zero = 1;
  2000. int vn;
  2001. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2002. u32 vn_cfg = bp->mf_config[vn];
  2003. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  2004. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  2005. /* Skip hidden vns */
  2006. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2007. vn_min_rate = 0;
  2008. /* If min rate is zero - set it to 1 */
  2009. else if (!vn_min_rate)
  2010. vn_min_rate = DEF_MIN_RATE;
  2011. else
  2012. all_zero = 0;
  2013. input->vnic_min_rate[vn] = vn_min_rate;
  2014. }
  2015. /* if ETS or all min rates are zeros - disable fairness */
  2016. if (BNX2X_IS_ETS_ENABLED(bp)) {
  2017. input->flags.cmng_enables &=
  2018. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2019. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  2020. } else if (all_zero) {
  2021. input->flags.cmng_enables &=
  2022. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2023. DP(NETIF_MSG_IFUP,
  2024. "All MIN values are zeroes fairness will be disabled\n");
  2025. } else
  2026. input->flags.cmng_enables |=
  2027. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2028. }
  2029. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  2030. struct cmng_init_input *input)
  2031. {
  2032. u16 vn_max_rate;
  2033. u32 vn_cfg = bp->mf_config[vn];
  2034. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2035. vn_max_rate = 0;
  2036. else {
  2037. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  2038. if (IS_MF_SI(bp)) {
  2039. /* maxCfg in percents of linkspeed */
  2040. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  2041. } else /* SD modes */
  2042. /* maxCfg is absolute in 100Mb units */
  2043. vn_max_rate = maxCfg * 100;
  2044. }
  2045. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  2046. input->vnic_max_rate[vn] = vn_max_rate;
  2047. }
  2048. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2049. {
  2050. if (CHIP_REV_IS_SLOW(bp))
  2051. return CMNG_FNS_NONE;
  2052. if (IS_MF(bp))
  2053. return CMNG_FNS_MINMAX;
  2054. return CMNG_FNS_NONE;
  2055. }
  2056. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2057. {
  2058. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2059. if (BP_NOMCP(bp))
  2060. return; /* what should be the default bvalue in this case */
  2061. /* For 2 port configuration the absolute function number formula
  2062. * is:
  2063. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2064. *
  2065. * and there are 4 functions per port
  2066. *
  2067. * For 4 port configuration it is
  2068. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2069. *
  2070. * and there are 2 functions per port
  2071. */
  2072. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2073. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2074. if (func >= E1H_FUNC_MAX)
  2075. break;
  2076. bp->mf_config[vn] =
  2077. MF_CFG_RD(bp, func_mf_config[func].config);
  2078. }
  2079. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2080. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  2081. bp->flags |= MF_FUNC_DIS;
  2082. } else {
  2083. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2084. bp->flags &= ~MF_FUNC_DIS;
  2085. }
  2086. }
  2087. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2088. {
  2089. struct cmng_init_input input;
  2090. memset(&input, 0, sizeof(struct cmng_init_input));
  2091. input.port_rate = bp->link_vars.line_speed;
  2092. if (cmng_type == CMNG_FNS_MINMAX) {
  2093. int vn;
  2094. /* read mf conf from shmem */
  2095. if (read_cfg)
  2096. bnx2x_read_mf_cfg(bp);
  2097. /* vn_weight_sum and enable fairness if not 0 */
  2098. bnx2x_calc_vn_min(bp, &input);
  2099. /* calculate and set min-max rate for each vn */
  2100. if (bp->port.pmf)
  2101. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2102. bnx2x_calc_vn_max(bp, vn, &input);
  2103. /* always enable rate shaping and fairness */
  2104. input.flags.cmng_enables |=
  2105. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2106. bnx2x_init_cmng(&input, &bp->cmng);
  2107. return;
  2108. }
  2109. /* rate shaping and fairness are disabled */
  2110. DP(NETIF_MSG_IFUP,
  2111. "rate shaping and fairness are disabled\n");
  2112. }
  2113. static void storm_memset_cmng(struct bnx2x *bp,
  2114. struct cmng_init *cmng,
  2115. u8 port)
  2116. {
  2117. int vn;
  2118. size_t size = sizeof(struct cmng_struct_per_port);
  2119. u32 addr = BAR_XSTRORM_INTMEM +
  2120. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2121. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2122. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2123. int func = func_by_vn(bp, vn);
  2124. addr = BAR_XSTRORM_INTMEM +
  2125. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2126. size = sizeof(struct rate_shaping_vars_per_vn);
  2127. __storm_memset_struct(bp, addr, size,
  2128. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2129. addr = BAR_XSTRORM_INTMEM +
  2130. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2131. size = sizeof(struct fairness_vars_per_vn);
  2132. __storm_memset_struct(bp, addr, size,
  2133. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2134. }
  2135. }
  2136. /* This function is called upon link interrupt */
  2137. static void bnx2x_link_attn(struct bnx2x *bp)
  2138. {
  2139. /* Make sure that we are synced with the current statistics */
  2140. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2141. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2142. if (bp->link_vars.link_up) {
  2143. /* dropless flow control */
  2144. if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
  2145. int port = BP_PORT(bp);
  2146. u32 pause_enabled = 0;
  2147. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  2148. pause_enabled = 1;
  2149. REG_WR(bp, BAR_USTRORM_INTMEM +
  2150. USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
  2151. pause_enabled);
  2152. }
  2153. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2154. struct host_port_stats *pstats;
  2155. pstats = bnx2x_sp(bp, port_stats);
  2156. /* reset old mac stats */
  2157. memset(&(pstats->mac_stx[0]), 0,
  2158. sizeof(struct mac_stx));
  2159. }
  2160. if (bp->state == BNX2X_STATE_OPEN)
  2161. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2162. }
  2163. if (bp->link_vars.link_up && bp->link_vars.line_speed) {
  2164. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2165. if (cmng_fns != CMNG_FNS_NONE) {
  2166. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2167. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2168. } else
  2169. /* rate shaping and fairness are disabled */
  2170. DP(NETIF_MSG_IFUP,
  2171. "single function mode without fairness\n");
  2172. }
  2173. __bnx2x_link_report(bp);
  2174. if (IS_MF(bp))
  2175. bnx2x_link_sync_notify(bp);
  2176. }
  2177. void bnx2x__link_status_update(struct bnx2x *bp)
  2178. {
  2179. if (bp->state != BNX2X_STATE_OPEN)
  2180. return;
  2181. /* read updated dcb configuration */
  2182. if (IS_PF(bp)) {
  2183. bnx2x_dcbx_pmf_update(bp);
  2184. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2185. if (bp->link_vars.link_up)
  2186. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2187. else
  2188. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2189. /* indicate link status */
  2190. bnx2x_link_report(bp);
  2191. } else { /* VF */
  2192. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2193. SUPPORTED_10baseT_Full |
  2194. SUPPORTED_100baseT_Half |
  2195. SUPPORTED_100baseT_Full |
  2196. SUPPORTED_1000baseT_Full |
  2197. SUPPORTED_2500baseX_Full |
  2198. SUPPORTED_10000baseT_Full |
  2199. SUPPORTED_TP |
  2200. SUPPORTED_FIBRE |
  2201. SUPPORTED_Autoneg |
  2202. SUPPORTED_Pause |
  2203. SUPPORTED_Asym_Pause);
  2204. bp->port.advertising[0] = bp->port.supported[0];
  2205. bp->link_params.bp = bp;
  2206. bp->link_params.port = BP_PORT(bp);
  2207. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2208. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2209. bp->link_params.req_line_speed[0] = SPEED_10000;
  2210. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2211. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2212. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2213. bp->link_vars.line_speed = SPEED_10000;
  2214. bp->link_vars.link_status =
  2215. (LINK_STATUS_LINK_UP |
  2216. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2217. bp->link_vars.link_up = 1;
  2218. bp->link_vars.duplex = DUPLEX_FULL;
  2219. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2220. __bnx2x_link_report(bp);
  2221. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2222. }
  2223. }
  2224. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2225. u16 vlan_val, u8 allowed_prio)
  2226. {
  2227. struct bnx2x_func_state_params func_params = {NULL};
  2228. struct bnx2x_func_afex_update_params *f_update_params =
  2229. &func_params.params.afex_update;
  2230. func_params.f_obj = &bp->func_obj;
  2231. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2232. /* no need to wait for RAMROD completion, so don't
  2233. * set RAMROD_COMP_WAIT flag
  2234. */
  2235. f_update_params->vif_id = vifid;
  2236. f_update_params->afex_default_vlan = vlan_val;
  2237. f_update_params->allowed_priorities = allowed_prio;
  2238. /* if ramrod can not be sent, response to MCP immediately */
  2239. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2240. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2241. return 0;
  2242. }
  2243. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2244. u16 vif_index, u8 func_bit_map)
  2245. {
  2246. struct bnx2x_func_state_params func_params = {NULL};
  2247. struct bnx2x_func_afex_viflists_params *update_params =
  2248. &func_params.params.afex_viflists;
  2249. int rc;
  2250. u32 drv_msg_code;
  2251. /* validate only LIST_SET and LIST_GET are received from switch */
  2252. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2253. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2254. cmd_type);
  2255. func_params.f_obj = &bp->func_obj;
  2256. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2257. /* set parameters according to cmd_type */
  2258. update_params->afex_vif_list_command = cmd_type;
  2259. update_params->vif_list_index = vif_index;
  2260. update_params->func_bit_map =
  2261. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2262. update_params->func_to_clear = 0;
  2263. drv_msg_code =
  2264. (cmd_type == VIF_LIST_RULE_GET) ?
  2265. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2266. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2267. /* if ramrod can not be sent, respond to MCP immediately for
  2268. * SET and GET requests (other are not triggered from MCP)
  2269. */
  2270. rc = bnx2x_func_state_change(bp, &func_params);
  2271. if (rc < 0)
  2272. bnx2x_fw_command(bp, drv_msg_code, 0);
  2273. return 0;
  2274. }
  2275. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2276. {
  2277. struct afex_stats afex_stats;
  2278. u32 func = BP_ABS_FUNC(bp);
  2279. u32 mf_config;
  2280. u16 vlan_val;
  2281. u32 vlan_prio;
  2282. u16 vif_id;
  2283. u8 allowed_prio;
  2284. u8 vlan_mode;
  2285. u32 addr_to_write, vifid, addrs, stats_type, i;
  2286. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2287. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2288. DP(BNX2X_MSG_MCP,
  2289. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2290. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2291. }
  2292. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2293. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2294. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2295. DP(BNX2X_MSG_MCP,
  2296. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2297. vifid, addrs);
  2298. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2299. addrs);
  2300. }
  2301. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2302. addr_to_write = SHMEM2_RD(bp,
  2303. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2304. stats_type = SHMEM2_RD(bp,
  2305. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2306. DP(BNX2X_MSG_MCP,
  2307. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2308. addr_to_write);
  2309. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2310. /* write response to scratchpad, for MCP */
  2311. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2312. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2313. *(((u32 *)(&afex_stats))+i));
  2314. /* send ack message to MCP */
  2315. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2316. }
  2317. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2318. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2319. bp->mf_config[BP_VN(bp)] = mf_config;
  2320. DP(BNX2X_MSG_MCP,
  2321. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2322. mf_config);
  2323. /* if VIF_SET is "enabled" */
  2324. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2325. /* set rate limit directly to internal RAM */
  2326. struct cmng_init_input cmng_input;
  2327. struct rate_shaping_vars_per_vn m_rs_vn;
  2328. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2329. u32 addr = BAR_XSTRORM_INTMEM +
  2330. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2331. bp->mf_config[BP_VN(bp)] = mf_config;
  2332. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2333. m_rs_vn.vn_counter.rate =
  2334. cmng_input.vnic_max_rate[BP_VN(bp)];
  2335. m_rs_vn.vn_counter.quota =
  2336. (m_rs_vn.vn_counter.rate *
  2337. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2338. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2339. /* read relevant values from mf_cfg struct in shmem */
  2340. vif_id =
  2341. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2342. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2343. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2344. vlan_val =
  2345. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2346. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2347. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2348. vlan_prio = (mf_config &
  2349. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2350. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2351. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2352. vlan_mode =
  2353. (MF_CFG_RD(bp,
  2354. func_mf_config[func].afex_config) &
  2355. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2356. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2357. allowed_prio =
  2358. (MF_CFG_RD(bp,
  2359. func_mf_config[func].afex_config) &
  2360. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2361. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2362. /* send ramrod to FW, return in case of failure */
  2363. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2364. allowed_prio))
  2365. return;
  2366. bp->afex_def_vlan_tag = vlan_val;
  2367. bp->afex_vlan_mode = vlan_mode;
  2368. } else {
  2369. /* notify link down because BP->flags is disabled */
  2370. bnx2x_link_report(bp);
  2371. /* send INVALID VIF ramrod to FW */
  2372. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2373. /* Reset the default afex VLAN */
  2374. bp->afex_def_vlan_tag = -1;
  2375. }
  2376. }
  2377. }
  2378. static void bnx2x_pmf_update(struct bnx2x *bp)
  2379. {
  2380. int port = BP_PORT(bp);
  2381. u32 val;
  2382. bp->port.pmf = 1;
  2383. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2384. /*
  2385. * We need the mb() to ensure the ordering between the writing to
  2386. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2387. */
  2388. smp_mb();
  2389. /* queue a periodic task */
  2390. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2391. bnx2x_dcbx_pmf_update(bp);
  2392. /* enable nig attention */
  2393. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2394. if (bp->common.int_block == INT_BLOCK_HC) {
  2395. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2396. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2397. } else if (!CHIP_IS_E1x(bp)) {
  2398. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2399. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2400. }
  2401. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2402. }
  2403. /* end of Link */
  2404. /* slow path */
  2405. /*
  2406. * General service functions
  2407. */
  2408. /* send the MCP a request, block until there is a reply */
  2409. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2410. {
  2411. int mb_idx = BP_FW_MB_IDX(bp);
  2412. u32 seq;
  2413. u32 rc = 0;
  2414. u32 cnt = 1;
  2415. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2416. mutex_lock(&bp->fw_mb_mutex);
  2417. seq = ++bp->fw_seq;
  2418. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2419. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2420. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2421. (command | seq), param);
  2422. do {
  2423. /* let the FW do it's magic ... */
  2424. msleep(delay);
  2425. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2426. /* Give the FW up to 5 second (500*10ms) */
  2427. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2428. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2429. cnt*delay, rc, seq);
  2430. /* is this a reply to our command? */
  2431. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2432. rc &= FW_MSG_CODE_MASK;
  2433. else {
  2434. /* FW BUG! */
  2435. BNX2X_ERR("FW failed to respond!\n");
  2436. bnx2x_fw_dump(bp);
  2437. rc = 0;
  2438. }
  2439. mutex_unlock(&bp->fw_mb_mutex);
  2440. return rc;
  2441. }
  2442. static void storm_memset_func_cfg(struct bnx2x *bp,
  2443. struct tstorm_eth_function_common_config *tcfg,
  2444. u16 abs_fid)
  2445. {
  2446. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2447. u32 addr = BAR_TSTRORM_INTMEM +
  2448. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2449. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2450. }
  2451. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2452. {
  2453. if (CHIP_IS_E1x(bp)) {
  2454. struct tstorm_eth_function_common_config tcfg = {0};
  2455. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2456. }
  2457. /* Enable the function in the FW */
  2458. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2459. storm_memset_func_en(bp, p->func_id, 1);
  2460. /* spq */
  2461. if (p->func_flgs & FUNC_FLG_SPQ) {
  2462. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2463. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2464. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2465. }
  2466. }
  2467. /**
  2468. * bnx2x_get_tx_only_flags - Return common flags
  2469. *
  2470. * @bp device handle
  2471. * @fp queue handle
  2472. * @zero_stats TRUE if statistics zeroing is needed
  2473. *
  2474. * Return the flags that are common for the Tx-only and not normal connections.
  2475. */
  2476. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2477. struct bnx2x_fastpath *fp,
  2478. bool zero_stats)
  2479. {
  2480. unsigned long flags = 0;
  2481. /* PF driver will always initialize the Queue to an ACTIVE state */
  2482. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2483. /* tx only connections collect statistics (on the same index as the
  2484. * parent connection). The statistics are zeroed when the parent
  2485. * connection is initialized.
  2486. */
  2487. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2488. if (zero_stats)
  2489. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2490. #ifdef BNX2X_STOP_ON_ERROR
  2491. __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
  2492. #endif
  2493. return flags;
  2494. }
  2495. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2496. struct bnx2x_fastpath *fp,
  2497. bool leading)
  2498. {
  2499. unsigned long flags = 0;
  2500. /* calculate other queue flags */
  2501. if (IS_MF_SD(bp))
  2502. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2503. if (IS_FCOE_FP(fp)) {
  2504. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2505. /* For FCoE - force usage of default priority (for afex) */
  2506. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2507. }
  2508. if (!fp->disable_tpa) {
  2509. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2510. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2511. if (fp->mode == TPA_MODE_GRO)
  2512. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2513. }
  2514. if (leading) {
  2515. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2516. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2517. }
  2518. /* Always set HW VLAN stripping */
  2519. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2520. /* configure silent vlan removal */
  2521. if (IS_MF_AFEX(bp))
  2522. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2523. return flags | bnx2x_get_common_flags(bp, fp, true);
  2524. }
  2525. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2526. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2527. u8 cos)
  2528. {
  2529. gen_init->stat_id = bnx2x_stats_id(fp);
  2530. gen_init->spcl_id = fp->cl_id;
  2531. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2532. if (IS_FCOE_FP(fp))
  2533. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2534. else
  2535. gen_init->mtu = bp->dev->mtu;
  2536. gen_init->cos = cos;
  2537. }
  2538. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2539. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2540. struct bnx2x_rxq_setup_params *rxq_init)
  2541. {
  2542. u8 max_sge = 0;
  2543. u16 sge_sz = 0;
  2544. u16 tpa_agg_size = 0;
  2545. if (!fp->disable_tpa) {
  2546. pause->sge_th_lo = SGE_TH_LO(bp);
  2547. pause->sge_th_hi = SGE_TH_HI(bp);
  2548. /* validate SGE ring has enough to cross high threshold */
  2549. WARN_ON(bp->dropless_fc &&
  2550. pause->sge_th_hi + FW_PREFETCH_CNT >
  2551. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2552. tpa_agg_size = TPA_AGG_SIZE;
  2553. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2554. SGE_PAGE_SHIFT;
  2555. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2556. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2557. sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
  2558. }
  2559. /* pause - not for e1 */
  2560. if (!CHIP_IS_E1(bp)) {
  2561. pause->bd_th_lo = BD_TH_LO(bp);
  2562. pause->bd_th_hi = BD_TH_HI(bp);
  2563. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2564. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2565. /*
  2566. * validate that rings have enough entries to cross
  2567. * high thresholds
  2568. */
  2569. WARN_ON(bp->dropless_fc &&
  2570. pause->bd_th_hi + FW_PREFETCH_CNT >
  2571. bp->rx_ring_size);
  2572. WARN_ON(bp->dropless_fc &&
  2573. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2574. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2575. pause->pri_map = 1;
  2576. }
  2577. /* rxq setup */
  2578. rxq_init->dscr_map = fp->rx_desc_mapping;
  2579. rxq_init->sge_map = fp->rx_sge_mapping;
  2580. rxq_init->rcq_map = fp->rx_comp_mapping;
  2581. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2582. /* This should be a maximum number of data bytes that may be
  2583. * placed on the BD (not including paddings).
  2584. */
  2585. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2586. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2587. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2588. rxq_init->tpa_agg_sz = tpa_agg_size;
  2589. rxq_init->sge_buf_sz = sge_sz;
  2590. rxq_init->max_sges_pkt = max_sge;
  2591. rxq_init->rss_engine_id = BP_FUNC(bp);
  2592. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2593. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2594. *
  2595. * For PF Clients it should be the maximum available number.
  2596. * VF driver(s) may want to define it to a smaller value.
  2597. */
  2598. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2599. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2600. rxq_init->fw_sb_id = fp->fw_sb_id;
  2601. if (IS_FCOE_FP(fp))
  2602. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2603. else
  2604. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2605. /* configure silent vlan removal
  2606. * if multi function mode is afex, then mask default vlan
  2607. */
  2608. if (IS_MF_AFEX(bp)) {
  2609. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2610. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2611. }
  2612. }
  2613. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2614. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2615. u8 cos)
  2616. {
  2617. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2618. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2619. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2620. txq_init->fw_sb_id = fp->fw_sb_id;
  2621. /*
  2622. * set the tss leading client id for TX classfication ==
  2623. * leading RSS client id
  2624. */
  2625. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2626. if (IS_FCOE_FP(fp)) {
  2627. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2628. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2629. }
  2630. }
  2631. static void bnx2x_pf_init(struct bnx2x *bp)
  2632. {
  2633. struct bnx2x_func_init_params func_init = {0};
  2634. struct event_ring_data eq_data = { {0} };
  2635. u16 flags;
  2636. if (!CHIP_IS_E1x(bp)) {
  2637. /* reset IGU PF statistics: MSIX + ATTN */
  2638. /* PF */
  2639. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2640. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2641. (CHIP_MODE_IS_4_PORT(bp) ?
  2642. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2643. /* ATTN */
  2644. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2645. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2646. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2647. (CHIP_MODE_IS_4_PORT(bp) ?
  2648. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2649. }
  2650. /* function setup flags */
  2651. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2652. /* This flag is relevant for E1x only.
  2653. * E2 doesn't have a TPA configuration in a function level.
  2654. */
  2655. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2656. func_init.func_flgs = flags;
  2657. func_init.pf_id = BP_FUNC(bp);
  2658. func_init.func_id = BP_FUNC(bp);
  2659. func_init.spq_map = bp->spq_mapping;
  2660. func_init.spq_prod = bp->spq_prod_idx;
  2661. bnx2x_func_init(bp, &func_init);
  2662. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2663. /*
  2664. * Congestion management values depend on the link rate
  2665. * There is no active link so initial link rate is set to 10 Gbps.
  2666. * When the link comes up The congestion management values are
  2667. * re-calculated according to the actual link rate.
  2668. */
  2669. bp->link_vars.line_speed = SPEED_10000;
  2670. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2671. /* Only the PMF sets the HW */
  2672. if (bp->port.pmf)
  2673. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2674. /* init Event Queue - PCI bus guarantees correct endianity*/
  2675. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2676. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2677. eq_data.producer = bp->eq_prod;
  2678. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2679. eq_data.sb_id = DEF_SB_ID;
  2680. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2681. }
  2682. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2683. {
  2684. int port = BP_PORT(bp);
  2685. bnx2x_tx_disable(bp);
  2686. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2687. }
  2688. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2689. {
  2690. int port = BP_PORT(bp);
  2691. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2692. /* Tx queue should be only reenabled */
  2693. netif_tx_wake_all_queues(bp->dev);
  2694. /*
  2695. * Should not call netif_carrier_on since it will be called if the link
  2696. * is up when checking for link state
  2697. */
  2698. }
  2699. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2700. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2701. {
  2702. struct eth_stats_info *ether_stat =
  2703. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2704. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2705. ETH_STAT_INFO_VERSION_LEN);
  2706. bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2707. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2708. ether_stat->mac_local);
  2709. ether_stat->mtu_size = bp->dev->mtu;
  2710. if (bp->dev->features & NETIF_F_RXCSUM)
  2711. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2712. if (bp->dev->features & NETIF_F_TSO)
  2713. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2714. ether_stat->feature_flags |= bp->common.boot_mode;
  2715. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2716. ether_stat->txq_size = bp->tx_ring_size;
  2717. ether_stat->rxq_size = bp->rx_ring_size;
  2718. }
  2719. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2720. {
  2721. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2722. struct fcoe_stats_info *fcoe_stat =
  2723. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2724. if (!CNIC_LOADED(bp))
  2725. return;
  2726. memcpy(fcoe_stat->mac_local + MAC_LEADING_ZERO_CNT,
  2727. bp->fip_mac, ETH_ALEN);
  2728. fcoe_stat->qos_priority =
  2729. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2730. /* insert FCoE stats from ramrod response */
  2731. if (!NO_FCOE(bp)) {
  2732. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2733. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2734. tstorm_queue_statistics;
  2735. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2736. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2737. xstorm_queue_statistics;
  2738. struct fcoe_statistics_params *fw_fcoe_stat =
  2739. &bp->fw_stats_data->fcoe;
  2740. ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
  2741. fcoe_stat->rx_bytes_lo,
  2742. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2743. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2744. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2745. fcoe_stat->rx_bytes_lo,
  2746. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2747. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2748. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2749. fcoe_stat->rx_bytes_lo,
  2750. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2751. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2752. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2753. fcoe_stat->rx_bytes_lo,
  2754. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2755. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2756. fcoe_stat->rx_frames_lo,
  2757. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2758. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2759. fcoe_stat->rx_frames_lo,
  2760. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2761. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2762. fcoe_stat->rx_frames_lo,
  2763. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2764. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2765. fcoe_stat->rx_frames_lo,
  2766. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2767. ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
  2768. fcoe_stat->tx_bytes_lo,
  2769. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2770. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2771. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2772. fcoe_stat->tx_bytes_lo,
  2773. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2774. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2775. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2776. fcoe_stat->tx_bytes_lo,
  2777. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2778. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2779. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2780. fcoe_stat->tx_bytes_lo,
  2781. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2782. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2783. fcoe_stat->tx_frames_lo,
  2784. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2785. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2786. fcoe_stat->tx_frames_lo,
  2787. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2788. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2789. fcoe_stat->tx_frames_lo,
  2790. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2791. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2792. fcoe_stat->tx_frames_lo,
  2793. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2794. }
  2795. /* ask L5 driver to add data to the struct */
  2796. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2797. }
  2798. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2799. {
  2800. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2801. struct iscsi_stats_info *iscsi_stat =
  2802. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2803. if (!CNIC_LOADED(bp))
  2804. return;
  2805. memcpy(iscsi_stat->mac_local + MAC_LEADING_ZERO_CNT,
  2806. bp->cnic_eth_dev.iscsi_mac, ETH_ALEN);
  2807. iscsi_stat->qos_priority =
  2808. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2809. /* ask L5 driver to add data to the struct */
  2810. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2811. }
  2812. /* called due to MCP event (on pmf):
  2813. * reread new bandwidth configuration
  2814. * configure FW
  2815. * notify others function about the change
  2816. */
  2817. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2818. {
  2819. if (bp->link_vars.link_up) {
  2820. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2821. bnx2x_link_sync_notify(bp);
  2822. }
  2823. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2824. }
  2825. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2826. {
  2827. bnx2x_config_mf_bw(bp);
  2828. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2829. }
  2830. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2831. {
  2832. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2833. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2834. }
  2835. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2836. {
  2837. enum drv_info_opcode op_code;
  2838. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2839. /* if drv_info version supported by MFW doesn't match - send NACK */
  2840. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2841. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2842. return;
  2843. }
  2844. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2845. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2846. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2847. sizeof(union drv_info_to_mcp));
  2848. switch (op_code) {
  2849. case ETH_STATS_OPCODE:
  2850. bnx2x_drv_info_ether_stat(bp);
  2851. break;
  2852. case FCOE_STATS_OPCODE:
  2853. bnx2x_drv_info_fcoe_stat(bp);
  2854. break;
  2855. case ISCSI_STATS_OPCODE:
  2856. bnx2x_drv_info_iscsi_stat(bp);
  2857. break;
  2858. default:
  2859. /* if op code isn't supported - send NACK */
  2860. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2861. return;
  2862. }
  2863. /* if we got drv_info attn from MFW then these fields are defined in
  2864. * shmem2 for sure
  2865. */
  2866. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2867. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2868. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2869. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2870. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2871. }
  2872. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2873. {
  2874. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2875. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2876. /*
  2877. * This is the only place besides the function initialization
  2878. * where the bp->flags can change so it is done without any
  2879. * locks
  2880. */
  2881. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2882. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  2883. bp->flags |= MF_FUNC_DIS;
  2884. bnx2x_e1h_disable(bp);
  2885. } else {
  2886. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  2887. bp->flags &= ~MF_FUNC_DIS;
  2888. bnx2x_e1h_enable(bp);
  2889. }
  2890. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2891. }
  2892. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2893. bnx2x_config_mf_bw(bp);
  2894. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2895. }
  2896. /* Report results to MCP */
  2897. if (dcc_event)
  2898. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2899. else
  2900. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2901. }
  2902. /* must be called under the spq lock */
  2903. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2904. {
  2905. struct eth_spe *next_spe = bp->spq_prod_bd;
  2906. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2907. bp->spq_prod_bd = bp->spq;
  2908. bp->spq_prod_idx = 0;
  2909. DP(BNX2X_MSG_SP, "end of spq\n");
  2910. } else {
  2911. bp->spq_prod_bd++;
  2912. bp->spq_prod_idx++;
  2913. }
  2914. return next_spe;
  2915. }
  2916. /* must be called under the spq lock */
  2917. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  2918. {
  2919. int func = BP_FUNC(bp);
  2920. /*
  2921. * Make sure that BD data is updated before writing the producer:
  2922. * BD data is written to the memory, the producer is read from the
  2923. * memory, thus we need a full memory barrier to ensure the ordering.
  2924. */
  2925. mb();
  2926. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2927. bp->spq_prod_idx);
  2928. mmiowb();
  2929. }
  2930. /**
  2931. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2932. *
  2933. * @cmd: command to check
  2934. * @cmd_type: command type
  2935. */
  2936. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2937. {
  2938. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2939. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  2940. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2941. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2942. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  2943. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  2944. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  2945. return true;
  2946. else
  2947. return false;
  2948. }
  2949. /**
  2950. * bnx2x_sp_post - place a single command on an SP ring
  2951. *
  2952. * @bp: driver handle
  2953. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  2954. * @cid: SW CID the command is related to
  2955. * @data_hi: command private data address (high 32 bits)
  2956. * @data_lo: command private data address (low 32 bits)
  2957. * @cmd_type: command type (e.g. NONE, ETH)
  2958. *
  2959. * SP data is handled as if it's always an address pair, thus data fields are
  2960. * not swapped to little endian in upper functions. Instead this function swaps
  2961. * data as if it's two u32 fields.
  2962. */
  2963. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  2964. u32 data_hi, u32 data_lo, int cmd_type)
  2965. {
  2966. struct eth_spe *spe;
  2967. u16 type;
  2968. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  2969. #ifdef BNX2X_STOP_ON_ERROR
  2970. if (unlikely(bp->panic)) {
  2971. BNX2X_ERR("Can't post SP when there is panic\n");
  2972. return -EIO;
  2973. }
  2974. #endif
  2975. spin_lock_bh(&bp->spq_lock);
  2976. if (common) {
  2977. if (!atomic_read(&bp->eq_spq_left)) {
  2978. BNX2X_ERR("BUG! EQ ring full!\n");
  2979. spin_unlock_bh(&bp->spq_lock);
  2980. bnx2x_panic();
  2981. return -EBUSY;
  2982. }
  2983. } else if (!atomic_read(&bp->cq_spq_left)) {
  2984. BNX2X_ERR("BUG! SPQ ring full!\n");
  2985. spin_unlock_bh(&bp->spq_lock);
  2986. bnx2x_panic();
  2987. return -EBUSY;
  2988. }
  2989. spe = bnx2x_sp_get_next(bp);
  2990. /* CID needs port number to be encoded int it */
  2991. spe->hdr.conn_and_cmd_data =
  2992. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  2993. HW_CID(bp, cid));
  2994. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  2995. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  2996. SPE_HDR_FUNCTION_ID);
  2997. spe->hdr.type = cpu_to_le16(type);
  2998. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  2999. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  3000. /*
  3001. * It's ok if the actual decrement is issued towards the memory
  3002. * somewhere between the spin_lock and spin_unlock. Thus no
  3003. * more explict memory barrier is needed.
  3004. */
  3005. if (common)
  3006. atomic_dec(&bp->eq_spq_left);
  3007. else
  3008. atomic_dec(&bp->cq_spq_left);
  3009. DP(BNX2X_MSG_SP,
  3010. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  3011. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  3012. (u32)(U64_LO(bp->spq_mapping) +
  3013. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  3014. HW_CID(bp, cid), data_hi, data_lo, type,
  3015. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  3016. bnx2x_sp_prod_update(bp);
  3017. spin_unlock_bh(&bp->spq_lock);
  3018. return 0;
  3019. }
  3020. /* acquire split MCP access lock register */
  3021. static int bnx2x_acquire_alr(struct bnx2x *bp)
  3022. {
  3023. u32 j, val;
  3024. int rc = 0;
  3025. might_sleep();
  3026. for (j = 0; j < 1000; j++) {
  3027. val = (1UL << 31);
  3028. REG_WR(bp, GRCBASE_MCP + 0x9c, val);
  3029. val = REG_RD(bp, GRCBASE_MCP + 0x9c);
  3030. if (val & (1L << 31))
  3031. break;
  3032. msleep(5);
  3033. }
  3034. if (!(val & (1L << 31))) {
  3035. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  3036. rc = -EBUSY;
  3037. }
  3038. return rc;
  3039. }
  3040. /* release split MCP access lock register */
  3041. static void bnx2x_release_alr(struct bnx2x *bp)
  3042. {
  3043. REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
  3044. }
  3045. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  3046. #define BNX2X_DEF_SB_IDX 0x0002
  3047. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  3048. {
  3049. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3050. u16 rc = 0;
  3051. barrier(); /* status block is written to by the chip */
  3052. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3053. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3054. rc |= BNX2X_DEF_SB_ATT_IDX;
  3055. }
  3056. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3057. bp->def_idx = def_sb->sp_sb.running_index;
  3058. rc |= BNX2X_DEF_SB_IDX;
  3059. }
  3060. /* Do not reorder: indecies reading should complete before handling */
  3061. barrier();
  3062. return rc;
  3063. }
  3064. /*
  3065. * slow path service functions
  3066. */
  3067. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3068. {
  3069. int port = BP_PORT(bp);
  3070. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3071. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3072. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3073. NIG_REG_MASK_INTERRUPT_PORT0;
  3074. u32 aeu_mask;
  3075. u32 nig_mask = 0;
  3076. u32 reg_addr;
  3077. if (bp->attn_state & asserted)
  3078. BNX2X_ERR("IGU ERROR\n");
  3079. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3080. aeu_mask = REG_RD(bp, aeu_addr);
  3081. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3082. aeu_mask, asserted);
  3083. aeu_mask &= ~(asserted & 0x3ff);
  3084. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3085. REG_WR(bp, aeu_addr, aeu_mask);
  3086. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3087. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3088. bp->attn_state |= asserted;
  3089. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3090. if (asserted & ATTN_HARD_WIRED_MASK) {
  3091. if (asserted & ATTN_NIG_FOR_FUNC) {
  3092. bnx2x_acquire_phy_lock(bp);
  3093. /* save nig interrupt mask */
  3094. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3095. /* If nig_mask is not set, no need to call the update
  3096. * function.
  3097. */
  3098. if (nig_mask) {
  3099. REG_WR(bp, nig_int_mask_addr, 0);
  3100. bnx2x_link_attn(bp);
  3101. }
  3102. /* handle unicore attn? */
  3103. }
  3104. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3105. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3106. if (asserted & GPIO_2_FUNC)
  3107. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3108. if (asserted & GPIO_3_FUNC)
  3109. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3110. if (asserted & GPIO_4_FUNC)
  3111. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3112. if (port == 0) {
  3113. if (asserted & ATTN_GENERAL_ATTN_1) {
  3114. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3115. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3116. }
  3117. if (asserted & ATTN_GENERAL_ATTN_2) {
  3118. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3119. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3120. }
  3121. if (asserted & ATTN_GENERAL_ATTN_3) {
  3122. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3123. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3124. }
  3125. } else {
  3126. if (asserted & ATTN_GENERAL_ATTN_4) {
  3127. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3128. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3129. }
  3130. if (asserted & ATTN_GENERAL_ATTN_5) {
  3131. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3132. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3133. }
  3134. if (asserted & ATTN_GENERAL_ATTN_6) {
  3135. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3136. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3137. }
  3138. }
  3139. } /* if hardwired */
  3140. if (bp->common.int_block == INT_BLOCK_HC)
  3141. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3142. COMMAND_REG_ATTN_BITS_SET);
  3143. else
  3144. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3145. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3146. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3147. REG_WR(bp, reg_addr, asserted);
  3148. /* now set back the mask */
  3149. if (asserted & ATTN_NIG_FOR_FUNC) {
  3150. /* Verify that IGU ack through BAR was written before restoring
  3151. * NIG mask. This loop should exit after 2-3 iterations max.
  3152. */
  3153. if (bp->common.int_block != INT_BLOCK_HC) {
  3154. u32 cnt = 0, igu_acked;
  3155. do {
  3156. igu_acked = REG_RD(bp,
  3157. IGU_REG_ATTENTION_ACK_BITS);
  3158. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3159. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3160. if (!igu_acked)
  3161. DP(NETIF_MSG_HW,
  3162. "Failed to verify IGU ack on time\n");
  3163. barrier();
  3164. }
  3165. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3166. bnx2x_release_phy_lock(bp);
  3167. }
  3168. }
  3169. static void bnx2x_fan_failure(struct bnx2x *bp)
  3170. {
  3171. int port = BP_PORT(bp);
  3172. u32 ext_phy_config;
  3173. /* mark the failure */
  3174. ext_phy_config =
  3175. SHMEM_RD(bp,
  3176. dev_info.port_hw_config[port].external_phy_config);
  3177. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3178. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3179. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3180. ext_phy_config);
  3181. /* log the failure */
  3182. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3183. "Please contact OEM Support for assistance\n");
  3184. /*
  3185. * Schedule device reset (unload)
  3186. * This is due to some boards consuming sufficient power when driver is
  3187. * up to overheat if fan fails.
  3188. */
  3189. smp_mb__before_clear_bit();
  3190. set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
  3191. smp_mb__after_clear_bit();
  3192. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3193. }
  3194. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3195. {
  3196. int port = BP_PORT(bp);
  3197. int reg_offset;
  3198. u32 val;
  3199. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3200. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3201. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3202. val = REG_RD(bp, reg_offset);
  3203. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3204. REG_WR(bp, reg_offset, val);
  3205. BNX2X_ERR("SPIO5 hw attention\n");
  3206. /* Fan failure attention */
  3207. bnx2x_hw_reset_phy(&bp->link_params);
  3208. bnx2x_fan_failure(bp);
  3209. }
  3210. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3211. bnx2x_acquire_phy_lock(bp);
  3212. bnx2x_handle_module_detect_int(&bp->link_params);
  3213. bnx2x_release_phy_lock(bp);
  3214. }
  3215. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3216. val = REG_RD(bp, reg_offset);
  3217. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3218. REG_WR(bp, reg_offset, val);
  3219. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3220. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3221. bnx2x_panic();
  3222. }
  3223. }
  3224. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3225. {
  3226. u32 val;
  3227. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3228. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3229. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3230. /* DORQ discard attention */
  3231. if (val & 0x2)
  3232. BNX2X_ERR("FATAL error from DORQ\n");
  3233. }
  3234. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3235. int port = BP_PORT(bp);
  3236. int reg_offset;
  3237. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3238. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3239. val = REG_RD(bp, reg_offset);
  3240. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3241. REG_WR(bp, reg_offset, val);
  3242. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3243. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3244. bnx2x_panic();
  3245. }
  3246. }
  3247. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3248. {
  3249. u32 val;
  3250. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3251. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3252. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3253. /* CFC error attention */
  3254. if (val & 0x2)
  3255. BNX2X_ERR("FATAL error from CFC\n");
  3256. }
  3257. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3258. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3259. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3260. /* RQ_USDMDP_FIFO_OVERFLOW */
  3261. if (val & 0x18000)
  3262. BNX2X_ERR("FATAL error from PXP\n");
  3263. if (!CHIP_IS_E1x(bp)) {
  3264. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3265. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3266. }
  3267. }
  3268. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3269. int port = BP_PORT(bp);
  3270. int reg_offset;
  3271. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3272. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3273. val = REG_RD(bp, reg_offset);
  3274. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3275. REG_WR(bp, reg_offset, val);
  3276. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3277. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3278. bnx2x_panic();
  3279. }
  3280. }
  3281. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3282. {
  3283. u32 val;
  3284. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3285. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3286. int func = BP_FUNC(bp);
  3287. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3288. bnx2x_read_mf_cfg(bp);
  3289. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3290. func_mf_config[BP_ABS_FUNC(bp)].config);
  3291. val = SHMEM_RD(bp,
  3292. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3293. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3294. bnx2x_dcc_event(bp,
  3295. (val & DRV_STATUS_DCC_EVENT_MASK));
  3296. if (val & DRV_STATUS_SET_MF_BW)
  3297. bnx2x_set_mf_bw(bp);
  3298. if (val & DRV_STATUS_DRV_INFO_REQ)
  3299. bnx2x_handle_drv_info_req(bp);
  3300. if (val & DRV_STATUS_VF_DISABLED)
  3301. bnx2x_vf_handle_flr_event(bp);
  3302. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3303. bnx2x_pmf_update(bp);
  3304. if (bp->port.pmf &&
  3305. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3306. bp->dcbx_enabled > 0)
  3307. /* start dcbx state machine */
  3308. bnx2x_dcbx_set_params(bp,
  3309. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3310. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3311. bnx2x_handle_afex_cmd(bp,
  3312. val & DRV_STATUS_AFEX_EVENT_MASK);
  3313. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3314. bnx2x_handle_eee_event(bp);
  3315. if (bp->link_vars.periodic_flags &
  3316. PERIODIC_FLAGS_LINK_EVENT) {
  3317. /* sync with link */
  3318. bnx2x_acquire_phy_lock(bp);
  3319. bp->link_vars.periodic_flags &=
  3320. ~PERIODIC_FLAGS_LINK_EVENT;
  3321. bnx2x_release_phy_lock(bp);
  3322. if (IS_MF(bp))
  3323. bnx2x_link_sync_notify(bp);
  3324. bnx2x_link_report(bp);
  3325. }
  3326. /* Always call it here: bnx2x_link_report() will
  3327. * prevent the link indication duplication.
  3328. */
  3329. bnx2x__link_status_update(bp);
  3330. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3331. BNX2X_ERR("MC assert!\n");
  3332. bnx2x_mc_assert(bp);
  3333. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3334. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3335. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3336. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3337. bnx2x_panic();
  3338. } else if (attn & BNX2X_MCP_ASSERT) {
  3339. BNX2X_ERR("MCP assert!\n");
  3340. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3341. bnx2x_fw_dump(bp);
  3342. } else
  3343. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3344. }
  3345. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3346. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3347. if (attn & BNX2X_GRC_TIMEOUT) {
  3348. val = CHIP_IS_E1(bp) ? 0 :
  3349. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3350. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3351. }
  3352. if (attn & BNX2X_GRC_RSV) {
  3353. val = CHIP_IS_E1(bp) ? 0 :
  3354. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3355. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3356. }
  3357. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3358. }
  3359. }
  3360. /*
  3361. * Bits map:
  3362. * 0-7 - Engine0 load counter.
  3363. * 8-15 - Engine1 load counter.
  3364. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3365. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3366. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3367. * on the engine
  3368. * 19 - Engine1 ONE_IS_LOADED.
  3369. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3370. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3371. * just the one belonging to its engine).
  3372. *
  3373. */
  3374. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3375. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3376. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3377. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3378. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3379. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3380. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3381. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3382. /*
  3383. * Set the GLOBAL_RESET bit.
  3384. *
  3385. * Should be run under rtnl lock
  3386. */
  3387. void bnx2x_set_reset_global(struct bnx2x *bp)
  3388. {
  3389. u32 val;
  3390. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3391. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3392. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3393. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3394. }
  3395. /*
  3396. * Clear the GLOBAL_RESET bit.
  3397. *
  3398. * Should be run under rtnl lock
  3399. */
  3400. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3401. {
  3402. u32 val;
  3403. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3404. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3405. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3406. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3407. }
  3408. /*
  3409. * Checks the GLOBAL_RESET bit.
  3410. *
  3411. * should be run under rtnl lock
  3412. */
  3413. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3414. {
  3415. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3416. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3417. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3418. }
  3419. /*
  3420. * Clear RESET_IN_PROGRESS bit for the current engine.
  3421. *
  3422. * Should be run under rtnl lock
  3423. */
  3424. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3425. {
  3426. u32 val;
  3427. u32 bit = BP_PATH(bp) ?
  3428. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3429. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3430. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3431. /* Clear the bit */
  3432. val &= ~bit;
  3433. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3434. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3435. }
  3436. /*
  3437. * Set RESET_IN_PROGRESS for the current engine.
  3438. *
  3439. * should be run under rtnl lock
  3440. */
  3441. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3442. {
  3443. u32 val;
  3444. u32 bit = BP_PATH(bp) ?
  3445. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3446. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3447. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3448. /* Set the bit */
  3449. val |= bit;
  3450. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3451. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3452. }
  3453. /*
  3454. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3455. * should be run under rtnl lock
  3456. */
  3457. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3458. {
  3459. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3460. u32 bit = engine ?
  3461. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3462. /* return false if bit is set */
  3463. return (val & bit) ? false : true;
  3464. }
  3465. /*
  3466. * set pf load for the current pf.
  3467. *
  3468. * should be run under rtnl lock
  3469. */
  3470. void bnx2x_set_pf_load(struct bnx2x *bp)
  3471. {
  3472. u32 val1, val;
  3473. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3474. BNX2X_PATH0_LOAD_CNT_MASK;
  3475. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3476. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3477. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3478. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3479. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3480. /* get the current counter value */
  3481. val1 = (val & mask) >> shift;
  3482. /* set bit of that PF */
  3483. val1 |= (1 << bp->pf_num);
  3484. /* clear the old value */
  3485. val &= ~mask;
  3486. /* set the new one */
  3487. val |= ((val1 << shift) & mask);
  3488. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3489. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3490. }
  3491. /**
  3492. * bnx2x_clear_pf_load - clear pf load mark
  3493. *
  3494. * @bp: driver handle
  3495. *
  3496. * Should be run under rtnl lock.
  3497. * Decrements the load counter for the current engine. Returns
  3498. * whether other functions are still loaded
  3499. */
  3500. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3501. {
  3502. u32 val1, val;
  3503. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3504. BNX2X_PATH0_LOAD_CNT_MASK;
  3505. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3506. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3507. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3508. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3509. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3510. /* get the current counter value */
  3511. val1 = (val & mask) >> shift;
  3512. /* clear bit of that PF */
  3513. val1 &= ~(1 << bp->pf_num);
  3514. /* clear the old value */
  3515. val &= ~mask;
  3516. /* set the new one */
  3517. val |= ((val1 << shift) & mask);
  3518. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3519. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3520. return val1 != 0;
  3521. }
  3522. /*
  3523. * Read the load status for the current engine.
  3524. *
  3525. * should be run under rtnl lock
  3526. */
  3527. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3528. {
  3529. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3530. BNX2X_PATH0_LOAD_CNT_MASK);
  3531. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3532. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3533. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3534. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3535. val = (val & mask) >> shift;
  3536. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3537. engine, val);
  3538. return val != 0;
  3539. }
  3540. static void _print_next_block(int idx, const char *blk)
  3541. {
  3542. pr_cont("%s%s", idx ? ", " : "", blk);
  3543. }
  3544. static int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
  3545. bool print)
  3546. {
  3547. int i = 0;
  3548. u32 cur_bit = 0;
  3549. for (i = 0; sig; i++) {
  3550. cur_bit = ((u32)0x1 << i);
  3551. if (sig & cur_bit) {
  3552. switch (cur_bit) {
  3553. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3554. if (print)
  3555. _print_next_block(par_num++, "BRB");
  3556. break;
  3557. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3558. if (print)
  3559. _print_next_block(par_num++, "PARSER");
  3560. break;
  3561. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3562. if (print)
  3563. _print_next_block(par_num++, "TSDM");
  3564. break;
  3565. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3566. if (print)
  3567. _print_next_block(par_num++,
  3568. "SEARCHER");
  3569. break;
  3570. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3571. if (print)
  3572. _print_next_block(par_num++, "TCM");
  3573. break;
  3574. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3575. if (print)
  3576. _print_next_block(par_num++, "TSEMI");
  3577. break;
  3578. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3579. if (print)
  3580. _print_next_block(par_num++, "XPB");
  3581. break;
  3582. }
  3583. /* Clear the bit */
  3584. sig &= ~cur_bit;
  3585. }
  3586. }
  3587. return par_num;
  3588. }
  3589. static int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
  3590. bool *global, bool print)
  3591. {
  3592. int i = 0;
  3593. u32 cur_bit = 0;
  3594. for (i = 0; sig; i++) {
  3595. cur_bit = ((u32)0x1 << i);
  3596. if (sig & cur_bit) {
  3597. switch (cur_bit) {
  3598. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3599. if (print)
  3600. _print_next_block(par_num++, "PBF");
  3601. break;
  3602. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3603. if (print)
  3604. _print_next_block(par_num++, "QM");
  3605. break;
  3606. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3607. if (print)
  3608. _print_next_block(par_num++, "TM");
  3609. break;
  3610. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3611. if (print)
  3612. _print_next_block(par_num++, "XSDM");
  3613. break;
  3614. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3615. if (print)
  3616. _print_next_block(par_num++, "XCM");
  3617. break;
  3618. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3619. if (print)
  3620. _print_next_block(par_num++, "XSEMI");
  3621. break;
  3622. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3623. if (print)
  3624. _print_next_block(par_num++,
  3625. "DOORBELLQ");
  3626. break;
  3627. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3628. if (print)
  3629. _print_next_block(par_num++, "NIG");
  3630. break;
  3631. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3632. if (print)
  3633. _print_next_block(par_num++,
  3634. "VAUX PCI CORE");
  3635. *global = true;
  3636. break;
  3637. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3638. if (print)
  3639. _print_next_block(par_num++, "DEBUG");
  3640. break;
  3641. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3642. if (print)
  3643. _print_next_block(par_num++, "USDM");
  3644. break;
  3645. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3646. if (print)
  3647. _print_next_block(par_num++, "UCM");
  3648. break;
  3649. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3650. if (print)
  3651. _print_next_block(par_num++, "USEMI");
  3652. break;
  3653. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3654. if (print)
  3655. _print_next_block(par_num++, "UPB");
  3656. break;
  3657. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3658. if (print)
  3659. _print_next_block(par_num++, "CSDM");
  3660. break;
  3661. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3662. if (print)
  3663. _print_next_block(par_num++, "CCM");
  3664. break;
  3665. }
  3666. /* Clear the bit */
  3667. sig &= ~cur_bit;
  3668. }
  3669. }
  3670. return par_num;
  3671. }
  3672. static int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
  3673. bool print)
  3674. {
  3675. int i = 0;
  3676. u32 cur_bit = 0;
  3677. for (i = 0; sig; i++) {
  3678. cur_bit = ((u32)0x1 << i);
  3679. if (sig & cur_bit) {
  3680. switch (cur_bit) {
  3681. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3682. if (print)
  3683. _print_next_block(par_num++, "CSEMI");
  3684. break;
  3685. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3686. if (print)
  3687. _print_next_block(par_num++, "PXP");
  3688. break;
  3689. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3690. if (print)
  3691. _print_next_block(par_num++,
  3692. "PXPPCICLOCKCLIENT");
  3693. break;
  3694. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3695. if (print)
  3696. _print_next_block(par_num++, "CFC");
  3697. break;
  3698. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3699. if (print)
  3700. _print_next_block(par_num++, "CDU");
  3701. break;
  3702. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3703. if (print)
  3704. _print_next_block(par_num++, "DMAE");
  3705. break;
  3706. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3707. if (print)
  3708. _print_next_block(par_num++, "IGU");
  3709. break;
  3710. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3711. if (print)
  3712. _print_next_block(par_num++, "MISC");
  3713. break;
  3714. }
  3715. /* Clear the bit */
  3716. sig &= ~cur_bit;
  3717. }
  3718. }
  3719. return par_num;
  3720. }
  3721. static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
  3722. bool *global, bool print)
  3723. {
  3724. int i = 0;
  3725. u32 cur_bit = 0;
  3726. for (i = 0; sig; i++) {
  3727. cur_bit = ((u32)0x1 << i);
  3728. if (sig & cur_bit) {
  3729. switch (cur_bit) {
  3730. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3731. if (print)
  3732. _print_next_block(par_num++, "MCP ROM");
  3733. *global = true;
  3734. break;
  3735. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3736. if (print)
  3737. _print_next_block(par_num++,
  3738. "MCP UMP RX");
  3739. *global = true;
  3740. break;
  3741. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3742. if (print)
  3743. _print_next_block(par_num++,
  3744. "MCP UMP TX");
  3745. *global = true;
  3746. break;
  3747. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3748. if (print)
  3749. _print_next_block(par_num++,
  3750. "MCP SCPAD");
  3751. *global = true;
  3752. break;
  3753. }
  3754. /* Clear the bit */
  3755. sig &= ~cur_bit;
  3756. }
  3757. }
  3758. return par_num;
  3759. }
  3760. static int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
  3761. bool print)
  3762. {
  3763. int i = 0;
  3764. u32 cur_bit = 0;
  3765. for (i = 0; sig; i++) {
  3766. cur_bit = ((u32)0x1 << i);
  3767. if (sig & cur_bit) {
  3768. switch (cur_bit) {
  3769. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3770. if (print)
  3771. _print_next_block(par_num++, "PGLUE_B");
  3772. break;
  3773. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3774. if (print)
  3775. _print_next_block(par_num++, "ATC");
  3776. break;
  3777. }
  3778. /* Clear the bit */
  3779. sig &= ~cur_bit;
  3780. }
  3781. }
  3782. return par_num;
  3783. }
  3784. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3785. u32 *sig)
  3786. {
  3787. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3788. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3789. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3790. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3791. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3792. int par_num = 0;
  3793. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  3794. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  3795. sig[0] & HW_PRTY_ASSERT_SET_0,
  3796. sig[1] & HW_PRTY_ASSERT_SET_1,
  3797. sig[2] & HW_PRTY_ASSERT_SET_2,
  3798. sig[3] & HW_PRTY_ASSERT_SET_3,
  3799. sig[4] & HW_PRTY_ASSERT_SET_4);
  3800. if (print)
  3801. netdev_err(bp->dev,
  3802. "Parity errors detected in blocks: ");
  3803. par_num = bnx2x_check_blocks_with_parity0(
  3804. sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
  3805. par_num = bnx2x_check_blocks_with_parity1(
  3806. sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
  3807. par_num = bnx2x_check_blocks_with_parity2(
  3808. sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
  3809. par_num = bnx2x_check_blocks_with_parity3(
  3810. sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
  3811. par_num = bnx2x_check_blocks_with_parity4(
  3812. sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
  3813. if (print)
  3814. pr_cont("\n");
  3815. return true;
  3816. } else
  3817. return false;
  3818. }
  3819. /**
  3820. * bnx2x_chk_parity_attn - checks for parity attentions.
  3821. *
  3822. * @bp: driver handle
  3823. * @global: true if there was a global attention
  3824. * @print: show parity attention in syslog
  3825. */
  3826. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3827. {
  3828. struct attn_route attn = { {0} };
  3829. int port = BP_PORT(bp);
  3830. attn.sig[0] = REG_RD(bp,
  3831. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3832. port*4);
  3833. attn.sig[1] = REG_RD(bp,
  3834. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3835. port*4);
  3836. attn.sig[2] = REG_RD(bp,
  3837. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3838. port*4);
  3839. attn.sig[3] = REG_RD(bp,
  3840. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  3841. port*4);
  3842. if (!CHIP_IS_E1x(bp))
  3843. attn.sig[4] = REG_RD(bp,
  3844. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  3845. port*4);
  3846. return bnx2x_parity_attn(bp, global, print, attn.sig);
  3847. }
  3848. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  3849. {
  3850. u32 val;
  3851. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  3852. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  3853. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  3854. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  3855. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  3856. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  3857. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  3858. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  3859. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  3860. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  3861. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  3862. if (val &
  3863. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  3864. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  3865. if (val &
  3866. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  3867. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  3868. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  3869. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  3870. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  3871. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  3872. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  3873. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  3874. }
  3875. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  3876. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  3877. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  3878. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  3879. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  3880. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  3881. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  3882. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  3883. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  3884. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  3885. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  3886. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  3887. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  3888. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  3889. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  3890. }
  3891. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3892. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  3893. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  3894. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3895. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  3896. }
  3897. }
  3898. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  3899. {
  3900. struct attn_route attn, *group_mask;
  3901. int port = BP_PORT(bp);
  3902. int index;
  3903. u32 reg_addr;
  3904. u32 val;
  3905. u32 aeu_mask;
  3906. bool global = false;
  3907. /* need to take HW lock because MCP or other port might also
  3908. try to handle this event */
  3909. bnx2x_acquire_alr(bp);
  3910. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  3911. #ifndef BNX2X_STOP_ON_ERROR
  3912. bp->recovery_state = BNX2X_RECOVERY_INIT;
  3913. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3914. /* Disable HW interrupts */
  3915. bnx2x_int_disable(bp);
  3916. /* In case of parity errors don't handle attentions so that
  3917. * other function would "see" parity errors.
  3918. */
  3919. #else
  3920. bnx2x_panic();
  3921. #endif
  3922. bnx2x_release_alr(bp);
  3923. return;
  3924. }
  3925. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  3926. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  3927. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  3928. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  3929. if (!CHIP_IS_E1x(bp))
  3930. attn.sig[4] =
  3931. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  3932. else
  3933. attn.sig[4] = 0;
  3934. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  3935. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  3936. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  3937. if (deasserted & (1 << index)) {
  3938. group_mask = &bp->attn_group[index];
  3939. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  3940. index,
  3941. group_mask->sig[0], group_mask->sig[1],
  3942. group_mask->sig[2], group_mask->sig[3],
  3943. group_mask->sig[4]);
  3944. bnx2x_attn_int_deasserted4(bp,
  3945. attn.sig[4] & group_mask->sig[4]);
  3946. bnx2x_attn_int_deasserted3(bp,
  3947. attn.sig[3] & group_mask->sig[3]);
  3948. bnx2x_attn_int_deasserted1(bp,
  3949. attn.sig[1] & group_mask->sig[1]);
  3950. bnx2x_attn_int_deasserted2(bp,
  3951. attn.sig[2] & group_mask->sig[2]);
  3952. bnx2x_attn_int_deasserted0(bp,
  3953. attn.sig[0] & group_mask->sig[0]);
  3954. }
  3955. }
  3956. bnx2x_release_alr(bp);
  3957. if (bp->common.int_block == INT_BLOCK_HC)
  3958. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3959. COMMAND_REG_ATTN_BITS_CLR);
  3960. else
  3961. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  3962. val = ~deasserted;
  3963. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  3964. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3965. REG_WR(bp, reg_addr, val);
  3966. if (~bp->attn_state & deasserted)
  3967. BNX2X_ERR("IGU ERROR\n");
  3968. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3969. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3970. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3971. aeu_mask = REG_RD(bp, reg_addr);
  3972. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  3973. aeu_mask, deasserted);
  3974. aeu_mask |= (deasserted & 0x3ff);
  3975. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3976. REG_WR(bp, reg_addr, aeu_mask);
  3977. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3978. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3979. bp->attn_state &= ~deasserted;
  3980. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3981. }
  3982. static void bnx2x_attn_int(struct bnx2x *bp)
  3983. {
  3984. /* read local copy of bits */
  3985. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3986. attn_bits);
  3987. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3988. attn_bits_ack);
  3989. u32 attn_state = bp->attn_state;
  3990. /* look for changed bits */
  3991. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  3992. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  3993. DP(NETIF_MSG_HW,
  3994. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  3995. attn_bits, attn_ack, asserted, deasserted);
  3996. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  3997. BNX2X_ERR("BAD attention state\n");
  3998. /* handle bits that were raised */
  3999. if (asserted)
  4000. bnx2x_attn_int_asserted(bp, asserted);
  4001. if (deasserted)
  4002. bnx2x_attn_int_deasserted(bp, deasserted);
  4003. }
  4004. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  4005. u16 index, u8 op, u8 update)
  4006. {
  4007. u32 igu_addr = bp->igu_base_addr;
  4008. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  4009. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  4010. igu_addr);
  4011. }
  4012. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  4013. {
  4014. /* No memory barriers */
  4015. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  4016. mmiowb(); /* keep prod updates ordered */
  4017. }
  4018. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  4019. union event_ring_elem *elem)
  4020. {
  4021. u8 err = elem->message.error;
  4022. if (!bp->cnic_eth_dev.starting_cid ||
  4023. (cid < bp->cnic_eth_dev.starting_cid &&
  4024. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  4025. return 1;
  4026. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  4027. if (unlikely(err)) {
  4028. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  4029. cid);
  4030. bnx2x_panic_dump(bp, false);
  4031. }
  4032. bnx2x_cnic_cfc_comp(bp, cid, err);
  4033. return 0;
  4034. }
  4035. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  4036. {
  4037. struct bnx2x_mcast_ramrod_params rparam;
  4038. int rc;
  4039. memset(&rparam, 0, sizeof(rparam));
  4040. rparam.mcast_obj = &bp->mcast_obj;
  4041. netif_addr_lock_bh(bp->dev);
  4042. /* Clear pending state for the last command */
  4043. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  4044. /* If there are pending mcast commands - send them */
  4045. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  4046. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  4047. if (rc < 0)
  4048. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  4049. rc);
  4050. }
  4051. netif_addr_unlock_bh(bp->dev);
  4052. }
  4053. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4054. union event_ring_elem *elem)
  4055. {
  4056. unsigned long ramrod_flags = 0;
  4057. int rc = 0;
  4058. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  4059. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4060. /* Always push next commands out, don't wait here */
  4061. __set_bit(RAMROD_CONT, &ramrod_flags);
  4062. switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo)
  4063. >> BNX2X_SWCID_SHIFT) {
  4064. case BNX2X_FILTER_MAC_PENDING:
  4065. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4066. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4067. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4068. else
  4069. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4070. break;
  4071. case BNX2X_FILTER_MCAST_PENDING:
  4072. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4073. /* This is only relevant for 57710 where multicast MACs are
  4074. * configured as unicast MACs using the same ramrod.
  4075. */
  4076. bnx2x_handle_mcast_eqe(bp);
  4077. return;
  4078. default:
  4079. BNX2X_ERR("Unsupported classification command: %d\n",
  4080. elem->message.data.eth_event.echo);
  4081. return;
  4082. }
  4083. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4084. if (rc < 0)
  4085. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4086. else if (rc > 0)
  4087. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4088. }
  4089. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4090. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4091. {
  4092. netif_addr_lock_bh(bp->dev);
  4093. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4094. /* Send rx_mode command again if was requested */
  4095. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4096. bnx2x_set_storm_rx_mode(bp);
  4097. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4098. &bp->sp_state))
  4099. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4100. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4101. &bp->sp_state))
  4102. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4103. netif_addr_unlock_bh(bp->dev);
  4104. }
  4105. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4106. union event_ring_elem *elem)
  4107. {
  4108. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4109. DP(BNX2X_MSG_SP,
  4110. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4111. elem->message.data.vif_list_event.func_bit_map);
  4112. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4113. elem->message.data.vif_list_event.func_bit_map);
  4114. } else if (elem->message.data.vif_list_event.echo ==
  4115. VIF_LIST_RULE_SET) {
  4116. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4117. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4118. }
  4119. }
  4120. /* called with rtnl_lock */
  4121. static void bnx2x_after_function_update(struct bnx2x *bp)
  4122. {
  4123. int q, rc;
  4124. struct bnx2x_fastpath *fp;
  4125. struct bnx2x_queue_state_params queue_params = {NULL};
  4126. struct bnx2x_queue_update_params *q_update_params =
  4127. &queue_params.params.update;
  4128. /* Send Q update command with afex vlan removal values for all Qs */
  4129. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4130. /* set silent vlan removal values according to vlan mode */
  4131. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4132. &q_update_params->update_flags);
  4133. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4134. &q_update_params->update_flags);
  4135. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4136. /* in access mode mark mask and value are 0 to strip all vlans */
  4137. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4138. q_update_params->silent_removal_value = 0;
  4139. q_update_params->silent_removal_mask = 0;
  4140. } else {
  4141. q_update_params->silent_removal_value =
  4142. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4143. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4144. }
  4145. for_each_eth_queue(bp, q) {
  4146. /* Set the appropriate Queue object */
  4147. fp = &bp->fp[q];
  4148. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4149. /* send the ramrod */
  4150. rc = bnx2x_queue_state_change(bp, &queue_params);
  4151. if (rc < 0)
  4152. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4153. q);
  4154. }
  4155. if (!NO_FCOE(bp)) {
  4156. fp = &bp->fp[FCOE_IDX(bp)];
  4157. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4158. /* clear pending completion bit */
  4159. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4160. /* mark latest Q bit */
  4161. smp_mb__before_clear_bit();
  4162. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4163. smp_mb__after_clear_bit();
  4164. /* send Q update ramrod for FCoE Q */
  4165. rc = bnx2x_queue_state_change(bp, &queue_params);
  4166. if (rc < 0)
  4167. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4168. q);
  4169. } else {
  4170. /* If no FCoE ring - ACK MCP now */
  4171. bnx2x_link_report(bp);
  4172. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4173. }
  4174. }
  4175. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4176. struct bnx2x *bp, u32 cid)
  4177. {
  4178. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4179. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4180. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4181. else
  4182. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4183. }
  4184. static void bnx2x_eq_int(struct bnx2x *bp)
  4185. {
  4186. u16 hw_cons, sw_cons, sw_prod;
  4187. union event_ring_elem *elem;
  4188. u8 echo;
  4189. u32 cid;
  4190. u8 opcode;
  4191. int rc, spqe_cnt = 0;
  4192. struct bnx2x_queue_sp_obj *q_obj;
  4193. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4194. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4195. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4196. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4197. * when we get the the next-page we nned to adjust so the loop
  4198. * condition below will be met. The next element is the size of a
  4199. * regular element and hence incrementing by 1
  4200. */
  4201. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4202. hw_cons++;
  4203. /* This function may never run in parallel with itself for a
  4204. * specific bp, thus there is no need in "paired" read memory
  4205. * barrier here.
  4206. */
  4207. sw_cons = bp->eq_cons;
  4208. sw_prod = bp->eq_prod;
  4209. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4210. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4211. for (; sw_cons != hw_cons;
  4212. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4213. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4214. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4215. if (!rc) {
  4216. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4217. rc);
  4218. goto next_spqe;
  4219. }
  4220. /* elem CID originates from FW; actually LE */
  4221. cid = SW_CID((__force __le32)
  4222. elem->message.data.cfc_del_event.cid);
  4223. opcode = elem->message.opcode;
  4224. /* handle eq element */
  4225. switch (opcode) {
  4226. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4227. DP(BNX2X_MSG_IOV, "vf pf channel element on eq\n");
  4228. bnx2x_vf_mbx(bp, &elem->message.data.vf_pf_event);
  4229. continue;
  4230. case EVENT_RING_OPCODE_STAT_QUERY:
  4231. DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
  4232. "got statistics comp event %d\n",
  4233. bp->stats_comp++);
  4234. /* nothing to do with stats comp */
  4235. goto next_spqe;
  4236. case EVENT_RING_OPCODE_CFC_DEL:
  4237. /* handle according to cid range */
  4238. /*
  4239. * we may want to verify here that the bp state is
  4240. * HALTING
  4241. */
  4242. DP(BNX2X_MSG_SP,
  4243. "got delete ramrod for MULTI[%d]\n", cid);
  4244. if (CNIC_LOADED(bp) &&
  4245. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4246. goto next_spqe;
  4247. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4248. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4249. break;
  4250. goto next_spqe;
  4251. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4252. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4253. if (f_obj->complete_cmd(bp, f_obj,
  4254. BNX2X_F_CMD_TX_STOP))
  4255. break;
  4256. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4257. goto next_spqe;
  4258. case EVENT_RING_OPCODE_START_TRAFFIC:
  4259. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4260. if (f_obj->complete_cmd(bp, f_obj,
  4261. BNX2X_F_CMD_TX_START))
  4262. break;
  4263. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4264. goto next_spqe;
  4265. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4266. echo = elem->message.data.function_update_event.echo;
  4267. if (echo == SWITCH_UPDATE) {
  4268. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4269. "got FUNC_SWITCH_UPDATE ramrod\n");
  4270. if (f_obj->complete_cmd(
  4271. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4272. break;
  4273. } else {
  4274. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4275. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4276. f_obj->complete_cmd(bp, f_obj,
  4277. BNX2X_F_CMD_AFEX_UPDATE);
  4278. /* We will perform the Queues update from
  4279. * sp_rtnl task as all Queue SP operations
  4280. * should run under rtnl_lock.
  4281. */
  4282. smp_mb__before_clear_bit();
  4283. set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
  4284. &bp->sp_rtnl_state);
  4285. smp_mb__after_clear_bit();
  4286. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4287. }
  4288. goto next_spqe;
  4289. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4290. f_obj->complete_cmd(bp, f_obj,
  4291. BNX2X_F_CMD_AFEX_VIFLISTS);
  4292. bnx2x_after_afex_vif_lists(bp, elem);
  4293. goto next_spqe;
  4294. case EVENT_RING_OPCODE_FUNCTION_START:
  4295. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4296. "got FUNC_START ramrod\n");
  4297. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4298. break;
  4299. goto next_spqe;
  4300. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4301. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4302. "got FUNC_STOP ramrod\n");
  4303. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4304. break;
  4305. goto next_spqe;
  4306. }
  4307. switch (opcode | bp->state) {
  4308. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4309. BNX2X_STATE_OPEN):
  4310. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4311. BNX2X_STATE_OPENING_WAIT4_PORT):
  4312. cid = elem->message.data.eth_event.echo &
  4313. BNX2X_SWCID_MASK;
  4314. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4315. cid);
  4316. rss_raw->clear_pending(rss_raw);
  4317. break;
  4318. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4319. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4320. case (EVENT_RING_OPCODE_SET_MAC |
  4321. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4322. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4323. BNX2X_STATE_OPEN):
  4324. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4325. BNX2X_STATE_DIAG):
  4326. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4327. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4328. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4329. bnx2x_handle_classification_eqe(bp, elem);
  4330. break;
  4331. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4332. BNX2X_STATE_OPEN):
  4333. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4334. BNX2X_STATE_DIAG):
  4335. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4336. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4337. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4338. bnx2x_handle_mcast_eqe(bp);
  4339. break;
  4340. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4341. BNX2X_STATE_OPEN):
  4342. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4343. BNX2X_STATE_DIAG):
  4344. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4345. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4346. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4347. bnx2x_handle_rx_mode_eqe(bp);
  4348. break;
  4349. default:
  4350. /* unknown event log error and continue */
  4351. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4352. elem->message.opcode, bp->state);
  4353. }
  4354. next_spqe:
  4355. spqe_cnt++;
  4356. } /* for */
  4357. smp_mb__before_atomic_inc();
  4358. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4359. bp->eq_cons = sw_cons;
  4360. bp->eq_prod = sw_prod;
  4361. /* Make sure that above mem writes were issued towards the memory */
  4362. smp_wmb();
  4363. /* update producer */
  4364. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4365. }
  4366. static void bnx2x_sp_task(struct work_struct *work)
  4367. {
  4368. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4369. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4370. /* make sure the atomic interupt_occurred has been written */
  4371. smp_rmb();
  4372. if (atomic_read(&bp->interrupt_occurred)) {
  4373. /* what work needs to be performed? */
  4374. u16 status = bnx2x_update_dsb_idx(bp);
  4375. DP(BNX2X_MSG_SP, "status %x\n", status);
  4376. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4377. atomic_set(&bp->interrupt_occurred, 0);
  4378. /* HW attentions */
  4379. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4380. bnx2x_attn_int(bp);
  4381. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4382. }
  4383. /* SP events: STAT_QUERY and others */
  4384. if (status & BNX2X_DEF_SB_IDX) {
  4385. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4386. if (FCOE_INIT(bp) &&
  4387. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4388. /* Prevent local bottom-halves from running as
  4389. * we are going to change the local NAPI list.
  4390. */
  4391. local_bh_disable();
  4392. napi_schedule(&bnx2x_fcoe(bp, napi));
  4393. local_bh_enable();
  4394. }
  4395. /* Handle EQ completions */
  4396. bnx2x_eq_int(bp);
  4397. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4398. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4399. status &= ~BNX2X_DEF_SB_IDX;
  4400. }
  4401. /* if status is non zero then perhaps something went wrong */
  4402. if (unlikely(status))
  4403. DP(BNX2X_MSG_SP,
  4404. "got an unknown interrupt! (status 0x%x)\n", status);
  4405. /* ack status block only if something was actually handled */
  4406. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4407. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4408. }
  4409. /* must be called after the EQ processing (since eq leads to sriov
  4410. * ramrod completion flows).
  4411. * This flow may have been scheduled by the arrival of a ramrod
  4412. * completion, or by the sriov code rescheduling itself.
  4413. */
  4414. bnx2x_iov_sp_task(bp);
  4415. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4416. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4417. &bp->sp_state)) {
  4418. bnx2x_link_report(bp);
  4419. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4420. }
  4421. }
  4422. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4423. {
  4424. struct net_device *dev = dev_instance;
  4425. struct bnx2x *bp = netdev_priv(dev);
  4426. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4427. IGU_INT_DISABLE, 0);
  4428. #ifdef BNX2X_STOP_ON_ERROR
  4429. if (unlikely(bp->panic))
  4430. return IRQ_HANDLED;
  4431. #endif
  4432. if (CNIC_LOADED(bp)) {
  4433. struct cnic_ops *c_ops;
  4434. rcu_read_lock();
  4435. c_ops = rcu_dereference(bp->cnic_ops);
  4436. if (c_ops)
  4437. c_ops->cnic_handler(bp->cnic_data, NULL);
  4438. rcu_read_unlock();
  4439. }
  4440. /* schedule sp task to perform default status block work, ack
  4441. * attentions and enable interrupts.
  4442. */
  4443. bnx2x_schedule_sp_task(bp);
  4444. return IRQ_HANDLED;
  4445. }
  4446. /* end of slow path */
  4447. void bnx2x_drv_pulse(struct bnx2x *bp)
  4448. {
  4449. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4450. bp->fw_drv_pulse_wr_seq);
  4451. }
  4452. static void bnx2x_timer(unsigned long data)
  4453. {
  4454. struct bnx2x *bp = (struct bnx2x *) data;
  4455. if (!netif_running(bp->dev))
  4456. return;
  4457. if (IS_PF(bp) &&
  4458. !BP_NOMCP(bp)) {
  4459. int mb_idx = BP_FW_MB_IDX(bp);
  4460. u32 drv_pulse;
  4461. u32 mcp_pulse;
  4462. ++bp->fw_drv_pulse_wr_seq;
  4463. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4464. /* TBD - add SYSTEM_TIME */
  4465. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4466. bnx2x_drv_pulse(bp);
  4467. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4468. MCP_PULSE_SEQ_MASK);
  4469. /* The delta between driver pulse and mcp response
  4470. * should be 1 (before mcp response) or 0 (after mcp response)
  4471. */
  4472. if ((drv_pulse != mcp_pulse) &&
  4473. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  4474. /* someone lost a heartbeat... */
  4475. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4476. drv_pulse, mcp_pulse);
  4477. }
  4478. }
  4479. if (bp->state == BNX2X_STATE_OPEN)
  4480. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4481. /* sample pf vf bulletin board for new posts from pf */
  4482. if (IS_VF(bp))
  4483. bnx2x_sample_bulletin(bp);
  4484. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4485. }
  4486. /* end of Statistics */
  4487. /* nic init */
  4488. /*
  4489. * nic init service functions
  4490. */
  4491. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4492. {
  4493. u32 i;
  4494. if (!(len%4) && !(addr%4))
  4495. for (i = 0; i < len; i += 4)
  4496. REG_WR(bp, addr + i, fill);
  4497. else
  4498. for (i = 0; i < len; i++)
  4499. REG_WR8(bp, addr + i, fill);
  4500. }
  4501. /* helper: writes FP SP data to FW - data_size in dwords */
  4502. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4503. int fw_sb_id,
  4504. u32 *sb_data_p,
  4505. u32 data_size)
  4506. {
  4507. int index;
  4508. for (index = 0; index < data_size; index++)
  4509. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4510. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4511. sizeof(u32)*index,
  4512. *(sb_data_p + index));
  4513. }
  4514. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4515. {
  4516. u32 *sb_data_p;
  4517. u32 data_size = 0;
  4518. struct hc_status_block_data_e2 sb_data_e2;
  4519. struct hc_status_block_data_e1x sb_data_e1x;
  4520. /* disable the function first */
  4521. if (!CHIP_IS_E1x(bp)) {
  4522. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4523. sb_data_e2.common.state = SB_DISABLED;
  4524. sb_data_e2.common.p_func.vf_valid = false;
  4525. sb_data_p = (u32 *)&sb_data_e2;
  4526. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4527. } else {
  4528. memset(&sb_data_e1x, 0,
  4529. sizeof(struct hc_status_block_data_e1x));
  4530. sb_data_e1x.common.state = SB_DISABLED;
  4531. sb_data_e1x.common.p_func.vf_valid = false;
  4532. sb_data_p = (u32 *)&sb_data_e1x;
  4533. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4534. }
  4535. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4536. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4537. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4538. CSTORM_STATUS_BLOCK_SIZE);
  4539. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4540. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4541. CSTORM_SYNC_BLOCK_SIZE);
  4542. }
  4543. /* helper: writes SP SB data to FW */
  4544. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4545. struct hc_sp_status_block_data *sp_sb_data)
  4546. {
  4547. int func = BP_FUNC(bp);
  4548. int i;
  4549. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4550. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4551. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4552. i*sizeof(u32),
  4553. *((u32 *)sp_sb_data + i));
  4554. }
  4555. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4556. {
  4557. int func = BP_FUNC(bp);
  4558. struct hc_sp_status_block_data sp_sb_data;
  4559. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4560. sp_sb_data.state = SB_DISABLED;
  4561. sp_sb_data.p_func.vf_valid = false;
  4562. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4563. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4564. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4565. CSTORM_SP_STATUS_BLOCK_SIZE);
  4566. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4567. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4568. CSTORM_SP_SYNC_BLOCK_SIZE);
  4569. }
  4570. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4571. int igu_sb_id, int igu_seg_id)
  4572. {
  4573. hc_sm->igu_sb_id = igu_sb_id;
  4574. hc_sm->igu_seg_id = igu_seg_id;
  4575. hc_sm->timer_value = 0xFF;
  4576. hc_sm->time_to_expire = 0xFFFFFFFF;
  4577. }
  4578. /* allocates state machine ids. */
  4579. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4580. {
  4581. /* zero out state machine indices */
  4582. /* rx indices */
  4583. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4584. /* tx indices */
  4585. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4586. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4587. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4588. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4589. /* map indices */
  4590. /* rx indices */
  4591. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4592. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4593. /* tx indices */
  4594. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4595. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4596. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4597. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4598. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4599. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4600. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4601. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4602. }
  4603. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4604. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4605. {
  4606. int igu_seg_id;
  4607. struct hc_status_block_data_e2 sb_data_e2;
  4608. struct hc_status_block_data_e1x sb_data_e1x;
  4609. struct hc_status_block_sm *hc_sm_p;
  4610. int data_size;
  4611. u32 *sb_data_p;
  4612. if (CHIP_INT_MODE_IS_BC(bp))
  4613. igu_seg_id = HC_SEG_ACCESS_NORM;
  4614. else
  4615. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4616. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4617. if (!CHIP_IS_E1x(bp)) {
  4618. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4619. sb_data_e2.common.state = SB_ENABLED;
  4620. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4621. sb_data_e2.common.p_func.vf_id = vfid;
  4622. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4623. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4624. sb_data_e2.common.same_igu_sb_1b = true;
  4625. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4626. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4627. hc_sm_p = sb_data_e2.common.state_machine;
  4628. sb_data_p = (u32 *)&sb_data_e2;
  4629. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4630. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4631. } else {
  4632. memset(&sb_data_e1x, 0,
  4633. sizeof(struct hc_status_block_data_e1x));
  4634. sb_data_e1x.common.state = SB_ENABLED;
  4635. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4636. sb_data_e1x.common.p_func.vf_id = 0xff;
  4637. sb_data_e1x.common.p_func.vf_valid = false;
  4638. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4639. sb_data_e1x.common.same_igu_sb_1b = true;
  4640. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4641. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4642. hc_sm_p = sb_data_e1x.common.state_machine;
  4643. sb_data_p = (u32 *)&sb_data_e1x;
  4644. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4645. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4646. }
  4647. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4648. igu_sb_id, igu_seg_id);
  4649. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4650. igu_sb_id, igu_seg_id);
  4651. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4652. /* write indices to HW - PCI guarantees endianity of regpairs */
  4653. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4654. }
  4655. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4656. u16 tx_usec, u16 rx_usec)
  4657. {
  4658. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4659. false, rx_usec);
  4660. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4661. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4662. tx_usec);
  4663. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4664. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4665. tx_usec);
  4666. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4667. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4668. tx_usec);
  4669. }
  4670. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4671. {
  4672. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4673. dma_addr_t mapping = bp->def_status_blk_mapping;
  4674. int igu_sp_sb_index;
  4675. int igu_seg_id;
  4676. int port = BP_PORT(bp);
  4677. int func = BP_FUNC(bp);
  4678. int reg_offset, reg_offset_en5;
  4679. u64 section;
  4680. int index;
  4681. struct hc_sp_status_block_data sp_sb_data;
  4682. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4683. if (CHIP_INT_MODE_IS_BC(bp)) {
  4684. igu_sp_sb_index = DEF_SB_IGU_ID;
  4685. igu_seg_id = HC_SEG_ACCESS_DEF;
  4686. } else {
  4687. igu_sp_sb_index = bp->igu_dsb_id;
  4688. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4689. }
  4690. /* ATTN */
  4691. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4692. atten_status_block);
  4693. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4694. bp->attn_state = 0;
  4695. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4696. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4697. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4698. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4699. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4700. int sindex;
  4701. /* take care of sig[0]..sig[4] */
  4702. for (sindex = 0; sindex < 4; sindex++)
  4703. bp->attn_group[index].sig[sindex] =
  4704. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4705. if (!CHIP_IS_E1x(bp))
  4706. /*
  4707. * enable5 is separate from the rest of the registers,
  4708. * and therefore the address skip is 4
  4709. * and not 16 between the different groups
  4710. */
  4711. bp->attn_group[index].sig[4] = REG_RD(bp,
  4712. reg_offset_en5 + 0x4*index);
  4713. else
  4714. bp->attn_group[index].sig[4] = 0;
  4715. }
  4716. if (bp->common.int_block == INT_BLOCK_HC) {
  4717. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4718. HC_REG_ATTN_MSG0_ADDR_L);
  4719. REG_WR(bp, reg_offset, U64_LO(section));
  4720. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4721. } else if (!CHIP_IS_E1x(bp)) {
  4722. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4723. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4724. }
  4725. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4726. sp_sb);
  4727. bnx2x_zero_sp_sb(bp);
  4728. /* PCI guarantees endianity of regpairs */
  4729. sp_sb_data.state = SB_ENABLED;
  4730. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4731. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4732. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4733. sp_sb_data.igu_seg_id = igu_seg_id;
  4734. sp_sb_data.p_func.pf_id = func;
  4735. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4736. sp_sb_data.p_func.vf_id = 0xff;
  4737. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4738. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4739. }
  4740. void bnx2x_update_coalesce(struct bnx2x *bp)
  4741. {
  4742. int i;
  4743. for_each_eth_queue(bp, i)
  4744. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4745. bp->tx_ticks, bp->rx_ticks);
  4746. }
  4747. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4748. {
  4749. spin_lock_init(&bp->spq_lock);
  4750. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4751. bp->spq_prod_idx = 0;
  4752. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4753. bp->spq_prod_bd = bp->spq;
  4754. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4755. }
  4756. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4757. {
  4758. int i;
  4759. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4760. union event_ring_elem *elem =
  4761. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4762. elem->next_page.addr.hi =
  4763. cpu_to_le32(U64_HI(bp->eq_mapping +
  4764. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4765. elem->next_page.addr.lo =
  4766. cpu_to_le32(U64_LO(bp->eq_mapping +
  4767. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4768. }
  4769. bp->eq_cons = 0;
  4770. bp->eq_prod = NUM_EQ_DESC;
  4771. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4772. /* we want a warning message before it gets rought... */
  4773. atomic_set(&bp->eq_spq_left,
  4774. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4775. }
  4776. /* called with netif_addr_lock_bh() */
  4777. int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4778. unsigned long rx_mode_flags,
  4779. unsigned long rx_accept_flags,
  4780. unsigned long tx_accept_flags,
  4781. unsigned long ramrod_flags)
  4782. {
  4783. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4784. int rc;
  4785. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4786. /* Prepare ramrod parameters */
  4787. ramrod_param.cid = 0;
  4788. ramrod_param.cl_id = cl_id;
  4789. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4790. ramrod_param.func_id = BP_FUNC(bp);
  4791. ramrod_param.pstate = &bp->sp_state;
  4792. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4793. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4794. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4795. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4796. ramrod_param.ramrod_flags = ramrod_flags;
  4797. ramrod_param.rx_mode_flags = rx_mode_flags;
  4798. ramrod_param.rx_accept_flags = rx_accept_flags;
  4799. ramrod_param.tx_accept_flags = tx_accept_flags;
  4800. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4801. if (rc < 0) {
  4802. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4803. return rc;
  4804. }
  4805. return 0;
  4806. }
  4807. static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
  4808. unsigned long *rx_accept_flags,
  4809. unsigned long *tx_accept_flags)
  4810. {
  4811. /* Clear the flags first */
  4812. *rx_accept_flags = 0;
  4813. *tx_accept_flags = 0;
  4814. switch (rx_mode) {
  4815. case BNX2X_RX_MODE_NONE:
  4816. /*
  4817. * 'drop all' supersedes any accept flags that may have been
  4818. * passed to the function.
  4819. */
  4820. break;
  4821. case BNX2X_RX_MODE_NORMAL:
  4822. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4823. __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
  4824. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4825. /* internal switching mode */
  4826. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4827. __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
  4828. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4829. break;
  4830. case BNX2X_RX_MODE_ALLMULTI:
  4831. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4832. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  4833. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4834. /* internal switching mode */
  4835. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4836. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  4837. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4838. break;
  4839. case BNX2X_RX_MODE_PROMISC:
  4840. /* According to deffinition of SI mode, iface in promisc mode
  4841. * should receive matched and unmatched (in resolution of port)
  4842. * unicast packets.
  4843. */
  4844. __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
  4845. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4846. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  4847. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4848. /* internal switching mode */
  4849. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  4850. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4851. if (IS_MF_SI(bp))
  4852. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
  4853. else
  4854. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4855. break;
  4856. default:
  4857. BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
  4858. return -EINVAL;
  4859. }
  4860. /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
  4861. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  4862. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  4863. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  4864. }
  4865. return 0;
  4866. }
  4867. /* called with netif_addr_lock_bh() */
  4868. int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  4869. {
  4870. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  4871. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  4872. int rc;
  4873. if (!NO_FCOE(bp))
  4874. /* Configure rx_mode of FCoE Queue */
  4875. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  4876. rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
  4877. &tx_accept_flags);
  4878. if (rc)
  4879. return rc;
  4880. __set_bit(RAMROD_RX, &ramrod_flags);
  4881. __set_bit(RAMROD_TX, &ramrod_flags);
  4882. return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
  4883. rx_accept_flags, tx_accept_flags,
  4884. ramrod_flags);
  4885. }
  4886. static void bnx2x_init_internal_common(struct bnx2x *bp)
  4887. {
  4888. int i;
  4889. if (IS_MF_SI(bp))
  4890. /*
  4891. * In switch independent mode, the TSTORM needs to accept
  4892. * packets that failed classification, since approximate match
  4893. * mac addresses aren't written to NIG LLH
  4894. */
  4895. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4896. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  4897. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  4898. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4899. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  4900. /* Zero this manually as its initialization is
  4901. currently missing in the initTool */
  4902. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  4903. REG_WR(bp, BAR_USTRORM_INTMEM +
  4904. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  4905. if (!CHIP_IS_E1x(bp)) {
  4906. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  4907. CHIP_INT_MODE_IS_BC(bp) ?
  4908. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  4909. }
  4910. }
  4911. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  4912. {
  4913. switch (load_code) {
  4914. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4915. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  4916. bnx2x_init_internal_common(bp);
  4917. /* no break */
  4918. case FW_MSG_CODE_DRV_LOAD_PORT:
  4919. /* nothing to do */
  4920. /* no break */
  4921. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4922. /* internal memory per function is
  4923. initialized inside bnx2x_pf_init */
  4924. break;
  4925. default:
  4926. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4927. break;
  4928. }
  4929. }
  4930. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  4931. {
  4932. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  4933. }
  4934. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  4935. {
  4936. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  4937. }
  4938. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  4939. {
  4940. if (CHIP_IS_E1x(fp->bp))
  4941. return BP_L_ID(fp->bp) + fp->index;
  4942. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  4943. return bnx2x_fp_igu_sb_id(fp);
  4944. }
  4945. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  4946. {
  4947. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  4948. u8 cos;
  4949. unsigned long q_type = 0;
  4950. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  4951. fp->rx_queue = fp_idx;
  4952. fp->cid = fp_idx;
  4953. fp->cl_id = bnx2x_fp_cl_id(fp);
  4954. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  4955. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  4956. /* qZone id equals to FW (per path) client id */
  4957. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  4958. /* init shortcut */
  4959. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  4960. /* Setup SB indicies */
  4961. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  4962. /* Configure Queue State object */
  4963. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  4964. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  4965. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  4966. /* init tx data */
  4967. for_each_cos_in_tx_queue(fp, cos) {
  4968. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  4969. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  4970. FP_COS_TO_TXQ(fp, cos, bp),
  4971. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  4972. cids[cos] = fp->txdata_ptr[cos]->cid;
  4973. }
  4974. /* nothing more for vf to do here */
  4975. if (IS_VF(bp))
  4976. return;
  4977. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  4978. fp->fw_sb_id, fp->igu_sb_id);
  4979. bnx2x_update_fpsb_idx(fp);
  4980. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  4981. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  4982. bnx2x_sp_mapping(bp, q_rdata), q_type);
  4983. /**
  4984. * Configure classification DBs: Always enable Tx switching
  4985. */
  4986. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  4987. DP(NETIF_MSG_IFUP,
  4988. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  4989. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  4990. fp->igu_sb_id);
  4991. }
  4992. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  4993. {
  4994. int i;
  4995. for (i = 1; i <= NUM_TX_RINGS; i++) {
  4996. struct eth_tx_next_bd *tx_next_bd =
  4997. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  4998. tx_next_bd->addr_hi =
  4999. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  5000. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5001. tx_next_bd->addr_lo =
  5002. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  5003. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5004. }
  5005. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  5006. txdata->tx_db.data.zero_fill1 = 0;
  5007. txdata->tx_db.data.prod = 0;
  5008. txdata->tx_pkt_prod = 0;
  5009. txdata->tx_pkt_cons = 0;
  5010. txdata->tx_bd_prod = 0;
  5011. txdata->tx_bd_cons = 0;
  5012. txdata->tx_pkt = 0;
  5013. }
  5014. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  5015. {
  5016. int i;
  5017. for_each_tx_queue_cnic(bp, i)
  5018. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  5019. }
  5020. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  5021. {
  5022. int i;
  5023. u8 cos;
  5024. for_each_eth_queue(bp, i)
  5025. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  5026. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  5027. }
  5028. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  5029. {
  5030. if (!NO_FCOE(bp))
  5031. bnx2x_init_fcoe_fp(bp);
  5032. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  5033. BNX2X_VF_ID_INVALID, false,
  5034. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  5035. /* ensure status block indices were read */
  5036. rmb();
  5037. bnx2x_init_rx_rings_cnic(bp);
  5038. bnx2x_init_tx_rings_cnic(bp);
  5039. /* flush all */
  5040. mb();
  5041. mmiowb();
  5042. }
  5043. void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
  5044. {
  5045. int i;
  5046. for_each_eth_queue(bp, i)
  5047. bnx2x_init_eth_fp(bp, i);
  5048. /* ensure status block indices were read */
  5049. rmb();
  5050. bnx2x_init_rx_rings(bp);
  5051. bnx2x_init_tx_rings(bp);
  5052. if (IS_VF(bp))
  5053. return;
  5054. /* Initialize MOD_ABS interrupts */
  5055. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  5056. bp->common.shmem_base, bp->common.shmem2_base,
  5057. BP_PORT(bp));
  5058. bnx2x_init_def_sb(bp);
  5059. bnx2x_update_dsb_idx(bp);
  5060. bnx2x_init_sp_ring(bp);
  5061. bnx2x_init_eq_ring(bp);
  5062. bnx2x_init_internal(bp, load_code);
  5063. bnx2x_pf_init(bp);
  5064. bnx2x_stats_init(bp);
  5065. /* flush all before enabling interrupts */
  5066. mb();
  5067. mmiowb();
  5068. bnx2x_int_enable(bp);
  5069. /* Check for SPIO5 */
  5070. bnx2x_attn_int_deasserted0(bp,
  5071. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  5072. AEU_INPUTS_ATTN_BITS_SPIO5);
  5073. }
  5074. /* end of nic init */
  5075. /*
  5076. * gzip service functions
  5077. */
  5078. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5079. {
  5080. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5081. &bp->gunzip_mapping, GFP_KERNEL);
  5082. if (bp->gunzip_buf == NULL)
  5083. goto gunzip_nomem1;
  5084. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5085. if (bp->strm == NULL)
  5086. goto gunzip_nomem2;
  5087. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5088. if (bp->strm->workspace == NULL)
  5089. goto gunzip_nomem3;
  5090. return 0;
  5091. gunzip_nomem3:
  5092. kfree(bp->strm);
  5093. bp->strm = NULL;
  5094. gunzip_nomem2:
  5095. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5096. bp->gunzip_mapping);
  5097. bp->gunzip_buf = NULL;
  5098. gunzip_nomem1:
  5099. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5100. return -ENOMEM;
  5101. }
  5102. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5103. {
  5104. if (bp->strm) {
  5105. vfree(bp->strm->workspace);
  5106. kfree(bp->strm);
  5107. bp->strm = NULL;
  5108. }
  5109. if (bp->gunzip_buf) {
  5110. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5111. bp->gunzip_mapping);
  5112. bp->gunzip_buf = NULL;
  5113. }
  5114. }
  5115. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5116. {
  5117. int n, rc;
  5118. /* check gzip header */
  5119. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5120. BNX2X_ERR("Bad gzip header\n");
  5121. return -EINVAL;
  5122. }
  5123. n = 10;
  5124. #define FNAME 0x8
  5125. if (zbuf[3] & FNAME)
  5126. while ((zbuf[n++] != 0) && (n < len));
  5127. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5128. bp->strm->avail_in = len - n;
  5129. bp->strm->next_out = bp->gunzip_buf;
  5130. bp->strm->avail_out = FW_BUF_SIZE;
  5131. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5132. if (rc != Z_OK)
  5133. return rc;
  5134. rc = zlib_inflate(bp->strm, Z_FINISH);
  5135. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5136. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5137. bp->strm->msg);
  5138. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5139. if (bp->gunzip_outlen & 0x3)
  5140. netdev_err(bp->dev,
  5141. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5142. bp->gunzip_outlen);
  5143. bp->gunzip_outlen >>= 2;
  5144. zlib_inflateEnd(bp->strm);
  5145. if (rc == Z_STREAM_END)
  5146. return 0;
  5147. return rc;
  5148. }
  5149. /* nic load/unload */
  5150. /*
  5151. * General service functions
  5152. */
  5153. /* send a NIG loopback debug packet */
  5154. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5155. {
  5156. u32 wb_write[3];
  5157. /* Ethernet source and destination addresses */
  5158. wb_write[0] = 0x55555555;
  5159. wb_write[1] = 0x55555555;
  5160. wb_write[2] = 0x20; /* SOP */
  5161. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5162. /* NON-IP protocol */
  5163. wb_write[0] = 0x09000000;
  5164. wb_write[1] = 0x55555555;
  5165. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5166. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5167. }
  5168. /* some of the internal memories
  5169. * are not directly readable from the driver
  5170. * to test them we send debug packets
  5171. */
  5172. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5173. {
  5174. int factor;
  5175. int count, i;
  5176. u32 val = 0;
  5177. if (CHIP_REV_IS_FPGA(bp))
  5178. factor = 120;
  5179. else if (CHIP_REV_IS_EMUL(bp))
  5180. factor = 200;
  5181. else
  5182. factor = 1;
  5183. /* Disable inputs of parser neighbor blocks */
  5184. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5185. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5186. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5187. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5188. /* Write 0 to parser credits for CFC search request */
  5189. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5190. /* send Ethernet packet */
  5191. bnx2x_lb_pckt(bp);
  5192. /* TODO do i reset NIG statistic? */
  5193. /* Wait until NIG register shows 1 packet of size 0x10 */
  5194. count = 1000 * factor;
  5195. while (count) {
  5196. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5197. val = *bnx2x_sp(bp, wb_data[0]);
  5198. if (val == 0x10)
  5199. break;
  5200. msleep(10);
  5201. count--;
  5202. }
  5203. if (val != 0x10) {
  5204. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5205. return -1;
  5206. }
  5207. /* Wait until PRS register shows 1 packet */
  5208. count = 1000 * factor;
  5209. while (count) {
  5210. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5211. if (val == 1)
  5212. break;
  5213. msleep(10);
  5214. count--;
  5215. }
  5216. if (val != 0x1) {
  5217. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5218. return -2;
  5219. }
  5220. /* Reset and init BRB, PRS */
  5221. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5222. msleep(50);
  5223. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5224. msleep(50);
  5225. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5226. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5227. DP(NETIF_MSG_HW, "part2\n");
  5228. /* Disable inputs of parser neighbor blocks */
  5229. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5230. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5231. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5232. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5233. /* Write 0 to parser credits for CFC search request */
  5234. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5235. /* send 10 Ethernet packets */
  5236. for (i = 0; i < 10; i++)
  5237. bnx2x_lb_pckt(bp);
  5238. /* Wait until NIG register shows 10 + 1
  5239. packets of size 11*0x10 = 0xb0 */
  5240. count = 1000 * factor;
  5241. while (count) {
  5242. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5243. val = *bnx2x_sp(bp, wb_data[0]);
  5244. if (val == 0xb0)
  5245. break;
  5246. msleep(10);
  5247. count--;
  5248. }
  5249. if (val != 0xb0) {
  5250. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5251. return -3;
  5252. }
  5253. /* Wait until PRS register shows 2 packets */
  5254. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5255. if (val != 2)
  5256. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5257. /* Write 1 to parser credits for CFC search request */
  5258. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5259. /* Wait until PRS register shows 3 packets */
  5260. msleep(10 * factor);
  5261. /* Wait until NIG register shows 1 packet of size 0x10 */
  5262. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5263. if (val != 3)
  5264. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5265. /* clear NIG EOP FIFO */
  5266. for (i = 0; i < 11; i++)
  5267. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5268. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5269. if (val != 1) {
  5270. BNX2X_ERR("clear of NIG failed\n");
  5271. return -4;
  5272. }
  5273. /* Reset and init BRB, PRS, NIG */
  5274. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5275. msleep(50);
  5276. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5277. msleep(50);
  5278. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5279. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5280. if (!CNIC_SUPPORT(bp))
  5281. /* set NIC mode */
  5282. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5283. /* Enable inputs of parser neighbor blocks */
  5284. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5285. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5286. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5287. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5288. DP(NETIF_MSG_HW, "done\n");
  5289. return 0; /* OK */
  5290. }
  5291. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5292. {
  5293. u32 val;
  5294. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5295. if (!CHIP_IS_E1x(bp))
  5296. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5297. else
  5298. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5299. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5300. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5301. /*
  5302. * mask read length error interrupts in brb for parser
  5303. * (parsing unit and 'checksum and crc' unit)
  5304. * these errors are legal (PU reads fixed length and CAC can cause
  5305. * read length error on truncated packets)
  5306. */
  5307. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5308. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5309. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5310. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5311. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5312. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5313. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5314. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5315. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5316. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5317. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5318. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5319. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5320. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5321. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5322. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5323. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5324. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5325. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5326. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5327. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5328. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5329. if (!CHIP_IS_E1x(bp))
  5330. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5331. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5332. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5333. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5334. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5335. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5336. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5337. if (!CHIP_IS_E1x(bp))
  5338. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5339. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5340. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5341. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5342. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5343. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5344. }
  5345. static void bnx2x_reset_common(struct bnx2x *bp)
  5346. {
  5347. u32 val = 0x1400;
  5348. /* reset_common */
  5349. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5350. 0xd3ffff7f);
  5351. if (CHIP_IS_E3(bp)) {
  5352. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5353. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5354. }
  5355. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5356. }
  5357. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5358. {
  5359. bp->dmae_ready = 0;
  5360. spin_lock_init(&bp->dmae_lock);
  5361. }
  5362. static void bnx2x_init_pxp(struct bnx2x *bp)
  5363. {
  5364. u16 devctl;
  5365. int r_order, w_order;
  5366. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5367. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5368. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5369. if (bp->mrrs == -1)
  5370. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5371. else {
  5372. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5373. r_order = bp->mrrs;
  5374. }
  5375. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5376. }
  5377. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5378. {
  5379. int is_required;
  5380. u32 val;
  5381. int port;
  5382. if (BP_NOMCP(bp))
  5383. return;
  5384. is_required = 0;
  5385. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5386. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5387. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5388. is_required = 1;
  5389. /*
  5390. * The fan failure mechanism is usually related to the PHY type since
  5391. * the power consumption of the board is affected by the PHY. Currently,
  5392. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5393. */
  5394. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5395. for (port = PORT_0; port < PORT_MAX; port++) {
  5396. is_required |=
  5397. bnx2x_fan_failure_det_req(
  5398. bp,
  5399. bp->common.shmem_base,
  5400. bp->common.shmem2_base,
  5401. port);
  5402. }
  5403. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5404. if (is_required == 0)
  5405. return;
  5406. /* Fan failure is indicated by SPIO 5 */
  5407. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5408. /* set to active low mode */
  5409. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5410. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5411. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5412. /* enable interrupt to signal the IGU */
  5413. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5414. val |= MISC_SPIO_SPIO5;
  5415. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5416. }
  5417. void bnx2x_pf_disable(struct bnx2x *bp)
  5418. {
  5419. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5420. val &= ~IGU_PF_CONF_FUNC_EN;
  5421. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5422. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5423. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5424. }
  5425. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5426. {
  5427. u32 shmem_base[2], shmem2_base[2];
  5428. /* Avoid common init in case MFW supports LFA */
  5429. if (SHMEM2_RD(bp, size) >
  5430. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5431. return;
  5432. shmem_base[0] = bp->common.shmem_base;
  5433. shmem2_base[0] = bp->common.shmem2_base;
  5434. if (!CHIP_IS_E1x(bp)) {
  5435. shmem_base[1] =
  5436. SHMEM2_RD(bp, other_shmem_base_addr);
  5437. shmem2_base[1] =
  5438. SHMEM2_RD(bp, other_shmem2_base_addr);
  5439. }
  5440. bnx2x_acquire_phy_lock(bp);
  5441. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5442. bp->common.chip_id);
  5443. bnx2x_release_phy_lock(bp);
  5444. }
  5445. /**
  5446. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5447. *
  5448. * @bp: driver handle
  5449. */
  5450. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5451. {
  5452. u32 val;
  5453. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5454. /*
  5455. * take the RESET lock to protect undi_unload flow from accessing
  5456. * registers while we're resetting the chip
  5457. */
  5458. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5459. bnx2x_reset_common(bp);
  5460. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5461. val = 0xfffc;
  5462. if (CHIP_IS_E3(bp)) {
  5463. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5464. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5465. }
  5466. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5467. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5468. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5469. if (!CHIP_IS_E1x(bp)) {
  5470. u8 abs_func_id;
  5471. /**
  5472. * 4-port mode or 2-port mode we need to turn of master-enable
  5473. * for everyone, after that, turn it back on for self.
  5474. * so, we disregard multi-function or not, and always disable
  5475. * for all functions on the given path, this means 0,2,4,6 for
  5476. * path 0 and 1,3,5,7 for path 1
  5477. */
  5478. for (abs_func_id = BP_PATH(bp);
  5479. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5480. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5481. REG_WR(bp,
  5482. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5483. 1);
  5484. continue;
  5485. }
  5486. bnx2x_pretend_func(bp, abs_func_id);
  5487. /* clear pf enable */
  5488. bnx2x_pf_disable(bp);
  5489. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5490. }
  5491. }
  5492. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5493. if (CHIP_IS_E1(bp)) {
  5494. /* enable HW interrupt from PXP on USDM overflow
  5495. bit 16 on INT_MASK_0 */
  5496. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5497. }
  5498. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5499. bnx2x_init_pxp(bp);
  5500. #ifdef __BIG_ENDIAN
  5501. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5502. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5503. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5504. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5505. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5506. /* make sure this value is 0 */
  5507. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5508. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5509. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5510. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5511. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5512. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5513. #endif
  5514. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5515. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5516. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5517. /* let the HW do it's magic ... */
  5518. msleep(100);
  5519. /* finish PXP init */
  5520. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5521. if (val != 1) {
  5522. BNX2X_ERR("PXP2 CFG failed\n");
  5523. return -EBUSY;
  5524. }
  5525. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5526. if (val != 1) {
  5527. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5528. return -EBUSY;
  5529. }
  5530. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5531. * have entries with value "0" and valid bit on.
  5532. * This needs to be done by the first PF that is loaded in a path
  5533. * (i.e. common phase)
  5534. */
  5535. if (!CHIP_IS_E1x(bp)) {
  5536. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5537. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5538. * This occurs when a different function (func2,3) is being marked
  5539. * as "scan-off". Real-life scenario for example: if a driver is being
  5540. * load-unloaded while func6,7 are down. This will cause the timer to access
  5541. * the ilt, translate to a logical address and send a request to read/write.
  5542. * Since the ilt for the function that is down is not valid, this will cause
  5543. * a translation error which is unrecoverable.
  5544. * The Workaround is intended to make sure that when this happens nothing fatal
  5545. * will occur. The workaround:
  5546. * 1. First PF driver which loads on a path will:
  5547. * a. After taking the chip out of reset, by using pretend,
  5548. * it will write "0" to the following registers of
  5549. * the other vnics.
  5550. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5551. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5552. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5553. * And for itself it will write '1' to
  5554. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5555. * dmae-operations (writing to pram for example.)
  5556. * note: can be done for only function 6,7 but cleaner this
  5557. * way.
  5558. * b. Write zero+valid to the entire ILT.
  5559. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5560. * VNIC3 (of that port). The range allocated will be the
  5561. * entire ILT. This is needed to prevent ILT range error.
  5562. * 2. Any PF driver load flow:
  5563. * a. ILT update with the physical addresses of the allocated
  5564. * logical pages.
  5565. * b. Wait 20msec. - note that this timeout is needed to make
  5566. * sure there are no requests in one of the PXP internal
  5567. * queues with "old" ILT addresses.
  5568. * c. PF enable in the PGLC.
  5569. * d. Clear the was_error of the PF in the PGLC. (could have
  5570. * occurred while driver was down)
  5571. * e. PF enable in the CFC (WEAK + STRONG)
  5572. * f. Timers scan enable
  5573. * 3. PF driver unload flow:
  5574. * a. Clear the Timers scan_en.
  5575. * b. Polling for scan_on=0 for that PF.
  5576. * c. Clear the PF enable bit in the PXP.
  5577. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5578. * e. Write zero+valid to all ILT entries (The valid bit must
  5579. * stay set)
  5580. * f. If this is VNIC 3 of a port then also init
  5581. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5582. * to the last enrty in the ILT.
  5583. *
  5584. * Notes:
  5585. * Currently the PF error in the PGLC is non recoverable.
  5586. * In the future the there will be a recovery routine for this error.
  5587. * Currently attention is masked.
  5588. * Having an MCP lock on the load/unload process does not guarantee that
  5589. * there is no Timer disable during Func6/7 enable. This is because the
  5590. * Timers scan is currently being cleared by the MCP on FLR.
  5591. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5592. * there is error before clearing it. But the flow above is simpler and
  5593. * more general.
  5594. * All ILT entries are written by zero+valid and not just PF6/7
  5595. * ILT entries since in the future the ILT entries allocation for
  5596. * PF-s might be dynamic.
  5597. */
  5598. struct ilt_client_info ilt_cli;
  5599. struct bnx2x_ilt ilt;
  5600. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5601. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5602. /* initialize dummy TM client */
  5603. ilt_cli.start = 0;
  5604. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5605. ilt_cli.client_num = ILT_CLIENT_TM;
  5606. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5607. * Step 2: set the timers first/last ilt entry to point
  5608. * to the entire range to prevent ILT range error for 3rd/4th
  5609. * vnic (this code assumes existence of the vnic)
  5610. *
  5611. * both steps performed by call to bnx2x_ilt_client_init_op()
  5612. * with dummy TM client
  5613. *
  5614. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5615. * and his brother are split registers
  5616. */
  5617. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5618. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5619. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5620. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5621. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5622. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5623. }
  5624. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5625. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5626. if (!CHIP_IS_E1x(bp)) {
  5627. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5628. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5629. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5630. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5631. /* let the HW do it's magic ... */
  5632. do {
  5633. msleep(200);
  5634. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5635. } while (factor-- && (val != 1));
  5636. if (val != 1) {
  5637. BNX2X_ERR("ATC_INIT failed\n");
  5638. return -EBUSY;
  5639. }
  5640. }
  5641. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5642. bnx2x_iov_init_dmae(bp);
  5643. /* clean the DMAE memory */
  5644. bp->dmae_ready = 1;
  5645. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5646. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5647. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5648. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5649. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5650. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5651. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5652. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5653. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5654. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5655. /* QM queues pointers table */
  5656. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5657. /* soft reset pulse */
  5658. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5659. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5660. if (CNIC_SUPPORT(bp))
  5661. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5662. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5663. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
  5664. if (!CHIP_REV_IS_SLOW(bp))
  5665. /* enable hw interrupt from doorbell Q */
  5666. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5667. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5668. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5669. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5670. if (!CHIP_IS_E1(bp))
  5671. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5672. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  5673. if (IS_MF_AFEX(bp)) {
  5674. /* configure that VNTag and VLAN headers must be
  5675. * received in afex mode
  5676. */
  5677. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  5678. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  5679. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  5680. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  5681. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  5682. } else {
  5683. /* Bit-map indicating which L2 hdrs may appear
  5684. * after the basic Ethernet header
  5685. */
  5686. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5687. bp->path_has_ovlan ? 7 : 6);
  5688. }
  5689. }
  5690. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5691. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5692. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5693. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5694. if (!CHIP_IS_E1x(bp)) {
  5695. /* reset VFC memories */
  5696. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5697. VFC_MEMORIES_RST_REG_CAM_RST |
  5698. VFC_MEMORIES_RST_REG_RAM_RST);
  5699. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5700. VFC_MEMORIES_RST_REG_CAM_RST |
  5701. VFC_MEMORIES_RST_REG_RAM_RST);
  5702. msleep(20);
  5703. }
  5704. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5705. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5706. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5707. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5708. /* sync semi rtc */
  5709. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5710. 0x80000000);
  5711. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5712. 0x80000000);
  5713. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5714. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5715. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5716. if (!CHIP_IS_E1x(bp)) {
  5717. if (IS_MF_AFEX(bp)) {
  5718. /* configure that VNTag and VLAN headers must be
  5719. * sent in afex mode
  5720. */
  5721. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  5722. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  5723. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  5724. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  5725. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  5726. } else {
  5727. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5728. bp->path_has_ovlan ? 7 : 6);
  5729. }
  5730. }
  5731. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5732. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5733. if (CNIC_SUPPORT(bp)) {
  5734. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5735. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5736. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5737. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5738. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5739. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5740. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5741. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5742. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5743. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5744. }
  5745. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5746. if (sizeof(union cdu_context) != 1024)
  5747. /* we currently assume that a context is 1024 bytes */
  5748. dev_alert(&bp->pdev->dev,
  5749. "please adjust the size of cdu_context(%ld)\n",
  5750. (long)sizeof(union cdu_context));
  5751. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5752. val = (4 << 24) + (0 << 12) + 1024;
  5753. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5754. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5755. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5756. /* enable context validation interrupt from CFC */
  5757. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5758. /* set the thresholds to prevent CFC/CDU race */
  5759. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5760. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5761. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5762. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5763. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5764. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5765. /* Reset PCIE errors for debug */
  5766. REG_WR(bp, 0x2814, 0xffffffff);
  5767. REG_WR(bp, 0x3820, 0xffffffff);
  5768. if (!CHIP_IS_E1x(bp)) {
  5769. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5770. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5771. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5772. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5773. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5774. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5775. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5776. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5777. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5778. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5779. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5780. }
  5781. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5782. if (!CHIP_IS_E1(bp)) {
  5783. /* in E3 this done in per-port section */
  5784. if (!CHIP_IS_E3(bp))
  5785. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5786. }
  5787. if (CHIP_IS_E1H(bp))
  5788. /* not applicable for E2 (and above ...) */
  5789. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5790. if (CHIP_REV_IS_SLOW(bp))
  5791. msleep(200);
  5792. /* finish CFC init */
  5793. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5794. if (val != 1) {
  5795. BNX2X_ERR("CFC LL_INIT failed\n");
  5796. return -EBUSY;
  5797. }
  5798. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5799. if (val != 1) {
  5800. BNX2X_ERR("CFC AC_INIT failed\n");
  5801. return -EBUSY;
  5802. }
  5803. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5804. if (val != 1) {
  5805. BNX2X_ERR("CFC CAM_INIT failed\n");
  5806. return -EBUSY;
  5807. }
  5808. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5809. if (CHIP_IS_E1(bp)) {
  5810. /* read NIG statistic
  5811. to see if this is our first up since powerup */
  5812. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5813. val = *bnx2x_sp(bp, wb_data[0]);
  5814. /* do internal memory self test */
  5815. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5816. BNX2X_ERR("internal mem self test failed\n");
  5817. return -EBUSY;
  5818. }
  5819. }
  5820. bnx2x_setup_fan_failure_detection(bp);
  5821. /* clear PXP2 attentions */
  5822. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5823. bnx2x_enable_blocks_attention(bp);
  5824. bnx2x_enable_blocks_parity(bp);
  5825. if (!BP_NOMCP(bp)) {
  5826. if (CHIP_IS_E1x(bp))
  5827. bnx2x__common_init_phy(bp);
  5828. } else
  5829. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5830. return 0;
  5831. }
  5832. /**
  5833. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  5834. *
  5835. * @bp: driver handle
  5836. */
  5837. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  5838. {
  5839. int rc = bnx2x_init_hw_common(bp);
  5840. if (rc)
  5841. return rc;
  5842. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  5843. if (!BP_NOMCP(bp))
  5844. bnx2x__common_init_phy(bp);
  5845. return 0;
  5846. }
  5847. static int bnx2x_init_hw_port(struct bnx2x *bp)
  5848. {
  5849. int port = BP_PORT(bp);
  5850. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  5851. u32 low, high;
  5852. u32 val;
  5853. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  5854. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  5855. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5856. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5857. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5858. /* Timers bug workaround: disables the pf_master bit in pglue at
  5859. * common phase, we need to enable it here before any dmae access are
  5860. * attempted. Therefore we manually added the enable-master to the
  5861. * port phase (it also happens in the function phase)
  5862. */
  5863. if (!CHIP_IS_E1x(bp))
  5864. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5865. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5866. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5867. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5868. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5869. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5870. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5871. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5872. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5873. /* QM cid (connection) count */
  5874. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  5875. if (CNIC_SUPPORT(bp)) {
  5876. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5877. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  5878. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  5879. }
  5880. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5881. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5882. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  5883. if (IS_MF(bp))
  5884. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  5885. else if (bp->dev->mtu > 4096) {
  5886. if (bp->flags & ONE_PORT_FLAG)
  5887. low = 160;
  5888. else {
  5889. val = bp->dev->mtu;
  5890. /* (24*1024 + val*4)/256 */
  5891. low = 96 + (val/64) +
  5892. ((val % 64) ? 1 : 0);
  5893. }
  5894. } else
  5895. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  5896. high = low + 56; /* 14*1024/256 */
  5897. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  5898. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  5899. }
  5900. if (CHIP_MODE_IS_4_PORT(bp))
  5901. REG_WR(bp, (BP_PORT(bp) ?
  5902. BRB1_REG_MAC_GUARANTIED_1 :
  5903. BRB1_REG_MAC_GUARANTIED_0), 40);
  5904. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5905. if (CHIP_IS_E3B0(bp)) {
  5906. if (IS_MF_AFEX(bp)) {
  5907. /* configure headers for AFEX mode */
  5908. REG_WR(bp, BP_PORT(bp) ?
  5909. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5910. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  5911. REG_WR(bp, BP_PORT(bp) ?
  5912. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  5913. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  5914. REG_WR(bp, BP_PORT(bp) ?
  5915. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  5916. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  5917. } else {
  5918. /* Ovlan exists only if we are in multi-function +
  5919. * switch-dependent mode, in switch-independent there
  5920. * is no ovlan headers
  5921. */
  5922. REG_WR(bp, BP_PORT(bp) ?
  5923. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5924. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  5925. (bp->path_has_ovlan ? 7 : 6));
  5926. }
  5927. }
  5928. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5929. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5930. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5931. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5932. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5933. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5934. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5935. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5936. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5937. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5938. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5939. if (CHIP_IS_E1x(bp)) {
  5940. /* configure PBF to work without PAUSE mtu 9000 */
  5941. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  5942. /* update threshold */
  5943. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  5944. /* update init credit */
  5945. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  5946. /* probe changes */
  5947. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  5948. udelay(50);
  5949. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  5950. }
  5951. if (CNIC_SUPPORT(bp))
  5952. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5953. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5954. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5955. if (CHIP_IS_E1(bp)) {
  5956. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5957. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5958. }
  5959. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5960. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5961. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5962. /* init aeu_mask_attn_func_0/1:
  5963. * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
  5964. * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
  5965. * bits 4-7 are used for "per vn group attention" */
  5966. val = IS_MF(bp) ? 0xF7 : 0x7;
  5967. /* Enable DCBX attention for all but E1 */
  5968. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  5969. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  5970. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5971. if (!CHIP_IS_E1x(bp)) {
  5972. /* Bit-map indicating which L2 hdrs may appear after the
  5973. * basic Ethernet header
  5974. */
  5975. if (IS_MF_AFEX(bp))
  5976. REG_WR(bp, BP_PORT(bp) ?
  5977. NIG_REG_P1_HDRS_AFTER_BASIC :
  5978. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  5979. else
  5980. REG_WR(bp, BP_PORT(bp) ?
  5981. NIG_REG_P1_HDRS_AFTER_BASIC :
  5982. NIG_REG_P0_HDRS_AFTER_BASIC,
  5983. IS_MF_SD(bp) ? 7 : 6);
  5984. if (CHIP_IS_E3(bp))
  5985. REG_WR(bp, BP_PORT(bp) ?
  5986. NIG_REG_LLH1_MF_MODE :
  5987. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5988. }
  5989. if (!CHIP_IS_E3(bp))
  5990. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  5991. if (!CHIP_IS_E1(bp)) {
  5992. /* 0x2 disable mf_ov, 0x1 enable */
  5993. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  5994. (IS_MF_SD(bp) ? 0x1 : 0x2));
  5995. if (!CHIP_IS_E1x(bp)) {
  5996. val = 0;
  5997. switch (bp->mf_mode) {
  5998. case MULTI_FUNCTION_SD:
  5999. val = 1;
  6000. break;
  6001. case MULTI_FUNCTION_SI:
  6002. case MULTI_FUNCTION_AFEX:
  6003. val = 2;
  6004. break;
  6005. }
  6006. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  6007. NIG_REG_LLH0_CLS_TYPE), val);
  6008. }
  6009. {
  6010. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  6011. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  6012. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  6013. }
  6014. }
  6015. /* If SPIO5 is set to generate interrupts, enable it for this port */
  6016. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  6017. if (val & MISC_SPIO_SPIO5) {
  6018. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  6019. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  6020. val = REG_RD(bp, reg_addr);
  6021. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  6022. REG_WR(bp, reg_addr, val);
  6023. }
  6024. return 0;
  6025. }
  6026. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  6027. {
  6028. int reg;
  6029. u32 wb_write[2];
  6030. if (CHIP_IS_E1(bp))
  6031. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  6032. else
  6033. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  6034. wb_write[0] = ONCHIP_ADDR1(addr);
  6035. wb_write[1] = ONCHIP_ADDR2(addr);
  6036. REG_WR_DMAE(bp, reg, wb_write, 2);
  6037. }
  6038. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  6039. {
  6040. u32 data, ctl, cnt = 100;
  6041. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  6042. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  6043. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  6044. u32 sb_bit = 1 << (idu_sb_id%32);
  6045. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  6046. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  6047. /* Not supported in BC mode */
  6048. if (CHIP_INT_MODE_IS_BC(bp))
  6049. return;
  6050. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  6051. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  6052. IGU_REGULAR_CLEANUP_SET |
  6053. IGU_REGULAR_BCLEANUP;
  6054. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  6055. func_encode << IGU_CTRL_REG_FID_SHIFT |
  6056. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  6057. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6058. data, igu_addr_data);
  6059. REG_WR(bp, igu_addr_data, data);
  6060. mmiowb();
  6061. barrier();
  6062. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6063. ctl, igu_addr_ctl);
  6064. REG_WR(bp, igu_addr_ctl, ctl);
  6065. mmiowb();
  6066. barrier();
  6067. /* wait for clean up to finish */
  6068. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  6069. msleep(20);
  6070. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  6071. DP(NETIF_MSG_HW,
  6072. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  6073. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  6074. }
  6075. }
  6076. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  6077. {
  6078. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6079. }
  6080. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6081. {
  6082. u32 i, base = FUNC_ILT_BASE(func);
  6083. for (i = base; i < base + ILT_PER_FUNC; i++)
  6084. bnx2x_ilt_wr(bp, i, 0);
  6085. }
  6086. static void bnx2x_init_searcher(struct bnx2x *bp)
  6087. {
  6088. int port = BP_PORT(bp);
  6089. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6090. /* T1 hash bits value determines the T1 number of entries */
  6091. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6092. }
  6093. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6094. {
  6095. int rc;
  6096. struct bnx2x_func_state_params func_params = {NULL};
  6097. struct bnx2x_func_switch_update_params *switch_update_params =
  6098. &func_params.params.switch_update;
  6099. /* Prepare parameters for function state transitions */
  6100. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6101. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6102. func_params.f_obj = &bp->func_obj;
  6103. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6104. /* Function parameters */
  6105. switch_update_params->suspend = suspend;
  6106. rc = bnx2x_func_state_change(bp, &func_params);
  6107. return rc;
  6108. }
  6109. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6110. {
  6111. int rc, i, port = BP_PORT(bp);
  6112. int vlan_en = 0, mac_en[NUM_MACS];
  6113. /* Close input from network */
  6114. if (bp->mf_mode == SINGLE_FUNCTION) {
  6115. bnx2x_set_rx_filter(&bp->link_params, 0);
  6116. } else {
  6117. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6118. NIG_REG_LLH0_FUNC_EN);
  6119. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6120. NIG_REG_LLH0_FUNC_EN, 0);
  6121. for (i = 0; i < NUM_MACS; i++) {
  6122. mac_en[i] = REG_RD(bp, port ?
  6123. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6124. 4 * i) :
  6125. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6126. 4 * i));
  6127. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6128. 4 * i) :
  6129. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6130. }
  6131. }
  6132. /* Close BMC to host */
  6133. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6134. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6135. /* Suspend Tx switching to the PF. Completion of this ramrod
  6136. * further guarantees that all the packets of that PF / child
  6137. * VFs in BRB were processed by the Parser, so it is safe to
  6138. * change the NIC_MODE register.
  6139. */
  6140. rc = bnx2x_func_switch_update(bp, 1);
  6141. if (rc) {
  6142. BNX2X_ERR("Can't suspend tx-switching!\n");
  6143. return rc;
  6144. }
  6145. /* Change NIC_MODE register */
  6146. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6147. /* Open input from network */
  6148. if (bp->mf_mode == SINGLE_FUNCTION) {
  6149. bnx2x_set_rx_filter(&bp->link_params, 1);
  6150. } else {
  6151. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6152. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6153. for (i = 0; i < NUM_MACS; i++) {
  6154. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6155. 4 * i) :
  6156. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6157. mac_en[i]);
  6158. }
  6159. }
  6160. /* Enable BMC to host */
  6161. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6162. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6163. /* Resume Tx switching to the PF */
  6164. rc = bnx2x_func_switch_update(bp, 0);
  6165. if (rc) {
  6166. BNX2X_ERR("Can't resume tx-switching!\n");
  6167. return rc;
  6168. }
  6169. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6170. return 0;
  6171. }
  6172. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6173. {
  6174. int rc;
  6175. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6176. if (CONFIGURE_NIC_MODE(bp)) {
  6177. /* Configrue searcher as part of function hw init */
  6178. bnx2x_init_searcher(bp);
  6179. /* Reset NIC mode */
  6180. rc = bnx2x_reset_nic_mode(bp);
  6181. if (rc)
  6182. BNX2X_ERR("Can't change NIC mode!\n");
  6183. return rc;
  6184. }
  6185. return 0;
  6186. }
  6187. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6188. {
  6189. int port = BP_PORT(bp);
  6190. int func = BP_FUNC(bp);
  6191. int init_phase = PHASE_PF0 + func;
  6192. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6193. u16 cdu_ilt_start;
  6194. u32 addr, val;
  6195. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6196. int i, main_mem_width, rc;
  6197. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6198. /* FLR cleanup - hmmm */
  6199. if (!CHIP_IS_E1x(bp)) {
  6200. rc = bnx2x_pf_flr_clnup(bp);
  6201. if (rc) {
  6202. bnx2x_fw_dump(bp);
  6203. return rc;
  6204. }
  6205. }
  6206. /* set MSI reconfigure capability */
  6207. if (bp->common.int_block == INT_BLOCK_HC) {
  6208. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6209. val = REG_RD(bp, addr);
  6210. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6211. REG_WR(bp, addr, val);
  6212. }
  6213. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6214. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6215. ilt = BP_ILT(bp);
  6216. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6217. if (IS_SRIOV(bp))
  6218. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6219. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6220. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6221. * those of the VFs, so start line should be reset
  6222. */
  6223. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6224. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6225. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6226. ilt->lines[cdu_ilt_start + i].page_mapping =
  6227. bp->context[i].cxt_mapping;
  6228. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6229. }
  6230. bnx2x_ilt_init_op(bp, INITOP_SET);
  6231. if (!CONFIGURE_NIC_MODE(bp)) {
  6232. bnx2x_init_searcher(bp);
  6233. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6234. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6235. } else {
  6236. /* Set NIC mode */
  6237. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6238. DP(NETIF_MSG_IFUP, "NIC MODE configrued\n");
  6239. }
  6240. if (!CHIP_IS_E1x(bp)) {
  6241. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6242. /* Turn on a single ISR mode in IGU if driver is going to use
  6243. * INT#x or MSI
  6244. */
  6245. if (!(bp->flags & USING_MSIX_FLAG))
  6246. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6247. /*
  6248. * Timers workaround bug: function init part.
  6249. * Need to wait 20msec after initializing ILT,
  6250. * needed to make sure there are no requests in
  6251. * one of the PXP internal queues with "old" ILT addresses
  6252. */
  6253. msleep(20);
  6254. /*
  6255. * Master enable - Due to WB DMAE writes performed before this
  6256. * register is re-initialized as part of the regular function
  6257. * init
  6258. */
  6259. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6260. /* Enable the function in IGU */
  6261. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6262. }
  6263. bp->dmae_ready = 1;
  6264. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6265. if (!CHIP_IS_E1x(bp))
  6266. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  6267. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6268. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6269. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6270. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6271. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6272. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6273. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6274. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6275. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6276. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6277. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6278. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6279. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6280. if (!CHIP_IS_E1x(bp))
  6281. REG_WR(bp, QM_REG_PF_EN, 1);
  6282. if (!CHIP_IS_E1x(bp)) {
  6283. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6284. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6285. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6286. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6287. }
  6288. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6289. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6290. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6291. bnx2x_iov_init_dq(bp);
  6292. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6293. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6294. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6295. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6296. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6297. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6298. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6299. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6300. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6301. if (!CHIP_IS_E1x(bp))
  6302. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6303. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6304. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6305. if (!CHIP_IS_E1x(bp))
  6306. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6307. if (IS_MF(bp)) {
  6308. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  6309. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  6310. }
  6311. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6312. /* HC init per function */
  6313. if (bp->common.int_block == INT_BLOCK_HC) {
  6314. if (CHIP_IS_E1H(bp)) {
  6315. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6316. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6317. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6318. }
  6319. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6320. } else {
  6321. int num_segs, sb_idx, prod_offset;
  6322. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6323. if (!CHIP_IS_E1x(bp)) {
  6324. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6325. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6326. }
  6327. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6328. if (!CHIP_IS_E1x(bp)) {
  6329. int dsb_idx = 0;
  6330. /**
  6331. * Producer memory:
  6332. * E2 mode: address 0-135 match to the mapping memory;
  6333. * 136 - PF0 default prod; 137 - PF1 default prod;
  6334. * 138 - PF2 default prod; 139 - PF3 default prod;
  6335. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6336. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6337. * 144-147 reserved.
  6338. *
  6339. * E1.5 mode - In backward compatible mode;
  6340. * for non default SB; each even line in the memory
  6341. * holds the U producer and each odd line hold
  6342. * the C producer. The first 128 producers are for
  6343. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6344. * producers are for the DSB for each PF.
  6345. * Each PF has five segments: (the order inside each
  6346. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6347. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6348. * 144-147 attn prods;
  6349. */
  6350. /* non-default-status-blocks */
  6351. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6352. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6353. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6354. prod_offset = (bp->igu_base_sb + sb_idx) *
  6355. num_segs;
  6356. for (i = 0; i < num_segs; i++) {
  6357. addr = IGU_REG_PROD_CONS_MEMORY +
  6358. (prod_offset + i) * 4;
  6359. REG_WR(bp, addr, 0);
  6360. }
  6361. /* send consumer update with value 0 */
  6362. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6363. USTORM_ID, 0, IGU_INT_NOP, 1);
  6364. bnx2x_igu_clear_sb(bp,
  6365. bp->igu_base_sb + sb_idx);
  6366. }
  6367. /* default-status-blocks */
  6368. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6369. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6370. if (CHIP_MODE_IS_4_PORT(bp))
  6371. dsb_idx = BP_FUNC(bp);
  6372. else
  6373. dsb_idx = BP_VN(bp);
  6374. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6375. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6376. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6377. /*
  6378. * igu prods come in chunks of E1HVN_MAX (4) -
  6379. * does not matters what is the current chip mode
  6380. */
  6381. for (i = 0; i < (num_segs * E1HVN_MAX);
  6382. i += E1HVN_MAX) {
  6383. addr = IGU_REG_PROD_CONS_MEMORY +
  6384. (prod_offset + i)*4;
  6385. REG_WR(bp, addr, 0);
  6386. }
  6387. /* send consumer update with 0 */
  6388. if (CHIP_INT_MODE_IS_BC(bp)) {
  6389. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6390. USTORM_ID, 0, IGU_INT_NOP, 1);
  6391. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6392. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6393. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6394. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6395. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6396. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6397. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6398. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6399. } else {
  6400. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6401. USTORM_ID, 0, IGU_INT_NOP, 1);
  6402. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6403. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6404. }
  6405. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6406. /* !!! these should become driver const once
  6407. rf-tool supports split-68 const */
  6408. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6409. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6410. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6411. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6412. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6413. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6414. }
  6415. }
  6416. /* Reset PCIE errors for debug */
  6417. REG_WR(bp, 0x2114, 0xffffffff);
  6418. REG_WR(bp, 0x2120, 0xffffffff);
  6419. if (CHIP_IS_E1x(bp)) {
  6420. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6421. main_mem_base = HC_REG_MAIN_MEMORY +
  6422. BP_PORT(bp) * (main_mem_size * 4);
  6423. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6424. main_mem_width = 8;
  6425. val = REG_RD(bp, main_mem_prty_clr);
  6426. if (val)
  6427. DP(NETIF_MSG_HW,
  6428. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6429. val);
  6430. /* Clear "false" parity errors in MSI-X table */
  6431. for (i = main_mem_base;
  6432. i < main_mem_base + main_mem_size * 4;
  6433. i += main_mem_width) {
  6434. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6435. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6436. i, main_mem_width / 4);
  6437. }
  6438. /* Clear HC parity attention */
  6439. REG_RD(bp, main_mem_prty_clr);
  6440. }
  6441. #ifdef BNX2X_STOP_ON_ERROR
  6442. /* Enable STORMs SP logging */
  6443. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6444. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6445. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6446. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6447. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6448. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6449. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6450. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6451. #endif
  6452. bnx2x_phy_probe(&bp->link_params);
  6453. return 0;
  6454. }
  6455. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6456. {
  6457. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6458. if (!CHIP_IS_E1x(bp))
  6459. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6460. sizeof(struct host_hc_status_block_e2));
  6461. else
  6462. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6463. sizeof(struct host_hc_status_block_e1x));
  6464. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6465. }
  6466. void bnx2x_free_mem(struct bnx2x *bp)
  6467. {
  6468. int i;
  6469. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6470. sizeof(struct host_sp_status_block));
  6471. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6472. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6473. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6474. sizeof(struct bnx2x_slowpath));
  6475. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6476. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6477. bp->context[i].size);
  6478. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6479. BNX2X_FREE(bp->ilt->lines);
  6480. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6481. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6482. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6483. bnx2x_iov_free_mem(bp);
  6484. }
  6485. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6486. {
  6487. if (!CHIP_IS_E1x(bp))
  6488. /* size = the status block + ramrod buffers */
  6489. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  6490. sizeof(struct host_hc_status_block_e2));
  6491. else
  6492. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
  6493. &bp->cnic_sb_mapping,
  6494. sizeof(struct
  6495. host_hc_status_block_e1x));
  6496. if (CONFIGURE_NIC_MODE(bp))
  6497. /* allocate searcher T2 table, as it wan't allocated before */
  6498. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6499. /* write address to which L5 should insert its values */
  6500. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6501. &bp->slowpath->drv_info_to_mcp;
  6502. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6503. goto alloc_mem_err;
  6504. return 0;
  6505. alloc_mem_err:
  6506. bnx2x_free_mem_cnic(bp);
  6507. BNX2X_ERR("Can't allocate memory\n");
  6508. return -ENOMEM;
  6509. }
  6510. int bnx2x_alloc_mem(struct bnx2x *bp)
  6511. {
  6512. int i, allocated, context_size;
  6513. if (!CONFIGURE_NIC_MODE(bp))
  6514. /* allocate searcher T2 table */
  6515. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6516. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  6517. sizeof(struct host_sp_status_block));
  6518. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  6519. sizeof(struct bnx2x_slowpath));
  6520. /* Allocate memory for CDU context:
  6521. * This memory is allocated separately and not in the generic ILT
  6522. * functions because CDU differs in few aspects:
  6523. * 1. There are multiple entities allocating memory for context -
  6524. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6525. * its own ILT lines.
  6526. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6527. * for the other ILT clients), to be efficient we want to support
  6528. * allocation of sub-page-size in the last entry.
  6529. * 3. Context pointers are used by the driver to pass to FW / update
  6530. * the context (for the other ILT clients the pointers are used just to
  6531. * free the memory during unload).
  6532. */
  6533. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6534. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6535. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6536. (context_size - allocated));
  6537. BNX2X_PCI_ALLOC(bp->context[i].vcxt,
  6538. &bp->context[i].cxt_mapping,
  6539. bp->context[i].size);
  6540. allocated += bp->context[i].size;
  6541. }
  6542. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  6543. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6544. goto alloc_mem_err;
  6545. if (bnx2x_iov_alloc_mem(bp))
  6546. goto alloc_mem_err;
  6547. /* Slow path ring */
  6548. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  6549. /* EQ */
  6550. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  6551. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6552. return 0;
  6553. alloc_mem_err:
  6554. bnx2x_free_mem(bp);
  6555. BNX2X_ERR("Can't allocate memory\n");
  6556. return -ENOMEM;
  6557. }
  6558. /*
  6559. * Init service functions
  6560. */
  6561. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6562. struct bnx2x_vlan_mac_obj *obj, bool set,
  6563. int mac_type, unsigned long *ramrod_flags)
  6564. {
  6565. int rc;
  6566. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6567. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6568. /* Fill general parameters */
  6569. ramrod_param.vlan_mac_obj = obj;
  6570. ramrod_param.ramrod_flags = *ramrod_flags;
  6571. /* Fill a user request section if needed */
  6572. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6573. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6574. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6575. /* Set the command: ADD or DEL */
  6576. if (set)
  6577. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6578. else
  6579. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6580. }
  6581. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6582. if (rc == -EEXIST) {
  6583. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  6584. /* do not treat adding same MAC as error */
  6585. rc = 0;
  6586. } else if (rc < 0)
  6587. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6588. return rc;
  6589. }
  6590. int bnx2x_del_all_macs(struct bnx2x *bp,
  6591. struct bnx2x_vlan_mac_obj *mac_obj,
  6592. int mac_type, bool wait_for_comp)
  6593. {
  6594. int rc;
  6595. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6596. /* Wait for completion of requested */
  6597. if (wait_for_comp)
  6598. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6599. /* Set the mac type of addresses we want to clear */
  6600. __set_bit(mac_type, &vlan_mac_flags);
  6601. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6602. if (rc < 0)
  6603. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6604. return rc;
  6605. }
  6606. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6607. {
  6608. unsigned long ramrod_flags = 0;
  6609. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6610. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6611. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6612. "Ignoring Zero MAC for STORAGE SD mode\n");
  6613. return 0;
  6614. }
  6615. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6616. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6617. /* Eth MAC is set on RSS leading client (fp[0]) */
  6618. return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->sp_objs->mac_obj,
  6619. set, BNX2X_ETH_MAC, &ramrod_flags);
  6620. }
  6621. int bnx2x_setup_leading(struct bnx2x *bp)
  6622. {
  6623. return bnx2x_setup_queue(bp, &bp->fp[0], 1);
  6624. }
  6625. /**
  6626. * bnx2x_set_int_mode - configure interrupt mode
  6627. *
  6628. * @bp: driver handle
  6629. *
  6630. * In case of MSI-X it will also try to enable MSI-X.
  6631. */
  6632. int bnx2x_set_int_mode(struct bnx2x *bp)
  6633. {
  6634. int rc = 0;
  6635. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX)
  6636. return -EINVAL;
  6637. switch (int_mode) {
  6638. case BNX2X_INT_MODE_MSIX:
  6639. /* attempt to enable msix */
  6640. rc = bnx2x_enable_msix(bp);
  6641. /* msix attained */
  6642. if (!rc)
  6643. return 0;
  6644. /* vfs use only msix */
  6645. if (rc && IS_VF(bp))
  6646. return rc;
  6647. /* failed to enable multiple MSI-X */
  6648. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  6649. bp->num_queues,
  6650. 1 + bp->num_cnic_queues);
  6651. /* falling through... */
  6652. case BNX2X_INT_MODE_MSI:
  6653. bnx2x_enable_msi(bp);
  6654. /* falling through... */
  6655. case BNX2X_INT_MODE_INTX:
  6656. bp->num_ethernet_queues = 1;
  6657. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  6658. BNX2X_DEV_INFO("set number of queues to 1\n");
  6659. break;
  6660. default:
  6661. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  6662. return -EINVAL;
  6663. }
  6664. return 0;
  6665. }
  6666. /* must be called prior to any HW initializations */
  6667. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  6668. {
  6669. if (IS_SRIOV(bp))
  6670. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  6671. return L2_ILT_LINES(bp);
  6672. }
  6673. void bnx2x_ilt_set_info(struct bnx2x *bp)
  6674. {
  6675. struct ilt_client_info *ilt_client;
  6676. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6677. u16 line = 0;
  6678. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  6679. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  6680. /* CDU */
  6681. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  6682. ilt_client->client_num = ILT_CLIENT_CDU;
  6683. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  6684. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  6685. ilt_client->start = line;
  6686. line += bnx2x_cid_ilt_lines(bp);
  6687. if (CNIC_SUPPORT(bp))
  6688. line += CNIC_ILT_LINES;
  6689. ilt_client->end = line - 1;
  6690. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6691. ilt_client->start,
  6692. ilt_client->end,
  6693. ilt_client->page_size,
  6694. ilt_client->flags,
  6695. ilog2(ilt_client->page_size >> 12));
  6696. /* QM */
  6697. if (QM_INIT(bp->qm_cid_count)) {
  6698. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  6699. ilt_client->client_num = ILT_CLIENT_QM;
  6700. ilt_client->page_size = QM_ILT_PAGE_SZ;
  6701. ilt_client->flags = 0;
  6702. ilt_client->start = line;
  6703. /* 4 bytes for each cid */
  6704. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  6705. QM_ILT_PAGE_SZ);
  6706. ilt_client->end = line - 1;
  6707. DP(NETIF_MSG_IFUP,
  6708. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6709. ilt_client->start,
  6710. ilt_client->end,
  6711. ilt_client->page_size,
  6712. ilt_client->flags,
  6713. ilog2(ilt_client->page_size >> 12));
  6714. }
  6715. if (CNIC_SUPPORT(bp)) {
  6716. /* SRC */
  6717. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  6718. ilt_client->client_num = ILT_CLIENT_SRC;
  6719. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  6720. ilt_client->flags = 0;
  6721. ilt_client->start = line;
  6722. line += SRC_ILT_LINES;
  6723. ilt_client->end = line - 1;
  6724. DP(NETIF_MSG_IFUP,
  6725. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6726. ilt_client->start,
  6727. ilt_client->end,
  6728. ilt_client->page_size,
  6729. ilt_client->flags,
  6730. ilog2(ilt_client->page_size >> 12));
  6731. /* TM */
  6732. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  6733. ilt_client->client_num = ILT_CLIENT_TM;
  6734. ilt_client->page_size = TM_ILT_PAGE_SZ;
  6735. ilt_client->flags = 0;
  6736. ilt_client->start = line;
  6737. line += TM_ILT_LINES;
  6738. ilt_client->end = line - 1;
  6739. DP(NETIF_MSG_IFUP,
  6740. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6741. ilt_client->start,
  6742. ilt_client->end,
  6743. ilt_client->page_size,
  6744. ilt_client->flags,
  6745. ilog2(ilt_client->page_size >> 12));
  6746. }
  6747. BUG_ON(line > ILT_MAX_LINES);
  6748. }
  6749. /**
  6750. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6751. *
  6752. * @bp: driver handle
  6753. * @fp: pointer to fastpath
  6754. * @init_params: pointer to parameters structure
  6755. *
  6756. * parameters configured:
  6757. * - HC configuration
  6758. * - Queue's CDU context
  6759. */
  6760. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  6761. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  6762. {
  6763. u8 cos;
  6764. int cxt_index, cxt_offset;
  6765. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  6766. if (!IS_FCOE_FP(fp)) {
  6767. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  6768. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  6769. /* If HC is supporterd, enable host coalescing in the transition
  6770. * to INIT state.
  6771. */
  6772. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  6773. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  6774. /* HC rate */
  6775. init_params->rx.hc_rate = bp->rx_ticks ?
  6776. (1000000 / bp->rx_ticks) : 0;
  6777. init_params->tx.hc_rate = bp->tx_ticks ?
  6778. (1000000 / bp->tx_ticks) : 0;
  6779. /* FW SB ID */
  6780. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  6781. fp->fw_sb_id;
  6782. /*
  6783. * CQ index among the SB indices: FCoE clients uses the default
  6784. * SB, therefore it's different.
  6785. */
  6786. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  6787. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  6788. }
  6789. /* set maximum number of COSs supported by this queue */
  6790. init_params->max_cos = fp->max_cos;
  6791. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  6792. fp->index, init_params->max_cos);
  6793. /* set the context pointers queue object */
  6794. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  6795. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  6796. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  6797. ILT_PAGE_CIDS);
  6798. init_params->cxts[cos] =
  6799. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  6800. }
  6801. }
  6802. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6803. struct bnx2x_queue_state_params *q_params,
  6804. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  6805. int tx_index, bool leading)
  6806. {
  6807. memset(tx_only_params, 0, sizeof(*tx_only_params));
  6808. /* Set the command */
  6809. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  6810. /* Set tx-only QUEUE flags: don't zero statistics */
  6811. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  6812. /* choose the index of the cid to send the slow path on */
  6813. tx_only_params->cid_index = tx_index;
  6814. /* Set general TX_ONLY_SETUP parameters */
  6815. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  6816. /* Set Tx TX_ONLY_SETUP parameters */
  6817. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  6818. DP(NETIF_MSG_IFUP,
  6819. "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",
  6820. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  6821. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  6822. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  6823. /* send the ramrod */
  6824. return bnx2x_queue_state_change(bp, q_params);
  6825. }
  6826. /**
  6827. * bnx2x_setup_queue - setup queue
  6828. *
  6829. * @bp: driver handle
  6830. * @fp: pointer to fastpath
  6831. * @leading: is leading
  6832. *
  6833. * This function performs 2 steps in a Queue state machine
  6834. * actually: 1) RESET->INIT 2) INIT->SETUP
  6835. */
  6836. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6837. bool leading)
  6838. {
  6839. struct bnx2x_queue_state_params q_params = {NULL};
  6840. struct bnx2x_queue_setup_params *setup_params =
  6841. &q_params.params.setup;
  6842. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  6843. &q_params.params.tx_only;
  6844. int rc;
  6845. u8 tx_index;
  6846. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  6847. /* reset IGU state skip FCoE L2 queue */
  6848. if (!IS_FCOE_FP(fp))
  6849. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  6850. IGU_INT_ENABLE, 0);
  6851. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6852. /* We want to wait for completion in this context */
  6853. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6854. /* Prepare the INIT parameters */
  6855. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  6856. /* Set the command */
  6857. q_params.cmd = BNX2X_Q_CMD_INIT;
  6858. /* Change the state to INIT */
  6859. rc = bnx2x_queue_state_change(bp, &q_params);
  6860. if (rc) {
  6861. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  6862. return rc;
  6863. }
  6864. DP(NETIF_MSG_IFUP, "init complete\n");
  6865. /* Now move the Queue to the SETUP state... */
  6866. memset(setup_params, 0, sizeof(*setup_params));
  6867. /* Set QUEUE flags */
  6868. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  6869. /* Set general SETUP parameters */
  6870. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  6871. FIRST_TX_COS_INDEX);
  6872. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  6873. &setup_params->rxq_params);
  6874. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  6875. FIRST_TX_COS_INDEX);
  6876. /* Set the command */
  6877. q_params.cmd = BNX2X_Q_CMD_SETUP;
  6878. if (IS_FCOE_FP(fp))
  6879. bp->fcoe_init = true;
  6880. /* Change the state to SETUP */
  6881. rc = bnx2x_queue_state_change(bp, &q_params);
  6882. if (rc) {
  6883. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  6884. return rc;
  6885. }
  6886. /* loop through the relevant tx-only indices */
  6887. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6888. tx_index < fp->max_cos;
  6889. tx_index++) {
  6890. /* prepare and send tx-only ramrod*/
  6891. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  6892. tx_only_params, tx_index, leading);
  6893. if (rc) {
  6894. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  6895. fp->index, tx_index);
  6896. return rc;
  6897. }
  6898. }
  6899. return rc;
  6900. }
  6901. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  6902. {
  6903. struct bnx2x_fastpath *fp = &bp->fp[index];
  6904. struct bnx2x_fp_txdata *txdata;
  6905. struct bnx2x_queue_state_params q_params = {NULL};
  6906. int rc, tx_index;
  6907. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  6908. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6909. /* We want to wait for completion in this context */
  6910. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6911. /* close tx-only connections */
  6912. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6913. tx_index < fp->max_cos;
  6914. tx_index++){
  6915. /* ascertain this is a normal queue*/
  6916. txdata = fp->txdata_ptr[tx_index];
  6917. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  6918. txdata->txq_index);
  6919. /* send halt terminate on tx-only connection */
  6920. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6921. memset(&q_params.params.terminate, 0,
  6922. sizeof(q_params.params.terminate));
  6923. q_params.params.terminate.cid_index = tx_index;
  6924. rc = bnx2x_queue_state_change(bp, &q_params);
  6925. if (rc)
  6926. return rc;
  6927. /* send halt terminate on tx-only connection */
  6928. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6929. memset(&q_params.params.cfc_del, 0,
  6930. sizeof(q_params.params.cfc_del));
  6931. q_params.params.cfc_del.cid_index = tx_index;
  6932. rc = bnx2x_queue_state_change(bp, &q_params);
  6933. if (rc)
  6934. return rc;
  6935. }
  6936. /* Stop the primary connection: */
  6937. /* ...halt the connection */
  6938. q_params.cmd = BNX2X_Q_CMD_HALT;
  6939. rc = bnx2x_queue_state_change(bp, &q_params);
  6940. if (rc)
  6941. return rc;
  6942. /* ...terminate the connection */
  6943. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6944. memset(&q_params.params.terminate, 0,
  6945. sizeof(q_params.params.terminate));
  6946. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  6947. rc = bnx2x_queue_state_change(bp, &q_params);
  6948. if (rc)
  6949. return rc;
  6950. /* ...delete cfc entry */
  6951. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6952. memset(&q_params.params.cfc_del, 0,
  6953. sizeof(q_params.params.cfc_del));
  6954. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  6955. return bnx2x_queue_state_change(bp, &q_params);
  6956. }
  6957. static void bnx2x_reset_func(struct bnx2x *bp)
  6958. {
  6959. int port = BP_PORT(bp);
  6960. int func = BP_FUNC(bp);
  6961. int i;
  6962. /* Disable the function in the FW */
  6963. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  6964. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  6965. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  6966. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  6967. /* FP SBs */
  6968. for_each_eth_queue(bp, i) {
  6969. struct bnx2x_fastpath *fp = &bp->fp[i];
  6970. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6971. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  6972. SB_DISABLED);
  6973. }
  6974. if (CNIC_LOADED(bp))
  6975. /* CNIC SB */
  6976. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6977. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  6978. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  6979. /* SP SB */
  6980. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6981. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  6982. SB_DISABLED);
  6983. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  6984. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  6985. 0);
  6986. /* Configure IGU */
  6987. if (bp->common.int_block == INT_BLOCK_HC) {
  6988. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6989. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6990. } else {
  6991. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6992. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6993. }
  6994. if (CNIC_LOADED(bp)) {
  6995. /* Disable Timer scan */
  6996. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  6997. /*
  6998. * Wait for at least 10ms and up to 2 second for the timers
  6999. * scan to complete
  7000. */
  7001. for (i = 0; i < 200; i++) {
  7002. msleep(10);
  7003. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  7004. break;
  7005. }
  7006. }
  7007. /* Clear ILT */
  7008. bnx2x_clear_func_ilt(bp, func);
  7009. /* Timers workaround bug for E2: if this is vnic-3,
  7010. * we need to set the entire ilt range for this timers.
  7011. */
  7012. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  7013. struct ilt_client_info ilt_cli;
  7014. /* use dummy TM client */
  7015. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  7016. ilt_cli.start = 0;
  7017. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  7018. ilt_cli.client_num = ILT_CLIENT_TM;
  7019. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  7020. }
  7021. /* this assumes that reset_port() called before reset_func()*/
  7022. if (!CHIP_IS_E1x(bp))
  7023. bnx2x_pf_disable(bp);
  7024. bp->dmae_ready = 0;
  7025. }
  7026. static void bnx2x_reset_port(struct bnx2x *bp)
  7027. {
  7028. int port = BP_PORT(bp);
  7029. u32 val;
  7030. /* Reset physical Link */
  7031. bnx2x__link_reset(bp);
  7032. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  7033. /* Do not rcv packets to BRB */
  7034. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  7035. /* Do not direct rcv packets that are not for MCP to the BRB */
  7036. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7037. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7038. /* Configure AEU */
  7039. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  7040. msleep(100);
  7041. /* Check for BRB port occupancy */
  7042. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7043. if (val)
  7044. DP(NETIF_MSG_IFDOWN,
  7045. "BRB1 is not empty %d blocks are occupied\n", val);
  7046. /* TODO: Close Doorbell port? */
  7047. }
  7048. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7049. {
  7050. struct bnx2x_func_state_params func_params = {NULL};
  7051. /* Prepare parameters for function state transitions */
  7052. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7053. func_params.f_obj = &bp->func_obj;
  7054. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7055. func_params.params.hw_init.load_phase = load_code;
  7056. return bnx2x_func_state_change(bp, &func_params);
  7057. }
  7058. static int bnx2x_func_stop(struct bnx2x *bp)
  7059. {
  7060. struct bnx2x_func_state_params func_params = {NULL};
  7061. int rc;
  7062. /* Prepare parameters for function state transitions */
  7063. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7064. func_params.f_obj = &bp->func_obj;
  7065. func_params.cmd = BNX2X_F_CMD_STOP;
  7066. /*
  7067. * Try to stop the function the 'good way'. If fails (in case
  7068. * of a parity error during bnx2x_chip_cleanup()) and we are
  7069. * not in a debug mode, perform a state transaction in order to
  7070. * enable further HW_RESET transaction.
  7071. */
  7072. rc = bnx2x_func_state_change(bp, &func_params);
  7073. if (rc) {
  7074. #ifdef BNX2X_STOP_ON_ERROR
  7075. return rc;
  7076. #else
  7077. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7078. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7079. return bnx2x_func_state_change(bp, &func_params);
  7080. #endif
  7081. }
  7082. return 0;
  7083. }
  7084. /**
  7085. * bnx2x_send_unload_req - request unload mode from the MCP.
  7086. *
  7087. * @bp: driver handle
  7088. * @unload_mode: requested function's unload mode
  7089. *
  7090. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7091. */
  7092. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7093. {
  7094. u32 reset_code = 0;
  7095. int port = BP_PORT(bp);
  7096. /* Select the UNLOAD request mode */
  7097. if (unload_mode == UNLOAD_NORMAL)
  7098. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7099. else if (bp->flags & NO_WOL_FLAG)
  7100. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7101. else if (bp->wol) {
  7102. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7103. u8 *mac_addr = bp->dev->dev_addr;
  7104. u32 val;
  7105. u16 pmc;
  7106. /* The mac address is written to entries 1-4 to
  7107. * preserve entry 0 which is used by the PMF
  7108. */
  7109. u8 entry = (BP_VN(bp) + 1)*8;
  7110. val = (mac_addr[0] << 8) | mac_addr[1];
  7111. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7112. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7113. (mac_addr[4] << 8) | mac_addr[5];
  7114. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7115. /* Enable the PME and clear the status */
  7116. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
  7117. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7118. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
  7119. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7120. } else
  7121. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7122. /* Send the request to the MCP */
  7123. if (!BP_NOMCP(bp))
  7124. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7125. else {
  7126. int path = BP_PATH(bp);
  7127. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7128. path, load_count[path][0], load_count[path][1],
  7129. load_count[path][2]);
  7130. load_count[path][0]--;
  7131. load_count[path][1 + port]--;
  7132. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7133. path, load_count[path][0], load_count[path][1],
  7134. load_count[path][2]);
  7135. if (load_count[path][0] == 0)
  7136. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7137. else if (load_count[path][1 + port] == 0)
  7138. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7139. else
  7140. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7141. }
  7142. return reset_code;
  7143. }
  7144. /**
  7145. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7146. *
  7147. * @bp: driver handle
  7148. * @keep_link: true iff link should be kept up
  7149. */
  7150. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7151. {
  7152. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7153. /* Report UNLOAD_DONE to MCP */
  7154. if (!BP_NOMCP(bp))
  7155. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7156. }
  7157. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7158. {
  7159. int tout = 50;
  7160. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7161. if (!bp->port.pmf)
  7162. return 0;
  7163. /*
  7164. * (assumption: No Attention from MCP at this stage)
  7165. * PMF probably in the middle of TXdisable/enable transaction
  7166. * 1. Sync IRS for default SB
  7167. * 2. Sync SP queue - this guarantes us that attention handling started
  7168. * 3. Wait, that TXdisable/enable transaction completes
  7169. *
  7170. * 1+2 guranty that if DCBx attention was scheduled it already changed
  7171. * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
  7172. * received complettion for the transaction the state is TX_STOPPED.
  7173. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7174. * transaction.
  7175. */
  7176. /* make sure default SB ISR is done */
  7177. if (msix)
  7178. synchronize_irq(bp->msix_table[0].vector);
  7179. else
  7180. synchronize_irq(bp->pdev->irq);
  7181. flush_workqueue(bnx2x_wq);
  7182. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7183. BNX2X_F_STATE_STARTED && tout--)
  7184. msleep(20);
  7185. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7186. BNX2X_F_STATE_STARTED) {
  7187. #ifdef BNX2X_STOP_ON_ERROR
  7188. BNX2X_ERR("Wrong function state\n");
  7189. return -EBUSY;
  7190. #else
  7191. /*
  7192. * Failed to complete the transaction in a "good way"
  7193. * Force both transactions with CLR bit
  7194. */
  7195. struct bnx2x_func_state_params func_params = {NULL};
  7196. DP(NETIF_MSG_IFDOWN,
  7197. "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  7198. func_params.f_obj = &bp->func_obj;
  7199. __set_bit(RAMROD_DRV_CLR_ONLY,
  7200. &func_params.ramrod_flags);
  7201. /* STARTED-->TX_ST0PPED */
  7202. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7203. bnx2x_func_state_change(bp, &func_params);
  7204. /* TX_ST0PPED-->STARTED */
  7205. func_params.cmd = BNX2X_F_CMD_TX_START;
  7206. return bnx2x_func_state_change(bp, &func_params);
  7207. #endif
  7208. }
  7209. return 0;
  7210. }
  7211. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7212. {
  7213. int port = BP_PORT(bp);
  7214. int i, rc = 0;
  7215. u8 cos;
  7216. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7217. u32 reset_code;
  7218. /* Wait until tx fastpath tasks complete */
  7219. for_each_tx_queue(bp, i) {
  7220. struct bnx2x_fastpath *fp = &bp->fp[i];
  7221. for_each_cos_in_tx_queue(fp, cos)
  7222. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7223. #ifdef BNX2X_STOP_ON_ERROR
  7224. if (rc)
  7225. return;
  7226. #endif
  7227. }
  7228. /* Give HW time to discard old tx messages */
  7229. usleep_range(1000, 2000);
  7230. /* Clean all ETH MACs */
  7231. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7232. false);
  7233. if (rc < 0)
  7234. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7235. /* Clean up UC list */
  7236. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7237. true);
  7238. if (rc < 0)
  7239. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7240. rc);
  7241. /* Disable LLH */
  7242. if (!CHIP_IS_E1(bp))
  7243. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7244. /* Set "drop all" (stop Rx).
  7245. * We need to take a netif_addr_lock() here in order to prevent
  7246. * a race between the completion code and this code.
  7247. */
  7248. netif_addr_lock_bh(bp->dev);
  7249. /* Schedule the rx_mode command */
  7250. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7251. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7252. else
  7253. bnx2x_set_storm_rx_mode(bp);
  7254. /* Cleanup multicast configuration */
  7255. rparam.mcast_obj = &bp->mcast_obj;
  7256. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7257. if (rc < 0)
  7258. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7259. netif_addr_unlock_bh(bp->dev);
  7260. bnx2x_iov_chip_cleanup(bp);
  7261. /*
  7262. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7263. * this function should perform FUNC, PORT or COMMON HW
  7264. * reset.
  7265. */
  7266. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7267. /*
  7268. * (assumption: No Attention from MCP at this stage)
  7269. * PMF probably in the middle of TXdisable/enable transaction
  7270. */
  7271. rc = bnx2x_func_wait_started(bp);
  7272. if (rc) {
  7273. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7274. #ifdef BNX2X_STOP_ON_ERROR
  7275. return;
  7276. #endif
  7277. }
  7278. /* Close multi and leading connections
  7279. * Completions for ramrods are collected in a synchronous way
  7280. */
  7281. for_each_eth_queue(bp, i)
  7282. if (bnx2x_stop_queue(bp, i))
  7283. #ifdef BNX2X_STOP_ON_ERROR
  7284. return;
  7285. #else
  7286. goto unload_error;
  7287. #endif
  7288. if (CNIC_LOADED(bp)) {
  7289. for_each_cnic_queue(bp, i)
  7290. if (bnx2x_stop_queue(bp, i))
  7291. #ifdef BNX2X_STOP_ON_ERROR
  7292. return;
  7293. #else
  7294. goto unload_error;
  7295. #endif
  7296. }
  7297. /* If SP settings didn't get completed so far - something
  7298. * very wrong has happen.
  7299. */
  7300. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7301. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7302. #ifndef BNX2X_STOP_ON_ERROR
  7303. unload_error:
  7304. #endif
  7305. rc = bnx2x_func_stop(bp);
  7306. if (rc) {
  7307. BNX2X_ERR("Function stop failed!\n");
  7308. #ifdef BNX2X_STOP_ON_ERROR
  7309. return;
  7310. #endif
  7311. }
  7312. /* Disable HW interrupts, NAPI */
  7313. bnx2x_netif_stop(bp, 1);
  7314. /* Delete all NAPI objects */
  7315. bnx2x_del_all_napi(bp);
  7316. if (CNIC_LOADED(bp))
  7317. bnx2x_del_all_napi_cnic(bp);
  7318. /* Release IRQs */
  7319. bnx2x_free_irq(bp);
  7320. /* Reset the chip */
  7321. rc = bnx2x_reset_hw(bp, reset_code);
  7322. if (rc)
  7323. BNX2X_ERR("HW_RESET failed\n");
  7324. /* Report UNLOAD_DONE to MCP */
  7325. bnx2x_send_unload_done(bp, keep_link);
  7326. }
  7327. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7328. {
  7329. u32 val;
  7330. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7331. if (CHIP_IS_E1(bp)) {
  7332. int port = BP_PORT(bp);
  7333. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7334. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7335. val = REG_RD(bp, addr);
  7336. val &= ~(0x300);
  7337. REG_WR(bp, addr, val);
  7338. } else {
  7339. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7340. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7341. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7342. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7343. }
  7344. }
  7345. /* Close gates #2, #3 and #4: */
  7346. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7347. {
  7348. u32 val;
  7349. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7350. if (!CHIP_IS_E1(bp)) {
  7351. /* #4 */
  7352. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7353. /* #2 */
  7354. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7355. }
  7356. /* #3 */
  7357. if (CHIP_IS_E1x(bp)) {
  7358. /* Prevent interrupts from HC on both ports */
  7359. val = REG_RD(bp, HC_REG_CONFIG_1);
  7360. REG_WR(bp, HC_REG_CONFIG_1,
  7361. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7362. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7363. val = REG_RD(bp, HC_REG_CONFIG_0);
  7364. REG_WR(bp, HC_REG_CONFIG_0,
  7365. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7366. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7367. } else {
  7368. /* Prevent incoming interrupts in IGU */
  7369. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7370. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7371. (!close) ?
  7372. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7373. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7374. }
  7375. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7376. close ? "closing" : "opening");
  7377. mmiowb();
  7378. }
  7379. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7380. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7381. {
  7382. /* Do some magic... */
  7383. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7384. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7385. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7386. }
  7387. /**
  7388. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7389. *
  7390. * @bp: driver handle
  7391. * @magic_val: old value of the `magic' bit.
  7392. */
  7393. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7394. {
  7395. /* Restore the `magic' bit value... */
  7396. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7397. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7398. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7399. }
  7400. /**
  7401. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7402. *
  7403. * @bp: driver handle
  7404. * @magic_val: old value of 'magic' bit.
  7405. *
  7406. * Takes care of CLP configurations.
  7407. */
  7408. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7409. {
  7410. u32 shmem;
  7411. u32 validity_offset;
  7412. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7413. /* Set `magic' bit in order to save MF config */
  7414. if (!CHIP_IS_E1(bp))
  7415. bnx2x_clp_reset_prep(bp, magic_val);
  7416. /* Get shmem offset */
  7417. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7418. validity_offset =
  7419. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7420. /* Clear validity map flags */
  7421. if (shmem > 0)
  7422. REG_WR(bp, shmem + validity_offset, 0);
  7423. }
  7424. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7425. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7426. /**
  7427. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7428. *
  7429. * @bp: driver handle
  7430. */
  7431. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7432. {
  7433. /* special handling for emulation and FPGA,
  7434. wait 10 times longer */
  7435. if (CHIP_REV_IS_SLOW(bp))
  7436. msleep(MCP_ONE_TIMEOUT*10);
  7437. else
  7438. msleep(MCP_ONE_TIMEOUT);
  7439. }
  7440. /*
  7441. * initializes bp->common.shmem_base and waits for validity signature to appear
  7442. */
  7443. static int bnx2x_init_shmem(struct bnx2x *bp)
  7444. {
  7445. int cnt = 0;
  7446. u32 val = 0;
  7447. do {
  7448. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7449. if (bp->common.shmem_base) {
  7450. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7451. if (val & SHR_MEM_VALIDITY_MB)
  7452. return 0;
  7453. }
  7454. bnx2x_mcp_wait_one(bp);
  7455. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7456. BNX2X_ERR("BAD MCP validity signature\n");
  7457. return -ENODEV;
  7458. }
  7459. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7460. {
  7461. int rc = bnx2x_init_shmem(bp);
  7462. /* Restore the `magic' bit value */
  7463. if (!CHIP_IS_E1(bp))
  7464. bnx2x_clp_reset_done(bp, magic_val);
  7465. return rc;
  7466. }
  7467. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7468. {
  7469. if (!CHIP_IS_E1(bp)) {
  7470. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7471. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7472. mmiowb();
  7473. }
  7474. }
  7475. /*
  7476. * Reset the whole chip except for:
  7477. * - PCIE core
  7478. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7479. * one reset bit)
  7480. * - IGU
  7481. * - MISC (including AEU)
  7482. * - GRC
  7483. * - RBCN, RBCP
  7484. */
  7485. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7486. {
  7487. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7488. u32 global_bits2, stay_reset2;
  7489. /*
  7490. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7491. * (per chip) blocks.
  7492. */
  7493. global_bits2 =
  7494. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7495. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7496. /* Don't reset the following blocks.
  7497. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  7498. * reset, as in 4 port device they might still be owned
  7499. * by the MCP (there is only one leader per path).
  7500. */
  7501. not_reset_mask1 =
  7502. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7503. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7504. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7505. not_reset_mask2 =
  7506. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7507. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7508. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7509. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7510. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7511. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7512. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7513. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7514. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7515. MISC_REGISTERS_RESET_REG_2_PGLC |
  7516. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7517. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7518. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7519. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7520. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7521. MISC_REGISTERS_RESET_REG_2_UMAC1;
  7522. /*
  7523. * Keep the following blocks in reset:
  7524. * - all xxMACs are handled by the bnx2x_link code.
  7525. */
  7526. stay_reset2 =
  7527. MISC_REGISTERS_RESET_REG_2_XMAC |
  7528. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7529. /* Full reset masks according to the chip */
  7530. reset_mask1 = 0xffffffff;
  7531. if (CHIP_IS_E1(bp))
  7532. reset_mask2 = 0xffff;
  7533. else if (CHIP_IS_E1H(bp))
  7534. reset_mask2 = 0x1ffff;
  7535. else if (CHIP_IS_E2(bp))
  7536. reset_mask2 = 0xfffff;
  7537. else /* CHIP_IS_E3 */
  7538. reset_mask2 = 0x3ffffff;
  7539. /* Don't reset global blocks unless we need to */
  7540. if (!global)
  7541. reset_mask2 &= ~global_bits2;
  7542. /*
  7543. * In case of attention in the QM, we need to reset PXP
  7544. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7545. * because otherwise QM reset would release 'close the gates' shortly
  7546. * before resetting the PXP, then the PSWRQ would send a write
  7547. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7548. * read the payload data from PSWWR, but PSWWR would not
  7549. * respond. The write queue in PGLUE would stuck, dmae commands
  7550. * would not return. Therefore it's important to reset the second
  7551. * reset register (containing the
  7552. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7553. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7554. * bit).
  7555. */
  7556. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7557. reset_mask2 & (~not_reset_mask2));
  7558. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7559. reset_mask1 & (~not_reset_mask1));
  7560. barrier();
  7561. mmiowb();
  7562. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7563. reset_mask2 & (~stay_reset2));
  7564. barrier();
  7565. mmiowb();
  7566. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7567. mmiowb();
  7568. }
  7569. /**
  7570. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7571. * It should get cleared in no more than 1s.
  7572. *
  7573. * @bp: driver handle
  7574. *
  7575. * It should get cleared in no more than 1s. Returns 0 if
  7576. * pending writes bit gets cleared.
  7577. */
  7578. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7579. {
  7580. u32 cnt = 1000;
  7581. u32 pend_bits = 0;
  7582. do {
  7583. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7584. if (pend_bits == 0)
  7585. break;
  7586. usleep_range(1000, 2000);
  7587. } while (cnt-- > 0);
  7588. if (cnt <= 0) {
  7589. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7590. pend_bits);
  7591. return -EBUSY;
  7592. }
  7593. return 0;
  7594. }
  7595. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7596. {
  7597. int cnt = 1000;
  7598. u32 val = 0;
  7599. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7600. u32 tags_63_32 = 0;
  7601. /* Empty the Tetris buffer, wait for 1s */
  7602. do {
  7603. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7604. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7605. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7606. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7607. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7608. if (CHIP_IS_E3(bp))
  7609. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  7610. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7611. ((port_is_idle_0 & 0x1) == 0x1) &&
  7612. ((port_is_idle_1 & 0x1) == 0x1) &&
  7613. (pgl_exp_rom2 == 0xffffffff) &&
  7614. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  7615. break;
  7616. usleep_range(1000, 2000);
  7617. } while (cnt-- > 0);
  7618. if (cnt <= 0) {
  7619. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7620. 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",
  7621. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7622. pgl_exp_rom2);
  7623. return -EAGAIN;
  7624. }
  7625. barrier();
  7626. /* Close gates #2, #3 and #4 */
  7627. bnx2x_set_234_gates(bp, true);
  7628. /* Poll for IGU VQs for 57712 and newer chips */
  7629. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  7630. return -EAGAIN;
  7631. /* TBD: Indicate that "process kill" is in progress to MCP */
  7632. /* Clear "unprepared" bit */
  7633. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  7634. barrier();
  7635. /* Make sure all is written to the chip before the reset */
  7636. mmiowb();
  7637. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  7638. * PSWHST, GRC and PSWRD Tetris buffer.
  7639. */
  7640. usleep_range(1000, 2000);
  7641. /* Prepare to chip reset: */
  7642. /* MCP */
  7643. if (global)
  7644. bnx2x_reset_mcp_prep(bp, &val);
  7645. /* PXP */
  7646. bnx2x_pxp_prep(bp);
  7647. barrier();
  7648. /* reset the chip */
  7649. bnx2x_process_kill_chip_reset(bp, global);
  7650. barrier();
  7651. /* Recover after reset: */
  7652. /* MCP */
  7653. if (global && bnx2x_reset_mcp_comp(bp, val))
  7654. return -EAGAIN;
  7655. /* TBD: Add resetting the NO_MCP mode DB here */
  7656. /* Open the gates #2, #3 and #4 */
  7657. bnx2x_set_234_gates(bp, false);
  7658. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  7659. * reset state, re-enable attentions. */
  7660. return 0;
  7661. }
  7662. static int bnx2x_leader_reset(struct bnx2x *bp)
  7663. {
  7664. int rc = 0;
  7665. bool global = bnx2x_reset_is_global(bp);
  7666. u32 load_code;
  7667. /* if not going to reset MCP - load "fake" driver to reset HW while
  7668. * driver is owner of the HW
  7669. */
  7670. if (!global && !BP_NOMCP(bp)) {
  7671. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  7672. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  7673. if (!load_code) {
  7674. BNX2X_ERR("MCP response failure, aborting\n");
  7675. rc = -EAGAIN;
  7676. goto exit_leader_reset;
  7677. }
  7678. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  7679. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  7680. BNX2X_ERR("MCP unexpected resp, aborting\n");
  7681. rc = -EAGAIN;
  7682. goto exit_leader_reset2;
  7683. }
  7684. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  7685. if (!load_code) {
  7686. BNX2X_ERR("MCP response failure, aborting\n");
  7687. rc = -EAGAIN;
  7688. goto exit_leader_reset2;
  7689. }
  7690. }
  7691. /* Try to recover after the failure */
  7692. if (bnx2x_process_kill(bp, global)) {
  7693. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  7694. BP_PATH(bp));
  7695. rc = -EAGAIN;
  7696. goto exit_leader_reset2;
  7697. }
  7698. /*
  7699. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  7700. * state.
  7701. */
  7702. bnx2x_set_reset_done(bp);
  7703. if (global)
  7704. bnx2x_clear_reset_global(bp);
  7705. exit_leader_reset2:
  7706. /* unload "fake driver" if it was loaded */
  7707. if (!global && !BP_NOMCP(bp)) {
  7708. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  7709. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7710. }
  7711. exit_leader_reset:
  7712. bp->is_leader = 0;
  7713. bnx2x_release_leader_lock(bp);
  7714. smp_mb();
  7715. return rc;
  7716. }
  7717. static void bnx2x_recovery_failed(struct bnx2x *bp)
  7718. {
  7719. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  7720. /* Disconnect this device */
  7721. netif_device_detach(bp->dev);
  7722. /*
  7723. * Block ifup for all function on this engine until "process kill"
  7724. * or power cycle.
  7725. */
  7726. bnx2x_set_reset_in_progress(bp);
  7727. /* Shut down the power */
  7728. bnx2x_set_power_state(bp, PCI_D3hot);
  7729. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  7730. smp_mb();
  7731. }
  7732. /*
  7733. * Assumption: runs under rtnl lock. This together with the fact
  7734. * that it's called only from bnx2x_sp_rtnl() ensure that it
  7735. * will never be called when netif_running(bp->dev) is false.
  7736. */
  7737. static void bnx2x_parity_recover(struct bnx2x *bp)
  7738. {
  7739. bool global = false;
  7740. u32 error_recovered, error_unrecovered;
  7741. bool is_parity;
  7742. DP(NETIF_MSG_HW, "Handling parity\n");
  7743. while (1) {
  7744. switch (bp->recovery_state) {
  7745. case BNX2X_RECOVERY_INIT:
  7746. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  7747. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  7748. WARN_ON(!is_parity);
  7749. /* Try to get a LEADER_LOCK HW lock */
  7750. if (bnx2x_trylock_leader_lock(bp)) {
  7751. bnx2x_set_reset_in_progress(bp);
  7752. /*
  7753. * Check if there is a global attention and if
  7754. * there was a global attention, set the global
  7755. * reset bit.
  7756. */
  7757. if (global)
  7758. bnx2x_set_reset_global(bp);
  7759. bp->is_leader = 1;
  7760. }
  7761. /* Stop the driver */
  7762. /* If interface has been removed - break */
  7763. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  7764. return;
  7765. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  7766. /* Ensure "is_leader", MCP command sequence and
  7767. * "recovery_state" update values are seen on other
  7768. * CPUs.
  7769. */
  7770. smp_mb();
  7771. break;
  7772. case BNX2X_RECOVERY_WAIT:
  7773. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  7774. if (bp->is_leader) {
  7775. int other_engine = BP_PATH(bp) ? 0 : 1;
  7776. bool other_load_status =
  7777. bnx2x_get_load_status(bp, other_engine);
  7778. bool load_status =
  7779. bnx2x_get_load_status(bp, BP_PATH(bp));
  7780. global = bnx2x_reset_is_global(bp);
  7781. /*
  7782. * In case of a parity in a global block, let
  7783. * the first leader that performs a
  7784. * leader_reset() reset the global blocks in
  7785. * order to clear global attentions. Otherwise
  7786. * the the gates will remain closed for that
  7787. * engine.
  7788. */
  7789. if (load_status ||
  7790. (global && other_load_status)) {
  7791. /* Wait until all other functions get
  7792. * down.
  7793. */
  7794. schedule_delayed_work(&bp->sp_rtnl_task,
  7795. HZ/10);
  7796. return;
  7797. } else {
  7798. /* If all other functions got down -
  7799. * try to bring the chip back to
  7800. * normal. In any case it's an exit
  7801. * point for a leader.
  7802. */
  7803. if (bnx2x_leader_reset(bp)) {
  7804. bnx2x_recovery_failed(bp);
  7805. return;
  7806. }
  7807. /* If we are here, means that the
  7808. * leader has succeeded and doesn't
  7809. * want to be a leader any more. Try
  7810. * to continue as a none-leader.
  7811. */
  7812. break;
  7813. }
  7814. } else { /* non-leader */
  7815. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  7816. /* Try to get a LEADER_LOCK HW lock as
  7817. * long as a former leader may have
  7818. * been unloaded by the user or
  7819. * released a leadership by another
  7820. * reason.
  7821. */
  7822. if (bnx2x_trylock_leader_lock(bp)) {
  7823. /* I'm a leader now! Restart a
  7824. * switch case.
  7825. */
  7826. bp->is_leader = 1;
  7827. break;
  7828. }
  7829. schedule_delayed_work(&bp->sp_rtnl_task,
  7830. HZ/10);
  7831. return;
  7832. } else {
  7833. /*
  7834. * If there was a global attention, wait
  7835. * for it to be cleared.
  7836. */
  7837. if (bnx2x_reset_is_global(bp)) {
  7838. schedule_delayed_work(
  7839. &bp->sp_rtnl_task,
  7840. HZ/10);
  7841. return;
  7842. }
  7843. error_recovered =
  7844. bp->eth_stats.recoverable_error;
  7845. error_unrecovered =
  7846. bp->eth_stats.unrecoverable_error;
  7847. bp->recovery_state =
  7848. BNX2X_RECOVERY_NIC_LOADING;
  7849. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  7850. error_unrecovered++;
  7851. netdev_err(bp->dev,
  7852. "Recovery failed. Power cycle needed\n");
  7853. /* Disconnect this device */
  7854. netif_device_detach(bp->dev);
  7855. /* Shut down the power */
  7856. bnx2x_set_power_state(
  7857. bp, PCI_D3hot);
  7858. smp_mb();
  7859. } else {
  7860. bp->recovery_state =
  7861. BNX2X_RECOVERY_DONE;
  7862. error_recovered++;
  7863. smp_mb();
  7864. }
  7865. bp->eth_stats.recoverable_error =
  7866. error_recovered;
  7867. bp->eth_stats.unrecoverable_error =
  7868. error_unrecovered;
  7869. return;
  7870. }
  7871. }
  7872. default:
  7873. return;
  7874. }
  7875. }
  7876. }
  7877. static int bnx2x_close(struct net_device *dev);
  7878. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  7879. * scheduled on a general queue in order to prevent a dead lock.
  7880. */
  7881. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  7882. {
  7883. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  7884. rtnl_lock();
  7885. if (!netif_running(bp->dev)) {
  7886. rtnl_unlock();
  7887. return;
  7888. }
  7889. /* if stop on error is defined no recovery flows should be executed */
  7890. #ifdef BNX2X_STOP_ON_ERROR
  7891. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  7892. "you will need to reboot when done\n");
  7893. goto sp_rtnl_not_reset;
  7894. #endif
  7895. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  7896. /*
  7897. * Clear all pending SP commands as we are going to reset the
  7898. * function anyway.
  7899. */
  7900. bp->sp_rtnl_state = 0;
  7901. smp_mb();
  7902. bnx2x_parity_recover(bp);
  7903. rtnl_unlock();
  7904. return;
  7905. }
  7906. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  7907. /*
  7908. * Clear all pending SP commands as we are going to reset the
  7909. * function anyway.
  7910. */
  7911. bp->sp_rtnl_state = 0;
  7912. smp_mb();
  7913. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  7914. bnx2x_nic_load(bp, LOAD_NORMAL);
  7915. rtnl_unlock();
  7916. return;
  7917. }
  7918. #ifdef BNX2X_STOP_ON_ERROR
  7919. sp_rtnl_not_reset:
  7920. #endif
  7921. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  7922. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  7923. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  7924. bnx2x_after_function_update(bp);
  7925. /*
  7926. * in case of fan failure we need to reset id if the "stop on error"
  7927. * debug flag is set, since we trying to prevent permanent overheating
  7928. * damage
  7929. */
  7930. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  7931. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  7932. netif_device_detach(bp->dev);
  7933. bnx2x_close(bp->dev);
  7934. rtnl_unlock();
  7935. return;
  7936. }
  7937. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  7938. DP(BNX2X_MSG_SP,
  7939. "sending set mcast vf pf channel message from rtnl sp-task\n");
  7940. bnx2x_vfpf_set_mcast(bp->dev);
  7941. }
  7942. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
  7943. &bp->sp_rtnl_state)) {
  7944. DP(BNX2X_MSG_SP,
  7945. "sending set storm rx mode vf pf channel message from rtnl sp-task\n");
  7946. bnx2x_vfpf_storm_rx_mode(bp);
  7947. }
  7948. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  7949. * can be called from other contexts as well)
  7950. */
  7951. rtnl_unlock();
  7952. /* enable SR-IOV if applicable */
  7953. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  7954. &bp->sp_rtnl_state))
  7955. bnx2x_enable_sriov(bp);
  7956. }
  7957. static void bnx2x_period_task(struct work_struct *work)
  7958. {
  7959. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  7960. if (!netif_running(bp->dev))
  7961. goto period_task_exit;
  7962. if (CHIP_REV_IS_SLOW(bp)) {
  7963. BNX2X_ERR("period task called on emulation, ignoring\n");
  7964. goto period_task_exit;
  7965. }
  7966. bnx2x_acquire_phy_lock(bp);
  7967. /*
  7968. * The barrier is needed to ensure the ordering between the writing to
  7969. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  7970. * the reading here.
  7971. */
  7972. smp_mb();
  7973. if (bp->port.pmf) {
  7974. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  7975. /* Re-queue task in 1 sec */
  7976. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  7977. }
  7978. bnx2x_release_phy_lock(bp);
  7979. period_task_exit:
  7980. return;
  7981. }
  7982. /*
  7983. * Init service functions
  7984. */
  7985. u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  7986. {
  7987. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  7988. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  7989. return base + (BP_ABS_FUNC(bp)) * stride;
  7990. }
  7991. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  7992. struct bnx2x_mac_vals *vals)
  7993. {
  7994. u32 val, base_addr, offset, mask, reset_reg;
  7995. bool mac_stopped = false;
  7996. u8 port = BP_PORT(bp);
  7997. /* reset addresses as they also mark which values were changed */
  7998. vals->bmac_addr = 0;
  7999. vals->umac_addr = 0;
  8000. vals->xmac_addr = 0;
  8001. vals->emac_addr = 0;
  8002. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  8003. if (!CHIP_IS_E3(bp)) {
  8004. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  8005. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  8006. if ((mask & reset_reg) && val) {
  8007. u32 wb_data[2];
  8008. BNX2X_DEV_INFO("Disable bmac Rx\n");
  8009. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  8010. : NIG_REG_INGRESS_BMAC0_MEM;
  8011. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  8012. : BIGMAC_REGISTER_BMAC_CONTROL;
  8013. /*
  8014. * use rd/wr since we cannot use dmae. This is safe
  8015. * since MCP won't access the bus due to the request
  8016. * to unload, and no function on the path can be
  8017. * loaded at this time.
  8018. */
  8019. wb_data[0] = REG_RD(bp, base_addr + offset);
  8020. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8021. vals->bmac_addr = base_addr + offset;
  8022. vals->bmac_val[0] = wb_data[0];
  8023. vals->bmac_val[1] = wb_data[1];
  8024. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8025. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8026. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8027. }
  8028. BNX2X_DEV_INFO("Disable emac Rx\n");
  8029. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8030. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8031. REG_WR(bp, vals->emac_addr, 0);
  8032. mac_stopped = true;
  8033. } else {
  8034. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8035. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8036. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8037. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8038. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8039. val & ~(1 << 1));
  8040. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8041. val | (1 << 1));
  8042. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8043. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8044. REG_WR(bp, vals->xmac_addr, 0);
  8045. mac_stopped = true;
  8046. }
  8047. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8048. if (mask & reset_reg) {
  8049. BNX2X_DEV_INFO("Disable umac Rx\n");
  8050. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8051. vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
  8052. vals->umac_val = REG_RD(bp, vals->umac_addr);
  8053. REG_WR(bp, vals->umac_addr, 0);
  8054. mac_stopped = true;
  8055. }
  8056. }
  8057. if (mac_stopped)
  8058. msleep(20);
  8059. }
  8060. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8061. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8062. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8063. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8064. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
  8065. {
  8066. u16 rcq, bd;
  8067. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  8068. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8069. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8070. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8071. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  8072. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8073. port, bd, rcq);
  8074. }
  8075. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8076. {
  8077. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8078. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8079. if (!rc) {
  8080. BNX2X_ERR("MCP response failure, aborting\n");
  8081. return -EBUSY;
  8082. }
  8083. return 0;
  8084. }
  8085. static struct bnx2x_prev_path_list *
  8086. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8087. {
  8088. struct bnx2x_prev_path_list *tmp_list;
  8089. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8090. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8091. bp->pdev->bus->number == tmp_list->bus &&
  8092. BP_PATH(bp) == tmp_list->path)
  8093. return tmp_list;
  8094. return NULL;
  8095. }
  8096. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8097. {
  8098. struct bnx2x_prev_path_list *tmp_list;
  8099. int rc = false;
  8100. if (down_trylock(&bnx2x_prev_sem))
  8101. return false;
  8102. list_for_each_entry(tmp_list, &bnx2x_prev_list, list) {
  8103. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8104. bp->pdev->bus->number == tmp_list->bus &&
  8105. BP_PATH(bp) == tmp_list->path) {
  8106. rc = true;
  8107. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8108. BP_PATH(bp));
  8109. break;
  8110. }
  8111. }
  8112. up(&bnx2x_prev_sem);
  8113. return rc;
  8114. }
  8115. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8116. {
  8117. struct bnx2x_prev_path_list *tmp_list;
  8118. int rc;
  8119. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8120. if (!tmp_list) {
  8121. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8122. return -ENOMEM;
  8123. }
  8124. tmp_list->bus = bp->pdev->bus->number;
  8125. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8126. tmp_list->path = BP_PATH(bp);
  8127. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8128. rc = down_interruptible(&bnx2x_prev_sem);
  8129. if (rc) {
  8130. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8131. kfree(tmp_list);
  8132. } else {
  8133. BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
  8134. BP_PATH(bp));
  8135. list_add(&tmp_list->list, &bnx2x_prev_list);
  8136. up(&bnx2x_prev_sem);
  8137. }
  8138. return rc;
  8139. }
  8140. static int bnx2x_do_flr(struct bnx2x *bp)
  8141. {
  8142. int i;
  8143. u16 status;
  8144. struct pci_dev *dev = bp->pdev;
  8145. if (CHIP_IS_E1x(bp)) {
  8146. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8147. return -EINVAL;
  8148. }
  8149. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8150. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8151. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8152. bp->common.bc_ver);
  8153. return -EINVAL;
  8154. }
  8155. /* Wait for Transaction Pending bit clean */
  8156. for (i = 0; i < 4; i++) {
  8157. if (i)
  8158. msleep((1 << (i - 1)) * 100);
  8159. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  8160. if (!(status & PCI_EXP_DEVSTA_TRPND))
  8161. goto clear;
  8162. }
  8163. dev_err(&dev->dev,
  8164. "transaction is not cleared; proceeding with reset anyway\n");
  8165. clear:
  8166. BNX2X_DEV_INFO("Initiating FLR\n");
  8167. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8168. return 0;
  8169. }
  8170. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8171. {
  8172. int rc;
  8173. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8174. /* Test if previous unload process was already finished for this path */
  8175. if (bnx2x_prev_is_path_marked(bp))
  8176. return bnx2x_prev_mcp_done(bp);
  8177. BNX2X_DEV_INFO("Path is unmarked\n");
  8178. /* If function has FLR capabilities, and existing FW version matches
  8179. * the one required, then FLR will be sufficient to clean any residue
  8180. * left by previous driver
  8181. */
  8182. rc = bnx2x_nic_load_analyze_req(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION);
  8183. if (!rc) {
  8184. /* fw version is good */
  8185. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8186. rc = bnx2x_do_flr(bp);
  8187. }
  8188. if (!rc) {
  8189. /* FLR was performed */
  8190. BNX2X_DEV_INFO("FLR successful\n");
  8191. return 0;
  8192. }
  8193. BNX2X_DEV_INFO("Could not FLR\n");
  8194. /* Close the MCP request, return failure*/
  8195. rc = bnx2x_prev_mcp_done(bp);
  8196. if (!rc)
  8197. rc = BNX2X_PREV_WAIT_NEEDED;
  8198. return rc;
  8199. }
  8200. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  8201. {
  8202. u32 reset_reg, tmp_reg = 0, rc;
  8203. bool prev_undi = false;
  8204. struct bnx2x_mac_vals mac_vals;
  8205. /* It is possible a previous function received 'common' answer,
  8206. * but hasn't loaded yet, therefore creating a scenario of
  8207. * multiple functions receiving 'common' on the same path.
  8208. */
  8209. BNX2X_DEV_INFO("Common unload Flow\n");
  8210. memset(&mac_vals, 0, sizeof(mac_vals));
  8211. if (bnx2x_prev_is_path_marked(bp))
  8212. return bnx2x_prev_mcp_done(bp);
  8213. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8214. /* Reset should be performed after BRB is emptied */
  8215. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8216. u32 timer_count = 1000;
  8217. /* Close the MAC Rx to prevent BRB from filling up */
  8218. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  8219. /* close LLH filters towards the BRB */
  8220. bnx2x_set_rx_filter(&bp->link_params, 0);
  8221. /* Check if the UNDI driver was previously loaded
  8222. * UNDI driver initializes CID offset for normal bell to 0x7
  8223. */
  8224. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
  8225. tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  8226. if (tmp_reg == 0x7) {
  8227. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8228. prev_undi = true;
  8229. /* clear the UNDI indication */
  8230. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8231. /* clear possible idle check errors */
  8232. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  8233. }
  8234. }
  8235. /* wait until BRB is empty */
  8236. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8237. while (timer_count) {
  8238. u32 prev_brb = tmp_reg;
  8239. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8240. if (!tmp_reg)
  8241. break;
  8242. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8243. /* reset timer as long as BRB actually gets emptied */
  8244. if (prev_brb > tmp_reg)
  8245. timer_count = 1000;
  8246. else
  8247. timer_count--;
  8248. /* If UNDI resides in memory, manually increment it */
  8249. if (prev_undi)
  8250. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  8251. udelay(10);
  8252. }
  8253. if (!timer_count)
  8254. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8255. }
  8256. /* No packets are in the pipeline, path is ready for reset */
  8257. bnx2x_reset_common(bp);
  8258. if (mac_vals.xmac_addr)
  8259. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  8260. if (mac_vals.umac_addr)
  8261. REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
  8262. if (mac_vals.emac_addr)
  8263. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  8264. if (mac_vals.bmac_addr) {
  8265. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  8266. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  8267. }
  8268. rc = bnx2x_prev_mark_path(bp, prev_undi);
  8269. if (rc) {
  8270. bnx2x_prev_mcp_done(bp);
  8271. return rc;
  8272. }
  8273. return bnx2x_prev_mcp_done(bp);
  8274. }
  8275. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  8276. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  8277. * the addresses of the transaction, resulting in was-error bit set in the pci
  8278. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  8279. * to clear the interrupt which detected this from the pglueb and the was done
  8280. * bit
  8281. */
  8282. static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  8283. {
  8284. if (!CHIP_IS_E1x(bp)) {
  8285. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  8286. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  8287. DP(BNX2X_MSG_SP,
  8288. "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
  8289. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  8290. 1 << BP_FUNC(bp));
  8291. }
  8292. }
  8293. }
  8294. static int bnx2x_prev_unload(struct bnx2x *bp)
  8295. {
  8296. int time_counter = 10;
  8297. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8298. struct bnx2x_prev_path_list *prev_list;
  8299. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8300. /* clear hw from errors which may have resulted from an interrupted
  8301. * dmae transaction.
  8302. */
  8303. bnx2x_prev_interrupted_dmae(bp);
  8304. /* Release previously held locks */
  8305. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8306. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8307. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8308. hw_lock_val = (REG_RD(bp, hw_lock_reg));
  8309. if (hw_lock_val) {
  8310. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8311. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8312. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8313. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8314. }
  8315. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8316. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8317. } else
  8318. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8319. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8320. BNX2X_DEV_INFO("Release previously held alr\n");
  8321. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  8322. }
  8323. do {
  8324. /* Lock MCP using an unload request */
  8325. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8326. if (!fw) {
  8327. BNX2X_ERR("MCP response failure, aborting\n");
  8328. rc = -EBUSY;
  8329. break;
  8330. }
  8331. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
  8332. rc = bnx2x_prev_unload_common(bp);
  8333. break;
  8334. }
  8335. /* non-common reply from MCP night require looping */
  8336. rc = bnx2x_prev_unload_uncommon(bp);
  8337. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8338. break;
  8339. msleep(20);
  8340. } while (--time_counter);
  8341. if (!time_counter || rc) {
  8342. BNX2X_ERR("Failed unloading previous driver, aborting\n");
  8343. rc = -EBUSY;
  8344. }
  8345. /* Mark function if its port was used to boot from SAN */
  8346. prev_list = bnx2x_prev_path_get_entry(bp);
  8347. if (prev_list && (prev_list->undi & (1 << BP_PORT(bp))))
  8348. bp->link_params.feature_config_flags |=
  8349. FEATURE_CONFIG_BOOT_FROM_SAN;
  8350. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8351. return rc;
  8352. }
  8353. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8354. {
  8355. u32 val, val2, val3, val4, id, boot_mode;
  8356. u16 pmc;
  8357. /* Get the chip revision id and number. */
  8358. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8359. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8360. id = ((val & 0xffff) << 16);
  8361. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8362. id |= ((val & 0xf) << 12);
  8363. val = REG_RD(bp, MISC_REG_CHIP_METAL);
  8364. id |= ((val & 0xff) << 4);
  8365. val = REG_RD(bp, MISC_REG_BOND_ID);
  8366. id |= (val & 0xf);
  8367. bp->common.chip_id = id;
  8368. /* force 57811 according to MISC register */
  8369. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8370. if (CHIP_IS_57810(bp))
  8371. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8372. (bp->common.chip_id & 0x0000FFFF);
  8373. else if (CHIP_IS_57810_MF(bp))
  8374. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8375. (bp->common.chip_id & 0x0000FFFF);
  8376. bp->common.chip_id |= 0x1;
  8377. }
  8378. /* Set doorbell size */
  8379. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8380. if (!CHIP_IS_E1x(bp)) {
  8381. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8382. if ((val & 1) == 0)
  8383. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8384. else
  8385. val = (val >> 1) & 1;
  8386. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8387. "2_PORT_MODE");
  8388. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8389. CHIP_2_PORT_MODE;
  8390. if (CHIP_MODE_IS_4_PORT(bp))
  8391. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8392. else
  8393. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8394. } else {
  8395. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8396. bp->pfid = bp->pf_num; /* 0..7 */
  8397. }
  8398. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8399. bp->link_params.chip_id = bp->common.chip_id;
  8400. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8401. val = (REG_RD(bp, 0x2874) & 0x55);
  8402. if ((bp->common.chip_id & 0x1) ||
  8403. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8404. bp->flags |= ONE_PORT_FLAG;
  8405. BNX2X_DEV_INFO("single port device\n");
  8406. }
  8407. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  8408. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8409. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8410. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8411. bp->common.flash_size, bp->common.flash_size);
  8412. bnx2x_init_shmem(bp);
  8413. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8414. MISC_REG_GENERIC_CR_1 :
  8415. MISC_REG_GENERIC_CR_0));
  8416. bp->link_params.shmem_base = bp->common.shmem_base;
  8417. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8418. if (SHMEM2_RD(bp, size) >
  8419. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  8420. bp->link_params.lfa_base =
  8421. REG_RD(bp, bp->common.shmem2_base +
  8422. (u32)offsetof(struct shmem2_region,
  8423. lfa_host_addr[BP_PORT(bp)]));
  8424. else
  8425. bp->link_params.lfa_base = 0;
  8426. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8427. bp->common.shmem_base, bp->common.shmem2_base);
  8428. if (!bp->common.shmem_base) {
  8429. BNX2X_DEV_INFO("MCP not active\n");
  8430. bp->flags |= NO_MCP_FLAG;
  8431. return;
  8432. }
  8433. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8434. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8435. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8436. SHARED_HW_CFG_LED_MODE_MASK) >>
  8437. SHARED_HW_CFG_LED_MODE_SHIFT);
  8438. bp->link_params.feature_config_flags = 0;
  8439. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8440. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8441. bp->link_params.feature_config_flags |=
  8442. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8443. else
  8444. bp->link_params.feature_config_flags &=
  8445. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8446. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8447. bp->common.bc_ver = val;
  8448. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8449. if (val < BNX2X_BC_VER) {
  8450. /* for now only warn
  8451. * later we might need to enforce this */
  8452. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8453. BNX2X_BC_VER, val);
  8454. }
  8455. bp->link_params.feature_config_flags |=
  8456. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8457. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8458. bp->link_params.feature_config_flags |=
  8459. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8460. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8461. bp->link_params.feature_config_flags |=
  8462. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8463. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8464. bp->link_params.feature_config_flags |=
  8465. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8466. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8467. bp->link_params.feature_config_flags |=
  8468. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  8469. FEATURE_CONFIG_MT_SUPPORT : 0;
  8470. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8471. BC_SUPPORTS_PFC_STATS : 0;
  8472. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  8473. BC_SUPPORTS_FCOE_FEATURES : 0;
  8474. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  8475. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  8476. boot_mode = SHMEM_RD(bp,
  8477. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8478. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8479. switch (boot_mode) {
  8480. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8481. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8482. break;
  8483. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8484. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8485. break;
  8486. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  8487. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  8488. break;
  8489. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  8490. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  8491. break;
  8492. }
  8493. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  8494. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  8495. BNX2X_DEV_INFO("%sWoL capable\n",
  8496. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  8497. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  8498. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  8499. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  8500. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  8501. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  8502. val, val2, val3, val4);
  8503. }
  8504. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  8505. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  8506. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  8507. {
  8508. int pfid = BP_FUNC(bp);
  8509. int igu_sb_id;
  8510. u32 val;
  8511. u8 fid, igu_sb_cnt = 0;
  8512. bp->igu_base_sb = 0xff;
  8513. if (CHIP_INT_MODE_IS_BC(bp)) {
  8514. int vn = BP_VN(bp);
  8515. igu_sb_cnt = bp->igu_sb_cnt;
  8516. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  8517. FP_SB_MAX_E1x;
  8518. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  8519. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  8520. return 0;
  8521. }
  8522. /* IGU in normal mode - read CAM */
  8523. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  8524. igu_sb_id++) {
  8525. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  8526. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  8527. continue;
  8528. fid = IGU_FID(val);
  8529. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  8530. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  8531. continue;
  8532. if (IGU_VEC(val) == 0)
  8533. /* default status block */
  8534. bp->igu_dsb_id = igu_sb_id;
  8535. else {
  8536. if (bp->igu_base_sb == 0xff)
  8537. bp->igu_base_sb = igu_sb_id;
  8538. igu_sb_cnt++;
  8539. }
  8540. }
  8541. }
  8542. #ifdef CONFIG_PCI_MSI
  8543. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  8544. * optional that number of CAM entries will not be equal to the value
  8545. * advertised in PCI.
  8546. * Driver should use the minimal value of both as the actual status
  8547. * block count
  8548. */
  8549. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  8550. #endif
  8551. if (igu_sb_cnt == 0) {
  8552. BNX2X_ERR("CAM configuration error\n");
  8553. return -EINVAL;
  8554. }
  8555. return 0;
  8556. }
  8557. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  8558. {
  8559. int cfg_size = 0, idx, port = BP_PORT(bp);
  8560. /* Aggregation of supported attributes of all external phys */
  8561. bp->port.supported[0] = 0;
  8562. bp->port.supported[1] = 0;
  8563. switch (bp->link_params.num_phys) {
  8564. case 1:
  8565. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  8566. cfg_size = 1;
  8567. break;
  8568. case 2:
  8569. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  8570. cfg_size = 1;
  8571. break;
  8572. case 3:
  8573. if (bp->link_params.multi_phy_config &
  8574. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  8575. bp->port.supported[1] =
  8576. bp->link_params.phy[EXT_PHY1].supported;
  8577. bp->port.supported[0] =
  8578. bp->link_params.phy[EXT_PHY2].supported;
  8579. } else {
  8580. bp->port.supported[0] =
  8581. bp->link_params.phy[EXT_PHY1].supported;
  8582. bp->port.supported[1] =
  8583. bp->link_params.phy[EXT_PHY2].supported;
  8584. }
  8585. cfg_size = 2;
  8586. break;
  8587. }
  8588. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  8589. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  8590. SHMEM_RD(bp,
  8591. dev_info.port_hw_config[port].external_phy_config),
  8592. SHMEM_RD(bp,
  8593. dev_info.port_hw_config[port].external_phy_config2));
  8594. return;
  8595. }
  8596. if (CHIP_IS_E3(bp))
  8597. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  8598. else {
  8599. switch (switch_cfg) {
  8600. case SWITCH_CFG_1G:
  8601. bp->port.phy_addr = REG_RD(
  8602. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  8603. break;
  8604. case SWITCH_CFG_10G:
  8605. bp->port.phy_addr = REG_RD(
  8606. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  8607. break;
  8608. default:
  8609. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  8610. bp->port.link_config[0]);
  8611. return;
  8612. }
  8613. }
  8614. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  8615. /* mask what we support according to speed_cap_mask per configuration */
  8616. for (idx = 0; idx < cfg_size; idx++) {
  8617. if (!(bp->link_params.speed_cap_mask[idx] &
  8618. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  8619. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  8620. if (!(bp->link_params.speed_cap_mask[idx] &
  8621. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  8622. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  8623. if (!(bp->link_params.speed_cap_mask[idx] &
  8624. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  8625. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  8626. if (!(bp->link_params.speed_cap_mask[idx] &
  8627. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  8628. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  8629. if (!(bp->link_params.speed_cap_mask[idx] &
  8630. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  8631. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  8632. SUPPORTED_1000baseT_Full);
  8633. if (!(bp->link_params.speed_cap_mask[idx] &
  8634. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  8635. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  8636. if (!(bp->link_params.speed_cap_mask[idx] &
  8637. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  8638. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  8639. }
  8640. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  8641. bp->port.supported[1]);
  8642. }
  8643. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  8644. {
  8645. u32 link_config, idx, cfg_size = 0;
  8646. bp->port.advertising[0] = 0;
  8647. bp->port.advertising[1] = 0;
  8648. switch (bp->link_params.num_phys) {
  8649. case 1:
  8650. case 2:
  8651. cfg_size = 1;
  8652. break;
  8653. case 3:
  8654. cfg_size = 2;
  8655. break;
  8656. }
  8657. for (idx = 0; idx < cfg_size; idx++) {
  8658. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  8659. link_config = bp->port.link_config[idx];
  8660. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  8661. case PORT_FEATURE_LINK_SPEED_AUTO:
  8662. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  8663. bp->link_params.req_line_speed[idx] =
  8664. SPEED_AUTO_NEG;
  8665. bp->port.advertising[idx] |=
  8666. bp->port.supported[idx];
  8667. if (bp->link_params.phy[EXT_PHY1].type ==
  8668. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  8669. bp->port.advertising[idx] |=
  8670. (SUPPORTED_100baseT_Half |
  8671. SUPPORTED_100baseT_Full);
  8672. } else {
  8673. /* force 10G, no AN */
  8674. bp->link_params.req_line_speed[idx] =
  8675. SPEED_10000;
  8676. bp->port.advertising[idx] |=
  8677. (ADVERTISED_10000baseT_Full |
  8678. ADVERTISED_FIBRE);
  8679. continue;
  8680. }
  8681. break;
  8682. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  8683. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  8684. bp->link_params.req_line_speed[idx] =
  8685. SPEED_10;
  8686. bp->port.advertising[idx] |=
  8687. (ADVERTISED_10baseT_Full |
  8688. ADVERTISED_TP);
  8689. } else {
  8690. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8691. link_config,
  8692. bp->link_params.speed_cap_mask[idx]);
  8693. return;
  8694. }
  8695. break;
  8696. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  8697. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  8698. bp->link_params.req_line_speed[idx] =
  8699. SPEED_10;
  8700. bp->link_params.req_duplex[idx] =
  8701. DUPLEX_HALF;
  8702. bp->port.advertising[idx] |=
  8703. (ADVERTISED_10baseT_Half |
  8704. ADVERTISED_TP);
  8705. } else {
  8706. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8707. link_config,
  8708. bp->link_params.speed_cap_mask[idx]);
  8709. return;
  8710. }
  8711. break;
  8712. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  8713. if (bp->port.supported[idx] &
  8714. SUPPORTED_100baseT_Full) {
  8715. bp->link_params.req_line_speed[idx] =
  8716. SPEED_100;
  8717. bp->port.advertising[idx] |=
  8718. (ADVERTISED_100baseT_Full |
  8719. ADVERTISED_TP);
  8720. } else {
  8721. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8722. link_config,
  8723. bp->link_params.speed_cap_mask[idx]);
  8724. return;
  8725. }
  8726. break;
  8727. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  8728. if (bp->port.supported[idx] &
  8729. SUPPORTED_100baseT_Half) {
  8730. bp->link_params.req_line_speed[idx] =
  8731. SPEED_100;
  8732. bp->link_params.req_duplex[idx] =
  8733. DUPLEX_HALF;
  8734. bp->port.advertising[idx] |=
  8735. (ADVERTISED_100baseT_Half |
  8736. ADVERTISED_TP);
  8737. } else {
  8738. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8739. link_config,
  8740. bp->link_params.speed_cap_mask[idx]);
  8741. return;
  8742. }
  8743. break;
  8744. case PORT_FEATURE_LINK_SPEED_1G:
  8745. if (bp->port.supported[idx] &
  8746. SUPPORTED_1000baseT_Full) {
  8747. bp->link_params.req_line_speed[idx] =
  8748. SPEED_1000;
  8749. bp->port.advertising[idx] |=
  8750. (ADVERTISED_1000baseT_Full |
  8751. ADVERTISED_TP);
  8752. } else {
  8753. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8754. link_config,
  8755. bp->link_params.speed_cap_mask[idx]);
  8756. return;
  8757. }
  8758. break;
  8759. case PORT_FEATURE_LINK_SPEED_2_5G:
  8760. if (bp->port.supported[idx] &
  8761. SUPPORTED_2500baseX_Full) {
  8762. bp->link_params.req_line_speed[idx] =
  8763. SPEED_2500;
  8764. bp->port.advertising[idx] |=
  8765. (ADVERTISED_2500baseX_Full |
  8766. ADVERTISED_TP);
  8767. } else {
  8768. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8769. link_config,
  8770. bp->link_params.speed_cap_mask[idx]);
  8771. return;
  8772. }
  8773. break;
  8774. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  8775. if (bp->port.supported[idx] &
  8776. SUPPORTED_10000baseT_Full) {
  8777. bp->link_params.req_line_speed[idx] =
  8778. SPEED_10000;
  8779. bp->port.advertising[idx] |=
  8780. (ADVERTISED_10000baseT_Full |
  8781. ADVERTISED_FIBRE);
  8782. } else {
  8783. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8784. link_config,
  8785. bp->link_params.speed_cap_mask[idx]);
  8786. return;
  8787. }
  8788. break;
  8789. case PORT_FEATURE_LINK_SPEED_20G:
  8790. bp->link_params.req_line_speed[idx] = SPEED_20000;
  8791. break;
  8792. default:
  8793. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  8794. link_config);
  8795. bp->link_params.req_line_speed[idx] =
  8796. SPEED_AUTO_NEG;
  8797. bp->port.advertising[idx] =
  8798. bp->port.supported[idx];
  8799. break;
  8800. }
  8801. bp->link_params.req_flow_ctrl[idx] = (link_config &
  8802. PORT_FEATURE_FLOW_CONTROL_MASK);
  8803. if (bp->link_params.req_flow_ctrl[idx] ==
  8804. BNX2X_FLOW_CTRL_AUTO) {
  8805. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  8806. bp->link_params.req_flow_ctrl[idx] =
  8807. BNX2X_FLOW_CTRL_NONE;
  8808. else
  8809. bnx2x_set_requested_fc(bp);
  8810. }
  8811. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  8812. bp->link_params.req_line_speed[idx],
  8813. bp->link_params.req_duplex[idx],
  8814. bp->link_params.req_flow_ctrl[idx],
  8815. bp->port.advertising[idx]);
  8816. }
  8817. }
  8818. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  8819. {
  8820. __be16 mac_hi_be = cpu_to_be16(mac_hi);
  8821. __be32 mac_lo_be = cpu_to_be32(mac_lo);
  8822. memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
  8823. memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
  8824. }
  8825. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  8826. {
  8827. int port = BP_PORT(bp);
  8828. u32 config;
  8829. u32 ext_phy_type, ext_phy_config, eee_mode;
  8830. bp->link_params.bp = bp;
  8831. bp->link_params.port = port;
  8832. bp->link_params.lane_config =
  8833. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  8834. bp->link_params.speed_cap_mask[0] =
  8835. SHMEM_RD(bp,
  8836. dev_info.port_hw_config[port].speed_capability_mask);
  8837. bp->link_params.speed_cap_mask[1] =
  8838. SHMEM_RD(bp,
  8839. dev_info.port_hw_config[port].speed_capability_mask2);
  8840. bp->port.link_config[0] =
  8841. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  8842. bp->port.link_config[1] =
  8843. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  8844. bp->link_params.multi_phy_config =
  8845. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  8846. /* If the device is capable of WoL, set the default state according
  8847. * to the HW
  8848. */
  8849. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  8850. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  8851. (config & PORT_FEATURE_WOL_ENABLED));
  8852. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  8853. PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
  8854. bp->flags |= NO_ISCSI_FLAG;
  8855. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  8856. PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
  8857. bp->flags |= NO_FCOE_FLAG;
  8858. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  8859. bp->link_params.lane_config,
  8860. bp->link_params.speed_cap_mask[0],
  8861. bp->port.link_config[0]);
  8862. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  8863. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  8864. bnx2x_phy_probe(&bp->link_params);
  8865. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  8866. bnx2x_link_settings_requested(bp);
  8867. /*
  8868. * If connected directly, work with the internal PHY, otherwise, work
  8869. * with the external PHY
  8870. */
  8871. ext_phy_config =
  8872. SHMEM_RD(bp,
  8873. dev_info.port_hw_config[port].external_phy_config);
  8874. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  8875. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  8876. bp->mdio.prtad = bp->port.phy_addr;
  8877. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  8878. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  8879. bp->mdio.prtad =
  8880. XGXS_EXT_PHY_ADDR(ext_phy_config);
  8881. /* Configure link feature according to nvram value */
  8882. eee_mode = (((SHMEM_RD(bp, dev_info.
  8883. port_feature_config[port].eee_power_mode)) &
  8884. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  8885. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  8886. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  8887. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  8888. EEE_MODE_ENABLE_LPI |
  8889. EEE_MODE_OUTPUT_TIME;
  8890. } else {
  8891. bp->link_params.eee_mode = 0;
  8892. }
  8893. }
  8894. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  8895. {
  8896. u32 no_flags = NO_ISCSI_FLAG;
  8897. int port = BP_PORT(bp);
  8898. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8899. drv_lic_key[port].max_iscsi_conn);
  8900. if (!CNIC_SUPPORT(bp)) {
  8901. bp->flags |= no_flags;
  8902. return;
  8903. }
  8904. /* Get the number of maximum allowed iSCSI connections */
  8905. bp->cnic_eth_dev.max_iscsi_conn =
  8906. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  8907. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  8908. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  8909. bp->cnic_eth_dev.max_iscsi_conn);
  8910. /*
  8911. * If maximum allowed number of connections is zero -
  8912. * disable the feature.
  8913. */
  8914. if (!bp->cnic_eth_dev.max_iscsi_conn)
  8915. bp->flags |= no_flags;
  8916. }
  8917. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  8918. {
  8919. /* Port info */
  8920. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8921. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  8922. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8923. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  8924. /* Node info */
  8925. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8926. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  8927. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8928. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  8929. }
  8930. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  8931. {
  8932. int port = BP_PORT(bp);
  8933. int func = BP_ABS_FUNC(bp);
  8934. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8935. drv_lic_key[port].max_fcoe_conn);
  8936. if (!CNIC_SUPPORT(bp)) {
  8937. bp->flags |= NO_FCOE_FLAG;
  8938. return;
  8939. }
  8940. /* Get the number of maximum allowed FCoE connections */
  8941. bp->cnic_eth_dev.max_fcoe_conn =
  8942. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  8943. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  8944. /* Read the WWN: */
  8945. if (!IS_MF(bp)) {
  8946. /* Port info */
  8947. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8948. SHMEM_RD(bp,
  8949. dev_info.port_hw_config[port].
  8950. fcoe_wwn_port_name_upper);
  8951. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8952. SHMEM_RD(bp,
  8953. dev_info.port_hw_config[port].
  8954. fcoe_wwn_port_name_lower);
  8955. /* Node info */
  8956. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8957. SHMEM_RD(bp,
  8958. dev_info.port_hw_config[port].
  8959. fcoe_wwn_node_name_upper);
  8960. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8961. SHMEM_RD(bp,
  8962. dev_info.port_hw_config[port].
  8963. fcoe_wwn_node_name_lower);
  8964. } else if (!IS_MF_SD(bp)) {
  8965. /*
  8966. * Read the WWN info only if the FCoE feature is enabled for
  8967. * this function.
  8968. */
  8969. if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  8970. bnx2x_get_ext_wwn_info(bp, func);
  8971. } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
  8972. bnx2x_get_ext_wwn_info(bp, func);
  8973. }
  8974. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  8975. /*
  8976. * If maximum allowed number of connections is zero -
  8977. * disable the feature.
  8978. */
  8979. if (!bp->cnic_eth_dev.max_fcoe_conn)
  8980. bp->flags |= NO_FCOE_FLAG;
  8981. }
  8982. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  8983. {
  8984. /*
  8985. * iSCSI may be dynamically disabled but reading
  8986. * info here we will decrease memory usage by driver
  8987. * if the feature is disabled for good
  8988. */
  8989. bnx2x_get_iscsi_info(bp);
  8990. bnx2x_get_fcoe_info(bp);
  8991. }
  8992. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  8993. {
  8994. u32 val, val2;
  8995. int func = BP_ABS_FUNC(bp);
  8996. int port = BP_PORT(bp);
  8997. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  8998. u8 *fip_mac = bp->fip_mac;
  8999. if (IS_MF(bp)) {
  9000. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  9001. * FCoE MAC then the appropriate feature should be disabled.
  9002. * In non SD mode features configuration comes from struct
  9003. * func_ext_config.
  9004. */
  9005. if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
  9006. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  9007. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  9008. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9009. iscsi_mac_addr_upper);
  9010. val = MF_CFG_RD(bp, func_ext_config[func].
  9011. iscsi_mac_addr_lower);
  9012. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9013. BNX2X_DEV_INFO
  9014. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9015. } else {
  9016. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9017. }
  9018. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  9019. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9020. fcoe_mac_addr_upper);
  9021. val = MF_CFG_RD(bp, func_ext_config[func].
  9022. fcoe_mac_addr_lower);
  9023. bnx2x_set_mac_buf(fip_mac, val, val2);
  9024. BNX2X_DEV_INFO
  9025. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  9026. } else {
  9027. bp->flags |= NO_FCOE_FLAG;
  9028. }
  9029. bp->mf_ext_config = cfg;
  9030. } else { /* SD MODE */
  9031. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9032. /* use primary mac as iscsi mac */
  9033. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9034. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9035. BNX2X_DEV_INFO
  9036. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9037. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9038. /* use primary mac as fip mac */
  9039. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9040. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9041. BNX2X_DEV_INFO
  9042. ("Read FIP MAC: %pM\n", fip_mac);
  9043. }
  9044. }
  9045. if (IS_MF_STORAGE_SD(bp))
  9046. /* Zero primary MAC configuration */
  9047. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9048. if (IS_MF_FCOE_AFEX(bp) || IS_MF_FCOE_SD(bp))
  9049. /* use FIP MAC as primary MAC */
  9050. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9051. } else {
  9052. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9053. iscsi_mac_upper);
  9054. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9055. iscsi_mac_lower);
  9056. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9057. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9058. fcoe_fip_mac_upper);
  9059. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9060. fcoe_fip_mac_lower);
  9061. bnx2x_set_mac_buf(fip_mac, val, val2);
  9062. }
  9063. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9064. if (!is_valid_ether_addr(iscsi_mac)) {
  9065. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9066. memset(iscsi_mac, 0, ETH_ALEN);
  9067. }
  9068. /* Disable FCoE if MAC configuration is invalid. */
  9069. if (!is_valid_ether_addr(fip_mac)) {
  9070. bp->flags |= NO_FCOE_FLAG;
  9071. memset(bp->fip_mac, 0, ETH_ALEN);
  9072. }
  9073. }
  9074. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9075. {
  9076. u32 val, val2;
  9077. int func = BP_ABS_FUNC(bp);
  9078. int port = BP_PORT(bp);
  9079. /* Zero primary MAC configuration */
  9080. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9081. if (BP_NOMCP(bp)) {
  9082. BNX2X_ERROR("warning: random MAC workaround active\n");
  9083. eth_hw_addr_random(bp->dev);
  9084. } else if (IS_MF(bp)) {
  9085. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9086. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9087. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9088. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9089. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9090. if (CNIC_SUPPORT(bp))
  9091. bnx2x_get_cnic_mac_hwinfo(bp);
  9092. } else {
  9093. /* in SF read MACs from port configuration */
  9094. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9095. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9096. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9097. if (CNIC_SUPPORT(bp))
  9098. bnx2x_get_cnic_mac_hwinfo(bp);
  9099. }
  9100. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9101. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  9102. dev_err(&bp->pdev->dev,
  9103. "bad Ethernet MAC address configuration: %pM\n"
  9104. "change it manually before bringing up the appropriate network interface\n",
  9105. bp->dev->dev_addr);
  9106. }
  9107. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9108. {
  9109. int tmp;
  9110. u32 cfg;
  9111. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  9112. /* Take function: tmp = func */
  9113. tmp = BP_ABS_FUNC(bp);
  9114. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  9115. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  9116. } else {
  9117. /* Take port: tmp = port */
  9118. tmp = BP_PORT(bp);
  9119. cfg = SHMEM_RD(bp,
  9120. dev_info.port_hw_config[tmp].generic_features);
  9121. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  9122. }
  9123. return cfg;
  9124. }
  9125. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  9126. {
  9127. int /*abs*/func = BP_ABS_FUNC(bp);
  9128. int vn;
  9129. u32 val = 0;
  9130. int rc = 0;
  9131. bnx2x_get_common_hwinfo(bp);
  9132. /*
  9133. * initialize IGU parameters
  9134. */
  9135. if (CHIP_IS_E1x(bp)) {
  9136. bp->common.int_block = INT_BLOCK_HC;
  9137. bp->igu_dsb_id = DEF_SB_IGU_ID;
  9138. bp->igu_base_sb = 0;
  9139. } else {
  9140. bp->common.int_block = INT_BLOCK_IGU;
  9141. /* do not allow device reset during IGU info preocessing */
  9142. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9143. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  9144. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9145. int tout = 5000;
  9146. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  9147. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  9148. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  9149. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  9150. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9151. tout--;
  9152. usleep_range(1000, 2000);
  9153. }
  9154. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9155. dev_err(&bp->pdev->dev,
  9156. "FORCING Normal Mode failed!!!\n");
  9157. bnx2x_release_hw_lock(bp,
  9158. HW_LOCK_RESOURCE_RESET);
  9159. return -EPERM;
  9160. }
  9161. }
  9162. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9163. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  9164. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  9165. } else
  9166. BNX2X_DEV_INFO("IGU Normal Mode\n");
  9167. rc = bnx2x_get_igu_cam_info(bp);
  9168. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9169. if (rc)
  9170. return rc;
  9171. }
  9172. /*
  9173. * set base FW non-default (fast path) status block id, this value is
  9174. * used to initialize the fw_sb_id saved on the fp/queue structure to
  9175. * determine the id used by the FW.
  9176. */
  9177. if (CHIP_IS_E1x(bp))
  9178. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  9179. else /*
  9180. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  9181. * the same queue are indicated on the same IGU SB). So we prefer
  9182. * FW and IGU SBs to be the same value.
  9183. */
  9184. bp->base_fw_ndsb = bp->igu_base_sb;
  9185. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  9186. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  9187. bp->igu_sb_cnt, bp->base_fw_ndsb);
  9188. /*
  9189. * Initialize MF configuration
  9190. */
  9191. bp->mf_ov = 0;
  9192. bp->mf_mode = 0;
  9193. vn = BP_VN(bp);
  9194. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  9195. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  9196. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  9197. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  9198. if (SHMEM2_HAS(bp, mf_cfg_addr))
  9199. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  9200. else
  9201. bp->common.mf_cfg_base = bp->common.shmem_base +
  9202. offsetof(struct shmem_region, func_mb) +
  9203. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  9204. /*
  9205. * get mf configuration:
  9206. * 1. existence of MF configuration
  9207. * 2. MAC address must be legal (check only upper bytes)
  9208. * for Switch-Independent mode;
  9209. * OVLAN must be legal for Switch-Dependent mode
  9210. * 3. SF_MODE configures specific MF mode
  9211. */
  9212. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9213. /* get mf configuration */
  9214. val = SHMEM_RD(bp,
  9215. dev_info.shared_feature_config.config);
  9216. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  9217. switch (val) {
  9218. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  9219. val = MF_CFG_RD(bp, func_mf_config[func].
  9220. mac_upper);
  9221. /* check for legal mac (upper bytes)*/
  9222. if (val != 0xffff) {
  9223. bp->mf_mode = MULTI_FUNCTION_SI;
  9224. bp->mf_config[vn] = MF_CFG_RD(bp,
  9225. func_mf_config[func].config);
  9226. } else
  9227. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9228. break;
  9229. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9230. if ((!CHIP_IS_E1x(bp)) &&
  9231. (MF_CFG_RD(bp, func_mf_config[func].
  9232. mac_upper) != 0xffff) &&
  9233. (SHMEM2_HAS(bp,
  9234. afex_driver_support))) {
  9235. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9236. bp->mf_config[vn] = MF_CFG_RD(bp,
  9237. func_mf_config[func].config);
  9238. } else {
  9239. BNX2X_DEV_INFO("can not configure afex mode\n");
  9240. }
  9241. break;
  9242. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9243. /* get OV configuration */
  9244. val = MF_CFG_RD(bp,
  9245. func_mf_config[FUNC_0].e1hov_tag);
  9246. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9247. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9248. bp->mf_mode = MULTI_FUNCTION_SD;
  9249. bp->mf_config[vn] = MF_CFG_RD(bp,
  9250. func_mf_config[func].config);
  9251. } else
  9252. BNX2X_DEV_INFO("illegal OV for SD\n");
  9253. break;
  9254. default:
  9255. /* Unknown configuration: reset mf_config */
  9256. bp->mf_config[vn] = 0;
  9257. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9258. }
  9259. }
  9260. BNX2X_DEV_INFO("%s function mode\n",
  9261. IS_MF(bp) ? "multi" : "single");
  9262. switch (bp->mf_mode) {
  9263. case MULTI_FUNCTION_SD:
  9264. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9265. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9266. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9267. bp->mf_ov = val;
  9268. bp->path_has_ovlan = true;
  9269. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9270. func, bp->mf_ov, bp->mf_ov);
  9271. } else {
  9272. dev_err(&bp->pdev->dev,
  9273. "No valid MF OV for func %d, aborting\n",
  9274. func);
  9275. return -EPERM;
  9276. }
  9277. break;
  9278. case MULTI_FUNCTION_AFEX:
  9279. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9280. break;
  9281. case MULTI_FUNCTION_SI:
  9282. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9283. func);
  9284. break;
  9285. default:
  9286. if (vn) {
  9287. dev_err(&bp->pdev->dev,
  9288. "VN %d is in a single function mode, aborting\n",
  9289. vn);
  9290. return -EPERM;
  9291. }
  9292. break;
  9293. }
  9294. /* check if other port on the path needs ovlan:
  9295. * Since MF configuration is shared between ports
  9296. * Possible mixed modes are only
  9297. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9298. */
  9299. if (CHIP_MODE_IS_4_PORT(bp) &&
  9300. !bp->path_has_ovlan &&
  9301. !IS_MF(bp) &&
  9302. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9303. u8 other_port = !BP_PORT(bp);
  9304. u8 other_func = BP_PATH(bp) + 2*other_port;
  9305. val = MF_CFG_RD(bp,
  9306. func_mf_config[other_func].e1hov_tag);
  9307. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  9308. bp->path_has_ovlan = true;
  9309. }
  9310. }
  9311. /* adjust igu_sb_cnt to MF for E1x */
  9312. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  9313. bp->igu_sb_cnt /= E1HVN_MAX;
  9314. /* port info */
  9315. bnx2x_get_port_hwinfo(bp);
  9316. /* Get MAC addresses */
  9317. bnx2x_get_mac_hwinfo(bp);
  9318. bnx2x_get_cnic_info(bp);
  9319. return rc;
  9320. }
  9321. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  9322. {
  9323. int cnt, i, block_end, rodi;
  9324. char vpd_start[BNX2X_VPD_LEN+1];
  9325. char str_id_reg[VENDOR_ID_LEN+1];
  9326. char str_id_cap[VENDOR_ID_LEN+1];
  9327. char *vpd_data;
  9328. char *vpd_extended_data = NULL;
  9329. u8 len;
  9330. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  9331. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  9332. if (cnt < BNX2X_VPD_LEN)
  9333. goto out_not_found;
  9334. /* VPD RO tag should be first tag after identifier string, hence
  9335. * we should be able to find it in first BNX2X_VPD_LEN chars
  9336. */
  9337. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  9338. PCI_VPD_LRDT_RO_DATA);
  9339. if (i < 0)
  9340. goto out_not_found;
  9341. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  9342. pci_vpd_lrdt_size(&vpd_start[i]);
  9343. i += PCI_VPD_LRDT_TAG_SIZE;
  9344. if (block_end > BNX2X_VPD_LEN) {
  9345. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  9346. if (vpd_extended_data == NULL)
  9347. goto out_not_found;
  9348. /* read rest of vpd image into vpd_extended_data */
  9349. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  9350. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  9351. block_end - BNX2X_VPD_LEN,
  9352. vpd_extended_data + BNX2X_VPD_LEN);
  9353. if (cnt < (block_end - BNX2X_VPD_LEN))
  9354. goto out_not_found;
  9355. vpd_data = vpd_extended_data;
  9356. } else
  9357. vpd_data = vpd_start;
  9358. /* now vpd_data holds full vpd content in both cases */
  9359. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9360. PCI_VPD_RO_KEYWORD_MFR_ID);
  9361. if (rodi < 0)
  9362. goto out_not_found;
  9363. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9364. if (len != VENDOR_ID_LEN)
  9365. goto out_not_found;
  9366. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9367. /* vendor specific info */
  9368. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  9369. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  9370. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  9371. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  9372. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9373. PCI_VPD_RO_KEYWORD_VENDOR0);
  9374. if (rodi >= 0) {
  9375. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9376. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9377. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  9378. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  9379. bp->fw_ver[len] = ' ';
  9380. }
  9381. }
  9382. kfree(vpd_extended_data);
  9383. return;
  9384. }
  9385. out_not_found:
  9386. kfree(vpd_extended_data);
  9387. return;
  9388. }
  9389. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  9390. {
  9391. u32 flags = 0;
  9392. if (CHIP_REV_IS_FPGA(bp))
  9393. SET_FLAGS(flags, MODE_FPGA);
  9394. else if (CHIP_REV_IS_EMUL(bp))
  9395. SET_FLAGS(flags, MODE_EMUL);
  9396. else
  9397. SET_FLAGS(flags, MODE_ASIC);
  9398. if (CHIP_MODE_IS_4_PORT(bp))
  9399. SET_FLAGS(flags, MODE_PORT4);
  9400. else
  9401. SET_FLAGS(flags, MODE_PORT2);
  9402. if (CHIP_IS_E2(bp))
  9403. SET_FLAGS(flags, MODE_E2);
  9404. else if (CHIP_IS_E3(bp)) {
  9405. SET_FLAGS(flags, MODE_E3);
  9406. if (CHIP_REV(bp) == CHIP_REV_Ax)
  9407. SET_FLAGS(flags, MODE_E3_A0);
  9408. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  9409. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  9410. }
  9411. if (IS_MF(bp)) {
  9412. SET_FLAGS(flags, MODE_MF);
  9413. switch (bp->mf_mode) {
  9414. case MULTI_FUNCTION_SD:
  9415. SET_FLAGS(flags, MODE_MF_SD);
  9416. break;
  9417. case MULTI_FUNCTION_SI:
  9418. SET_FLAGS(flags, MODE_MF_SI);
  9419. break;
  9420. case MULTI_FUNCTION_AFEX:
  9421. SET_FLAGS(flags, MODE_MF_AFEX);
  9422. break;
  9423. }
  9424. } else
  9425. SET_FLAGS(flags, MODE_SF);
  9426. #if defined(__LITTLE_ENDIAN)
  9427. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  9428. #else /*(__BIG_ENDIAN)*/
  9429. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  9430. #endif
  9431. INIT_MODE_FLAGS(bp) = flags;
  9432. }
  9433. static int bnx2x_init_bp(struct bnx2x *bp)
  9434. {
  9435. int func;
  9436. int rc;
  9437. mutex_init(&bp->port.phy_mutex);
  9438. mutex_init(&bp->fw_mb_mutex);
  9439. spin_lock_init(&bp->stats_lock);
  9440. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  9441. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  9442. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  9443. if (IS_PF(bp)) {
  9444. rc = bnx2x_get_hwinfo(bp);
  9445. if (rc)
  9446. return rc;
  9447. } else {
  9448. random_ether_addr(bp->dev->dev_addr);
  9449. }
  9450. bnx2x_set_modes_bitmap(bp);
  9451. rc = bnx2x_alloc_mem_bp(bp);
  9452. if (rc)
  9453. return rc;
  9454. bnx2x_read_fwinfo(bp);
  9455. func = BP_FUNC(bp);
  9456. /* need to reset chip if undi was active */
  9457. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  9458. /* init fw_seq */
  9459. bp->fw_seq =
  9460. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  9461. DRV_MSG_SEQ_NUMBER_MASK;
  9462. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9463. bnx2x_prev_unload(bp);
  9464. }
  9465. if (CHIP_REV_IS_FPGA(bp))
  9466. dev_err(&bp->pdev->dev, "FPGA detected\n");
  9467. if (BP_NOMCP(bp) && (func == 0))
  9468. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  9469. bp->disable_tpa = disable_tpa;
  9470. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  9471. /* Set TPA flags */
  9472. if (bp->disable_tpa) {
  9473. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9474. bp->dev->features &= ~NETIF_F_LRO;
  9475. } else {
  9476. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9477. bp->dev->features |= NETIF_F_LRO;
  9478. }
  9479. if (CHIP_IS_E1(bp))
  9480. bp->dropless_fc = 0;
  9481. else
  9482. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  9483. bp->mrrs = mrrs;
  9484. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  9485. if (IS_VF(bp))
  9486. bp->rx_ring_size = MAX_RX_AVAIL;
  9487. /* make sure that the numbers are in the right granularity */
  9488. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  9489. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  9490. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  9491. init_timer(&bp->timer);
  9492. bp->timer.expires = jiffies + bp->current_interval;
  9493. bp->timer.data = (unsigned long) bp;
  9494. bp->timer.function = bnx2x_timer;
  9495. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  9496. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  9497. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  9498. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
  9499. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  9500. bnx2x_dcbx_init_params(bp);
  9501. } else {
  9502. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  9503. }
  9504. if (CHIP_IS_E1x(bp))
  9505. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  9506. else
  9507. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  9508. /* multiple tx priority */
  9509. if (IS_VF(bp))
  9510. bp->max_cos = 1;
  9511. else if (CHIP_IS_E1x(bp))
  9512. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  9513. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  9514. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  9515. else if (CHIP_IS_E3B0(bp))
  9516. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  9517. else
  9518. BNX2X_ERR("unknown chip %x revision %x\n",
  9519. CHIP_NUM(bp), CHIP_REV(bp));
  9520. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  9521. /* We need at least one default status block for slow-path events,
  9522. * second status block for the L2 queue, and a third status block for
  9523. * CNIC if supproted.
  9524. */
  9525. if (CNIC_SUPPORT(bp))
  9526. bp->min_msix_vec_cnt = 3;
  9527. else
  9528. bp->min_msix_vec_cnt = 2;
  9529. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  9530. return rc;
  9531. }
  9532. /****************************************************************************
  9533. * General service functions
  9534. ****************************************************************************/
  9535. /*
  9536. * net_device service functions
  9537. */
  9538. static int bnx2x_open_epilog(struct bnx2x *bp)
  9539. {
  9540. /* Enable sriov via delayed work. This must be done via delayed work
  9541. * because it causes the probe of the vf devices to be run, which invoke
  9542. * register_netdevice which must have rtnl lock taken. As we are holding
  9543. * the lock right now, that could only work if the probe would not take
  9544. * the lock. However, as the probe of the vf may be called from other
  9545. * contexts as well (such as passthrough to vm failes) it can't assume
  9546. * the lock is being held for it. Using delayed work here allows the
  9547. * probe code to simply take the lock (i.e. wait for it to be released
  9548. * if it is being held).
  9549. */
  9550. smp_mb__before_clear_bit();
  9551. set_bit(BNX2X_SP_RTNL_ENABLE_SRIOV, &bp->sp_rtnl_state);
  9552. smp_mb__after_clear_bit();
  9553. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  9554. return 0;
  9555. }
  9556. /* called with rtnl_lock */
  9557. static int bnx2x_open(struct net_device *dev)
  9558. {
  9559. struct bnx2x *bp = netdev_priv(dev);
  9560. bool global = false;
  9561. int other_engine = BP_PATH(bp) ? 0 : 1;
  9562. bool other_load_status, load_status;
  9563. int rc;
  9564. bp->stats_init = true;
  9565. netif_carrier_off(dev);
  9566. bnx2x_set_power_state(bp, PCI_D0);
  9567. /* If parity had happen during the unload, then attentions
  9568. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  9569. * want the first function loaded on the current engine to
  9570. * complete the recovery.
  9571. * Parity recovery is only relevant for PF driver.
  9572. */
  9573. if (IS_PF(bp)) {
  9574. other_load_status = bnx2x_get_load_status(bp, other_engine);
  9575. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  9576. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  9577. bnx2x_chk_parity_attn(bp, &global, true)) {
  9578. do {
  9579. /* If there are attentions and they are in a
  9580. * global blocks, set the GLOBAL_RESET bit
  9581. * regardless whether it will be this function
  9582. * that will complete the recovery or not.
  9583. */
  9584. if (global)
  9585. bnx2x_set_reset_global(bp);
  9586. /* Only the first function on the current
  9587. * engine should try to recover in open. In case
  9588. * of attentions in global blocks only the first
  9589. * in the chip should try to recover.
  9590. */
  9591. if ((!load_status &&
  9592. (!global || !other_load_status)) &&
  9593. bnx2x_trylock_leader_lock(bp) &&
  9594. !bnx2x_leader_reset(bp)) {
  9595. netdev_info(bp->dev,
  9596. "Recovered in open\n");
  9597. break;
  9598. }
  9599. /* recovery has failed... */
  9600. bnx2x_set_power_state(bp, PCI_D3hot);
  9601. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  9602. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  9603. "If you still see this message after a few retries then power cycle is required.\n");
  9604. return -EAGAIN;
  9605. } while (0);
  9606. }
  9607. }
  9608. bp->recovery_state = BNX2X_RECOVERY_DONE;
  9609. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  9610. if (rc)
  9611. return rc;
  9612. return bnx2x_open_epilog(bp);
  9613. }
  9614. /* called with rtnl_lock */
  9615. static int bnx2x_close(struct net_device *dev)
  9616. {
  9617. struct bnx2x *bp = netdev_priv(dev);
  9618. /* Unload the driver, release IRQs */
  9619. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  9620. /* Power off */
  9621. bnx2x_set_power_state(bp, PCI_D3hot);
  9622. return 0;
  9623. }
  9624. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  9625. struct bnx2x_mcast_ramrod_params *p)
  9626. {
  9627. int mc_count = netdev_mc_count(bp->dev);
  9628. struct bnx2x_mcast_list_elem *mc_mac =
  9629. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  9630. struct netdev_hw_addr *ha;
  9631. if (!mc_mac)
  9632. return -ENOMEM;
  9633. INIT_LIST_HEAD(&p->mcast_list);
  9634. netdev_for_each_mc_addr(ha, bp->dev) {
  9635. mc_mac->mac = bnx2x_mc_addr(ha);
  9636. list_add_tail(&mc_mac->link, &p->mcast_list);
  9637. mc_mac++;
  9638. }
  9639. p->mcast_list_len = mc_count;
  9640. return 0;
  9641. }
  9642. static void bnx2x_free_mcast_macs_list(
  9643. struct bnx2x_mcast_ramrod_params *p)
  9644. {
  9645. struct bnx2x_mcast_list_elem *mc_mac =
  9646. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  9647. link);
  9648. WARN_ON(!mc_mac);
  9649. kfree(mc_mac);
  9650. }
  9651. /**
  9652. * bnx2x_set_uc_list - configure a new unicast MACs list.
  9653. *
  9654. * @bp: driver handle
  9655. *
  9656. * We will use zero (0) as a MAC type for these MACs.
  9657. */
  9658. static int bnx2x_set_uc_list(struct bnx2x *bp)
  9659. {
  9660. int rc;
  9661. struct net_device *dev = bp->dev;
  9662. struct netdev_hw_addr *ha;
  9663. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  9664. unsigned long ramrod_flags = 0;
  9665. /* First schedule a cleanup up of old configuration */
  9666. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  9667. if (rc < 0) {
  9668. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  9669. return rc;
  9670. }
  9671. netdev_for_each_uc_addr(ha, dev) {
  9672. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  9673. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9674. if (rc == -EEXIST) {
  9675. DP(BNX2X_MSG_SP,
  9676. "Failed to schedule ADD operations: %d\n", rc);
  9677. /* do not treat adding same MAC as error */
  9678. rc = 0;
  9679. } else if (rc < 0) {
  9680. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  9681. rc);
  9682. return rc;
  9683. }
  9684. }
  9685. /* Execute the pending commands */
  9686. __set_bit(RAMROD_CONT, &ramrod_flags);
  9687. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  9688. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9689. }
  9690. static int bnx2x_set_mc_list(struct bnx2x *bp)
  9691. {
  9692. struct net_device *dev = bp->dev;
  9693. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  9694. int rc = 0;
  9695. rparam.mcast_obj = &bp->mcast_obj;
  9696. /* first, clear all configured multicast MACs */
  9697. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  9698. if (rc < 0) {
  9699. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  9700. return rc;
  9701. }
  9702. /* then, configure a new MACs list */
  9703. if (netdev_mc_count(dev)) {
  9704. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  9705. if (rc) {
  9706. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  9707. rc);
  9708. return rc;
  9709. }
  9710. /* Now add the new MACs */
  9711. rc = bnx2x_config_mcast(bp, &rparam,
  9712. BNX2X_MCAST_CMD_ADD);
  9713. if (rc < 0)
  9714. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  9715. rc);
  9716. bnx2x_free_mcast_macs_list(&rparam);
  9717. }
  9718. return rc;
  9719. }
  9720. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  9721. void bnx2x_set_rx_mode(struct net_device *dev)
  9722. {
  9723. struct bnx2x *bp = netdev_priv(dev);
  9724. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  9725. if (bp->state != BNX2X_STATE_OPEN) {
  9726. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  9727. return;
  9728. }
  9729. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  9730. if (dev->flags & IFF_PROMISC)
  9731. rx_mode = BNX2X_RX_MODE_PROMISC;
  9732. else if ((dev->flags & IFF_ALLMULTI) ||
  9733. ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
  9734. CHIP_IS_E1(bp)))
  9735. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9736. else {
  9737. if (IS_PF(bp)) {
  9738. /* some multicasts */
  9739. if (bnx2x_set_mc_list(bp) < 0)
  9740. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9741. if (bnx2x_set_uc_list(bp) < 0)
  9742. rx_mode = BNX2X_RX_MODE_PROMISC;
  9743. } else {
  9744. /* configuring mcast to a vf involves sleeping (when we
  9745. * wait for the pf's response). Since this function is
  9746. * called from non sleepable context we must schedule
  9747. * a work item for this purpose
  9748. */
  9749. smp_mb__before_clear_bit();
  9750. set_bit(BNX2X_SP_RTNL_VFPF_MCAST,
  9751. &bp->sp_rtnl_state);
  9752. smp_mb__after_clear_bit();
  9753. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  9754. }
  9755. }
  9756. bp->rx_mode = rx_mode;
  9757. /* handle ISCSI SD mode */
  9758. if (IS_MF_ISCSI_SD(bp))
  9759. bp->rx_mode = BNX2X_RX_MODE_NONE;
  9760. /* Schedule the rx_mode command */
  9761. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  9762. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  9763. return;
  9764. }
  9765. if (IS_PF(bp)) {
  9766. bnx2x_set_storm_rx_mode(bp);
  9767. } else {
  9768. /* configuring rx mode to storms in a vf involves sleeping (when
  9769. * we wait for the pf's response). Since this function is
  9770. * called from non sleepable context we must schedule
  9771. * a work item for this purpose
  9772. */
  9773. smp_mb__before_clear_bit();
  9774. set_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
  9775. &bp->sp_rtnl_state);
  9776. smp_mb__after_clear_bit();
  9777. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  9778. }
  9779. }
  9780. /* called with rtnl_lock */
  9781. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  9782. int devad, u16 addr)
  9783. {
  9784. struct bnx2x *bp = netdev_priv(netdev);
  9785. u16 value;
  9786. int rc;
  9787. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  9788. prtad, devad, addr);
  9789. /* The HW expects different devad if CL22 is used */
  9790. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9791. bnx2x_acquire_phy_lock(bp);
  9792. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  9793. bnx2x_release_phy_lock(bp);
  9794. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  9795. if (!rc)
  9796. rc = value;
  9797. return rc;
  9798. }
  9799. /* called with rtnl_lock */
  9800. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  9801. u16 addr, u16 value)
  9802. {
  9803. struct bnx2x *bp = netdev_priv(netdev);
  9804. int rc;
  9805. DP(NETIF_MSG_LINK,
  9806. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  9807. prtad, devad, addr, value);
  9808. /* The HW expects different devad if CL22 is used */
  9809. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9810. bnx2x_acquire_phy_lock(bp);
  9811. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  9812. bnx2x_release_phy_lock(bp);
  9813. return rc;
  9814. }
  9815. /* called with rtnl_lock */
  9816. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  9817. {
  9818. struct bnx2x *bp = netdev_priv(dev);
  9819. struct mii_ioctl_data *mdio = if_mii(ifr);
  9820. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  9821. mdio->phy_id, mdio->reg_num, mdio->val_in);
  9822. if (!netif_running(dev))
  9823. return -EAGAIN;
  9824. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  9825. }
  9826. #ifdef CONFIG_NET_POLL_CONTROLLER
  9827. static void poll_bnx2x(struct net_device *dev)
  9828. {
  9829. struct bnx2x *bp = netdev_priv(dev);
  9830. int i;
  9831. for_each_eth_queue(bp, i) {
  9832. struct bnx2x_fastpath *fp = &bp->fp[i];
  9833. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  9834. }
  9835. }
  9836. #endif
  9837. static int bnx2x_validate_addr(struct net_device *dev)
  9838. {
  9839. struct bnx2x *bp = netdev_priv(dev);
  9840. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  9841. BNX2X_ERR("Non-valid Ethernet address\n");
  9842. return -EADDRNOTAVAIL;
  9843. }
  9844. return 0;
  9845. }
  9846. static const struct net_device_ops bnx2x_netdev_ops = {
  9847. .ndo_open = bnx2x_open,
  9848. .ndo_stop = bnx2x_close,
  9849. .ndo_start_xmit = bnx2x_start_xmit,
  9850. .ndo_select_queue = bnx2x_select_queue,
  9851. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  9852. .ndo_set_mac_address = bnx2x_change_mac_addr,
  9853. .ndo_validate_addr = bnx2x_validate_addr,
  9854. .ndo_do_ioctl = bnx2x_ioctl,
  9855. .ndo_change_mtu = bnx2x_change_mtu,
  9856. .ndo_fix_features = bnx2x_fix_features,
  9857. .ndo_set_features = bnx2x_set_features,
  9858. .ndo_tx_timeout = bnx2x_tx_timeout,
  9859. #ifdef CONFIG_NET_POLL_CONTROLLER
  9860. .ndo_poll_controller = poll_bnx2x,
  9861. #endif
  9862. .ndo_setup_tc = bnx2x_setup_tc,
  9863. #ifdef CONFIG_BNX2X_SRIOV
  9864. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  9865. #endif
  9866. #ifdef NETDEV_FCOE_WWNN
  9867. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  9868. #endif
  9869. };
  9870. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  9871. {
  9872. struct device *dev = &bp->pdev->dev;
  9873. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  9874. bp->flags |= USING_DAC_FLAG;
  9875. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  9876. dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
  9877. return -EIO;
  9878. }
  9879. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  9880. dev_err(dev, "System does not support DMA, aborting\n");
  9881. return -EIO;
  9882. }
  9883. return 0;
  9884. }
  9885. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  9886. struct net_device *dev, unsigned long board_type)
  9887. {
  9888. int rc;
  9889. u32 pci_cfg_dword;
  9890. bool chip_is_e1x = (board_type == BCM57710 ||
  9891. board_type == BCM57711 ||
  9892. board_type == BCM57711E);
  9893. SET_NETDEV_DEV(dev, &pdev->dev);
  9894. bp->dev = dev;
  9895. bp->pdev = pdev;
  9896. rc = pci_enable_device(pdev);
  9897. if (rc) {
  9898. dev_err(&bp->pdev->dev,
  9899. "Cannot enable PCI device, aborting\n");
  9900. goto err_out;
  9901. }
  9902. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  9903. dev_err(&bp->pdev->dev,
  9904. "Cannot find PCI device base address, aborting\n");
  9905. rc = -ENODEV;
  9906. goto err_out_disable;
  9907. }
  9908. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  9909. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  9910. rc = -ENODEV;
  9911. goto err_out_disable;
  9912. }
  9913. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  9914. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  9915. PCICFG_REVESION_ID_ERROR_VAL) {
  9916. pr_err("PCI device error, probably due to fan failure, aborting\n");
  9917. rc = -ENODEV;
  9918. goto err_out_disable;
  9919. }
  9920. if (atomic_read(&pdev->enable_cnt) == 1) {
  9921. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  9922. if (rc) {
  9923. dev_err(&bp->pdev->dev,
  9924. "Cannot obtain PCI resources, aborting\n");
  9925. goto err_out_disable;
  9926. }
  9927. pci_set_master(pdev);
  9928. pci_save_state(pdev);
  9929. }
  9930. if (IS_PF(bp)) {
  9931. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  9932. if (bp->pm_cap == 0) {
  9933. dev_err(&bp->pdev->dev,
  9934. "Cannot find power management capability, aborting\n");
  9935. rc = -EIO;
  9936. goto err_out_release;
  9937. }
  9938. }
  9939. if (!pci_is_pcie(pdev)) {
  9940. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  9941. rc = -EIO;
  9942. goto err_out_release;
  9943. }
  9944. rc = bnx2x_set_coherency_mask(bp);
  9945. if (rc)
  9946. goto err_out_release;
  9947. dev->mem_start = pci_resource_start(pdev, 0);
  9948. dev->base_addr = dev->mem_start;
  9949. dev->mem_end = pci_resource_end(pdev, 0);
  9950. dev->irq = pdev->irq;
  9951. bp->regview = pci_ioremap_bar(pdev, 0);
  9952. if (!bp->regview) {
  9953. dev_err(&bp->pdev->dev,
  9954. "Cannot map register space, aborting\n");
  9955. rc = -ENOMEM;
  9956. goto err_out_release;
  9957. }
  9958. /* In E1/E1H use pci device function given by kernel.
  9959. * In E2/E3 read physical function from ME register since these chips
  9960. * support Physical Device Assignment where kernel BDF maybe arbitrary
  9961. * (depending on hypervisor).
  9962. */
  9963. if (chip_is_e1x) {
  9964. bp->pf_num = PCI_FUNC(pdev->devfn);
  9965. } else {
  9966. /* chip is E2/3*/
  9967. pci_read_config_dword(bp->pdev,
  9968. PCICFG_ME_REGISTER, &pci_cfg_dword);
  9969. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  9970. ME_REG_ABS_PF_NUM_SHIFT);
  9971. }
  9972. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  9973. bnx2x_set_power_state(bp, PCI_D0);
  9974. /* clean indirect addresses */
  9975. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  9976. PCICFG_VENDOR_ID_OFFSET);
  9977. /*
  9978. * Clean the following indirect addresses for all functions since it
  9979. * is not used by the driver.
  9980. */
  9981. if (IS_PF(bp)) {
  9982. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  9983. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  9984. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  9985. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  9986. if (chip_is_e1x) {
  9987. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  9988. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  9989. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  9990. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  9991. }
  9992. /* Enable internal target-read (in case we are probed after PF
  9993. * FLR). Must be done prior to any BAR read access. Only for
  9994. * 57712 and up
  9995. */
  9996. if (!chip_is_e1x)
  9997. REG_WR(bp,
  9998. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  9999. }
  10000. dev->watchdog_timeo = TX_TIMEOUT;
  10001. dev->netdev_ops = &bnx2x_netdev_ops;
  10002. bnx2x_set_ethtool_ops(dev);
  10003. dev->priv_flags |= IFF_UNICAST_FLT;
  10004. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10005. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10006. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  10007. NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
  10008. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10009. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  10010. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
  10011. if (bp->flags & USING_DAC_FLAG)
  10012. dev->features |= NETIF_F_HIGHDMA;
  10013. /* Add Loopback capability to the device */
  10014. dev->hw_features |= NETIF_F_LOOPBACK;
  10015. #ifdef BCM_DCBNL
  10016. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  10017. #endif
  10018. /* get_port_hwinfo() will set prtad and mmds properly */
  10019. bp->mdio.prtad = MDIO_PRTAD_NONE;
  10020. bp->mdio.mmds = 0;
  10021. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  10022. bp->mdio.dev = dev;
  10023. bp->mdio.mdio_read = bnx2x_mdio_read;
  10024. bp->mdio.mdio_write = bnx2x_mdio_write;
  10025. return 0;
  10026. err_out_release:
  10027. if (atomic_read(&pdev->enable_cnt) == 1)
  10028. pci_release_regions(pdev);
  10029. err_out_disable:
  10030. pci_disable_device(pdev);
  10031. pci_set_drvdata(pdev, NULL);
  10032. err_out:
  10033. return rc;
  10034. }
  10035. static void bnx2x_get_pcie_width_speed(struct bnx2x *bp, int *width, int *speed)
  10036. {
  10037. u32 val = 0;
  10038. pci_read_config_dword(bp->pdev, PCICFG_LINK_CONTROL, &val);
  10039. *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  10040. /* return value of 1=2.5GHz 2=5GHz */
  10041. *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  10042. }
  10043. static int bnx2x_check_firmware(struct bnx2x *bp)
  10044. {
  10045. const struct firmware *firmware = bp->firmware;
  10046. struct bnx2x_fw_file_hdr *fw_hdr;
  10047. struct bnx2x_fw_file_section *sections;
  10048. u32 offset, len, num_ops;
  10049. __be16 *ops_offsets;
  10050. int i;
  10051. const u8 *fw_ver;
  10052. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  10053. BNX2X_ERR("Wrong FW size\n");
  10054. return -EINVAL;
  10055. }
  10056. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  10057. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  10058. /* Make sure none of the offsets and sizes make us read beyond
  10059. * the end of the firmware data */
  10060. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  10061. offset = be32_to_cpu(sections[i].offset);
  10062. len = be32_to_cpu(sections[i].len);
  10063. if (offset + len > firmware->size) {
  10064. BNX2X_ERR("Section %d length is out of bounds\n", i);
  10065. return -EINVAL;
  10066. }
  10067. }
  10068. /* Likewise for the init_ops offsets */
  10069. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  10070. ops_offsets = (__force __be16 *)(firmware->data + offset);
  10071. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  10072. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  10073. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  10074. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  10075. return -EINVAL;
  10076. }
  10077. }
  10078. /* Check FW version */
  10079. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  10080. fw_ver = firmware->data + offset;
  10081. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  10082. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  10083. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  10084. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  10085. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  10086. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  10087. BCM_5710_FW_MAJOR_VERSION,
  10088. BCM_5710_FW_MINOR_VERSION,
  10089. BCM_5710_FW_REVISION_VERSION,
  10090. BCM_5710_FW_ENGINEERING_VERSION);
  10091. return -EINVAL;
  10092. }
  10093. return 0;
  10094. }
  10095. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10096. {
  10097. const __be32 *source = (const __be32 *)_source;
  10098. u32 *target = (u32 *)_target;
  10099. u32 i;
  10100. for (i = 0; i < n/4; i++)
  10101. target[i] = be32_to_cpu(source[i]);
  10102. }
  10103. /*
  10104. Ops array is stored in the following format:
  10105. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  10106. */
  10107. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  10108. {
  10109. const __be32 *source = (const __be32 *)_source;
  10110. struct raw_op *target = (struct raw_op *)_target;
  10111. u32 i, j, tmp;
  10112. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  10113. tmp = be32_to_cpu(source[j]);
  10114. target[i].op = (tmp >> 24) & 0xff;
  10115. target[i].offset = tmp & 0xffffff;
  10116. target[i].raw_data = be32_to_cpu(source[j + 1]);
  10117. }
  10118. }
  10119. /* IRO array is stored in the following format:
  10120. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  10121. */
  10122. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  10123. {
  10124. const __be32 *source = (const __be32 *)_source;
  10125. struct iro *target = (struct iro *)_target;
  10126. u32 i, j, tmp;
  10127. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  10128. target[i].base = be32_to_cpu(source[j]);
  10129. j++;
  10130. tmp = be32_to_cpu(source[j]);
  10131. target[i].m1 = (tmp >> 16) & 0xffff;
  10132. target[i].m2 = tmp & 0xffff;
  10133. j++;
  10134. tmp = be32_to_cpu(source[j]);
  10135. target[i].m3 = (tmp >> 16) & 0xffff;
  10136. target[i].size = tmp & 0xffff;
  10137. j++;
  10138. }
  10139. }
  10140. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10141. {
  10142. const __be16 *source = (const __be16 *)_source;
  10143. u16 *target = (u16 *)_target;
  10144. u32 i;
  10145. for (i = 0; i < n/2; i++)
  10146. target[i] = be16_to_cpu(source[i]);
  10147. }
  10148. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  10149. do { \
  10150. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  10151. bp->arr = kmalloc(len, GFP_KERNEL); \
  10152. if (!bp->arr) \
  10153. goto lbl; \
  10154. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  10155. (u8 *)bp->arr, len); \
  10156. } while (0)
  10157. static int bnx2x_init_firmware(struct bnx2x *bp)
  10158. {
  10159. const char *fw_file_name;
  10160. struct bnx2x_fw_file_hdr *fw_hdr;
  10161. int rc;
  10162. if (bp->firmware)
  10163. return 0;
  10164. if (CHIP_IS_E1(bp))
  10165. fw_file_name = FW_FILE_NAME_E1;
  10166. else if (CHIP_IS_E1H(bp))
  10167. fw_file_name = FW_FILE_NAME_E1H;
  10168. else if (!CHIP_IS_E1x(bp))
  10169. fw_file_name = FW_FILE_NAME_E2;
  10170. else {
  10171. BNX2X_ERR("Unsupported chip revision\n");
  10172. return -EINVAL;
  10173. }
  10174. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  10175. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  10176. if (rc) {
  10177. BNX2X_ERR("Can't load firmware file %s\n",
  10178. fw_file_name);
  10179. goto request_firmware_exit;
  10180. }
  10181. rc = bnx2x_check_firmware(bp);
  10182. if (rc) {
  10183. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  10184. goto request_firmware_exit;
  10185. }
  10186. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  10187. /* Initialize the pointers to the init arrays */
  10188. /* Blob */
  10189. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  10190. /* Opcodes */
  10191. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  10192. /* Offsets */
  10193. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  10194. be16_to_cpu_n);
  10195. /* STORMs firmware */
  10196. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10197. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  10198. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  10199. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  10200. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10201. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  10202. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  10203. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  10204. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10205. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  10206. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  10207. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  10208. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10209. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  10210. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  10211. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  10212. /* IRO */
  10213. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  10214. return 0;
  10215. iro_alloc_err:
  10216. kfree(bp->init_ops_offsets);
  10217. init_offsets_alloc_err:
  10218. kfree(bp->init_ops);
  10219. init_ops_alloc_err:
  10220. kfree(bp->init_data);
  10221. request_firmware_exit:
  10222. release_firmware(bp->firmware);
  10223. bp->firmware = NULL;
  10224. return rc;
  10225. }
  10226. static void bnx2x_release_firmware(struct bnx2x *bp)
  10227. {
  10228. kfree(bp->init_ops_offsets);
  10229. kfree(bp->init_ops);
  10230. kfree(bp->init_data);
  10231. release_firmware(bp->firmware);
  10232. bp->firmware = NULL;
  10233. }
  10234. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  10235. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  10236. .init_hw_cmn = bnx2x_init_hw_common,
  10237. .init_hw_port = bnx2x_init_hw_port,
  10238. .init_hw_func = bnx2x_init_hw_func,
  10239. .reset_hw_cmn = bnx2x_reset_common,
  10240. .reset_hw_port = bnx2x_reset_port,
  10241. .reset_hw_func = bnx2x_reset_func,
  10242. .gunzip_init = bnx2x_gunzip_init,
  10243. .gunzip_end = bnx2x_gunzip_end,
  10244. .init_fw = bnx2x_init_firmware,
  10245. .release_fw = bnx2x_release_firmware,
  10246. };
  10247. void bnx2x__init_func_obj(struct bnx2x *bp)
  10248. {
  10249. /* Prepare DMAE related driver resources */
  10250. bnx2x_setup_dmae(bp);
  10251. bnx2x_init_func_obj(bp, &bp->func_obj,
  10252. bnx2x_sp(bp, func_rdata),
  10253. bnx2x_sp_mapping(bp, func_rdata),
  10254. bnx2x_sp(bp, func_afex_rdata),
  10255. bnx2x_sp_mapping(bp, func_afex_rdata),
  10256. &bnx2x_func_sp_drv);
  10257. }
  10258. /* must be called after sriov-enable */
  10259. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  10260. {
  10261. int cid_count = BNX2X_L2_MAX_CID(bp);
  10262. if (IS_SRIOV(bp))
  10263. cid_count += BNX2X_VF_CIDS;
  10264. if (CNIC_SUPPORT(bp))
  10265. cid_count += CNIC_CID_MAX;
  10266. return roundup(cid_count, QM_CID_ROUND);
  10267. }
  10268. /**
  10269. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  10270. *
  10271. * @dev: pci device
  10272. *
  10273. */
  10274. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev,
  10275. int cnic_cnt, bool is_vf)
  10276. {
  10277. int pos, index;
  10278. u16 control = 0;
  10279. pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  10280. /*
  10281. * If MSI-X is not supported - return number of SBs needed to support
  10282. * one fast path queue: one FP queue + SB for CNIC
  10283. */
  10284. if (!pos) {
  10285. dev_info(&pdev->dev, "no msix capability found\n");
  10286. return 1 + cnic_cnt;
  10287. }
  10288. dev_info(&pdev->dev, "msix capability found\n");
  10289. /*
  10290. * The value in the PCI configuration space is the index of the last
  10291. * entry, namely one less than the actual size of the table, which is
  10292. * exactly what we want to return from this function: number of all SBs
  10293. * without the default SB.
  10294. * For VFs there is no default SB, then we return (index+1).
  10295. */
  10296. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
  10297. index = control & PCI_MSIX_FLAGS_QSIZE;
  10298. return is_vf ? index + 1 : index;
  10299. }
  10300. static int set_max_cos_est(int chip_id)
  10301. {
  10302. switch (chip_id) {
  10303. case BCM57710:
  10304. case BCM57711:
  10305. case BCM57711E:
  10306. return BNX2X_MULTI_TX_COS_E1X;
  10307. case BCM57712:
  10308. case BCM57712_MF:
  10309. case BCM57712_VF:
  10310. return BNX2X_MULTI_TX_COS_E2_E3A0;
  10311. case BCM57800:
  10312. case BCM57800_MF:
  10313. case BCM57800_VF:
  10314. case BCM57810:
  10315. case BCM57810_MF:
  10316. case BCM57840_4_10:
  10317. case BCM57840_2_20:
  10318. case BCM57840_O:
  10319. case BCM57840_MFO:
  10320. case BCM57810_VF:
  10321. case BCM57840_MF:
  10322. case BCM57840_VF:
  10323. case BCM57811:
  10324. case BCM57811_MF:
  10325. case BCM57811_VF:
  10326. return BNX2X_MULTI_TX_COS_E3B0;
  10327. return 1;
  10328. default:
  10329. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  10330. return -ENODEV;
  10331. }
  10332. }
  10333. static int set_is_vf(int chip_id)
  10334. {
  10335. switch (chip_id) {
  10336. case BCM57712_VF:
  10337. case BCM57800_VF:
  10338. case BCM57810_VF:
  10339. case BCM57840_VF:
  10340. case BCM57811_VF:
  10341. return true;
  10342. default:
  10343. return false;
  10344. }
  10345. }
  10346. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  10347. static int bnx2x_init_one(struct pci_dev *pdev,
  10348. const struct pci_device_id *ent)
  10349. {
  10350. struct net_device *dev = NULL;
  10351. struct bnx2x *bp;
  10352. int pcie_width, pcie_speed;
  10353. int rc, max_non_def_sbs;
  10354. int rx_count, tx_count, rss_count, doorbell_size;
  10355. int max_cos_est;
  10356. bool is_vf;
  10357. int cnic_cnt;
  10358. /* An estimated maximum supported CoS number according to the chip
  10359. * version.
  10360. * We will try to roughly estimate the maximum number of CoSes this chip
  10361. * may support in order to minimize the memory allocated for Tx
  10362. * netdev_queue's. This number will be accurately calculated during the
  10363. * initialization of bp->max_cos based on the chip versions AND chip
  10364. * revision in the bnx2x_init_bp().
  10365. */
  10366. max_cos_est = set_max_cos_est(ent->driver_data);
  10367. if (max_cos_est < 0)
  10368. return max_cos_est;
  10369. is_vf = set_is_vf(ent->driver_data);
  10370. cnic_cnt = is_vf ? 0 : 1;
  10371. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt, is_vf);
  10372. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  10373. rss_count = is_vf ? 1 : max_non_def_sbs - cnic_cnt;
  10374. if (rss_count < 1)
  10375. return -EINVAL;
  10376. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  10377. rx_count = rss_count + cnic_cnt;
  10378. /* Maximum number of netdev Tx queues:
  10379. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  10380. */
  10381. tx_count = rss_count * max_cos_est + cnic_cnt;
  10382. /* dev zeroed in init_etherdev */
  10383. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  10384. if (!dev)
  10385. return -ENOMEM;
  10386. bp = netdev_priv(dev);
  10387. bp->flags = 0;
  10388. if (is_vf)
  10389. bp->flags |= IS_VF_FLAG;
  10390. bp->igu_sb_cnt = max_non_def_sbs;
  10391. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  10392. bp->msg_enable = debug;
  10393. bp->cnic_support = cnic_cnt;
  10394. bp->cnic_probe = bnx2x_cnic_probe;
  10395. pci_set_drvdata(pdev, dev);
  10396. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  10397. if (rc < 0) {
  10398. free_netdev(dev);
  10399. return rc;
  10400. }
  10401. BNX2X_DEV_INFO("This is a %s function\n",
  10402. IS_PF(bp) ? "physical" : "virtual");
  10403. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  10404. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  10405. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  10406. tx_count, rx_count);
  10407. rc = bnx2x_init_bp(bp);
  10408. if (rc)
  10409. goto init_one_exit;
  10410. /* Map doorbells here as we need the real value of bp->max_cos which
  10411. * is initialized in bnx2x_init_bp() to determine the number of
  10412. * l2 connections.
  10413. */
  10414. if (IS_VF(bp)) {
  10415. bnx2x_vf_map_doorbells(bp);
  10416. rc = bnx2x_vf_pci_alloc(bp);
  10417. if (rc)
  10418. goto init_one_exit;
  10419. } else {
  10420. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  10421. if (doorbell_size > pci_resource_len(pdev, 2)) {
  10422. dev_err(&bp->pdev->dev,
  10423. "Cannot map doorbells, bar size too small, aborting\n");
  10424. rc = -ENOMEM;
  10425. goto init_one_exit;
  10426. }
  10427. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  10428. doorbell_size);
  10429. }
  10430. if (!bp->doorbells) {
  10431. dev_err(&bp->pdev->dev,
  10432. "Cannot map doorbell space, aborting\n");
  10433. rc = -ENOMEM;
  10434. goto init_one_exit;
  10435. }
  10436. if (IS_VF(bp)) {
  10437. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  10438. if (rc)
  10439. goto init_one_exit;
  10440. }
  10441. /* Enable SRIOV if capability found in configuration space.
  10442. * Once the generic SR-IOV framework makes it in from the
  10443. * pci tree this will be revised, to allow dynamic control
  10444. * over the number of VFs. Right now, change the num of vfs
  10445. * param below to enable SR-IOV.
  10446. */
  10447. rc = bnx2x_iov_init_one(bp, int_mode, 0/*num vfs*/);
  10448. if (rc)
  10449. goto init_one_exit;
  10450. /* calc qm_cid_count */
  10451. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  10452. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  10453. /* disable FCOE L2 queue for E1x*/
  10454. if (CHIP_IS_E1x(bp))
  10455. bp->flags |= NO_FCOE_FLAG;
  10456. /* disable FCOE for 57840 device, until FW supports it */
  10457. switch (ent->driver_data) {
  10458. case BCM57840_O:
  10459. case BCM57840_4_10:
  10460. case BCM57840_2_20:
  10461. case BCM57840_MFO:
  10462. case BCM57840_MF:
  10463. bp->flags |= NO_FCOE_FLAG;
  10464. }
  10465. /* Set bp->num_queues for MSI-X mode*/
  10466. bnx2x_set_num_queues(bp);
  10467. /* Configure interrupt mode: try to enable MSI-X/MSI if
  10468. * needed.
  10469. */
  10470. rc = bnx2x_set_int_mode(bp);
  10471. if (rc) {
  10472. dev_err(&pdev->dev, "Cannot set interrupts\n");
  10473. goto init_one_exit;
  10474. }
  10475. BNX2X_DEV_INFO("set interrupts successfully\n");
  10476. /* register the net device */
  10477. rc = register_netdev(dev);
  10478. if (rc) {
  10479. dev_err(&pdev->dev, "Cannot register net device\n");
  10480. goto init_one_exit;
  10481. }
  10482. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  10483. if (!NO_FCOE(bp)) {
  10484. /* Add storage MAC address */
  10485. rtnl_lock();
  10486. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10487. rtnl_unlock();
  10488. }
  10489. bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
  10490. BNX2X_DEV_INFO("got pcie width %d and speed %d\n",
  10491. pcie_width, pcie_speed);
  10492. BNX2X_DEV_INFO(
  10493. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  10494. board_info[ent->driver_data].name,
  10495. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  10496. pcie_width,
  10497. ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
  10498. (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
  10499. "5GHz (Gen2)" : "2.5GHz",
  10500. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  10501. return 0;
  10502. init_one_exit:
  10503. if (bp->regview)
  10504. iounmap(bp->regview);
  10505. if (IS_PF(bp) && bp->doorbells)
  10506. iounmap(bp->doorbells);
  10507. free_netdev(dev);
  10508. if (atomic_read(&pdev->enable_cnt) == 1)
  10509. pci_release_regions(pdev);
  10510. pci_disable_device(pdev);
  10511. pci_set_drvdata(pdev, NULL);
  10512. return rc;
  10513. }
  10514. static void bnx2x_remove_one(struct pci_dev *pdev)
  10515. {
  10516. struct net_device *dev = pci_get_drvdata(pdev);
  10517. struct bnx2x *bp;
  10518. if (!dev) {
  10519. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  10520. return;
  10521. }
  10522. bp = netdev_priv(dev);
  10523. /* Delete storage MAC address */
  10524. if (!NO_FCOE(bp)) {
  10525. rtnl_lock();
  10526. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10527. rtnl_unlock();
  10528. }
  10529. #ifdef BCM_DCBNL
  10530. /* Delete app tlvs from dcbnl */
  10531. bnx2x_dcbnl_update_applist(bp, true);
  10532. #endif
  10533. unregister_netdev(dev);
  10534. /* Power on: we can't let PCI layer write to us while we are in D3 */
  10535. if (IS_PF(bp))
  10536. bnx2x_set_power_state(bp, PCI_D0);
  10537. /* Disable MSI/MSI-X */
  10538. bnx2x_disable_msi(bp);
  10539. /* Power off */
  10540. if (IS_PF(bp))
  10541. bnx2x_set_power_state(bp, PCI_D3hot);
  10542. /* Make sure RESET task is not scheduled before continuing */
  10543. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  10544. bnx2x_iov_remove_one(bp);
  10545. /* send message via vfpf channel to release the resources of this vf */
  10546. if (IS_VF(bp))
  10547. bnx2x_vfpf_release(bp);
  10548. if (bp->regview)
  10549. iounmap(bp->regview);
  10550. /* for vf doorbells are part of the regview and were unmapped along with
  10551. * it. FW is only loaded by PF.
  10552. */
  10553. if (IS_PF(bp)) {
  10554. if (bp->doorbells)
  10555. iounmap(bp->doorbells);
  10556. bnx2x_release_firmware(bp);
  10557. }
  10558. bnx2x_free_mem_bp(bp);
  10559. free_netdev(dev);
  10560. if (atomic_read(&pdev->enable_cnt) == 1)
  10561. pci_release_regions(pdev);
  10562. pci_disable_device(pdev);
  10563. pci_set_drvdata(pdev, NULL);
  10564. }
  10565. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  10566. {
  10567. int i;
  10568. bp->state = BNX2X_STATE_ERROR;
  10569. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10570. if (CNIC_LOADED(bp))
  10571. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  10572. /* Stop Tx */
  10573. bnx2x_tx_disable(bp);
  10574. bnx2x_netif_stop(bp, 0);
  10575. /* Delete all NAPI objects */
  10576. bnx2x_del_all_napi(bp);
  10577. if (CNIC_LOADED(bp))
  10578. bnx2x_del_all_napi_cnic(bp);
  10579. del_timer_sync(&bp->timer);
  10580. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  10581. /* Release IRQs */
  10582. bnx2x_free_irq(bp);
  10583. /* Free SKBs, SGEs, TPA pool and driver internals */
  10584. bnx2x_free_skbs(bp);
  10585. for_each_rx_queue(bp, i)
  10586. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  10587. bnx2x_free_mem(bp);
  10588. bp->state = BNX2X_STATE_CLOSED;
  10589. netif_carrier_off(bp->dev);
  10590. return 0;
  10591. }
  10592. static void bnx2x_eeh_recover(struct bnx2x *bp)
  10593. {
  10594. u32 val;
  10595. mutex_init(&bp->port.phy_mutex);
  10596. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  10597. if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10598. != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10599. BNX2X_ERR("BAD MCP validity signature\n");
  10600. }
  10601. /**
  10602. * bnx2x_io_error_detected - called when PCI error is detected
  10603. * @pdev: Pointer to PCI device
  10604. * @state: The current pci connection state
  10605. *
  10606. * This function is called after a PCI bus error affecting
  10607. * this device has been detected.
  10608. */
  10609. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  10610. pci_channel_state_t state)
  10611. {
  10612. struct net_device *dev = pci_get_drvdata(pdev);
  10613. struct bnx2x *bp = netdev_priv(dev);
  10614. rtnl_lock();
  10615. netif_device_detach(dev);
  10616. if (state == pci_channel_io_perm_failure) {
  10617. rtnl_unlock();
  10618. return PCI_ERS_RESULT_DISCONNECT;
  10619. }
  10620. if (netif_running(dev))
  10621. bnx2x_eeh_nic_unload(bp);
  10622. pci_disable_device(pdev);
  10623. rtnl_unlock();
  10624. /* Request a slot reset */
  10625. return PCI_ERS_RESULT_NEED_RESET;
  10626. }
  10627. /**
  10628. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  10629. * @pdev: Pointer to PCI device
  10630. *
  10631. * Restart the card from scratch, as if from a cold-boot.
  10632. */
  10633. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  10634. {
  10635. struct net_device *dev = pci_get_drvdata(pdev);
  10636. struct bnx2x *bp = netdev_priv(dev);
  10637. rtnl_lock();
  10638. if (pci_enable_device(pdev)) {
  10639. dev_err(&pdev->dev,
  10640. "Cannot re-enable PCI device after reset\n");
  10641. rtnl_unlock();
  10642. return PCI_ERS_RESULT_DISCONNECT;
  10643. }
  10644. pci_set_master(pdev);
  10645. pci_restore_state(pdev);
  10646. if (netif_running(dev))
  10647. bnx2x_set_power_state(bp, PCI_D0);
  10648. rtnl_unlock();
  10649. return PCI_ERS_RESULT_RECOVERED;
  10650. }
  10651. /**
  10652. * bnx2x_io_resume - called when traffic can start flowing again
  10653. * @pdev: Pointer to PCI device
  10654. *
  10655. * This callback is called when the error recovery driver tells us that
  10656. * its OK to resume normal operation.
  10657. */
  10658. static void bnx2x_io_resume(struct pci_dev *pdev)
  10659. {
  10660. struct net_device *dev = pci_get_drvdata(pdev);
  10661. struct bnx2x *bp = netdev_priv(dev);
  10662. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  10663. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  10664. return;
  10665. }
  10666. rtnl_lock();
  10667. bnx2x_eeh_recover(bp);
  10668. if (netif_running(dev))
  10669. bnx2x_nic_load(bp, LOAD_NORMAL);
  10670. netif_device_attach(dev);
  10671. rtnl_unlock();
  10672. }
  10673. static const struct pci_error_handlers bnx2x_err_handler = {
  10674. .error_detected = bnx2x_io_error_detected,
  10675. .slot_reset = bnx2x_io_slot_reset,
  10676. .resume = bnx2x_io_resume,
  10677. };
  10678. static struct pci_driver bnx2x_pci_driver = {
  10679. .name = DRV_MODULE_NAME,
  10680. .id_table = bnx2x_pci_tbl,
  10681. .probe = bnx2x_init_one,
  10682. .remove = bnx2x_remove_one,
  10683. .suspend = bnx2x_suspend,
  10684. .resume = bnx2x_resume,
  10685. .err_handler = &bnx2x_err_handler,
  10686. };
  10687. static int __init bnx2x_init(void)
  10688. {
  10689. int ret;
  10690. pr_info("%s", version);
  10691. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  10692. if (bnx2x_wq == NULL) {
  10693. pr_err("Cannot create workqueue\n");
  10694. return -ENOMEM;
  10695. }
  10696. ret = pci_register_driver(&bnx2x_pci_driver);
  10697. if (ret) {
  10698. pr_err("Cannot register driver\n");
  10699. destroy_workqueue(bnx2x_wq);
  10700. }
  10701. return ret;
  10702. }
  10703. static void __exit bnx2x_cleanup(void)
  10704. {
  10705. struct list_head *pos, *q;
  10706. pci_unregister_driver(&bnx2x_pci_driver);
  10707. destroy_workqueue(bnx2x_wq);
  10708. /* Free globablly allocated resources */
  10709. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  10710. struct bnx2x_prev_path_list *tmp =
  10711. list_entry(pos, struct bnx2x_prev_path_list, list);
  10712. list_del(pos);
  10713. kfree(tmp);
  10714. }
  10715. }
  10716. void bnx2x_notify_link_changed(struct bnx2x *bp)
  10717. {
  10718. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  10719. }
  10720. module_init(bnx2x_init);
  10721. module_exit(bnx2x_cleanup);
  10722. /**
  10723. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  10724. *
  10725. * @bp: driver handle
  10726. * @set: set or clear the CAM entry
  10727. *
  10728. * This function will wait until the ramdord completion returns.
  10729. * Return 0 if success, -ENODEV if ramrod doesn't return.
  10730. */
  10731. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  10732. {
  10733. unsigned long ramrod_flags = 0;
  10734. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  10735. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  10736. &bp->iscsi_l2_mac_obj, true,
  10737. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  10738. }
  10739. /* count denotes the number of new completions we have seen */
  10740. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  10741. {
  10742. struct eth_spe *spe;
  10743. int cxt_index, cxt_offset;
  10744. #ifdef BNX2X_STOP_ON_ERROR
  10745. if (unlikely(bp->panic))
  10746. return;
  10747. #endif
  10748. spin_lock_bh(&bp->spq_lock);
  10749. BUG_ON(bp->cnic_spq_pending < count);
  10750. bp->cnic_spq_pending -= count;
  10751. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  10752. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  10753. & SPE_HDR_CONN_TYPE) >>
  10754. SPE_HDR_CONN_TYPE_SHIFT;
  10755. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  10756. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  10757. /* Set validation for iSCSI L2 client before sending SETUP
  10758. * ramrod
  10759. */
  10760. if (type == ETH_CONNECTION_TYPE) {
  10761. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  10762. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  10763. ILT_PAGE_CIDS;
  10764. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  10765. (cxt_index * ILT_PAGE_CIDS);
  10766. bnx2x_set_ctx_validation(bp,
  10767. &bp->context[cxt_index].
  10768. vcxt[cxt_offset].eth,
  10769. BNX2X_ISCSI_ETH_CID(bp));
  10770. }
  10771. }
  10772. /*
  10773. * There may be not more than 8 L2, not more than 8 L5 SPEs
  10774. * and in the air. We also check that number of outstanding
  10775. * COMMON ramrods is not more than the EQ and SPQ can
  10776. * accommodate.
  10777. */
  10778. if (type == ETH_CONNECTION_TYPE) {
  10779. if (!atomic_read(&bp->cq_spq_left))
  10780. break;
  10781. else
  10782. atomic_dec(&bp->cq_spq_left);
  10783. } else if (type == NONE_CONNECTION_TYPE) {
  10784. if (!atomic_read(&bp->eq_spq_left))
  10785. break;
  10786. else
  10787. atomic_dec(&bp->eq_spq_left);
  10788. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  10789. (type == FCOE_CONNECTION_TYPE)) {
  10790. if (bp->cnic_spq_pending >=
  10791. bp->cnic_eth_dev.max_kwqe_pending)
  10792. break;
  10793. else
  10794. bp->cnic_spq_pending++;
  10795. } else {
  10796. BNX2X_ERR("Unknown SPE type: %d\n", type);
  10797. bnx2x_panic();
  10798. break;
  10799. }
  10800. spe = bnx2x_sp_get_next(bp);
  10801. *spe = *bp->cnic_kwq_cons;
  10802. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  10803. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  10804. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  10805. bp->cnic_kwq_cons = bp->cnic_kwq;
  10806. else
  10807. bp->cnic_kwq_cons++;
  10808. }
  10809. bnx2x_sp_prod_update(bp);
  10810. spin_unlock_bh(&bp->spq_lock);
  10811. }
  10812. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  10813. struct kwqe_16 *kwqes[], u32 count)
  10814. {
  10815. struct bnx2x *bp = netdev_priv(dev);
  10816. int i;
  10817. #ifdef BNX2X_STOP_ON_ERROR
  10818. if (unlikely(bp->panic)) {
  10819. BNX2X_ERR("Can't post to SP queue while panic\n");
  10820. return -EIO;
  10821. }
  10822. #endif
  10823. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  10824. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  10825. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  10826. return -EAGAIN;
  10827. }
  10828. spin_lock_bh(&bp->spq_lock);
  10829. for (i = 0; i < count; i++) {
  10830. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  10831. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  10832. break;
  10833. *bp->cnic_kwq_prod = *spe;
  10834. bp->cnic_kwq_pending++;
  10835. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  10836. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  10837. spe->data.update_data_addr.hi,
  10838. spe->data.update_data_addr.lo,
  10839. bp->cnic_kwq_pending);
  10840. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  10841. bp->cnic_kwq_prod = bp->cnic_kwq;
  10842. else
  10843. bp->cnic_kwq_prod++;
  10844. }
  10845. spin_unlock_bh(&bp->spq_lock);
  10846. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  10847. bnx2x_cnic_sp_post(bp, 0);
  10848. return i;
  10849. }
  10850. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10851. {
  10852. struct cnic_ops *c_ops;
  10853. int rc = 0;
  10854. mutex_lock(&bp->cnic_mutex);
  10855. c_ops = rcu_dereference_protected(bp->cnic_ops,
  10856. lockdep_is_held(&bp->cnic_mutex));
  10857. if (c_ops)
  10858. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10859. mutex_unlock(&bp->cnic_mutex);
  10860. return rc;
  10861. }
  10862. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10863. {
  10864. struct cnic_ops *c_ops;
  10865. int rc = 0;
  10866. rcu_read_lock();
  10867. c_ops = rcu_dereference(bp->cnic_ops);
  10868. if (c_ops)
  10869. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10870. rcu_read_unlock();
  10871. return rc;
  10872. }
  10873. /*
  10874. * for commands that have no data
  10875. */
  10876. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  10877. {
  10878. struct cnic_ctl_info ctl = {0};
  10879. ctl.cmd = cmd;
  10880. return bnx2x_cnic_ctl_send(bp, &ctl);
  10881. }
  10882. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  10883. {
  10884. struct cnic_ctl_info ctl = {0};
  10885. /* first we tell CNIC and only then we count this as a completion */
  10886. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  10887. ctl.data.comp.cid = cid;
  10888. ctl.data.comp.error = err;
  10889. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  10890. bnx2x_cnic_sp_post(bp, 0);
  10891. }
  10892. /* Called with netif_addr_lock_bh() taken.
  10893. * Sets an rx_mode config for an iSCSI ETH client.
  10894. * Doesn't block.
  10895. * Completion should be checked outside.
  10896. */
  10897. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  10898. {
  10899. unsigned long accept_flags = 0, ramrod_flags = 0;
  10900. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  10901. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  10902. if (start) {
  10903. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  10904. * because it's the only way for UIO Queue to accept
  10905. * multicasts (in non-promiscuous mode only one Queue per
  10906. * function will receive multicast packets (leading in our
  10907. * case).
  10908. */
  10909. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  10910. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  10911. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  10912. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  10913. /* Clear STOP_PENDING bit if START is requested */
  10914. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  10915. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  10916. } else
  10917. /* Clear START_PENDING bit if STOP is requested */
  10918. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  10919. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  10920. set_bit(sched_state, &bp->sp_state);
  10921. else {
  10922. __set_bit(RAMROD_RX, &ramrod_flags);
  10923. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  10924. ramrod_flags);
  10925. }
  10926. }
  10927. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  10928. {
  10929. struct bnx2x *bp = netdev_priv(dev);
  10930. int rc = 0;
  10931. switch (ctl->cmd) {
  10932. case DRV_CTL_CTXTBL_WR_CMD: {
  10933. u32 index = ctl->data.io.offset;
  10934. dma_addr_t addr = ctl->data.io.dma_addr;
  10935. bnx2x_ilt_wr(bp, index, addr);
  10936. break;
  10937. }
  10938. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  10939. int count = ctl->data.credit.credit_count;
  10940. bnx2x_cnic_sp_post(bp, count);
  10941. break;
  10942. }
  10943. /* rtnl_lock is held. */
  10944. case DRV_CTL_START_L2_CMD: {
  10945. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10946. unsigned long sp_bits = 0;
  10947. /* Configure the iSCSI classification object */
  10948. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  10949. cp->iscsi_l2_client_id,
  10950. cp->iscsi_l2_cid, BP_FUNC(bp),
  10951. bnx2x_sp(bp, mac_rdata),
  10952. bnx2x_sp_mapping(bp, mac_rdata),
  10953. BNX2X_FILTER_MAC_PENDING,
  10954. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  10955. &bp->macs_pool);
  10956. /* Set iSCSI MAC address */
  10957. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  10958. if (rc)
  10959. break;
  10960. mmiowb();
  10961. barrier();
  10962. /* Start accepting on iSCSI L2 ring */
  10963. netif_addr_lock_bh(dev);
  10964. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  10965. netif_addr_unlock_bh(dev);
  10966. /* bits to wait on */
  10967. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10968. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  10969. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10970. BNX2X_ERR("rx_mode completion timed out!\n");
  10971. break;
  10972. }
  10973. /* rtnl_lock is held. */
  10974. case DRV_CTL_STOP_L2_CMD: {
  10975. unsigned long sp_bits = 0;
  10976. /* Stop accepting on iSCSI L2 ring */
  10977. netif_addr_lock_bh(dev);
  10978. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  10979. netif_addr_unlock_bh(dev);
  10980. /* bits to wait on */
  10981. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10982. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  10983. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10984. BNX2X_ERR("rx_mode completion timed out!\n");
  10985. mmiowb();
  10986. barrier();
  10987. /* Unset iSCSI L2 MAC */
  10988. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  10989. BNX2X_ISCSI_ETH_MAC, true);
  10990. break;
  10991. }
  10992. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  10993. int count = ctl->data.credit.credit_count;
  10994. smp_mb__before_atomic_inc();
  10995. atomic_add(count, &bp->cq_spq_left);
  10996. smp_mb__after_atomic_inc();
  10997. break;
  10998. }
  10999. case DRV_CTL_ULP_REGISTER_CMD: {
  11000. int ulp_type = ctl->data.register_data.ulp_type;
  11001. if (CHIP_IS_E3(bp)) {
  11002. int idx = BP_FW_MB_IDX(bp);
  11003. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11004. int path = BP_PATH(bp);
  11005. int port = BP_PORT(bp);
  11006. int i;
  11007. u32 scratch_offset;
  11008. u32 *host_addr;
  11009. /* first write capability to shmem2 */
  11010. if (ulp_type == CNIC_ULP_ISCSI)
  11011. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11012. else if (ulp_type == CNIC_ULP_FCOE)
  11013. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11014. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11015. if ((ulp_type != CNIC_ULP_FCOE) ||
  11016. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  11017. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  11018. break;
  11019. /* if reached here - should write fcoe capabilities */
  11020. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  11021. if (!scratch_offset)
  11022. break;
  11023. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  11024. fcoe_features[path][port]);
  11025. host_addr = (u32 *) &(ctl->data.register_data.
  11026. fcoe_features);
  11027. for (i = 0; i < sizeof(struct fcoe_capabilities);
  11028. i += 4)
  11029. REG_WR(bp, scratch_offset + i,
  11030. *(host_addr + i/4));
  11031. }
  11032. break;
  11033. }
  11034. case DRV_CTL_ULP_UNREGISTER_CMD: {
  11035. int ulp_type = ctl->data.ulp_type;
  11036. if (CHIP_IS_E3(bp)) {
  11037. int idx = BP_FW_MB_IDX(bp);
  11038. u32 cap;
  11039. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11040. if (ulp_type == CNIC_ULP_ISCSI)
  11041. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11042. else if (ulp_type == CNIC_ULP_FCOE)
  11043. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11044. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11045. }
  11046. break;
  11047. }
  11048. default:
  11049. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  11050. rc = -EINVAL;
  11051. }
  11052. return rc;
  11053. }
  11054. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  11055. {
  11056. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11057. if (bp->flags & USING_MSIX_FLAG) {
  11058. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  11059. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  11060. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  11061. } else {
  11062. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  11063. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  11064. }
  11065. if (!CHIP_IS_E1x(bp))
  11066. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  11067. else
  11068. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  11069. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  11070. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  11071. cp->irq_arr[1].status_blk = bp->def_status_blk;
  11072. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  11073. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  11074. cp->num_irq = 2;
  11075. }
  11076. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  11077. {
  11078. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11079. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11080. bnx2x_cid_ilt_lines(bp);
  11081. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11082. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11083. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11084. if (NO_ISCSI_OOO(bp))
  11085. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11086. }
  11087. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  11088. void *data)
  11089. {
  11090. struct bnx2x *bp = netdev_priv(dev);
  11091. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11092. int rc;
  11093. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  11094. if (ops == NULL) {
  11095. BNX2X_ERR("NULL ops received\n");
  11096. return -EINVAL;
  11097. }
  11098. if (!CNIC_SUPPORT(bp)) {
  11099. BNX2X_ERR("Can't register CNIC when not supported\n");
  11100. return -EOPNOTSUPP;
  11101. }
  11102. if (!CNIC_LOADED(bp)) {
  11103. rc = bnx2x_load_cnic(bp);
  11104. if (rc) {
  11105. BNX2X_ERR("CNIC-related load failed\n");
  11106. return rc;
  11107. }
  11108. }
  11109. bp->cnic_enabled = true;
  11110. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  11111. if (!bp->cnic_kwq)
  11112. return -ENOMEM;
  11113. bp->cnic_kwq_cons = bp->cnic_kwq;
  11114. bp->cnic_kwq_prod = bp->cnic_kwq;
  11115. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  11116. bp->cnic_spq_pending = 0;
  11117. bp->cnic_kwq_pending = 0;
  11118. bp->cnic_data = data;
  11119. cp->num_irq = 0;
  11120. cp->drv_state |= CNIC_DRV_STATE_REGD;
  11121. cp->iro_arr = bp->iro_arr;
  11122. bnx2x_setup_cnic_irq_info(bp);
  11123. rcu_assign_pointer(bp->cnic_ops, ops);
  11124. return 0;
  11125. }
  11126. static int bnx2x_unregister_cnic(struct net_device *dev)
  11127. {
  11128. struct bnx2x *bp = netdev_priv(dev);
  11129. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11130. mutex_lock(&bp->cnic_mutex);
  11131. cp->drv_state = 0;
  11132. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  11133. mutex_unlock(&bp->cnic_mutex);
  11134. synchronize_rcu();
  11135. kfree(bp->cnic_kwq);
  11136. bp->cnic_kwq = NULL;
  11137. return 0;
  11138. }
  11139. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  11140. {
  11141. struct bnx2x *bp = netdev_priv(dev);
  11142. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11143. /* If both iSCSI and FCoE are disabled - return NULL in
  11144. * order to indicate CNIC that it should not try to work
  11145. * with this device.
  11146. */
  11147. if (NO_ISCSI(bp) && NO_FCOE(bp))
  11148. return NULL;
  11149. cp->drv_owner = THIS_MODULE;
  11150. cp->chip_id = CHIP_ID(bp);
  11151. cp->pdev = bp->pdev;
  11152. cp->io_base = bp->regview;
  11153. cp->io_base2 = bp->doorbells;
  11154. cp->max_kwqe_pending = 8;
  11155. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  11156. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11157. bnx2x_cid_ilt_lines(bp);
  11158. cp->ctx_tbl_len = CNIC_ILT_LINES;
  11159. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11160. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  11161. cp->drv_ctl = bnx2x_drv_ctl;
  11162. cp->drv_register_cnic = bnx2x_register_cnic;
  11163. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  11164. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11165. cp->iscsi_l2_client_id =
  11166. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11167. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11168. if (NO_ISCSI_OOO(bp))
  11169. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11170. if (NO_ISCSI(bp))
  11171. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  11172. if (NO_FCOE(bp))
  11173. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  11174. BNX2X_DEV_INFO(
  11175. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  11176. cp->ctx_blk_size,
  11177. cp->ctx_tbl_offset,
  11178. cp->ctx_tbl_len,
  11179. cp->starting_cid);
  11180. return cp;
  11181. }
  11182. u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  11183. {
  11184. struct bnx2x *bp = fp->bp;
  11185. u32 offset = BAR_USTRORM_INTMEM;
  11186. if (IS_VF(bp))
  11187. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  11188. else if (!CHIP_IS_E1x(bp))
  11189. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  11190. else
  11191. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  11192. return offset;
  11193. }
  11194. /* called only on E1H or E2.
  11195. * When pretending to be PF, the pretend value is the function number 0...7
  11196. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  11197. * combination
  11198. */
  11199. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  11200. {
  11201. u32 pretend_reg;
  11202. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  11203. return -1;
  11204. /* get my own pretend register */
  11205. pretend_reg = bnx2x_get_pretend_reg(bp);
  11206. REG_WR(bp, pretend_reg, pretend_func_val);
  11207. REG_RD(bp, pretend_reg);
  11208. return 0;
  11209. }