s2io.c 156 KB

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