s2io.c 175 KB

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