s2io.c 220 KB

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