s2io.c 230 KB

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