bnx2x_main.c 322 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098
  1. /* bnx2x_main.c: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2012 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_dcb.h"
  60. #include "bnx2x_sp.h"
  61. #include <linux/firmware.h>
  62. #include "bnx2x_fw_file_hdr.h"
  63. /* FW files */
  64. #define FW_FILE_VERSION \
  65. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  66. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  67. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  68. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  69. #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
  70. #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
  71. #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
  72. /* Time in jiffies before concluding the transmitter is hung */
  73. #define TX_TIMEOUT (5*HZ)
  74. static char version[] __devinitdata =
  75. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  76. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  77. MODULE_AUTHOR("Eliezer Tamir");
  78. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  79. "BCM57710/57711/57711E/"
  80. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  81. "57840/57840_MF Driver");
  82. MODULE_LICENSE("GPL");
  83. MODULE_VERSION(DRV_MODULE_VERSION);
  84. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  85. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  86. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  87. static int multi_mode = 1;
  88. module_param(multi_mode, int, 0);
  89. MODULE_PARM_DESC(multi_mode, " Multi queue mode "
  90. "(0 Disable; 1 Enable (default))");
  91. int num_queues;
  92. module_param(num_queues, int, 0);
  93. MODULE_PARM_DESC(num_queues, " Number of queues for multi_mode=1"
  94. " (default is as a number of CPUs)");
  95. static int disable_tpa;
  96. module_param(disable_tpa, int, 0);
  97. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  98. #define INT_MODE_INTx 1
  99. #define INT_MODE_MSI 2
  100. static int int_mode;
  101. module_param(int_mode, int, 0);
  102. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  103. "(1 INT#x; 2 MSI)");
  104. static int dropless_fc;
  105. module_param(dropless_fc, int, 0);
  106. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  107. static int mrrs = -1;
  108. module_param(mrrs, int, 0);
  109. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  110. static int debug;
  111. module_param(debug, int, 0);
  112. MODULE_PARM_DESC(debug, " Default debug msglevel");
  113. struct workqueue_struct *bnx2x_wq;
  114. enum bnx2x_board_type {
  115. BCM57710 = 0,
  116. BCM57711,
  117. BCM57711E,
  118. BCM57712,
  119. BCM57712_MF,
  120. BCM57800,
  121. BCM57800_MF,
  122. BCM57810,
  123. BCM57810_MF,
  124. BCM57840,
  125. BCM57840_MF,
  126. BCM57811,
  127. BCM57811_MF
  128. };
  129. /* indexed by board_type, above */
  130. static struct {
  131. char *name;
  132. } board_info[] __devinitdata = {
  133. { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  134. { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  135. { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  136. { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  137. { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  138. { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  139. { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  140. { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  141. { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  142. { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  143. { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function"},
  144. { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet"},
  145. { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function"},
  146. };
  147. #ifndef PCI_DEVICE_ID_NX2_57710
  148. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  149. #endif
  150. #ifndef PCI_DEVICE_ID_NX2_57711
  151. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  152. #endif
  153. #ifndef PCI_DEVICE_ID_NX2_57711E
  154. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  155. #endif
  156. #ifndef PCI_DEVICE_ID_NX2_57712
  157. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  158. #endif
  159. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  160. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  161. #endif
  162. #ifndef PCI_DEVICE_ID_NX2_57800
  163. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  164. #endif
  165. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  166. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  167. #endif
  168. #ifndef PCI_DEVICE_ID_NX2_57810
  169. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  170. #endif
  171. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  172. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  173. #endif
  174. #ifndef PCI_DEVICE_ID_NX2_57840
  175. #define PCI_DEVICE_ID_NX2_57840 CHIP_NUM_57840
  176. #endif
  177. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  178. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  179. #endif
  180. #ifndef PCI_DEVICE_ID_NX2_57811
  181. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  182. #endif
  183. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  184. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  185. #endif
  186. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  187. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  188. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  189. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  190. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  191. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  192. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  193. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  194. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  195. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  196. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840), BCM57840 },
  197. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  198. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  199. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  200. { 0 }
  201. };
  202. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  203. /* Global resources for unloading a previously loaded device */
  204. #define BNX2X_PREV_WAIT_NEEDED 1
  205. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  206. static LIST_HEAD(bnx2x_prev_list);
  207. /****************************************************************************
  208. * General service functions
  209. ****************************************************************************/
  210. static inline void __storm_memset_dma_mapping(struct bnx2x *bp,
  211. u32 addr, dma_addr_t mapping)
  212. {
  213. REG_WR(bp, addr, U64_LO(mapping));
  214. REG_WR(bp, addr + 4, U64_HI(mapping));
  215. }
  216. static inline void storm_memset_spq_addr(struct bnx2x *bp,
  217. dma_addr_t mapping, u16 abs_fid)
  218. {
  219. u32 addr = XSEM_REG_FAST_MEMORY +
  220. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  221. __storm_memset_dma_mapping(bp, addr, mapping);
  222. }
  223. static inline void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  224. u16 pf_id)
  225. {
  226. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  227. pf_id);
  228. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  229. pf_id);
  230. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  231. pf_id);
  232. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  233. pf_id);
  234. }
  235. static inline void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  236. u8 enable)
  237. {
  238. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  239. enable);
  240. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  241. enable);
  242. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  243. enable);
  244. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  245. enable);
  246. }
  247. static inline void storm_memset_eq_data(struct bnx2x *bp,
  248. struct event_ring_data *eq_data,
  249. u16 pfid)
  250. {
  251. size_t size = sizeof(struct event_ring_data);
  252. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  253. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  254. }
  255. static inline void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  256. u16 pfid)
  257. {
  258. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  259. REG_WR16(bp, addr, eq_prod);
  260. }
  261. /* used only at init
  262. * locking is done by mcp
  263. */
  264. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  265. {
  266. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  267. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  268. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  269. PCICFG_VENDOR_ID_OFFSET);
  270. }
  271. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  272. {
  273. u32 val;
  274. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  275. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  276. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  277. PCICFG_VENDOR_ID_OFFSET);
  278. return val;
  279. }
  280. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  281. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  282. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  283. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  284. #define DMAE_DP_DST_NONE "dst_addr [none]"
  285. /* copy command into DMAE command memory and set DMAE command go */
  286. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  287. {
  288. u32 cmd_offset;
  289. int i;
  290. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  291. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  292. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  293. }
  294. REG_WR(bp, dmae_reg_go_c[idx], 1);
  295. }
  296. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  297. {
  298. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  299. DMAE_CMD_C_ENABLE);
  300. }
  301. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  302. {
  303. return opcode & ~DMAE_CMD_SRC_RESET;
  304. }
  305. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  306. bool with_comp, u8 comp_type)
  307. {
  308. u32 opcode = 0;
  309. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  310. (dst_type << DMAE_COMMAND_DST_SHIFT));
  311. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  312. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  313. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  314. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  315. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  316. #ifdef __BIG_ENDIAN
  317. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  318. #else
  319. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  320. #endif
  321. if (with_comp)
  322. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  323. return opcode;
  324. }
  325. static void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  326. struct dmae_command *dmae,
  327. u8 src_type, u8 dst_type)
  328. {
  329. memset(dmae, 0, sizeof(struct dmae_command));
  330. /* set the opcode */
  331. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  332. true, DMAE_COMP_PCI);
  333. /* fill in the completion parameters */
  334. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  335. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  336. dmae->comp_val = DMAE_COMP_VAL;
  337. }
  338. /* issue a dmae command over the init-channel and wailt for completion */
  339. static int bnx2x_issue_dmae_with_comp(struct bnx2x *bp,
  340. struct dmae_command *dmae)
  341. {
  342. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  343. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  344. int rc = 0;
  345. /*
  346. * Lock the dmae channel. Disable BHs to prevent a dead-lock
  347. * as long as this code is called both from syscall context and
  348. * from ndo_set_rx_mode() flow that may be called from BH.
  349. */
  350. spin_lock_bh(&bp->dmae_lock);
  351. /* reset completion */
  352. *wb_comp = 0;
  353. /* post the command on the channel used for initializations */
  354. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  355. /* wait for completion */
  356. udelay(5);
  357. while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  358. if (!cnt ||
  359. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  360. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  361. BNX2X_ERR("DMAE timeout!\n");
  362. rc = DMAE_TIMEOUT;
  363. goto unlock;
  364. }
  365. cnt--;
  366. udelay(50);
  367. }
  368. if (*wb_comp & DMAE_PCI_ERR_FLAG) {
  369. BNX2X_ERR("DMAE PCI error!\n");
  370. rc = DMAE_PCI_ERROR;
  371. }
  372. unlock:
  373. spin_unlock_bh(&bp->dmae_lock);
  374. return rc;
  375. }
  376. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  377. u32 len32)
  378. {
  379. struct dmae_command dmae;
  380. if (!bp->dmae_ready) {
  381. u32 *data = bnx2x_sp(bp, wb_data[0]);
  382. if (CHIP_IS_E1(bp))
  383. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  384. else
  385. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  386. return;
  387. }
  388. /* set opcode and fixed command fields */
  389. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  390. /* fill in addresses and len */
  391. dmae.src_addr_lo = U64_LO(dma_addr);
  392. dmae.src_addr_hi = U64_HI(dma_addr);
  393. dmae.dst_addr_lo = dst_addr >> 2;
  394. dmae.dst_addr_hi = 0;
  395. dmae.len = len32;
  396. /* issue the command and wait for completion */
  397. bnx2x_issue_dmae_with_comp(bp, &dmae);
  398. }
  399. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  400. {
  401. struct dmae_command dmae;
  402. if (!bp->dmae_ready) {
  403. u32 *data = bnx2x_sp(bp, wb_data[0]);
  404. int i;
  405. if (CHIP_IS_E1(bp))
  406. for (i = 0; i < len32; i++)
  407. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  408. else
  409. for (i = 0; i < len32; i++)
  410. data[i] = REG_RD(bp, src_addr + i*4);
  411. return;
  412. }
  413. /* set opcode and fixed command fields */
  414. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  415. /* fill in addresses and len */
  416. dmae.src_addr_lo = src_addr >> 2;
  417. dmae.src_addr_hi = 0;
  418. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  419. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  420. dmae.len = len32;
  421. /* issue the command and wait for completion */
  422. bnx2x_issue_dmae_with_comp(bp, &dmae);
  423. }
  424. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  425. u32 addr, u32 len)
  426. {
  427. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  428. int offset = 0;
  429. while (len > dmae_wr_max) {
  430. bnx2x_write_dmae(bp, phys_addr + offset,
  431. addr + offset, dmae_wr_max);
  432. offset += dmae_wr_max * 4;
  433. len -= dmae_wr_max;
  434. }
  435. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  436. }
  437. static int bnx2x_mc_assert(struct bnx2x *bp)
  438. {
  439. char last_idx;
  440. int i, rc = 0;
  441. u32 row0, row1, row2, row3;
  442. /* XSTORM */
  443. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  444. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  445. if (last_idx)
  446. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  447. /* print the asserts */
  448. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  449. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  450. XSTORM_ASSERT_LIST_OFFSET(i));
  451. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  452. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  453. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  454. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  455. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  456. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  457. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  458. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  459. i, row3, row2, row1, row0);
  460. rc++;
  461. } else {
  462. break;
  463. }
  464. }
  465. /* TSTORM */
  466. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  467. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  468. if (last_idx)
  469. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  470. /* print the asserts */
  471. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  472. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  473. TSTORM_ASSERT_LIST_OFFSET(i));
  474. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  475. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  476. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  477. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  478. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  479. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  480. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  481. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  482. i, row3, row2, row1, row0);
  483. rc++;
  484. } else {
  485. break;
  486. }
  487. }
  488. /* CSTORM */
  489. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  490. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  491. if (last_idx)
  492. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  493. /* print the asserts */
  494. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  495. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  496. CSTORM_ASSERT_LIST_OFFSET(i));
  497. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  498. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  499. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  500. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  501. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  502. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  503. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  504. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  505. i, row3, row2, row1, row0);
  506. rc++;
  507. } else {
  508. break;
  509. }
  510. }
  511. /* USTORM */
  512. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  513. USTORM_ASSERT_LIST_INDEX_OFFSET);
  514. if (last_idx)
  515. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  516. /* print the asserts */
  517. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  518. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  519. USTORM_ASSERT_LIST_OFFSET(i));
  520. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  521. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  522. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  523. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  524. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  525. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  526. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  527. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  528. i, row3, row2, row1, row0);
  529. rc++;
  530. } else {
  531. break;
  532. }
  533. }
  534. return rc;
  535. }
  536. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  537. {
  538. u32 addr, val;
  539. u32 mark, offset;
  540. __be32 data[9];
  541. int word;
  542. u32 trace_shmem_base;
  543. if (BP_NOMCP(bp)) {
  544. BNX2X_ERR("NO MCP - can not dump\n");
  545. return;
  546. }
  547. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  548. (bp->common.bc_ver & 0xff0000) >> 16,
  549. (bp->common.bc_ver & 0xff00) >> 8,
  550. (bp->common.bc_ver & 0xff));
  551. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  552. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  553. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  554. if (BP_PATH(bp) == 0)
  555. trace_shmem_base = bp->common.shmem_base;
  556. else
  557. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  558. addr = trace_shmem_base - 0x800;
  559. /* validate TRCB signature */
  560. mark = REG_RD(bp, addr);
  561. if (mark != MFW_TRACE_SIGNATURE) {
  562. BNX2X_ERR("Trace buffer signature is missing.");
  563. return ;
  564. }
  565. /* read cyclic buffer pointer */
  566. addr += 4;
  567. mark = REG_RD(bp, addr);
  568. mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
  569. + ((mark + 0x3) & ~0x3) - 0x08000000;
  570. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  571. printk("%s", lvl);
  572. for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
  573. for (word = 0; word < 8; word++)
  574. data[word] = htonl(REG_RD(bp, offset + 4*word));
  575. data[8] = 0x0;
  576. pr_cont("%s", (char *)data);
  577. }
  578. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  579. for (word = 0; word < 8; word++)
  580. data[word] = htonl(REG_RD(bp, offset + 4*word));
  581. data[8] = 0x0;
  582. pr_cont("%s", (char *)data);
  583. }
  584. printk("%s" "end of fw dump\n", lvl);
  585. }
  586. static inline void bnx2x_fw_dump(struct bnx2x *bp)
  587. {
  588. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  589. }
  590. void bnx2x_panic_dump(struct bnx2x *bp)
  591. {
  592. int i;
  593. u16 j;
  594. struct hc_sp_status_block_data sp_sb_data;
  595. int func = BP_FUNC(bp);
  596. #ifdef BNX2X_STOP_ON_ERROR
  597. u16 start = 0, end = 0;
  598. u8 cos;
  599. #endif
  600. bp->stats_state = STATS_STATE_DISABLED;
  601. bp->eth_stats.unrecoverable_error++;
  602. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  603. BNX2X_ERR("begin crash dump -----------------\n");
  604. /* Indices */
  605. /* Common */
  606. 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",
  607. bp->def_idx, bp->def_att_idx, bp->attn_state,
  608. bp->spq_prod_idx, bp->stats_counter);
  609. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  610. bp->def_status_blk->atten_status_block.attn_bits,
  611. bp->def_status_blk->atten_status_block.attn_bits_ack,
  612. bp->def_status_blk->atten_status_block.status_block_id,
  613. bp->def_status_blk->atten_status_block.attn_bits_index);
  614. BNX2X_ERR(" def (");
  615. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  616. pr_cont("0x%x%s",
  617. bp->def_status_blk->sp_sb.index_values[i],
  618. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  619. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  620. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  621. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  622. i*sizeof(u32));
  623. 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",
  624. sp_sb_data.igu_sb_id,
  625. sp_sb_data.igu_seg_id,
  626. sp_sb_data.p_func.pf_id,
  627. sp_sb_data.p_func.vnic_id,
  628. sp_sb_data.p_func.vf_id,
  629. sp_sb_data.p_func.vf_valid,
  630. sp_sb_data.state);
  631. for_each_eth_queue(bp, i) {
  632. struct bnx2x_fastpath *fp = &bp->fp[i];
  633. int loop;
  634. struct hc_status_block_data_e2 sb_data_e2;
  635. struct hc_status_block_data_e1x sb_data_e1x;
  636. struct hc_status_block_sm *hc_sm_p =
  637. CHIP_IS_E1x(bp) ?
  638. sb_data_e1x.common.state_machine :
  639. sb_data_e2.common.state_machine;
  640. struct hc_index_data *hc_index_p =
  641. CHIP_IS_E1x(bp) ?
  642. sb_data_e1x.index_data :
  643. sb_data_e2.index_data;
  644. u8 data_size, cos;
  645. u32 *sb_data_p;
  646. struct bnx2x_fp_txdata txdata;
  647. /* Rx */
  648. 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",
  649. i, fp->rx_bd_prod, fp->rx_bd_cons,
  650. fp->rx_comp_prod,
  651. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  652. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  653. fp->rx_sge_prod, fp->last_max_sge,
  654. le16_to_cpu(fp->fp_hc_idx));
  655. /* Tx */
  656. for_each_cos_in_tx_queue(fp, cos)
  657. {
  658. txdata = fp->txdata[cos];
  659. 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",
  660. i, txdata.tx_pkt_prod,
  661. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  662. txdata.tx_bd_cons,
  663. le16_to_cpu(*txdata.tx_cons_sb));
  664. }
  665. loop = CHIP_IS_E1x(bp) ?
  666. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  667. /* host sb data */
  668. #ifdef BCM_CNIC
  669. if (IS_FCOE_FP(fp))
  670. continue;
  671. #endif
  672. BNX2X_ERR(" run indexes (");
  673. for (j = 0; j < HC_SB_MAX_SM; j++)
  674. pr_cont("0x%x%s",
  675. fp->sb_running_index[j],
  676. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  677. BNX2X_ERR(" indexes (");
  678. for (j = 0; j < loop; j++)
  679. pr_cont("0x%x%s",
  680. fp->sb_index_values[j],
  681. (j == loop - 1) ? ")" : " ");
  682. /* fw sb data */
  683. data_size = CHIP_IS_E1x(bp) ?
  684. sizeof(struct hc_status_block_data_e1x) :
  685. sizeof(struct hc_status_block_data_e2);
  686. data_size /= sizeof(u32);
  687. sb_data_p = CHIP_IS_E1x(bp) ?
  688. (u32 *)&sb_data_e1x :
  689. (u32 *)&sb_data_e2;
  690. /* copy sb data in here */
  691. for (j = 0; j < data_size; j++)
  692. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  693. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  694. j * sizeof(u32));
  695. if (!CHIP_IS_E1x(bp)) {
  696. 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",
  697. sb_data_e2.common.p_func.pf_id,
  698. sb_data_e2.common.p_func.vf_id,
  699. sb_data_e2.common.p_func.vf_valid,
  700. sb_data_e2.common.p_func.vnic_id,
  701. sb_data_e2.common.same_igu_sb_1b,
  702. sb_data_e2.common.state);
  703. } else {
  704. 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",
  705. sb_data_e1x.common.p_func.pf_id,
  706. sb_data_e1x.common.p_func.vf_id,
  707. sb_data_e1x.common.p_func.vf_valid,
  708. sb_data_e1x.common.p_func.vnic_id,
  709. sb_data_e1x.common.same_igu_sb_1b,
  710. sb_data_e1x.common.state);
  711. }
  712. /* SB_SMs data */
  713. for (j = 0; j < HC_SB_MAX_SM; j++) {
  714. 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",
  715. j, hc_sm_p[j].__flags,
  716. hc_sm_p[j].igu_sb_id,
  717. hc_sm_p[j].igu_seg_id,
  718. hc_sm_p[j].time_to_expire,
  719. hc_sm_p[j].timer_value);
  720. }
  721. /* Indecies data */
  722. for (j = 0; j < loop; j++) {
  723. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  724. hc_index_p[j].flags,
  725. hc_index_p[j].timeout);
  726. }
  727. }
  728. #ifdef BNX2X_STOP_ON_ERROR
  729. /* Rings */
  730. /* Rx */
  731. for_each_rx_queue(bp, i) {
  732. struct bnx2x_fastpath *fp = &bp->fp[i];
  733. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  734. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  735. for (j = start; j != end; j = RX_BD(j + 1)) {
  736. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  737. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  738. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  739. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  740. }
  741. start = RX_SGE(fp->rx_sge_prod);
  742. end = RX_SGE(fp->last_max_sge);
  743. for (j = start; j != end; j = RX_SGE(j + 1)) {
  744. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  745. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  746. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  747. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  748. }
  749. start = RCQ_BD(fp->rx_comp_cons - 10);
  750. end = RCQ_BD(fp->rx_comp_cons + 503);
  751. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  752. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  753. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  754. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  755. }
  756. }
  757. /* Tx */
  758. for_each_tx_queue(bp, i) {
  759. struct bnx2x_fastpath *fp = &bp->fp[i];
  760. for_each_cos_in_tx_queue(fp, cos) {
  761. struct bnx2x_fp_txdata *txdata = &fp->txdata[cos];
  762. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  763. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  764. for (j = start; j != end; j = TX_BD(j + 1)) {
  765. struct sw_tx_bd *sw_bd =
  766. &txdata->tx_buf_ring[j];
  767. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  768. i, cos, j, sw_bd->skb,
  769. sw_bd->first_bd);
  770. }
  771. start = TX_BD(txdata->tx_bd_cons - 10);
  772. end = TX_BD(txdata->tx_bd_cons + 254);
  773. for (j = start; j != end; j = TX_BD(j + 1)) {
  774. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  775. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  776. i, cos, j, tx_bd[0], tx_bd[1],
  777. tx_bd[2], tx_bd[3]);
  778. }
  779. }
  780. }
  781. #endif
  782. bnx2x_fw_dump(bp);
  783. bnx2x_mc_assert(bp);
  784. BNX2X_ERR("end crash dump -----------------\n");
  785. }
  786. /*
  787. * FLR Support for E2
  788. *
  789. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  790. * initialization.
  791. */
  792. #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
  793. #define FLR_WAIT_INTERVAL 50 /* usec */
  794. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  795. struct pbf_pN_buf_regs {
  796. int pN;
  797. u32 init_crd;
  798. u32 crd;
  799. u32 crd_freed;
  800. };
  801. struct pbf_pN_cmd_regs {
  802. int pN;
  803. u32 lines_occup;
  804. u32 lines_freed;
  805. };
  806. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  807. struct pbf_pN_buf_regs *regs,
  808. u32 poll_count)
  809. {
  810. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  811. u32 cur_cnt = poll_count;
  812. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  813. crd = crd_start = REG_RD(bp, regs->crd);
  814. init_crd = REG_RD(bp, regs->init_crd);
  815. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  816. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  817. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  818. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  819. (init_crd - crd_start))) {
  820. if (cur_cnt--) {
  821. udelay(FLR_WAIT_INTERVAL);
  822. crd = REG_RD(bp, regs->crd);
  823. crd_freed = REG_RD(bp, regs->crd_freed);
  824. } else {
  825. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  826. regs->pN);
  827. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  828. regs->pN, crd);
  829. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  830. regs->pN, crd_freed);
  831. break;
  832. }
  833. }
  834. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  835. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  836. }
  837. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  838. struct pbf_pN_cmd_regs *regs,
  839. u32 poll_count)
  840. {
  841. u32 occup, to_free, freed, freed_start;
  842. u32 cur_cnt = poll_count;
  843. occup = to_free = REG_RD(bp, regs->lines_occup);
  844. freed = freed_start = REG_RD(bp, regs->lines_freed);
  845. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  846. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  847. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  848. if (cur_cnt--) {
  849. udelay(FLR_WAIT_INTERVAL);
  850. occup = REG_RD(bp, regs->lines_occup);
  851. freed = REG_RD(bp, regs->lines_freed);
  852. } else {
  853. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  854. regs->pN);
  855. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  856. regs->pN, occup);
  857. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  858. regs->pN, freed);
  859. break;
  860. }
  861. }
  862. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  863. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  864. }
  865. static inline u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  866. u32 expected, u32 poll_count)
  867. {
  868. u32 cur_cnt = poll_count;
  869. u32 val;
  870. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  871. udelay(FLR_WAIT_INTERVAL);
  872. return val;
  873. }
  874. static inline int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  875. char *msg, u32 poll_cnt)
  876. {
  877. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  878. if (val != 0) {
  879. BNX2X_ERR("%s usage count=%d\n", msg, val);
  880. return 1;
  881. }
  882. return 0;
  883. }
  884. static u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  885. {
  886. /* adjust polling timeout */
  887. if (CHIP_REV_IS_EMUL(bp))
  888. return FLR_POLL_CNT * 2000;
  889. if (CHIP_REV_IS_FPGA(bp))
  890. return FLR_POLL_CNT * 120;
  891. return FLR_POLL_CNT;
  892. }
  893. static void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  894. {
  895. struct pbf_pN_cmd_regs cmd_regs[] = {
  896. {0, (CHIP_IS_E3B0(bp)) ?
  897. PBF_REG_TQ_OCCUPANCY_Q0 :
  898. PBF_REG_P0_TQ_OCCUPANCY,
  899. (CHIP_IS_E3B0(bp)) ?
  900. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  901. PBF_REG_P0_TQ_LINES_FREED_CNT},
  902. {1, (CHIP_IS_E3B0(bp)) ?
  903. PBF_REG_TQ_OCCUPANCY_Q1 :
  904. PBF_REG_P1_TQ_OCCUPANCY,
  905. (CHIP_IS_E3B0(bp)) ?
  906. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  907. PBF_REG_P1_TQ_LINES_FREED_CNT},
  908. {4, (CHIP_IS_E3B0(bp)) ?
  909. PBF_REG_TQ_OCCUPANCY_LB_Q :
  910. PBF_REG_P4_TQ_OCCUPANCY,
  911. (CHIP_IS_E3B0(bp)) ?
  912. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  913. PBF_REG_P4_TQ_LINES_FREED_CNT}
  914. };
  915. struct pbf_pN_buf_regs buf_regs[] = {
  916. {0, (CHIP_IS_E3B0(bp)) ?
  917. PBF_REG_INIT_CRD_Q0 :
  918. PBF_REG_P0_INIT_CRD ,
  919. (CHIP_IS_E3B0(bp)) ?
  920. PBF_REG_CREDIT_Q0 :
  921. PBF_REG_P0_CREDIT,
  922. (CHIP_IS_E3B0(bp)) ?
  923. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  924. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  925. {1, (CHIP_IS_E3B0(bp)) ?
  926. PBF_REG_INIT_CRD_Q1 :
  927. PBF_REG_P1_INIT_CRD,
  928. (CHIP_IS_E3B0(bp)) ?
  929. PBF_REG_CREDIT_Q1 :
  930. PBF_REG_P1_CREDIT,
  931. (CHIP_IS_E3B0(bp)) ?
  932. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  933. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  934. {4, (CHIP_IS_E3B0(bp)) ?
  935. PBF_REG_INIT_CRD_LB_Q :
  936. PBF_REG_P4_INIT_CRD,
  937. (CHIP_IS_E3B0(bp)) ?
  938. PBF_REG_CREDIT_LB_Q :
  939. PBF_REG_P4_CREDIT,
  940. (CHIP_IS_E3B0(bp)) ?
  941. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  942. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  943. };
  944. int i;
  945. /* Verify the command queues are flushed P0, P1, P4 */
  946. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  947. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  948. /* Verify the transmission buffers are flushed P0, P1, P4 */
  949. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  950. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  951. }
  952. #define OP_GEN_PARAM(param) \
  953. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  954. #define OP_GEN_TYPE(type) \
  955. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  956. #define OP_GEN_AGG_VECT(index) \
  957. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  958. static inline int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func,
  959. u32 poll_cnt)
  960. {
  961. struct sdm_op_gen op_gen = {0};
  962. u32 comp_addr = BAR_CSTRORM_INTMEM +
  963. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  964. int ret = 0;
  965. if (REG_RD(bp, comp_addr)) {
  966. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  967. return 1;
  968. }
  969. op_gen.command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  970. op_gen.command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  971. op_gen.command |= OP_GEN_AGG_VECT(clnup_func);
  972. op_gen.command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  973. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  974. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen.command);
  975. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  976. BNX2X_ERR("FW final cleanup did not succeed\n");
  977. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  978. (REG_RD(bp, comp_addr)));
  979. ret = 1;
  980. }
  981. /* Zero completion for nxt FLR */
  982. REG_WR(bp, comp_addr, 0);
  983. return ret;
  984. }
  985. static inline u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  986. {
  987. int pos;
  988. u16 status;
  989. pos = pci_pcie_cap(dev);
  990. if (!pos)
  991. return false;
  992. pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status);
  993. return status & PCI_EXP_DEVSTA_TRPND;
  994. }
  995. /* PF FLR specific routines
  996. */
  997. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  998. {
  999. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1000. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1001. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1002. "CFC PF usage counter timed out",
  1003. poll_cnt))
  1004. return 1;
  1005. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1006. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1007. DORQ_REG_PF_USAGE_CNT,
  1008. "DQ PF usage counter timed out",
  1009. poll_cnt))
  1010. return 1;
  1011. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1012. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1013. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1014. "QM PF usage counter timed out",
  1015. poll_cnt))
  1016. return 1;
  1017. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1018. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1019. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1020. "Timers VNIC usage counter timed out",
  1021. poll_cnt))
  1022. return 1;
  1023. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1024. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1025. "Timers NUM_SCANS usage counter timed out",
  1026. poll_cnt))
  1027. return 1;
  1028. /* Wait DMAE PF usage counter to zero */
  1029. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1030. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1031. "DMAE dommand register timed out",
  1032. poll_cnt))
  1033. return 1;
  1034. return 0;
  1035. }
  1036. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1037. {
  1038. u32 val;
  1039. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1040. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1041. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1042. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1043. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1044. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1045. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1046. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1047. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1048. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1049. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1050. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1051. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1052. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1053. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1054. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1055. val);
  1056. }
  1057. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1058. {
  1059. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1060. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1061. /* Re-enable PF target read access */
  1062. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1063. /* Poll HW usage counters */
  1064. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1065. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1066. return -EBUSY;
  1067. /* Zero the igu 'trailing edge' and 'leading edge' */
  1068. /* Send the FW cleanup command */
  1069. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1070. return -EBUSY;
  1071. /* ATC cleanup */
  1072. /* Verify TX hw is flushed */
  1073. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1074. /* Wait 100ms (not adjusted according to platform) */
  1075. msleep(100);
  1076. /* Verify no pending pci transactions */
  1077. if (bnx2x_is_pcie_pending(bp->pdev))
  1078. BNX2X_ERR("PCIE Transactions still pending\n");
  1079. /* Debug */
  1080. bnx2x_hw_enable_status(bp);
  1081. /*
  1082. * Master enable - Due to WB DMAE writes performed before this
  1083. * register is re-initialized as part of the regular function init
  1084. */
  1085. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1086. return 0;
  1087. }
  1088. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1089. {
  1090. int port = BP_PORT(bp);
  1091. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1092. u32 val = REG_RD(bp, addr);
  1093. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1094. int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
  1095. if (msix) {
  1096. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1097. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1098. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1099. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1100. } else if (msi) {
  1101. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1102. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1103. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1104. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1105. } else {
  1106. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1107. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1108. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1109. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1110. if (!CHIP_IS_E1(bp)) {
  1111. DP(NETIF_MSG_IFUP,
  1112. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1113. REG_WR(bp, addr, val);
  1114. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1115. }
  1116. }
  1117. if (CHIP_IS_E1(bp))
  1118. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1119. DP(NETIF_MSG_IFUP,
  1120. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1121. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1122. REG_WR(bp, addr, val);
  1123. /*
  1124. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1125. */
  1126. mmiowb();
  1127. barrier();
  1128. if (!CHIP_IS_E1(bp)) {
  1129. /* init leading/trailing edge */
  1130. if (IS_MF(bp)) {
  1131. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1132. if (bp->port.pmf)
  1133. /* enable nig and gpio3 attention */
  1134. val |= 0x1100;
  1135. } else
  1136. val = 0xffff;
  1137. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1138. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1139. }
  1140. /* Make sure that interrupts are indeed enabled from here on */
  1141. mmiowb();
  1142. }
  1143. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1144. {
  1145. u32 val;
  1146. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1147. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1148. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1149. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1150. if (msix) {
  1151. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1152. IGU_PF_CONF_SINGLE_ISR_EN);
  1153. val |= (IGU_PF_CONF_FUNC_EN |
  1154. IGU_PF_CONF_MSI_MSIX_EN |
  1155. IGU_PF_CONF_ATTN_BIT_EN);
  1156. if (single_msix)
  1157. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1158. } else if (msi) {
  1159. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1160. val |= (IGU_PF_CONF_FUNC_EN |
  1161. IGU_PF_CONF_MSI_MSIX_EN |
  1162. IGU_PF_CONF_ATTN_BIT_EN |
  1163. IGU_PF_CONF_SINGLE_ISR_EN);
  1164. } else {
  1165. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1166. val |= (IGU_PF_CONF_FUNC_EN |
  1167. IGU_PF_CONF_INT_LINE_EN |
  1168. IGU_PF_CONF_ATTN_BIT_EN |
  1169. IGU_PF_CONF_SINGLE_ISR_EN);
  1170. }
  1171. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1172. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1173. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1174. if (val & IGU_PF_CONF_INT_LINE_EN)
  1175. pci_intx(bp->pdev, true);
  1176. barrier();
  1177. /* init leading/trailing edge */
  1178. if (IS_MF(bp)) {
  1179. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1180. if (bp->port.pmf)
  1181. /* enable nig and gpio3 attention */
  1182. val |= 0x1100;
  1183. } else
  1184. val = 0xffff;
  1185. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1186. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1187. /* Make sure that interrupts are indeed enabled from here on */
  1188. mmiowb();
  1189. }
  1190. void bnx2x_int_enable(struct bnx2x *bp)
  1191. {
  1192. if (bp->common.int_block == INT_BLOCK_HC)
  1193. bnx2x_hc_int_enable(bp);
  1194. else
  1195. bnx2x_igu_int_enable(bp);
  1196. }
  1197. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  1198. {
  1199. int port = BP_PORT(bp);
  1200. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1201. u32 val = REG_RD(bp, addr);
  1202. /*
  1203. * in E1 we must use only PCI configuration space to disable
  1204. * MSI/MSIX capablility
  1205. * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  1206. */
  1207. if (CHIP_IS_E1(bp)) {
  1208. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  1209. * Use mask register to prevent from HC sending interrupts
  1210. * after we exit the function
  1211. */
  1212. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  1213. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1214. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1215. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1216. } else
  1217. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1218. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1219. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1220. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1221. DP(NETIF_MSG_IFDOWN,
  1222. "write %x to HC %d (addr 0x%x)\n",
  1223. val, port, addr);
  1224. /* flush all outstanding writes */
  1225. mmiowb();
  1226. REG_WR(bp, addr, val);
  1227. if (REG_RD(bp, addr) != val)
  1228. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1229. }
  1230. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  1231. {
  1232. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1233. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  1234. IGU_PF_CONF_INT_LINE_EN |
  1235. IGU_PF_CONF_ATTN_BIT_EN);
  1236. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  1237. /* flush all outstanding writes */
  1238. mmiowb();
  1239. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1240. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  1241. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1242. }
  1243. void bnx2x_int_disable(struct bnx2x *bp)
  1244. {
  1245. if (bp->common.int_block == INT_BLOCK_HC)
  1246. bnx2x_hc_int_disable(bp);
  1247. else
  1248. bnx2x_igu_int_disable(bp);
  1249. }
  1250. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1251. {
  1252. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1253. int i, offset;
  1254. if (disable_hw)
  1255. /* prevent the HW from sending interrupts */
  1256. bnx2x_int_disable(bp);
  1257. /* make sure all ISRs are done */
  1258. if (msix) {
  1259. synchronize_irq(bp->msix_table[0].vector);
  1260. offset = 1;
  1261. #ifdef BCM_CNIC
  1262. offset++;
  1263. #endif
  1264. for_each_eth_queue(bp, i)
  1265. synchronize_irq(bp->msix_table[offset++].vector);
  1266. } else
  1267. synchronize_irq(bp->pdev->irq);
  1268. /* make sure sp_task is not running */
  1269. cancel_delayed_work(&bp->sp_task);
  1270. cancel_delayed_work(&bp->period_task);
  1271. flush_workqueue(bnx2x_wq);
  1272. }
  1273. /* fast path */
  1274. /*
  1275. * General service functions
  1276. */
  1277. /* Return true if succeeded to acquire the lock */
  1278. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1279. {
  1280. u32 lock_status;
  1281. u32 resource_bit = (1 << resource);
  1282. int func = BP_FUNC(bp);
  1283. u32 hw_lock_control_reg;
  1284. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1285. "Trying to take a lock on resource %d\n", resource);
  1286. /* Validating that the resource is within range */
  1287. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1288. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1289. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1290. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1291. return false;
  1292. }
  1293. if (func <= 5)
  1294. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1295. else
  1296. hw_lock_control_reg =
  1297. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1298. /* Try to acquire the lock */
  1299. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1300. lock_status = REG_RD(bp, hw_lock_control_reg);
  1301. if (lock_status & resource_bit)
  1302. return true;
  1303. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1304. "Failed to get a lock on resource %d\n", resource);
  1305. return false;
  1306. }
  1307. /**
  1308. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1309. *
  1310. * @bp: driver handle
  1311. *
  1312. * Returns the recovery leader resource id according to the engine this function
  1313. * belongs to. Currently only only 2 engines is supported.
  1314. */
  1315. static inline int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1316. {
  1317. if (BP_PATH(bp))
  1318. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1319. else
  1320. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1321. }
  1322. /**
  1323. * bnx2x_trylock_leader_lock- try to aquire a leader lock.
  1324. *
  1325. * @bp: driver handle
  1326. *
  1327. * Tries to aquire a leader lock for cuurent engine.
  1328. */
  1329. static inline bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1330. {
  1331. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1332. }
  1333. #ifdef BCM_CNIC
  1334. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1335. #endif
  1336. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1337. {
  1338. struct bnx2x *bp = fp->bp;
  1339. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1340. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1341. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1342. struct bnx2x_queue_sp_obj *q_obj = &fp->q_obj;
  1343. DP(BNX2X_MSG_SP,
  1344. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1345. fp->index, cid, command, bp->state,
  1346. rr_cqe->ramrod_cqe.ramrod_type);
  1347. switch (command) {
  1348. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1349. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1350. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1351. break;
  1352. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1353. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1354. drv_cmd = BNX2X_Q_CMD_SETUP;
  1355. break;
  1356. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1357. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1358. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1359. break;
  1360. case (RAMROD_CMD_ID_ETH_HALT):
  1361. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1362. drv_cmd = BNX2X_Q_CMD_HALT;
  1363. break;
  1364. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1365. DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
  1366. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1367. break;
  1368. case (RAMROD_CMD_ID_ETH_EMPTY):
  1369. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1370. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1371. break;
  1372. default:
  1373. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1374. command, fp->index);
  1375. return;
  1376. }
  1377. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1378. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1379. /* q_obj->complete_cmd() failure means that this was
  1380. * an unexpected completion.
  1381. *
  1382. * In this case we don't want to increase the bp->spq_left
  1383. * because apparently we haven't sent this command the first
  1384. * place.
  1385. */
  1386. #ifdef BNX2X_STOP_ON_ERROR
  1387. bnx2x_panic();
  1388. #else
  1389. return;
  1390. #endif
  1391. smp_mb__before_atomic_inc();
  1392. atomic_inc(&bp->cq_spq_left);
  1393. /* push the change in bp->spq_left and towards the memory */
  1394. smp_mb__after_atomic_inc();
  1395. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1396. return;
  1397. }
  1398. void bnx2x_update_rx_prod(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  1399. u16 bd_prod, u16 rx_comp_prod, u16 rx_sge_prod)
  1400. {
  1401. u32 start = BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset;
  1402. bnx2x_update_rx_prod_gen(bp, fp, bd_prod, rx_comp_prod, rx_sge_prod,
  1403. start);
  1404. }
  1405. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1406. {
  1407. struct bnx2x *bp = netdev_priv(dev_instance);
  1408. u16 status = bnx2x_ack_int(bp);
  1409. u16 mask;
  1410. int i;
  1411. u8 cos;
  1412. /* Return here if interrupt is shared and it's not for us */
  1413. if (unlikely(status == 0)) {
  1414. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1415. return IRQ_NONE;
  1416. }
  1417. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1418. #ifdef BNX2X_STOP_ON_ERROR
  1419. if (unlikely(bp->panic))
  1420. return IRQ_HANDLED;
  1421. #endif
  1422. for_each_eth_queue(bp, i) {
  1423. struct bnx2x_fastpath *fp = &bp->fp[i];
  1424. mask = 0x2 << (fp->index + CNIC_PRESENT);
  1425. if (status & mask) {
  1426. /* Handle Rx or Tx according to SB id */
  1427. prefetch(fp->rx_cons_sb);
  1428. for_each_cos_in_tx_queue(fp, cos)
  1429. prefetch(fp->txdata[cos].tx_cons_sb);
  1430. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1431. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1432. status &= ~mask;
  1433. }
  1434. }
  1435. #ifdef BCM_CNIC
  1436. mask = 0x2;
  1437. if (status & (mask | 0x1)) {
  1438. struct cnic_ops *c_ops = NULL;
  1439. if (likely(bp->state == BNX2X_STATE_OPEN)) {
  1440. rcu_read_lock();
  1441. c_ops = rcu_dereference(bp->cnic_ops);
  1442. if (c_ops)
  1443. c_ops->cnic_handler(bp->cnic_data, NULL);
  1444. rcu_read_unlock();
  1445. }
  1446. status &= ~mask;
  1447. }
  1448. #endif
  1449. if (unlikely(status & 0x1)) {
  1450. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1451. status &= ~0x1;
  1452. if (!status)
  1453. return IRQ_HANDLED;
  1454. }
  1455. if (unlikely(status))
  1456. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1457. status);
  1458. return IRQ_HANDLED;
  1459. }
  1460. /* Link */
  1461. /*
  1462. * General service functions
  1463. */
  1464. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1465. {
  1466. u32 lock_status;
  1467. u32 resource_bit = (1 << resource);
  1468. int func = BP_FUNC(bp);
  1469. u32 hw_lock_control_reg;
  1470. int cnt;
  1471. /* Validating that the resource is within range */
  1472. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1473. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1474. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1475. return -EINVAL;
  1476. }
  1477. if (func <= 5) {
  1478. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1479. } else {
  1480. hw_lock_control_reg =
  1481. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1482. }
  1483. /* Validating that the resource is not already taken */
  1484. lock_status = REG_RD(bp, hw_lock_control_reg);
  1485. if (lock_status & resource_bit) {
  1486. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1487. lock_status, resource_bit);
  1488. return -EEXIST;
  1489. }
  1490. /* Try for 5 second every 5ms */
  1491. for (cnt = 0; cnt < 1000; cnt++) {
  1492. /* Try to acquire the lock */
  1493. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1494. lock_status = REG_RD(bp, hw_lock_control_reg);
  1495. if (lock_status & resource_bit)
  1496. return 0;
  1497. msleep(5);
  1498. }
  1499. BNX2X_ERR("Timeout\n");
  1500. return -EAGAIN;
  1501. }
  1502. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1503. {
  1504. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1505. }
  1506. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1507. {
  1508. u32 lock_status;
  1509. u32 resource_bit = (1 << resource);
  1510. int func = BP_FUNC(bp);
  1511. u32 hw_lock_control_reg;
  1512. /* Validating that the resource is within range */
  1513. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1514. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1515. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1516. return -EINVAL;
  1517. }
  1518. if (func <= 5) {
  1519. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1520. } else {
  1521. hw_lock_control_reg =
  1522. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1523. }
  1524. /* Validating that the resource is currently taken */
  1525. lock_status = REG_RD(bp, hw_lock_control_reg);
  1526. if (!(lock_status & resource_bit)) {
  1527. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
  1528. lock_status, resource_bit);
  1529. return -EFAULT;
  1530. }
  1531. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1532. return 0;
  1533. }
  1534. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1535. {
  1536. /* The GPIO should be swapped if swap register is set and active */
  1537. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1538. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1539. int gpio_shift = gpio_num +
  1540. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1541. u32 gpio_mask = (1 << gpio_shift);
  1542. u32 gpio_reg;
  1543. int value;
  1544. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1545. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1546. return -EINVAL;
  1547. }
  1548. /* read GPIO value */
  1549. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1550. /* get the requested pin value */
  1551. if ((gpio_reg & gpio_mask) == gpio_mask)
  1552. value = 1;
  1553. else
  1554. value = 0;
  1555. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1556. return value;
  1557. }
  1558. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1559. {
  1560. /* The GPIO should be swapped if swap register is set and active */
  1561. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1562. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1563. int gpio_shift = gpio_num +
  1564. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1565. u32 gpio_mask = (1 << gpio_shift);
  1566. u32 gpio_reg;
  1567. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1568. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1569. return -EINVAL;
  1570. }
  1571. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1572. /* read GPIO and mask except the float bits */
  1573. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1574. switch (mode) {
  1575. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1576. DP(NETIF_MSG_LINK,
  1577. "Set GPIO %d (shift %d) -> output low\n",
  1578. gpio_num, gpio_shift);
  1579. /* clear FLOAT and set CLR */
  1580. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1581. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1582. break;
  1583. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1584. DP(NETIF_MSG_LINK,
  1585. "Set GPIO %d (shift %d) -> output high\n",
  1586. gpio_num, gpio_shift);
  1587. /* clear FLOAT and set SET */
  1588. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1589. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1590. break;
  1591. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1592. DP(NETIF_MSG_LINK,
  1593. "Set GPIO %d (shift %d) -> input\n",
  1594. gpio_num, gpio_shift);
  1595. /* set FLOAT */
  1596. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1597. break;
  1598. default:
  1599. break;
  1600. }
  1601. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1602. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1603. return 0;
  1604. }
  1605. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1606. {
  1607. u32 gpio_reg = 0;
  1608. int rc = 0;
  1609. /* Any port swapping should be handled by caller. */
  1610. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1611. /* read GPIO and mask except the float bits */
  1612. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1613. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1614. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1615. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1616. switch (mode) {
  1617. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1618. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1619. /* set CLR */
  1620. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1621. break;
  1622. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1623. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1624. /* set SET */
  1625. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1626. break;
  1627. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1628. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1629. /* set FLOAT */
  1630. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1631. break;
  1632. default:
  1633. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1634. rc = -EINVAL;
  1635. break;
  1636. }
  1637. if (rc == 0)
  1638. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1639. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1640. return rc;
  1641. }
  1642. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1643. {
  1644. /* The GPIO should be swapped if swap register is set and active */
  1645. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1646. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1647. int gpio_shift = gpio_num +
  1648. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1649. u32 gpio_mask = (1 << gpio_shift);
  1650. u32 gpio_reg;
  1651. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1652. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1653. return -EINVAL;
  1654. }
  1655. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1656. /* read GPIO int */
  1657. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1658. switch (mode) {
  1659. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1660. DP(NETIF_MSG_LINK,
  1661. "Clear GPIO INT %d (shift %d) -> output low\n",
  1662. gpio_num, gpio_shift);
  1663. /* clear SET and set CLR */
  1664. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1665. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1666. break;
  1667. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1668. DP(NETIF_MSG_LINK,
  1669. "Set GPIO INT %d (shift %d) -> output high\n",
  1670. gpio_num, gpio_shift);
  1671. /* clear CLR and set SET */
  1672. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1673. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1674. break;
  1675. default:
  1676. break;
  1677. }
  1678. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1679. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1680. return 0;
  1681. }
  1682. static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode)
  1683. {
  1684. u32 spio_mask = (1 << spio_num);
  1685. u32 spio_reg;
  1686. if ((spio_num < MISC_REGISTERS_SPIO_4) ||
  1687. (spio_num > MISC_REGISTERS_SPIO_7)) {
  1688. BNX2X_ERR("Invalid SPIO %d\n", spio_num);
  1689. return -EINVAL;
  1690. }
  1691. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1692. /* read SPIO and mask except the float bits */
  1693. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT);
  1694. switch (mode) {
  1695. case MISC_REGISTERS_SPIO_OUTPUT_LOW:
  1696. DP(NETIF_MSG_HW, "Set SPIO %d -> output low\n", spio_num);
  1697. /* clear FLOAT and set CLR */
  1698. spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1699. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS);
  1700. break;
  1701. case MISC_REGISTERS_SPIO_OUTPUT_HIGH:
  1702. DP(NETIF_MSG_HW, "Set SPIO %d -> output high\n", spio_num);
  1703. /* clear FLOAT and set SET */
  1704. spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1705. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS);
  1706. break;
  1707. case MISC_REGISTERS_SPIO_INPUT_HI_Z:
  1708. DP(NETIF_MSG_HW, "Set SPIO %d -> input\n", spio_num);
  1709. /* set FLOAT */
  1710. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1711. break;
  1712. default:
  1713. break;
  1714. }
  1715. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1716. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1717. return 0;
  1718. }
  1719. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1720. {
  1721. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1722. switch (bp->link_vars.ieee_fc &
  1723. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1724. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1725. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1726. ADVERTISED_Pause);
  1727. break;
  1728. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1729. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1730. ADVERTISED_Pause);
  1731. break;
  1732. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1733. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1734. break;
  1735. default:
  1736. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1737. ADVERTISED_Pause);
  1738. break;
  1739. }
  1740. }
  1741. u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1742. {
  1743. if (!BP_NOMCP(bp)) {
  1744. u8 rc;
  1745. int cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1746. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1747. /*
  1748. * Initialize link parameters structure variables
  1749. * It is recommended to turn off RX FC for jumbo frames
  1750. * for better performance
  1751. */
  1752. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1753. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1754. else
  1755. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1756. bnx2x_acquire_phy_lock(bp);
  1757. if (load_mode == LOAD_DIAG) {
  1758. struct link_params *lp = &bp->link_params;
  1759. lp->loopback_mode = LOOPBACK_XGXS;
  1760. /* do PHY loopback at 10G speed, if possible */
  1761. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1762. if (lp->speed_cap_mask[cfx_idx] &
  1763. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1764. lp->req_line_speed[cfx_idx] =
  1765. SPEED_10000;
  1766. else
  1767. lp->req_line_speed[cfx_idx] =
  1768. SPEED_1000;
  1769. }
  1770. }
  1771. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1772. bnx2x_release_phy_lock(bp);
  1773. bnx2x_calc_fc_adv(bp);
  1774. if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) {
  1775. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1776. bnx2x_link_report(bp);
  1777. } else
  1778. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1779. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1780. return rc;
  1781. }
  1782. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1783. return -EINVAL;
  1784. }
  1785. void bnx2x_link_set(struct bnx2x *bp)
  1786. {
  1787. if (!BP_NOMCP(bp)) {
  1788. bnx2x_acquire_phy_lock(bp);
  1789. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1790. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1791. bnx2x_release_phy_lock(bp);
  1792. bnx2x_calc_fc_adv(bp);
  1793. } else
  1794. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1795. }
  1796. static void bnx2x__link_reset(struct bnx2x *bp)
  1797. {
  1798. if (!BP_NOMCP(bp)) {
  1799. bnx2x_acquire_phy_lock(bp);
  1800. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1801. bnx2x_release_phy_lock(bp);
  1802. } else
  1803. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1804. }
  1805. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  1806. {
  1807. u8 rc = 0;
  1808. if (!BP_NOMCP(bp)) {
  1809. bnx2x_acquire_phy_lock(bp);
  1810. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  1811. is_serdes);
  1812. bnx2x_release_phy_lock(bp);
  1813. } else
  1814. BNX2X_ERR("Bootcode is missing - can not test link\n");
  1815. return rc;
  1816. }
  1817. /* Calculates the sum of vn_min_rates.
  1818. It's needed for further normalizing of the min_rates.
  1819. Returns:
  1820. sum of vn_min_rates.
  1821. or
  1822. 0 - if all the min_rates are 0.
  1823. In the later case fainess algorithm should be deactivated.
  1824. If not all min_rates are zero then those that are zeroes will be set to 1.
  1825. */
  1826. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  1827. struct cmng_init_input *input)
  1828. {
  1829. int all_zero = 1;
  1830. int vn;
  1831. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1832. u32 vn_cfg = bp->mf_config[vn];
  1833. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  1834. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  1835. /* Skip hidden vns */
  1836. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  1837. vn_min_rate = 0;
  1838. /* If min rate is zero - set it to 1 */
  1839. else if (!vn_min_rate)
  1840. vn_min_rate = DEF_MIN_RATE;
  1841. else
  1842. all_zero = 0;
  1843. input->vnic_min_rate[vn] = vn_min_rate;
  1844. }
  1845. /* if ETS or all min rates are zeros - disable fairness */
  1846. if (BNX2X_IS_ETS_ENABLED(bp)) {
  1847. input->flags.cmng_enables &=
  1848. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1849. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  1850. } else if (all_zero) {
  1851. input->flags.cmng_enables &=
  1852. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1853. DP(NETIF_MSG_IFUP,
  1854. "All MIN values are zeroes fairness will be disabled\n");
  1855. } else
  1856. input->flags.cmng_enables |=
  1857. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1858. }
  1859. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  1860. struct cmng_init_input *input)
  1861. {
  1862. u16 vn_max_rate;
  1863. u32 vn_cfg = bp->mf_config[vn];
  1864. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  1865. vn_max_rate = 0;
  1866. else {
  1867. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  1868. if (IS_MF_SI(bp)) {
  1869. /* maxCfg in percents of linkspeed */
  1870. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  1871. } else /* SD modes */
  1872. /* maxCfg is absolute in 100Mb units */
  1873. vn_max_rate = maxCfg * 100;
  1874. }
  1875. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  1876. input->vnic_max_rate[vn] = vn_max_rate;
  1877. }
  1878. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  1879. {
  1880. if (CHIP_REV_IS_SLOW(bp))
  1881. return CMNG_FNS_NONE;
  1882. if (IS_MF(bp))
  1883. return CMNG_FNS_MINMAX;
  1884. return CMNG_FNS_NONE;
  1885. }
  1886. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  1887. {
  1888. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  1889. if (BP_NOMCP(bp))
  1890. return; /* what should be the default bvalue in this case */
  1891. /* For 2 port configuration the absolute function number formula
  1892. * is:
  1893. * abs_func = 2 * vn + BP_PORT + BP_PATH
  1894. *
  1895. * and there are 4 functions per port
  1896. *
  1897. * For 4 port configuration it is
  1898. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  1899. *
  1900. * and there are 2 functions per port
  1901. */
  1902. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1903. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  1904. if (func >= E1H_FUNC_MAX)
  1905. break;
  1906. bp->mf_config[vn] =
  1907. MF_CFG_RD(bp, func_mf_config[func].config);
  1908. }
  1909. }
  1910. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  1911. {
  1912. struct cmng_init_input input;
  1913. memset(&input, 0, sizeof(struct cmng_init_input));
  1914. input.port_rate = bp->link_vars.line_speed;
  1915. if (cmng_type == CMNG_FNS_MINMAX) {
  1916. int vn;
  1917. /* read mf conf from shmem */
  1918. if (read_cfg)
  1919. bnx2x_read_mf_cfg(bp);
  1920. /* vn_weight_sum and enable fairness if not 0 */
  1921. bnx2x_calc_vn_min(bp, &input);
  1922. /* calculate and set min-max rate for each vn */
  1923. if (bp->port.pmf)
  1924. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  1925. bnx2x_calc_vn_max(bp, vn, &input);
  1926. /* always enable rate shaping and fairness */
  1927. input.flags.cmng_enables |=
  1928. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  1929. bnx2x_init_cmng(&input, &bp->cmng);
  1930. return;
  1931. }
  1932. /* rate shaping and fairness are disabled */
  1933. DP(NETIF_MSG_IFUP,
  1934. "rate shaping and fairness are disabled\n");
  1935. }
  1936. /* This function is called upon link interrupt */
  1937. static void bnx2x_link_attn(struct bnx2x *bp)
  1938. {
  1939. /* Make sure that we are synced with the current statistics */
  1940. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  1941. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  1942. if (bp->link_vars.link_up) {
  1943. /* dropless flow control */
  1944. if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
  1945. int port = BP_PORT(bp);
  1946. u32 pause_enabled = 0;
  1947. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  1948. pause_enabled = 1;
  1949. REG_WR(bp, BAR_USTRORM_INTMEM +
  1950. USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
  1951. pause_enabled);
  1952. }
  1953. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  1954. struct host_port_stats *pstats;
  1955. pstats = bnx2x_sp(bp, port_stats);
  1956. /* reset old mac stats */
  1957. memset(&(pstats->mac_stx[0]), 0,
  1958. sizeof(struct mac_stx));
  1959. }
  1960. if (bp->state == BNX2X_STATE_OPEN)
  1961. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1962. }
  1963. if (bp->link_vars.link_up && bp->link_vars.line_speed) {
  1964. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  1965. if (cmng_fns != CMNG_FNS_NONE) {
  1966. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  1967. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  1968. } else
  1969. /* rate shaping and fairness are disabled */
  1970. DP(NETIF_MSG_IFUP,
  1971. "single function mode without fairness\n");
  1972. }
  1973. __bnx2x_link_report(bp);
  1974. if (IS_MF(bp))
  1975. bnx2x_link_sync_notify(bp);
  1976. }
  1977. void bnx2x__link_status_update(struct bnx2x *bp)
  1978. {
  1979. if (bp->state != BNX2X_STATE_OPEN)
  1980. return;
  1981. /* read updated dcb configuration */
  1982. bnx2x_dcbx_pmf_update(bp);
  1983. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  1984. if (bp->link_vars.link_up)
  1985. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1986. else
  1987. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  1988. /* indicate link status */
  1989. bnx2x_link_report(bp);
  1990. }
  1991. static void bnx2x_pmf_update(struct bnx2x *bp)
  1992. {
  1993. int port = BP_PORT(bp);
  1994. u32 val;
  1995. bp->port.pmf = 1;
  1996. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  1997. /*
  1998. * We need the mb() to ensure the ordering between the writing to
  1999. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2000. */
  2001. smp_mb();
  2002. /* queue a periodic task */
  2003. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2004. bnx2x_dcbx_pmf_update(bp);
  2005. /* enable nig attention */
  2006. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2007. if (bp->common.int_block == INT_BLOCK_HC) {
  2008. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2009. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2010. } else if (!CHIP_IS_E1x(bp)) {
  2011. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2012. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2013. }
  2014. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2015. }
  2016. /* end of Link */
  2017. /* slow path */
  2018. /*
  2019. * General service functions
  2020. */
  2021. /* send the MCP a request, block until there is a reply */
  2022. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2023. {
  2024. int mb_idx = BP_FW_MB_IDX(bp);
  2025. u32 seq;
  2026. u32 rc = 0;
  2027. u32 cnt = 1;
  2028. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2029. mutex_lock(&bp->fw_mb_mutex);
  2030. seq = ++bp->fw_seq;
  2031. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2032. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2033. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2034. (command | seq), param);
  2035. do {
  2036. /* let the FW do it's magic ... */
  2037. msleep(delay);
  2038. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2039. /* Give the FW up to 5 second (500*10ms) */
  2040. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2041. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2042. cnt*delay, rc, seq);
  2043. /* is this a reply to our command? */
  2044. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2045. rc &= FW_MSG_CODE_MASK;
  2046. else {
  2047. /* FW BUG! */
  2048. BNX2X_ERR("FW failed to respond!\n");
  2049. bnx2x_fw_dump(bp);
  2050. rc = 0;
  2051. }
  2052. mutex_unlock(&bp->fw_mb_mutex);
  2053. return rc;
  2054. }
  2055. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2056. {
  2057. if (CHIP_IS_E1x(bp)) {
  2058. struct tstorm_eth_function_common_config tcfg = {0};
  2059. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2060. }
  2061. /* Enable the function in the FW */
  2062. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2063. storm_memset_func_en(bp, p->func_id, 1);
  2064. /* spq */
  2065. if (p->func_flgs & FUNC_FLG_SPQ) {
  2066. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2067. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2068. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2069. }
  2070. }
  2071. /**
  2072. * bnx2x_get_tx_only_flags - Return common flags
  2073. *
  2074. * @bp device handle
  2075. * @fp queue handle
  2076. * @zero_stats TRUE if statistics zeroing is needed
  2077. *
  2078. * Return the flags that are common for the Tx-only and not normal connections.
  2079. */
  2080. static inline unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2081. struct bnx2x_fastpath *fp,
  2082. bool zero_stats)
  2083. {
  2084. unsigned long flags = 0;
  2085. /* PF driver will always initialize the Queue to an ACTIVE state */
  2086. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2087. /* tx only connections collect statistics (on the same index as the
  2088. * parent connection). The statistics are zeroed when the parent
  2089. * connection is initialized.
  2090. */
  2091. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2092. if (zero_stats)
  2093. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2094. return flags;
  2095. }
  2096. static inline unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2097. struct bnx2x_fastpath *fp,
  2098. bool leading)
  2099. {
  2100. unsigned long flags = 0;
  2101. /* calculate other queue flags */
  2102. if (IS_MF_SD(bp))
  2103. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2104. if (IS_FCOE_FP(fp))
  2105. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2106. if (!fp->disable_tpa) {
  2107. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2108. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2109. if (fp->mode == TPA_MODE_GRO)
  2110. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2111. }
  2112. if (leading) {
  2113. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2114. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2115. }
  2116. /* Always set HW VLAN stripping */
  2117. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2118. return flags | bnx2x_get_common_flags(bp, fp, true);
  2119. }
  2120. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2121. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2122. u8 cos)
  2123. {
  2124. gen_init->stat_id = bnx2x_stats_id(fp);
  2125. gen_init->spcl_id = fp->cl_id;
  2126. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2127. if (IS_FCOE_FP(fp))
  2128. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2129. else
  2130. gen_init->mtu = bp->dev->mtu;
  2131. gen_init->cos = cos;
  2132. }
  2133. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2134. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2135. struct bnx2x_rxq_setup_params *rxq_init)
  2136. {
  2137. u8 max_sge = 0;
  2138. u16 sge_sz = 0;
  2139. u16 tpa_agg_size = 0;
  2140. if (!fp->disable_tpa) {
  2141. pause->sge_th_lo = SGE_TH_LO(bp);
  2142. pause->sge_th_hi = SGE_TH_HI(bp);
  2143. /* validate SGE ring has enough to cross high threshold */
  2144. WARN_ON(bp->dropless_fc &&
  2145. pause->sge_th_hi + FW_PREFETCH_CNT >
  2146. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2147. tpa_agg_size = min_t(u32,
  2148. (min_t(u32, 8, MAX_SKB_FRAGS) *
  2149. SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
  2150. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2151. SGE_PAGE_SHIFT;
  2152. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2153. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2154. sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
  2155. 0xffff);
  2156. }
  2157. /* pause - not for e1 */
  2158. if (!CHIP_IS_E1(bp)) {
  2159. pause->bd_th_lo = BD_TH_LO(bp);
  2160. pause->bd_th_hi = BD_TH_HI(bp);
  2161. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2162. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2163. /*
  2164. * validate that rings have enough entries to cross
  2165. * high thresholds
  2166. */
  2167. WARN_ON(bp->dropless_fc &&
  2168. pause->bd_th_hi + FW_PREFETCH_CNT >
  2169. bp->rx_ring_size);
  2170. WARN_ON(bp->dropless_fc &&
  2171. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2172. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2173. pause->pri_map = 1;
  2174. }
  2175. /* rxq setup */
  2176. rxq_init->dscr_map = fp->rx_desc_mapping;
  2177. rxq_init->sge_map = fp->rx_sge_mapping;
  2178. rxq_init->rcq_map = fp->rx_comp_mapping;
  2179. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2180. /* This should be a maximum number of data bytes that may be
  2181. * placed on the BD (not including paddings).
  2182. */
  2183. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2184. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2185. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2186. rxq_init->tpa_agg_sz = tpa_agg_size;
  2187. rxq_init->sge_buf_sz = sge_sz;
  2188. rxq_init->max_sges_pkt = max_sge;
  2189. rxq_init->rss_engine_id = BP_FUNC(bp);
  2190. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2191. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2192. *
  2193. * For PF Clients it should be the maximum avaliable number.
  2194. * VF driver(s) may want to define it to a smaller value.
  2195. */
  2196. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2197. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2198. rxq_init->fw_sb_id = fp->fw_sb_id;
  2199. if (IS_FCOE_FP(fp))
  2200. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2201. else
  2202. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2203. }
  2204. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2205. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2206. u8 cos)
  2207. {
  2208. txq_init->dscr_map = fp->txdata[cos].tx_desc_mapping;
  2209. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2210. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2211. txq_init->fw_sb_id = fp->fw_sb_id;
  2212. /*
  2213. * set the tss leading client id for TX classfication ==
  2214. * leading RSS client id
  2215. */
  2216. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2217. if (IS_FCOE_FP(fp)) {
  2218. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2219. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2220. }
  2221. }
  2222. static void bnx2x_pf_init(struct bnx2x *bp)
  2223. {
  2224. struct bnx2x_func_init_params func_init = {0};
  2225. struct event_ring_data eq_data = { {0} };
  2226. u16 flags;
  2227. if (!CHIP_IS_E1x(bp)) {
  2228. /* reset IGU PF statistics: MSIX + ATTN */
  2229. /* PF */
  2230. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2231. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2232. (CHIP_MODE_IS_4_PORT(bp) ?
  2233. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2234. /* ATTN */
  2235. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2236. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2237. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2238. (CHIP_MODE_IS_4_PORT(bp) ?
  2239. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2240. }
  2241. /* function setup flags */
  2242. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2243. /* This flag is relevant for E1x only.
  2244. * E2 doesn't have a TPA configuration in a function level.
  2245. */
  2246. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2247. func_init.func_flgs = flags;
  2248. func_init.pf_id = BP_FUNC(bp);
  2249. func_init.func_id = BP_FUNC(bp);
  2250. func_init.spq_map = bp->spq_mapping;
  2251. func_init.spq_prod = bp->spq_prod_idx;
  2252. bnx2x_func_init(bp, &func_init);
  2253. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2254. /*
  2255. * Congestion management values depend on the link rate
  2256. * There is no active link so initial link rate is set to 10 Gbps.
  2257. * When the link comes up The congestion management values are
  2258. * re-calculated according to the actual link rate.
  2259. */
  2260. bp->link_vars.line_speed = SPEED_10000;
  2261. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2262. /* Only the PMF sets the HW */
  2263. if (bp->port.pmf)
  2264. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2265. /* init Event Queue */
  2266. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2267. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2268. eq_data.producer = bp->eq_prod;
  2269. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2270. eq_data.sb_id = DEF_SB_ID;
  2271. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2272. }
  2273. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2274. {
  2275. int port = BP_PORT(bp);
  2276. bnx2x_tx_disable(bp);
  2277. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2278. }
  2279. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2280. {
  2281. int port = BP_PORT(bp);
  2282. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2283. /* Tx queue should be only reenabled */
  2284. netif_tx_wake_all_queues(bp->dev);
  2285. /*
  2286. * Should not call netif_carrier_on since it will be called if the link
  2287. * is up when checking for link state
  2288. */
  2289. }
  2290. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2291. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2292. {
  2293. struct eth_stats_info *ether_stat =
  2294. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2295. /* leave last char as NULL */
  2296. memcpy(ether_stat->version, DRV_MODULE_VERSION,
  2297. ETH_STAT_INFO_VERSION_LEN - 1);
  2298. bp->fp[0].mac_obj.get_n_elements(bp, &bp->fp[0].mac_obj,
  2299. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2300. ether_stat->mac_local);
  2301. ether_stat->mtu_size = bp->dev->mtu;
  2302. if (bp->dev->features & NETIF_F_RXCSUM)
  2303. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2304. if (bp->dev->features & NETIF_F_TSO)
  2305. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2306. ether_stat->feature_flags |= bp->common.boot_mode;
  2307. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2308. ether_stat->txq_size = bp->tx_ring_size;
  2309. ether_stat->rxq_size = bp->rx_ring_size;
  2310. }
  2311. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2312. {
  2313. #ifdef BCM_CNIC
  2314. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2315. struct fcoe_stats_info *fcoe_stat =
  2316. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2317. memcpy(fcoe_stat->mac_local, bp->fip_mac, ETH_ALEN);
  2318. fcoe_stat->qos_priority =
  2319. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2320. /* insert FCoE stats from ramrod response */
  2321. if (!NO_FCOE(bp)) {
  2322. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2323. &bp->fw_stats_data->queue_stats[FCOE_IDX].
  2324. tstorm_queue_statistics;
  2325. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2326. &bp->fw_stats_data->queue_stats[FCOE_IDX].
  2327. xstorm_queue_statistics;
  2328. struct fcoe_statistics_params *fw_fcoe_stat =
  2329. &bp->fw_stats_data->fcoe;
  2330. ADD_64(fcoe_stat->rx_bytes_hi, 0, fcoe_stat->rx_bytes_lo,
  2331. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2332. ADD_64(fcoe_stat->rx_bytes_hi,
  2333. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2334. fcoe_stat->rx_bytes_lo,
  2335. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2336. ADD_64(fcoe_stat->rx_bytes_hi,
  2337. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2338. fcoe_stat->rx_bytes_lo,
  2339. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2340. ADD_64(fcoe_stat->rx_bytes_hi,
  2341. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2342. fcoe_stat->rx_bytes_lo,
  2343. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2344. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2345. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2346. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2347. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2348. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2349. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2350. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2351. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2352. ADD_64(fcoe_stat->tx_bytes_hi, 0, fcoe_stat->tx_bytes_lo,
  2353. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2354. ADD_64(fcoe_stat->tx_bytes_hi,
  2355. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2356. fcoe_stat->tx_bytes_lo,
  2357. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2358. ADD_64(fcoe_stat->tx_bytes_hi,
  2359. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2360. fcoe_stat->tx_bytes_lo,
  2361. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2362. ADD_64(fcoe_stat->tx_bytes_hi,
  2363. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2364. fcoe_stat->tx_bytes_lo,
  2365. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2366. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2367. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2368. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2369. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2370. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2371. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2372. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2373. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2374. }
  2375. /* ask L5 driver to add data to the struct */
  2376. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2377. #endif
  2378. }
  2379. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2380. {
  2381. #ifdef BCM_CNIC
  2382. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2383. struct iscsi_stats_info *iscsi_stat =
  2384. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2385. memcpy(iscsi_stat->mac_local, bp->cnic_eth_dev.iscsi_mac, ETH_ALEN);
  2386. iscsi_stat->qos_priority =
  2387. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2388. /* ask L5 driver to add data to the struct */
  2389. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2390. #endif
  2391. }
  2392. /* called due to MCP event (on pmf):
  2393. * reread new bandwidth configuration
  2394. * configure FW
  2395. * notify others function about the change
  2396. */
  2397. static inline void bnx2x_config_mf_bw(struct bnx2x *bp)
  2398. {
  2399. if (bp->link_vars.link_up) {
  2400. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2401. bnx2x_link_sync_notify(bp);
  2402. }
  2403. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2404. }
  2405. static inline void bnx2x_set_mf_bw(struct bnx2x *bp)
  2406. {
  2407. bnx2x_config_mf_bw(bp);
  2408. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2409. }
  2410. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2411. {
  2412. enum drv_info_opcode op_code;
  2413. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2414. /* if drv_info version supported by MFW doesn't match - send NACK */
  2415. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2416. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2417. return;
  2418. }
  2419. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2420. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2421. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2422. sizeof(union drv_info_to_mcp));
  2423. switch (op_code) {
  2424. case ETH_STATS_OPCODE:
  2425. bnx2x_drv_info_ether_stat(bp);
  2426. break;
  2427. case FCOE_STATS_OPCODE:
  2428. bnx2x_drv_info_fcoe_stat(bp);
  2429. break;
  2430. case ISCSI_STATS_OPCODE:
  2431. bnx2x_drv_info_iscsi_stat(bp);
  2432. break;
  2433. default:
  2434. /* if op code isn't supported - send NACK */
  2435. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2436. return;
  2437. }
  2438. /* if we got drv_info attn from MFW then these fields are defined in
  2439. * shmem2 for sure
  2440. */
  2441. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2442. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2443. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2444. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2445. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2446. }
  2447. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2448. {
  2449. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2450. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2451. /*
  2452. * This is the only place besides the function initialization
  2453. * where the bp->flags can change so it is done without any
  2454. * locks
  2455. */
  2456. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2457. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  2458. bp->flags |= MF_FUNC_DIS;
  2459. bnx2x_e1h_disable(bp);
  2460. } else {
  2461. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  2462. bp->flags &= ~MF_FUNC_DIS;
  2463. bnx2x_e1h_enable(bp);
  2464. }
  2465. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2466. }
  2467. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2468. bnx2x_config_mf_bw(bp);
  2469. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2470. }
  2471. /* Report results to MCP */
  2472. if (dcc_event)
  2473. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2474. else
  2475. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2476. }
  2477. /* must be called under the spq lock */
  2478. static inline struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2479. {
  2480. struct eth_spe *next_spe = bp->spq_prod_bd;
  2481. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2482. bp->spq_prod_bd = bp->spq;
  2483. bp->spq_prod_idx = 0;
  2484. DP(BNX2X_MSG_SP, "end of spq\n");
  2485. } else {
  2486. bp->spq_prod_bd++;
  2487. bp->spq_prod_idx++;
  2488. }
  2489. return next_spe;
  2490. }
  2491. /* must be called under the spq lock */
  2492. static inline void bnx2x_sp_prod_update(struct bnx2x *bp)
  2493. {
  2494. int func = BP_FUNC(bp);
  2495. /*
  2496. * Make sure that BD data is updated before writing the producer:
  2497. * BD data is written to the memory, the producer is read from the
  2498. * memory, thus we need a full memory barrier to ensure the ordering.
  2499. */
  2500. mb();
  2501. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2502. bp->spq_prod_idx);
  2503. mmiowb();
  2504. }
  2505. /**
  2506. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2507. *
  2508. * @cmd: command to check
  2509. * @cmd_type: command type
  2510. */
  2511. static inline bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2512. {
  2513. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2514. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  2515. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2516. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2517. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  2518. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  2519. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  2520. return true;
  2521. else
  2522. return false;
  2523. }
  2524. /**
  2525. * bnx2x_sp_post - place a single command on an SP ring
  2526. *
  2527. * @bp: driver handle
  2528. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  2529. * @cid: SW CID the command is related to
  2530. * @data_hi: command private data address (high 32 bits)
  2531. * @data_lo: command private data address (low 32 bits)
  2532. * @cmd_type: command type (e.g. NONE, ETH)
  2533. *
  2534. * SP data is handled as if it's always an address pair, thus data fields are
  2535. * not swapped to little endian in upper functions. Instead this function swaps
  2536. * data as if it's two u32 fields.
  2537. */
  2538. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  2539. u32 data_hi, u32 data_lo, int cmd_type)
  2540. {
  2541. struct eth_spe *spe;
  2542. u16 type;
  2543. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  2544. #ifdef BNX2X_STOP_ON_ERROR
  2545. if (unlikely(bp->panic)) {
  2546. BNX2X_ERR("Can't post SP when there is panic\n");
  2547. return -EIO;
  2548. }
  2549. #endif
  2550. spin_lock_bh(&bp->spq_lock);
  2551. if (common) {
  2552. if (!atomic_read(&bp->eq_spq_left)) {
  2553. BNX2X_ERR("BUG! EQ ring full!\n");
  2554. spin_unlock_bh(&bp->spq_lock);
  2555. bnx2x_panic();
  2556. return -EBUSY;
  2557. }
  2558. } else if (!atomic_read(&bp->cq_spq_left)) {
  2559. BNX2X_ERR("BUG! SPQ ring full!\n");
  2560. spin_unlock_bh(&bp->spq_lock);
  2561. bnx2x_panic();
  2562. return -EBUSY;
  2563. }
  2564. spe = bnx2x_sp_get_next(bp);
  2565. /* CID needs port number to be encoded int it */
  2566. spe->hdr.conn_and_cmd_data =
  2567. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  2568. HW_CID(bp, cid));
  2569. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  2570. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  2571. SPE_HDR_FUNCTION_ID);
  2572. spe->hdr.type = cpu_to_le16(type);
  2573. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  2574. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  2575. /*
  2576. * It's ok if the actual decrement is issued towards the memory
  2577. * somewhere between the spin_lock and spin_unlock. Thus no
  2578. * more explict memory barrier is needed.
  2579. */
  2580. if (common)
  2581. atomic_dec(&bp->eq_spq_left);
  2582. else
  2583. atomic_dec(&bp->cq_spq_left);
  2584. DP(BNX2X_MSG_SP,
  2585. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  2586. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  2587. (u32)(U64_LO(bp->spq_mapping) +
  2588. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  2589. HW_CID(bp, cid), data_hi, data_lo, type,
  2590. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  2591. bnx2x_sp_prod_update(bp);
  2592. spin_unlock_bh(&bp->spq_lock);
  2593. return 0;
  2594. }
  2595. /* acquire split MCP access lock register */
  2596. static int bnx2x_acquire_alr(struct bnx2x *bp)
  2597. {
  2598. u32 j, val;
  2599. int rc = 0;
  2600. might_sleep();
  2601. for (j = 0; j < 1000; j++) {
  2602. val = (1UL << 31);
  2603. REG_WR(bp, GRCBASE_MCP + 0x9c, val);
  2604. val = REG_RD(bp, GRCBASE_MCP + 0x9c);
  2605. if (val & (1L << 31))
  2606. break;
  2607. msleep(5);
  2608. }
  2609. if (!(val & (1L << 31))) {
  2610. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  2611. rc = -EBUSY;
  2612. }
  2613. return rc;
  2614. }
  2615. /* release split MCP access lock register */
  2616. static void bnx2x_release_alr(struct bnx2x *bp)
  2617. {
  2618. REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
  2619. }
  2620. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  2621. #define BNX2X_DEF_SB_IDX 0x0002
  2622. static inline u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  2623. {
  2624. struct host_sp_status_block *def_sb = bp->def_status_blk;
  2625. u16 rc = 0;
  2626. barrier(); /* status block is written to by the chip */
  2627. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  2628. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  2629. rc |= BNX2X_DEF_SB_ATT_IDX;
  2630. }
  2631. if (bp->def_idx != def_sb->sp_sb.running_index) {
  2632. bp->def_idx = def_sb->sp_sb.running_index;
  2633. rc |= BNX2X_DEF_SB_IDX;
  2634. }
  2635. /* Do not reorder: indecies reading should complete before handling */
  2636. barrier();
  2637. return rc;
  2638. }
  2639. /*
  2640. * slow path service functions
  2641. */
  2642. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  2643. {
  2644. int port = BP_PORT(bp);
  2645. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  2646. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  2647. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  2648. NIG_REG_MASK_INTERRUPT_PORT0;
  2649. u32 aeu_mask;
  2650. u32 nig_mask = 0;
  2651. u32 reg_addr;
  2652. if (bp->attn_state & asserted)
  2653. BNX2X_ERR("IGU ERROR\n");
  2654. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2655. aeu_mask = REG_RD(bp, aeu_addr);
  2656. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  2657. aeu_mask, asserted);
  2658. aeu_mask &= ~(asserted & 0x3ff);
  2659. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  2660. REG_WR(bp, aeu_addr, aeu_mask);
  2661. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2662. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  2663. bp->attn_state |= asserted;
  2664. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  2665. if (asserted & ATTN_HARD_WIRED_MASK) {
  2666. if (asserted & ATTN_NIG_FOR_FUNC) {
  2667. bnx2x_acquire_phy_lock(bp);
  2668. /* save nig interrupt mask */
  2669. nig_mask = REG_RD(bp, nig_int_mask_addr);
  2670. /* If nig_mask is not set, no need to call the update
  2671. * function.
  2672. */
  2673. if (nig_mask) {
  2674. REG_WR(bp, nig_int_mask_addr, 0);
  2675. bnx2x_link_attn(bp);
  2676. }
  2677. /* handle unicore attn? */
  2678. }
  2679. if (asserted & ATTN_SW_TIMER_4_FUNC)
  2680. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  2681. if (asserted & GPIO_2_FUNC)
  2682. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  2683. if (asserted & GPIO_3_FUNC)
  2684. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  2685. if (asserted & GPIO_4_FUNC)
  2686. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  2687. if (port == 0) {
  2688. if (asserted & ATTN_GENERAL_ATTN_1) {
  2689. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  2690. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  2691. }
  2692. if (asserted & ATTN_GENERAL_ATTN_2) {
  2693. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  2694. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  2695. }
  2696. if (asserted & ATTN_GENERAL_ATTN_3) {
  2697. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  2698. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  2699. }
  2700. } else {
  2701. if (asserted & ATTN_GENERAL_ATTN_4) {
  2702. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  2703. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  2704. }
  2705. if (asserted & ATTN_GENERAL_ATTN_5) {
  2706. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  2707. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  2708. }
  2709. if (asserted & ATTN_GENERAL_ATTN_6) {
  2710. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  2711. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  2712. }
  2713. }
  2714. } /* if hardwired */
  2715. if (bp->common.int_block == INT_BLOCK_HC)
  2716. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  2717. COMMAND_REG_ATTN_BITS_SET);
  2718. else
  2719. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  2720. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  2721. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  2722. REG_WR(bp, reg_addr, asserted);
  2723. /* now set back the mask */
  2724. if (asserted & ATTN_NIG_FOR_FUNC) {
  2725. REG_WR(bp, nig_int_mask_addr, nig_mask);
  2726. bnx2x_release_phy_lock(bp);
  2727. }
  2728. }
  2729. static inline void bnx2x_fan_failure(struct bnx2x *bp)
  2730. {
  2731. int port = BP_PORT(bp);
  2732. u32 ext_phy_config;
  2733. /* mark the failure */
  2734. ext_phy_config =
  2735. SHMEM_RD(bp,
  2736. dev_info.port_hw_config[port].external_phy_config);
  2737. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  2738. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  2739. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  2740. ext_phy_config);
  2741. /* log the failure */
  2742. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  2743. "Please contact OEM Support for assistance\n");
  2744. /*
  2745. * Scheudle device reset (unload)
  2746. * This is due to some boards consuming sufficient power when driver is
  2747. * up to overheat if fan fails.
  2748. */
  2749. smp_mb__before_clear_bit();
  2750. set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
  2751. smp_mb__after_clear_bit();
  2752. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  2753. }
  2754. static inline void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  2755. {
  2756. int port = BP_PORT(bp);
  2757. int reg_offset;
  2758. u32 val;
  2759. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  2760. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  2761. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  2762. val = REG_RD(bp, reg_offset);
  2763. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  2764. REG_WR(bp, reg_offset, val);
  2765. BNX2X_ERR("SPIO5 hw attention\n");
  2766. /* Fan failure attention */
  2767. bnx2x_hw_reset_phy(&bp->link_params);
  2768. bnx2x_fan_failure(bp);
  2769. }
  2770. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  2771. bnx2x_acquire_phy_lock(bp);
  2772. bnx2x_handle_module_detect_int(&bp->link_params);
  2773. bnx2x_release_phy_lock(bp);
  2774. }
  2775. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  2776. val = REG_RD(bp, reg_offset);
  2777. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  2778. REG_WR(bp, reg_offset, val);
  2779. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  2780. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  2781. bnx2x_panic();
  2782. }
  2783. }
  2784. static inline void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  2785. {
  2786. u32 val;
  2787. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  2788. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  2789. BNX2X_ERR("DB hw attention 0x%x\n", val);
  2790. /* DORQ discard attention */
  2791. if (val & 0x2)
  2792. BNX2X_ERR("FATAL error from DORQ\n");
  2793. }
  2794. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  2795. int port = BP_PORT(bp);
  2796. int reg_offset;
  2797. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  2798. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  2799. val = REG_RD(bp, reg_offset);
  2800. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  2801. REG_WR(bp, reg_offset, val);
  2802. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  2803. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  2804. bnx2x_panic();
  2805. }
  2806. }
  2807. static inline void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  2808. {
  2809. u32 val;
  2810. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  2811. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  2812. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  2813. /* CFC error attention */
  2814. if (val & 0x2)
  2815. BNX2X_ERR("FATAL error from CFC\n");
  2816. }
  2817. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  2818. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  2819. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  2820. /* RQ_USDMDP_FIFO_OVERFLOW */
  2821. if (val & 0x18000)
  2822. BNX2X_ERR("FATAL error from PXP\n");
  2823. if (!CHIP_IS_E1x(bp)) {
  2824. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  2825. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  2826. }
  2827. }
  2828. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  2829. int port = BP_PORT(bp);
  2830. int reg_offset;
  2831. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  2832. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  2833. val = REG_RD(bp, reg_offset);
  2834. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  2835. REG_WR(bp, reg_offset, val);
  2836. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  2837. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  2838. bnx2x_panic();
  2839. }
  2840. }
  2841. static inline void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  2842. {
  2843. u32 val;
  2844. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  2845. if (attn & BNX2X_PMF_LINK_ASSERT) {
  2846. int func = BP_FUNC(bp);
  2847. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  2848. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  2849. func_mf_config[BP_ABS_FUNC(bp)].config);
  2850. val = SHMEM_RD(bp,
  2851. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  2852. if (val & DRV_STATUS_DCC_EVENT_MASK)
  2853. bnx2x_dcc_event(bp,
  2854. (val & DRV_STATUS_DCC_EVENT_MASK));
  2855. if (val & DRV_STATUS_SET_MF_BW)
  2856. bnx2x_set_mf_bw(bp);
  2857. if (val & DRV_STATUS_DRV_INFO_REQ)
  2858. bnx2x_handle_drv_info_req(bp);
  2859. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  2860. bnx2x_pmf_update(bp);
  2861. if (bp->port.pmf &&
  2862. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  2863. bp->dcbx_enabled > 0)
  2864. /* start dcbx state machine */
  2865. bnx2x_dcbx_set_params(bp,
  2866. BNX2X_DCBX_STATE_NEG_RECEIVED);
  2867. if (bp->link_vars.periodic_flags &
  2868. PERIODIC_FLAGS_LINK_EVENT) {
  2869. /* sync with link */
  2870. bnx2x_acquire_phy_lock(bp);
  2871. bp->link_vars.periodic_flags &=
  2872. ~PERIODIC_FLAGS_LINK_EVENT;
  2873. bnx2x_release_phy_lock(bp);
  2874. if (IS_MF(bp))
  2875. bnx2x_link_sync_notify(bp);
  2876. bnx2x_link_report(bp);
  2877. }
  2878. /* Always call it here: bnx2x_link_report() will
  2879. * prevent the link indication duplication.
  2880. */
  2881. bnx2x__link_status_update(bp);
  2882. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  2883. BNX2X_ERR("MC assert!\n");
  2884. bnx2x_mc_assert(bp);
  2885. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  2886. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  2887. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  2888. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  2889. bnx2x_panic();
  2890. } else if (attn & BNX2X_MCP_ASSERT) {
  2891. BNX2X_ERR("MCP assert!\n");
  2892. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  2893. bnx2x_fw_dump(bp);
  2894. } else
  2895. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  2896. }
  2897. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  2898. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  2899. if (attn & BNX2X_GRC_TIMEOUT) {
  2900. val = CHIP_IS_E1(bp) ? 0 :
  2901. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  2902. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  2903. }
  2904. if (attn & BNX2X_GRC_RSV) {
  2905. val = CHIP_IS_E1(bp) ? 0 :
  2906. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  2907. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  2908. }
  2909. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  2910. }
  2911. }
  2912. /*
  2913. * Bits map:
  2914. * 0-7 - Engine0 load counter.
  2915. * 8-15 - Engine1 load counter.
  2916. * 16 - Engine0 RESET_IN_PROGRESS bit.
  2917. * 17 - Engine1 RESET_IN_PROGRESS bit.
  2918. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  2919. * on the engine
  2920. * 19 - Engine1 ONE_IS_LOADED.
  2921. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  2922. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  2923. * just the one belonging to its engine).
  2924. *
  2925. */
  2926. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  2927. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  2928. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  2929. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  2930. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  2931. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  2932. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  2933. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  2934. /*
  2935. * Set the GLOBAL_RESET bit.
  2936. *
  2937. * Should be run under rtnl lock
  2938. */
  2939. void bnx2x_set_reset_global(struct bnx2x *bp)
  2940. {
  2941. u32 val;
  2942. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  2943. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  2944. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  2945. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  2946. }
  2947. /*
  2948. * Clear the GLOBAL_RESET bit.
  2949. *
  2950. * Should be run under rtnl lock
  2951. */
  2952. static inline void bnx2x_clear_reset_global(struct bnx2x *bp)
  2953. {
  2954. u32 val;
  2955. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  2956. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  2957. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  2958. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  2959. }
  2960. /*
  2961. * Checks the GLOBAL_RESET bit.
  2962. *
  2963. * should be run under rtnl lock
  2964. */
  2965. static inline bool bnx2x_reset_is_global(struct bnx2x *bp)
  2966. {
  2967. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  2968. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  2969. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  2970. }
  2971. /*
  2972. * Clear RESET_IN_PROGRESS bit for the current engine.
  2973. *
  2974. * Should be run under rtnl lock
  2975. */
  2976. static inline void bnx2x_set_reset_done(struct bnx2x *bp)
  2977. {
  2978. u32 val;
  2979. u32 bit = BP_PATH(bp) ?
  2980. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  2981. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  2982. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  2983. /* Clear the bit */
  2984. val &= ~bit;
  2985. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  2986. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  2987. }
  2988. /*
  2989. * Set RESET_IN_PROGRESS for the current engine.
  2990. *
  2991. * should be run under rtnl lock
  2992. */
  2993. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  2994. {
  2995. u32 val;
  2996. u32 bit = BP_PATH(bp) ?
  2997. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  2998. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  2999. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3000. /* Set the bit */
  3001. val |= bit;
  3002. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3003. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3004. }
  3005. /*
  3006. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3007. * should be run under rtnl lock
  3008. */
  3009. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3010. {
  3011. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3012. u32 bit = engine ?
  3013. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3014. /* return false if bit is set */
  3015. return (val & bit) ? false : true;
  3016. }
  3017. /*
  3018. * set pf load for the current pf.
  3019. *
  3020. * should be run under rtnl lock
  3021. */
  3022. void bnx2x_set_pf_load(struct bnx2x *bp)
  3023. {
  3024. u32 val1, val;
  3025. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3026. BNX2X_PATH0_LOAD_CNT_MASK;
  3027. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3028. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3029. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3030. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3031. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3032. /* get the current counter value */
  3033. val1 = (val & mask) >> shift;
  3034. /* set bit of that PF */
  3035. val1 |= (1 << bp->pf_num);
  3036. /* clear the old value */
  3037. val &= ~mask;
  3038. /* set the new one */
  3039. val |= ((val1 << shift) & mask);
  3040. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3041. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3042. }
  3043. /**
  3044. * bnx2x_clear_pf_load - clear pf load mark
  3045. *
  3046. * @bp: driver handle
  3047. *
  3048. * Should be run under rtnl lock.
  3049. * Decrements the load counter for the current engine. Returns
  3050. * whether other functions are still loaded
  3051. */
  3052. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3053. {
  3054. u32 val1, val;
  3055. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3056. BNX2X_PATH0_LOAD_CNT_MASK;
  3057. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3058. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3059. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3060. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3061. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3062. /* get the current counter value */
  3063. val1 = (val & mask) >> shift;
  3064. /* clear bit of that PF */
  3065. val1 &= ~(1 << bp->pf_num);
  3066. /* clear the old value */
  3067. val &= ~mask;
  3068. /* set the new one */
  3069. val |= ((val1 << shift) & mask);
  3070. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3071. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3072. return val1 != 0;
  3073. }
  3074. /*
  3075. * Read the load status for the current engine.
  3076. *
  3077. * should be run under rtnl lock
  3078. */
  3079. static inline bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3080. {
  3081. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3082. BNX2X_PATH0_LOAD_CNT_MASK);
  3083. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3084. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3085. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3086. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3087. val = (val & mask) >> shift;
  3088. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3089. engine, val);
  3090. return val != 0;
  3091. }
  3092. /*
  3093. * Reset the load status for the current engine.
  3094. */
  3095. static inline void bnx2x_clear_load_status(struct bnx2x *bp)
  3096. {
  3097. u32 val;
  3098. u32 mask = (BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3099. BNX2X_PATH0_LOAD_CNT_MASK);
  3100. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3101. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3102. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~mask));
  3103. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3104. }
  3105. static inline void _print_next_block(int idx, const char *blk)
  3106. {
  3107. pr_cont("%s%s", idx ? ", " : "", blk);
  3108. }
  3109. static inline int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
  3110. bool print)
  3111. {
  3112. int i = 0;
  3113. u32 cur_bit = 0;
  3114. for (i = 0; sig; i++) {
  3115. cur_bit = ((u32)0x1 << i);
  3116. if (sig & cur_bit) {
  3117. switch (cur_bit) {
  3118. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3119. if (print)
  3120. _print_next_block(par_num++, "BRB");
  3121. break;
  3122. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3123. if (print)
  3124. _print_next_block(par_num++, "PARSER");
  3125. break;
  3126. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3127. if (print)
  3128. _print_next_block(par_num++, "TSDM");
  3129. break;
  3130. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3131. if (print)
  3132. _print_next_block(par_num++,
  3133. "SEARCHER");
  3134. break;
  3135. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3136. if (print)
  3137. _print_next_block(par_num++, "TCM");
  3138. break;
  3139. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3140. if (print)
  3141. _print_next_block(par_num++, "TSEMI");
  3142. break;
  3143. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3144. if (print)
  3145. _print_next_block(par_num++, "XPB");
  3146. break;
  3147. }
  3148. /* Clear the bit */
  3149. sig &= ~cur_bit;
  3150. }
  3151. }
  3152. return par_num;
  3153. }
  3154. static inline int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
  3155. bool *global, bool print)
  3156. {
  3157. int i = 0;
  3158. u32 cur_bit = 0;
  3159. for (i = 0; sig; i++) {
  3160. cur_bit = ((u32)0x1 << i);
  3161. if (sig & cur_bit) {
  3162. switch (cur_bit) {
  3163. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3164. if (print)
  3165. _print_next_block(par_num++, "PBF");
  3166. break;
  3167. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3168. if (print)
  3169. _print_next_block(par_num++, "QM");
  3170. break;
  3171. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3172. if (print)
  3173. _print_next_block(par_num++, "TM");
  3174. break;
  3175. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3176. if (print)
  3177. _print_next_block(par_num++, "XSDM");
  3178. break;
  3179. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3180. if (print)
  3181. _print_next_block(par_num++, "XCM");
  3182. break;
  3183. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3184. if (print)
  3185. _print_next_block(par_num++, "XSEMI");
  3186. break;
  3187. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3188. if (print)
  3189. _print_next_block(par_num++,
  3190. "DOORBELLQ");
  3191. break;
  3192. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3193. if (print)
  3194. _print_next_block(par_num++, "NIG");
  3195. break;
  3196. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3197. if (print)
  3198. _print_next_block(par_num++,
  3199. "VAUX PCI CORE");
  3200. *global = true;
  3201. break;
  3202. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3203. if (print)
  3204. _print_next_block(par_num++, "DEBUG");
  3205. break;
  3206. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3207. if (print)
  3208. _print_next_block(par_num++, "USDM");
  3209. break;
  3210. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3211. if (print)
  3212. _print_next_block(par_num++, "UCM");
  3213. break;
  3214. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3215. if (print)
  3216. _print_next_block(par_num++, "USEMI");
  3217. break;
  3218. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3219. if (print)
  3220. _print_next_block(par_num++, "UPB");
  3221. break;
  3222. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3223. if (print)
  3224. _print_next_block(par_num++, "CSDM");
  3225. break;
  3226. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3227. if (print)
  3228. _print_next_block(par_num++, "CCM");
  3229. break;
  3230. }
  3231. /* Clear the bit */
  3232. sig &= ~cur_bit;
  3233. }
  3234. }
  3235. return par_num;
  3236. }
  3237. static inline int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
  3238. bool print)
  3239. {
  3240. int i = 0;
  3241. u32 cur_bit = 0;
  3242. for (i = 0; sig; i++) {
  3243. cur_bit = ((u32)0x1 << i);
  3244. if (sig & cur_bit) {
  3245. switch (cur_bit) {
  3246. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3247. if (print)
  3248. _print_next_block(par_num++, "CSEMI");
  3249. break;
  3250. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3251. if (print)
  3252. _print_next_block(par_num++, "PXP");
  3253. break;
  3254. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3255. if (print)
  3256. _print_next_block(par_num++,
  3257. "PXPPCICLOCKCLIENT");
  3258. break;
  3259. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3260. if (print)
  3261. _print_next_block(par_num++, "CFC");
  3262. break;
  3263. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3264. if (print)
  3265. _print_next_block(par_num++, "CDU");
  3266. break;
  3267. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3268. if (print)
  3269. _print_next_block(par_num++, "DMAE");
  3270. break;
  3271. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3272. if (print)
  3273. _print_next_block(par_num++, "IGU");
  3274. break;
  3275. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3276. if (print)
  3277. _print_next_block(par_num++, "MISC");
  3278. break;
  3279. }
  3280. /* Clear the bit */
  3281. sig &= ~cur_bit;
  3282. }
  3283. }
  3284. return par_num;
  3285. }
  3286. static inline int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
  3287. bool *global, bool print)
  3288. {
  3289. int i = 0;
  3290. u32 cur_bit = 0;
  3291. for (i = 0; sig; i++) {
  3292. cur_bit = ((u32)0x1 << i);
  3293. if (sig & cur_bit) {
  3294. switch (cur_bit) {
  3295. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3296. if (print)
  3297. _print_next_block(par_num++, "MCP ROM");
  3298. *global = true;
  3299. break;
  3300. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3301. if (print)
  3302. _print_next_block(par_num++,
  3303. "MCP UMP RX");
  3304. *global = true;
  3305. break;
  3306. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3307. if (print)
  3308. _print_next_block(par_num++,
  3309. "MCP UMP TX");
  3310. *global = true;
  3311. break;
  3312. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3313. if (print)
  3314. _print_next_block(par_num++,
  3315. "MCP SCPAD");
  3316. *global = true;
  3317. break;
  3318. }
  3319. /* Clear the bit */
  3320. sig &= ~cur_bit;
  3321. }
  3322. }
  3323. return par_num;
  3324. }
  3325. static inline int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
  3326. bool print)
  3327. {
  3328. int i = 0;
  3329. u32 cur_bit = 0;
  3330. for (i = 0; sig; i++) {
  3331. cur_bit = ((u32)0x1 << i);
  3332. if (sig & cur_bit) {
  3333. switch (cur_bit) {
  3334. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3335. if (print)
  3336. _print_next_block(par_num++, "PGLUE_B");
  3337. break;
  3338. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3339. if (print)
  3340. _print_next_block(par_num++, "ATC");
  3341. break;
  3342. }
  3343. /* Clear the bit */
  3344. sig &= ~cur_bit;
  3345. }
  3346. }
  3347. return par_num;
  3348. }
  3349. static inline bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3350. u32 *sig)
  3351. {
  3352. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3353. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3354. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3355. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3356. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3357. int par_num = 0;
  3358. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  3359. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  3360. sig[0] & HW_PRTY_ASSERT_SET_0,
  3361. sig[1] & HW_PRTY_ASSERT_SET_1,
  3362. sig[2] & HW_PRTY_ASSERT_SET_2,
  3363. sig[3] & HW_PRTY_ASSERT_SET_3,
  3364. sig[4] & HW_PRTY_ASSERT_SET_4);
  3365. if (print)
  3366. netdev_err(bp->dev,
  3367. "Parity errors detected in blocks: ");
  3368. par_num = bnx2x_check_blocks_with_parity0(
  3369. sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
  3370. par_num = bnx2x_check_blocks_with_parity1(
  3371. sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
  3372. par_num = bnx2x_check_blocks_with_parity2(
  3373. sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
  3374. par_num = bnx2x_check_blocks_with_parity3(
  3375. sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
  3376. par_num = bnx2x_check_blocks_with_parity4(
  3377. sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
  3378. if (print)
  3379. pr_cont("\n");
  3380. return true;
  3381. } else
  3382. return false;
  3383. }
  3384. /**
  3385. * bnx2x_chk_parity_attn - checks for parity attentions.
  3386. *
  3387. * @bp: driver handle
  3388. * @global: true if there was a global attention
  3389. * @print: show parity attention in syslog
  3390. */
  3391. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3392. {
  3393. struct attn_route attn = { {0} };
  3394. int port = BP_PORT(bp);
  3395. attn.sig[0] = REG_RD(bp,
  3396. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3397. port*4);
  3398. attn.sig[1] = REG_RD(bp,
  3399. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3400. port*4);
  3401. attn.sig[2] = REG_RD(bp,
  3402. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3403. port*4);
  3404. attn.sig[3] = REG_RD(bp,
  3405. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  3406. port*4);
  3407. if (!CHIP_IS_E1x(bp))
  3408. attn.sig[4] = REG_RD(bp,
  3409. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  3410. port*4);
  3411. return bnx2x_parity_attn(bp, global, print, attn.sig);
  3412. }
  3413. static inline void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  3414. {
  3415. u32 val;
  3416. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  3417. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  3418. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  3419. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  3420. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  3421. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  3422. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  3423. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  3424. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  3425. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  3426. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  3427. if (val &
  3428. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  3429. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  3430. if (val &
  3431. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  3432. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  3433. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  3434. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  3435. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  3436. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  3437. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  3438. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  3439. }
  3440. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  3441. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  3442. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  3443. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  3444. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  3445. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  3446. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  3447. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  3448. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  3449. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  3450. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  3451. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  3452. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  3453. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  3454. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  3455. }
  3456. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3457. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  3458. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  3459. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3460. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  3461. }
  3462. }
  3463. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  3464. {
  3465. struct attn_route attn, *group_mask;
  3466. int port = BP_PORT(bp);
  3467. int index;
  3468. u32 reg_addr;
  3469. u32 val;
  3470. u32 aeu_mask;
  3471. bool global = false;
  3472. /* need to take HW lock because MCP or other port might also
  3473. try to handle this event */
  3474. bnx2x_acquire_alr(bp);
  3475. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  3476. #ifndef BNX2X_STOP_ON_ERROR
  3477. bp->recovery_state = BNX2X_RECOVERY_INIT;
  3478. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3479. /* Disable HW interrupts */
  3480. bnx2x_int_disable(bp);
  3481. /* In case of parity errors don't handle attentions so that
  3482. * other function would "see" parity errors.
  3483. */
  3484. #else
  3485. bnx2x_panic();
  3486. #endif
  3487. bnx2x_release_alr(bp);
  3488. return;
  3489. }
  3490. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  3491. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  3492. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  3493. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  3494. if (!CHIP_IS_E1x(bp))
  3495. attn.sig[4] =
  3496. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  3497. else
  3498. attn.sig[4] = 0;
  3499. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  3500. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  3501. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  3502. if (deasserted & (1 << index)) {
  3503. group_mask = &bp->attn_group[index];
  3504. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  3505. index,
  3506. group_mask->sig[0], group_mask->sig[1],
  3507. group_mask->sig[2], group_mask->sig[3],
  3508. group_mask->sig[4]);
  3509. bnx2x_attn_int_deasserted4(bp,
  3510. attn.sig[4] & group_mask->sig[4]);
  3511. bnx2x_attn_int_deasserted3(bp,
  3512. attn.sig[3] & group_mask->sig[3]);
  3513. bnx2x_attn_int_deasserted1(bp,
  3514. attn.sig[1] & group_mask->sig[1]);
  3515. bnx2x_attn_int_deasserted2(bp,
  3516. attn.sig[2] & group_mask->sig[2]);
  3517. bnx2x_attn_int_deasserted0(bp,
  3518. attn.sig[0] & group_mask->sig[0]);
  3519. }
  3520. }
  3521. bnx2x_release_alr(bp);
  3522. if (bp->common.int_block == INT_BLOCK_HC)
  3523. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3524. COMMAND_REG_ATTN_BITS_CLR);
  3525. else
  3526. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  3527. val = ~deasserted;
  3528. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  3529. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3530. REG_WR(bp, reg_addr, val);
  3531. if (~bp->attn_state & deasserted)
  3532. BNX2X_ERR("IGU ERROR\n");
  3533. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3534. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3535. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3536. aeu_mask = REG_RD(bp, reg_addr);
  3537. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  3538. aeu_mask, deasserted);
  3539. aeu_mask |= (deasserted & 0x3ff);
  3540. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3541. REG_WR(bp, reg_addr, aeu_mask);
  3542. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3543. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3544. bp->attn_state &= ~deasserted;
  3545. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3546. }
  3547. static void bnx2x_attn_int(struct bnx2x *bp)
  3548. {
  3549. /* read local copy of bits */
  3550. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3551. attn_bits);
  3552. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3553. attn_bits_ack);
  3554. u32 attn_state = bp->attn_state;
  3555. /* look for changed bits */
  3556. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  3557. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  3558. DP(NETIF_MSG_HW,
  3559. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  3560. attn_bits, attn_ack, asserted, deasserted);
  3561. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  3562. BNX2X_ERR("BAD attention state\n");
  3563. /* handle bits that were raised */
  3564. if (asserted)
  3565. bnx2x_attn_int_asserted(bp, asserted);
  3566. if (deasserted)
  3567. bnx2x_attn_int_deasserted(bp, deasserted);
  3568. }
  3569. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  3570. u16 index, u8 op, u8 update)
  3571. {
  3572. u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  3573. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  3574. igu_addr);
  3575. }
  3576. static inline void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  3577. {
  3578. /* No memory barriers */
  3579. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  3580. mmiowb(); /* keep prod updates ordered */
  3581. }
  3582. #ifdef BCM_CNIC
  3583. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  3584. union event_ring_elem *elem)
  3585. {
  3586. u8 err = elem->message.error;
  3587. if (!bp->cnic_eth_dev.starting_cid ||
  3588. (cid < bp->cnic_eth_dev.starting_cid &&
  3589. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  3590. return 1;
  3591. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  3592. if (unlikely(err)) {
  3593. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  3594. cid);
  3595. bnx2x_panic_dump(bp);
  3596. }
  3597. bnx2x_cnic_cfc_comp(bp, cid, err);
  3598. return 0;
  3599. }
  3600. #endif
  3601. static inline void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  3602. {
  3603. struct bnx2x_mcast_ramrod_params rparam;
  3604. int rc;
  3605. memset(&rparam, 0, sizeof(rparam));
  3606. rparam.mcast_obj = &bp->mcast_obj;
  3607. netif_addr_lock_bh(bp->dev);
  3608. /* Clear pending state for the last command */
  3609. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  3610. /* If there are pending mcast commands - send them */
  3611. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  3612. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  3613. if (rc < 0)
  3614. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  3615. rc);
  3616. }
  3617. netif_addr_unlock_bh(bp->dev);
  3618. }
  3619. static inline void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  3620. union event_ring_elem *elem)
  3621. {
  3622. unsigned long ramrod_flags = 0;
  3623. int rc = 0;
  3624. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  3625. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  3626. /* Always push next commands out, don't wait here */
  3627. __set_bit(RAMROD_CONT, &ramrod_flags);
  3628. switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
  3629. case BNX2X_FILTER_MAC_PENDING:
  3630. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  3631. #ifdef BCM_CNIC
  3632. if (cid == BNX2X_ISCSI_ETH_CID)
  3633. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  3634. else
  3635. #endif
  3636. vlan_mac_obj = &bp->fp[cid].mac_obj;
  3637. break;
  3638. case BNX2X_FILTER_MCAST_PENDING:
  3639. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  3640. /* This is only relevant for 57710 where multicast MACs are
  3641. * configured as unicast MACs using the same ramrod.
  3642. */
  3643. bnx2x_handle_mcast_eqe(bp);
  3644. return;
  3645. default:
  3646. BNX2X_ERR("Unsupported classification command: %d\n",
  3647. elem->message.data.eth_event.echo);
  3648. return;
  3649. }
  3650. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  3651. if (rc < 0)
  3652. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  3653. else if (rc > 0)
  3654. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  3655. }
  3656. #ifdef BCM_CNIC
  3657. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  3658. #endif
  3659. static inline void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  3660. {
  3661. netif_addr_lock_bh(bp->dev);
  3662. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  3663. /* Send rx_mode command again if was requested */
  3664. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  3665. bnx2x_set_storm_rx_mode(bp);
  3666. #ifdef BCM_CNIC
  3667. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  3668. &bp->sp_state))
  3669. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  3670. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  3671. &bp->sp_state))
  3672. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  3673. #endif
  3674. netif_addr_unlock_bh(bp->dev);
  3675. }
  3676. static inline struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  3677. struct bnx2x *bp, u32 cid)
  3678. {
  3679. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  3680. #ifdef BCM_CNIC
  3681. if (cid == BNX2X_FCOE_ETH_CID)
  3682. return &bnx2x_fcoe(bp, q_obj);
  3683. else
  3684. #endif
  3685. return &bnx2x_fp(bp, CID_TO_FP(cid), q_obj);
  3686. }
  3687. static void bnx2x_eq_int(struct bnx2x *bp)
  3688. {
  3689. u16 hw_cons, sw_cons, sw_prod;
  3690. union event_ring_elem *elem;
  3691. u32 cid;
  3692. u8 opcode;
  3693. int spqe_cnt = 0;
  3694. struct bnx2x_queue_sp_obj *q_obj;
  3695. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  3696. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  3697. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  3698. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  3699. * when we get the the next-page we nned to adjust so the loop
  3700. * condition below will be met. The next element is the size of a
  3701. * regular element and hence incrementing by 1
  3702. */
  3703. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  3704. hw_cons++;
  3705. /* This function may never run in parallel with itself for a
  3706. * specific bp, thus there is no need in "paired" read memory
  3707. * barrier here.
  3708. */
  3709. sw_cons = bp->eq_cons;
  3710. sw_prod = bp->eq_prod;
  3711. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  3712. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  3713. for (; sw_cons != hw_cons;
  3714. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  3715. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  3716. cid = SW_CID(elem->message.data.cfc_del_event.cid);
  3717. opcode = elem->message.opcode;
  3718. /* handle eq element */
  3719. switch (opcode) {
  3720. case EVENT_RING_OPCODE_STAT_QUERY:
  3721. DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
  3722. "got statistics comp event %d\n",
  3723. bp->stats_comp++);
  3724. /* nothing to do with stats comp */
  3725. goto next_spqe;
  3726. case EVENT_RING_OPCODE_CFC_DEL:
  3727. /* handle according to cid range */
  3728. /*
  3729. * we may want to verify here that the bp state is
  3730. * HALTING
  3731. */
  3732. DP(BNX2X_MSG_SP,
  3733. "got delete ramrod for MULTI[%d]\n", cid);
  3734. #ifdef BCM_CNIC
  3735. if (!bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  3736. goto next_spqe;
  3737. #endif
  3738. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  3739. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  3740. break;
  3741. goto next_spqe;
  3742. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  3743. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  3744. if (f_obj->complete_cmd(bp, f_obj,
  3745. BNX2X_F_CMD_TX_STOP))
  3746. break;
  3747. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  3748. goto next_spqe;
  3749. case EVENT_RING_OPCODE_START_TRAFFIC:
  3750. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  3751. if (f_obj->complete_cmd(bp, f_obj,
  3752. BNX2X_F_CMD_TX_START))
  3753. break;
  3754. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  3755. goto next_spqe;
  3756. case EVENT_RING_OPCODE_FUNCTION_START:
  3757. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  3758. "got FUNC_START ramrod\n");
  3759. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  3760. break;
  3761. goto next_spqe;
  3762. case EVENT_RING_OPCODE_FUNCTION_STOP:
  3763. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  3764. "got FUNC_STOP ramrod\n");
  3765. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  3766. break;
  3767. goto next_spqe;
  3768. }
  3769. switch (opcode | bp->state) {
  3770. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  3771. BNX2X_STATE_OPEN):
  3772. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  3773. BNX2X_STATE_OPENING_WAIT4_PORT):
  3774. cid = elem->message.data.eth_event.echo &
  3775. BNX2X_SWCID_MASK;
  3776. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  3777. cid);
  3778. rss_raw->clear_pending(rss_raw);
  3779. break;
  3780. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  3781. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  3782. case (EVENT_RING_OPCODE_SET_MAC |
  3783. BNX2X_STATE_CLOSING_WAIT4_HALT):
  3784. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  3785. BNX2X_STATE_OPEN):
  3786. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  3787. BNX2X_STATE_DIAG):
  3788. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  3789. BNX2X_STATE_CLOSING_WAIT4_HALT):
  3790. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  3791. bnx2x_handle_classification_eqe(bp, elem);
  3792. break;
  3793. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  3794. BNX2X_STATE_OPEN):
  3795. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  3796. BNX2X_STATE_DIAG):
  3797. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  3798. BNX2X_STATE_CLOSING_WAIT4_HALT):
  3799. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  3800. bnx2x_handle_mcast_eqe(bp);
  3801. break;
  3802. case (EVENT_RING_OPCODE_FILTERS_RULES |
  3803. BNX2X_STATE_OPEN):
  3804. case (EVENT_RING_OPCODE_FILTERS_RULES |
  3805. BNX2X_STATE_DIAG):
  3806. case (EVENT_RING_OPCODE_FILTERS_RULES |
  3807. BNX2X_STATE_CLOSING_WAIT4_HALT):
  3808. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  3809. bnx2x_handle_rx_mode_eqe(bp);
  3810. break;
  3811. default:
  3812. /* unknown event log error and continue */
  3813. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  3814. elem->message.opcode, bp->state);
  3815. }
  3816. next_spqe:
  3817. spqe_cnt++;
  3818. } /* for */
  3819. smp_mb__before_atomic_inc();
  3820. atomic_add(spqe_cnt, &bp->eq_spq_left);
  3821. bp->eq_cons = sw_cons;
  3822. bp->eq_prod = sw_prod;
  3823. /* Make sure that above mem writes were issued towards the memory */
  3824. smp_wmb();
  3825. /* update producer */
  3826. bnx2x_update_eq_prod(bp, bp->eq_prod);
  3827. }
  3828. static void bnx2x_sp_task(struct work_struct *work)
  3829. {
  3830. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  3831. u16 status;
  3832. status = bnx2x_update_dsb_idx(bp);
  3833. /* if (status == 0) */
  3834. /* BNX2X_ERR("spurious slowpath interrupt!\n"); */
  3835. DP(BNX2X_MSG_SP, "got a slowpath interrupt (status 0x%x)\n", status);
  3836. /* HW attentions */
  3837. if (status & BNX2X_DEF_SB_ATT_IDX) {
  3838. bnx2x_attn_int(bp);
  3839. status &= ~BNX2X_DEF_SB_ATT_IDX;
  3840. }
  3841. /* SP events: STAT_QUERY and others */
  3842. if (status & BNX2X_DEF_SB_IDX) {
  3843. #ifdef BCM_CNIC
  3844. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  3845. if ((!NO_FCOE(bp)) &&
  3846. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  3847. /*
  3848. * Prevent local bottom-halves from running as
  3849. * we are going to change the local NAPI list.
  3850. */
  3851. local_bh_disable();
  3852. napi_schedule(&bnx2x_fcoe(bp, napi));
  3853. local_bh_enable();
  3854. }
  3855. #endif
  3856. /* Handle EQ completions */
  3857. bnx2x_eq_int(bp);
  3858. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  3859. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  3860. status &= ~BNX2X_DEF_SB_IDX;
  3861. }
  3862. if (unlikely(status))
  3863. DP(BNX2X_MSG_SP, "got an unknown interrupt! (status 0x%x)\n",
  3864. status);
  3865. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  3866. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  3867. }
  3868. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  3869. {
  3870. struct net_device *dev = dev_instance;
  3871. struct bnx2x *bp = netdev_priv(dev);
  3872. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  3873. IGU_INT_DISABLE, 0);
  3874. #ifdef BNX2X_STOP_ON_ERROR
  3875. if (unlikely(bp->panic))
  3876. return IRQ_HANDLED;
  3877. #endif
  3878. #ifdef BCM_CNIC
  3879. {
  3880. struct cnic_ops *c_ops;
  3881. rcu_read_lock();
  3882. c_ops = rcu_dereference(bp->cnic_ops);
  3883. if (c_ops)
  3884. c_ops->cnic_handler(bp->cnic_data, NULL);
  3885. rcu_read_unlock();
  3886. }
  3887. #endif
  3888. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  3889. return IRQ_HANDLED;
  3890. }
  3891. /* end of slow path */
  3892. void bnx2x_drv_pulse(struct bnx2x *bp)
  3893. {
  3894. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  3895. bp->fw_drv_pulse_wr_seq);
  3896. }
  3897. static void bnx2x_timer(unsigned long data)
  3898. {
  3899. struct bnx2x *bp = (struct bnx2x *) data;
  3900. if (!netif_running(bp->dev))
  3901. return;
  3902. if (!BP_NOMCP(bp)) {
  3903. int mb_idx = BP_FW_MB_IDX(bp);
  3904. u32 drv_pulse;
  3905. u32 mcp_pulse;
  3906. ++bp->fw_drv_pulse_wr_seq;
  3907. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  3908. /* TBD - add SYSTEM_TIME */
  3909. drv_pulse = bp->fw_drv_pulse_wr_seq;
  3910. bnx2x_drv_pulse(bp);
  3911. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  3912. MCP_PULSE_SEQ_MASK);
  3913. /* The delta between driver pulse and mcp response
  3914. * should be 1 (before mcp response) or 0 (after mcp response)
  3915. */
  3916. if ((drv_pulse != mcp_pulse) &&
  3917. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  3918. /* someone lost a heartbeat... */
  3919. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  3920. drv_pulse, mcp_pulse);
  3921. }
  3922. }
  3923. if (bp->state == BNX2X_STATE_OPEN)
  3924. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  3925. mod_timer(&bp->timer, jiffies + bp->current_interval);
  3926. }
  3927. /* end of Statistics */
  3928. /* nic init */
  3929. /*
  3930. * nic init service functions
  3931. */
  3932. static inline void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  3933. {
  3934. u32 i;
  3935. if (!(len%4) && !(addr%4))
  3936. for (i = 0; i < len; i += 4)
  3937. REG_WR(bp, addr + i, fill);
  3938. else
  3939. for (i = 0; i < len; i++)
  3940. REG_WR8(bp, addr + i, fill);
  3941. }
  3942. /* helper: writes FP SP data to FW - data_size in dwords */
  3943. static inline void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  3944. int fw_sb_id,
  3945. u32 *sb_data_p,
  3946. u32 data_size)
  3947. {
  3948. int index;
  3949. for (index = 0; index < data_size; index++)
  3950. REG_WR(bp, BAR_CSTRORM_INTMEM +
  3951. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  3952. sizeof(u32)*index,
  3953. *(sb_data_p + index));
  3954. }
  3955. static inline void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  3956. {
  3957. u32 *sb_data_p;
  3958. u32 data_size = 0;
  3959. struct hc_status_block_data_e2 sb_data_e2;
  3960. struct hc_status_block_data_e1x sb_data_e1x;
  3961. /* disable the function first */
  3962. if (!CHIP_IS_E1x(bp)) {
  3963. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  3964. sb_data_e2.common.state = SB_DISABLED;
  3965. sb_data_e2.common.p_func.vf_valid = false;
  3966. sb_data_p = (u32 *)&sb_data_e2;
  3967. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  3968. } else {
  3969. memset(&sb_data_e1x, 0,
  3970. sizeof(struct hc_status_block_data_e1x));
  3971. sb_data_e1x.common.state = SB_DISABLED;
  3972. sb_data_e1x.common.p_func.vf_valid = false;
  3973. sb_data_p = (u32 *)&sb_data_e1x;
  3974. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  3975. }
  3976. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  3977. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  3978. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  3979. CSTORM_STATUS_BLOCK_SIZE);
  3980. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  3981. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  3982. CSTORM_SYNC_BLOCK_SIZE);
  3983. }
  3984. /* helper: writes SP SB data to FW */
  3985. static inline void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  3986. struct hc_sp_status_block_data *sp_sb_data)
  3987. {
  3988. int func = BP_FUNC(bp);
  3989. int i;
  3990. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  3991. REG_WR(bp, BAR_CSTRORM_INTMEM +
  3992. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  3993. i*sizeof(u32),
  3994. *((u32 *)sp_sb_data + i));
  3995. }
  3996. static inline void bnx2x_zero_sp_sb(struct bnx2x *bp)
  3997. {
  3998. int func = BP_FUNC(bp);
  3999. struct hc_sp_status_block_data sp_sb_data;
  4000. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4001. sp_sb_data.state = SB_DISABLED;
  4002. sp_sb_data.p_func.vf_valid = false;
  4003. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4004. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4005. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4006. CSTORM_SP_STATUS_BLOCK_SIZE);
  4007. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4008. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4009. CSTORM_SP_SYNC_BLOCK_SIZE);
  4010. }
  4011. static inline
  4012. void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4013. int igu_sb_id, int igu_seg_id)
  4014. {
  4015. hc_sm->igu_sb_id = igu_sb_id;
  4016. hc_sm->igu_seg_id = igu_seg_id;
  4017. hc_sm->timer_value = 0xFF;
  4018. hc_sm->time_to_expire = 0xFFFFFFFF;
  4019. }
  4020. /* allocates state machine ids. */
  4021. static inline
  4022. void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4023. {
  4024. /* zero out state machine indices */
  4025. /* rx indices */
  4026. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4027. /* tx indices */
  4028. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4029. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4030. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4031. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4032. /* map indices */
  4033. /* rx indices */
  4034. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4035. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4036. /* tx indices */
  4037. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4038. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4039. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4040. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4041. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4042. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4043. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4044. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4045. }
  4046. static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4047. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4048. {
  4049. int igu_seg_id;
  4050. struct hc_status_block_data_e2 sb_data_e2;
  4051. struct hc_status_block_data_e1x sb_data_e1x;
  4052. struct hc_status_block_sm *hc_sm_p;
  4053. int data_size;
  4054. u32 *sb_data_p;
  4055. if (CHIP_INT_MODE_IS_BC(bp))
  4056. igu_seg_id = HC_SEG_ACCESS_NORM;
  4057. else
  4058. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4059. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4060. if (!CHIP_IS_E1x(bp)) {
  4061. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4062. sb_data_e2.common.state = SB_ENABLED;
  4063. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4064. sb_data_e2.common.p_func.vf_id = vfid;
  4065. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4066. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4067. sb_data_e2.common.same_igu_sb_1b = true;
  4068. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4069. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4070. hc_sm_p = sb_data_e2.common.state_machine;
  4071. sb_data_p = (u32 *)&sb_data_e2;
  4072. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4073. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4074. } else {
  4075. memset(&sb_data_e1x, 0,
  4076. sizeof(struct hc_status_block_data_e1x));
  4077. sb_data_e1x.common.state = SB_ENABLED;
  4078. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4079. sb_data_e1x.common.p_func.vf_id = 0xff;
  4080. sb_data_e1x.common.p_func.vf_valid = false;
  4081. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4082. sb_data_e1x.common.same_igu_sb_1b = true;
  4083. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4084. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4085. hc_sm_p = sb_data_e1x.common.state_machine;
  4086. sb_data_p = (u32 *)&sb_data_e1x;
  4087. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4088. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4089. }
  4090. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4091. igu_sb_id, igu_seg_id);
  4092. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4093. igu_sb_id, igu_seg_id);
  4094. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4095. /* write indecies to HW */
  4096. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4097. }
  4098. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4099. u16 tx_usec, u16 rx_usec)
  4100. {
  4101. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4102. false, rx_usec);
  4103. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4104. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4105. tx_usec);
  4106. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4107. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4108. tx_usec);
  4109. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4110. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4111. tx_usec);
  4112. }
  4113. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4114. {
  4115. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4116. dma_addr_t mapping = bp->def_status_blk_mapping;
  4117. int igu_sp_sb_index;
  4118. int igu_seg_id;
  4119. int port = BP_PORT(bp);
  4120. int func = BP_FUNC(bp);
  4121. int reg_offset, reg_offset_en5;
  4122. u64 section;
  4123. int index;
  4124. struct hc_sp_status_block_data sp_sb_data;
  4125. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4126. if (CHIP_INT_MODE_IS_BC(bp)) {
  4127. igu_sp_sb_index = DEF_SB_IGU_ID;
  4128. igu_seg_id = HC_SEG_ACCESS_DEF;
  4129. } else {
  4130. igu_sp_sb_index = bp->igu_dsb_id;
  4131. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4132. }
  4133. /* ATTN */
  4134. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4135. atten_status_block);
  4136. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4137. bp->attn_state = 0;
  4138. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4139. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4140. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4141. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4142. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4143. int sindex;
  4144. /* take care of sig[0]..sig[4] */
  4145. for (sindex = 0; sindex < 4; sindex++)
  4146. bp->attn_group[index].sig[sindex] =
  4147. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4148. if (!CHIP_IS_E1x(bp))
  4149. /*
  4150. * enable5 is separate from the rest of the registers,
  4151. * and therefore the address skip is 4
  4152. * and not 16 between the different groups
  4153. */
  4154. bp->attn_group[index].sig[4] = REG_RD(bp,
  4155. reg_offset_en5 + 0x4*index);
  4156. else
  4157. bp->attn_group[index].sig[4] = 0;
  4158. }
  4159. if (bp->common.int_block == INT_BLOCK_HC) {
  4160. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4161. HC_REG_ATTN_MSG0_ADDR_L);
  4162. REG_WR(bp, reg_offset, U64_LO(section));
  4163. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4164. } else if (!CHIP_IS_E1x(bp)) {
  4165. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4166. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4167. }
  4168. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4169. sp_sb);
  4170. bnx2x_zero_sp_sb(bp);
  4171. sp_sb_data.state = SB_ENABLED;
  4172. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4173. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4174. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4175. sp_sb_data.igu_seg_id = igu_seg_id;
  4176. sp_sb_data.p_func.pf_id = func;
  4177. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4178. sp_sb_data.p_func.vf_id = 0xff;
  4179. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4180. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4181. }
  4182. void bnx2x_update_coalesce(struct bnx2x *bp)
  4183. {
  4184. int i;
  4185. for_each_eth_queue(bp, i)
  4186. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4187. bp->tx_ticks, bp->rx_ticks);
  4188. }
  4189. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4190. {
  4191. spin_lock_init(&bp->spq_lock);
  4192. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4193. bp->spq_prod_idx = 0;
  4194. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4195. bp->spq_prod_bd = bp->spq;
  4196. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4197. }
  4198. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4199. {
  4200. int i;
  4201. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4202. union event_ring_elem *elem =
  4203. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4204. elem->next_page.addr.hi =
  4205. cpu_to_le32(U64_HI(bp->eq_mapping +
  4206. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4207. elem->next_page.addr.lo =
  4208. cpu_to_le32(U64_LO(bp->eq_mapping +
  4209. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4210. }
  4211. bp->eq_cons = 0;
  4212. bp->eq_prod = NUM_EQ_DESC;
  4213. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4214. /* we want a warning message before it gets rought... */
  4215. atomic_set(&bp->eq_spq_left,
  4216. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4217. }
  4218. /* called with netif_addr_lock_bh() */
  4219. void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4220. unsigned long rx_mode_flags,
  4221. unsigned long rx_accept_flags,
  4222. unsigned long tx_accept_flags,
  4223. unsigned long ramrod_flags)
  4224. {
  4225. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4226. int rc;
  4227. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4228. /* Prepare ramrod parameters */
  4229. ramrod_param.cid = 0;
  4230. ramrod_param.cl_id = cl_id;
  4231. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4232. ramrod_param.func_id = BP_FUNC(bp);
  4233. ramrod_param.pstate = &bp->sp_state;
  4234. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4235. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4236. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4237. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4238. ramrod_param.ramrod_flags = ramrod_flags;
  4239. ramrod_param.rx_mode_flags = rx_mode_flags;
  4240. ramrod_param.rx_accept_flags = rx_accept_flags;
  4241. ramrod_param.tx_accept_flags = tx_accept_flags;
  4242. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4243. if (rc < 0) {
  4244. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4245. return;
  4246. }
  4247. }
  4248. /* called with netif_addr_lock_bh() */
  4249. void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  4250. {
  4251. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  4252. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  4253. #ifdef BCM_CNIC
  4254. if (!NO_FCOE(bp))
  4255. /* Configure rx_mode of FCoE Queue */
  4256. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  4257. #endif
  4258. switch (bp->rx_mode) {
  4259. case BNX2X_RX_MODE_NONE:
  4260. /*
  4261. * 'drop all' supersedes any accept flags that may have been
  4262. * passed to the function.
  4263. */
  4264. break;
  4265. case BNX2X_RX_MODE_NORMAL:
  4266. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4267. __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
  4268. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4269. /* internal switching mode */
  4270. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4271. __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
  4272. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4273. break;
  4274. case BNX2X_RX_MODE_ALLMULTI:
  4275. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4276. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4277. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4278. /* internal switching mode */
  4279. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4280. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4281. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4282. break;
  4283. case BNX2X_RX_MODE_PROMISC:
  4284. /* According to deffinition of SI mode, iface in promisc mode
  4285. * should receive matched and unmatched (in resolution of port)
  4286. * unicast packets.
  4287. */
  4288. __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
  4289. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4290. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4291. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4292. /* internal switching mode */
  4293. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4294. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4295. if (IS_MF_SI(bp))
  4296. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
  4297. else
  4298. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4299. break;
  4300. default:
  4301. BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
  4302. return;
  4303. }
  4304. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  4305. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
  4306. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
  4307. }
  4308. __set_bit(RAMROD_RX, &ramrod_flags);
  4309. __set_bit(RAMROD_TX, &ramrod_flags);
  4310. bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
  4311. tx_accept_flags, ramrod_flags);
  4312. }
  4313. static void bnx2x_init_internal_common(struct bnx2x *bp)
  4314. {
  4315. int i;
  4316. if (IS_MF_SI(bp))
  4317. /*
  4318. * In switch independent mode, the TSTORM needs to accept
  4319. * packets that failed classification, since approximate match
  4320. * mac addresses aren't written to NIG LLH
  4321. */
  4322. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4323. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  4324. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  4325. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4326. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  4327. /* Zero this manually as its initialization is
  4328. currently missing in the initTool */
  4329. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  4330. REG_WR(bp, BAR_USTRORM_INTMEM +
  4331. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  4332. if (!CHIP_IS_E1x(bp)) {
  4333. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  4334. CHIP_INT_MODE_IS_BC(bp) ?
  4335. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  4336. }
  4337. }
  4338. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  4339. {
  4340. switch (load_code) {
  4341. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4342. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  4343. bnx2x_init_internal_common(bp);
  4344. /* no break */
  4345. case FW_MSG_CODE_DRV_LOAD_PORT:
  4346. /* nothing to do */
  4347. /* no break */
  4348. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4349. /* internal memory per function is
  4350. initialized inside bnx2x_pf_init */
  4351. break;
  4352. default:
  4353. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4354. break;
  4355. }
  4356. }
  4357. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  4358. {
  4359. return fp->bp->igu_base_sb + fp->index + CNIC_PRESENT;
  4360. }
  4361. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  4362. {
  4363. return fp->bp->base_fw_ndsb + fp->index + CNIC_PRESENT;
  4364. }
  4365. static inline u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  4366. {
  4367. if (CHIP_IS_E1x(fp->bp))
  4368. return BP_L_ID(fp->bp) + fp->index;
  4369. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  4370. return bnx2x_fp_igu_sb_id(fp);
  4371. }
  4372. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  4373. {
  4374. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  4375. u8 cos;
  4376. unsigned long q_type = 0;
  4377. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  4378. fp->rx_queue = fp_idx;
  4379. fp->cid = fp_idx;
  4380. fp->cl_id = bnx2x_fp_cl_id(fp);
  4381. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  4382. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  4383. /* qZone id equals to FW (per path) client id */
  4384. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  4385. /* init shortcut */
  4386. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  4387. /* Setup SB indicies */
  4388. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  4389. /* Configure Queue State object */
  4390. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  4391. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  4392. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  4393. /* init tx data */
  4394. for_each_cos_in_tx_queue(fp, cos) {
  4395. bnx2x_init_txdata(bp, &fp->txdata[cos],
  4396. CID_COS_TO_TX_ONLY_CID(fp->cid, cos),
  4397. FP_COS_TO_TXQ(fp, cos),
  4398. BNX2X_TX_SB_INDEX_BASE + cos);
  4399. cids[cos] = fp->txdata[cos].cid;
  4400. }
  4401. bnx2x_init_queue_obj(bp, &fp->q_obj, fp->cl_id, cids, fp->max_cos,
  4402. BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  4403. bnx2x_sp_mapping(bp, q_rdata), q_type);
  4404. /**
  4405. * Configure classification DBs: Always enable Tx switching
  4406. */
  4407. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  4408. DP(NETIF_MSG_IFUP, "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  4409. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  4410. fp->igu_sb_id);
  4411. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  4412. fp->fw_sb_id, fp->igu_sb_id);
  4413. bnx2x_update_fpsb_idx(fp);
  4414. }
  4415. void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
  4416. {
  4417. int i;
  4418. for_each_eth_queue(bp, i)
  4419. bnx2x_init_eth_fp(bp, i);
  4420. #ifdef BCM_CNIC
  4421. if (!NO_FCOE(bp))
  4422. bnx2x_init_fcoe_fp(bp);
  4423. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  4424. BNX2X_VF_ID_INVALID, false,
  4425. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  4426. #endif
  4427. /* Initialize MOD_ABS interrupts */
  4428. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  4429. bp->common.shmem_base, bp->common.shmem2_base,
  4430. BP_PORT(bp));
  4431. /* ensure status block indices were read */
  4432. rmb();
  4433. bnx2x_init_def_sb(bp);
  4434. bnx2x_update_dsb_idx(bp);
  4435. bnx2x_init_rx_rings(bp);
  4436. bnx2x_init_tx_rings(bp);
  4437. bnx2x_init_sp_ring(bp);
  4438. bnx2x_init_eq_ring(bp);
  4439. bnx2x_init_internal(bp, load_code);
  4440. bnx2x_pf_init(bp);
  4441. bnx2x_stats_init(bp);
  4442. /* flush all before enabling interrupts */
  4443. mb();
  4444. mmiowb();
  4445. bnx2x_int_enable(bp);
  4446. /* Check for SPIO5 */
  4447. bnx2x_attn_int_deasserted0(bp,
  4448. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  4449. AEU_INPUTS_ATTN_BITS_SPIO5);
  4450. }
  4451. /* end of nic init */
  4452. /*
  4453. * gzip service functions
  4454. */
  4455. static int bnx2x_gunzip_init(struct bnx2x *bp)
  4456. {
  4457. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  4458. &bp->gunzip_mapping, GFP_KERNEL);
  4459. if (bp->gunzip_buf == NULL)
  4460. goto gunzip_nomem1;
  4461. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  4462. if (bp->strm == NULL)
  4463. goto gunzip_nomem2;
  4464. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  4465. if (bp->strm->workspace == NULL)
  4466. goto gunzip_nomem3;
  4467. return 0;
  4468. gunzip_nomem3:
  4469. kfree(bp->strm);
  4470. bp->strm = NULL;
  4471. gunzip_nomem2:
  4472. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  4473. bp->gunzip_mapping);
  4474. bp->gunzip_buf = NULL;
  4475. gunzip_nomem1:
  4476. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  4477. return -ENOMEM;
  4478. }
  4479. static void bnx2x_gunzip_end(struct bnx2x *bp)
  4480. {
  4481. if (bp->strm) {
  4482. vfree(bp->strm->workspace);
  4483. kfree(bp->strm);
  4484. bp->strm = NULL;
  4485. }
  4486. if (bp->gunzip_buf) {
  4487. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  4488. bp->gunzip_mapping);
  4489. bp->gunzip_buf = NULL;
  4490. }
  4491. }
  4492. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  4493. {
  4494. int n, rc;
  4495. /* check gzip header */
  4496. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  4497. BNX2X_ERR("Bad gzip header\n");
  4498. return -EINVAL;
  4499. }
  4500. n = 10;
  4501. #define FNAME 0x8
  4502. if (zbuf[3] & FNAME)
  4503. while ((zbuf[n++] != 0) && (n < len));
  4504. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  4505. bp->strm->avail_in = len - n;
  4506. bp->strm->next_out = bp->gunzip_buf;
  4507. bp->strm->avail_out = FW_BUF_SIZE;
  4508. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  4509. if (rc != Z_OK)
  4510. return rc;
  4511. rc = zlib_inflate(bp->strm, Z_FINISH);
  4512. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  4513. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  4514. bp->strm->msg);
  4515. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  4516. if (bp->gunzip_outlen & 0x3)
  4517. netdev_err(bp->dev,
  4518. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  4519. bp->gunzip_outlen);
  4520. bp->gunzip_outlen >>= 2;
  4521. zlib_inflateEnd(bp->strm);
  4522. if (rc == Z_STREAM_END)
  4523. return 0;
  4524. return rc;
  4525. }
  4526. /* nic load/unload */
  4527. /*
  4528. * General service functions
  4529. */
  4530. /* send a NIG loopback debug packet */
  4531. static void bnx2x_lb_pckt(struct bnx2x *bp)
  4532. {
  4533. u32 wb_write[3];
  4534. /* Ethernet source and destination addresses */
  4535. wb_write[0] = 0x55555555;
  4536. wb_write[1] = 0x55555555;
  4537. wb_write[2] = 0x20; /* SOP */
  4538. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4539. /* NON-IP protocol */
  4540. wb_write[0] = 0x09000000;
  4541. wb_write[1] = 0x55555555;
  4542. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  4543. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4544. }
  4545. /* some of the internal memories
  4546. * are not directly readable from the driver
  4547. * to test them we send debug packets
  4548. */
  4549. static int bnx2x_int_mem_test(struct bnx2x *bp)
  4550. {
  4551. int factor;
  4552. int count, i;
  4553. u32 val = 0;
  4554. if (CHIP_REV_IS_FPGA(bp))
  4555. factor = 120;
  4556. else if (CHIP_REV_IS_EMUL(bp))
  4557. factor = 200;
  4558. else
  4559. factor = 1;
  4560. /* Disable inputs of parser neighbor blocks */
  4561. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  4562. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  4563. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  4564. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  4565. /* Write 0 to parser credits for CFC search request */
  4566. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  4567. /* send Ethernet packet */
  4568. bnx2x_lb_pckt(bp);
  4569. /* TODO do i reset NIG statistic? */
  4570. /* Wait until NIG register shows 1 packet of size 0x10 */
  4571. count = 1000 * factor;
  4572. while (count) {
  4573. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4574. val = *bnx2x_sp(bp, wb_data[0]);
  4575. if (val == 0x10)
  4576. break;
  4577. msleep(10);
  4578. count--;
  4579. }
  4580. if (val != 0x10) {
  4581. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  4582. return -1;
  4583. }
  4584. /* Wait until PRS register shows 1 packet */
  4585. count = 1000 * factor;
  4586. while (count) {
  4587. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4588. if (val == 1)
  4589. break;
  4590. msleep(10);
  4591. count--;
  4592. }
  4593. if (val != 0x1) {
  4594. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4595. return -2;
  4596. }
  4597. /* Reset and init BRB, PRS */
  4598. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  4599. msleep(50);
  4600. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  4601. msleep(50);
  4602. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  4603. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  4604. DP(NETIF_MSG_HW, "part2\n");
  4605. /* Disable inputs of parser neighbor blocks */
  4606. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  4607. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  4608. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  4609. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  4610. /* Write 0 to parser credits for CFC search request */
  4611. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  4612. /* send 10 Ethernet packets */
  4613. for (i = 0; i < 10; i++)
  4614. bnx2x_lb_pckt(bp);
  4615. /* Wait until NIG register shows 10 + 1
  4616. packets of size 11*0x10 = 0xb0 */
  4617. count = 1000 * factor;
  4618. while (count) {
  4619. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4620. val = *bnx2x_sp(bp, wb_data[0]);
  4621. if (val == 0xb0)
  4622. break;
  4623. msleep(10);
  4624. count--;
  4625. }
  4626. if (val != 0xb0) {
  4627. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  4628. return -3;
  4629. }
  4630. /* Wait until PRS register shows 2 packets */
  4631. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4632. if (val != 2)
  4633. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4634. /* Write 1 to parser credits for CFC search request */
  4635. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  4636. /* Wait until PRS register shows 3 packets */
  4637. msleep(10 * factor);
  4638. /* Wait until NIG register shows 1 packet of size 0x10 */
  4639. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4640. if (val != 3)
  4641. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4642. /* clear NIG EOP FIFO */
  4643. for (i = 0; i < 11; i++)
  4644. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  4645. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  4646. if (val != 1) {
  4647. BNX2X_ERR("clear of NIG failed\n");
  4648. return -4;
  4649. }
  4650. /* Reset and init BRB, PRS, NIG */
  4651. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  4652. msleep(50);
  4653. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  4654. msleep(50);
  4655. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  4656. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  4657. #ifndef BCM_CNIC
  4658. /* set NIC mode */
  4659. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  4660. #endif
  4661. /* Enable inputs of parser neighbor blocks */
  4662. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  4663. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  4664. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  4665. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  4666. DP(NETIF_MSG_HW, "done\n");
  4667. return 0; /* OK */
  4668. }
  4669. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  4670. {
  4671. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  4672. if (!CHIP_IS_E1x(bp))
  4673. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  4674. else
  4675. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  4676. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  4677. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  4678. /*
  4679. * mask read length error interrupts in brb for parser
  4680. * (parsing unit and 'checksum and crc' unit)
  4681. * these errors are legal (PU reads fixed length and CAC can cause
  4682. * read length error on truncated packets)
  4683. */
  4684. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  4685. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  4686. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  4687. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  4688. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  4689. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  4690. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  4691. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  4692. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  4693. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  4694. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  4695. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  4696. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  4697. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  4698. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  4699. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  4700. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  4701. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  4702. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  4703. if (CHIP_REV_IS_FPGA(bp))
  4704. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000);
  4705. else if (!CHIP_IS_E1x(bp))
  4706. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0,
  4707. (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF
  4708. | PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT
  4709. | PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN
  4710. | PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED
  4711. | PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED));
  4712. else
  4713. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000);
  4714. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  4715. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  4716. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  4717. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  4718. if (!CHIP_IS_E1x(bp))
  4719. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  4720. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  4721. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  4722. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  4723. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  4724. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  4725. }
  4726. static void bnx2x_reset_common(struct bnx2x *bp)
  4727. {
  4728. u32 val = 0x1400;
  4729. /* reset_common */
  4730. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  4731. 0xd3ffff7f);
  4732. if (CHIP_IS_E3(bp)) {
  4733. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  4734. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  4735. }
  4736. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  4737. }
  4738. static void bnx2x_setup_dmae(struct bnx2x *bp)
  4739. {
  4740. bp->dmae_ready = 0;
  4741. spin_lock_init(&bp->dmae_lock);
  4742. }
  4743. static void bnx2x_init_pxp(struct bnx2x *bp)
  4744. {
  4745. u16 devctl;
  4746. int r_order, w_order;
  4747. pci_read_config_word(bp->pdev,
  4748. pci_pcie_cap(bp->pdev) + PCI_EXP_DEVCTL, &devctl);
  4749. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  4750. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  4751. if (bp->mrrs == -1)
  4752. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  4753. else {
  4754. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  4755. r_order = bp->mrrs;
  4756. }
  4757. bnx2x_init_pxp_arb(bp, r_order, w_order);
  4758. }
  4759. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  4760. {
  4761. int is_required;
  4762. u32 val;
  4763. int port;
  4764. if (BP_NOMCP(bp))
  4765. return;
  4766. is_required = 0;
  4767. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  4768. SHARED_HW_CFG_FAN_FAILURE_MASK;
  4769. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  4770. is_required = 1;
  4771. /*
  4772. * The fan failure mechanism is usually related to the PHY type since
  4773. * the power consumption of the board is affected by the PHY. Currently,
  4774. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  4775. */
  4776. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  4777. for (port = PORT_0; port < PORT_MAX; port++) {
  4778. is_required |=
  4779. bnx2x_fan_failure_det_req(
  4780. bp,
  4781. bp->common.shmem_base,
  4782. bp->common.shmem2_base,
  4783. port);
  4784. }
  4785. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  4786. if (is_required == 0)
  4787. return;
  4788. /* Fan failure is indicated by SPIO 5 */
  4789. bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5,
  4790. MISC_REGISTERS_SPIO_INPUT_HI_Z);
  4791. /* set to active low mode */
  4792. val = REG_RD(bp, MISC_REG_SPIO_INT);
  4793. val |= ((1 << MISC_REGISTERS_SPIO_5) <<
  4794. MISC_REGISTERS_SPIO_INT_OLD_SET_POS);
  4795. REG_WR(bp, MISC_REG_SPIO_INT, val);
  4796. /* enable interrupt to signal the IGU */
  4797. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  4798. val |= (1 << MISC_REGISTERS_SPIO_5);
  4799. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  4800. }
  4801. static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num)
  4802. {
  4803. u32 offset = 0;
  4804. if (CHIP_IS_E1(bp))
  4805. return;
  4806. if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX))
  4807. return;
  4808. switch (BP_ABS_FUNC(bp)) {
  4809. case 0:
  4810. offset = PXP2_REG_PGL_PRETEND_FUNC_F0;
  4811. break;
  4812. case 1:
  4813. offset = PXP2_REG_PGL_PRETEND_FUNC_F1;
  4814. break;
  4815. case 2:
  4816. offset = PXP2_REG_PGL_PRETEND_FUNC_F2;
  4817. break;
  4818. case 3:
  4819. offset = PXP2_REG_PGL_PRETEND_FUNC_F3;
  4820. break;
  4821. case 4:
  4822. offset = PXP2_REG_PGL_PRETEND_FUNC_F4;
  4823. break;
  4824. case 5:
  4825. offset = PXP2_REG_PGL_PRETEND_FUNC_F5;
  4826. break;
  4827. case 6:
  4828. offset = PXP2_REG_PGL_PRETEND_FUNC_F6;
  4829. break;
  4830. case 7:
  4831. offset = PXP2_REG_PGL_PRETEND_FUNC_F7;
  4832. break;
  4833. default:
  4834. return;
  4835. }
  4836. REG_WR(bp, offset, pretend_func_num);
  4837. REG_RD(bp, offset);
  4838. DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num);
  4839. }
  4840. void bnx2x_pf_disable(struct bnx2x *bp)
  4841. {
  4842. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  4843. val &= ~IGU_PF_CONF_FUNC_EN;
  4844. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  4845. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  4846. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  4847. }
  4848. static inline void bnx2x__common_init_phy(struct bnx2x *bp)
  4849. {
  4850. u32 shmem_base[2], shmem2_base[2];
  4851. shmem_base[0] = bp->common.shmem_base;
  4852. shmem2_base[0] = bp->common.shmem2_base;
  4853. if (!CHIP_IS_E1x(bp)) {
  4854. shmem_base[1] =
  4855. SHMEM2_RD(bp, other_shmem_base_addr);
  4856. shmem2_base[1] =
  4857. SHMEM2_RD(bp, other_shmem2_base_addr);
  4858. }
  4859. bnx2x_acquire_phy_lock(bp);
  4860. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  4861. bp->common.chip_id);
  4862. bnx2x_release_phy_lock(bp);
  4863. }
  4864. /**
  4865. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  4866. *
  4867. * @bp: driver handle
  4868. */
  4869. static int bnx2x_init_hw_common(struct bnx2x *bp)
  4870. {
  4871. u32 val;
  4872. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  4873. /*
  4874. * take the UNDI lock to protect undi_unload flow from accessing
  4875. * registers while we're resetting the chip
  4876. */
  4877. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  4878. bnx2x_reset_common(bp);
  4879. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  4880. val = 0xfffc;
  4881. if (CHIP_IS_E3(bp)) {
  4882. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  4883. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  4884. }
  4885. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  4886. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  4887. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  4888. if (!CHIP_IS_E1x(bp)) {
  4889. u8 abs_func_id;
  4890. /**
  4891. * 4-port mode or 2-port mode we need to turn of master-enable
  4892. * for everyone, after that, turn it back on for self.
  4893. * so, we disregard multi-function or not, and always disable
  4894. * for all functions on the given path, this means 0,2,4,6 for
  4895. * path 0 and 1,3,5,7 for path 1
  4896. */
  4897. for (abs_func_id = BP_PATH(bp);
  4898. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  4899. if (abs_func_id == BP_ABS_FUNC(bp)) {
  4900. REG_WR(bp,
  4901. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  4902. 1);
  4903. continue;
  4904. }
  4905. bnx2x_pretend_func(bp, abs_func_id);
  4906. /* clear pf enable */
  4907. bnx2x_pf_disable(bp);
  4908. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  4909. }
  4910. }
  4911. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  4912. if (CHIP_IS_E1(bp)) {
  4913. /* enable HW interrupt from PXP on USDM overflow
  4914. bit 16 on INT_MASK_0 */
  4915. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  4916. }
  4917. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  4918. bnx2x_init_pxp(bp);
  4919. #ifdef __BIG_ENDIAN
  4920. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  4921. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  4922. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  4923. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  4924. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  4925. /* make sure this value is 0 */
  4926. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  4927. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  4928. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  4929. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  4930. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  4931. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  4932. #endif
  4933. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  4934. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  4935. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  4936. /* let the HW do it's magic ... */
  4937. msleep(100);
  4938. /* finish PXP init */
  4939. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  4940. if (val != 1) {
  4941. BNX2X_ERR("PXP2 CFG failed\n");
  4942. return -EBUSY;
  4943. }
  4944. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  4945. if (val != 1) {
  4946. BNX2X_ERR("PXP2 RD_INIT failed\n");
  4947. return -EBUSY;
  4948. }
  4949. /* Timers bug workaround E2 only. We need to set the entire ILT to
  4950. * have entries with value "0" and valid bit on.
  4951. * This needs to be done by the first PF that is loaded in a path
  4952. * (i.e. common phase)
  4953. */
  4954. if (!CHIP_IS_E1x(bp)) {
  4955. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  4956. * (i.e. vnic3) to start even if it is marked as "scan-off".
  4957. * This occurs when a different function (func2,3) is being marked
  4958. * as "scan-off". Real-life scenario for example: if a driver is being
  4959. * load-unloaded while func6,7 are down. This will cause the timer to access
  4960. * the ilt, translate to a logical address and send a request to read/write.
  4961. * Since the ilt for the function that is down is not valid, this will cause
  4962. * a translation error which is unrecoverable.
  4963. * The Workaround is intended to make sure that when this happens nothing fatal
  4964. * will occur. The workaround:
  4965. * 1. First PF driver which loads on a path will:
  4966. * a. After taking the chip out of reset, by using pretend,
  4967. * it will write "0" to the following registers of
  4968. * the other vnics.
  4969. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  4970. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  4971. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  4972. * And for itself it will write '1' to
  4973. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  4974. * dmae-operations (writing to pram for example.)
  4975. * note: can be done for only function 6,7 but cleaner this
  4976. * way.
  4977. * b. Write zero+valid to the entire ILT.
  4978. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  4979. * VNIC3 (of that port). The range allocated will be the
  4980. * entire ILT. This is needed to prevent ILT range error.
  4981. * 2. Any PF driver load flow:
  4982. * a. ILT update with the physical addresses of the allocated
  4983. * logical pages.
  4984. * b. Wait 20msec. - note that this timeout is needed to make
  4985. * sure there are no requests in one of the PXP internal
  4986. * queues with "old" ILT addresses.
  4987. * c. PF enable in the PGLC.
  4988. * d. Clear the was_error of the PF in the PGLC. (could have
  4989. * occured while driver was down)
  4990. * e. PF enable in the CFC (WEAK + STRONG)
  4991. * f. Timers scan enable
  4992. * 3. PF driver unload flow:
  4993. * a. Clear the Timers scan_en.
  4994. * b. Polling for scan_on=0 for that PF.
  4995. * c. Clear the PF enable bit in the PXP.
  4996. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  4997. * e. Write zero+valid to all ILT entries (The valid bit must
  4998. * stay set)
  4999. * f. If this is VNIC 3 of a port then also init
  5000. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5001. * to the last enrty in the ILT.
  5002. *
  5003. * Notes:
  5004. * Currently the PF error in the PGLC is non recoverable.
  5005. * In the future the there will be a recovery routine for this error.
  5006. * Currently attention is masked.
  5007. * Having an MCP lock on the load/unload process does not guarantee that
  5008. * there is no Timer disable during Func6/7 enable. This is because the
  5009. * Timers scan is currently being cleared by the MCP on FLR.
  5010. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5011. * there is error before clearing it. But the flow above is simpler and
  5012. * more general.
  5013. * All ILT entries are written by zero+valid and not just PF6/7
  5014. * ILT entries since in the future the ILT entries allocation for
  5015. * PF-s might be dynamic.
  5016. */
  5017. struct ilt_client_info ilt_cli;
  5018. struct bnx2x_ilt ilt;
  5019. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5020. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5021. /* initialize dummy TM client */
  5022. ilt_cli.start = 0;
  5023. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5024. ilt_cli.client_num = ILT_CLIENT_TM;
  5025. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5026. * Step 2: set the timers first/last ilt entry to point
  5027. * to the entire range to prevent ILT range error for 3rd/4th
  5028. * vnic (this code assumes existance of the vnic)
  5029. *
  5030. * both steps performed by call to bnx2x_ilt_client_init_op()
  5031. * with dummy TM client
  5032. *
  5033. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5034. * and his brother are split registers
  5035. */
  5036. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5037. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5038. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5039. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5040. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5041. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5042. }
  5043. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5044. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5045. if (!CHIP_IS_E1x(bp)) {
  5046. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5047. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5048. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5049. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5050. /* let the HW do it's magic ... */
  5051. do {
  5052. msleep(200);
  5053. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5054. } while (factor-- && (val != 1));
  5055. if (val != 1) {
  5056. BNX2X_ERR("ATC_INIT failed\n");
  5057. return -EBUSY;
  5058. }
  5059. }
  5060. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5061. /* clean the DMAE memory */
  5062. bp->dmae_ready = 1;
  5063. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5064. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5065. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5066. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5067. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5068. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5069. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5070. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5071. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5072. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5073. /* QM queues pointers table */
  5074. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5075. /* soft reset pulse */
  5076. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5077. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5078. #ifdef BCM_CNIC
  5079. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5080. #endif
  5081. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5082. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
  5083. if (!CHIP_REV_IS_SLOW(bp))
  5084. /* enable hw interrupt from doorbell Q */
  5085. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5086. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5087. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5088. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5089. if (!CHIP_IS_E1(bp))
  5090. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5091. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp))
  5092. /* Bit-map indicating which L2 hdrs may appear
  5093. * after the basic Ethernet header
  5094. */
  5095. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5096. bp->path_has_ovlan ? 7 : 6);
  5097. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5098. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5099. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5100. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5101. if (!CHIP_IS_E1x(bp)) {
  5102. /* reset VFC memories */
  5103. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5104. VFC_MEMORIES_RST_REG_CAM_RST |
  5105. VFC_MEMORIES_RST_REG_RAM_RST);
  5106. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5107. VFC_MEMORIES_RST_REG_CAM_RST |
  5108. VFC_MEMORIES_RST_REG_RAM_RST);
  5109. msleep(20);
  5110. }
  5111. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5112. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5113. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5114. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5115. /* sync semi rtc */
  5116. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5117. 0x80000000);
  5118. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5119. 0x80000000);
  5120. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5121. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5122. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5123. if (!CHIP_IS_E1x(bp))
  5124. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5125. bp->path_has_ovlan ? 7 : 6);
  5126. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5127. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5128. #ifdef BCM_CNIC
  5129. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5130. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5131. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5132. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5133. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5134. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5135. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5136. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5137. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5138. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5139. #endif
  5140. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5141. if (sizeof(union cdu_context) != 1024)
  5142. /* we currently assume that a context is 1024 bytes */
  5143. dev_alert(&bp->pdev->dev,
  5144. "please adjust the size of cdu_context(%ld)\n",
  5145. (long)sizeof(union cdu_context));
  5146. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5147. val = (4 << 24) + (0 << 12) + 1024;
  5148. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5149. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5150. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5151. /* enable context validation interrupt from CFC */
  5152. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5153. /* set the thresholds to prevent CFC/CDU race */
  5154. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5155. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5156. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5157. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5158. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5159. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5160. /* Reset PCIE errors for debug */
  5161. REG_WR(bp, 0x2814, 0xffffffff);
  5162. REG_WR(bp, 0x3820, 0xffffffff);
  5163. if (!CHIP_IS_E1x(bp)) {
  5164. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5165. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5166. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5167. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5168. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5169. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5170. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5171. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5172. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5173. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5174. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5175. }
  5176. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5177. if (!CHIP_IS_E1(bp)) {
  5178. /* in E3 this done in per-port section */
  5179. if (!CHIP_IS_E3(bp))
  5180. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5181. }
  5182. if (CHIP_IS_E1H(bp))
  5183. /* not applicable for E2 (and above ...) */
  5184. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5185. if (CHIP_REV_IS_SLOW(bp))
  5186. msleep(200);
  5187. /* finish CFC init */
  5188. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5189. if (val != 1) {
  5190. BNX2X_ERR("CFC LL_INIT failed\n");
  5191. return -EBUSY;
  5192. }
  5193. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5194. if (val != 1) {
  5195. BNX2X_ERR("CFC AC_INIT failed\n");
  5196. return -EBUSY;
  5197. }
  5198. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5199. if (val != 1) {
  5200. BNX2X_ERR("CFC CAM_INIT failed\n");
  5201. return -EBUSY;
  5202. }
  5203. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5204. if (CHIP_IS_E1(bp)) {
  5205. /* read NIG statistic
  5206. to see if this is our first up since powerup */
  5207. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5208. val = *bnx2x_sp(bp, wb_data[0]);
  5209. /* do internal memory self test */
  5210. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5211. BNX2X_ERR("internal mem self test failed\n");
  5212. return -EBUSY;
  5213. }
  5214. }
  5215. bnx2x_setup_fan_failure_detection(bp);
  5216. /* clear PXP2 attentions */
  5217. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5218. bnx2x_enable_blocks_attention(bp);
  5219. bnx2x_enable_blocks_parity(bp);
  5220. if (!BP_NOMCP(bp)) {
  5221. if (CHIP_IS_E1x(bp))
  5222. bnx2x__common_init_phy(bp);
  5223. } else
  5224. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5225. return 0;
  5226. }
  5227. /**
  5228. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  5229. *
  5230. * @bp: driver handle
  5231. */
  5232. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  5233. {
  5234. int rc = bnx2x_init_hw_common(bp);
  5235. if (rc)
  5236. return rc;
  5237. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  5238. if (!BP_NOMCP(bp))
  5239. bnx2x__common_init_phy(bp);
  5240. return 0;
  5241. }
  5242. static int bnx2x_init_hw_port(struct bnx2x *bp)
  5243. {
  5244. int port = BP_PORT(bp);
  5245. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  5246. u32 low, high;
  5247. u32 val;
  5248. bnx2x__link_reset(bp);
  5249. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  5250. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  5251. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5252. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5253. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5254. /* Timers bug workaround: disables the pf_master bit in pglue at
  5255. * common phase, we need to enable it here before any dmae access are
  5256. * attempted. Therefore we manually added the enable-master to the
  5257. * port phase (it also happens in the function phase)
  5258. */
  5259. if (!CHIP_IS_E1x(bp))
  5260. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5261. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5262. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5263. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5264. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5265. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5266. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5267. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5268. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5269. /* QM cid (connection) count */
  5270. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  5271. #ifdef BCM_CNIC
  5272. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5273. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  5274. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  5275. #endif
  5276. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5277. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  5278. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5279. if (IS_MF(bp))
  5280. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  5281. else if (bp->dev->mtu > 4096) {
  5282. if (bp->flags & ONE_PORT_FLAG)
  5283. low = 160;
  5284. else {
  5285. val = bp->dev->mtu;
  5286. /* (24*1024 + val*4)/256 */
  5287. low = 96 + (val/64) +
  5288. ((val % 64) ? 1 : 0);
  5289. }
  5290. } else
  5291. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  5292. high = low + 56; /* 14*1024/256 */
  5293. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  5294. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  5295. }
  5296. if (CHIP_MODE_IS_4_PORT(bp))
  5297. REG_WR(bp, (BP_PORT(bp) ?
  5298. BRB1_REG_MAC_GUARANTIED_1 :
  5299. BRB1_REG_MAC_GUARANTIED_0), 40);
  5300. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5301. if (CHIP_IS_E3B0(bp))
  5302. /* Ovlan exists only if we are in multi-function +
  5303. * switch-dependent mode, in switch-independent there
  5304. * is no ovlan headers
  5305. */
  5306. REG_WR(bp, BP_PORT(bp) ?
  5307. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5308. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  5309. (bp->path_has_ovlan ? 7 : 6));
  5310. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5311. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5312. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5313. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5314. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5315. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5316. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5317. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5318. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5319. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5320. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5321. if (CHIP_IS_E1x(bp)) {
  5322. /* configure PBF to work without PAUSE mtu 9000 */
  5323. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  5324. /* update threshold */
  5325. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  5326. /* update init credit */
  5327. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  5328. /* probe changes */
  5329. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  5330. udelay(50);
  5331. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  5332. }
  5333. #ifdef BCM_CNIC
  5334. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5335. #endif
  5336. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5337. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5338. if (CHIP_IS_E1(bp)) {
  5339. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5340. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5341. }
  5342. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5343. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5344. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5345. /* init aeu_mask_attn_func_0/1:
  5346. * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
  5347. * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
  5348. * bits 4-7 are used for "per vn group attention" */
  5349. val = IS_MF(bp) ? 0xF7 : 0x7;
  5350. /* Enable DCBX attention for all but E1 */
  5351. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  5352. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  5353. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5354. if (!CHIP_IS_E1x(bp)) {
  5355. /* Bit-map indicating which L2 hdrs may appear after the
  5356. * basic Ethernet header
  5357. */
  5358. REG_WR(bp, BP_PORT(bp) ?
  5359. NIG_REG_P1_HDRS_AFTER_BASIC :
  5360. NIG_REG_P0_HDRS_AFTER_BASIC,
  5361. IS_MF_SD(bp) ? 7 : 6);
  5362. if (CHIP_IS_E3(bp))
  5363. REG_WR(bp, BP_PORT(bp) ?
  5364. NIG_REG_LLH1_MF_MODE :
  5365. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5366. }
  5367. if (!CHIP_IS_E3(bp))
  5368. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  5369. if (!CHIP_IS_E1(bp)) {
  5370. /* 0x2 disable mf_ov, 0x1 enable */
  5371. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  5372. (IS_MF_SD(bp) ? 0x1 : 0x2));
  5373. if (!CHIP_IS_E1x(bp)) {
  5374. val = 0;
  5375. switch (bp->mf_mode) {
  5376. case MULTI_FUNCTION_SD:
  5377. val = 1;
  5378. break;
  5379. case MULTI_FUNCTION_SI:
  5380. val = 2;
  5381. break;
  5382. }
  5383. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  5384. NIG_REG_LLH0_CLS_TYPE), val);
  5385. }
  5386. {
  5387. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  5388. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  5389. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  5390. }
  5391. }
  5392. /* If SPIO5 is set to generate interrupts, enable it for this port */
  5393. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5394. if (val & (1 << MISC_REGISTERS_SPIO_5)) {
  5395. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  5396. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  5397. val = REG_RD(bp, reg_addr);
  5398. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  5399. REG_WR(bp, reg_addr, val);
  5400. }
  5401. return 0;
  5402. }
  5403. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  5404. {
  5405. int reg;
  5406. u32 wb_write[2];
  5407. if (CHIP_IS_E1(bp))
  5408. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  5409. else
  5410. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  5411. wb_write[0] = ONCHIP_ADDR1(addr);
  5412. wb_write[1] = ONCHIP_ADDR2(addr);
  5413. REG_WR_DMAE(bp, reg, wb_write, 2);
  5414. }
  5415. static inline void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  5416. {
  5417. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  5418. }
  5419. static inline void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  5420. {
  5421. u32 i, base = FUNC_ILT_BASE(func);
  5422. for (i = base; i < base + ILT_PER_FUNC; i++)
  5423. bnx2x_ilt_wr(bp, i, 0);
  5424. }
  5425. static int bnx2x_init_hw_func(struct bnx2x *bp)
  5426. {
  5427. int port = BP_PORT(bp);
  5428. int func = BP_FUNC(bp);
  5429. int init_phase = PHASE_PF0 + func;
  5430. struct bnx2x_ilt *ilt = BP_ILT(bp);
  5431. u16 cdu_ilt_start;
  5432. u32 addr, val;
  5433. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  5434. int i, main_mem_width, rc;
  5435. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  5436. /* FLR cleanup - hmmm */
  5437. if (!CHIP_IS_E1x(bp)) {
  5438. rc = bnx2x_pf_flr_clnup(bp);
  5439. if (rc)
  5440. return rc;
  5441. }
  5442. /* set MSI reconfigure capability */
  5443. if (bp->common.int_block == INT_BLOCK_HC) {
  5444. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  5445. val = REG_RD(bp, addr);
  5446. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  5447. REG_WR(bp, addr, val);
  5448. }
  5449. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5450. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5451. ilt = BP_ILT(bp);
  5452. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  5453. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  5454. ilt->lines[cdu_ilt_start + i].page =
  5455. bp->context.vcxt + (ILT_PAGE_CIDS * i);
  5456. ilt->lines[cdu_ilt_start + i].page_mapping =
  5457. bp->context.cxt_mapping + (CDU_ILT_PAGE_SZ * i);
  5458. /* cdu ilt pages are allocated manually so there's no need to
  5459. set the size */
  5460. }
  5461. bnx2x_ilt_init_op(bp, INITOP_SET);
  5462. #ifdef BCM_CNIC
  5463. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  5464. /* T1 hash bits value determines the T1 number of entries */
  5465. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  5466. #endif
  5467. #ifndef BCM_CNIC
  5468. /* set NIC mode */
  5469. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5470. #endif /* BCM_CNIC */
  5471. if (!CHIP_IS_E1x(bp)) {
  5472. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  5473. /* Turn on a single ISR mode in IGU if driver is going to use
  5474. * INT#x or MSI
  5475. */
  5476. if (!(bp->flags & USING_MSIX_FLAG))
  5477. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  5478. /*
  5479. * Timers workaround bug: function init part.
  5480. * Need to wait 20msec after initializing ILT,
  5481. * needed to make sure there are no requests in
  5482. * one of the PXP internal queues with "old" ILT addresses
  5483. */
  5484. msleep(20);
  5485. /*
  5486. * Master enable - Due to WB DMAE writes performed before this
  5487. * register is re-initialized as part of the regular function
  5488. * init
  5489. */
  5490. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5491. /* Enable the function in IGU */
  5492. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  5493. }
  5494. bp->dmae_ready = 1;
  5495. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5496. if (!CHIP_IS_E1x(bp))
  5497. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  5498. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5499. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5500. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5501. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5502. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5503. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5504. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5505. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5506. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5507. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5508. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5509. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5510. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5511. if (!CHIP_IS_E1x(bp))
  5512. REG_WR(bp, QM_REG_PF_EN, 1);
  5513. if (!CHIP_IS_E1x(bp)) {
  5514. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5515. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5516. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5517. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5518. }
  5519. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5520. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5521. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5522. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5523. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5524. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5525. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5526. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5527. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5528. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5529. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5530. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5531. if (!CHIP_IS_E1x(bp))
  5532. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  5533. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5534. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5535. if (!CHIP_IS_E1x(bp))
  5536. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  5537. if (IS_MF(bp)) {
  5538. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  5539. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  5540. }
  5541. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5542. /* HC init per function */
  5543. if (bp->common.int_block == INT_BLOCK_HC) {
  5544. if (CHIP_IS_E1H(bp)) {
  5545. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  5546. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5547. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5548. }
  5549. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5550. } else {
  5551. int num_segs, sb_idx, prod_offset;
  5552. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  5553. if (!CHIP_IS_E1x(bp)) {
  5554. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  5555. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  5556. }
  5557. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5558. if (!CHIP_IS_E1x(bp)) {
  5559. int dsb_idx = 0;
  5560. /**
  5561. * Producer memory:
  5562. * E2 mode: address 0-135 match to the mapping memory;
  5563. * 136 - PF0 default prod; 137 - PF1 default prod;
  5564. * 138 - PF2 default prod; 139 - PF3 default prod;
  5565. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  5566. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  5567. * 144-147 reserved.
  5568. *
  5569. * E1.5 mode - In backward compatible mode;
  5570. * for non default SB; each even line in the memory
  5571. * holds the U producer and each odd line hold
  5572. * the C producer. The first 128 producers are for
  5573. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  5574. * producers are for the DSB for each PF.
  5575. * Each PF has five segments: (the order inside each
  5576. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  5577. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  5578. * 144-147 attn prods;
  5579. */
  5580. /* non-default-status-blocks */
  5581. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  5582. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  5583. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  5584. prod_offset = (bp->igu_base_sb + sb_idx) *
  5585. num_segs;
  5586. for (i = 0; i < num_segs; i++) {
  5587. addr = IGU_REG_PROD_CONS_MEMORY +
  5588. (prod_offset + i) * 4;
  5589. REG_WR(bp, addr, 0);
  5590. }
  5591. /* send consumer update with value 0 */
  5592. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  5593. USTORM_ID, 0, IGU_INT_NOP, 1);
  5594. bnx2x_igu_clear_sb(bp,
  5595. bp->igu_base_sb + sb_idx);
  5596. }
  5597. /* default-status-blocks */
  5598. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  5599. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  5600. if (CHIP_MODE_IS_4_PORT(bp))
  5601. dsb_idx = BP_FUNC(bp);
  5602. else
  5603. dsb_idx = BP_VN(bp);
  5604. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  5605. IGU_BC_BASE_DSB_PROD + dsb_idx :
  5606. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  5607. /*
  5608. * igu prods come in chunks of E1HVN_MAX (4) -
  5609. * does not matters what is the current chip mode
  5610. */
  5611. for (i = 0; i < (num_segs * E1HVN_MAX);
  5612. i += E1HVN_MAX) {
  5613. addr = IGU_REG_PROD_CONS_MEMORY +
  5614. (prod_offset + i)*4;
  5615. REG_WR(bp, addr, 0);
  5616. }
  5617. /* send consumer update with 0 */
  5618. if (CHIP_INT_MODE_IS_BC(bp)) {
  5619. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5620. USTORM_ID, 0, IGU_INT_NOP, 1);
  5621. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5622. CSTORM_ID, 0, IGU_INT_NOP, 1);
  5623. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5624. XSTORM_ID, 0, IGU_INT_NOP, 1);
  5625. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5626. TSTORM_ID, 0, IGU_INT_NOP, 1);
  5627. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5628. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  5629. } else {
  5630. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5631. USTORM_ID, 0, IGU_INT_NOP, 1);
  5632. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5633. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  5634. }
  5635. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  5636. /* !!! these should become driver const once
  5637. rf-tool supports split-68 const */
  5638. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  5639. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  5640. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  5641. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  5642. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  5643. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  5644. }
  5645. }
  5646. /* Reset PCIE errors for debug */
  5647. REG_WR(bp, 0x2114, 0xffffffff);
  5648. REG_WR(bp, 0x2120, 0xffffffff);
  5649. if (CHIP_IS_E1x(bp)) {
  5650. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  5651. main_mem_base = HC_REG_MAIN_MEMORY +
  5652. BP_PORT(bp) * (main_mem_size * 4);
  5653. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  5654. main_mem_width = 8;
  5655. val = REG_RD(bp, main_mem_prty_clr);
  5656. if (val)
  5657. DP(NETIF_MSG_HW,
  5658. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  5659. val);
  5660. /* Clear "false" parity errors in MSI-X table */
  5661. for (i = main_mem_base;
  5662. i < main_mem_base + main_mem_size * 4;
  5663. i += main_mem_width) {
  5664. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  5665. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  5666. i, main_mem_width / 4);
  5667. }
  5668. /* Clear HC parity attention */
  5669. REG_RD(bp, main_mem_prty_clr);
  5670. }
  5671. #ifdef BNX2X_STOP_ON_ERROR
  5672. /* Enable STORMs SP logging */
  5673. REG_WR8(bp, BAR_USTRORM_INTMEM +
  5674. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  5675. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  5676. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  5677. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  5678. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  5679. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  5680. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  5681. #endif
  5682. bnx2x_phy_probe(&bp->link_params);
  5683. return 0;
  5684. }
  5685. void bnx2x_free_mem(struct bnx2x *bp)
  5686. {
  5687. /* fastpath */
  5688. bnx2x_free_fp_mem(bp);
  5689. /* end of fastpath */
  5690. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  5691. sizeof(struct host_sp_status_block));
  5692. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  5693. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  5694. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  5695. sizeof(struct bnx2x_slowpath));
  5696. BNX2X_PCI_FREE(bp->context.vcxt, bp->context.cxt_mapping,
  5697. bp->context.size);
  5698. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  5699. BNX2X_FREE(bp->ilt->lines);
  5700. #ifdef BCM_CNIC
  5701. if (!CHIP_IS_E1x(bp))
  5702. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  5703. sizeof(struct host_hc_status_block_e2));
  5704. else
  5705. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  5706. sizeof(struct host_hc_status_block_e1x));
  5707. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  5708. #endif
  5709. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  5710. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  5711. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  5712. }
  5713. static inline int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp)
  5714. {
  5715. int num_groups;
  5716. int is_fcoe_stats = NO_FCOE(bp) ? 0 : 1;
  5717. /* number of queues for statistics is number of eth queues + FCoE */
  5718. u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp) + is_fcoe_stats;
  5719. /* Total number of FW statistics requests =
  5720. * 1 for port stats + 1 for PF stats + potential 1 for FCoE stats +
  5721. * num of queues
  5722. */
  5723. bp->fw_stats_num = 2 + is_fcoe_stats + num_queue_stats;
  5724. /* Request is built from stats_query_header and an array of
  5725. * stats_query_cmd_group each of which contains
  5726. * STATS_QUERY_CMD_COUNT rules. The real number or requests is
  5727. * configured in the stats_query_header.
  5728. */
  5729. num_groups = ((bp->fw_stats_num) / STATS_QUERY_CMD_COUNT) +
  5730. (((bp->fw_stats_num) % STATS_QUERY_CMD_COUNT) ? 1 : 0);
  5731. bp->fw_stats_req_sz = sizeof(struct stats_query_header) +
  5732. num_groups * sizeof(struct stats_query_cmd_group);
  5733. /* Data for statistics requests + stats_conter
  5734. *
  5735. * stats_counter holds per-STORM counters that are incremented
  5736. * when STORM has finished with the current request.
  5737. *
  5738. * memory for FCoE offloaded statistics are counted anyway,
  5739. * even if they will not be sent.
  5740. */
  5741. bp->fw_stats_data_sz = sizeof(struct per_port_stats) +
  5742. sizeof(struct per_pf_stats) +
  5743. sizeof(struct fcoe_statistics_params) +
  5744. sizeof(struct per_queue_stats) * num_queue_stats +
  5745. sizeof(struct stats_counter);
  5746. BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping,
  5747. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  5748. /* Set shortcuts */
  5749. bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats;
  5750. bp->fw_stats_req_mapping = bp->fw_stats_mapping;
  5751. bp->fw_stats_data = (struct bnx2x_fw_stats_data *)
  5752. ((u8 *)bp->fw_stats + bp->fw_stats_req_sz);
  5753. bp->fw_stats_data_mapping = bp->fw_stats_mapping +
  5754. bp->fw_stats_req_sz;
  5755. return 0;
  5756. alloc_mem_err:
  5757. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  5758. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  5759. BNX2X_ERR("Can't allocate memory\n");
  5760. return -ENOMEM;
  5761. }
  5762. int bnx2x_alloc_mem(struct bnx2x *bp)
  5763. {
  5764. #ifdef BCM_CNIC
  5765. if (!CHIP_IS_E1x(bp))
  5766. /* size = the status block + ramrod buffers */
  5767. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  5768. sizeof(struct host_hc_status_block_e2));
  5769. else
  5770. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb, &bp->cnic_sb_mapping,
  5771. sizeof(struct host_hc_status_block_e1x));
  5772. /* allocate searcher T2 table */
  5773. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  5774. #endif
  5775. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  5776. sizeof(struct host_sp_status_block));
  5777. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  5778. sizeof(struct bnx2x_slowpath));
  5779. #ifdef BCM_CNIC
  5780. /* write address to which L5 should insert its values */
  5781. bp->cnic_eth_dev.addr_drv_info_to_mcp = &bp->slowpath->drv_info_to_mcp;
  5782. #endif
  5783. /* Allocated memory for FW statistics */
  5784. if (bnx2x_alloc_fw_stats_mem(bp))
  5785. goto alloc_mem_err;
  5786. bp->context.size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  5787. BNX2X_PCI_ALLOC(bp->context.vcxt, &bp->context.cxt_mapping,
  5788. bp->context.size);
  5789. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  5790. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  5791. goto alloc_mem_err;
  5792. /* Slow path ring */
  5793. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  5794. /* EQ */
  5795. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  5796. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  5797. /* fastpath */
  5798. /* need to be done at the end, since it's self adjusting to amount
  5799. * of memory available for RSS queues
  5800. */
  5801. if (bnx2x_alloc_fp_mem(bp))
  5802. goto alloc_mem_err;
  5803. return 0;
  5804. alloc_mem_err:
  5805. bnx2x_free_mem(bp);
  5806. BNX2X_ERR("Can't allocate memory\n");
  5807. return -ENOMEM;
  5808. }
  5809. /*
  5810. * Init service functions
  5811. */
  5812. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  5813. struct bnx2x_vlan_mac_obj *obj, bool set,
  5814. int mac_type, unsigned long *ramrod_flags)
  5815. {
  5816. int rc;
  5817. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  5818. memset(&ramrod_param, 0, sizeof(ramrod_param));
  5819. /* Fill general parameters */
  5820. ramrod_param.vlan_mac_obj = obj;
  5821. ramrod_param.ramrod_flags = *ramrod_flags;
  5822. /* Fill a user request section if needed */
  5823. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  5824. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  5825. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  5826. /* Set the command: ADD or DEL */
  5827. if (set)
  5828. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  5829. else
  5830. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  5831. }
  5832. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  5833. if (rc < 0)
  5834. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  5835. return rc;
  5836. }
  5837. int bnx2x_del_all_macs(struct bnx2x *bp,
  5838. struct bnx2x_vlan_mac_obj *mac_obj,
  5839. int mac_type, bool wait_for_comp)
  5840. {
  5841. int rc;
  5842. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  5843. /* Wait for completion of requested */
  5844. if (wait_for_comp)
  5845. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  5846. /* Set the mac type of addresses we want to clear */
  5847. __set_bit(mac_type, &vlan_mac_flags);
  5848. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  5849. if (rc < 0)
  5850. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  5851. return rc;
  5852. }
  5853. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  5854. {
  5855. unsigned long ramrod_flags = 0;
  5856. #ifdef BCM_CNIC
  5857. if (is_zero_ether_addr(bp->dev->dev_addr) && IS_MF_STORAGE_SD(bp)) {
  5858. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  5859. "Ignoring Zero MAC for STORAGE SD mode\n");
  5860. return 0;
  5861. }
  5862. #endif
  5863. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  5864. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  5865. /* Eth MAC is set on RSS leading client (fp[0]) */
  5866. return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->fp->mac_obj, set,
  5867. BNX2X_ETH_MAC, &ramrod_flags);
  5868. }
  5869. int bnx2x_setup_leading(struct bnx2x *bp)
  5870. {
  5871. return bnx2x_setup_queue(bp, &bp->fp[0], 1);
  5872. }
  5873. /**
  5874. * bnx2x_set_int_mode - configure interrupt mode
  5875. *
  5876. * @bp: driver handle
  5877. *
  5878. * In case of MSI-X it will also try to enable MSI-X.
  5879. */
  5880. static void __devinit bnx2x_set_int_mode(struct bnx2x *bp)
  5881. {
  5882. switch (int_mode) {
  5883. case INT_MODE_MSI:
  5884. bnx2x_enable_msi(bp);
  5885. /* falling through... */
  5886. case INT_MODE_INTx:
  5887. bp->num_queues = 1 + NON_ETH_CONTEXT_USE;
  5888. BNX2X_DEV_INFO("set number of queues to 1\n");
  5889. break;
  5890. default:
  5891. /* Set number of queues for MSI-X mode */
  5892. bnx2x_set_num_queues(bp);
  5893. BNX2X_DEV_INFO("set number of queues to %d\n", bp->num_queues);
  5894. /* if we can't use MSI-X we only need one fp,
  5895. * so try to enable MSI-X with the requested number of fp's
  5896. * and fallback to MSI or legacy INTx with one fp
  5897. */
  5898. if (bnx2x_enable_msix(bp) ||
  5899. bp->flags & USING_SINGLE_MSIX_FLAG) {
  5900. /* failed to enable multiple MSI-X */
  5901. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  5902. bp->num_queues, 1 + NON_ETH_CONTEXT_USE);
  5903. bp->num_queues = 1 + NON_ETH_CONTEXT_USE;
  5904. /* Try to enable MSI */
  5905. if (!(bp->flags & USING_SINGLE_MSIX_FLAG) &&
  5906. !(bp->flags & DISABLE_MSI_FLAG))
  5907. bnx2x_enable_msi(bp);
  5908. }
  5909. break;
  5910. }
  5911. }
  5912. /* must be called prioir to any HW initializations */
  5913. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  5914. {
  5915. return L2_ILT_LINES(bp);
  5916. }
  5917. void bnx2x_ilt_set_info(struct bnx2x *bp)
  5918. {
  5919. struct ilt_client_info *ilt_client;
  5920. struct bnx2x_ilt *ilt = BP_ILT(bp);
  5921. u16 line = 0;
  5922. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  5923. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  5924. /* CDU */
  5925. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  5926. ilt_client->client_num = ILT_CLIENT_CDU;
  5927. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  5928. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  5929. ilt_client->start = line;
  5930. line += bnx2x_cid_ilt_lines(bp);
  5931. #ifdef BCM_CNIC
  5932. line += CNIC_ILT_LINES;
  5933. #endif
  5934. ilt_client->end = line - 1;
  5935. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  5936. ilt_client->start,
  5937. ilt_client->end,
  5938. ilt_client->page_size,
  5939. ilt_client->flags,
  5940. ilog2(ilt_client->page_size >> 12));
  5941. /* QM */
  5942. if (QM_INIT(bp->qm_cid_count)) {
  5943. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  5944. ilt_client->client_num = ILT_CLIENT_QM;
  5945. ilt_client->page_size = QM_ILT_PAGE_SZ;
  5946. ilt_client->flags = 0;
  5947. ilt_client->start = line;
  5948. /* 4 bytes for each cid */
  5949. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  5950. QM_ILT_PAGE_SZ);
  5951. ilt_client->end = line - 1;
  5952. DP(NETIF_MSG_IFUP,
  5953. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  5954. ilt_client->start,
  5955. ilt_client->end,
  5956. ilt_client->page_size,
  5957. ilt_client->flags,
  5958. ilog2(ilt_client->page_size >> 12));
  5959. }
  5960. /* SRC */
  5961. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  5962. #ifdef BCM_CNIC
  5963. ilt_client->client_num = ILT_CLIENT_SRC;
  5964. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  5965. ilt_client->flags = 0;
  5966. ilt_client->start = line;
  5967. line += SRC_ILT_LINES;
  5968. ilt_client->end = line - 1;
  5969. DP(NETIF_MSG_IFUP,
  5970. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  5971. ilt_client->start,
  5972. ilt_client->end,
  5973. ilt_client->page_size,
  5974. ilt_client->flags,
  5975. ilog2(ilt_client->page_size >> 12));
  5976. #else
  5977. ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
  5978. #endif
  5979. /* TM */
  5980. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  5981. #ifdef BCM_CNIC
  5982. ilt_client->client_num = ILT_CLIENT_TM;
  5983. ilt_client->page_size = TM_ILT_PAGE_SZ;
  5984. ilt_client->flags = 0;
  5985. ilt_client->start = line;
  5986. line += TM_ILT_LINES;
  5987. ilt_client->end = line - 1;
  5988. DP(NETIF_MSG_IFUP,
  5989. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  5990. ilt_client->start,
  5991. ilt_client->end,
  5992. ilt_client->page_size,
  5993. ilt_client->flags,
  5994. ilog2(ilt_client->page_size >> 12));
  5995. #else
  5996. ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
  5997. #endif
  5998. BUG_ON(line > ILT_MAX_LINES);
  5999. }
  6000. /**
  6001. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6002. *
  6003. * @bp: driver handle
  6004. * @fp: pointer to fastpath
  6005. * @init_params: pointer to parameters structure
  6006. *
  6007. * parameters configured:
  6008. * - HC configuration
  6009. * - Queue's CDU context
  6010. */
  6011. static inline void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  6012. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  6013. {
  6014. u8 cos;
  6015. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  6016. if (!IS_FCOE_FP(fp)) {
  6017. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  6018. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  6019. /* If HC is supporterd, enable host coalescing in the transition
  6020. * to INIT state.
  6021. */
  6022. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  6023. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  6024. /* HC rate */
  6025. init_params->rx.hc_rate = bp->rx_ticks ?
  6026. (1000000 / bp->rx_ticks) : 0;
  6027. init_params->tx.hc_rate = bp->tx_ticks ?
  6028. (1000000 / bp->tx_ticks) : 0;
  6029. /* FW SB ID */
  6030. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  6031. fp->fw_sb_id;
  6032. /*
  6033. * CQ index among the SB indices: FCoE clients uses the default
  6034. * SB, therefore it's different.
  6035. */
  6036. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  6037. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  6038. }
  6039. /* set maximum number of COSs supported by this queue */
  6040. init_params->max_cos = fp->max_cos;
  6041. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  6042. fp->index, init_params->max_cos);
  6043. /* set the context pointers queue object */
  6044. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++)
  6045. init_params->cxts[cos] =
  6046. &bp->context.vcxt[fp->txdata[cos].cid].eth;
  6047. }
  6048. int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6049. struct bnx2x_queue_state_params *q_params,
  6050. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  6051. int tx_index, bool leading)
  6052. {
  6053. memset(tx_only_params, 0, sizeof(*tx_only_params));
  6054. /* Set the command */
  6055. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  6056. /* Set tx-only QUEUE flags: don't zero statistics */
  6057. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  6058. /* choose the index of the cid to send the slow path on */
  6059. tx_only_params->cid_index = tx_index;
  6060. /* Set general TX_ONLY_SETUP parameters */
  6061. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  6062. /* Set Tx TX_ONLY_SETUP parameters */
  6063. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  6064. DP(NETIF_MSG_IFUP,
  6065. "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",
  6066. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  6067. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  6068. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  6069. /* send the ramrod */
  6070. return bnx2x_queue_state_change(bp, q_params);
  6071. }
  6072. /**
  6073. * bnx2x_setup_queue - setup queue
  6074. *
  6075. * @bp: driver handle
  6076. * @fp: pointer to fastpath
  6077. * @leading: is leading
  6078. *
  6079. * This function performs 2 steps in a Queue state machine
  6080. * actually: 1) RESET->INIT 2) INIT->SETUP
  6081. */
  6082. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6083. bool leading)
  6084. {
  6085. struct bnx2x_queue_state_params q_params = {NULL};
  6086. struct bnx2x_queue_setup_params *setup_params =
  6087. &q_params.params.setup;
  6088. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  6089. &q_params.params.tx_only;
  6090. int rc;
  6091. u8 tx_index;
  6092. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  6093. /* reset IGU state skip FCoE L2 queue */
  6094. if (!IS_FCOE_FP(fp))
  6095. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  6096. IGU_INT_ENABLE, 0);
  6097. q_params.q_obj = &fp->q_obj;
  6098. /* We want to wait for completion in this context */
  6099. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6100. /* Prepare the INIT parameters */
  6101. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  6102. /* Set the command */
  6103. q_params.cmd = BNX2X_Q_CMD_INIT;
  6104. /* Change the state to INIT */
  6105. rc = bnx2x_queue_state_change(bp, &q_params);
  6106. if (rc) {
  6107. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  6108. return rc;
  6109. }
  6110. DP(NETIF_MSG_IFUP, "init complete\n");
  6111. /* Now move the Queue to the SETUP state... */
  6112. memset(setup_params, 0, sizeof(*setup_params));
  6113. /* Set QUEUE flags */
  6114. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  6115. /* Set general SETUP parameters */
  6116. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  6117. FIRST_TX_COS_INDEX);
  6118. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  6119. &setup_params->rxq_params);
  6120. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  6121. FIRST_TX_COS_INDEX);
  6122. /* Set the command */
  6123. q_params.cmd = BNX2X_Q_CMD_SETUP;
  6124. /* Change the state to SETUP */
  6125. rc = bnx2x_queue_state_change(bp, &q_params);
  6126. if (rc) {
  6127. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  6128. return rc;
  6129. }
  6130. /* loop through the relevant tx-only indices */
  6131. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6132. tx_index < fp->max_cos;
  6133. tx_index++) {
  6134. /* prepare and send tx-only ramrod*/
  6135. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  6136. tx_only_params, tx_index, leading);
  6137. if (rc) {
  6138. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  6139. fp->index, tx_index);
  6140. return rc;
  6141. }
  6142. }
  6143. return rc;
  6144. }
  6145. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  6146. {
  6147. struct bnx2x_fastpath *fp = &bp->fp[index];
  6148. struct bnx2x_fp_txdata *txdata;
  6149. struct bnx2x_queue_state_params q_params = {NULL};
  6150. int rc, tx_index;
  6151. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  6152. q_params.q_obj = &fp->q_obj;
  6153. /* We want to wait for completion in this context */
  6154. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6155. /* close tx-only connections */
  6156. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6157. tx_index < fp->max_cos;
  6158. tx_index++){
  6159. /* ascertain this is a normal queue*/
  6160. txdata = &fp->txdata[tx_index];
  6161. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  6162. txdata->txq_index);
  6163. /* send halt terminate on tx-only connection */
  6164. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6165. memset(&q_params.params.terminate, 0,
  6166. sizeof(q_params.params.terminate));
  6167. q_params.params.terminate.cid_index = tx_index;
  6168. rc = bnx2x_queue_state_change(bp, &q_params);
  6169. if (rc)
  6170. return rc;
  6171. /* send halt terminate on tx-only connection */
  6172. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6173. memset(&q_params.params.cfc_del, 0,
  6174. sizeof(q_params.params.cfc_del));
  6175. q_params.params.cfc_del.cid_index = tx_index;
  6176. rc = bnx2x_queue_state_change(bp, &q_params);
  6177. if (rc)
  6178. return rc;
  6179. }
  6180. /* Stop the primary connection: */
  6181. /* ...halt the connection */
  6182. q_params.cmd = BNX2X_Q_CMD_HALT;
  6183. rc = bnx2x_queue_state_change(bp, &q_params);
  6184. if (rc)
  6185. return rc;
  6186. /* ...terminate the connection */
  6187. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6188. memset(&q_params.params.terminate, 0,
  6189. sizeof(q_params.params.terminate));
  6190. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  6191. rc = bnx2x_queue_state_change(bp, &q_params);
  6192. if (rc)
  6193. return rc;
  6194. /* ...delete cfc entry */
  6195. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6196. memset(&q_params.params.cfc_del, 0,
  6197. sizeof(q_params.params.cfc_del));
  6198. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  6199. return bnx2x_queue_state_change(bp, &q_params);
  6200. }
  6201. static void bnx2x_reset_func(struct bnx2x *bp)
  6202. {
  6203. int port = BP_PORT(bp);
  6204. int func = BP_FUNC(bp);
  6205. int i;
  6206. /* Disable the function in the FW */
  6207. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  6208. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  6209. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  6210. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  6211. /* FP SBs */
  6212. for_each_eth_queue(bp, i) {
  6213. struct bnx2x_fastpath *fp = &bp->fp[i];
  6214. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6215. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  6216. SB_DISABLED);
  6217. }
  6218. #ifdef BCM_CNIC
  6219. /* CNIC SB */
  6220. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6221. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(bnx2x_cnic_fw_sb_id(bp)),
  6222. SB_DISABLED);
  6223. #endif
  6224. /* SP SB */
  6225. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6226. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  6227. SB_DISABLED);
  6228. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  6229. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  6230. 0);
  6231. /* Configure IGU */
  6232. if (bp->common.int_block == INT_BLOCK_HC) {
  6233. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6234. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6235. } else {
  6236. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6237. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6238. }
  6239. #ifdef BCM_CNIC
  6240. /* Disable Timer scan */
  6241. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  6242. /*
  6243. * Wait for at least 10ms and up to 2 second for the timers scan to
  6244. * complete
  6245. */
  6246. for (i = 0; i < 200; i++) {
  6247. msleep(10);
  6248. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  6249. break;
  6250. }
  6251. #endif
  6252. /* Clear ILT */
  6253. bnx2x_clear_func_ilt(bp, func);
  6254. /* Timers workaround bug for E2: if this is vnic-3,
  6255. * we need to set the entire ilt range for this timers.
  6256. */
  6257. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  6258. struct ilt_client_info ilt_cli;
  6259. /* use dummy TM client */
  6260. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  6261. ilt_cli.start = 0;
  6262. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  6263. ilt_cli.client_num = ILT_CLIENT_TM;
  6264. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  6265. }
  6266. /* this assumes that reset_port() called before reset_func()*/
  6267. if (!CHIP_IS_E1x(bp))
  6268. bnx2x_pf_disable(bp);
  6269. bp->dmae_ready = 0;
  6270. }
  6271. static void bnx2x_reset_port(struct bnx2x *bp)
  6272. {
  6273. int port = BP_PORT(bp);
  6274. u32 val;
  6275. /* Reset physical Link */
  6276. bnx2x__link_reset(bp);
  6277. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6278. /* Do not rcv packets to BRB */
  6279. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  6280. /* Do not direct rcv packets that are not for MCP to the BRB */
  6281. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  6282. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  6283. /* Configure AEU */
  6284. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  6285. msleep(100);
  6286. /* Check for BRB port occupancy */
  6287. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  6288. if (val)
  6289. DP(NETIF_MSG_IFDOWN,
  6290. "BRB1 is not empty %d blocks are occupied\n", val);
  6291. /* TODO: Close Doorbell port? */
  6292. }
  6293. static inline int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  6294. {
  6295. struct bnx2x_func_state_params func_params = {NULL};
  6296. /* Prepare parameters for function state transitions */
  6297. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6298. func_params.f_obj = &bp->func_obj;
  6299. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  6300. func_params.params.hw_init.load_phase = load_code;
  6301. return bnx2x_func_state_change(bp, &func_params);
  6302. }
  6303. static inline int bnx2x_func_stop(struct bnx2x *bp)
  6304. {
  6305. struct bnx2x_func_state_params func_params = {NULL};
  6306. int rc;
  6307. /* Prepare parameters for function state transitions */
  6308. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6309. func_params.f_obj = &bp->func_obj;
  6310. func_params.cmd = BNX2X_F_CMD_STOP;
  6311. /*
  6312. * Try to stop the function the 'good way'. If fails (in case
  6313. * of a parity error during bnx2x_chip_cleanup()) and we are
  6314. * not in a debug mode, perform a state transaction in order to
  6315. * enable further HW_RESET transaction.
  6316. */
  6317. rc = bnx2x_func_state_change(bp, &func_params);
  6318. if (rc) {
  6319. #ifdef BNX2X_STOP_ON_ERROR
  6320. return rc;
  6321. #else
  6322. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  6323. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  6324. return bnx2x_func_state_change(bp, &func_params);
  6325. #endif
  6326. }
  6327. return 0;
  6328. }
  6329. /**
  6330. * bnx2x_send_unload_req - request unload mode from the MCP.
  6331. *
  6332. * @bp: driver handle
  6333. * @unload_mode: requested function's unload mode
  6334. *
  6335. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  6336. */
  6337. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  6338. {
  6339. u32 reset_code = 0;
  6340. int port = BP_PORT(bp);
  6341. /* Select the UNLOAD request mode */
  6342. if (unload_mode == UNLOAD_NORMAL)
  6343. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6344. else if (bp->flags & NO_WOL_FLAG)
  6345. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  6346. else if (bp->wol) {
  6347. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  6348. u8 *mac_addr = bp->dev->dev_addr;
  6349. u32 val;
  6350. u16 pmc;
  6351. /* The mac address is written to entries 1-4 to
  6352. * preserve entry 0 which is used by the PMF
  6353. */
  6354. u8 entry = (BP_VN(bp) + 1)*8;
  6355. val = (mac_addr[0] << 8) | mac_addr[1];
  6356. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  6357. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  6358. (mac_addr[4] << 8) | mac_addr[5];
  6359. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  6360. /* Enable the PME and clear the status */
  6361. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
  6362. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  6363. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
  6364. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  6365. } else
  6366. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6367. /* Send the request to the MCP */
  6368. if (!BP_NOMCP(bp))
  6369. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  6370. else {
  6371. int path = BP_PATH(bp);
  6372. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  6373. path, load_count[path][0], load_count[path][1],
  6374. load_count[path][2]);
  6375. load_count[path][0]--;
  6376. load_count[path][1 + port]--;
  6377. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  6378. path, load_count[path][0], load_count[path][1],
  6379. load_count[path][2]);
  6380. if (load_count[path][0] == 0)
  6381. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  6382. else if (load_count[path][1 + port] == 0)
  6383. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  6384. else
  6385. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  6386. }
  6387. return reset_code;
  6388. }
  6389. /**
  6390. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  6391. *
  6392. * @bp: driver handle
  6393. */
  6394. void bnx2x_send_unload_done(struct bnx2x *bp)
  6395. {
  6396. /* Report UNLOAD_DONE to MCP */
  6397. if (!BP_NOMCP(bp))
  6398. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  6399. }
  6400. static inline int bnx2x_func_wait_started(struct bnx2x *bp)
  6401. {
  6402. int tout = 50;
  6403. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  6404. if (!bp->port.pmf)
  6405. return 0;
  6406. /*
  6407. * (assumption: No Attention from MCP at this stage)
  6408. * PMF probably in the middle of TXdisable/enable transaction
  6409. * 1. Sync IRS for default SB
  6410. * 2. Sync SP queue - this guarantes us that attention handling started
  6411. * 3. Wait, that TXdisable/enable transaction completes
  6412. *
  6413. * 1+2 guranty that if DCBx attention was scheduled it already changed
  6414. * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
  6415. * received complettion for the transaction the state is TX_STOPPED.
  6416. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  6417. * transaction.
  6418. */
  6419. /* make sure default SB ISR is done */
  6420. if (msix)
  6421. synchronize_irq(bp->msix_table[0].vector);
  6422. else
  6423. synchronize_irq(bp->pdev->irq);
  6424. flush_workqueue(bnx2x_wq);
  6425. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  6426. BNX2X_F_STATE_STARTED && tout--)
  6427. msleep(20);
  6428. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  6429. BNX2X_F_STATE_STARTED) {
  6430. #ifdef BNX2X_STOP_ON_ERROR
  6431. BNX2X_ERR("Wrong function state\n");
  6432. return -EBUSY;
  6433. #else
  6434. /*
  6435. * Failed to complete the transaction in a "good way"
  6436. * Force both transactions with CLR bit
  6437. */
  6438. struct bnx2x_func_state_params func_params = {NULL};
  6439. DP(NETIF_MSG_IFDOWN,
  6440. "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  6441. func_params.f_obj = &bp->func_obj;
  6442. __set_bit(RAMROD_DRV_CLR_ONLY,
  6443. &func_params.ramrod_flags);
  6444. /* STARTED-->TX_ST0PPED */
  6445. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  6446. bnx2x_func_state_change(bp, &func_params);
  6447. /* TX_ST0PPED-->STARTED */
  6448. func_params.cmd = BNX2X_F_CMD_TX_START;
  6449. return bnx2x_func_state_change(bp, &func_params);
  6450. #endif
  6451. }
  6452. return 0;
  6453. }
  6454. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode)
  6455. {
  6456. int port = BP_PORT(bp);
  6457. int i, rc = 0;
  6458. u8 cos;
  6459. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  6460. u32 reset_code;
  6461. /* Wait until tx fastpath tasks complete */
  6462. for_each_tx_queue(bp, i) {
  6463. struct bnx2x_fastpath *fp = &bp->fp[i];
  6464. for_each_cos_in_tx_queue(fp, cos)
  6465. rc = bnx2x_clean_tx_queue(bp, &fp->txdata[cos]);
  6466. #ifdef BNX2X_STOP_ON_ERROR
  6467. if (rc)
  6468. return;
  6469. #endif
  6470. }
  6471. /* Give HW time to discard old tx messages */
  6472. usleep_range(1000, 1000);
  6473. /* Clean all ETH MACs */
  6474. rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_ETH_MAC, false);
  6475. if (rc < 0)
  6476. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  6477. /* Clean up UC list */
  6478. rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_UC_LIST_MAC,
  6479. true);
  6480. if (rc < 0)
  6481. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  6482. rc);
  6483. /* Disable LLH */
  6484. if (!CHIP_IS_E1(bp))
  6485. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  6486. /* Set "drop all" (stop Rx).
  6487. * We need to take a netif_addr_lock() here in order to prevent
  6488. * a race between the completion code and this code.
  6489. */
  6490. netif_addr_lock_bh(bp->dev);
  6491. /* Schedule the rx_mode command */
  6492. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  6493. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  6494. else
  6495. bnx2x_set_storm_rx_mode(bp);
  6496. /* Cleanup multicast configuration */
  6497. rparam.mcast_obj = &bp->mcast_obj;
  6498. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  6499. if (rc < 0)
  6500. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  6501. netif_addr_unlock_bh(bp->dev);
  6502. /*
  6503. * Send the UNLOAD_REQUEST to the MCP. This will return if
  6504. * this function should perform FUNC, PORT or COMMON HW
  6505. * reset.
  6506. */
  6507. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  6508. /*
  6509. * (assumption: No Attention from MCP at this stage)
  6510. * PMF probably in the middle of TXdisable/enable transaction
  6511. */
  6512. rc = bnx2x_func_wait_started(bp);
  6513. if (rc) {
  6514. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  6515. #ifdef BNX2X_STOP_ON_ERROR
  6516. return;
  6517. #endif
  6518. }
  6519. /* Close multi and leading connections
  6520. * Completions for ramrods are collected in a synchronous way
  6521. */
  6522. for_each_queue(bp, i)
  6523. if (bnx2x_stop_queue(bp, i))
  6524. #ifdef BNX2X_STOP_ON_ERROR
  6525. return;
  6526. #else
  6527. goto unload_error;
  6528. #endif
  6529. /* If SP settings didn't get completed so far - something
  6530. * very wrong has happen.
  6531. */
  6532. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  6533. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  6534. #ifndef BNX2X_STOP_ON_ERROR
  6535. unload_error:
  6536. #endif
  6537. rc = bnx2x_func_stop(bp);
  6538. if (rc) {
  6539. BNX2X_ERR("Function stop failed!\n");
  6540. #ifdef BNX2X_STOP_ON_ERROR
  6541. return;
  6542. #endif
  6543. }
  6544. /* Disable HW interrupts, NAPI */
  6545. bnx2x_netif_stop(bp, 1);
  6546. /* Release IRQs */
  6547. bnx2x_free_irq(bp);
  6548. /* Reset the chip */
  6549. rc = bnx2x_reset_hw(bp, reset_code);
  6550. if (rc)
  6551. BNX2X_ERR("HW_RESET failed\n");
  6552. /* Report UNLOAD_DONE to MCP */
  6553. bnx2x_send_unload_done(bp);
  6554. }
  6555. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  6556. {
  6557. u32 val;
  6558. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  6559. if (CHIP_IS_E1(bp)) {
  6560. int port = BP_PORT(bp);
  6561. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  6562. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  6563. val = REG_RD(bp, addr);
  6564. val &= ~(0x300);
  6565. REG_WR(bp, addr, val);
  6566. } else {
  6567. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  6568. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  6569. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  6570. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  6571. }
  6572. }
  6573. /* Close gates #2, #3 and #4: */
  6574. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  6575. {
  6576. u32 val;
  6577. /* Gates #2 and #4a are closed/opened for "not E1" only */
  6578. if (!CHIP_IS_E1(bp)) {
  6579. /* #4 */
  6580. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  6581. /* #2 */
  6582. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  6583. }
  6584. /* #3 */
  6585. if (CHIP_IS_E1x(bp)) {
  6586. /* Prevent interrupts from HC on both ports */
  6587. val = REG_RD(bp, HC_REG_CONFIG_1);
  6588. REG_WR(bp, HC_REG_CONFIG_1,
  6589. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  6590. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  6591. val = REG_RD(bp, HC_REG_CONFIG_0);
  6592. REG_WR(bp, HC_REG_CONFIG_0,
  6593. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  6594. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  6595. } else {
  6596. /* Prevent incomming interrupts in IGU */
  6597. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  6598. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  6599. (!close) ?
  6600. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  6601. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  6602. }
  6603. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  6604. close ? "closing" : "opening");
  6605. mmiowb();
  6606. }
  6607. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  6608. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  6609. {
  6610. /* Do some magic... */
  6611. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  6612. *magic_val = val & SHARED_MF_CLP_MAGIC;
  6613. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  6614. }
  6615. /**
  6616. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  6617. *
  6618. * @bp: driver handle
  6619. * @magic_val: old value of the `magic' bit.
  6620. */
  6621. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  6622. {
  6623. /* Restore the `magic' bit value... */
  6624. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  6625. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  6626. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  6627. }
  6628. /**
  6629. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  6630. *
  6631. * @bp: driver handle
  6632. * @magic_val: old value of 'magic' bit.
  6633. *
  6634. * Takes care of CLP configurations.
  6635. */
  6636. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  6637. {
  6638. u32 shmem;
  6639. u32 validity_offset;
  6640. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  6641. /* Set `magic' bit in order to save MF config */
  6642. if (!CHIP_IS_E1(bp))
  6643. bnx2x_clp_reset_prep(bp, magic_val);
  6644. /* Get shmem offset */
  6645. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  6646. validity_offset = offsetof(struct shmem_region, validity_map[0]);
  6647. /* Clear validity map flags */
  6648. if (shmem > 0)
  6649. REG_WR(bp, shmem + validity_offset, 0);
  6650. }
  6651. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  6652. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  6653. /**
  6654. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  6655. *
  6656. * @bp: driver handle
  6657. */
  6658. static inline void bnx2x_mcp_wait_one(struct bnx2x *bp)
  6659. {
  6660. /* special handling for emulation and FPGA,
  6661. wait 10 times longer */
  6662. if (CHIP_REV_IS_SLOW(bp))
  6663. msleep(MCP_ONE_TIMEOUT*10);
  6664. else
  6665. msleep(MCP_ONE_TIMEOUT);
  6666. }
  6667. /*
  6668. * initializes bp->common.shmem_base and waits for validity signature to appear
  6669. */
  6670. static int bnx2x_init_shmem(struct bnx2x *bp)
  6671. {
  6672. int cnt = 0;
  6673. u32 val = 0;
  6674. do {
  6675. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  6676. if (bp->common.shmem_base) {
  6677. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  6678. if (val & SHR_MEM_VALIDITY_MB)
  6679. return 0;
  6680. }
  6681. bnx2x_mcp_wait_one(bp);
  6682. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  6683. BNX2X_ERR("BAD MCP validity signature\n");
  6684. return -ENODEV;
  6685. }
  6686. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  6687. {
  6688. int rc = bnx2x_init_shmem(bp);
  6689. /* Restore the `magic' bit value */
  6690. if (!CHIP_IS_E1(bp))
  6691. bnx2x_clp_reset_done(bp, magic_val);
  6692. return rc;
  6693. }
  6694. static void bnx2x_pxp_prep(struct bnx2x *bp)
  6695. {
  6696. if (!CHIP_IS_E1(bp)) {
  6697. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  6698. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  6699. mmiowb();
  6700. }
  6701. }
  6702. /*
  6703. * Reset the whole chip except for:
  6704. * - PCIE core
  6705. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  6706. * one reset bit)
  6707. * - IGU
  6708. * - MISC (including AEU)
  6709. * - GRC
  6710. * - RBCN, RBCP
  6711. */
  6712. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  6713. {
  6714. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  6715. u32 global_bits2, stay_reset2;
  6716. /*
  6717. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  6718. * (per chip) blocks.
  6719. */
  6720. global_bits2 =
  6721. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  6722. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  6723. /* Don't reset the following blocks */
  6724. not_reset_mask1 =
  6725. MISC_REGISTERS_RESET_REG_1_RST_HC |
  6726. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  6727. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  6728. not_reset_mask2 =
  6729. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  6730. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  6731. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  6732. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  6733. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  6734. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  6735. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  6736. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  6737. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  6738. MISC_REGISTERS_RESET_REG_2_PGLC;
  6739. /*
  6740. * Keep the following blocks in reset:
  6741. * - all xxMACs are handled by the bnx2x_link code.
  6742. */
  6743. stay_reset2 =
  6744. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  6745. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  6746. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  6747. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  6748. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  6749. MISC_REGISTERS_RESET_REG_2_UMAC1 |
  6750. MISC_REGISTERS_RESET_REG_2_XMAC |
  6751. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  6752. /* Full reset masks according to the chip */
  6753. reset_mask1 = 0xffffffff;
  6754. if (CHIP_IS_E1(bp))
  6755. reset_mask2 = 0xffff;
  6756. else if (CHIP_IS_E1H(bp))
  6757. reset_mask2 = 0x1ffff;
  6758. else if (CHIP_IS_E2(bp))
  6759. reset_mask2 = 0xfffff;
  6760. else /* CHIP_IS_E3 */
  6761. reset_mask2 = 0x3ffffff;
  6762. /* Don't reset global blocks unless we need to */
  6763. if (!global)
  6764. reset_mask2 &= ~global_bits2;
  6765. /*
  6766. * In case of attention in the QM, we need to reset PXP
  6767. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  6768. * because otherwise QM reset would release 'close the gates' shortly
  6769. * before resetting the PXP, then the PSWRQ would send a write
  6770. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  6771. * read the payload data from PSWWR, but PSWWR would not
  6772. * respond. The write queue in PGLUE would stuck, dmae commands
  6773. * would not return. Therefore it's important to reset the second
  6774. * reset register (containing the
  6775. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  6776. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  6777. * bit).
  6778. */
  6779. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  6780. reset_mask2 & (~not_reset_mask2));
  6781. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  6782. reset_mask1 & (~not_reset_mask1));
  6783. barrier();
  6784. mmiowb();
  6785. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  6786. reset_mask2 & (~stay_reset2));
  6787. barrier();
  6788. mmiowb();
  6789. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  6790. mmiowb();
  6791. }
  6792. /**
  6793. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  6794. * It should get cleared in no more than 1s.
  6795. *
  6796. * @bp: driver handle
  6797. *
  6798. * It should get cleared in no more than 1s. Returns 0 if
  6799. * pending writes bit gets cleared.
  6800. */
  6801. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  6802. {
  6803. u32 cnt = 1000;
  6804. u32 pend_bits = 0;
  6805. do {
  6806. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  6807. if (pend_bits == 0)
  6808. break;
  6809. usleep_range(1000, 1000);
  6810. } while (cnt-- > 0);
  6811. if (cnt <= 0) {
  6812. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  6813. pend_bits);
  6814. return -EBUSY;
  6815. }
  6816. return 0;
  6817. }
  6818. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  6819. {
  6820. int cnt = 1000;
  6821. u32 val = 0;
  6822. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  6823. /* Empty the Tetris buffer, wait for 1s */
  6824. do {
  6825. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  6826. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  6827. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  6828. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  6829. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  6830. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  6831. ((port_is_idle_0 & 0x1) == 0x1) &&
  6832. ((port_is_idle_1 & 0x1) == 0x1) &&
  6833. (pgl_exp_rom2 == 0xffffffff))
  6834. break;
  6835. usleep_range(1000, 1000);
  6836. } while (cnt-- > 0);
  6837. if (cnt <= 0) {
  6838. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  6839. 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",
  6840. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  6841. pgl_exp_rom2);
  6842. return -EAGAIN;
  6843. }
  6844. barrier();
  6845. /* Close gates #2, #3 and #4 */
  6846. bnx2x_set_234_gates(bp, true);
  6847. /* Poll for IGU VQs for 57712 and newer chips */
  6848. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  6849. return -EAGAIN;
  6850. /* TBD: Indicate that "process kill" is in progress to MCP */
  6851. /* Clear "unprepared" bit */
  6852. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  6853. barrier();
  6854. /* Make sure all is written to the chip before the reset */
  6855. mmiowb();
  6856. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  6857. * PSWHST, GRC and PSWRD Tetris buffer.
  6858. */
  6859. usleep_range(1000, 1000);
  6860. /* Prepare to chip reset: */
  6861. /* MCP */
  6862. if (global)
  6863. bnx2x_reset_mcp_prep(bp, &val);
  6864. /* PXP */
  6865. bnx2x_pxp_prep(bp);
  6866. barrier();
  6867. /* reset the chip */
  6868. bnx2x_process_kill_chip_reset(bp, global);
  6869. barrier();
  6870. /* Recover after reset: */
  6871. /* MCP */
  6872. if (global && bnx2x_reset_mcp_comp(bp, val))
  6873. return -EAGAIN;
  6874. /* TBD: Add resetting the NO_MCP mode DB here */
  6875. /* PXP */
  6876. bnx2x_pxp_prep(bp);
  6877. /* Open the gates #2, #3 and #4 */
  6878. bnx2x_set_234_gates(bp, false);
  6879. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  6880. * reset state, re-enable attentions. */
  6881. return 0;
  6882. }
  6883. int bnx2x_leader_reset(struct bnx2x *bp)
  6884. {
  6885. int rc = 0;
  6886. bool global = bnx2x_reset_is_global(bp);
  6887. u32 load_code;
  6888. /* if not going to reset MCP - load "fake" driver to reset HW while
  6889. * driver is owner of the HW
  6890. */
  6891. if (!global && !BP_NOMCP(bp)) {
  6892. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ, 0);
  6893. if (!load_code) {
  6894. BNX2X_ERR("MCP response failure, aborting\n");
  6895. rc = -EAGAIN;
  6896. goto exit_leader_reset;
  6897. }
  6898. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  6899. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  6900. BNX2X_ERR("MCP unexpected resp, aborting\n");
  6901. rc = -EAGAIN;
  6902. goto exit_leader_reset2;
  6903. }
  6904. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  6905. if (!load_code) {
  6906. BNX2X_ERR("MCP response failure, aborting\n");
  6907. rc = -EAGAIN;
  6908. goto exit_leader_reset2;
  6909. }
  6910. }
  6911. /* Try to recover after the failure */
  6912. if (bnx2x_process_kill(bp, global)) {
  6913. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  6914. BP_PATH(bp));
  6915. rc = -EAGAIN;
  6916. goto exit_leader_reset2;
  6917. }
  6918. /*
  6919. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  6920. * state.
  6921. */
  6922. bnx2x_set_reset_done(bp);
  6923. if (global)
  6924. bnx2x_clear_reset_global(bp);
  6925. exit_leader_reset2:
  6926. /* unload "fake driver" if it was loaded */
  6927. if (!global && !BP_NOMCP(bp)) {
  6928. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  6929. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  6930. }
  6931. exit_leader_reset:
  6932. bp->is_leader = 0;
  6933. bnx2x_release_leader_lock(bp);
  6934. smp_mb();
  6935. return rc;
  6936. }
  6937. static inline void bnx2x_recovery_failed(struct bnx2x *bp)
  6938. {
  6939. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  6940. /* Disconnect this device */
  6941. netif_device_detach(bp->dev);
  6942. /*
  6943. * Block ifup for all function on this engine until "process kill"
  6944. * or power cycle.
  6945. */
  6946. bnx2x_set_reset_in_progress(bp);
  6947. /* Shut down the power */
  6948. bnx2x_set_power_state(bp, PCI_D3hot);
  6949. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  6950. smp_mb();
  6951. }
  6952. /*
  6953. * Assumption: runs under rtnl lock. This together with the fact
  6954. * that it's called only from bnx2x_sp_rtnl() ensure that it
  6955. * will never be called when netif_running(bp->dev) is false.
  6956. */
  6957. static void bnx2x_parity_recover(struct bnx2x *bp)
  6958. {
  6959. bool global = false;
  6960. u32 error_recovered, error_unrecovered;
  6961. bool is_parity;
  6962. DP(NETIF_MSG_HW, "Handling parity\n");
  6963. while (1) {
  6964. switch (bp->recovery_state) {
  6965. case BNX2X_RECOVERY_INIT:
  6966. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  6967. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  6968. WARN_ON(!is_parity);
  6969. /* Try to get a LEADER_LOCK HW lock */
  6970. if (bnx2x_trylock_leader_lock(bp)) {
  6971. bnx2x_set_reset_in_progress(bp);
  6972. /*
  6973. * Check if there is a global attention and if
  6974. * there was a global attention, set the global
  6975. * reset bit.
  6976. */
  6977. if (global)
  6978. bnx2x_set_reset_global(bp);
  6979. bp->is_leader = 1;
  6980. }
  6981. /* Stop the driver */
  6982. /* If interface has been removed - break */
  6983. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY))
  6984. return;
  6985. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  6986. /* Ensure "is_leader", MCP command sequence and
  6987. * "recovery_state" update values are seen on other
  6988. * CPUs.
  6989. */
  6990. smp_mb();
  6991. break;
  6992. case BNX2X_RECOVERY_WAIT:
  6993. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  6994. if (bp->is_leader) {
  6995. int other_engine = BP_PATH(bp) ? 0 : 1;
  6996. bool other_load_status =
  6997. bnx2x_get_load_status(bp, other_engine);
  6998. bool load_status =
  6999. bnx2x_get_load_status(bp, BP_PATH(bp));
  7000. global = bnx2x_reset_is_global(bp);
  7001. /*
  7002. * In case of a parity in a global block, let
  7003. * the first leader that performs a
  7004. * leader_reset() reset the global blocks in
  7005. * order to clear global attentions. Otherwise
  7006. * the the gates will remain closed for that
  7007. * engine.
  7008. */
  7009. if (load_status ||
  7010. (global && other_load_status)) {
  7011. /* Wait until all other functions get
  7012. * down.
  7013. */
  7014. schedule_delayed_work(&bp->sp_rtnl_task,
  7015. HZ/10);
  7016. return;
  7017. } else {
  7018. /* If all other functions got down -
  7019. * try to bring the chip back to
  7020. * normal. In any case it's an exit
  7021. * point for a leader.
  7022. */
  7023. if (bnx2x_leader_reset(bp)) {
  7024. bnx2x_recovery_failed(bp);
  7025. return;
  7026. }
  7027. /* If we are here, means that the
  7028. * leader has succeeded and doesn't
  7029. * want to be a leader any more. Try
  7030. * to continue as a none-leader.
  7031. */
  7032. break;
  7033. }
  7034. } else { /* non-leader */
  7035. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  7036. /* Try to get a LEADER_LOCK HW lock as
  7037. * long as a former leader may have
  7038. * been unloaded by the user or
  7039. * released a leadership by another
  7040. * reason.
  7041. */
  7042. if (bnx2x_trylock_leader_lock(bp)) {
  7043. /* I'm a leader now! Restart a
  7044. * switch case.
  7045. */
  7046. bp->is_leader = 1;
  7047. break;
  7048. }
  7049. schedule_delayed_work(&bp->sp_rtnl_task,
  7050. HZ/10);
  7051. return;
  7052. } else {
  7053. /*
  7054. * If there was a global attention, wait
  7055. * for it to be cleared.
  7056. */
  7057. if (bnx2x_reset_is_global(bp)) {
  7058. schedule_delayed_work(
  7059. &bp->sp_rtnl_task,
  7060. HZ/10);
  7061. return;
  7062. }
  7063. error_recovered =
  7064. bp->eth_stats.recoverable_error;
  7065. error_unrecovered =
  7066. bp->eth_stats.unrecoverable_error;
  7067. bp->recovery_state =
  7068. BNX2X_RECOVERY_NIC_LOADING;
  7069. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  7070. error_unrecovered++;
  7071. netdev_err(bp->dev,
  7072. "Recovery failed. Power cycle needed\n");
  7073. /* Disconnect this device */
  7074. netif_device_detach(bp->dev);
  7075. /* Shut down the power */
  7076. bnx2x_set_power_state(
  7077. bp, PCI_D3hot);
  7078. smp_mb();
  7079. } else {
  7080. bp->recovery_state =
  7081. BNX2X_RECOVERY_DONE;
  7082. error_recovered++;
  7083. smp_mb();
  7084. }
  7085. bp->eth_stats.recoverable_error =
  7086. error_recovered;
  7087. bp->eth_stats.unrecoverable_error =
  7088. error_unrecovered;
  7089. return;
  7090. }
  7091. }
  7092. default:
  7093. return;
  7094. }
  7095. }
  7096. }
  7097. static int bnx2x_close(struct net_device *dev);
  7098. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  7099. * scheduled on a general queue in order to prevent a dead lock.
  7100. */
  7101. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  7102. {
  7103. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  7104. rtnl_lock();
  7105. if (!netif_running(bp->dev))
  7106. goto sp_rtnl_exit;
  7107. /* if stop on error is defined no recovery flows should be executed */
  7108. #ifdef BNX2X_STOP_ON_ERROR
  7109. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  7110. "you will need to reboot when done\n");
  7111. goto sp_rtnl_not_reset;
  7112. #endif
  7113. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  7114. /*
  7115. * Clear all pending SP commands as we are going to reset the
  7116. * function anyway.
  7117. */
  7118. bp->sp_rtnl_state = 0;
  7119. smp_mb();
  7120. bnx2x_parity_recover(bp);
  7121. goto sp_rtnl_exit;
  7122. }
  7123. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  7124. /*
  7125. * Clear all pending SP commands as we are going to reset the
  7126. * function anyway.
  7127. */
  7128. bp->sp_rtnl_state = 0;
  7129. smp_mb();
  7130. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  7131. bnx2x_nic_load(bp, LOAD_NORMAL);
  7132. goto sp_rtnl_exit;
  7133. }
  7134. #ifdef BNX2X_STOP_ON_ERROR
  7135. sp_rtnl_not_reset:
  7136. #endif
  7137. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  7138. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  7139. /*
  7140. * in case of fan failure we need to reset id if the "stop on error"
  7141. * debug flag is set, since we trying to prevent permanent overheating
  7142. * damage
  7143. */
  7144. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  7145. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  7146. netif_device_detach(bp->dev);
  7147. bnx2x_close(bp->dev);
  7148. }
  7149. sp_rtnl_exit:
  7150. rtnl_unlock();
  7151. }
  7152. /* end of nic load/unload */
  7153. static void bnx2x_period_task(struct work_struct *work)
  7154. {
  7155. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  7156. if (!netif_running(bp->dev))
  7157. goto period_task_exit;
  7158. if (CHIP_REV_IS_SLOW(bp)) {
  7159. BNX2X_ERR("period task called on emulation, ignoring\n");
  7160. goto period_task_exit;
  7161. }
  7162. bnx2x_acquire_phy_lock(bp);
  7163. /*
  7164. * The barrier is needed to ensure the ordering between the writing to
  7165. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  7166. * the reading here.
  7167. */
  7168. smp_mb();
  7169. if (bp->port.pmf) {
  7170. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  7171. /* Re-queue task in 1 sec */
  7172. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  7173. }
  7174. bnx2x_release_phy_lock(bp);
  7175. period_task_exit:
  7176. return;
  7177. }
  7178. /*
  7179. * Init service functions
  7180. */
  7181. static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  7182. {
  7183. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  7184. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  7185. return base + (BP_ABS_FUNC(bp)) * stride;
  7186. }
  7187. static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
  7188. {
  7189. u32 reg = bnx2x_get_pretend_reg(bp);
  7190. /* Flush all outstanding writes */
  7191. mmiowb();
  7192. /* Pretend to be function 0 */
  7193. REG_WR(bp, reg, 0);
  7194. REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
  7195. /* From now we are in the "like-E1" mode */
  7196. bnx2x_int_disable(bp);
  7197. /* Flush all outstanding writes */
  7198. mmiowb();
  7199. /* Restore the original function */
  7200. REG_WR(bp, reg, BP_ABS_FUNC(bp));
  7201. REG_RD(bp, reg);
  7202. }
  7203. static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
  7204. {
  7205. if (CHIP_IS_E1(bp))
  7206. bnx2x_int_disable(bp);
  7207. else
  7208. bnx2x_undi_int_disable_e1h(bp);
  7209. }
  7210. static void __devinit bnx2x_prev_unload_close_mac(struct bnx2x *bp)
  7211. {
  7212. u32 val, base_addr, offset, mask, reset_reg;
  7213. bool mac_stopped = false;
  7214. u8 port = BP_PORT(bp);
  7215. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  7216. if (!CHIP_IS_E3(bp)) {
  7217. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  7218. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  7219. if ((mask & reset_reg) && val) {
  7220. u32 wb_data[2];
  7221. BNX2X_DEV_INFO("Disable bmac Rx\n");
  7222. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  7223. : NIG_REG_INGRESS_BMAC0_MEM;
  7224. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  7225. : BIGMAC_REGISTER_BMAC_CONTROL;
  7226. /*
  7227. * use rd/wr since we cannot use dmae. This is safe
  7228. * since MCP won't access the bus due to the request
  7229. * to unload, and no function on the path can be
  7230. * loaded at this time.
  7231. */
  7232. wb_data[0] = REG_RD(bp, base_addr + offset);
  7233. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  7234. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  7235. REG_WR(bp, base_addr + offset, wb_data[0]);
  7236. REG_WR(bp, base_addr + offset + 0x4, wb_data[1]);
  7237. }
  7238. BNX2X_DEV_INFO("Disable emac Rx\n");
  7239. REG_WR(bp, NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4, 0);
  7240. mac_stopped = true;
  7241. } else {
  7242. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  7243. BNX2X_DEV_INFO("Disable xmac Rx\n");
  7244. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  7245. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  7246. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  7247. val & ~(1 << 1));
  7248. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  7249. val | (1 << 1));
  7250. REG_WR(bp, base_addr + XMAC_REG_CTRL, 0);
  7251. mac_stopped = true;
  7252. }
  7253. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  7254. if (mask & reset_reg) {
  7255. BNX2X_DEV_INFO("Disable umac Rx\n");
  7256. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  7257. REG_WR(bp, base_addr + UMAC_REG_COMMAND_CONFIG, 0);
  7258. mac_stopped = true;
  7259. }
  7260. }
  7261. if (mac_stopped)
  7262. msleep(20);
  7263. }
  7264. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  7265. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  7266. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  7267. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  7268. static void __devinit bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port,
  7269. u8 inc)
  7270. {
  7271. u16 rcq, bd;
  7272. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  7273. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  7274. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  7275. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  7276. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  7277. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  7278. port, bd, rcq);
  7279. }
  7280. static int __devinit bnx2x_prev_mcp_done(struct bnx2x *bp)
  7281. {
  7282. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7283. if (!rc) {
  7284. BNX2X_ERR("MCP response failure, aborting\n");
  7285. return -EBUSY;
  7286. }
  7287. return 0;
  7288. }
  7289. static bool __devinit bnx2x_prev_is_path_marked(struct bnx2x *bp)
  7290. {
  7291. struct bnx2x_prev_path_list *tmp_list;
  7292. int rc = false;
  7293. if (down_trylock(&bnx2x_prev_sem))
  7294. return false;
  7295. list_for_each_entry(tmp_list, &bnx2x_prev_list, list) {
  7296. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  7297. bp->pdev->bus->number == tmp_list->bus &&
  7298. BP_PATH(bp) == tmp_list->path) {
  7299. rc = true;
  7300. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  7301. BP_PATH(bp));
  7302. break;
  7303. }
  7304. }
  7305. up(&bnx2x_prev_sem);
  7306. return rc;
  7307. }
  7308. static int __devinit bnx2x_prev_mark_path(struct bnx2x *bp)
  7309. {
  7310. struct bnx2x_prev_path_list *tmp_list;
  7311. int rc;
  7312. tmp_list = (struct bnx2x_prev_path_list *)
  7313. kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  7314. if (!tmp_list) {
  7315. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  7316. return -ENOMEM;
  7317. }
  7318. tmp_list->bus = bp->pdev->bus->number;
  7319. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  7320. tmp_list->path = BP_PATH(bp);
  7321. rc = down_interruptible(&bnx2x_prev_sem);
  7322. if (rc) {
  7323. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  7324. kfree(tmp_list);
  7325. } else {
  7326. BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
  7327. BP_PATH(bp));
  7328. list_add(&tmp_list->list, &bnx2x_prev_list);
  7329. up(&bnx2x_prev_sem);
  7330. }
  7331. return rc;
  7332. }
  7333. static bool __devinit bnx2x_can_flr(struct bnx2x *bp)
  7334. {
  7335. int pos;
  7336. u32 cap;
  7337. struct pci_dev *dev = bp->pdev;
  7338. pos = pci_pcie_cap(dev);
  7339. if (!pos)
  7340. return false;
  7341. pci_read_config_dword(dev, pos + PCI_EXP_DEVCAP, &cap);
  7342. if (!(cap & PCI_EXP_DEVCAP_FLR))
  7343. return false;
  7344. return true;
  7345. }
  7346. static int __devinit bnx2x_do_flr(struct bnx2x *bp)
  7347. {
  7348. int i, pos;
  7349. u16 status;
  7350. struct pci_dev *dev = bp->pdev;
  7351. /* probe the capability first */
  7352. if (bnx2x_can_flr(bp))
  7353. return -ENOTTY;
  7354. pos = pci_pcie_cap(dev);
  7355. if (!pos)
  7356. return -ENOTTY;
  7357. /* Wait for Transaction Pending bit clean */
  7358. for (i = 0; i < 4; i++) {
  7359. if (i)
  7360. msleep((1 << (i - 1)) * 100);
  7361. pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status);
  7362. if (!(status & PCI_EXP_DEVSTA_TRPND))
  7363. goto clear;
  7364. }
  7365. dev_err(&dev->dev,
  7366. "transaction is not cleared; proceeding with reset anyway\n");
  7367. clear:
  7368. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  7369. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  7370. bp->common.bc_ver);
  7371. return -EINVAL;
  7372. }
  7373. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  7374. return 0;
  7375. }
  7376. static int __devinit bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  7377. {
  7378. int rc;
  7379. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  7380. /* Test if previous unload process was already finished for this path */
  7381. if (bnx2x_prev_is_path_marked(bp))
  7382. return bnx2x_prev_mcp_done(bp);
  7383. /* If function has FLR capabilities, and existing FW version matches
  7384. * the one required, then FLR will be sufficient to clean any residue
  7385. * left by previous driver
  7386. */
  7387. if (bnx2x_test_firmware_version(bp, false) && bnx2x_can_flr(bp))
  7388. return bnx2x_do_flr(bp);
  7389. /* Close the MCP request, return failure*/
  7390. rc = bnx2x_prev_mcp_done(bp);
  7391. if (!rc)
  7392. rc = BNX2X_PREV_WAIT_NEEDED;
  7393. return rc;
  7394. }
  7395. static int __devinit bnx2x_prev_unload_common(struct bnx2x *bp)
  7396. {
  7397. u32 reset_reg, tmp_reg = 0, rc;
  7398. /* It is possible a previous function received 'common' answer,
  7399. * but hasn't loaded yet, therefore creating a scenario of
  7400. * multiple functions receiving 'common' on the same path.
  7401. */
  7402. BNX2X_DEV_INFO("Common unload Flow\n");
  7403. if (bnx2x_prev_is_path_marked(bp))
  7404. return bnx2x_prev_mcp_done(bp);
  7405. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  7406. /* Reset should be performed after BRB is emptied */
  7407. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  7408. u32 timer_count = 1000;
  7409. bool prev_undi = false;
  7410. /* Close the MAC Rx to prevent BRB from filling up */
  7411. bnx2x_prev_unload_close_mac(bp);
  7412. /* Check if the UNDI driver was previously loaded
  7413. * UNDI driver initializes CID offset for normal bell to 0x7
  7414. */
  7415. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  7416. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
  7417. tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  7418. if (tmp_reg == 0x7) {
  7419. BNX2X_DEV_INFO("UNDI previously loaded\n");
  7420. prev_undi = true;
  7421. /* clear the UNDI indication */
  7422. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  7423. }
  7424. }
  7425. /* wait until BRB is empty */
  7426. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  7427. while (timer_count) {
  7428. u32 prev_brb = tmp_reg;
  7429. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  7430. if (!tmp_reg)
  7431. break;
  7432. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  7433. /* reset timer as long as BRB actually gets emptied */
  7434. if (prev_brb > tmp_reg)
  7435. timer_count = 1000;
  7436. else
  7437. timer_count--;
  7438. /* If UNDI resides in memory, manually increment it */
  7439. if (prev_undi)
  7440. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  7441. udelay(10);
  7442. }
  7443. if (!timer_count)
  7444. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  7445. }
  7446. /* No packets are in the pipeline, path is ready for reset */
  7447. bnx2x_reset_common(bp);
  7448. rc = bnx2x_prev_mark_path(bp);
  7449. if (rc) {
  7450. bnx2x_prev_mcp_done(bp);
  7451. return rc;
  7452. }
  7453. return bnx2x_prev_mcp_done(bp);
  7454. }
  7455. static int __devinit bnx2x_prev_unload(struct bnx2x *bp)
  7456. {
  7457. int time_counter = 10;
  7458. u32 rc, fw, hw_lock_reg, hw_lock_val;
  7459. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  7460. /* Release previously held locks */
  7461. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  7462. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  7463. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  7464. hw_lock_val = (REG_RD(bp, hw_lock_reg));
  7465. if (hw_lock_val) {
  7466. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  7467. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  7468. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  7469. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  7470. }
  7471. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  7472. REG_WR(bp, hw_lock_reg, 0xffffffff);
  7473. } else
  7474. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  7475. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  7476. BNX2X_DEV_INFO("Release previously held alr\n");
  7477. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  7478. }
  7479. do {
  7480. /* Lock MCP using an unload request */
  7481. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  7482. if (!fw) {
  7483. BNX2X_ERR("MCP response failure, aborting\n");
  7484. rc = -EBUSY;
  7485. break;
  7486. }
  7487. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
  7488. rc = bnx2x_prev_unload_common(bp);
  7489. break;
  7490. }
  7491. /* non-common reply from MCP night require looping */
  7492. rc = bnx2x_prev_unload_uncommon(bp);
  7493. if (rc != BNX2X_PREV_WAIT_NEEDED)
  7494. break;
  7495. msleep(20);
  7496. } while (--time_counter);
  7497. if (!time_counter || rc) {
  7498. BNX2X_ERR("Failed unloading previous driver, aborting\n");
  7499. rc = -EBUSY;
  7500. }
  7501. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  7502. return rc;
  7503. }
  7504. static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
  7505. {
  7506. u32 val, val2, val3, val4, id, boot_mode;
  7507. u16 pmc;
  7508. /* Get the chip revision id and number. */
  7509. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  7510. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  7511. id = ((val & 0xffff) << 16);
  7512. val = REG_RD(bp, MISC_REG_CHIP_REV);
  7513. id |= ((val & 0xf) << 12);
  7514. val = REG_RD(bp, MISC_REG_CHIP_METAL);
  7515. id |= ((val & 0xff) << 4);
  7516. val = REG_RD(bp, MISC_REG_BOND_ID);
  7517. id |= (val & 0xf);
  7518. bp->common.chip_id = id;
  7519. /* force 57811 according to MISC register */
  7520. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  7521. if (CHIP_IS_57810(bp))
  7522. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  7523. (bp->common.chip_id & 0x0000FFFF);
  7524. else if (CHIP_IS_57810_MF(bp))
  7525. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  7526. (bp->common.chip_id & 0x0000FFFF);
  7527. bp->common.chip_id |= 0x1;
  7528. }
  7529. /* Set doorbell size */
  7530. bp->db_size = (1 << BNX2X_DB_SHIFT);
  7531. if (!CHIP_IS_E1x(bp)) {
  7532. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  7533. if ((val & 1) == 0)
  7534. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  7535. else
  7536. val = (val >> 1) & 1;
  7537. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  7538. "2_PORT_MODE");
  7539. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  7540. CHIP_2_PORT_MODE;
  7541. if (CHIP_MODE_IS_4_PORT(bp))
  7542. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  7543. else
  7544. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  7545. } else {
  7546. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  7547. bp->pfid = bp->pf_num; /* 0..7 */
  7548. }
  7549. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  7550. bp->link_params.chip_id = bp->common.chip_id;
  7551. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  7552. val = (REG_RD(bp, 0x2874) & 0x55);
  7553. if ((bp->common.chip_id & 0x1) ||
  7554. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  7555. bp->flags |= ONE_PORT_FLAG;
  7556. BNX2X_DEV_INFO("single port device\n");
  7557. }
  7558. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  7559. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  7560. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  7561. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  7562. bp->common.flash_size, bp->common.flash_size);
  7563. bnx2x_init_shmem(bp);
  7564. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  7565. MISC_REG_GENERIC_CR_1 :
  7566. MISC_REG_GENERIC_CR_0));
  7567. bp->link_params.shmem_base = bp->common.shmem_base;
  7568. bp->link_params.shmem2_base = bp->common.shmem2_base;
  7569. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  7570. bp->common.shmem_base, bp->common.shmem2_base);
  7571. if (!bp->common.shmem_base) {
  7572. BNX2X_DEV_INFO("MCP not active\n");
  7573. bp->flags |= NO_MCP_FLAG;
  7574. return;
  7575. }
  7576. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  7577. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  7578. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  7579. SHARED_HW_CFG_LED_MODE_MASK) >>
  7580. SHARED_HW_CFG_LED_MODE_SHIFT);
  7581. bp->link_params.feature_config_flags = 0;
  7582. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  7583. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  7584. bp->link_params.feature_config_flags |=
  7585. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  7586. else
  7587. bp->link_params.feature_config_flags &=
  7588. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  7589. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  7590. bp->common.bc_ver = val;
  7591. BNX2X_DEV_INFO("bc_ver %X\n", val);
  7592. if (val < BNX2X_BC_VER) {
  7593. /* for now only warn
  7594. * later we might need to enforce this */
  7595. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  7596. BNX2X_BC_VER, val);
  7597. }
  7598. bp->link_params.feature_config_flags |=
  7599. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  7600. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  7601. bp->link_params.feature_config_flags |=
  7602. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  7603. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  7604. bp->link_params.feature_config_flags |=
  7605. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  7606. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  7607. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  7608. BC_SUPPORTS_PFC_STATS : 0;
  7609. boot_mode = SHMEM_RD(bp,
  7610. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  7611. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  7612. switch (boot_mode) {
  7613. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  7614. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  7615. break;
  7616. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  7617. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  7618. break;
  7619. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  7620. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  7621. break;
  7622. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  7623. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  7624. break;
  7625. }
  7626. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  7627. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  7628. BNX2X_DEV_INFO("%sWoL capable\n",
  7629. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  7630. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  7631. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  7632. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  7633. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  7634. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  7635. val, val2, val3, val4);
  7636. }
  7637. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  7638. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  7639. static void __devinit bnx2x_get_igu_cam_info(struct bnx2x *bp)
  7640. {
  7641. int pfid = BP_FUNC(bp);
  7642. int igu_sb_id;
  7643. u32 val;
  7644. u8 fid, igu_sb_cnt = 0;
  7645. bp->igu_base_sb = 0xff;
  7646. if (CHIP_INT_MODE_IS_BC(bp)) {
  7647. int vn = BP_VN(bp);
  7648. igu_sb_cnt = bp->igu_sb_cnt;
  7649. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  7650. FP_SB_MAX_E1x;
  7651. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  7652. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  7653. return;
  7654. }
  7655. /* IGU in normal mode - read CAM */
  7656. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  7657. igu_sb_id++) {
  7658. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  7659. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  7660. continue;
  7661. fid = IGU_FID(val);
  7662. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  7663. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  7664. continue;
  7665. if (IGU_VEC(val) == 0)
  7666. /* default status block */
  7667. bp->igu_dsb_id = igu_sb_id;
  7668. else {
  7669. if (bp->igu_base_sb == 0xff)
  7670. bp->igu_base_sb = igu_sb_id;
  7671. igu_sb_cnt++;
  7672. }
  7673. }
  7674. }
  7675. #ifdef CONFIG_PCI_MSI
  7676. /*
  7677. * It's expected that number of CAM entries for this functions is equal
  7678. * to the number evaluated based on the MSI-X table size. We want a
  7679. * harsh warning if these values are different!
  7680. */
  7681. WARN_ON(bp->igu_sb_cnt != igu_sb_cnt);
  7682. #endif
  7683. if (igu_sb_cnt == 0)
  7684. BNX2X_ERR("CAM configuration error\n");
  7685. }
  7686. static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
  7687. u32 switch_cfg)
  7688. {
  7689. int cfg_size = 0, idx, port = BP_PORT(bp);
  7690. /* Aggregation of supported attributes of all external phys */
  7691. bp->port.supported[0] = 0;
  7692. bp->port.supported[1] = 0;
  7693. switch (bp->link_params.num_phys) {
  7694. case 1:
  7695. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  7696. cfg_size = 1;
  7697. break;
  7698. case 2:
  7699. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  7700. cfg_size = 1;
  7701. break;
  7702. case 3:
  7703. if (bp->link_params.multi_phy_config &
  7704. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  7705. bp->port.supported[1] =
  7706. bp->link_params.phy[EXT_PHY1].supported;
  7707. bp->port.supported[0] =
  7708. bp->link_params.phy[EXT_PHY2].supported;
  7709. } else {
  7710. bp->port.supported[0] =
  7711. bp->link_params.phy[EXT_PHY1].supported;
  7712. bp->port.supported[1] =
  7713. bp->link_params.phy[EXT_PHY2].supported;
  7714. }
  7715. cfg_size = 2;
  7716. break;
  7717. }
  7718. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  7719. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  7720. SHMEM_RD(bp,
  7721. dev_info.port_hw_config[port].external_phy_config),
  7722. SHMEM_RD(bp,
  7723. dev_info.port_hw_config[port].external_phy_config2));
  7724. return;
  7725. }
  7726. if (CHIP_IS_E3(bp))
  7727. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  7728. else {
  7729. switch (switch_cfg) {
  7730. case SWITCH_CFG_1G:
  7731. bp->port.phy_addr = REG_RD(
  7732. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  7733. break;
  7734. case SWITCH_CFG_10G:
  7735. bp->port.phy_addr = REG_RD(
  7736. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  7737. break;
  7738. default:
  7739. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  7740. bp->port.link_config[0]);
  7741. return;
  7742. }
  7743. }
  7744. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  7745. /* mask what we support according to speed_cap_mask per configuration */
  7746. for (idx = 0; idx < cfg_size; idx++) {
  7747. if (!(bp->link_params.speed_cap_mask[idx] &
  7748. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  7749. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  7750. if (!(bp->link_params.speed_cap_mask[idx] &
  7751. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  7752. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  7753. if (!(bp->link_params.speed_cap_mask[idx] &
  7754. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  7755. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  7756. if (!(bp->link_params.speed_cap_mask[idx] &
  7757. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  7758. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  7759. if (!(bp->link_params.speed_cap_mask[idx] &
  7760. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  7761. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  7762. SUPPORTED_1000baseT_Full);
  7763. if (!(bp->link_params.speed_cap_mask[idx] &
  7764. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  7765. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  7766. if (!(bp->link_params.speed_cap_mask[idx] &
  7767. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  7768. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  7769. }
  7770. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  7771. bp->port.supported[1]);
  7772. }
  7773. static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
  7774. {
  7775. u32 link_config, idx, cfg_size = 0;
  7776. bp->port.advertising[0] = 0;
  7777. bp->port.advertising[1] = 0;
  7778. switch (bp->link_params.num_phys) {
  7779. case 1:
  7780. case 2:
  7781. cfg_size = 1;
  7782. break;
  7783. case 3:
  7784. cfg_size = 2;
  7785. break;
  7786. }
  7787. for (idx = 0; idx < cfg_size; idx++) {
  7788. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  7789. link_config = bp->port.link_config[idx];
  7790. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  7791. case PORT_FEATURE_LINK_SPEED_AUTO:
  7792. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  7793. bp->link_params.req_line_speed[idx] =
  7794. SPEED_AUTO_NEG;
  7795. bp->port.advertising[idx] |=
  7796. bp->port.supported[idx];
  7797. if (bp->link_params.phy[EXT_PHY1].type ==
  7798. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  7799. bp->port.advertising[idx] |=
  7800. (SUPPORTED_100baseT_Half |
  7801. SUPPORTED_100baseT_Full);
  7802. } else {
  7803. /* force 10G, no AN */
  7804. bp->link_params.req_line_speed[idx] =
  7805. SPEED_10000;
  7806. bp->port.advertising[idx] |=
  7807. (ADVERTISED_10000baseT_Full |
  7808. ADVERTISED_FIBRE);
  7809. continue;
  7810. }
  7811. break;
  7812. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  7813. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  7814. bp->link_params.req_line_speed[idx] =
  7815. SPEED_10;
  7816. bp->port.advertising[idx] |=
  7817. (ADVERTISED_10baseT_Full |
  7818. ADVERTISED_TP);
  7819. } else {
  7820. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  7821. link_config,
  7822. bp->link_params.speed_cap_mask[idx]);
  7823. return;
  7824. }
  7825. break;
  7826. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  7827. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  7828. bp->link_params.req_line_speed[idx] =
  7829. SPEED_10;
  7830. bp->link_params.req_duplex[idx] =
  7831. DUPLEX_HALF;
  7832. bp->port.advertising[idx] |=
  7833. (ADVERTISED_10baseT_Half |
  7834. ADVERTISED_TP);
  7835. } else {
  7836. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  7837. link_config,
  7838. bp->link_params.speed_cap_mask[idx]);
  7839. return;
  7840. }
  7841. break;
  7842. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  7843. if (bp->port.supported[idx] &
  7844. SUPPORTED_100baseT_Full) {
  7845. bp->link_params.req_line_speed[idx] =
  7846. SPEED_100;
  7847. bp->port.advertising[idx] |=
  7848. (ADVERTISED_100baseT_Full |
  7849. ADVERTISED_TP);
  7850. } else {
  7851. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  7852. link_config,
  7853. bp->link_params.speed_cap_mask[idx]);
  7854. return;
  7855. }
  7856. break;
  7857. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  7858. if (bp->port.supported[idx] &
  7859. SUPPORTED_100baseT_Half) {
  7860. bp->link_params.req_line_speed[idx] =
  7861. SPEED_100;
  7862. bp->link_params.req_duplex[idx] =
  7863. DUPLEX_HALF;
  7864. bp->port.advertising[idx] |=
  7865. (ADVERTISED_100baseT_Half |
  7866. ADVERTISED_TP);
  7867. } else {
  7868. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  7869. link_config,
  7870. bp->link_params.speed_cap_mask[idx]);
  7871. return;
  7872. }
  7873. break;
  7874. case PORT_FEATURE_LINK_SPEED_1G:
  7875. if (bp->port.supported[idx] &
  7876. SUPPORTED_1000baseT_Full) {
  7877. bp->link_params.req_line_speed[idx] =
  7878. SPEED_1000;
  7879. bp->port.advertising[idx] |=
  7880. (ADVERTISED_1000baseT_Full |
  7881. ADVERTISED_TP);
  7882. } else {
  7883. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  7884. link_config,
  7885. bp->link_params.speed_cap_mask[idx]);
  7886. return;
  7887. }
  7888. break;
  7889. case PORT_FEATURE_LINK_SPEED_2_5G:
  7890. if (bp->port.supported[idx] &
  7891. SUPPORTED_2500baseX_Full) {
  7892. bp->link_params.req_line_speed[idx] =
  7893. SPEED_2500;
  7894. bp->port.advertising[idx] |=
  7895. (ADVERTISED_2500baseX_Full |
  7896. ADVERTISED_TP);
  7897. } else {
  7898. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  7899. link_config,
  7900. bp->link_params.speed_cap_mask[idx]);
  7901. return;
  7902. }
  7903. break;
  7904. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  7905. if (bp->port.supported[idx] &
  7906. SUPPORTED_10000baseT_Full) {
  7907. bp->link_params.req_line_speed[idx] =
  7908. SPEED_10000;
  7909. bp->port.advertising[idx] |=
  7910. (ADVERTISED_10000baseT_Full |
  7911. ADVERTISED_FIBRE);
  7912. } else {
  7913. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  7914. link_config,
  7915. bp->link_params.speed_cap_mask[idx]);
  7916. return;
  7917. }
  7918. break;
  7919. case PORT_FEATURE_LINK_SPEED_20G:
  7920. bp->link_params.req_line_speed[idx] = SPEED_20000;
  7921. break;
  7922. default:
  7923. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  7924. link_config);
  7925. bp->link_params.req_line_speed[idx] =
  7926. SPEED_AUTO_NEG;
  7927. bp->port.advertising[idx] =
  7928. bp->port.supported[idx];
  7929. break;
  7930. }
  7931. bp->link_params.req_flow_ctrl[idx] = (link_config &
  7932. PORT_FEATURE_FLOW_CONTROL_MASK);
  7933. if ((bp->link_params.req_flow_ctrl[idx] ==
  7934. BNX2X_FLOW_CTRL_AUTO) &&
  7935. !(bp->port.supported[idx] & SUPPORTED_Autoneg)) {
  7936. bp->link_params.req_flow_ctrl[idx] =
  7937. BNX2X_FLOW_CTRL_NONE;
  7938. }
  7939. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  7940. bp->link_params.req_line_speed[idx],
  7941. bp->link_params.req_duplex[idx],
  7942. bp->link_params.req_flow_ctrl[idx],
  7943. bp->port.advertising[idx]);
  7944. }
  7945. }
  7946. static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  7947. {
  7948. mac_hi = cpu_to_be16(mac_hi);
  7949. mac_lo = cpu_to_be32(mac_lo);
  7950. memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
  7951. memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
  7952. }
  7953. static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
  7954. {
  7955. int port = BP_PORT(bp);
  7956. u32 config;
  7957. u32 ext_phy_type, ext_phy_config;
  7958. bp->link_params.bp = bp;
  7959. bp->link_params.port = port;
  7960. bp->link_params.lane_config =
  7961. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  7962. bp->link_params.speed_cap_mask[0] =
  7963. SHMEM_RD(bp,
  7964. dev_info.port_hw_config[port].speed_capability_mask);
  7965. bp->link_params.speed_cap_mask[1] =
  7966. SHMEM_RD(bp,
  7967. dev_info.port_hw_config[port].speed_capability_mask2);
  7968. bp->port.link_config[0] =
  7969. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  7970. bp->port.link_config[1] =
  7971. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  7972. bp->link_params.multi_phy_config =
  7973. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  7974. /* If the device is capable of WoL, set the default state according
  7975. * to the HW
  7976. */
  7977. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  7978. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  7979. (config & PORT_FEATURE_WOL_ENABLED));
  7980. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  7981. bp->link_params.lane_config,
  7982. bp->link_params.speed_cap_mask[0],
  7983. bp->port.link_config[0]);
  7984. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  7985. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  7986. bnx2x_phy_probe(&bp->link_params);
  7987. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  7988. bnx2x_link_settings_requested(bp);
  7989. /*
  7990. * If connected directly, work with the internal PHY, otherwise, work
  7991. * with the external PHY
  7992. */
  7993. ext_phy_config =
  7994. SHMEM_RD(bp,
  7995. dev_info.port_hw_config[port].external_phy_config);
  7996. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  7997. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  7998. bp->mdio.prtad = bp->port.phy_addr;
  7999. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  8000. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  8001. bp->mdio.prtad =
  8002. XGXS_EXT_PHY_ADDR(ext_phy_config);
  8003. /*
  8004. * Check if hw lock is required to access MDC/MDIO bus to the PHY(s)
  8005. * In MF mode, it is set to cover self test cases
  8006. */
  8007. if (IS_MF(bp))
  8008. bp->port.need_hw_lock = 1;
  8009. else
  8010. bp->port.need_hw_lock = bnx2x_hw_lock_required(bp,
  8011. bp->common.shmem_base,
  8012. bp->common.shmem2_base);
  8013. }
  8014. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  8015. {
  8016. u32 no_flags = NO_ISCSI_FLAG;
  8017. #ifdef BCM_CNIC
  8018. int port = BP_PORT(bp);
  8019. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8020. drv_lic_key[port].max_iscsi_conn);
  8021. /* Get the number of maximum allowed iSCSI connections */
  8022. bp->cnic_eth_dev.max_iscsi_conn =
  8023. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  8024. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  8025. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  8026. bp->cnic_eth_dev.max_iscsi_conn);
  8027. /*
  8028. * If maximum allowed number of connections is zero -
  8029. * disable the feature.
  8030. */
  8031. if (!bp->cnic_eth_dev.max_iscsi_conn)
  8032. bp->flags |= no_flags;
  8033. #else
  8034. bp->flags |= no_flags;
  8035. #endif
  8036. }
  8037. #ifdef BCM_CNIC
  8038. static void __devinit bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  8039. {
  8040. /* Port info */
  8041. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8042. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  8043. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8044. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  8045. /* Node info */
  8046. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8047. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  8048. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8049. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  8050. }
  8051. #endif
  8052. static void __devinit bnx2x_get_fcoe_info(struct bnx2x *bp)
  8053. {
  8054. #ifdef BCM_CNIC
  8055. int port = BP_PORT(bp);
  8056. int func = BP_ABS_FUNC(bp);
  8057. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8058. drv_lic_key[port].max_fcoe_conn);
  8059. /* Get the number of maximum allowed FCoE connections */
  8060. bp->cnic_eth_dev.max_fcoe_conn =
  8061. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  8062. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  8063. /* Read the WWN: */
  8064. if (!IS_MF(bp)) {
  8065. /* Port info */
  8066. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8067. SHMEM_RD(bp,
  8068. dev_info.port_hw_config[port].
  8069. fcoe_wwn_port_name_upper);
  8070. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8071. SHMEM_RD(bp,
  8072. dev_info.port_hw_config[port].
  8073. fcoe_wwn_port_name_lower);
  8074. /* Node info */
  8075. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8076. SHMEM_RD(bp,
  8077. dev_info.port_hw_config[port].
  8078. fcoe_wwn_node_name_upper);
  8079. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8080. SHMEM_RD(bp,
  8081. dev_info.port_hw_config[port].
  8082. fcoe_wwn_node_name_lower);
  8083. } else if (!IS_MF_SD(bp)) {
  8084. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  8085. /*
  8086. * Read the WWN info only if the FCoE feature is enabled for
  8087. * this function.
  8088. */
  8089. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD)
  8090. bnx2x_get_ext_wwn_info(bp, func);
  8091. } else if (IS_MF_FCOE_SD(bp))
  8092. bnx2x_get_ext_wwn_info(bp, func);
  8093. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  8094. /*
  8095. * If maximum allowed number of connections is zero -
  8096. * disable the feature.
  8097. */
  8098. if (!bp->cnic_eth_dev.max_fcoe_conn)
  8099. bp->flags |= NO_FCOE_FLAG;
  8100. #else
  8101. bp->flags |= NO_FCOE_FLAG;
  8102. #endif
  8103. }
  8104. static void __devinit bnx2x_get_cnic_info(struct bnx2x *bp)
  8105. {
  8106. /*
  8107. * iSCSI may be dynamically disabled but reading
  8108. * info here we will decrease memory usage by driver
  8109. * if the feature is disabled for good
  8110. */
  8111. bnx2x_get_iscsi_info(bp);
  8112. bnx2x_get_fcoe_info(bp);
  8113. }
  8114. static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  8115. {
  8116. u32 val, val2;
  8117. int func = BP_ABS_FUNC(bp);
  8118. int port = BP_PORT(bp);
  8119. #ifdef BCM_CNIC
  8120. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  8121. u8 *fip_mac = bp->fip_mac;
  8122. #endif
  8123. /* Zero primary MAC configuration */
  8124. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  8125. if (BP_NOMCP(bp)) {
  8126. BNX2X_ERROR("warning: random MAC workaround active\n");
  8127. eth_hw_addr_random(bp->dev);
  8128. } else if (IS_MF(bp)) {
  8129. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  8130. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  8131. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  8132. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  8133. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  8134. #ifdef BCM_CNIC
  8135. /*
  8136. * iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  8137. * FCoE MAC then the appropriate feature should be disabled.
  8138. *
  8139. * In non SD mode features configuration comes from
  8140. * struct func_ext_config.
  8141. */
  8142. if (!IS_MF_SD(bp)) {
  8143. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  8144. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  8145. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8146. iscsi_mac_addr_upper);
  8147. val = MF_CFG_RD(bp, func_ext_config[func].
  8148. iscsi_mac_addr_lower);
  8149. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  8150. BNX2X_DEV_INFO("Read iSCSI MAC: %pM\n",
  8151. iscsi_mac);
  8152. } else
  8153. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  8154. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  8155. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8156. fcoe_mac_addr_upper);
  8157. val = MF_CFG_RD(bp, func_ext_config[func].
  8158. fcoe_mac_addr_lower);
  8159. bnx2x_set_mac_buf(fip_mac, val, val2);
  8160. BNX2X_DEV_INFO("Read FCoE L2 MAC: %pM\n",
  8161. fip_mac);
  8162. } else
  8163. bp->flags |= NO_FCOE_FLAG;
  8164. } else { /* SD MODE */
  8165. if (IS_MF_STORAGE_SD(bp)) {
  8166. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  8167. /* use primary mac as iscsi mac */
  8168. memcpy(iscsi_mac, bp->dev->dev_addr,
  8169. ETH_ALEN);
  8170. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  8171. BNX2X_DEV_INFO("Read iSCSI MAC: %pM\n",
  8172. iscsi_mac);
  8173. } else { /* FCoE */
  8174. memcpy(fip_mac, bp->dev->dev_addr,
  8175. ETH_ALEN);
  8176. BNX2X_DEV_INFO("SD FCoE MODE\n");
  8177. BNX2X_DEV_INFO("Read FIP MAC: %pM\n",
  8178. fip_mac);
  8179. }
  8180. /* Zero primary MAC configuration */
  8181. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  8182. }
  8183. }
  8184. #endif
  8185. } else {
  8186. /* in SF read MACs from port configuration */
  8187. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  8188. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  8189. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  8190. #ifdef BCM_CNIC
  8191. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8192. iscsi_mac_upper);
  8193. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8194. iscsi_mac_lower);
  8195. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  8196. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8197. fcoe_fip_mac_upper);
  8198. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8199. fcoe_fip_mac_lower);
  8200. bnx2x_set_mac_buf(fip_mac, val, val2);
  8201. #endif
  8202. }
  8203. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  8204. memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
  8205. #ifdef BCM_CNIC
  8206. /* Disable iSCSI if MAC configuration is
  8207. * invalid.
  8208. */
  8209. if (!is_valid_ether_addr(iscsi_mac)) {
  8210. bp->flags |= NO_ISCSI_FLAG;
  8211. memset(iscsi_mac, 0, ETH_ALEN);
  8212. }
  8213. /* Disable FCoE if MAC configuration is
  8214. * invalid.
  8215. */
  8216. if (!is_valid_ether_addr(fip_mac)) {
  8217. bp->flags |= NO_FCOE_FLAG;
  8218. memset(bp->fip_mac, 0, ETH_ALEN);
  8219. }
  8220. #endif
  8221. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  8222. dev_err(&bp->pdev->dev,
  8223. "bad Ethernet MAC address configuration: %pM\n"
  8224. "change it manually before bringing up the appropriate network interface\n",
  8225. bp->dev->dev_addr);
  8226. }
  8227. static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
  8228. {
  8229. int /*abs*/func = BP_ABS_FUNC(bp);
  8230. int vn;
  8231. u32 val = 0;
  8232. int rc = 0;
  8233. bnx2x_get_common_hwinfo(bp);
  8234. /*
  8235. * initialize IGU parameters
  8236. */
  8237. if (CHIP_IS_E1x(bp)) {
  8238. bp->common.int_block = INT_BLOCK_HC;
  8239. bp->igu_dsb_id = DEF_SB_IGU_ID;
  8240. bp->igu_base_sb = 0;
  8241. } else {
  8242. bp->common.int_block = INT_BLOCK_IGU;
  8243. /* do not allow device reset during IGU info preocessing */
  8244. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  8245. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  8246. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  8247. int tout = 5000;
  8248. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  8249. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  8250. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  8251. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  8252. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  8253. tout--;
  8254. usleep_range(1000, 1000);
  8255. }
  8256. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  8257. dev_err(&bp->pdev->dev,
  8258. "FORCING Normal Mode failed!!!\n");
  8259. return -EPERM;
  8260. }
  8261. }
  8262. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  8263. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  8264. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  8265. } else
  8266. BNX2X_DEV_INFO("IGU Normal Mode\n");
  8267. bnx2x_get_igu_cam_info(bp);
  8268. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  8269. }
  8270. /*
  8271. * set base FW non-default (fast path) status block id, this value is
  8272. * used to initialize the fw_sb_id saved on the fp/queue structure to
  8273. * determine the id used by the FW.
  8274. */
  8275. if (CHIP_IS_E1x(bp))
  8276. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  8277. else /*
  8278. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  8279. * the same queue are indicated on the same IGU SB). So we prefer
  8280. * FW and IGU SBs to be the same value.
  8281. */
  8282. bp->base_fw_ndsb = bp->igu_base_sb;
  8283. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  8284. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  8285. bp->igu_sb_cnt, bp->base_fw_ndsb);
  8286. /*
  8287. * Initialize MF configuration
  8288. */
  8289. bp->mf_ov = 0;
  8290. bp->mf_mode = 0;
  8291. vn = BP_VN(bp);
  8292. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  8293. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  8294. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  8295. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  8296. if (SHMEM2_HAS(bp, mf_cfg_addr))
  8297. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  8298. else
  8299. bp->common.mf_cfg_base = bp->common.shmem_base +
  8300. offsetof(struct shmem_region, func_mb) +
  8301. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  8302. /*
  8303. * get mf configuration:
  8304. * 1. existence of MF configuration
  8305. * 2. MAC address must be legal (check only upper bytes)
  8306. * for Switch-Independent mode;
  8307. * OVLAN must be legal for Switch-Dependent mode
  8308. * 3. SF_MODE configures specific MF mode
  8309. */
  8310. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  8311. /* get mf configuration */
  8312. val = SHMEM_RD(bp,
  8313. dev_info.shared_feature_config.config);
  8314. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  8315. switch (val) {
  8316. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  8317. val = MF_CFG_RD(bp, func_mf_config[func].
  8318. mac_upper);
  8319. /* check for legal mac (upper bytes)*/
  8320. if (val != 0xffff) {
  8321. bp->mf_mode = MULTI_FUNCTION_SI;
  8322. bp->mf_config[vn] = MF_CFG_RD(bp,
  8323. func_mf_config[func].config);
  8324. } else
  8325. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  8326. break;
  8327. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  8328. /* get OV configuration */
  8329. val = MF_CFG_RD(bp,
  8330. func_mf_config[FUNC_0].e1hov_tag);
  8331. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  8332. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  8333. bp->mf_mode = MULTI_FUNCTION_SD;
  8334. bp->mf_config[vn] = MF_CFG_RD(bp,
  8335. func_mf_config[func].config);
  8336. } else
  8337. BNX2X_DEV_INFO("illegal OV for SD\n");
  8338. break;
  8339. default:
  8340. /* Unknown configuration: reset mf_config */
  8341. bp->mf_config[vn] = 0;
  8342. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  8343. }
  8344. }
  8345. BNX2X_DEV_INFO("%s function mode\n",
  8346. IS_MF(bp) ? "multi" : "single");
  8347. switch (bp->mf_mode) {
  8348. case MULTI_FUNCTION_SD:
  8349. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  8350. FUNC_MF_CFG_E1HOV_TAG_MASK;
  8351. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  8352. bp->mf_ov = val;
  8353. bp->path_has_ovlan = true;
  8354. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  8355. func, bp->mf_ov, bp->mf_ov);
  8356. } else {
  8357. dev_err(&bp->pdev->dev,
  8358. "No valid MF OV for func %d, aborting\n",
  8359. func);
  8360. return -EPERM;
  8361. }
  8362. break;
  8363. case MULTI_FUNCTION_SI:
  8364. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  8365. func);
  8366. break;
  8367. default:
  8368. if (vn) {
  8369. dev_err(&bp->pdev->dev,
  8370. "VN %d is in a single function mode, aborting\n",
  8371. vn);
  8372. return -EPERM;
  8373. }
  8374. break;
  8375. }
  8376. /* check if other port on the path needs ovlan:
  8377. * Since MF configuration is shared between ports
  8378. * Possible mixed modes are only
  8379. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  8380. */
  8381. if (CHIP_MODE_IS_4_PORT(bp) &&
  8382. !bp->path_has_ovlan &&
  8383. !IS_MF(bp) &&
  8384. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  8385. u8 other_port = !BP_PORT(bp);
  8386. u8 other_func = BP_PATH(bp) + 2*other_port;
  8387. val = MF_CFG_RD(bp,
  8388. func_mf_config[other_func].e1hov_tag);
  8389. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  8390. bp->path_has_ovlan = true;
  8391. }
  8392. }
  8393. /* adjust igu_sb_cnt to MF for E1x */
  8394. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  8395. bp->igu_sb_cnt /= E1HVN_MAX;
  8396. /* port info */
  8397. bnx2x_get_port_hwinfo(bp);
  8398. /* Get MAC addresses */
  8399. bnx2x_get_mac_hwinfo(bp);
  8400. bnx2x_get_cnic_info(bp);
  8401. return rc;
  8402. }
  8403. static void __devinit bnx2x_read_fwinfo(struct bnx2x *bp)
  8404. {
  8405. int cnt, i, block_end, rodi;
  8406. char vpd_start[BNX2X_VPD_LEN+1];
  8407. char str_id_reg[VENDOR_ID_LEN+1];
  8408. char str_id_cap[VENDOR_ID_LEN+1];
  8409. char *vpd_data;
  8410. char *vpd_extended_data = NULL;
  8411. u8 len;
  8412. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  8413. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  8414. if (cnt < BNX2X_VPD_LEN)
  8415. goto out_not_found;
  8416. /* VPD RO tag should be first tag after identifier string, hence
  8417. * we should be able to find it in first BNX2X_VPD_LEN chars
  8418. */
  8419. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  8420. PCI_VPD_LRDT_RO_DATA);
  8421. if (i < 0)
  8422. goto out_not_found;
  8423. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  8424. pci_vpd_lrdt_size(&vpd_start[i]);
  8425. i += PCI_VPD_LRDT_TAG_SIZE;
  8426. if (block_end > BNX2X_VPD_LEN) {
  8427. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  8428. if (vpd_extended_data == NULL)
  8429. goto out_not_found;
  8430. /* read rest of vpd image into vpd_extended_data */
  8431. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  8432. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  8433. block_end - BNX2X_VPD_LEN,
  8434. vpd_extended_data + BNX2X_VPD_LEN);
  8435. if (cnt < (block_end - BNX2X_VPD_LEN))
  8436. goto out_not_found;
  8437. vpd_data = vpd_extended_data;
  8438. } else
  8439. vpd_data = vpd_start;
  8440. /* now vpd_data holds full vpd content in both cases */
  8441. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  8442. PCI_VPD_RO_KEYWORD_MFR_ID);
  8443. if (rodi < 0)
  8444. goto out_not_found;
  8445. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  8446. if (len != VENDOR_ID_LEN)
  8447. goto out_not_found;
  8448. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  8449. /* vendor specific info */
  8450. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  8451. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  8452. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  8453. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  8454. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  8455. PCI_VPD_RO_KEYWORD_VENDOR0);
  8456. if (rodi >= 0) {
  8457. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  8458. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  8459. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  8460. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  8461. bp->fw_ver[len] = ' ';
  8462. }
  8463. }
  8464. kfree(vpd_extended_data);
  8465. return;
  8466. }
  8467. out_not_found:
  8468. kfree(vpd_extended_data);
  8469. return;
  8470. }
  8471. static void __devinit bnx2x_set_modes_bitmap(struct bnx2x *bp)
  8472. {
  8473. u32 flags = 0;
  8474. if (CHIP_REV_IS_FPGA(bp))
  8475. SET_FLAGS(flags, MODE_FPGA);
  8476. else if (CHIP_REV_IS_EMUL(bp))
  8477. SET_FLAGS(flags, MODE_EMUL);
  8478. else
  8479. SET_FLAGS(flags, MODE_ASIC);
  8480. if (CHIP_MODE_IS_4_PORT(bp))
  8481. SET_FLAGS(flags, MODE_PORT4);
  8482. else
  8483. SET_FLAGS(flags, MODE_PORT2);
  8484. if (CHIP_IS_E2(bp))
  8485. SET_FLAGS(flags, MODE_E2);
  8486. else if (CHIP_IS_E3(bp)) {
  8487. SET_FLAGS(flags, MODE_E3);
  8488. if (CHIP_REV(bp) == CHIP_REV_Ax)
  8489. SET_FLAGS(flags, MODE_E3_A0);
  8490. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  8491. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  8492. }
  8493. if (IS_MF(bp)) {
  8494. SET_FLAGS(flags, MODE_MF);
  8495. switch (bp->mf_mode) {
  8496. case MULTI_FUNCTION_SD:
  8497. SET_FLAGS(flags, MODE_MF_SD);
  8498. break;
  8499. case MULTI_FUNCTION_SI:
  8500. SET_FLAGS(flags, MODE_MF_SI);
  8501. break;
  8502. }
  8503. } else
  8504. SET_FLAGS(flags, MODE_SF);
  8505. #if defined(__LITTLE_ENDIAN)
  8506. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  8507. #else /*(__BIG_ENDIAN)*/
  8508. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  8509. #endif
  8510. INIT_MODE_FLAGS(bp) = flags;
  8511. }
  8512. static int __devinit bnx2x_init_bp(struct bnx2x *bp)
  8513. {
  8514. int func;
  8515. int rc;
  8516. mutex_init(&bp->port.phy_mutex);
  8517. mutex_init(&bp->fw_mb_mutex);
  8518. spin_lock_init(&bp->stats_lock);
  8519. #ifdef BCM_CNIC
  8520. mutex_init(&bp->cnic_mutex);
  8521. #endif
  8522. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  8523. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  8524. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  8525. rc = bnx2x_get_hwinfo(bp);
  8526. if (rc)
  8527. return rc;
  8528. bnx2x_set_modes_bitmap(bp);
  8529. rc = bnx2x_alloc_mem_bp(bp);
  8530. if (rc)
  8531. return rc;
  8532. bnx2x_read_fwinfo(bp);
  8533. func = BP_FUNC(bp);
  8534. /* need to reset chip if undi was active */
  8535. if (!BP_NOMCP(bp)) {
  8536. /* init fw_seq */
  8537. bp->fw_seq =
  8538. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  8539. DRV_MSG_SEQ_NUMBER_MASK;
  8540. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  8541. bnx2x_prev_unload(bp);
  8542. }
  8543. if (CHIP_REV_IS_FPGA(bp))
  8544. dev_err(&bp->pdev->dev, "FPGA detected\n");
  8545. if (BP_NOMCP(bp) && (func == 0))
  8546. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  8547. bp->multi_mode = multi_mode;
  8548. bp->disable_tpa = disable_tpa;
  8549. #ifdef BCM_CNIC
  8550. bp->disable_tpa |= IS_MF_STORAGE_SD(bp);
  8551. #endif
  8552. /* Set TPA flags */
  8553. if (bp->disable_tpa) {
  8554. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  8555. bp->dev->features &= ~NETIF_F_LRO;
  8556. } else {
  8557. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  8558. bp->dev->features |= NETIF_F_LRO;
  8559. }
  8560. if (CHIP_IS_E1(bp))
  8561. bp->dropless_fc = 0;
  8562. else
  8563. bp->dropless_fc = dropless_fc;
  8564. bp->mrrs = mrrs;
  8565. bp->tx_ring_size = MAX_TX_AVAIL;
  8566. /* make sure that the numbers are in the right granularity */
  8567. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  8568. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  8569. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  8570. init_timer(&bp->timer);
  8571. bp->timer.expires = jiffies + bp->current_interval;
  8572. bp->timer.data = (unsigned long) bp;
  8573. bp->timer.function = bnx2x_timer;
  8574. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  8575. bnx2x_dcbx_init_params(bp);
  8576. #ifdef BCM_CNIC
  8577. if (CHIP_IS_E1x(bp))
  8578. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  8579. else
  8580. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  8581. #endif
  8582. /* multiple tx priority */
  8583. if (CHIP_IS_E1x(bp))
  8584. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  8585. if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  8586. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  8587. if (CHIP_IS_E3B0(bp))
  8588. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  8589. bp->gro_check = bnx2x_need_gro_check(bp->dev->mtu);
  8590. return rc;
  8591. }
  8592. /****************************************************************************
  8593. * General service functions
  8594. ****************************************************************************/
  8595. /*
  8596. * net_device service functions
  8597. */
  8598. /* called with rtnl_lock */
  8599. static int bnx2x_open(struct net_device *dev)
  8600. {
  8601. struct bnx2x *bp = netdev_priv(dev);
  8602. bool global = false;
  8603. int other_engine = BP_PATH(bp) ? 0 : 1;
  8604. bool other_load_status, load_status;
  8605. bp->stats_init = true;
  8606. netif_carrier_off(dev);
  8607. bnx2x_set_power_state(bp, PCI_D0);
  8608. other_load_status = bnx2x_get_load_status(bp, other_engine);
  8609. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  8610. /*
  8611. * If parity had happen during the unload, then attentions
  8612. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  8613. * want the first function loaded on the current engine to
  8614. * complete the recovery.
  8615. */
  8616. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  8617. bnx2x_chk_parity_attn(bp, &global, true))
  8618. do {
  8619. /*
  8620. * If there are attentions and they are in a global
  8621. * blocks, set the GLOBAL_RESET bit regardless whether
  8622. * it will be this function that will complete the
  8623. * recovery or not.
  8624. */
  8625. if (global)
  8626. bnx2x_set_reset_global(bp);
  8627. /*
  8628. * Only the first function on the current engine should
  8629. * try to recover in open. In case of attentions in
  8630. * global blocks only the first in the chip should try
  8631. * to recover.
  8632. */
  8633. if ((!load_status &&
  8634. (!global || !other_load_status)) &&
  8635. bnx2x_trylock_leader_lock(bp) &&
  8636. !bnx2x_leader_reset(bp)) {
  8637. netdev_info(bp->dev, "Recovered in open\n");
  8638. break;
  8639. }
  8640. /* recovery has failed... */
  8641. bnx2x_set_power_state(bp, PCI_D3hot);
  8642. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  8643. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  8644. "If you still see this message after a few retries then power cycle is required.\n");
  8645. return -EAGAIN;
  8646. } while (0);
  8647. bp->recovery_state = BNX2X_RECOVERY_DONE;
  8648. return bnx2x_nic_load(bp, LOAD_OPEN);
  8649. }
  8650. /* called with rtnl_lock */
  8651. static int bnx2x_close(struct net_device *dev)
  8652. {
  8653. struct bnx2x *bp = netdev_priv(dev);
  8654. /* Unload the driver, release IRQs */
  8655. bnx2x_nic_unload(bp, UNLOAD_CLOSE);
  8656. /* Power off */
  8657. bnx2x_set_power_state(bp, PCI_D3hot);
  8658. return 0;
  8659. }
  8660. static inline int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  8661. struct bnx2x_mcast_ramrod_params *p)
  8662. {
  8663. int mc_count = netdev_mc_count(bp->dev);
  8664. struct bnx2x_mcast_list_elem *mc_mac =
  8665. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  8666. struct netdev_hw_addr *ha;
  8667. if (!mc_mac)
  8668. return -ENOMEM;
  8669. INIT_LIST_HEAD(&p->mcast_list);
  8670. netdev_for_each_mc_addr(ha, bp->dev) {
  8671. mc_mac->mac = bnx2x_mc_addr(ha);
  8672. list_add_tail(&mc_mac->link, &p->mcast_list);
  8673. mc_mac++;
  8674. }
  8675. p->mcast_list_len = mc_count;
  8676. return 0;
  8677. }
  8678. static inline void bnx2x_free_mcast_macs_list(
  8679. struct bnx2x_mcast_ramrod_params *p)
  8680. {
  8681. struct bnx2x_mcast_list_elem *mc_mac =
  8682. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  8683. link);
  8684. WARN_ON(!mc_mac);
  8685. kfree(mc_mac);
  8686. }
  8687. /**
  8688. * bnx2x_set_uc_list - configure a new unicast MACs list.
  8689. *
  8690. * @bp: driver handle
  8691. *
  8692. * We will use zero (0) as a MAC type for these MACs.
  8693. */
  8694. static inline int bnx2x_set_uc_list(struct bnx2x *bp)
  8695. {
  8696. int rc;
  8697. struct net_device *dev = bp->dev;
  8698. struct netdev_hw_addr *ha;
  8699. struct bnx2x_vlan_mac_obj *mac_obj = &bp->fp->mac_obj;
  8700. unsigned long ramrod_flags = 0;
  8701. /* First schedule a cleanup up of old configuration */
  8702. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  8703. if (rc < 0) {
  8704. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  8705. return rc;
  8706. }
  8707. netdev_for_each_uc_addr(ha, dev) {
  8708. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  8709. BNX2X_UC_LIST_MAC, &ramrod_flags);
  8710. if (rc < 0) {
  8711. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  8712. rc);
  8713. return rc;
  8714. }
  8715. }
  8716. /* Execute the pending commands */
  8717. __set_bit(RAMROD_CONT, &ramrod_flags);
  8718. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  8719. BNX2X_UC_LIST_MAC, &ramrod_flags);
  8720. }
  8721. static inline int bnx2x_set_mc_list(struct bnx2x *bp)
  8722. {
  8723. struct net_device *dev = bp->dev;
  8724. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  8725. int rc = 0;
  8726. rparam.mcast_obj = &bp->mcast_obj;
  8727. /* first, clear all configured multicast MACs */
  8728. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  8729. if (rc < 0) {
  8730. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  8731. return rc;
  8732. }
  8733. /* then, configure a new MACs list */
  8734. if (netdev_mc_count(dev)) {
  8735. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  8736. if (rc) {
  8737. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  8738. rc);
  8739. return rc;
  8740. }
  8741. /* Now add the new MACs */
  8742. rc = bnx2x_config_mcast(bp, &rparam,
  8743. BNX2X_MCAST_CMD_ADD);
  8744. if (rc < 0)
  8745. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  8746. rc);
  8747. bnx2x_free_mcast_macs_list(&rparam);
  8748. }
  8749. return rc;
  8750. }
  8751. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  8752. void bnx2x_set_rx_mode(struct net_device *dev)
  8753. {
  8754. struct bnx2x *bp = netdev_priv(dev);
  8755. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  8756. if (bp->state != BNX2X_STATE_OPEN) {
  8757. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  8758. return;
  8759. }
  8760. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  8761. if (dev->flags & IFF_PROMISC)
  8762. rx_mode = BNX2X_RX_MODE_PROMISC;
  8763. else if ((dev->flags & IFF_ALLMULTI) ||
  8764. ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
  8765. CHIP_IS_E1(bp)))
  8766. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  8767. else {
  8768. /* some multicasts */
  8769. if (bnx2x_set_mc_list(bp) < 0)
  8770. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  8771. if (bnx2x_set_uc_list(bp) < 0)
  8772. rx_mode = BNX2X_RX_MODE_PROMISC;
  8773. }
  8774. bp->rx_mode = rx_mode;
  8775. #ifdef BCM_CNIC
  8776. /* handle ISCSI SD mode */
  8777. if (IS_MF_ISCSI_SD(bp))
  8778. bp->rx_mode = BNX2X_RX_MODE_NONE;
  8779. #endif
  8780. /* Schedule the rx_mode command */
  8781. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  8782. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  8783. return;
  8784. }
  8785. bnx2x_set_storm_rx_mode(bp);
  8786. }
  8787. /* called with rtnl_lock */
  8788. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  8789. int devad, u16 addr)
  8790. {
  8791. struct bnx2x *bp = netdev_priv(netdev);
  8792. u16 value;
  8793. int rc;
  8794. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  8795. prtad, devad, addr);
  8796. /* The HW expects different devad if CL22 is used */
  8797. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  8798. bnx2x_acquire_phy_lock(bp);
  8799. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  8800. bnx2x_release_phy_lock(bp);
  8801. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  8802. if (!rc)
  8803. rc = value;
  8804. return rc;
  8805. }
  8806. /* called with rtnl_lock */
  8807. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  8808. u16 addr, u16 value)
  8809. {
  8810. struct bnx2x *bp = netdev_priv(netdev);
  8811. int rc;
  8812. DP(NETIF_MSG_LINK,
  8813. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  8814. prtad, devad, addr, value);
  8815. /* The HW expects different devad if CL22 is used */
  8816. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  8817. bnx2x_acquire_phy_lock(bp);
  8818. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  8819. bnx2x_release_phy_lock(bp);
  8820. return rc;
  8821. }
  8822. /* called with rtnl_lock */
  8823. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  8824. {
  8825. struct bnx2x *bp = netdev_priv(dev);
  8826. struct mii_ioctl_data *mdio = if_mii(ifr);
  8827. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  8828. mdio->phy_id, mdio->reg_num, mdio->val_in);
  8829. if (!netif_running(dev))
  8830. return -EAGAIN;
  8831. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  8832. }
  8833. #ifdef CONFIG_NET_POLL_CONTROLLER
  8834. static void poll_bnx2x(struct net_device *dev)
  8835. {
  8836. struct bnx2x *bp = netdev_priv(dev);
  8837. disable_irq(bp->pdev->irq);
  8838. bnx2x_interrupt(bp->pdev->irq, dev);
  8839. enable_irq(bp->pdev->irq);
  8840. }
  8841. #endif
  8842. static int bnx2x_validate_addr(struct net_device *dev)
  8843. {
  8844. struct bnx2x *bp = netdev_priv(dev);
  8845. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  8846. BNX2X_ERR("Non-valid Ethernet address\n");
  8847. return -EADDRNOTAVAIL;
  8848. }
  8849. return 0;
  8850. }
  8851. static const struct net_device_ops bnx2x_netdev_ops = {
  8852. .ndo_open = bnx2x_open,
  8853. .ndo_stop = bnx2x_close,
  8854. .ndo_start_xmit = bnx2x_start_xmit,
  8855. .ndo_select_queue = bnx2x_select_queue,
  8856. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  8857. .ndo_set_mac_address = bnx2x_change_mac_addr,
  8858. .ndo_validate_addr = bnx2x_validate_addr,
  8859. .ndo_do_ioctl = bnx2x_ioctl,
  8860. .ndo_change_mtu = bnx2x_change_mtu,
  8861. .ndo_fix_features = bnx2x_fix_features,
  8862. .ndo_set_features = bnx2x_set_features,
  8863. .ndo_tx_timeout = bnx2x_tx_timeout,
  8864. #ifdef CONFIG_NET_POLL_CONTROLLER
  8865. .ndo_poll_controller = poll_bnx2x,
  8866. #endif
  8867. .ndo_setup_tc = bnx2x_setup_tc,
  8868. #if defined(NETDEV_FCOE_WWNN) && defined(BCM_CNIC)
  8869. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  8870. #endif
  8871. };
  8872. static inline int bnx2x_set_coherency_mask(struct bnx2x *bp)
  8873. {
  8874. struct device *dev = &bp->pdev->dev;
  8875. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  8876. bp->flags |= USING_DAC_FLAG;
  8877. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  8878. dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
  8879. return -EIO;
  8880. }
  8881. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  8882. dev_err(dev, "System does not support DMA, aborting\n");
  8883. return -EIO;
  8884. }
  8885. return 0;
  8886. }
  8887. static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
  8888. struct net_device *dev,
  8889. unsigned long board_type)
  8890. {
  8891. struct bnx2x *bp;
  8892. int rc;
  8893. u32 pci_cfg_dword;
  8894. bool chip_is_e1x = (board_type == BCM57710 ||
  8895. board_type == BCM57711 ||
  8896. board_type == BCM57711E);
  8897. SET_NETDEV_DEV(dev, &pdev->dev);
  8898. bp = netdev_priv(dev);
  8899. bp->dev = dev;
  8900. bp->pdev = pdev;
  8901. bp->flags = 0;
  8902. rc = pci_enable_device(pdev);
  8903. if (rc) {
  8904. dev_err(&bp->pdev->dev,
  8905. "Cannot enable PCI device, aborting\n");
  8906. goto err_out;
  8907. }
  8908. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  8909. dev_err(&bp->pdev->dev,
  8910. "Cannot find PCI device base address, aborting\n");
  8911. rc = -ENODEV;
  8912. goto err_out_disable;
  8913. }
  8914. if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  8915. dev_err(&bp->pdev->dev, "Cannot find second PCI device"
  8916. " base address, aborting\n");
  8917. rc = -ENODEV;
  8918. goto err_out_disable;
  8919. }
  8920. if (atomic_read(&pdev->enable_cnt) == 1) {
  8921. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  8922. if (rc) {
  8923. dev_err(&bp->pdev->dev,
  8924. "Cannot obtain PCI resources, aborting\n");
  8925. goto err_out_disable;
  8926. }
  8927. pci_set_master(pdev);
  8928. pci_save_state(pdev);
  8929. }
  8930. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  8931. if (bp->pm_cap == 0) {
  8932. dev_err(&bp->pdev->dev,
  8933. "Cannot find power management capability, aborting\n");
  8934. rc = -EIO;
  8935. goto err_out_release;
  8936. }
  8937. if (!pci_is_pcie(pdev)) {
  8938. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  8939. rc = -EIO;
  8940. goto err_out_release;
  8941. }
  8942. rc = bnx2x_set_coherency_mask(bp);
  8943. if (rc)
  8944. goto err_out_release;
  8945. dev->mem_start = pci_resource_start(pdev, 0);
  8946. dev->base_addr = dev->mem_start;
  8947. dev->mem_end = pci_resource_end(pdev, 0);
  8948. dev->irq = pdev->irq;
  8949. bp->regview = pci_ioremap_bar(pdev, 0);
  8950. if (!bp->regview) {
  8951. dev_err(&bp->pdev->dev,
  8952. "Cannot map register space, aborting\n");
  8953. rc = -ENOMEM;
  8954. goto err_out_release;
  8955. }
  8956. /* In E1/E1H use pci device function given by kernel.
  8957. * In E2/E3 read physical function from ME register since these chips
  8958. * support Physical Device Assignment where kernel BDF maybe arbitrary
  8959. * (depending on hypervisor).
  8960. */
  8961. if (chip_is_e1x)
  8962. bp->pf_num = PCI_FUNC(pdev->devfn);
  8963. else {/* chip is E2/3*/
  8964. pci_read_config_dword(bp->pdev,
  8965. PCICFG_ME_REGISTER, &pci_cfg_dword);
  8966. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  8967. ME_REG_ABS_PF_NUM_SHIFT);
  8968. }
  8969. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  8970. bnx2x_set_power_state(bp, PCI_D0);
  8971. /* clean indirect addresses */
  8972. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  8973. PCICFG_VENDOR_ID_OFFSET);
  8974. /*
  8975. * Clean the following indirect addresses for all functions since it
  8976. * is not used by the driver.
  8977. */
  8978. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  8979. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  8980. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  8981. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  8982. if (chip_is_e1x) {
  8983. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  8984. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  8985. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  8986. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  8987. }
  8988. /*
  8989. * Enable internal target-read (in case we are probed after PF FLR).
  8990. * Must be done prior to any BAR read access. Only for 57712 and up
  8991. */
  8992. if (!chip_is_e1x)
  8993. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  8994. /* Reset the load counter */
  8995. bnx2x_clear_load_status(bp);
  8996. dev->watchdog_timeo = TX_TIMEOUT;
  8997. dev->netdev_ops = &bnx2x_netdev_ops;
  8998. bnx2x_set_ethtool_ops(dev);
  8999. dev->priv_flags |= IFF_UNICAST_FLT;
  9000. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9001. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  9002. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  9003. NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
  9004. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9005. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  9006. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
  9007. if (bp->flags & USING_DAC_FLAG)
  9008. dev->features |= NETIF_F_HIGHDMA;
  9009. /* Add Loopback capability to the device */
  9010. dev->hw_features |= NETIF_F_LOOPBACK;
  9011. #ifdef BCM_DCBNL
  9012. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  9013. #endif
  9014. /* get_port_hwinfo() will set prtad and mmds properly */
  9015. bp->mdio.prtad = MDIO_PRTAD_NONE;
  9016. bp->mdio.mmds = 0;
  9017. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  9018. bp->mdio.dev = dev;
  9019. bp->mdio.mdio_read = bnx2x_mdio_read;
  9020. bp->mdio.mdio_write = bnx2x_mdio_write;
  9021. return 0;
  9022. err_out_release:
  9023. if (atomic_read(&pdev->enable_cnt) == 1)
  9024. pci_release_regions(pdev);
  9025. err_out_disable:
  9026. pci_disable_device(pdev);
  9027. pci_set_drvdata(pdev, NULL);
  9028. err_out:
  9029. return rc;
  9030. }
  9031. static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp,
  9032. int *width, int *speed)
  9033. {
  9034. u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
  9035. *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  9036. /* return value of 1=2.5GHz 2=5GHz */
  9037. *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  9038. }
  9039. static int bnx2x_check_firmware(struct bnx2x *bp)
  9040. {
  9041. const struct firmware *firmware = bp->firmware;
  9042. struct bnx2x_fw_file_hdr *fw_hdr;
  9043. struct bnx2x_fw_file_section *sections;
  9044. u32 offset, len, num_ops;
  9045. u16 *ops_offsets;
  9046. int i;
  9047. const u8 *fw_ver;
  9048. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  9049. BNX2X_ERR("Wrong FW size\n");
  9050. return -EINVAL;
  9051. }
  9052. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  9053. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  9054. /* Make sure none of the offsets and sizes make us read beyond
  9055. * the end of the firmware data */
  9056. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  9057. offset = be32_to_cpu(sections[i].offset);
  9058. len = be32_to_cpu(sections[i].len);
  9059. if (offset + len > firmware->size) {
  9060. BNX2X_ERR("Section %d length is out of bounds\n", i);
  9061. return -EINVAL;
  9062. }
  9063. }
  9064. /* Likewise for the init_ops offsets */
  9065. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  9066. ops_offsets = (u16 *)(firmware->data + offset);
  9067. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  9068. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  9069. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  9070. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  9071. return -EINVAL;
  9072. }
  9073. }
  9074. /* Check FW version */
  9075. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  9076. fw_ver = firmware->data + offset;
  9077. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  9078. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  9079. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  9080. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  9081. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  9082. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  9083. BCM_5710_FW_MAJOR_VERSION,
  9084. BCM_5710_FW_MINOR_VERSION,
  9085. BCM_5710_FW_REVISION_VERSION,
  9086. BCM_5710_FW_ENGINEERING_VERSION);
  9087. return -EINVAL;
  9088. }
  9089. return 0;
  9090. }
  9091. static inline void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  9092. {
  9093. const __be32 *source = (const __be32 *)_source;
  9094. u32 *target = (u32 *)_target;
  9095. u32 i;
  9096. for (i = 0; i < n/4; i++)
  9097. target[i] = be32_to_cpu(source[i]);
  9098. }
  9099. /*
  9100. Ops array is stored in the following format:
  9101. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  9102. */
  9103. static inline void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  9104. {
  9105. const __be32 *source = (const __be32 *)_source;
  9106. struct raw_op *target = (struct raw_op *)_target;
  9107. u32 i, j, tmp;
  9108. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  9109. tmp = be32_to_cpu(source[j]);
  9110. target[i].op = (tmp >> 24) & 0xff;
  9111. target[i].offset = tmp & 0xffffff;
  9112. target[i].raw_data = be32_to_cpu(source[j + 1]);
  9113. }
  9114. }
  9115. /**
  9116. * IRO array is stored in the following format:
  9117. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  9118. */
  9119. static inline void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  9120. {
  9121. const __be32 *source = (const __be32 *)_source;
  9122. struct iro *target = (struct iro *)_target;
  9123. u32 i, j, tmp;
  9124. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  9125. target[i].base = be32_to_cpu(source[j]);
  9126. j++;
  9127. tmp = be32_to_cpu(source[j]);
  9128. target[i].m1 = (tmp >> 16) & 0xffff;
  9129. target[i].m2 = tmp & 0xffff;
  9130. j++;
  9131. tmp = be32_to_cpu(source[j]);
  9132. target[i].m3 = (tmp >> 16) & 0xffff;
  9133. target[i].size = tmp & 0xffff;
  9134. j++;
  9135. }
  9136. }
  9137. static inline void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  9138. {
  9139. const __be16 *source = (const __be16 *)_source;
  9140. u16 *target = (u16 *)_target;
  9141. u32 i;
  9142. for (i = 0; i < n/2; i++)
  9143. target[i] = be16_to_cpu(source[i]);
  9144. }
  9145. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  9146. do { \
  9147. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  9148. bp->arr = kmalloc(len, GFP_KERNEL); \
  9149. if (!bp->arr) \
  9150. goto lbl; \
  9151. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  9152. (u8 *)bp->arr, len); \
  9153. } while (0)
  9154. static int bnx2x_init_firmware(struct bnx2x *bp)
  9155. {
  9156. const char *fw_file_name;
  9157. struct bnx2x_fw_file_hdr *fw_hdr;
  9158. int rc;
  9159. if (bp->firmware)
  9160. return 0;
  9161. if (CHIP_IS_E1(bp))
  9162. fw_file_name = FW_FILE_NAME_E1;
  9163. else if (CHIP_IS_E1H(bp))
  9164. fw_file_name = FW_FILE_NAME_E1H;
  9165. else if (!CHIP_IS_E1x(bp))
  9166. fw_file_name = FW_FILE_NAME_E2;
  9167. else {
  9168. BNX2X_ERR("Unsupported chip revision\n");
  9169. return -EINVAL;
  9170. }
  9171. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  9172. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  9173. if (rc) {
  9174. BNX2X_ERR("Can't load firmware file %s\n",
  9175. fw_file_name);
  9176. goto request_firmware_exit;
  9177. }
  9178. rc = bnx2x_check_firmware(bp);
  9179. if (rc) {
  9180. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  9181. goto request_firmware_exit;
  9182. }
  9183. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  9184. /* Initialize the pointers to the init arrays */
  9185. /* Blob */
  9186. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  9187. /* Opcodes */
  9188. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  9189. /* Offsets */
  9190. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  9191. be16_to_cpu_n);
  9192. /* STORMs firmware */
  9193. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9194. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  9195. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  9196. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  9197. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9198. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  9199. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  9200. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  9201. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9202. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  9203. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  9204. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  9205. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9206. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  9207. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  9208. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  9209. /* IRO */
  9210. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  9211. return 0;
  9212. iro_alloc_err:
  9213. kfree(bp->init_ops_offsets);
  9214. init_offsets_alloc_err:
  9215. kfree(bp->init_ops);
  9216. init_ops_alloc_err:
  9217. kfree(bp->init_data);
  9218. request_firmware_exit:
  9219. release_firmware(bp->firmware);
  9220. bp->firmware = NULL;
  9221. return rc;
  9222. }
  9223. static void bnx2x_release_firmware(struct bnx2x *bp)
  9224. {
  9225. kfree(bp->init_ops_offsets);
  9226. kfree(bp->init_ops);
  9227. kfree(bp->init_data);
  9228. release_firmware(bp->firmware);
  9229. bp->firmware = NULL;
  9230. }
  9231. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  9232. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  9233. .init_hw_cmn = bnx2x_init_hw_common,
  9234. .init_hw_port = bnx2x_init_hw_port,
  9235. .init_hw_func = bnx2x_init_hw_func,
  9236. .reset_hw_cmn = bnx2x_reset_common,
  9237. .reset_hw_port = bnx2x_reset_port,
  9238. .reset_hw_func = bnx2x_reset_func,
  9239. .gunzip_init = bnx2x_gunzip_init,
  9240. .gunzip_end = bnx2x_gunzip_end,
  9241. .init_fw = bnx2x_init_firmware,
  9242. .release_fw = bnx2x_release_firmware,
  9243. };
  9244. void bnx2x__init_func_obj(struct bnx2x *bp)
  9245. {
  9246. /* Prepare DMAE related driver resources */
  9247. bnx2x_setup_dmae(bp);
  9248. bnx2x_init_func_obj(bp, &bp->func_obj,
  9249. bnx2x_sp(bp, func_rdata),
  9250. bnx2x_sp_mapping(bp, func_rdata),
  9251. &bnx2x_func_sp_drv);
  9252. }
  9253. /* must be called after sriov-enable */
  9254. static inline int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  9255. {
  9256. int cid_count = BNX2X_L2_CID_COUNT(bp);
  9257. #ifdef BCM_CNIC
  9258. cid_count += CNIC_CID_MAX;
  9259. #endif
  9260. return roundup(cid_count, QM_CID_ROUND);
  9261. }
  9262. /**
  9263. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  9264. *
  9265. * @dev: pci device
  9266. *
  9267. */
  9268. static inline int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev)
  9269. {
  9270. int pos;
  9271. u16 control;
  9272. pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  9273. /*
  9274. * If MSI-X is not supported - return number of SBs needed to support
  9275. * one fast path queue: one FP queue + SB for CNIC
  9276. */
  9277. if (!pos)
  9278. return 1 + CNIC_PRESENT;
  9279. /*
  9280. * The value in the PCI configuration space is the index of the last
  9281. * entry, namely one less than the actual size of the table, which is
  9282. * exactly what we want to return from this function: number of all SBs
  9283. * without the default SB.
  9284. */
  9285. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
  9286. return control & PCI_MSIX_FLAGS_QSIZE;
  9287. }
  9288. static int __devinit bnx2x_init_one(struct pci_dev *pdev,
  9289. const struct pci_device_id *ent)
  9290. {
  9291. struct net_device *dev = NULL;
  9292. struct bnx2x *bp;
  9293. int pcie_width, pcie_speed;
  9294. int rc, max_non_def_sbs;
  9295. int rx_count, tx_count, rss_count;
  9296. /*
  9297. * An estimated maximum supported CoS number according to the chip
  9298. * version.
  9299. * We will try to roughly estimate the maximum number of CoSes this chip
  9300. * may support in order to minimize the memory allocated for Tx
  9301. * netdev_queue's. This number will be accurately calculated during the
  9302. * initialization of bp->max_cos based on the chip versions AND chip
  9303. * revision in the bnx2x_init_bp().
  9304. */
  9305. u8 max_cos_est = 0;
  9306. switch (ent->driver_data) {
  9307. case BCM57710:
  9308. case BCM57711:
  9309. case BCM57711E:
  9310. max_cos_est = BNX2X_MULTI_TX_COS_E1X;
  9311. break;
  9312. case BCM57712:
  9313. case BCM57712_MF:
  9314. max_cos_est = BNX2X_MULTI_TX_COS_E2_E3A0;
  9315. break;
  9316. case BCM57800:
  9317. case BCM57800_MF:
  9318. case BCM57810:
  9319. case BCM57810_MF:
  9320. case BCM57840:
  9321. case BCM57840_MF:
  9322. case BCM57811:
  9323. case BCM57811_MF:
  9324. max_cos_est = BNX2X_MULTI_TX_COS_E3B0;
  9325. break;
  9326. default:
  9327. pr_err("Unknown board_type (%ld), aborting\n",
  9328. ent->driver_data);
  9329. return -ENODEV;
  9330. }
  9331. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev);
  9332. /* !!! FIXME !!!
  9333. * Do not allow the maximum SB count to grow above 16
  9334. * since Special CIDs starts from 16*BNX2X_MULTI_TX_COS=48.
  9335. * We will use the FP_SB_MAX_E1x macro for this matter.
  9336. */
  9337. max_non_def_sbs = min_t(int, FP_SB_MAX_E1x, max_non_def_sbs);
  9338. WARN_ON(!max_non_def_sbs);
  9339. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  9340. rss_count = max_non_def_sbs - CNIC_PRESENT;
  9341. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  9342. rx_count = rss_count + FCOE_PRESENT;
  9343. /*
  9344. * Maximum number of netdev Tx queues:
  9345. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  9346. */
  9347. tx_count = MAX_TXQS_PER_COS * max_cos_est + FCOE_PRESENT;
  9348. /* dev zeroed in init_etherdev */
  9349. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  9350. if (!dev)
  9351. return -ENOMEM;
  9352. bp = netdev_priv(dev);
  9353. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  9354. tx_count, rx_count);
  9355. bp->igu_sb_cnt = max_non_def_sbs;
  9356. bp->msg_enable = debug;
  9357. pci_set_drvdata(pdev, dev);
  9358. rc = bnx2x_init_dev(pdev, dev, ent->driver_data);
  9359. if (rc < 0) {
  9360. free_netdev(dev);
  9361. return rc;
  9362. }
  9363. BNX2X_DEV_INFO("max_non_def_sbs %d\n", max_non_def_sbs);
  9364. rc = bnx2x_init_bp(bp);
  9365. if (rc)
  9366. goto init_one_exit;
  9367. /*
  9368. * Map doorbels here as we need the real value of bp->max_cos which
  9369. * is initialized in bnx2x_init_bp().
  9370. */
  9371. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  9372. min_t(u64, BNX2X_DB_SIZE(bp),
  9373. pci_resource_len(pdev, 2)));
  9374. if (!bp->doorbells) {
  9375. dev_err(&bp->pdev->dev,
  9376. "Cannot map doorbell space, aborting\n");
  9377. rc = -ENOMEM;
  9378. goto init_one_exit;
  9379. }
  9380. /* calc qm_cid_count */
  9381. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  9382. #ifdef BCM_CNIC
  9383. /* disable FCOE L2 queue for E1x */
  9384. if (CHIP_IS_E1x(bp))
  9385. bp->flags |= NO_FCOE_FLAG;
  9386. #endif
  9387. /* Configure interrupt mode: try to enable MSI-X/MSI if
  9388. * needed, set bp->num_queues appropriately.
  9389. */
  9390. bnx2x_set_int_mode(bp);
  9391. /* Add all NAPI objects */
  9392. bnx2x_add_all_napi(bp);
  9393. rc = register_netdev(dev);
  9394. if (rc) {
  9395. dev_err(&pdev->dev, "Cannot register net device\n");
  9396. goto init_one_exit;
  9397. }
  9398. #ifdef BCM_CNIC
  9399. if (!NO_FCOE(bp)) {
  9400. /* Add storage MAC address */
  9401. rtnl_lock();
  9402. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  9403. rtnl_unlock();
  9404. }
  9405. #endif
  9406. bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
  9407. BNX2X_DEV_INFO(
  9408. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  9409. board_info[ent->driver_data].name,
  9410. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  9411. pcie_width,
  9412. ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
  9413. (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
  9414. "5GHz (Gen2)" : "2.5GHz",
  9415. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  9416. return 0;
  9417. init_one_exit:
  9418. if (bp->regview)
  9419. iounmap(bp->regview);
  9420. if (bp->doorbells)
  9421. iounmap(bp->doorbells);
  9422. free_netdev(dev);
  9423. if (atomic_read(&pdev->enable_cnt) == 1)
  9424. pci_release_regions(pdev);
  9425. pci_disable_device(pdev);
  9426. pci_set_drvdata(pdev, NULL);
  9427. return rc;
  9428. }
  9429. static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
  9430. {
  9431. struct net_device *dev = pci_get_drvdata(pdev);
  9432. struct bnx2x *bp;
  9433. if (!dev) {
  9434. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  9435. return;
  9436. }
  9437. bp = netdev_priv(dev);
  9438. #ifdef BCM_CNIC
  9439. /* Delete storage MAC address */
  9440. if (!NO_FCOE(bp)) {
  9441. rtnl_lock();
  9442. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  9443. rtnl_unlock();
  9444. }
  9445. #endif
  9446. #ifdef BCM_DCBNL
  9447. /* Delete app tlvs from dcbnl */
  9448. bnx2x_dcbnl_update_applist(bp, true);
  9449. #endif
  9450. unregister_netdev(dev);
  9451. /* Delete all NAPI objects */
  9452. bnx2x_del_all_napi(bp);
  9453. /* Power on: we can't let PCI layer write to us while we are in D3 */
  9454. bnx2x_set_power_state(bp, PCI_D0);
  9455. /* Disable MSI/MSI-X */
  9456. bnx2x_disable_msi(bp);
  9457. /* Power off */
  9458. bnx2x_set_power_state(bp, PCI_D3hot);
  9459. /* Make sure RESET task is not scheduled before continuing */
  9460. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  9461. if (bp->regview)
  9462. iounmap(bp->regview);
  9463. if (bp->doorbells)
  9464. iounmap(bp->doorbells);
  9465. bnx2x_release_firmware(bp);
  9466. bnx2x_free_mem_bp(bp);
  9467. free_netdev(dev);
  9468. if (atomic_read(&pdev->enable_cnt) == 1)
  9469. pci_release_regions(pdev);
  9470. pci_disable_device(pdev);
  9471. pci_set_drvdata(pdev, NULL);
  9472. }
  9473. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  9474. {
  9475. int i;
  9476. bp->state = BNX2X_STATE_ERROR;
  9477. bp->rx_mode = BNX2X_RX_MODE_NONE;
  9478. #ifdef BCM_CNIC
  9479. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  9480. #endif
  9481. /* Stop Tx */
  9482. bnx2x_tx_disable(bp);
  9483. bnx2x_netif_stop(bp, 0);
  9484. del_timer_sync(&bp->timer);
  9485. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  9486. /* Release IRQs */
  9487. bnx2x_free_irq(bp);
  9488. /* Free SKBs, SGEs, TPA pool and driver internals */
  9489. bnx2x_free_skbs(bp);
  9490. for_each_rx_queue(bp, i)
  9491. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  9492. bnx2x_free_mem(bp);
  9493. bp->state = BNX2X_STATE_CLOSED;
  9494. netif_carrier_off(bp->dev);
  9495. return 0;
  9496. }
  9497. static void bnx2x_eeh_recover(struct bnx2x *bp)
  9498. {
  9499. u32 val;
  9500. mutex_init(&bp->port.phy_mutex);
  9501. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  9502. if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  9503. != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  9504. BNX2X_ERR("BAD MCP validity signature\n");
  9505. }
  9506. /**
  9507. * bnx2x_io_error_detected - called when PCI error is detected
  9508. * @pdev: Pointer to PCI device
  9509. * @state: The current pci connection state
  9510. *
  9511. * This function is called after a PCI bus error affecting
  9512. * this device has been detected.
  9513. */
  9514. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  9515. pci_channel_state_t state)
  9516. {
  9517. struct net_device *dev = pci_get_drvdata(pdev);
  9518. struct bnx2x *bp = netdev_priv(dev);
  9519. rtnl_lock();
  9520. netif_device_detach(dev);
  9521. if (state == pci_channel_io_perm_failure) {
  9522. rtnl_unlock();
  9523. return PCI_ERS_RESULT_DISCONNECT;
  9524. }
  9525. if (netif_running(dev))
  9526. bnx2x_eeh_nic_unload(bp);
  9527. pci_disable_device(pdev);
  9528. rtnl_unlock();
  9529. /* Request a slot reset */
  9530. return PCI_ERS_RESULT_NEED_RESET;
  9531. }
  9532. /**
  9533. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  9534. * @pdev: Pointer to PCI device
  9535. *
  9536. * Restart the card from scratch, as if from a cold-boot.
  9537. */
  9538. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  9539. {
  9540. struct net_device *dev = pci_get_drvdata(pdev);
  9541. struct bnx2x *bp = netdev_priv(dev);
  9542. rtnl_lock();
  9543. if (pci_enable_device(pdev)) {
  9544. dev_err(&pdev->dev,
  9545. "Cannot re-enable PCI device after reset\n");
  9546. rtnl_unlock();
  9547. return PCI_ERS_RESULT_DISCONNECT;
  9548. }
  9549. pci_set_master(pdev);
  9550. pci_restore_state(pdev);
  9551. if (netif_running(dev))
  9552. bnx2x_set_power_state(bp, PCI_D0);
  9553. rtnl_unlock();
  9554. return PCI_ERS_RESULT_RECOVERED;
  9555. }
  9556. /**
  9557. * bnx2x_io_resume - called when traffic can start flowing again
  9558. * @pdev: Pointer to PCI device
  9559. *
  9560. * This callback is called when the error recovery driver tells us that
  9561. * its OK to resume normal operation.
  9562. */
  9563. static void bnx2x_io_resume(struct pci_dev *pdev)
  9564. {
  9565. struct net_device *dev = pci_get_drvdata(pdev);
  9566. struct bnx2x *bp = netdev_priv(dev);
  9567. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  9568. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  9569. return;
  9570. }
  9571. rtnl_lock();
  9572. bnx2x_eeh_recover(bp);
  9573. if (netif_running(dev))
  9574. bnx2x_nic_load(bp, LOAD_NORMAL);
  9575. netif_device_attach(dev);
  9576. rtnl_unlock();
  9577. }
  9578. static struct pci_error_handlers bnx2x_err_handler = {
  9579. .error_detected = bnx2x_io_error_detected,
  9580. .slot_reset = bnx2x_io_slot_reset,
  9581. .resume = bnx2x_io_resume,
  9582. };
  9583. static struct pci_driver bnx2x_pci_driver = {
  9584. .name = DRV_MODULE_NAME,
  9585. .id_table = bnx2x_pci_tbl,
  9586. .probe = bnx2x_init_one,
  9587. .remove = __devexit_p(bnx2x_remove_one),
  9588. .suspend = bnx2x_suspend,
  9589. .resume = bnx2x_resume,
  9590. .err_handler = &bnx2x_err_handler,
  9591. };
  9592. static int __init bnx2x_init(void)
  9593. {
  9594. int ret;
  9595. pr_info("%s", version);
  9596. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  9597. if (bnx2x_wq == NULL) {
  9598. pr_err("Cannot create workqueue\n");
  9599. return -ENOMEM;
  9600. }
  9601. ret = pci_register_driver(&bnx2x_pci_driver);
  9602. if (ret) {
  9603. pr_err("Cannot register driver\n");
  9604. destroy_workqueue(bnx2x_wq);
  9605. }
  9606. return ret;
  9607. }
  9608. static void __exit bnx2x_cleanup(void)
  9609. {
  9610. struct list_head *pos, *q;
  9611. pci_unregister_driver(&bnx2x_pci_driver);
  9612. destroy_workqueue(bnx2x_wq);
  9613. /* Free globablly allocated resources */
  9614. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  9615. struct bnx2x_prev_path_list *tmp =
  9616. list_entry(pos, struct bnx2x_prev_path_list, list);
  9617. list_del(pos);
  9618. kfree(tmp);
  9619. }
  9620. }
  9621. void bnx2x_notify_link_changed(struct bnx2x *bp)
  9622. {
  9623. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  9624. }
  9625. module_init(bnx2x_init);
  9626. module_exit(bnx2x_cleanup);
  9627. #ifdef BCM_CNIC
  9628. /**
  9629. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  9630. *
  9631. * @bp: driver handle
  9632. * @set: set or clear the CAM entry
  9633. *
  9634. * This function will wait until the ramdord completion returns.
  9635. * Return 0 if success, -ENODEV if ramrod doesn't return.
  9636. */
  9637. static inline int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  9638. {
  9639. unsigned long ramrod_flags = 0;
  9640. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  9641. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  9642. &bp->iscsi_l2_mac_obj, true,
  9643. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  9644. }
  9645. /* count denotes the number of new completions we have seen */
  9646. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  9647. {
  9648. struct eth_spe *spe;
  9649. #ifdef BNX2X_STOP_ON_ERROR
  9650. if (unlikely(bp->panic))
  9651. return;
  9652. #endif
  9653. spin_lock_bh(&bp->spq_lock);
  9654. BUG_ON(bp->cnic_spq_pending < count);
  9655. bp->cnic_spq_pending -= count;
  9656. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  9657. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  9658. & SPE_HDR_CONN_TYPE) >>
  9659. SPE_HDR_CONN_TYPE_SHIFT;
  9660. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  9661. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  9662. /* Set validation for iSCSI L2 client before sending SETUP
  9663. * ramrod
  9664. */
  9665. if (type == ETH_CONNECTION_TYPE) {
  9666. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP)
  9667. bnx2x_set_ctx_validation(bp, &bp->context.
  9668. vcxt[BNX2X_ISCSI_ETH_CID].eth,
  9669. BNX2X_ISCSI_ETH_CID);
  9670. }
  9671. /*
  9672. * There may be not more than 8 L2, not more than 8 L5 SPEs
  9673. * and in the air. We also check that number of outstanding
  9674. * COMMON ramrods is not more than the EQ and SPQ can
  9675. * accommodate.
  9676. */
  9677. if (type == ETH_CONNECTION_TYPE) {
  9678. if (!atomic_read(&bp->cq_spq_left))
  9679. break;
  9680. else
  9681. atomic_dec(&bp->cq_spq_left);
  9682. } else if (type == NONE_CONNECTION_TYPE) {
  9683. if (!atomic_read(&bp->eq_spq_left))
  9684. break;
  9685. else
  9686. atomic_dec(&bp->eq_spq_left);
  9687. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  9688. (type == FCOE_CONNECTION_TYPE)) {
  9689. if (bp->cnic_spq_pending >=
  9690. bp->cnic_eth_dev.max_kwqe_pending)
  9691. break;
  9692. else
  9693. bp->cnic_spq_pending++;
  9694. } else {
  9695. BNX2X_ERR("Unknown SPE type: %d\n", type);
  9696. bnx2x_panic();
  9697. break;
  9698. }
  9699. spe = bnx2x_sp_get_next(bp);
  9700. *spe = *bp->cnic_kwq_cons;
  9701. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  9702. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  9703. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  9704. bp->cnic_kwq_cons = bp->cnic_kwq;
  9705. else
  9706. bp->cnic_kwq_cons++;
  9707. }
  9708. bnx2x_sp_prod_update(bp);
  9709. spin_unlock_bh(&bp->spq_lock);
  9710. }
  9711. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  9712. struct kwqe_16 *kwqes[], u32 count)
  9713. {
  9714. struct bnx2x *bp = netdev_priv(dev);
  9715. int i;
  9716. #ifdef BNX2X_STOP_ON_ERROR
  9717. if (unlikely(bp->panic)) {
  9718. BNX2X_ERR("Can't post to SP queue while panic\n");
  9719. return -EIO;
  9720. }
  9721. #endif
  9722. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  9723. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  9724. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  9725. return -EAGAIN;
  9726. }
  9727. spin_lock_bh(&bp->spq_lock);
  9728. for (i = 0; i < count; i++) {
  9729. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  9730. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  9731. break;
  9732. *bp->cnic_kwq_prod = *spe;
  9733. bp->cnic_kwq_pending++;
  9734. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  9735. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  9736. spe->data.update_data_addr.hi,
  9737. spe->data.update_data_addr.lo,
  9738. bp->cnic_kwq_pending);
  9739. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  9740. bp->cnic_kwq_prod = bp->cnic_kwq;
  9741. else
  9742. bp->cnic_kwq_prod++;
  9743. }
  9744. spin_unlock_bh(&bp->spq_lock);
  9745. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  9746. bnx2x_cnic_sp_post(bp, 0);
  9747. return i;
  9748. }
  9749. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  9750. {
  9751. struct cnic_ops *c_ops;
  9752. int rc = 0;
  9753. mutex_lock(&bp->cnic_mutex);
  9754. c_ops = rcu_dereference_protected(bp->cnic_ops,
  9755. lockdep_is_held(&bp->cnic_mutex));
  9756. if (c_ops)
  9757. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  9758. mutex_unlock(&bp->cnic_mutex);
  9759. return rc;
  9760. }
  9761. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  9762. {
  9763. struct cnic_ops *c_ops;
  9764. int rc = 0;
  9765. rcu_read_lock();
  9766. c_ops = rcu_dereference(bp->cnic_ops);
  9767. if (c_ops)
  9768. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  9769. rcu_read_unlock();
  9770. return rc;
  9771. }
  9772. /*
  9773. * for commands that have no data
  9774. */
  9775. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  9776. {
  9777. struct cnic_ctl_info ctl = {0};
  9778. ctl.cmd = cmd;
  9779. return bnx2x_cnic_ctl_send(bp, &ctl);
  9780. }
  9781. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  9782. {
  9783. struct cnic_ctl_info ctl = {0};
  9784. /* first we tell CNIC and only then we count this as a completion */
  9785. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  9786. ctl.data.comp.cid = cid;
  9787. ctl.data.comp.error = err;
  9788. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  9789. bnx2x_cnic_sp_post(bp, 0);
  9790. }
  9791. /* Called with netif_addr_lock_bh() taken.
  9792. * Sets an rx_mode config for an iSCSI ETH client.
  9793. * Doesn't block.
  9794. * Completion should be checked outside.
  9795. */
  9796. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  9797. {
  9798. unsigned long accept_flags = 0, ramrod_flags = 0;
  9799. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  9800. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  9801. if (start) {
  9802. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  9803. * because it's the only way for UIO Queue to accept
  9804. * multicasts (in non-promiscuous mode only one Queue per
  9805. * function will receive multicast packets (leading in our
  9806. * case).
  9807. */
  9808. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  9809. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  9810. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  9811. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  9812. /* Clear STOP_PENDING bit if START is requested */
  9813. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  9814. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  9815. } else
  9816. /* Clear START_PENDING bit if STOP is requested */
  9817. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  9818. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  9819. set_bit(sched_state, &bp->sp_state);
  9820. else {
  9821. __set_bit(RAMROD_RX, &ramrod_flags);
  9822. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  9823. ramrod_flags);
  9824. }
  9825. }
  9826. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  9827. {
  9828. struct bnx2x *bp = netdev_priv(dev);
  9829. int rc = 0;
  9830. switch (ctl->cmd) {
  9831. case DRV_CTL_CTXTBL_WR_CMD: {
  9832. u32 index = ctl->data.io.offset;
  9833. dma_addr_t addr = ctl->data.io.dma_addr;
  9834. bnx2x_ilt_wr(bp, index, addr);
  9835. break;
  9836. }
  9837. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  9838. int count = ctl->data.credit.credit_count;
  9839. bnx2x_cnic_sp_post(bp, count);
  9840. break;
  9841. }
  9842. /* rtnl_lock is held. */
  9843. case DRV_CTL_START_L2_CMD: {
  9844. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  9845. unsigned long sp_bits = 0;
  9846. /* Configure the iSCSI classification object */
  9847. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  9848. cp->iscsi_l2_client_id,
  9849. cp->iscsi_l2_cid, BP_FUNC(bp),
  9850. bnx2x_sp(bp, mac_rdata),
  9851. bnx2x_sp_mapping(bp, mac_rdata),
  9852. BNX2X_FILTER_MAC_PENDING,
  9853. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  9854. &bp->macs_pool);
  9855. /* Set iSCSI MAC address */
  9856. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  9857. if (rc)
  9858. break;
  9859. mmiowb();
  9860. barrier();
  9861. /* Start accepting on iSCSI L2 ring */
  9862. netif_addr_lock_bh(dev);
  9863. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  9864. netif_addr_unlock_bh(dev);
  9865. /* bits to wait on */
  9866. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  9867. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  9868. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  9869. BNX2X_ERR("rx_mode completion timed out!\n");
  9870. break;
  9871. }
  9872. /* rtnl_lock is held. */
  9873. case DRV_CTL_STOP_L2_CMD: {
  9874. unsigned long sp_bits = 0;
  9875. /* Stop accepting on iSCSI L2 ring */
  9876. netif_addr_lock_bh(dev);
  9877. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  9878. netif_addr_unlock_bh(dev);
  9879. /* bits to wait on */
  9880. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  9881. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  9882. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  9883. BNX2X_ERR("rx_mode completion timed out!\n");
  9884. mmiowb();
  9885. barrier();
  9886. /* Unset iSCSI L2 MAC */
  9887. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  9888. BNX2X_ISCSI_ETH_MAC, true);
  9889. break;
  9890. }
  9891. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  9892. int count = ctl->data.credit.credit_count;
  9893. smp_mb__before_atomic_inc();
  9894. atomic_add(count, &bp->cq_spq_left);
  9895. smp_mb__after_atomic_inc();
  9896. break;
  9897. }
  9898. case DRV_CTL_ULP_REGISTER_CMD: {
  9899. int ulp_type = ctl->data.ulp_type;
  9900. if (CHIP_IS_E3(bp)) {
  9901. int idx = BP_FW_MB_IDX(bp);
  9902. u32 cap;
  9903. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  9904. if (ulp_type == CNIC_ULP_ISCSI)
  9905. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  9906. else if (ulp_type == CNIC_ULP_FCOE)
  9907. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  9908. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  9909. }
  9910. break;
  9911. }
  9912. case DRV_CTL_ULP_UNREGISTER_CMD: {
  9913. int ulp_type = ctl->data.ulp_type;
  9914. if (CHIP_IS_E3(bp)) {
  9915. int idx = BP_FW_MB_IDX(bp);
  9916. u32 cap;
  9917. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  9918. if (ulp_type == CNIC_ULP_ISCSI)
  9919. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  9920. else if (ulp_type == CNIC_ULP_FCOE)
  9921. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  9922. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  9923. }
  9924. break;
  9925. }
  9926. default:
  9927. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  9928. rc = -EINVAL;
  9929. }
  9930. return rc;
  9931. }
  9932. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  9933. {
  9934. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  9935. if (bp->flags & USING_MSIX_FLAG) {
  9936. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  9937. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  9938. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  9939. } else {
  9940. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  9941. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  9942. }
  9943. if (!CHIP_IS_E1x(bp))
  9944. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  9945. else
  9946. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  9947. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  9948. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  9949. cp->irq_arr[1].status_blk = bp->def_status_blk;
  9950. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  9951. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  9952. cp->num_irq = 2;
  9953. }
  9954. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  9955. void *data)
  9956. {
  9957. struct bnx2x *bp = netdev_priv(dev);
  9958. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  9959. if (ops == NULL) {
  9960. BNX2X_ERR("NULL ops received\n");
  9961. return -EINVAL;
  9962. }
  9963. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  9964. if (!bp->cnic_kwq)
  9965. return -ENOMEM;
  9966. bp->cnic_kwq_cons = bp->cnic_kwq;
  9967. bp->cnic_kwq_prod = bp->cnic_kwq;
  9968. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  9969. bp->cnic_spq_pending = 0;
  9970. bp->cnic_kwq_pending = 0;
  9971. bp->cnic_data = data;
  9972. cp->num_irq = 0;
  9973. cp->drv_state |= CNIC_DRV_STATE_REGD;
  9974. cp->iro_arr = bp->iro_arr;
  9975. bnx2x_setup_cnic_irq_info(bp);
  9976. rcu_assign_pointer(bp->cnic_ops, ops);
  9977. return 0;
  9978. }
  9979. static int bnx2x_unregister_cnic(struct net_device *dev)
  9980. {
  9981. struct bnx2x *bp = netdev_priv(dev);
  9982. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  9983. mutex_lock(&bp->cnic_mutex);
  9984. cp->drv_state = 0;
  9985. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  9986. mutex_unlock(&bp->cnic_mutex);
  9987. synchronize_rcu();
  9988. kfree(bp->cnic_kwq);
  9989. bp->cnic_kwq = NULL;
  9990. return 0;
  9991. }
  9992. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  9993. {
  9994. struct bnx2x *bp = netdev_priv(dev);
  9995. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  9996. /* If both iSCSI and FCoE are disabled - return NULL in
  9997. * order to indicate CNIC that it should not try to work
  9998. * with this device.
  9999. */
  10000. if (NO_ISCSI(bp) && NO_FCOE(bp))
  10001. return NULL;
  10002. cp->drv_owner = THIS_MODULE;
  10003. cp->chip_id = CHIP_ID(bp);
  10004. cp->pdev = bp->pdev;
  10005. cp->io_base = bp->regview;
  10006. cp->io_base2 = bp->doorbells;
  10007. cp->max_kwqe_pending = 8;
  10008. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  10009. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  10010. bnx2x_cid_ilt_lines(bp);
  10011. cp->ctx_tbl_len = CNIC_ILT_LINES;
  10012. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  10013. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  10014. cp->drv_ctl = bnx2x_drv_ctl;
  10015. cp->drv_register_cnic = bnx2x_register_cnic;
  10016. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  10017. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID;
  10018. cp->iscsi_l2_client_id =
  10019. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  10020. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID;
  10021. if (NO_ISCSI_OOO(bp))
  10022. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  10023. if (NO_ISCSI(bp))
  10024. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  10025. if (NO_FCOE(bp))
  10026. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  10027. BNX2X_DEV_INFO(
  10028. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  10029. cp->ctx_blk_size,
  10030. cp->ctx_tbl_offset,
  10031. cp->ctx_tbl_len,
  10032. cp->starting_cid);
  10033. return cp;
  10034. }
  10035. EXPORT_SYMBOL(bnx2x_cnic_probe);
  10036. #endif /* BCM_CNIC */