s2io.c 138 KB

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