s2io.c 138 KB

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