s2io.c 143 KB

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