s2io.c 159 KB

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