s2io.c 144 KB

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