bnx2x_main.c 321 KB

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