s2io.c 172 KB

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