bnx2x_main.c 349 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001
  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. #define MAC_LEADING_ZERO_CNT (ALIGN(ETH_ALEN, sizeof(u32)) - ETH_ALEN)
  73. /* Time in jiffies before concluding the transmitter is hung */
  74. #define TX_TIMEOUT (5*HZ)
  75. static char version[] __devinitdata =
  76. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  77. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  78. MODULE_AUTHOR("Eliezer Tamir");
  79. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  80. "BCM57710/57711/57711E/"
  81. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  82. "57840/57840_MF Driver");
  83. MODULE_LICENSE("GPL");
  84. MODULE_VERSION(DRV_MODULE_VERSION);
  85. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  86. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  87. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  88. int num_queues;
  89. module_param(num_queues, int, 0);
  90. MODULE_PARM_DESC(num_queues,
  91. " Set number of queues (default is as a number of CPUs)");
  92. static int disable_tpa;
  93. module_param(disable_tpa, int, 0);
  94. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  95. #define INT_MODE_INTx 1
  96. #define INT_MODE_MSI 2
  97. int int_mode;
  98. module_param(int_mode, int, 0);
  99. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  100. "(1 INT#x; 2 MSI)");
  101. static int dropless_fc;
  102. module_param(dropless_fc, int, 0);
  103. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  104. static int mrrs = -1;
  105. module_param(mrrs, int, 0);
  106. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  107. static int debug;
  108. module_param(debug, int, 0);
  109. MODULE_PARM_DESC(debug, " Default debug msglevel");
  110. struct workqueue_struct *bnx2x_wq;
  111. enum bnx2x_board_type {
  112. BCM57710 = 0,
  113. BCM57711,
  114. BCM57711E,
  115. BCM57712,
  116. BCM57712_MF,
  117. BCM57800,
  118. BCM57800_MF,
  119. BCM57810,
  120. BCM57810_MF,
  121. BCM57840_O,
  122. BCM57840_4_10,
  123. BCM57840_2_20,
  124. BCM57840_MFO,
  125. BCM57840_MF,
  126. BCM57811,
  127. BCM57811_MF
  128. };
  129. /* indexed by board_type, above */
  130. static struct {
  131. char *name;
  132. } board_info[] __devinitdata = {
  133. { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  134. { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  135. { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  136. { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  137. { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  138. { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  139. { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  140. { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  141. { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  142. { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  143. { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
  144. { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
  145. { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function"},
  146. { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function"},
  147. { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet"},
  148. { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function"},
  149. };
  150. #ifndef PCI_DEVICE_ID_NX2_57710
  151. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  152. #endif
  153. #ifndef PCI_DEVICE_ID_NX2_57711
  154. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  155. #endif
  156. #ifndef PCI_DEVICE_ID_NX2_57711E
  157. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  158. #endif
  159. #ifndef PCI_DEVICE_ID_NX2_57712
  160. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  161. #endif
  162. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  163. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  164. #endif
  165. #ifndef PCI_DEVICE_ID_NX2_57800
  166. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  167. #endif
  168. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  169. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  170. #endif
  171. #ifndef PCI_DEVICE_ID_NX2_57810
  172. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  173. #endif
  174. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  175. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  176. #endif
  177. #ifndef PCI_DEVICE_ID_NX2_57840_O
  178. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  179. #endif
  180. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  181. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  182. #endif
  183. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  184. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  185. #endif
  186. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  187. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  188. #endif
  189. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  190. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  191. #endif
  192. #ifndef PCI_DEVICE_ID_NX2_57811
  193. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  194. #endif
  195. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  196. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  197. #endif
  198. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  199. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  200. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  201. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  202. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  203. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  204. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  205. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  206. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  207. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  208. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  209. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  210. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  211. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  212. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  213. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  214. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  215. { 0 }
  216. };
  217. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  218. /* Global resources for unloading a previously loaded device */
  219. #define BNX2X_PREV_WAIT_NEEDED 1
  220. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  221. static LIST_HEAD(bnx2x_prev_list);
  222. /****************************************************************************
  223. * General service functions
  224. ****************************************************************************/
  225. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  226. u32 addr, dma_addr_t mapping)
  227. {
  228. REG_WR(bp, addr, U64_LO(mapping));
  229. REG_WR(bp, addr + 4, U64_HI(mapping));
  230. }
  231. static void storm_memset_spq_addr(struct bnx2x *bp,
  232. dma_addr_t mapping, u16 abs_fid)
  233. {
  234. u32 addr = XSEM_REG_FAST_MEMORY +
  235. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  236. __storm_memset_dma_mapping(bp, addr, mapping);
  237. }
  238. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  239. u16 pf_id)
  240. {
  241. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  242. pf_id);
  243. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  244. pf_id);
  245. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  246. pf_id);
  247. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  248. pf_id);
  249. }
  250. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  251. u8 enable)
  252. {
  253. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  254. enable);
  255. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  256. enable);
  257. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  258. enable);
  259. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  260. enable);
  261. }
  262. static void storm_memset_eq_data(struct bnx2x *bp,
  263. struct event_ring_data *eq_data,
  264. u16 pfid)
  265. {
  266. size_t size = sizeof(struct event_ring_data);
  267. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  268. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  269. }
  270. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  271. u16 pfid)
  272. {
  273. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  274. REG_WR16(bp, addr, eq_prod);
  275. }
  276. /* used only at init
  277. * locking is done by mcp
  278. */
  279. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  280. {
  281. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  282. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  283. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  284. PCICFG_VENDOR_ID_OFFSET);
  285. }
  286. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  287. {
  288. u32 val;
  289. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  290. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  291. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  292. PCICFG_VENDOR_ID_OFFSET);
  293. return val;
  294. }
  295. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  296. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  297. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  298. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  299. #define DMAE_DP_DST_NONE "dst_addr [none]"
  300. /* copy command into DMAE command memory and set DMAE command go */
  301. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  302. {
  303. u32 cmd_offset;
  304. int i;
  305. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  306. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  307. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  308. }
  309. REG_WR(bp, dmae_reg_go_c[idx], 1);
  310. }
  311. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  312. {
  313. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  314. DMAE_CMD_C_ENABLE);
  315. }
  316. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  317. {
  318. return opcode & ~DMAE_CMD_SRC_RESET;
  319. }
  320. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  321. bool with_comp, u8 comp_type)
  322. {
  323. u32 opcode = 0;
  324. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  325. (dst_type << DMAE_COMMAND_DST_SHIFT));
  326. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  327. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  328. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  329. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  330. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  331. #ifdef __BIG_ENDIAN
  332. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  333. #else
  334. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  335. #endif
  336. if (with_comp)
  337. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  338. return opcode;
  339. }
  340. static void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  341. struct dmae_command *dmae,
  342. u8 src_type, u8 dst_type)
  343. {
  344. memset(dmae, 0, sizeof(struct dmae_command));
  345. /* set the opcode */
  346. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  347. true, DMAE_COMP_PCI);
  348. /* fill in the completion parameters */
  349. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  350. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  351. dmae->comp_val = DMAE_COMP_VAL;
  352. }
  353. /* issue a dmae command over the init-channel and wailt for completion */
  354. static int bnx2x_issue_dmae_with_comp(struct bnx2x *bp,
  355. struct dmae_command *dmae)
  356. {
  357. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  358. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  359. int rc = 0;
  360. /*
  361. * Lock the dmae channel. Disable BHs to prevent a dead-lock
  362. * as long as this code is called both from syscall context and
  363. * from ndo_set_rx_mode() flow that may be called from BH.
  364. */
  365. spin_lock_bh(&bp->dmae_lock);
  366. /* reset completion */
  367. *wb_comp = 0;
  368. /* post the command on the channel used for initializations */
  369. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  370. /* wait for completion */
  371. udelay(5);
  372. while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  373. if (!cnt ||
  374. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  375. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  376. BNX2X_ERR("DMAE timeout!\n");
  377. rc = DMAE_TIMEOUT;
  378. goto unlock;
  379. }
  380. cnt--;
  381. udelay(50);
  382. }
  383. if (*wb_comp & DMAE_PCI_ERR_FLAG) {
  384. BNX2X_ERR("DMAE PCI error!\n");
  385. rc = DMAE_PCI_ERROR;
  386. }
  387. unlock:
  388. spin_unlock_bh(&bp->dmae_lock);
  389. return rc;
  390. }
  391. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  392. u32 len32)
  393. {
  394. struct dmae_command dmae;
  395. if (!bp->dmae_ready) {
  396. u32 *data = bnx2x_sp(bp, wb_data[0]);
  397. if (CHIP_IS_E1(bp))
  398. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  399. else
  400. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  401. return;
  402. }
  403. /* set opcode and fixed command fields */
  404. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  405. /* fill in addresses and len */
  406. dmae.src_addr_lo = U64_LO(dma_addr);
  407. dmae.src_addr_hi = U64_HI(dma_addr);
  408. dmae.dst_addr_lo = dst_addr >> 2;
  409. dmae.dst_addr_hi = 0;
  410. dmae.len = len32;
  411. /* issue the command and wait for completion */
  412. bnx2x_issue_dmae_with_comp(bp, &dmae);
  413. }
  414. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  415. {
  416. struct dmae_command dmae;
  417. if (!bp->dmae_ready) {
  418. u32 *data = bnx2x_sp(bp, wb_data[0]);
  419. int i;
  420. if (CHIP_IS_E1(bp))
  421. for (i = 0; i < len32; i++)
  422. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  423. else
  424. for (i = 0; i < len32; i++)
  425. data[i] = REG_RD(bp, src_addr + i*4);
  426. return;
  427. }
  428. /* set opcode and fixed command fields */
  429. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  430. /* fill in addresses and len */
  431. dmae.src_addr_lo = src_addr >> 2;
  432. dmae.src_addr_hi = 0;
  433. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  434. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  435. dmae.len = len32;
  436. /* issue the command and wait for completion */
  437. bnx2x_issue_dmae_with_comp(bp, &dmae);
  438. }
  439. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  440. u32 addr, u32 len)
  441. {
  442. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  443. int offset = 0;
  444. while (len > dmae_wr_max) {
  445. bnx2x_write_dmae(bp, phys_addr + offset,
  446. addr + offset, dmae_wr_max);
  447. offset += dmae_wr_max * 4;
  448. len -= dmae_wr_max;
  449. }
  450. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  451. }
  452. static int bnx2x_mc_assert(struct bnx2x *bp)
  453. {
  454. char last_idx;
  455. int i, rc = 0;
  456. u32 row0, row1, row2, row3;
  457. /* XSTORM */
  458. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  459. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  460. if (last_idx)
  461. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  462. /* print the asserts */
  463. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  464. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  465. XSTORM_ASSERT_LIST_OFFSET(i));
  466. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  467. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  468. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  469. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  470. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  471. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  472. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  473. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  474. i, row3, row2, row1, row0);
  475. rc++;
  476. } else {
  477. break;
  478. }
  479. }
  480. /* TSTORM */
  481. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  482. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  483. if (last_idx)
  484. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  485. /* print the asserts */
  486. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  487. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  488. TSTORM_ASSERT_LIST_OFFSET(i));
  489. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  490. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  491. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  492. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  493. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  494. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  495. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  496. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  497. i, row3, row2, row1, row0);
  498. rc++;
  499. } else {
  500. break;
  501. }
  502. }
  503. /* CSTORM */
  504. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  505. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  506. if (last_idx)
  507. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  508. /* print the asserts */
  509. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  510. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  511. CSTORM_ASSERT_LIST_OFFSET(i));
  512. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  513. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  514. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  515. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  516. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  517. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  518. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  519. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  520. i, row3, row2, row1, row0);
  521. rc++;
  522. } else {
  523. break;
  524. }
  525. }
  526. /* USTORM */
  527. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  528. USTORM_ASSERT_LIST_INDEX_OFFSET);
  529. if (last_idx)
  530. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  531. /* print the asserts */
  532. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  533. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  534. USTORM_ASSERT_LIST_OFFSET(i));
  535. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  536. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  537. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  538. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  539. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  540. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  541. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  542. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  543. i, row3, row2, row1, row0);
  544. rc++;
  545. } else {
  546. break;
  547. }
  548. }
  549. return rc;
  550. }
  551. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  552. {
  553. u32 addr, val;
  554. u32 mark, offset;
  555. __be32 data[9];
  556. int word;
  557. u32 trace_shmem_base;
  558. if (BP_NOMCP(bp)) {
  559. BNX2X_ERR("NO MCP - can not dump\n");
  560. return;
  561. }
  562. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  563. (bp->common.bc_ver & 0xff0000) >> 16,
  564. (bp->common.bc_ver & 0xff00) >> 8,
  565. (bp->common.bc_ver & 0xff));
  566. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  567. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  568. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  569. if (BP_PATH(bp) == 0)
  570. trace_shmem_base = bp->common.shmem_base;
  571. else
  572. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  573. addr = trace_shmem_base - 0x800;
  574. /* validate TRCB signature */
  575. mark = REG_RD(bp, addr);
  576. if (mark != MFW_TRACE_SIGNATURE) {
  577. BNX2X_ERR("Trace buffer signature is missing.");
  578. return ;
  579. }
  580. /* read cyclic buffer pointer */
  581. addr += 4;
  582. mark = REG_RD(bp, addr);
  583. mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
  584. + ((mark + 0x3) & ~0x3) - 0x08000000;
  585. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  586. printk("%s", lvl);
  587. for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
  588. for (word = 0; word < 8; word++)
  589. data[word] = htonl(REG_RD(bp, offset + 4*word));
  590. data[8] = 0x0;
  591. pr_cont("%s", (char *)data);
  592. }
  593. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  594. for (word = 0; word < 8; word++)
  595. data[word] = htonl(REG_RD(bp, offset + 4*word));
  596. data[8] = 0x0;
  597. pr_cont("%s", (char *)data);
  598. }
  599. printk("%s" "end of fw dump\n", lvl);
  600. }
  601. static void bnx2x_fw_dump(struct bnx2x *bp)
  602. {
  603. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  604. }
  605. void bnx2x_panic_dump(struct bnx2x *bp)
  606. {
  607. int i;
  608. u16 j;
  609. struct hc_sp_status_block_data sp_sb_data;
  610. int func = BP_FUNC(bp);
  611. #ifdef BNX2X_STOP_ON_ERROR
  612. u16 start = 0, end = 0;
  613. u8 cos;
  614. #endif
  615. bp->stats_state = STATS_STATE_DISABLED;
  616. bp->eth_stats.unrecoverable_error++;
  617. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  618. BNX2X_ERR("begin crash dump -----------------\n");
  619. /* Indices */
  620. /* Common */
  621. 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",
  622. bp->def_idx, bp->def_att_idx, bp->attn_state,
  623. bp->spq_prod_idx, bp->stats_counter);
  624. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  625. bp->def_status_blk->atten_status_block.attn_bits,
  626. bp->def_status_blk->atten_status_block.attn_bits_ack,
  627. bp->def_status_blk->atten_status_block.status_block_id,
  628. bp->def_status_blk->atten_status_block.attn_bits_index);
  629. BNX2X_ERR(" def (");
  630. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  631. pr_cont("0x%x%s",
  632. bp->def_status_blk->sp_sb.index_values[i],
  633. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  634. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  635. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  636. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  637. i*sizeof(u32));
  638. 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",
  639. sp_sb_data.igu_sb_id,
  640. sp_sb_data.igu_seg_id,
  641. sp_sb_data.p_func.pf_id,
  642. sp_sb_data.p_func.vnic_id,
  643. sp_sb_data.p_func.vf_id,
  644. sp_sb_data.p_func.vf_valid,
  645. sp_sb_data.state);
  646. for_each_eth_queue(bp, i) {
  647. struct bnx2x_fastpath *fp = &bp->fp[i];
  648. int loop;
  649. struct hc_status_block_data_e2 sb_data_e2;
  650. struct hc_status_block_data_e1x sb_data_e1x;
  651. struct hc_status_block_sm *hc_sm_p =
  652. CHIP_IS_E1x(bp) ?
  653. sb_data_e1x.common.state_machine :
  654. sb_data_e2.common.state_machine;
  655. struct hc_index_data *hc_index_p =
  656. CHIP_IS_E1x(bp) ?
  657. sb_data_e1x.index_data :
  658. sb_data_e2.index_data;
  659. u8 data_size, cos;
  660. u32 *sb_data_p;
  661. struct bnx2x_fp_txdata txdata;
  662. /* Rx */
  663. 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",
  664. i, fp->rx_bd_prod, fp->rx_bd_cons,
  665. fp->rx_comp_prod,
  666. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  667. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  668. fp->rx_sge_prod, fp->last_max_sge,
  669. le16_to_cpu(fp->fp_hc_idx));
  670. /* Tx */
  671. for_each_cos_in_tx_queue(fp, cos)
  672. {
  673. txdata = *fp->txdata_ptr[cos];
  674. 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",
  675. i, txdata.tx_pkt_prod,
  676. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  677. txdata.tx_bd_cons,
  678. le16_to_cpu(*txdata.tx_cons_sb));
  679. }
  680. loop = CHIP_IS_E1x(bp) ?
  681. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  682. /* host sb data */
  683. if (IS_FCOE_FP(fp))
  684. continue;
  685. BNX2X_ERR(" run indexes (");
  686. for (j = 0; j < HC_SB_MAX_SM; j++)
  687. pr_cont("0x%x%s",
  688. fp->sb_running_index[j],
  689. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  690. BNX2X_ERR(" indexes (");
  691. for (j = 0; j < loop; j++)
  692. pr_cont("0x%x%s",
  693. fp->sb_index_values[j],
  694. (j == loop - 1) ? ")" : " ");
  695. /* fw sb data */
  696. data_size = CHIP_IS_E1x(bp) ?
  697. sizeof(struct hc_status_block_data_e1x) :
  698. sizeof(struct hc_status_block_data_e2);
  699. data_size /= sizeof(u32);
  700. sb_data_p = CHIP_IS_E1x(bp) ?
  701. (u32 *)&sb_data_e1x :
  702. (u32 *)&sb_data_e2;
  703. /* copy sb data in here */
  704. for (j = 0; j < data_size; j++)
  705. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  706. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  707. j * sizeof(u32));
  708. if (!CHIP_IS_E1x(bp)) {
  709. 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",
  710. sb_data_e2.common.p_func.pf_id,
  711. sb_data_e2.common.p_func.vf_id,
  712. sb_data_e2.common.p_func.vf_valid,
  713. sb_data_e2.common.p_func.vnic_id,
  714. sb_data_e2.common.same_igu_sb_1b,
  715. sb_data_e2.common.state);
  716. } else {
  717. 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",
  718. sb_data_e1x.common.p_func.pf_id,
  719. sb_data_e1x.common.p_func.vf_id,
  720. sb_data_e1x.common.p_func.vf_valid,
  721. sb_data_e1x.common.p_func.vnic_id,
  722. sb_data_e1x.common.same_igu_sb_1b,
  723. sb_data_e1x.common.state);
  724. }
  725. /* SB_SMs data */
  726. for (j = 0; j < HC_SB_MAX_SM; j++) {
  727. 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",
  728. j, hc_sm_p[j].__flags,
  729. hc_sm_p[j].igu_sb_id,
  730. hc_sm_p[j].igu_seg_id,
  731. hc_sm_p[j].time_to_expire,
  732. hc_sm_p[j].timer_value);
  733. }
  734. /* Indecies data */
  735. for (j = 0; j < loop; j++) {
  736. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  737. hc_index_p[j].flags,
  738. hc_index_p[j].timeout);
  739. }
  740. }
  741. #ifdef BNX2X_STOP_ON_ERROR
  742. /* Rings */
  743. /* Rx */
  744. for_each_valid_rx_queue(bp, i) {
  745. struct bnx2x_fastpath *fp = &bp->fp[i];
  746. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  747. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  748. for (j = start; j != end; j = RX_BD(j + 1)) {
  749. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  750. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  751. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  752. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  753. }
  754. start = RX_SGE(fp->rx_sge_prod);
  755. end = RX_SGE(fp->last_max_sge);
  756. for (j = start; j != end; j = RX_SGE(j + 1)) {
  757. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  758. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  759. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  760. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  761. }
  762. start = RCQ_BD(fp->rx_comp_cons - 10);
  763. end = RCQ_BD(fp->rx_comp_cons + 503);
  764. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  765. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  766. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  767. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  768. }
  769. }
  770. /* Tx */
  771. for_each_valid_tx_queue(bp, i) {
  772. struct bnx2x_fastpath *fp = &bp->fp[i];
  773. for_each_cos_in_tx_queue(fp, cos) {
  774. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  775. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  776. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  777. for (j = start; j != end; j = TX_BD(j + 1)) {
  778. struct sw_tx_bd *sw_bd =
  779. &txdata->tx_buf_ring[j];
  780. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  781. i, cos, j, sw_bd->skb,
  782. sw_bd->first_bd);
  783. }
  784. start = TX_BD(txdata->tx_bd_cons - 10);
  785. end = TX_BD(txdata->tx_bd_cons + 254);
  786. for (j = start; j != end; j = TX_BD(j + 1)) {
  787. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  788. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  789. i, cos, j, tx_bd[0], tx_bd[1],
  790. tx_bd[2], tx_bd[3]);
  791. }
  792. }
  793. }
  794. #endif
  795. bnx2x_fw_dump(bp);
  796. bnx2x_mc_assert(bp);
  797. BNX2X_ERR("end crash dump -----------------\n");
  798. }
  799. /*
  800. * FLR Support for E2
  801. *
  802. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  803. * initialization.
  804. */
  805. #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
  806. #define FLR_WAIT_INTERVAL 50 /* usec */
  807. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  808. struct pbf_pN_buf_regs {
  809. int pN;
  810. u32 init_crd;
  811. u32 crd;
  812. u32 crd_freed;
  813. };
  814. struct pbf_pN_cmd_regs {
  815. int pN;
  816. u32 lines_occup;
  817. u32 lines_freed;
  818. };
  819. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  820. struct pbf_pN_buf_regs *regs,
  821. u32 poll_count)
  822. {
  823. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  824. u32 cur_cnt = poll_count;
  825. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  826. crd = crd_start = REG_RD(bp, regs->crd);
  827. init_crd = REG_RD(bp, regs->init_crd);
  828. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  829. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  830. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  831. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  832. (init_crd - crd_start))) {
  833. if (cur_cnt--) {
  834. udelay(FLR_WAIT_INTERVAL);
  835. crd = REG_RD(bp, regs->crd);
  836. crd_freed = REG_RD(bp, regs->crd_freed);
  837. } else {
  838. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  839. regs->pN);
  840. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  841. regs->pN, crd);
  842. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  843. regs->pN, crd_freed);
  844. break;
  845. }
  846. }
  847. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  848. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  849. }
  850. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  851. struct pbf_pN_cmd_regs *regs,
  852. u32 poll_count)
  853. {
  854. u32 occup, to_free, freed, freed_start;
  855. u32 cur_cnt = poll_count;
  856. occup = to_free = REG_RD(bp, regs->lines_occup);
  857. freed = freed_start = REG_RD(bp, regs->lines_freed);
  858. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  859. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  860. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  861. if (cur_cnt--) {
  862. udelay(FLR_WAIT_INTERVAL);
  863. occup = REG_RD(bp, regs->lines_occup);
  864. freed = REG_RD(bp, regs->lines_freed);
  865. } else {
  866. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  867. regs->pN);
  868. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  869. regs->pN, occup);
  870. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  871. regs->pN, freed);
  872. break;
  873. }
  874. }
  875. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  876. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  877. }
  878. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  879. u32 expected, u32 poll_count)
  880. {
  881. u32 cur_cnt = poll_count;
  882. u32 val;
  883. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  884. udelay(FLR_WAIT_INTERVAL);
  885. return val;
  886. }
  887. static int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  888. char *msg, u32 poll_cnt)
  889. {
  890. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  891. if (val != 0) {
  892. BNX2X_ERR("%s usage count=%d\n", msg, val);
  893. return 1;
  894. }
  895. return 0;
  896. }
  897. static u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  898. {
  899. /* adjust polling timeout */
  900. if (CHIP_REV_IS_EMUL(bp))
  901. return FLR_POLL_CNT * 2000;
  902. if (CHIP_REV_IS_FPGA(bp))
  903. return FLR_POLL_CNT * 120;
  904. return FLR_POLL_CNT;
  905. }
  906. static void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  907. {
  908. struct pbf_pN_cmd_regs cmd_regs[] = {
  909. {0, (CHIP_IS_E3B0(bp)) ?
  910. PBF_REG_TQ_OCCUPANCY_Q0 :
  911. PBF_REG_P0_TQ_OCCUPANCY,
  912. (CHIP_IS_E3B0(bp)) ?
  913. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  914. PBF_REG_P0_TQ_LINES_FREED_CNT},
  915. {1, (CHIP_IS_E3B0(bp)) ?
  916. PBF_REG_TQ_OCCUPANCY_Q1 :
  917. PBF_REG_P1_TQ_OCCUPANCY,
  918. (CHIP_IS_E3B0(bp)) ?
  919. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  920. PBF_REG_P1_TQ_LINES_FREED_CNT},
  921. {4, (CHIP_IS_E3B0(bp)) ?
  922. PBF_REG_TQ_OCCUPANCY_LB_Q :
  923. PBF_REG_P4_TQ_OCCUPANCY,
  924. (CHIP_IS_E3B0(bp)) ?
  925. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  926. PBF_REG_P4_TQ_LINES_FREED_CNT}
  927. };
  928. struct pbf_pN_buf_regs buf_regs[] = {
  929. {0, (CHIP_IS_E3B0(bp)) ?
  930. PBF_REG_INIT_CRD_Q0 :
  931. PBF_REG_P0_INIT_CRD ,
  932. (CHIP_IS_E3B0(bp)) ?
  933. PBF_REG_CREDIT_Q0 :
  934. PBF_REG_P0_CREDIT,
  935. (CHIP_IS_E3B0(bp)) ?
  936. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  937. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  938. {1, (CHIP_IS_E3B0(bp)) ?
  939. PBF_REG_INIT_CRD_Q1 :
  940. PBF_REG_P1_INIT_CRD,
  941. (CHIP_IS_E3B0(bp)) ?
  942. PBF_REG_CREDIT_Q1 :
  943. PBF_REG_P1_CREDIT,
  944. (CHIP_IS_E3B0(bp)) ?
  945. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  946. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  947. {4, (CHIP_IS_E3B0(bp)) ?
  948. PBF_REG_INIT_CRD_LB_Q :
  949. PBF_REG_P4_INIT_CRD,
  950. (CHIP_IS_E3B0(bp)) ?
  951. PBF_REG_CREDIT_LB_Q :
  952. PBF_REG_P4_CREDIT,
  953. (CHIP_IS_E3B0(bp)) ?
  954. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  955. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  956. };
  957. int i;
  958. /* Verify the command queues are flushed P0, P1, P4 */
  959. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  960. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  961. /* Verify the transmission buffers are flushed P0, P1, P4 */
  962. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  963. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  964. }
  965. #define OP_GEN_PARAM(param) \
  966. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  967. #define OP_GEN_TYPE(type) \
  968. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  969. #define OP_GEN_AGG_VECT(index) \
  970. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  971. static int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func,
  972. u32 poll_cnt)
  973. {
  974. struct sdm_op_gen op_gen = {0};
  975. u32 comp_addr = BAR_CSTRORM_INTMEM +
  976. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  977. int ret = 0;
  978. if (REG_RD(bp, comp_addr)) {
  979. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  980. return 1;
  981. }
  982. op_gen.command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  983. op_gen.command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  984. op_gen.command |= OP_GEN_AGG_VECT(clnup_func);
  985. op_gen.command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  986. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  987. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen.command);
  988. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  989. BNX2X_ERR("FW final cleanup did not succeed\n");
  990. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  991. (REG_RD(bp, comp_addr)));
  992. ret = 1;
  993. }
  994. /* Zero completion for nxt FLR */
  995. REG_WR(bp, comp_addr, 0);
  996. return ret;
  997. }
  998. static u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  999. {
  1000. u16 status;
  1001. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1002. return status & PCI_EXP_DEVSTA_TRPND;
  1003. }
  1004. /* PF FLR specific routines
  1005. */
  1006. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1007. {
  1008. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1009. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1010. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1011. "CFC PF usage counter timed out",
  1012. poll_cnt))
  1013. return 1;
  1014. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1015. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1016. DORQ_REG_PF_USAGE_CNT,
  1017. "DQ PF usage counter timed out",
  1018. poll_cnt))
  1019. return 1;
  1020. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1021. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1022. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1023. "QM PF usage counter timed out",
  1024. poll_cnt))
  1025. return 1;
  1026. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1027. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1028. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1029. "Timers VNIC usage counter timed out",
  1030. poll_cnt))
  1031. return 1;
  1032. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1033. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1034. "Timers NUM_SCANS usage counter timed out",
  1035. poll_cnt))
  1036. return 1;
  1037. /* Wait DMAE PF usage counter to zero */
  1038. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1039. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1040. "DMAE dommand register timed out",
  1041. poll_cnt))
  1042. return 1;
  1043. return 0;
  1044. }
  1045. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1046. {
  1047. u32 val;
  1048. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1049. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1050. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1051. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1052. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1053. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1054. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1055. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1056. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1057. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1058. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1059. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1060. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1061. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1062. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1063. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1064. val);
  1065. }
  1066. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1067. {
  1068. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1069. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1070. /* Re-enable PF target read access */
  1071. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1072. /* Poll HW usage counters */
  1073. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1074. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1075. return -EBUSY;
  1076. /* Zero the igu 'trailing edge' and 'leading edge' */
  1077. /* Send the FW cleanup command */
  1078. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1079. return -EBUSY;
  1080. /* ATC cleanup */
  1081. /* Verify TX hw is flushed */
  1082. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1083. /* Wait 100ms (not adjusted according to platform) */
  1084. msleep(100);
  1085. /* Verify no pending pci transactions */
  1086. if (bnx2x_is_pcie_pending(bp->pdev))
  1087. BNX2X_ERR("PCIE Transactions still pending\n");
  1088. /* Debug */
  1089. bnx2x_hw_enable_status(bp);
  1090. /*
  1091. * Master enable - Due to WB DMAE writes performed before this
  1092. * register is re-initialized as part of the regular function init
  1093. */
  1094. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1095. return 0;
  1096. }
  1097. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1098. {
  1099. int port = BP_PORT(bp);
  1100. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1101. u32 val = REG_RD(bp, addr);
  1102. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1103. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1104. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1105. if (msix) {
  1106. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1107. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1108. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1109. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1110. if (single_msix)
  1111. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1112. } else if (msi) {
  1113. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1114. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1115. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1116. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1117. } else {
  1118. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1119. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1120. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1121. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1122. if (!CHIP_IS_E1(bp)) {
  1123. DP(NETIF_MSG_IFUP,
  1124. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1125. REG_WR(bp, addr, val);
  1126. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1127. }
  1128. }
  1129. if (CHIP_IS_E1(bp))
  1130. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1131. DP(NETIF_MSG_IFUP,
  1132. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1133. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1134. REG_WR(bp, addr, val);
  1135. /*
  1136. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1137. */
  1138. mmiowb();
  1139. barrier();
  1140. if (!CHIP_IS_E1(bp)) {
  1141. /* init leading/trailing edge */
  1142. if (IS_MF(bp)) {
  1143. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1144. if (bp->port.pmf)
  1145. /* enable nig and gpio3 attention */
  1146. val |= 0x1100;
  1147. } else
  1148. val = 0xffff;
  1149. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1150. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1151. }
  1152. /* Make sure that interrupts are indeed enabled from here on */
  1153. mmiowb();
  1154. }
  1155. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1156. {
  1157. u32 val;
  1158. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1159. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1160. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1161. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1162. if (msix) {
  1163. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1164. IGU_PF_CONF_SINGLE_ISR_EN);
  1165. val |= (IGU_PF_CONF_FUNC_EN |
  1166. IGU_PF_CONF_MSI_MSIX_EN |
  1167. IGU_PF_CONF_ATTN_BIT_EN);
  1168. if (single_msix)
  1169. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1170. } else if (msi) {
  1171. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1172. val |= (IGU_PF_CONF_FUNC_EN |
  1173. IGU_PF_CONF_MSI_MSIX_EN |
  1174. IGU_PF_CONF_ATTN_BIT_EN |
  1175. IGU_PF_CONF_SINGLE_ISR_EN);
  1176. } else {
  1177. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1178. val |= (IGU_PF_CONF_FUNC_EN |
  1179. IGU_PF_CONF_INT_LINE_EN |
  1180. IGU_PF_CONF_ATTN_BIT_EN |
  1181. IGU_PF_CONF_SINGLE_ISR_EN);
  1182. }
  1183. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1184. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1185. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1186. if (val & IGU_PF_CONF_INT_LINE_EN)
  1187. pci_intx(bp->pdev, true);
  1188. barrier();
  1189. /* init leading/trailing edge */
  1190. if (IS_MF(bp)) {
  1191. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1192. if (bp->port.pmf)
  1193. /* enable nig and gpio3 attention */
  1194. val |= 0x1100;
  1195. } else
  1196. val = 0xffff;
  1197. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1198. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1199. /* Make sure that interrupts are indeed enabled from here on */
  1200. mmiowb();
  1201. }
  1202. void bnx2x_int_enable(struct bnx2x *bp)
  1203. {
  1204. if (bp->common.int_block == INT_BLOCK_HC)
  1205. bnx2x_hc_int_enable(bp);
  1206. else
  1207. bnx2x_igu_int_enable(bp);
  1208. }
  1209. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  1210. {
  1211. int port = BP_PORT(bp);
  1212. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1213. u32 val = REG_RD(bp, addr);
  1214. /*
  1215. * in E1 we must use only PCI configuration space to disable
  1216. * MSI/MSIX capablility
  1217. * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  1218. */
  1219. if (CHIP_IS_E1(bp)) {
  1220. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  1221. * Use mask register to prevent from HC sending interrupts
  1222. * after we exit the function
  1223. */
  1224. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  1225. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1226. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1227. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1228. } else
  1229. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1230. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1231. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1232. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1233. DP(NETIF_MSG_IFDOWN,
  1234. "write %x to HC %d (addr 0x%x)\n",
  1235. val, port, addr);
  1236. /* flush all outstanding writes */
  1237. mmiowb();
  1238. REG_WR(bp, addr, val);
  1239. if (REG_RD(bp, addr) != val)
  1240. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1241. }
  1242. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  1243. {
  1244. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1245. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  1246. IGU_PF_CONF_INT_LINE_EN |
  1247. IGU_PF_CONF_ATTN_BIT_EN);
  1248. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  1249. /* flush all outstanding writes */
  1250. mmiowb();
  1251. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1252. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  1253. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1254. }
  1255. static void bnx2x_int_disable(struct bnx2x *bp)
  1256. {
  1257. if (bp->common.int_block == INT_BLOCK_HC)
  1258. bnx2x_hc_int_disable(bp);
  1259. else
  1260. bnx2x_igu_int_disable(bp);
  1261. }
  1262. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1263. {
  1264. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1265. int i, offset;
  1266. if (disable_hw)
  1267. /* prevent the HW from sending interrupts */
  1268. bnx2x_int_disable(bp);
  1269. /* make sure all ISRs are done */
  1270. if (msix) {
  1271. synchronize_irq(bp->msix_table[0].vector);
  1272. offset = 1;
  1273. if (CNIC_SUPPORT(bp))
  1274. offset++;
  1275. for_each_eth_queue(bp, i)
  1276. synchronize_irq(bp->msix_table[offset++].vector);
  1277. } else
  1278. synchronize_irq(bp->pdev->irq);
  1279. /* make sure sp_task is not running */
  1280. cancel_delayed_work(&bp->sp_task);
  1281. cancel_delayed_work(&bp->period_task);
  1282. flush_workqueue(bnx2x_wq);
  1283. }
  1284. /* fast path */
  1285. /*
  1286. * General service functions
  1287. */
  1288. /* Return true if succeeded to acquire the lock */
  1289. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1290. {
  1291. u32 lock_status;
  1292. u32 resource_bit = (1 << resource);
  1293. int func = BP_FUNC(bp);
  1294. u32 hw_lock_control_reg;
  1295. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1296. "Trying to take a lock on resource %d\n", resource);
  1297. /* Validating that the resource is within range */
  1298. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1299. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1300. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1301. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1302. return false;
  1303. }
  1304. if (func <= 5)
  1305. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1306. else
  1307. hw_lock_control_reg =
  1308. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1309. /* Try to acquire the lock */
  1310. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1311. lock_status = REG_RD(bp, hw_lock_control_reg);
  1312. if (lock_status & resource_bit)
  1313. return true;
  1314. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1315. "Failed to get a lock on resource %d\n", resource);
  1316. return false;
  1317. }
  1318. /**
  1319. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1320. *
  1321. * @bp: driver handle
  1322. *
  1323. * Returns the recovery leader resource id according to the engine this function
  1324. * belongs to. Currently only only 2 engines is supported.
  1325. */
  1326. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1327. {
  1328. if (BP_PATH(bp))
  1329. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1330. else
  1331. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1332. }
  1333. /**
  1334. * bnx2x_trylock_leader_lock- try to aquire a leader lock.
  1335. *
  1336. * @bp: driver handle
  1337. *
  1338. * Tries to aquire a leader lock for current engine.
  1339. */
  1340. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1341. {
  1342. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1343. }
  1344. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1345. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1346. {
  1347. struct bnx2x *bp = fp->bp;
  1348. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1349. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1350. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1351. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1352. DP(BNX2X_MSG_SP,
  1353. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1354. fp->index, cid, command, bp->state,
  1355. rr_cqe->ramrod_cqe.ramrod_type);
  1356. switch (command) {
  1357. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1358. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1359. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1360. break;
  1361. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1362. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1363. drv_cmd = BNX2X_Q_CMD_SETUP;
  1364. break;
  1365. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1366. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1367. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1368. break;
  1369. case (RAMROD_CMD_ID_ETH_HALT):
  1370. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1371. drv_cmd = BNX2X_Q_CMD_HALT;
  1372. break;
  1373. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1374. DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
  1375. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1376. break;
  1377. case (RAMROD_CMD_ID_ETH_EMPTY):
  1378. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1379. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1380. break;
  1381. default:
  1382. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1383. command, fp->index);
  1384. return;
  1385. }
  1386. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1387. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1388. /* q_obj->complete_cmd() failure means that this was
  1389. * an unexpected completion.
  1390. *
  1391. * In this case we don't want to increase the bp->spq_left
  1392. * because apparently we haven't sent this command the first
  1393. * place.
  1394. */
  1395. #ifdef BNX2X_STOP_ON_ERROR
  1396. bnx2x_panic();
  1397. #else
  1398. return;
  1399. #endif
  1400. smp_mb__before_atomic_inc();
  1401. atomic_inc(&bp->cq_spq_left);
  1402. /* push the change in bp->spq_left and towards the memory */
  1403. smp_mb__after_atomic_inc();
  1404. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1405. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1406. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1407. /* if Q update ramrod is completed for last Q in AFEX vif set
  1408. * flow, then ACK MCP at the end
  1409. *
  1410. * mark pending ACK to MCP bit.
  1411. * prevent case that both bits are cleared.
  1412. * At the end of load/unload driver checks that
  1413. * sp_state is cleaerd, and this order prevents
  1414. * races
  1415. */
  1416. smp_mb__before_clear_bit();
  1417. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1418. wmb();
  1419. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1420. smp_mb__after_clear_bit();
  1421. /* schedule workqueue to send ack to MCP */
  1422. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1423. }
  1424. return;
  1425. }
  1426. void bnx2x_update_rx_prod(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  1427. u16 bd_prod, u16 rx_comp_prod, u16 rx_sge_prod)
  1428. {
  1429. u32 start = BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset;
  1430. bnx2x_update_rx_prod_gen(bp, fp, bd_prod, rx_comp_prod, rx_sge_prod,
  1431. start);
  1432. }
  1433. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1434. {
  1435. struct bnx2x *bp = netdev_priv(dev_instance);
  1436. u16 status = bnx2x_ack_int(bp);
  1437. u16 mask;
  1438. int i;
  1439. u8 cos;
  1440. /* Return here if interrupt is shared and it's not for us */
  1441. if (unlikely(status == 0)) {
  1442. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1443. return IRQ_NONE;
  1444. }
  1445. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1446. #ifdef BNX2X_STOP_ON_ERROR
  1447. if (unlikely(bp->panic))
  1448. return IRQ_HANDLED;
  1449. #endif
  1450. for_each_eth_queue(bp, i) {
  1451. struct bnx2x_fastpath *fp = &bp->fp[i];
  1452. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1453. if (status & mask) {
  1454. /* Handle Rx or Tx according to SB id */
  1455. prefetch(fp->rx_cons_sb);
  1456. for_each_cos_in_tx_queue(fp, cos)
  1457. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1458. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1459. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1460. status &= ~mask;
  1461. }
  1462. }
  1463. if (CNIC_SUPPORT(bp)) {
  1464. mask = 0x2;
  1465. if (status & (mask | 0x1)) {
  1466. struct cnic_ops *c_ops = NULL;
  1467. if (likely(bp->state == BNX2X_STATE_OPEN)) {
  1468. rcu_read_lock();
  1469. c_ops = rcu_dereference(bp->cnic_ops);
  1470. if (c_ops)
  1471. c_ops->cnic_handler(bp->cnic_data,
  1472. NULL);
  1473. rcu_read_unlock();
  1474. }
  1475. status &= ~mask;
  1476. }
  1477. }
  1478. if (unlikely(status & 0x1)) {
  1479. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1480. status &= ~0x1;
  1481. if (!status)
  1482. return IRQ_HANDLED;
  1483. }
  1484. if (unlikely(status))
  1485. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1486. status);
  1487. return IRQ_HANDLED;
  1488. }
  1489. /* Link */
  1490. /*
  1491. * General service functions
  1492. */
  1493. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1494. {
  1495. u32 lock_status;
  1496. u32 resource_bit = (1 << resource);
  1497. int func = BP_FUNC(bp);
  1498. u32 hw_lock_control_reg;
  1499. int cnt;
  1500. /* Validating that the resource is within range */
  1501. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1502. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1503. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1504. return -EINVAL;
  1505. }
  1506. if (func <= 5) {
  1507. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1508. } else {
  1509. hw_lock_control_reg =
  1510. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1511. }
  1512. /* Validating that the resource is not already taken */
  1513. lock_status = REG_RD(bp, hw_lock_control_reg);
  1514. if (lock_status & resource_bit) {
  1515. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1516. lock_status, resource_bit);
  1517. return -EEXIST;
  1518. }
  1519. /* Try for 5 second every 5ms */
  1520. for (cnt = 0; cnt < 1000; cnt++) {
  1521. /* Try to acquire the lock */
  1522. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1523. lock_status = REG_RD(bp, hw_lock_control_reg);
  1524. if (lock_status & resource_bit)
  1525. return 0;
  1526. msleep(5);
  1527. }
  1528. BNX2X_ERR("Timeout\n");
  1529. return -EAGAIN;
  1530. }
  1531. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1532. {
  1533. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1534. }
  1535. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1536. {
  1537. u32 lock_status;
  1538. u32 resource_bit = (1 << resource);
  1539. int func = BP_FUNC(bp);
  1540. u32 hw_lock_control_reg;
  1541. /* Validating that the resource is within range */
  1542. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1543. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1544. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1545. return -EINVAL;
  1546. }
  1547. if (func <= 5) {
  1548. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1549. } else {
  1550. hw_lock_control_reg =
  1551. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1552. }
  1553. /* Validating that the resource is currently taken */
  1554. lock_status = REG_RD(bp, hw_lock_control_reg);
  1555. if (!(lock_status & resource_bit)) {
  1556. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
  1557. lock_status, resource_bit);
  1558. return -EFAULT;
  1559. }
  1560. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1561. return 0;
  1562. }
  1563. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1564. {
  1565. /* The GPIO should be swapped if swap register is set and active */
  1566. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1567. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1568. int gpio_shift = gpio_num +
  1569. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1570. u32 gpio_mask = (1 << gpio_shift);
  1571. u32 gpio_reg;
  1572. int value;
  1573. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1574. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1575. return -EINVAL;
  1576. }
  1577. /* read GPIO value */
  1578. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1579. /* get the requested pin value */
  1580. if ((gpio_reg & gpio_mask) == gpio_mask)
  1581. value = 1;
  1582. else
  1583. value = 0;
  1584. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1585. return value;
  1586. }
  1587. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1588. {
  1589. /* The GPIO should be swapped if swap register is set and active */
  1590. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1591. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1592. int gpio_shift = gpio_num +
  1593. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1594. u32 gpio_mask = (1 << gpio_shift);
  1595. u32 gpio_reg;
  1596. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1597. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1598. return -EINVAL;
  1599. }
  1600. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1601. /* read GPIO and mask except the float bits */
  1602. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1603. switch (mode) {
  1604. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1605. DP(NETIF_MSG_LINK,
  1606. "Set GPIO %d (shift %d) -> output low\n",
  1607. gpio_num, gpio_shift);
  1608. /* clear FLOAT and set CLR */
  1609. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1610. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1611. break;
  1612. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1613. DP(NETIF_MSG_LINK,
  1614. "Set GPIO %d (shift %d) -> output high\n",
  1615. gpio_num, gpio_shift);
  1616. /* clear FLOAT and set SET */
  1617. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1618. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1619. break;
  1620. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1621. DP(NETIF_MSG_LINK,
  1622. "Set GPIO %d (shift %d) -> input\n",
  1623. gpio_num, gpio_shift);
  1624. /* set FLOAT */
  1625. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1626. break;
  1627. default:
  1628. break;
  1629. }
  1630. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1631. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1632. return 0;
  1633. }
  1634. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1635. {
  1636. u32 gpio_reg = 0;
  1637. int rc = 0;
  1638. /* Any port swapping should be handled by caller. */
  1639. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1640. /* read GPIO and mask except the float bits */
  1641. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1642. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1643. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1644. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1645. switch (mode) {
  1646. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1647. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1648. /* set CLR */
  1649. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1650. break;
  1651. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1652. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1653. /* set SET */
  1654. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1655. break;
  1656. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1657. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1658. /* set FLOAT */
  1659. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1660. break;
  1661. default:
  1662. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1663. rc = -EINVAL;
  1664. break;
  1665. }
  1666. if (rc == 0)
  1667. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1668. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1669. return rc;
  1670. }
  1671. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1672. {
  1673. /* The GPIO should be swapped if swap register is set and active */
  1674. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1675. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1676. int gpio_shift = gpio_num +
  1677. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1678. u32 gpio_mask = (1 << gpio_shift);
  1679. u32 gpio_reg;
  1680. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1681. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1682. return -EINVAL;
  1683. }
  1684. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1685. /* read GPIO int */
  1686. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1687. switch (mode) {
  1688. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1689. DP(NETIF_MSG_LINK,
  1690. "Clear GPIO INT %d (shift %d) -> output low\n",
  1691. gpio_num, gpio_shift);
  1692. /* clear SET and set CLR */
  1693. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1694. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1695. break;
  1696. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1697. DP(NETIF_MSG_LINK,
  1698. "Set GPIO INT %d (shift %d) -> output high\n",
  1699. gpio_num, gpio_shift);
  1700. /* clear CLR and set SET */
  1701. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1702. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1703. break;
  1704. default:
  1705. break;
  1706. }
  1707. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1708. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1709. return 0;
  1710. }
  1711. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1712. {
  1713. u32 spio_reg;
  1714. /* Only 2 SPIOs are configurable */
  1715. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1716. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1717. return -EINVAL;
  1718. }
  1719. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1720. /* read SPIO and mask except the float bits */
  1721. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1722. switch (mode) {
  1723. case MISC_SPIO_OUTPUT_LOW:
  1724. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1725. /* clear FLOAT and set CLR */
  1726. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1727. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1728. break;
  1729. case MISC_SPIO_OUTPUT_HIGH:
  1730. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1731. /* clear FLOAT and set SET */
  1732. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1733. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1734. break;
  1735. case MISC_SPIO_INPUT_HI_Z:
  1736. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1737. /* set FLOAT */
  1738. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1739. break;
  1740. default:
  1741. break;
  1742. }
  1743. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1744. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1745. return 0;
  1746. }
  1747. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1748. {
  1749. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1750. switch (bp->link_vars.ieee_fc &
  1751. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1752. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1753. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1754. ADVERTISED_Pause);
  1755. break;
  1756. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1757. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1758. ADVERTISED_Pause);
  1759. break;
  1760. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1761. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1762. break;
  1763. default:
  1764. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1765. ADVERTISED_Pause);
  1766. break;
  1767. }
  1768. }
  1769. u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1770. {
  1771. if (!BP_NOMCP(bp)) {
  1772. u8 rc;
  1773. int cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1774. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1775. /*
  1776. * Initialize link parameters structure variables
  1777. * It is recommended to turn off RX FC for jumbo frames
  1778. * for better performance
  1779. */
  1780. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1781. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1782. else
  1783. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1784. bnx2x_acquire_phy_lock(bp);
  1785. if (load_mode == LOAD_DIAG) {
  1786. struct link_params *lp = &bp->link_params;
  1787. lp->loopback_mode = LOOPBACK_XGXS;
  1788. /* do PHY loopback at 10G speed, if possible */
  1789. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1790. if (lp->speed_cap_mask[cfx_idx] &
  1791. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1792. lp->req_line_speed[cfx_idx] =
  1793. SPEED_10000;
  1794. else
  1795. lp->req_line_speed[cfx_idx] =
  1796. SPEED_1000;
  1797. }
  1798. }
  1799. if (load_mode == LOAD_LOOPBACK_EXT) {
  1800. struct link_params *lp = &bp->link_params;
  1801. lp->loopback_mode = LOOPBACK_EXT;
  1802. }
  1803. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1804. bnx2x_release_phy_lock(bp);
  1805. bnx2x_calc_fc_adv(bp);
  1806. if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) {
  1807. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1808. bnx2x_link_report(bp);
  1809. } else
  1810. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1811. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1812. return rc;
  1813. }
  1814. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1815. return -EINVAL;
  1816. }
  1817. void bnx2x_link_set(struct bnx2x *bp)
  1818. {
  1819. if (!BP_NOMCP(bp)) {
  1820. bnx2x_acquire_phy_lock(bp);
  1821. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1822. bnx2x_release_phy_lock(bp);
  1823. bnx2x_calc_fc_adv(bp);
  1824. } else
  1825. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1826. }
  1827. static void bnx2x__link_reset(struct bnx2x *bp)
  1828. {
  1829. if (!BP_NOMCP(bp)) {
  1830. bnx2x_acquire_phy_lock(bp);
  1831. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  1832. bnx2x_release_phy_lock(bp);
  1833. } else
  1834. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1835. }
  1836. void bnx2x_force_link_reset(struct bnx2x *bp)
  1837. {
  1838. bnx2x_acquire_phy_lock(bp);
  1839. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1840. bnx2x_release_phy_lock(bp);
  1841. }
  1842. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  1843. {
  1844. u8 rc = 0;
  1845. if (!BP_NOMCP(bp)) {
  1846. bnx2x_acquire_phy_lock(bp);
  1847. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  1848. is_serdes);
  1849. bnx2x_release_phy_lock(bp);
  1850. } else
  1851. BNX2X_ERR("Bootcode is missing - can not test link\n");
  1852. return rc;
  1853. }
  1854. /* Calculates the sum of vn_min_rates.
  1855. It's needed for further normalizing of the min_rates.
  1856. Returns:
  1857. sum of vn_min_rates.
  1858. or
  1859. 0 - if all the min_rates are 0.
  1860. In the later case fainess algorithm should be deactivated.
  1861. If not all min_rates are zero then those that are zeroes will be set to 1.
  1862. */
  1863. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  1864. struct cmng_init_input *input)
  1865. {
  1866. int all_zero = 1;
  1867. int vn;
  1868. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1869. u32 vn_cfg = bp->mf_config[vn];
  1870. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  1871. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  1872. /* Skip hidden vns */
  1873. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  1874. vn_min_rate = 0;
  1875. /* If min rate is zero - set it to 1 */
  1876. else if (!vn_min_rate)
  1877. vn_min_rate = DEF_MIN_RATE;
  1878. else
  1879. all_zero = 0;
  1880. input->vnic_min_rate[vn] = vn_min_rate;
  1881. }
  1882. /* if ETS or all min rates are zeros - disable fairness */
  1883. if (BNX2X_IS_ETS_ENABLED(bp)) {
  1884. input->flags.cmng_enables &=
  1885. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1886. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  1887. } else if (all_zero) {
  1888. input->flags.cmng_enables &=
  1889. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1890. DP(NETIF_MSG_IFUP,
  1891. "All MIN values are zeroes fairness will be disabled\n");
  1892. } else
  1893. input->flags.cmng_enables |=
  1894. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1895. }
  1896. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  1897. struct cmng_init_input *input)
  1898. {
  1899. u16 vn_max_rate;
  1900. u32 vn_cfg = bp->mf_config[vn];
  1901. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  1902. vn_max_rate = 0;
  1903. else {
  1904. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  1905. if (IS_MF_SI(bp)) {
  1906. /* maxCfg in percents of linkspeed */
  1907. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  1908. } else /* SD modes */
  1909. /* maxCfg is absolute in 100Mb units */
  1910. vn_max_rate = maxCfg * 100;
  1911. }
  1912. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  1913. input->vnic_max_rate[vn] = vn_max_rate;
  1914. }
  1915. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  1916. {
  1917. if (CHIP_REV_IS_SLOW(bp))
  1918. return CMNG_FNS_NONE;
  1919. if (IS_MF(bp))
  1920. return CMNG_FNS_MINMAX;
  1921. return CMNG_FNS_NONE;
  1922. }
  1923. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  1924. {
  1925. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  1926. if (BP_NOMCP(bp))
  1927. return; /* what should be the default bvalue in this case */
  1928. /* For 2 port configuration the absolute function number formula
  1929. * is:
  1930. * abs_func = 2 * vn + BP_PORT + BP_PATH
  1931. *
  1932. * and there are 4 functions per port
  1933. *
  1934. * For 4 port configuration it is
  1935. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  1936. *
  1937. * and there are 2 functions per port
  1938. */
  1939. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1940. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  1941. if (func >= E1H_FUNC_MAX)
  1942. break;
  1943. bp->mf_config[vn] =
  1944. MF_CFG_RD(bp, func_mf_config[func].config);
  1945. }
  1946. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  1947. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  1948. bp->flags |= MF_FUNC_DIS;
  1949. } else {
  1950. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  1951. bp->flags &= ~MF_FUNC_DIS;
  1952. }
  1953. }
  1954. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  1955. {
  1956. struct cmng_init_input input;
  1957. memset(&input, 0, sizeof(struct cmng_init_input));
  1958. input.port_rate = bp->link_vars.line_speed;
  1959. if (cmng_type == CMNG_FNS_MINMAX) {
  1960. int vn;
  1961. /* read mf conf from shmem */
  1962. if (read_cfg)
  1963. bnx2x_read_mf_cfg(bp);
  1964. /* vn_weight_sum and enable fairness if not 0 */
  1965. bnx2x_calc_vn_min(bp, &input);
  1966. /* calculate and set min-max rate for each vn */
  1967. if (bp->port.pmf)
  1968. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  1969. bnx2x_calc_vn_max(bp, vn, &input);
  1970. /* always enable rate shaping and fairness */
  1971. input.flags.cmng_enables |=
  1972. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  1973. bnx2x_init_cmng(&input, &bp->cmng);
  1974. return;
  1975. }
  1976. /* rate shaping and fairness are disabled */
  1977. DP(NETIF_MSG_IFUP,
  1978. "rate shaping and fairness are disabled\n");
  1979. }
  1980. static void storm_memset_cmng(struct bnx2x *bp,
  1981. struct cmng_init *cmng,
  1982. u8 port)
  1983. {
  1984. int vn;
  1985. size_t size = sizeof(struct cmng_struct_per_port);
  1986. u32 addr = BAR_XSTRORM_INTMEM +
  1987. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  1988. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  1989. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1990. int func = func_by_vn(bp, vn);
  1991. addr = BAR_XSTRORM_INTMEM +
  1992. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  1993. size = sizeof(struct rate_shaping_vars_per_vn);
  1994. __storm_memset_struct(bp, addr, size,
  1995. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  1996. addr = BAR_XSTRORM_INTMEM +
  1997. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  1998. size = sizeof(struct fairness_vars_per_vn);
  1999. __storm_memset_struct(bp, addr, size,
  2000. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2001. }
  2002. }
  2003. /* This function is called upon link interrupt */
  2004. static void bnx2x_link_attn(struct bnx2x *bp)
  2005. {
  2006. /* Make sure that we are synced with the current statistics */
  2007. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2008. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2009. if (bp->link_vars.link_up) {
  2010. /* dropless flow control */
  2011. if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
  2012. int port = BP_PORT(bp);
  2013. u32 pause_enabled = 0;
  2014. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  2015. pause_enabled = 1;
  2016. REG_WR(bp, BAR_USTRORM_INTMEM +
  2017. USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
  2018. pause_enabled);
  2019. }
  2020. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2021. struct host_port_stats *pstats;
  2022. pstats = bnx2x_sp(bp, port_stats);
  2023. /* reset old mac stats */
  2024. memset(&(pstats->mac_stx[0]), 0,
  2025. sizeof(struct mac_stx));
  2026. }
  2027. if (bp->state == BNX2X_STATE_OPEN)
  2028. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2029. }
  2030. if (bp->link_vars.link_up && bp->link_vars.line_speed) {
  2031. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2032. if (cmng_fns != CMNG_FNS_NONE) {
  2033. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2034. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2035. } else
  2036. /* rate shaping and fairness are disabled */
  2037. DP(NETIF_MSG_IFUP,
  2038. "single function mode without fairness\n");
  2039. }
  2040. __bnx2x_link_report(bp);
  2041. if (IS_MF(bp))
  2042. bnx2x_link_sync_notify(bp);
  2043. }
  2044. void bnx2x__link_status_update(struct bnx2x *bp)
  2045. {
  2046. if (bp->state != BNX2X_STATE_OPEN)
  2047. return;
  2048. /* read updated dcb configuration */
  2049. bnx2x_dcbx_pmf_update(bp);
  2050. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2051. if (bp->link_vars.link_up)
  2052. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2053. else
  2054. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2055. /* indicate link status */
  2056. bnx2x_link_report(bp);
  2057. }
  2058. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2059. u16 vlan_val, u8 allowed_prio)
  2060. {
  2061. struct bnx2x_func_state_params func_params = {0};
  2062. struct bnx2x_func_afex_update_params *f_update_params =
  2063. &func_params.params.afex_update;
  2064. func_params.f_obj = &bp->func_obj;
  2065. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2066. /* no need to wait for RAMROD completion, so don't
  2067. * set RAMROD_COMP_WAIT flag
  2068. */
  2069. f_update_params->vif_id = vifid;
  2070. f_update_params->afex_default_vlan = vlan_val;
  2071. f_update_params->allowed_priorities = allowed_prio;
  2072. /* if ramrod can not be sent, response to MCP immediately */
  2073. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2074. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2075. return 0;
  2076. }
  2077. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2078. u16 vif_index, u8 func_bit_map)
  2079. {
  2080. struct bnx2x_func_state_params func_params = {0};
  2081. struct bnx2x_func_afex_viflists_params *update_params =
  2082. &func_params.params.afex_viflists;
  2083. int rc;
  2084. u32 drv_msg_code;
  2085. /* validate only LIST_SET and LIST_GET are received from switch */
  2086. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2087. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2088. cmd_type);
  2089. func_params.f_obj = &bp->func_obj;
  2090. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2091. /* set parameters according to cmd_type */
  2092. update_params->afex_vif_list_command = cmd_type;
  2093. update_params->vif_list_index = cpu_to_le16(vif_index);
  2094. update_params->func_bit_map =
  2095. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2096. update_params->func_to_clear = 0;
  2097. drv_msg_code =
  2098. (cmd_type == VIF_LIST_RULE_GET) ?
  2099. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2100. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2101. /* if ramrod can not be sent, respond to MCP immediately for
  2102. * SET and GET requests (other are not triggered from MCP)
  2103. */
  2104. rc = bnx2x_func_state_change(bp, &func_params);
  2105. if (rc < 0)
  2106. bnx2x_fw_command(bp, drv_msg_code, 0);
  2107. return 0;
  2108. }
  2109. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2110. {
  2111. struct afex_stats afex_stats;
  2112. u32 func = BP_ABS_FUNC(bp);
  2113. u32 mf_config;
  2114. u16 vlan_val;
  2115. u32 vlan_prio;
  2116. u16 vif_id;
  2117. u8 allowed_prio;
  2118. u8 vlan_mode;
  2119. u32 addr_to_write, vifid, addrs, stats_type, i;
  2120. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2121. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2122. DP(BNX2X_MSG_MCP,
  2123. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2124. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2125. }
  2126. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2127. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2128. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2129. DP(BNX2X_MSG_MCP,
  2130. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2131. vifid, addrs);
  2132. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2133. addrs);
  2134. }
  2135. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2136. addr_to_write = SHMEM2_RD(bp,
  2137. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2138. stats_type = SHMEM2_RD(bp,
  2139. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2140. DP(BNX2X_MSG_MCP,
  2141. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2142. addr_to_write);
  2143. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2144. /* write response to scratchpad, for MCP */
  2145. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2146. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2147. *(((u32 *)(&afex_stats))+i));
  2148. /* send ack message to MCP */
  2149. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2150. }
  2151. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2152. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2153. bp->mf_config[BP_VN(bp)] = mf_config;
  2154. DP(BNX2X_MSG_MCP,
  2155. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2156. mf_config);
  2157. /* if VIF_SET is "enabled" */
  2158. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2159. /* set rate limit directly to internal RAM */
  2160. struct cmng_init_input cmng_input;
  2161. struct rate_shaping_vars_per_vn m_rs_vn;
  2162. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2163. u32 addr = BAR_XSTRORM_INTMEM +
  2164. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2165. bp->mf_config[BP_VN(bp)] = mf_config;
  2166. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2167. m_rs_vn.vn_counter.rate =
  2168. cmng_input.vnic_max_rate[BP_VN(bp)];
  2169. m_rs_vn.vn_counter.quota =
  2170. (m_rs_vn.vn_counter.rate *
  2171. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2172. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2173. /* read relevant values from mf_cfg struct in shmem */
  2174. vif_id =
  2175. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2176. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2177. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2178. vlan_val =
  2179. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2180. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2181. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2182. vlan_prio = (mf_config &
  2183. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2184. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2185. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2186. vlan_mode =
  2187. (MF_CFG_RD(bp,
  2188. func_mf_config[func].afex_config) &
  2189. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2190. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2191. allowed_prio =
  2192. (MF_CFG_RD(bp,
  2193. func_mf_config[func].afex_config) &
  2194. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2195. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2196. /* send ramrod to FW, return in case of failure */
  2197. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2198. allowed_prio))
  2199. return;
  2200. bp->afex_def_vlan_tag = vlan_val;
  2201. bp->afex_vlan_mode = vlan_mode;
  2202. } else {
  2203. /* notify link down because BP->flags is disabled */
  2204. bnx2x_link_report(bp);
  2205. /* send INVALID VIF ramrod to FW */
  2206. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2207. /* Reset the default afex VLAN */
  2208. bp->afex_def_vlan_tag = -1;
  2209. }
  2210. }
  2211. }
  2212. static void bnx2x_pmf_update(struct bnx2x *bp)
  2213. {
  2214. int port = BP_PORT(bp);
  2215. u32 val;
  2216. bp->port.pmf = 1;
  2217. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2218. /*
  2219. * We need the mb() to ensure the ordering between the writing to
  2220. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2221. */
  2222. smp_mb();
  2223. /* queue a periodic task */
  2224. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2225. bnx2x_dcbx_pmf_update(bp);
  2226. /* enable nig attention */
  2227. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2228. if (bp->common.int_block == INT_BLOCK_HC) {
  2229. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2230. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2231. } else if (!CHIP_IS_E1x(bp)) {
  2232. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2233. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2234. }
  2235. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2236. }
  2237. /* end of Link */
  2238. /* slow path */
  2239. /*
  2240. * General service functions
  2241. */
  2242. /* send the MCP a request, block until there is a reply */
  2243. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2244. {
  2245. int mb_idx = BP_FW_MB_IDX(bp);
  2246. u32 seq;
  2247. u32 rc = 0;
  2248. u32 cnt = 1;
  2249. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2250. mutex_lock(&bp->fw_mb_mutex);
  2251. seq = ++bp->fw_seq;
  2252. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2253. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2254. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2255. (command | seq), param);
  2256. do {
  2257. /* let the FW do it's magic ... */
  2258. msleep(delay);
  2259. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2260. /* Give the FW up to 5 second (500*10ms) */
  2261. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2262. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2263. cnt*delay, rc, seq);
  2264. /* is this a reply to our command? */
  2265. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2266. rc &= FW_MSG_CODE_MASK;
  2267. else {
  2268. /* FW BUG! */
  2269. BNX2X_ERR("FW failed to respond!\n");
  2270. bnx2x_fw_dump(bp);
  2271. rc = 0;
  2272. }
  2273. mutex_unlock(&bp->fw_mb_mutex);
  2274. return rc;
  2275. }
  2276. static void storm_memset_func_cfg(struct bnx2x *bp,
  2277. struct tstorm_eth_function_common_config *tcfg,
  2278. u16 abs_fid)
  2279. {
  2280. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2281. u32 addr = BAR_TSTRORM_INTMEM +
  2282. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2283. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2284. }
  2285. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2286. {
  2287. if (CHIP_IS_E1x(bp)) {
  2288. struct tstorm_eth_function_common_config tcfg = {0};
  2289. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2290. }
  2291. /* Enable the function in the FW */
  2292. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2293. storm_memset_func_en(bp, p->func_id, 1);
  2294. /* spq */
  2295. if (p->func_flgs & FUNC_FLG_SPQ) {
  2296. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2297. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2298. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2299. }
  2300. }
  2301. /**
  2302. * bnx2x_get_tx_only_flags - Return common flags
  2303. *
  2304. * @bp device handle
  2305. * @fp queue handle
  2306. * @zero_stats TRUE if statistics zeroing is needed
  2307. *
  2308. * Return the flags that are common for the Tx-only and not normal connections.
  2309. */
  2310. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2311. struct bnx2x_fastpath *fp,
  2312. bool zero_stats)
  2313. {
  2314. unsigned long flags = 0;
  2315. /* PF driver will always initialize the Queue to an ACTIVE state */
  2316. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2317. /* tx only connections collect statistics (on the same index as the
  2318. * parent connection). The statistics are zeroed when the parent
  2319. * connection is initialized.
  2320. */
  2321. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2322. if (zero_stats)
  2323. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2324. return flags;
  2325. }
  2326. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2327. struct bnx2x_fastpath *fp,
  2328. bool leading)
  2329. {
  2330. unsigned long flags = 0;
  2331. /* calculate other queue flags */
  2332. if (IS_MF_SD(bp))
  2333. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2334. if (IS_FCOE_FP(fp)) {
  2335. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2336. /* For FCoE - force usage of default priority (for afex) */
  2337. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2338. }
  2339. if (!fp->disable_tpa) {
  2340. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2341. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2342. if (fp->mode == TPA_MODE_GRO)
  2343. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2344. }
  2345. if (leading) {
  2346. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2347. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2348. }
  2349. /* Always set HW VLAN stripping */
  2350. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2351. /* configure silent vlan removal */
  2352. if (IS_MF_AFEX(bp))
  2353. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2354. return flags | bnx2x_get_common_flags(bp, fp, true);
  2355. }
  2356. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2357. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2358. u8 cos)
  2359. {
  2360. gen_init->stat_id = bnx2x_stats_id(fp);
  2361. gen_init->spcl_id = fp->cl_id;
  2362. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2363. if (IS_FCOE_FP(fp))
  2364. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2365. else
  2366. gen_init->mtu = bp->dev->mtu;
  2367. gen_init->cos = cos;
  2368. }
  2369. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2370. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2371. struct bnx2x_rxq_setup_params *rxq_init)
  2372. {
  2373. u8 max_sge = 0;
  2374. u16 sge_sz = 0;
  2375. u16 tpa_agg_size = 0;
  2376. if (!fp->disable_tpa) {
  2377. pause->sge_th_lo = SGE_TH_LO(bp);
  2378. pause->sge_th_hi = SGE_TH_HI(bp);
  2379. /* validate SGE ring has enough to cross high threshold */
  2380. WARN_ON(bp->dropless_fc &&
  2381. pause->sge_th_hi + FW_PREFETCH_CNT >
  2382. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2383. tpa_agg_size = min_t(u32,
  2384. (min_t(u32, 8, MAX_SKB_FRAGS) *
  2385. SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
  2386. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2387. SGE_PAGE_SHIFT;
  2388. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2389. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2390. sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
  2391. 0xffff);
  2392. }
  2393. /* pause - not for e1 */
  2394. if (!CHIP_IS_E1(bp)) {
  2395. pause->bd_th_lo = BD_TH_LO(bp);
  2396. pause->bd_th_hi = BD_TH_HI(bp);
  2397. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2398. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2399. /*
  2400. * validate that rings have enough entries to cross
  2401. * high thresholds
  2402. */
  2403. WARN_ON(bp->dropless_fc &&
  2404. pause->bd_th_hi + FW_PREFETCH_CNT >
  2405. bp->rx_ring_size);
  2406. WARN_ON(bp->dropless_fc &&
  2407. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2408. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2409. pause->pri_map = 1;
  2410. }
  2411. /* rxq setup */
  2412. rxq_init->dscr_map = fp->rx_desc_mapping;
  2413. rxq_init->sge_map = fp->rx_sge_mapping;
  2414. rxq_init->rcq_map = fp->rx_comp_mapping;
  2415. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2416. /* This should be a maximum number of data bytes that may be
  2417. * placed on the BD (not including paddings).
  2418. */
  2419. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2420. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2421. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2422. rxq_init->tpa_agg_sz = tpa_agg_size;
  2423. rxq_init->sge_buf_sz = sge_sz;
  2424. rxq_init->max_sges_pkt = max_sge;
  2425. rxq_init->rss_engine_id = BP_FUNC(bp);
  2426. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2427. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2428. *
  2429. * For PF Clients it should be the maximum avaliable number.
  2430. * VF driver(s) may want to define it to a smaller value.
  2431. */
  2432. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2433. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2434. rxq_init->fw_sb_id = fp->fw_sb_id;
  2435. if (IS_FCOE_FP(fp))
  2436. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2437. else
  2438. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2439. /* configure silent vlan removal
  2440. * if multi function mode is afex, then mask default vlan
  2441. */
  2442. if (IS_MF_AFEX(bp)) {
  2443. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2444. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2445. }
  2446. }
  2447. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2448. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2449. u8 cos)
  2450. {
  2451. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2452. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2453. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2454. txq_init->fw_sb_id = fp->fw_sb_id;
  2455. /*
  2456. * set the tss leading client id for TX classfication ==
  2457. * leading RSS client id
  2458. */
  2459. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2460. if (IS_FCOE_FP(fp)) {
  2461. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2462. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2463. }
  2464. }
  2465. static void bnx2x_pf_init(struct bnx2x *bp)
  2466. {
  2467. struct bnx2x_func_init_params func_init = {0};
  2468. struct event_ring_data eq_data = { {0} };
  2469. u16 flags;
  2470. if (!CHIP_IS_E1x(bp)) {
  2471. /* reset IGU PF statistics: MSIX + ATTN */
  2472. /* PF */
  2473. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2474. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2475. (CHIP_MODE_IS_4_PORT(bp) ?
  2476. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2477. /* ATTN */
  2478. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2479. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2480. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2481. (CHIP_MODE_IS_4_PORT(bp) ?
  2482. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2483. }
  2484. /* function setup flags */
  2485. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2486. /* This flag is relevant for E1x only.
  2487. * E2 doesn't have a TPA configuration in a function level.
  2488. */
  2489. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2490. func_init.func_flgs = flags;
  2491. func_init.pf_id = BP_FUNC(bp);
  2492. func_init.func_id = BP_FUNC(bp);
  2493. func_init.spq_map = bp->spq_mapping;
  2494. func_init.spq_prod = bp->spq_prod_idx;
  2495. bnx2x_func_init(bp, &func_init);
  2496. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2497. /*
  2498. * Congestion management values depend on the link rate
  2499. * There is no active link so initial link rate is set to 10 Gbps.
  2500. * When the link comes up The congestion management values are
  2501. * re-calculated according to the actual link rate.
  2502. */
  2503. bp->link_vars.line_speed = SPEED_10000;
  2504. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2505. /* Only the PMF sets the HW */
  2506. if (bp->port.pmf)
  2507. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2508. /* init Event Queue */
  2509. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2510. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2511. eq_data.producer = bp->eq_prod;
  2512. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2513. eq_data.sb_id = DEF_SB_ID;
  2514. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2515. }
  2516. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2517. {
  2518. int port = BP_PORT(bp);
  2519. bnx2x_tx_disable(bp);
  2520. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2521. }
  2522. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2523. {
  2524. int port = BP_PORT(bp);
  2525. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2526. /* Tx queue should be only reenabled */
  2527. netif_tx_wake_all_queues(bp->dev);
  2528. /*
  2529. * Should not call netif_carrier_on since it will be called if the link
  2530. * is up when checking for link state
  2531. */
  2532. }
  2533. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2534. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2535. {
  2536. struct eth_stats_info *ether_stat =
  2537. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2538. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2539. ETH_STAT_INFO_VERSION_LEN);
  2540. bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2541. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2542. ether_stat->mac_local);
  2543. ether_stat->mtu_size = bp->dev->mtu;
  2544. if (bp->dev->features & NETIF_F_RXCSUM)
  2545. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2546. if (bp->dev->features & NETIF_F_TSO)
  2547. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2548. ether_stat->feature_flags |= bp->common.boot_mode;
  2549. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2550. ether_stat->txq_size = bp->tx_ring_size;
  2551. ether_stat->rxq_size = bp->rx_ring_size;
  2552. }
  2553. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2554. {
  2555. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2556. struct fcoe_stats_info *fcoe_stat =
  2557. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2558. if (!CNIC_LOADED(bp))
  2559. return;
  2560. memcpy(fcoe_stat->mac_local + MAC_LEADING_ZERO_CNT,
  2561. bp->fip_mac, ETH_ALEN);
  2562. fcoe_stat->qos_priority =
  2563. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2564. /* insert FCoE stats from ramrod response */
  2565. if (!NO_FCOE(bp)) {
  2566. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2567. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2568. tstorm_queue_statistics;
  2569. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2570. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2571. xstorm_queue_statistics;
  2572. struct fcoe_statistics_params *fw_fcoe_stat =
  2573. &bp->fw_stats_data->fcoe;
  2574. ADD_64(fcoe_stat->rx_bytes_hi, 0, fcoe_stat->rx_bytes_lo,
  2575. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2576. ADD_64(fcoe_stat->rx_bytes_hi,
  2577. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2578. fcoe_stat->rx_bytes_lo,
  2579. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2580. ADD_64(fcoe_stat->rx_bytes_hi,
  2581. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2582. fcoe_stat->rx_bytes_lo,
  2583. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2584. ADD_64(fcoe_stat->rx_bytes_hi,
  2585. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2586. fcoe_stat->rx_bytes_lo,
  2587. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2588. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2589. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2590. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2591. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2592. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2593. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2594. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2595. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2596. ADD_64(fcoe_stat->tx_bytes_hi, 0, fcoe_stat->tx_bytes_lo,
  2597. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2598. ADD_64(fcoe_stat->tx_bytes_hi,
  2599. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2600. fcoe_stat->tx_bytes_lo,
  2601. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2602. ADD_64(fcoe_stat->tx_bytes_hi,
  2603. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2604. fcoe_stat->tx_bytes_lo,
  2605. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2606. ADD_64(fcoe_stat->tx_bytes_hi,
  2607. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2608. fcoe_stat->tx_bytes_lo,
  2609. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2610. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2611. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2612. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2613. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2614. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2615. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2616. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2617. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2618. }
  2619. /* ask L5 driver to add data to the struct */
  2620. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2621. }
  2622. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2623. {
  2624. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2625. struct iscsi_stats_info *iscsi_stat =
  2626. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2627. if (!CNIC_LOADED(bp))
  2628. return;
  2629. memcpy(iscsi_stat->mac_local + MAC_LEADING_ZERO_CNT,
  2630. bp->cnic_eth_dev.iscsi_mac, ETH_ALEN);
  2631. iscsi_stat->qos_priority =
  2632. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2633. /* ask L5 driver to add data to the struct */
  2634. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2635. }
  2636. /* called due to MCP event (on pmf):
  2637. * reread new bandwidth configuration
  2638. * configure FW
  2639. * notify others function about the change
  2640. */
  2641. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2642. {
  2643. if (bp->link_vars.link_up) {
  2644. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2645. bnx2x_link_sync_notify(bp);
  2646. }
  2647. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2648. }
  2649. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2650. {
  2651. bnx2x_config_mf_bw(bp);
  2652. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2653. }
  2654. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2655. {
  2656. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2657. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2658. }
  2659. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2660. {
  2661. enum drv_info_opcode op_code;
  2662. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2663. /* if drv_info version supported by MFW doesn't match - send NACK */
  2664. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2665. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2666. return;
  2667. }
  2668. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2669. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2670. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2671. sizeof(union drv_info_to_mcp));
  2672. switch (op_code) {
  2673. case ETH_STATS_OPCODE:
  2674. bnx2x_drv_info_ether_stat(bp);
  2675. break;
  2676. case FCOE_STATS_OPCODE:
  2677. bnx2x_drv_info_fcoe_stat(bp);
  2678. break;
  2679. case ISCSI_STATS_OPCODE:
  2680. bnx2x_drv_info_iscsi_stat(bp);
  2681. break;
  2682. default:
  2683. /* if op code isn't supported - send NACK */
  2684. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2685. return;
  2686. }
  2687. /* if we got drv_info attn from MFW then these fields are defined in
  2688. * shmem2 for sure
  2689. */
  2690. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2691. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2692. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2693. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2694. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2695. }
  2696. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2697. {
  2698. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2699. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2700. /*
  2701. * This is the only place besides the function initialization
  2702. * where the bp->flags can change so it is done without any
  2703. * locks
  2704. */
  2705. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2706. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  2707. bp->flags |= MF_FUNC_DIS;
  2708. bnx2x_e1h_disable(bp);
  2709. } else {
  2710. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  2711. bp->flags &= ~MF_FUNC_DIS;
  2712. bnx2x_e1h_enable(bp);
  2713. }
  2714. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2715. }
  2716. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2717. bnx2x_config_mf_bw(bp);
  2718. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2719. }
  2720. /* Report results to MCP */
  2721. if (dcc_event)
  2722. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2723. else
  2724. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2725. }
  2726. /* must be called under the spq lock */
  2727. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2728. {
  2729. struct eth_spe *next_spe = bp->spq_prod_bd;
  2730. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2731. bp->spq_prod_bd = bp->spq;
  2732. bp->spq_prod_idx = 0;
  2733. DP(BNX2X_MSG_SP, "end of spq\n");
  2734. } else {
  2735. bp->spq_prod_bd++;
  2736. bp->spq_prod_idx++;
  2737. }
  2738. return next_spe;
  2739. }
  2740. /* must be called under the spq lock */
  2741. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  2742. {
  2743. int func = BP_FUNC(bp);
  2744. /*
  2745. * Make sure that BD data is updated before writing the producer:
  2746. * BD data is written to the memory, the producer is read from the
  2747. * memory, thus we need a full memory barrier to ensure the ordering.
  2748. */
  2749. mb();
  2750. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2751. bp->spq_prod_idx);
  2752. mmiowb();
  2753. }
  2754. /**
  2755. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2756. *
  2757. * @cmd: command to check
  2758. * @cmd_type: command type
  2759. */
  2760. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2761. {
  2762. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2763. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  2764. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2765. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2766. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  2767. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  2768. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  2769. return true;
  2770. else
  2771. return false;
  2772. }
  2773. /**
  2774. * bnx2x_sp_post - place a single command on an SP ring
  2775. *
  2776. * @bp: driver handle
  2777. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  2778. * @cid: SW CID the command is related to
  2779. * @data_hi: command private data address (high 32 bits)
  2780. * @data_lo: command private data address (low 32 bits)
  2781. * @cmd_type: command type (e.g. NONE, ETH)
  2782. *
  2783. * SP data is handled as if it's always an address pair, thus data fields are
  2784. * not swapped to little endian in upper functions. Instead this function swaps
  2785. * data as if it's two u32 fields.
  2786. */
  2787. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  2788. u32 data_hi, u32 data_lo, int cmd_type)
  2789. {
  2790. struct eth_spe *spe;
  2791. u16 type;
  2792. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  2793. #ifdef BNX2X_STOP_ON_ERROR
  2794. if (unlikely(bp->panic)) {
  2795. BNX2X_ERR("Can't post SP when there is panic\n");
  2796. return -EIO;
  2797. }
  2798. #endif
  2799. spin_lock_bh(&bp->spq_lock);
  2800. if (common) {
  2801. if (!atomic_read(&bp->eq_spq_left)) {
  2802. BNX2X_ERR("BUG! EQ ring full!\n");
  2803. spin_unlock_bh(&bp->spq_lock);
  2804. bnx2x_panic();
  2805. return -EBUSY;
  2806. }
  2807. } else if (!atomic_read(&bp->cq_spq_left)) {
  2808. BNX2X_ERR("BUG! SPQ ring full!\n");
  2809. spin_unlock_bh(&bp->spq_lock);
  2810. bnx2x_panic();
  2811. return -EBUSY;
  2812. }
  2813. spe = bnx2x_sp_get_next(bp);
  2814. /* CID needs port number to be encoded int it */
  2815. spe->hdr.conn_and_cmd_data =
  2816. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  2817. HW_CID(bp, cid));
  2818. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  2819. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  2820. SPE_HDR_FUNCTION_ID);
  2821. spe->hdr.type = cpu_to_le16(type);
  2822. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  2823. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  2824. /*
  2825. * It's ok if the actual decrement is issued towards the memory
  2826. * somewhere between the spin_lock and spin_unlock. Thus no
  2827. * more explict memory barrier is needed.
  2828. */
  2829. if (common)
  2830. atomic_dec(&bp->eq_spq_left);
  2831. else
  2832. atomic_dec(&bp->cq_spq_left);
  2833. DP(BNX2X_MSG_SP,
  2834. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  2835. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  2836. (u32)(U64_LO(bp->spq_mapping) +
  2837. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  2838. HW_CID(bp, cid), data_hi, data_lo, type,
  2839. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  2840. bnx2x_sp_prod_update(bp);
  2841. spin_unlock_bh(&bp->spq_lock);
  2842. return 0;
  2843. }
  2844. /* acquire split MCP access lock register */
  2845. static int bnx2x_acquire_alr(struct bnx2x *bp)
  2846. {
  2847. u32 j, val;
  2848. int rc = 0;
  2849. might_sleep();
  2850. for (j = 0; j < 1000; j++) {
  2851. val = (1UL << 31);
  2852. REG_WR(bp, GRCBASE_MCP + 0x9c, val);
  2853. val = REG_RD(bp, GRCBASE_MCP + 0x9c);
  2854. if (val & (1L << 31))
  2855. break;
  2856. msleep(5);
  2857. }
  2858. if (!(val & (1L << 31))) {
  2859. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  2860. rc = -EBUSY;
  2861. }
  2862. return rc;
  2863. }
  2864. /* release split MCP access lock register */
  2865. static void bnx2x_release_alr(struct bnx2x *bp)
  2866. {
  2867. REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
  2868. }
  2869. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  2870. #define BNX2X_DEF_SB_IDX 0x0002
  2871. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  2872. {
  2873. struct host_sp_status_block *def_sb = bp->def_status_blk;
  2874. u16 rc = 0;
  2875. barrier(); /* status block is written to by the chip */
  2876. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  2877. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  2878. rc |= BNX2X_DEF_SB_ATT_IDX;
  2879. }
  2880. if (bp->def_idx != def_sb->sp_sb.running_index) {
  2881. bp->def_idx = def_sb->sp_sb.running_index;
  2882. rc |= BNX2X_DEF_SB_IDX;
  2883. }
  2884. /* Do not reorder: indecies reading should complete before handling */
  2885. barrier();
  2886. return rc;
  2887. }
  2888. /*
  2889. * slow path service functions
  2890. */
  2891. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  2892. {
  2893. int port = BP_PORT(bp);
  2894. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  2895. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  2896. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  2897. NIG_REG_MASK_INTERRUPT_PORT0;
  2898. u32 aeu_mask;
  2899. u32 nig_mask = 0;
  2900. u32 reg_addr;
  2901. if (bp->attn_state & asserted)
  2902. BNX2X_ERR("IGU ERROR\n");
  2903. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2904. aeu_mask = REG_RD(bp, aeu_addr);
  2905. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  2906. aeu_mask, asserted);
  2907. aeu_mask &= ~(asserted & 0x3ff);
  2908. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  2909. REG_WR(bp, aeu_addr, aeu_mask);
  2910. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2911. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  2912. bp->attn_state |= asserted;
  2913. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  2914. if (asserted & ATTN_HARD_WIRED_MASK) {
  2915. if (asserted & ATTN_NIG_FOR_FUNC) {
  2916. bnx2x_acquire_phy_lock(bp);
  2917. /* save nig interrupt mask */
  2918. nig_mask = REG_RD(bp, nig_int_mask_addr);
  2919. /* If nig_mask is not set, no need to call the update
  2920. * function.
  2921. */
  2922. if (nig_mask) {
  2923. REG_WR(bp, nig_int_mask_addr, 0);
  2924. bnx2x_link_attn(bp);
  2925. }
  2926. /* handle unicore attn? */
  2927. }
  2928. if (asserted & ATTN_SW_TIMER_4_FUNC)
  2929. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  2930. if (asserted & GPIO_2_FUNC)
  2931. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  2932. if (asserted & GPIO_3_FUNC)
  2933. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  2934. if (asserted & GPIO_4_FUNC)
  2935. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  2936. if (port == 0) {
  2937. if (asserted & ATTN_GENERAL_ATTN_1) {
  2938. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  2939. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  2940. }
  2941. if (asserted & ATTN_GENERAL_ATTN_2) {
  2942. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  2943. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  2944. }
  2945. if (asserted & ATTN_GENERAL_ATTN_3) {
  2946. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  2947. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  2948. }
  2949. } else {
  2950. if (asserted & ATTN_GENERAL_ATTN_4) {
  2951. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  2952. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  2953. }
  2954. if (asserted & ATTN_GENERAL_ATTN_5) {
  2955. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  2956. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  2957. }
  2958. if (asserted & ATTN_GENERAL_ATTN_6) {
  2959. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  2960. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  2961. }
  2962. }
  2963. } /* if hardwired */
  2964. if (bp->common.int_block == INT_BLOCK_HC)
  2965. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  2966. COMMAND_REG_ATTN_BITS_SET);
  2967. else
  2968. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  2969. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  2970. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  2971. REG_WR(bp, reg_addr, asserted);
  2972. /* now set back the mask */
  2973. if (asserted & ATTN_NIG_FOR_FUNC) {
  2974. REG_WR(bp, nig_int_mask_addr, nig_mask);
  2975. bnx2x_release_phy_lock(bp);
  2976. }
  2977. }
  2978. static void bnx2x_fan_failure(struct bnx2x *bp)
  2979. {
  2980. int port = BP_PORT(bp);
  2981. u32 ext_phy_config;
  2982. /* mark the failure */
  2983. ext_phy_config =
  2984. SHMEM_RD(bp,
  2985. dev_info.port_hw_config[port].external_phy_config);
  2986. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  2987. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  2988. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  2989. ext_phy_config);
  2990. /* log the failure */
  2991. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  2992. "Please contact OEM Support for assistance\n");
  2993. /*
  2994. * Scheudle device reset (unload)
  2995. * This is due to some boards consuming sufficient power when driver is
  2996. * up to overheat if fan fails.
  2997. */
  2998. smp_mb__before_clear_bit();
  2999. set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
  3000. smp_mb__after_clear_bit();
  3001. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3002. }
  3003. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3004. {
  3005. int port = BP_PORT(bp);
  3006. int reg_offset;
  3007. u32 val;
  3008. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3009. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3010. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3011. val = REG_RD(bp, reg_offset);
  3012. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3013. REG_WR(bp, reg_offset, val);
  3014. BNX2X_ERR("SPIO5 hw attention\n");
  3015. /* Fan failure attention */
  3016. bnx2x_hw_reset_phy(&bp->link_params);
  3017. bnx2x_fan_failure(bp);
  3018. }
  3019. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3020. bnx2x_acquire_phy_lock(bp);
  3021. bnx2x_handle_module_detect_int(&bp->link_params);
  3022. bnx2x_release_phy_lock(bp);
  3023. }
  3024. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3025. val = REG_RD(bp, reg_offset);
  3026. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3027. REG_WR(bp, reg_offset, val);
  3028. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3029. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3030. bnx2x_panic();
  3031. }
  3032. }
  3033. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3034. {
  3035. u32 val;
  3036. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3037. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3038. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3039. /* DORQ discard attention */
  3040. if (val & 0x2)
  3041. BNX2X_ERR("FATAL error from DORQ\n");
  3042. }
  3043. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3044. int port = BP_PORT(bp);
  3045. int reg_offset;
  3046. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3047. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3048. val = REG_RD(bp, reg_offset);
  3049. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3050. REG_WR(bp, reg_offset, val);
  3051. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3052. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3053. bnx2x_panic();
  3054. }
  3055. }
  3056. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3057. {
  3058. u32 val;
  3059. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3060. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3061. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3062. /* CFC error attention */
  3063. if (val & 0x2)
  3064. BNX2X_ERR("FATAL error from CFC\n");
  3065. }
  3066. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3067. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3068. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3069. /* RQ_USDMDP_FIFO_OVERFLOW */
  3070. if (val & 0x18000)
  3071. BNX2X_ERR("FATAL error from PXP\n");
  3072. if (!CHIP_IS_E1x(bp)) {
  3073. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3074. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3075. }
  3076. }
  3077. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3078. int port = BP_PORT(bp);
  3079. int reg_offset;
  3080. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3081. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3082. val = REG_RD(bp, reg_offset);
  3083. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3084. REG_WR(bp, reg_offset, val);
  3085. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3086. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3087. bnx2x_panic();
  3088. }
  3089. }
  3090. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3091. {
  3092. u32 val;
  3093. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3094. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3095. int func = BP_FUNC(bp);
  3096. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3097. bnx2x_read_mf_cfg(bp);
  3098. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3099. func_mf_config[BP_ABS_FUNC(bp)].config);
  3100. val = SHMEM_RD(bp,
  3101. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3102. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3103. bnx2x_dcc_event(bp,
  3104. (val & DRV_STATUS_DCC_EVENT_MASK));
  3105. if (val & DRV_STATUS_SET_MF_BW)
  3106. bnx2x_set_mf_bw(bp);
  3107. if (val & DRV_STATUS_DRV_INFO_REQ)
  3108. bnx2x_handle_drv_info_req(bp);
  3109. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3110. bnx2x_pmf_update(bp);
  3111. if (bp->port.pmf &&
  3112. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3113. bp->dcbx_enabled > 0)
  3114. /* start dcbx state machine */
  3115. bnx2x_dcbx_set_params(bp,
  3116. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3117. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3118. bnx2x_handle_afex_cmd(bp,
  3119. val & DRV_STATUS_AFEX_EVENT_MASK);
  3120. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3121. bnx2x_handle_eee_event(bp);
  3122. if (bp->link_vars.periodic_flags &
  3123. PERIODIC_FLAGS_LINK_EVENT) {
  3124. /* sync with link */
  3125. bnx2x_acquire_phy_lock(bp);
  3126. bp->link_vars.periodic_flags &=
  3127. ~PERIODIC_FLAGS_LINK_EVENT;
  3128. bnx2x_release_phy_lock(bp);
  3129. if (IS_MF(bp))
  3130. bnx2x_link_sync_notify(bp);
  3131. bnx2x_link_report(bp);
  3132. }
  3133. /* Always call it here: bnx2x_link_report() will
  3134. * prevent the link indication duplication.
  3135. */
  3136. bnx2x__link_status_update(bp);
  3137. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3138. BNX2X_ERR("MC assert!\n");
  3139. bnx2x_mc_assert(bp);
  3140. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3141. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3142. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3143. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3144. bnx2x_panic();
  3145. } else if (attn & BNX2X_MCP_ASSERT) {
  3146. BNX2X_ERR("MCP assert!\n");
  3147. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3148. bnx2x_fw_dump(bp);
  3149. } else
  3150. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3151. }
  3152. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3153. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3154. if (attn & BNX2X_GRC_TIMEOUT) {
  3155. val = CHIP_IS_E1(bp) ? 0 :
  3156. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3157. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3158. }
  3159. if (attn & BNX2X_GRC_RSV) {
  3160. val = CHIP_IS_E1(bp) ? 0 :
  3161. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3162. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3163. }
  3164. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3165. }
  3166. }
  3167. /*
  3168. * Bits map:
  3169. * 0-7 - Engine0 load counter.
  3170. * 8-15 - Engine1 load counter.
  3171. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3172. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3173. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3174. * on the engine
  3175. * 19 - Engine1 ONE_IS_LOADED.
  3176. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3177. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3178. * just the one belonging to its engine).
  3179. *
  3180. */
  3181. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3182. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3183. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3184. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3185. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3186. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3187. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3188. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3189. /*
  3190. * Set the GLOBAL_RESET bit.
  3191. *
  3192. * Should be run under rtnl lock
  3193. */
  3194. void bnx2x_set_reset_global(struct bnx2x *bp)
  3195. {
  3196. u32 val;
  3197. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3198. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3199. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3200. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3201. }
  3202. /*
  3203. * Clear the GLOBAL_RESET bit.
  3204. *
  3205. * Should be run under rtnl lock
  3206. */
  3207. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3208. {
  3209. u32 val;
  3210. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3211. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3212. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3213. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3214. }
  3215. /*
  3216. * Checks the GLOBAL_RESET bit.
  3217. *
  3218. * should be run under rtnl lock
  3219. */
  3220. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3221. {
  3222. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3223. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3224. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3225. }
  3226. /*
  3227. * Clear RESET_IN_PROGRESS bit for the current engine.
  3228. *
  3229. * Should be run under rtnl lock
  3230. */
  3231. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3232. {
  3233. u32 val;
  3234. u32 bit = BP_PATH(bp) ?
  3235. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3236. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3237. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3238. /* Clear the bit */
  3239. val &= ~bit;
  3240. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3241. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3242. }
  3243. /*
  3244. * Set RESET_IN_PROGRESS for the current engine.
  3245. *
  3246. * should be run under rtnl lock
  3247. */
  3248. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3249. {
  3250. u32 val;
  3251. u32 bit = BP_PATH(bp) ?
  3252. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3253. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3254. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3255. /* Set the bit */
  3256. val |= bit;
  3257. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3258. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3259. }
  3260. /*
  3261. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3262. * should be run under rtnl lock
  3263. */
  3264. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3265. {
  3266. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3267. u32 bit = engine ?
  3268. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3269. /* return false if bit is set */
  3270. return (val & bit) ? false : true;
  3271. }
  3272. /*
  3273. * set pf load for the current pf.
  3274. *
  3275. * should be run under rtnl lock
  3276. */
  3277. void bnx2x_set_pf_load(struct bnx2x *bp)
  3278. {
  3279. u32 val1, val;
  3280. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3281. BNX2X_PATH0_LOAD_CNT_MASK;
  3282. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3283. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3284. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3285. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3286. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3287. /* get the current counter value */
  3288. val1 = (val & mask) >> shift;
  3289. /* set bit of that PF */
  3290. val1 |= (1 << bp->pf_num);
  3291. /* clear the old value */
  3292. val &= ~mask;
  3293. /* set the new one */
  3294. val |= ((val1 << shift) & mask);
  3295. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3296. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3297. }
  3298. /**
  3299. * bnx2x_clear_pf_load - clear pf load mark
  3300. *
  3301. * @bp: driver handle
  3302. *
  3303. * Should be run under rtnl lock.
  3304. * Decrements the load counter for the current engine. Returns
  3305. * whether other functions are still loaded
  3306. */
  3307. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3308. {
  3309. u32 val1, val;
  3310. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3311. BNX2X_PATH0_LOAD_CNT_MASK;
  3312. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3313. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3314. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3315. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3316. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3317. /* get the current counter value */
  3318. val1 = (val & mask) >> shift;
  3319. /* clear bit of that PF */
  3320. val1 &= ~(1 << bp->pf_num);
  3321. /* clear the old value */
  3322. val &= ~mask;
  3323. /* set the new one */
  3324. val |= ((val1 << shift) & mask);
  3325. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3326. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3327. return val1 != 0;
  3328. }
  3329. /*
  3330. * Read the load status for the current engine.
  3331. *
  3332. * should be run under rtnl lock
  3333. */
  3334. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3335. {
  3336. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3337. BNX2X_PATH0_LOAD_CNT_MASK);
  3338. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3339. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3340. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3341. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3342. val = (val & mask) >> shift;
  3343. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3344. engine, val);
  3345. return val != 0;
  3346. }
  3347. static void _print_next_block(int idx, const char *blk)
  3348. {
  3349. pr_cont("%s%s", idx ? ", " : "", blk);
  3350. }
  3351. static int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
  3352. bool print)
  3353. {
  3354. int i = 0;
  3355. u32 cur_bit = 0;
  3356. for (i = 0; sig; i++) {
  3357. cur_bit = ((u32)0x1 << i);
  3358. if (sig & cur_bit) {
  3359. switch (cur_bit) {
  3360. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3361. if (print)
  3362. _print_next_block(par_num++, "BRB");
  3363. break;
  3364. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3365. if (print)
  3366. _print_next_block(par_num++, "PARSER");
  3367. break;
  3368. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3369. if (print)
  3370. _print_next_block(par_num++, "TSDM");
  3371. break;
  3372. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3373. if (print)
  3374. _print_next_block(par_num++,
  3375. "SEARCHER");
  3376. break;
  3377. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3378. if (print)
  3379. _print_next_block(par_num++, "TCM");
  3380. break;
  3381. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3382. if (print)
  3383. _print_next_block(par_num++, "TSEMI");
  3384. break;
  3385. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3386. if (print)
  3387. _print_next_block(par_num++, "XPB");
  3388. break;
  3389. }
  3390. /* Clear the bit */
  3391. sig &= ~cur_bit;
  3392. }
  3393. }
  3394. return par_num;
  3395. }
  3396. static int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
  3397. bool *global, bool print)
  3398. {
  3399. int i = 0;
  3400. u32 cur_bit = 0;
  3401. for (i = 0; sig; i++) {
  3402. cur_bit = ((u32)0x1 << i);
  3403. if (sig & cur_bit) {
  3404. switch (cur_bit) {
  3405. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3406. if (print)
  3407. _print_next_block(par_num++, "PBF");
  3408. break;
  3409. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3410. if (print)
  3411. _print_next_block(par_num++, "QM");
  3412. break;
  3413. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3414. if (print)
  3415. _print_next_block(par_num++, "TM");
  3416. break;
  3417. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3418. if (print)
  3419. _print_next_block(par_num++, "XSDM");
  3420. break;
  3421. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3422. if (print)
  3423. _print_next_block(par_num++, "XCM");
  3424. break;
  3425. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3426. if (print)
  3427. _print_next_block(par_num++, "XSEMI");
  3428. break;
  3429. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3430. if (print)
  3431. _print_next_block(par_num++,
  3432. "DOORBELLQ");
  3433. break;
  3434. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3435. if (print)
  3436. _print_next_block(par_num++, "NIG");
  3437. break;
  3438. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3439. if (print)
  3440. _print_next_block(par_num++,
  3441. "VAUX PCI CORE");
  3442. *global = true;
  3443. break;
  3444. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3445. if (print)
  3446. _print_next_block(par_num++, "DEBUG");
  3447. break;
  3448. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3449. if (print)
  3450. _print_next_block(par_num++, "USDM");
  3451. break;
  3452. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3453. if (print)
  3454. _print_next_block(par_num++, "UCM");
  3455. break;
  3456. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3457. if (print)
  3458. _print_next_block(par_num++, "USEMI");
  3459. break;
  3460. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3461. if (print)
  3462. _print_next_block(par_num++, "UPB");
  3463. break;
  3464. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3465. if (print)
  3466. _print_next_block(par_num++, "CSDM");
  3467. break;
  3468. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3469. if (print)
  3470. _print_next_block(par_num++, "CCM");
  3471. break;
  3472. }
  3473. /* Clear the bit */
  3474. sig &= ~cur_bit;
  3475. }
  3476. }
  3477. return par_num;
  3478. }
  3479. static int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
  3480. 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_CSEMI_PARITY_ERROR:
  3489. if (print)
  3490. _print_next_block(par_num++, "CSEMI");
  3491. break;
  3492. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3493. if (print)
  3494. _print_next_block(par_num++, "PXP");
  3495. break;
  3496. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3497. if (print)
  3498. _print_next_block(par_num++,
  3499. "PXPPCICLOCKCLIENT");
  3500. break;
  3501. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3502. if (print)
  3503. _print_next_block(par_num++, "CFC");
  3504. break;
  3505. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3506. if (print)
  3507. _print_next_block(par_num++, "CDU");
  3508. break;
  3509. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3510. if (print)
  3511. _print_next_block(par_num++, "DMAE");
  3512. break;
  3513. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3514. if (print)
  3515. _print_next_block(par_num++, "IGU");
  3516. break;
  3517. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3518. if (print)
  3519. _print_next_block(par_num++, "MISC");
  3520. break;
  3521. }
  3522. /* Clear the bit */
  3523. sig &= ~cur_bit;
  3524. }
  3525. }
  3526. return par_num;
  3527. }
  3528. static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
  3529. bool *global, bool print)
  3530. {
  3531. int i = 0;
  3532. u32 cur_bit = 0;
  3533. for (i = 0; sig; i++) {
  3534. cur_bit = ((u32)0x1 << i);
  3535. if (sig & cur_bit) {
  3536. switch (cur_bit) {
  3537. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3538. if (print)
  3539. _print_next_block(par_num++, "MCP ROM");
  3540. *global = true;
  3541. break;
  3542. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3543. if (print)
  3544. _print_next_block(par_num++,
  3545. "MCP UMP RX");
  3546. *global = true;
  3547. break;
  3548. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3549. if (print)
  3550. _print_next_block(par_num++,
  3551. "MCP UMP TX");
  3552. *global = true;
  3553. break;
  3554. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3555. if (print)
  3556. _print_next_block(par_num++,
  3557. "MCP SCPAD");
  3558. *global = true;
  3559. break;
  3560. }
  3561. /* Clear the bit */
  3562. sig &= ~cur_bit;
  3563. }
  3564. }
  3565. return par_num;
  3566. }
  3567. static int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
  3568. bool print)
  3569. {
  3570. int i = 0;
  3571. u32 cur_bit = 0;
  3572. for (i = 0; sig; i++) {
  3573. cur_bit = ((u32)0x1 << i);
  3574. if (sig & cur_bit) {
  3575. switch (cur_bit) {
  3576. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3577. if (print)
  3578. _print_next_block(par_num++, "PGLUE_B");
  3579. break;
  3580. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3581. if (print)
  3582. _print_next_block(par_num++, "ATC");
  3583. break;
  3584. }
  3585. /* Clear the bit */
  3586. sig &= ~cur_bit;
  3587. }
  3588. }
  3589. return par_num;
  3590. }
  3591. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3592. u32 *sig)
  3593. {
  3594. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3595. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3596. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3597. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3598. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3599. int par_num = 0;
  3600. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  3601. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  3602. sig[0] & HW_PRTY_ASSERT_SET_0,
  3603. sig[1] & HW_PRTY_ASSERT_SET_1,
  3604. sig[2] & HW_PRTY_ASSERT_SET_2,
  3605. sig[3] & HW_PRTY_ASSERT_SET_3,
  3606. sig[4] & HW_PRTY_ASSERT_SET_4);
  3607. if (print)
  3608. netdev_err(bp->dev,
  3609. "Parity errors detected in blocks: ");
  3610. par_num = bnx2x_check_blocks_with_parity0(
  3611. sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
  3612. par_num = bnx2x_check_blocks_with_parity1(
  3613. sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
  3614. par_num = bnx2x_check_blocks_with_parity2(
  3615. sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
  3616. par_num = bnx2x_check_blocks_with_parity3(
  3617. sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
  3618. par_num = bnx2x_check_blocks_with_parity4(
  3619. sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
  3620. if (print)
  3621. pr_cont("\n");
  3622. return true;
  3623. } else
  3624. return false;
  3625. }
  3626. /**
  3627. * bnx2x_chk_parity_attn - checks for parity attentions.
  3628. *
  3629. * @bp: driver handle
  3630. * @global: true if there was a global attention
  3631. * @print: show parity attention in syslog
  3632. */
  3633. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3634. {
  3635. struct attn_route attn = { {0} };
  3636. int port = BP_PORT(bp);
  3637. attn.sig[0] = REG_RD(bp,
  3638. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3639. port*4);
  3640. attn.sig[1] = REG_RD(bp,
  3641. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3642. port*4);
  3643. attn.sig[2] = REG_RD(bp,
  3644. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3645. port*4);
  3646. attn.sig[3] = REG_RD(bp,
  3647. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  3648. port*4);
  3649. if (!CHIP_IS_E1x(bp))
  3650. attn.sig[4] = REG_RD(bp,
  3651. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  3652. port*4);
  3653. return bnx2x_parity_attn(bp, global, print, attn.sig);
  3654. }
  3655. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  3656. {
  3657. u32 val;
  3658. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  3659. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  3660. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  3661. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  3662. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  3663. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  3664. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  3665. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  3666. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  3667. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  3668. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  3669. if (val &
  3670. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  3671. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  3672. if (val &
  3673. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  3674. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  3675. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  3676. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  3677. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  3678. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  3679. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  3680. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  3681. }
  3682. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  3683. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  3684. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  3685. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  3686. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  3687. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  3688. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  3689. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  3690. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  3691. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  3692. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  3693. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  3694. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  3695. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  3696. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  3697. }
  3698. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3699. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  3700. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  3701. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3702. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  3703. }
  3704. }
  3705. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  3706. {
  3707. struct attn_route attn, *group_mask;
  3708. int port = BP_PORT(bp);
  3709. int index;
  3710. u32 reg_addr;
  3711. u32 val;
  3712. u32 aeu_mask;
  3713. bool global = false;
  3714. /* need to take HW lock because MCP or other port might also
  3715. try to handle this event */
  3716. bnx2x_acquire_alr(bp);
  3717. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  3718. #ifndef BNX2X_STOP_ON_ERROR
  3719. bp->recovery_state = BNX2X_RECOVERY_INIT;
  3720. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3721. /* Disable HW interrupts */
  3722. bnx2x_int_disable(bp);
  3723. /* In case of parity errors don't handle attentions so that
  3724. * other function would "see" parity errors.
  3725. */
  3726. #else
  3727. bnx2x_panic();
  3728. #endif
  3729. bnx2x_release_alr(bp);
  3730. return;
  3731. }
  3732. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  3733. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  3734. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  3735. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  3736. if (!CHIP_IS_E1x(bp))
  3737. attn.sig[4] =
  3738. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  3739. else
  3740. attn.sig[4] = 0;
  3741. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  3742. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  3743. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  3744. if (deasserted & (1 << index)) {
  3745. group_mask = &bp->attn_group[index];
  3746. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  3747. index,
  3748. group_mask->sig[0], group_mask->sig[1],
  3749. group_mask->sig[2], group_mask->sig[3],
  3750. group_mask->sig[4]);
  3751. bnx2x_attn_int_deasserted4(bp,
  3752. attn.sig[4] & group_mask->sig[4]);
  3753. bnx2x_attn_int_deasserted3(bp,
  3754. attn.sig[3] & group_mask->sig[3]);
  3755. bnx2x_attn_int_deasserted1(bp,
  3756. attn.sig[1] & group_mask->sig[1]);
  3757. bnx2x_attn_int_deasserted2(bp,
  3758. attn.sig[2] & group_mask->sig[2]);
  3759. bnx2x_attn_int_deasserted0(bp,
  3760. attn.sig[0] & group_mask->sig[0]);
  3761. }
  3762. }
  3763. bnx2x_release_alr(bp);
  3764. if (bp->common.int_block == INT_BLOCK_HC)
  3765. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3766. COMMAND_REG_ATTN_BITS_CLR);
  3767. else
  3768. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  3769. val = ~deasserted;
  3770. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  3771. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3772. REG_WR(bp, reg_addr, val);
  3773. if (~bp->attn_state & deasserted)
  3774. BNX2X_ERR("IGU ERROR\n");
  3775. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3776. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3777. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3778. aeu_mask = REG_RD(bp, reg_addr);
  3779. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  3780. aeu_mask, deasserted);
  3781. aeu_mask |= (deasserted & 0x3ff);
  3782. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3783. REG_WR(bp, reg_addr, aeu_mask);
  3784. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3785. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3786. bp->attn_state &= ~deasserted;
  3787. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3788. }
  3789. static void bnx2x_attn_int(struct bnx2x *bp)
  3790. {
  3791. /* read local copy of bits */
  3792. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3793. attn_bits);
  3794. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3795. attn_bits_ack);
  3796. u32 attn_state = bp->attn_state;
  3797. /* look for changed bits */
  3798. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  3799. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  3800. DP(NETIF_MSG_HW,
  3801. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  3802. attn_bits, attn_ack, asserted, deasserted);
  3803. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  3804. BNX2X_ERR("BAD attention state\n");
  3805. /* handle bits that were raised */
  3806. if (asserted)
  3807. bnx2x_attn_int_asserted(bp, asserted);
  3808. if (deasserted)
  3809. bnx2x_attn_int_deasserted(bp, deasserted);
  3810. }
  3811. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  3812. u16 index, u8 op, u8 update)
  3813. {
  3814. u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  3815. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  3816. igu_addr);
  3817. }
  3818. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  3819. {
  3820. /* No memory barriers */
  3821. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  3822. mmiowb(); /* keep prod updates ordered */
  3823. }
  3824. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  3825. union event_ring_elem *elem)
  3826. {
  3827. u8 err = elem->message.error;
  3828. if (!bp->cnic_eth_dev.starting_cid ||
  3829. (cid < bp->cnic_eth_dev.starting_cid &&
  3830. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  3831. return 1;
  3832. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  3833. if (unlikely(err)) {
  3834. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  3835. cid);
  3836. bnx2x_panic_dump(bp);
  3837. }
  3838. bnx2x_cnic_cfc_comp(bp, cid, err);
  3839. return 0;
  3840. }
  3841. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  3842. {
  3843. struct bnx2x_mcast_ramrod_params rparam;
  3844. int rc;
  3845. memset(&rparam, 0, sizeof(rparam));
  3846. rparam.mcast_obj = &bp->mcast_obj;
  3847. netif_addr_lock_bh(bp->dev);
  3848. /* Clear pending state for the last command */
  3849. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  3850. /* If there are pending mcast commands - send them */
  3851. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  3852. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  3853. if (rc < 0)
  3854. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  3855. rc);
  3856. }
  3857. netif_addr_unlock_bh(bp->dev);
  3858. }
  3859. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  3860. union event_ring_elem *elem)
  3861. {
  3862. unsigned long ramrod_flags = 0;
  3863. int rc = 0;
  3864. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  3865. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  3866. /* Always push next commands out, don't wait here */
  3867. __set_bit(RAMROD_CONT, &ramrod_flags);
  3868. switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
  3869. case BNX2X_FILTER_MAC_PENDING:
  3870. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  3871. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  3872. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  3873. else
  3874. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  3875. break;
  3876. case BNX2X_FILTER_MCAST_PENDING:
  3877. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  3878. /* This is only relevant for 57710 where multicast MACs are
  3879. * configured as unicast MACs using the same ramrod.
  3880. */
  3881. bnx2x_handle_mcast_eqe(bp);
  3882. return;
  3883. default:
  3884. BNX2X_ERR("Unsupported classification command: %d\n",
  3885. elem->message.data.eth_event.echo);
  3886. return;
  3887. }
  3888. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  3889. if (rc < 0)
  3890. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  3891. else if (rc > 0)
  3892. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  3893. }
  3894. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  3895. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  3896. {
  3897. netif_addr_lock_bh(bp->dev);
  3898. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  3899. /* Send rx_mode command again if was requested */
  3900. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  3901. bnx2x_set_storm_rx_mode(bp);
  3902. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  3903. &bp->sp_state))
  3904. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  3905. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  3906. &bp->sp_state))
  3907. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  3908. netif_addr_unlock_bh(bp->dev);
  3909. }
  3910. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  3911. union event_ring_elem *elem)
  3912. {
  3913. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  3914. DP(BNX2X_MSG_SP,
  3915. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  3916. elem->message.data.vif_list_event.func_bit_map);
  3917. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  3918. elem->message.data.vif_list_event.func_bit_map);
  3919. } else if (elem->message.data.vif_list_event.echo ==
  3920. VIF_LIST_RULE_SET) {
  3921. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  3922. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  3923. }
  3924. }
  3925. /* called with rtnl_lock */
  3926. static void bnx2x_after_function_update(struct bnx2x *bp)
  3927. {
  3928. int q, rc;
  3929. struct bnx2x_fastpath *fp;
  3930. struct bnx2x_queue_state_params queue_params = {NULL};
  3931. struct bnx2x_queue_update_params *q_update_params =
  3932. &queue_params.params.update;
  3933. /* Send Q update command with afex vlan removal values for all Qs */
  3934. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  3935. /* set silent vlan removal values according to vlan mode */
  3936. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  3937. &q_update_params->update_flags);
  3938. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  3939. &q_update_params->update_flags);
  3940. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  3941. /* in access mode mark mask and value are 0 to strip all vlans */
  3942. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  3943. q_update_params->silent_removal_value = 0;
  3944. q_update_params->silent_removal_mask = 0;
  3945. } else {
  3946. q_update_params->silent_removal_value =
  3947. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  3948. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  3949. }
  3950. for_each_eth_queue(bp, q) {
  3951. /* Set the appropriate Queue object */
  3952. fp = &bp->fp[q];
  3953. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  3954. /* send the ramrod */
  3955. rc = bnx2x_queue_state_change(bp, &queue_params);
  3956. if (rc < 0)
  3957. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  3958. q);
  3959. }
  3960. if (!NO_FCOE(bp)) {
  3961. fp = &bp->fp[FCOE_IDX(bp)];
  3962. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  3963. /* clear pending completion bit */
  3964. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  3965. /* mark latest Q bit */
  3966. smp_mb__before_clear_bit();
  3967. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  3968. smp_mb__after_clear_bit();
  3969. /* send Q update ramrod for FCoE Q */
  3970. rc = bnx2x_queue_state_change(bp, &queue_params);
  3971. if (rc < 0)
  3972. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  3973. q);
  3974. } else {
  3975. /* If no FCoE ring - ACK MCP now */
  3976. bnx2x_link_report(bp);
  3977. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  3978. }
  3979. }
  3980. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  3981. struct bnx2x *bp, u32 cid)
  3982. {
  3983. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  3984. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  3985. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  3986. else
  3987. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  3988. }
  3989. static void bnx2x_eq_int(struct bnx2x *bp)
  3990. {
  3991. u16 hw_cons, sw_cons, sw_prod;
  3992. union event_ring_elem *elem;
  3993. u8 echo;
  3994. u32 cid;
  3995. u8 opcode;
  3996. int spqe_cnt = 0;
  3997. struct bnx2x_queue_sp_obj *q_obj;
  3998. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  3999. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4000. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4001. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4002. * when we get the the next-page we nned to adjust so the loop
  4003. * condition below will be met. The next element is the size of a
  4004. * regular element and hence incrementing by 1
  4005. */
  4006. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4007. hw_cons++;
  4008. /* This function may never run in parallel with itself for a
  4009. * specific bp, thus there is no need in "paired" read memory
  4010. * barrier here.
  4011. */
  4012. sw_cons = bp->eq_cons;
  4013. sw_prod = bp->eq_prod;
  4014. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4015. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4016. for (; sw_cons != hw_cons;
  4017. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4018. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4019. cid = SW_CID(elem->message.data.cfc_del_event.cid);
  4020. opcode = elem->message.opcode;
  4021. /* handle eq element */
  4022. switch (opcode) {
  4023. case EVENT_RING_OPCODE_STAT_QUERY:
  4024. DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
  4025. "got statistics comp event %d\n",
  4026. bp->stats_comp++);
  4027. /* nothing to do with stats comp */
  4028. goto next_spqe;
  4029. case EVENT_RING_OPCODE_CFC_DEL:
  4030. /* handle according to cid range */
  4031. /*
  4032. * we may want to verify here that the bp state is
  4033. * HALTING
  4034. */
  4035. DP(BNX2X_MSG_SP,
  4036. "got delete ramrod for MULTI[%d]\n", cid);
  4037. if (CNIC_LOADED(bp) &&
  4038. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4039. goto next_spqe;
  4040. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4041. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4042. break;
  4043. goto next_spqe;
  4044. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4045. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4046. if (f_obj->complete_cmd(bp, f_obj,
  4047. BNX2X_F_CMD_TX_STOP))
  4048. break;
  4049. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4050. goto next_spqe;
  4051. case EVENT_RING_OPCODE_START_TRAFFIC:
  4052. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4053. if (f_obj->complete_cmd(bp, f_obj,
  4054. BNX2X_F_CMD_TX_START))
  4055. break;
  4056. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4057. goto next_spqe;
  4058. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4059. echo = elem->message.data.function_update_event.echo;
  4060. if (echo == SWITCH_UPDATE) {
  4061. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4062. "got FUNC_SWITCH_UPDATE ramrod\n");
  4063. if (f_obj->complete_cmd(
  4064. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4065. break;
  4066. } else {
  4067. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4068. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4069. f_obj->complete_cmd(bp, f_obj,
  4070. BNX2X_F_CMD_AFEX_UPDATE);
  4071. /* We will perform the Queues update from
  4072. * sp_rtnl task as all Queue SP operations
  4073. * should run under rtnl_lock.
  4074. */
  4075. smp_mb__before_clear_bit();
  4076. set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
  4077. &bp->sp_rtnl_state);
  4078. smp_mb__after_clear_bit();
  4079. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4080. }
  4081. goto next_spqe;
  4082. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4083. f_obj->complete_cmd(bp, f_obj,
  4084. BNX2X_F_CMD_AFEX_VIFLISTS);
  4085. bnx2x_after_afex_vif_lists(bp, elem);
  4086. goto next_spqe;
  4087. case EVENT_RING_OPCODE_FUNCTION_START:
  4088. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4089. "got FUNC_START ramrod\n");
  4090. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4091. break;
  4092. goto next_spqe;
  4093. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4094. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4095. "got FUNC_STOP ramrod\n");
  4096. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4097. break;
  4098. goto next_spqe;
  4099. }
  4100. switch (opcode | bp->state) {
  4101. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4102. BNX2X_STATE_OPEN):
  4103. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4104. BNX2X_STATE_OPENING_WAIT4_PORT):
  4105. cid = elem->message.data.eth_event.echo &
  4106. BNX2X_SWCID_MASK;
  4107. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4108. cid);
  4109. rss_raw->clear_pending(rss_raw);
  4110. break;
  4111. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4112. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4113. case (EVENT_RING_OPCODE_SET_MAC |
  4114. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4115. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4116. BNX2X_STATE_OPEN):
  4117. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4118. BNX2X_STATE_DIAG):
  4119. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4120. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4121. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4122. bnx2x_handle_classification_eqe(bp, elem);
  4123. break;
  4124. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4125. BNX2X_STATE_OPEN):
  4126. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4127. BNX2X_STATE_DIAG):
  4128. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4129. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4130. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4131. bnx2x_handle_mcast_eqe(bp);
  4132. break;
  4133. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4134. BNX2X_STATE_OPEN):
  4135. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4136. BNX2X_STATE_DIAG):
  4137. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4138. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4139. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4140. bnx2x_handle_rx_mode_eqe(bp);
  4141. break;
  4142. default:
  4143. /* unknown event log error and continue */
  4144. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4145. elem->message.opcode, bp->state);
  4146. }
  4147. next_spqe:
  4148. spqe_cnt++;
  4149. } /* for */
  4150. smp_mb__before_atomic_inc();
  4151. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4152. bp->eq_cons = sw_cons;
  4153. bp->eq_prod = sw_prod;
  4154. /* Make sure that above mem writes were issued towards the memory */
  4155. smp_wmb();
  4156. /* update producer */
  4157. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4158. }
  4159. static void bnx2x_sp_task(struct work_struct *work)
  4160. {
  4161. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4162. u16 status;
  4163. status = bnx2x_update_dsb_idx(bp);
  4164. /* if (status == 0) */
  4165. /* BNX2X_ERR("spurious slowpath interrupt!\n"); */
  4166. DP(BNX2X_MSG_SP, "got a slowpath interrupt (status 0x%x)\n", status);
  4167. /* HW attentions */
  4168. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4169. bnx2x_attn_int(bp);
  4170. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4171. }
  4172. /* SP events: STAT_QUERY and others */
  4173. if (status & BNX2X_DEF_SB_IDX) {
  4174. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4175. if (FCOE_INIT(bp) &&
  4176. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4177. /*
  4178. * Prevent local bottom-halves from running as
  4179. * we are going to change the local NAPI list.
  4180. */
  4181. local_bh_disable();
  4182. napi_schedule(&bnx2x_fcoe(bp, napi));
  4183. local_bh_enable();
  4184. }
  4185. /* Handle EQ completions */
  4186. bnx2x_eq_int(bp);
  4187. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4188. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4189. status &= ~BNX2X_DEF_SB_IDX;
  4190. }
  4191. if (unlikely(status))
  4192. DP(BNX2X_MSG_SP, "got an unknown interrupt! (status 0x%x)\n",
  4193. status);
  4194. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4195. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4196. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4197. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4198. &bp->sp_state)) {
  4199. bnx2x_link_report(bp);
  4200. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4201. }
  4202. }
  4203. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4204. {
  4205. struct net_device *dev = dev_instance;
  4206. struct bnx2x *bp = netdev_priv(dev);
  4207. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4208. IGU_INT_DISABLE, 0);
  4209. #ifdef BNX2X_STOP_ON_ERROR
  4210. if (unlikely(bp->panic))
  4211. return IRQ_HANDLED;
  4212. #endif
  4213. if (CNIC_LOADED(bp)) {
  4214. struct cnic_ops *c_ops;
  4215. rcu_read_lock();
  4216. c_ops = rcu_dereference(bp->cnic_ops);
  4217. if (c_ops)
  4218. c_ops->cnic_handler(bp->cnic_data, NULL);
  4219. rcu_read_unlock();
  4220. }
  4221. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  4222. return IRQ_HANDLED;
  4223. }
  4224. /* end of slow path */
  4225. void bnx2x_drv_pulse(struct bnx2x *bp)
  4226. {
  4227. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4228. bp->fw_drv_pulse_wr_seq);
  4229. }
  4230. static void bnx2x_timer(unsigned long data)
  4231. {
  4232. struct bnx2x *bp = (struct bnx2x *) data;
  4233. if (!netif_running(bp->dev))
  4234. return;
  4235. if (!BP_NOMCP(bp)) {
  4236. int mb_idx = BP_FW_MB_IDX(bp);
  4237. u32 drv_pulse;
  4238. u32 mcp_pulse;
  4239. ++bp->fw_drv_pulse_wr_seq;
  4240. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4241. /* TBD - add SYSTEM_TIME */
  4242. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4243. bnx2x_drv_pulse(bp);
  4244. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4245. MCP_PULSE_SEQ_MASK);
  4246. /* The delta between driver pulse and mcp response
  4247. * should be 1 (before mcp response) or 0 (after mcp response)
  4248. */
  4249. if ((drv_pulse != mcp_pulse) &&
  4250. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  4251. /* someone lost a heartbeat... */
  4252. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4253. drv_pulse, mcp_pulse);
  4254. }
  4255. }
  4256. if (bp->state == BNX2X_STATE_OPEN)
  4257. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4258. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4259. }
  4260. /* end of Statistics */
  4261. /* nic init */
  4262. /*
  4263. * nic init service functions
  4264. */
  4265. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4266. {
  4267. u32 i;
  4268. if (!(len%4) && !(addr%4))
  4269. for (i = 0; i < len; i += 4)
  4270. REG_WR(bp, addr + i, fill);
  4271. else
  4272. for (i = 0; i < len; i++)
  4273. REG_WR8(bp, addr + i, fill);
  4274. }
  4275. /* helper: writes FP SP data to FW - data_size in dwords */
  4276. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4277. int fw_sb_id,
  4278. u32 *sb_data_p,
  4279. u32 data_size)
  4280. {
  4281. int index;
  4282. for (index = 0; index < data_size; index++)
  4283. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4284. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4285. sizeof(u32)*index,
  4286. *(sb_data_p + index));
  4287. }
  4288. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4289. {
  4290. u32 *sb_data_p;
  4291. u32 data_size = 0;
  4292. struct hc_status_block_data_e2 sb_data_e2;
  4293. struct hc_status_block_data_e1x sb_data_e1x;
  4294. /* disable the function first */
  4295. if (!CHIP_IS_E1x(bp)) {
  4296. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4297. sb_data_e2.common.state = SB_DISABLED;
  4298. sb_data_e2.common.p_func.vf_valid = false;
  4299. sb_data_p = (u32 *)&sb_data_e2;
  4300. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4301. } else {
  4302. memset(&sb_data_e1x, 0,
  4303. sizeof(struct hc_status_block_data_e1x));
  4304. sb_data_e1x.common.state = SB_DISABLED;
  4305. sb_data_e1x.common.p_func.vf_valid = false;
  4306. sb_data_p = (u32 *)&sb_data_e1x;
  4307. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4308. }
  4309. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4310. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4311. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4312. CSTORM_STATUS_BLOCK_SIZE);
  4313. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4314. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4315. CSTORM_SYNC_BLOCK_SIZE);
  4316. }
  4317. /* helper: writes SP SB data to FW */
  4318. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4319. struct hc_sp_status_block_data *sp_sb_data)
  4320. {
  4321. int func = BP_FUNC(bp);
  4322. int i;
  4323. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4324. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4325. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4326. i*sizeof(u32),
  4327. *((u32 *)sp_sb_data + i));
  4328. }
  4329. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4330. {
  4331. int func = BP_FUNC(bp);
  4332. struct hc_sp_status_block_data sp_sb_data;
  4333. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4334. sp_sb_data.state = SB_DISABLED;
  4335. sp_sb_data.p_func.vf_valid = false;
  4336. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4337. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4338. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4339. CSTORM_SP_STATUS_BLOCK_SIZE);
  4340. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4341. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4342. CSTORM_SP_SYNC_BLOCK_SIZE);
  4343. }
  4344. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4345. int igu_sb_id, int igu_seg_id)
  4346. {
  4347. hc_sm->igu_sb_id = igu_sb_id;
  4348. hc_sm->igu_seg_id = igu_seg_id;
  4349. hc_sm->timer_value = 0xFF;
  4350. hc_sm->time_to_expire = 0xFFFFFFFF;
  4351. }
  4352. /* allocates state machine ids. */
  4353. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4354. {
  4355. /* zero out state machine indices */
  4356. /* rx indices */
  4357. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4358. /* tx indices */
  4359. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4360. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4361. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4362. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4363. /* map indices */
  4364. /* rx indices */
  4365. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4366. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4367. /* tx indices */
  4368. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4369. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4370. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4371. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4372. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4373. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4374. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4375. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4376. }
  4377. static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4378. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4379. {
  4380. int igu_seg_id;
  4381. struct hc_status_block_data_e2 sb_data_e2;
  4382. struct hc_status_block_data_e1x sb_data_e1x;
  4383. struct hc_status_block_sm *hc_sm_p;
  4384. int data_size;
  4385. u32 *sb_data_p;
  4386. if (CHIP_INT_MODE_IS_BC(bp))
  4387. igu_seg_id = HC_SEG_ACCESS_NORM;
  4388. else
  4389. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4390. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4391. if (!CHIP_IS_E1x(bp)) {
  4392. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4393. sb_data_e2.common.state = SB_ENABLED;
  4394. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4395. sb_data_e2.common.p_func.vf_id = vfid;
  4396. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4397. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4398. sb_data_e2.common.same_igu_sb_1b = true;
  4399. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4400. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4401. hc_sm_p = sb_data_e2.common.state_machine;
  4402. sb_data_p = (u32 *)&sb_data_e2;
  4403. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4404. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4405. } else {
  4406. memset(&sb_data_e1x, 0,
  4407. sizeof(struct hc_status_block_data_e1x));
  4408. sb_data_e1x.common.state = SB_ENABLED;
  4409. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4410. sb_data_e1x.common.p_func.vf_id = 0xff;
  4411. sb_data_e1x.common.p_func.vf_valid = false;
  4412. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4413. sb_data_e1x.common.same_igu_sb_1b = true;
  4414. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4415. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4416. hc_sm_p = sb_data_e1x.common.state_machine;
  4417. sb_data_p = (u32 *)&sb_data_e1x;
  4418. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4419. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4420. }
  4421. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4422. igu_sb_id, igu_seg_id);
  4423. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4424. igu_sb_id, igu_seg_id);
  4425. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4426. /* write indecies to HW */
  4427. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4428. }
  4429. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4430. u16 tx_usec, u16 rx_usec)
  4431. {
  4432. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4433. false, rx_usec);
  4434. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4435. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4436. tx_usec);
  4437. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4438. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4439. tx_usec);
  4440. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4441. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4442. tx_usec);
  4443. }
  4444. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4445. {
  4446. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4447. dma_addr_t mapping = bp->def_status_blk_mapping;
  4448. int igu_sp_sb_index;
  4449. int igu_seg_id;
  4450. int port = BP_PORT(bp);
  4451. int func = BP_FUNC(bp);
  4452. int reg_offset, reg_offset_en5;
  4453. u64 section;
  4454. int index;
  4455. struct hc_sp_status_block_data sp_sb_data;
  4456. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4457. if (CHIP_INT_MODE_IS_BC(bp)) {
  4458. igu_sp_sb_index = DEF_SB_IGU_ID;
  4459. igu_seg_id = HC_SEG_ACCESS_DEF;
  4460. } else {
  4461. igu_sp_sb_index = bp->igu_dsb_id;
  4462. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4463. }
  4464. /* ATTN */
  4465. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4466. atten_status_block);
  4467. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4468. bp->attn_state = 0;
  4469. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4470. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4471. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4472. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4473. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4474. int sindex;
  4475. /* take care of sig[0]..sig[4] */
  4476. for (sindex = 0; sindex < 4; sindex++)
  4477. bp->attn_group[index].sig[sindex] =
  4478. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4479. if (!CHIP_IS_E1x(bp))
  4480. /*
  4481. * enable5 is separate from the rest of the registers,
  4482. * and therefore the address skip is 4
  4483. * and not 16 between the different groups
  4484. */
  4485. bp->attn_group[index].sig[4] = REG_RD(bp,
  4486. reg_offset_en5 + 0x4*index);
  4487. else
  4488. bp->attn_group[index].sig[4] = 0;
  4489. }
  4490. if (bp->common.int_block == INT_BLOCK_HC) {
  4491. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4492. HC_REG_ATTN_MSG0_ADDR_L);
  4493. REG_WR(bp, reg_offset, U64_LO(section));
  4494. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4495. } else if (!CHIP_IS_E1x(bp)) {
  4496. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4497. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4498. }
  4499. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4500. sp_sb);
  4501. bnx2x_zero_sp_sb(bp);
  4502. sp_sb_data.state = SB_ENABLED;
  4503. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4504. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4505. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4506. sp_sb_data.igu_seg_id = igu_seg_id;
  4507. sp_sb_data.p_func.pf_id = func;
  4508. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4509. sp_sb_data.p_func.vf_id = 0xff;
  4510. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4511. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4512. }
  4513. void bnx2x_update_coalesce(struct bnx2x *bp)
  4514. {
  4515. int i;
  4516. for_each_eth_queue(bp, i)
  4517. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4518. bp->tx_ticks, bp->rx_ticks);
  4519. }
  4520. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4521. {
  4522. spin_lock_init(&bp->spq_lock);
  4523. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4524. bp->spq_prod_idx = 0;
  4525. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4526. bp->spq_prod_bd = bp->spq;
  4527. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4528. }
  4529. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4530. {
  4531. int i;
  4532. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4533. union event_ring_elem *elem =
  4534. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4535. elem->next_page.addr.hi =
  4536. cpu_to_le32(U64_HI(bp->eq_mapping +
  4537. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4538. elem->next_page.addr.lo =
  4539. cpu_to_le32(U64_LO(bp->eq_mapping +
  4540. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4541. }
  4542. bp->eq_cons = 0;
  4543. bp->eq_prod = NUM_EQ_DESC;
  4544. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4545. /* we want a warning message before it gets rought... */
  4546. atomic_set(&bp->eq_spq_left,
  4547. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4548. }
  4549. /* called with netif_addr_lock_bh() */
  4550. void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4551. unsigned long rx_mode_flags,
  4552. unsigned long rx_accept_flags,
  4553. unsigned long tx_accept_flags,
  4554. unsigned long ramrod_flags)
  4555. {
  4556. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4557. int rc;
  4558. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4559. /* Prepare ramrod parameters */
  4560. ramrod_param.cid = 0;
  4561. ramrod_param.cl_id = cl_id;
  4562. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4563. ramrod_param.func_id = BP_FUNC(bp);
  4564. ramrod_param.pstate = &bp->sp_state;
  4565. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4566. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4567. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4568. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4569. ramrod_param.ramrod_flags = ramrod_flags;
  4570. ramrod_param.rx_mode_flags = rx_mode_flags;
  4571. ramrod_param.rx_accept_flags = rx_accept_flags;
  4572. ramrod_param.tx_accept_flags = tx_accept_flags;
  4573. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4574. if (rc < 0) {
  4575. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4576. return;
  4577. }
  4578. }
  4579. /* called with netif_addr_lock_bh() */
  4580. void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  4581. {
  4582. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  4583. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  4584. if (!NO_FCOE(bp))
  4585. /* Configure rx_mode of FCoE Queue */
  4586. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  4587. switch (bp->rx_mode) {
  4588. case BNX2X_RX_MODE_NONE:
  4589. /*
  4590. * 'drop all' supersedes any accept flags that may have been
  4591. * passed to the function.
  4592. */
  4593. break;
  4594. case BNX2X_RX_MODE_NORMAL:
  4595. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4596. __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
  4597. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4598. /* internal switching mode */
  4599. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4600. __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
  4601. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4602. break;
  4603. case BNX2X_RX_MODE_ALLMULTI:
  4604. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4605. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4606. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4607. /* internal switching mode */
  4608. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4609. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4610. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4611. break;
  4612. case BNX2X_RX_MODE_PROMISC:
  4613. /* According to deffinition of SI mode, iface in promisc mode
  4614. * should receive matched and unmatched (in resolution of port)
  4615. * unicast packets.
  4616. */
  4617. __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
  4618. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4619. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4620. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4621. /* internal switching mode */
  4622. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4623. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4624. if (IS_MF_SI(bp))
  4625. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
  4626. else
  4627. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4628. break;
  4629. default:
  4630. BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
  4631. return;
  4632. }
  4633. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  4634. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
  4635. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
  4636. }
  4637. __set_bit(RAMROD_RX, &ramrod_flags);
  4638. __set_bit(RAMROD_TX, &ramrod_flags);
  4639. bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
  4640. tx_accept_flags, ramrod_flags);
  4641. }
  4642. static void bnx2x_init_internal_common(struct bnx2x *bp)
  4643. {
  4644. int i;
  4645. if (IS_MF_SI(bp))
  4646. /*
  4647. * In switch independent mode, the TSTORM needs to accept
  4648. * packets that failed classification, since approximate match
  4649. * mac addresses aren't written to NIG LLH
  4650. */
  4651. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4652. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  4653. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  4654. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4655. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  4656. /* Zero this manually as its initialization is
  4657. currently missing in the initTool */
  4658. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  4659. REG_WR(bp, BAR_USTRORM_INTMEM +
  4660. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  4661. if (!CHIP_IS_E1x(bp)) {
  4662. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  4663. CHIP_INT_MODE_IS_BC(bp) ?
  4664. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  4665. }
  4666. }
  4667. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  4668. {
  4669. switch (load_code) {
  4670. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4671. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  4672. bnx2x_init_internal_common(bp);
  4673. /* no break */
  4674. case FW_MSG_CODE_DRV_LOAD_PORT:
  4675. /* nothing to do */
  4676. /* no break */
  4677. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4678. /* internal memory per function is
  4679. initialized inside bnx2x_pf_init */
  4680. break;
  4681. default:
  4682. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4683. break;
  4684. }
  4685. }
  4686. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  4687. {
  4688. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  4689. }
  4690. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  4691. {
  4692. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  4693. }
  4694. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  4695. {
  4696. if (CHIP_IS_E1x(fp->bp))
  4697. return BP_L_ID(fp->bp) + fp->index;
  4698. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  4699. return bnx2x_fp_igu_sb_id(fp);
  4700. }
  4701. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  4702. {
  4703. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  4704. u8 cos;
  4705. unsigned long q_type = 0;
  4706. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  4707. fp->rx_queue = fp_idx;
  4708. fp->cid = fp_idx;
  4709. fp->cl_id = bnx2x_fp_cl_id(fp);
  4710. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  4711. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  4712. /* qZone id equals to FW (per path) client id */
  4713. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  4714. /* init shortcut */
  4715. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  4716. /* Setup SB indicies */
  4717. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  4718. /* Configure Queue State object */
  4719. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  4720. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  4721. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  4722. /* init tx data */
  4723. for_each_cos_in_tx_queue(fp, cos) {
  4724. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  4725. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  4726. FP_COS_TO_TXQ(fp, cos, bp),
  4727. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  4728. cids[cos] = fp->txdata_ptr[cos]->cid;
  4729. }
  4730. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  4731. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  4732. bnx2x_sp_mapping(bp, q_rdata), q_type);
  4733. /**
  4734. * Configure classification DBs: Always enable Tx switching
  4735. */
  4736. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  4737. DP(NETIF_MSG_IFUP, "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  4738. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  4739. fp->igu_sb_id);
  4740. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  4741. fp->fw_sb_id, fp->igu_sb_id);
  4742. bnx2x_update_fpsb_idx(fp);
  4743. }
  4744. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  4745. {
  4746. int i;
  4747. for (i = 1; i <= NUM_TX_RINGS; i++) {
  4748. struct eth_tx_next_bd *tx_next_bd =
  4749. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  4750. tx_next_bd->addr_hi =
  4751. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  4752. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4753. tx_next_bd->addr_lo =
  4754. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  4755. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4756. }
  4757. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  4758. txdata->tx_db.data.zero_fill1 = 0;
  4759. txdata->tx_db.data.prod = 0;
  4760. txdata->tx_pkt_prod = 0;
  4761. txdata->tx_pkt_cons = 0;
  4762. txdata->tx_bd_prod = 0;
  4763. txdata->tx_bd_cons = 0;
  4764. txdata->tx_pkt = 0;
  4765. }
  4766. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  4767. {
  4768. int i;
  4769. for_each_tx_queue_cnic(bp, i)
  4770. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  4771. }
  4772. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  4773. {
  4774. int i;
  4775. u8 cos;
  4776. for_each_eth_queue(bp, i)
  4777. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  4778. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  4779. }
  4780. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  4781. {
  4782. if (!NO_FCOE(bp))
  4783. bnx2x_init_fcoe_fp(bp);
  4784. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  4785. BNX2X_VF_ID_INVALID, false,
  4786. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  4787. /* ensure status block indices were read */
  4788. rmb();
  4789. bnx2x_init_rx_rings_cnic(bp);
  4790. bnx2x_init_tx_rings_cnic(bp);
  4791. /* flush all */
  4792. mb();
  4793. mmiowb();
  4794. }
  4795. void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
  4796. {
  4797. int i;
  4798. for_each_eth_queue(bp, i)
  4799. bnx2x_init_eth_fp(bp, i);
  4800. /* Initialize MOD_ABS interrupts */
  4801. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  4802. bp->common.shmem_base, bp->common.shmem2_base,
  4803. BP_PORT(bp));
  4804. /* ensure status block indices were read */
  4805. rmb();
  4806. bnx2x_init_def_sb(bp);
  4807. bnx2x_update_dsb_idx(bp);
  4808. bnx2x_init_rx_rings(bp);
  4809. bnx2x_init_tx_rings(bp);
  4810. bnx2x_init_sp_ring(bp);
  4811. bnx2x_init_eq_ring(bp);
  4812. bnx2x_init_internal(bp, load_code);
  4813. bnx2x_pf_init(bp);
  4814. bnx2x_stats_init(bp);
  4815. /* flush all before enabling interrupts */
  4816. mb();
  4817. mmiowb();
  4818. bnx2x_int_enable(bp);
  4819. /* Check for SPIO5 */
  4820. bnx2x_attn_int_deasserted0(bp,
  4821. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  4822. AEU_INPUTS_ATTN_BITS_SPIO5);
  4823. }
  4824. /* end of nic init */
  4825. /*
  4826. * gzip service functions
  4827. */
  4828. static int bnx2x_gunzip_init(struct bnx2x *bp)
  4829. {
  4830. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  4831. &bp->gunzip_mapping, GFP_KERNEL);
  4832. if (bp->gunzip_buf == NULL)
  4833. goto gunzip_nomem1;
  4834. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  4835. if (bp->strm == NULL)
  4836. goto gunzip_nomem2;
  4837. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  4838. if (bp->strm->workspace == NULL)
  4839. goto gunzip_nomem3;
  4840. return 0;
  4841. gunzip_nomem3:
  4842. kfree(bp->strm);
  4843. bp->strm = NULL;
  4844. gunzip_nomem2:
  4845. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  4846. bp->gunzip_mapping);
  4847. bp->gunzip_buf = NULL;
  4848. gunzip_nomem1:
  4849. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  4850. return -ENOMEM;
  4851. }
  4852. static void bnx2x_gunzip_end(struct bnx2x *bp)
  4853. {
  4854. if (bp->strm) {
  4855. vfree(bp->strm->workspace);
  4856. kfree(bp->strm);
  4857. bp->strm = NULL;
  4858. }
  4859. if (bp->gunzip_buf) {
  4860. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  4861. bp->gunzip_mapping);
  4862. bp->gunzip_buf = NULL;
  4863. }
  4864. }
  4865. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  4866. {
  4867. int n, rc;
  4868. /* check gzip header */
  4869. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  4870. BNX2X_ERR("Bad gzip header\n");
  4871. return -EINVAL;
  4872. }
  4873. n = 10;
  4874. #define FNAME 0x8
  4875. if (zbuf[3] & FNAME)
  4876. while ((zbuf[n++] != 0) && (n < len));
  4877. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  4878. bp->strm->avail_in = len - n;
  4879. bp->strm->next_out = bp->gunzip_buf;
  4880. bp->strm->avail_out = FW_BUF_SIZE;
  4881. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  4882. if (rc != Z_OK)
  4883. return rc;
  4884. rc = zlib_inflate(bp->strm, Z_FINISH);
  4885. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  4886. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  4887. bp->strm->msg);
  4888. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  4889. if (bp->gunzip_outlen & 0x3)
  4890. netdev_err(bp->dev,
  4891. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  4892. bp->gunzip_outlen);
  4893. bp->gunzip_outlen >>= 2;
  4894. zlib_inflateEnd(bp->strm);
  4895. if (rc == Z_STREAM_END)
  4896. return 0;
  4897. return rc;
  4898. }
  4899. /* nic load/unload */
  4900. /*
  4901. * General service functions
  4902. */
  4903. /* send a NIG loopback debug packet */
  4904. static void bnx2x_lb_pckt(struct bnx2x *bp)
  4905. {
  4906. u32 wb_write[3];
  4907. /* Ethernet source and destination addresses */
  4908. wb_write[0] = 0x55555555;
  4909. wb_write[1] = 0x55555555;
  4910. wb_write[2] = 0x20; /* SOP */
  4911. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4912. /* NON-IP protocol */
  4913. wb_write[0] = 0x09000000;
  4914. wb_write[1] = 0x55555555;
  4915. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  4916. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4917. }
  4918. /* some of the internal memories
  4919. * are not directly readable from the driver
  4920. * to test them we send debug packets
  4921. */
  4922. static int bnx2x_int_mem_test(struct bnx2x *bp)
  4923. {
  4924. int factor;
  4925. int count, i;
  4926. u32 val = 0;
  4927. if (CHIP_REV_IS_FPGA(bp))
  4928. factor = 120;
  4929. else if (CHIP_REV_IS_EMUL(bp))
  4930. factor = 200;
  4931. else
  4932. factor = 1;
  4933. /* Disable inputs of parser neighbor blocks */
  4934. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  4935. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  4936. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  4937. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  4938. /* Write 0 to parser credits for CFC search request */
  4939. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  4940. /* send Ethernet packet */
  4941. bnx2x_lb_pckt(bp);
  4942. /* TODO do i reset NIG statistic? */
  4943. /* Wait until NIG register shows 1 packet of size 0x10 */
  4944. count = 1000 * factor;
  4945. while (count) {
  4946. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4947. val = *bnx2x_sp(bp, wb_data[0]);
  4948. if (val == 0x10)
  4949. break;
  4950. msleep(10);
  4951. count--;
  4952. }
  4953. if (val != 0x10) {
  4954. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  4955. return -1;
  4956. }
  4957. /* Wait until PRS register shows 1 packet */
  4958. count = 1000 * factor;
  4959. while (count) {
  4960. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4961. if (val == 1)
  4962. break;
  4963. msleep(10);
  4964. count--;
  4965. }
  4966. if (val != 0x1) {
  4967. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4968. return -2;
  4969. }
  4970. /* Reset and init BRB, PRS */
  4971. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  4972. msleep(50);
  4973. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  4974. msleep(50);
  4975. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  4976. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  4977. DP(NETIF_MSG_HW, "part2\n");
  4978. /* Disable inputs of parser neighbor blocks */
  4979. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  4980. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  4981. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  4982. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  4983. /* Write 0 to parser credits for CFC search request */
  4984. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  4985. /* send 10 Ethernet packets */
  4986. for (i = 0; i < 10; i++)
  4987. bnx2x_lb_pckt(bp);
  4988. /* Wait until NIG register shows 10 + 1
  4989. packets of size 11*0x10 = 0xb0 */
  4990. count = 1000 * factor;
  4991. while (count) {
  4992. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4993. val = *bnx2x_sp(bp, wb_data[0]);
  4994. if (val == 0xb0)
  4995. break;
  4996. msleep(10);
  4997. count--;
  4998. }
  4999. if (val != 0xb0) {
  5000. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5001. return -3;
  5002. }
  5003. /* Wait until PRS register shows 2 packets */
  5004. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5005. if (val != 2)
  5006. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5007. /* Write 1 to parser credits for CFC search request */
  5008. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5009. /* Wait until PRS register shows 3 packets */
  5010. msleep(10 * factor);
  5011. /* Wait until NIG register shows 1 packet of size 0x10 */
  5012. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5013. if (val != 3)
  5014. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5015. /* clear NIG EOP FIFO */
  5016. for (i = 0; i < 11; i++)
  5017. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5018. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5019. if (val != 1) {
  5020. BNX2X_ERR("clear of NIG failed\n");
  5021. return -4;
  5022. }
  5023. /* Reset and init BRB, PRS, NIG */
  5024. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5025. msleep(50);
  5026. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5027. msleep(50);
  5028. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5029. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5030. if (!CNIC_SUPPORT(bp))
  5031. /* set NIC mode */
  5032. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5033. /* Enable inputs of parser neighbor blocks */
  5034. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5035. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5036. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5037. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5038. DP(NETIF_MSG_HW, "done\n");
  5039. return 0; /* OK */
  5040. }
  5041. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5042. {
  5043. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5044. if (!CHIP_IS_E1x(bp))
  5045. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5046. else
  5047. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5048. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5049. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5050. /*
  5051. * mask read length error interrupts in brb for parser
  5052. * (parsing unit and 'checksum and crc' unit)
  5053. * these errors are legal (PU reads fixed length and CAC can cause
  5054. * read length error on truncated packets)
  5055. */
  5056. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5057. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5058. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5059. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5060. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5061. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5062. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5063. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5064. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5065. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5066. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5067. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5068. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5069. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5070. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5071. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5072. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5073. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5074. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5075. if (CHIP_REV_IS_FPGA(bp))
  5076. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000);
  5077. else if (!CHIP_IS_E1x(bp))
  5078. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0,
  5079. (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF
  5080. | PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT
  5081. | PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN
  5082. | PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED
  5083. | PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED));
  5084. else
  5085. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000);
  5086. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5087. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5088. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5089. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5090. if (!CHIP_IS_E1x(bp))
  5091. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5092. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5093. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5094. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5095. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5096. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5097. }
  5098. static void bnx2x_reset_common(struct bnx2x *bp)
  5099. {
  5100. u32 val = 0x1400;
  5101. /* reset_common */
  5102. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5103. 0xd3ffff7f);
  5104. if (CHIP_IS_E3(bp)) {
  5105. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5106. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5107. }
  5108. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5109. }
  5110. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5111. {
  5112. bp->dmae_ready = 0;
  5113. spin_lock_init(&bp->dmae_lock);
  5114. }
  5115. static void bnx2x_init_pxp(struct bnx2x *bp)
  5116. {
  5117. u16 devctl;
  5118. int r_order, w_order;
  5119. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5120. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5121. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5122. if (bp->mrrs == -1)
  5123. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5124. else {
  5125. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5126. r_order = bp->mrrs;
  5127. }
  5128. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5129. }
  5130. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5131. {
  5132. int is_required;
  5133. u32 val;
  5134. int port;
  5135. if (BP_NOMCP(bp))
  5136. return;
  5137. is_required = 0;
  5138. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5139. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5140. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5141. is_required = 1;
  5142. /*
  5143. * The fan failure mechanism is usually related to the PHY type since
  5144. * the power consumption of the board is affected by the PHY. Currently,
  5145. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5146. */
  5147. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5148. for (port = PORT_0; port < PORT_MAX; port++) {
  5149. is_required |=
  5150. bnx2x_fan_failure_det_req(
  5151. bp,
  5152. bp->common.shmem_base,
  5153. bp->common.shmem2_base,
  5154. port);
  5155. }
  5156. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5157. if (is_required == 0)
  5158. return;
  5159. /* Fan failure is indicated by SPIO 5 */
  5160. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5161. /* set to active low mode */
  5162. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5163. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5164. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5165. /* enable interrupt to signal the IGU */
  5166. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5167. val |= MISC_SPIO_SPIO5;
  5168. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5169. }
  5170. static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num)
  5171. {
  5172. u32 offset = 0;
  5173. if (CHIP_IS_E1(bp))
  5174. return;
  5175. if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX))
  5176. return;
  5177. switch (BP_ABS_FUNC(bp)) {
  5178. case 0:
  5179. offset = PXP2_REG_PGL_PRETEND_FUNC_F0;
  5180. break;
  5181. case 1:
  5182. offset = PXP2_REG_PGL_PRETEND_FUNC_F1;
  5183. break;
  5184. case 2:
  5185. offset = PXP2_REG_PGL_PRETEND_FUNC_F2;
  5186. break;
  5187. case 3:
  5188. offset = PXP2_REG_PGL_PRETEND_FUNC_F3;
  5189. break;
  5190. case 4:
  5191. offset = PXP2_REG_PGL_PRETEND_FUNC_F4;
  5192. break;
  5193. case 5:
  5194. offset = PXP2_REG_PGL_PRETEND_FUNC_F5;
  5195. break;
  5196. case 6:
  5197. offset = PXP2_REG_PGL_PRETEND_FUNC_F6;
  5198. break;
  5199. case 7:
  5200. offset = PXP2_REG_PGL_PRETEND_FUNC_F7;
  5201. break;
  5202. default:
  5203. return;
  5204. }
  5205. REG_WR(bp, offset, pretend_func_num);
  5206. REG_RD(bp, offset);
  5207. DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num);
  5208. }
  5209. void bnx2x_pf_disable(struct bnx2x *bp)
  5210. {
  5211. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5212. val &= ~IGU_PF_CONF_FUNC_EN;
  5213. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5214. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5215. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5216. }
  5217. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5218. {
  5219. u32 shmem_base[2], shmem2_base[2];
  5220. /* Avoid common init in case MFW supports LFA */
  5221. if (SHMEM2_RD(bp, size) >
  5222. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5223. return;
  5224. shmem_base[0] = bp->common.shmem_base;
  5225. shmem2_base[0] = bp->common.shmem2_base;
  5226. if (!CHIP_IS_E1x(bp)) {
  5227. shmem_base[1] =
  5228. SHMEM2_RD(bp, other_shmem_base_addr);
  5229. shmem2_base[1] =
  5230. SHMEM2_RD(bp, other_shmem2_base_addr);
  5231. }
  5232. bnx2x_acquire_phy_lock(bp);
  5233. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5234. bp->common.chip_id);
  5235. bnx2x_release_phy_lock(bp);
  5236. }
  5237. /**
  5238. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5239. *
  5240. * @bp: driver handle
  5241. */
  5242. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5243. {
  5244. u32 val;
  5245. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5246. /*
  5247. * take the UNDI lock to protect undi_unload flow from accessing
  5248. * registers while we're resetting the chip
  5249. */
  5250. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5251. bnx2x_reset_common(bp);
  5252. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5253. val = 0xfffc;
  5254. if (CHIP_IS_E3(bp)) {
  5255. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5256. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5257. }
  5258. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5259. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5260. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5261. if (!CHIP_IS_E1x(bp)) {
  5262. u8 abs_func_id;
  5263. /**
  5264. * 4-port mode or 2-port mode we need to turn of master-enable
  5265. * for everyone, after that, turn it back on for self.
  5266. * so, we disregard multi-function or not, and always disable
  5267. * for all functions on the given path, this means 0,2,4,6 for
  5268. * path 0 and 1,3,5,7 for path 1
  5269. */
  5270. for (abs_func_id = BP_PATH(bp);
  5271. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5272. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5273. REG_WR(bp,
  5274. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5275. 1);
  5276. continue;
  5277. }
  5278. bnx2x_pretend_func(bp, abs_func_id);
  5279. /* clear pf enable */
  5280. bnx2x_pf_disable(bp);
  5281. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5282. }
  5283. }
  5284. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5285. if (CHIP_IS_E1(bp)) {
  5286. /* enable HW interrupt from PXP on USDM overflow
  5287. bit 16 on INT_MASK_0 */
  5288. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5289. }
  5290. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5291. bnx2x_init_pxp(bp);
  5292. #ifdef __BIG_ENDIAN
  5293. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5294. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5295. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5296. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5297. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5298. /* make sure this value is 0 */
  5299. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5300. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5301. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5302. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5303. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5304. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5305. #endif
  5306. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5307. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5308. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5309. /* let the HW do it's magic ... */
  5310. msleep(100);
  5311. /* finish PXP init */
  5312. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5313. if (val != 1) {
  5314. BNX2X_ERR("PXP2 CFG failed\n");
  5315. return -EBUSY;
  5316. }
  5317. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5318. if (val != 1) {
  5319. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5320. return -EBUSY;
  5321. }
  5322. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5323. * have entries with value "0" and valid bit on.
  5324. * This needs to be done by the first PF that is loaded in a path
  5325. * (i.e. common phase)
  5326. */
  5327. if (!CHIP_IS_E1x(bp)) {
  5328. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5329. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5330. * This occurs when a different function (func2,3) is being marked
  5331. * as "scan-off". Real-life scenario for example: if a driver is being
  5332. * load-unloaded while func6,7 are down. This will cause the timer to access
  5333. * the ilt, translate to a logical address and send a request to read/write.
  5334. * Since the ilt for the function that is down is not valid, this will cause
  5335. * a translation error which is unrecoverable.
  5336. * The Workaround is intended to make sure that when this happens nothing fatal
  5337. * will occur. The workaround:
  5338. * 1. First PF driver which loads on a path will:
  5339. * a. After taking the chip out of reset, by using pretend,
  5340. * it will write "0" to the following registers of
  5341. * the other vnics.
  5342. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5343. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5344. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5345. * And for itself it will write '1' to
  5346. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5347. * dmae-operations (writing to pram for example.)
  5348. * note: can be done for only function 6,7 but cleaner this
  5349. * way.
  5350. * b. Write zero+valid to the entire ILT.
  5351. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5352. * VNIC3 (of that port). The range allocated will be the
  5353. * entire ILT. This is needed to prevent ILT range error.
  5354. * 2. Any PF driver load flow:
  5355. * a. ILT update with the physical addresses of the allocated
  5356. * logical pages.
  5357. * b. Wait 20msec. - note that this timeout is needed to make
  5358. * sure there are no requests in one of the PXP internal
  5359. * queues with "old" ILT addresses.
  5360. * c. PF enable in the PGLC.
  5361. * d. Clear the was_error of the PF in the PGLC. (could have
  5362. * occured while driver was down)
  5363. * e. PF enable in the CFC (WEAK + STRONG)
  5364. * f. Timers scan enable
  5365. * 3. PF driver unload flow:
  5366. * a. Clear the Timers scan_en.
  5367. * b. Polling for scan_on=0 for that PF.
  5368. * c. Clear the PF enable bit in the PXP.
  5369. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5370. * e. Write zero+valid to all ILT entries (The valid bit must
  5371. * stay set)
  5372. * f. If this is VNIC 3 of a port then also init
  5373. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5374. * to the last enrty in the ILT.
  5375. *
  5376. * Notes:
  5377. * Currently the PF error in the PGLC is non recoverable.
  5378. * In the future the there will be a recovery routine for this error.
  5379. * Currently attention is masked.
  5380. * Having an MCP lock on the load/unload process does not guarantee that
  5381. * there is no Timer disable during Func6/7 enable. This is because the
  5382. * Timers scan is currently being cleared by the MCP on FLR.
  5383. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5384. * there is error before clearing it. But the flow above is simpler and
  5385. * more general.
  5386. * All ILT entries are written by zero+valid and not just PF6/7
  5387. * ILT entries since in the future the ILT entries allocation for
  5388. * PF-s might be dynamic.
  5389. */
  5390. struct ilt_client_info ilt_cli;
  5391. struct bnx2x_ilt ilt;
  5392. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5393. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5394. /* initialize dummy TM client */
  5395. ilt_cli.start = 0;
  5396. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5397. ilt_cli.client_num = ILT_CLIENT_TM;
  5398. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5399. * Step 2: set the timers first/last ilt entry to point
  5400. * to the entire range to prevent ILT range error for 3rd/4th
  5401. * vnic (this code assumes existance of the vnic)
  5402. *
  5403. * both steps performed by call to bnx2x_ilt_client_init_op()
  5404. * with dummy TM client
  5405. *
  5406. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5407. * and his brother are split registers
  5408. */
  5409. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5410. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5411. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5412. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5413. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5414. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5415. }
  5416. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5417. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5418. if (!CHIP_IS_E1x(bp)) {
  5419. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5420. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5421. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5422. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5423. /* let the HW do it's magic ... */
  5424. do {
  5425. msleep(200);
  5426. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5427. } while (factor-- && (val != 1));
  5428. if (val != 1) {
  5429. BNX2X_ERR("ATC_INIT failed\n");
  5430. return -EBUSY;
  5431. }
  5432. }
  5433. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5434. /* clean the DMAE memory */
  5435. bp->dmae_ready = 1;
  5436. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5437. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5438. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5439. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5440. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5441. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5442. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5443. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5444. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5445. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5446. /* QM queues pointers table */
  5447. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5448. /* soft reset pulse */
  5449. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5450. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5451. if (CNIC_SUPPORT(bp))
  5452. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5453. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5454. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
  5455. if (!CHIP_REV_IS_SLOW(bp))
  5456. /* enable hw interrupt from doorbell Q */
  5457. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5458. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5459. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5460. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5461. if (!CHIP_IS_E1(bp))
  5462. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5463. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  5464. if (IS_MF_AFEX(bp)) {
  5465. /* configure that VNTag and VLAN headers must be
  5466. * received in afex mode
  5467. */
  5468. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  5469. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  5470. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  5471. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  5472. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  5473. } else {
  5474. /* Bit-map indicating which L2 hdrs may appear
  5475. * after the basic Ethernet header
  5476. */
  5477. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5478. bp->path_has_ovlan ? 7 : 6);
  5479. }
  5480. }
  5481. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5482. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5483. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5484. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5485. if (!CHIP_IS_E1x(bp)) {
  5486. /* reset VFC memories */
  5487. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5488. VFC_MEMORIES_RST_REG_CAM_RST |
  5489. VFC_MEMORIES_RST_REG_RAM_RST);
  5490. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5491. VFC_MEMORIES_RST_REG_CAM_RST |
  5492. VFC_MEMORIES_RST_REG_RAM_RST);
  5493. msleep(20);
  5494. }
  5495. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5496. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5497. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5498. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5499. /* sync semi rtc */
  5500. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5501. 0x80000000);
  5502. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5503. 0x80000000);
  5504. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5505. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5506. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5507. if (!CHIP_IS_E1x(bp)) {
  5508. if (IS_MF_AFEX(bp)) {
  5509. /* configure that VNTag and VLAN headers must be
  5510. * sent in afex mode
  5511. */
  5512. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  5513. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  5514. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  5515. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  5516. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  5517. } else {
  5518. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5519. bp->path_has_ovlan ? 7 : 6);
  5520. }
  5521. }
  5522. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5523. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5524. if (CNIC_SUPPORT(bp)) {
  5525. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5526. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5527. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5528. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5529. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5530. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5531. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5532. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5533. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5534. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5535. }
  5536. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5537. if (sizeof(union cdu_context) != 1024)
  5538. /* we currently assume that a context is 1024 bytes */
  5539. dev_alert(&bp->pdev->dev,
  5540. "please adjust the size of cdu_context(%ld)\n",
  5541. (long)sizeof(union cdu_context));
  5542. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5543. val = (4 << 24) + (0 << 12) + 1024;
  5544. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5545. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5546. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5547. /* enable context validation interrupt from CFC */
  5548. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5549. /* set the thresholds to prevent CFC/CDU race */
  5550. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5551. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5552. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5553. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5554. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5555. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5556. /* Reset PCIE errors for debug */
  5557. REG_WR(bp, 0x2814, 0xffffffff);
  5558. REG_WR(bp, 0x3820, 0xffffffff);
  5559. if (!CHIP_IS_E1x(bp)) {
  5560. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5561. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5562. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5563. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5564. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5565. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5566. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5567. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5568. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5569. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5570. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5571. }
  5572. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5573. if (!CHIP_IS_E1(bp)) {
  5574. /* in E3 this done in per-port section */
  5575. if (!CHIP_IS_E3(bp))
  5576. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5577. }
  5578. if (CHIP_IS_E1H(bp))
  5579. /* not applicable for E2 (and above ...) */
  5580. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5581. if (CHIP_REV_IS_SLOW(bp))
  5582. msleep(200);
  5583. /* finish CFC init */
  5584. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5585. if (val != 1) {
  5586. BNX2X_ERR("CFC LL_INIT failed\n");
  5587. return -EBUSY;
  5588. }
  5589. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5590. if (val != 1) {
  5591. BNX2X_ERR("CFC AC_INIT failed\n");
  5592. return -EBUSY;
  5593. }
  5594. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5595. if (val != 1) {
  5596. BNX2X_ERR("CFC CAM_INIT failed\n");
  5597. return -EBUSY;
  5598. }
  5599. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5600. if (CHIP_IS_E1(bp)) {
  5601. /* read NIG statistic
  5602. to see if this is our first up since powerup */
  5603. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5604. val = *bnx2x_sp(bp, wb_data[0]);
  5605. /* do internal memory self test */
  5606. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5607. BNX2X_ERR("internal mem self test failed\n");
  5608. return -EBUSY;
  5609. }
  5610. }
  5611. bnx2x_setup_fan_failure_detection(bp);
  5612. /* clear PXP2 attentions */
  5613. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5614. bnx2x_enable_blocks_attention(bp);
  5615. bnx2x_enable_blocks_parity(bp);
  5616. if (!BP_NOMCP(bp)) {
  5617. if (CHIP_IS_E1x(bp))
  5618. bnx2x__common_init_phy(bp);
  5619. } else
  5620. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5621. return 0;
  5622. }
  5623. /**
  5624. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  5625. *
  5626. * @bp: driver handle
  5627. */
  5628. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  5629. {
  5630. int rc = bnx2x_init_hw_common(bp);
  5631. if (rc)
  5632. return rc;
  5633. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  5634. if (!BP_NOMCP(bp))
  5635. bnx2x__common_init_phy(bp);
  5636. return 0;
  5637. }
  5638. static int bnx2x_init_hw_port(struct bnx2x *bp)
  5639. {
  5640. int port = BP_PORT(bp);
  5641. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  5642. u32 low, high;
  5643. u32 val;
  5644. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  5645. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  5646. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5647. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5648. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5649. /* Timers bug workaround: disables the pf_master bit in pglue at
  5650. * common phase, we need to enable it here before any dmae access are
  5651. * attempted. Therefore we manually added the enable-master to the
  5652. * port phase (it also happens in the function phase)
  5653. */
  5654. if (!CHIP_IS_E1x(bp))
  5655. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5656. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5657. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5658. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5659. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5660. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5661. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5662. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5663. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5664. /* QM cid (connection) count */
  5665. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  5666. if (CNIC_SUPPORT(bp)) {
  5667. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5668. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  5669. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  5670. }
  5671. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5672. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5673. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  5674. if (IS_MF(bp))
  5675. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  5676. else if (bp->dev->mtu > 4096) {
  5677. if (bp->flags & ONE_PORT_FLAG)
  5678. low = 160;
  5679. else {
  5680. val = bp->dev->mtu;
  5681. /* (24*1024 + val*4)/256 */
  5682. low = 96 + (val/64) +
  5683. ((val % 64) ? 1 : 0);
  5684. }
  5685. } else
  5686. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  5687. high = low + 56; /* 14*1024/256 */
  5688. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  5689. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  5690. }
  5691. if (CHIP_MODE_IS_4_PORT(bp))
  5692. REG_WR(bp, (BP_PORT(bp) ?
  5693. BRB1_REG_MAC_GUARANTIED_1 :
  5694. BRB1_REG_MAC_GUARANTIED_0), 40);
  5695. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5696. if (CHIP_IS_E3B0(bp)) {
  5697. if (IS_MF_AFEX(bp)) {
  5698. /* configure headers for AFEX mode */
  5699. REG_WR(bp, BP_PORT(bp) ?
  5700. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5701. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  5702. REG_WR(bp, BP_PORT(bp) ?
  5703. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  5704. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  5705. REG_WR(bp, BP_PORT(bp) ?
  5706. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  5707. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  5708. } else {
  5709. /* Ovlan exists only if we are in multi-function +
  5710. * switch-dependent mode, in switch-independent there
  5711. * is no ovlan headers
  5712. */
  5713. REG_WR(bp, BP_PORT(bp) ?
  5714. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5715. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  5716. (bp->path_has_ovlan ? 7 : 6));
  5717. }
  5718. }
  5719. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5720. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5721. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5722. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5723. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5724. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5725. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5726. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5727. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5728. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5729. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5730. if (CHIP_IS_E1x(bp)) {
  5731. /* configure PBF to work without PAUSE mtu 9000 */
  5732. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  5733. /* update threshold */
  5734. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  5735. /* update init credit */
  5736. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  5737. /* probe changes */
  5738. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  5739. udelay(50);
  5740. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  5741. }
  5742. if (CNIC_SUPPORT(bp))
  5743. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5744. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5745. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5746. if (CHIP_IS_E1(bp)) {
  5747. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5748. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5749. }
  5750. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5751. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5752. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5753. /* init aeu_mask_attn_func_0/1:
  5754. * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
  5755. * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
  5756. * bits 4-7 are used for "per vn group attention" */
  5757. val = IS_MF(bp) ? 0xF7 : 0x7;
  5758. /* Enable DCBX attention for all but E1 */
  5759. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  5760. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  5761. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5762. if (!CHIP_IS_E1x(bp)) {
  5763. /* Bit-map indicating which L2 hdrs may appear after the
  5764. * basic Ethernet header
  5765. */
  5766. if (IS_MF_AFEX(bp))
  5767. REG_WR(bp, BP_PORT(bp) ?
  5768. NIG_REG_P1_HDRS_AFTER_BASIC :
  5769. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  5770. else
  5771. REG_WR(bp, BP_PORT(bp) ?
  5772. NIG_REG_P1_HDRS_AFTER_BASIC :
  5773. NIG_REG_P0_HDRS_AFTER_BASIC,
  5774. IS_MF_SD(bp) ? 7 : 6);
  5775. if (CHIP_IS_E3(bp))
  5776. REG_WR(bp, BP_PORT(bp) ?
  5777. NIG_REG_LLH1_MF_MODE :
  5778. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5779. }
  5780. if (!CHIP_IS_E3(bp))
  5781. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  5782. if (!CHIP_IS_E1(bp)) {
  5783. /* 0x2 disable mf_ov, 0x1 enable */
  5784. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  5785. (IS_MF_SD(bp) ? 0x1 : 0x2));
  5786. if (!CHIP_IS_E1x(bp)) {
  5787. val = 0;
  5788. switch (bp->mf_mode) {
  5789. case MULTI_FUNCTION_SD:
  5790. val = 1;
  5791. break;
  5792. case MULTI_FUNCTION_SI:
  5793. case MULTI_FUNCTION_AFEX:
  5794. val = 2;
  5795. break;
  5796. }
  5797. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  5798. NIG_REG_LLH0_CLS_TYPE), val);
  5799. }
  5800. {
  5801. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  5802. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  5803. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  5804. }
  5805. }
  5806. /* If SPIO5 is set to generate interrupts, enable it for this port */
  5807. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5808. if (val & MISC_SPIO_SPIO5) {
  5809. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  5810. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  5811. val = REG_RD(bp, reg_addr);
  5812. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  5813. REG_WR(bp, reg_addr, val);
  5814. }
  5815. return 0;
  5816. }
  5817. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  5818. {
  5819. int reg;
  5820. u32 wb_write[2];
  5821. if (CHIP_IS_E1(bp))
  5822. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  5823. else
  5824. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  5825. wb_write[0] = ONCHIP_ADDR1(addr);
  5826. wb_write[1] = ONCHIP_ADDR2(addr);
  5827. REG_WR_DMAE(bp, reg, wb_write, 2);
  5828. }
  5829. static void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func,
  5830. u8 idu_sb_id, bool is_Pf)
  5831. {
  5832. u32 data, ctl, cnt = 100;
  5833. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  5834. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  5835. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  5836. u32 sb_bit = 1 << (idu_sb_id%32);
  5837. u32 func_encode = func | (is_Pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  5838. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  5839. /* Not supported in BC mode */
  5840. if (CHIP_INT_MODE_IS_BC(bp))
  5841. return;
  5842. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  5843. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  5844. IGU_REGULAR_CLEANUP_SET |
  5845. IGU_REGULAR_BCLEANUP;
  5846. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  5847. func_encode << IGU_CTRL_REG_FID_SHIFT |
  5848. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  5849. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  5850. data, igu_addr_data);
  5851. REG_WR(bp, igu_addr_data, data);
  5852. mmiowb();
  5853. barrier();
  5854. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  5855. ctl, igu_addr_ctl);
  5856. REG_WR(bp, igu_addr_ctl, ctl);
  5857. mmiowb();
  5858. barrier();
  5859. /* wait for clean up to finish */
  5860. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  5861. msleep(20);
  5862. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  5863. DP(NETIF_MSG_HW,
  5864. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  5865. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  5866. }
  5867. }
  5868. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  5869. {
  5870. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  5871. }
  5872. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  5873. {
  5874. u32 i, base = FUNC_ILT_BASE(func);
  5875. for (i = base; i < base + ILT_PER_FUNC; i++)
  5876. bnx2x_ilt_wr(bp, i, 0);
  5877. }
  5878. static void bnx2x_init_searcher(struct bnx2x *bp)
  5879. {
  5880. int port = BP_PORT(bp);
  5881. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  5882. /* T1 hash bits value determines the T1 number of entries */
  5883. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  5884. }
  5885. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  5886. {
  5887. int rc;
  5888. struct bnx2x_func_state_params func_params = {NULL};
  5889. struct bnx2x_func_switch_update_params *switch_update_params =
  5890. &func_params.params.switch_update;
  5891. /* Prepare parameters for function state transitions */
  5892. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  5893. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  5894. func_params.f_obj = &bp->func_obj;
  5895. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  5896. /* Function parameters */
  5897. switch_update_params->suspend = suspend;
  5898. rc = bnx2x_func_state_change(bp, &func_params);
  5899. return rc;
  5900. }
  5901. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  5902. {
  5903. int rc, i, port = BP_PORT(bp);
  5904. int vlan_en = 0, mac_en[NUM_MACS];
  5905. /* Close input from network */
  5906. if (bp->mf_mode == SINGLE_FUNCTION) {
  5907. bnx2x_set_rx_filter(&bp->link_params, 0);
  5908. } else {
  5909. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  5910. NIG_REG_LLH0_FUNC_EN);
  5911. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  5912. NIG_REG_LLH0_FUNC_EN, 0);
  5913. for (i = 0; i < NUM_MACS; i++) {
  5914. mac_en[i] = REG_RD(bp, port ?
  5915. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  5916. 4 * i) :
  5917. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  5918. 4 * i));
  5919. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  5920. 4 * i) :
  5921. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  5922. }
  5923. }
  5924. /* Close BMC to host */
  5925. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  5926. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  5927. /* Suspend Tx switching to the PF. Completion of this ramrod
  5928. * further guarantees that all the packets of that PF / child
  5929. * VFs in BRB were processed by the Parser, so it is safe to
  5930. * change the NIC_MODE register.
  5931. */
  5932. rc = bnx2x_func_switch_update(bp, 1);
  5933. if (rc) {
  5934. BNX2X_ERR("Can't suspend tx-switching!\n");
  5935. return rc;
  5936. }
  5937. /* Change NIC_MODE register */
  5938. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  5939. /* Open input from network */
  5940. if (bp->mf_mode == SINGLE_FUNCTION) {
  5941. bnx2x_set_rx_filter(&bp->link_params, 1);
  5942. } else {
  5943. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  5944. NIG_REG_LLH0_FUNC_EN, vlan_en);
  5945. for (i = 0; i < NUM_MACS; i++) {
  5946. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  5947. 4 * i) :
  5948. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  5949. mac_en[i]);
  5950. }
  5951. }
  5952. /* Enable BMC to host */
  5953. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  5954. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  5955. /* Resume Tx switching to the PF */
  5956. rc = bnx2x_func_switch_update(bp, 0);
  5957. if (rc) {
  5958. BNX2X_ERR("Can't resume tx-switching!\n");
  5959. return rc;
  5960. }
  5961. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  5962. return 0;
  5963. }
  5964. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  5965. {
  5966. int rc;
  5967. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  5968. if (CONFIGURE_NIC_MODE(bp)) {
  5969. /* Configrue searcher as part of function hw init */
  5970. bnx2x_init_searcher(bp);
  5971. /* Reset NIC mode */
  5972. rc = bnx2x_reset_nic_mode(bp);
  5973. if (rc)
  5974. BNX2X_ERR("Can't change NIC mode!\n");
  5975. return rc;
  5976. }
  5977. return 0;
  5978. }
  5979. static int bnx2x_init_hw_func(struct bnx2x *bp)
  5980. {
  5981. int port = BP_PORT(bp);
  5982. int func = BP_FUNC(bp);
  5983. int init_phase = PHASE_PF0 + func;
  5984. struct bnx2x_ilt *ilt = BP_ILT(bp);
  5985. u16 cdu_ilt_start;
  5986. u32 addr, val;
  5987. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  5988. int i, main_mem_width, rc;
  5989. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  5990. /* FLR cleanup - hmmm */
  5991. if (!CHIP_IS_E1x(bp)) {
  5992. rc = bnx2x_pf_flr_clnup(bp);
  5993. if (rc)
  5994. return rc;
  5995. }
  5996. /* set MSI reconfigure capability */
  5997. if (bp->common.int_block == INT_BLOCK_HC) {
  5998. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  5999. val = REG_RD(bp, addr);
  6000. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6001. REG_WR(bp, addr, val);
  6002. }
  6003. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6004. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6005. ilt = BP_ILT(bp);
  6006. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6007. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6008. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6009. ilt->lines[cdu_ilt_start + i].page_mapping =
  6010. bp->context[i].cxt_mapping;
  6011. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6012. }
  6013. bnx2x_ilt_init_op(bp, INITOP_SET);
  6014. if (!CONFIGURE_NIC_MODE(bp)) {
  6015. bnx2x_init_searcher(bp);
  6016. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6017. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6018. } else {
  6019. /* Set NIC mode */
  6020. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6021. DP(NETIF_MSG_IFUP, "NIC MODE configrued\n");
  6022. }
  6023. if (!CHIP_IS_E1x(bp)) {
  6024. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6025. /* Turn on a single ISR mode in IGU if driver is going to use
  6026. * INT#x or MSI
  6027. */
  6028. if (!(bp->flags & USING_MSIX_FLAG))
  6029. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6030. /*
  6031. * Timers workaround bug: function init part.
  6032. * Need to wait 20msec after initializing ILT,
  6033. * needed to make sure there are no requests in
  6034. * one of the PXP internal queues with "old" ILT addresses
  6035. */
  6036. msleep(20);
  6037. /*
  6038. * Master enable - Due to WB DMAE writes performed before this
  6039. * register is re-initialized as part of the regular function
  6040. * init
  6041. */
  6042. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6043. /* Enable the function in IGU */
  6044. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6045. }
  6046. bp->dmae_ready = 1;
  6047. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6048. if (!CHIP_IS_E1x(bp))
  6049. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  6050. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6051. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6052. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6053. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6054. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6055. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6056. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6057. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6058. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6059. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6060. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6061. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6062. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6063. if (!CHIP_IS_E1x(bp))
  6064. REG_WR(bp, QM_REG_PF_EN, 1);
  6065. if (!CHIP_IS_E1x(bp)) {
  6066. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6067. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6068. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6069. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6070. }
  6071. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6072. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6073. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6074. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6075. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6076. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6077. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6078. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6079. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6080. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6081. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6082. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6083. if (!CHIP_IS_E1x(bp))
  6084. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6085. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6086. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6087. if (!CHIP_IS_E1x(bp))
  6088. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6089. if (IS_MF(bp)) {
  6090. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  6091. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  6092. }
  6093. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6094. /* HC init per function */
  6095. if (bp->common.int_block == INT_BLOCK_HC) {
  6096. if (CHIP_IS_E1H(bp)) {
  6097. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6098. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6099. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6100. }
  6101. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6102. } else {
  6103. int num_segs, sb_idx, prod_offset;
  6104. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6105. if (!CHIP_IS_E1x(bp)) {
  6106. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6107. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6108. }
  6109. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6110. if (!CHIP_IS_E1x(bp)) {
  6111. int dsb_idx = 0;
  6112. /**
  6113. * Producer memory:
  6114. * E2 mode: address 0-135 match to the mapping memory;
  6115. * 136 - PF0 default prod; 137 - PF1 default prod;
  6116. * 138 - PF2 default prod; 139 - PF3 default prod;
  6117. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6118. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6119. * 144-147 reserved.
  6120. *
  6121. * E1.5 mode - In backward compatible mode;
  6122. * for non default SB; each even line in the memory
  6123. * holds the U producer and each odd line hold
  6124. * the C producer. The first 128 producers are for
  6125. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6126. * producers are for the DSB for each PF.
  6127. * Each PF has five segments: (the order inside each
  6128. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6129. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6130. * 144-147 attn prods;
  6131. */
  6132. /* non-default-status-blocks */
  6133. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6134. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6135. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6136. prod_offset = (bp->igu_base_sb + sb_idx) *
  6137. num_segs;
  6138. for (i = 0; i < num_segs; i++) {
  6139. addr = IGU_REG_PROD_CONS_MEMORY +
  6140. (prod_offset + i) * 4;
  6141. REG_WR(bp, addr, 0);
  6142. }
  6143. /* send consumer update with value 0 */
  6144. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6145. USTORM_ID, 0, IGU_INT_NOP, 1);
  6146. bnx2x_igu_clear_sb(bp,
  6147. bp->igu_base_sb + sb_idx);
  6148. }
  6149. /* default-status-blocks */
  6150. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6151. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6152. if (CHIP_MODE_IS_4_PORT(bp))
  6153. dsb_idx = BP_FUNC(bp);
  6154. else
  6155. dsb_idx = BP_VN(bp);
  6156. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6157. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6158. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6159. /*
  6160. * igu prods come in chunks of E1HVN_MAX (4) -
  6161. * does not matters what is the current chip mode
  6162. */
  6163. for (i = 0; i < (num_segs * E1HVN_MAX);
  6164. i += E1HVN_MAX) {
  6165. addr = IGU_REG_PROD_CONS_MEMORY +
  6166. (prod_offset + i)*4;
  6167. REG_WR(bp, addr, 0);
  6168. }
  6169. /* send consumer update with 0 */
  6170. if (CHIP_INT_MODE_IS_BC(bp)) {
  6171. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6172. USTORM_ID, 0, IGU_INT_NOP, 1);
  6173. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6174. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6175. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6176. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6177. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6178. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6179. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6180. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6181. } else {
  6182. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6183. USTORM_ID, 0, IGU_INT_NOP, 1);
  6184. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6185. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6186. }
  6187. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6188. /* !!! these should become driver const once
  6189. rf-tool supports split-68 const */
  6190. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6191. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6192. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6193. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6194. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6195. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6196. }
  6197. }
  6198. /* Reset PCIE errors for debug */
  6199. REG_WR(bp, 0x2114, 0xffffffff);
  6200. REG_WR(bp, 0x2120, 0xffffffff);
  6201. if (CHIP_IS_E1x(bp)) {
  6202. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6203. main_mem_base = HC_REG_MAIN_MEMORY +
  6204. BP_PORT(bp) * (main_mem_size * 4);
  6205. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6206. main_mem_width = 8;
  6207. val = REG_RD(bp, main_mem_prty_clr);
  6208. if (val)
  6209. DP(NETIF_MSG_HW,
  6210. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6211. val);
  6212. /* Clear "false" parity errors in MSI-X table */
  6213. for (i = main_mem_base;
  6214. i < main_mem_base + main_mem_size * 4;
  6215. i += main_mem_width) {
  6216. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6217. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6218. i, main_mem_width / 4);
  6219. }
  6220. /* Clear HC parity attention */
  6221. REG_RD(bp, main_mem_prty_clr);
  6222. }
  6223. #ifdef BNX2X_STOP_ON_ERROR
  6224. /* Enable STORMs SP logging */
  6225. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6226. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6227. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6228. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6229. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6230. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6231. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6232. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6233. #endif
  6234. bnx2x_phy_probe(&bp->link_params);
  6235. return 0;
  6236. }
  6237. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6238. {
  6239. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6240. if (!CHIP_IS_E1x(bp))
  6241. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6242. sizeof(struct host_hc_status_block_e2));
  6243. else
  6244. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6245. sizeof(struct host_hc_status_block_e1x));
  6246. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6247. }
  6248. void bnx2x_free_mem(struct bnx2x *bp)
  6249. {
  6250. int i;
  6251. /* fastpath */
  6252. bnx2x_free_fp_mem(bp);
  6253. /* end of fastpath */
  6254. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6255. sizeof(struct host_sp_status_block));
  6256. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6257. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6258. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6259. sizeof(struct bnx2x_slowpath));
  6260. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6261. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6262. bp->context[i].size);
  6263. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6264. BNX2X_FREE(bp->ilt->lines);
  6265. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6266. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6267. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6268. }
  6269. static int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp)
  6270. {
  6271. int num_groups;
  6272. int is_fcoe_stats = NO_FCOE(bp) ? 0 : 1;
  6273. /* number of queues for statistics is number of eth queues + FCoE */
  6274. u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp) + is_fcoe_stats;
  6275. /* Total number of FW statistics requests =
  6276. * 1 for port stats + 1 for PF stats + potential 1 for FCoE stats +
  6277. * num of queues
  6278. */
  6279. bp->fw_stats_num = 2 + is_fcoe_stats + num_queue_stats;
  6280. /* Request is built from stats_query_header and an array of
  6281. * stats_query_cmd_group each of which contains
  6282. * STATS_QUERY_CMD_COUNT rules. The real number or requests is
  6283. * configured in the stats_query_header.
  6284. */
  6285. num_groups = ((bp->fw_stats_num) / STATS_QUERY_CMD_COUNT) +
  6286. (((bp->fw_stats_num) % STATS_QUERY_CMD_COUNT) ? 1 : 0);
  6287. bp->fw_stats_req_sz = sizeof(struct stats_query_header) +
  6288. num_groups * sizeof(struct stats_query_cmd_group);
  6289. /* Data for statistics requests + stats_conter
  6290. *
  6291. * stats_counter holds per-STORM counters that are incremented
  6292. * when STORM has finished with the current request.
  6293. *
  6294. * memory for FCoE offloaded statistics are counted anyway,
  6295. * even if they will not be sent.
  6296. */
  6297. bp->fw_stats_data_sz = sizeof(struct per_port_stats) +
  6298. sizeof(struct per_pf_stats) +
  6299. sizeof(struct fcoe_statistics_params) +
  6300. sizeof(struct per_queue_stats) * num_queue_stats +
  6301. sizeof(struct stats_counter);
  6302. BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping,
  6303. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6304. /* Set shortcuts */
  6305. bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats;
  6306. bp->fw_stats_req_mapping = bp->fw_stats_mapping;
  6307. bp->fw_stats_data = (struct bnx2x_fw_stats_data *)
  6308. ((u8 *)bp->fw_stats + bp->fw_stats_req_sz);
  6309. bp->fw_stats_data_mapping = bp->fw_stats_mapping +
  6310. bp->fw_stats_req_sz;
  6311. return 0;
  6312. alloc_mem_err:
  6313. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6314. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6315. BNX2X_ERR("Can't allocate memory\n");
  6316. return -ENOMEM;
  6317. }
  6318. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6319. {
  6320. if (!CHIP_IS_E1x(bp))
  6321. /* size = the status block + ramrod buffers */
  6322. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  6323. sizeof(struct host_hc_status_block_e2));
  6324. else
  6325. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
  6326. &bp->cnic_sb_mapping,
  6327. sizeof(struct
  6328. host_hc_status_block_e1x));
  6329. if (CONFIGURE_NIC_MODE(bp))
  6330. /* allocate searcher T2 table, as it wan't allocated before */
  6331. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6332. /* write address to which L5 should insert its values */
  6333. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6334. &bp->slowpath->drv_info_to_mcp;
  6335. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6336. goto alloc_mem_err;
  6337. return 0;
  6338. alloc_mem_err:
  6339. bnx2x_free_mem_cnic(bp);
  6340. BNX2X_ERR("Can't allocate memory\n");
  6341. return -ENOMEM;
  6342. }
  6343. int bnx2x_alloc_mem(struct bnx2x *bp)
  6344. {
  6345. int i, allocated, context_size;
  6346. if (!CONFIGURE_NIC_MODE(bp))
  6347. /* allocate searcher T2 table */
  6348. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6349. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  6350. sizeof(struct host_sp_status_block));
  6351. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  6352. sizeof(struct bnx2x_slowpath));
  6353. /* Allocated memory for FW statistics */
  6354. if (bnx2x_alloc_fw_stats_mem(bp))
  6355. goto alloc_mem_err;
  6356. /* Allocate memory for CDU context:
  6357. * This memory is allocated separately and not in the generic ILT
  6358. * functions because CDU differs in few aspects:
  6359. * 1. There are multiple entities allocating memory for context -
  6360. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6361. * its own ILT lines.
  6362. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6363. * for the other ILT clients), to be efficient we want to support
  6364. * allocation of sub-page-size in the last entry.
  6365. * 3. Context pointers are used by the driver to pass to FW / update
  6366. * the context (for the other ILT clients the pointers are used just to
  6367. * free the memory during unload).
  6368. */
  6369. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6370. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6371. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6372. (context_size - allocated));
  6373. BNX2X_PCI_ALLOC(bp->context[i].vcxt,
  6374. &bp->context[i].cxt_mapping,
  6375. bp->context[i].size);
  6376. allocated += bp->context[i].size;
  6377. }
  6378. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  6379. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6380. goto alloc_mem_err;
  6381. /* Slow path ring */
  6382. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  6383. /* EQ */
  6384. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  6385. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6386. /* fastpath */
  6387. /* need to be done at the end, since it's self adjusting to amount
  6388. * of memory available for RSS queues
  6389. */
  6390. if (bnx2x_alloc_fp_mem(bp))
  6391. goto alloc_mem_err;
  6392. return 0;
  6393. alloc_mem_err:
  6394. bnx2x_free_mem(bp);
  6395. BNX2X_ERR("Can't allocate memory\n");
  6396. return -ENOMEM;
  6397. }
  6398. /*
  6399. * Init service functions
  6400. */
  6401. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6402. struct bnx2x_vlan_mac_obj *obj, bool set,
  6403. int mac_type, unsigned long *ramrod_flags)
  6404. {
  6405. int rc;
  6406. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6407. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6408. /* Fill general parameters */
  6409. ramrod_param.vlan_mac_obj = obj;
  6410. ramrod_param.ramrod_flags = *ramrod_flags;
  6411. /* Fill a user request section if needed */
  6412. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6413. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6414. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6415. /* Set the command: ADD or DEL */
  6416. if (set)
  6417. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6418. else
  6419. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6420. }
  6421. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6422. if (rc == -EEXIST) {
  6423. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  6424. /* do not treat adding same MAC as error */
  6425. rc = 0;
  6426. } else if (rc < 0)
  6427. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6428. return rc;
  6429. }
  6430. int bnx2x_del_all_macs(struct bnx2x *bp,
  6431. struct bnx2x_vlan_mac_obj *mac_obj,
  6432. int mac_type, bool wait_for_comp)
  6433. {
  6434. int rc;
  6435. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6436. /* Wait for completion of requested */
  6437. if (wait_for_comp)
  6438. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6439. /* Set the mac type of addresses we want to clear */
  6440. __set_bit(mac_type, &vlan_mac_flags);
  6441. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6442. if (rc < 0)
  6443. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6444. return rc;
  6445. }
  6446. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6447. {
  6448. unsigned long ramrod_flags = 0;
  6449. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6450. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6451. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6452. "Ignoring Zero MAC for STORAGE SD mode\n");
  6453. return 0;
  6454. }
  6455. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6456. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6457. /* Eth MAC is set on RSS leading client (fp[0]) */
  6458. return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->sp_objs->mac_obj,
  6459. set, BNX2X_ETH_MAC, &ramrod_flags);
  6460. }
  6461. int bnx2x_setup_leading(struct bnx2x *bp)
  6462. {
  6463. return bnx2x_setup_queue(bp, &bp->fp[0], 1);
  6464. }
  6465. /**
  6466. * bnx2x_set_int_mode - configure interrupt mode
  6467. *
  6468. * @bp: driver handle
  6469. *
  6470. * In case of MSI-X it will also try to enable MSI-X.
  6471. */
  6472. void bnx2x_set_int_mode(struct bnx2x *bp)
  6473. {
  6474. switch (int_mode) {
  6475. case INT_MODE_MSI:
  6476. bnx2x_enable_msi(bp);
  6477. /* falling through... */
  6478. case INT_MODE_INTx:
  6479. bp->num_ethernet_queues = 1;
  6480. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  6481. BNX2X_DEV_INFO("set number of queues to 1\n");
  6482. break;
  6483. default:
  6484. /* if we can't use MSI-X we only need one fp,
  6485. * so try to enable MSI-X with the requested number of fp's
  6486. * and fallback to MSI or legacy INTx with one fp
  6487. */
  6488. if (bnx2x_enable_msix(bp) ||
  6489. bp->flags & USING_SINGLE_MSIX_FLAG) {
  6490. /* failed to enable multiple MSI-X */
  6491. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  6492. bp->num_queues,
  6493. 1 + bp->num_cnic_queues);
  6494. bp->num_queues = 1 + bp->num_cnic_queues;
  6495. /* Try to enable MSI */
  6496. if (!(bp->flags & USING_SINGLE_MSIX_FLAG) &&
  6497. !(bp->flags & DISABLE_MSI_FLAG))
  6498. bnx2x_enable_msi(bp);
  6499. }
  6500. break;
  6501. }
  6502. }
  6503. /* must be called prioir to any HW initializations */
  6504. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  6505. {
  6506. return L2_ILT_LINES(bp);
  6507. }
  6508. void bnx2x_ilt_set_info(struct bnx2x *bp)
  6509. {
  6510. struct ilt_client_info *ilt_client;
  6511. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6512. u16 line = 0;
  6513. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  6514. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  6515. /* CDU */
  6516. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  6517. ilt_client->client_num = ILT_CLIENT_CDU;
  6518. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  6519. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  6520. ilt_client->start = line;
  6521. line += bnx2x_cid_ilt_lines(bp);
  6522. if (CNIC_SUPPORT(bp))
  6523. line += CNIC_ILT_LINES;
  6524. ilt_client->end = line - 1;
  6525. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6526. ilt_client->start,
  6527. ilt_client->end,
  6528. ilt_client->page_size,
  6529. ilt_client->flags,
  6530. ilog2(ilt_client->page_size >> 12));
  6531. /* QM */
  6532. if (QM_INIT(bp->qm_cid_count)) {
  6533. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  6534. ilt_client->client_num = ILT_CLIENT_QM;
  6535. ilt_client->page_size = QM_ILT_PAGE_SZ;
  6536. ilt_client->flags = 0;
  6537. ilt_client->start = line;
  6538. /* 4 bytes for each cid */
  6539. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  6540. QM_ILT_PAGE_SZ);
  6541. ilt_client->end = line - 1;
  6542. DP(NETIF_MSG_IFUP,
  6543. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6544. ilt_client->start,
  6545. ilt_client->end,
  6546. ilt_client->page_size,
  6547. ilt_client->flags,
  6548. ilog2(ilt_client->page_size >> 12));
  6549. }
  6550. if (CNIC_SUPPORT(bp)) {
  6551. /* SRC */
  6552. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  6553. ilt_client->client_num = ILT_CLIENT_SRC;
  6554. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  6555. ilt_client->flags = 0;
  6556. ilt_client->start = line;
  6557. line += SRC_ILT_LINES;
  6558. ilt_client->end = line - 1;
  6559. DP(NETIF_MSG_IFUP,
  6560. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6561. ilt_client->start,
  6562. ilt_client->end,
  6563. ilt_client->page_size,
  6564. ilt_client->flags,
  6565. ilog2(ilt_client->page_size >> 12));
  6566. /* TM */
  6567. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  6568. ilt_client->client_num = ILT_CLIENT_TM;
  6569. ilt_client->page_size = TM_ILT_PAGE_SZ;
  6570. ilt_client->flags = 0;
  6571. ilt_client->start = line;
  6572. line += TM_ILT_LINES;
  6573. ilt_client->end = line - 1;
  6574. DP(NETIF_MSG_IFUP,
  6575. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6576. ilt_client->start,
  6577. ilt_client->end,
  6578. ilt_client->page_size,
  6579. ilt_client->flags,
  6580. ilog2(ilt_client->page_size >> 12));
  6581. }
  6582. BUG_ON(line > ILT_MAX_LINES);
  6583. }
  6584. /**
  6585. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6586. *
  6587. * @bp: driver handle
  6588. * @fp: pointer to fastpath
  6589. * @init_params: pointer to parameters structure
  6590. *
  6591. * parameters configured:
  6592. * - HC configuration
  6593. * - Queue's CDU context
  6594. */
  6595. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  6596. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  6597. {
  6598. u8 cos;
  6599. int cxt_index, cxt_offset;
  6600. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  6601. if (!IS_FCOE_FP(fp)) {
  6602. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  6603. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  6604. /* If HC is supporterd, enable host coalescing in the transition
  6605. * to INIT state.
  6606. */
  6607. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  6608. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  6609. /* HC rate */
  6610. init_params->rx.hc_rate = bp->rx_ticks ?
  6611. (1000000 / bp->rx_ticks) : 0;
  6612. init_params->tx.hc_rate = bp->tx_ticks ?
  6613. (1000000 / bp->tx_ticks) : 0;
  6614. /* FW SB ID */
  6615. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  6616. fp->fw_sb_id;
  6617. /*
  6618. * CQ index among the SB indices: FCoE clients uses the default
  6619. * SB, therefore it's different.
  6620. */
  6621. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  6622. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  6623. }
  6624. /* set maximum number of COSs supported by this queue */
  6625. init_params->max_cos = fp->max_cos;
  6626. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  6627. fp->index, init_params->max_cos);
  6628. /* set the context pointers queue object */
  6629. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  6630. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  6631. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  6632. ILT_PAGE_CIDS);
  6633. init_params->cxts[cos] =
  6634. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  6635. }
  6636. }
  6637. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6638. struct bnx2x_queue_state_params *q_params,
  6639. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  6640. int tx_index, bool leading)
  6641. {
  6642. memset(tx_only_params, 0, sizeof(*tx_only_params));
  6643. /* Set the command */
  6644. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  6645. /* Set tx-only QUEUE flags: don't zero statistics */
  6646. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  6647. /* choose the index of the cid to send the slow path on */
  6648. tx_only_params->cid_index = tx_index;
  6649. /* Set general TX_ONLY_SETUP parameters */
  6650. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  6651. /* Set Tx TX_ONLY_SETUP parameters */
  6652. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  6653. DP(NETIF_MSG_IFUP,
  6654. "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",
  6655. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  6656. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  6657. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  6658. /* send the ramrod */
  6659. return bnx2x_queue_state_change(bp, q_params);
  6660. }
  6661. /**
  6662. * bnx2x_setup_queue - setup queue
  6663. *
  6664. * @bp: driver handle
  6665. * @fp: pointer to fastpath
  6666. * @leading: is leading
  6667. *
  6668. * This function performs 2 steps in a Queue state machine
  6669. * actually: 1) RESET->INIT 2) INIT->SETUP
  6670. */
  6671. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6672. bool leading)
  6673. {
  6674. struct bnx2x_queue_state_params q_params = {NULL};
  6675. struct bnx2x_queue_setup_params *setup_params =
  6676. &q_params.params.setup;
  6677. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  6678. &q_params.params.tx_only;
  6679. int rc;
  6680. u8 tx_index;
  6681. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  6682. /* reset IGU state skip FCoE L2 queue */
  6683. if (!IS_FCOE_FP(fp))
  6684. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  6685. IGU_INT_ENABLE, 0);
  6686. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6687. /* We want to wait for completion in this context */
  6688. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6689. /* Prepare the INIT parameters */
  6690. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  6691. /* Set the command */
  6692. q_params.cmd = BNX2X_Q_CMD_INIT;
  6693. /* Change the state to INIT */
  6694. rc = bnx2x_queue_state_change(bp, &q_params);
  6695. if (rc) {
  6696. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  6697. return rc;
  6698. }
  6699. DP(NETIF_MSG_IFUP, "init complete\n");
  6700. /* Now move the Queue to the SETUP state... */
  6701. memset(setup_params, 0, sizeof(*setup_params));
  6702. /* Set QUEUE flags */
  6703. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  6704. /* Set general SETUP parameters */
  6705. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  6706. FIRST_TX_COS_INDEX);
  6707. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  6708. &setup_params->rxq_params);
  6709. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  6710. FIRST_TX_COS_INDEX);
  6711. /* Set the command */
  6712. q_params.cmd = BNX2X_Q_CMD_SETUP;
  6713. if (IS_FCOE_FP(fp))
  6714. bp->fcoe_init = true;
  6715. /* Change the state to SETUP */
  6716. rc = bnx2x_queue_state_change(bp, &q_params);
  6717. if (rc) {
  6718. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  6719. return rc;
  6720. }
  6721. /* loop through the relevant tx-only indices */
  6722. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6723. tx_index < fp->max_cos;
  6724. tx_index++) {
  6725. /* prepare and send tx-only ramrod*/
  6726. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  6727. tx_only_params, tx_index, leading);
  6728. if (rc) {
  6729. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  6730. fp->index, tx_index);
  6731. return rc;
  6732. }
  6733. }
  6734. return rc;
  6735. }
  6736. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  6737. {
  6738. struct bnx2x_fastpath *fp = &bp->fp[index];
  6739. struct bnx2x_fp_txdata *txdata;
  6740. struct bnx2x_queue_state_params q_params = {NULL};
  6741. int rc, tx_index;
  6742. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  6743. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6744. /* We want to wait for completion in this context */
  6745. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6746. /* close tx-only connections */
  6747. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6748. tx_index < fp->max_cos;
  6749. tx_index++){
  6750. /* ascertain this is a normal queue*/
  6751. txdata = fp->txdata_ptr[tx_index];
  6752. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  6753. txdata->txq_index);
  6754. /* send halt terminate on tx-only connection */
  6755. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6756. memset(&q_params.params.terminate, 0,
  6757. sizeof(q_params.params.terminate));
  6758. q_params.params.terminate.cid_index = tx_index;
  6759. rc = bnx2x_queue_state_change(bp, &q_params);
  6760. if (rc)
  6761. return rc;
  6762. /* send halt terminate on tx-only connection */
  6763. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6764. memset(&q_params.params.cfc_del, 0,
  6765. sizeof(q_params.params.cfc_del));
  6766. q_params.params.cfc_del.cid_index = tx_index;
  6767. rc = bnx2x_queue_state_change(bp, &q_params);
  6768. if (rc)
  6769. return rc;
  6770. }
  6771. /* Stop the primary connection: */
  6772. /* ...halt the connection */
  6773. q_params.cmd = BNX2X_Q_CMD_HALT;
  6774. rc = bnx2x_queue_state_change(bp, &q_params);
  6775. if (rc)
  6776. return rc;
  6777. /* ...terminate the connection */
  6778. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6779. memset(&q_params.params.terminate, 0,
  6780. sizeof(q_params.params.terminate));
  6781. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  6782. rc = bnx2x_queue_state_change(bp, &q_params);
  6783. if (rc)
  6784. return rc;
  6785. /* ...delete cfc entry */
  6786. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6787. memset(&q_params.params.cfc_del, 0,
  6788. sizeof(q_params.params.cfc_del));
  6789. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  6790. return bnx2x_queue_state_change(bp, &q_params);
  6791. }
  6792. static void bnx2x_reset_func(struct bnx2x *bp)
  6793. {
  6794. int port = BP_PORT(bp);
  6795. int func = BP_FUNC(bp);
  6796. int i;
  6797. /* Disable the function in the FW */
  6798. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  6799. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  6800. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  6801. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  6802. /* FP SBs */
  6803. for_each_eth_queue(bp, i) {
  6804. struct bnx2x_fastpath *fp = &bp->fp[i];
  6805. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6806. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  6807. SB_DISABLED);
  6808. }
  6809. if (CNIC_LOADED(bp))
  6810. /* CNIC SB */
  6811. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6812. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  6813. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  6814. /* SP SB */
  6815. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6816. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  6817. SB_DISABLED);
  6818. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  6819. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  6820. 0);
  6821. /* Configure IGU */
  6822. if (bp->common.int_block == INT_BLOCK_HC) {
  6823. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6824. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6825. } else {
  6826. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6827. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6828. }
  6829. if (CNIC_LOADED(bp)) {
  6830. /* Disable Timer scan */
  6831. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  6832. /*
  6833. * Wait for at least 10ms and up to 2 second for the timers
  6834. * scan to complete
  6835. */
  6836. for (i = 0; i < 200; i++) {
  6837. msleep(10);
  6838. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  6839. break;
  6840. }
  6841. }
  6842. /* Clear ILT */
  6843. bnx2x_clear_func_ilt(bp, func);
  6844. /* Timers workaround bug for E2: if this is vnic-3,
  6845. * we need to set the entire ilt range for this timers.
  6846. */
  6847. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  6848. struct ilt_client_info ilt_cli;
  6849. /* use dummy TM client */
  6850. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  6851. ilt_cli.start = 0;
  6852. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  6853. ilt_cli.client_num = ILT_CLIENT_TM;
  6854. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  6855. }
  6856. /* this assumes that reset_port() called before reset_func()*/
  6857. if (!CHIP_IS_E1x(bp))
  6858. bnx2x_pf_disable(bp);
  6859. bp->dmae_ready = 0;
  6860. }
  6861. static void bnx2x_reset_port(struct bnx2x *bp)
  6862. {
  6863. int port = BP_PORT(bp);
  6864. u32 val;
  6865. /* Reset physical Link */
  6866. bnx2x__link_reset(bp);
  6867. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6868. /* Do not rcv packets to BRB */
  6869. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  6870. /* Do not direct rcv packets that are not for MCP to the BRB */
  6871. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  6872. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  6873. /* Configure AEU */
  6874. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  6875. msleep(100);
  6876. /* Check for BRB port occupancy */
  6877. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  6878. if (val)
  6879. DP(NETIF_MSG_IFDOWN,
  6880. "BRB1 is not empty %d blocks are occupied\n", val);
  6881. /* TODO: Close Doorbell port? */
  6882. }
  6883. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  6884. {
  6885. struct bnx2x_func_state_params func_params = {NULL};
  6886. /* Prepare parameters for function state transitions */
  6887. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6888. func_params.f_obj = &bp->func_obj;
  6889. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  6890. func_params.params.hw_init.load_phase = load_code;
  6891. return bnx2x_func_state_change(bp, &func_params);
  6892. }
  6893. static int bnx2x_func_stop(struct bnx2x *bp)
  6894. {
  6895. struct bnx2x_func_state_params func_params = {NULL};
  6896. int rc;
  6897. /* Prepare parameters for function state transitions */
  6898. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6899. func_params.f_obj = &bp->func_obj;
  6900. func_params.cmd = BNX2X_F_CMD_STOP;
  6901. /*
  6902. * Try to stop the function the 'good way'. If fails (in case
  6903. * of a parity error during bnx2x_chip_cleanup()) and we are
  6904. * not in a debug mode, perform a state transaction in order to
  6905. * enable further HW_RESET transaction.
  6906. */
  6907. rc = bnx2x_func_state_change(bp, &func_params);
  6908. if (rc) {
  6909. #ifdef BNX2X_STOP_ON_ERROR
  6910. return rc;
  6911. #else
  6912. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  6913. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  6914. return bnx2x_func_state_change(bp, &func_params);
  6915. #endif
  6916. }
  6917. return 0;
  6918. }
  6919. /**
  6920. * bnx2x_send_unload_req - request unload mode from the MCP.
  6921. *
  6922. * @bp: driver handle
  6923. * @unload_mode: requested function's unload mode
  6924. *
  6925. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  6926. */
  6927. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  6928. {
  6929. u32 reset_code = 0;
  6930. int port = BP_PORT(bp);
  6931. /* Select the UNLOAD request mode */
  6932. if (unload_mode == UNLOAD_NORMAL)
  6933. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6934. else if (bp->flags & NO_WOL_FLAG)
  6935. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  6936. else if (bp->wol) {
  6937. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  6938. u8 *mac_addr = bp->dev->dev_addr;
  6939. u32 val;
  6940. u16 pmc;
  6941. /* The mac address is written to entries 1-4 to
  6942. * preserve entry 0 which is used by the PMF
  6943. */
  6944. u8 entry = (BP_VN(bp) + 1)*8;
  6945. val = (mac_addr[0] << 8) | mac_addr[1];
  6946. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  6947. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  6948. (mac_addr[4] << 8) | mac_addr[5];
  6949. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  6950. /* Enable the PME and clear the status */
  6951. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
  6952. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  6953. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
  6954. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  6955. } else
  6956. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6957. /* Send the request to the MCP */
  6958. if (!BP_NOMCP(bp))
  6959. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  6960. else {
  6961. int path = BP_PATH(bp);
  6962. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  6963. path, load_count[path][0], load_count[path][1],
  6964. load_count[path][2]);
  6965. load_count[path][0]--;
  6966. load_count[path][1 + port]--;
  6967. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  6968. path, load_count[path][0], load_count[path][1],
  6969. load_count[path][2]);
  6970. if (load_count[path][0] == 0)
  6971. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  6972. else if (load_count[path][1 + port] == 0)
  6973. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  6974. else
  6975. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  6976. }
  6977. return reset_code;
  6978. }
  6979. /**
  6980. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  6981. *
  6982. * @bp: driver handle
  6983. * @keep_link: true iff link should be kept up
  6984. */
  6985. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  6986. {
  6987. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  6988. /* Report UNLOAD_DONE to MCP */
  6989. if (!BP_NOMCP(bp))
  6990. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  6991. }
  6992. static int bnx2x_func_wait_started(struct bnx2x *bp)
  6993. {
  6994. int tout = 50;
  6995. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  6996. if (!bp->port.pmf)
  6997. return 0;
  6998. /*
  6999. * (assumption: No Attention from MCP at this stage)
  7000. * PMF probably in the middle of TXdisable/enable transaction
  7001. * 1. Sync IRS for default SB
  7002. * 2. Sync SP queue - this guarantes us that attention handling started
  7003. * 3. Wait, that TXdisable/enable transaction completes
  7004. *
  7005. * 1+2 guranty that if DCBx attention was scheduled it already changed
  7006. * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
  7007. * received complettion for the transaction the state is TX_STOPPED.
  7008. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7009. * transaction.
  7010. */
  7011. /* make sure default SB ISR is done */
  7012. if (msix)
  7013. synchronize_irq(bp->msix_table[0].vector);
  7014. else
  7015. synchronize_irq(bp->pdev->irq);
  7016. flush_workqueue(bnx2x_wq);
  7017. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7018. BNX2X_F_STATE_STARTED && tout--)
  7019. msleep(20);
  7020. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7021. BNX2X_F_STATE_STARTED) {
  7022. #ifdef BNX2X_STOP_ON_ERROR
  7023. BNX2X_ERR("Wrong function state\n");
  7024. return -EBUSY;
  7025. #else
  7026. /*
  7027. * Failed to complete the transaction in a "good way"
  7028. * Force both transactions with CLR bit
  7029. */
  7030. struct bnx2x_func_state_params func_params = {NULL};
  7031. DP(NETIF_MSG_IFDOWN,
  7032. "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  7033. func_params.f_obj = &bp->func_obj;
  7034. __set_bit(RAMROD_DRV_CLR_ONLY,
  7035. &func_params.ramrod_flags);
  7036. /* STARTED-->TX_ST0PPED */
  7037. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7038. bnx2x_func_state_change(bp, &func_params);
  7039. /* TX_ST0PPED-->STARTED */
  7040. func_params.cmd = BNX2X_F_CMD_TX_START;
  7041. return bnx2x_func_state_change(bp, &func_params);
  7042. #endif
  7043. }
  7044. return 0;
  7045. }
  7046. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7047. {
  7048. int port = BP_PORT(bp);
  7049. int i, rc = 0;
  7050. u8 cos;
  7051. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7052. u32 reset_code;
  7053. /* Wait until tx fastpath tasks complete */
  7054. for_each_tx_queue(bp, i) {
  7055. struct bnx2x_fastpath *fp = &bp->fp[i];
  7056. for_each_cos_in_tx_queue(fp, cos)
  7057. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7058. #ifdef BNX2X_STOP_ON_ERROR
  7059. if (rc)
  7060. return;
  7061. #endif
  7062. }
  7063. /* Give HW time to discard old tx messages */
  7064. usleep_range(1000, 1000);
  7065. /* Clean all ETH MACs */
  7066. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7067. false);
  7068. if (rc < 0)
  7069. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7070. /* Clean up UC list */
  7071. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7072. true);
  7073. if (rc < 0)
  7074. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7075. rc);
  7076. /* Disable LLH */
  7077. if (!CHIP_IS_E1(bp))
  7078. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7079. /* Set "drop all" (stop Rx).
  7080. * We need to take a netif_addr_lock() here in order to prevent
  7081. * a race between the completion code and this code.
  7082. */
  7083. netif_addr_lock_bh(bp->dev);
  7084. /* Schedule the rx_mode command */
  7085. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7086. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7087. else
  7088. bnx2x_set_storm_rx_mode(bp);
  7089. /* Cleanup multicast configuration */
  7090. rparam.mcast_obj = &bp->mcast_obj;
  7091. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7092. if (rc < 0)
  7093. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7094. netif_addr_unlock_bh(bp->dev);
  7095. /*
  7096. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7097. * this function should perform FUNC, PORT or COMMON HW
  7098. * reset.
  7099. */
  7100. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7101. /*
  7102. * (assumption: No Attention from MCP at this stage)
  7103. * PMF probably in the middle of TXdisable/enable transaction
  7104. */
  7105. rc = bnx2x_func_wait_started(bp);
  7106. if (rc) {
  7107. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7108. #ifdef BNX2X_STOP_ON_ERROR
  7109. return;
  7110. #endif
  7111. }
  7112. /* Close multi and leading connections
  7113. * Completions for ramrods are collected in a synchronous way
  7114. */
  7115. for_each_eth_queue(bp, i)
  7116. if (bnx2x_stop_queue(bp, i))
  7117. #ifdef BNX2X_STOP_ON_ERROR
  7118. return;
  7119. #else
  7120. goto unload_error;
  7121. #endif
  7122. if (CNIC_LOADED(bp)) {
  7123. for_each_cnic_queue(bp, i)
  7124. if (bnx2x_stop_queue(bp, i))
  7125. #ifdef BNX2X_STOP_ON_ERROR
  7126. return;
  7127. #else
  7128. goto unload_error;
  7129. #endif
  7130. }
  7131. /* If SP settings didn't get completed so far - something
  7132. * very wrong has happen.
  7133. */
  7134. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7135. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7136. #ifndef BNX2X_STOP_ON_ERROR
  7137. unload_error:
  7138. #endif
  7139. rc = bnx2x_func_stop(bp);
  7140. if (rc) {
  7141. BNX2X_ERR("Function stop failed!\n");
  7142. #ifdef BNX2X_STOP_ON_ERROR
  7143. return;
  7144. #endif
  7145. }
  7146. /* Disable HW interrupts, NAPI */
  7147. bnx2x_netif_stop(bp, 1);
  7148. /* Delete all NAPI objects */
  7149. bnx2x_del_all_napi(bp);
  7150. if (CNIC_LOADED(bp))
  7151. bnx2x_del_all_napi_cnic(bp);
  7152. /* Release IRQs */
  7153. bnx2x_free_irq(bp);
  7154. /* Reset the chip */
  7155. rc = bnx2x_reset_hw(bp, reset_code);
  7156. if (rc)
  7157. BNX2X_ERR("HW_RESET failed\n");
  7158. /* Report UNLOAD_DONE to MCP */
  7159. bnx2x_send_unload_done(bp, keep_link);
  7160. }
  7161. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7162. {
  7163. u32 val;
  7164. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7165. if (CHIP_IS_E1(bp)) {
  7166. int port = BP_PORT(bp);
  7167. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7168. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7169. val = REG_RD(bp, addr);
  7170. val &= ~(0x300);
  7171. REG_WR(bp, addr, val);
  7172. } else {
  7173. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7174. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7175. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7176. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7177. }
  7178. }
  7179. /* Close gates #2, #3 and #4: */
  7180. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7181. {
  7182. u32 val;
  7183. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7184. if (!CHIP_IS_E1(bp)) {
  7185. /* #4 */
  7186. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7187. /* #2 */
  7188. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7189. }
  7190. /* #3 */
  7191. if (CHIP_IS_E1x(bp)) {
  7192. /* Prevent interrupts from HC on both ports */
  7193. val = REG_RD(bp, HC_REG_CONFIG_1);
  7194. REG_WR(bp, HC_REG_CONFIG_1,
  7195. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7196. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7197. val = REG_RD(bp, HC_REG_CONFIG_0);
  7198. REG_WR(bp, HC_REG_CONFIG_0,
  7199. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7200. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7201. } else {
  7202. /* Prevent incomming interrupts in IGU */
  7203. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7204. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7205. (!close) ?
  7206. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7207. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7208. }
  7209. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7210. close ? "closing" : "opening");
  7211. mmiowb();
  7212. }
  7213. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7214. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7215. {
  7216. /* Do some magic... */
  7217. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7218. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7219. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7220. }
  7221. /**
  7222. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7223. *
  7224. * @bp: driver handle
  7225. * @magic_val: old value of the `magic' bit.
  7226. */
  7227. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7228. {
  7229. /* Restore the `magic' bit value... */
  7230. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7231. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7232. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7233. }
  7234. /**
  7235. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7236. *
  7237. * @bp: driver handle
  7238. * @magic_val: old value of 'magic' bit.
  7239. *
  7240. * Takes care of CLP configurations.
  7241. */
  7242. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7243. {
  7244. u32 shmem;
  7245. u32 validity_offset;
  7246. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7247. /* Set `magic' bit in order to save MF config */
  7248. if (!CHIP_IS_E1(bp))
  7249. bnx2x_clp_reset_prep(bp, magic_val);
  7250. /* Get shmem offset */
  7251. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7252. validity_offset =
  7253. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7254. /* Clear validity map flags */
  7255. if (shmem > 0)
  7256. REG_WR(bp, shmem + validity_offset, 0);
  7257. }
  7258. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7259. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7260. /**
  7261. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7262. *
  7263. * @bp: driver handle
  7264. */
  7265. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7266. {
  7267. /* special handling for emulation and FPGA,
  7268. wait 10 times longer */
  7269. if (CHIP_REV_IS_SLOW(bp))
  7270. msleep(MCP_ONE_TIMEOUT*10);
  7271. else
  7272. msleep(MCP_ONE_TIMEOUT);
  7273. }
  7274. /*
  7275. * initializes bp->common.shmem_base and waits for validity signature to appear
  7276. */
  7277. static int bnx2x_init_shmem(struct bnx2x *bp)
  7278. {
  7279. int cnt = 0;
  7280. u32 val = 0;
  7281. do {
  7282. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7283. if (bp->common.shmem_base) {
  7284. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7285. if (val & SHR_MEM_VALIDITY_MB)
  7286. return 0;
  7287. }
  7288. bnx2x_mcp_wait_one(bp);
  7289. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7290. BNX2X_ERR("BAD MCP validity signature\n");
  7291. return -ENODEV;
  7292. }
  7293. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7294. {
  7295. int rc = bnx2x_init_shmem(bp);
  7296. /* Restore the `magic' bit value */
  7297. if (!CHIP_IS_E1(bp))
  7298. bnx2x_clp_reset_done(bp, magic_val);
  7299. return rc;
  7300. }
  7301. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7302. {
  7303. if (!CHIP_IS_E1(bp)) {
  7304. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7305. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7306. mmiowb();
  7307. }
  7308. }
  7309. /*
  7310. * Reset the whole chip except for:
  7311. * - PCIE core
  7312. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7313. * one reset bit)
  7314. * - IGU
  7315. * - MISC (including AEU)
  7316. * - GRC
  7317. * - RBCN, RBCP
  7318. */
  7319. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7320. {
  7321. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7322. u32 global_bits2, stay_reset2;
  7323. /*
  7324. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7325. * (per chip) blocks.
  7326. */
  7327. global_bits2 =
  7328. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7329. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7330. /* Don't reset the following blocks.
  7331. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  7332. * reset, as in 4 port device they might still be owned
  7333. * by the MCP (there is only one leader per path).
  7334. */
  7335. not_reset_mask1 =
  7336. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7337. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7338. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7339. not_reset_mask2 =
  7340. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7341. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7342. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7343. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7344. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7345. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7346. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7347. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7348. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7349. MISC_REGISTERS_RESET_REG_2_PGLC |
  7350. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7351. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7352. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7353. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7354. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7355. MISC_REGISTERS_RESET_REG_2_UMAC1;
  7356. /*
  7357. * Keep the following blocks in reset:
  7358. * - all xxMACs are handled by the bnx2x_link code.
  7359. */
  7360. stay_reset2 =
  7361. MISC_REGISTERS_RESET_REG_2_XMAC |
  7362. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7363. /* Full reset masks according to the chip */
  7364. reset_mask1 = 0xffffffff;
  7365. if (CHIP_IS_E1(bp))
  7366. reset_mask2 = 0xffff;
  7367. else if (CHIP_IS_E1H(bp))
  7368. reset_mask2 = 0x1ffff;
  7369. else if (CHIP_IS_E2(bp))
  7370. reset_mask2 = 0xfffff;
  7371. else /* CHIP_IS_E3 */
  7372. reset_mask2 = 0x3ffffff;
  7373. /* Don't reset global blocks unless we need to */
  7374. if (!global)
  7375. reset_mask2 &= ~global_bits2;
  7376. /*
  7377. * In case of attention in the QM, we need to reset PXP
  7378. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7379. * because otherwise QM reset would release 'close the gates' shortly
  7380. * before resetting the PXP, then the PSWRQ would send a write
  7381. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7382. * read the payload data from PSWWR, but PSWWR would not
  7383. * respond. The write queue in PGLUE would stuck, dmae commands
  7384. * would not return. Therefore it's important to reset the second
  7385. * reset register (containing the
  7386. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7387. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7388. * bit).
  7389. */
  7390. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7391. reset_mask2 & (~not_reset_mask2));
  7392. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7393. reset_mask1 & (~not_reset_mask1));
  7394. barrier();
  7395. mmiowb();
  7396. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7397. reset_mask2 & (~stay_reset2));
  7398. barrier();
  7399. mmiowb();
  7400. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7401. mmiowb();
  7402. }
  7403. /**
  7404. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7405. * It should get cleared in no more than 1s.
  7406. *
  7407. * @bp: driver handle
  7408. *
  7409. * It should get cleared in no more than 1s. Returns 0 if
  7410. * pending writes bit gets cleared.
  7411. */
  7412. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7413. {
  7414. u32 cnt = 1000;
  7415. u32 pend_bits = 0;
  7416. do {
  7417. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7418. if (pend_bits == 0)
  7419. break;
  7420. usleep_range(1000, 1000);
  7421. } while (cnt-- > 0);
  7422. if (cnt <= 0) {
  7423. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7424. pend_bits);
  7425. return -EBUSY;
  7426. }
  7427. return 0;
  7428. }
  7429. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7430. {
  7431. int cnt = 1000;
  7432. u32 val = 0;
  7433. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7434. u32 tags_63_32 = 0;
  7435. /* Empty the Tetris buffer, wait for 1s */
  7436. do {
  7437. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7438. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7439. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7440. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7441. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7442. if (CHIP_IS_E3(bp))
  7443. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  7444. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7445. ((port_is_idle_0 & 0x1) == 0x1) &&
  7446. ((port_is_idle_1 & 0x1) == 0x1) &&
  7447. (pgl_exp_rom2 == 0xffffffff) &&
  7448. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  7449. break;
  7450. usleep_range(1000, 1000);
  7451. } while (cnt-- > 0);
  7452. if (cnt <= 0) {
  7453. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7454. 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",
  7455. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7456. pgl_exp_rom2);
  7457. return -EAGAIN;
  7458. }
  7459. barrier();
  7460. /* Close gates #2, #3 and #4 */
  7461. bnx2x_set_234_gates(bp, true);
  7462. /* Poll for IGU VQs for 57712 and newer chips */
  7463. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  7464. return -EAGAIN;
  7465. /* TBD: Indicate that "process kill" is in progress to MCP */
  7466. /* Clear "unprepared" bit */
  7467. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  7468. barrier();
  7469. /* Make sure all is written to the chip before the reset */
  7470. mmiowb();
  7471. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  7472. * PSWHST, GRC and PSWRD Tetris buffer.
  7473. */
  7474. usleep_range(1000, 1000);
  7475. /* Prepare to chip reset: */
  7476. /* MCP */
  7477. if (global)
  7478. bnx2x_reset_mcp_prep(bp, &val);
  7479. /* PXP */
  7480. bnx2x_pxp_prep(bp);
  7481. barrier();
  7482. /* reset the chip */
  7483. bnx2x_process_kill_chip_reset(bp, global);
  7484. barrier();
  7485. /* Recover after reset: */
  7486. /* MCP */
  7487. if (global && bnx2x_reset_mcp_comp(bp, val))
  7488. return -EAGAIN;
  7489. /* TBD: Add resetting the NO_MCP mode DB here */
  7490. /* Open the gates #2, #3 and #4 */
  7491. bnx2x_set_234_gates(bp, false);
  7492. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  7493. * reset state, re-enable attentions. */
  7494. return 0;
  7495. }
  7496. static int bnx2x_leader_reset(struct bnx2x *bp)
  7497. {
  7498. int rc = 0;
  7499. bool global = bnx2x_reset_is_global(bp);
  7500. u32 load_code;
  7501. /* if not going to reset MCP - load "fake" driver to reset HW while
  7502. * driver is owner of the HW
  7503. */
  7504. if (!global && !BP_NOMCP(bp)) {
  7505. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  7506. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  7507. if (!load_code) {
  7508. BNX2X_ERR("MCP response failure, aborting\n");
  7509. rc = -EAGAIN;
  7510. goto exit_leader_reset;
  7511. }
  7512. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  7513. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  7514. BNX2X_ERR("MCP unexpected resp, aborting\n");
  7515. rc = -EAGAIN;
  7516. goto exit_leader_reset2;
  7517. }
  7518. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  7519. if (!load_code) {
  7520. BNX2X_ERR("MCP response failure, aborting\n");
  7521. rc = -EAGAIN;
  7522. goto exit_leader_reset2;
  7523. }
  7524. }
  7525. /* Try to recover after the failure */
  7526. if (bnx2x_process_kill(bp, global)) {
  7527. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  7528. BP_PATH(bp));
  7529. rc = -EAGAIN;
  7530. goto exit_leader_reset2;
  7531. }
  7532. /*
  7533. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  7534. * state.
  7535. */
  7536. bnx2x_set_reset_done(bp);
  7537. if (global)
  7538. bnx2x_clear_reset_global(bp);
  7539. exit_leader_reset2:
  7540. /* unload "fake driver" if it was loaded */
  7541. if (!global && !BP_NOMCP(bp)) {
  7542. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  7543. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7544. }
  7545. exit_leader_reset:
  7546. bp->is_leader = 0;
  7547. bnx2x_release_leader_lock(bp);
  7548. smp_mb();
  7549. return rc;
  7550. }
  7551. static void bnx2x_recovery_failed(struct bnx2x *bp)
  7552. {
  7553. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  7554. /* Disconnect this device */
  7555. netif_device_detach(bp->dev);
  7556. /*
  7557. * Block ifup for all function on this engine until "process kill"
  7558. * or power cycle.
  7559. */
  7560. bnx2x_set_reset_in_progress(bp);
  7561. /* Shut down the power */
  7562. bnx2x_set_power_state(bp, PCI_D3hot);
  7563. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  7564. smp_mb();
  7565. }
  7566. /*
  7567. * Assumption: runs under rtnl lock. This together with the fact
  7568. * that it's called only from bnx2x_sp_rtnl() ensure that it
  7569. * will never be called when netif_running(bp->dev) is false.
  7570. */
  7571. static void bnx2x_parity_recover(struct bnx2x *bp)
  7572. {
  7573. bool global = false;
  7574. u32 error_recovered, error_unrecovered;
  7575. bool is_parity;
  7576. DP(NETIF_MSG_HW, "Handling parity\n");
  7577. while (1) {
  7578. switch (bp->recovery_state) {
  7579. case BNX2X_RECOVERY_INIT:
  7580. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  7581. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  7582. WARN_ON(!is_parity);
  7583. /* Try to get a LEADER_LOCK HW lock */
  7584. if (bnx2x_trylock_leader_lock(bp)) {
  7585. bnx2x_set_reset_in_progress(bp);
  7586. /*
  7587. * Check if there is a global attention and if
  7588. * there was a global attention, set the global
  7589. * reset bit.
  7590. */
  7591. if (global)
  7592. bnx2x_set_reset_global(bp);
  7593. bp->is_leader = 1;
  7594. }
  7595. /* Stop the driver */
  7596. /* If interface has been removed - break */
  7597. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  7598. return;
  7599. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  7600. /* Ensure "is_leader", MCP command sequence and
  7601. * "recovery_state" update values are seen on other
  7602. * CPUs.
  7603. */
  7604. smp_mb();
  7605. break;
  7606. case BNX2X_RECOVERY_WAIT:
  7607. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  7608. if (bp->is_leader) {
  7609. int other_engine = BP_PATH(bp) ? 0 : 1;
  7610. bool other_load_status =
  7611. bnx2x_get_load_status(bp, other_engine);
  7612. bool load_status =
  7613. bnx2x_get_load_status(bp, BP_PATH(bp));
  7614. global = bnx2x_reset_is_global(bp);
  7615. /*
  7616. * In case of a parity in a global block, let
  7617. * the first leader that performs a
  7618. * leader_reset() reset the global blocks in
  7619. * order to clear global attentions. Otherwise
  7620. * the the gates will remain closed for that
  7621. * engine.
  7622. */
  7623. if (load_status ||
  7624. (global && other_load_status)) {
  7625. /* Wait until all other functions get
  7626. * down.
  7627. */
  7628. schedule_delayed_work(&bp->sp_rtnl_task,
  7629. HZ/10);
  7630. return;
  7631. } else {
  7632. /* If all other functions got down -
  7633. * try to bring the chip back to
  7634. * normal. In any case it's an exit
  7635. * point for a leader.
  7636. */
  7637. if (bnx2x_leader_reset(bp)) {
  7638. bnx2x_recovery_failed(bp);
  7639. return;
  7640. }
  7641. /* If we are here, means that the
  7642. * leader has succeeded and doesn't
  7643. * want to be a leader any more. Try
  7644. * to continue as a none-leader.
  7645. */
  7646. break;
  7647. }
  7648. } else { /* non-leader */
  7649. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  7650. /* Try to get a LEADER_LOCK HW lock as
  7651. * long as a former leader may have
  7652. * been unloaded by the user or
  7653. * released a leadership by another
  7654. * reason.
  7655. */
  7656. if (bnx2x_trylock_leader_lock(bp)) {
  7657. /* I'm a leader now! Restart a
  7658. * switch case.
  7659. */
  7660. bp->is_leader = 1;
  7661. break;
  7662. }
  7663. schedule_delayed_work(&bp->sp_rtnl_task,
  7664. HZ/10);
  7665. return;
  7666. } else {
  7667. /*
  7668. * If there was a global attention, wait
  7669. * for it to be cleared.
  7670. */
  7671. if (bnx2x_reset_is_global(bp)) {
  7672. schedule_delayed_work(
  7673. &bp->sp_rtnl_task,
  7674. HZ/10);
  7675. return;
  7676. }
  7677. error_recovered =
  7678. bp->eth_stats.recoverable_error;
  7679. error_unrecovered =
  7680. bp->eth_stats.unrecoverable_error;
  7681. bp->recovery_state =
  7682. BNX2X_RECOVERY_NIC_LOADING;
  7683. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  7684. error_unrecovered++;
  7685. netdev_err(bp->dev,
  7686. "Recovery failed. Power cycle needed\n");
  7687. /* Disconnect this device */
  7688. netif_device_detach(bp->dev);
  7689. /* Shut down the power */
  7690. bnx2x_set_power_state(
  7691. bp, PCI_D3hot);
  7692. smp_mb();
  7693. } else {
  7694. bp->recovery_state =
  7695. BNX2X_RECOVERY_DONE;
  7696. error_recovered++;
  7697. smp_mb();
  7698. }
  7699. bp->eth_stats.recoverable_error =
  7700. error_recovered;
  7701. bp->eth_stats.unrecoverable_error =
  7702. error_unrecovered;
  7703. return;
  7704. }
  7705. }
  7706. default:
  7707. return;
  7708. }
  7709. }
  7710. }
  7711. static int bnx2x_close(struct net_device *dev);
  7712. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  7713. * scheduled on a general queue in order to prevent a dead lock.
  7714. */
  7715. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  7716. {
  7717. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  7718. rtnl_lock();
  7719. if (!netif_running(bp->dev))
  7720. goto sp_rtnl_exit;
  7721. /* if stop on error is defined no recovery flows should be executed */
  7722. #ifdef BNX2X_STOP_ON_ERROR
  7723. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  7724. "you will need to reboot when done\n");
  7725. goto sp_rtnl_not_reset;
  7726. #endif
  7727. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  7728. /*
  7729. * Clear all pending SP commands as we are going to reset the
  7730. * function anyway.
  7731. */
  7732. bp->sp_rtnl_state = 0;
  7733. smp_mb();
  7734. bnx2x_parity_recover(bp);
  7735. goto sp_rtnl_exit;
  7736. }
  7737. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  7738. /*
  7739. * Clear all pending SP commands as we are going to reset the
  7740. * function anyway.
  7741. */
  7742. bp->sp_rtnl_state = 0;
  7743. smp_mb();
  7744. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  7745. bnx2x_nic_load(bp, LOAD_NORMAL);
  7746. goto sp_rtnl_exit;
  7747. }
  7748. #ifdef BNX2X_STOP_ON_ERROR
  7749. sp_rtnl_not_reset:
  7750. #endif
  7751. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  7752. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  7753. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  7754. bnx2x_after_function_update(bp);
  7755. /*
  7756. * in case of fan failure we need to reset id if the "stop on error"
  7757. * debug flag is set, since we trying to prevent permanent overheating
  7758. * damage
  7759. */
  7760. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  7761. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  7762. netif_device_detach(bp->dev);
  7763. bnx2x_close(bp->dev);
  7764. }
  7765. sp_rtnl_exit:
  7766. rtnl_unlock();
  7767. }
  7768. /* end of nic load/unload */
  7769. static void bnx2x_period_task(struct work_struct *work)
  7770. {
  7771. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  7772. if (!netif_running(bp->dev))
  7773. goto period_task_exit;
  7774. if (CHIP_REV_IS_SLOW(bp)) {
  7775. BNX2X_ERR("period task called on emulation, ignoring\n");
  7776. goto period_task_exit;
  7777. }
  7778. bnx2x_acquire_phy_lock(bp);
  7779. /*
  7780. * The barrier is needed to ensure the ordering between the writing to
  7781. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  7782. * the reading here.
  7783. */
  7784. smp_mb();
  7785. if (bp->port.pmf) {
  7786. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  7787. /* Re-queue task in 1 sec */
  7788. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  7789. }
  7790. bnx2x_release_phy_lock(bp);
  7791. period_task_exit:
  7792. return;
  7793. }
  7794. /*
  7795. * Init service functions
  7796. */
  7797. static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  7798. {
  7799. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  7800. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  7801. return base + (BP_ABS_FUNC(bp)) * stride;
  7802. }
  7803. static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
  7804. {
  7805. u32 reg = bnx2x_get_pretend_reg(bp);
  7806. /* Flush all outstanding writes */
  7807. mmiowb();
  7808. /* Pretend to be function 0 */
  7809. REG_WR(bp, reg, 0);
  7810. REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
  7811. /* From now we are in the "like-E1" mode */
  7812. bnx2x_int_disable(bp);
  7813. /* Flush all outstanding writes */
  7814. mmiowb();
  7815. /* Restore the original function */
  7816. REG_WR(bp, reg, BP_ABS_FUNC(bp));
  7817. REG_RD(bp, reg);
  7818. }
  7819. static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
  7820. {
  7821. if (CHIP_IS_E1(bp))
  7822. bnx2x_int_disable(bp);
  7823. else
  7824. bnx2x_undi_int_disable_e1h(bp);
  7825. }
  7826. static void __devinit bnx2x_prev_unload_close_mac(struct bnx2x *bp)
  7827. {
  7828. u32 val, base_addr, offset, mask, reset_reg;
  7829. bool mac_stopped = false;
  7830. u8 port = BP_PORT(bp);
  7831. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  7832. if (!CHIP_IS_E3(bp)) {
  7833. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  7834. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  7835. if ((mask & reset_reg) && val) {
  7836. u32 wb_data[2];
  7837. BNX2X_DEV_INFO("Disable bmac Rx\n");
  7838. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  7839. : NIG_REG_INGRESS_BMAC0_MEM;
  7840. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  7841. : BIGMAC_REGISTER_BMAC_CONTROL;
  7842. /*
  7843. * use rd/wr since we cannot use dmae. This is safe
  7844. * since MCP won't access the bus due to the request
  7845. * to unload, and no function on the path can be
  7846. * loaded at this time.
  7847. */
  7848. wb_data[0] = REG_RD(bp, base_addr + offset);
  7849. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  7850. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  7851. REG_WR(bp, base_addr + offset, wb_data[0]);
  7852. REG_WR(bp, base_addr + offset + 0x4, wb_data[1]);
  7853. }
  7854. BNX2X_DEV_INFO("Disable emac Rx\n");
  7855. REG_WR(bp, NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4, 0);
  7856. mac_stopped = true;
  7857. } else {
  7858. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  7859. BNX2X_DEV_INFO("Disable xmac Rx\n");
  7860. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  7861. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  7862. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  7863. val & ~(1 << 1));
  7864. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  7865. val | (1 << 1));
  7866. REG_WR(bp, base_addr + XMAC_REG_CTRL, 0);
  7867. mac_stopped = true;
  7868. }
  7869. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  7870. if (mask & reset_reg) {
  7871. BNX2X_DEV_INFO("Disable umac Rx\n");
  7872. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  7873. REG_WR(bp, base_addr + UMAC_REG_COMMAND_CONFIG, 0);
  7874. mac_stopped = true;
  7875. }
  7876. }
  7877. if (mac_stopped)
  7878. msleep(20);
  7879. }
  7880. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  7881. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  7882. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  7883. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  7884. static void __devinit bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port,
  7885. u8 inc)
  7886. {
  7887. u16 rcq, bd;
  7888. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  7889. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  7890. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  7891. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  7892. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  7893. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  7894. port, bd, rcq);
  7895. }
  7896. static int __devinit bnx2x_prev_mcp_done(struct bnx2x *bp)
  7897. {
  7898. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  7899. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  7900. if (!rc) {
  7901. BNX2X_ERR("MCP response failure, aborting\n");
  7902. return -EBUSY;
  7903. }
  7904. return 0;
  7905. }
  7906. static bool __devinit bnx2x_prev_is_path_marked(struct bnx2x *bp)
  7907. {
  7908. struct bnx2x_prev_path_list *tmp_list;
  7909. int rc = false;
  7910. if (down_trylock(&bnx2x_prev_sem))
  7911. return false;
  7912. list_for_each_entry(tmp_list, &bnx2x_prev_list, list) {
  7913. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  7914. bp->pdev->bus->number == tmp_list->bus &&
  7915. BP_PATH(bp) == tmp_list->path) {
  7916. rc = true;
  7917. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  7918. BP_PATH(bp));
  7919. break;
  7920. }
  7921. }
  7922. up(&bnx2x_prev_sem);
  7923. return rc;
  7924. }
  7925. static int __devinit bnx2x_prev_mark_path(struct bnx2x *bp)
  7926. {
  7927. struct bnx2x_prev_path_list *tmp_list;
  7928. int rc;
  7929. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  7930. if (!tmp_list) {
  7931. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  7932. return -ENOMEM;
  7933. }
  7934. tmp_list->bus = bp->pdev->bus->number;
  7935. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  7936. tmp_list->path = BP_PATH(bp);
  7937. rc = down_interruptible(&bnx2x_prev_sem);
  7938. if (rc) {
  7939. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  7940. kfree(tmp_list);
  7941. } else {
  7942. BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
  7943. BP_PATH(bp));
  7944. list_add(&tmp_list->list, &bnx2x_prev_list);
  7945. up(&bnx2x_prev_sem);
  7946. }
  7947. return rc;
  7948. }
  7949. static int __devinit bnx2x_do_flr(struct bnx2x *bp)
  7950. {
  7951. int i;
  7952. u16 status;
  7953. struct pci_dev *dev = bp->pdev;
  7954. if (CHIP_IS_E1x(bp)) {
  7955. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  7956. return -EINVAL;
  7957. }
  7958. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  7959. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  7960. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  7961. bp->common.bc_ver);
  7962. return -EINVAL;
  7963. }
  7964. /* Wait for Transaction Pending bit clean */
  7965. for (i = 0; i < 4; i++) {
  7966. if (i)
  7967. msleep((1 << (i - 1)) * 100);
  7968. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  7969. if (!(status & PCI_EXP_DEVSTA_TRPND))
  7970. goto clear;
  7971. }
  7972. dev_err(&dev->dev,
  7973. "transaction is not cleared; proceeding with reset anyway\n");
  7974. clear:
  7975. BNX2X_DEV_INFO("Initiating FLR\n");
  7976. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  7977. return 0;
  7978. }
  7979. static int __devinit bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  7980. {
  7981. int rc;
  7982. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  7983. /* Test if previous unload process was already finished for this path */
  7984. if (bnx2x_prev_is_path_marked(bp))
  7985. return bnx2x_prev_mcp_done(bp);
  7986. /* If function has FLR capabilities, and existing FW version matches
  7987. * the one required, then FLR will be sufficient to clean any residue
  7988. * left by previous driver
  7989. */
  7990. rc = bnx2x_test_firmware_version(bp, false);
  7991. if (!rc) {
  7992. /* fw version is good */
  7993. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  7994. rc = bnx2x_do_flr(bp);
  7995. }
  7996. if (!rc) {
  7997. /* FLR was performed */
  7998. BNX2X_DEV_INFO("FLR successful\n");
  7999. return 0;
  8000. }
  8001. BNX2X_DEV_INFO("Could not FLR\n");
  8002. /* Close the MCP request, return failure*/
  8003. rc = bnx2x_prev_mcp_done(bp);
  8004. if (!rc)
  8005. rc = BNX2X_PREV_WAIT_NEEDED;
  8006. return rc;
  8007. }
  8008. static int __devinit bnx2x_prev_unload_common(struct bnx2x *bp)
  8009. {
  8010. u32 reset_reg, tmp_reg = 0, rc;
  8011. /* It is possible a previous function received 'common' answer,
  8012. * but hasn't loaded yet, therefore creating a scenario of
  8013. * multiple functions receiving 'common' on the same path.
  8014. */
  8015. BNX2X_DEV_INFO("Common unload Flow\n");
  8016. if (bnx2x_prev_is_path_marked(bp))
  8017. return bnx2x_prev_mcp_done(bp);
  8018. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8019. /* Reset should be performed after BRB is emptied */
  8020. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8021. u32 timer_count = 1000;
  8022. bool prev_undi = false;
  8023. /* Close the MAC Rx to prevent BRB from filling up */
  8024. bnx2x_prev_unload_close_mac(bp);
  8025. /* Check if the UNDI driver was previously loaded
  8026. * UNDI driver initializes CID offset for normal bell to 0x7
  8027. */
  8028. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8029. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
  8030. tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  8031. if (tmp_reg == 0x7) {
  8032. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8033. prev_undi = true;
  8034. /* clear the UNDI indication */
  8035. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8036. }
  8037. }
  8038. /* wait until BRB is empty */
  8039. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8040. while (timer_count) {
  8041. u32 prev_brb = tmp_reg;
  8042. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8043. if (!tmp_reg)
  8044. break;
  8045. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8046. /* reset timer as long as BRB actually gets emptied */
  8047. if (prev_brb > tmp_reg)
  8048. timer_count = 1000;
  8049. else
  8050. timer_count--;
  8051. /* If UNDI resides in memory, manually increment it */
  8052. if (prev_undi)
  8053. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  8054. udelay(10);
  8055. }
  8056. if (!timer_count)
  8057. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8058. }
  8059. /* No packets are in the pipeline, path is ready for reset */
  8060. bnx2x_reset_common(bp);
  8061. rc = bnx2x_prev_mark_path(bp);
  8062. if (rc) {
  8063. bnx2x_prev_mcp_done(bp);
  8064. return rc;
  8065. }
  8066. return bnx2x_prev_mcp_done(bp);
  8067. }
  8068. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  8069. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  8070. * the addresses of the transaction, resulting in was-error bit set in the pci
  8071. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  8072. * to clear the interrupt which detected this from the pglueb and the was done
  8073. * bit
  8074. */
  8075. static void __devinit bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  8076. {
  8077. if (!CHIP_IS_E1x(bp)) {
  8078. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  8079. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  8080. BNX2X_ERR("was error bit was found to be set in pglueb upon startup. Clearing");
  8081. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  8082. 1 << BP_FUNC(bp));
  8083. }
  8084. }
  8085. }
  8086. static int __devinit bnx2x_prev_unload(struct bnx2x *bp)
  8087. {
  8088. int time_counter = 10;
  8089. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8090. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8091. /* clear hw from errors which may have resulted from an interrupted
  8092. * dmae transaction.
  8093. */
  8094. bnx2x_prev_interrupted_dmae(bp);
  8095. /* Release previously held locks */
  8096. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8097. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8098. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8099. hw_lock_val = (REG_RD(bp, hw_lock_reg));
  8100. if (hw_lock_val) {
  8101. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8102. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8103. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8104. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8105. }
  8106. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8107. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8108. } else
  8109. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8110. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8111. BNX2X_DEV_INFO("Release previously held alr\n");
  8112. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  8113. }
  8114. do {
  8115. /* Lock MCP using an unload request */
  8116. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8117. if (!fw) {
  8118. BNX2X_ERR("MCP response failure, aborting\n");
  8119. rc = -EBUSY;
  8120. break;
  8121. }
  8122. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
  8123. rc = bnx2x_prev_unload_common(bp);
  8124. break;
  8125. }
  8126. /* non-common reply from MCP night require looping */
  8127. rc = bnx2x_prev_unload_uncommon(bp);
  8128. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8129. break;
  8130. msleep(20);
  8131. } while (--time_counter);
  8132. if (!time_counter || rc) {
  8133. BNX2X_ERR("Failed unloading previous driver, aborting\n");
  8134. rc = -EBUSY;
  8135. }
  8136. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8137. return rc;
  8138. }
  8139. static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8140. {
  8141. u32 val, val2, val3, val4, id, boot_mode;
  8142. u16 pmc;
  8143. /* Get the chip revision id and number. */
  8144. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8145. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8146. id = ((val & 0xffff) << 16);
  8147. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8148. id |= ((val & 0xf) << 12);
  8149. val = REG_RD(bp, MISC_REG_CHIP_METAL);
  8150. id |= ((val & 0xff) << 4);
  8151. val = REG_RD(bp, MISC_REG_BOND_ID);
  8152. id |= (val & 0xf);
  8153. bp->common.chip_id = id;
  8154. /* force 57811 according to MISC register */
  8155. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8156. if (CHIP_IS_57810(bp))
  8157. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8158. (bp->common.chip_id & 0x0000FFFF);
  8159. else if (CHIP_IS_57810_MF(bp))
  8160. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8161. (bp->common.chip_id & 0x0000FFFF);
  8162. bp->common.chip_id |= 0x1;
  8163. }
  8164. /* Set doorbell size */
  8165. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8166. if (!CHIP_IS_E1x(bp)) {
  8167. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8168. if ((val & 1) == 0)
  8169. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8170. else
  8171. val = (val >> 1) & 1;
  8172. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8173. "2_PORT_MODE");
  8174. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8175. CHIP_2_PORT_MODE;
  8176. if (CHIP_MODE_IS_4_PORT(bp))
  8177. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8178. else
  8179. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8180. } else {
  8181. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8182. bp->pfid = bp->pf_num; /* 0..7 */
  8183. }
  8184. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8185. bp->link_params.chip_id = bp->common.chip_id;
  8186. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8187. val = (REG_RD(bp, 0x2874) & 0x55);
  8188. if ((bp->common.chip_id & 0x1) ||
  8189. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8190. bp->flags |= ONE_PORT_FLAG;
  8191. BNX2X_DEV_INFO("single port device\n");
  8192. }
  8193. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  8194. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8195. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8196. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8197. bp->common.flash_size, bp->common.flash_size);
  8198. bnx2x_init_shmem(bp);
  8199. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8200. MISC_REG_GENERIC_CR_1 :
  8201. MISC_REG_GENERIC_CR_0));
  8202. bp->link_params.shmem_base = bp->common.shmem_base;
  8203. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8204. if (SHMEM2_RD(bp, size) >
  8205. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  8206. bp->link_params.lfa_base =
  8207. REG_RD(bp, bp->common.shmem2_base +
  8208. (u32)offsetof(struct shmem2_region,
  8209. lfa_host_addr[BP_PORT(bp)]));
  8210. else
  8211. bp->link_params.lfa_base = 0;
  8212. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8213. bp->common.shmem_base, bp->common.shmem2_base);
  8214. if (!bp->common.shmem_base) {
  8215. BNX2X_DEV_INFO("MCP not active\n");
  8216. bp->flags |= NO_MCP_FLAG;
  8217. return;
  8218. }
  8219. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8220. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8221. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8222. SHARED_HW_CFG_LED_MODE_MASK) >>
  8223. SHARED_HW_CFG_LED_MODE_SHIFT);
  8224. bp->link_params.feature_config_flags = 0;
  8225. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8226. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8227. bp->link_params.feature_config_flags |=
  8228. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8229. else
  8230. bp->link_params.feature_config_flags &=
  8231. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8232. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8233. bp->common.bc_ver = val;
  8234. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8235. if (val < BNX2X_BC_VER) {
  8236. /* for now only warn
  8237. * later we might need to enforce this */
  8238. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8239. BNX2X_BC_VER, val);
  8240. }
  8241. bp->link_params.feature_config_flags |=
  8242. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8243. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8244. bp->link_params.feature_config_flags |=
  8245. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8246. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8247. bp->link_params.feature_config_flags |=
  8248. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8249. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8250. bp->link_params.feature_config_flags |=
  8251. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8252. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8253. bp->link_params.feature_config_flags |=
  8254. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  8255. FEATURE_CONFIG_MT_SUPPORT : 0;
  8256. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8257. BC_SUPPORTS_PFC_STATS : 0;
  8258. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  8259. BC_SUPPORTS_FCOE_FEATURES : 0;
  8260. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  8261. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  8262. boot_mode = SHMEM_RD(bp,
  8263. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8264. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8265. switch (boot_mode) {
  8266. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8267. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8268. break;
  8269. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8270. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8271. break;
  8272. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  8273. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  8274. break;
  8275. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  8276. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  8277. break;
  8278. }
  8279. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  8280. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  8281. BNX2X_DEV_INFO("%sWoL capable\n",
  8282. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  8283. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  8284. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  8285. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  8286. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  8287. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  8288. val, val2, val3, val4);
  8289. }
  8290. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  8291. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  8292. static void __devinit bnx2x_get_igu_cam_info(struct bnx2x *bp)
  8293. {
  8294. int pfid = BP_FUNC(bp);
  8295. int igu_sb_id;
  8296. u32 val;
  8297. u8 fid, igu_sb_cnt = 0;
  8298. bp->igu_base_sb = 0xff;
  8299. if (CHIP_INT_MODE_IS_BC(bp)) {
  8300. int vn = BP_VN(bp);
  8301. igu_sb_cnt = bp->igu_sb_cnt;
  8302. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  8303. FP_SB_MAX_E1x;
  8304. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  8305. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  8306. return;
  8307. }
  8308. /* IGU in normal mode - read CAM */
  8309. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  8310. igu_sb_id++) {
  8311. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  8312. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  8313. continue;
  8314. fid = IGU_FID(val);
  8315. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  8316. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  8317. continue;
  8318. if (IGU_VEC(val) == 0)
  8319. /* default status block */
  8320. bp->igu_dsb_id = igu_sb_id;
  8321. else {
  8322. if (bp->igu_base_sb == 0xff)
  8323. bp->igu_base_sb = igu_sb_id;
  8324. igu_sb_cnt++;
  8325. }
  8326. }
  8327. }
  8328. #ifdef CONFIG_PCI_MSI
  8329. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  8330. * optional that number of CAM entries will not be equal to the value
  8331. * advertised in PCI.
  8332. * Driver should use the minimal value of both as the actual status
  8333. * block count
  8334. */
  8335. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  8336. #endif
  8337. if (igu_sb_cnt == 0)
  8338. BNX2X_ERR("CAM configuration error\n");
  8339. }
  8340. static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
  8341. u32 switch_cfg)
  8342. {
  8343. int cfg_size = 0, idx, port = BP_PORT(bp);
  8344. /* Aggregation of supported attributes of all external phys */
  8345. bp->port.supported[0] = 0;
  8346. bp->port.supported[1] = 0;
  8347. switch (bp->link_params.num_phys) {
  8348. case 1:
  8349. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  8350. cfg_size = 1;
  8351. break;
  8352. case 2:
  8353. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  8354. cfg_size = 1;
  8355. break;
  8356. case 3:
  8357. if (bp->link_params.multi_phy_config &
  8358. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  8359. bp->port.supported[1] =
  8360. bp->link_params.phy[EXT_PHY1].supported;
  8361. bp->port.supported[0] =
  8362. bp->link_params.phy[EXT_PHY2].supported;
  8363. } else {
  8364. bp->port.supported[0] =
  8365. bp->link_params.phy[EXT_PHY1].supported;
  8366. bp->port.supported[1] =
  8367. bp->link_params.phy[EXT_PHY2].supported;
  8368. }
  8369. cfg_size = 2;
  8370. break;
  8371. }
  8372. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  8373. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  8374. SHMEM_RD(bp,
  8375. dev_info.port_hw_config[port].external_phy_config),
  8376. SHMEM_RD(bp,
  8377. dev_info.port_hw_config[port].external_phy_config2));
  8378. return;
  8379. }
  8380. if (CHIP_IS_E3(bp))
  8381. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  8382. else {
  8383. switch (switch_cfg) {
  8384. case SWITCH_CFG_1G:
  8385. bp->port.phy_addr = REG_RD(
  8386. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  8387. break;
  8388. case SWITCH_CFG_10G:
  8389. bp->port.phy_addr = REG_RD(
  8390. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  8391. break;
  8392. default:
  8393. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  8394. bp->port.link_config[0]);
  8395. return;
  8396. }
  8397. }
  8398. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  8399. /* mask what we support according to speed_cap_mask per configuration */
  8400. for (idx = 0; idx < cfg_size; idx++) {
  8401. if (!(bp->link_params.speed_cap_mask[idx] &
  8402. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  8403. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  8404. if (!(bp->link_params.speed_cap_mask[idx] &
  8405. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  8406. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  8407. if (!(bp->link_params.speed_cap_mask[idx] &
  8408. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  8409. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  8410. if (!(bp->link_params.speed_cap_mask[idx] &
  8411. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  8412. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  8413. if (!(bp->link_params.speed_cap_mask[idx] &
  8414. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  8415. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  8416. SUPPORTED_1000baseT_Full);
  8417. if (!(bp->link_params.speed_cap_mask[idx] &
  8418. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  8419. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  8420. if (!(bp->link_params.speed_cap_mask[idx] &
  8421. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  8422. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  8423. }
  8424. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  8425. bp->port.supported[1]);
  8426. }
  8427. static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
  8428. {
  8429. u32 link_config, idx, cfg_size = 0;
  8430. bp->port.advertising[0] = 0;
  8431. bp->port.advertising[1] = 0;
  8432. switch (bp->link_params.num_phys) {
  8433. case 1:
  8434. case 2:
  8435. cfg_size = 1;
  8436. break;
  8437. case 3:
  8438. cfg_size = 2;
  8439. break;
  8440. }
  8441. for (idx = 0; idx < cfg_size; idx++) {
  8442. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  8443. link_config = bp->port.link_config[idx];
  8444. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  8445. case PORT_FEATURE_LINK_SPEED_AUTO:
  8446. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  8447. bp->link_params.req_line_speed[idx] =
  8448. SPEED_AUTO_NEG;
  8449. bp->port.advertising[idx] |=
  8450. bp->port.supported[idx];
  8451. if (bp->link_params.phy[EXT_PHY1].type ==
  8452. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  8453. bp->port.advertising[idx] |=
  8454. (SUPPORTED_100baseT_Half |
  8455. SUPPORTED_100baseT_Full);
  8456. } else {
  8457. /* force 10G, no AN */
  8458. bp->link_params.req_line_speed[idx] =
  8459. SPEED_10000;
  8460. bp->port.advertising[idx] |=
  8461. (ADVERTISED_10000baseT_Full |
  8462. ADVERTISED_FIBRE);
  8463. continue;
  8464. }
  8465. break;
  8466. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  8467. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  8468. bp->link_params.req_line_speed[idx] =
  8469. SPEED_10;
  8470. bp->port.advertising[idx] |=
  8471. (ADVERTISED_10baseT_Full |
  8472. ADVERTISED_TP);
  8473. } else {
  8474. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8475. link_config,
  8476. bp->link_params.speed_cap_mask[idx]);
  8477. return;
  8478. }
  8479. break;
  8480. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  8481. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  8482. bp->link_params.req_line_speed[idx] =
  8483. SPEED_10;
  8484. bp->link_params.req_duplex[idx] =
  8485. DUPLEX_HALF;
  8486. bp->port.advertising[idx] |=
  8487. (ADVERTISED_10baseT_Half |
  8488. ADVERTISED_TP);
  8489. } else {
  8490. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8491. link_config,
  8492. bp->link_params.speed_cap_mask[idx]);
  8493. return;
  8494. }
  8495. break;
  8496. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  8497. if (bp->port.supported[idx] &
  8498. SUPPORTED_100baseT_Full) {
  8499. bp->link_params.req_line_speed[idx] =
  8500. SPEED_100;
  8501. bp->port.advertising[idx] |=
  8502. (ADVERTISED_100baseT_Full |
  8503. ADVERTISED_TP);
  8504. } else {
  8505. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8506. link_config,
  8507. bp->link_params.speed_cap_mask[idx]);
  8508. return;
  8509. }
  8510. break;
  8511. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  8512. if (bp->port.supported[idx] &
  8513. SUPPORTED_100baseT_Half) {
  8514. bp->link_params.req_line_speed[idx] =
  8515. SPEED_100;
  8516. bp->link_params.req_duplex[idx] =
  8517. DUPLEX_HALF;
  8518. bp->port.advertising[idx] |=
  8519. (ADVERTISED_100baseT_Half |
  8520. ADVERTISED_TP);
  8521. } else {
  8522. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8523. link_config,
  8524. bp->link_params.speed_cap_mask[idx]);
  8525. return;
  8526. }
  8527. break;
  8528. case PORT_FEATURE_LINK_SPEED_1G:
  8529. if (bp->port.supported[idx] &
  8530. SUPPORTED_1000baseT_Full) {
  8531. bp->link_params.req_line_speed[idx] =
  8532. SPEED_1000;
  8533. bp->port.advertising[idx] |=
  8534. (ADVERTISED_1000baseT_Full |
  8535. ADVERTISED_TP);
  8536. } else {
  8537. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8538. link_config,
  8539. bp->link_params.speed_cap_mask[idx]);
  8540. return;
  8541. }
  8542. break;
  8543. case PORT_FEATURE_LINK_SPEED_2_5G:
  8544. if (bp->port.supported[idx] &
  8545. SUPPORTED_2500baseX_Full) {
  8546. bp->link_params.req_line_speed[idx] =
  8547. SPEED_2500;
  8548. bp->port.advertising[idx] |=
  8549. (ADVERTISED_2500baseX_Full |
  8550. ADVERTISED_TP);
  8551. } else {
  8552. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8553. link_config,
  8554. bp->link_params.speed_cap_mask[idx]);
  8555. return;
  8556. }
  8557. break;
  8558. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  8559. if (bp->port.supported[idx] &
  8560. SUPPORTED_10000baseT_Full) {
  8561. bp->link_params.req_line_speed[idx] =
  8562. SPEED_10000;
  8563. bp->port.advertising[idx] |=
  8564. (ADVERTISED_10000baseT_Full |
  8565. ADVERTISED_FIBRE);
  8566. } else {
  8567. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8568. link_config,
  8569. bp->link_params.speed_cap_mask[idx]);
  8570. return;
  8571. }
  8572. break;
  8573. case PORT_FEATURE_LINK_SPEED_20G:
  8574. bp->link_params.req_line_speed[idx] = SPEED_20000;
  8575. break;
  8576. default:
  8577. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  8578. link_config);
  8579. bp->link_params.req_line_speed[idx] =
  8580. SPEED_AUTO_NEG;
  8581. bp->port.advertising[idx] =
  8582. bp->port.supported[idx];
  8583. break;
  8584. }
  8585. bp->link_params.req_flow_ctrl[idx] = (link_config &
  8586. PORT_FEATURE_FLOW_CONTROL_MASK);
  8587. if ((bp->link_params.req_flow_ctrl[idx] ==
  8588. BNX2X_FLOW_CTRL_AUTO) &&
  8589. !(bp->port.supported[idx] & SUPPORTED_Autoneg)) {
  8590. bp->link_params.req_flow_ctrl[idx] =
  8591. BNX2X_FLOW_CTRL_NONE;
  8592. }
  8593. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  8594. bp->link_params.req_line_speed[idx],
  8595. bp->link_params.req_duplex[idx],
  8596. bp->link_params.req_flow_ctrl[idx],
  8597. bp->port.advertising[idx]);
  8598. }
  8599. }
  8600. static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  8601. {
  8602. mac_hi = cpu_to_be16(mac_hi);
  8603. mac_lo = cpu_to_be32(mac_lo);
  8604. memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
  8605. memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
  8606. }
  8607. static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
  8608. {
  8609. int port = BP_PORT(bp);
  8610. u32 config;
  8611. u32 ext_phy_type, ext_phy_config, eee_mode;
  8612. bp->link_params.bp = bp;
  8613. bp->link_params.port = port;
  8614. bp->link_params.lane_config =
  8615. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  8616. bp->link_params.speed_cap_mask[0] =
  8617. SHMEM_RD(bp,
  8618. dev_info.port_hw_config[port].speed_capability_mask);
  8619. bp->link_params.speed_cap_mask[1] =
  8620. SHMEM_RD(bp,
  8621. dev_info.port_hw_config[port].speed_capability_mask2);
  8622. bp->port.link_config[0] =
  8623. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  8624. bp->port.link_config[1] =
  8625. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  8626. bp->link_params.multi_phy_config =
  8627. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  8628. /* If the device is capable of WoL, set the default state according
  8629. * to the HW
  8630. */
  8631. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  8632. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  8633. (config & PORT_FEATURE_WOL_ENABLED));
  8634. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  8635. bp->link_params.lane_config,
  8636. bp->link_params.speed_cap_mask[0],
  8637. bp->port.link_config[0]);
  8638. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  8639. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  8640. bnx2x_phy_probe(&bp->link_params);
  8641. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  8642. bnx2x_link_settings_requested(bp);
  8643. /*
  8644. * If connected directly, work with the internal PHY, otherwise, work
  8645. * with the external PHY
  8646. */
  8647. ext_phy_config =
  8648. SHMEM_RD(bp,
  8649. dev_info.port_hw_config[port].external_phy_config);
  8650. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  8651. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  8652. bp->mdio.prtad = bp->port.phy_addr;
  8653. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  8654. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  8655. bp->mdio.prtad =
  8656. XGXS_EXT_PHY_ADDR(ext_phy_config);
  8657. /* Configure link feature according to nvram value */
  8658. eee_mode = (((SHMEM_RD(bp, dev_info.
  8659. port_feature_config[port].eee_power_mode)) &
  8660. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  8661. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  8662. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  8663. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  8664. EEE_MODE_ENABLE_LPI |
  8665. EEE_MODE_OUTPUT_TIME;
  8666. } else {
  8667. bp->link_params.eee_mode = 0;
  8668. }
  8669. }
  8670. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  8671. {
  8672. u32 no_flags = NO_ISCSI_FLAG;
  8673. int port = BP_PORT(bp);
  8674. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8675. drv_lic_key[port].max_iscsi_conn);
  8676. if (!CNIC_SUPPORT(bp)) {
  8677. bp->flags |= no_flags;
  8678. return;
  8679. }
  8680. /* Get the number of maximum allowed iSCSI connections */
  8681. bp->cnic_eth_dev.max_iscsi_conn =
  8682. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  8683. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  8684. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  8685. bp->cnic_eth_dev.max_iscsi_conn);
  8686. /*
  8687. * If maximum allowed number of connections is zero -
  8688. * disable the feature.
  8689. */
  8690. if (!bp->cnic_eth_dev.max_iscsi_conn)
  8691. bp->flags |= no_flags;
  8692. }
  8693. static void __devinit bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  8694. {
  8695. /* Port info */
  8696. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8697. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  8698. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8699. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  8700. /* Node info */
  8701. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8702. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  8703. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8704. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  8705. }
  8706. static void __devinit bnx2x_get_fcoe_info(struct bnx2x *bp)
  8707. {
  8708. int port = BP_PORT(bp);
  8709. int func = BP_ABS_FUNC(bp);
  8710. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8711. drv_lic_key[port].max_fcoe_conn);
  8712. if (!CNIC_SUPPORT(bp)) {
  8713. bp->flags |= NO_FCOE_FLAG;
  8714. return;
  8715. }
  8716. /* Get the number of maximum allowed FCoE connections */
  8717. bp->cnic_eth_dev.max_fcoe_conn =
  8718. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  8719. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  8720. /* Read the WWN: */
  8721. if (!IS_MF(bp)) {
  8722. /* Port info */
  8723. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8724. SHMEM_RD(bp,
  8725. dev_info.port_hw_config[port].
  8726. fcoe_wwn_port_name_upper);
  8727. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8728. SHMEM_RD(bp,
  8729. dev_info.port_hw_config[port].
  8730. fcoe_wwn_port_name_lower);
  8731. /* Node info */
  8732. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8733. SHMEM_RD(bp,
  8734. dev_info.port_hw_config[port].
  8735. fcoe_wwn_node_name_upper);
  8736. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8737. SHMEM_RD(bp,
  8738. dev_info.port_hw_config[port].
  8739. fcoe_wwn_node_name_lower);
  8740. } else if (!IS_MF_SD(bp)) {
  8741. /*
  8742. * Read the WWN info only if the FCoE feature is enabled for
  8743. * this function.
  8744. */
  8745. if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  8746. bnx2x_get_ext_wwn_info(bp, func);
  8747. } else if (IS_MF_FCOE_SD(bp))
  8748. bnx2x_get_ext_wwn_info(bp, func);
  8749. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  8750. /*
  8751. * If maximum allowed number of connections is zero -
  8752. * disable the feature.
  8753. */
  8754. if (!bp->cnic_eth_dev.max_fcoe_conn)
  8755. bp->flags |= NO_FCOE_FLAG;
  8756. }
  8757. static void __devinit bnx2x_get_cnic_info(struct bnx2x *bp)
  8758. {
  8759. /*
  8760. * iSCSI may be dynamically disabled but reading
  8761. * info here we will decrease memory usage by driver
  8762. * if the feature is disabled for good
  8763. */
  8764. bnx2x_get_iscsi_info(bp);
  8765. bnx2x_get_fcoe_info(bp);
  8766. }
  8767. static void __devinit bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  8768. {
  8769. u32 val, val2;
  8770. int func = BP_ABS_FUNC(bp);
  8771. int port = BP_PORT(bp);
  8772. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  8773. u8 *fip_mac = bp->fip_mac;
  8774. if (IS_MF(bp)) {
  8775. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  8776. * FCoE MAC then the appropriate feature should be disabled.
  8777. * In non SD mode features configuration comes from struct
  8778. * func_ext_config.
  8779. */
  8780. if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
  8781. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  8782. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  8783. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8784. iscsi_mac_addr_upper);
  8785. val = MF_CFG_RD(bp, func_ext_config[func].
  8786. iscsi_mac_addr_lower);
  8787. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  8788. BNX2X_DEV_INFO
  8789. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  8790. } else {
  8791. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  8792. }
  8793. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  8794. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8795. fcoe_mac_addr_upper);
  8796. val = MF_CFG_RD(bp, func_ext_config[func].
  8797. fcoe_mac_addr_lower);
  8798. bnx2x_set_mac_buf(fip_mac, val, val2);
  8799. BNX2X_DEV_INFO
  8800. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  8801. } else {
  8802. bp->flags |= NO_FCOE_FLAG;
  8803. }
  8804. bp->mf_ext_config = cfg;
  8805. } else { /* SD MODE */
  8806. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  8807. /* use primary mac as iscsi mac */
  8808. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  8809. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  8810. BNX2X_DEV_INFO
  8811. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  8812. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  8813. /* use primary mac as fip mac */
  8814. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  8815. BNX2X_DEV_INFO("SD FCoE MODE\n");
  8816. BNX2X_DEV_INFO
  8817. ("Read FIP MAC: %pM\n", fip_mac);
  8818. }
  8819. }
  8820. if (IS_MF_STORAGE_SD(bp))
  8821. /* Zero primary MAC configuration */
  8822. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  8823. if (IS_MF_FCOE_AFEX(bp))
  8824. /* use FIP MAC as primary MAC */
  8825. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  8826. } else {
  8827. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8828. iscsi_mac_upper);
  8829. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8830. iscsi_mac_lower);
  8831. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  8832. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8833. fcoe_fip_mac_upper);
  8834. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8835. fcoe_fip_mac_lower);
  8836. bnx2x_set_mac_buf(fip_mac, val, val2);
  8837. }
  8838. /* Disable iSCSI OOO if MAC configuration is invalid. */
  8839. if (!is_valid_ether_addr(iscsi_mac)) {
  8840. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  8841. memset(iscsi_mac, 0, ETH_ALEN);
  8842. }
  8843. /* Disable FCoE if MAC configuration is invalid. */
  8844. if (!is_valid_ether_addr(fip_mac)) {
  8845. bp->flags |= NO_FCOE_FLAG;
  8846. memset(bp->fip_mac, 0, ETH_ALEN);
  8847. }
  8848. }
  8849. static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  8850. {
  8851. u32 val, val2;
  8852. int func = BP_ABS_FUNC(bp);
  8853. int port = BP_PORT(bp);
  8854. /* Zero primary MAC configuration */
  8855. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  8856. if (BP_NOMCP(bp)) {
  8857. BNX2X_ERROR("warning: random MAC workaround active\n");
  8858. eth_hw_addr_random(bp->dev);
  8859. } else if (IS_MF(bp)) {
  8860. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  8861. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  8862. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  8863. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  8864. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  8865. if (CNIC_SUPPORT(bp))
  8866. bnx2x_get_cnic_mac_hwinfo(bp);
  8867. } else {
  8868. /* in SF read MACs from port configuration */
  8869. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  8870. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  8871. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  8872. if (CNIC_SUPPORT(bp))
  8873. bnx2x_get_cnic_mac_hwinfo(bp);
  8874. }
  8875. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  8876. memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
  8877. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  8878. dev_err(&bp->pdev->dev,
  8879. "bad Ethernet MAC address configuration: %pM\n"
  8880. "change it manually before bringing up the appropriate network interface\n",
  8881. bp->dev->dev_addr);
  8882. }
  8883. static bool __devinit bnx2x_get_dropless_info(struct bnx2x *bp)
  8884. {
  8885. int tmp;
  8886. u32 cfg;
  8887. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  8888. /* Take function: tmp = func */
  8889. tmp = BP_ABS_FUNC(bp);
  8890. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  8891. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  8892. } else {
  8893. /* Take port: tmp = port */
  8894. tmp = BP_PORT(bp);
  8895. cfg = SHMEM_RD(bp,
  8896. dev_info.port_hw_config[tmp].generic_features);
  8897. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  8898. }
  8899. return cfg;
  8900. }
  8901. static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
  8902. {
  8903. int /*abs*/func = BP_ABS_FUNC(bp);
  8904. int vn;
  8905. u32 val = 0;
  8906. int rc = 0;
  8907. bnx2x_get_common_hwinfo(bp);
  8908. /*
  8909. * initialize IGU parameters
  8910. */
  8911. if (CHIP_IS_E1x(bp)) {
  8912. bp->common.int_block = INT_BLOCK_HC;
  8913. bp->igu_dsb_id = DEF_SB_IGU_ID;
  8914. bp->igu_base_sb = 0;
  8915. } else {
  8916. bp->common.int_block = INT_BLOCK_IGU;
  8917. /* do not allow device reset during IGU info preocessing */
  8918. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  8919. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  8920. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  8921. int tout = 5000;
  8922. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  8923. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  8924. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  8925. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  8926. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  8927. tout--;
  8928. usleep_range(1000, 1000);
  8929. }
  8930. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  8931. dev_err(&bp->pdev->dev,
  8932. "FORCING Normal Mode failed!!!\n");
  8933. return -EPERM;
  8934. }
  8935. }
  8936. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  8937. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  8938. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  8939. } else
  8940. BNX2X_DEV_INFO("IGU Normal Mode\n");
  8941. bnx2x_get_igu_cam_info(bp);
  8942. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  8943. }
  8944. /*
  8945. * set base FW non-default (fast path) status block id, this value is
  8946. * used to initialize the fw_sb_id saved on the fp/queue structure to
  8947. * determine the id used by the FW.
  8948. */
  8949. if (CHIP_IS_E1x(bp))
  8950. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  8951. else /*
  8952. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  8953. * the same queue are indicated on the same IGU SB). So we prefer
  8954. * FW and IGU SBs to be the same value.
  8955. */
  8956. bp->base_fw_ndsb = bp->igu_base_sb;
  8957. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  8958. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  8959. bp->igu_sb_cnt, bp->base_fw_ndsb);
  8960. /*
  8961. * Initialize MF configuration
  8962. */
  8963. bp->mf_ov = 0;
  8964. bp->mf_mode = 0;
  8965. vn = BP_VN(bp);
  8966. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  8967. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  8968. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  8969. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  8970. if (SHMEM2_HAS(bp, mf_cfg_addr))
  8971. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  8972. else
  8973. bp->common.mf_cfg_base = bp->common.shmem_base +
  8974. offsetof(struct shmem_region, func_mb) +
  8975. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  8976. /*
  8977. * get mf configuration:
  8978. * 1. existence of MF configuration
  8979. * 2. MAC address must be legal (check only upper bytes)
  8980. * for Switch-Independent mode;
  8981. * OVLAN must be legal for Switch-Dependent mode
  8982. * 3. SF_MODE configures specific MF mode
  8983. */
  8984. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  8985. /* get mf configuration */
  8986. val = SHMEM_RD(bp,
  8987. dev_info.shared_feature_config.config);
  8988. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  8989. switch (val) {
  8990. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  8991. val = MF_CFG_RD(bp, func_mf_config[func].
  8992. mac_upper);
  8993. /* check for legal mac (upper bytes)*/
  8994. if (val != 0xffff) {
  8995. bp->mf_mode = MULTI_FUNCTION_SI;
  8996. bp->mf_config[vn] = MF_CFG_RD(bp,
  8997. func_mf_config[func].config);
  8998. } else
  8999. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9000. break;
  9001. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9002. if ((!CHIP_IS_E1x(bp)) &&
  9003. (MF_CFG_RD(bp, func_mf_config[func].
  9004. mac_upper) != 0xffff) &&
  9005. (SHMEM2_HAS(bp,
  9006. afex_driver_support))) {
  9007. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9008. bp->mf_config[vn] = MF_CFG_RD(bp,
  9009. func_mf_config[func].config);
  9010. } else {
  9011. BNX2X_DEV_INFO("can not configure afex mode\n");
  9012. }
  9013. break;
  9014. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9015. /* get OV configuration */
  9016. val = MF_CFG_RD(bp,
  9017. func_mf_config[FUNC_0].e1hov_tag);
  9018. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9019. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9020. bp->mf_mode = MULTI_FUNCTION_SD;
  9021. bp->mf_config[vn] = MF_CFG_RD(bp,
  9022. func_mf_config[func].config);
  9023. } else
  9024. BNX2X_DEV_INFO("illegal OV for SD\n");
  9025. break;
  9026. default:
  9027. /* Unknown configuration: reset mf_config */
  9028. bp->mf_config[vn] = 0;
  9029. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9030. }
  9031. }
  9032. BNX2X_DEV_INFO("%s function mode\n",
  9033. IS_MF(bp) ? "multi" : "single");
  9034. switch (bp->mf_mode) {
  9035. case MULTI_FUNCTION_SD:
  9036. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9037. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9038. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9039. bp->mf_ov = val;
  9040. bp->path_has_ovlan = true;
  9041. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9042. func, bp->mf_ov, bp->mf_ov);
  9043. } else {
  9044. dev_err(&bp->pdev->dev,
  9045. "No valid MF OV for func %d, aborting\n",
  9046. func);
  9047. return -EPERM;
  9048. }
  9049. break;
  9050. case MULTI_FUNCTION_AFEX:
  9051. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9052. break;
  9053. case MULTI_FUNCTION_SI:
  9054. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9055. func);
  9056. break;
  9057. default:
  9058. if (vn) {
  9059. dev_err(&bp->pdev->dev,
  9060. "VN %d is in a single function mode, aborting\n",
  9061. vn);
  9062. return -EPERM;
  9063. }
  9064. break;
  9065. }
  9066. /* check if other port on the path needs ovlan:
  9067. * Since MF configuration is shared between ports
  9068. * Possible mixed modes are only
  9069. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9070. */
  9071. if (CHIP_MODE_IS_4_PORT(bp) &&
  9072. !bp->path_has_ovlan &&
  9073. !IS_MF(bp) &&
  9074. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9075. u8 other_port = !BP_PORT(bp);
  9076. u8 other_func = BP_PATH(bp) + 2*other_port;
  9077. val = MF_CFG_RD(bp,
  9078. func_mf_config[other_func].e1hov_tag);
  9079. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  9080. bp->path_has_ovlan = true;
  9081. }
  9082. }
  9083. /* adjust igu_sb_cnt to MF for E1x */
  9084. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  9085. bp->igu_sb_cnt /= E1HVN_MAX;
  9086. /* port info */
  9087. bnx2x_get_port_hwinfo(bp);
  9088. /* Get MAC addresses */
  9089. bnx2x_get_mac_hwinfo(bp);
  9090. bnx2x_get_cnic_info(bp);
  9091. return rc;
  9092. }
  9093. static void __devinit bnx2x_read_fwinfo(struct bnx2x *bp)
  9094. {
  9095. int cnt, i, block_end, rodi;
  9096. char vpd_start[BNX2X_VPD_LEN+1];
  9097. char str_id_reg[VENDOR_ID_LEN+1];
  9098. char str_id_cap[VENDOR_ID_LEN+1];
  9099. char *vpd_data;
  9100. char *vpd_extended_data = NULL;
  9101. u8 len;
  9102. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  9103. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  9104. if (cnt < BNX2X_VPD_LEN)
  9105. goto out_not_found;
  9106. /* VPD RO tag should be first tag after identifier string, hence
  9107. * we should be able to find it in first BNX2X_VPD_LEN chars
  9108. */
  9109. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  9110. PCI_VPD_LRDT_RO_DATA);
  9111. if (i < 0)
  9112. goto out_not_found;
  9113. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  9114. pci_vpd_lrdt_size(&vpd_start[i]);
  9115. i += PCI_VPD_LRDT_TAG_SIZE;
  9116. if (block_end > BNX2X_VPD_LEN) {
  9117. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  9118. if (vpd_extended_data == NULL)
  9119. goto out_not_found;
  9120. /* read rest of vpd image into vpd_extended_data */
  9121. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  9122. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  9123. block_end - BNX2X_VPD_LEN,
  9124. vpd_extended_data + BNX2X_VPD_LEN);
  9125. if (cnt < (block_end - BNX2X_VPD_LEN))
  9126. goto out_not_found;
  9127. vpd_data = vpd_extended_data;
  9128. } else
  9129. vpd_data = vpd_start;
  9130. /* now vpd_data holds full vpd content in both cases */
  9131. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9132. PCI_VPD_RO_KEYWORD_MFR_ID);
  9133. if (rodi < 0)
  9134. goto out_not_found;
  9135. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9136. if (len != VENDOR_ID_LEN)
  9137. goto out_not_found;
  9138. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9139. /* vendor specific info */
  9140. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  9141. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  9142. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  9143. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  9144. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9145. PCI_VPD_RO_KEYWORD_VENDOR0);
  9146. if (rodi >= 0) {
  9147. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9148. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9149. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  9150. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  9151. bp->fw_ver[len] = ' ';
  9152. }
  9153. }
  9154. kfree(vpd_extended_data);
  9155. return;
  9156. }
  9157. out_not_found:
  9158. kfree(vpd_extended_data);
  9159. return;
  9160. }
  9161. static void __devinit bnx2x_set_modes_bitmap(struct bnx2x *bp)
  9162. {
  9163. u32 flags = 0;
  9164. if (CHIP_REV_IS_FPGA(bp))
  9165. SET_FLAGS(flags, MODE_FPGA);
  9166. else if (CHIP_REV_IS_EMUL(bp))
  9167. SET_FLAGS(flags, MODE_EMUL);
  9168. else
  9169. SET_FLAGS(flags, MODE_ASIC);
  9170. if (CHIP_MODE_IS_4_PORT(bp))
  9171. SET_FLAGS(flags, MODE_PORT4);
  9172. else
  9173. SET_FLAGS(flags, MODE_PORT2);
  9174. if (CHIP_IS_E2(bp))
  9175. SET_FLAGS(flags, MODE_E2);
  9176. else if (CHIP_IS_E3(bp)) {
  9177. SET_FLAGS(flags, MODE_E3);
  9178. if (CHIP_REV(bp) == CHIP_REV_Ax)
  9179. SET_FLAGS(flags, MODE_E3_A0);
  9180. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  9181. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  9182. }
  9183. if (IS_MF(bp)) {
  9184. SET_FLAGS(flags, MODE_MF);
  9185. switch (bp->mf_mode) {
  9186. case MULTI_FUNCTION_SD:
  9187. SET_FLAGS(flags, MODE_MF_SD);
  9188. break;
  9189. case MULTI_FUNCTION_SI:
  9190. SET_FLAGS(flags, MODE_MF_SI);
  9191. break;
  9192. case MULTI_FUNCTION_AFEX:
  9193. SET_FLAGS(flags, MODE_MF_AFEX);
  9194. break;
  9195. }
  9196. } else
  9197. SET_FLAGS(flags, MODE_SF);
  9198. #if defined(__LITTLE_ENDIAN)
  9199. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  9200. #else /*(__BIG_ENDIAN)*/
  9201. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  9202. #endif
  9203. INIT_MODE_FLAGS(bp) = flags;
  9204. }
  9205. static int __devinit bnx2x_init_bp(struct bnx2x *bp)
  9206. {
  9207. int func;
  9208. int rc;
  9209. mutex_init(&bp->port.phy_mutex);
  9210. mutex_init(&bp->fw_mb_mutex);
  9211. spin_lock_init(&bp->stats_lock);
  9212. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  9213. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  9214. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  9215. rc = bnx2x_get_hwinfo(bp);
  9216. if (rc)
  9217. return rc;
  9218. bnx2x_set_modes_bitmap(bp);
  9219. rc = bnx2x_alloc_mem_bp(bp);
  9220. if (rc)
  9221. return rc;
  9222. bnx2x_read_fwinfo(bp);
  9223. func = BP_FUNC(bp);
  9224. /* need to reset chip if undi was active */
  9225. if (!BP_NOMCP(bp)) {
  9226. /* init fw_seq */
  9227. bp->fw_seq =
  9228. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  9229. DRV_MSG_SEQ_NUMBER_MASK;
  9230. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9231. bnx2x_prev_unload(bp);
  9232. }
  9233. if (CHIP_REV_IS_FPGA(bp))
  9234. dev_err(&bp->pdev->dev, "FPGA detected\n");
  9235. if (BP_NOMCP(bp) && (func == 0))
  9236. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  9237. bp->disable_tpa = disable_tpa;
  9238. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  9239. /* Set TPA flags */
  9240. if (bp->disable_tpa) {
  9241. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9242. bp->dev->features &= ~NETIF_F_LRO;
  9243. } else {
  9244. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9245. bp->dev->features |= NETIF_F_LRO;
  9246. }
  9247. if (CHIP_IS_E1(bp))
  9248. bp->dropless_fc = 0;
  9249. else
  9250. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  9251. bp->mrrs = mrrs;
  9252. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  9253. /* make sure that the numbers are in the right granularity */
  9254. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  9255. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  9256. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  9257. init_timer(&bp->timer);
  9258. bp->timer.expires = jiffies + bp->current_interval;
  9259. bp->timer.data = (unsigned long) bp;
  9260. bp->timer.function = bnx2x_timer;
  9261. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  9262. bnx2x_dcbx_init_params(bp);
  9263. if (CHIP_IS_E1x(bp))
  9264. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  9265. else
  9266. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  9267. /* multiple tx priority */
  9268. if (CHIP_IS_E1x(bp))
  9269. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  9270. if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  9271. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  9272. if (CHIP_IS_E3B0(bp))
  9273. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  9274. /* We need at least one default status block for slow-path events,
  9275. * second status block for the L2 queue, and a third status block for
  9276. * CNIC if supproted.
  9277. */
  9278. if (CNIC_SUPPORT(bp))
  9279. bp->min_msix_vec_cnt = 3;
  9280. else
  9281. bp->min_msix_vec_cnt = 2;
  9282. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  9283. return rc;
  9284. }
  9285. /****************************************************************************
  9286. * General service functions
  9287. ****************************************************************************/
  9288. /*
  9289. * net_device service functions
  9290. */
  9291. /* called with rtnl_lock */
  9292. static int bnx2x_open(struct net_device *dev)
  9293. {
  9294. struct bnx2x *bp = netdev_priv(dev);
  9295. bool global = false;
  9296. int other_engine = BP_PATH(bp) ? 0 : 1;
  9297. bool other_load_status, load_status;
  9298. bp->stats_init = true;
  9299. netif_carrier_off(dev);
  9300. bnx2x_set_power_state(bp, PCI_D0);
  9301. other_load_status = bnx2x_get_load_status(bp, other_engine);
  9302. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  9303. /*
  9304. * If parity had happen during the unload, then attentions
  9305. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  9306. * want the first function loaded on the current engine to
  9307. * complete the recovery.
  9308. */
  9309. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  9310. bnx2x_chk_parity_attn(bp, &global, true))
  9311. do {
  9312. /*
  9313. * If there are attentions and they are in a global
  9314. * blocks, set the GLOBAL_RESET bit regardless whether
  9315. * it will be this function that will complete the
  9316. * recovery or not.
  9317. */
  9318. if (global)
  9319. bnx2x_set_reset_global(bp);
  9320. /*
  9321. * Only the first function on the current engine should
  9322. * try to recover in open. In case of attentions in
  9323. * global blocks only the first in the chip should try
  9324. * to recover.
  9325. */
  9326. if ((!load_status &&
  9327. (!global || !other_load_status)) &&
  9328. bnx2x_trylock_leader_lock(bp) &&
  9329. !bnx2x_leader_reset(bp)) {
  9330. netdev_info(bp->dev, "Recovered in open\n");
  9331. break;
  9332. }
  9333. /* recovery has failed... */
  9334. bnx2x_set_power_state(bp, PCI_D3hot);
  9335. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  9336. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  9337. "If you still see this message after a few retries then power cycle is required.\n");
  9338. return -EAGAIN;
  9339. } while (0);
  9340. bp->recovery_state = BNX2X_RECOVERY_DONE;
  9341. return bnx2x_nic_load(bp, LOAD_OPEN);
  9342. }
  9343. /* called with rtnl_lock */
  9344. static int bnx2x_close(struct net_device *dev)
  9345. {
  9346. struct bnx2x *bp = netdev_priv(dev);
  9347. /* Unload the driver, release IRQs */
  9348. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  9349. /* Power off */
  9350. bnx2x_set_power_state(bp, PCI_D3hot);
  9351. return 0;
  9352. }
  9353. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  9354. struct bnx2x_mcast_ramrod_params *p)
  9355. {
  9356. int mc_count = netdev_mc_count(bp->dev);
  9357. struct bnx2x_mcast_list_elem *mc_mac =
  9358. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  9359. struct netdev_hw_addr *ha;
  9360. if (!mc_mac)
  9361. return -ENOMEM;
  9362. INIT_LIST_HEAD(&p->mcast_list);
  9363. netdev_for_each_mc_addr(ha, bp->dev) {
  9364. mc_mac->mac = bnx2x_mc_addr(ha);
  9365. list_add_tail(&mc_mac->link, &p->mcast_list);
  9366. mc_mac++;
  9367. }
  9368. p->mcast_list_len = mc_count;
  9369. return 0;
  9370. }
  9371. static void bnx2x_free_mcast_macs_list(
  9372. struct bnx2x_mcast_ramrod_params *p)
  9373. {
  9374. struct bnx2x_mcast_list_elem *mc_mac =
  9375. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  9376. link);
  9377. WARN_ON(!mc_mac);
  9378. kfree(mc_mac);
  9379. }
  9380. /**
  9381. * bnx2x_set_uc_list - configure a new unicast MACs list.
  9382. *
  9383. * @bp: driver handle
  9384. *
  9385. * We will use zero (0) as a MAC type for these MACs.
  9386. */
  9387. static int bnx2x_set_uc_list(struct bnx2x *bp)
  9388. {
  9389. int rc;
  9390. struct net_device *dev = bp->dev;
  9391. struct netdev_hw_addr *ha;
  9392. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  9393. unsigned long ramrod_flags = 0;
  9394. /* First schedule a cleanup up of old configuration */
  9395. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  9396. if (rc < 0) {
  9397. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  9398. return rc;
  9399. }
  9400. netdev_for_each_uc_addr(ha, dev) {
  9401. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  9402. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9403. if (rc == -EEXIST) {
  9404. DP(BNX2X_MSG_SP,
  9405. "Failed to schedule ADD operations: %d\n", rc);
  9406. /* do not treat adding same MAC as error */
  9407. rc = 0;
  9408. } else if (rc < 0) {
  9409. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  9410. rc);
  9411. return rc;
  9412. }
  9413. }
  9414. /* Execute the pending commands */
  9415. __set_bit(RAMROD_CONT, &ramrod_flags);
  9416. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  9417. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9418. }
  9419. static int bnx2x_set_mc_list(struct bnx2x *bp)
  9420. {
  9421. struct net_device *dev = bp->dev;
  9422. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  9423. int rc = 0;
  9424. rparam.mcast_obj = &bp->mcast_obj;
  9425. /* first, clear all configured multicast MACs */
  9426. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  9427. if (rc < 0) {
  9428. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  9429. return rc;
  9430. }
  9431. /* then, configure a new MACs list */
  9432. if (netdev_mc_count(dev)) {
  9433. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  9434. if (rc) {
  9435. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  9436. rc);
  9437. return rc;
  9438. }
  9439. /* Now add the new MACs */
  9440. rc = bnx2x_config_mcast(bp, &rparam,
  9441. BNX2X_MCAST_CMD_ADD);
  9442. if (rc < 0)
  9443. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  9444. rc);
  9445. bnx2x_free_mcast_macs_list(&rparam);
  9446. }
  9447. return rc;
  9448. }
  9449. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  9450. void bnx2x_set_rx_mode(struct net_device *dev)
  9451. {
  9452. struct bnx2x *bp = netdev_priv(dev);
  9453. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  9454. if (bp->state != BNX2X_STATE_OPEN) {
  9455. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  9456. return;
  9457. }
  9458. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  9459. if (dev->flags & IFF_PROMISC)
  9460. rx_mode = BNX2X_RX_MODE_PROMISC;
  9461. else if ((dev->flags & IFF_ALLMULTI) ||
  9462. ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
  9463. CHIP_IS_E1(bp)))
  9464. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9465. else {
  9466. /* some multicasts */
  9467. if (bnx2x_set_mc_list(bp) < 0)
  9468. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9469. if (bnx2x_set_uc_list(bp) < 0)
  9470. rx_mode = BNX2X_RX_MODE_PROMISC;
  9471. }
  9472. bp->rx_mode = rx_mode;
  9473. /* handle ISCSI SD mode */
  9474. if (IS_MF_ISCSI_SD(bp))
  9475. bp->rx_mode = BNX2X_RX_MODE_NONE;
  9476. /* Schedule the rx_mode command */
  9477. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  9478. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  9479. return;
  9480. }
  9481. bnx2x_set_storm_rx_mode(bp);
  9482. }
  9483. /* called with rtnl_lock */
  9484. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  9485. int devad, u16 addr)
  9486. {
  9487. struct bnx2x *bp = netdev_priv(netdev);
  9488. u16 value;
  9489. int rc;
  9490. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  9491. prtad, devad, addr);
  9492. /* The HW expects different devad if CL22 is used */
  9493. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9494. bnx2x_acquire_phy_lock(bp);
  9495. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  9496. bnx2x_release_phy_lock(bp);
  9497. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  9498. if (!rc)
  9499. rc = value;
  9500. return rc;
  9501. }
  9502. /* called with rtnl_lock */
  9503. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  9504. u16 addr, u16 value)
  9505. {
  9506. struct bnx2x *bp = netdev_priv(netdev);
  9507. int rc;
  9508. DP(NETIF_MSG_LINK,
  9509. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  9510. prtad, devad, addr, value);
  9511. /* The HW expects different devad if CL22 is used */
  9512. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9513. bnx2x_acquire_phy_lock(bp);
  9514. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  9515. bnx2x_release_phy_lock(bp);
  9516. return rc;
  9517. }
  9518. /* called with rtnl_lock */
  9519. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  9520. {
  9521. struct bnx2x *bp = netdev_priv(dev);
  9522. struct mii_ioctl_data *mdio = if_mii(ifr);
  9523. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  9524. mdio->phy_id, mdio->reg_num, mdio->val_in);
  9525. if (!netif_running(dev))
  9526. return -EAGAIN;
  9527. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  9528. }
  9529. #ifdef CONFIG_NET_POLL_CONTROLLER
  9530. static void poll_bnx2x(struct net_device *dev)
  9531. {
  9532. struct bnx2x *bp = netdev_priv(dev);
  9533. int i;
  9534. for_each_eth_queue(bp, i) {
  9535. struct bnx2x_fastpath *fp = &bp->fp[i];
  9536. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  9537. }
  9538. }
  9539. #endif
  9540. static int bnx2x_validate_addr(struct net_device *dev)
  9541. {
  9542. struct bnx2x *bp = netdev_priv(dev);
  9543. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  9544. BNX2X_ERR("Non-valid Ethernet address\n");
  9545. return -EADDRNOTAVAIL;
  9546. }
  9547. return 0;
  9548. }
  9549. static const struct net_device_ops bnx2x_netdev_ops = {
  9550. .ndo_open = bnx2x_open,
  9551. .ndo_stop = bnx2x_close,
  9552. .ndo_start_xmit = bnx2x_start_xmit,
  9553. .ndo_select_queue = bnx2x_select_queue,
  9554. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  9555. .ndo_set_mac_address = bnx2x_change_mac_addr,
  9556. .ndo_validate_addr = bnx2x_validate_addr,
  9557. .ndo_do_ioctl = bnx2x_ioctl,
  9558. .ndo_change_mtu = bnx2x_change_mtu,
  9559. .ndo_fix_features = bnx2x_fix_features,
  9560. .ndo_set_features = bnx2x_set_features,
  9561. .ndo_tx_timeout = bnx2x_tx_timeout,
  9562. #ifdef CONFIG_NET_POLL_CONTROLLER
  9563. .ndo_poll_controller = poll_bnx2x,
  9564. #endif
  9565. .ndo_setup_tc = bnx2x_setup_tc,
  9566. #ifdef NETDEV_FCOE_WWNN
  9567. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  9568. #endif
  9569. };
  9570. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  9571. {
  9572. struct device *dev = &bp->pdev->dev;
  9573. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  9574. bp->flags |= USING_DAC_FLAG;
  9575. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  9576. dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
  9577. return -EIO;
  9578. }
  9579. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  9580. dev_err(dev, "System does not support DMA, aborting\n");
  9581. return -EIO;
  9582. }
  9583. return 0;
  9584. }
  9585. static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
  9586. struct net_device *dev,
  9587. unsigned long board_type)
  9588. {
  9589. struct bnx2x *bp;
  9590. int rc;
  9591. u32 pci_cfg_dword;
  9592. bool chip_is_e1x = (board_type == BCM57710 ||
  9593. board_type == BCM57711 ||
  9594. board_type == BCM57711E);
  9595. SET_NETDEV_DEV(dev, &pdev->dev);
  9596. bp = netdev_priv(dev);
  9597. bp->dev = dev;
  9598. bp->pdev = pdev;
  9599. bp->flags = 0;
  9600. rc = pci_enable_device(pdev);
  9601. if (rc) {
  9602. dev_err(&bp->pdev->dev,
  9603. "Cannot enable PCI device, aborting\n");
  9604. goto err_out;
  9605. }
  9606. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  9607. dev_err(&bp->pdev->dev,
  9608. "Cannot find PCI device base address, aborting\n");
  9609. rc = -ENODEV;
  9610. goto err_out_disable;
  9611. }
  9612. if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  9613. dev_err(&bp->pdev->dev, "Cannot find second PCI device"
  9614. " base address, aborting\n");
  9615. rc = -ENODEV;
  9616. goto err_out_disable;
  9617. }
  9618. if (atomic_read(&pdev->enable_cnt) == 1) {
  9619. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  9620. if (rc) {
  9621. dev_err(&bp->pdev->dev,
  9622. "Cannot obtain PCI resources, aborting\n");
  9623. goto err_out_disable;
  9624. }
  9625. pci_set_master(pdev);
  9626. pci_save_state(pdev);
  9627. }
  9628. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  9629. if (bp->pm_cap == 0) {
  9630. dev_err(&bp->pdev->dev,
  9631. "Cannot find power management capability, aborting\n");
  9632. rc = -EIO;
  9633. goto err_out_release;
  9634. }
  9635. if (!pci_is_pcie(pdev)) {
  9636. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  9637. rc = -EIO;
  9638. goto err_out_release;
  9639. }
  9640. rc = bnx2x_set_coherency_mask(bp);
  9641. if (rc)
  9642. goto err_out_release;
  9643. dev->mem_start = pci_resource_start(pdev, 0);
  9644. dev->base_addr = dev->mem_start;
  9645. dev->mem_end = pci_resource_end(pdev, 0);
  9646. dev->irq = pdev->irq;
  9647. bp->regview = pci_ioremap_bar(pdev, 0);
  9648. if (!bp->regview) {
  9649. dev_err(&bp->pdev->dev,
  9650. "Cannot map register space, aborting\n");
  9651. rc = -ENOMEM;
  9652. goto err_out_release;
  9653. }
  9654. /* In E1/E1H use pci device function given by kernel.
  9655. * In E2/E3 read physical function from ME register since these chips
  9656. * support Physical Device Assignment where kernel BDF maybe arbitrary
  9657. * (depending on hypervisor).
  9658. */
  9659. if (chip_is_e1x)
  9660. bp->pf_num = PCI_FUNC(pdev->devfn);
  9661. else {/* chip is E2/3*/
  9662. pci_read_config_dword(bp->pdev,
  9663. PCICFG_ME_REGISTER, &pci_cfg_dword);
  9664. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  9665. ME_REG_ABS_PF_NUM_SHIFT);
  9666. }
  9667. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  9668. bnx2x_set_power_state(bp, PCI_D0);
  9669. /* clean indirect addresses */
  9670. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  9671. PCICFG_VENDOR_ID_OFFSET);
  9672. /*
  9673. * Clean the following indirect addresses for all functions since it
  9674. * is not used by the driver.
  9675. */
  9676. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  9677. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  9678. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  9679. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  9680. if (chip_is_e1x) {
  9681. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  9682. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  9683. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  9684. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  9685. }
  9686. /*
  9687. * Enable internal target-read (in case we are probed after PF FLR).
  9688. * Must be done prior to any BAR read access. Only for 57712 and up
  9689. */
  9690. if (!chip_is_e1x)
  9691. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  9692. dev->watchdog_timeo = TX_TIMEOUT;
  9693. dev->netdev_ops = &bnx2x_netdev_ops;
  9694. bnx2x_set_ethtool_ops(dev);
  9695. dev->priv_flags |= IFF_UNICAST_FLT;
  9696. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9697. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  9698. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  9699. NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
  9700. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9701. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  9702. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
  9703. if (bp->flags & USING_DAC_FLAG)
  9704. dev->features |= NETIF_F_HIGHDMA;
  9705. /* Add Loopback capability to the device */
  9706. dev->hw_features |= NETIF_F_LOOPBACK;
  9707. #ifdef BCM_DCBNL
  9708. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  9709. #endif
  9710. /* get_port_hwinfo() will set prtad and mmds properly */
  9711. bp->mdio.prtad = MDIO_PRTAD_NONE;
  9712. bp->mdio.mmds = 0;
  9713. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  9714. bp->mdio.dev = dev;
  9715. bp->mdio.mdio_read = bnx2x_mdio_read;
  9716. bp->mdio.mdio_write = bnx2x_mdio_write;
  9717. return 0;
  9718. err_out_release:
  9719. if (atomic_read(&pdev->enable_cnt) == 1)
  9720. pci_release_regions(pdev);
  9721. err_out_disable:
  9722. pci_disable_device(pdev);
  9723. pci_set_drvdata(pdev, NULL);
  9724. err_out:
  9725. return rc;
  9726. }
  9727. static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp,
  9728. int *width, int *speed)
  9729. {
  9730. u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
  9731. *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  9732. /* return value of 1=2.5GHz 2=5GHz */
  9733. *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  9734. }
  9735. static int bnx2x_check_firmware(struct bnx2x *bp)
  9736. {
  9737. const struct firmware *firmware = bp->firmware;
  9738. struct bnx2x_fw_file_hdr *fw_hdr;
  9739. struct bnx2x_fw_file_section *sections;
  9740. u32 offset, len, num_ops;
  9741. u16 *ops_offsets;
  9742. int i;
  9743. const u8 *fw_ver;
  9744. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  9745. BNX2X_ERR("Wrong FW size\n");
  9746. return -EINVAL;
  9747. }
  9748. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  9749. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  9750. /* Make sure none of the offsets and sizes make us read beyond
  9751. * the end of the firmware data */
  9752. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  9753. offset = be32_to_cpu(sections[i].offset);
  9754. len = be32_to_cpu(sections[i].len);
  9755. if (offset + len > firmware->size) {
  9756. BNX2X_ERR("Section %d length is out of bounds\n", i);
  9757. return -EINVAL;
  9758. }
  9759. }
  9760. /* Likewise for the init_ops offsets */
  9761. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  9762. ops_offsets = (u16 *)(firmware->data + offset);
  9763. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  9764. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  9765. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  9766. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  9767. return -EINVAL;
  9768. }
  9769. }
  9770. /* Check FW version */
  9771. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  9772. fw_ver = firmware->data + offset;
  9773. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  9774. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  9775. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  9776. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  9777. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  9778. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  9779. BCM_5710_FW_MAJOR_VERSION,
  9780. BCM_5710_FW_MINOR_VERSION,
  9781. BCM_5710_FW_REVISION_VERSION,
  9782. BCM_5710_FW_ENGINEERING_VERSION);
  9783. return -EINVAL;
  9784. }
  9785. return 0;
  9786. }
  9787. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  9788. {
  9789. const __be32 *source = (const __be32 *)_source;
  9790. u32 *target = (u32 *)_target;
  9791. u32 i;
  9792. for (i = 0; i < n/4; i++)
  9793. target[i] = be32_to_cpu(source[i]);
  9794. }
  9795. /*
  9796. Ops array is stored in the following format:
  9797. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  9798. */
  9799. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  9800. {
  9801. const __be32 *source = (const __be32 *)_source;
  9802. struct raw_op *target = (struct raw_op *)_target;
  9803. u32 i, j, tmp;
  9804. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  9805. tmp = be32_to_cpu(source[j]);
  9806. target[i].op = (tmp >> 24) & 0xff;
  9807. target[i].offset = tmp & 0xffffff;
  9808. target[i].raw_data = be32_to_cpu(source[j + 1]);
  9809. }
  9810. }
  9811. /* IRO array is stored in the following format:
  9812. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  9813. */
  9814. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  9815. {
  9816. const __be32 *source = (const __be32 *)_source;
  9817. struct iro *target = (struct iro *)_target;
  9818. u32 i, j, tmp;
  9819. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  9820. target[i].base = be32_to_cpu(source[j]);
  9821. j++;
  9822. tmp = be32_to_cpu(source[j]);
  9823. target[i].m1 = (tmp >> 16) & 0xffff;
  9824. target[i].m2 = tmp & 0xffff;
  9825. j++;
  9826. tmp = be32_to_cpu(source[j]);
  9827. target[i].m3 = (tmp >> 16) & 0xffff;
  9828. target[i].size = tmp & 0xffff;
  9829. j++;
  9830. }
  9831. }
  9832. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  9833. {
  9834. const __be16 *source = (const __be16 *)_source;
  9835. u16 *target = (u16 *)_target;
  9836. u32 i;
  9837. for (i = 0; i < n/2; i++)
  9838. target[i] = be16_to_cpu(source[i]);
  9839. }
  9840. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  9841. do { \
  9842. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  9843. bp->arr = kmalloc(len, GFP_KERNEL); \
  9844. if (!bp->arr) \
  9845. goto lbl; \
  9846. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  9847. (u8 *)bp->arr, len); \
  9848. } while (0)
  9849. static int bnx2x_init_firmware(struct bnx2x *bp)
  9850. {
  9851. const char *fw_file_name;
  9852. struct bnx2x_fw_file_hdr *fw_hdr;
  9853. int rc;
  9854. if (bp->firmware)
  9855. return 0;
  9856. if (CHIP_IS_E1(bp))
  9857. fw_file_name = FW_FILE_NAME_E1;
  9858. else if (CHIP_IS_E1H(bp))
  9859. fw_file_name = FW_FILE_NAME_E1H;
  9860. else if (!CHIP_IS_E1x(bp))
  9861. fw_file_name = FW_FILE_NAME_E2;
  9862. else {
  9863. BNX2X_ERR("Unsupported chip revision\n");
  9864. return -EINVAL;
  9865. }
  9866. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  9867. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  9868. if (rc) {
  9869. BNX2X_ERR("Can't load firmware file %s\n",
  9870. fw_file_name);
  9871. goto request_firmware_exit;
  9872. }
  9873. rc = bnx2x_check_firmware(bp);
  9874. if (rc) {
  9875. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  9876. goto request_firmware_exit;
  9877. }
  9878. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  9879. /* Initialize the pointers to the init arrays */
  9880. /* Blob */
  9881. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  9882. /* Opcodes */
  9883. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  9884. /* Offsets */
  9885. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  9886. be16_to_cpu_n);
  9887. /* STORMs firmware */
  9888. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9889. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  9890. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  9891. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  9892. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9893. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  9894. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  9895. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  9896. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9897. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  9898. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  9899. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  9900. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9901. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  9902. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  9903. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  9904. /* IRO */
  9905. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  9906. return 0;
  9907. iro_alloc_err:
  9908. kfree(bp->init_ops_offsets);
  9909. init_offsets_alloc_err:
  9910. kfree(bp->init_ops);
  9911. init_ops_alloc_err:
  9912. kfree(bp->init_data);
  9913. request_firmware_exit:
  9914. release_firmware(bp->firmware);
  9915. bp->firmware = NULL;
  9916. return rc;
  9917. }
  9918. static void bnx2x_release_firmware(struct bnx2x *bp)
  9919. {
  9920. kfree(bp->init_ops_offsets);
  9921. kfree(bp->init_ops);
  9922. kfree(bp->init_data);
  9923. release_firmware(bp->firmware);
  9924. bp->firmware = NULL;
  9925. }
  9926. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  9927. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  9928. .init_hw_cmn = bnx2x_init_hw_common,
  9929. .init_hw_port = bnx2x_init_hw_port,
  9930. .init_hw_func = bnx2x_init_hw_func,
  9931. .reset_hw_cmn = bnx2x_reset_common,
  9932. .reset_hw_port = bnx2x_reset_port,
  9933. .reset_hw_func = bnx2x_reset_func,
  9934. .gunzip_init = bnx2x_gunzip_init,
  9935. .gunzip_end = bnx2x_gunzip_end,
  9936. .init_fw = bnx2x_init_firmware,
  9937. .release_fw = bnx2x_release_firmware,
  9938. };
  9939. void bnx2x__init_func_obj(struct bnx2x *bp)
  9940. {
  9941. /* Prepare DMAE related driver resources */
  9942. bnx2x_setup_dmae(bp);
  9943. bnx2x_init_func_obj(bp, &bp->func_obj,
  9944. bnx2x_sp(bp, func_rdata),
  9945. bnx2x_sp_mapping(bp, func_rdata),
  9946. bnx2x_sp(bp, func_afex_rdata),
  9947. bnx2x_sp_mapping(bp, func_afex_rdata),
  9948. &bnx2x_func_sp_drv);
  9949. }
  9950. /* must be called after sriov-enable */
  9951. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  9952. {
  9953. int cid_count = BNX2X_L2_MAX_CID(bp);
  9954. if (CNIC_SUPPORT(bp))
  9955. cid_count += CNIC_CID_MAX;
  9956. return roundup(cid_count, QM_CID_ROUND);
  9957. }
  9958. /**
  9959. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  9960. *
  9961. * @dev: pci device
  9962. *
  9963. */
  9964. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev,
  9965. int cnic_cnt)
  9966. {
  9967. int pos;
  9968. u16 control;
  9969. pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  9970. /*
  9971. * If MSI-X is not supported - return number of SBs needed to support
  9972. * one fast path queue: one FP queue + SB for CNIC
  9973. */
  9974. if (!pos)
  9975. return 1 + cnic_cnt;
  9976. /*
  9977. * The value in the PCI configuration space is the index of the last
  9978. * entry, namely one less than the actual size of the table, which is
  9979. * exactly what we want to return from this function: number of all SBs
  9980. * without the default SB.
  9981. */
  9982. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
  9983. return control & PCI_MSIX_FLAGS_QSIZE;
  9984. }
  9985. static int __devinit bnx2x_init_one(struct pci_dev *pdev,
  9986. const struct pci_device_id *ent)
  9987. {
  9988. struct net_device *dev = NULL;
  9989. struct bnx2x *bp;
  9990. int pcie_width, pcie_speed;
  9991. int rc, max_non_def_sbs;
  9992. int rx_count, tx_count, rss_count, doorbell_size;
  9993. int cnic_cnt;
  9994. /*
  9995. * An estimated maximum supported CoS number according to the chip
  9996. * version.
  9997. * We will try to roughly estimate the maximum number of CoSes this chip
  9998. * may support in order to minimize the memory allocated for Tx
  9999. * netdev_queue's. This number will be accurately calculated during the
  10000. * initialization of bp->max_cos based on the chip versions AND chip
  10001. * revision in the bnx2x_init_bp().
  10002. */
  10003. u8 max_cos_est = 0;
  10004. switch (ent->driver_data) {
  10005. case BCM57710:
  10006. case BCM57711:
  10007. case BCM57711E:
  10008. max_cos_est = BNX2X_MULTI_TX_COS_E1X;
  10009. break;
  10010. case BCM57712:
  10011. case BCM57712_MF:
  10012. max_cos_est = BNX2X_MULTI_TX_COS_E2_E3A0;
  10013. break;
  10014. case BCM57800:
  10015. case BCM57800_MF:
  10016. case BCM57810:
  10017. case BCM57810_MF:
  10018. case BCM57840_O:
  10019. case BCM57840_4_10:
  10020. case BCM57840_2_20:
  10021. case BCM57840_MFO:
  10022. case BCM57840_MF:
  10023. case BCM57811:
  10024. case BCM57811_MF:
  10025. max_cos_est = BNX2X_MULTI_TX_COS_E3B0;
  10026. break;
  10027. default:
  10028. pr_err("Unknown board_type (%ld), aborting\n",
  10029. ent->driver_data);
  10030. return -ENODEV;
  10031. }
  10032. cnic_cnt = 1;
  10033. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt);
  10034. WARN_ON(!max_non_def_sbs);
  10035. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  10036. rss_count = max_non_def_sbs - cnic_cnt;
  10037. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  10038. rx_count = rss_count + cnic_cnt;
  10039. /*
  10040. * Maximum number of netdev Tx queues:
  10041. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  10042. */
  10043. tx_count = rss_count * max_cos_est + cnic_cnt;
  10044. /* dev zeroed in init_etherdev */
  10045. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  10046. if (!dev)
  10047. return -ENOMEM;
  10048. bp = netdev_priv(dev);
  10049. bp->igu_sb_cnt = max_non_def_sbs;
  10050. bp->msg_enable = debug;
  10051. bp->cnic_support = cnic_cnt;
  10052. pci_set_drvdata(pdev, dev);
  10053. rc = bnx2x_init_dev(pdev, dev, ent->driver_data);
  10054. if (rc < 0) {
  10055. free_netdev(dev);
  10056. return rc;
  10057. }
  10058. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  10059. BNX2X_DEV_INFO("max_non_def_sbs %d\n", max_non_def_sbs);
  10060. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  10061. tx_count, rx_count);
  10062. rc = bnx2x_init_bp(bp);
  10063. if (rc)
  10064. goto init_one_exit;
  10065. /*
  10066. * Map doorbels here as we need the real value of bp->max_cos which
  10067. * is initialized in bnx2x_init_bp().
  10068. */
  10069. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  10070. if (doorbell_size > pci_resource_len(pdev, 2)) {
  10071. dev_err(&bp->pdev->dev,
  10072. "Cannot map doorbells, bar size too small, aborting\n");
  10073. rc = -ENOMEM;
  10074. goto init_one_exit;
  10075. }
  10076. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  10077. doorbell_size);
  10078. if (!bp->doorbells) {
  10079. dev_err(&bp->pdev->dev,
  10080. "Cannot map doorbell space, aborting\n");
  10081. rc = -ENOMEM;
  10082. goto init_one_exit;
  10083. }
  10084. /* calc qm_cid_count */
  10085. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  10086. /* disable FCOE L2 queue for E1x*/
  10087. if (CHIP_IS_E1x(bp))
  10088. bp->flags |= NO_FCOE_FLAG;
  10089. /* disable FCOE for 57840 device, until FW supports it */
  10090. switch (ent->driver_data) {
  10091. case BCM57840_O:
  10092. case BCM57840_4_10:
  10093. case BCM57840_2_20:
  10094. case BCM57840_MFO:
  10095. case BCM57840_MF:
  10096. bp->flags |= NO_FCOE_FLAG;
  10097. }
  10098. /* Set bp->num_queues for MSI-X mode*/
  10099. bnx2x_set_num_queues(bp);
  10100. /* Configure interrupt mode: try to enable MSI-X/MSI if
  10101. * needed.
  10102. */
  10103. bnx2x_set_int_mode(bp);
  10104. rc = register_netdev(dev);
  10105. if (rc) {
  10106. dev_err(&pdev->dev, "Cannot register net device\n");
  10107. goto init_one_exit;
  10108. }
  10109. if (!NO_FCOE(bp)) {
  10110. /* Add storage MAC address */
  10111. rtnl_lock();
  10112. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10113. rtnl_unlock();
  10114. }
  10115. bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
  10116. BNX2X_DEV_INFO(
  10117. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  10118. board_info[ent->driver_data].name,
  10119. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  10120. pcie_width,
  10121. ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
  10122. (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
  10123. "5GHz (Gen2)" : "2.5GHz",
  10124. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  10125. return 0;
  10126. init_one_exit:
  10127. if (bp->regview)
  10128. iounmap(bp->regview);
  10129. if (bp->doorbells)
  10130. iounmap(bp->doorbells);
  10131. free_netdev(dev);
  10132. if (atomic_read(&pdev->enable_cnt) == 1)
  10133. pci_release_regions(pdev);
  10134. pci_disable_device(pdev);
  10135. pci_set_drvdata(pdev, NULL);
  10136. return rc;
  10137. }
  10138. static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
  10139. {
  10140. struct net_device *dev = pci_get_drvdata(pdev);
  10141. struct bnx2x *bp;
  10142. if (!dev) {
  10143. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  10144. return;
  10145. }
  10146. bp = netdev_priv(dev);
  10147. /* Delete storage MAC address */
  10148. if (!NO_FCOE(bp)) {
  10149. rtnl_lock();
  10150. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10151. rtnl_unlock();
  10152. }
  10153. #ifdef BCM_DCBNL
  10154. /* Delete app tlvs from dcbnl */
  10155. bnx2x_dcbnl_update_applist(bp, true);
  10156. #endif
  10157. unregister_netdev(dev);
  10158. /* Power on: we can't let PCI layer write to us while we are in D3 */
  10159. bnx2x_set_power_state(bp, PCI_D0);
  10160. /* Disable MSI/MSI-X */
  10161. bnx2x_disable_msi(bp);
  10162. /* Power off */
  10163. bnx2x_set_power_state(bp, PCI_D3hot);
  10164. /* Make sure RESET task is not scheduled before continuing */
  10165. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  10166. if (bp->regview)
  10167. iounmap(bp->regview);
  10168. if (bp->doorbells)
  10169. iounmap(bp->doorbells);
  10170. bnx2x_release_firmware(bp);
  10171. bnx2x_free_mem_bp(bp);
  10172. free_netdev(dev);
  10173. if (atomic_read(&pdev->enable_cnt) == 1)
  10174. pci_release_regions(pdev);
  10175. pci_disable_device(pdev);
  10176. pci_set_drvdata(pdev, NULL);
  10177. }
  10178. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  10179. {
  10180. int i;
  10181. bp->state = BNX2X_STATE_ERROR;
  10182. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10183. if (CNIC_LOADED(bp))
  10184. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  10185. /* Stop Tx */
  10186. bnx2x_tx_disable(bp);
  10187. bnx2x_netif_stop(bp, 0);
  10188. /* Delete all NAPI objects */
  10189. bnx2x_del_all_napi(bp);
  10190. if (CNIC_LOADED(bp))
  10191. bnx2x_del_all_napi_cnic(bp);
  10192. del_timer_sync(&bp->timer);
  10193. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  10194. /* Release IRQs */
  10195. bnx2x_free_irq(bp);
  10196. /* Free SKBs, SGEs, TPA pool and driver internals */
  10197. bnx2x_free_skbs(bp);
  10198. for_each_rx_queue(bp, i)
  10199. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  10200. bnx2x_free_mem(bp);
  10201. bp->state = BNX2X_STATE_CLOSED;
  10202. netif_carrier_off(bp->dev);
  10203. return 0;
  10204. }
  10205. static void bnx2x_eeh_recover(struct bnx2x *bp)
  10206. {
  10207. u32 val;
  10208. mutex_init(&bp->port.phy_mutex);
  10209. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  10210. if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10211. != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10212. BNX2X_ERR("BAD MCP validity signature\n");
  10213. }
  10214. /**
  10215. * bnx2x_io_error_detected - called when PCI error is detected
  10216. * @pdev: Pointer to PCI device
  10217. * @state: The current pci connection state
  10218. *
  10219. * This function is called after a PCI bus error affecting
  10220. * this device has been detected.
  10221. */
  10222. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  10223. pci_channel_state_t state)
  10224. {
  10225. struct net_device *dev = pci_get_drvdata(pdev);
  10226. struct bnx2x *bp = netdev_priv(dev);
  10227. rtnl_lock();
  10228. netif_device_detach(dev);
  10229. if (state == pci_channel_io_perm_failure) {
  10230. rtnl_unlock();
  10231. return PCI_ERS_RESULT_DISCONNECT;
  10232. }
  10233. if (netif_running(dev))
  10234. bnx2x_eeh_nic_unload(bp);
  10235. pci_disable_device(pdev);
  10236. rtnl_unlock();
  10237. /* Request a slot reset */
  10238. return PCI_ERS_RESULT_NEED_RESET;
  10239. }
  10240. /**
  10241. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  10242. * @pdev: Pointer to PCI device
  10243. *
  10244. * Restart the card from scratch, as if from a cold-boot.
  10245. */
  10246. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  10247. {
  10248. struct net_device *dev = pci_get_drvdata(pdev);
  10249. struct bnx2x *bp = netdev_priv(dev);
  10250. rtnl_lock();
  10251. if (pci_enable_device(pdev)) {
  10252. dev_err(&pdev->dev,
  10253. "Cannot re-enable PCI device after reset\n");
  10254. rtnl_unlock();
  10255. return PCI_ERS_RESULT_DISCONNECT;
  10256. }
  10257. pci_set_master(pdev);
  10258. pci_restore_state(pdev);
  10259. if (netif_running(dev))
  10260. bnx2x_set_power_state(bp, PCI_D0);
  10261. rtnl_unlock();
  10262. return PCI_ERS_RESULT_RECOVERED;
  10263. }
  10264. /**
  10265. * bnx2x_io_resume - called when traffic can start flowing again
  10266. * @pdev: Pointer to PCI device
  10267. *
  10268. * This callback is called when the error recovery driver tells us that
  10269. * its OK to resume normal operation.
  10270. */
  10271. static void bnx2x_io_resume(struct pci_dev *pdev)
  10272. {
  10273. struct net_device *dev = pci_get_drvdata(pdev);
  10274. struct bnx2x *bp = netdev_priv(dev);
  10275. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  10276. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  10277. return;
  10278. }
  10279. rtnl_lock();
  10280. bnx2x_eeh_recover(bp);
  10281. if (netif_running(dev))
  10282. bnx2x_nic_load(bp, LOAD_NORMAL);
  10283. netif_device_attach(dev);
  10284. rtnl_unlock();
  10285. }
  10286. static const struct pci_error_handlers bnx2x_err_handler = {
  10287. .error_detected = bnx2x_io_error_detected,
  10288. .slot_reset = bnx2x_io_slot_reset,
  10289. .resume = bnx2x_io_resume,
  10290. };
  10291. static struct pci_driver bnx2x_pci_driver = {
  10292. .name = DRV_MODULE_NAME,
  10293. .id_table = bnx2x_pci_tbl,
  10294. .probe = bnx2x_init_one,
  10295. .remove = __devexit_p(bnx2x_remove_one),
  10296. .suspend = bnx2x_suspend,
  10297. .resume = bnx2x_resume,
  10298. .err_handler = &bnx2x_err_handler,
  10299. };
  10300. static int __init bnx2x_init(void)
  10301. {
  10302. int ret;
  10303. pr_info("%s", version);
  10304. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  10305. if (bnx2x_wq == NULL) {
  10306. pr_err("Cannot create workqueue\n");
  10307. return -ENOMEM;
  10308. }
  10309. ret = pci_register_driver(&bnx2x_pci_driver);
  10310. if (ret) {
  10311. pr_err("Cannot register driver\n");
  10312. destroy_workqueue(bnx2x_wq);
  10313. }
  10314. return ret;
  10315. }
  10316. static void __exit bnx2x_cleanup(void)
  10317. {
  10318. struct list_head *pos, *q;
  10319. pci_unregister_driver(&bnx2x_pci_driver);
  10320. destroy_workqueue(bnx2x_wq);
  10321. /* Free globablly allocated resources */
  10322. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  10323. struct bnx2x_prev_path_list *tmp =
  10324. list_entry(pos, struct bnx2x_prev_path_list, list);
  10325. list_del(pos);
  10326. kfree(tmp);
  10327. }
  10328. }
  10329. void bnx2x_notify_link_changed(struct bnx2x *bp)
  10330. {
  10331. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  10332. }
  10333. module_init(bnx2x_init);
  10334. module_exit(bnx2x_cleanup);
  10335. /**
  10336. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  10337. *
  10338. * @bp: driver handle
  10339. * @set: set or clear the CAM entry
  10340. *
  10341. * This function will wait until the ramdord completion returns.
  10342. * Return 0 if success, -ENODEV if ramrod doesn't return.
  10343. */
  10344. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  10345. {
  10346. unsigned long ramrod_flags = 0;
  10347. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  10348. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  10349. &bp->iscsi_l2_mac_obj, true,
  10350. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  10351. }
  10352. /* count denotes the number of new completions we have seen */
  10353. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  10354. {
  10355. struct eth_spe *spe;
  10356. int cxt_index, cxt_offset;
  10357. #ifdef BNX2X_STOP_ON_ERROR
  10358. if (unlikely(bp->panic))
  10359. return;
  10360. #endif
  10361. spin_lock_bh(&bp->spq_lock);
  10362. BUG_ON(bp->cnic_spq_pending < count);
  10363. bp->cnic_spq_pending -= count;
  10364. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  10365. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  10366. & SPE_HDR_CONN_TYPE) >>
  10367. SPE_HDR_CONN_TYPE_SHIFT;
  10368. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  10369. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  10370. /* Set validation for iSCSI L2 client before sending SETUP
  10371. * ramrod
  10372. */
  10373. if (type == ETH_CONNECTION_TYPE) {
  10374. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  10375. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  10376. ILT_PAGE_CIDS;
  10377. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  10378. (cxt_index * ILT_PAGE_CIDS);
  10379. bnx2x_set_ctx_validation(bp,
  10380. &bp->context[cxt_index].
  10381. vcxt[cxt_offset].eth,
  10382. BNX2X_ISCSI_ETH_CID(bp));
  10383. }
  10384. }
  10385. /*
  10386. * There may be not more than 8 L2, not more than 8 L5 SPEs
  10387. * and in the air. We also check that number of outstanding
  10388. * COMMON ramrods is not more than the EQ and SPQ can
  10389. * accommodate.
  10390. */
  10391. if (type == ETH_CONNECTION_TYPE) {
  10392. if (!atomic_read(&bp->cq_spq_left))
  10393. break;
  10394. else
  10395. atomic_dec(&bp->cq_spq_left);
  10396. } else if (type == NONE_CONNECTION_TYPE) {
  10397. if (!atomic_read(&bp->eq_spq_left))
  10398. break;
  10399. else
  10400. atomic_dec(&bp->eq_spq_left);
  10401. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  10402. (type == FCOE_CONNECTION_TYPE)) {
  10403. if (bp->cnic_spq_pending >=
  10404. bp->cnic_eth_dev.max_kwqe_pending)
  10405. break;
  10406. else
  10407. bp->cnic_spq_pending++;
  10408. } else {
  10409. BNX2X_ERR("Unknown SPE type: %d\n", type);
  10410. bnx2x_panic();
  10411. break;
  10412. }
  10413. spe = bnx2x_sp_get_next(bp);
  10414. *spe = *bp->cnic_kwq_cons;
  10415. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  10416. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  10417. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  10418. bp->cnic_kwq_cons = bp->cnic_kwq;
  10419. else
  10420. bp->cnic_kwq_cons++;
  10421. }
  10422. bnx2x_sp_prod_update(bp);
  10423. spin_unlock_bh(&bp->spq_lock);
  10424. }
  10425. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  10426. struct kwqe_16 *kwqes[], u32 count)
  10427. {
  10428. struct bnx2x *bp = netdev_priv(dev);
  10429. int i;
  10430. #ifdef BNX2X_STOP_ON_ERROR
  10431. if (unlikely(bp->panic)) {
  10432. BNX2X_ERR("Can't post to SP queue while panic\n");
  10433. return -EIO;
  10434. }
  10435. #endif
  10436. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  10437. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  10438. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  10439. return -EAGAIN;
  10440. }
  10441. spin_lock_bh(&bp->spq_lock);
  10442. for (i = 0; i < count; i++) {
  10443. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  10444. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  10445. break;
  10446. *bp->cnic_kwq_prod = *spe;
  10447. bp->cnic_kwq_pending++;
  10448. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  10449. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  10450. spe->data.update_data_addr.hi,
  10451. spe->data.update_data_addr.lo,
  10452. bp->cnic_kwq_pending);
  10453. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  10454. bp->cnic_kwq_prod = bp->cnic_kwq;
  10455. else
  10456. bp->cnic_kwq_prod++;
  10457. }
  10458. spin_unlock_bh(&bp->spq_lock);
  10459. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  10460. bnx2x_cnic_sp_post(bp, 0);
  10461. return i;
  10462. }
  10463. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10464. {
  10465. struct cnic_ops *c_ops;
  10466. int rc = 0;
  10467. mutex_lock(&bp->cnic_mutex);
  10468. c_ops = rcu_dereference_protected(bp->cnic_ops,
  10469. lockdep_is_held(&bp->cnic_mutex));
  10470. if (c_ops)
  10471. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10472. mutex_unlock(&bp->cnic_mutex);
  10473. return rc;
  10474. }
  10475. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10476. {
  10477. struct cnic_ops *c_ops;
  10478. int rc = 0;
  10479. rcu_read_lock();
  10480. c_ops = rcu_dereference(bp->cnic_ops);
  10481. if (c_ops)
  10482. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10483. rcu_read_unlock();
  10484. return rc;
  10485. }
  10486. /*
  10487. * for commands that have no data
  10488. */
  10489. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  10490. {
  10491. struct cnic_ctl_info ctl = {0};
  10492. ctl.cmd = cmd;
  10493. return bnx2x_cnic_ctl_send(bp, &ctl);
  10494. }
  10495. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  10496. {
  10497. struct cnic_ctl_info ctl = {0};
  10498. /* first we tell CNIC and only then we count this as a completion */
  10499. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  10500. ctl.data.comp.cid = cid;
  10501. ctl.data.comp.error = err;
  10502. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  10503. bnx2x_cnic_sp_post(bp, 0);
  10504. }
  10505. /* Called with netif_addr_lock_bh() taken.
  10506. * Sets an rx_mode config for an iSCSI ETH client.
  10507. * Doesn't block.
  10508. * Completion should be checked outside.
  10509. */
  10510. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  10511. {
  10512. unsigned long accept_flags = 0, ramrod_flags = 0;
  10513. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  10514. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  10515. if (start) {
  10516. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  10517. * because it's the only way for UIO Queue to accept
  10518. * multicasts (in non-promiscuous mode only one Queue per
  10519. * function will receive multicast packets (leading in our
  10520. * case).
  10521. */
  10522. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  10523. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  10524. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  10525. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  10526. /* Clear STOP_PENDING bit if START is requested */
  10527. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  10528. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  10529. } else
  10530. /* Clear START_PENDING bit if STOP is requested */
  10531. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  10532. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  10533. set_bit(sched_state, &bp->sp_state);
  10534. else {
  10535. __set_bit(RAMROD_RX, &ramrod_flags);
  10536. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  10537. ramrod_flags);
  10538. }
  10539. }
  10540. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  10541. {
  10542. struct bnx2x *bp = netdev_priv(dev);
  10543. int rc = 0;
  10544. switch (ctl->cmd) {
  10545. case DRV_CTL_CTXTBL_WR_CMD: {
  10546. u32 index = ctl->data.io.offset;
  10547. dma_addr_t addr = ctl->data.io.dma_addr;
  10548. bnx2x_ilt_wr(bp, index, addr);
  10549. break;
  10550. }
  10551. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  10552. int count = ctl->data.credit.credit_count;
  10553. bnx2x_cnic_sp_post(bp, count);
  10554. break;
  10555. }
  10556. /* rtnl_lock is held. */
  10557. case DRV_CTL_START_L2_CMD: {
  10558. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10559. unsigned long sp_bits = 0;
  10560. /* Configure the iSCSI classification object */
  10561. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  10562. cp->iscsi_l2_client_id,
  10563. cp->iscsi_l2_cid, BP_FUNC(bp),
  10564. bnx2x_sp(bp, mac_rdata),
  10565. bnx2x_sp_mapping(bp, mac_rdata),
  10566. BNX2X_FILTER_MAC_PENDING,
  10567. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  10568. &bp->macs_pool);
  10569. /* Set iSCSI MAC address */
  10570. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  10571. if (rc)
  10572. break;
  10573. mmiowb();
  10574. barrier();
  10575. /* Start accepting on iSCSI L2 ring */
  10576. netif_addr_lock_bh(dev);
  10577. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  10578. netif_addr_unlock_bh(dev);
  10579. /* bits to wait on */
  10580. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10581. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  10582. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10583. BNX2X_ERR("rx_mode completion timed out!\n");
  10584. break;
  10585. }
  10586. /* rtnl_lock is held. */
  10587. case DRV_CTL_STOP_L2_CMD: {
  10588. unsigned long sp_bits = 0;
  10589. /* Stop accepting on iSCSI L2 ring */
  10590. netif_addr_lock_bh(dev);
  10591. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  10592. netif_addr_unlock_bh(dev);
  10593. /* bits to wait on */
  10594. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10595. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  10596. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10597. BNX2X_ERR("rx_mode completion timed out!\n");
  10598. mmiowb();
  10599. barrier();
  10600. /* Unset iSCSI L2 MAC */
  10601. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  10602. BNX2X_ISCSI_ETH_MAC, true);
  10603. break;
  10604. }
  10605. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  10606. int count = ctl->data.credit.credit_count;
  10607. smp_mb__before_atomic_inc();
  10608. atomic_add(count, &bp->cq_spq_left);
  10609. smp_mb__after_atomic_inc();
  10610. break;
  10611. }
  10612. case DRV_CTL_ULP_REGISTER_CMD: {
  10613. int ulp_type = ctl->data.register_data.ulp_type;
  10614. if (CHIP_IS_E3(bp)) {
  10615. int idx = BP_FW_MB_IDX(bp);
  10616. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  10617. int path = BP_PATH(bp);
  10618. int port = BP_PORT(bp);
  10619. int i;
  10620. u32 scratch_offset;
  10621. u32 *host_addr;
  10622. /* first write capability to shmem2 */
  10623. if (ulp_type == CNIC_ULP_ISCSI)
  10624. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  10625. else if (ulp_type == CNIC_ULP_FCOE)
  10626. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  10627. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  10628. if ((ulp_type != CNIC_ULP_FCOE) ||
  10629. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  10630. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  10631. break;
  10632. /* if reached here - should write fcoe capabilities */
  10633. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  10634. if (!scratch_offset)
  10635. break;
  10636. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  10637. fcoe_features[path][port]);
  10638. host_addr = (u32 *) &(ctl->data.register_data.
  10639. fcoe_features);
  10640. for (i = 0; i < sizeof(struct fcoe_capabilities);
  10641. i += 4)
  10642. REG_WR(bp, scratch_offset + i,
  10643. *(host_addr + i/4));
  10644. }
  10645. break;
  10646. }
  10647. case DRV_CTL_ULP_UNREGISTER_CMD: {
  10648. int ulp_type = ctl->data.ulp_type;
  10649. if (CHIP_IS_E3(bp)) {
  10650. int idx = BP_FW_MB_IDX(bp);
  10651. u32 cap;
  10652. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  10653. if (ulp_type == CNIC_ULP_ISCSI)
  10654. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  10655. else if (ulp_type == CNIC_ULP_FCOE)
  10656. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  10657. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  10658. }
  10659. break;
  10660. }
  10661. default:
  10662. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  10663. rc = -EINVAL;
  10664. }
  10665. return rc;
  10666. }
  10667. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  10668. {
  10669. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10670. if (bp->flags & USING_MSIX_FLAG) {
  10671. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  10672. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  10673. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  10674. } else {
  10675. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  10676. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  10677. }
  10678. if (!CHIP_IS_E1x(bp))
  10679. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  10680. else
  10681. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  10682. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  10683. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  10684. cp->irq_arr[1].status_blk = bp->def_status_blk;
  10685. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  10686. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  10687. cp->num_irq = 2;
  10688. }
  10689. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  10690. {
  10691. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10692. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  10693. bnx2x_cid_ilt_lines(bp);
  10694. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  10695. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  10696. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  10697. if (NO_ISCSI_OOO(bp))
  10698. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  10699. }
  10700. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  10701. void *data)
  10702. {
  10703. struct bnx2x *bp = netdev_priv(dev);
  10704. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10705. int rc;
  10706. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  10707. if (ops == NULL) {
  10708. BNX2X_ERR("NULL ops received\n");
  10709. return -EINVAL;
  10710. }
  10711. if (!CNIC_SUPPORT(bp)) {
  10712. BNX2X_ERR("Can't register CNIC when not supported\n");
  10713. return -EOPNOTSUPP;
  10714. }
  10715. if (!CNIC_LOADED(bp)) {
  10716. rc = bnx2x_load_cnic(bp);
  10717. if (rc) {
  10718. BNX2X_ERR("CNIC-related load failed\n");
  10719. return rc;
  10720. }
  10721. }
  10722. bp->cnic_enabled = true;
  10723. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  10724. if (!bp->cnic_kwq)
  10725. return -ENOMEM;
  10726. bp->cnic_kwq_cons = bp->cnic_kwq;
  10727. bp->cnic_kwq_prod = bp->cnic_kwq;
  10728. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  10729. bp->cnic_spq_pending = 0;
  10730. bp->cnic_kwq_pending = 0;
  10731. bp->cnic_data = data;
  10732. cp->num_irq = 0;
  10733. cp->drv_state |= CNIC_DRV_STATE_REGD;
  10734. cp->iro_arr = bp->iro_arr;
  10735. bnx2x_setup_cnic_irq_info(bp);
  10736. rcu_assign_pointer(bp->cnic_ops, ops);
  10737. return 0;
  10738. }
  10739. static int bnx2x_unregister_cnic(struct net_device *dev)
  10740. {
  10741. struct bnx2x *bp = netdev_priv(dev);
  10742. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10743. mutex_lock(&bp->cnic_mutex);
  10744. cp->drv_state = 0;
  10745. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  10746. mutex_unlock(&bp->cnic_mutex);
  10747. synchronize_rcu();
  10748. kfree(bp->cnic_kwq);
  10749. bp->cnic_kwq = NULL;
  10750. return 0;
  10751. }
  10752. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  10753. {
  10754. struct bnx2x *bp = netdev_priv(dev);
  10755. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10756. /* If both iSCSI and FCoE are disabled - return NULL in
  10757. * order to indicate CNIC that it should not try to work
  10758. * with this device.
  10759. */
  10760. if (NO_ISCSI(bp) && NO_FCOE(bp))
  10761. return NULL;
  10762. cp->drv_owner = THIS_MODULE;
  10763. cp->chip_id = CHIP_ID(bp);
  10764. cp->pdev = bp->pdev;
  10765. cp->io_base = bp->regview;
  10766. cp->io_base2 = bp->doorbells;
  10767. cp->max_kwqe_pending = 8;
  10768. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  10769. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  10770. bnx2x_cid_ilt_lines(bp);
  10771. cp->ctx_tbl_len = CNIC_ILT_LINES;
  10772. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  10773. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  10774. cp->drv_ctl = bnx2x_drv_ctl;
  10775. cp->drv_register_cnic = bnx2x_register_cnic;
  10776. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  10777. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  10778. cp->iscsi_l2_client_id =
  10779. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  10780. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  10781. if (NO_ISCSI_OOO(bp))
  10782. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  10783. if (NO_ISCSI(bp))
  10784. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  10785. if (NO_FCOE(bp))
  10786. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  10787. BNX2X_DEV_INFO(
  10788. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  10789. cp->ctx_blk_size,
  10790. cp->ctx_tbl_offset,
  10791. cp->ctx_tbl_len,
  10792. cp->starting_cid);
  10793. return cp;
  10794. }
  10795. EXPORT_SYMBOL(bnx2x_cnic_probe);