s2io.c 144 KB

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