s2io.c 214 KB

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