s2io.c 218 KB

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