s2io.c 235 KB

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