s2io.c 246 KB

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