bnx2x_main.c 335 KB

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