s2io.c 241 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665
  1. /************************************************************************
  2. * s2io.c: A Linux PCI-X Ethernet driver for Neterion 10GbE Server NIC
  3. * Copyright(c) 2002-2010 Exar Corp.
  4. *
  5. * This software may be used and distributed according to the terms of
  6. * the GNU General Public License (GPL), incorporated herein by reference.
  7. * Drivers based on or derived from this code fall under the GPL and must
  8. * retain the authorship, copyright and license notice. This file is not
  9. * a complete program and may only be used when the entire operating
  10. * system is licensed under the GPL.
  11. * See the file COPYING in this distribution for more information.
  12. *
  13. * Credits:
  14. * Jeff Garzik : For pointing out the improper error condition
  15. * check in the s2io_xmit routine and also some
  16. * issues in the Tx watch dog function. Also for
  17. * patiently answering all those innumerable
  18. * questions regaring the 2.6 porting issues.
  19. * Stephen Hemminger : Providing proper 2.6 porting mechanism for some
  20. * macros available only in 2.6 Kernel.
  21. * Francois Romieu : For pointing out all code part that were
  22. * deprecated and also styling related comments.
  23. * Grant Grundler : For helping me get rid of some Architecture
  24. * dependent code.
  25. * Christopher Hellwig : Some more 2.6 specific issues in the driver.
  26. *
  27. * The module loadable parameters that are supported by the driver and a brief
  28. * explanation of all the variables.
  29. *
  30. * rx_ring_num : This can be used to program the number of receive rings used
  31. * in the driver.
  32. * rx_ring_sz: This defines the number of receive blocks each ring can have.
  33. * This is also an array of size 8.
  34. * rx_ring_mode: This defines the operation mode of all 8 rings. The valid
  35. * values are 1, 2.
  36. * tx_fifo_num: This defines the number of Tx FIFOs thats used int the driver.
  37. * tx_fifo_len: This too is an array of 8. Each element defines the number of
  38. * Tx descriptors that can be associated with each corresponding FIFO.
  39. * intr_type: This defines the type of interrupt. The values can be 0(INTA),
  40. * 2(MSI_X). Default value is '2(MSI_X)'
  41. * lro_max_pkts: This parameter defines maximum number of packets can be
  42. * aggregated as a single large packet
  43. * napi: This parameter used to enable/disable NAPI (polling Rx)
  44. * Possible values '1' for enable and '0' for disable. Default is '1'
  45. * ufo: This parameter used to enable/disable UDP Fragmentation Offload(UFO)
  46. * Possible values '1' for enable and '0' for disable. Default is '0'
  47. * vlan_tag_strip: This can be used to enable or disable vlan stripping.
  48. * Possible values '1' for enable , '0' for disable.
  49. * Default is '2' - which means disable in promisc mode
  50. * and enable in non-promiscuous mode.
  51. * multiq: This parameter used to enable/disable MULTIQUEUE support.
  52. * Possible values '1' for enable and '0' for disable. Default is '0'
  53. ************************************************************************/
  54. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  55. #include <linux/module.h>
  56. #include <linux/types.h>
  57. #include <linux/errno.h>
  58. #include <linux/ioport.h>
  59. #include <linux/pci.h>
  60. #include <linux/dma-mapping.h>
  61. #include <linux/kernel.h>
  62. #include <linux/netdevice.h>
  63. #include <linux/etherdevice.h>
  64. #include <linux/mdio.h>
  65. #include <linux/skbuff.h>
  66. #include <linux/init.h>
  67. #include <linux/delay.h>
  68. #include <linux/stddef.h>
  69. #include <linux/ioctl.h>
  70. #include <linux/timex.h>
  71. #include <linux/ethtool.h>
  72. #include <linux/workqueue.h>
  73. #include <linux/if_vlan.h>
  74. #include <linux/ip.h>
  75. #include <linux/tcp.h>
  76. #include <linux/uaccess.h>
  77. #include <linux/io.h>
  78. #include <linux/slab.h>
  79. #include <linux/prefetch.h>
  80. #include <net/tcp.h>
  81. #include <asm/div64.h>
  82. #include <asm/irq.h>
  83. /* local include */
  84. #include "s2io.h"
  85. #include "s2io-regs.h"
  86. #define DRV_VERSION "2.0.26.28"
  87. /* S2io Driver name & version. */
  88. static const char s2io_driver_name[] = "Neterion";
  89. static const char s2io_driver_version[] = DRV_VERSION;
  90. static const int rxd_size[2] = {32, 48};
  91. static const int rxd_count[2] = {127, 85};
  92. static inline int RXD_IS_UP2DT(struct RxD_t *rxdp)
  93. {
  94. int ret;
  95. ret = ((!(rxdp->Control_1 & RXD_OWN_XENA)) &&
  96. (GET_RXD_MARKER(rxdp->Control_2) != THE_RXD_MARK));
  97. return ret;
  98. }
  99. /*
  100. * Cards with following subsystem_id have a link state indication
  101. * problem, 600B, 600C, 600D, 640B, 640C and 640D.
  102. * macro below identifies these cards given the subsystem_id.
  103. */
  104. #define CARDS_WITH_FAULTY_LINK_INDICATORS(dev_type, subid) \
  105. (dev_type == XFRAME_I_DEVICE) ? \
  106. ((((subid >= 0x600B) && (subid <= 0x600D)) || \
  107. ((subid >= 0x640B) && (subid <= 0x640D))) ? 1 : 0) : 0
  108. #define LINK_IS_UP(val64) (!(val64 & (ADAPTER_STATUS_RMAC_REMOTE_FAULT | \
  109. ADAPTER_STATUS_RMAC_LOCAL_FAULT)))
  110. static inline int is_s2io_card_up(const struct s2io_nic *sp)
  111. {
  112. return test_bit(__S2IO_STATE_CARD_UP, &sp->state);
  113. }
  114. /* Ethtool related variables and Macros. */
  115. static const char s2io_gstrings[][ETH_GSTRING_LEN] = {
  116. "Register test\t(offline)",
  117. "Eeprom test\t(offline)",
  118. "Link test\t(online)",
  119. "RLDRAM test\t(offline)",
  120. "BIST Test\t(offline)"
  121. };
  122. static const char ethtool_xena_stats_keys[][ETH_GSTRING_LEN] = {
  123. {"tmac_frms"},
  124. {"tmac_data_octets"},
  125. {"tmac_drop_frms"},
  126. {"tmac_mcst_frms"},
  127. {"tmac_bcst_frms"},
  128. {"tmac_pause_ctrl_frms"},
  129. {"tmac_ttl_octets"},
  130. {"tmac_ucst_frms"},
  131. {"tmac_nucst_frms"},
  132. {"tmac_any_err_frms"},
  133. {"tmac_ttl_less_fb_octets"},
  134. {"tmac_vld_ip_octets"},
  135. {"tmac_vld_ip"},
  136. {"tmac_drop_ip"},
  137. {"tmac_icmp"},
  138. {"tmac_rst_tcp"},
  139. {"tmac_tcp"},
  140. {"tmac_udp"},
  141. {"rmac_vld_frms"},
  142. {"rmac_data_octets"},
  143. {"rmac_fcs_err_frms"},
  144. {"rmac_drop_frms"},
  145. {"rmac_vld_mcst_frms"},
  146. {"rmac_vld_bcst_frms"},
  147. {"rmac_in_rng_len_err_frms"},
  148. {"rmac_out_rng_len_err_frms"},
  149. {"rmac_long_frms"},
  150. {"rmac_pause_ctrl_frms"},
  151. {"rmac_unsup_ctrl_frms"},
  152. {"rmac_ttl_octets"},
  153. {"rmac_accepted_ucst_frms"},
  154. {"rmac_accepted_nucst_frms"},
  155. {"rmac_discarded_frms"},
  156. {"rmac_drop_events"},
  157. {"rmac_ttl_less_fb_octets"},
  158. {"rmac_ttl_frms"},
  159. {"rmac_usized_frms"},
  160. {"rmac_osized_frms"},
  161. {"rmac_frag_frms"},
  162. {"rmac_jabber_frms"},
  163. {"rmac_ttl_64_frms"},
  164. {"rmac_ttl_65_127_frms"},
  165. {"rmac_ttl_128_255_frms"},
  166. {"rmac_ttl_256_511_frms"},
  167. {"rmac_ttl_512_1023_frms"},
  168. {"rmac_ttl_1024_1518_frms"},
  169. {"rmac_ip"},
  170. {"rmac_ip_octets"},
  171. {"rmac_hdr_err_ip"},
  172. {"rmac_drop_ip"},
  173. {"rmac_icmp"},
  174. {"rmac_tcp"},
  175. {"rmac_udp"},
  176. {"rmac_err_drp_udp"},
  177. {"rmac_xgmii_err_sym"},
  178. {"rmac_frms_q0"},
  179. {"rmac_frms_q1"},
  180. {"rmac_frms_q2"},
  181. {"rmac_frms_q3"},
  182. {"rmac_frms_q4"},
  183. {"rmac_frms_q5"},
  184. {"rmac_frms_q6"},
  185. {"rmac_frms_q7"},
  186. {"rmac_full_q0"},
  187. {"rmac_full_q1"},
  188. {"rmac_full_q2"},
  189. {"rmac_full_q3"},
  190. {"rmac_full_q4"},
  191. {"rmac_full_q5"},
  192. {"rmac_full_q6"},
  193. {"rmac_full_q7"},
  194. {"rmac_pause_cnt"},
  195. {"rmac_xgmii_data_err_cnt"},
  196. {"rmac_xgmii_ctrl_err_cnt"},
  197. {"rmac_accepted_ip"},
  198. {"rmac_err_tcp"},
  199. {"rd_req_cnt"},
  200. {"new_rd_req_cnt"},
  201. {"new_rd_req_rtry_cnt"},
  202. {"rd_rtry_cnt"},
  203. {"wr_rtry_rd_ack_cnt"},
  204. {"wr_req_cnt"},
  205. {"new_wr_req_cnt"},
  206. {"new_wr_req_rtry_cnt"},
  207. {"wr_rtry_cnt"},
  208. {"wr_disc_cnt"},
  209. {"rd_rtry_wr_ack_cnt"},
  210. {"txp_wr_cnt"},
  211. {"txd_rd_cnt"},
  212. {"txd_wr_cnt"},
  213. {"rxd_rd_cnt"},
  214. {"rxd_wr_cnt"},
  215. {"txf_rd_cnt"},
  216. {"rxf_wr_cnt"}
  217. };
  218. static const char ethtool_enhanced_stats_keys[][ETH_GSTRING_LEN] = {
  219. {"rmac_ttl_1519_4095_frms"},
  220. {"rmac_ttl_4096_8191_frms"},
  221. {"rmac_ttl_8192_max_frms"},
  222. {"rmac_ttl_gt_max_frms"},
  223. {"rmac_osized_alt_frms"},
  224. {"rmac_jabber_alt_frms"},
  225. {"rmac_gt_max_alt_frms"},
  226. {"rmac_vlan_frms"},
  227. {"rmac_len_discard"},
  228. {"rmac_fcs_discard"},
  229. {"rmac_pf_discard"},
  230. {"rmac_da_discard"},
  231. {"rmac_red_discard"},
  232. {"rmac_rts_discard"},
  233. {"rmac_ingm_full_discard"},
  234. {"link_fault_cnt"}
  235. };
  236. static const char ethtool_driver_stats_keys[][ETH_GSTRING_LEN] = {
  237. {"\n DRIVER STATISTICS"},
  238. {"single_bit_ecc_errs"},
  239. {"double_bit_ecc_errs"},
  240. {"parity_err_cnt"},
  241. {"serious_err_cnt"},
  242. {"soft_reset_cnt"},
  243. {"fifo_full_cnt"},
  244. {"ring_0_full_cnt"},
  245. {"ring_1_full_cnt"},
  246. {"ring_2_full_cnt"},
  247. {"ring_3_full_cnt"},
  248. {"ring_4_full_cnt"},
  249. {"ring_5_full_cnt"},
  250. {"ring_6_full_cnt"},
  251. {"ring_7_full_cnt"},
  252. {"alarm_transceiver_temp_high"},
  253. {"alarm_transceiver_temp_low"},
  254. {"alarm_laser_bias_current_high"},
  255. {"alarm_laser_bias_current_low"},
  256. {"alarm_laser_output_power_high"},
  257. {"alarm_laser_output_power_low"},
  258. {"warn_transceiver_temp_high"},
  259. {"warn_transceiver_temp_low"},
  260. {"warn_laser_bias_current_high"},
  261. {"warn_laser_bias_current_low"},
  262. {"warn_laser_output_power_high"},
  263. {"warn_laser_output_power_low"},
  264. {"lro_aggregated_pkts"},
  265. {"lro_flush_both_count"},
  266. {"lro_out_of_sequence_pkts"},
  267. {"lro_flush_due_to_max_pkts"},
  268. {"lro_avg_aggr_pkts"},
  269. {"mem_alloc_fail_cnt"},
  270. {"pci_map_fail_cnt"},
  271. {"watchdog_timer_cnt"},
  272. {"mem_allocated"},
  273. {"mem_freed"},
  274. {"link_up_cnt"},
  275. {"link_down_cnt"},
  276. {"link_up_time"},
  277. {"link_down_time"},
  278. {"tx_tcode_buf_abort_cnt"},
  279. {"tx_tcode_desc_abort_cnt"},
  280. {"tx_tcode_parity_err_cnt"},
  281. {"tx_tcode_link_loss_cnt"},
  282. {"tx_tcode_list_proc_err_cnt"},
  283. {"rx_tcode_parity_err_cnt"},
  284. {"rx_tcode_abort_cnt"},
  285. {"rx_tcode_parity_abort_cnt"},
  286. {"rx_tcode_rda_fail_cnt"},
  287. {"rx_tcode_unkn_prot_cnt"},
  288. {"rx_tcode_fcs_err_cnt"},
  289. {"rx_tcode_buf_size_err_cnt"},
  290. {"rx_tcode_rxd_corrupt_cnt"},
  291. {"rx_tcode_unkn_err_cnt"},
  292. {"tda_err_cnt"},
  293. {"pfc_err_cnt"},
  294. {"pcc_err_cnt"},
  295. {"tti_err_cnt"},
  296. {"tpa_err_cnt"},
  297. {"sm_err_cnt"},
  298. {"lso_err_cnt"},
  299. {"mac_tmac_err_cnt"},
  300. {"mac_rmac_err_cnt"},
  301. {"xgxs_txgxs_err_cnt"},
  302. {"xgxs_rxgxs_err_cnt"},
  303. {"rc_err_cnt"},
  304. {"prc_pcix_err_cnt"},
  305. {"rpa_err_cnt"},
  306. {"rda_err_cnt"},
  307. {"rti_err_cnt"},
  308. {"mc_err_cnt"}
  309. };
  310. #define S2IO_XENA_STAT_LEN ARRAY_SIZE(ethtool_xena_stats_keys)
  311. #define S2IO_ENHANCED_STAT_LEN ARRAY_SIZE(ethtool_enhanced_stats_keys)
  312. #define S2IO_DRIVER_STAT_LEN ARRAY_SIZE(ethtool_driver_stats_keys)
  313. #define XFRAME_I_STAT_LEN (S2IO_XENA_STAT_LEN + S2IO_DRIVER_STAT_LEN)
  314. #define XFRAME_II_STAT_LEN (XFRAME_I_STAT_LEN + S2IO_ENHANCED_STAT_LEN)
  315. #define XFRAME_I_STAT_STRINGS_LEN (XFRAME_I_STAT_LEN * ETH_GSTRING_LEN)
  316. #define XFRAME_II_STAT_STRINGS_LEN (XFRAME_II_STAT_LEN * ETH_GSTRING_LEN)
  317. #define S2IO_TEST_LEN ARRAY_SIZE(s2io_gstrings)
  318. #define S2IO_STRINGS_LEN (S2IO_TEST_LEN * ETH_GSTRING_LEN)
  319. #define S2IO_TIMER_CONF(timer, handle, arg, exp) \
  320. init_timer(&timer); \
  321. timer.function = handle; \
  322. timer.data = (unsigned long)arg; \
  323. mod_timer(&timer, (jiffies + exp)) \
  324. /* copy mac addr to def_mac_addr array */
  325. static void do_s2io_copy_mac_addr(struct s2io_nic *sp, int offset, u64 mac_addr)
  326. {
  327. sp->def_mac_addr[offset].mac_addr[5] = (u8) (mac_addr);
  328. sp->def_mac_addr[offset].mac_addr[4] = (u8) (mac_addr >> 8);
  329. sp->def_mac_addr[offset].mac_addr[3] = (u8) (mac_addr >> 16);
  330. sp->def_mac_addr[offset].mac_addr[2] = (u8) (mac_addr >> 24);
  331. sp->def_mac_addr[offset].mac_addr[1] = (u8) (mac_addr >> 32);
  332. sp->def_mac_addr[offset].mac_addr[0] = (u8) (mac_addr >> 40);
  333. }
  334. /*
  335. * Constants to be programmed into the Xena's registers, to configure
  336. * the XAUI.
  337. */
  338. #define END_SIGN 0x0
  339. static const u64 herc_act_dtx_cfg[] = {
  340. /* Set address */
  341. 0x8000051536750000ULL, 0x80000515367500E0ULL,
  342. /* Write data */
  343. 0x8000051536750004ULL, 0x80000515367500E4ULL,
  344. /* Set address */
  345. 0x80010515003F0000ULL, 0x80010515003F00E0ULL,
  346. /* Write data */
  347. 0x80010515003F0004ULL, 0x80010515003F00E4ULL,
  348. /* Set address */
  349. 0x801205150D440000ULL, 0x801205150D4400E0ULL,
  350. /* Write data */
  351. 0x801205150D440004ULL, 0x801205150D4400E4ULL,
  352. /* Set address */
  353. 0x80020515F2100000ULL, 0x80020515F21000E0ULL,
  354. /* Write data */
  355. 0x80020515F2100004ULL, 0x80020515F21000E4ULL,
  356. /* Done */
  357. END_SIGN
  358. };
  359. static const u64 xena_dtx_cfg[] = {
  360. /* Set address */
  361. 0x8000051500000000ULL, 0x80000515000000E0ULL,
  362. /* Write data */
  363. 0x80000515D9350004ULL, 0x80000515D93500E4ULL,
  364. /* Set address */
  365. 0x8001051500000000ULL, 0x80010515000000E0ULL,
  366. /* Write data */
  367. 0x80010515001E0004ULL, 0x80010515001E00E4ULL,
  368. /* Set address */
  369. 0x8002051500000000ULL, 0x80020515000000E0ULL,
  370. /* Write data */
  371. 0x80020515F2100004ULL, 0x80020515F21000E4ULL,
  372. END_SIGN
  373. };
  374. /*
  375. * Constants for Fixing the MacAddress problem seen mostly on
  376. * Alpha machines.
  377. */
  378. static const u64 fix_mac[] = {
  379. 0x0060000000000000ULL, 0x0060600000000000ULL,
  380. 0x0040600000000000ULL, 0x0000600000000000ULL,
  381. 0x0020600000000000ULL, 0x0060600000000000ULL,
  382. 0x0020600000000000ULL, 0x0060600000000000ULL,
  383. 0x0020600000000000ULL, 0x0060600000000000ULL,
  384. 0x0020600000000000ULL, 0x0060600000000000ULL,
  385. 0x0020600000000000ULL, 0x0060600000000000ULL,
  386. 0x0020600000000000ULL, 0x0060600000000000ULL,
  387. 0x0020600000000000ULL, 0x0060600000000000ULL,
  388. 0x0020600000000000ULL, 0x0060600000000000ULL,
  389. 0x0020600000000000ULL, 0x0060600000000000ULL,
  390. 0x0020600000000000ULL, 0x0060600000000000ULL,
  391. 0x0020600000000000ULL, 0x0000600000000000ULL,
  392. 0x0040600000000000ULL, 0x0060600000000000ULL,
  393. END_SIGN
  394. };
  395. MODULE_LICENSE("GPL");
  396. MODULE_VERSION(DRV_VERSION);
  397. /* Module Loadable parameters. */
  398. S2IO_PARM_INT(tx_fifo_num, FIFO_DEFAULT_NUM);
  399. S2IO_PARM_INT(rx_ring_num, 1);
  400. S2IO_PARM_INT(multiq, 0);
  401. S2IO_PARM_INT(rx_ring_mode, 1);
  402. S2IO_PARM_INT(use_continuous_tx_intrs, 1);
  403. S2IO_PARM_INT(rmac_pause_time, 0x100);
  404. S2IO_PARM_INT(mc_pause_threshold_q0q3, 187);
  405. S2IO_PARM_INT(mc_pause_threshold_q4q7, 187);
  406. S2IO_PARM_INT(shared_splits, 0);
  407. S2IO_PARM_INT(tmac_util_period, 5);
  408. S2IO_PARM_INT(rmac_util_period, 5);
  409. S2IO_PARM_INT(l3l4hdr_size, 128);
  410. /* 0 is no steering, 1 is Priority steering, 2 is Default steering */
  411. S2IO_PARM_INT(tx_steering_type, TX_DEFAULT_STEERING);
  412. /* Frequency of Rx desc syncs expressed as power of 2 */
  413. S2IO_PARM_INT(rxsync_frequency, 3);
  414. /* Interrupt type. Values can be 0(INTA), 2(MSI_X) */
  415. S2IO_PARM_INT(intr_type, 2);
  416. /* Large receive offload feature */
  417. /* Max pkts to be aggregated by LRO at one time. If not specified,
  418. * aggregation happens until we hit max IP pkt size(64K)
  419. */
  420. S2IO_PARM_INT(lro_max_pkts, 0xFFFF);
  421. S2IO_PARM_INT(indicate_max_pkts, 0);
  422. S2IO_PARM_INT(napi, 1);
  423. S2IO_PARM_INT(ufo, 0);
  424. S2IO_PARM_INT(vlan_tag_strip, NO_STRIP_IN_PROMISC);
  425. static unsigned int tx_fifo_len[MAX_TX_FIFOS] =
  426. {DEFAULT_FIFO_0_LEN, [1 ...(MAX_TX_FIFOS - 1)] = DEFAULT_FIFO_1_7_LEN};
  427. static unsigned int rx_ring_sz[MAX_RX_RINGS] =
  428. {[0 ...(MAX_RX_RINGS - 1)] = SMALL_BLK_CNT};
  429. static unsigned int rts_frm_len[MAX_RX_RINGS] =
  430. {[0 ...(MAX_RX_RINGS - 1)] = 0 };
  431. module_param_array(tx_fifo_len, uint, NULL, 0);
  432. module_param_array(rx_ring_sz, uint, NULL, 0);
  433. module_param_array(rts_frm_len, uint, NULL, 0);
  434. /*
  435. * S2IO device table.
  436. * This table lists all the devices that this driver supports.
  437. */
  438. static DEFINE_PCI_DEVICE_TABLE(s2io_tbl) = {
  439. {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_S2IO_WIN,
  440. PCI_ANY_ID, PCI_ANY_ID},
  441. {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_S2IO_UNI,
  442. PCI_ANY_ID, PCI_ANY_ID},
  443. {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_HERC_WIN,
  444. PCI_ANY_ID, PCI_ANY_ID},
  445. {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_HERC_UNI,
  446. PCI_ANY_ID, PCI_ANY_ID},
  447. {0,}
  448. };
  449. MODULE_DEVICE_TABLE(pci, s2io_tbl);
  450. static struct pci_error_handlers s2io_err_handler = {
  451. .error_detected = s2io_io_error_detected,
  452. .slot_reset = s2io_io_slot_reset,
  453. .resume = s2io_io_resume,
  454. };
  455. static struct pci_driver s2io_driver = {
  456. .name = "S2IO",
  457. .id_table = s2io_tbl,
  458. .probe = s2io_init_nic,
  459. .remove = __devexit_p(s2io_rem_nic),
  460. .err_handler = &s2io_err_handler,
  461. };
  462. /* A simplifier macro used both by init and free shared_mem Fns(). */
  463. #define TXD_MEM_PAGE_CNT(len, per_each) ((len+per_each - 1) / per_each)
  464. /* netqueue manipulation helper functions */
  465. static inline void s2io_stop_all_tx_queue(struct s2io_nic *sp)
  466. {
  467. if (!sp->config.multiq) {
  468. int i;
  469. for (i = 0; i < sp->config.tx_fifo_num; i++)
  470. sp->mac_control.fifos[i].queue_state = FIFO_QUEUE_STOP;
  471. }
  472. netif_tx_stop_all_queues(sp->dev);
  473. }
  474. static inline void s2io_stop_tx_queue(struct s2io_nic *sp, int fifo_no)
  475. {
  476. if (!sp->config.multiq)
  477. sp->mac_control.fifos[fifo_no].queue_state =
  478. FIFO_QUEUE_STOP;
  479. netif_tx_stop_all_queues(sp->dev);
  480. }
  481. static inline void s2io_start_all_tx_queue(struct s2io_nic *sp)
  482. {
  483. if (!sp->config.multiq) {
  484. int i;
  485. for (i = 0; i < sp->config.tx_fifo_num; i++)
  486. sp->mac_control.fifos[i].queue_state = FIFO_QUEUE_START;
  487. }
  488. netif_tx_start_all_queues(sp->dev);
  489. }
  490. static inline void s2io_start_tx_queue(struct s2io_nic *sp, int fifo_no)
  491. {
  492. if (!sp->config.multiq)
  493. sp->mac_control.fifos[fifo_no].queue_state =
  494. FIFO_QUEUE_START;
  495. netif_tx_start_all_queues(sp->dev);
  496. }
  497. static inline void s2io_wake_all_tx_queue(struct s2io_nic *sp)
  498. {
  499. if (!sp->config.multiq) {
  500. int i;
  501. for (i = 0; i < sp->config.tx_fifo_num; i++)
  502. sp->mac_control.fifos[i].queue_state = FIFO_QUEUE_START;
  503. }
  504. netif_tx_wake_all_queues(sp->dev);
  505. }
  506. static inline void s2io_wake_tx_queue(
  507. struct fifo_info *fifo, int cnt, u8 multiq)
  508. {
  509. if (multiq) {
  510. if (cnt && __netif_subqueue_stopped(fifo->dev, fifo->fifo_no))
  511. netif_wake_subqueue(fifo->dev, fifo->fifo_no);
  512. } else if (cnt && (fifo->queue_state == FIFO_QUEUE_STOP)) {
  513. if (netif_queue_stopped(fifo->dev)) {
  514. fifo->queue_state = FIFO_QUEUE_START;
  515. netif_wake_queue(fifo->dev);
  516. }
  517. }
  518. }
  519. /**
  520. * init_shared_mem - Allocation and Initialization of Memory
  521. * @nic: Device private variable.
  522. * Description: The function allocates all the memory areas shared
  523. * between the NIC and the driver. This includes Tx descriptors,
  524. * Rx descriptors and the statistics block.
  525. */
  526. static int init_shared_mem(struct s2io_nic *nic)
  527. {
  528. u32 size;
  529. void *tmp_v_addr, *tmp_v_addr_next;
  530. dma_addr_t tmp_p_addr, tmp_p_addr_next;
  531. struct RxD_block *pre_rxd_blk = NULL;
  532. int i, j, blk_cnt;
  533. int lst_size, lst_per_page;
  534. struct net_device *dev = nic->dev;
  535. unsigned long tmp;
  536. struct buffAdd *ba;
  537. struct config_param *config = &nic->config;
  538. struct mac_info *mac_control = &nic->mac_control;
  539. unsigned long long mem_allocated = 0;
  540. /* Allocation and initialization of TXDLs in FIFOs */
  541. size = 0;
  542. for (i = 0; i < config->tx_fifo_num; i++) {
  543. struct tx_fifo_config *tx_cfg = &config->tx_cfg[i];
  544. size += tx_cfg->fifo_len;
  545. }
  546. if (size > MAX_AVAILABLE_TXDS) {
  547. DBG_PRINT(ERR_DBG,
  548. "Too many TxDs requested: %d, max supported: %d\n",
  549. size, MAX_AVAILABLE_TXDS);
  550. return -EINVAL;
  551. }
  552. size = 0;
  553. for (i = 0; i < config->tx_fifo_num; i++) {
  554. struct tx_fifo_config *tx_cfg = &config->tx_cfg[i];
  555. size = tx_cfg->fifo_len;
  556. /*
  557. * Legal values are from 2 to 8192
  558. */
  559. if (size < 2) {
  560. DBG_PRINT(ERR_DBG, "Fifo %d: Invalid length (%d) - "
  561. "Valid lengths are 2 through 8192\n",
  562. i, size);
  563. return -EINVAL;
  564. }
  565. }
  566. lst_size = (sizeof(struct TxD) * config->max_txds);
  567. lst_per_page = PAGE_SIZE / lst_size;
  568. for (i = 0; i < config->tx_fifo_num; i++) {
  569. struct fifo_info *fifo = &mac_control->fifos[i];
  570. struct tx_fifo_config *tx_cfg = &config->tx_cfg[i];
  571. int fifo_len = tx_cfg->fifo_len;
  572. int list_holder_size = fifo_len * sizeof(struct list_info_hold);
  573. fifo->list_info = kzalloc(list_holder_size, GFP_KERNEL);
  574. if (!fifo->list_info) {
  575. DBG_PRINT(INFO_DBG, "Malloc failed for list_info\n");
  576. return -ENOMEM;
  577. }
  578. mem_allocated += list_holder_size;
  579. }
  580. for (i = 0; i < config->tx_fifo_num; i++) {
  581. int page_num = TXD_MEM_PAGE_CNT(config->tx_cfg[i].fifo_len,
  582. lst_per_page);
  583. struct fifo_info *fifo = &mac_control->fifos[i];
  584. struct tx_fifo_config *tx_cfg = &config->tx_cfg[i];
  585. fifo->tx_curr_put_info.offset = 0;
  586. fifo->tx_curr_put_info.fifo_len = tx_cfg->fifo_len - 1;
  587. fifo->tx_curr_get_info.offset = 0;
  588. fifo->tx_curr_get_info.fifo_len = tx_cfg->fifo_len - 1;
  589. fifo->fifo_no = i;
  590. fifo->nic = nic;
  591. fifo->max_txds = MAX_SKB_FRAGS + 2;
  592. fifo->dev = dev;
  593. for (j = 0; j < page_num; j++) {
  594. int k = 0;
  595. dma_addr_t tmp_p;
  596. void *tmp_v;
  597. tmp_v = pci_alloc_consistent(nic->pdev,
  598. PAGE_SIZE, &tmp_p);
  599. if (!tmp_v) {
  600. DBG_PRINT(INFO_DBG,
  601. "pci_alloc_consistent failed for TxDL\n");
  602. return -ENOMEM;
  603. }
  604. /* If we got a zero DMA address(can happen on
  605. * certain platforms like PPC), reallocate.
  606. * Store virtual address of page we don't want,
  607. * to be freed later.
  608. */
  609. if (!tmp_p) {
  610. mac_control->zerodma_virt_addr = tmp_v;
  611. DBG_PRINT(INIT_DBG,
  612. "%s: Zero DMA address for TxDL. "
  613. "Virtual address %p\n",
  614. dev->name, tmp_v);
  615. tmp_v = pci_alloc_consistent(nic->pdev,
  616. PAGE_SIZE, &tmp_p);
  617. if (!tmp_v) {
  618. DBG_PRINT(INFO_DBG,
  619. "pci_alloc_consistent failed for TxDL\n");
  620. return -ENOMEM;
  621. }
  622. mem_allocated += PAGE_SIZE;
  623. }
  624. while (k < lst_per_page) {
  625. int l = (j * lst_per_page) + k;
  626. if (l == tx_cfg->fifo_len)
  627. break;
  628. fifo->list_info[l].list_virt_addr =
  629. tmp_v + (k * lst_size);
  630. fifo->list_info[l].list_phy_addr =
  631. tmp_p + (k * lst_size);
  632. k++;
  633. }
  634. }
  635. }
  636. for (i = 0; i < config->tx_fifo_num; i++) {
  637. struct fifo_info *fifo = &mac_control->fifos[i];
  638. struct tx_fifo_config *tx_cfg = &config->tx_cfg[i];
  639. size = tx_cfg->fifo_len;
  640. fifo->ufo_in_band_v = kcalloc(size, sizeof(u64), GFP_KERNEL);
  641. if (!fifo->ufo_in_band_v)
  642. return -ENOMEM;
  643. mem_allocated += (size * sizeof(u64));
  644. }
  645. /* Allocation and initialization of RXDs in Rings */
  646. size = 0;
  647. for (i = 0; i < config->rx_ring_num; i++) {
  648. struct rx_ring_config *rx_cfg = &config->rx_cfg[i];
  649. struct ring_info *ring = &mac_control->rings[i];
  650. if (rx_cfg->num_rxd % (rxd_count[nic->rxd_mode] + 1)) {
  651. DBG_PRINT(ERR_DBG, "%s: Ring%d RxD count is not a "
  652. "multiple of RxDs per Block\n",
  653. dev->name, i);
  654. return FAILURE;
  655. }
  656. size += rx_cfg->num_rxd;
  657. ring->block_count = rx_cfg->num_rxd /
  658. (rxd_count[nic->rxd_mode] + 1);
  659. ring->pkt_cnt = rx_cfg->num_rxd - ring->block_count;
  660. }
  661. if (nic->rxd_mode == RXD_MODE_1)
  662. size = (size * (sizeof(struct RxD1)));
  663. else
  664. size = (size * (sizeof(struct RxD3)));
  665. for (i = 0; i < config->rx_ring_num; i++) {
  666. struct rx_ring_config *rx_cfg = &config->rx_cfg[i];
  667. struct ring_info *ring = &mac_control->rings[i];
  668. ring->rx_curr_get_info.block_index = 0;
  669. ring->rx_curr_get_info.offset = 0;
  670. ring->rx_curr_get_info.ring_len = rx_cfg->num_rxd - 1;
  671. ring->rx_curr_put_info.block_index = 0;
  672. ring->rx_curr_put_info.offset = 0;
  673. ring->rx_curr_put_info.ring_len = rx_cfg->num_rxd - 1;
  674. ring->nic = nic;
  675. ring->ring_no = i;
  676. blk_cnt = rx_cfg->num_rxd / (rxd_count[nic->rxd_mode] + 1);
  677. /* Allocating all the Rx blocks */
  678. for (j = 0; j < blk_cnt; j++) {
  679. struct rx_block_info *rx_blocks;
  680. int l;
  681. rx_blocks = &ring->rx_blocks[j];
  682. size = SIZE_OF_BLOCK; /* size is always page size */
  683. tmp_v_addr = pci_alloc_consistent(nic->pdev, size,
  684. &tmp_p_addr);
  685. if (tmp_v_addr == NULL) {
  686. /*
  687. * In case of failure, free_shared_mem()
  688. * is called, which should free any
  689. * memory that was alloced till the
  690. * failure happened.
  691. */
  692. rx_blocks->block_virt_addr = tmp_v_addr;
  693. return -ENOMEM;
  694. }
  695. mem_allocated += size;
  696. memset(tmp_v_addr, 0, size);
  697. size = sizeof(struct rxd_info) *
  698. rxd_count[nic->rxd_mode];
  699. rx_blocks->block_virt_addr = tmp_v_addr;
  700. rx_blocks->block_dma_addr = tmp_p_addr;
  701. rx_blocks->rxds = kmalloc(size, GFP_KERNEL);
  702. if (!rx_blocks->rxds)
  703. return -ENOMEM;
  704. mem_allocated += size;
  705. for (l = 0; l < rxd_count[nic->rxd_mode]; l++) {
  706. rx_blocks->rxds[l].virt_addr =
  707. rx_blocks->block_virt_addr +
  708. (rxd_size[nic->rxd_mode] * l);
  709. rx_blocks->rxds[l].dma_addr =
  710. rx_blocks->block_dma_addr +
  711. (rxd_size[nic->rxd_mode] * l);
  712. }
  713. }
  714. /* Interlinking all Rx Blocks */
  715. for (j = 0; j < blk_cnt; j++) {
  716. int next = (j + 1) % blk_cnt;
  717. tmp_v_addr = ring->rx_blocks[j].block_virt_addr;
  718. tmp_v_addr_next = ring->rx_blocks[next].block_virt_addr;
  719. tmp_p_addr = ring->rx_blocks[j].block_dma_addr;
  720. tmp_p_addr_next = ring->rx_blocks[next].block_dma_addr;
  721. pre_rxd_blk = tmp_v_addr;
  722. pre_rxd_blk->reserved_2_pNext_RxD_block =
  723. (unsigned long)tmp_v_addr_next;
  724. pre_rxd_blk->pNext_RxD_Blk_physical =
  725. (u64)tmp_p_addr_next;
  726. }
  727. }
  728. if (nic->rxd_mode == RXD_MODE_3B) {
  729. /*
  730. * Allocation of Storages for buffer addresses in 2BUFF mode
  731. * and the buffers as well.
  732. */
  733. for (i = 0; i < config->rx_ring_num; i++) {
  734. struct rx_ring_config *rx_cfg = &config->rx_cfg[i];
  735. struct ring_info *ring = &mac_control->rings[i];
  736. blk_cnt = rx_cfg->num_rxd /
  737. (rxd_count[nic->rxd_mode] + 1);
  738. size = sizeof(struct buffAdd *) * blk_cnt;
  739. ring->ba = kmalloc(size, GFP_KERNEL);
  740. if (!ring->ba)
  741. return -ENOMEM;
  742. mem_allocated += size;
  743. for (j = 0; j < blk_cnt; j++) {
  744. int k = 0;
  745. size = sizeof(struct buffAdd) *
  746. (rxd_count[nic->rxd_mode] + 1);
  747. ring->ba[j] = kmalloc(size, GFP_KERNEL);
  748. if (!ring->ba[j])
  749. return -ENOMEM;
  750. mem_allocated += size;
  751. while (k != rxd_count[nic->rxd_mode]) {
  752. ba = &ring->ba[j][k];
  753. size = BUF0_LEN + ALIGN_SIZE;
  754. ba->ba_0_org = kmalloc(size, GFP_KERNEL);
  755. if (!ba->ba_0_org)
  756. return -ENOMEM;
  757. mem_allocated += size;
  758. tmp = (unsigned long)ba->ba_0_org;
  759. tmp += ALIGN_SIZE;
  760. tmp &= ~((unsigned long)ALIGN_SIZE);
  761. ba->ba_0 = (void *)tmp;
  762. size = BUF1_LEN + ALIGN_SIZE;
  763. ba->ba_1_org = kmalloc(size, GFP_KERNEL);
  764. if (!ba->ba_1_org)
  765. return -ENOMEM;
  766. mem_allocated += size;
  767. tmp = (unsigned long)ba->ba_1_org;
  768. tmp += ALIGN_SIZE;
  769. tmp &= ~((unsigned long)ALIGN_SIZE);
  770. ba->ba_1 = (void *)tmp;
  771. k++;
  772. }
  773. }
  774. }
  775. }
  776. /* Allocation and initialization of Statistics block */
  777. size = sizeof(struct stat_block);
  778. mac_control->stats_mem =
  779. pci_alloc_consistent(nic->pdev, size,
  780. &mac_control->stats_mem_phy);
  781. if (!mac_control->stats_mem) {
  782. /*
  783. * In case of failure, free_shared_mem() is called, which
  784. * should free any memory that was alloced till the
  785. * failure happened.
  786. */
  787. return -ENOMEM;
  788. }
  789. mem_allocated += size;
  790. mac_control->stats_mem_sz = size;
  791. tmp_v_addr = mac_control->stats_mem;
  792. mac_control->stats_info = tmp_v_addr;
  793. memset(tmp_v_addr, 0, size);
  794. DBG_PRINT(INIT_DBG, "%s: Ring Mem PHY: 0x%llx\n",
  795. dev_name(&nic->pdev->dev), (unsigned long long)tmp_p_addr);
  796. mac_control->stats_info->sw_stat.mem_allocated += mem_allocated;
  797. return SUCCESS;
  798. }
  799. /**
  800. * free_shared_mem - Free the allocated Memory
  801. * @nic: Device private variable.
  802. * Description: This function is to free all memory locations allocated by
  803. * the init_shared_mem() function and return it to the kernel.
  804. */
  805. static void free_shared_mem(struct s2io_nic *nic)
  806. {
  807. int i, j, blk_cnt, size;
  808. void *tmp_v_addr;
  809. dma_addr_t tmp_p_addr;
  810. int lst_size, lst_per_page;
  811. struct net_device *dev;
  812. int page_num = 0;
  813. struct config_param *config;
  814. struct mac_info *mac_control;
  815. struct stat_block *stats;
  816. struct swStat *swstats;
  817. if (!nic)
  818. return;
  819. dev = nic->dev;
  820. config = &nic->config;
  821. mac_control = &nic->mac_control;
  822. stats = mac_control->stats_info;
  823. swstats = &stats->sw_stat;
  824. lst_size = sizeof(struct TxD) * config->max_txds;
  825. lst_per_page = PAGE_SIZE / lst_size;
  826. for (i = 0; i < config->tx_fifo_num; i++) {
  827. struct fifo_info *fifo = &mac_control->fifos[i];
  828. struct tx_fifo_config *tx_cfg = &config->tx_cfg[i];
  829. page_num = TXD_MEM_PAGE_CNT(tx_cfg->fifo_len, lst_per_page);
  830. for (j = 0; j < page_num; j++) {
  831. int mem_blks = (j * lst_per_page);
  832. struct list_info_hold *fli;
  833. if (!fifo->list_info)
  834. return;
  835. fli = &fifo->list_info[mem_blks];
  836. if (!fli->list_virt_addr)
  837. break;
  838. pci_free_consistent(nic->pdev, PAGE_SIZE,
  839. fli->list_virt_addr,
  840. fli->list_phy_addr);
  841. swstats->mem_freed += PAGE_SIZE;
  842. }
  843. /* If we got a zero DMA address during allocation,
  844. * free the page now
  845. */
  846. if (mac_control->zerodma_virt_addr) {
  847. pci_free_consistent(nic->pdev, PAGE_SIZE,
  848. mac_control->zerodma_virt_addr,
  849. (dma_addr_t)0);
  850. DBG_PRINT(INIT_DBG,
  851. "%s: Freeing TxDL with zero DMA address. "
  852. "Virtual address %p\n",
  853. dev->name, mac_control->zerodma_virt_addr);
  854. swstats->mem_freed += PAGE_SIZE;
  855. }
  856. kfree(fifo->list_info);
  857. swstats->mem_freed += tx_cfg->fifo_len *
  858. sizeof(struct list_info_hold);
  859. }
  860. size = SIZE_OF_BLOCK;
  861. for (i = 0; i < config->rx_ring_num; i++) {
  862. struct ring_info *ring = &mac_control->rings[i];
  863. blk_cnt = ring->block_count;
  864. for (j = 0; j < blk_cnt; j++) {
  865. tmp_v_addr = ring->rx_blocks[j].block_virt_addr;
  866. tmp_p_addr = ring->rx_blocks[j].block_dma_addr;
  867. if (tmp_v_addr == NULL)
  868. break;
  869. pci_free_consistent(nic->pdev, size,
  870. tmp_v_addr, tmp_p_addr);
  871. swstats->mem_freed += size;
  872. kfree(ring->rx_blocks[j].rxds);
  873. swstats->mem_freed += sizeof(struct rxd_info) *
  874. rxd_count[nic->rxd_mode];
  875. }
  876. }
  877. if (nic->rxd_mode == RXD_MODE_3B) {
  878. /* Freeing buffer storage addresses in 2BUFF mode. */
  879. for (i = 0; i < config->rx_ring_num; i++) {
  880. struct rx_ring_config *rx_cfg = &config->rx_cfg[i];
  881. struct ring_info *ring = &mac_control->rings[i];
  882. blk_cnt = rx_cfg->num_rxd /
  883. (rxd_count[nic->rxd_mode] + 1);
  884. for (j = 0; j < blk_cnt; j++) {
  885. int k = 0;
  886. if (!ring->ba[j])
  887. continue;
  888. while (k != rxd_count[nic->rxd_mode]) {
  889. struct buffAdd *ba = &ring->ba[j][k];
  890. kfree(ba->ba_0_org);
  891. swstats->mem_freed +=
  892. BUF0_LEN + ALIGN_SIZE;
  893. kfree(ba->ba_1_org);
  894. swstats->mem_freed +=
  895. BUF1_LEN + ALIGN_SIZE;
  896. k++;
  897. }
  898. kfree(ring->ba[j]);
  899. swstats->mem_freed += sizeof(struct buffAdd) *
  900. (rxd_count[nic->rxd_mode] + 1);
  901. }
  902. kfree(ring->ba);
  903. swstats->mem_freed += sizeof(struct buffAdd *) *
  904. blk_cnt;
  905. }
  906. }
  907. for (i = 0; i < nic->config.tx_fifo_num; i++) {
  908. struct fifo_info *fifo = &mac_control->fifos[i];
  909. struct tx_fifo_config *tx_cfg = &config->tx_cfg[i];
  910. if (fifo->ufo_in_band_v) {
  911. swstats->mem_freed += tx_cfg->fifo_len *
  912. sizeof(u64);
  913. kfree(fifo->ufo_in_band_v);
  914. }
  915. }
  916. if (mac_control->stats_mem) {
  917. swstats->mem_freed += mac_control->stats_mem_sz;
  918. pci_free_consistent(nic->pdev,
  919. mac_control->stats_mem_sz,
  920. mac_control->stats_mem,
  921. mac_control->stats_mem_phy);
  922. }
  923. }
  924. /**
  925. * s2io_verify_pci_mode -
  926. */
  927. static int s2io_verify_pci_mode(struct s2io_nic *nic)
  928. {
  929. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  930. register u64 val64 = 0;
  931. int mode;
  932. val64 = readq(&bar0->pci_mode);
  933. mode = (u8)GET_PCI_MODE(val64);
  934. if (val64 & PCI_MODE_UNKNOWN_MODE)
  935. return -1; /* Unknown PCI mode */
  936. return mode;
  937. }
  938. #define NEC_VENID 0x1033
  939. #define NEC_DEVID 0x0125
  940. static int s2io_on_nec_bridge(struct pci_dev *s2io_pdev)
  941. {
  942. struct pci_dev *tdev = NULL;
  943. while ((tdev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, tdev)) != NULL) {
  944. if (tdev->vendor == NEC_VENID && tdev->device == NEC_DEVID) {
  945. if (tdev->bus == s2io_pdev->bus->parent) {
  946. pci_dev_put(tdev);
  947. return 1;
  948. }
  949. }
  950. }
  951. return 0;
  952. }
  953. static int bus_speed[8] = {33, 133, 133, 200, 266, 133, 200, 266};
  954. /**
  955. * s2io_print_pci_mode -
  956. */
  957. static int s2io_print_pci_mode(struct s2io_nic *nic)
  958. {
  959. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  960. register u64 val64 = 0;
  961. int mode;
  962. struct config_param *config = &nic->config;
  963. const char *pcimode;
  964. val64 = readq(&bar0->pci_mode);
  965. mode = (u8)GET_PCI_MODE(val64);
  966. if (val64 & PCI_MODE_UNKNOWN_MODE)
  967. return -1; /* Unknown PCI mode */
  968. config->bus_speed = bus_speed[mode];
  969. if (s2io_on_nec_bridge(nic->pdev)) {
  970. DBG_PRINT(ERR_DBG, "%s: Device is on PCI-E bus\n",
  971. nic->dev->name);
  972. return mode;
  973. }
  974. switch (mode) {
  975. case PCI_MODE_PCI_33:
  976. pcimode = "33MHz PCI bus";
  977. break;
  978. case PCI_MODE_PCI_66:
  979. pcimode = "66MHz PCI bus";
  980. break;
  981. case PCI_MODE_PCIX_M1_66:
  982. pcimode = "66MHz PCIX(M1) bus";
  983. break;
  984. case PCI_MODE_PCIX_M1_100:
  985. pcimode = "100MHz PCIX(M1) bus";
  986. break;
  987. case PCI_MODE_PCIX_M1_133:
  988. pcimode = "133MHz PCIX(M1) bus";
  989. break;
  990. case PCI_MODE_PCIX_M2_66:
  991. pcimode = "133MHz PCIX(M2) bus";
  992. break;
  993. case PCI_MODE_PCIX_M2_100:
  994. pcimode = "200MHz PCIX(M2) bus";
  995. break;
  996. case PCI_MODE_PCIX_M2_133:
  997. pcimode = "266MHz PCIX(M2) bus";
  998. break;
  999. default:
  1000. pcimode = "unsupported bus!";
  1001. mode = -1;
  1002. }
  1003. DBG_PRINT(ERR_DBG, "%s: Device is on %d bit %s\n",
  1004. nic->dev->name, val64 & PCI_MODE_32_BITS ? 32 : 64, pcimode);
  1005. return mode;
  1006. }
  1007. /**
  1008. * init_tti - Initialization transmit traffic interrupt scheme
  1009. * @nic: device private variable
  1010. * @link: link status (UP/DOWN) used to enable/disable continuous
  1011. * transmit interrupts
  1012. * Description: The function configures transmit traffic interrupts
  1013. * Return Value: SUCCESS on success and
  1014. * '-1' on failure
  1015. */
  1016. static int init_tti(struct s2io_nic *nic, int link)
  1017. {
  1018. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  1019. register u64 val64 = 0;
  1020. int i;
  1021. struct config_param *config = &nic->config;
  1022. for (i = 0; i < config->tx_fifo_num; i++) {
  1023. /*
  1024. * TTI Initialization. Default Tx timer gets us about
  1025. * 250 interrupts per sec. Continuous interrupts are enabled
  1026. * by default.
  1027. */
  1028. if (nic->device_type == XFRAME_II_DEVICE) {
  1029. int count = (nic->config.bus_speed * 125)/2;
  1030. val64 = TTI_DATA1_MEM_TX_TIMER_VAL(count);
  1031. } else
  1032. val64 = TTI_DATA1_MEM_TX_TIMER_VAL(0x2078);
  1033. val64 |= TTI_DATA1_MEM_TX_URNG_A(0xA) |
  1034. TTI_DATA1_MEM_TX_URNG_B(0x10) |
  1035. TTI_DATA1_MEM_TX_URNG_C(0x30) |
  1036. TTI_DATA1_MEM_TX_TIMER_AC_EN;
  1037. if (i == 0)
  1038. if (use_continuous_tx_intrs && (link == LINK_UP))
  1039. val64 |= TTI_DATA1_MEM_TX_TIMER_CI_EN;
  1040. writeq(val64, &bar0->tti_data1_mem);
  1041. if (nic->config.intr_type == MSI_X) {
  1042. val64 = TTI_DATA2_MEM_TX_UFC_A(0x10) |
  1043. TTI_DATA2_MEM_TX_UFC_B(0x100) |
  1044. TTI_DATA2_MEM_TX_UFC_C(0x200) |
  1045. TTI_DATA2_MEM_TX_UFC_D(0x300);
  1046. } else {
  1047. if ((nic->config.tx_steering_type ==
  1048. TX_DEFAULT_STEERING) &&
  1049. (config->tx_fifo_num > 1) &&
  1050. (i >= nic->udp_fifo_idx) &&
  1051. (i < (nic->udp_fifo_idx +
  1052. nic->total_udp_fifos)))
  1053. val64 = TTI_DATA2_MEM_TX_UFC_A(0x50) |
  1054. TTI_DATA2_MEM_TX_UFC_B(0x80) |
  1055. TTI_DATA2_MEM_TX_UFC_C(0x100) |
  1056. TTI_DATA2_MEM_TX_UFC_D(0x120);
  1057. else
  1058. val64 = TTI_DATA2_MEM_TX_UFC_A(0x10) |
  1059. TTI_DATA2_MEM_TX_UFC_B(0x20) |
  1060. TTI_DATA2_MEM_TX_UFC_C(0x40) |
  1061. TTI_DATA2_MEM_TX_UFC_D(0x80);
  1062. }
  1063. writeq(val64, &bar0->tti_data2_mem);
  1064. val64 = TTI_CMD_MEM_WE |
  1065. TTI_CMD_MEM_STROBE_NEW_CMD |
  1066. TTI_CMD_MEM_OFFSET(i);
  1067. writeq(val64, &bar0->tti_command_mem);
  1068. if (wait_for_cmd_complete(&bar0->tti_command_mem,
  1069. TTI_CMD_MEM_STROBE_NEW_CMD,
  1070. S2IO_BIT_RESET) != SUCCESS)
  1071. return FAILURE;
  1072. }
  1073. return SUCCESS;
  1074. }
  1075. /**
  1076. * init_nic - Initialization of hardware
  1077. * @nic: device private variable
  1078. * Description: The function sequentially configures every block
  1079. * of the H/W from their reset values.
  1080. * Return Value: SUCCESS on success and
  1081. * '-1' on failure (endian settings incorrect).
  1082. */
  1083. static int init_nic(struct s2io_nic *nic)
  1084. {
  1085. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  1086. struct net_device *dev = nic->dev;
  1087. register u64 val64 = 0;
  1088. void __iomem *add;
  1089. u32 time;
  1090. int i, j;
  1091. int dtx_cnt = 0;
  1092. unsigned long long mem_share;
  1093. int mem_size;
  1094. struct config_param *config = &nic->config;
  1095. struct mac_info *mac_control = &nic->mac_control;
  1096. /* to set the swapper controle on the card */
  1097. if (s2io_set_swapper(nic)) {
  1098. DBG_PRINT(ERR_DBG, "ERROR: Setting Swapper failed\n");
  1099. return -EIO;
  1100. }
  1101. /*
  1102. * Herc requires EOI to be removed from reset before XGXS, so..
  1103. */
  1104. if (nic->device_type & XFRAME_II_DEVICE) {
  1105. val64 = 0xA500000000ULL;
  1106. writeq(val64, &bar0->sw_reset);
  1107. msleep(500);
  1108. val64 = readq(&bar0->sw_reset);
  1109. }
  1110. /* Remove XGXS from reset state */
  1111. val64 = 0;
  1112. writeq(val64, &bar0->sw_reset);
  1113. msleep(500);
  1114. val64 = readq(&bar0->sw_reset);
  1115. /* Ensure that it's safe to access registers by checking
  1116. * RIC_RUNNING bit is reset. Check is valid only for XframeII.
  1117. */
  1118. if (nic->device_type == XFRAME_II_DEVICE) {
  1119. for (i = 0; i < 50; i++) {
  1120. val64 = readq(&bar0->adapter_status);
  1121. if (!(val64 & ADAPTER_STATUS_RIC_RUNNING))
  1122. break;
  1123. msleep(10);
  1124. }
  1125. if (i == 50)
  1126. return -ENODEV;
  1127. }
  1128. /* Enable Receiving broadcasts */
  1129. add = &bar0->mac_cfg;
  1130. val64 = readq(&bar0->mac_cfg);
  1131. val64 |= MAC_RMAC_BCAST_ENABLE;
  1132. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  1133. writel((u32)val64, add);
  1134. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  1135. writel((u32) (val64 >> 32), (add + 4));
  1136. /* Read registers in all blocks */
  1137. val64 = readq(&bar0->mac_int_mask);
  1138. val64 = readq(&bar0->mc_int_mask);
  1139. val64 = readq(&bar0->xgxs_int_mask);
  1140. /* Set MTU */
  1141. val64 = dev->mtu;
  1142. writeq(vBIT(val64, 2, 14), &bar0->rmac_max_pyld_len);
  1143. if (nic->device_type & XFRAME_II_DEVICE) {
  1144. while (herc_act_dtx_cfg[dtx_cnt] != END_SIGN) {
  1145. SPECIAL_REG_WRITE(herc_act_dtx_cfg[dtx_cnt],
  1146. &bar0->dtx_control, UF);
  1147. if (dtx_cnt & 0x1)
  1148. msleep(1); /* Necessary!! */
  1149. dtx_cnt++;
  1150. }
  1151. } else {
  1152. while (xena_dtx_cfg[dtx_cnt] != END_SIGN) {
  1153. SPECIAL_REG_WRITE(xena_dtx_cfg[dtx_cnt],
  1154. &bar0->dtx_control, UF);
  1155. val64 = readq(&bar0->dtx_control);
  1156. dtx_cnt++;
  1157. }
  1158. }
  1159. /* Tx DMA Initialization */
  1160. val64 = 0;
  1161. writeq(val64, &bar0->tx_fifo_partition_0);
  1162. writeq(val64, &bar0->tx_fifo_partition_1);
  1163. writeq(val64, &bar0->tx_fifo_partition_2);
  1164. writeq(val64, &bar0->tx_fifo_partition_3);
  1165. for (i = 0, j = 0; i < config->tx_fifo_num; i++) {
  1166. struct tx_fifo_config *tx_cfg = &config->tx_cfg[i];
  1167. val64 |= vBIT(tx_cfg->fifo_len - 1, ((j * 32) + 19), 13) |
  1168. vBIT(tx_cfg->fifo_priority, ((j * 32) + 5), 3);
  1169. if (i == (config->tx_fifo_num - 1)) {
  1170. if (i % 2 == 0)
  1171. i++;
  1172. }
  1173. switch (i) {
  1174. case 1:
  1175. writeq(val64, &bar0->tx_fifo_partition_0);
  1176. val64 = 0;
  1177. j = 0;
  1178. break;
  1179. case 3:
  1180. writeq(val64, &bar0->tx_fifo_partition_1);
  1181. val64 = 0;
  1182. j = 0;
  1183. break;
  1184. case 5:
  1185. writeq(val64, &bar0->tx_fifo_partition_2);
  1186. val64 = 0;
  1187. j = 0;
  1188. break;
  1189. case 7:
  1190. writeq(val64, &bar0->tx_fifo_partition_3);
  1191. val64 = 0;
  1192. j = 0;
  1193. break;
  1194. default:
  1195. j++;
  1196. break;
  1197. }
  1198. }
  1199. /*
  1200. * Disable 4 PCCs for Xena1, 2 and 3 as per H/W bug
  1201. * SXE-008 TRANSMIT DMA ARBITRATION ISSUE.
  1202. */
  1203. if ((nic->device_type == XFRAME_I_DEVICE) && (nic->pdev->revision < 4))
  1204. writeq(PCC_ENABLE_FOUR, &bar0->pcc_enable);
  1205. val64 = readq(&bar0->tx_fifo_partition_0);
  1206. DBG_PRINT(INIT_DBG, "Fifo partition at: 0x%p is: 0x%llx\n",
  1207. &bar0->tx_fifo_partition_0, (unsigned long long)val64);
  1208. /*
  1209. * Initialization of Tx_PA_CONFIG register to ignore packet
  1210. * integrity checking.
  1211. */
  1212. val64 = readq(&bar0->tx_pa_cfg);
  1213. val64 |= TX_PA_CFG_IGNORE_FRM_ERR |
  1214. TX_PA_CFG_IGNORE_SNAP_OUI |
  1215. TX_PA_CFG_IGNORE_LLC_CTRL |
  1216. TX_PA_CFG_IGNORE_L2_ERR;
  1217. writeq(val64, &bar0->tx_pa_cfg);
  1218. /* Rx DMA intialization. */
  1219. val64 = 0;
  1220. for (i = 0; i < config->rx_ring_num; i++) {
  1221. struct rx_ring_config *rx_cfg = &config->rx_cfg[i];
  1222. val64 |= vBIT(rx_cfg->ring_priority, (5 + (i * 8)), 3);
  1223. }
  1224. writeq(val64, &bar0->rx_queue_priority);
  1225. /*
  1226. * Allocating equal share of memory to all the
  1227. * configured Rings.
  1228. */
  1229. val64 = 0;
  1230. if (nic->device_type & XFRAME_II_DEVICE)
  1231. mem_size = 32;
  1232. else
  1233. mem_size = 64;
  1234. for (i = 0; i < config->rx_ring_num; i++) {
  1235. switch (i) {
  1236. case 0:
  1237. mem_share = (mem_size / config->rx_ring_num +
  1238. mem_size % config->rx_ring_num);
  1239. val64 |= RX_QUEUE_CFG_Q0_SZ(mem_share);
  1240. continue;
  1241. case 1:
  1242. mem_share = (mem_size / config->rx_ring_num);
  1243. val64 |= RX_QUEUE_CFG_Q1_SZ(mem_share);
  1244. continue;
  1245. case 2:
  1246. mem_share = (mem_size / config->rx_ring_num);
  1247. val64 |= RX_QUEUE_CFG_Q2_SZ(mem_share);
  1248. continue;
  1249. case 3:
  1250. mem_share = (mem_size / config->rx_ring_num);
  1251. val64 |= RX_QUEUE_CFG_Q3_SZ(mem_share);
  1252. continue;
  1253. case 4:
  1254. mem_share = (mem_size / config->rx_ring_num);
  1255. val64 |= RX_QUEUE_CFG_Q4_SZ(mem_share);
  1256. continue;
  1257. case 5:
  1258. mem_share = (mem_size / config->rx_ring_num);
  1259. val64 |= RX_QUEUE_CFG_Q5_SZ(mem_share);
  1260. continue;
  1261. case 6:
  1262. mem_share = (mem_size / config->rx_ring_num);
  1263. val64 |= RX_QUEUE_CFG_Q6_SZ(mem_share);
  1264. continue;
  1265. case 7:
  1266. mem_share = (mem_size / config->rx_ring_num);
  1267. val64 |= RX_QUEUE_CFG_Q7_SZ(mem_share);
  1268. continue;
  1269. }
  1270. }
  1271. writeq(val64, &bar0->rx_queue_cfg);
  1272. /*
  1273. * Filling Tx round robin registers
  1274. * as per the number of FIFOs for equal scheduling priority
  1275. */
  1276. switch (config->tx_fifo_num) {
  1277. case 1:
  1278. val64 = 0x0;
  1279. writeq(val64, &bar0->tx_w_round_robin_0);
  1280. writeq(val64, &bar0->tx_w_round_robin_1);
  1281. writeq(val64, &bar0->tx_w_round_robin_2);
  1282. writeq(val64, &bar0->tx_w_round_robin_3);
  1283. writeq(val64, &bar0->tx_w_round_robin_4);
  1284. break;
  1285. case 2:
  1286. val64 = 0x0001000100010001ULL;
  1287. writeq(val64, &bar0->tx_w_round_robin_0);
  1288. writeq(val64, &bar0->tx_w_round_robin_1);
  1289. writeq(val64, &bar0->tx_w_round_robin_2);
  1290. writeq(val64, &bar0->tx_w_round_robin_3);
  1291. val64 = 0x0001000100000000ULL;
  1292. writeq(val64, &bar0->tx_w_round_robin_4);
  1293. break;
  1294. case 3:
  1295. val64 = 0x0001020001020001ULL;
  1296. writeq(val64, &bar0->tx_w_round_robin_0);
  1297. val64 = 0x0200010200010200ULL;
  1298. writeq(val64, &bar0->tx_w_round_robin_1);
  1299. val64 = 0x0102000102000102ULL;
  1300. writeq(val64, &bar0->tx_w_round_robin_2);
  1301. val64 = 0x0001020001020001ULL;
  1302. writeq(val64, &bar0->tx_w_round_robin_3);
  1303. val64 = 0x0200010200000000ULL;
  1304. writeq(val64, &bar0->tx_w_round_robin_4);
  1305. break;
  1306. case 4:
  1307. val64 = 0x0001020300010203ULL;
  1308. writeq(val64, &bar0->tx_w_round_robin_0);
  1309. writeq(val64, &bar0->tx_w_round_robin_1);
  1310. writeq(val64, &bar0->tx_w_round_robin_2);
  1311. writeq(val64, &bar0->tx_w_round_robin_3);
  1312. val64 = 0x0001020300000000ULL;
  1313. writeq(val64, &bar0->tx_w_round_robin_4);
  1314. break;
  1315. case 5:
  1316. val64 = 0x0001020304000102ULL;
  1317. writeq(val64, &bar0->tx_w_round_robin_0);
  1318. val64 = 0x0304000102030400ULL;
  1319. writeq(val64, &bar0->tx_w_round_robin_1);
  1320. val64 = 0x0102030400010203ULL;
  1321. writeq(val64, &bar0->tx_w_round_robin_2);
  1322. val64 = 0x0400010203040001ULL;
  1323. writeq(val64, &bar0->tx_w_round_robin_3);
  1324. val64 = 0x0203040000000000ULL;
  1325. writeq(val64, &bar0->tx_w_round_robin_4);
  1326. break;
  1327. case 6:
  1328. val64 = 0x0001020304050001ULL;
  1329. writeq(val64, &bar0->tx_w_round_robin_0);
  1330. val64 = 0x0203040500010203ULL;
  1331. writeq(val64, &bar0->tx_w_round_robin_1);
  1332. val64 = 0x0405000102030405ULL;
  1333. writeq(val64, &bar0->tx_w_round_robin_2);
  1334. val64 = 0x0001020304050001ULL;
  1335. writeq(val64, &bar0->tx_w_round_robin_3);
  1336. val64 = 0x0203040500000000ULL;
  1337. writeq(val64, &bar0->tx_w_round_robin_4);
  1338. break;
  1339. case 7:
  1340. val64 = 0x0001020304050600ULL;
  1341. writeq(val64, &bar0->tx_w_round_robin_0);
  1342. val64 = 0x0102030405060001ULL;
  1343. writeq(val64, &bar0->tx_w_round_robin_1);
  1344. val64 = 0x0203040506000102ULL;
  1345. writeq(val64, &bar0->tx_w_round_robin_2);
  1346. val64 = 0x0304050600010203ULL;
  1347. writeq(val64, &bar0->tx_w_round_robin_3);
  1348. val64 = 0x0405060000000000ULL;
  1349. writeq(val64, &bar0->tx_w_round_robin_4);
  1350. break;
  1351. case 8:
  1352. val64 = 0x0001020304050607ULL;
  1353. writeq(val64, &bar0->tx_w_round_robin_0);
  1354. writeq(val64, &bar0->tx_w_round_robin_1);
  1355. writeq(val64, &bar0->tx_w_round_robin_2);
  1356. writeq(val64, &bar0->tx_w_round_robin_3);
  1357. val64 = 0x0001020300000000ULL;
  1358. writeq(val64, &bar0->tx_w_round_robin_4);
  1359. break;
  1360. }
  1361. /* Enable all configured Tx FIFO partitions */
  1362. val64 = readq(&bar0->tx_fifo_partition_0);
  1363. val64 |= (TX_FIFO_PARTITION_EN);
  1364. writeq(val64, &bar0->tx_fifo_partition_0);
  1365. /* Filling the Rx round robin registers as per the
  1366. * number of Rings and steering based on QoS with
  1367. * equal priority.
  1368. */
  1369. switch (config->rx_ring_num) {
  1370. case 1:
  1371. val64 = 0x0;
  1372. writeq(val64, &bar0->rx_w_round_robin_0);
  1373. writeq(val64, &bar0->rx_w_round_robin_1);
  1374. writeq(val64, &bar0->rx_w_round_robin_2);
  1375. writeq(val64, &bar0->rx_w_round_robin_3);
  1376. writeq(val64, &bar0->rx_w_round_robin_4);
  1377. val64 = 0x8080808080808080ULL;
  1378. writeq(val64, &bar0->rts_qos_steering);
  1379. break;
  1380. case 2:
  1381. val64 = 0x0001000100010001ULL;
  1382. writeq(val64, &bar0->rx_w_round_robin_0);
  1383. writeq(val64, &bar0->rx_w_round_robin_1);
  1384. writeq(val64, &bar0->rx_w_round_robin_2);
  1385. writeq(val64, &bar0->rx_w_round_robin_3);
  1386. val64 = 0x0001000100000000ULL;
  1387. writeq(val64, &bar0->rx_w_round_robin_4);
  1388. val64 = 0x8080808040404040ULL;
  1389. writeq(val64, &bar0->rts_qos_steering);
  1390. break;
  1391. case 3:
  1392. val64 = 0x0001020001020001ULL;
  1393. writeq(val64, &bar0->rx_w_round_robin_0);
  1394. val64 = 0x0200010200010200ULL;
  1395. writeq(val64, &bar0->rx_w_round_robin_1);
  1396. val64 = 0x0102000102000102ULL;
  1397. writeq(val64, &bar0->rx_w_round_robin_2);
  1398. val64 = 0x0001020001020001ULL;
  1399. writeq(val64, &bar0->rx_w_round_robin_3);
  1400. val64 = 0x0200010200000000ULL;
  1401. writeq(val64, &bar0->rx_w_round_robin_4);
  1402. val64 = 0x8080804040402020ULL;
  1403. writeq(val64, &bar0->rts_qos_steering);
  1404. break;
  1405. case 4:
  1406. val64 = 0x0001020300010203ULL;
  1407. writeq(val64, &bar0->rx_w_round_robin_0);
  1408. writeq(val64, &bar0->rx_w_round_robin_1);
  1409. writeq(val64, &bar0->rx_w_round_robin_2);
  1410. writeq(val64, &bar0->rx_w_round_robin_3);
  1411. val64 = 0x0001020300000000ULL;
  1412. writeq(val64, &bar0->rx_w_round_robin_4);
  1413. val64 = 0x8080404020201010ULL;
  1414. writeq(val64, &bar0->rts_qos_steering);
  1415. break;
  1416. case 5:
  1417. val64 = 0x0001020304000102ULL;
  1418. writeq(val64, &bar0->rx_w_round_robin_0);
  1419. val64 = 0x0304000102030400ULL;
  1420. writeq(val64, &bar0->rx_w_round_robin_1);
  1421. val64 = 0x0102030400010203ULL;
  1422. writeq(val64, &bar0->rx_w_round_robin_2);
  1423. val64 = 0x0400010203040001ULL;
  1424. writeq(val64, &bar0->rx_w_round_robin_3);
  1425. val64 = 0x0203040000000000ULL;
  1426. writeq(val64, &bar0->rx_w_round_robin_4);
  1427. val64 = 0x8080404020201008ULL;
  1428. writeq(val64, &bar0->rts_qos_steering);
  1429. break;
  1430. case 6:
  1431. val64 = 0x0001020304050001ULL;
  1432. writeq(val64, &bar0->rx_w_round_robin_0);
  1433. val64 = 0x0203040500010203ULL;
  1434. writeq(val64, &bar0->rx_w_round_robin_1);
  1435. val64 = 0x0405000102030405ULL;
  1436. writeq(val64, &bar0->rx_w_round_robin_2);
  1437. val64 = 0x0001020304050001ULL;
  1438. writeq(val64, &bar0->rx_w_round_robin_3);
  1439. val64 = 0x0203040500000000ULL;
  1440. writeq(val64, &bar0->rx_w_round_robin_4);
  1441. val64 = 0x8080404020100804ULL;
  1442. writeq(val64, &bar0->rts_qos_steering);
  1443. break;
  1444. case 7:
  1445. val64 = 0x0001020304050600ULL;
  1446. writeq(val64, &bar0->rx_w_round_robin_0);
  1447. val64 = 0x0102030405060001ULL;
  1448. writeq(val64, &bar0->rx_w_round_robin_1);
  1449. val64 = 0x0203040506000102ULL;
  1450. writeq(val64, &bar0->rx_w_round_robin_2);
  1451. val64 = 0x0304050600010203ULL;
  1452. writeq(val64, &bar0->rx_w_round_robin_3);
  1453. val64 = 0x0405060000000000ULL;
  1454. writeq(val64, &bar0->rx_w_round_robin_4);
  1455. val64 = 0x8080402010080402ULL;
  1456. writeq(val64, &bar0->rts_qos_steering);
  1457. break;
  1458. case 8:
  1459. val64 = 0x0001020304050607ULL;
  1460. writeq(val64, &bar0->rx_w_round_robin_0);
  1461. writeq(val64, &bar0->rx_w_round_robin_1);
  1462. writeq(val64, &bar0->rx_w_round_robin_2);
  1463. writeq(val64, &bar0->rx_w_round_robin_3);
  1464. val64 = 0x0001020300000000ULL;
  1465. writeq(val64, &bar0->rx_w_round_robin_4);
  1466. val64 = 0x8040201008040201ULL;
  1467. writeq(val64, &bar0->rts_qos_steering);
  1468. break;
  1469. }
  1470. /* UDP Fix */
  1471. val64 = 0;
  1472. for (i = 0; i < 8; i++)
  1473. writeq(val64, &bar0->rts_frm_len_n[i]);
  1474. /* Set the default rts frame length for the rings configured */
  1475. val64 = MAC_RTS_FRM_LEN_SET(dev->mtu+22);
  1476. for (i = 0 ; i < config->rx_ring_num ; i++)
  1477. writeq(val64, &bar0->rts_frm_len_n[i]);
  1478. /* Set the frame length for the configured rings
  1479. * desired by the user
  1480. */
  1481. for (i = 0; i < config->rx_ring_num; i++) {
  1482. /* If rts_frm_len[i] == 0 then it is assumed that user not
  1483. * specified frame length steering.
  1484. * If the user provides the frame length then program
  1485. * the rts_frm_len register for those values or else
  1486. * leave it as it is.
  1487. */
  1488. if (rts_frm_len[i] != 0) {
  1489. writeq(MAC_RTS_FRM_LEN_SET(rts_frm_len[i]),
  1490. &bar0->rts_frm_len_n[i]);
  1491. }
  1492. }
  1493. /* Disable differentiated services steering logic */
  1494. for (i = 0; i < 64; i++) {
  1495. if (rts_ds_steer(nic, i, 0) == FAILURE) {
  1496. DBG_PRINT(ERR_DBG,
  1497. "%s: rts_ds_steer failed on codepoint %d\n",
  1498. dev->name, i);
  1499. return -ENODEV;
  1500. }
  1501. }
  1502. /* Program statistics memory */
  1503. writeq(mac_control->stats_mem_phy, &bar0->stat_addr);
  1504. if (nic->device_type == XFRAME_II_DEVICE) {
  1505. val64 = STAT_BC(0x320);
  1506. writeq(val64, &bar0->stat_byte_cnt);
  1507. }
  1508. /*
  1509. * Initializing the sampling rate for the device to calculate the
  1510. * bandwidth utilization.
  1511. */
  1512. val64 = MAC_TX_LINK_UTIL_VAL(tmac_util_period) |
  1513. MAC_RX_LINK_UTIL_VAL(rmac_util_period);
  1514. writeq(val64, &bar0->mac_link_util);
  1515. /*
  1516. * Initializing the Transmit and Receive Traffic Interrupt
  1517. * Scheme.
  1518. */
  1519. /* Initialize TTI */
  1520. if (SUCCESS != init_tti(nic, nic->last_link_state))
  1521. return -ENODEV;
  1522. /* RTI Initialization */
  1523. if (nic->device_type == XFRAME_II_DEVICE) {
  1524. /*
  1525. * Programmed to generate Apprx 500 Intrs per
  1526. * second
  1527. */
  1528. int count = (nic->config.bus_speed * 125)/4;
  1529. val64 = RTI_DATA1_MEM_RX_TIMER_VAL(count);
  1530. } else
  1531. val64 = RTI_DATA1_MEM_RX_TIMER_VAL(0xFFF);
  1532. val64 |= RTI_DATA1_MEM_RX_URNG_A(0xA) |
  1533. RTI_DATA1_MEM_RX_URNG_B(0x10) |
  1534. RTI_DATA1_MEM_RX_URNG_C(0x30) |
  1535. RTI_DATA1_MEM_RX_TIMER_AC_EN;
  1536. writeq(val64, &bar0->rti_data1_mem);
  1537. val64 = RTI_DATA2_MEM_RX_UFC_A(0x1) |
  1538. RTI_DATA2_MEM_RX_UFC_B(0x2) ;
  1539. if (nic->config.intr_type == MSI_X)
  1540. val64 |= (RTI_DATA2_MEM_RX_UFC_C(0x20) |
  1541. RTI_DATA2_MEM_RX_UFC_D(0x40));
  1542. else
  1543. val64 |= (RTI_DATA2_MEM_RX_UFC_C(0x40) |
  1544. RTI_DATA2_MEM_RX_UFC_D(0x80));
  1545. writeq(val64, &bar0->rti_data2_mem);
  1546. for (i = 0; i < config->rx_ring_num; i++) {
  1547. val64 = RTI_CMD_MEM_WE |
  1548. RTI_CMD_MEM_STROBE_NEW_CMD |
  1549. RTI_CMD_MEM_OFFSET(i);
  1550. writeq(val64, &bar0->rti_command_mem);
  1551. /*
  1552. * Once the operation completes, the Strobe bit of the
  1553. * command register will be reset. We poll for this
  1554. * particular condition. We wait for a maximum of 500ms
  1555. * for the operation to complete, if it's not complete
  1556. * by then we return error.
  1557. */
  1558. time = 0;
  1559. while (true) {
  1560. val64 = readq(&bar0->rti_command_mem);
  1561. if (!(val64 & RTI_CMD_MEM_STROBE_NEW_CMD))
  1562. break;
  1563. if (time > 10) {
  1564. DBG_PRINT(ERR_DBG, "%s: RTI init failed\n",
  1565. dev->name);
  1566. return -ENODEV;
  1567. }
  1568. time++;
  1569. msleep(50);
  1570. }
  1571. }
  1572. /*
  1573. * Initializing proper values as Pause threshold into all
  1574. * the 8 Queues on Rx side.
  1575. */
  1576. writeq(0xffbbffbbffbbffbbULL, &bar0->mc_pause_thresh_q0q3);
  1577. writeq(0xffbbffbbffbbffbbULL, &bar0->mc_pause_thresh_q4q7);
  1578. /* Disable RMAC PAD STRIPPING */
  1579. add = &bar0->mac_cfg;
  1580. val64 = readq(&bar0->mac_cfg);
  1581. val64 &= ~(MAC_CFG_RMAC_STRIP_PAD);
  1582. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  1583. writel((u32) (val64), add);
  1584. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  1585. writel((u32) (val64 >> 32), (add + 4));
  1586. val64 = readq(&bar0->mac_cfg);
  1587. /* Enable FCS stripping by adapter */
  1588. add = &bar0->mac_cfg;
  1589. val64 = readq(&bar0->mac_cfg);
  1590. val64 |= MAC_CFG_RMAC_STRIP_FCS;
  1591. if (nic->device_type == XFRAME_II_DEVICE)
  1592. writeq(val64, &bar0->mac_cfg);
  1593. else {
  1594. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  1595. writel((u32) (val64), add);
  1596. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  1597. writel((u32) (val64 >> 32), (add + 4));
  1598. }
  1599. /*
  1600. * Set the time value to be inserted in the pause frame
  1601. * generated by xena.
  1602. */
  1603. val64 = readq(&bar0->rmac_pause_cfg);
  1604. val64 &= ~(RMAC_PAUSE_HG_PTIME(0xffff));
  1605. val64 |= RMAC_PAUSE_HG_PTIME(nic->mac_control.rmac_pause_time);
  1606. writeq(val64, &bar0->rmac_pause_cfg);
  1607. /*
  1608. * Set the Threshold Limit for Generating the pause frame
  1609. * If the amount of data in any Queue exceeds ratio of
  1610. * (mac_control.mc_pause_threshold_q0q3 or q4q7)/256
  1611. * pause frame is generated
  1612. */
  1613. val64 = 0;
  1614. for (i = 0; i < 4; i++) {
  1615. val64 |= (((u64)0xFF00 |
  1616. nic->mac_control.mc_pause_threshold_q0q3)
  1617. << (i * 2 * 8));
  1618. }
  1619. writeq(val64, &bar0->mc_pause_thresh_q0q3);
  1620. val64 = 0;
  1621. for (i = 0; i < 4; i++) {
  1622. val64 |= (((u64)0xFF00 |
  1623. nic->mac_control.mc_pause_threshold_q4q7)
  1624. << (i * 2 * 8));
  1625. }
  1626. writeq(val64, &bar0->mc_pause_thresh_q4q7);
  1627. /*
  1628. * TxDMA will stop Read request if the number of read split has
  1629. * exceeded the limit pointed by shared_splits
  1630. */
  1631. val64 = readq(&bar0->pic_control);
  1632. val64 |= PIC_CNTL_SHARED_SPLITS(shared_splits);
  1633. writeq(val64, &bar0->pic_control);
  1634. if (nic->config.bus_speed == 266) {
  1635. writeq(TXREQTO_VAL(0x7f) | TXREQTO_EN, &bar0->txreqtimeout);
  1636. writeq(0x0, &bar0->read_retry_delay);
  1637. writeq(0x0, &bar0->write_retry_delay);
  1638. }
  1639. /*
  1640. * Programming the Herc to split every write transaction
  1641. * that does not start on an ADB to reduce disconnects.
  1642. */
  1643. if (nic->device_type == XFRAME_II_DEVICE) {
  1644. val64 = FAULT_BEHAVIOUR | EXT_REQ_EN |
  1645. MISC_LINK_STABILITY_PRD(3);
  1646. writeq(val64, &bar0->misc_control);
  1647. val64 = readq(&bar0->pic_control2);
  1648. val64 &= ~(s2BIT(13)|s2BIT(14)|s2BIT(15));
  1649. writeq(val64, &bar0->pic_control2);
  1650. }
  1651. if (strstr(nic->product_name, "CX4")) {
  1652. val64 = TMAC_AVG_IPG(0x17);
  1653. writeq(val64, &bar0->tmac_avg_ipg);
  1654. }
  1655. return SUCCESS;
  1656. }
  1657. #define LINK_UP_DOWN_INTERRUPT 1
  1658. #define MAC_RMAC_ERR_TIMER 2
  1659. static int s2io_link_fault_indication(struct s2io_nic *nic)
  1660. {
  1661. if (nic->device_type == XFRAME_II_DEVICE)
  1662. return LINK_UP_DOWN_INTERRUPT;
  1663. else
  1664. return MAC_RMAC_ERR_TIMER;
  1665. }
  1666. /**
  1667. * do_s2io_write_bits - update alarm bits in alarm register
  1668. * @value: alarm bits
  1669. * @flag: interrupt status
  1670. * @addr: address value
  1671. * Description: update alarm bits in alarm register
  1672. * Return Value:
  1673. * NONE.
  1674. */
  1675. static void do_s2io_write_bits(u64 value, int flag, void __iomem *addr)
  1676. {
  1677. u64 temp64;
  1678. temp64 = readq(addr);
  1679. if (flag == ENABLE_INTRS)
  1680. temp64 &= ~((u64)value);
  1681. else
  1682. temp64 |= ((u64)value);
  1683. writeq(temp64, addr);
  1684. }
  1685. static void en_dis_err_alarms(struct s2io_nic *nic, u16 mask, int flag)
  1686. {
  1687. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  1688. register u64 gen_int_mask = 0;
  1689. u64 interruptible;
  1690. writeq(DISABLE_ALL_INTRS, &bar0->general_int_mask);
  1691. if (mask & TX_DMA_INTR) {
  1692. gen_int_mask |= TXDMA_INT_M;
  1693. do_s2io_write_bits(TXDMA_TDA_INT | TXDMA_PFC_INT |
  1694. TXDMA_PCC_INT | TXDMA_TTI_INT |
  1695. TXDMA_LSO_INT | TXDMA_TPA_INT |
  1696. TXDMA_SM_INT, flag, &bar0->txdma_int_mask);
  1697. do_s2io_write_bits(PFC_ECC_DB_ERR | PFC_SM_ERR_ALARM |
  1698. PFC_MISC_0_ERR | PFC_MISC_1_ERR |
  1699. PFC_PCIX_ERR | PFC_ECC_SG_ERR, flag,
  1700. &bar0->pfc_err_mask);
  1701. do_s2io_write_bits(TDA_Fn_ECC_DB_ERR | TDA_SM0_ERR_ALARM |
  1702. TDA_SM1_ERR_ALARM | TDA_Fn_ECC_SG_ERR |
  1703. TDA_PCIX_ERR, flag, &bar0->tda_err_mask);
  1704. do_s2io_write_bits(PCC_FB_ECC_DB_ERR | PCC_TXB_ECC_DB_ERR |
  1705. PCC_SM_ERR_ALARM | PCC_WR_ERR_ALARM |
  1706. PCC_N_SERR | PCC_6_COF_OV_ERR |
  1707. PCC_7_COF_OV_ERR | PCC_6_LSO_OV_ERR |
  1708. PCC_7_LSO_OV_ERR | PCC_FB_ECC_SG_ERR |
  1709. PCC_TXB_ECC_SG_ERR,
  1710. flag, &bar0->pcc_err_mask);
  1711. do_s2io_write_bits(TTI_SM_ERR_ALARM | TTI_ECC_SG_ERR |
  1712. TTI_ECC_DB_ERR, flag, &bar0->tti_err_mask);
  1713. do_s2io_write_bits(LSO6_ABORT | LSO7_ABORT |
  1714. LSO6_SM_ERR_ALARM | LSO7_SM_ERR_ALARM |
  1715. LSO6_SEND_OFLOW | LSO7_SEND_OFLOW,
  1716. flag, &bar0->lso_err_mask);
  1717. do_s2io_write_bits(TPA_SM_ERR_ALARM | TPA_TX_FRM_DROP,
  1718. flag, &bar0->tpa_err_mask);
  1719. do_s2io_write_bits(SM_SM_ERR_ALARM, flag, &bar0->sm_err_mask);
  1720. }
  1721. if (mask & TX_MAC_INTR) {
  1722. gen_int_mask |= TXMAC_INT_M;
  1723. do_s2io_write_bits(MAC_INT_STATUS_TMAC_INT, flag,
  1724. &bar0->mac_int_mask);
  1725. do_s2io_write_bits(TMAC_TX_BUF_OVRN | TMAC_TX_SM_ERR |
  1726. TMAC_ECC_SG_ERR | TMAC_ECC_DB_ERR |
  1727. TMAC_DESC_ECC_SG_ERR | TMAC_DESC_ECC_DB_ERR,
  1728. flag, &bar0->mac_tmac_err_mask);
  1729. }
  1730. if (mask & TX_XGXS_INTR) {
  1731. gen_int_mask |= TXXGXS_INT_M;
  1732. do_s2io_write_bits(XGXS_INT_STATUS_TXGXS, flag,
  1733. &bar0->xgxs_int_mask);
  1734. do_s2io_write_bits(TXGXS_ESTORE_UFLOW | TXGXS_TX_SM_ERR |
  1735. TXGXS_ECC_SG_ERR | TXGXS_ECC_DB_ERR,
  1736. flag, &bar0->xgxs_txgxs_err_mask);
  1737. }
  1738. if (mask & RX_DMA_INTR) {
  1739. gen_int_mask |= RXDMA_INT_M;
  1740. do_s2io_write_bits(RXDMA_INT_RC_INT_M | RXDMA_INT_RPA_INT_M |
  1741. RXDMA_INT_RDA_INT_M | RXDMA_INT_RTI_INT_M,
  1742. flag, &bar0->rxdma_int_mask);
  1743. do_s2io_write_bits(RC_PRCn_ECC_DB_ERR | RC_FTC_ECC_DB_ERR |
  1744. RC_PRCn_SM_ERR_ALARM | RC_FTC_SM_ERR_ALARM |
  1745. RC_PRCn_ECC_SG_ERR | RC_FTC_ECC_SG_ERR |
  1746. RC_RDA_FAIL_WR_Rn, flag, &bar0->rc_err_mask);
  1747. do_s2io_write_bits(PRC_PCI_AB_RD_Rn | PRC_PCI_AB_WR_Rn |
  1748. PRC_PCI_AB_F_WR_Rn | PRC_PCI_DP_RD_Rn |
  1749. PRC_PCI_DP_WR_Rn | PRC_PCI_DP_F_WR_Rn, flag,
  1750. &bar0->prc_pcix_err_mask);
  1751. do_s2io_write_bits(RPA_SM_ERR_ALARM | RPA_CREDIT_ERR |
  1752. RPA_ECC_SG_ERR | RPA_ECC_DB_ERR, flag,
  1753. &bar0->rpa_err_mask);
  1754. do_s2io_write_bits(RDA_RXDn_ECC_DB_ERR | RDA_FRM_ECC_DB_N_AERR |
  1755. RDA_SM1_ERR_ALARM | RDA_SM0_ERR_ALARM |
  1756. RDA_RXD_ECC_DB_SERR | RDA_RXDn_ECC_SG_ERR |
  1757. RDA_FRM_ECC_SG_ERR |
  1758. RDA_MISC_ERR|RDA_PCIX_ERR,
  1759. flag, &bar0->rda_err_mask);
  1760. do_s2io_write_bits(RTI_SM_ERR_ALARM |
  1761. RTI_ECC_SG_ERR | RTI_ECC_DB_ERR,
  1762. flag, &bar0->rti_err_mask);
  1763. }
  1764. if (mask & RX_MAC_INTR) {
  1765. gen_int_mask |= RXMAC_INT_M;
  1766. do_s2io_write_bits(MAC_INT_STATUS_RMAC_INT, flag,
  1767. &bar0->mac_int_mask);
  1768. interruptible = (RMAC_RX_BUFF_OVRN | RMAC_RX_SM_ERR |
  1769. RMAC_UNUSED_INT | RMAC_SINGLE_ECC_ERR |
  1770. RMAC_DOUBLE_ECC_ERR);
  1771. if (s2io_link_fault_indication(nic) == MAC_RMAC_ERR_TIMER)
  1772. interruptible |= RMAC_LINK_STATE_CHANGE_INT;
  1773. do_s2io_write_bits(interruptible,
  1774. flag, &bar0->mac_rmac_err_mask);
  1775. }
  1776. if (mask & RX_XGXS_INTR) {
  1777. gen_int_mask |= RXXGXS_INT_M;
  1778. do_s2io_write_bits(XGXS_INT_STATUS_RXGXS, flag,
  1779. &bar0->xgxs_int_mask);
  1780. do_s2io_write_bits(RXGXS_ESTORE_OFLOW | RXGXS_RX_SM_ERR, flag,
  1781. &bar0->xgxs_rxgxs_err_mask);
  1782. }
  1783. if (mask & MC_INTR) {
  1784. gen_int_mask |= MC_INT_M;
  1785. do_s2io_write_bits(MC_INT_MASK_MC_INT,
  1786. flag, &bar0->mc_int_mask);
  1787. do_s2io_write_bits(MC_ERR_REG_SM_ERR | MC_ERR_REG_ECC_ALL_SNG |
  1788. MC_ERR_REG_ECC_ALL_DBL | PLL_LOCK_N, flag,
  1789. &bar0->mc_err_mask);
  1790. }
  1791. nic->general_int_mask = gen_int_mask;
  1792. /* Remove this line when alarm interrupts are enabled */
  1793. nic->general_int_mask = 0;
  1794. }
  1795. /**
  1796. * en_dis_able_nic_intrs - Enable or Disable the interrupts
  1797. * @nic: device private variable,
  1798. * @mask: A mask indicating which Intr block must be modified and,
  1799. * @flag: A flag indicating whether to enable or disable the Intrs.
  1800. * Description: This function will either disable or enable the interrupts
  1801. * depending on the flag argument. The mask argument can be used to
  1802. * enable/disable any Intr block.
  1803. * Return Value: NONE.
  1804. */
  1805. static void en_dis_able_nic_intrs(struct s2io_nic *nic, u16 mask, int flag)
  1806. {
  1807. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  1808. register u64 temp64 = 0, intr_mask = 0;
  1809. intr_mask = nic->general_int_mask;
  1810. /* Top level interrupt classification */
  1811. /* PIC Interrupts */
  1812. if (mask & TX_PIC_INTR) {
  1813. /* Enable PIC Intrs in the general intr mask register */
  1814. intr_mask |= TXPIC_INT_M;
  1815. if (flag == ENABLE_INTRS) {
  1816. /*
  1817. * If Hercules adapter enable GPIO otherwise
  1818. * disable all PCIX, Flash, MDIO, IIC and GPIO
  1819. * interrupts for now.
  1820. * TODO
  1821. */
  1822. if (s2io_link_fault_indication(nic) ==
  1823. LINK_UP_DOWN_INTERRUPT) {
  1824. do_s2io_write_bits(PIC_INT_GPIO, flag,
  1825. &bar0->pic_int_mask);
  1826. do_s2io_write_bits(GPIO_INT_MASK_LINK_UP, flag,
  1827. &bar0->gpio_int_mask);
  1828. } else
  1829. writeq(DISABLE_ALL_INTRS, &bar0->pic_int_mask);
  1830. } else if (flag == DISABLE_INTRS) {
  1831. /*
  1832. * Disable PIC Intrs in the general
  1833. * intr mask register
  1834. */
  1835. writeq(DISABLE_ALL_INTRS, &bar0->pic_int_mask);
  1836. }
  1837. }
  1838. /* Tx traffic interrupts */
  1839. if (mask & TX_TRAFFIC_INTR) {
  1840. intr_mask |= TXTRAFFIC_INT_M;
  1841. if (flag == ENABLE_INTRS) {
  1842. /*
  1843. * Enable all the Tx side interrupts
  1844. * writing 0 Enables all 64 TX interrupt levels
  1845. */
  1846. writeq(0x0, &bar0->tx_traffic_mask);
  1847. } else if (flag == DISABLE_INTRS) {
  1848. /*
  1849. * Disable Tx Traffic Intrs in the general intr mask
  1850. * register.
  1851. */
  1852. writeq(DISABLE_ALL_INTRS, &bar0->tx_traffic_mask);
  1853. }
  1854. }
  1855. /* Rx traffic interrupts */
  1856. if (mask & RX_TRAFFIC_INTR) {
  1857. intr_mask |= RXTRAFFIC_INT_M;
  1858. if (flag == ENABLE_INTRS) {
  1859. /* writing 0 Enables all 8 RX interrupt levels */
  1860. writeq(0x0, &bar0->rx_traffic_mask);
  1861. } else if (flag == DISABLE_INTRS) {
  1862. /*
  1863. * Disable Rx Traffic Intrs in the general intr mask
  1864. * register.
  1865. */
  1866. writeq(DISABLE_ALL_INTRS, &bar0->rx_traffic_mask);
  1867. }
  1868. }
  1869. temp64 = readq(&bar0->general_int_mask);
  1870. if (flag == ENABLE_INTRS)
  1871. temp64 &= ~((u64)intr_mask);
  1872. else
  1873. temp64 = DISABLE_ALL_INTRS;
  1874. writeq(temp64, &bar0->general_int_mask);
  1875. nic->general_int_mask = readq(&bar0->general_int_mask);
  1876. }
  1877. /**
  1878. * verify_pcc_quiescent- Checks for PCC quiescent state
  1879. * Return: 1 If PCC is quiescence
  1880. * 0 If PCC is not quiescence
  1881. */
  1882. static int verify_pcc_quiescent(struct s2io_nic *sp, int flag)
  1883. {
  1884. int ret = 0, herc;
  1885. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  1886. u64 val64 = readq(&bar0->adapter_status);
  1887. herc = (sp->device_type == XFRAME_II_DEVICE);
  1888. if (flag == false) {
  1889. if ((!herc && (sp->pdev->revision >= 4)) || herc) {
  1890. if (!(val64 & ADAPTER_STATUS_RMAC_PCC_IDLE))
  1891. ret = 1;
  1892. } else {
  1893. if (!(val64 & ADAPTER_STATUS_RMAC_PCC_FOUR_IDLE))
  1894. ret = 1;
  1895. }
  1896. } else {
  1897. if ((!herc && (sp->pdev->revision >= 4)) || herc) {
  1898. if (((val64 & ADAPTER_STATUS_RMAC_PCC_IDLE) ==
  1899. ADAPTER_STATUS_RMAC_PCC_IDLE))
  1900. ret = 1;
  1901. } else {
  1902. if (((val64 & ADAPTER_STATUS_RMAC_PCC_FOUR_IDLE) ==
  1903. ADAPTER_STATUS_RMAC_PCC_FOUR_IDLE))
  1904. ret = 1;
  1905. }
  1906. }
  1907. return ret;
  1908. }
  1909. /**
  1910. * verify_xena_quiescence - Checks whether the H/W is ready
  1911. * Description: Returns whether the H/W is ready to go or not. Depending
  1912. * on whether adapter enable bit was written or not the comparison
  1913. * differs and the calling function passes the input argument flag to
  1914. * indicate this.
  1915. * Return: 1 If xena is quiescence
  1916. * 0 If Xena is not quiescence
  1917. */
  1918. static int verify_xena_quiescence(struct s2io_nic *sp)
  1919. {
  1920. int mode;
  1921. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  1922. u64 val64 = readq(&bar0->adapter_status);
  1923. mode = s2io_verify_pci_mode(sp);
  1924. if (!(val64 & ADAPTER_STATUS_TDMA_READY)) {
  1925. DBG_PRINT(ERR_DBG, "TDMA is not ready!\n");
  1926. return 0;
  1927. }
  1928. if (!(val64 & ADAPTER_STATUS_RDMA_READY)) {
  1929. DBG_PRINT(ERR_DBG, "RDMA is not ready!\n");
  1930. return 0;
  1931. }
  1932. if (!(val64 & ADAPTER_STATUS_PFC_READY)) {
  1933. DBG_PRINT(ERR_DBG, "PFC is not ready!\n");
  1934. return 0;
  1935. }
  1936. if (!(val64 & ADAPTER_STATUS_TMAC_BUF_EMPTY)) {
  1937. DBG_PRINT(ERR_DBG, "TMAC BUF is not empty!\n");
  1938. return 0;
  1939. }
  1940. if (!(val64 & ADAPTER_STATUS_PIC_QUIESCENT)) {
  1941. DBG_PRINT(ERR_DBG, "PIC is not QUIESCENT!\n");
  1942. return 0;
  1943. }
  1944. if (!(val64 & ADAPTER_STATUS_MC_DRAM_READY)) {
  1945. DBG_PRINT(ERR_DBG, "MC_DRAM is not ready!\n");
  1946. return 0;
  1947. }
  1948. if (!(val64 & ADAPTER_STATUS_MC_QUEUES_READY)) {
  1949. DBG_PRINT(ERR_DBG, "MC_QUEUES is not ready!\n");
  1950. return 0;
  1951. }
  1952. if (!(val64 & ADAPTER_STATUS_M_PLL_LOCK)) {
  1953. DBG_PRINT(ERR_DBG, "M_PLL is not locked!\n");
  1954. return 0;
  1955. }
  1956. /*
  1957. * In PCI 33 mode, the P_PLL is not used, and therefore,
  1958. * the the P_PLL_LOCK bit in the adapter_status register will
  1959. * not be asserted.
  1960. */
  1961. if (!(val64 & ADAPTER_STATUS_P_PLL_LOCK) &&
  1962. sp->device_type == XFRAME_II_DEVICE &&
  1963. mode != PCI_MODE_PCI_33) {
  1964. DBG_PRINT(ERR_DBG, "P_PLL is not locked!\n");
  1965. return 0;
  1966. }
  1967. if (!((val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ==
  1968. ADAPTER_STATUS_RC_PRC_QUIESCENT)) {
  1969. DBG_PRINT(ERR_DBG, "RC_PRC is not QUIESCENT!\n");
  1970. return 0;
  1971. }
  1972. return 1;
  1973. }
  1974. /**
  1975. * fix_mac_address - Fix for Mac addr problem on Alpha platforms
  1976. * @sp: Pointer to device specifc structure
  1977. * Description :
  1978. * New procedure to clear mac address reading problems on Alpha platforms
  1979. *
  1980. */
  1981. static void fix_mac_address(struct s2io_nic *sp)
  1982. {
  1983. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  1984. int i = 0;
  1985. while (fix_mac[i] != END_SIGN) {
  1986. writeq(fix_mac[i++], &bar0->gpio_control);
  1987. udelay(10);
  1988. (void) readq(&bar0->gpio_control);
  1989. }
  1990. }
  1991. /**
  1992. * start_nic - Turns the device on
  1993. * @nic : device private variable.
  1994. * Description:
  1995. * This function actually turns the device on. Before this function is
  1996. * called,all Registers are configured from their reset states
  1997. * and shared memory is allocated but the NIC is still quiescent. On
  1998. * calling this function, the device interrupts are cleared and the NIC is
  1999. * literally switched on by writing into the adapter control register.
  2000. * Return Value:
  2001. * SUCCESS on success and -1 on failure.
  2002. */
  2003. static int start_nic(struct s2io_nic *nic)
  2004. {
  2005. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  2006. struct net_device *dev = nic->dev;
  2007. register u64 val64 = 0;
  2008. u16 subid, i;
  2009. struct config_param *config = &nic->config;
  2010. struct mac_info *mac_control = &nic->mac_control;
  2011. /* PRC Initialization and configuration */
  2012. for (i = 0; i < config->rx_ring_num; i++) {
  2013. struct ring_info *ring = &mac_control->rings[i];
  2014. writeq((u64)ring->rx_blocks[0].block_dma_addr,
  2015. &bar0->prc_rxd0_n[i]);
  2016. val64 = readq(&bar0->prc_ctrl_n[i]);
  2017. if (nic->rxd_mode == RXD_MODE_1)
  2018. val64 |= PRC_CTRL_RC_ENABLED;
  2019. else
  2020. val64 |= PRC_CTRL_RC_ENABLED | PRC_CTRL_RING_MODE_3;
  2021. if (nic->device_type == XFRAME_II_DEVICE)
  2022. val64 |= PRC_CTRL_GROUP_READS;
  2023. val64 &= ~PRC_CTRL_RXD_BACKOFF_INTERVAL(0xFFFFFF);
  2024. val64 |= PRC_CTRL_RXD_BACKOFF_INTERVAL(0x1000);
  2025. writeq(val64, &bar0->prc_ctrl_n[i]);
  2026. }
  2027. if (nic->rxd_mode == RXD_MODE_3B) {
  2028. /* Enabling 2 buffer mode by writing into Rx_pa_cfg reg. */
  2029. val64 = readq(&bar0->rx_pa_cfg);
  2030. val64 |= RX_PA_CFG_IGNORE_L2_ERR;
  2031. writeq(val64, &bar0->rx_pa_cfg);
  2032. }
  2033. if (vlan_tag_strip == 0) {
  2034. val64 = readq(&bar0->rx_pa_cfg);
  2035. val64 &= ~RX_PA_CFG_STRIP_VLAN_TAG;
  2036. writeq(val64, &bar0->rx_pa_cfg);
  2037. nic->vlan_strip_flag = 0;
  2038. }
  2039. /*
  2040. * Enabling MC-RLDRAM. After enabling the device, we timeout
  2041. * for around 100ms, which is approximately the time required
  2042. * for the device to be ready for operation.
  2043. */
  2044. val64 = readq(&bar0->mc_rldram_mrs);
  2045. val64 |= MC_RLDRAM_QUEUE_SIZE_ENABLE | MC_RLDRAM_MRS_ENABLE;
  2046. SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_mrs, UF);
  2047. val64 = readq(&bar0->mc_rldram_mrs);
  2048. msleep(100); /* Delay by around 100 ms. */
  2049. /* Enabling ECC Protection. */
  2050. val64 = readq(&bar0->adapter_control);
  2051. val64 &= ~ADAPTER_ECC_EN;
  2052. writeq(val64, &bar0->adapter_control);
  2053. /*
  2054. * Verify if the device is ready to be enabled, if so enable
  2055. * it.
  2056. */
  2057. val64 = readq(&bar0->adapter_status);
  2058. if (!verify_xena_quiescence(nic)) {
  2059. DBG_PRINT(ERR_DBG, "%s: device is not ready, "
  2060. "Adapter status reads: 0x%llx\n",
  2061. dev->name, (unsigned long long)val64);
  2062. return FAILURE;
  2063. }
  2064. /*
  2065. * With some switches, link might be already up at this point.
  2066. * Because of this weird behavior, when we enable laser,
  2067. * we may not get link. We need to handle this. We cannot
  2068. * figure out which switch is misbehaving. So we are forced to
  2069. * make a global change.
  2070. */
  2071. /* Enabling Laser. */
  2072. val64 = readq(&bar0->adapter_control);
  2073. val64 |= ADAPTER_EOI_TX_ON;
  2074. writeq(val64, &bar0->adapter_control);
  2075. if (s2io_link_fault_indication(nic) == MAC_RMAC_ERR_TIMER) {
  2076. /*
  2077. * Dont see link state interrupts initially on some switches,
  2078. * so directly scheduling the link state task here.
  2079. */
  2080. schedule_work(&nic->set_link_task);
  2081. }
  2082. /* SXE-002: Initialize link and activity LED */
  2083. subid = nic->pdev->subsystem_device;
  2084. if (((subid & 0xFF) >= 0x07) &&
  2085. (nic->device_type == XFRAME_I_DEVICE)) {
  2086. val64 = readq(&bar0->gpio_control);
  2087. val64 |= 0x0000800000000000ULL;
  2088. writeq(val64, &bar0->gpio_control);
  2089. val64 = 0x0411040400000000ULL;
  2090. writeq(val64, (void __iomem *)bar0 + 0x2700);
  2091. }
  2092. return SUCCESS;
  2093. }
  2094. /**
  2095. * s2io_txdl_getskb - Get the skb from txdl, unmap and return skb
  2096. */
  2097. static struct sk_buff *s2io_txdl_getskb(struct fifo_info *fifo_data,
  2098. struct TxD *txdlp, int get_off)
  2099. {
  2100. struct s2io_nic *nic = fifo_data->nic;
  2101. struct sk_buff *skb;
  2102. struct TxD *txds;
  2103. u16 j, frg_cnt;
  2104. txds = txdlp;
  2105. if (txds->Host_Control == (u64)(long)fifo_data->ufo_in_band_v) {
  2106. pci_unmap_single(nic->pdev, (dma_addr_t)txds->Buffer_Pointer,
  2107. sizeof(u64), PCI_DMA_TODEVICE);
  2108. txds++;
  2109. }
  2110. skb = (struct sk_buff *)((unsigned long)txds->Host_Control);
  2111. if (!skb) {
  2112. memset(txdlp, 0, (sizeof(struct TxD) * fifo_data->max_txds));
  2113. return NULL;
  2114. }
  2115. pci_unmap_single(nic->pdev, (dma_addr_t)txds->Buffer_Pointer,
  2116. skb_headlen(skb), PCI_DMA_TODEVICE);
  2117. frg_cnt = skb_shinfo(skb)->nr_frags;
  2118. if (frg_cnt) {
  2119. txds++;
  2120. for (j = 0; j < frg_cnt; j++, txds++) {
  2121. const skb_frag_t *frag = &skb_shinfo(skb)->frags[j];
  2122. if (!txds->Buffer_Pointer)
  2123. break;
  2124. pci_unmap_page(nic->pdev,
  2125. (dma_addr_t)txds->Buffer_Pointer,
  2126. skb_frag_size(frag), PCI_DMA_TODEVICE);
  2127. }
  2128. }
  2129. memset(txdlp, 0, (sizeof(struct TxD) * fifo_data->max_txds));
  2130. return skb;
  2131. }
  2132. /**
  2133. * free_tx_buffers - Free all queued Tx buffers
  2134. * @nic : device private variable.
  2135. * Description:
  2136. * Free all queued Tx buffers.
  2137. * Return Value: void
  2138. */
  2139. static void free_tx_buffers(struct s2io_nic *nic)
  2140. {
  2141. struct net_device *dev = nic->dev;
  2142. struct sk_buff *skb;
  2143. struct TxD *txdp;
  2144. int i, j;
  2145. int cnt = 0;
  2146. struct config_param *config = &nic->config;
  2147. struct mac_info *mac_control = &nic->mac_control;
  2148. struct stat_block *stats = mac_control->stats_info;
  2149. struct swStat *swstats = &stats->sw_stat;
  2150. for (i = 0; i < config->tx_fifo_num; i++) {
  2151. struct tx_fifo_config *tx_cfg = &config->tx_cfg[i];
  2152. struct fifo_info *fifo = &mac_control->fifos[i];
  2153. unsigned long flags;
  2154. spin_lock_irqsave(&fifo->tx_lock, flags);
  2155. for (j = 0; j < tx_cfg->fifo_len; j++) {
  2156. txdp = fifo->list_info[j].list_virt_addr;
  2157. skb = s2io_txdl_getskb(&mac_control->fifos[i], txdp, j);
  2158. if (skb) {
  2159. swstats->mem_freed += skb->truesize;
  2160. dev_kfree_skb(skb);
  2161. cnt++;
  2162. }
  2163. }
  2164. DBG_PRINT(INTR_DBG,
  2165. "%s: forcibly freeing %d skbs on FIFO%d\n",
  2166. dev->name, cnt, i);
  2167. fifo->tx_curr_get_info.offset = 0;
  2168. fifo->tx_curr_put_info.offset = 0;
  2169. spin_unlock_irqrestore(&fifo->tx_lock, flags);
  2170. }
  2171. }
  2172. /**
  2173. * stop_nic - To stop the nic
  2174. * @nic ; device private variable.
  2175. * Description:
  2176. * This function does exactly the opposite of what the start_nic()
  2177. * function does. This function is called to stop the device.
  2178. * Return Value:
  2179. * void.
  2180. */
  2181. static void stop_nic(struct s2io_nic *nic)
  2182. {
  2183. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  2184. register u64 val64 = 0;
  2185. u16 interruptible;
  2186. /* Disable all interrupts */
  2187. en_dis_err_alarms(nic, ENA_ALL_INTRS, DISABLE_INTRS);
  2188. interruptible = TX_TRAFFIC_INTR | RX_TRAFFIC_INTR;
  2189. interruptible |= TX_PIC_INTR;
  2190. en_dis_able_nic_intrs(nic, interruptible, DISABLE_INTRS);
  2191. /* Clearing Adapter_En bit of ADAPTER_CONTROL Register */
  2192. val64 = readq(&bar0->adapter_control);
  2193. val64 &= ~(ADAPTER_CNTL_EN);
  2194. writeq(val64, &bar0->adapter_control);
  2195. }
  2196. /**
  2197. * fill_rx_buffers - Allocates the Rx side skbs
  2198. * @ring_info: per ring structure
  2199. * @from_card_up: If this is true, we will map the buffer to get
  2200. * the dma address for buf0 and buf1 to give it to the card.
  2201. * Else we will sync the already mapped buffer to give it to the card.
  2202. * Description:
  2203. * The function allocates Rx side skbs and puts the physical
  2204. * address of these buffers into the RxD buffer pointers, so that the NIC
  2205. * can DMA the received frame into these locations.
  2206. * The NIC supports 3 receive modes, viz
  2207. * 1. single buffer,
  2208. * 2. three buffer and
  2209. * 3. Five buffer modes.
  2210. * Each mode defines how many fragments the received frame will be split
  2211. * up into by the NIC. The frame is split into L3 header, L4 Header,
  2212. * L4 payload in three buffer mode and in 5 buffer mode, L4 payload itself
  2213. * is split into 3 fragments. As of now only single buffer mode is
  2214. * supported.
  2215. * Return Value:
  2216. * SUCCESS on success or an appropriate -ve value on failure.
  2217. */
  2218. static int fill_rx_buffers(struct s2io_nic *nic, struct ring_info *ring,
  2219. int from_card_up)
  2220. {
  2221. struct sk_buff *skb;
  2222. struct RxD_t *rxdp;
  2223. int off, size, block_no, block_no1;
  2224. u32 alloc_tab = 0;
  2225. u32 alloc_cnt;
  2226. u64 tmp;
  2227. struct buffAdd *ba;
  2228. struct RxD_t *first_rxdp = NULL;
  2229. u64 Buffer0_ptr = 0, Buffer1_ptr = 0;
  2230. int rxd_index = 0;
  2231. struct RxD1 *rxdp1;
  2232. struct RxD3 *rxdp3;
  2233. struct swStat *swstats = &ring->nic->mac_control.stats_info->sw_stat;
  2234. alloc_cnt = ring->pkt_cnt - ring->rx_bufs_left;
  2235. block_no1 = ring->rx_curr_get_info.block_index;
  2236. while (alloc_tab < alloc_cnt) {
  2237. block_no = ring->rx_curr_put_info.block_index;
  2238. off = ring->rx_curr_put_info.offset;
  2239. rxdp = ring->rx_blocks[block_no].rxds[off].virt_addr;
  2240. rxd_index = off + 1;
  2241. if (block_no)
  2242. rxd_index += (block_no * ring->rxd_count);
  2243. if ((block_no == block_no1) &&
  2244. (off == ring->rx_curr_get_info.offset) &&
  2245. (rxdp->Host_Control)) {
  2246. DBG_PRINT(INTR_DBG, "%s: Get and Put info equated\n",
  2247. ring->dev->name);
  2248. goto end;
  2249. }
  2250. if (off && (off == ring->rxd_count)) {
  2251. ring->rx_curr_put_info.block_index++;
  2252. if (ring->rx_curr_put_info.block_index ==
  2253. ring->block_count)
  2254. ring->rx_curr_put_info.block_index = 0;
  2255. block_no = ring->rx_curr_put_info.block_index;
  2256. off = 0;
  2257. ring->rx_curr_put_info.offset = off;
  2258. rxdp = ring->rx_blocks[block_no].block_virt_addr;
  2259. DBG_PRINT(INTR_DBG, "%s: Next block at: %p\n",
  2260. ring->dev->name, rxdp);
  2261. }
  2262. if ((rxdp->Control_1 & RXD_OWN_XENA) &&
  2263. ((ring->rxd_mode == RXD_MODE_3B) &&
  2264. (rxdp->Control_2 & s2BIT(0)))) {
  2265. ring->rx_curr_put_info.offset = off;
  2266. goto end;
  2267. }
  2268. /* calculate size of skb based on ring mode */
  2269. size = ring->mtu +
  2270. HEADER_ETHERNET_II_802_3_SIZE +
  2271. HEADER_802_2_SIZE + HEADER_SNAP_SIZE;
  2272. if (ring->rxd_mode == RXD_MODE_1)
  2273. size += NET_IP_ALIGN;
  2274. else
  2275. size = ring->mtu + ALIGN_SIZE + BUF0_LEN + 4;
  2276. /* allocate skb */
  2277. skb = netdev_alloc_skb(nic->dev, size);
  2278. if (!skb) {
  2279. DBG_PRINT(INFO_DBG, "%s: Could not allocate skb\n",
  2280. ring->dev->name);
  2281. if (first_rxdp) {
  2282. wmb();
  2283. first_rxdp->Control_1 |= RXD_OWN_XENA;
  2284. }
  2285. swstats->mem_alloc_fail_cnt++;
  2286. return -ENOMEM ;
  2287. }
  2288. swstats->mem_allocated += skb->truesize;
  2289. if (ring->rxd_mode == RXD_MODE_1) {
  2290. /* 1 buffer mode - normal operation mode */
  2291. rxdp1 = (struct RxD1 *)rxdp;
  2292. memset(rxdp, 0, sizeof(struct RxD1));
  2293. skb_reserve(skb, NET_IP_ALIGN);
  2294. rxdp1->Buffer0_ptr =
  2295. pci_map_single(ring->pdev, skb->data,
  2296. size - NET_IP_ALIGN,
  2297. PCI_DMA_FROMDEVICE);
  2298. if (pci_dma_mapping_error(nic->pdev,
  2299. rxdp1->Buffer0_ptr))
  2300. goto pci_map_failed;
  2301. rxdp->Control_2 =
  2302. SET_BUFFER0_SIZE_1(size - NET_IP_ALIGN);
  2303. rxdp->Host_Control = (unsigned long)skb;
  2304. } else if (ring->rxd_mode == RXD_MODE_3B) {
  2305. /*
  2306. * 2 buffer mode -
  2307. * 2 buffer mode provides 128
  2308. * byte aligned receive buffers.
  2309. */
  2310. rxdp3 = (struct RxD3 *)rxdp;
  2311. /* save buffer pointers to avoid frequent dma mapping */
  2312. Buffer0_ptr = rxdp3->Buffer0_ptr;
  2313. Buffer1_ptr = rxdp3->Buffer1_ptr;
  2314. memset(rxdp, 0, sizeof(struct RxD3));
  2315. /* restore the buffer pointers for dma sync*/
  2316. rxdp3->Buffer0_ptr = Buffer0_ptr;
  2317. rxdp3->Buffer1_ptr = Buffer1_ptr;
  2318. ba = &ring->ba[block_no][off];
  2319. skb_reserve(skb, BUF0_LEN);
  2320. tmp = (u64)(unsigned long)skb->data;
  2321. tmp += ALIGN_SIZE;
  2322. tmp &= ~ALIGN_SIZE;
  2323. skb->data = (void *) (unsigned long)tmp;
  2324. skb_reset_tail_pointer(skb);
  2325. if (from_card_up) {
  2326. rxdp3->Buffer0_ptr =
  2327. pci_map_single(ring->pdev, ba->ba_0,
  2328. BUF0_LEN,
  2329. PCI_DMA_FROMDEVICE);
  2330. if (pci_dma_mapping_error(nic->pdev,
  2331. rxdp3->Buffer0_ptr))
  2332. goto pci_map_failed;
  2333. } else
  2334. pci_dma_sync_single_for_device(ring->pdev,
  2335. (dma_addr_t)rxdp3->Buffer0_ptr,
  2336. BUF0_LEN,
  2337. PCI_DMA_FROMDEVICE);
  2338. rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN);
  2339. if (ring->rxd_mode == RXD_MODE_3B) {
  2340. /* Two buffer mode */
  2341. /*
  2342. * Buffer2 will have L3/L4 header plus
  2343. * L4 payload
  2344. */
  2345. rxdp3->Buffer2_ptr = pci_map_single(ring->pdev,
  2346. skb->data,
  2347. ring->mtu + 4,
  2348. PCI_DMA_FROMDEVICE);
  2349. if (pci_dma_mapping_error(nic->pdev,
  2350. rxdp3->Buffer2_ptr))
  2351. goto pci_map_failed;
  2352. if (from_card_up) {
  2353. rxdp3->Buffer1_ptr =
  2354. pci_map_single(ring->pdev,
  2355. ba->ba_1,
  2356. BUF1_LEN,
  2357. PCI_DMA_FROMDEVICE);
  2358. if (pci_dma_mapping_error(nic->pdev,
  2359. rxdp3->Buffer1_ptr)) {
  2360. pci_unmap_single(ring->pdev,
  2361. (dma_addr_t)(unsigned long)
  2362. skb->data,
  2363. ring->mtu + 4,
  2364. PCI_DMA_FROMDEVICE);
  2365. goto pci_map_failed;
  2366. }
  2367. }
  2368. rxdp->Control_2 |= SET_BUFFER1_SIZE_3(1);
  2369. rxdp->Control_2 |= SET_BUFFER2_SIZE_3
  2370. (ring->mtu + 4);
  2371. }
  2372. rxdp->Control_2 |= s2BIT(0);
  2373. rxdp->Host_Control = (unsigned long) (skb);
  2374. }
  2375. if (alloc_tab & ((1 << rxsync_frequency) - 1))
  2376. rxdp->Control_1 |= RXD_OWN_XENA;
  2377. off++;
  2378. if (off == (ring->rxd_count + 1))
  2379. off = 0;
  2380. ring->rx_curr_put_info.offset = off;
  2381. rxdp->Control_2 |= SET_RXD_MARKER;
  2382. if (!(alloc_tab & ((1 << rxsync_frequency) - 1))) {
  2383. if (first_rxdp) {
  2384. wmb();
  2385. first_rxdp->Control_1 |= RXD_OWN_XENA;
  2386. }
  2387. first_rxdp = rxdp;
  2388. }
  2389. ring->rx_bufs_left += 1;
  2390. alloc_tab++;
  2391. }
  2392. end:
  2393. /* Transfer ownership of first descriptor to adapter just before
  2394. * exiting. Before that, use memory barrier so that ownership
  2395. * and other fields are seen by adapter correctly.
  2396. */
  2397. if (first_rxdp) {
  2398. wmb();
  2399. first_rxdp->Control_1 |= RXD_OWN_XENA;
  2400. }
  2401. return SUCCESS;
  2402. pci_map_failed:
  2403. swstats->pci_map_fail_cnt++;
  2404. swstats->mem_freed += skb->truesize;
  2405. dev_kfree_skb_irq(skb);
  2406. return -ENOMEM;
  2407. }
  2408. static void free_rxd_blk(struct s2io_nic *sp, int ring_no, int blk)
  2409. {
  2410. struct net_device *dev = sp->dev;
  2411. int j;
  2412. struct sk_buff *skb;
  2413. struct RxD_t *rxdp;
  2414. struct RxD1 *rxdp1;
  2415. struct RxD3 *rxdp3;
  2416. struct mac_info *mac_control = &sp->mac_control;
  2417. struct stat_block *stats = mac_control->stats_info;
  2418. struct swStat *swstats = &stats->sw_stat;
  2419. for (j = 0 ; j < rxd_count[sp->rxd_mode]; j++) {
  2420. rxdp = mac_control->rings[ring_no].
  2421. rx_blocks[blk].rxds[j].virt_addr;
  2422. skb = (struct sk_buff *)((unsigned long)rxdp->Host_Control);
  2423. if (!skb)
  2424. continue;
  2425. if (sp->rxd_mode == RXD_MODE_1) {
  2426. rxdp1 = (struct RxD1 *)rxdp;
  2427. pci_unmap_single(sp->pdev,
  2428. (dma_addr_t)rxdp1->Buffer0_ptr,
  2429. dev->mtu +
  2430. HEADER_ETHERNET_II_802_3_SIZE +
  2431. HEADER_802_2_SIZE + HEADER_SNAP_SIZE,
  2432. PCI_DMA_FROMDEVICE);
  2433. memset(rxdp, 0, sizeof(struct RxD1));
  2434. } else if (sp->rxd_mode == RXD_MODE_3B) {
  2435. rxdp3 = (struct RxD3 *)rxdp;
  2436. pci_unmap_single(sp->pdev,
  2437. (dma_addr_t)rxdp3->Buffer0_ptr,
  2438. BUF0_LEN,
  2439. PCI_DMA_FROMDEVICE);
  2440. pci_unmap_single(sp->pdev,
  2441. (dma_addr_t)rxdp3->Buffer1_ptr,
  2442. BUF1_LEN,
  2443. PCI_DMA_FROMDEVICE);
  2444. pci_unmap_single(sp->pdev,
  2445. (dma_addr_t)rxdp3->Buffer2_ptr,
  2446. dev->mtu + 4,
  2447. PCI_DMA_FROMDEVICE);
  2448. memset(rxdp, 0, sizeof(struct RxD3));
  2449. }
  2450. swstats->mem_freed += skb->truesize;
  2451. dev_kfree_skb(skb);
  2452. mac_control->rings[ring_no].rx_bufs_left -= 1;
  2453. }
  2454. }
  2455. /**
  2456. * free_rx_buffers - Frees all Rx buffers
  2457. * @sp: device private variable.
  2458. * Description:
  2459. * This function will free all Rx buffers allocated by host.
  2460. * Return Value:
  2461. * NONE.
  2462. */
  2463. static void free_rx_buffers(struct s2io_nic *sp)
  2464. {
  2465. struct net_device *dev = sp->dev;
  2466. int i, blk = 0, buf_cnt = 0;
  2467. struct config_param *config = &sp->config;
  2468. struct mac_info *mac_control = &sp->mac_control;
  2469. for (i = 0; i < config->rx_ring_num; i++) {
  2470. struct ring_info *ring = &mac_control->rings[i];
  2471. for (blk = 0; blk < rx_ring_sz[i]; blk++)
  2472. free_rxd_blk(sp, i, blk);
  2473. ring->rx_curr_put_info.block_index = 0;
  2474. ring->rx_curr_get_info.block_index = 0;
  2475. ring->rx_curr_put_info.offset = 0;
  2476. ring->rx_curr_get_info.offset = 0;
  2477. ring->rx_bufs_left = 0;
  2478. DBG_PRINT(INIT_DBG, "%s: Freed 0x%x Rx Buffers on ring%d\n",
  2479. dev->name, buf_cnt, i);
  2480. }
  2481. }
  2482. static int s2io_chk_rx_buffers(struct s2io_nic *nic, struct ring_info *ring)
  2483. {
  2484. if (fill_rx_buffers(nic, ring, 0) == -ENOMEM) {
  2485. DBG_PRINT(INFO_DBG, "%s: Out of memory in Rx Intr!!\n",
  2486. ring->dev->name);
  2487. }
  2488. return 0;
  2489. }
  2490. /**
  2491. * s2io_poll - Rx interrupt handler for NAPI support
  2492. * @napi : pointer to the napi structure.
  2493. * @budget : The number of packets that were budgeted to be processed
  2494. * during one pass through the 'Poll" function.
  2495. * Description:
  2496. * Comes into picture only if NAPI support has been incorporated. It does
  2497. * the same thing that rx_intr_handler does, but not in a interrupt context
  2498. * also It will process only a given number of packets.
  2499. * Return value:
  2500. * 0 on success and 1 if there are No Rx packets to be processed.
  2501. */
  2502. static int s2io_poll_msix(struct napi_struct *napi, int budget)
  2503. {
  2504. struct ring_info *ring = container_of(napi, struct ring_info, napi);
  2505. struct net_device *dev = ring->dev;
  2506. int pkts_processed = 0;
  2507. u8 __iomem *addr = NULL;
  2508. u8 val8 = 0;
  2509. struct s2io_nic *nic = netdev_priv(dev);
  2510. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  2511. int budget_org = budget;
  2512. if (unlikely(!is_s2io_card_up(nic)))
  2513. return 0;
  2514. pkts_processed = rx_intr_handler(ring, budget);
  2515. s2io_chk_rx_buffers(nic, ring);
  2516. if (pkts_processed < budget_org) {
  2517. napi_complete(napi);
  2518. /*Re Enable MSI-Rx Vector*/
  2519. addr = (u8 __iomem *)&bar0->xmsi_mask_reg;
  2520. addr += 7 - ring->ring_no;
  2521. val8 = (ring->ring_no == 0) ? 0x3f : 0xbf;
  2522. writeb(val8, addr);
  2523. val8 = readb(addr);
  2524. }
  2525. return pkts_processed;
  2526. }
  2527. static int s2io_poll_inta(struct napi_struct *napi, int budget)
  2528. {
  2529. struct s2io_nic *nic = container_of(napi, struct s2io_nic, napi);
  2530. int pkts_processed = 0;
  2531. int ring_pkts_processed, i;
  2532. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  2533. int budget_org = budget;
  2534. struct config_param *config = &nic->config;
  2535. struct mac_info *mac_control = &nic->mac_control;
  2536. if (unlikely(!is_s2io_card_up(nic)))
  2537. return 0;
  2538. for (i = 0; i < config->rx_ring_num; i++) {
  2539. struct ring_info *ring = &mac_control->rings[i];
  2540. ring_pkts_processed = rx_intr_handler(ring, budget);
  2541. s2io_chk_rx_buffers(nic, ring);
  2542. pkts_processed += ring_pkts_processed;
  2543. budget -= ring_pkts_processed;
  2544. if (budget <= 0)
  2545. break;
  2546. }
  2547. if (pkts_processed < budget_org) {
  2548. napi_complete(napi);
  2549. /* Re enable the Rx interrupts for the ring */
  2550. writeq(0, &bar0->rx_traffic_mask);
  2551. readl(&bar0->rx_traffic_mask);
  2552. }
  2553. return pkts_processed;
  2554. }
  2555. #ifdef CONFIG_NET_POLL_CONTROLLER
  2556. /**
  2557. * s2io_netpoll - netpoll event handler entry point
  2558. * @dev : pointer to the device structure.
  2559. * Description:
  2560. * This function will be called by upper layer to check for events on the
  2561. * interface in situations where interrupts are disabled. It is used for
  2562. * specific in-kernel networking tasks, such as remote consoles and kernel
  2563. * debugging over the network (example netdump in RedHat).
  2564. */
  2565. static void s2io_netpoll(struct net_device *dev)
  2566. {
  2567. struct s2io_nic *nic = netdev_priv(dev);
  2568. const int irq = nic->pdev->irq;
  2569. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  2570. u64 val64 = 0xFFFFFFFFFFFFFFFFULL;
  2571. int i;
  2572. struct config_param *config = &nic->config;
  2573. struct mac_info *mac_control = &nic->mac_control;
  2574. if (pci_channel_offline(nic->pdev))
  2575. return;
  2576. disable_irq(irq);
  2577. writeq(val64, &bar0->rx_traffic_int);
  2578. writeq(val64, &bar0->tx_traffic_int);
  2579. /* we need to free up the transmitted skbufs or else netpoll will
  2580. * run out of skbs and will fail and eventually netpoll application such
  2581. * as netdump will fail.
  2582. */
  2583. for (i = 0; i < config->tx_fifo_num; i++)
  2584. tx_intr_handler(&mac_control->fifos[i]);
  2585. /* check for received packet and indicate up to network */
  2586. for (i = 0; i < config->rx_ring_num; i++) {
  2587. struct ring_info *ring = &mac_control->rings[i];
  2588. rx_intr_handler(ring, 0);
  2589. }
  2590. for (i = 0; i < config->rx_ring_num; i++) {
  2591. struct ring_info *ring = &mac_control->rings[i];
  2592. if (fill_rx_buffers(nic, ring, 0) == -ENOMEM) {
  2593. DBG_PRINT(INFO_DBG,
  2594. "%s: Out of memory in Rx Netpoll!!\n",
  2595. dev->name);
  2596. break;
  2597. }
  2598. }
  2599. enable_irq(irq);
  2600. }
  2601. #endif
  2602. /**
  2603. * rx_intr_handler - Rx interrupt handler
  2604. * @ring_info: per ring structure.
  2605. * @budget: budget for napi processing.
  2606. * Description:
  2607. * If the interrupt is because of a received frame or if the
  2608. * receive ring contains fresh as yet un-processed frames,this function is
  2609. * called. It picks out the RxD at which place the last Rx processing had
  2610. * stopped and sends the skb to the OSM's Rx handler and then increments
  2611. * the offset.
  2612. * Return Value:
  2613. * No. of napi packets processed.
  2614. */
  2615. static int rx_intr_handler(struct ring_info *ring_data, int budget)
  2616. {
  2617. int get_block, put_block;
  2618. struct rx_curr_get_info get_info, put_info;
  2619. struct RxD_t *rxdp;
  2620. struct sk_buff *skb;
  2621. int pkt_cnt = 0, napi_pkts = 0;
  2622. int i;
  2623. struct RxD1 *rxdp1;
  2624. struct RxD3 *rxdp3;
  2625. get_info = ring_data->rx_curr_get_info;
  2626. get_block = get_info.block_index;
  2627. memcpy(&put_info, &ring_data->rx_curr_put_info, sizeof(put_info));
  2628. put_block = put_info.block_index;
  2629. rxdp = ring_data->rx_blocks[get_block].rxds[get_info.offset].virt_addr;
  2630. while (RXD_IS_UP2DT(rxdp)) {
  2631. /*
  2632. * If your are next to put index then it's
  2633. * FIFO full condition
  2634. */
  2635. if ((get_block == put_block) &&
  2636. (get_info.offset + 1) == put_info.offset) {
  2637. DBG_PRINT(INTR_DBG, "%s: Ring Full\n",
  2638. ring_data->dev->name);
  2639. break;
  2640. }
  2641. skb = (struct sk_buff *)((unsigned long)rxdp->Host_Control);
  2642. if (skb == NULL) {
  2643. DBG_PRINT(ERR_DBG, "%s: NULL skb in Rx Intr\n",
  2644. ring_data->dev->name);
  2645. return 0;
  2646. }
  2647. if (ring_data->rxd_mode == RXD_MODE_1) {
  2648. rxdp1 = (struct RxD1 *)rxdp;
  2649. pci_unmap_single(ring_data->pdev, (dma_addr_t)
  2650. rxdp1->Buffer0_ptr,
  2651. ring_data->mtu +
  2652. HEADER_ETHERNET_II_802_3_SIZE +
  2653. HEADER_802_2_SIZE +
  2654. HEADER_SNAP_SIZE,
  2655. PCI_DMA_FROMDEVICE);
  2656. } else if (ring_data->rxd_mode == RXD_MODE_3B) {
  2657. rxdp3 = (struct RxD3 *)rxdp;
  2658. pci_dma_sync_single_for_cpu(ring_data->pdev,
  2659. (dma_addr_t)rxdp3->Buffer0_ptr,
  2660. BUF0_LEN,
  2661. PCI_DMA_FROMDEVICE);
  2662. pci_unmap_single(ring_data->pdev,
  2663. (dma_addr_t)rxdp3->Buffer2_ptr,
  2664. ring_data->mtu + 4,
  2665. PCI_DMA_FROMDEVICE);
  2666. }
  2667. prefetch(skb->data);
  2668. rx_osm_handler(ring_data, rxdp);
  2669. get_info.offset++;
  2670. ring_data->rx_curr_get_info.offset = get_info.offset;
  2671. rxdp = ring_data->rx_blocks[get_block].
  2672. rxds[get_info.offset].virt_addr;
  2673. if (get_info.offset == rxd_count[ring_data->rxd_mode]) {
  2674. get_info.offset = 0;
  2675. ring_data->rx_curr_get_info.offset = get_info.offset;
  2676. get_block++;
  2677. if (get_block == ring_data->block_count)
  2678. get_block = 0;
  2679. ring_data->rx_curr_get_info.block_index = get_block;
  2680. rxdp = ring_data->rx_blocks[get_block].block_virt_addr;
  2681. }
  2682. if (ring_data->nic->config.napi) {
  2683. budget--;
  2684. napi_pkts++;
  2685. if (!budget)
  2686. break;
  2687. }
  2688. pkt_cnt++;
  2689. if ((indicate_max_pkts) && (pkt_cnt > indicate_max_pkts))
  2690. break;
  2691. }
  2692. if (ring_data->lro) {
  2693. /* Clear all LRO sessions before exiting */
  2694. for (i = 0; i < MAX_LRO_SESSIONS; i++) {
  2695. struct lro *lro = &ring_data->lro0_n[i];
  2696. if (lro->in_use) {
  2697. update_L3L4_header(ring_data->nic, lro);
  2698. queue_rx_frame(lro->parent, lro->vlan_tag);
  2699. clear_lro_session(lro);
  2700. }
  2701. }
  2702. }
  2703. return napi_pkts;
  2704. }
  2705. /**
  2706. * tx_intr_handler - Transmit interrupt handler
  2707. * @nic : device private variable
  2708. * Description:
  2709. * If an interrupt was raised to indicate DMA complete of the
  2710. * Tx packet, this function is called. It identifies the last TxD
  2711. * whose buffer was freed and frees all skbs whose data have already
  2712. * DMA'ed into the NICs internal memory.
  2713. * Return Value:
  2714. * NONE
  2715. */
  2716. static void tx_intr_handler(struct fifo_info *fifo_data)
  2717. {
  2718. struct s2io_nic *nic = fifo_data->nic;
  2719. struct tx_curr_get_info get_info, put_info;
  2720. struct sk_buff *skb = NULL;
  2721. struct TxD *txdlp;
  2722. int pkt_cnt = 0;
  2723. unsigned long flags = 0;
  2724. u8 err_mask;
  2725. struct stat_block *stats = nic->mac_control.stats_info;
  2726. struct swStat *swstats = &stats->sw_stat;
  2727. if (!spin_trylock_irqsave(&fifo_data->tx_lock, flags))
  2728. return;
  2729. get_info = fifo_data->tx_curr_get_info;
  2730. memcpy(&put_info, &fifo_data->tx_curr_put_info, sizeof(put_info));
  2731. txdlp = fifo_data->list_info[get_info.offset].list_virt_addr;
  2732. while ((!(txdlp->Control_1 & TXD_LIST_OWN_XENA)) &&
  2733. (get_info.offset != put_info.offset) &&
  2734. (txdlp->Host_Control)) {
  2735. /* Check for TxD errors */
  2736. if (txdlp->Control_1 & TXD_T_CODE) {
  2737. unsigned long long err;
  2738. err = txdlp->Control_1 & TXD_T_CODE;
  2739. if (err & 0x1) {
  2740. swstats->parity_err_cnt++;
  2741. }
  2742. /* update t_code statistics */
  2743. err_mask = err >> 48;
  2744. switch (err_mask) {
  2745. case 2:
  2746. swstats->tx_buf_abort_cnt++;
  2747. break;
  2748. case 3:
  2749. swstats->tx_desc_abort_cnt++;
  2750. break;
  2751. case 7:
  2752. swstats->tx_parity_err_cnt++;
  2753. break;
  2754. case 10:
  2755. swstats->tx_link_loss_cnt++;
  2756. break;
  2757. case 15:
  2758. swstats->tx_list_proc_err_cnt++;
  2759. break;
  2760. }
  2761. }
  2762. skb = s2io_txdl_getskb(fifo_data, txdlp, get_info.offset);
  2763. if (skb == NULL) {
  2764. spin_unlock_irqrestore(&fifo_data->tx_lock, flags);
  2765. DBG_PRINT(ERR_DBG, "%s: NULL skb in Tx Free Intr\n",
  2766. __func__);
  2767. return;
  2768. }
  2769. pkt_cnt++;
  2770. /* Updating the statistics block */
  2771. swstats->mem_freed += skb->truesize;
  2772. dev_kfree_skb_irq(skb);
  2773. get_info.offset++;
  2774. if (get_info.offset == get_info.fifo_len + 1)
  2775. get_info.offset = 0;
  2776. txdlp = fifo_data->list_info[get_info.offset].list_virt_addr;
  2777. fifo_data->tx_curr_get_info.offset = get_info.offset;
  2778. }
  2779. s2io_wake_tx_queue(fifo_data, pkt_cnt, nic->config.multiq);
  2780. spin_unlock_irqrestore(&fifo_data->tx_lock, flags);
  2781. }
  2782. /**
  2783. * s2io_mdio_write - Function to write in to MDIO registers
  2784. * @mmd_type : MMD type value (PMA/PMD/WIS/PCS/PHYXS)
  2785. * @addr : address value
  2786. * @value : data value
  2787. * @dev : pointer to net_device structure
  2788. * Description:
  2789. * This function is used to write values to the MDIO registers
  2790. * NONE
  2791. */
  2792. static void s2io_mdio_write(u32 mmd_type, u64 addr, u16 value,
  2793. struct net_device *dev)
  2794. {
  2795. u64 val64;
  2796. struct s2io_nic *sp = netdev_priv(dev);
  2797. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  2798. /* address transaction */
  2799. val64 = MDIO_MMD_INDX_ADDR(addr) |
  2800. MDIO_MMD_DEV_ADDR(mmd_type) |
  2801. MDIO_MMS_PRT_ADDR(0x0);
  2802. writeq(val64, &bar0->mdio_control);
  2803. val64 = val64 | MDIO_CTRL_START_TRANS(0xE);
  2804. writeq(val64, &bar0->mdio_control);
  2805. udelay(100);
  2806. /* Data transaction */
  2807. val64 = MDIO_MMD_INDX_ADDR(addr) |
  2808. MDIO_MMD_DEV_ADDR(mmd_type) |
  2809. MDIO_MMS_PRT_ADDR(0x0) |
  2810. MDIO_MDIO_DATA(value) |
  2811. MDIO_OP(MDIO_OP_WRITE_TRANS);
  2812. writeq(val64, &bar0->mdio_control);
  2813. val64 = val64 | MDIO_CTRL_START_TRANS(0xE);
  2814. writeq(val64, &bar0->mdio_control);
  2815. udelay(100);
  2816. val64 = MDIO_MMD_INDX_ADDR(addr) |
  2817. MDIO_MMD_DEV_ADDR(mmd_type) |
  2818. MDIO_MMS_PRT_ADDR(0x0) |
  2819. MDIO_OP(MDIO_OP_READ_TRANS);
  2820. writeq(val64, &bar0->mdio_control);
  2821. val64 = val64 | MDIO_CTRL_START_TRANS(0xE);
  2822. writeq(val64, &bar0->mdio_control);
  2823. udelay(100);
  2824. }
  2825. /**
  2826. * s2io_mdio_read - Function to write in to MDIO registers
  2827. * @mmd_type : MMD type value (PMA/PMD/WIS/PCS/PHYXS)
  2828. * @addr : address value
  2829. * @dev : pointer to net_device structure
  2830. * Description:
  2831. * This function is used to read values to the MDIO registers
  2832. * NONE
  2833. */
  2834. static u64 s2io_mdio_read(u32 mmd_type, u64 addr, struct net_device *dev)
  2835. {
  2836. u64 val64 = 0x0;
  2837. u64 rval64 = 0x0;
  2838. struct s2io_nic *sp = netdev_priv(dev);
  2839. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  2840. /* address transaction */
  2841. val64 = val64 | (MDIO_MMD_INDX_ADDR(addr)
  2842. | MDIO_MMD_DEV_ADDR(mmd_type)
  2843. | MDIO_MMS_PRT_ADDR(0x0));
  2844. writeq(val64, &bar0->mdio_control);
  2845. val64 = val64 | MDIO_CTRL_START_TRANS(0xE);
  2846. writeq(val64, &bar0->mdio_control);
  2847. udelay(100);
  2848. /* Data transaction */
  2849. val64 = MDIO_MMD_INDX_ADDR(addr) |
  2850. MDIO_MMD_DEV_ADDR(mmd_type) |
  2851. MDIO_MMS_PRT_ADDR(0x0) |
  2852. MDIO_OP(MDIO_OP_READ_TRANS);
  2853. writeq(val64, &bar0->mdio_control);
  2854. val64 = val64 | MDIO_CTRL_START_TRANS(0xE);
  2855. writeq(val64, &bar0->mdio_control);
  2856. udelay(100);
  2857. /* Read the value from regs */
  2858. rval64 = readq(&bar0->mdio_control);
  2859. rval64 = rval64 & 0xFFFF0000;
  2860. rval64 = rval64 >> 16;
  2861. return rval64;
  2862. }
  2863. /**
  2864. * s2io_chk_xpak_counter - Function to check the status of the xpak counters
  2865. * @counter : counter value to be updated
  2866. * @flag : flag to indicate the status
  2867. * @type : counter type
  2868. * Description:
  2869. * This function is to check the status of the xpak counters value
  2870. * NONE
  2871. */
  2872. static void s2io_chk_xpak_counter(u64 *counter, u64 * regs_stat, u32 index,
  2873. u16 flag, u16 type)
  2874. {
  2875. u64 mask = 0x3;
  2876. u64 val64;
  2877. int i;
  2878. for (i = 0; i < index; i++)
  2879. mask = mask << 0x2;
  2880. if (flag > 0) {
  2881. *counter = *counter + 1;
  2882. val64 = *regs_stat & mask;
  2883. val64 = val64 >> (index * 0x2);
  2884. val64 = val64 + 1;
  2885. if (val64 == 3) {
  2886. switch (type) {
  2887. case 1:
  2888. DBG_PRINT(ERR_DBG,
  2889. "Take Xframe NIC out of service.\n");
  2890. DBG_PRINT(ERR_DBG,
  2891. "Excessive temperatures may result in premature transceiver failure.\n");
  2892. break;
  2893. case 2:
  2894. DBG_PRINT(ERR_DBG,
  2895. "Take Xframe NIC out of service.\n");
  2896. DBG_PRINT(ERR_DBG,
  2897. "Excessive bias currents may indicate imminent laser diode failure.\n");
  2898. break;
  2899. case 3:
  2900. DBG_PRINT(ERR_DBG,
  2901. "Take Xframe NIC out of service.\n");
  2902. DBG_PRINT(ERR_DBG,
  2903. "Excessive laser output power may saturate far-end receiver.\n");
  2904. break;
  2905. default:
  2906. DBG_PRINT(ERR_DBG,
  2907. "Incorrect XPAK Alarm type\n");
  2908. }
  2909. val64 = 0x0;
  2910. }
  2911. val64 = val64 << (index * 0x2);
  2912. *regs_stat = (*regs_stat & (~mask)) | (val64);
  2913. } else {
  2914. *regs_stat = *regs_stat & (~mask);
  2915. }
  2916. }
  2917. /**
  2918. * s2io_updt_xpak_counter - Function to update the xpak counters
  2919. * @dev : pointer to net_device struct
  2920. * Description:
  2921. * This function is to upate the status of the xpak counters value
  2922. * NONE
  2923. */
  2924. static void s2io_updt_xpak_counter(struct net_device *dev)
  2925. {
  2926. u16 flag = 0x0;
  2927. u16 type = 0x0;
  2928. u16 val16 = 0x0;
  2929. u64 val64 = 0x0;
  2930. u64 addr = 0x0;
  2931. struct s2io_nic *sp = netdev_priv(dev);
  2932. struct stat_block *stats = sp->mac_control.stats_info;
  2933. struct xpakStat *xstats = &stats->xpak_stat;
  2934. /* Check the communication with the MDIO slave */
  2935. addr = MDIO_CTRL1;
  2936. val64 = 0x0;
  2937. val64 = s2io_mdio_read(MDIO_MMD_PMAPMD, addr, dev);
  2938. if ((val64 == 0xFFFF) || (val64 == 0x0000)) {
  2939. DBG_PRINT(ERR_DBG,
  2940. "ERR: MDIO slave access failed - Returned %llx\n",
  2941. (unsigned long long)val64);
  2942. return;
  2943. }
  2944. /* Check for the expected value of control reg 1 */
  2945. if (val64 != MDIO_CTRL1_SPEED10G) {
  2946. DBG_PRINT(ERR_DBG, "Incorrect value at PMA address 0x0000 - "
  2947. "Returned: %llx- Expected: 0x%x\n",
  2948. (unsigned long long)val64, MDIO_CTRL1_SPEED10G);
  2949. return;
  2950. }
  2951. /* Loading the DOM register to MDIO register */
  2952. addr = 0xA100;
  2953. s2io_mdio_write(MDIO_MMD_PMAPMD, addr, val16, dev);
  2954. val64 = s2io_mdio_read(MDIO_MMD_PMAPMD, addr, dev);
  2955. /* Reading the Alarm flags */
  2956. addr = 0xA070;
  2957. val64 = 0x0;
  2958. val64 = s2io_mdio_read(MDIO_MMD_PMAPMD, addr, dev);
  2959. flag = CHECKBIT(val64, 0x7);
  2960. type = 1;
  2961. s2io_chk_xpak_counter(&xstats->alarm_transceiver_temp_high,
  2962. &xstats->xpak_regs_stat,
  2963. 0x0, flag, type);
  2964. if (CHECKBIT(val64, 0x6))
  2965. xstats->alarm_transceiver_temp_low++;
  2966. flag = CHECKBIT(val64, 0x3);
  2967. type = 2;
  2968. s2io_chk_xpak_counter(&xstats->alarm_laser_bias_current_high,
  2969. &xstats->xpak_regs_stat,
  2970. 0x2, flag, type);
  2971. if (CHECKBIT(val64, 0x2))
  2972. xstats->alarm_laser_bias_current_low++;
  2973. flag = CHECKBIT(val64, 0x1);
  2974. type = 3;
  2975. s2io_chk_xpak_counter(&xstats->alarm_laser_output_power_high,
  2976. &xstats->xpak_regs_stat,
  2977. 0x4, flag, type);
  2978. if (CHECKBIT(val64, 0x0))
  2979. xstats->alarm_laser_output_power_low++;
  2980. /* Reading the Warning flags */
  2981. addr = 0xA074;
  2982. val64 = 0x0;
  2983. val64 = s2io_mdio_read(MDIO_MMD_PMAPMD, addr, dev);
  2984. if (CHECKBIT(val64, 0x7))
  2985. xstats->warn_transceiver_temp_high++;
  2986. if (CHECKBIT(val64, 0x6))
  2987. xstats->warn_transceiver_temp_low++;
  2988. if (CHECKBIT(val64, 0x3))
  2989. xstats->warn_laser_bias_current_high++;
  2990. if (CHECKBIT(val64, 0x2))
  2991. xstats->warn_laser_bias_current_low++;
  2992. if (CHECKBIT(val64, 0x1))
  2993. xstats->warn_laser_output_power_high++;
  2994. if (CHECKBIT(val64, 0x0))
  2995. xstats->warn_laser_output_power_low++;
  2996. }
  2997. /**
  2998. * wait_for_cmd_complete - waits for a command to complete.
  2999. * @sp : private member of the device structure, which is a pointer to the
  3000. * s2io_nic structure.
  3001. * Description: Function that waits for a command to Write into RMAC
  3002. * ADDR DATA registers to be completed and returns either success or
  3003. * error depending on whether the command was complete or not.
  3004. * Return value:
  3005. * SUCCESS on success and FAILURE on failure.
  3006. */
  3007. static int wait_for_cmd_complete(void __iomem *addr, u64 busy_bit,
  3008. int bit_state)
  3009. {
  3010. int ret = FAILURE, cnt = 0, delay = 1;
  3011. u64 val64;
  3012. if ((bit_state != S2IO_BIT_RESET) && (bit_state != S2IO_BIT_SET))
  3013. return FAILURE;
  3014. do {
  3015. val64 = readq(addr);
  3016. if (bit_state == S2IO_BIT_RESET) {
  3017. if (!(val64 & busy_bit)) {
  3018. ret = SUCCESS;
  3019. break;
  3020. }
  3021. } else {
  3022. if (val64 & busy_bit) {
  3023. ret = SUCCESS;
  3024. break;
  3025. }
  3026. }
  3027. if (in_interrupt())
  3028. mdelay(delay);
  3029. else
  3030. msleep(delay);
  3031. if (++cnt >= 10)
  3032. delay = 50;
  3033. } while (cnt < 20);
  3034. return ret;
  3035. }
  3036. /*
  3037. * check_pci_device_id - Checks if the device id is supported
  3038. * @id : device id
  3039. * Description: Function to check if the pci device id is supported by driver.
  3040. * Return value: Actual device id if supported else PCI_ANY_ID
  3041. */
  3042. static u16 check_pci_device_id(u16 id)
  3043. {
  3044. switch (id) {
  3045. case PCI_DEVICE_ID_HERC_WIN:
  3046. case PCI_DEVICE_ID_HERC_UNI:
  3047. return XFRAME_II_DEVICE;
  3048. case PCI_DEVICE_ID_S2IO_UNI:
  3049. case PCI_DEVICE_ID_S2IO_WIN:
  3050. return XFRAME_I_DEVICE;
  3051. default:
  3052. return PCI_ANY_ID;
  3053. }
  3054. }
  3055. /**
  3056. * s2io_reset - Resets the card.
  3057. * @sp : private member of the device structure.
  3058. * Description: Function to Reset the card. This function then also
  3059. * restores the previously saved PCI configuration space registers as
  3060. * the card reset also resets the configuration space.
  3061. * Return value:
  3062. * void.
  3063. */
  3064. static void s2io_reset(struct s2io_nic *sp)
  3065. {
  3066. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  3067. u64 val64;
  3068. u16 subid, pci_cmd;
  3069. int i;
  3070. u16 val16;
  3071. unsigned long long up_cnt, down_cnt, up_time, down_time, reset_cnt;
  3072. unsigned long long mem_alloc_cnt, mem_free_cnt, watchdog_cnt;
  3073. struct stat_block *stats;
  3074. struct swStat *swstats;
  3075. DBG_PRINT(INIT_DBG, "%s: Resetting XFrame card %s\n",
  3076. __func__, pci_name(sp->pdev));
  3077. /* Back up the PCI-X CMD reg, dont want to lose MMRBC, OST settings */
  3078. pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER, &(pci_cmd));
  3079. val64 = SW_RESET_ALL;
  3080. writeq(val64, &bar0->sw_reset);
  3081. if (strstr(sp->product_name, "CX4"))
  3082. msleep(750);
  3083. msleep(250);
  3084. for (i = 0; i < S2IO_MAX_PCI_CONFIG_SPACE_REINIT; i++) {
  3085. /* Restore the PCI state saved during initialization. */
  3086. pci_restore_state(sp->pdev);
  3087. pci_save_state(sp->pdev);
  3088. pci_read_config_word(sp->pdev, 0x2, &val16);
  3089. if (check_pci_device_id(val16) != (u16)PCI_ANY_ID)
  3090. break;
  3091. msleep(200);
  3092. }
  3093. if (check_pci_device_id(val16) == (u16)PCI_ANY_ID)
  3094. DBG_PRINT(ERR_DBG, "%s SW_Reset failed!\n", __func__);
  3095. pci_write_config_word(sp->pdev, PCIX_COMMAND_REGISTER, pci_cmd);
  3096. s2io_init_pci(sp);
  3097. /* Set swapper to enable I/O register access */
  3098. s2io_set_swapper(sp);
  3099. /* restore mac_addr entries */
  3100. do_s2io_restore_unicast_mc(sp);
  3101. /* Restore the MSIX table entries from local variables */
  3102. restore_xmsi_data(sp);
  3103. /* Clear certain PCI/PCI-X fields after reset */
  3104. if (sp->device_type == XFRAME_II_DEVICE) {
  3105. /* Clear "detected parity error" bit */
  3106. pci_write_config_word(sp->pdev, PCI_STATUS, 0x8000);
  3107. /* Clearing PCIX Ecc status register */
  3108. pci_write_config_dword(sp->pdev, 0x68, 0x7C);
  3109. /* Clearing PCI_STATUS error reflected here */
  3110. writeq(s2BIT(62), &bar0->txpic_int_reg);
  3111. }
  3112. /* Reset device statistics maintained by OS */
  3113. memset(&sp->stats, 0, sizeof(struct net_device_stats));
  3114. stats = sp->mac_control.stats_info;
  3115. swstats = &stats->sw_stat;
  3116. /* save link up/down time/cnt, reset/memory/watchdog cnt */
  3117. up_cnt = swstats->link_up_cnt;
  3118. down_cnt = swstats->link_down_cnt;
  3119. up_time = swstats->link_up_time;
  3120. down_time = swstats->link_down_time;
  3121. reset_cnt = swstats->soft_reset_cnt;
  3122. mem_alloc_cnt = swstats->mem_allocated;
  3123. mem_free_cnt = swstats->mem_freed;
  3124. watchdog_cnt = swstats->watchdog_timer_cnt;
  3125. memset(stats, 0, sizeof(struct stat_block));
  3126. /* restore link up/down time/cnt, reset/memory/watchdog cnt */
  3127. swstats->link_up_cnt = up_cnt;
  3128. swstats->link_down_cnt = down_cnt;
  3129. swstats->link_up_time = up_time;
  3130. swstats->link_down_time = down_time;
  3131. swstats->soft_reset_cnt = reset_cnt;
  3132. swstats->mem_allocated = mem_alloc_cnt;
  3133. swstats->mem_freed = mem_free_cnt;
  3134. swstats->watchdog_timer_cnt = watchdog_cnt;
  3135. /* SXE-002: Configure link and activity LED to turn it off */
  3136. subid = sp->pdev->subsystem_device;
  3137. if (((subid & 0xFF) >= 0x07) &&
  3138. (sp->device_type == XFRAME_I_DEVICE)) {
  3139. val64 = readq(&bar0->gpio_control);
  3140. val64 |= 0x0000800000000000ULL;
  3141. writeq(val64, &bar0->gpio_control);
  3142. val64 = 0x0411040400000000ULL;
  3143. writeq(val64, (void __iomem *)bar0 + 0x2700);
  3144. }
  3145. /*
  3146. * Clear spurious ECC interrupts that would have occurred on
  3147. * XFRAME II cards after reset.
  3148. */
  3149. if (sp->device_type == XFRAME_II_DEVICE) {
  3150. val64 = readq(&bar0->pcc_err_reg);
  3151. writeq(val64, &bar0->pcc_err_reg);
  3152. }
  3153. sp->device_enabled_once = false;
  3154. }
  3155. /**
  3156. * s2io_set_swapper - to set the swapper controle on the card
  3157. * @sp : private member of the device structure,
  3158. * pointer to the s2io_nic structure.
  3159. * Description: Function to set the swapper control on the card
  3160. * correctly depending on the 'endianness' of the system.
  3161. * Return value:
  3162. * SUCCESS on success and FAILURE on failure.
  3163. */
  3164. static int s2io_set_swapper(struct s2io_nic *sp)
  3165. {
  3166. struct net_device *dev = sp->dev;
  3167. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  3168. u64 val64, valt, valr;
  3169. /*
  3170. * Set proper endian settings and verify the same by reading
  3171. * the PIF Feed-back register.
  3172. */
  3173. val64 = readq(&bar0->pif_rd_swapper_fb);
  3174. if (val64 != 0x0123456789ABCDEFULL) {
  3175. int i = 0;
  3176. static const u64 value[] = {
  3177. 0xC30000C3C30000C3ULL, /* FE=1, SE=1 */
  3178. 0x8100008181000081ULL, /* FE=1, SE=0 */
  3179. 0x4200004242000042ULL, /* FE=0, SE=1 */
  3180. 0 /* FE=0, SE=0 */
  3181. };
  3182. while (i < 4) {
  3183. writeq(value[i], &bar0->swapper_ctrl);
  3184. val64 = readq(&bar0->pif_rd_swapper_fb);
  3185. if (val64 == 0x0123456789ABCDEFULL)
  3186. break;
  3187. i++;
  3188. }
  3189. if (i == 4) {
  3190. DBG_PRINT(ERR_DBG, "%s: Endian settings are wrong, "
  3191. "feedback read %llx\n",
  3192. dev->name, (unsigned long long)val64);
  3193. return FAILURE;
  3194. }
  3195. valr = value[i];
  3196. } else {
  3197. valr = readq(&bar0->swapper_ctrl);
  3198. }
  3199. valt = 0x0123456789ABCDEFULL;
  3200. writeq(valt, &bar0->xmsi_address);
  3201. val64 = readq(&bar0->xmsi_address);
  3202. if (val64 != valt) {
  3203. int i = 0;
  3204. static const u64 value[] = {
  3205. 0x00C3C30000C3C300ULL, /* FE=1, SE=1 */
  3206. 0x0081810000818100ULL, /* FE=1, SE=0 */
  3207. 0x0042420000424200ULL, /* FE=0, SE=1 */
  3208. 0 /* FE=0, SE=0 */
  3209. };
  3210. while (i < 4) {
  3211. writeq((value[i] | valr), &bar0->swapper_ctrl);
  3212. writeq(valt, &bar0->xmsi_address);
  3213. val64 = readq(&bar0->xmsi_address);
  3214. if (val64 == valt)
  3215. break;
  3216. i++;
  3217. }
  3218. if (i == 4) {
  3219. unsigned long long x = val64;
  3220. DBG_PRINT(ERR_DBG,
  3221. "Write failed, Xmsi_addr reads:0x%llx\n", x);
  3222. return FAILURE;
  3223. }
  3224. }
  3225. val64 = readq(&bar0->swapper_ctrl);
  3226. val64 &= 0xFFFF000000000000ULL;
  3227. #ifdef __BIG_ENDIAN
  3228. /*
  3229. * The device by default set to a big endian format, so a
  3230. * big endian driver need not set anything.
  3231. */
  3232. val64 |= (SWAPPER_CTRL_TXP_FE |
  3233. SWAPPER_CTRL_TXP_SE |
  3234. SWAPPER_CTRL_TXD_R_FE |
  3235. SWAPPER_CTRL_TXD_W_FE |
  3236. SWAPPER_CTRL_TXF_R_FE |
  3237. SWAPPER_CTRL_RXD_R_FE |
  3238. SWAPPER_CTRL_RXD_W_FE |
  3239. SWAPPER_CTRL_RXF_W_FE |
  3240. SWAPPER_CTRL_XMSI_FE |
  3241. SWAPPER_CTRL_STATS_FE |
  3242. SWAPPER_CTRL_STATS_SE);
  3243. if (sp->config.intr_type == INTA)
  3244. val64 |= SWAPPER_CTRL_XMSI_SE;
  3245. writeq(val64, &bar0->swapper_ctrl);
  3246. #else
  3247. /*
  3248. * Initially we enable all bits to make it accessible by the
  3249. * driver, then we selectively enable only those bits that
  3250. * we want to set.
  3251. */
  3252. val64 |= (SWAPPER_CTRL_TXP_FE |
  3253. SWAPPER_CTRL_TXP_SE |
  3254. SWAPPER_CTRL_TXD_R_FE |
  3255. SWAPPER_CTRL_TXD_R_SE |
  3256. SWAPPER_CTRL_TXD_W_FE |
  3257. SWAPPER_CTRL_TXD_W_SE |
  3258. SWAPPER_CTRL_TXF_R_FE |
  3259. SWAPPER_CTRL_RXD_R_FE |
  3260. SWAPPER_CTRL_RXD_R_SE |
  3261. SWAPPER_CTRL_RXD_W_FE |
  3262. SWAPPER_CTRL_RXD_W_SE |
  3263. SWAPPER_CTRL_RXF_W_FE |
  3264. SWAPPER_CTRL_XMSI_FE |
  3265. SWAPPER_CTRL_STATS_FE |
  3266. SWAPPER_CTRL_STATS_SE);
  3267. if (sp->config.intr_type == INTA)
  3268. val64 |= SWAPPER_CTRL_XMSI_SE;
  3269. writeq(val64, &bar0->swapper_ctrl);
  3270. #endif
  3271. val64 = readq(&bar0->swapper_ctrl);
  3272. /*
  3273. * Verifying if endian settings are accurate by reading a
  3274. * feedback register.
  3275. */
  3276. val64 = readq(&bar0->pif_rd_swapper_fb);
  3277. if (val64 != 0x0123456789ABCDEFULL) {
  3278. /* Endian settings are incorrect, calls for another dekko. */
  3279. DBG_PRINT(ERR_DBG,
  3280. "%s: Endian settings are wrong, feedback read %llx\n",
  3281. dev->name, (unsigned long long)val64);
  3282. return FAILURE;
  3283. }
  3284. return SUCCESS;
  3285. }
  3286. static int wait_for_msix_trans(struct s2io_nic *nic, int i)
  3287. {
  3288. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  3289. u64 val64;
  3290. int ret = 0, cnt = 0;
  3291. do {
  3292. val64 = readq(&bar0->xmsi_access);
  3293. if (!(val64 & s2BIT(15)))
  3294. break;
  3295. mdelay(1);
  3296. cnt++;
  3297. } while (cnt < 5);
  3298. if (cnt == 5) {
  3299. DBG_PRINT(ERR_DBG, "XMSI # %d Access failed\n", i);
  3300. ret = 1;
  3301. }
  3302. return ret;
  3303. }
  3304. static void restore_xmsi_data(struct s2io_nic *nic)
  3305. {
  3306. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  3307. u64 val64;
  3308. int i, msix_index;
  3309. if (nic->device_type == XFRAME_I_DEVICE)
  3310. return;
  3311. for (i = 0; i < MAX_REQUESTED_MSI_X; i++) {
  3312. msix_index = (i) ? ((i-1) * 8 + 1) : 0;
  3313. writeq(nic->msix_info[i].addr, &bar0->xmsi_address);
  3314. writeq(nic->msix_info[i].data, &bar0->xmsi_data);
  3315. val64 = (s2BIT(7) | s2BIT(15) | vBIT(msix_index, 26, 6));
  3316. writeq(val64, &bar0->xmsi_access);
  3317. if (wait_for_msix_trans(nic, msix_index)) {
  3318. DBG_PRINT(ERR_DBG, "%s: index: %d failed\n",
  3319. __func__, msix_index);
  3320. continue;
  3321. }
  3322. }
  3323. }
  3324. static void store_xmsi_data(struct s2io_nic *nic)
  3325. {
  3326. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  3327. u64 val64, addr, data;
  3328. int i, msix_index;
  3329. if (nic->device_type == XFRAME_I_DEVICE)
  3330. return;
  3331. /* Store and display */
  3332. for (i = 0; i < MAX_REQUESTED_MSI_X; i++) {
  3333. msix_index = (i) ? ((i-1) * 8 + 1) : 0;
  3334. val64 = (s2BIT(15) | vBIT(msix_index, 26, 6));
  3335. writeq(val64, &bar0->xmsi_access);
  3336. if (wait_for_msix_trans(nic, msix_index)) {
  3337. DBG_PRINT(ERR_DBG, "%s: index: %d failed\n",
  3338. __func__, msix_index);
  3339. continue;
  3340. }
  3341. addr = readq(&bar0->xmsi_address);
  3342. data = readq(&bar0->xmsi_data);
  3343. if (addr && data) {
  3344. nic->msix_info[i].addr = addr;
  3345. nic->msix_info[i].data = data;
  3346. }
  3347. }
  3348. }
  3349. static int s2io_enable_msi_x(struct s2io_nic *nic)
  3350. {
  3351. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  3352. u64 rx_mat;
  3353. u16 msi_control; /* Temp variable */
  3354. int ret, i, j, msix_indx = 1;
  3355. int size;
  3356. struct stat_block *stats = nic->mac_control.stats_info;
  3357. struct swStat *swstats = &stats->sw_stat;
  3358. size = nic->num_entries * sizeof(struct msix_entry);
  3359. nic->entries = kzalloc(size, GFP_KERNEL);
  3360. if (!nic->entries) {
  3361. DBG_PRINT(INFO_DBG, "%s: Memory allocation failed\n",
  3362. __func__);
  3363. swstats->mem_alloc_fail_cnt++;
  3364. return -ENOMEM;
  3365. }
  3366. swstats->mem_allocated += size;
  3367. size = nic->num_entries * sizeof(struct s2io_msix_entry);
  3368. nic->s2io_entries = kzalloc(size, GFP_KERNEL);
  3369. if (!nic->s2io_entries) {
  3370. DBG_PRINT(INFO_DBG, "%s: Memory allocation failed\n",
  3371. __func__);
  3372. swstats->mem_alloc_fail_cnt++;
  3373. kfree(nic->entries);
  3374. swstats->mem_freed
  3375. += (nic->num_entries * sizeof(struct msix_entry));
  3376. return -ENOMEM;
  3377. }
  3378. swstats->mem_allocated += size;
  3379. nic->entries[0].entry = 0;
  3380. nic->s2io_entries[0].entry = 0;
  3381. nic->s2io_entries[0].in_use = MSIX_FLG;
  3382. nic->s2io_entries[0].type = MSIX_ALARM_TYPE;
  3383. nic->s2io_entries[0].arg = &nic->mac_control.fifos;
  3384. for (i = 1; i < nic->num_entries; i++) {
  3385. nic->entries[i].entry = ((i - 1) * 8) + 1;
  3386. nic->s2io_entries[i].entry = ((i - 1) * 8) + 1;
  3387. nic->s2io_entries[i].arg = NULL;
  3388. nic->s2io_entries[i].in_use = 0;
  3389. }
  3390. rx_mat = readq(&bar0->rx_mat);
  3391. for (j = 0; j < nic->config.rx_ring_num; j++) {
  3392. rx_mat |= RX_MAT_SET(j, msix_indx);
  3393. nic->s2io_entries[j+1].arg = &nic->mac_control.rings[j];
  3394. nic->s2io_entries[j+1].type = MSIX_RING_TYPE;
  3395. nic->s2io_entries[j+1].in_use = MSIX_FLG;
  3396. msix_indx += 8;
  3397. }
  3398. writeq(rx_mat, &bar0->rx_mat);
  3399. readq(&bar0->rx_mat);
  3400. ret = pci_enable_msix(nic->pdev, nic->entries, nic->num_entries);
  3401. /* We fail init if error or we get less vectors than min required */
  3402. if (ret) {
  3403. DBG_PRINT(ERR_DBG, "Enabling MSI-X failed\n");
  3404. kfree(nic->entries);
  3405. swstats->mem_freed += nic->num_entries *
  3406. sizeof(struct msix_entry);
  3407. kfree(nic->s2io_entries);
  3408. swstats->mem_freed += nic->num_entries *
  3409. sizeof(struct s2io_msix_entry);
  3410. nic->entries = NULL;
  3411. nic->s2io_entries = NULL;
  3412. return -ENOMEM;
  3413. }
  3414. /*
  3415. * To enable MSI-X, MSI also needs to be enabled, due to a bug
  3416. * in the herc NIC. (Temp change, needs to be removed later)
  3417. */
  3418. pci_read_config_word(nic->pdev, 0x42, &msi_control);
  3419. msi_control |= 0x1; /* Enable MSI */
  3420. pci_write_config_word(nic->pdev, 0x42, msi_control);
  3421. return 0;
  3422. }
  3423. /* Handle software interrupt used during MSI(X) test */
  3424. static irqreturn_t s2io_test_intr(int irq, void *dev_id)
  3425. {
  3426. struct s2io_nic *sp = dev_id;
  3427. sp->msi_detected = 1;
  3428. wake_up(&sp->msi_wait);
  3429. return IRQ_HANDLED;
  3430. }
  3431. /* Test interrupt path by forcing a a software IRQ */
  3432. static int s2io_test_msi(struct s2io_nic *sp)
  3433. {
  3434. struct pci_dev *pdev = sp->pdev;
  3435. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  3436. int err;
  3437. u64 val64, saved64;
  3438. err = request_irq(sp->entries[1].vector, s2io_test_intr, 0,
  3439. sp->name, sp);
  3440. if (err) {
  3441. DBG_PRINT(ERR_DBG, "%s: PCI %s: cannot assign irq %d\n",
  3442. sp->dev->name, pci_name(pdev), pdev->irq);
  3443. return err;
  3444. }
  3445. init_waitqueue_head(&sp->msi_wait);
  3446. sp->msi_detected = 0;
  3447. saved64 = val64 = readq(&bar0->scheduled_int_ctrl);
  3448. val64 |= SCHED_INT_CTRL_ONE_SHOT;
  3449. val64 |= SCHED_INT_CTRL_TIMER_EN;
  3450. val64 |= SCHED_INT_CTRL_INT2MSI(1);
  3451. writeq(val64, &bar0->scheduled_int_ctrl);
  3452. wait_event_timeout(sp->msi_wait, sp->msi_detected, HZ/10);
  3453. if (!sp->msi_detected) {
  3454. /* MSI(X) test failed, go back to INTx mode */
  3455. DBG_PRINT(ERR_DBG, "%s: PCI %s: No interrupt was generated "
  3456. "using MSI(X) during test\n",
  3457. sp->dev->name, pci_name(pdev));
  3458. err = -EOPNOTSUPP;
  3459. }
  3460. free_irq(sp->entries[1].vector, sp);
  3461. writeq(saved64, &bar0->scheduled_int_ctrl);
  3462. return err;
  3463. }
  3464. static void remove_msix_isr(struct s2io_nic *sp)
  3465. {
  3466. int i;
  3467. u16 msi_control;
  3468. for (i = 0; i < sp->num_entries; i++) {
  3469. if (sp->s2io_entries[i].in_use == MSIX_REGISTERED_SUCCESS) {
  3470. int vector = sp->entries[i].vector;
  3471. void *arg = sp->s2io_entries[i].arg;
  3472. free_irq(vector, arg);
  3473. }
  3474. }
  3475. kfree(sp->entries);
  3476. kfree(sp->s2io_entries);
  3477. sp->entries = NULL;
  3478. sp->s2io_entries = NULL;
  3479. pci_read_config_word(sp->pdev, 0x42, &msi_control);
  3480. msi_control &= 0xFFFE; /* Disable MSI */
  3481. pci_write_config_word(sp->pdev, 0x42, msi_control);
  3482. pci_disable_msix(sp->pdev);
  3483. }
  3484. static void remove_inta_isr(struct s2io_nic *sp)
  3485. {
  3486. free_irq(sp->pdev->irq, sp->dev);
  3487. }
  3488. /* ********************************************************* *
  3489. * Functions defined below concern the OS part of the driver *
  3490. * ********************************************************* */
  3491. /**
  3492. * s2io_open - open entry point of the driver
  3493. * @dev : pointer to the device structure.
  3494. * Description:
  3495. * This function is the open entry point of the driver. It mainly calls a
  3496. * function to allocate Rx buffers and inserts them into the buffer
  3497. * descriptors and then enables the Rx part of the NIC.
  3498. * Return value:
  3499. * 0 on success and an appropriate (-)ve integer as defined in errno.h
  3500. * file on failure.
  3501. */
  3502. static int s2io_open(struct net_device *dev)
  3503. {
  3504. struct s2io_nic *sp = netdev_priv(dev);
  3505. struct swStat *swstats = &sp->mac_control.stats_info->sw_stat;
  3506. int err = 0;
  3507. /*
  3508. * Make sure you have link off by default every time
  3509. * Nic is initialized
  3510. */
  3511. netif_carrier_off(dev);
  3512. sp->last_link_state = 0;
  3513. /* Initialize H/W and enable interrupts */
  3514. err = s2io_card_up(sp);
  3515. if (err) {
  3516. DBG_PRINT(ERR_DBG, "%s: H/W initialization failed\n",
  3517. dev->name);
  3518. goto hw_init_failed;
  3519. }
  3520. if (do_s2io_prog_unicast(dev, dev->dev_addr) == FAILURE) {
  3521. DBG_PRINT(ERR_DBG, "Set Mac Address Failed\n");
  3522. s2io_card_down(sp);
  3523. err = -ENODEV;
  3524. goto hw_init_failed;
  3525. }
  3526. s2io_start_all_tx_queue(sp);
  3527. return 0;
  3528. hw_init_failed:
  3529. if (sp->config.intr_type == MSI_X) {
  3530. if (sp->entries) {
  3531. kfree(sp->entries);
  3532. swstats->mem_freed += sp->num_entries *
  3533. sizeof(struct msix_entry);
  3534. }
  3535. if (sp->s2io_entries) {
  3536. kfree(sp->s2io_entries);
  3537. swstats->mem_freed += sp->num_entries *
  3538. sizeof(struct s2io_msix_entry);
  3539. }
  3540. }
  3541. return err;
  3542. }
  3543. /**
  3544. * s2io_close -close entry point of the driver
  3545. * @dev : device pointer.
  3546. * Description:
  3547. * This is the stop entry point of the driver. It needs to undo exactly
  3548. * whatever was done by the open entry point,thus it's usually referred to
  3549. * as the close function.Among other things this function mainly stops the
  3550. * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
  3551. * Return value:
  3552. * 0 on success and an appropriate (-)ve integer as defined in errno.h
  3553. * file on failure.
  3554. */
  3555. static int s2io_close(struct net_device *dev)
  3556. {
  3557. struct s2io_nic *sp = netdev_priv(dev);
  3558. struct config_param *config = &sp->config;
  3559. u64 tmp64;
  3560. int offset;
  3561. /* Return if the device is already closed *
  3562. * Can happen when s2io_card_up failed in change_mtu *
  3563. */
  3564. if (!is_s2io_card_up(sp))
  3565. return 0;
  3566. s2io_stop_all_tx_queue(sp);
  3567. /* delete all populated mac entries */
  3568. for (offset = 1; offset < config->max_mc_addr; offset++) {
  3569. tmp64 = do_s2io_read_unicast_mc(sp, offset);
  3570. if (tmp64 != S2IO_DISABLE_MAC_ENTRY)
  3571. do_s2io_delete_unicast_mc(sp, tmp64);
  3572. }
  3573. s2io_card_down(sp);
  3574. return 0;
  3575. }
  3576. /**
  3577. * s2io_xmit - Tx entry point of te driver
  3578. * @skb : the socket buffer containing the Tx data.
  3579. * @dev : device pointer.
  3580. * Description :
  3581. * This function is the Tx entry point of the driver. S2IO NIC supports
  3582. * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
  3583. * NOTE: when device can't queue the pkt,just the trans_start variable will
  3584. * not be upadted.
  3585. * Return value:
  3586. * 0 on success & 1 on failure.
  3587. */
  3588. static netdev_tx_t s2io_xmit(struct sk_buff *skb, struct net_device *dev)
  3589. {
  3590. struct s2io_nic *sp = netdev_priv(dev);
  3591. u16 frg_cnt, frg_len, i, queue, queue_len, put_off, get_off;
  3592. register u64 val64;
  3593. struct TxD *txdp;
  3594. struct TxFIFO_element __iomem *tx_fifo;
  3595. unsigned long flags = 0;
  3596. u16 vlan_tag = 0;
  3597. struct fifo_info *fifo = NULL;
  3598. int do_spin_lock = 1;
  3599. int offload_type;
  3600. int enable_per_list_interrupt = 0;
  3601. struct config_param *config = &sp->config;
  3602. struct mac_info *mac_control = &sp->mac_control;
  3603. struct stat_block *stats = mac_control->stats_info;
  3604. struct swStat *swstats = &stats->sw_stat;
  3605. DBG_PRINT(TX_DBG, "%s: In Neterion Tx routine\n", dev->name);
  3606. if (unlikely(skb->len <= 0)) {
  3607. DBG_PRINT(TX_DBG, "%s: Buffer has no data..\n", dev->name);
  3608. dev_kfree_skb_any(skb);
  3609. return NETDEV_TX_OK;
  3610. }
  3611. if (!is_s2io_card_up(sp)) {
  3612. DBG_PRINT(TX_DBG, "%s: Card going down for reset\n",
  3613. dev->name);
  3614. dev_kfree_skb(skb);
  3615. return NETDEV_TX_OK;
  3616. }
  3617. queue = 0;
  3618. if (vlan_tx_tag_present(skb))
  3619. vlan_tag = vlan_tx_tag_get(skb);
  3620. if (sp->config.tx_steering_type == TX_DEFAULT_STEERING) {
  3621. if (skb->protocol == htons(ETH_P_IP)) {
  3622. struct iphdr *ip;
  3623. struct tcphdr *th;
  3624. ip = ip_hdr(skb);
  3625. if (!ip_is_fragment(ip)) {
  3626. th = (struct tcphdr *)(((unsigned char *)ip) +
  3627. ip->ihl*4);
  3628. if (ip->protocol == IPPROTO_TCP) {
  3629. queue_len = sp->total_tcp_fifos;
  3630. queue = (ntohs(th->source) +
  3631. ntohs(th->dest)) &
  3632. sp->fifo_selector[queue_len - 1];
  3633. if (queue >= queue_len)
  3634. queue = queue_len - 1;
  3635. } else if (ip->protocol == IPPROTO_UDP) {
  3636. queue_len = sp->total_udp_fifos;
  3637. queue = (ntohs(th->source) +
  3638. ntohs(th->dest)) &
  3639. sp->fifo_selector[queue_len - 1];
  3640. if (queue >= queue_len)
  3641. queue = queue_len - 1;
  3642. queue += sp->udp_fifo_idx;
  3643. if (skb->len > 1024)
  3644. enable_per_list_interrupt = 1;
  3645. do_spin_lock = 0;
  3646. }
  3647. }
  3648. }
  3649. } else if (sp->config.tx_steering_type == TX_PRIORITY_STEERING)
  3650. /* get fifo number based on skb->priority value */
  3651. queue = config->fifo_mapping
  3652. [skb->priority & (MAX_TX_FIFOS - 1)];
  3653. fifo = &mac_control->fifos[queue];
  3654. if (do_spin_lock)
  3655. spin_lock_irqsave(&fifo->tx_lock, flags);
  3656. else {
  3657. if (unlikely(!spin_trylock_irqsave(&fifo->tx_lock, flags)))
  3658. return NETDEV_TX_LOCKED;
  3659. }
  3660. if (sp->config.multiq) {
  3661. if (__netif_subqueue_stopped(dev, fifo->fifo_no)) {
  3662. spin_unlock_irqrestore(&fifo->tx_lock, flags);
  3663. return NETDEV_TX_BUSY;
  3664. }
  3665. } else if (unlikely(fifo->queue_state == FIFO_QUEUE_STOP)) {
  3666. if (netif_queue_stopped(dev)) {
  3667. spin_unlock_irqrestore(&fifo->tx_lock, flags);
  3668. return NETDEV_TX_BUSY;
  3669. }
  3670. }
  3671. put_off = (u16)fifo->tx_curr_put_info.offset;
  3672. get_off = (u16)fifo->tx_curr_get_info.offset;
  3673. txdp = fifo->list_info[put_off].list_virt_addr;
  3674. queue_len = fifo->tx_curr_put_info.fifo_len + 1;
  3675. /* Avoid "put" pointer going beyond "get" pointer */
  3676. if (txdp->Host_Control ||
  3677. ((put_off+1) == queue_len ? 0 : (put_off+1)) == get_off) {
  3678. DBG_PRINT(TX_DBG, "Error in xmit, No free TXDs.\n");
  3679. s2io_stop_tx_queue(sp, fifo->fifo_no);
  3680. dev_kfree_skb(skb);
  3681. spin_unlock_irqrestore(&fifo->tx_lock, flags);
  3682. return NETDEV_TX_OK;
  3683. }
  3684. offload_type = s2io_offload_type(skb);
  3685. if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
  3686. txdp->Control_1 |= TXD_TCP_LSO_EN;
  3687. txdp->Control_1 |= TXD_TCP_LSO_MSS(s2io_tcp_mss(skb));
  3688. }
  3689. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  3690. txdp->Control_2 |= (TXD_TX_CKO_IPV4_EN |
  3691. TXD_TX_CKO_TCP_EN |
  3692. TXD_TX_CKO_UDP_EN);
  3693. }
  3694. txdp->Control_1 |= TXD_GATHER_CODE_FIRST;
  3695. txdp->Control_1 |= TXD_LIST_OWN_XENA;
  3696. txdp->Control_2 |= TXD_INT_NUMBER(fifo->fifo_no);
  3697. if (enable_per_list_interrupt)
  3698. if (put_off & (queue_len >> 5))
  3699. txdp->Control_2 |= TXD_INT_TYPE_PER_LIST;
  3700. if (vlan_tag) {
  3701. txdp->Control_2 |= TXD_VLAN_ENABLE;
  3702. txdp->Control_2 |= TXD_VLAN_TAG(vlan_tag);
  3703. }
  3704. frg_len = skb_headlen(skb);
  3705. if (offload_type == SKB_GSO_UDP) {
  3706. int ufo_size;
  3707. ufo_size = s2io_udp_mss(skb);
  3708. ufo_size &= ~7;
  3709. txdp->Control_1 |= TXD_UFO_EN;
  3710. txdp->Control_1 |= TXD_UFO_MSS(ufo_size);
  3711. txdp->Control_1 |= TXD_BUFFER0_SIZE(8);
  3712. #ifdef __BIG_ENDIAN
  3713. /* both variants do cpu_to_be64(be32_to_cpu(...)) */
  3714. fifo->ufo_in_band_v[put_off] =
  3715. (__force u64)skb_shinfo(skb)->ip6_frag_id;
  3716. #else
  3717. fifo->ufo_in_band_v[put_off] =
  3718. (__force u64)skb_shinfo(skb)->ip6_frag_id << 32;
  3719. #endif
  3720. txdp->Host_Control = (unsigned long)fifo->ufo_in_band_v;
  3721. txdp->Buffer_Pointer = pci_map_single(sp->pdev,
  3722. fifo->ufo_in_band_v,
  3723. sizeof(u64),
  3724. PCI_DMA_TODEVICE);
  3725. if (pci_dma_mapping_error(sp->pdev, txdp->Buffer_Pointer))
  3726. goto pci_map_failed;
  3727. txdp++;
  3728. }
  3729. txdp->Buffer_Pointer = pci_map_single(sp->pdev, skb->data,
  3730. frg_len, PCI_DMA_TODEVICE);
  3731. if (pci_dma_mapping_error(sp->pdev, txdp->Buffer_Pointer))
  3732. goto pci_map_failed;
  3733. txdp->Host_Control = (unsigned long)skb;
  3734. txdp->Control_1 |= TXD_BUFFER0_SIZE(frg_len);
  3735. if (offload_type == SKB_GSO_UDP)
  3736. txdp->Control_1 |= TXD_UFO_EN;
  3737. frg_cnt = skb_shinfo(skb)->nr_frags;
  3738. /* For fragmented SKB. */
  3739. for (i = 0; i < frg_cnt; i++) {
  3740. const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3741. /* A '0' length fragment will be ignored */
  3742. if (!skb_frag_size(frag))
  3743. continue;
  3744. txdp++;
  3745. txdp->Buffer_Pointer = (u64)skb_frag_dma_map(&sp->pdev->dev,
  3746. frag, 0,
  3747. skb_frag_size(frag),
  3748. DMA_TO_DEVICE);
  3749. txdp->Control_1 = TXD_BUFFER0_SIZE(skb_frag_size(frag));
  3750. if (offload_type == SKB_GSO_UDP)
  3751. txdp->Control_1 |= TXD_UFO_EN;
  3752. }
  3753. txdp->Control_1 |= TXD_GATHER_CODE_LAST;
  3754. if (offload_type == SKB_GSO_UDP)
  3755. frg_cnt++; /* as Txd0 was used for inband header */
  3756. tx_fifo = mac_control->tx_FIFO_start[queue];
  3757. val64 = fifo->list_info[put_off].list_phy_addr;
  3758. writeq(val64, &tx_fifo->TxDL_Pointer);
  3759. val64 = (TX_FIFO_LAST_TXD_NUM(frg_cnt) | TX_FIFO_FIRST_LIST |
  3760. TX_FIFO_LAST_LIST);
  3761. if (offload_type)
  3762. val64 |= TX_FIFO_SPECIAL_FUNC;
  3763. writeq(val64, &tx_fifo->List_Control);
  3764. mmiowb();
  3765. put_off++;
  3766. if (put_off == fifo->tx_curr_put_info.fifo_len + 1)
  3767. put_off = 0;
  3768. fifo->tx_curr_put_info.offset = put_off;
  3769. /* Avoid "put" pointer going beyond "get" pointer */
  3770. if (((put_off+1) == queue_len ? 0 : (put_off+1)) == get_off) {
  3771. swstats->fifo_full_cnt++;
  3772. DBG_PRINT(TX_DBG,
  3773. "No free TxDs for xmit, Put: 0x%x Get:0x%x\n",
  3774. put_off, get_off);
  3775. s2io_stop_tx_queue(sp, fifo->fifo_no);
  3776. }
  3777. swstats->mem_allocated += skb->truesize;
  3778. spin_unlock_irqrestore(&fifo->tx_lock, flags);
  3779. if (sp->config.intr_type == MSI_X)
  3780. tx_intr_handler(fifo);
  3781. return NETDEV_TX_OK;
  3782. pci_map_failed:
  3783. swstats->pci_map_fail_cnt++;
  3784. s2io_stop_tx_queue(sp, fifo->fifo_no);
  3785. swstats->mem_freed += skb->truesize;
  3786. dev_kfree_skb(skb);
  3787. spin_unlock_irqrestore(&fifo->tx_lock, flags);
  3788. return NETDEV_TX_OK;
  3789. }
  3790. static void
  3791. s2io_alarm_handle(unsigned long data)
  3792. {
  3793. struct s2io_nic *sp = (struct s2io_nic *)data;
  3794. struct net_device *dev = sp->dev;
  3795. s2io_handle_errors(dev);
  3796. mod_timer(&sp->alarm_timer, jiffies + HZ / 2);
  3797. }
  3798. static irqreturn_t s2io_msix_ring_handle(int irq, void *dev_id)
  3799. {
  3800. struct ring_info *ring = (struct ring_info *)dev_id;
  3801. struct s2io_nic *sp = ring->nic;
  3802. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  3803. if (unlikely(!is_s2io_card_up(sp)))
  3804. return IRQ_HANDLED;
  3805. if (sp->config.napi) {
  3806. u8 __iomem *addr = NULL;
  3807. u8 val8 = 0;
  3808. addr = (u8 __iomem *)&bar0->xmsi_mask_reg;
  3809. addr += (7 - ring->ring_no);
  3810. val8 = (ring->ring_no == 0) ? 0x7f : 0xff;
  3811. writeb(val8, addr);
  3812. val8 = readb(addr);
  3813. napi_schedule(&ring->napi);
  3814. } else {
  3815. rx_intr_handler(ring, 0);
  3816. s2io_chk_rx_buffers(sp, ring);
  3817. }
  3818. return IRQ_HANDLED;
  3819. }
  3820. static irqreturn_t s2io_msix_fifo_handle(int irq, void *dev_id)
  3821. {
  3822. int i;
  3823. struct fifo_info *fifos = (struct fifo_info *)dev_id;
  3824. struct s2io_nic *sp = fifos->nic;
  3825. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  3826. struct config_param *config = &sp->config;
  3827. u64 reason;
  3828. if (unlikely(!is_s2io_card_up(sp)))
  3829. return IRQ_NONE;
  3830. reason = readq(&bar0->general_int_status);
  3831. if (unlikely(reason == S2IO_MINUS_ONE))
  3832. /* Nothing much can be done. Get out */
  3833. return IRQ_HANDLED;
  3834. if (reason & (GEN_INTR_TXPIC | GEN_INTR_TXTRAFFIC)) {
  3835. writeq(S2IO_MINUS_ONE, &bar0->general_int_mask);
  3836. if (reason & GEN_INTR_TXPIC)
  3837. s2io_txpic_intr_handle(sp);
  3838. if (reason & GEN_INTR_TXTRAFFIC)
  3839. writeq(S2IO_MINUS_ONE, &bar0->tx_traffic_int);
  3840. for (i = 0; i < config->tx_fifo_num; i++)
  3841. tx_intr_handler(&fifos[i]);
  3842. writeq(sp->general_int_mask, &bar0->general_int_mask);
  3843. readl(&bar0->general_int_status);
  3844. return IRQ_HANDLED;
  3845. }
  3846. /* The interrupt was not raised by us */
  3847. return IRQ_NONE;
  3848. }
  3849. static void s2io_txpic_intr_handle(struct s2io_nic *sp)
  3850. {
  3851. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  3852. u64 val64;
  3853. val64 = readq(&bar0->pic_int_status);
  3854. if (val64 & PIC_INT_GPIO) {
  3855. val64 = readq(&bar0->gpio_int_reg);
  3856. if ((val64 & GPIO_INT_REG_LINK_DOWN) &&
  3857. (val64 & GPIO_INT_REG_LINK_UP)) {
  3858. /*
  3859. * This is unstable state so clear both up/down
  3860. * interrupt and adapter to re-evaluate the link state.
  3861. */
  3862. val64 |= GPIO_INT_REG_LINK_DOWN;
  3863. val64 |= GPIO_INT_REG_LINK_UP;
  3864. writeq(val64, &bar0->gpio_int_reg);
  3865. val64 = readq(&bar0->gpio_int_mask);
  3866. val64 &= ~(GPIO_INT_MASK_LINK_UP |
  3867. GPIO_INT_MASK_LINK_DOWN);
  3868. writeq(val64, &bar0->gpio_int_mask);
  3869. } else if (val64 & GPIO_INT_REG_LINK_UP) {
  3870. val64 = readq(&bar0->adapter_status);
  3871. /* Enable Adapter */
  3872. val64 = readq(&bar0->adapter_control);
  3873. val64 |= ADAPTER_CNTL_EN;
  3874. writeq(val64, &bar0->adapter_control);
  3875. val64 |= ADAPTER_LED_ON;
  3876. writeq(val64, &bar0->adapter_control);
  3877. if (!sp->device_enabled_once)
  3878. sp->device_enabled_once = 1;
  3879. s2io_link(sp, LINK_UP);
  3880. /*
  3881. * unmask link down interrupt and mask link-up
  3882. * intr
  3883. */
  3884. val64 = readq(&bar0->gpio_int_mask);
  3885. val64 &= ~GPIO_INT_MASK_LINK_DOWN;
  3886. val64 |= GPIO_INT_MASK_LINK_UP;
  3887. writeq(val64, &bar0->gpio_int_mask);
  3888. } else if (val64 & GPIO_INT_REG_LINK_DOWN) {
  3889. val64 = readq(&bar0->adapter_status);
  3890. s2io_link(sp, LINK_DOWN);
  3891. /* Link is down so unmaks link up interrupt */
  3892. val64 = readq(&bar0->gpio_int_mask);
  3893. val64 &= ~GPIO_INT_MASK_LINK_UP;
  3894. val64 |= GPIO_INT_MASK_LINK_DOWN;
  3895. writeq(val64, &bar0->gpio_int_mask);
  3896. /* turn off LED */
  3897. val64 = readq(&bar0->adapter_control);
  3898. val64 = val64 & (~ADAPTER_LED_ON);
  3899. writeq(val64, &bar0->adapter_control);
  3900. }
  3901. }
  3902. val64 = readq(&bar0->gpio_int_mask);
  3903. }
  3904. /**
  3905. * do_s2io_chk_alarm_bit - Check for alarm and incrment the counter
  3906. * @value: alarm bits
  3907. * @addr: address value
  3908. * @cnt: counter variable
  3909. * Description: Check for alarm and increment the counter
  3910. * Return Value:
  3911. * 1 - if alarm bit set
  3912. * 0 - if alarm bit is not set
  3913. */
  3914. static int do_s2io_chk_alarm_bit(u64 value, void __iomem *addr,
  3915. unsigned long long *cnt)
  3916. {
  3917. u64 val64;
  3918. val64 = readq(addr);
  3919. if (val64 & value) {
  3920. writeq(val64, addr);
  3921. (*cnt)++;
  3922. return 1;
  3923. }
  3924. return 0;
  3925. }
  3926. /**
  3927. * s2io_handle_errors - Xframe error indication handler
  3928. * @nic: device private variable
  3929. * Description: Handle alarms such as loss of link, single or
  3930. * double ECC errors, critical and serious errors.
  3931. * Return Value:
  3932. * NONE
  3933. */
  3934. static void s2io_handle_errors(void *dev_id)
  3935. {
  3936. struct net_device *dev = (struct net_device *)dev_id;
  3937. struct s2io_nic *sp = netdev_priv(dev);
  3938. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  3939. u64 temp64 = 0, val64 = 0;
  3940. int i = 0;
  3941. struct swStat *sw_stat = &sp->mac_control.stats_info->sw_stat;
  3942. struct xpakStat *stats = &sp->mac_control.stats_info->xpak_stat;
  3943. if (!is_s2io_card_up(sp))
  3944. return;
  3945. if (pci_channel_offline(sp->pdev))
  3946. return;
  3947. memset(&sw_stat->ring_full_cnt, 0,
  3948. sizeof(sw_stat->ring_full_cnt));
  3949. /* Handling the XPAK counters update */
  3950. if (stats->xpak_timer_count < 72000) {
  3951. /* waiting for an hour */
  3952. stats->xpak_timer_count++;
  3953. } else {
  3954. s2io_updt_xpak_counter(dev);
  3955. /* reset the count to zero */
  3956. stats->xpak_timer_count = 0;
  3957. }
  3958. /* Handling link status change error Intr */
  3959. if (s2io_link_fault_indication(sp) == MAC_RMAC_ERR_TIMER) {
  3960. val64 = readq(&bar0->mac_rmac_err_reg);
  3961. writeq(val64, &bar0->mac_rmac_err_reg);
  3962. if (val64 & RMAC_LINK_STATE_CHANGE_INT)
  3963. schedule_work(&sp->set_link_task);
  3964. }
  3965. /* In case of a serious error, the device will be Reset. */
  3966. if (do_s2io_chk_alarm_bit(SERR_SOURCE_ANY, &bar0->serr_source,
  3967. &sw_stat->serious_err_cnt))
  3968. goto reset;
  3969. /* Check for data parity error */
  3970. if (do_s2io_chk_alarm_bit(GPIO_INT_REG_DP_ERR_INT, &bar0->gpio_int_reg,
  3971. &sw_stat->parity_err_cnt))
  3972. goto reset;
  3973. /* Check for ring full counter */
  3974. if (sp->device_type == XFRAME_II_DEVICE) {
  3975. val64 = readq(&bar0->ring_bump_counter1);
  3976. for (i = 0; i < 4; i++) {
  3977. temp64 = (val64 & vBIT(0xFFFF, (i*16), 16));
  3978. temp64 >>= 64 - ((i+1)*16);
  3979. sw_stat->ring_full_cnt[i] += temp64;
  3980. }
  3981. val64 = readq(&bar0->ring_bump_counter2);
  3982. for (i = 0; i < 4; i++) {
  3983. temp64 = (val64 & vBIT(0xFFFF, (i*16), 16));
  3984. temp64 >>= 64 - ((i+1)*16);
  3985. sw_stat->ring_full_cnt[i+4] += temp64;
  3986. }
  3987. }
  3988. val64 = readq(&bar0->txdma_int_status);
  3989. /*check for pfc_err*/
  3990. if (val64 & TXDMA_PFC_INT) {
  3991. if (do_s2io_chk_alarm_bit(PFC_ECC_DB_ERR | PFC_SM_ERR_ALARM |
  3992. PFC_MISC_0_ERR | PFC_MISC_1_ERR |
  3993. PFC_PCIX_ERR,
  3994. &bar0->pfc_err_reg,
  3995. &sw_stat->pfc_err_cnt))
  3996. goto reset;
  3997. do_s2io_chk_alarm_bit(PFC_ECC_SG_ERR,
  3998. &bar0->pfc_err_reg,
  3999. &sw_stat->pfc_err_cnt);
  4000. }
  4001. /*check for tda_err*/
  4002. if (val64 & TXDMA_TDA_INT) {
  4003. if (do_s2io_chk_alarm_bit(TDA_Fn_ECC_DB_ERR |
  4004. TDA_SM0_ERR_ALARM |
  4005. TDA_SM1_ERR_ALARM,
  4006. &bar0->tda_err_reg,
  4007. &sw_stat->tda_err_cnt))
  4008. goto reset;
  4009. do_s2io_chk_alarm_bit(TDA_Fn_ECC_SG_ERR | TDA_PCIX_ERR,
  4010. &bar0->tda_err_reg,
  4011. &sw_stat->tda_err_cnt);
  4012. }
  4013. /*check for pcc_err*/
  4014. if (val64 & TXDMA_PCC_INT) {
  4015. if (do_s2io_chk_alarm_bit(PCC_SM_ERR_ALARM | PCC_WR_ERR_ALARM |
  4016. PCC_N_SERR | PCC_6_COF_OV_ERR |
  4017. PCC_7_COF_OV_ERR | PCC_6_LSO_OV_ERR |
  4018. PCC_7_LSO_OV_ERR | PCC_FB_ECC_DB_ERR |
  4019. PCC_TXB_ECC_DB_ERR,
  4020. &bar0->pcc_err_reg,
  4021. &sw_stat->pcc_err_cnt))
  4022. goto reset;
  4023. do_s2io_chk_alarm_bit(PCC_FB_ECC_SG_ERR | PCC_TXB_ECC_SG_ERR,
  4024. &bar0->pcc_err_reg,
  4025. &sw_stat->pcc_err_cnt);
  4026. }
  4027. /*check for tti_err*/
  4028. if (val64 & TXDMA_TTI_INT) {
  4029. if (do_s2io_chk_alarm_bit(TTI_SM_ERR_ALARM,
  4030. &bar0->tti_err_reg,
  4031. &sw_stat->tti_err_cnt))
  4032. goto reset;
  4033. do_s2io_chk_alarm_bit(TTI_ECC_SG_ERR | TTI_ECC_DB_ERR,
  4034. &bar0->tti_err_reg,
  4035. &sw_stat->tti_err_cnt);
  4036. }
  4037. /*check for lso_err*/
  4038. if (val64 & TXDMA_LSO_INT) {
  4039. if (do_s2io_chk_alarm_bit(LSO6_ABORT | LSO7_ABORT |
  4040. LSO6_SM_ERR_ALARM | LSO7_SM_ERR_ALARM,
  4041. &bar0->lso_err_reg,
  4042. &sw_stat->lso_err_cnt))
  4043. goto reset;
  4044. do_s2io_chk_alarm_bit(LSO6_SEND_OFLOW | LSO7_SEND_OFLOW,
  4045. &bar0->lso_err_reg,
  4046. &sw_stat->lso_err_cnt);
  4047. }
  4048. /*check for tpa_err*/
  4049. if (val64 & TXDMA_TPA_INT) {
  4050. if (do_s2io_chk_alarm_bit(TPA_SM_ERR_ALARM,
  4051. &bar0->tpa_err_reg,
  4052. &sw_stat->tpa_err_cnt))
  4053. goto reset;
  4054. do_s2io_chk_alarm_bit(TPA_TX_FRM_DROP,
  4055. &bar0->tpa_err_reg,
  4056. &sw_stat->tpa_err_cnt);
  4057. }
  4058. /*check for sm_err*/
  4059. if (val64 & TXDMA_SM_INT) {
  4060. if (do_s2io_chk_alarm_bit(SM_SM_ERR_ALARM,
  4061. &bar0->sm_err_reg,
  4062. &sw_stat->sm_err_cnt))
  4063. goto reset;
  4064. }
  4065. val64 = readq(&bar0->mac_int_status);
  4066. if (val64 & MAC_INT_STATUS_TMAC_INT) {
  4067. if (do_s2io_chk_alarm_bit(TMAC_TX_BUF_OVRN | TMAC_TX_SM_ERR,
  4068. &bar0->mac_tmac_err_reg,
  4069. &sw_stat->mac_tmac_err_cnt))
  4070. goto reset;
  4071. do_s2io_chk_alarm_bit(TMAC_ECC_SG_ERR | TMAC_ECC_DB_ERR |
  4072. TMAC_DESC_ECC_SG_ERR |
  4073. TMAC_DESC_ECC_DB_ERR,
  4074. &bar0->mac_tmac_err_reg,
  4075. &sw_stat->mac_tmac_err_cnt);
  4076. }
  4077. val64 = readq(&bar0->xgxs_int_status);
  4078. if (val64 & XGXS_INT_STATUS_TXGXS) {
  4079. if (do_s2io_chk_alarm_bit(TXGXS_ESTORE_UFLOW | TXGXS_TX_SM_ERR,
  4080. &bar0->xgxs_txgxs_err_reg,
  4081. &sw_stat->xgxs_txgxs_err_cnt))
  4082. goto reset;
  4083. do_s2io_chk_alarm_bit(TXGXS_ECC_SG_ERR | TXGXS_ECC_DB_ERR,
  4084. &bar0->xgxs_txgxs_err_reg,
  4085. &sw_stat->xgxs_txgxs_err_cnt);
  4086. }
  4087. val64 = readq(&bar0->rxdma_int_status);
  4088. if (val64 & RXDMA_INT_RC_INT_M) {
  4089. if (do_s2io_chk_alarm_bit(RC_PRCn_ECC_DB_ERR |
  4090. RC_FTC_ECC_DB_ERR |
  4091. RC_PRCn_SM_ERR_ALARM |
  4092. RC_FTC_SM_ERR_ALARM,
  4093. &bar0->rc_err_reg,
  4094. &sw_stat->rc_err_cnt))
  4095. goto reset;
  4096. do_s2io_chk_alarm_bit(RC_PRCn_ECC_SG_ERR |
  4097. RC_FTC_ECC_SG_ERR |
  4098. RC_RDA_FAIL_WR_Rn, &bar0->rc_err_reg,
  4099. &sw_stat->rc_err_cnt);
  4100. if (do_s2io_chk_alarm_bit(PRC_PCI_AB_RD_Rn |
  4101. PRC_PCI_AB_WR_Rn |
  4102. PRC_PCI_AB_F_WR_Rn,
  4103. &bar0->prc_pcix_err_reg,
  4104. &sw_stat->prc_pcix_err_cnt))
  4105. goto reset;
  4106. do_s2io_chk_alarm_bit(PRC_PCI_DP_RD_Rn |
  4107. PRC_PCI_DP_WR_Rn |
  4108. PRC_PCI_DP_F_WR_Rn,
  4109. &bar0->prc_pcix_err_reg,
  4110. &sw_stat->prc_pcix_err_cnt);
  4111. }
  4112. if (val64 & RXDMA_INT_RPA_INT_M) {
  4113. if (do_s2io_chk_alarm_bit(RPA_SM_ERR_ALARM | RPA_CREDIT_ERR,
  4114. &bar0->rpa_err_reg,
  4115. &sw_stat->rpa_err_cnt))
  4116. goto reset;
  4117. do_s2io_chk_alarm_bit(RPA_ECC_SG_ERR | RPA_ECC_DB_ERR,
  4118. &bar0->rpa_err_reg,
  4119. &sw_stat->rpa_err_cnt);
  4120. }
  4121. if (val64 & RXDMA_INT_RDA_INT_M) {
  4122. if (do_s2io_chk_alarm_bit(RDA_RXDn_ECC_DB_ERR |
  4123. RDA_FRM_ECC_DB_N_AERR |
  4124. RDA_SM1_ERR_ALARM |
  4125. RDA_SM0_ERR_ALARM |
  4126. RDA_RXD_ECC_DB_SERR,
  4127. &bar0->rda_err_reg,
  4128. &sw_stat->rda_err_cnt))
  4129. goto reset;
  4130. do_s2io_chk_alarm_bit(RDA_RXDn_ECC_SG_ERR |
  4131. RDA_FRM_ECC_SG_ERR |
  4132. RDA_MISC_ERR |
  4133. RDA_PCIX_ERR,
  4134. &bar0->rda_err_reg,
  4135. &sw_stat->rda_err_cnt);
  4136. }
  4137. if (val64 & RXDMA_INT_RTI_INT_M) {
  4138. if (do_s2io_chk_alarm_bit(RTI_SM_ERR_ALARM,
  4139. &bar0->rti_err_reg,
  4140. &sw_stat->rti_err_cnt))
  4141. goto reset;
  4142. do_s2io_chk_alarm_bit(RTI_ECC_SG_ERR | RTI_ECC_DB_ERR,
  4143. &bar0->rti_err_reg,
  4144. &sw_stat->rti_err_cnt);
  4145. }
  4146. val64 = readq(&bar0->mac_int_status);
  4147. if (val64 & MAC_INT_STATUS_RMAC_INT) {
  4148. if (do_s2io_chk_alarm_bit(RMAC_RX_BUFF_OVRN | RMAC_RX_SM_ERR,
  4149. &bar0->mac_rmac_err_reg,
  4150. &sw_stat->mac_rmac_err_cnt))
  4151. goto reset;
  4152. do_s2io_chk_alarm_bit(RMAC_UNUSED_INT |
  4153. RMAC_SINGLE_ECC_ERR |
  4154. RMAC_DOUBLE_ECC_ERR,
  4155. &bar0->mac_rmac_err_reg,
  4156. &sw_stat->mac_rmac_err_cnt);
  4157. }
  4158. val64 = readq(&bar0->xgxs_int_status);
  4159. if (val64 & XGXS_INT_STATUS_RXGXS) {
  4160. if (do_s2io_chk_alarm_bit(RXGXS_ESTORE_OFLOW | RXGXS_RX_SM_ERR,
  4161. &bar0->xgxs_rxgxs_err_reg,
  4162. &sw_stat->xgxs_rxgxs_err_cnt))
  4163. goto reset;
  4164. }
  4165. val64 = readq(&bar0->mc_int_status);
  4166. if (val64 & MC_INT_STATUS_MC_INT) {
  4167. if (do_s2io_chk_alarm_bit(MC_ERR_REG_SM_ERR,
  4168. &bar0->mc_err_reg,
  4169. &sw_stat->mc_err_cnt))
  4170. goto reset;
  4171. /* Handling Ecc errors */
  4172. if (val64 & (MC_ERR_REG_ECC_ALL_SNG | MC_ERR_REG_ECC_ALL_DBL)) {
  4173. writeq(val64, &bar0->mc_err_reg);
  4174. if (val64 & MC_ERR_REG_ECC_ALL_DBL) {
  4175. sw_stat->double_ecc_errs++;
  4176. if (sp->device_type != XFRAME_II_DEVICE) {
  4177. /*
  4178. * Reset XframeI only if critical error
  4179. */
  4180. if (val64 &
  4181. (MC_ERR_REG_MIRI_ECC_DB_ERR_0 |
  4182. MC_ERR_REG_MIRI_ECC_DB_ERR_1))
  4183. goto reset;
  4184. }
  4185. } else
  4186. sw_stat->single_ecc_errs++;
  4187. }
  4188. }
  4189. return;
  4190. reset:
  4191. s2io_stop_all_tx_queue(sp);
  4192. schedule_work(&sp->rst_timer_task);
  4193. sw_stat->soft_reset_cnt++;
  4194. }
  4195. /**
  4196. * s2io_isr - ISR handler of the device .
  4197. * @irq: the irq of the device.
  4198. * @dev_id: a void pointer to the dev structure of the NIC.
  4199. * Description: This function is the ISR handler of the device. It
  4200. * identifies the reason for the interrupt and calls the relevant
  4201. * service routines. As a contongency measure, this ISR allocates the
  4202. * recv buffers, if their numbers are below the panic value which is
  4203. * presently set to 25% of the original number of rcv buffers allocated.
  4204. * Return value:
  4205. * IRQ_HANDLED: will be returned if IRQ was handled by this routine
  4206. * IRQ_NONE: will be returned if interrupt is not from our device
  4207. */
  4208. static irqreturn_t s2io_isr(int irq, void *dev_id)
  4209. {
  4210. struct net_device *dev = (struct net_device *)dev_id;
  4211. struct s2io_nic *sp = netdev_priv(dev);
  4212. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  4213. int i;
  4214. u64 reason = 0;
  4215. struct mac_info *mac_control;
  4216. struct config_param *config;
  4217. /* Pretend we handled any irq's from a disconnected card */
  4218. if (pci_channel_offline(sp->pdev))
  4219. return IRQ_NONE;
  4220. if (!is_s2io_card_up(sp))
  4221. return IRQ_NONE;
  4222. config = &sp->config;
  4223. mac_control = &sp->mac_control;
  4224. /*
  4225. * Identify the cause for interrupt and call the appropriate
  4226. * interrupt handler. Causes for the interrupt could be;
  4227. * 1. Rx of packet.
  4228. * 2. Tx complete.
  4229. * 3. Link down.
  4230. */
  4231. reason = readq(&bar0->general_int_status);
  4232. if (unlikely(reason == S2IO_MINUS_ONE))
  4233. return IRQ_HANDLED; /* Nothing much can be done. Get out */
  4234. if (reason &
  4235. (GEN_INTR_RXTRAFFIC | GEN_INTR_TXTRAFFIC | GEN_INTR_TXPIC)) {
  4236. writeq(S2IO_MINUS_ONE, &bar0->general_int_mask);
  4237. if (config->napi) {
  4238. if (reason & GEN_INTR_RXTRAFFIC) {
  4239. napi_schedule(&sp->napi);
  4240. writeq(S2IO_MINUS_ONE, &bar0->rx_traffic_mask);
  4241. writeq(S2IO_MINUS_ONE, &bar0->rx_traffic_int);
  4242. readl(&bar0->rx_traffic_int);
  4243. }
  4244. } else {
  4245. /*
  4246. * rx_traffic_int reg is an R1 register, writing all 1's
  4247. * will ensure that the actual interrupt causing bit
  4248. * get's cleared and hence a read can be avoided.
  4249. */
  4250. if (reason & GEN_INTR_RXTRAFFIC)
  4251. writeq(S2IO_MINUS_ONE, &bar0->rx_traffic_int);
  4252. for (i = 0; i < config->rx_ring_num; i++) {
  4253. struct ring_info *ring = &mac_control->rings[i];
  4254. rx_intr_handler(ring, 0);
  4255. }
  4256. }
  4257. /*
  4258. * tx_traffic_int reg is an R1 register, writing all 1's
  4259. * will ensure that the actual interrupt causing bit get's
  4260. * cleared and hence a read can be avoided.
  4261. */
  4262. if (reason & GEN_INTR_TXTRAFFIC)
  4263. writeq(S2IO_MINUS_ONE, &bar0->tx_traffic_int);
  4264. for (i = 0; i < config->tx_fifo_num; i++)
  4265. tx_intr_handler(&mac_control->fifos[i]);
  4266. if (reason & GEN_INTR_TXPIC)
  4267. s2io_txpic_intr_handle(sp);
  4268. /*
  4269. * Reallocate the buffers from the interrupt handler itself.
  4270. */
  4271. if (!config->napi) {
  4272. for (i = 0; i < config->rx_ring_num; i++) {
  4273. struct ring_info *ring = &mac_control->rings[i];
  4274. s2io_chk_rx_buffers(sp, ring);
  4275. }
  4276. }
  4277. writeq(sp->general_int_mask, &bar0->general_int_mask);
  4278. readl(&bar0->general_int_status);
  4279. return IRQ_HANDLED;
  4280. } else if (!reason) {
  4281. /* The interrupt was not raised by us */
  4282. return IRQ_NONE;
  4283. }
  4284. return IRQ_HANDLED;
  4285. }
  4286. /**
  4287. * s2io_updt_stats -
  4288. */
  4289. static void s2io_updt_stats(struct s2io_nic *sp)
  4290. {
  4291. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  4292. u64 val64;
  4293. int cnt = 0;
  4294. if (is_s2io_card_up(sp)) {
  4295. /* Apprx 30us on a 133 MHz bus */
  4296. val64 = SET_UPDT_CLICKS(10) |
  4297. STAT_CFG_ONE_SHOT_EN | STAT_CFG_STAT_EN;
  4298. writeq(val64, &bar0->stat_cfg);
  4299. do {
  4300. udelay(100);
  4301. val64 = readq(&bar0->stat_cfg);
  4302. if (!(val64 & s2BIT(0)))
  4303. break;
  4304. cnt++;
  4305. if (cnt == 5)
  4306. break; /* Updt failed */
  4307. } while (1);
  4308. }
  4309. }
  4310. /**
  4311. * s2io_get_stats - Updates the device statistics structure.
  4312. * @dev : pointer to the device structure.
  4313. * Description:
  4314. * This function updates the device statistics structure in the s2io_nic
  4315. * structure and returns a pointer to the same.
  4316. * Return value:
  4317. * pointer to the updated net_device_stats structure.
  4318. */
  4319. static struct net_device_stats *s2io_get_stats(struct net_device *dev)
  4320. {
  4321. struct s2io_nic *sp = netdev_priv(dev);
  4322. struct mac_info *mac_control = &sp->mac_control;
  4323. struct stat_block *stats = mac_control->stats_info;
  4324. u64 delta;
  4325. /* Configure Stats for immediate updt */
  4326. s2io_updt_stats(sp);
  4327. /* A device reset will cause the on-adapter statistics to be zero'ed.
  4328. * This can be done while running by changing the MTU. To prevent the
  4329. * system from having the stats zero'ed, the driver keeps a copy of the
  4330. * last update to the system (which is also zero'ed on reset). This
  4331. * enables the driver to accurately know the delta between the last
  4332. * update and the current update.
  4333. */
  4334. delta = ((u64) le32_to_cpu(stats->rmac_vld_frms_oflow) << 32 |
  4335. le32_to_cpu(stats->rmac_vld_frms)) - sp->stats.rx_packets;
  4336. sp->stats.rx_packets += delta;
  4337. dev->stats.rx_packets += delta;
  4338. delta = ((u64) le32_to_cpu(stats->tmac_frms_oflow) << 32 |
  4339. le32_to_cpu(stats->tmac_frms)) - sp->stats.tx_packets;
  4340. sp->stats.tx_packets += delta;
  4341. dev->stats.tx_packets += delta;
  4342. delta = ((u64) le32_to_cpu(stats->rmac_data_octets_oflow) << 32 |
  4343. le32_to_cpu(stats->rmac_data_octets)) - sp->stats.rx_bytes;
  4344. sp->stats.rx_bytes += delta;
  4345. dev->stats.rx_bytes += delta;
  4346. delta = ((u64) le32_to_cpu(stats->tmac_data_octets_oflow) << 32 |
  4347. le32_to_cpu(stats->tmac_data_octets)) - sp->stats.tx_bytes;
  4348. sp->stats.tx_bytes += delta;
  4349. dev->stats.tx_bytes += delta;
  4350. delta = le64_to_cpu(stats->rmac_drop_frms) - sp->stats.rx_errors;
  4351. sp->stats.rx_errors += delta;
  4352. dev->stats.rx_errors += delta;
  4353. delta = ((u64) le32_to_cpu(stats->tmac_any_err_frms_oflow) << 32 |
  4354. le32_to_cpu(stats->tmac_any_err_frms)) - sp->stats.tx_errors;
  4355. sp->stats.tx_errors += delta;
  4356. dev->stats.tx_errors += delta;
  4357. delta = le64_to_cpu(stats->rmac_drop_frms) - sp->stats.rx_dropped;
  4358. sp->stats.rx_dropped += delta;
  4359. dev->stats.rx_dropped += delta;
  4360. delta = le64_to_cpu(stats->tmac_drop_frms) - sp->stats.tx_dropped;
  4361. sp->stats.tx_dropped += delta;
  4362. dev->stats.tx_dropped += delta;
  4363. /* The adapter MAC interprets pause frames as multicast packets, but
  4364. * does not pass them up. This erroneously increases the multicast
  4365. * packet count and needs to be deducted when the multicast frame count
  4366. * is queried.
  4367. */
  4368. delta = (u64) le32_to_cpu(stats->rmac_vld_mcst_frms_oflow) << 32 |
  4369. le32_to_cpu(stats->rmac_vld_mcst_frms);
  4370. delta -= le64_to_cpu(stats->rmac_pause_ctrl_frms);
  4371. delta -= sp->stats.multicast;
  4372. sp->stats.multicast += delta;
  4373. dev->stats.multicast += delta;
  4374. delta = ((u64) le32_to_cpu(stats->rmac_usized_frms_oflow) << 32 |
  4375. le32_to_cpu(stats->rmac_usized_frms)) +
  4376. le64_to_cpu(stats->rmac_long_frms) - sp->stats.rx_length_errors;
  4377. sp->stats.rx_length_errors += delta;
  4378. dev->stats.rx_length_errors += delta;
  4379. delta = le64_to_cpu(stats->rmac_fcs_err_frms) - sp->stats.rx_crc_errors;
  4380. sp->stats.rx_crc_errors += delta;
  4381. dev->stats.rx_crc_errors += delta;
  4382. return &dev->stats;
  4383. }
  4384. /**
  4385. * s2io_set_multicast - entry point for multicast address enable/disable.
  4386. * @dev : pointer to the device structure
  4387. * Description:
  4388. * This function is a driver entry point which gets called by the kernel
  4389. * whenever multicast addresses must be enabled/disabled. This also gets
  4390. * called to set/reset promiscuous mode. Depending on the deivce flag, we
  4391. * determine, if multicast address must be enabled or if promiscuous mode
  4392. * is to be disabled etc.
  4393. * Return value:
  4394. * void.
  4395. */
  4396. static void s2io_set_multicast(struct net_device *dev)
  4397. {
  4398. int i, j, prev_cnt;
  4399. struct netdev_hw_addr *ha;
  4400. struct s2io_nic *sp = netdev_priv(dev);
  4401. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  4402. u64 val64 = 0, multi_mac = 0x010203040506ULL, mask =
  4403. 0xfeffffffffffULL;
  4404. u64 dis_addr = S2IO_DISABLE_MAC_ENTRY, mac_addr = 0;
  4405. void __iomem *add;
  4406. struct config_param *config = &sp->config;
  4407. if ((dev->flags & IFF_ALLMULTI) && (!sp->m_cast_flg)) {
  4408. /* Enable all Multicast addresses */
  4409. writeq(RMAC_ADDR_DATA0_MEM_ADDR(multi_mac),
  4410. &bar0->rmac_addr_data0_mem);
  4411. writeq(RMAC_ADDR_DATA1_MEM_MASK(mask),
  4412. &bar0->rmac_addr_data1_mem);
  4413. val64 = RMAC_ADDR_CMD_MEM_WE |
  4414. RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
  4415. RMAC_ADDR_CMD_MEM_OFFSET(config->max_mc_addr - 1);
  4416. writeq(val64, &bar0->rmac_addr_cmd_mem);
  4417. /* Wait till command completes */
  4418. wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
  4419. RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
  4420. S2IO_BIT_RESET);
  4421. sp->m_cast_flg = 1;
  4422. sp->all_multi_pos = config->max_mc_addr - 1;
  4423. } else if ((dev->flags & IFF_ALLMULTI) && (sp->m_cast_flg)) {
  4424. /* Disable all Multicast addresses */
  4425. writeq(RMAC_ADDR_DATA0_MEM_ADDR(dis_addr),
  4426. &bar0->rmac_addr_data0_mem);
  4427. writeq(RMAC_ADDR_DATA1_MEM_MASK(0x0),
  4428. &bar0->rmac_addr_data1_mem);
  4429. val64 = RMAC_ADDR_CMD_MEM_WE |
  4430. RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
  4431. RMAC_ADDR_CMD_MEM_OFFSET(sp->all_multi_pos);
  4432. writeq(val64, &bar0->rmac_addr_cmd_mem);
  4433. /* Wait till command completes */
  4434. wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
  4435. RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
  4436. S2IO_BIT_RESET);
  4437. sp->m_cast_flg = 0;
  4438. sp->all_multi_pos = 0;
  4439. }
  4440. if ((dev->flags & IFF_PROMISC) && (!sp->promisc_flg)) {
  4441. /* Put the NIC into promiscuous mode */
  4442. add = &bar0->mac_cfg;
  4443. val64 = readq(&bar0->mac_cfg);
  4444. val64 |= MAC_CFG_RMAC_PROM_ENABLE;
  4445. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  4446. writel((u32)val64, add);
  4447. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  4448. writel((u32) (val64 >> 32), (add + 4));
  4449. if (vlan_tag_strip != 1) {
  4450. val64 = readq(&bar0->rx_pa_cfg);
  4451. val64 &= ~RX_PA_CFG_STRIP_VLAN_TAG;
  4452. writeq(val64, &bar0->rx_pa_cfg);
  4453. sp->vlan_strip_flag = 0;
  4454. }
  4455. val64 = readq(&bar0->mac_cfg);
  4456. sp->promisc_flg = 1;
  4457. DBG_PRINT(INFO_DBG, "%s: entered promiscuous mode\n",
  4458. dev->name);
  4459. } else if (!(dev->flags & IFF_PROMISC) && (sp->promisc_flg)) {
  4460. /* Remove the NIC from promiscuous mode */
  4461. add = &bar0->mac_cfg;
  4462. val64 = readq(&bar0->mac_cfg);
  4463. val64 &= ~MAC_CFG_RMAC_PROM_ENABLE;
  4464. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  4465. writel((u32)val64, add);
  4466. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  4467. writel((u32) (val64 >> 32), (add + 4));
  4468. if (vlan_tag_strip != 0) {
  4469. val64 = readq(&bar0->rx_pa_cfg);
  4470. val64 |= RX_PA_CFG_STRIP_VLAN_TAG;
  4471. writeq(val64, &bar0->rx_pa_cfg);
  4472. sp->vlan_strip_flag = 1;
  4473. }
  4474. val64 = readq(&bar0->mac_cfg);
  4475. sp->promisc_flg = 0;
  4476. DBG_PRINT(INFO_DBG, "%s: left promiscuous mode\n", dev->name);
  4477. }
  4478. /* Update individual M_CAST address list */
  4479. if ((!sp->m_cast_flg) && netdev_mc_count(dev)) {
  4480. if (netdev_mc_count(dev) >
  4481. (config->max_mc_addr - config->max_mac_addr)) {
  4482. DBG_PRINT(ERR_DBG,
  4483. "%s: No more Rx filters can be added - "
  4484. "please enable ALL_MULTI instead\n",
  4485. dev->name);
  4486. return;
  4487. }
  4488. prev_cnt = sp->mc_addr_count;
  4489. sp->mc_addr_count = netdev_mc_count(dev);
  4490. /* Clear out the previous list of Mc in the H/W. */
  4491. for (i = 0; i < prev_cnt; i++) {
  4492. writeq(RMAC_ADDR_DATA0_MEM_ADDR(dis_addr),
  4493. &bar0->rmac_addr_data0_mem);
  4494. writeq(RMAC_ADDR_DATA1_MEM_MASK(0ULL),
  4495. &bar0->rmac_addr_data1_mem);
  4496. val64 = RMAC_ADDR_CMD_MEM_WE |
  4497. RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
  4498. RMAC_ADDR_CMD_MEM_OFFSET
  4499. (config->mc_start_offset + i);
  4500. writeq(val64, &bar0->rmac_addr_cmd_mem);
  4501. /* Wait for command completes */
  4502. if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
  4503. RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
  4504. S2IO_BIT_RESET)) {
  4505. DBG_PRINT(ERR_DBG,
  4506. "%s: Adding Multicasts failed\n",
  4507. dev->name);
  4508. return;
  4509. }
  4510. }
  4511. /* Create the new Rx filter list and update the same in H/W. */
  4512. i = 0;
  4513. netdev_for_each_mc_addr(ha, dev) {
  4514. mac_addr = 0;
  4515. for (j = 0; j < ETH_ALEN; j++) {
  4516. mac_addr |= ha->addr[j];
  4517. mac_addr <<= 8;
  4518. }
  4519. mac_addr >>= 8;
  4520. writeq(RMAC_ADDR_DATA0_MEM_ADDR(mac_addr),
  4521. &bar0->rmac_addr_data0_mem);
  4522. writeq(RMAC_ADDR_DATA1_MEM_MASK(0ULL),
  4523. &bar0->rmac_addr_data1_mem);
  4524. val64 = RMAC_ADDR_CMD_MEM_WE |
  4525. RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
  4526. RMAC_ADDR_CMD_MEM_OFFSET
  4527. (i + config->mc_start_offset);
  4528. writeq(val64, &bar0->rmac_addr_cmd_mem);
  4529. /* Wait for command completes */
  4530. if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
  4531. RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
  4532. S2IO_BIT_RESET)) {
  4533. DBG_PRINT(ERR_DBG,
  4534. "%s: Adding Multicasts failed\n",
  4535. dev->name);
  4536. return;
  4537. }
  4538. i++;
  4539. }
  4540. }
  4541. }
  4542. /* read from CAM unicast & multicast addresses and store it in
  4543. * def_mac_addr structure
  4544. */
  4545. static void do_s2io_store_unicast_mc(struct s2io_nic *sp)
  4546. {
  4547. int offset;
  4548. u64 mac_addr = 0x0;
  4549. struct config_param *config = &sp->config;
  4550. /* store unicast & multicast mac addresses */
  4551. for (offset = 0; offset < config->max_mc_addr; offset++) {
  4552. mac_addr = do_s2io_read_unicast_mc(sp, offset);
  4553. /* if read fails disable the entry */
  4554. if (mac_addr == FAILURE)
  4555. mac_addr = S2IO_DISABLE_MAC_ENTRY;
  4556. do_s2io_copy_mac_addr(sp, offset, mac_addr);
  4557. }
  4558. }
  4559. /* restore unicast & multicast MAC to CAM from def_mac_addr structure */
  4560. static void do_s2io_restore_unicast_mc(struct s2io_nic *sp)
  4561. {
  4562. int offset;
  4563. struct config_param *config = &sp->config;
  4564. /* restore unicast mac address */
  4565. for (offset = 0; offset < config->max_mac_addr; offset++)
  4566. do_s2io_prog_unicast(sp->dev,
  4567. sp->def_mac_addr[offset].mac_addr);
  4568. /* restore multicast mac address */
  4569. for (offset = config->mc_start_offset;
  4570. offset < config->max_mc_addr; offset++)
  4571. do_s2io_add_mc(sp, sp->def_mac_addr[offset].mac_addr);
  4572. }
  4573. /* add a multicast MAC address to CAM */
  4574. static int do_s2io_add_mc(struct s2io_nic *sp, u8 *addr)
  4575. {
  4576. int i;
  4577. u64 mac_addr = 0;
  4578. struct config_param *config = &sp->config;
  4579. for (i = 0; i < ETH_ALEN; i++) {
  4580. mac_addr <<= 8;
  4581. mac_addr |= addr[i];
  4582. }
  4583. if ((0ULL == mac_addr) || (mac_addr == S2IO_DISABLE_MAC_ENTRY))
  4584. return SUCCESS;
  4585. /* check if the multicast mac already preset in CAM */
  4586. for (i = config->mc_start_offset; i < config->max_mc_addr; i++) {
  4587. u64 tmp64;
  4588. tmp64 = do_s2io_read_unicast_mc(sp, i);
  4589. if (tmp64 == S2IO_DISABLE_MAC_ENTRY) /* CAM entry is empty */
  4590. break;
  4591. if (tmp64 == mac_addr)
  4592. return SUCCESS;
  4593. }
  4594. if (i == config->max_mc_addr) {
  4595. DBG_PRINT(ERR_DBG,
  4596. "CAM full no space left for multicast MAC\n");
  4597. return FAILURE;
  4598. }
  4599. /* Update the internal structure with this new mac address */
  4600. do_s2io_copy_mac_addr(sp, i, mac_addr);
  4601. return do_s2io_add_mac(sp, mac_addr, i);
  4602. }
  4603. /* add MAC address to CAM */
  4604. static int do_s2io_add_mac(struct s2io_nic *sp, u64 addr, int off)
  4605. {
  4606. u64 val64;
  4607. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  4608. writeq(RMAC_ADDR_DATA0_MEM_ADDR(addr),
  4609. &bar0->rmac_addr_data0_mem);
  4610. val64 = RMAC_ADDR_CMD_MEM_WE | RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
  4611. RMAC_ADDR_CMD_MEM_OFFSET(off);
  4612. writeq(val64, &bar0->rmac_addr_cmd_mem);
  4613. /* Wait till command completes */
  4614. if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
  4615. RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
  4616. S2IO_BIT_RESET)) {
  4617. DBG_PRINT(INFO_DBG, "do_s2io_add_mac failed\n");
  4618. return FAILURE;
  4619. }
  4620. return SUCCESS;
  4621. }
  4622. /* deletes a specified unicast/multicast mac entry from CAM */
  4623. static int do_s2io_delete_unicast_mc(struct s2io_nic *sp, u64 addr)
  4624. {
  4625. int offset;
  4626. u64 dis_addr = S2IO_DISABLE_MAC_ENTRY, tmp64;
  4627. struct config_param *config = &sp->config;
  4628. for (offset = 1;
  4629. offset < config->max_mc_addr; offset++) {
  4630. tmp64 = do_s2io_read_unicast_mc(sp, offset);
  4631. if (tmp64 == addr) {
  4632. /* disable the entry by writing 0xffffffffffffULL */
  4633. if (do_s2io_add_mac(sp, dis_addr, offset) == FAILURE)
  4634. return FAILURE;
  4635. /* store the new mac list from CAM */
  4636. do_s2io_store_unicast_mc(sp);
  4637. return SUCCESS;
  4638. }
  4639. }
  4640. DBG_PRINT(ERR_DBG, "MAC address 0x%llx not found in CAM\n",
  4641. (unsigned long long)addr);
  4642. return FAILURE;
  4643. }
  4644. /* read mac entries from CAM */
  4645. static u64 do_s2io_read_unicast_mc(struct s2io_nic *sp, int offset)
  4646. {
  4647. u64 tmp64 = 0xffffffffffff0000ULL, val64;
  4648. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  4649. /* read mac addr */
  4650. val64 = RMAC_ADDR_CMD_MEM_RD | RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
  4651. RMAC_ADDR_CMD_MEM_OFFSET(offset);
  4652. writeq(val64, &bar0->rmac_addr_cmd_mem);
  4653. /* Wait till command completes */
  4654. if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
  4655. RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
  4656. S2IO_BIT_RESET)) {
  4657. DBG_PRINT(INFO_DBG, "do_s2io_read_unicast_mc failed\n");
  4658. return FAILURE;
  4659. }
  4660. tmp64 = readq(&bar0->rmac_addr_data0_mem);
  4661. return tmp64 >> 16;
  4662. }
  4663. /**
  4664. * s2io_set_mac_addr driver entry point
  4665. */
  4666. static int s2io_set_mac_addr(struct net_device *dev, void *p)
  4667. {
  4668. struct sockaddr *addr = p;
  4669. if (!is_valid_ether_addr(addr->sa_data))
  4670. return -EADDRNOTAVAIL;
  4671. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  4672. /* store the MAC address in CAM */
  4673. return do_s2io_prog_unicast(dev, dev->dev_addr);
  4674. }
  4675. /**
  4676. * do_s2io_prog_unicast - Programs the Xframe mac address
  4677. * @dev : pointer to the device structure.
  4678. * @addr: a uchar pointer to the new mac address which is to be set.
  4679. * Description : This procedure will program the Xframe to receive
  4680. * frames with new Mac Address
  4681. * Return value: SUCCESS on success and an appropriate (-)ve integer
  4682. * as defined in errno.h file on failure.
  4683. */
  4684. static int do_s2io_prog_unicast(struct net_device *dev, u8 *addr)
  4685. {
  4686. struct s2io_nic *sp = netdev_priv(dev);
  4687. register u64 mac_addr = 0, perm_addr = 0;
  4688. int i;
  4689. u64 tmp64;
  4690. struct config_param *config = &sp->config;
  4691. /*
  4692. * Set the new MAC address as the new unicast filter and reflect this
  4693. * change on the device address registered with the OS. It will be
  4694. * at offset 0.
  4695. */
  4696. for (i = 0; i < ETH_ALEN; i++) {
  4697. mac_addr <<= 8;
  4698. mac_addr |= addr[i];
  4699. perm_addr <<= 8;
  4700. perm_addr |= sp->def_mac_addr[0].mac_addr[i];
  4701. }
  4702. /* check if the dev_addr is different than perm_addr */
  4703. if (mac_addr == perm_addr)
  4704. return SUCCESS;
  4705. /* check if the mac already preset in CAM */
  4706. for (i = 1; i < config->max_mac_addr; i++) {
  4707. tmp64 = do_s2io_read_unicast_mc(sp, i);
  4708. if (tmp64 == S2IO_DISABLE_MAC_ENTRY) /* CAM entry is empty */
  4709. break;
  4710. if (tmp64 == mac_addr) {
  4711. DBG_PRINT(INFO_DBG,
  4712. "MAC addr:0x%llx already present in CAM\n",
  4713. (unsigned long long)mac_addr);
  4714. return SUCCESS;
  4715. }
  4716. }
  4717. if (i == config->max_mac_addr) {
  4718. DBG_PRINT(ERR_DBG, "CAM full no space left for Unicast MAC\n");
  4719. return FAILURE;
  4720. }
  4721. /* Update the internal structure with this new mac address */
  4722. do_s2io_copy_mac_addr(sp, i, mac_addr);
  4723. return do_s2io_add_mac(sp, mac_addr, i);
  4724. }
  4725. /**
  4726. * s2io_ethtool_sset - Sets different link parameters.
  4727. * @sp : private member of the device structure, which is a pointer to the * s2io_nic structure.
  4728. * @info: pointer to the structure with parameters given by ethtool to set
  4729. * link information.
  4730. * Description:
  4731. * The function sets different link parameters provided by the user onto
  4732. * the NIC.
  4733. * Return value:
  4734. * 0 on success.
  4735. */
  4736. static int s2io_ethtool_sset(struct net_device *dev,
  4737. struct ethtool_cmd *info)
  4738. {
  4739. struct s2io_nic *sp = netdev_priv(dev);
  4740. if ((info->autoneg == AUTONEG_ENABLE) ||
  4741. (ethtool_cmd_speed(info) != SPEED_10000) ||
  4742. (info->duplex != DUPLEX_FULL))
  4743. return -EINVAL;
  4744. else {
  4745. s2io_close(sp->dev);
  4746. s2io_open(sp->dev);
  4747. }
  4748. return 0;
  4749. }
  4750. /**
  4751. * s2io_ethtol_gset - Return link specific information.
  4752. * @sp : private member of the device structure, pointer to the
  4753. * s2io_nic structure.
  4754. * @info : pointer to the structure with parameters given by ethtool
  4755. * to return link information.
  4756. * Description:
  4757. * Returns link specific information like speed, duplex etc.. to ethtool.
  4758. * Return value :
  4759. * return 0 on success.
  4760. */
  4761. static int s2io_ethtool_gset(struct net_device *dev, struct ethtool_cmd *info)
  4762. {
  4763. struct s2io_nic *sp = netdev_priv(dev);
  4764. info->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
  4765. info->advertising = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
  4766. info->port = PORT_FIBRE;
  4767. /* info->transceiver */
  4768. info->transceiver = XCVR_EXTERNAL;
  4769. if (netif_carrier_ok(sp->dev)) {
  4770. ethtool_cmd_speed_set(info, SPEED_10000);
  4771. info->duplex = DUPLEX_FULL;
  4772. } else {
  4773. ethtool_cmd_speed_set(info, -1);
  4774. info->duplex = -1;
  4775. }
  4776. info->autoneg = AUTONEG_DISABLE;
  4777. return 0;
  4778. }
  4779. /**
  4780. * s2io_ethtool_gdrvinfo - Returns driver specific information.
  4781. * @sp : private member of the device structure, which is a pointer to the
  4782. * s2io_nic structure.
  4783. * @info : pointer to the structure with parameters given by ethtool to
  4784. * return driver information.
  4785. * Description:
  4786. * Returns driver specefic information like name, version etc.. to ethtool.
  4787. * Return value:
  4788. * void
  4789. */
  4790. static void s2io_ethtool_gdrvinfo(struct net_device *dev,
  4791. struct ethtool_drvinfo *info)
  4792. {
  4793. struct s2io_nic *sp = netdev_priv(dev);
  4794. strlcpy(info->driver, s2io_driver_name, sizeof(info->driver));
  4795. strlcpy(info->version, s2io_driver_version, sizeof(info->version));
  4796. strlcpy(info->bus_info, pci_name(sp->pdev), sizeof(info->bus_info));
  4797. info->regdump_len = XENA_REG_SPACE;
  4798. info->eedump_len = XENA_EEPROM_SPACE;
  4799. }
  4800. /**
  4801. * s2io_ethtool_gregs - dumps the entire space of Xfame into the buffer.
  4802. * @sp: private member of the device structure, which is a pointer to the
  4803. * s2io_nic structure.
  4804. * @regs : pointer to the structure with parameters given by ethtool for
  4805. * dumping the registers.
  4806. * @reg_space: The input argumnet into which all the registers are dumped.
  4807. * Description:
  4808. * Dumps the entire register space of xFrame NIC into the user given
  4809. * buffer area.
  4810. * Return value :
  4811. * void .
  4812. */
  4813. static void s2io_ethtool_gregs(struct net_device *dev,
  4814. struct ethtool_regs *regs, void *space)
  4815. {
  4816. int i;
  4817. u64 reg;
  4818. u8 *reg_space = (u8 *)space;
  4819. struct s2io_nic *sp = netdev_priv(dev);
  4820. regs->len = XENA_REG_SPACE;
  4821. regs->version = sp->pdev->subsystem_device;
  4822. for (i = 0; i < regs->len; i += 8) {
  4823. reg = readq(sp->bar0 + i);
  4824. memcpy((reg_space + i), &reg, 8);
  4825. }
  4826. }
  4827. /*
  4828. * s2io_set_led - control NIC led
  4829. */
  4830. static void s2io_set_led(struct s2io_nic *sp, bool on)
  4831. {
  4832. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  4833. u16 subid = sp->pdev->subsystem_device;
  4834. u64 val64;
  4835. if ((sp->device_type == XFRAME_II_DEVICE) ||
  4836. ((subid & 0xFF) >= 0x07)) {
  4837. val64 = readq(&bar0->gpio_control);
  4838. if (on)
  4839. val64 |= GPIO_CTRL_GPIO_0;
  4840. else
  4841. val64 &= ~GPIO_CTRL_GPIO_0;
  4842. writeq(val64, &bar0->gpio_control);
  4843. } else {
  4844. val64 = readq(&bar0->adapter_control);
  4845. if (on)
  4846. val64 |= ADAPTER_LED_ON;
  4847. else
  4848. val64 &= ~ADAPTER_LED_ON;
  4849. writeq(val64, &bar0->adapter_control);
  4850. }
  4851. }
  4852. /**
  4853. * s2io_ethtool_set_led - To physically identify the nic on the system.
  4854. * @dev : network device
  4855. * @state: led setting
  4856. *
  4857. * Description: Used to physically identify the NIC on the system.
  4858. * The Link LED will blink for a time specified by the user for
  4859. * identification.
  4860. * NOTE: The Link has to be Up to be able to blink the LED. Hence
  4861. * identification is possible only if it's link is up.
  4862. */
  4863. static int s2io_ethtool_set_led(struct net_device *dev,
  4864. enum ethtool_phys_id_state state)
  4865. {
  4866. struct s2io_nic *sp = netdev_priv(dev);
  4867. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  4868. u16 subid = sp->pdev->subsystem_device;
  4869. if ((sp->device_type == XFRAME_I_DEVICE) && ((subid & 0xFF) < 0x07)) {
  4870. u64 val64 = readq(&bar0->adapter_control);
  4871. if (!(val64 & ADAPTER_CNTL_EN)) {
  4872. pr_err("Adapter Link down, cannot blink LED\n");
  4873. return -EAGAIN;
  4874. }
  4875. }
  4876. switch (state) {
  4877. case ETHTOOL_ID_ACTIVE:
  4878. sp->adapt_ctrl_org = readq(&bar0->gpio_control);
  4879. return 1; /* cycle on/off once per second */
  4880. case ETHTOOL_ID_ON:
  4881. s2io_set_led(sp, true);
  4882. break;
  4883. case ETHTOOL_ID_OFF:
  4884. s2io_set_led(sp, false);
  4885. break;
  4886. case ETHTOOL_ID_INACTIVE:
  4887. if (CARDS_WITH_FAULTY_LINK_INDICATORS(sp->device_type, subid))
  4888. writeq(sp->adapt_ctrl_org, &bar0->gpio_control);
  4889. }
  4890. return 0;
  4891. }
  4892. static void s2io_ethtool_gringparam(struct net_device *dev,
  4893. struct ethtool_ringparam *ering)
  4894. {
  4895. struct s2io_nic *sp = netdev_priv(dev);
  4896. int i, tx_desc_count = 0, rx_desc_count = 0;
  4897. if (sp->rxd_mode == RXD_MODE_1) {
  4898. ering->rx_max_pending = MAX_RX_DESC_1;
  4899. ering->rx_jumbo_max_pending = MAX_RX_DESC_1;
  4900. } else {
  4901. ering->rx_max_pending = MAX_RX_DESC_2;
  4902. ering->rx_jumbo_max_pending = MAX_RX_DESC_2;
  4903. }
  4904. ering->tx_max_pending = MAX_TX_DESC;
  4905. for (i = 0; i < sp->config.rx_ring_num; i++)
  4906. rx_desc_count += sp->config.rx_cfg[i].num_rxd;
  4907. ering->rx_pending = rx_desc_count;
  4908. ering->rx_jumbo_pending = rx_desc_count;
  4909. for (i = 0; i < sp->config.tx_fifo_num; i++)
  4910. tx_desc_count += sp->config.tx_cfg[i].fifo_len;
  4911. ering->tx_pending = tx_desc_count;
  4912. DBG_PRINT(INFO_DBG, "max txds: %d\n", sp->config.max_txds);
  4913. }
  4914. /**
  4915. * s2io_ethtool_getpause_data -Pause frame frame generation and reception.
  4916. * @sp : private member of the device structure, which is a pointer to the
  4917. * s2io_nic structure.
  4918. * @ep : pointer to the structure with pause parameters given by ethtool.
  4919. * Description:
  4920. * Returns the Pause frame generation and reception capability of the NIC.
  4921. * Return value:
  4922. * void
  4923. */
  4924. static void s2io_ethtool_getpause_data(struct net_device *dev,
  4925. struct ethtool_pauseparam *ep)
  4926. {
  4927. u64 val64;
  4928. struct s2io_nic *sp = netdev_priv(dev);
  4929. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  4930. val64 = readq(&bar0->rmac_pause_cfg);
  4931. if (val64 & RMAC_PAUSE_GEN_ENABLE)
  4932. ep->tx_pause = true;
  4933. if (val64 & RMAC_PAUSE_RX_ENABLE)
  4934. ep->rx_pause = true;
  4935. ep->autoneg = false;
  4936. }
  4937. /**
  4938. * s2io_ethtool_setpause_data - set/reset pause frame generation.
  4939. * @sp : private member of the device structure, which is a pointer to the
  4940. * s2io_nic structure.
  4941. * @ep : pointer to the structure with pause parameters given by ethtool.
  4942. * Description:
  4943. * It can be used to set or reset Pause frame generation or reception
  4944. * support of the NIC.
  4945. * Return value:
  4946. * int, returns 0 on Success
  4947. */
  4948. static int s2io_ethtool_setpause_data(struct net_device *dev,
  4949. struct ethtool_pauseparam *ep)
  4950. {
  4951. u64 val64;
  4952. struct s2io_nic *sp = netdev_priv(dev);
  4953. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  4954. val64 = readq(&bar0->rmac_pause_cfg);
  4955. if (ep->tx_pause)
  4956. val64 |= RMAC_PAUSE_GEN_ENABLE;
  4957. else
  4958. val64 &= ~RMAC_PAUSE_GEN_ENABLE;
  4959. if (ep->rx_pause)
  4960. val64 |= RMAC_PAUSE_RX_ENABLE;
  4961. else
  4962. val64 &= ~RMAC_PAUSE_RX_ENABLE;
  4963. writeq(val64, &bar0->rmac_pause_cfg);
  4964. return 0;
  4965. }
  4966. /**
  4967. * read_eeprom - reads 4 bytes of data from user given offset.
  4968. * @sp : private member of the device structure, which is a pointer to the
  4969. * s2io_nic structure.
  4970. * @off : offset at which the data must be written
  4971. * @data : Its an output parameter where the data read at the given
  4972. * offset is stored.
  4973. * Description:
  4974. * Will read 4 bytes of data from the user given offset and return the
  4975. * read data.
  4976. * NOTE: Will allow to read only part of the EEPROM visible through the
  4977. * I2C bus.
  4978. * Return value:
  4979. * -1 on failure and 0 on success.
  4980. */
  4981. #define S2IO_DEV_ID 5
  4982. static int read_eeprom(struct s2io_nic *sp, int off, u64 *data)
  4983. {
  4984. int ret = -1;
  4985. u32 exit_cnt = 0;
  4986. u64 val64;
  4987. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  4988. if (sp->device_type == XFRAME_I_DEVICE) {
  4989. val64 = I2C_CONTROL_DEV_ID(S2IO_DEV_ID) |
  4990. I2C_CONTROL_ADDR(off) |
  4991. I2C_CONTROL_BYTE_CNT(0x3) |
  4992. I2C_CONTROL_READ |
  4993. I2C_CONTROL_CNTL_START;
  4994. SPECIAL_REG_WRITE(val64, &bar0->i2c_control, LF);
  4995. while (exit_cnt < 5) {
  4996. val64 = readq(&bar0->i2c_control);
  4997. if (I2C_CONTROL_CNTL_END(val64)) {
  4998. *data = I2C_CONTROL_GET_DATA(val64);
  4999. ret = 0;
  5000. break;
  5001. }
  5002. msleep(50);
  5003. exit_cnt++;
  5004. }
  5005. }
  5006. if (sp->device_type == XFRAME_II_DEVICE) {
  5007. val64 = SPI_CONTROL_KEY(0x9) | SPI_CONTROL_SEL1 |
  5008. SPI_CONTROL_BYTECNT(0x3) |
  5009. SPI_CONTROL_CMD(0x3) | SPI_CONTROL_ADDR(off);
  5010. SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
  5011. val64 |= SPI_CONTROL_REQ;
  5012. SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
  5013. while (exit_cnt < 5) {
  5014. val64 = readq(&bar0->spi_control);
  5015. if (val64 & SPI_CONTROL_NACK) {
  5016. ret = 1;
  5017. break;
  5018. } else if (val64 & SPI_CONTROL_DONE) {
  5019. *data = readq(&bar0->spi_data);
  5020. *data &= 0xffffff;
  5021. ret = 0;
  5022. break;
  5023. }
  5024. msleep(50);
  5025. exit_cnt++;
  5026. }
  5027. }
  5028. return ret;
  5029. }
  5030. /**
  5031. * write_eeprom - actually writes the relevant part of the data value.
  5032. * @sp : private member of the device structure, which is a pointer to the
  5033. * s2io_nic structure.
  5034. * @off : offset at which the data must be written
  5035. * @data : The data that is to be written
  5036. * @cnt : Number of bytes of the data that are actually to be written into
  5037. * the Eeprom. (max of 3)
  5038. * Description:
  5039. * Actually writes the relevant part of the data value into the Eeprom
  5040. * through the I2C bus.
  5041. * Return value:
  5042. * 0 on success, -1 on failure.
  5043. */
  5044. static int write_eeprom(struct s2io_nic *sp, int off, u64 data, int cnt)
  5045. {
  5046. int exit_cnt = 0, ret = -1;
  5047. u64 val64;
  5048. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  5049. if (sp->device_type == XFRAME_I_DEVICE) {
  5050. val64 = I2C_CONTROL_DEV_ID(S2IO_DEV_ID) |
  5051. I2C_CONTROL_ADDR(off) |
  5052. I2C_CONTROL_BYTE_CNT(cnt) |
  5053. I2C_CONTROL_SET_DATA((u32)data) |
  5054. I2C_CONTROL_CNTL_START;
  5055. SPECIAL_REG_WRITE(val64, &bar0->i2c_control, LF);
  5056. while (exit_cnt < 5) {
  5057. val64 = readq(&bar0->i2c_control);
  5058. if (I2C_CONTROL_CNTL_END(val64)) {
  5059. if (!(val64 & I2C_CONTROL_NACK))
  5060. ret = 0;
  5061. break;
  5062. }
  5063. msleep(50);
  5064. exit_cnt++;
  5065. }
  5066. }
  5067. if (sp->device_type == XFRAME_II_DEVICE) {
  5068. int write_cnt = (cnt == 8) ? 0 : cnt;
  5069. writeq(SPI_DATA_WRITE(data, (cnt << 3)), &bar0->spi_data);
  5070. val64 = SPI_CONTROL_KEY(0x9) | SPI_CONTROL_SEL1 |
  5071. SPI_CONTROL_BYTECNT(write_cnt) |
  5072. SPI_CONTROL_CMD(0x2) | SPI_CONTROL_ADDR(off);
  5073. SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
  5074. val64 |= SPI_CONTROL_REQ;
  5075. SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
  5076. while (exit_cnt < 5) {
  5077. val64 = readq(&bar0->spi_control);
  5078. if (val64 & SPI_CONTROL_NACK) {
  5079. ret = 1;
  5080. break;
  5081. } else if (val64 & SPI_CONTROL_DONE) {
  5082. ret = 0;
  5083. break;
  5084. }
  5085. msleep(50);
  5086. exit_cnt++;
  5087. }
  5088. }
  5089. return ret;
  5090. }
  5091. static void s2io_vpd_read(struct s2io_nic *nic)
  5092. {
  5093. u8 *vpd_data;
  5094. u8 data;
  5095. int i = 0, cnt, len, fail = 0;
  5096. int vpd_addr = 0x80;
  5097. struct swStat *swstats = &nic->mac_control.stats_info->sw_stat;
  5098. if (nic->device_type == XFRAME_II_DEVICE) {
  5099. strcpy(nic->product_name, "Xframe II 10GbE network adapter");
  5100. vpd_addr = 0x80;
  5101. } else {
  5102. strcpy(nic->product_name, "Xframe I 10GbE network adapter");
  5103. vpd_addr = 0x50;
  5104. }
  5105. strcpy(nic->serial_num, "NOT AVAILABLE");
  5106. vpd_data = kmalloc(256, GFP_KERNEL);
  5107. if (!vpd_data) {
  5108. swstats->mem_alloc_fail_cnt++;
  5109. return;
  5110. }
  5111. swstats->mem_allocated += 256;
  5112. for (i = 0; i < 256; i += 4) {
  5113. pci_write_config_byte(nic->pdev, (vpd_addr + 2), i);
  5114. pci_read_config_byte(nic->pdev, (vpd_addr + 2), &data);
  5115. pci_write_config_byte(nic->pdev, (vpd_addr + 3), 0);
  5116. for (cnt = 0; cnt < 5; cnt++) {
  5117. msleep(2);
  5118. pci_read_config_byte(nic->pdev, (vpd_addr + 3), &data);
  5119. if (data == 0x80)
  5120. break;
  5121. }
  5122. if (cnt >= 5) {
  5123. DBG_PRINT(ERR_DBG, "Read of VPD data failed\n");
  5124. fail = 1;
  5125. break;
  5126. }
  5127. pci_read_config_dword(nic->pdev, (vpd_addr + 4),
  5128. (u32 *)&vpd_data[i]);
  5129. }
  5130. if (!fail) {
  5131. /* read serial number of adapter */
  5132. for (cnt = 0; cnt < 252; cnt++) {
  5133. if ((vpd_data[cnt] == 'S') &&
  5134. (vpd_data[cnt+1] == 'N')) {
  5135. len = vpd_data[cnt+2];
  5136. if (len < min(VPD_STRING_LEN, 256-cnt-2)) {
  5137. memcpy(nic->serial_num,
  5138. &vpd_data[cnt + 3],
  5139. len);
  5140. memset(nic->serial_num+len,
  5141. 0,
  5142. VPD_STRING_LEN-len);
  5143. break;
  5144. }
  5145. }
  5146. }
  5147. }
  5148. if ((!fail) && (vpd_data[1] < VPD_STRING_LEN)) {
  5149. len = vpd_data[1];
  5150. memcpy(nic->product_name, &vpd_data[3], len);
  5151. nic->product_name[len] = 0;
  5152. }
  5153. kfree(vpd_data);
  5154. swstats->mem_freed += 256;
  5155. }
  5156. /**
  5157. * s2io_ethtool_geeprom - reads the value stored in the Eeprom.
  5158. * @sp : private member of the device structure, which is a pointer to the * s2io_nic structure.
  5159. * @eeprom : pointer to the user level structure provided by ethtool,
  5160. * containing all relevant information.
  5161. * @data_buf : user defined value to be written into Eeprom.
  5162. * Description: Reads the values stored in the Eeprom at given offset
  5163. * for a given length. Stores these values int the input argument data
  5164. * buffer 'data_buf' and returns these to the caller (ethtool.)
  5165. * Return value:
  5166. * int 0 on success
  5167. */
  5168. static int s2io_ethtool_geeprom(struct net_device *dev,
  5169. struct ethtool_eeprom *eeprom, u8 * data_buf)
  5170. {
  5171. u32 i, valid;
  5172. u64 data;
  5173. struct s2io_nic *sp = netdev_priv(dev);
  5174. eeprom->magic = sp->pdev->vendor | (sp->pdev->device << 16);
  5175. if ((eeprom->offset + eeprom->len) > (XENA_EEPROM_SPACE))
  5176. eeprom->len = XENA_EEPROM_SPACE - eeprom->offset;
  5177. for (i = 0; i < eeprom->len; i += 4) {
  5178. if (read_eeprom(sp, (eeprom->offset + i), &data)) {
  5179. DBG_PRINT(ERR_DBG, "Read of EEPROM failed\n");
  5180. return -EFAULT;
  5181. }
  5182. valid = INV(data);
  5183. memcpy((data_buf + i), &valid, 4);
  5184. }
  5185. return 0;
  5186. }
  5187. /**
  5188. * s2io_ethtool_seeprom - tries to write the user provided value in Eeprom
  5189. * @sp : private member of the device structure, which is a pointer to the
  5190. * s2io_nic structure.
  5191. * @eeprom : pointer to the user level structure provided by ethtool,
  5192. * containing all relevant information.
  5193. * @data_buf ; user defined value to be written into Eeprom.
  5194. * Description:
  5195. * Tries to write the user provided value in the Eeprom, at the offset
  5196. * given by the user.
  5197. * Return value:
  5198. * 0 on success, -EFAULT on failure.
  5199. */
  5200. static int s2io_ethtool_seeprom(struct net_device *dev,
  5201. struct ethtool_eeprom *eeprom,
  5202. u8 *data_buf)
  5203. {
  5204. int len = eeprom->len, cnt = 0;
  5205. u64 valid = 0, data;
  5206. struct s2io_nic *sp = netdev_priv(dev);
  5207. if (eeprom->magic != (sp->pdev->vendor | (sp->pdev->device << 16))) {
  5208. DBG_PRINT(ERR_DBG,
  5209. "ETHTOOL_WRITE_EEPROM Err: "
  5210. "Magic value is wrong, it is 0x%x should be 0x%x\n",
  5211. (sp->pdev->vendor | (sp->pdev->device << 16)),
  5212. eeprom->magic);
  5213. return -EFAULT;
  5214. }
  5215. while (len) {
  5216. data = (u32)data_buf[cnt] & 0x000000FF;
  5217. if (data)
  5218. valid = (u32)(data << 24);
  5219. else
  5220. valid = data;
  5221. if (write_eeprom(sp, (eeprom->offset + cnt), valid, 0)) {
  5222. DBG_PRINT(ERR_DBG,
  5223. "ETHTOOL_WRITE_EEPROM Err: "
  5224. "Cannot write into the specified offset\n");
  5225. return -EFAULT;
  5226. }
  5227. cnt++;
  5228. len--;
  5229. }
  5230. return 0;
  5231. }
  5232. /**
  5233. * s2io_register_test - reads and writes into all clock domains.
  5234. * @sp : private member of the device structure, which is a pointer to the
  5235. * s2io_nic structure.
  5236. * @data : variable that returns the result of each of the test conducted b
  5237. * by the driver.
  5238. * Description:
  5239. * Read and write into all clock domains. The NIC has 3 clock domains,
  5240. * see that registers in all the three regions are accessible.
  5241. * Return value:
  5242. * 0 on success.
  5243. */
  5244. static int s2io_register_test(struct s2io_nic *sp, uint64_t *data)
  5245. {
  5246. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  5247. u64 val64 = 0, exp_val;
  5248. int fail = 0;
  5249. val64 = readq(&bar0->pif_rd_swapper_fb);
  5250. if (val64 != 0x123456789abcdefULL) {
  5251. fail = 1;
  5252. DBG_PRINT(INFO_DBG, "Read Test level %d fails\n", 1);
  5253. }
  5254. val64 = readq(&bar0->rmac_pause_cfg);
  5255. if (val64 != 0xc000ffff00000000ULL) {
  5256. fail = 1;
  5257. DBG_PRINT(INFO_DBG, "Read Test level %d fails\n", 2);
  5258. }
  5259. val64 = readq(&bar0->rx_queue_cfg);
  5260. if (sp->device_type == XFRAME_II_DEVICE)
  5261. exp_val = 0x0404040404040404ULL;
  5262. else
  5263. exp_val = 0x0808080808080808ULL;
  5264. if (val64 != exp_val) {
  5265. fail = 1;
  5266. DBG_PRINT(INFO_DBG, "Read Test level %d fails\n", 3);
  5267. }
  5268. val64 = readq(&bar0->xgxs_efifo_cfg);
  5269. if (val64 != 0x000000001923141EULL) {
  5270. fail = 1;
  5271. DBG_PRINT(INFO_DBG, "Read Test level %d fails\n", 4);
  5272. }
  5273. val64 = 0x5A5A5A5A5A5A5A5AULL;
  5274. writeq(val64, &bar0->xmsi_data);
  5275. val64 = readq(&bar0->xmsi_data);
  5276. if (val64 != 0x5A5A5A5A5A5A5A5AULL) {
  5277. fail = 1;
  5278. DBG_PRINT(ERR_DBG, "Write Test level %d fails\n", 1);
  5279. }
  5280. val64 = 0xA5A5A5A5A5A5A5A5ULL;
  5281. writeq(val64, &bar0->xmsi_data);
  5282. val64 = readq(&bar0->xmsi_data);
  5283. if (val64 != 0xA5A5A5A5A5A5A5A5ULL) {
  5284. fail = 1;
  5285. DBG_PRINT(ERR_DBG, "Write Test level %d fails\n", 2);
  5286. }
  5287. *data = fail;
  5288. return fail;
  5289. }
  5290. /**
  5291. * s2io_eeprom_test - to verify that EEprom in the xena can be programmed.
  5292. * @sp : private member of the device structure, which is a pointer to the
  5293. * s2io_nic structure.
  5294. * @data:variable that returns the result of each of the test conducted by
  5295. * the driver.
  5296. * Description:
  5297. * Verify that EEPROM in the xena can be programmed using I2C_CONTROL
  5298. * register.
  5299. * Return value:
  5300. * 0 on success.
  5301. */
  5302. static int s2io_eeprom_test(struct s2io_nic *sp, uint64_t *data)
  5303. {
  5304. int fail = 0;
  5305. u64 ret_data, org_4F0, org_7F0;
  5306. u8 saved_4F0 = 0, saved_7F0 = 0;
  5307. struct net_device *dev = sp->dev;
  5308. /* Test Write Error at offset 0 */
  5309. /* Note that SPI interface allows write access to all areas
  5310. * of EEPROM. Hence doing all negative testing only for Xframe I.
  5311. */
  5312. if (sp->device_type == XFRAME_I_DEVICE)
  5313. if (!write_eeprom(sp, 0, 0, 3))
  5314. fail = 1;
  5315. /* Save current values at offsets 0x4F0 and 0x7F0 */
  5316. if (!read_eeprom(sp, 0x4F0, &org_4F0))
  5317. saved_4F0 = 1;
  5318. if (!read_eeprom(sp, 0x7F0, &org_7F0))
  5319. saved_7F0 = 1;
  5320. /* Test Write at offset 4f0 */
  5321. if (write_eeprom(sp, 0x4F0, 0x012345, 3))
  5322. fail = 1;
  5323. if (read_eeprom(sp, 0x4F0, &ret_data))
  5324. fail = 1;
  5325. if (ret_data != 0x012345) {
  5326. DBG_PRINT(ERR_DBG, "%s: eeprom test error at offset 0x4F0. "
  5327. "Data written %llx Data read %llx\n",
  5328. dev->name, (unsigned long long)0x12345,
  5329. (unsigned long long)ret_data);
  5330. fail = 1;
  5331. }
  5332. /* Reset the EEPROM data go FFFF */
  5333. write_eeprom(sp, 0x4F0, 0xFFFFFF, 3);
  5334. /* Test Write Request Error at offset 0x7c */
  5335. if (sp->device_type == XFRAME_I_DEVICE)
  5336. if (!write_eeprom(sp, 0x07C, 0, 3))
  5337. fail = 1;
  5338. /* Test Write Request at offset 0x7f0 */
  5339. if (write_eeprom(sp, 0x7F0, 0x012345, 3))
  5340. fail = 1;
  5341. if (read_eeprom(sp, 0x7F0, &ret_data))
  5342. fail = 1;
  5343. if (ret_data != 0x012345) {
  5344. DBG_PRINT(ERR_DBG, "%s: eeprom test error at offset 0x7F0. "
  5345. "Data written %llx Data read %llx\n",
  5346. dev->name, (unsigned long long)0x12345,
  5347. (unsigned long long)ret_data);
  5348. fail = 1;
  5349. }
  5350. /* Reset the EEPROM data go FFFF */
  5351. write_eeprom(sp, 0x7F0, 0xFFFFFF, 3);
  5352. if (sp->device_type == XFRAME_I_DEVICE) {
  5353. /* Test Write Error at offset 0x80 */
  5354. if (!write_eeprom(sp, 0x080, 0, 3))
  5355. fail = 1;
  5356. /* Test Write Error at offset 0xfc */
  5357. if (!write_eeprom(sp, 0x0FC, 0, 3))
  5358. fail = 1;
  5359. /* Test Write Error at offset 0x100 */
  5360. if (!write_eeprom(sp, 0x100, 0, 3))
  5361. fail = 1;
  5362. /* Test Write Error at offset 4ec */
  5363. if (!write_eeprom(sp, 0x4EC, 0, 3))
  5364. fail = 1;
  5365. }
  5366. /* Restore values at offsets 0x4F0 and 0x7F0 */
  5367. if (saved_4F0)
  5368. write_eeprom(sp, 0x4F0, org_4F0, 3);
  5369. if (saved_7F0)
  5370. write_eeprom(sp, 0x7F0, org_7F0, 3);
  5371. *data = fail;
  5372. return fail;
  5373. }
  5374. /**
  5375. * s2io_bist_test - invokes the MemBist test of the card .
  5376. * @sp : private member of the device structure, which is a pointer to the
  5377. * s2io_nic structure.
  5378. * @data:variable that returns the result of each of the test conducted by
  5379. * the driver.
  5380. * Description:
  5381. * This invokes the MemBist test of the card. We give around
  5382. * 2 secs time for the Test to complete. If it's still not complete
  5383. * within this peiod, we consider that the test failed.
  5384. * Return value:
  5385. * 0 on success and -1 on failure.
  5386. */
  5387. static int s2io_bist_test(struct s2io_nic *sp, uint64_t *data)
  5388. {
  5389. u8 bist = 0;
  5390. int cnt = 0, ret = -1;
  5391. pci_read_config_byte(sp->pdev, PCI_BIST, &bist);
  5392. bist |= PCI_BIST_START;
  5393. pci_write_config_word(sp->pdev, PCI_BIST, bist);
  5394. while (cnt < 20) {
  5395. pci_read_config_byte(sp->pdev, PCI_BIST, &bist);
  5396. if (!(bist & PCI_BIST_START)) {
  5397. *data = (bist & PCI_BIST_CODE_MASK);
  5398. ret = 0;
  5399. break;
  5400. }
  5401. msleep(100);
  5402. cnt++;
  5403. }
  5404. return ret;
  5405. }
  5406. /**
  5407. * s2io-link_test - verifies the link state of the nic
  5408. * @sp ; private member of the device structure, which is a pointer to the
  5409. * s2io_nic structure.
  5410. * @data: variable that returns the result of each of the test conducted by
  5411. * the driver.
  5412. * Description:
  5413. * The function verifies the link state of the NIC and updates the input
  5414. * argument 'data' appropriately.
  5415. * Return value:
  5416. * 0 on success.
  5417. */
  5418. static int s2io_link_test(struct s2io_nic *sp, uint64_t *data)
  5419. {
  5420. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  5421. u64 val64;
  5422. val64 = readq(&bar0->adapter_status);
  5423. if (!(LINK_IS_UP(val64)))
  5424. *data = 1;
  5425. else
  5426. *data = 0;
  5427. return *data;
  5428. }
  5429. /**
  5430. * s2io_rldram_test - offline test for access to the RldRam chip on the NIC
  5431. * @sp - private member of the device structure, which is a pointer to the
  5432. * s2io_nic structure.
  5433. * @data - variable that returns the result of each of the test
  5434. * conducted by the driver.
  5435. * Description:
  5436. * This is one of the offline test that tests the read and write
  5437. * access to the RldRam chip on the NIC.
  5438. * Return value:
  5439. * 0 on success.
  5440. */
  5441. static int s2io_rldram_test(struct s2io_nic *sp, uint64_t *data)
  5442. {
  5443. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  5444. u64 val64;
  5445. int cnt, iteration = 0, test_fail = 0;
  5446. val64 = readq(&bar0->adapter_control);
  5447. val64 &= ~ADAPTER_ECC_EN;
  5448. writeq(val64, &bar0->adapter_control);
  5449. val64 = readq(&bar0->mc_rldram_test_ctrl);
  5450. val64 |= MC_RLDRAM_TEST_MODE;
  5451. SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_test_ctrl, LF);
  5452. val64 = readq(&bar0->mc_rldram_mrs);
  5453. val64 |= MC_RLDRAM_QUEUE_SIZE_ENABLE;
  5454. SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_mrs, UF);
  5455. val64 |= MC_RLDRAM_MRS_ENABLE;
  5456. SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_mrs, UF);
  5457. while (iteration < 2) {
  5458. val64 = 0x55555555aaaa0000ULL;
  5459. if (iteration == 1)
  5460. val64 ^= 0xFFFFFFFFFFFF0000ULL;
  5461. writeq(val64, &bar0->mc_rldram_test_d0);
  5462. val64 = 0xaaaa5a5555550000ULL;
  5463. if (iteration == 1)
  5464. val64 ^= 0xFFFFFFFFFFFF0000ULL;
  5465. writeq(val64, &bar0->mc_rldram_test_d1);
  5466. val64 = 0x55aaaaaaaa5a0000ULL;
  5467. if (iteration == 1)
  5468. val64 ^= 0xFFFFFFFFFFFF0000ULL;
  5469. writeq(val64, &bar0->mc_rldram_test_d2);
  5470. val64 = (u64) (0x0000003ffffe0100ULL);
  5471. writeq(val64, &bar0->mc_rldram_test_add);
  5472. val64 = MC_RLDRAM_TEST_MODE |
  5473. MC_RLDRAM_TEST_WRITE |
  5474. MC_RLDRAM_TEST_GO;
  5475. SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_test_ctrl, LF);
  5476. for (cnt = 0; cnt < 5; cnt++) {
  5477. val64 = readq(&bar0->mc_rldram_test_ctrl);
  5478. if (val64 & MC_RLDRAM_TEST_DONE)
  5479. break;
  5480. msleep(200);
  5481. }
  5482. if (cnt == 5)
  5483. break;
  5484. val64 = MC_RLDRAM_TEST_MODE | MC_RLDRAM_TEST_GO;
  5485. SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_test_ctrl, LF);
  5486. for (cnt = 0; cnt < 5; cnt++) {
  5487. val64 = readq(&bar0->mc_rldram_test_ctrl);
  5488. if (val64 & MC_RLDRAM_TEST_DONE)
  5489. break;
  5490. msleep(500);
  5491. }
  5492. if (cnt == 5)
  5493. break;
  5494. val64 = readq(&bar0->mc_rldram_test_ctrl);
  5495. if (!(val64 & MC_RLDRAM_TEST_PASS))
  5496. test_fail = 1;
  5497. iteration++;
  5498. }
  5499. *data = test_fail;
  5500. /* Bring the adapter out of test mode */
  5501. SPECIAL_REG_WRITE(0, &bar0->mc_rldram_test_ctrl, LF);
  5502. return test_fail;
  5503. }
  5504. /**
  5505. * s2io_ethtool_test - conducts 6 tsets to determine the health of card.
  5506. * @sp : private member of the device structure, which is a pointer to the
  5507. * s2io_nic structure.
  5508. * @ethtest : pointer to a ethtool command specific structure that will be
  5509. * returned to the user.
  5510. * @data : variable that returns the result of each of the test
  5511. * conducted by the driver.
  5512. * Description:
  5513. * This function conducts 6 tests ( 4 offline and 2 online) to determine
  5514. * the health of the card.
  5515. * Return value:
  5516. * void
  5517. */
  5518. static void s2io_ethtool_test(struct net_device *dev,
  5519. struct ethtool_test *ethtest,
  5520. uint64_t *data)
  5521. {
  5522. struct s2io_nic *sp = netdev_priv(dev);
  5523. int orig_state = netif_running(sp->dev);
  5524. if (ethtest->flags == ETH_TEST_FL_OFFLINE) {
  5525. /* Offline Tests. */
  5526. if (orig_state)
  5527. s2io_close(sp->dev);
  5528. if (s2io_register_test(sp, &data[0]))
  5529. ethtest->flags |= ETH_TEST_FL_FAILED;
  5530. s2io_reset(sp);
  5531. if (s2io_rldram_test(sp, &data[3]))
  5532. ethtest->flags |= ETH_TEST_FL_FAILED;
  5533. s2io_reset(sp);
  5534. if (s2io_eeprom_test(sp, &data[1]))
  5535. ethtest->flags |= ETH_TEST_FL_FAILED;
  5536. if (s2io_bist_test(sp, &data[4]))
  5537. ethtest->flags |= ETH_TEST_FL_FAILED;
  5538. if (orig_state)
  5539. s2io_open(sp->dev);
  5540. data[2] = 0;
  5541. } else {
  5542. /* Online Tests. */
  5543. if (!orig_state) {
  5544. DBG_PRINT(ERR_DBG, "%s: is not up, cannot run test\n",
  5545. dev->name);
  5546. data[0] = -1;
  5547. data[1] = -1;
  5548. data[2] = -1;
  5549. data[3] = -1;
  5550. data[4] = -1;
  5551. }
  5552. if (s2io_link_test(sp, &data[2]))
  5553. ethtest->flags |= ETH_TEST_FL_FAILED;
  5554. data[0] = 0;
  5555. data[1] = 0;
  5556. data[3] = 0;
  5557. data[4] = 0;
  5558. }
  5559. }
  5560. static void s2io_get_ethtool_stats(struct net_device *dev,
  5561. struct ethtool_stats *estats,
  5562. u64 *tmp_stats)
  5563. {
  5564. int i = 0, k;
  5565. struct s2io_nic *sp = netdev_priv(dev);
  5566. struct stat_block *stats = sp->mac_control.stats_info;
  5567. struct swStat *swstats = &stats->sw_stat;
  5568. struct xpakStat *xstats = &stats->xpak_stat;
  5569. s2io_updt_stats(sp);
  5570. tmp_stats[i++] =
  5571. (u64)le32_to_cpu(stats->tmac_frms_oflow) << 32 |
  5572. le32_to_cpu(stats->tmac_frms);
  5573. tmp_stats[i++] =
  5574. (u64)le32_to_cpu(stats->tmac_data_octets_oflow) << 32 |
  5575. le32_to_cpu(stats->tmac_data_octets);
  5576. tmp_stats[i++] = le64_to_cpu(stats->tmac_drop_frms);
  5577. tmp_stats[i++] =
  5578. (u64)le32_to_cpu(stats->tmac_mcst_frms_oflow) << 32 |
  5579. le32_to_cpu(stats->tmac_mcst_frms);
  5580. tmp_stats[i++] =
  5581. (u64)le32_to_cpu(stats->tmac_bcst_frms_oflow) << 32 |
  5582. le32_to_cpu(stats->tmac_bcst_frms);
  5583. tmp_stats[i++] = le64_to_cpu(stats->tmac_pause_ctrl_frms);
  5584. tmp_stats[i++] =
  5585. (u64)le32_to_cpu(stats->tmac_ttl_octets_oflow) << 32 |
  5586. le32_to_cpu(stats->tmac_ttl_octets);
  5587. tmp_stats[i++] =
  5588. (u64)le32_to_cpu(stats->tmac_ucst_frms_oflow) << 32 |
  5589. le32_to_cpu(stats->tmac_ucst_frms);
  5590. tmp_stats[i++] =
  5591. (u64)le32_to_cpu(stats->tmac_nucst_frms_oflow) << 32 |
  5592. le32_to_cpu(stats->tmac_nucst_frms);
  5593. tmp_stats[i++] =
  5594. (u64)le32_to_cpu(stats->tmac_any_err_frms_oflow) << 32 |
  5595. le32_to_cpu(stats->tmac_any_err_frms);
  5596. tmp_stats[i++] = le64_to_cpu(stats->tmac_ttl_less_fb_octets);
  5597. tmp_stats[i++] = le64_to_cpu(stats->tmac_vld_ip_octets);
  5598. tmp_stats[i++] =
  5599. (u64)le32_to_cpu(stats->tmac_vld_ip_oflow) << 32 |
  5600. le32_to_cpu(stats->tmac_vld_ip);
  5601. tmp_stats[i++] =
  5602. (u64)le32_to_cpu(stats->tmac_drop_ip_oflow) << 32 |
  5603. le32_to_cpu(stats->tmac_drop_ip);
  5604. tmp_stats[i++] =
  5605. (u64)le32_to_cpu(stats->tmac_icmp_oflow) << 32 |
  5606. le32_to_cpu(stats->tmac_icmp);
  5607. tmp_stats[i++] =
  5608. (u64)le32_to_cpu(stats->tmac_rst_tcp_oflow) << 32 |
  5609. le32_to_cpu(stats->tmac_rst_tcp);
  5610. tmp_stats[i++] = le64_to_cpu(stats->tmac_tcp);
  5611. tmp_stats[i++] = (u64)le32_to_cpu(stats->tmac_udp_oflow) << 32 |
  5612. le32_to_cpu(stats->tmac_udp);
  5613. tmp_stats[i++] =
  5614. (u64)le32_to_cpu(stats->rmac_vld_frms_oflow) << 32 |
  5615. le32_to_cpu(stats->rmac_vld_frms);
  5616. tmp_stats[i++] =
  5617. (u64)le32_to_cpu(stats->rmac_data_octets_oflow) << 32 |
  5618. le32_to_cpu(stats->rmac_data_octets);
  5619. tmp_stats[i++] = le64_to_cpu(stats->rmac_fcs_err_frms);
  5620. tmp_stats[i++] = le64_to_cpu(stats->rmac_drop_frms);
  5621. tmp_stats[i++] =
  5622. (u64)le32_to_cpu(stats->rmac_vld_mcst_frms_oflow) << 32 |
  5623. le32_to_cpu(stats->rmac_vld_mcst_frms);
  5624. tmp_stats[i++] =
  5625. (u64)le32_to_cpu(stats->rmac_vld_bcst_frms_oflow) << 32 |
  5626. le32_to_cpu(stats->rmac_vld_bcst_frms);
  5627. tmp_stats[i++] = le32_to_cpu(stats->rmac_in_rng_len_err_frms);
  5628. tmp_stats[i++] = le32_to_cpu(stats->rmac_out_rng_len_err_frms);
  5629. tmp_stats[i++] = le64_to_cpu(stats->rmac_long_frms);
  5630. tmp_stats[i++] = le64_to_cpu(stats->rmac_pause_ctrl_frms);
  5631. tmp_stats[i++] = le64_to_cpu(stats->rmac_unsup_ctrl_frms);
  5632. tmp_stats[i++] =
  5633. (u64)le32_to_cpu(stats->rmac_ttl_octets_oflow) << 32 |
  5634. le32_to_cpu(stats->rmac_ttl_octets);
  5635. tmp_stats[i++] =
  5636. (u64)le32_to_cpu(stats->rmac_accepted_ucst_frms_oflow) << 32
  5637. | le32_to_cpu(stats->rmac_accepted_ucst_frms);
  5638. tmp_stats[i++] =
  5639. (u64)le32_to_cpu(stats->rmac_accepted_nucst_frms_oflow)
  5640. << 32 | le32_to_cpu(stats->rmac_accepted_nucst_frms);
  5641. tmp_stats[i++] =
  5642. (u64)le32_to_cpu(stats->rmac_discarded_frms_oflow) << 32 |
  5643. le32_to_cpu(stats->rmac_discarded_frms);
  5644. tmp_stats[i++] =
  5645. (u64)le32_to_cpu(stats->rmac_drop_events_oflow)
  5646. << 32 | le32_to_cpu(stats->rmac_drop_events);
  5647. tmp_stats[i++] = le64_to_cpu(stats->rmac_ttl_less_fb_octets);
  5648. tmp_stats[i++] = le64_to_cpu(stats->rmac_ttl_frms);
  5649. tmp_stats[i++] =
  5650. (u64)le32_to_cpu(stats->rmac_usized_frms_oflow) << 32 |
  5651. le32_to_cpu(stats->rmac_usized_frms);
  5652. tmp_stats[i++] =
  5653. (u64)le32_to_cpu(stats->rmac_osized_frms_oflow) << 32 |
  5654. le32_to_cpu(stats->rmac_osized_frms);
  5655. tmp_stats[i++] =
  5656. (u64)le32_to_cpu(stats->rmac_frag_frms_oflow) << 32 |
  5657. le32_to_cpu(stats->rmac_frag_frms);
  5658. tmp_stats[i++] =
  5659. (u64)le32_to_cpu(stats->rmac_jabber_frms_oflow) << 32 |
  5660. le32_to_cpu(stats->rmac_jabber_frms);
  5661. tmp_stats[i++] = le64_to_cpu(stats->rmac_ttl_64_frms);
  5662. tmp_stats[i++] = le64_to_cpu(stats->rmac_ttl_65_127_frms);
  5663. tmp_stats[i++] = le64_to_cpu(stats->rmac_ttl_128_255_frms);
  5664. tmp_stats[i++] = le64_to_cpu(stats->rmac_ttl_256_511_frms);
  5665. tmp_stats[i++] = le64_to_cpu(stats->rmac_ttl_512_1023_frms);
  5666. tmp_stats[i++] = le64_to_cpu(stats->rmac_ttl_1024_1518_frms);
  5667. tmp_stats[i++] =
  5668. (u64)le32_to_cpu(stats->rmac_ip_oflow) << 32 |
  5669. le32_to_cpu(stats->rmac_ip);
  5670. tmp_stats[i++] = le64_to_cpu(stats->rmac_ip_octets);
  5671. tmp_stats[i++] = le32_to_cpu(stats->rmac_hdr_err_ip);
  5672. tmp_stats[i++] =
  5673. (u64)le32_to_cpu(stats->rmac_drop_ip_oflow) << 32 |
  5674. le32_to_cpu(stats->rmac_drop_ip);
  5675. tmp_stats[i++] =
  5676. (u64)le32_to_cpu(stats->rmac_icmp_oflow) << 32 |
  5677. le32_to_cpu(stats->rmac_icmp);
  5678. tmp_stats[i++] = le64_to_cpu(stats->rmac_tcp);
  5679. tmp_stats[i++] =
  5680. (u64)le32_to_cpu(stats->rmac_udp_oflow) << 32 |
  5681. le32_to_cpu(stats->rmac_udp);
  5682. tmp_stats[i++] =
  5683. (u64)le32_to_cpu(stats->rmac_err_drp_udp_oflow) << 32 |
  5684. le32_to_cpu(stats->rmac_err_drp_udp);
  5685. tmp_stats[i++] = le64_to_cpu(stats->rmac_xgmii_err_sym);
  5686. tmp_stats[i++] = le64_to_cpu(stats->rmac_frms_q0);
  5687. tmp_stats[i++] = le64_to_cpu(stats->rmac_frms_q1);
  5688. tmp_stats[i++] = le64_to_cpu(stats->rmac_frms_q2);
  5689. tmp_stats[i++] = le64_to_cpu(stats->rmac_frms_q3);
  5690. tmp_stats[i++] = le64_to_cpu(stats->rmac_frms_q4);
  5691. tmp_stats[i++] = le64_to_cpu(stats->rmac_frms_q5);
  5692. tmp_stats[i++] = le64_to_cpu(stats->rmac_frms_q6);
  5693. tmp_stats[i++] = le64_to_cpu(stats->rmac_frms_q7);
  5694. tmp_stats[i++] = le16_to_cpu(stats->rmac_full_q0);
  5695. tmp_stats[i++] = le16_to_cpu(stats->rmac_full_q1);
  5696. tmp_stats[i++] = le16_to_cpu(stats->rmac_full_q2);
  5697. tmp_stats[i++] = le16_to_cpu(stats->rmac_full_q3);
  5698. tmp_stats[i++] = le16_to_cpu(stats->rmac_full_q4);
  5699. tmp_stats[i++] = le16_to_cpu(stats->rmac_full_q5);
  5700. tmp_stats[i++] = le16_to_cpu(stats->rmac_full_q6);
  5701. tmp_stats[i++] = le16_to_cpu(stats->rmac_full_q7);
  5702. tmp_stats[i++] =
  5703. (u64)le32_to_cpu(stats->rmac_pause_cnt_oflow) << 32 |
  5704. le32_to_cpu(stats->rmac_pause_cnt);
  5705. tmp_stats[i++] = le64_to_cpu(stats->rmac_xgmii_data_err_cnt);
  5706. tmp_stats[i++] = le64_to_cpu(stats->rmac_xgmii_ctrl_err_cnt);
  5707. tmp_stats[i++] =
  5708. (u64)le32_to_cpu(stats->rmac_accepted_ip_oflow) << 32 |
  5709. le32_to_cpu(stats->rmac_accepted_ip);
  5710. tmp_stats[i++] = le32_to_cpu(stats->rmac_err_tcp);
  5711. tmp_stats[i++] = le32_to_cpu(stats->rd_req_cnt);
  5712. tmp_stats[i++] = le32_to_cpu(stats->new_rd_req_cnt);
  5713. tmp_stats[i++] = le32_to_cpu(stats->new_rd_req_rtry_cnt);
  5714. tmp_stats[i++] = le32_to_cpu(stats->rd_rtry_cnt);
  5715. tmp_stats[i++] = le32_to_cpu(stats->wr_rtry_rd_ack_cnt);
  5716. tmp_stats[i++] = le32_to_cpu(stats->wr_req_cnt);
  5717. tmp_stats[i++] = le32_to_cpu(stats->new_wr_req_cnt);
  5718. tmp_stats[i++] = le32_to_cpu(stats->new_wr_req_rtry_cnt);
  5719. tmp_stats[i++] = le32_to_cpu(stats->wr_rtry_cnt);
  5720. tmp_stats[i++] = le32_to_cpu(stats->wr_disc_cnt);
  5721. tmp_stats[i++] = le32_to_cpu(stats->rd_rtry_wr_ack_cnt);
  5722. tmp_stats[i++] = le32_to_cpu(stats->txp_wr_cnt);
  5723. tmp_stats[i++] = le32_to_cpu(stats->txd_rd_cnt);
  5724. tmp_stats[i++] = le32_to_cpu(stats->txd_wr_cnt);
  5725. tmp_stats[i++] = le32_to_cpu(stats->rxd_rd_cnt);
  5726. tmp_stats[i++] = le32_to_cpu(stats->rxd_wr_cnt);
  5727. tmp_stats[i++] = le32_to_cpu(stats->txf_rd_cnt);
  5728. tmp_stats[i++] = le32_to_cpu(stats->rxf_wr_cnt);
  5729. /* Enhanced statistics exist only for Hercules */
  5730. if (sp->device_type == XFRAME_II_DEVICE) {
  5731. tmp_stats[i++] =
  5732. le64_to_cpu(stats->rmac_ttl_1519_4095_frms);
  5733. tmp_stats[i++] =
  5734. le64_to_cpu(stats->rmac_ttl_4096_8191_frms);
  5735. tmp_stats[i++] =
  5736. le64_to_cpu(stats->rmac_ttl_8192_max_frms);
  5737. tmp_stats[i++] = le64_to_cpu(stats->rmac_ttl_gt_max_frms);
  5738. tmp_stats[i++] = le64_to_cpu(stats->rmac_osized_alt_frms);
  5739. tmp_stats[i++] = le64_to_cpu(stats->rmac_jabber_alt_frms);
  5740. tmp_stats[i++] = le64_to_cpu(stats->rmac_gt_max_alt_frms);
  5741. tmp_stats[i++] = le64_to_cpu(stats->rmac_vlan_frms);
  5742. tmp_stats[i++] = le32_to_cpu(stats->rmac_len_discard);
  5743. tmp_stats[i++] = le32_to_cpu(stats->rmac_fcs_discard);
  5744. tmp_stats[i++] = le32_to_cpu(stats->rmac_pf_discard);
  5745. tmp_stats[i++] = le32_to_cpu(stats->rmac_da_discard);
  5746. tmp_stats[i++] = le32_to_cpu(stats->rmac_red_discard);
  5747. tmp_stats[i++] = le32_to_cpu(stats->rmac_rts_discard);
  5748. tmp_stats[i++] = le32_to_cpu(stats->rmac_ingm_full_discard);
  5749. tmp_stats[i++] = le32_to_cpu(stats->link_fault_cnt);
  5750. }
  5751. tmp_stats[i++] = 0;
  5752. tmp_stats[i++] = swstats->single_ecc_errs;
  5753. tmp_stats[i++] = swstats->double_ecc_errs;
  5754. tmp_stats[i++] = swstats->parity_err_cnt;
  5755. tmp_stats[i++] = swstats->serious_err_cnt;
  5756. tmp_stats[i++] = swstats->soft_reset_cnt;
  5757. tmp_stats[i++] = swstats->fifo_full_cnt;
  5758. for (k = 0; k < MAX_RX_RINGS; k++)
  5759. tmp_stats[i++] = swstats->ring_full_cnt[k];
  5760. tmp_stats[i++] = xstats->alarm_transceiver_temp_high;
  5761. tmp_stats[i++] = xstats->alarm_transceiver_temp_low;
  5762. tmp_stats[i++] = xstats->alarm_laser_bias_current_high;
  5763. tmp_stats[i++] = xstats->alarm_laser_bias_current_low;
  5764. tmp_stats[i++] = xstats->alarm_laser_output_power_high;
  5765. tmp_stats[i++] = xstats->alarm_laser_output_power_low;
  5766. tmp_stats[i++] = xstats->warn_transceiver_temp_high;
  5767. tmp_stats[i++] = xstats->warn_transceiver_temp_low;
  5768. tmp_stats[i++] = xstats->warn_laser_bias_current_high;
  5769. tmp_stats[i++] = xstats->warn_laser_bias_current_low;
  5770. tmp_stats[i++] = xstats->warn_laser_output_power_high;
  5771. tmp_stats[i++] = xstats->warn_laser_output_power_low;
  5772. tmp_stats[i++] = swstats->clubbed_frms_cnt;
  5773. tmp_stats[i++] = swstats->sending_both;
  5774. tmp_stats[i++] = swstats->outof_sequence_pkts;
  5775. tmp_stats[i++] = swstats->flush_max_pkts;
  5776. if (swstats->num_aggregations) {
  5777. u64 tmp = swstats->sum_avg_pkts_aggregated;
  5778. int count = 0;
  5779. /*
  5780. * Since 64-bit divide does not work on all platforms,
  5781. * do repeated subtraction.
  5782. */
  5783. while (tmp >= swstats->num_aggregations) {
  5784. tmp -= swstats->num_aggregations;
  5785. count++;
  5786. }
  5787. tmp_stats[i++] = count;
  5788. } else
  5789. tmp_stats[i++] = 0;
  5790. tmp_stats[i++] = swstats->mem_alloc_fail_cnt;
  5791. tmp_stats[i++] = swstats->pci_map_fail_cnt;
  5792. tmp_stats[i++] = swstats->watchdog_timer_cnt;
  5793. tmp_stats[i++] = swstats->mem_allocated;
  5794. tmp_stats[i++] = swstats->mem_freed;
  5795. tmp_stats[i++] = swstats->link_up_cnt;
  5796. tmp_stats[i++] = swstats->link_down_cnt;
  5797. tmp_stats[i++] = swstats->link_up_time;
  5798. tmp_stats[i++] = swstats->link_down_time;
  5799. tmp_stats[i++] = swstats->tx_buf_abort_cnt;
  5800. tmp_stats[i++] = swstats->tx_desc_abort_cnt;
  5801. tmp_stats[i++] = swstats->tx_parity_err_cnt;
  5802. tmp_stats[i++] = swstats->tx_link_loss_cnt;
  5803. tmp_stats[i++] = swstats->tx_list_proc_err_cnt;
  5804. tmp_stats[i++] = swstats->rx_parity_err_cnt;
  5805. tmp_stats[i++] = swstats->rx_abort_cnt;
  5806. tmp_stats[i++] = swstats->rx_parity_abort_cnt;
  5807. tmp_stats[i++] = swstats->rx_rda_fail_cnt;
  5808. tmp_stats[i++] = swstats->rx_unkn_prot_cnt;
  5809. tmp_stats[i++] = swstats->rx_fcs_err_cnt;
  5810. tmp_stats[i++] = swstats->rx_buf_size_err_cnt;
  5811. tmp_stats[i++] = swstats->rx_rxd_corrupt_cnt;
  5812. tmp_stats[i++] = swstats->rx_unkn_err_cnt;
  5813. tmp_stats[i++] = swstats->tda_err_cnt;
  5814. tmp_stats[i++] = swstats->pfc_err_cnt;
  5815. tmp_stats[i++] = swstats->pcc_err_cnt;
  5816. tmp_stats[i++] = swstats->tti_err_cnt;
  5817. tmp_stats[i++] = swstats->tpa_err_cnt;
  5818. tmp_stats[i++] = swstats->sm_err_cnt;
  5819. tmp_stats[i++] = swstats->lso_err_cnt;
  5820. tmp_stats[i++] = swstats->mac_tmac_err_cnt;
  5821. tmp_stats[i++] = swstats->mac_rmac_err_cnt;
  5822. tmp_stats[i++] = swstats->xgxs_txgxs_err_cnt;
  5823. tmp_stats[i++] = swstats->xgxs_rxgxs_err_cnt;
  5824. tmp_stats[i++] = swstats->rc_err_cnt;
  5825. tmp_stats[i++] = swstats->prc_pcix_err_cnt;
  5826. tmp_stats[i++] = swstats->rpa_err_cnt;
  5827. tmp_stats[i++] = swstats->rda_err_cnt;
  5828. tmp_stats[i++] = swstats->rti_err_cnt;
  5829. tmp_stats[i++] = swstats->mc_err_cnt;
  5830. }
  5831. static int s2io_ethtool_get_regs_len(struct net_device *dev)
  5832. {
  5833. return XENA_REG_SPACE;
  5834. }
  5835. static int s2io_get_eeprom_len(struct net_device *dev)
  5836. {
  5837. return XENA_EEPROM_SPACE;
  5838. }
  5839. static int s2io_get_sset_count(struct net_device *dev, int sset)
  5840. {
  5841. struct s2io_nic *sp = netdev_priv(dev);
  5842. switch (sset) {
  5843. case ETH_SS_TEST:
  5844. return S2IO_TEST_LEN;
  5845. case ETH_SS_STATS:
  5846. switch (sp->device_type) {
  5847. case XFRAME_I_DEVICE:
  5848. return XFRAME_I_STAT_LEN;
  5849. case XFRAME_II_DEVICE:
  5850. return XFRAME_II_STAT_LEN;
  5851. default:
  5852. return 0;
  5853. }
  5854. default:
  5855. return -EOPNOTSUPP;
  5856. }
  5857. }
  5858. static void s2io_ethtool_get_strings(struct net_device *dev,
  5859. u32 stringset, u8 *data)
  5860. {
  5861. int stat_size = 0;
  5862. struct s2io_nic *sp = netdev_priv(dev);
  5863. switch (stringset) {
  5864. case ETH_SS_TEST:
  5865. memcpy(data, s2io_gstrings, S2IO_STRINGS_LEN);
  5866. break;
  5867. case ETH_SS_STATS:
  5868. stat_size = sizeof(ethtool_xena_stats_keys);
  5869. memcpy(data, &ethtool_xena_stats_keys, stat_size);
  5870. if (sp->device_type == XFRAME_II_DEVICE) {
  5871. memcpy(data + stat_size,
  5872. &ethtool_enhanced_stats_keys,
  5873. sizeof(ethtool_enhanced_stats_keys));
  5874. stat_size += sizeof(ethtool_enhanced_stats_keys);
  5875. }
  5876. memcpy(data + stat_size, &ethtool_driver_stats_keys,
  5877. sizeof(ethtool_driver_stats_keys));
  5878. }
  5879. }
  5880. static int s2io_set_features(struct net_device *dev, netdev_features_t features)
  5881. {
  5882. struct s2io_nic *sp = netdev_priv(dev);
  5883. netdev_features_t changed = (features ^ dev->features) & NETIF_F_LRO;
  5884. if (changed && netif_running(dev)) {
  5885. int rc;
  5886. s2io_stop_all_tx_queue(sp);
  5887. s2io_card_down(sp);
  5888. dev->features = features;
  5889. rc = s2io_card_up(sp);
  5890. if (rc)
  5891. s2io_reset(sp);
  5892. else
  5893. s2io_start_all_tx_queue(sp);
  5894. return rc ? rc : 1;
  5895. }
  5896. return 0;
  5897. }
  5898. static const struct ethtool_ops netdev_ethtool_ops = {
  5899. .get_settings = s2io_ethtool_gset,
  5900. .set_settings = s2io_ethtool_sset,
  5901. .get_drvinfo = s2io_ethtool_gdrvinfo,
  5902. .get_regs_len = s2io_ethtool_get_regs_len,
  5903. .get_regs = s2io_ethtool_gregs,
  5904. .get_link = ethtool_op_get_link,
  5905. .get_eeprom_len = s2io_get_eeprom_len,
  5906. .get_eeprom = s2io_ethtool_geeprom,
  5907. .set_eeprom = s2io_ethtool_seeprom,
  5908. .get_ringparam = s2io_ethtool_gringparam,
  5909. .get_pauseparam = s2io_ethtool_getpause_data,
  5910. .set_pauseparam = s2io_ethtool_setpause_data,
  5911. .self_test = s2io_ethtool_test,
  5912. .get_strings = s2io_ethtool_get_strings,
  5913. .set_phys_id = s2io_ethtool_set_led,
  5914. .get_ethtool_stats = s2io_get_ethtool_stats,
  5915. .get_sset_count = s2io_get_sset_count,
  5916. };
  5917. /**
  5918. * s2io_ioctl - Entry point for the Ioctl
  5919. * @dev : Device pointer.
  5920. * @ifr : An IOCTL specefic structure, that can contain a pointer to
  5921. * a proprietary structure used to pass information to the driver.
  5922. * @cmd : This is used to distinguish between the different commands that
  5923. * can be passed to the IOCTL functions.
  5924. * Description:
  5925. * Currently there are no special functionality supported in IOCTL, hence
  5926. * function always return EOPNOTSUPPORTED
  5927. */
  5928. static int s2io_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  5929. {
  5930. return -EOPNOTSUPP;
  5931. }
  5932. /**
  5933. * s2io_change_mtu - entry point to change MTU size for the device.
  5934. * @dev : device pointer.
  5935. * @new_mtu : the new MTU size for the device.
  5936. * Description: A driver entry point to change MTU size for the device.
  5937. * Before changing the MTU the device must be stopped.
  5938. * Return value:
  5939. * 0 on success and an appropriate (-)ve integer as defined in errno.h
  5940. * file on failure.
  5941. */
  5942. static int s2io_change_mtu(struct net_device *dev, int new_mtu)
  5943. {
  5944. struct s2io_nic *sp = netdev_priv(dev);
  5945. int ret = 0;
  5946. if ((new_mtu < MIN_MTU) || (new_mtu > S2IO_JUMBO_SIZE)) {
  5947. DBG_PRINT(ERR_DBG, "%s: MTU size is invalid.\n", dev->name);
  5948. return -EPERM;
  5949. }
  5950. dev->mtu = new_mtu;
  5951. if (netif_running(dev)) {
  5952. s2io_stop_all_tx_queue(sp);
  5953. s2io_card_down(sp);
  5954. ret = s2io_card_up(sp);
  5955. if (ret) {
  5956. DBG_PRINT(ERR_DBG, "%s: Device bring up failed\n",
  5957. __func__);
  5958. return ret;
  5959. }
  5960. s2io_wake_all_tx_queue(sp);
  5961. } else { /* Device is down */
  5962. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  5963. u64 val64 = new_mtu;
  5964. writeq(vBIT(val64, 2, 14), &bar0->rmac_max_pyld_len);
  5965. }
  5966. return ret;
  5967. }
  5968. /**
  5969. * s2io_set_link - Set the LInk status
  5970. * @data: long pointer to device private structue
  5971. * Description: Sets the link status for the adapter
  5972. */
  5973. static void s2io_set_link(struct work_struct *work)
  5974. {
  5975. struct s2io_nic *nic = container_of(work, struct s2io_nic,
  5976. set_link_task);
  5977. struct net_device *dev = nic->dev;
  5978. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  5979. register u64 val64;
  5980. u16 subid;
  5981. rtnl_lock();
  5982. if (!netif_running(dev))
  5983. goto out_unlock;
  5984. if (test_and_set_bit(__S2IO_STATE_LINK_TASK, &(nic->state))) {
  5985. /* The card is being reset, no point doing anything */
  5986. goto out_unlock;
  5987. }
  5988. subid = nic->pdev->subsystem_device;
  5989. if (s2io_link_fault_indication(nic) == MAC_RMAC_ERR_TIMER) {
  5990. /*
  5991. * Allow a small delay for the NICs self initiated
  5992. * cleanup to complete.
  5993. */
  5994. msleep(100);
  5995. }
  5996. val64 = readq(&bar0->adapter_status);
  5997. if (LINK_IS_UP(val64)) {
  5998. if (!(readq(&bar0->adapter_control) & ADAPTER_CNTL_EN)) {
  5999. if (verify_xena_quiescence(nic)) {
  6000. val64 = readq(&bar0->adapter_control);
  6001. val64 |= ADAPTER_CNTL_EN;
  6002. writeq(val64, &bar0->adapter_control);
  6003. if (CARDS_WITH_FAULTY_LINK_INDICATORS(
  6004. nic->device_type, subid)) {
  6005. val64 = readq(&bar0->gpio_control);
  6006. val64 |= GPIO_CTRL_GPIO_0;
  6007. writeq(val64, &bar0->gpio_control);
  6008. val64 = readq(&bar0->gpio_control);
  6009. } else {
  6010. val64 |= ADAPTER_LED_ON;
  6011. writeq(val64, &bar0->adapter_control);
  6012. }
  6013. nic->device_enabled_once = true;
  6014. } else {
  6015. DBG_PRINT(ERR_DBG,
  6016. "%s: Error: device is not Quiescent\n",
  6017. dev->name);
  6018. s2io_stop_all_tx_queue(nic);
  6019. }
  6020. }
  6021. val64 = readq(&bar0->adapter_control);
  6022. val64 |= ADAPTER_LED_ON;
  6023. writeq(val64, &bar0->adapter_control);
  6024. s2io_link(nic, LINK_UP);
  6025. } else {
  6026. if (CARDS_WITH_FAULTY_LINK_INDICATORS(nic->device_type,
  6027. subid)) {
  6028. val64 = readq(&bar0->gpio_control);
  6029. val64 &= ~GPIO_CTRL_GPIO_0;
  6030. writeq(val64, &bar0->gpio_control);
  6031. val64 = readq(&bar0->gpio_control);
  6032. }
  6033. /* turn off LED */
  6034. val64 = readq(&bar0->adapter_control);
  6035. val64 = val64 & (~ADAPTER_LED_ON);
  6036. writeq(val64, &bar0->adapter_control);
  6037. s2io_link(nic, LINK_DOWN);
  6038. }
  6039. clear_bit(__S2IO_STATE_LINK_TASK, &(nic->state));
  6040. out_unlock:
  6041. rtnl_unlock();
  6042. }
  6043. static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp,
  6044. struct buffAdd *ba,
  6045. struct sk_buff **skb, u64 *temp0, u64 *temp1,
  6046. u64 *temp2, int size)
  6047. {
  6048. struct net_device *dev = sp->dev;
  6049. struct swStat *stats = &sp->mac_control.stats_info->sw_stat;
  6050. if ((sp->rxd_mode == RXD_MODE_1) && (rxdp->Host_Control == 0)) {
  6051. struct RxD1 *rxdp1 = (struct RxD1 *)rxdp;
  6052. /* allocate skb */
  6053. if (*skb) {
  6054. DBG_PRINT(INFO_DBG, "SKB is not NULL\n");
  6055. /*
  6056. * As Rx frame are not going to be processed,
  6057. * using same mapped address for the Rxd
  6058. * buffer pointer
  6059. */
  6060. rxdp1->Buffer0_ptr = *temp0;
  6061. } else {
  6062. *skb = netdev_alloc_skb(dev, size);
  6063. if (!(*skb)) {
  6064. DBG_PRINT(INFO_DBG,
  6065. "%s: Out of memory to allocate %s\n",
  6066. dev->name, "1 buf mode SKBs");
  6067. stats->mem_alloc_fail_cnt++;
  6068. return -ENOMEM ;
  6069. }
  6070. stats->mem_allocated += (*skb)->truesize;
  6071. /* storing the mapped addr in a temp variable
  6072. * such it will be used for next rxd whose
  6073. * Host Control is NULL
  6074. */
  6075. rxdp1->Buffer0_ptr = *temp0 =
  6076. pci_map_single(sp->pdev, (*skb)->data,
  6077. size - NET_IP_ALIGN,
  6078. PCI_DMA_FROMDEVICE);
  6079. if (pci_dma_mapping_error(sp->pdev, rxdp1->Buffer0_ptr))
  6080. goto memalloc_failed;
  6081. rxdp->Host_Control = (unsigned long) (*skb);
  6082. }
  6083. } else if ((sp->rxd_mode == RXD_MODE_3B) && (rxdp->Host_Control == 0)) {
  6084. struct RxD3 *rxdp3 = (struct RxD3 *)rxdp;
  6085. /* Two buffer Mode */
  6086. if (*skb) {
  6087. rxdp3->Buffer2_ptr = *temp2;
  6088. rxdp3->Buffer0_ptr = *temp0;
  6089. rxdp3->Buffer1_ptr = *temp1;
  6090. } else {
  6091. *skb = netdev_alloc_skb(dev, size);
  6092. if (!(*skb)) {
  6093. DBG_PRINT(INFO_DBG,
  6094. "%s: Out of memory to allocate %s\n",
  6095. dev->name,
  6096. "2 buf mode SKBs");
  6097. stats->mem_alloc_fail_cnt++;
  6098. return -ENOMEM;
  6099. }
  6100. stats->mem_allocated += (*skb)->truesize;
  6101. rxdp3->Buffer2_ptr = *temp2 =
  6102. pci_map_single(sp->pdev, (*skb)->data,
  6103. dev->mtu + 4,
  6104. PCI_DMA_FROMDEVICE);
  6105. if (pci_dma_mapping_error(sp->pdev, rxdp3->Buffer2_ptr))
  6106. goto memalloc_failed;
  6107. rxdp3->Buffer0_ptr = *temp0 =
  6108. pci_map_single(sp->pdev, ba->ba_0, BUF0_LEN,
  6109. PCI_DMA_FROMDEVICE);
  6110. if (pci_dma_mapping_error(sp->pdev,
  6111. rxdp3->Buffer0_ptr)) {
  6112. pci_unmap_single(sp->pdev,
  6113. (dma_addr_t)rxdp3->Buffer2_ptr,
  6114. dev->mtu + 4,
  6115. PCI_DMA_FROMDEVICE);
  6116. goto memalloc_failed;
  6117. }
  6118. rxdp->Host_Control = (unsigned long) (*skb);
  6119. /* Buffer-1 will be dummy buffer not used */
  6120. rxdp3->Buffer1_ptr = *temp1 =
  6121. pci_map_single(sp->pdev, ba->ba_1, BUF1_LEN,
  6122. PCI_DMA_FROMDEVICE);
  6123. if (pci_dma_mapping_error(sp->pdev,
  6124. rxdp3->Buffer1_ptr)) {
  6125. pci_unmap_single(sp->pdev,
  6126. (dma_addr_t)rxdp3->Buffer0_ptr,
  6127. BUF0_LEN, PCI_DMA_FROMDEVICE);
  6128. pci_unmap_single(sp->pdev,
  6129. (dma_addr_t)rxdp3->Buffer2_ptr,
  6130. dev->mtu + 4,
  6131. PCI_DMA_FROMDEVICE);
  6132. goto memalloc_failed;
  6133. }
  6134. }
  6135. }
  6136. return 0;
  6137. memalloc_failed:
  6138. stats->pci_map_fail_cnt++;
  6139. stats->mem_freed += (*skb)->truesize;
  6140. dev_kfree_skb(*skb);
  6141. return -ENOMEM;
  6142. }
  6143. static void set_rxd_buffer_size(struct s2io_nic *sp, struct RxD_t *rxdp,
  6144. int size)
  6145. {
  6146. struct net_device *dev = sp->dev;
  6147. if (sp->rxd_mode == RXD_MODE_1) {
  6148. rxdp->Control_2 = SET_BUFFER0_SIZE_1(size - NET_IP_ALIGN);
  6149. } else if (sp->rxd_mode == RXD_MODE_3B) {
  6150. rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN);
  6151. rxdp->Control_2 |= SET_BUFFER1_SIZE_3(1);
  6152. rxdp->Control_2 |= SET_BUFFER2_SIZE_3(dev->mtu + 4);
  6153. }
  6154. }
  6155. static int rxd_owner_bit_reset(struct s2io_nic *sp)
  6156. {
  6157. int i, j, k, blk_cnt = 0, size;
  6158. struct config_param *config = &sp->config;
  6159. struct mac_info *mac_control = &sp->mac_control;
  6160. struct net_device *dev = sp->dev;
  6161. struct RxD_t *rxdp = NULL;
  6162. struct sk_buff *skb = NULL;
  6163. struct buffAdd *ba = NULL;
  6164. u64 temp0_64 = 0, temp1_64 = 0, temp2_64 = 0;
  6165. /* Calculate the size based on ring mode */
  6166. size = dev->mtu + HEADER_ETHERNET_II_802_3_SIZE +
  6167. HEADER_802_2_SIZE + HEADER_SNAP_SIZE;
  6168. if (sp->rxd_mode == RXD_MODE_1)
  6169. size += NET_IP_ALIGN;
  6170. else if (sp->rxd_mode == RXD_MODE_3B)
  6171. size = dev->mtu + ALIGN_SIZE + BUF0_LEN + 4;
  6172. for (i = 0; i < config->rx_ring_num; i++) {
  6173. struct rx_ring_config *rx_cfg = &config->rx_cfg[i];
  6174. struct ring_info *ring = &mac_control->rings[i];
  6175. blk_cnt = rx_cfg->num_rxd / (rxd_count[sp->rxd_mode] + 1);
  6176. for (j = 0; j < blk_cnt; j++) {
  6177. for (k = 0; k < rxd_count[sp->rxd_mode]; k++) {
  6178. rxdp = ring->rx_blocks[j].rxds[k].virt_addr;
  6179. if (sp->rxd_mode == RXD_MODE_3B)
  6180. ba = &ring->ba[j][k];
  6181. if (set_rxd_buffer_pointer(sp, rxdp, ba, &skb,
  6182. (u64 *)&temp0_64,
  6183. (u64 *)&temp1_64,
  6184. (u64 *)&temp2_64,
  6185. size) == -ENOMEM) {
  6186. return 0;
  6187. }
  6188. set_rxd_buffer_size(sp, rxdp, size);
  6189. wmb();
  6190. /* flip the Ownership bit to Hardware */
  6191. rxdp->Control_1 |= RXD_OWN_XENA;
  6192. }
  6193. }
  6194. }
  6195. return 0;
  6196. }
  6197. static int s2io_add_isr(struct s2io_nic *sp)
  6198. {
  6199. int ret = 0;
  6200. struct net_device *dev = sp->dev;
  6201. int err = 0;
  6202. if (sp->config.intr_type == MSI_X)
  6203. ret = s2io_enable_msi_x(sp);
  6204. if (ret) {
  6205. DBG_PRINT(ERR_DBG, "%s: Defaulting to INTA\n", dev->name);
  6206. sp->config.intr_type = INTA;
  6207. }
  6208. /*
  6209. * Store the values of the MSIX table in
  6210. * the struct s2io_nic structure
  6211. */
  6212. store_xmsi_data(sp);
  6213. /* After proper initialization of H/W, register ISR */
  6214. if (sp->config.intr_type == MSI_X) {
  6215. int i, msix_rx_cnt = 0;
  6216. for (i = 0; i < sp->num_entries; i++) {
  6217. if (sp->s2io_entries[i].in_use == MSIX_FLG) {
  6218. if (sp->s2io_entries[i].type ==
  6219. MSIX_RING_TYPE) {
  6220. sprintf(sp->desc[i], "%s:MSI-X-%d-RX",
  6221. dev->name, i);
  6222. err = request_irq(sp->entries[i].vector,
  6223. s2io_msix_ring_handle,
  6224. 0,
  6225. sp->desc[i],
  6226. sp->s2io_entries[i].arg);
  6227. } else if (sp->s2io_entries[i].type ==
  6228. MSIX_ALARM_TYPE) {
  6229. sprintf(sp->desc[i], "%s:MSI-X-%d-TX",
  6230. dev->name, i);
  6231. err = request_irq(sp->entries[i].vector,
  6232. s2io_msix_fifo_handle,
  6233. 0,
  6234. sp->desc[i],
  6235. sp->s2io_entries[i].arg);
  6236. }
  6237. /* if either data or addr is zero print it. */
  6238. if (!(sp->msix_info[i].addr &&
  6239. sp->msix_info[i].data)) {
  6240. DBG_PRINT(ERR_DBG,
  6241. "%s @Addr:0x%llx Data:0x%llx\n",
  6242. sp->desc[i],
  6243. (unsigned long long)
  6244. sp->msix_info[i].addr,
  6245. (unsigned long long)
  6246. ntohl(sp->msix_info[i].data));
  6247. } else
  6248. msix_rx_cnt++;
  6249. if (err) {
  6250. remove_msix_isr(sp);
  6251. DBG_PRINT(ERR_DBG,
  6252. "%s:MSI-X-%d registration "
  6253. "failed\n", dev->name, i);
  6254. DBG_PRINT(ERR_DBG,
  6255. "%s: Defaulting to INTA\n",
  6256. dev->name);
  6257. sp->config.intr_type = INTA;
  6258. break;
  6259. }
  6260. sp->s2io_entries[i].in_use =
  6261. MSIX_REGISTERED_SUCCESS;
  6262. }
  6263. }
  6264. if (!err) {
  6265. pr_info("MSI-X-RX %d entries enabled\n", --msix_rx_cnt);
  6266. DBG_PRINT(INFO_DBG,
  6267. "MSI-X-TX entries enabled through alarm vector\n");
  6268. }
  6269. }
  6270. if (sp->config.intr_type == INTA) {
  6271. err = request_irq(sp->pdev->irq, s2io_isr, IRQF_SHARED,
  6272. sp->name, dev);
  6273. if (err) {
  6274. DBG_PRINT(ERR_DBG, "%s: ISR registration failed\n",
  6275. dev->name);
  6276. return -1;
  6277. }
  6278. }
  6279. return 0;
  6280. }
  6281. static void s2io_rem_isr(struct s2io_nic *sp)
  6282. {
  6283. if (sp->config.intr_type == MSI_X)
  6284. remove_msix_isr(sp);
  6285. else
  6286. remove_inta_isr(sp);
  6287. }
  6288. static void do_s2io_card_down(struct s2io_nic *sp, int do_io)
  6289. {
  6290. int cnt = 0;
  6291. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  6292. register u64 val64 = 0;
  6293. struct config_param *config;
  6294. config = &sp->config;
  6295. if (!is_s2io_card_up(sp))
  6296. return;
  6297. del_timer_sync(&sp->alarm_timer);
  6298. /* If s2io_set_link task is executing, wait till it completes. */
  6299. while (test_and_set_bit(__S2IO_STATE_LINK_TASK, &(sp->state)))
  6300. msleep(50);
  6301. clear_bit(__S2IO_STATE_CARD_UP, &sp->state);
  6302. /* Disable napi */
  6303. if (sp->config.napi) {
  6304. int off = 0;
  6305. if (config->intr_type == MSI_X) {
  6306. for (; off < sp->config.rx_ring_num; off++)
  6307. napi_disable(&sp->mac_control.rings[off].napi);
  6308. }
  6309. else
  6310. napi_disable(&sp->napi);
  6311. }
  6312. /* disable Tx and Rx traffic on the NIC */
  6313. if (do_io)
  6314. stop_nic(sp);
  6315. s2io_rem_isr(sp);
  6316. /* stop the tx queue, indicate link down */
  6317. s2io_link(sp, LINK_DOWN);
  6318. /* Check if the device is Quiescent and then Reset the NIC */
  6319. while (do_io) {
  6320. /* As per the HW requirement we need to replenish the
  6321. * receive buffer to avoid the ring bump. Since there is
  6322. * no intention of processing the Rx frame at this pointwe are
  6323. * just setting the ownership bit of rxd in Each Rx
  6324. * ring to HW and set the appropriate buffer size
  6325. * based on the ring mode
  6326. */
  6327. rxd_owner_bit_reset(sp);
  6328. val64 = readq(&bar0->adapter_status);
  6329. if (verify_xena_quiescence(sp)) {
  6330. if (verify_pcc_quiescent(sp, sp->device_enabled_once))
  6331. break;
  6332. }
  6333. msleep(50);
  6334. cnt++;
  6335. if (cnt == 10) {
  6336. DBG_PRINT(ERR_DBG, "Device not Quiescent - "
  6337. "adapter status reads 0x%llx\n",
  6338. (unsigned long long)val64);
  6339. break;
  6340. }
  6341. }
  6342. if (do_io)
  6343. s2io_reset(sp);
  6344. /* Free all Tx buffers */
  6345. free_tx_buffers(sp);
  6346. /* Free all Rx buffers */
  6347. free_rx_buffers(sp);
  6348. clear_bit(__S2IO_STATE_LINK_TASK, &(sp->state));
  6349. }
  6350. static void s2io_card_down(struct s2io_nic *sp)
  6351. {
  6352. do_s2io_card_down(sp, 1);
  6353. }
  6354. static int s2io_card_up(struct s2io_nic *sp)
  6355. {
  6356. int i, ret = 0;
  6357. struct config_param *config;
  6358. struct mac_info *mac_control;
  6359. struct net_device *dev = (struct net_device *)sp->dev;
  6360. u16 interruptible;
  6361. /* Initialize the H/W I/O registers */
  6362. ret = init_nic(sp);
  6363. if (ret != 0) {
  6364. DBG_PRINT(ERR_DBG, "%s: H/W initialization failed\n",
  6365. dev->name);
  6366. if (ret != -EIO)
  6367. s2io_reset(sp);
  6368. return ret;
  6369. }
  6370. /*
  6371. * Initializing the Rx buffers. For now we are considering only 1
  6372. * Rx ring and initializing buffers into 30 Rx blocks
  6373. */
  6374. config = &sp->config;
  6375. mac_control = &sp->mac_control;
  6376. for (i = 0; i < config->rx_ring_num; i++) {
  6377. struct ring_info *ring = &mac_control->rings[i];
  6378. ring->mtu = dev->mtu;
  6379. ring->lro = !!(dev->features & NETIF_F_LRO);
  6380. ret = fill_rx_buffers(sp, ring, 1);
  6381. if (ret) {
  6382. DBG_PRINT(ERR_DBG, "%s: Out of memory in Open\n",
  6383. dev->name);
  6384. s2io_reset(sp);
  6385. free_rx_buffers(sp);
  6386. return -ENOMEM;
  6387. }
  6388. DBG_PRINT(INFO_DBG, "Buf in ring:%d is %d:\n", i,
  6389. ring->rx_bufs_left);
  6390. }
  6391. /* Initialise napi */
  6392. if (config->napi) {
  6393. if (config->intr_type == MSI_X) {
  6394. for (i = 0; i < sp->config.rx_ring_num; i++)
  6395. napi_enable(&sp->mac_control.rings[i].napi);
  6396. } else {
  6397. napi_enable(&sp->napi);
  6398. }
  6399. }
  6400. /* Maintain the state prior to the open */
  6401. if (sp->promisc_flg)
  6402. sp->promisc_flg = 0;
  6403. if (sp->m_cast_flg) {
  6404. sp->m_cast_flg = 0;
  6405. sp->all_multi_pos = 0;
  6406. }
  6407. /* Setting its receive mode */
  6408. s2io_set_multicast(dev);
  6409. if (dev->features & NETIF_F_LRO) {
  6410. /* Initialize max aggregatable pkts per session based on MTU */
  6411. sp->lro_max_aggr_per_sess = ((1<<16) - 1) / dev->mtu;
  6412. /* Check if we can use (if specified) user provided value */
  6413. if (lro_max_pkts < sp->lro_max_aggr_per_sess)
  6414. sp->lro_max_aggr_per_sess = lro_max_pkts;
  6415. }
  6416. /* Enable Rx Traffic and interrupts on the NIC */
  6417. if (start_nic(sp)) {
  6418. DBG_PRINT(ERR_DBG, "%s: Starting NIC failed\n", dev->name);
  6419. s2io_reset(sp);
  6420. free_rx_buffers(sp);
  6421. return -ENODEV;
  6422. }
  6423. /* Add interrupt service routine */
  6424. if (s2io_add_isr(sp) != 0) {
  6425. if (sp->config.intr_type == MSI_X)
  6426. s2io_rem_isr(sp);
  6427. s2io_reset(sp);
  6428. free_rx_buffers(sp);
  6429. return -ENODEV;
  6430. }
  6431. S2IO_TIMER_CONF(sp->alarm_timer, s2io_alarm_handle, sp, (HZ/2));
  6432. set_bit(__S2IO_STATE_CARD_UP, &sp->state);
  6433. /* Enable select interrupts */
  6434. en_dis_err_alarms(sp, ENA_ALL_INTRS, ENABLE_INTRS);
  6435. if (sp->config.intr_type != INTA) {
  6436. interruptible = TX_TRAFFIC_INTR | TX_PIC_INTR;
  6437. en_dis_able_nic_intrs(sp, interruptible, ENABLE_INTRS);
  6438. } else {
  6439. interruptible = TX_TRAFFIC_INTR | RX_TRAFFIC_INTR;
  6440. interruptible |= TX_PIC_INTR;
  6441. en_dis_able_nic_intrs(sp, interruptible, ENABLE_INTRS);
  6442. }
  6443. return 0;
  6444. }
  6445. /**
  6446. * s2io_restart_nic - Resets the NIC.
  6447. * @data : long pointer to the device private structure
  6448. * Description:
  6449. * This function is scheduled to be run by the s2io_tx_watchdog
  6450. * function after 0.5 secs to reset the NIC. The idea is to reduce
  6451. * the run time of the watch dog routine which is run holding a
  6452. * spin lock.
  6453. */
  6454. static void s2io_restart_nic(struct work_struct *work)
  6455. {
  6456. struct s2io_nic *sp = container_of(work, struct s2io_nic, rst_timer_task);
  6457. struct net_device *dev = sp->dev;
  6458. rtnl_lock();
  6459. if (!netif_running(dev))
  6460. goto out_unlock;
  6461. s2io_card_down(sp);
  6462. if (s2io_card_up(sp)) {
  6463. DBG_PRINT(ERR_DBG, "%s: Device bring up failed\n", dev->name);
  6464. }
  6465. s2io_wake_all_tx_queue(sp);
  6466. DBG_PRINT(ERR_DBG, "%s: was reset by Tx watchdog timer\n", dev->name);
  6467. out_unlock:
  6468. rtnl_unlock();
  6469. }
  6470. /**
  6471. * s2io_tx_watchdog - Watchdog for transmit side.
  6472. * @dev : Pointer to net device structure
  6473. * Description:
  6474. * This function is triggered if the Tx Queue is stopped
  6475. * for a pre-defined amount of time when the Interface is still up.
  6476. * If the Interface is jammed in such a situation, the hardware is
  6477. * reset (by s2io_close) and restarted again (by s2io_open) to
  6478. * overcome any problem that might have been caused in the hardware.
  6479. * Return value:
  6480. * void
  6481. */
  6482. static void s2io_tx_watchdog(struct net_device *dev)
  6483. {
  6484. struct s2io_nic *sp = netdev_priv(dev);
  6485. struct swStat *swstats = &sp->mac_control.stats_info->sw_stat;
  6486. if (netif_carrier_ok(dev)) {
  6487. swstats->watchdog_timer_cnt++;
  6488. schedule_work(&sp->rst_timer_task);
  6489. swstats->soft_reset_cnt++;
  6490. }
  6491. }
  6492. /**
  6493. * rx_osm_handler - To perform some OS related operations on SKB.
  6494. * @sp: private member of the device structure,pointer to s2io_nic structure.
  6495. * @skb : the socket buffer pointer.
  6496. * @len : length of the packet
  6497. * @cksum : FCS checksum of the frame.
  6498. * @ring_no : the ring from which this RxD was extracted.
  6499. * Description:
  6500. * This function is called by the Rx interrupt serivce routine to perform
  6501. * some OS related operations on the SKB before passing it to the upper
  6502. * layers. It mainly checks if the checksum is OK, if so adds it to the
  6503. * SKBs cksum variable, increments the Rx packet count and passes the SKB
  6504. * to the upper layer. If the checksum is wrong, it increments the Rx
  6505. * packet error count, frees the SKB and returns error.
  6506. * Return value:
  6507. * SUCCESS on success and -1 on failure.
  6508. */
  6509. static int rx_osm_handler(struct ring_info *ring_data, struct RxD_t * rxdp)
  6510. {
  6511. struct s2io_nic *sp = ring_data->nic;
  6512. struct net_device *dev = (struct net_device *)ring_data->dev;
  6513. struct sk_buff *skb = (struct sk_buff *)
  6514. ((unsigned long)rxdp->Host_Control);
  6515. int ring_no = ring_data->ring_no;
  6516. u16 l3_csum, l4_csum;
  6517. unsigned long long err = rxdp->Control_1 & RXD_T_CODE;
  6518. struct lro *uninitialized_var(lro);
  6519. u8 err_mask;
  6520. struct swStat *swstats = &sp->mac_control.stats_info->sw_stat;
  6521. skb->dev = dev;
  6522. if (err) {
  6523. /* Check for parity error */
  6524. if (err & 0x1)
  6525. swstats->parity_err_cnt++;
  6526. err_mask = err >> 48;
  6527. switch (err_mask) {
  6528. case 1:
  6529. swstats->rx_parity_err_cnt++;
  6530. break;
  6531. case 2:
  6532. swstats->rx_abort_cnt++;
  6533. break;
  6534. case 3:
  6535. swstats->rx_parity_abort_cnt++;
  6536. break;
  6537. case 4:
  6538. swstats->rx_rda_fail_cnt++;
  6539. break;
  6540. case 5:
  6541. swstats->rx_unkn_prot_cnt++;
  6542. break;
  6543. case 6:
  6544. swstats->rx_fcs_err_cnt++;
  6545. break;
  6546. case 7:
  6547. swstats->rx_buf_size_err_cnt++;
  6548. break;
  6549. case 8:
  6550. swstats->rx_rxd_corrupt_cnt++;
  6551. break;
  6552. case 15:
  6553. swstats->rx_unkn_err_cnt++;
  6554. break;
  6555. }
  6556. /*
  6557. * Drop the packet if bad transfer code. Exception being
  6558. * 0x5, which could be due to unsupported IPv6 extension header.
  6559. * In this case, we let stack handle the packet.
  6560. * Note that in this case, since checksum will be incorrect,
  6561. * stack will validate the same.
  6562. */
  6563. if (err_mask != 0x5) {
  6564. DBG_PRINT(ERR_DBG, "%s: Rx error Value: 0x%x\n",
  6565. dev->name, err_mask);
  6566. dev->stats.rx_crc_errors++;
  6567. swstats->mem_freed
  6568. += skb->truesize;
  6569. dev_kfree_skb(skb);
  6570. ring_data->rx_bufs_left -= 1;
  6571. rxdp->Host_Control = 0;
  6572. return 0;
  6573. }
  6574. }
  6575. rxdp->Host_Control = 0;
  6576. if (sp->rxd_mode == RXD_MODE_1) {
  6577. int len = RXD_GET_BUFFER0_SIZE_1(rxdp->Control_2);
  6578. skb_put(skb, len);
  6579. } else if (sp->rxd_mode == RXD_MODE_3B) {
  6580. int get_block = ring_data->rx_curr_get_info.block_index;
  6581. int get_off = ring_data->rx_curr_get_info.offset;
  6582. int buf0_len = RXD_GET_BUFFER0_SIZE_3(rxdp->Control_2);
  6583. int buf2_len = RXD_GET_BUFFER2_SIZE_3(rxdp->Control_2);
  6584. unsigned char *buff = skb_push(skb, buf0_len);
  6585. struct buffAdd *ba = &ring_data->ba[get_block][get_off];
  6586. memcpy(buff, ba->ba_0, buf0_len);
  6587. skb_put(skb, buf2_len);
  6588. }
  6589. if ((rxdp->Control_1 & TCP_OR_UDP_FRAME) &&
  6590. ((!ring_data->lro) ||
  6591. (ring_data->lro && (!(rxdp->Control_1 & RXD_FRAME_IP_FRAG)))) &&
  6592. (dev->features & NETIF_F_RXCSUM)) {
  6593. l3_csum = RXD_GET_L3_CKSUM(rxdp->Control_1);
  6594. l4_csum = RXD_GET_L4_CKSUM(rxdp->Control_1);
  6595. if ((l3_csum == L3_CKSUM_OK) && (l4_csum == L4_CKSUM_OK)) {
  6596. /*
  6597. * NIC verifies if the Checksum of the received
  6598. * frame is Ok or not and accordingly returns
  6599. * a flag in the RxD.
  6600. */
  6601. skb->ip_summed = CHECKSUM_UNNECESSARY;
  6602. if (ring_data->lro) {
  6603. u32 tcp_len = 0;
  6604. u8 *tcp;
  6605. int ret = 0;
  6606. ret = s2io_club_tcp_session(ring_data,
  6607. skb->data, &tcp,
  6608. &tcp_len, &lro,
  6609. rxdp, sp);
  6610. switch (ret) {
  6611. case 3: /* Begin anew */
  6612. lro->parent = skb;
  6613. goto aggregate;
  6614. case 1: /* Aggregate */
  6615. lro_append_pkt(sp, lro, skb, tcp_len);
  6616. goto aggregate;
  6617. case 4: /* Flush session */
  6618. lro_append_pkt(sp, lro, skb, tcp_len);
  6619. queue_rx_frame(lro->parent,
  6620. lro->vlan_tag);
  6621. clear_lro_session(lro);
  6622. swstats->flush_max_pkts++;
  6623. goto aggregate;
  6624. case 2: /* Flush both */
  6625. lro->parent->data_len = lro->frags_len;
  6626. swstats->sending_both++;
  6627. queue_rx_frame(lro->parent,
  6628. lro->vlan_tag);
  6629. clear_lro_session(lro);
  6630. goto send_up;
  6631. case 0: /* sessions exceeded */
  6632. case -1: /* non-TCP or not L2 aggregatable */
  6633. case 5: /*
  6634. * First pkt in session not
  6635. * L3/L4 aggregatable
  6636. */
  6637. break;
  6638. default:
  6639. DBG_PRINT(ERR_DBG,
  6640. "%s: Samadhana!!\n",
  6641. __func__);
  6642. BUG();
  6643. }
  6644. }
  6645. } else {
  6646. /*
  6647. * Packet with erroneous checksum, let the
  6648. * upper layers deal with it.
  6649. */
  6650. skb_checksum_none_assert(skb);
  6651. }
  6652. } else
  6653. skb_checksum_none_assert(skb);
  6654. swstats->mem_freed += skb->truesize;
  6655. send_up:
  6656. skb_record_rx_queue(skb, ring_no);
  6657. queue_rx_frame(skb, RXD_GET_VLAN_TAG(rxdp->Control_2));
  6658. aggregate:
  6659. sp->mac_control.rings[ring_no].rx_bufs_left -= 1;
  6660. return SUCCESS;
  6661. }
  6662. /**
  6663. * s2io_link - stops/starts the Tx queue.
  6664. * @sp : private member of the device structure, which is a pointer to the
  6665. * s2io_nic structure.
  6666. * @link : inidicates whether link is UP/DOWN.
  6667. * Description:
  6668. * This function stops/starts the Tx queue depending on whether the link
  6669. * status of the NIC is is down or up. This is called by the Alarm
  6670. * interrupt handler whenever a link change interrupt comes up.
  6671. * Return value:
  6672. * void.
  6673. */
  6674. static void s2io_link(struct s2io_nic *sp, int link)
  6675. {
  6676. struct net_device *dev = (struct net_device *)sp->dev;
  6677. struct swStat *swstats = &sp->mac_control.stats_info->sw_stat;
  6678. if (link != sp->last_link_state) {
  6679. init_tti(sp, link);
  6680. if (link == LINK_DOWN) {
  6681. DBG_PRINT(ERR_DBG, "%s: Link down\n", dev->name);
  6682. s2io_stop_all_tx_queue(sp);
  6683. netif_carrier_off(dev);
  6684. if (swstats->link_up_cnt)
  6685. swstats->link_up_time =
  6686. jiffies - sp->start_time;
  6687. swstats->link_down_cnt++;
  6688. } else {
  6689. DBG_PRINT(ERR_DBG, "%s: Link Up\n", dev->name);
  6690. if (swstats->link_down_cnt)
  6691. swstats->link_down_time =
  6692. jiffies - sp->start_time;
  6693. swstats->link_up_cnt++;
  6694. netif_carrier_on(dev);
  6695. s2io_wake_all_tx_queue(sp);
  6696. }
  6697. }
  6698. sp->last_link_state = link;
  6699. sp->start_time = jiffies;
  6700. }
  6701. /**
  6702. * s2io_init_pci -Initialization of PCI and PCI-X configuration registers .
  6703. * @sp : private member of the device structure, which is a pointer to the
  6704. * s2io_nic structure.
  6705. * Description:
  6706. * This function initializes a few of the PCI and PCI-X configuration registers
  6707. * with recommended values.
  6708. * Return value:
  6709. * void
  6710. */
  6711. static void s2io_init_pci(struct s2io_nic *sp)
  6712. {
  6713. u16 pci_cmd = 0, pcix_cmd = 0;
  6714. /* Enable Data Parity Error Recovery in PCI-X command register. */
  6715. pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
  6716. &(pcix_cmd));
  6717. pci_write_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
  6718. (pcix_cmd | 1));
  6719. pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
  6720. &(pcix_cmd));
  6721. /* Set the PErr Response bit in PCI command register. */
  6722. pci_read_config_word(sp->pdev, PCI_COMMAND, &pci_cmd);
  6723. pci_write_config_word(sp->pdev, PCI_COMMAND,
  6724. (pci_cmd | PCI_COMMAND_PARITY));
  6725. pci_read_config_word(sp->pdev, PCI_COMMAND, &pci_cmd);
  6726. }
  6727. static int s2io_verify_parm(struct pci_dev *pdev, u8 *dev_intr_type,
  6728. u8 *dev_multiq)
  6729. {
  6730. int i;
  6731. if ((tx_fifo_num > MAX_TX_FIFOS) || (tx_fifo_num < 1)) {
  6732. DBG_PRINT(ERR_DBG, "Requested number of tx fifos "
  6733. "(%d) not supported\n", tx_fifo_num);
  6734. if (tx_fifo_num < 1)
  6735. tx_fifo_num = 1;
  6736. else
  6737. tx_fifo_num = MAX_TX_FIFOS;
  6738. DBG_PRINT(ERR_DBG, "Default to %d tx fifos\n", tx_fifo_num);
  6739. }
  6740. if (multiq)
  6741. *dev_multiq = multiq;
  6742. if (tx_steering_type && (1 == tx_fifo_num)) {
  6743. if (tx_steering_type != TX_DEFAULT_STEERING)
  6744. DBG_PRINT(ERR_DBG,
  6745. "Tx steering is not supported with "
  6746. "one fifo. Disabling Tx steering.\n");
  6747. tx_steering_type = NO_STEERING;
  6748. }
  6749. if ((tx_steering_type < NO_STEERING) ||
  6750. (tx_steering_type > TX_DEFAULT_STEERING)) {
  6751. DBG_PRINT(ERR_DBG,
  6752. "Requested transmit steering not supported\n");
  6753. DBG_PRINT(ERR_DBG, "Disabling transmit steering\n");
  6754. tx_steering_type = NO_STEERING;
  6755. }
  6756. if (rx_ring_num > MAX_RX_RINGS) {
  6757. DBG_PRINT(ERR_DBG,
  6758. "Requested number of rx rings not supported\n");
  6759. DBG_PRINT(ERR_DBG, "Default to %d rx rings\n",
  6760. MAX_RX_RINGS);
  6761. rx_ring_num = MAX_RX_RINGS;
  6762. }
  6763. if ((*dev_intr_type != INTA) && (*dev_intr_type != MSI_X)) {
  6764. DBG_PRINT(ERR_DBG, "Wrong intr_type requested. "
  6765. "Defaulting to INTA\n");
  6766. *dev_intr_type = INTA;
  6767. }
  6768. if ((*dev_intr_type == MSI_X) &&
  6769. ((pdev->device != PCI_DEVICE_ID_HERC_WIN) &&
  6770. (pdev->device != PCI_DEVICE_ID_HERC_UNI))) {
  6771. DBG_PRINT(ERR_DBG, "Xframe I does not support MSI_X. "
  6772. "Defaulting to INTA\n");
  6773. *dev_intr_type = INTA;
  6774. }
  6775. if ((rx_ring_mode != 1) && (rx_ring_mode != 2)) {
  6776. DBG_PRINT(ERR_DBG, "Requested ring mode not supported\n");
  6777. DBG_PRINT(ERR_DBG, "Defaulting to 1-buffer mode\n");
  6778. rx_ring_mode = 1;
  6779. }
  6780. for (i = 0; i < MAX_RX_RINGS; i++)
  6781. if (rx_ring_sz[i] > MAX_RX_BLOCKS_PER_RING) {
  6782. DBG_PRINT(ERR_DBG, "Requested rx ring size not "
  6783. "supported\nDefaulting to %d\n",
  6784. MAX_RX_BLOCKS_PER_RING);
  6785. rx_ring_sz[i] = MAX_RX_BLOCKS_PER_RING;
  6786. }
  6787. return SUCCESS;
  6788. }
  6789. /**
  6790. * rts_ds_steer - Receive traffic steering based on IPv4 or IPv6 TOS
  6791. * or Traffic class respectively.
  6792. * @nic: device private variable
  6793. * Description: The function configures the receive steering to
  6794. * desired receive ring.
  6795. * Return Value: SUCCESS on success and
  6796. * '-1' on failure (endian settings incorrect).
  6797. */
  6798. static int rts_ds_steer(struct s2io_nic *nic, u8 ds_codepoint, u8 ring)
  6799. {
  6800. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  6801. register u64 val64 = 0;
  6802. if (ds_codepoint > 63)
  6803. return FAILURE;
  6804. val64 = RTS_DS_MEM_DATA(ring);
  6805. writeq(val64, &bar0->rts_ds_mem_data);
  6806. val64 = RTS_DS_MEM_CTRL_WE |
  6807. RTS_DS_MEM_CTRL_STROBE_NEW_CMD |
  6808. RTS_DS_MEM_CTRL_OFFSET(ds_codepoint);
  6809. writeq(val64, &bar0->rts_ds_mem_ctrl);
  6810. return wait_for_cmd_complete(&bar0->rts_ds_mem_ctrl,
  6811. RTS_DS_MEM_CTRL_STROBE_CMD_BEING_EXECUTED,
  6812. S2IO_BIT_RESET);
  6813. }
  6814. static const struct net_device_ops s2io_netdev_ops = {
  6815. .ndo_open = s2io_open,
  6816. .ndo_stop = s2io_close,
  6817. .ndo_get_stats = s2io_get_stats,
  6818. .ndo_start_xmit = s2io_xmit,
  6819. .ndo_validate_addr = eth_validate_addr,
  6820. .ndo_set_rx_mode = s2io_set_multicast,
  6821. .ndo_do_ioctl = s2io_ioctl,
  6822. .ndo_set_mac_address = s2io_set_mac_addr,
  6823. .ndo_change_mtu = s2io_change_mtu,
  6824. .ndo_set_features = s2io_set_features,
  6825. .ndo_tx_timeout = s2io_tx_watchdog,
  6826. #ifdef CONFIG_NET_POLL_CONTROLLER
  6827. .ndo_poll_controller = s2io_netpoll,
  6828. #endif
  6829. };
  6830. /**
  6831. * s2io_init_nic - Initialization of the adapter .
  6832. * @pdev : structure containing the PCI related information of the device.
  6833. * @pre: List of PCI devices supported by the driver listed in s2io_tbl.
  6834. * Description:
  6835. * The function initializes an adapter identified by the pci_dec structure.
  6836. * All OS related initialization including memory and device structure and
  6837. * initlaization of the device private variable is done. Also the swapper
  6838. * control register is initialized to enable read and write into the I/O
  6839. * registers of the device.
  6840. * Return value:
  6841. * returns 0 on success and negative on failure.
  6842. */
  6843. static int __devinit
  6844. s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
  6845. {
  6846. struct s2io_nic *sp;
  6847. struct net_device *dev;
  6848. int i, j, ret;
  6849. int dma_flag = false;
  6850. u32 mac_up, mac_down;
  6851. u64 val64 = 0, tmp64 = 0;
  6852. struct XENA_dev_config __iomem *bar0 = NULL;
  6853. u16 subid;
  6854. struct config_param *config;
  6855. struct mac_info *mac_control;
  6856. int mode;
  6857. u8 dev_intr_type = intr_type;
  6858. u8 dev_multiq = 0;
  6859. ret = s2io_verify_parm(pdev, &dev_intr_type, &dev_multiq);
  6860. if (ret)
  6861. return ret;
  6862. ret = pci_enable_device(pdev);
  6863. if (ret) {
  6864. DBG_PRINT(ERR_DBG,
  6865. "%s: pci_enable_device failed\n", __func__);
  6866. return ret;
  6867. }
  6868. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
  6869. DBG_PRINT(INIT_DBG, "%s: Using 64bit DMA\n", __func__);
  6870. dma_flag = true;
  6871. if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) {
  6872. DBG_PRINT(ERR_DBG,
  6873. "Unable to obtain 64bit DMA "
  6874. "for consistent allocations\n");
  6875. pci_disable_device(pdev);
  6876. return -ENOMEM;
  6877. }
  6878. } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
  6879. DBG_PRINT(INIT_DBG, "%s: Using 32bit DMA\n", __func__);
  6880. } else {
  6881. pci_disable_device(pdev);
  6882. return -ENOMEM;
  6883. }
  6884. ret = pci_request_regions(pdev, s2io_driver_name);
  6885. if (ret) {
  6886. DBG_PRINT(ERR_DBG, "%s: Request Regions failed - %x\n",
  6887. __func__, ret);
  6888. pci_disable_device(pdev);
  6889. return -ENODEV;
  6890. }
  6891. if (dev_multiq)
  6892. dev = alloc_etherdev_mq(sizeof(struct s2io_nic), tx_fifo_num);
  6893. else
  6894. dev = alloc_etherdev(sizeof(struct s2io_nic));
  6895. if (dev == NULL) {
  6896. pci_disable_device(pdev);
  6897. pci_release_regions(pdev);
  6898. return -ENODEV;
  6899. }
  6900. pci_set_master(pdev);
  6901. pci_set_drvdata(pdev, dev);
  6902. SET_NETDEV_DEV(dev, &pdev->dev);
  6903. /* Private member variable initialized to s2io NIC structure */
  6904. sp = netdev_priv(dev);
  6905. sp->dev = dev;
  6906. sp->pdev = pdev;
  6907. sp->high_dma_flag = dma_flag;
  6908. sp->device_enabled_once = false;
  6909. if (rx_ring_mode == 1)
  6910. sp->rxd_mode = RXD_MODE_1;
  6911. if (rx_ring_mode == 2)
  6912. sp->rxd_mode = RXD_MODE_3B;
  6913. sp->config.intr_type = dev_intr_type;
  6914. if ((pdev->device == PCI_DEVICE_ID_HERC_WIN) ||
  6915. (pdev->device == PCI_DEVICE_ID_HERC_UNI))
  6916. sp->device_type = XFRAME_II_DEVICE;
  6917. else
  6918. sp->device_type = XFRAME_I_DEVICE;
  6919. /* Initialize some PCI/PCI-X fields of the NIC. */
  6920. s2io_init_pci(sp);
  6921. /*
  6922. * Setting the device configuration parameters.
  6923. * Most of these parameters can be specified by the user during
  6924. * module insertion as they are module loadable parameters. If
  6925. * these parameters are not not specified during load time, they
  6926. * are initialized with default values.
  6927. */
  6928. config = &sp->config;
  6929. mac_control = &sp->mac_control;
  6930. config->napi = napi;
  6931. config->tx_steering_type = tx_steering_type;
  6932. /* Tx side parameters. */
  6933. if (config->tx_steering_type == TX_PRIORITY_STEERING)
  6934. config->tx_fifo_num = MAX_TX_FIFOS;
  6935. else
  6936. config->tx_fifo_num = tx_fifo_num;
  6937. /* Initialize the fifos used for tx steering */
  6938. if (config->tx_fifo_num < 5) {
  6939. if (config->tx_fifo_num == 1)
  6940. sp->total_tcp_fifos = 1;
  6941. else
  6942. sp->total_tcp_fifos = config->tx_fifo_num - 1;
  6943. sp->udp_fifo_idx = config->tx_fifo_num - 1;
  6944. sp->total_udp_fifos = 1;
  6945. sp->other_fifo_idx = sp->total_tcp_fifos - 1;
  6946. } else {
  6947. sp->total_tcp_fifos = (tx_fifo_num - FIFO_UDP_MAX_NUM -
  6948. FIFO_OTHER_MAX_NUM);
  6949. sp->udp_fifo_idx = sp->total_tcp_fifos;
  6950. sp->total_udp_fifos = FIFO_UDP_MAX_NUM;
  6951. sp->other_fifo_idx = sp->udp_fifo_idx + FIFO_UDP_MAX_NUM;
  6952. }
  6953. config->multiq = dev_multiq;
  6954. for (i = 0; i < config->tx_fifo_num; i++) {
  6955. struct tx_fifo_config *tx_cfg = &config->tx_cfg[i];
  6956. tx_cfg->fifo_len = tx_fifo_len[i];
  6957. tx_cfg->fifo_priority = i;
  6958. }
  6959. /* mapping the QoS priority to the configured fifos */
  6960. for (i = 0; i < MAX_TX_FIFOS; i++)
  6961. config->fifo_mapping[i] = fifo_map[config->tx_fifo_num - 1][i];
  6962. /* map the hashing selector table to the configured fifos */
  6963. for (i = 0; i < config->tx_fifo_num; i++)
  6964. sp->fifo_selector[i] = fifo_selector[i];
  6965. config->tx_intr_type = TXD_INT_TYPE_UTILZ;
  6966. for (i = 0; i < config->tx_fifo_num; i++) {
  6967. struct tx_fifo_config *tx_cfg = &config->tx_cfg[i];
  6968. tx_cfg->f_no_snoop = (NO_SNOOP_TXD | NO_SNOOP_TXD_BUFFER);
  6969. if (tx_cfg->fifo_len < 65) {
  6970. config->tx_intr_type = TXD_INT_TYPE_PER_LIST;
  6971. break;
  6972. }
  6973. }
  6974. /* + 2 because one Txd for skb->data and one Txd for UFO */
  6975. config->max_txds = MAX_SKB_FRAGS + 2;
  6976. /* Rx side parameters. */
  6977. config->rx_ring_num = rx_ring_num;
  6978. for (i = 0; i < config->rx_ring_num; i++) {
  6979. struct rx_ring_config *rx_cfg = &config->rx_cfg[i];
  6980. struct ring_info *ring = &mac_control->rings[i];
  6981. rx_cfg->num_rxd = rx_ring_sz[i] * (rxd_count[sp->rxd_mode] + 1);
  6982. rx_cfg->ring_priority = i;
  6983. ring->rx_bufs_left = 0;
  6984. ring->rxd_mode = sp->rxd_mode;
  6985. ring->rxd_count = rxd_count[sp->rxd_mode];
  6986. ring->pdev = sp->pdev;
  6987. ring->dev = sp->dev;
  6988. }
  6989. for (i = 0; i < rx_ring_num; i++) {
  6990. struct rx_ring_config *rx_cfg = &config->rx_cfg[i];
  6991. rx_cfg->ring_org = RING_ORG_BUFF1;
  6992. rx_cfg->f_no_snoop = (NO_SNOOP_RXD | NO_SNOOP_RXD_BUFFER);
  6993. }
  6994. /* Setting Mac Control parameters */
  6995. mac_control->rmac_pause_time = rmac_pause_time;
  6996. mac_control->mc_pause_threshold_q0q3 = mc_pause_threshold_q0q3;
  6997. mac_control->mc_pause_threshold_q4q7 = mc_pause_threshold_q4q7;
  6998. /* initialize the shared memory used by the NIC and the host */
  6999. if (init_shared_mem(sp)) {
  7000. DBG_PRINT(ERR_DBG, "%s: Memory allocation failed\n", dev->name);
  7001. ret = -ENOMEM;
  7002. goto mem_alloc_failed;
  7003. }
  7004. sp->bar0 = pci_ioremap_bar(pdev, 0);
  7005. if (!sp->bar0) {
  7006. DBG_PRINT(ERR_DBG, "%s: Neterion: cannot remap io mem1\n",
  7007. dev->name);
  7008. ret = -ENOMEM;
  7009. goto bar0_remap_failed;
  7010. }
  7011. sp->bar1 = pci_ioremap_bar(pdev, 2);
  7012. if (!sp->bar1) {
  7013. DBG_PRINT(ERR_DBG, "%s: Neterion: cannot remap io mem2\n",
  7014. dev->name);
  7015. ret = -ENOMEM;
  7016. goto bar1_remap_failed;
  7017. }
  7018. /* Initializing the BAR1 address as the start of the FIFO pointer. */
  7019. for (j = 0; j < MAX_TX_FIFOS; j++) {
  7020. mac_control->tx_FIFO_start[j] = sp->bar1 + (j * 0x00020000);
  7021. }
  7022. /* Driver entry points */
  7023. dev->netdev_ops = &s2io_netdev_ops;
  7024. SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
  7025. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM |
  7026. NETIF_F_TSO | NETIF_F_TSO6 |
  7027. NETIF_F_RXCSUM | NETIF_F_LRO;
  7028. dev->features |= dev->hw_features |
  7029. NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  7030. if (sp->device_type & XFRAME_II_DEVICE) {
  7031. dev->hw_features |= NETIF_F_UFO;
  7032. if (ufo)
  7033. dev->features |= NETIF_F_UFO;
  7034. }
  7035. if (sp->high_dma_flag == true)
  7036. dev->features |= NETIF_F_HIGHDMA;
  7037. dev->watchdog_timeo = WATCH_DOG_TIMEOUT;
  7038. INIT_WORK(&sp->rst_timer_task, s2io_restart_nic);
  7039. INIT_WORK(&sp->set_link_task, s2io_set_link);
  7040. pci_save_state(sp->pdev);
  7041. /* Setting swapper control on the NIC, for proper reset operation */
  7042. if (s2io_set_swapper(sp)) {
  7043. DBG_PRINT(ERR_DBG, "%s: swapper settings are wrong\n",
  7044. dev->name);
  7045. ret = -EAGAIN;
  7046. goto set_swap_failed;
  7047. }
  7048. /* Verify if the Herc works on the slot its placed into */
  7049. if (sp->device_type & XFRAME_II_DEVICE) {
  7050. mode = s2io_verify_pci_mode(sp);
  7051. if (mode < 0) {
  7052. DBG_PRINT(ERR_DBG, "%s: Unsupported PCI bus mode\n",
  7053. __func__);
  7054. ret = -EBADSLT;
  7055. goto set_swap_failed;
  7056. }
  7057. }
  7058. if (sp->config.intr_type == MSI_X) {
  7059. sp->num_entries = config->rx_ring_num + 1;
  7060. ret = s2io_enable_msi_x(sp);
  7061. if (!ret) {
  7062. ret = s2io_test_msi(sp);
  7063. /* rollback MSI-X, will re-enable during add_isr() */
  7064. remove_msix_isr(sp);
  7065. }
  7066. if (ret) {
  7067. DBG_PRINT(ERR_DBG,
  7068. "MSI-X requested but failed to enable\n");
  7069. sp->config.intr_type = INTA;
  7070. }
  7071. }
  7072. if (config->intr_type == MSI_X) {
  7073. for (i = 0; i < config->rx_ring_num ; i++) {
  7074. struct ring_info *ring = &mac_control->rings[i];
  7075. netif_napi_add(dev, &ring->napi, s2io_poll_msix, 64);
  7076. }
  7077. } else {
  7078. netif_napi_add(dev, &sp->napi, s2io_poll_inta, 64);
  7079. }
  7080. /* Not needed for Herc */
  7081. if (sp->device_type & XFRAME_I_DEVICE) {
  7082. /*
  7083. * Fix for all "FFs" MAC address problems observed on
  7084. * Alpha platforms
  7085. */
  7086. fix_mac_address(sp);
  7087. s2io_reset(sp);
  7088. }
  7089. /*
  7090. * MAC address initialization.
  7091. * For now only one mac address will be read and used.
  7092. */
  7093. bar0 = sp->bar0;
  7094. val64 = RMAC_ADDR_CMD_MEM_RD | RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
  7095. RMAC_ADDR_CMD_MEM_OFFSET(0 + S2IO_MAC_ADDR_START_OFFSET);
  7096. writeq(val64, &bar0->rmac_addr_cmd_mem);
  7097. wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
  7098. RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
  7099. S2IO_BIT_RESET);
  7100. tmp64 = readq(&bar0->rmac_addr_data0_mem);
  7101. mac_down = (u32)tmp64;
  7102. mac_up = (u32) (tmp64 >> 32);
  7103. sp->def_mac_addr[0].mac_addr[3] = (u8) (mac_up);
  7104. sp->def_mac_addr[0].mac_addr[2] = (u8) (mac_up >> 8);
  7105. sp->def_mac_addr[0].mac_addr[1] = (u8) (mac_up >> 16);
  7106. sp->def_mac_addr[0].mac_addr[0] = (u8) (mac_up >> 24);
  7107. sp->def_mac_addr[0].mac_addr[5] = (u8) (mac_down >> 16);
  7108. sp->def_mac_addr[0].mac_addr[4] = (u8) (mac_down >> 24);
  7109. /* Set the factory defined MAC address initially */
  7110. dev->addr_len = ETH_ALEN;
  7111. memcpy(dev->dev_addr, sp->def_mac_addr, ETH_ALEN);
  7112. memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
  7113. /* initialize number of multicast & unicast MAC entries variables */
  7114. if (sp->device_type == XFRAME_I_DEVICE) {
  7115. config->max_mc_addr = S2IO_XENA_MAX_MC_ADDRESSES;
  7116. config->max_mac_addr = S2IO_XENA_MAX_MAC_ADDRESSES;
  7117. config->mc_start_offset = S2IO_XENA_MC_ADDR_START_OFFSET;
  7118. } else if (sp->device_type == XFRAME_II_DEVICE) {
  7119. config->max_mc_addr = S2IO_HERC_MAX_MC_ADDRESSES;
  7120. config->max_mac_addr = S2IO_HERC_MAX_MAC_ADDRESSES;
  7121. config->mc_start_offset = S2IO_HERC_MC_ADDR_START_OFFSET;
  7122. }
  7123. /* store mac addresses from CAM to s2io_nic structure */
  7124. do_s2io_store_unicast_mc(sp);
  7125. /* Configure MSIX vector for number of rings configured plus one */
  7126. if ((sp->device_type == XFRAME_II_DEVICE) &&
  7127. (config->intr_type == MSI_X))
  7128. sp->num_entries = config->rx_ring_num + 1;
  7129. /* Store the values of the MSIX table in the s2io_nic structure */
  7130. store_xmsi_data(sp);
  7131. /* reset Nic and bring it to known state */
  7132. s2io_reset(sp);
  7133. /*
  7134. * Initialize link state flags
  7135. * and the card state parameter
  7136. */
  7137. sp->state = 0;
  7138. /* Initialize spinlocks */
  7139. for (i = 0; i < sp->config.tx_fifo_num; i++) {
  7140. struct fifo_info *fifo = &mac_control->fifos[i];
  7141. spin_lock_init(&fifo->tx_lock);
  7142. }
  7143. /*
  7144. * SXE-002: Configure link and activity LED to init state
  7145. * on driver load.
  7146. */
  7147. subid = sp->pdev->subsystem_device;
  7148. if ((subid & 0xFF) >= 0x07) {
  7149. val64 = readq(&bar0->gpio_control);
  7150. val64 |= 0x0000800000000000ULL;
  7151. writeq(val64, &bar0->gpio_control);
  7152. val64 = 0x0411040400000000ULL;
  7153. writeq(val64, (void __iomem *)bar0 + 0x2700);
  7154. val64 = readq(&bar0->gpio_control);
  7155. }
  7156. sp->rx_csum = 1; /* Rx chksum verify enabled by default */
  7157. if (register_netdev(dev)) {
  7158. DBG_PRINT(ERR_DBG, "Device registration failed\n");
  7159. ret = -ENODEV;
  7160. goto register_failed;
  7161. }
  7162. s2io_vpd_read(sp);
  7163. DBG_PRINT(ERR_DBG, "Copyright(c) 2002-2010 Exar Corp.\n");
  7164. DBG_PRINT(ERR_DBG, "%s: Neterion %s (rev %d)\n", dev->name,
  7165. sp->product_name, pdev->revision);
  7166. DBG_PRINT(ERR_DBG, "%s: Driver version %s\n", dev->name,
  7167. s2io_driver_version);
  7168. DBG_PRINT(ERR_DBG, "%s: MAC Address: %pM\n", dev->name, dev->dev_addr);
  7169. DBG_PRINT(ERR_DBG, "Serial number: %s\n", sp->serial_num);
  7170. if (sp->device_type & XFRAME_II_DEVICE) {
  7171. mode = s2io_print_pci_mode(sp);
  7172. if (mode < 0) {
  7173. ret = -EBADSLT;
  7174. unregister_netdev(dev);
  7175. goto set_swap_failed;
  7176. }
  7177. }
  7178. switch (sp->rxd_mode) {
  7179. case RXD_MODE_1:
  7180. DBG_PRINT(ERR_DBG, "%s: 1-Buffer receive mode enabled\n",
  7181. dev->name);
  7182. break;
  7183. case RXD_MODE_3B:
  7184. DBG_PRINT(ERR_DBG, "%s: 2-Buffer receive mode enabled\n",
  7185. dev->name);
  7186. break;
  7187. }
  7188. switch (sp->config.napi) {
  7189. case 0:
  7190. DBG_PRINT(ERR_DBG, "%s: NAPI disabled\n", dev->name);
  7191. break;
  7192. case 1:
  7193. DBG_PRINT(ERR_DBG, "%s: NAPI enabled\n", dev->name);
  7194. break;
  7195. }
  7196. DBG_PRINT(ERR_DBG, "%s: Using %d Tx fifo(s)\n", dev->name,
  7197. sp->config.tx_fifo_num);
  7198. DBG_PRINT(ERR_DBG, "%s: Using %d Rx ring(s)\n", dev->name,
  7199. sp->config.rx_ring_num);
  7200. switch (sp->config.intr_type) {
  7201. case INTA:
  7202. DBG_PRINT(ERR_DBG, "%s: Interrupt type INTA\n", dev->name);
  7203. break;
  7204. case MSI_X:
  7205. DBG_PRINT(ERR_DBG, "%s: Interrupt type MSI-X\n", dev->name);
  7206. break;
  7207. }
  7208. if (sp->config.multiq) {
  7209. for (i = 0; i < sp->config.tx_fifo_num; i++) {
  7210. struct fifo_info *fifo = &mac_control->fifos[i];
  7211. fifo->multiq = config->multiq;
  7212. }
  7213. DBG_PRINT(ERR_DBG, "%s: Multiqueue support enabled\n",
  7214. dev->name);
  7215. } else
  7216. DBG_PRINT(ERR_DBG, "%s: Multiqueue support disabled\n",
  7217. dev->name);
  7218. switch (sp->config.tx_steering_type) {
  7219. case NO_STEERING:
  7220. DBG_PRINT(ERR_DBG, "%s: No steering enabled for transmit\n",
  7221. dev->name);
  7222. break;
  7223. case TX_PRIORITY_STEERING:
  7224. DBG_PRINT(ERR_DBG,
  7225. "%s: Priority steering enabled for transmit\n",
  7226. dev->name);
  7227. break;
  7228. case TX_DEFAULT_STEERING:
  7229. DBG_PRINT(ERR_DBG,
  7230. "%s: Default steering enabled for transmit\n",
  7231. dev->name);
  7232. }
  7233. DBG_PRINT(ERR_DBG, "%s: Large receive offload enabled\n",
  7234. dev->name);
  7235. if (ufo)
  7236. DBG_PRINT(ERR_DBG,
  7237. "%s: UDP Fragmentation Offload(UFO) enabled\n",
  7238. dev->name);
  7239. /* Initialize device name */
  7240. sprintf(sp->name, "%s Neterion %s", dev->name, sp->product_name);
  7241. if (vlan_tag_strip)
  7242. sp->vlan_strip_flag = 1;
  7243. else
  7244. sp->vlan_strip_flag = 0;
  7245. /*
  7246. * Make Link state as off at this point, when the Link change
  7247. * interrupt comes the state will be automatically changed to
  7248. * the right state.
  7249. */
  7250. netif_carrier_off(dev);
  7251. return 0;
  7252. register_failed:
  7253. set_swap_failed:
  7254. iounmap(sp->bar1);
  7255. bar1_remap_failed:
  7256. iounmap(sp->bar0);
  7257. bar0_remap_failed:
  7258. mem_alloc_failed:
  7259. free_shared_mem(sp);
  7260. pci_disable_device(pdev);
  7261. pci_release_regions(pdev);
  7262. pci_set_drvdata(pdev, NULL);
  7263. free_netdev(dev);
  7264. return ret;
  7265. }
  7266. /**
  7267. * s2io_rem_nic - Free the PCI device
  7268. * @pdev: structure containing the PCI related information of the device.
  7269. * Description: This function is called by the Pci subsystem to release a
  7270. * PCI device and free up all resource held up by the device. This could
  7271. * be in response to a Hot plug event or when the driver is to be removed
  7272. * from memory.
  7273. */
  7274. static void __devexit s2io_rem_nic(struct pci_dev *pdev)
  7275. {
  7276. struct net_device *dev = pci_get_drvdata(pdev);
  7277. struct s2io_nic *sp;
  7278. if (dev == NULL) {
  7279. DBG_PRINT(ERR_DBG, "Driver Data is NULL!!\n");
  7280. return;
  7281. }
  7282. sp = netdev_priv(dev);
  7283. cancel_work_sync(&sp->rst_timer_task);
  7284. cancel_work_sync(&sp->set_link_task);
  7285. unregister_netdev(dev);
  7286. free_shared_mem(sp);
  7287. iounmap(sp->bar0);
  7288. iounmap(sp->bar1);
  7289. pci_release_regions(pdev);
  7290. pci_set_drvdata(pdev, NULL);
  7291. free_netdev(dev);
  7292. pci_disable_device(pdev);
  7293. }
  7294. /**
  7295. * s2io_starter - Entry point for the driver
  7296. * Description: This function is the entry point for the driver. It verifies
  7297. * the module loadable parameters and initializes PCI configuration space.
  7298. */
  7299. static int __init s2io_starter(void)
  7300. {
  7301. return pci_register_driver(&s2io_driver);
  7302. }
  7303. /**
  7304. * s2io_closer - Cleanup routine for the driver
  7305. * Description: This function is the cleanup routine for the driver. It unregist * ers the driver.
  7306. */
  7307. static __exit void s2io_closer(void)
  7308. {
  7309. pci_unregister_driver(&s2io_driver);
  7310. DBG_PRINT(INIT_DBG, "cleanup done\n");
  7311. }
  7312. module_init(s2io_starter);
  7313. module_exit(s2io_closer);
  7314. static int check_L2_lro_capable(u8 *buffer, struct iphdr **ip,
  7315. struct tcphdr **tcp, struct RxD_t *rxdp,
  7316. struct s2io_nic *sp)
  7317. {
  7318. int ip_off;
  7319. u8 l2_type = (u8)((rxdp->Control_1 >> 37) & 0x7), ip_len;
  7320. if (!(rxdp->Control_1 & RXD_FRAME_PROTO_TCP)) {
  7321. DBG_PRINT(INIT_DBG,
  7322. "%s: Non-TCP frames not supported for LRO\n",
  7323. __func__);
  7324. return -1;
  7325. }
  7326. /* Checking for DIX type or DIX type with VLAN */
  7327. if ((l2_type == 0) || (l2_type == 4)) {
  7328. ip_off = HEADER_ETHERNET_II_802_3_SIZE;
  7329. /*
  7330. * If vlan stripping is disabled and the frame is VLAN tagged,
  7331. * shift the offset by the VLAN header size bytes.
  7332. */
  7333. if ((!sp->vlan_strip_flag) &&
  7334. (rxdp->Control_1 & RXD_FRAME_VLAN_TAG))
  7335. ip_off += HEADER_VLAN_SIZE;
  7336. } else {
  7337. /* LLC, SNAP etc are considered non-mergeable */
  7338. return -1;
  7339. }
  7340. *ip = (struct iphdr *)((u8 *)buffer + ip_off);
  7341. ip_len = (u8)((*ip)->ihl);
  7342. ip_len <<= 2;
  7343. *tcp = (struct tcphdr *)((unsigned long)*ip + ip_len);
  7344. return 0;
  7345. }
  7346. static int check_for_socket_match(struct lro *lro, struct iphdr *ip,
  7347. struct tcphdr *tcp)
  7348. {
  7349. DBG_PRINT(INFO_DBG, "%s: Been here...\n", __func__);
  7350. if ((lro->iph->saddr != ip->saddr) ||
  7351. (lro->iph->daddr != ip->daddr) ||
  7352. (lro->tcph->source != tcp->source) ||
  7353. (lro->tcph->dest != tcp->dest))
  7354. return -1;
  7355. return 0;
  7356. }
  7357. static inline int get_l4_pyld_length(struct iphdr *ip, struct tcphdr *tcp)
  7358. {
  7359. return ntohs(ip->tot_len) - (ip->ihl << 2) - (tcp->doff << 2);
  7360. }
  7361. static void initiate_new_session(struct lro *lro, u8 *l2h,
  7362. struct iphdr *ip, struct tcphdr *tcp,
  7363. u32 tcp_pyld_len, u16 vlan_tag)
  7364. {
  7365. DBG_PRINT(INFO_DBG, "%s: Been here...\n", __func__);
  7366. lro->l2h = l2h;
  7367. lro->iph = ip;
  7368. lro->tcph = tcp;
  7369. lro->tcp_next_seq = tcp_pyld_len + ntohl(tcp->seq);
  7370. lro->tcp_ack = tcp->ack_seq;
  7371. lro->sg_num = 1;
  7372. lro->total_len = ntohs(ip->tot_len);
  7373. lro->frags_len = 0;
  7374. lro->vlan_tag = vlan_tag;
  7375. /*
  7376. * Check if we saw TCP timestamp.
  7377. * Other consistency checks have already been done.
  7378. */
  7379. if (tcp->doff == 8) {
  7380. __be32 *ptr;
  7381. ptr = (__be32 *)(tcp+1);
  7382. lro->saw_ts = 1;
  7383. lro->cur_tsval = ntohl(*(ptr+1));
  7384. lro->cur_tsecr = *(ptr+2);
  7385. }
  7386. lro->in_use = 1;
  7387. }
  7388. static void update_L3L4_header(struct s2io_nic *sp, struct lro *lro)
  7389. {
  7390. struct iphdr *ip = lro->iph;
  7391. struct tcphdr *tcp = lro->tcph;
  7392. __sum16 nchk;
  7393. struct swStat *swstats = &sp->mac_control.stats_info->sw_stat;
  7394. DBG_PRINT(INFO_DBG, "%s: Been here...\n", __func__);
  7395. /* Update L3 header */
  7396. ip->tot_len = htons(lro->total_len);
  7397. ip->check = 0;
  7398. nchk = ip_fast_csum((u8 *)lro->iph, ip->ihl);
  7399. ip->check = nchk;
  7400. /* Update L4 header */
  7401. tcp->ack_seq = lro->tcp_ack;
  7402. tcp->window = lro->window;
  7403. /* Update tsecr field if this session has timestamps enabled */
  7404. if (lro->saw_ts) {
  7405. __be32 *ptr = (__be32 *)(tcp + 1);
  7406. *(ptr+2) = lro->cur_tsecr;
  7407. }
  7408. /* Update counters required for calculation of
  7409. * average no. of packets aggregated.
  7410. */
  7411. swstats->sum_avg_pkts_aggregated += lro->sg_num;
  7412. swstats->num_aggregations++;
  7413. }
  7414. static void aggregate_new_rx(struct lro *lro, struct iphdr *ip,
  7415. struct tcphdr *tcp, u32 l4_pyld)
  7416. {
  7417. DBG_PRINT(INFO_DBG, "%s: Been here...\n", __func__);
  7418. lro->total_len += l4_pyld;
  7419. lro->frags_len += l4_pyld;
  7420. lro->tcp_next_seq += l4_pyld;
  7421. lro->sg_num++;
  7422. /* Update ack seq no. and window ad(from this pkt) in LRO object */
  7423. lro->tcp_ack = tcp->ack_seq;
  7424. lro->window = tcp->window;
  7425. if (lro->saw_ts) {
  7426. __be32 *ptr;
  7427. /* Update tsecr and tsval from this packet */
  7428. ptr = (__be32 *)(tcp+1);
  7429. lro->cur_tsval = ntohl(*(ptr+1));
  7430. lro->cur_tsecr = *(ptr + 2);
  7431. }
  7432. }
  7433. static int verify_l3_l4_lro_capable(struct lro *l_lro, struct iphdr *ip,
  7434. struct tcphdr *tcp, u32 tcp_pyld_len)
  7435. {
  7436. u8 *ptr;
  7437. DBG_PRINT(INFO_DBG, "%s: Been here...\n", __func__);
  7438. if (!tcp_pyld_len) {
  7439. /* Runt frame or a pure ack */
  7440. return -1;
  7441. }
  7442. if (ip->ihl != 5) /* IP has options */
  7443. return -1;
  7444. /* If we see CE codepoint in IP header, packet is not mergeable */
  7445. if (INET_ECN_is_ce(ipv4_get_dsfield(ip)))
  7446. return -1;
  7447. /* If we see ECE or CWR flags in TCP header, packet is not mergeable */
  7448. if (tcp->urg || tcp->psh || tcp->rst ||
  7449. tcp->syn || tcp->fin ||
  7450. tcp->ece || tcp->cwr || !tcp->ack) {
  7451. /*
  7452. * Currently recognize only the ack control word and
  7453. * any other control field being set would result in
  7454. * flushing the LRO session
  7455. */
  7456. return -1;
  7457. }
  7458. /*
  7459. * Allow only one TCP timestamp option. Don't aggregate if
  7460. * any other options are detected.
  7461. */
  7462. if (tcp->doff != 5 && tcp->doff != 8)
  7463. return -1;
  7464. if (tcp->doff == 8) {
  7465. ptr = (u8 *)(tcp + 1);
  7466. while (*ptr == TCPOPT_NOP)
  7467. ptr++;
  7468. if (*ptr != TCPOPT_TIMESTAMP || *(ptr+1) != TCPOLEN_TIMESTAMP)
  7469. return -1;
  7470. /* Ensure timestamp value increases monotonically */
  7471. if (l_lro)
  7472. if (l_lro->cur_tsval > ntohl(*((__be32 *)(ptr+2))))
  7473. return -1;
  7474. /* timestamp echo reply should be non-zero */
  7475. if (*((__be32 *)(ptr+6)) == 0)
  7476. return -1;
  7477. }
  7478. return 0;
  7479. }
  7480. static int s2io_club_tcp_session(struct ring_info *ring_data, u8 *buffer,
  7481. u8 **tcp, u32 *tcp_len, struct lro **lro,
  7482. struct RxD_t *rxdp, struct s2io_nic *sp)
  7483. {
  7484. struct iphdr *ip;
  7485. struct tcphdr *tcph;
  7486. int ret = 0, i;
  7487. u16 vlan_tag = 0;
  7488. struct swStat *swstats = &sp->mac_control.stats_info->sw_stat;
  7489. ret = check_L2_lro_capable(buffer, &ip, (struct tcphdr **)tcp,
  7490. rxdp, sp);
  7491. if (ret)
  7492. return ret;
  7493. DBG_PRINT(INFO_DBG, "IP Saddr: %x Daddr: %x\n", ip->saddr, ip->daddr);
  7494. vlan_tag = RXD_GET_VLAN_TAG(rxdp->Control_2);
  7495. tcph = (struct tcphdr *)*tcp;
  7496. *tcp_len = get_l4_pyld_length(ip, tcph);
  7497. for (i = 0; i < MAX_LRO_SESSIONS; i++) {
  7498. struct lro *l_lro = &ring_data->lro0_n[i];
  7499. if (l_lro->in_use) {
  7500. if (check_for_socket_match(l_lro, ip, tcph))
  7501. continue;
  7502. /* Sock pair matched */
  7503. *lro = l_lro;
  7504. if ((*lro)->tcp_next_seq != ntohl(tcph->seq)) {
  7505. DBG_PRINT(INFO_DBG, "%s: Out of sequence. "
  7506. "expected 0x%x, actual 0x%x\n",
  7507. __func__,
  7508. (*lro)->tcp_next_seq,
  7509. ntohl(tcph->seq));
  7510. swstats->outof_sequence_pkts++;
  7511. ret = 2;
  7512. break;
  7513. }
  7514. if (!verify_l3_l4_lro_capable(l_lro, ip, tcph,
  7515. *tcp_len))
  7516. ret = 1; /* Aggregate */
  7517. else
  7518. ret = 2; /* Flush both */
  7519. break;
  7520. }
  7521. }
  7522. if (ret == 0) {
  7523. /* Before searching for available LRO objects,
  7524. * check if the pkt is L3/L4 aggregatable. If not
  7525. * don't create new LRO session. Just send this
  7526. * packet up.
  7527. */
  7528. if (verify_l3_l4_lro_capable(NULL, ip, tcph, *tcp_len))
  7529. return 5;
  7530. for (i = 0; i < MAX_LRO_SESSIONS; i++) {
  7531. struct lro *l_lro = &ring_data->lro0_n[i];
  7532. if (!(l_lro->in_use)) {
  7533. *lro = l_lro;
  7534. ret = 3; /* Begin anew */
  7535. break;
  7536. }
  7537. }
  7538. }
  7539. if (ret == 0) { /* sessions exceeded */
  7540. DBG_PRINT(INFO_DBG, "%s: All LRO sessions already in use\n",
  7541. __func__);
  7542. *lro = NULL;
  7543. return ret;
  7544. }
  7545. switch (ret) {
  7546. case 3:
  7547. initiate_new_session(*lro, buffer, ip, tcph, *tcp_len,
  7548. vlan_tag);
  7549. break;
  7550. case 2:
  7551. update_L3L4_header(sp, *lro);
  7552. break;
  7553. case 1:
  7554. aggregate_new_rx(*lro, ip, tcph, *tcp_len);
  7555. if ((*lro)->sg_num == sp->lro_max_aggr_per_sess) {
  7556. update_L3L4_header(sp, *lro);
  7557. ret = 4; /* Flush the LRO */
  7558. }
  7559. break;
  7560. default:
  7561. DBG_PRINT(ERR_DBG, "%s: Don't know, can't say!!\n", __func__);
  7562. break;
  7563. }
  7564. return ret;
  7565. }
  7566. static void clear_lro_session(struct lro *lro)
  7567. {
  7568. static u16 lro_struct_size = sizeof(struct lro);
  7569. memset(lro, 0, lro_struct_size);
  7570. }
  7571. static void queue_rx_frame(struct sk_buff *skb, u16 vlan_tag)
  7572. {
  7573. struct net_device *dev = skb->dev;
  7574. struct s2io_nic *sp = netdev_priv(dev);
  7575. skb->protocol = eth_type_trans(skb, dev);
  7576. if (vlan_tag && sp->vlan_strip_flag)
  7577. __vlan_hwaccel_put_tag(skb, vlan_tag);
  7578. if (sp->config.napi)
  7579. netif_receive_skb(skb);
  7580. else
  7581. netif_rx(skb);
  7582. }
  7583. static void lro_append_pkt(struct s2io_nic *sp, struct lro *lro,
  7584. struct sk_buff *skb, u32 tcp_len)
  7585. {
  7586. struct sk_buff *first = lro->parent;
  7587. struct swStat *swstats = &sp->mac_control.stats_info->sw_stat;
  7588. first->len += tcp_len;
  7589. first->data_len = lro->frags_len;
  7590. skb_pull(skb, (skb->len - tcp_len));
  7591. if (skb_shinfo(first)->frag_list)
  7592. lro->last_frag->next = skb;
  7593. else
  7594. skb_shinfo(first)->frag_list = skb;
  7595. first->truesize += skb->truesize;
  7596. lro->last_frag = skb;
  7597. swstats->clubbed_frms_cnt++;
  7598. }
  7599. /**
  7600. * s2io_io_error_detected - called when PCI error is detected
  7601. * @pdev: Pointer to PCI device
  7602. * @state: The current pci connection state
  7603. *
  7604. * This function is called after a PCI bus error affecting
  7605. * this device has been detected.
  7606. */
  7607. static pci_ers_result_t s2io_io_error_detected(struct pci_dev *pdev,
  7608. pci_channel_state_t state)
  7609. {
  7610. struct net_device *netdev = pci_get_drvdata(pdev);
  7611. struct s2io_nic *sp = netdev_priv(netdev);
  7612. netif_device_detach(netdev);
  7613. if (state == pci_channel_io_perm_failure)
  7614. return PCI_ERS_RESULT_DISCONNECT;
  7615. if (netif_running(netdev)) {
  7616. /* Bring down the card, while avoiding PCI I/O */
  7617. do_s2io_card_down(sp, 0);
  7618. }
  7619. pci_disable_device(pdev);
  7620. return PCI_ERS_RESULT_NEED_RESET;
  7621. }
  7622. /**
  7623. * s2io_io_slot_reset - called after the pci bus has been reset.
  7624. * @pdev: Pointer to PCI device
  7625. *
  7626. * Restart the card from scratch, as if from a cold-boot.
  7627. * At this point, the card has exprienced a hard reset,
  7628. * followed by fixups by BIOS, and has its config space
  7629. * set up identically to what it was at cold boot.
  7630. */
  7631. static pci_ers_result_t s2io_io_slot_reset(struct pci_dev *pdev)
  7632. {
  7633. struct net_device *netdev = pci_get_drvdata(pdev);
  7634. struct s2io_nic *sp = netdev_priv(netdev);
  7635. if (pci_enable_device(pdev)) {
  7636. pr_err("Cannot re-enable PCI device after reset.\n");
  7637. return PCI_ERS_RESULT_DISCONNECT;
  7638. }
  7639. pci_set_master(pdev);
  7640. s2io_reset(sp);
  7641. return PCI_ERS_RESULT_RECOVERED;
  7642. }
  7643. /**
  7644. * s2io_io_resume - called when traffic can start flowing again.
  7645. * @pdev: Pointer to PCI device
  7646. *
  7647. * This callback is called when the error recovery driver tells
  7648. * us that its OK to resume normal operation.
  7649. */
  7650. static void s2io_io_resume(struct pci_dev *pdev)
  7651. {
  7652. struct net_device *netdev = pci_get_drvdata(pdev);
  7653. struct s2io_nic *sp = netdev_priv(netdev);
  7654. if (netif_running(netdev)) {
  7655. if (s2io_card_up(sp)) {
  7656. pr_err("Can't bring device back up after reset.\n");
  7657. return;
  7658. }
  7659. if (s2io_set_mac_addr(netdev, netdev->dev_addr) == FAILURE) {
  7660. s2io_card_down(sp);
  7661. pr_err("Can't restore mac addr after reset.\n");
  7662. return;
  7663. }
  7664. }
  7665. netif_device_attach(netdev);
  7666. netif_tx_wake_all_queues(netdev);
  7667. }