s2io.c 223 KB

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