s2io.c 177 KB

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