s2io.c 213 KB

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