s2io.c 158 KB

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