myri10ge.c 117 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285
  1. /*************************************************************************
  2. * myri10ge.c: Myricom Myri-10G Ethernet driver.
  3. *
  4. * Copyright (C) 2005 - 2011 Myricom, Inc.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of Myricom, Inc. nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  23. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. * POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. *
  32. * If the eeprom on your board is not recent enough, you will need to get a
  33. * newer firmware image at:
  34. * http://www.myri.com/scs/download-Myri10GE.html
  35. *
  36. * Contact Information:
  37. * <help@myri.com>
  38. * Myricom, Inc., 325N Santa Anita Avenue, Arcadia, CA 91006
  39. *************************************************************************/
  40. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  41. #include <linux/tcp.h>
  42. #include <linux/netdevice.h>
  43. #include <linux/skbuff.h>
  44. #include <linux/string.h>
  45. #include <linux/module.h>
  46. #include <linux/pci.h>
  47. #include <linux/dma-mapping.h>
  48. #include <linux/etherdevice.h>
  49. #include <linux/if_ether.h>
  50. #include <linux/if_vlan.h>
  51. #include <linux/dca.h>
  52. #include <linux/ip.h>
  53. #include <linux/inet.h>
  54. #include <linux/in.h>
  55. #include <linux/ethtool.h>
  56. #include <linux/firmware.h>
  57. #include <linux/delay.h>
  58. #include <linux/timer.h>
  59. #include <linux/vmalloc.h>
  60. #include <linux/crc32.h>
  61. #include <linux/moduleparam.h>
  62. #include <linux/io.h>
  63. #include <linux/log2.h>
  64. #include <linux/slab.h>
  65. #include <linux/prefetch.h>
  66. #include <net/checksum.h>
  67. #include <net/ip.h>
  68. #include <net/tcp.h>
  69. #include <asm/byteorder.h>
  70. #include <asm/io.h>
  71. #include <asm/processor.h>
  72. #ifdef CONFIG_MTRR
  73. #include <asm/mtrr.h>
  74. #endif
  75. #include <net/busy_poll.h>
  76. #include "myri10ge_mcp.h"
  77. #include "myri10ge_mcp_gen_header.h"
  78. #define MYRI10GE_VERSION_STR "1.5.3-1.534"
  79. MODULE_DESCRIPTION("Myricom 10G driver (10GbE)");
  80. MODULE_AUTHOR("Maintainer: help@myri.com");
  81. MODULE_VERSION(MYRI10GE_VERSION_STR);
  82. MODULE_LICENSE("Dual BSD/GPL");
  83. #define MYRI10GE_MAX_ETHER_MTU 9014
  84. #define MYRI10GE_ETH_STOPPED 0
  85. #define MYRI10GE_ETH_STOPPING 1
  86. #define MYRI10GE_ETH_STARTING 2
  87. #define MYRI10GE_ETH_RUNNING 3
  88. #define MYRI10GE_ETH_OPEN_FAILED 4
  89. #define MYRI10GE_EEPROM_STRINGS_SIZE 256
  90. #define MYRI10GE_MAX_SEND_DESC_TSO ((65536 / 2048) * 2)
  91. #define MYRI10GE_NO_CONFIRM_DATA htonl(0xffffffff)
  92. #define MYRI10GE_NO_RESPONSE_RESULT 0xffffffff
  93. #define MYRI10GE_ALLOC_ORDER 0
  94. #define MYRI10GE_ALLOC_SIZE ((1 << MYRI10GE_ALLOC_ORDER) * PAGE_SIZE)
  95. #define MYRI10GE_MAX_FRAGS_PER_FRAME (MYRI10GE_MAX_ETHER_MTU/MYRI10GE_ALLOC_SIZE + 1)
  96. #define MYRI10GE_MAX_SLICES 32
  97. struct myri10ge_rx_buffer_state {
  98. struct page *page;
  99. int page_offset;
  100. DEFINE_DMA_UNMAP_ADDR(bus);
  101. DEFINE_DMA_UNMAP_LEN(len);
  102. };
  103. struct myri10ge_tx_buffer_state {
  104. struct sk_buff *skb;
  105. int last;
  106. DEFINE_DMA_UNMAP_ADDR(bus);
  107. DEFINE_DMA_UNMAP_LEN(len);
  108. };
  109. struct myri10ge_cmd {
  110. u32 data0;
  111. u32 data1;
  112. u32 data2;
  113. };
  114. struct myri10ge_rx_buf {
  115. struct mcp_kreq_ether_recv __iomem *lanai; /* lanai ptr for recv ring */
  116. struct mcp_kreq_ether_recv *shadow; /* host shadow of recv ring */
  117. struct myri10ge_rx_buffer_state *info;
  118. struct page *page;
  119. dma_addr_t bus;
  120. int page_offset;
  121. int cnt;
  122. int fill_cnt;
  123. int alloc_fail;
  124. int mask; /* number of rx slots -1 */
  125. int watchdog_needed;
  126. };
  127. struct myri10ge_tx_buf {
  128. struct mcp_kreq_ether_send __iomem *lanai; /* lanai ptr for sendq */
  129. __be32 __iomem *send_go; /* "go" doorbell ptr */
  130. __be32 __iomem *send_stop; /* "stop" doorbell ptr */
  131. struct mcp_kreq_ether_send *req_list; /* host shadow of sendq */
  132. char *req_bytes;
  133. struct myri10ge_tx_buffer_state *info;
  134. int mask; /* number of transmit slots -1 */
  135. int req ____cacheline_aligned; /* transmit slots submitted */
  136. int pkt_start; /* packets started */
  137. int stop_queue;
  138. int linearized;
  139. int done ____cacheline_aligned; /* transmit slots completed */
  140. int pkt_done; /* packets completed */
  141. int wake_queue;
  142. int queue_active;
  143. };
  144. struct myri10ge_rx_done {
  145. struct mcp_slot *entry;
  146. dma_addr_t bus;
  147. int cnt;
  148. int idx;
  149. };
  150. struct myri10ge_slice_netstats {
  151. unsigned long rx_packets;
  152. unsigned long tx_packets;
  153. unsigned long rx_bytes;
  154. unsigned long tx_bytes;
  155. unsigned long rx_dropped;
  156. unsigned long tx_dropped;
  157. };
  158. struct myri10ge_slice_state {
  159. struct myri10ge_tx_buf tx; /* transmit ring */
  160. struct myri10ge_rx_buf rx_small;
  161. struct myri10ge_rx_buf rx_big;
  162. struct myri10ge_rx_done rx_done;
  163. struct net_device *dev;
  164. struct napi_struct napi;
  165. struct myri10ge_priv *mgp;
  166. struct myri10ge_slice_netstats stats;
  167. __be32 __iomem *irq_claim;
  168. struct mcp_irq_data *fw_stats;
  169. dma_addr_t fw_stats_bus;
  170. int watchdog_tx_done;
  171. int watchdog_tx_req;
  172. int watchdog_rx_done;
  173. int stuck;
  174. #ifdef CONFIG_MYRI10GE_DCA
  175. int cached_dca_tag;
  176. int cpu;
  177. __be32 __iomem *dca_tag;
  178. #endif
  179. #ifdef CONFIG_NET_RX_BUSY_POLL
  180. unsigned int state;
  181. #define SLICE_STATE_IDLE 0
  182. #define SLICE_STATE_NAPI 1 /* NAPI owns this slice */
  183. #define SLICE_STATE_POLL 2 /* poll owns this slice */
  184. #define SLICE_LOCKED (SLICE_STATE_NAPI | SLICE_STATE_POLL)
  185. #define SLICE_STATE_NAPI_YIELD 4 /* NAPI yielded this slice */
  186. #define SLICE_STATE_POLL_YIELD 8 /* poll yielded this slice */
  187. #define SLICE_USER_PEND (SLICE_STATE_POLL | SLICE_STATE_POLL_YIELD)
  188. spinlock_t lock;
  189. unsigned long lock_napi_yield;
  190. unsigned long lock_poll_yield;
  191. unsigned long busy_poll_miss;
  192. unsigned long busy_poll_cnt;
  193. #endif /* CONFIG_NET_RX_BUSY_POLL */
  194. char irq_desc[32];
  195. };
  196. struct myri10ge_priv {
  197. struct myri10ge_slice_state *ss;
  198. int tx_boundary; /* boundary transmits cannot cross */
  199. int num_slices;
  200. int running; /* running? */
  201. int small_bytes;
  202. int big_bytes;
  203. int max_intr_slots;
  204. struct net_device *dev;
  205. u8 __iomem *sram;
  206. int sram_size;
  207. unsigned long board_span;
  208. unsigned long iomem_base;
  209. __be32 __iomem *irq_deassert;
  210. char *mac_addr_string;
  211. struct mcp_cmd_response *cmd;
  212. dma_addr_t cmd_bus;
  213. struct pci_dev *pdev;
  214. int msi_enabled;
  215. int msix_enabled;
  216. struct msix_entry *msix_vectors;
  217. #ifdef CONFIG_MYRI10GE_DCA
  218. int dca_enabled;
  219. int relaxed_order;
  220. #endif
  221. u32 link_state;
  222. unsigned int rdma_tags_available;
  223. int intr_coal_delay;
  224. __be32 __iomem *intr_coal_delay_ptr;
  225. int mtrr;
  226. int wc_enabled;
  227. int down_cnt;
  228. wait_queue_head_t down_wq;
  229. struct work_struct watchdog_work;
  230. struct timer_list watchdog_timer;
  231. int watchdog_resets;
  232. int watchdog_pause;
  233. int pause;
  234. bool fw_name_allocated;
  235. char *fw_name;
  236. char eeprom_strings[MYRI10GE_EEPROM_STRINGS_SIZE];
  237. char *product_code_string;
  238. char fw_version[128];
  239. int fw_ver_major;
  240. int fw_ver_minor;
  241. int fw_ver_tiny;
  242. int adopted_rx_filter_bug;
  243. u8 mac_addr[ETH_ALEN]; /* eeprom mac address */
  244. unsigned long serial_number;
  245. int vendor_specific_offset;
  246. int fw_multicast_support;
  247. u32 features;
  248. u32 max_tso6;
  249. u32 read_dma;
  250. u32 write_dma;
  251. u32 read_write_dma;
  252. u32 link_changes;
  253. u32 msg_enable;
  254. unsigned int board_number;
  255. int rebooted;
  256. };
  257. static char *myri10ge_fw_unaligned = "myri10ge_ethp_z8e.dat";
  258. static char *myri10ge_fw_aligned = "myri10ge_eth_z8e.dat";
  259. static char *myri10ge_fw_rss_unaligned = "myri10ge_rss_ethp_z8e.dat";
  260. static char *myri10ge_fw_rss_aligned = "myri10ge_rss_eth_z8e.dat";
  261. MODULE_FIRMWARE("myri10ge_ethp_z8e.dat");
  262. MODULE_FIRMWARE("myri10ge_eth_z8e.dat");
  263. MODULE_FIRMWARE("myri10ge_rss_ethp_z8e.dat");
  264. MODULE_FIRMWARE("myri10ge_rss_eth_z8e.dat");
  265. /* Careful: must be accessed under kparam_block_sysfs_write */
  266. static char *myri10ge_fw_name = NULL;
  267. module_param(myri10ge_fw_name, charp, S_IRUGO | S_IWUSR);
  268. MODULE_PARM_DESC(myri10ge_fw_name, "Firmware image name");
  269. #define MYRI10GE_MAX_BOARDS 8
  270. static char *myri10ge_fw_names[MYRI10GE_MAX_BOARDS] =
  271. {[0 ... (MYRI10GE_MAX_BOARDS - 1)] = NULL };
  272. module_param_array_named(myri10ge_fw_names, myri10ge_fw_names, charp, NULL,
  273. 0444);
  274. MODULE_PARM_DESC(myri10ge_fw_name, "Firmware image names per board");
  275. static int myri10ge_ecrc_enable = 1;
  276. module_param(myri10ge_ecrc_enable, int, S_IRUGO);
  277. MODULE_PARM_DESC(myri10ge_ecrc_enable, "Enable Extended CRC on PCI-E");
  278. static int myri10ge_small_bytes = -1; /* -1 == auto */
  279. module_param(myri10ge_small_bytes, int, S_IRUGO | S_IWUSR);
  280. MODULE_PARM_DESC(myri10ge_small_bytes, "Threshold of small packets");
  281. static int myri10ge_msi = 1; /* enable msi by default */
  282. module_param(myri10ge_msi, int, S_IRUGO | S_IWUSR);
  283. MODULE_PARM_DESC(myri10ge_msi, "Enable Message Signalled Interrupts");
  284. static int myri10ge_intr_coal_delay = 75;
  285. module_param(myri10ge_intr_coal_delay, int, S_IRUGO);
  286. MODULE_PARM_DESC(myri10ge_intr_coal_delay, "Interrupt coalescing delay");
  287. static int myri10ge_flow_control = 1;
  288. module_param(myri10ge_flow_control, int, S_IRUGO);
  289. MODULE_PARM_DESC(myri10ge_flow_control, "Pause parameter");
  290. static int myri10ge_deassert_wait = 1;
  291. module_param(myri10ge_deassert_wait, int, S_IRUGO | S_IWUSR);
  292. MODULE_PARM_DESC(myri10ge_deassert_wait,
  293. "Wait when deasserting legacy interrupts");
  294. static int myri10ge_force_firmware = 0;
  295. module_param(myri10ge_force_firmware, int, S_IRUGO);
  296. MODULE_PARM_DESC(myri10ge_force_firmware,
  297. "Force firmware to assume aligned completions");
  298. static int myri10ge_initial_mtu = MYRI10GE_MAX_ETHER_MTU - ETH_HLEN;
  299. module_param(myri10ge_initial_mtu, int, S_IRUGO);
  300. MODULE_PARM_DESC(myri10ge_initial_mtu, "Initial MTU");
  301. static int myri10ge_napi_weight = 64;
  302. module_param(myri10ge_napi_weight, int, S_IRUGO);
  303. MODULE_PARM_DESC(myri10ge_napi_weight, "Set NAPI weight");
  304. static int myri10ge_watchdog_timeout = 1;
  305. module_param(myri10ge_watchdog_timeout, int, S_IRUGO);
  306. MODULE_PARM_DESC(myri10ge_watchdog_timeout, "Set watchdog timeout");
  307. static int myri10ge_max_irq_loops = 1048576;
  308. module_param(myri10ge_max_irq_loops, int, S_IRUGO);
  309. MODULE_PARM_DESC(myri10ge_max_irq_loops,
  310. "Set stuck legacy IRQ detection threshold");
  311. #define MYRI10GE_MSG_DEFAULT NETIF_MSG_LINK
  312. static int myri10ge_debug = -1; /* defaults above */
  313. module_param(myri10ge_debug, int, 0);
  314. MODULE_PARM_DESC(myri10ge_debug, "Debug level (0=none,...,16=all)");
  315. static int myri10ge_fill_thresh = 256;
  316. module_param(myri10ge_fill_thresh, int, S_IRUGO | S_IWUSR);
  317. MODULE_PARM_DESC(myri10ge_fill_thresh, "Number of empty rx slots allowed");
  318. static int myri10ge_reset_recover = 1;
  319. static int myri10ge_max_slices = 1;
  320. module_param(myri10ge_max_slices, int, S_IRUGO);
  321. MODULE_PARM_DESC(myri10ge_max_slices, "Max tx/rx queues");
  322. static int myri10ge_rss_hash = MXGEFW_RSS_HASH_TYPE_SRC_DST_PORT;
  323. module_param(myri10ge_rss_hash, int, S_IRUGO);
  324. MODULE_PARM_DESC(myri10ge_rss_hash, "Type of RSS hashing to do");
  325. static int myri10ge_dca = 1;
  326. module_param(myri10ge_dca, int, S_IRUGO);
  327. MODULE_PARM_DESC(myri10ge_dca, "Enable DCA if possible");
  328. #define MYRI10GE_FW_OFFSET 1024*1024
  329. #define MYRI10GE_HIGHPART_TO_U32(X) \
  330. (sizeof (X) == 8) ? ((u32)((u64)(X) >> 32)) : (0)
  331. #define MYRI10GE_LOWPART_TO_U32(X) ((u32)(X))
  332. #define myri10ge_pio_copy(to,from,size) __iowrite64_copy(to,from,size/8)
  333. static void myri10ge_set_multicast_list(struct net_device *dev);
  334. static netdev_tx_t myri10ge_sw_tso(struct sk_buff *skb,
  335. struct net_device *dev);
  336. static inline void put_be32(__be32 val, __be32 __iomem * p)
  337. {
  338. __raw_writel((__force __u32) val, (__force void __iomem *)p);
  339. }
  340. static struct rtnl_link_stats64 *myri10ge_get_stats(struct net_device *dev,
  341. struct rtnl_link_stats64 *stats);
  342. static void set_fw_name(struct myri10ge_priv *mgp, char *name, bool allocated)
  343. {
  344. if (mgp->fw_name_allocated)
  345. kfree(mgp->fw_name);
  346. mgp->fw_name = name;
  347. mgp->fw_name_allocated = allocated;
  348. }
  349. static int
  350. myri10ge_send_cmd(struct myri10ge_priv *mgp, u32 cmd,
  351. struct myri10ge_cmd *data, int atomic)
  352. {
  353. struct mcp_cmd *buf;
  354. char buf_bytes[sizeof(*buf) + 8];
  355. struct mcp_cmd_response *response = mgp->cmd;
  356. char __iomem *cmd_addr = mgp->sram + MXGEFW_ETH_CMD;
  357. u32 dma_low, dma_high, result, value;
  358. int sleep_total = 0;
  359. /* ensure buf is aligned to 8 bytes */
  360. buf = (struct mcp_cmd *)ALIGN((unsigned long)buf_bytes, 8);
  361. buf->data0 = htonl(data->data0);
  362. buf->data1 = htonl(data->data1);
  363. buf->data2 = htonl(data->data2);
  364. buf->cmd = htonl(cmd);
  365. dma_low = MYRI10GE_LOWPART_TO_U32(mgp->cmd_bus);
  366. dma_high = MYRI10GE_HIGHPART_TO_U32(mgp->cmd_bus);
  367. buf->response_addr.low = htonl(dma_low);
  368. buf->response_addr.high = htonl(dma_high);
  369. response->result = htonl(MYRI10GE_NO_RESPONSE_RESULT);
  370. mb();
  371. myri10ge_pio_copy(cmd_addr, buf, sizeof(*buf));
  372. /* wait up to 15ms. Longest command is the DMA benchmark,
  373. * which is capped at 5ms, but runs from a timeout handler
  374. * that runs every 7.8ms. So a 15ms timeout leaves us with
  375. * a 2.2ms margin
  376. */
  377. if (atomic) {
  378. /* if atomic is set, do not sleep,
  379. * and try to get the completion quickly
  380. * (1ms will be enough for those commands) */
  381. for (sleep_total = 0;
  382. sleep_total < 1000 &&
  383. response->result == htonl(MYRI10GE_NO_RESPONSE_RESULT);
  384. sleep_total += 10) {
  385. udelay(10);
  386. mb();
  387. }
  388. } else {
  389. /* use msleep for most command */
  390. for (sleep_total = 0;
  391. sleep_total < 15 &&
  392. response->result == htonl(MYRI10GE_NO_RESPONSE_RESULT);
  393. sleep_total++)
  394. msleep(1);
  395. }
  396. result = ntohl(response->result);
  397. value = ntohl(response->data);
  398. if (result != MYRI10GE_NO_RESPONSE_RESULT) {
  399. if (result == 0) {
  400. data->data0 = value;
  401. return 0;
  402. } else if (result == MXGEFW_CMD_UNKNOWN) {
  403. return -ENOSYS;
  404. } else if (result == MXGEFW_CMD_ERROR_UNALIGNED) {
  405. return -E2BIG;
  406. } else if (result == MXGEFW_CMD_ERROR_RANGE &&
  407. cmd == MXGEFW_CMD_ENABLE_RSS_QUEUES &&
  408. (data->
  409. data1 & MXGEFW_SLICE_ENABLE_MULTIPLE_TX_QUEUES) !=
  410. 0) {
  411. return -ERANGE;
  412. } else {
  413. dev_err(&mgp->pdev->dev,
  414. "command %d failed, result = %d\n",
  415. cmd, result);
  416. return -ENXIO;
  417. }
  418. }
  419. dev_err(&mgp->pdev->dev, "command %d timed out, result = %d\n",
  420. cmd, result);
  421. return -EAGAIN;
  422. }
  423. /*
  424. * The eeprom strings on the lanaiX have the format
  425. * SN=x\0
  426. * MAC=x:x:x:x:x:x\0
  427. * PT:ddd mmm xx xx:xx:xx xx\0
  428. * PV:ddd mmm xx xx:xx:xx xx\0
  429. */
  430. static int myri10ge_read_mac_addr(struct myri10ge_priv *mgp)
  431. {
  432. char *ptr, *limit;
  433. int i;
  434. ptr = mgp->eeprom_strings;
  435. limit = mgp->eeprom_strings + MYRI10GE_EEPROM_STRINGS_SIZE;
  436. while (*ptr != '\0' && ptr < limit) {
  437. if (memcmp(ptr, "MAC=", 4) == 0) {
  438. ptr += 4;
  439. mgp->mac_addr_string = ptr;
  440. for (i = 0; i < 6; i++) {
  441. if ((ptr + 2) > limit)
  442. goto abort;
  443. mgp->mac_addr[i] =
  444. simple_strtoul(ptr, &ptr, 16);
  445. ptr += 1;
  446. }
  447. }
  448. if (memcmp(ptr, "PC=", 3) == 0) {
  449. ptr += 3;
  450. mgp->product_code_string = ptr;
  451. }
  452. if (memcmp((const void *)ptr, "SN=", 3) == 0) {
  453. ptr += 3;
  454. mgp->serial_number = simple_strtoul(ptr, &ptr, 10);
  455. }
  456. while (ptr < limit && *ptr++) ;
  457. }
  458. return 0;
  459. abort:
  460. dev_err(&mgp->pdev->dev, "failed to parse eeprom_strings\n");
  461. return -ENXIO;
  462. }
  463. /*
  464. * Enable or disable periodic RDMAs from the host to make certain
  465. * chipsets resend dropped PCIe messages
  466. */
  467. static void myri10ge_dummy_rdma(struct myri10ge_priv *mgp, int enable)
  468. {
  469. char __iomem *submit;
  470. __be32 buf[16] __attribute__ ((__aligned__(8)));
  471. u32 dma_low, dma_high;
  472. int i;
  473. /* clear confirmation addr */
  474. mgp->cmd->data = 0;
  475. mb();
  476. /* send a rdma command to the PCIe engine, and wait for the
  477. * response in the confirmation address. The firmware should
  478. * write a -1 there to indicate it is alive and well
  479. */
  480. dma_low = MYRI10GE_LOWPART_TO_U32(mgp->cmd_bus);
  481. dma_high = MYRI10GE_HIGHPART_TO_U32(mgp->cmd_bus);
  482. buf[0] = htonl(dma_high); /* confirm addr MSW */
  483. buf[1] = htonl(dma_low); /* confirm addr LSW */
  484. buf[2] = MYRI10GE_NO_CONFIRM_DATA; /* confirm data */
  485. buf[3] = htonl(dma_high); /* dummy addr MSW */
  486. buf[4] = htonl(dma_low); /* dummy addr LSW */
  487. buf[5] = htonl(enable); /* enable? */
  488. submit = mgp->sram + MXGEFW_BOOT_DUMMY_RDMA;
  489. myri10ge_pio_copy(submit, &buf, sizeof(buf));
  490. for (i = 0; mgp->cmd->data != MYRI10GE_NO_CONFIRM_DATA && i < 20; i++)
  491. msleep(1);
  492. if (mgp->cmd->data != MYRI10GE_NO_CONFIRM_DATA)
  493. dev_err(&mgp->pdev->dev, "dummy rdma %s failed\n",
  494. (enable ? "enable" : "disable"));
  495. }
  496. static int
  497. myri10ge_validate_firmware(struct myri10ge_priv *mgp,
  498. struct mcp_gen_header *hdr)
  499. {
  500. struct device *dev = &mgp->pdev->dev;
  501. /* check firmware type */
  502. if (ntohl(hdr->mcp_type) != MCP_TYPE_ETH) {
  503. dev_err(dev, "Bad firmware type: 0x%x\n", ntohl(hdr->mcp_type));
  504. return -EINVAL;
  505. }
  506. /* save firmware version for ethtool */
  507. strncpy(mgp->fw_version, hdr->version, sizeof(mgp->fw_version));
  508. sscanf(mgp->fw_version, "%d.%d.%d", &mgp->fw_ver_major,
  509. &mgp->fw_ver_minor, &mgp->fw_ver_tiny);
  510. if (!(mgp->fw_ver_major == MXGEFW_VERSION_MAJOR &&
  511. mgp->fw_ver_minor == MXGEFW_VERSION_MINOR)) {
  512. dev_err(dev, "Found firmware version %s\n", mgp->fw_version);
  513. dev_err(dev, "Driver needs %d.%d\n", MXGEFW_VERSION_MAJOR,
  514. MXGEFW_VERSION_MINOR);
  515. return -EINVAL;
  516. }
  517. return 0;
  518. }
  519. static int myri10ge_load_hotplug_firmware(struct myri10ge_priv *mgp, u32 * size)
  520. {
  521. unsigned crc, reread_crc;
  522. const struct firmware *fw;
  523. struct device *dev = &mgp->pdev->dev;
  524. unsigned char *fw_readback;
  525. struct mcp_gen_header *hdr;
  526. size_t hdr_offset;
  527. int status;
  528. unsigned i;
  529. if ((status = request_firmware(&fw, mgp->fw_name, dev)) < 0) {
  530. dev_err(dev, "Unable to load %s firmware image via hotplug\n",
  531. mgp->fw_name);
  532. status = -EINVAL;
  533. goto abort_with_nothing;
  534. }
  535. /* check size */
  536. if (fw->size >= mgp->sram_size - MYRI10GE_FW_OFFSET ||
  537. fw->size < MCP_HEADER_PTR_OFFSET + 4) {
  538. dev_err(dev, "Firmware size invalid:%d\n", (int)fw->size);
  539. status = -EINVAL;
  540. goto abort_with_fw;
  541. }
  542. /* check id */
  543. hdr_offset = ntohl(*(__be32 *) (fw->data + MCP_HEADER_PTR_OFFSET));
  544. if ((hdr_offset & 3) || hdr_offset + sizeof(*hdr) > fw->size) {
  545. dev_err(dev, "Bad firmware file\n");
  546. status = -EINVAL;
  547. goto abort_with_fw;
  548. }
  549. hdr = (void *)(fw->data + hdr_offset);
  550. status = myri10ge_validate_firmware(mgp, hdr);
  551. if (status != 0)
  552. goto abort_with_fw;
  553. crc = crc32(~0, fw->data, fw->size);
  554. for (i = 0; i < fw->size; i += 256) {
  555. myri10ge_pio_copy(mgp->sram + MYRI10GE_FW_OFFSET + i,
  556. fw->data + i,
  557. min(256U, (unsigned)(fw->size - i)));
  558. mb();
  559. readb(mgp->sram);
  560. }
  561. fw_readback = vmalloc(fw->size);
  562. if (!fw_readback) {
  563. status = -ENOMEM;
  564. goto abort_with_fw;
  565. }
  566. /* corruption checking is good for parity recovery and buggy chipset */
  567. memcpy_fromio(fw_readback, mgp->sram + MYRI10GE_FW_OFFSET, fw->size);
  568. reread_crc = crc32(~0, fw_readback, fw->size);
  569. vfree(fw_readback);
  570. if (crc != reread_crc) {
  571. dev_err(dev, "CRC failed(fw-len=%u), got 0x%x (expect 0x%x)\n",
  572. (unsigned)fw->size, reread_crc, crc);
  573. status = -EIO;
  574. goto abort_with_fw;
  575. }
  576. *size = (u32) fw->size;
  577. abort_with_fw:
  578. release_firmware(fw);
  579. abort_with_nothing:
  580. return status;
  581. }
  582. static int myri10ge_adopt_running_firmware(struct myri10ge_priv *mgp)
  583. {
  584. struct mcp_gen_header *hdr;
  585. struct device *dev = &mgp->pdev->dev;
  586. const size_t bytes = sizeof(struct mcp_gen_header);
  587. size_t hdr_offset;
  588. int status;
  589. /* find running firmware header */
  590. hdr_offset = swab32(readl(mgp->sram + MCP_HEADER_PTR_OFFSET));
  591. if ((hdr_offset & 3) || hdr_offset + sizeof(*hdr) > mgp->sram_size) {
  592. dev_err(dev, "Running firmware has bad header offset (%d)\n",
  593. (int)hdr_offset);
  594. return -EIO;
  595. }
  596. /* copy header of running firmware from SRAM to host memory to
  597. * validate firmware */
  598. hdr = kmalloc(bytes, GFP_KERNEL);
  599. if (hdr == NULL)
  600. return -ENOMEM;
  601. memcpy_fromio(hdr, mgp->sram + hdr_offset, bytes);
  602. status = myri10ge_validate_firmware(mgp, hdr);
  603. kfree(hdr);
  604. /* check to see if adopted firmware has bug where adopting
  605. * it will cause broadcasts to be filtered unless the NIC
  606. * is kept in ALLMULTI mode */
  607. if (mgp->fw_ver_major == 1 && mgp->fw_ver_minor == 4 &&
  608. mgp->fw_ver_tiny >= 4 && mgp->fw_ver_tiny <= 11) {
  609. mgp->adopted_rx_filter_bug = 1;
  610. dev_warn(dev, "Adopting fw %d.%d.%d: "
  611. "working around rx filter bug\n",
  612. mgp->fw_ver_major, mgp->fw_ver_minor,
  613. mgp->fw_ver_tiny);
  614. }
  615. return status;
  616. }
  617. static int myri10ge_get_firmware_capabilities(struct myri10ge_priv *mgp)
  618. {
  619. struct myri10ge_cmd cmd;
  620. int status;
  621. /* probe for IPv6 TSO support */
  622. mgp->features = NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_TSO;
  623. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_MAX_TSO6_HDR_SIZE,
  624. &cmd, 0);
  625. if (status == 0) {
  626. mgp->max_tso6 = cmd.data0;
  627. mgp->features |= NETIF_F_TSO6;
  628. }
  629. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_RX_RING_SIZE, &cmd, 0);
  630. if (status != 0) {
  631. dev_err(&mgp->pdev->dev,
  632. "failed MXGEFW_CMD_GET_RX_RING_SIZE\n");
  633. return -ENXIO;
  634. }
  635. mgp->max_intr_slots = 2 * (cmd.data0 / sizeof(struct mcp_dma_addr));
  636. return 0;
  637. }
  638. static int myri10ge_load_firmware(struct myri10ge_priv *mgp, int adopt)
  639. {
  640. char __iomem *submit;
  641. __be32 buf[16] __attribute__ ((__aligned__(8)));
  642. u32 dma_low, dma_high, size;
  643. int status, i;
  644. size = 0;
  645. status = myri10ge_load_hotplug_firmware(mgp, &size);
  646. if (status) {
  647. if (!adopt)
  648. return status;
  649. dev_warn(&mgp->pdev->dev, "hotplug firmware loading failed\n");
  650. /* Do not attempt to adopt firmware if there
  651. * was a bad crc */
  652. if (status == -EIO)
  653. return status;
  654. status = myri10ge_adopt_running_firmware(mgp);
  655. if (status != 0) {
  656. dev_err(&mgp->pdev->dev,
  657. "failed to adopt running firmware\n");
  658. return status;
  659. }
  660. dev_info(&mgp->pdev->dev,
  661. "Successfully adopted running firmware\n");
  662. if (mgp->tx_boundary == 4096) {
  663. dev_warn(&mgp->pdev->dev,
  664. "Using firmware currently running on NIC"
  665. ". For optimal\n");
  666. dev_warn(&mgp->pdev->dev,
  667. "performance consider loading optimized "
  668. "firmware\n");
  669. dev_warn(&mgp->pdev->dev, "via hotplug\n");
  670. }
  671. set_fw_name(mgp, "adopted", false);
  672. mgp->tx_boundary = 2048;
  673. myri10ge_dummy_rdma(mgp, 1);
  674. status = myri10ge_get_firmware_capabilities(mgp);
  675. return status;
  676. }
  677. /* clear confirmation addr */
  678. mgp->cmd->data = 0;
  679. mb();
  680. /* send a reload command to the bootstrap MCP, and wait for the
  681. * response in the confirmation address. The firmware should
  682. * write a -1 there to indicate it is alive and well
  683. */
  684. dma_low = MYRI10GE_LOWPART_TO_U32(mgp->cmd_bus);
  685. dma_high = MYRI10GE_HIGHPART_TO_U32(mgp->cmd_bus);
  686. buf[0] = htonl(dma_high); /* confirm addr MSW */
  687. buf[1] = htonl(dma_low); /* confirm addr LSW */
  688. buf[2] = MYRI10GE_NO_CONFIRM_DATA; /* confirm data */
  689. /* FIX: All newest firmware should un-protect the bottom of
  690. * the sram before handoff. However, the very first interfaces
  691. * do not. Therefore the handoff copy must skip the first 8 bytes
  692. */
  693. buf[3] = htonl(MYRI10GE_FW_OFFSET + 8); /* where the code starts */
  694. buf[4] = htonl(size - 8); /* length of code */
  695. buf[5] = htonl(8); /* where to copy to */
  696. buf[6] = htonl(0); /* where to jump to */
  697. submit = mgp->sram + MXGEFW_BOOT_HANDOFF;
  698. myri10ge_pio_copy(submit, &buf, sizeof(buf));
  699. mb();
  700. msleep(1);
  701. mb();
  702. i = 0;
  703. while (mgp->cmd->data != MYRI10GE_NO_CONFIRM_DATA && i < 9) {
  704. msleep(1 << i);
  705. i++;
  706. }
  707. if (mgp->cmd->data != MYRI10GE_NO_CONFIRM_DATA) {
  708. dev_err(&mgp->pdev->dev, "handoff failed\n");
  709. return -ENXIO;
  710. }
  711. myri10ge_dummy_rdma(mgp, 1);
  712. status = myri10ge_get_firmware_capabilities(mgp);
  713. return status;
  714. }
  715. static int myri10ge_update_mac_address(struct myri10ge_priv *mgp, u8 * addr)
  716. {
  717. struct myri10ge_cmd cmd;
  718. int status;
  719. cmd.data0 = ((addr[0] << 24) | (addr[1] << 16)
  720. | (addr[2] << 8) | addr[3]);
  721. cmd.data1 = ((addr[4] << 8) | (addr[5]));
  722. status = myri10ge_send_cmd(mgp, MXGEFW_SET_MAC_ADDRESS, &cmd, 0);
  723. return status;
  724. }
  725. static int myri10ge_change_pause(struct myri10ge_priv *mgp, int pause)
  726. {
  727. struct myri10ge_cmd cmd;
  728. int status, ctl;
  729. ctl = pause ? MXGEFW_ENABLE_FLOW_CONTROL : MXGEFW_DISABLE_FLOW_CONTROL;
  730. status = myri10ge_send_cmd(mgp, ctl, &cmd, 0);
  731. if (status) {
  732. netdev_err(mgp->dev, "Failed to set flow control mode\n");
  733. return status;
  734. }
  735. mgp->pause = pause;
  736. return 0;
  737. }
  738. static void
  739. myri10ge_change_promisc(struct myri10ge_priv *mgp, int promisc, int atomic)
  740. {
  741. struct myri10ge_cmd cmd;
  742. int status, ctl;
  743. ctl = promisc ? MXGEFW_ENABLE_PROMISC : MXGEFW_DISABLE_PROMISC;
  744. status = myri10ge_send_cmd(mgp, ctl, &cmd, atomic);
  745. if (status)
  746. netdev_err(mgp->dev, "Failed to set promisc mode\n");
  747. }
  748. static int myri10ge_dma_test(struct myri10ge_priv *mgp, int test_type)
  749. {
  750. struct myri10ge_cmd cmd;
  751. int status;
  752. u32 len;
  753. struct page *dmatest_page;
  754. dma_addr_t dmatest_bus;
  755. char *test = " ";
  756. dmatest_page = alloc_page(GFP_KERNEL);
  757. if (!dmatest_page)
  758. return -ENOMEM;
  759. dmatest_bus = pci_map_page(mgp->pdev, dmatest_page, 0, PAGE_SIZE,
  760. DMA_BIDIRECTIONAL);
  761. /* Run a small DMA test.
  762. * The magic multipliers to the length tell the firmware
  763. * to do DMA read, write, or read+write tests. The
  764. * results are returned in cmd.data0. The upper 16
  765. * bits or the return is the number of transfers completed.
  766. * The lower 16 bits is the time in 0.5us ticks that the
  767. * transfers took to complete.
  768. */
  769. len = mgp->tx_boundary;
  770. cmd.data0 = MYRI10GE_LOWPART_TO_U32(dmatest_bus);
  771. cmd.data1 = MYRI10GE_HIGHPART_TO_U32(dmatest_bus);
  772. cmd.data2 = len * 0x10000;
  773. status = myri10ge_send_cmd(mgp, test_type, &cmd, 0);
  774. if (status != 0) {
  775. test = "read";
  776. goto abort;
  777. }
  778. mgp->read_dma = ((cmd.data0 >> 16) * len * 2) / (cmd.data0 & 0xffff);
  779. cmd.data0 = MYRI10GE_LOWPART_TO_U32(dmatest_bus);
  780. cmd.data1 = MYRI10GE_HIGHPART_TO_U32(dmatest_bus);
  781. cmd.data2 = len * 0x1;
  782. status = myri10ge_send_cmd(mgp, test_type, &cmd, 0);
  783. if (status != 0) {
  784. test = "write";
  785. goto abort;
  786. }
  787. mgp->write_dma = ((cmd.data0 >> 16) * len * 2) / (cmd.data0 & 0xffff);
  788. cmd.data0 = MYRI10GE_LOWPART_TO_U32(dmatest_bus);
  789. cmd.data1 = MYRI10GE_HIGHPART_TO_U32(dmatest_bus);
  790. cmd.data2 = len * 0x10001;
  791. status = myri10ge_send_cmd(mgp, test_type, &cmd, 0);
  792. if (status != 0) {
  793. test = "read/write";
  794. goto abort;
  795. }
  796. mgp->read_write_dma = ((cmd.data0 >> 16) * len * 2 * 2) /
  797. (cmd.data0 & 0xffff);
  798. abort:
  799. pci_unmap_page(mgp->pdev, dmatest_bus, PAGE_SIZE, DMA_BIDIRECTIONAL);
  800. put_page(dmatest_page);
  801. if (status != 0 && test_type != MXGEFW_CMD_UNALIGNED_TEST)
  802. dev_warn(&mgp->pdev->dev, "DMA %s benchmark failed: %d\n",
  803. test, status);
  804. return status;
  805. }
  806. #ifdef CONFIG_NET_RX_BUSY_POLL
  807. static inline void myri10ge_ss_init_lock(struct myri10ge_slice_state *ss)
  808. {
  809. spin_lock_init(&ss->lock);
  810. ss->state = SLICE_STATE_IDLE;
  811. }
  812. static inline bool myri10ge_ss_lock_napi(struct myri10ge_slice_state *ss)
  813. {
  814. int rc = true;
  815. spin_lock(&ss->lock);
  816. if ((ss->state & SLICE_LOCKED)) {
  817. WARN_ON((ss->state & SLICE_STATE_NAPI));
  818. ss->state |= SLICE_STATE_NAPI_YIELD;
  819. rc = false;
  820. ss->lock_napi_yield++;
  821. } else
  822. ss->state = SLICE_STATE_NAPI;
  823. spin_unlock(&ss->lock);
  824. return rc;
  825. }
  826. static inline void myri10ge_ss_unlock_napi(struct myri10ge_slice_state *ss)
  827. {
  828. spin_lock(&ss->lock);
  829. WARN_ON((ss->state & (SLICE_STATE_POLL | SLICE_STATE_NAPI_YIELD)));
  830. ss->state = SLICE_STATE_IDLE;
  831. spin_unlock(&ss->lock);
  832. }
  833. static inline bool myri10ge_ss_lock_poll(struct myri10ge_slice_state *ss)
  834. {
  835. int rc = true;
  836. spin_lock_bh(&ss->lock);
  837. if ((ss->state & SLICE_LOCKED)) {
  838. ss->state |= SLICE_STATE_POLL_YIELD;
  839. rc = false;
  840. ss->lock_poll_yield++;
  841. } else
  842. ss->state |= SLICE_STATE_POLL;
  843. spin_unlock_bh(&ss->lock);
  844. return rc;
  845. }
  846. static inline void myri10ge_ss_unlock_poll(struct myri10ge_slice_state *ss)
  847. {
  848. spin_lock_bh(&ss->lock);
  849. WARN_ON((ss->state & SLICE_STATE_NAPI));
  850. ss->state = SLICE_STATE_IDLE;
  851. spin_unlock_bh(&ss->lock);
  852. }
  853. static inline bool myri10ge_ss_busy_polling(struct myri10ge_slice_state *ss)
  854. {
  855. WARN_ON(!(ss->state & SLICE_LOCKED));
  856. return (ss->state & SLICE_USER_PEND);
  857. }
  858. #else /* CONFIG_NET_RX_BUSY_POLL */
  859. static inline void myri10ge_ss_init_lock(struct myri10ge_slice_state *ss)
  860. {
  861. }
  862. static inline bool myri10ge_ss_lock_napi(struct myri10ge_slice_state *ss)
  863. {
  864. return false;
  865. }
  866. static inline void myri10ge_ss_unlock_napi(struct myri10ge_slice_state *ss)
  867. {
  868. }
  869. static inline bool myri10ge_ss_lock_poll(struct myri10ge_slice_state *ss)
  870. {
  871. return false;
  872. }
  873. static inline void myri10ge_ss_unlock_poll(struct myri10ge_slice_state *ss)
  874. {
  875. }
  876. static inline bool myri10ge_ss_busy_polling(struct myri10ge_slice_state *ss)
  877. {
  878. return false;
  879. }
  880. #endif
  881. static int myri10ge_reset(struct myri10ge_priv *mgp)
  882. {
  883. struct myri10ge_cmd cmd;
  884. struct myri10ge_slice_state *ss;
  885. int i, status;
  886. size_t bytes;
  887. #ifdef CONFIG_MYRI10GE_DCA
  888. unsigned long dca_tag_off;
  889. #endif
  890. /* try to send a reset command to the card to see if it
  891. * is alive */
  892. memset(&cmd, 0, sizeof(cmd));
  893. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_RESET, &cmd, 0);
  894. if (status != 0) {
  895. dev_err(&mgp->pdev->dev, "failed reset\n");
  896. return -ENXIO;
  897. }
  898. (void)myri10ge_dma_test(mgp, MXGEFW_DMA_TEST);
  899. /*
  900. * Use non-ndis mcp_slot (eg, 4 bytes total,
  901. * no toeplitz hash value returned. Older firmware will
  902. * not understand this command, but will use the correct
  903. * sized mcp_slot, so we ignore error returns
  904. */
  905. cmd.data0 = MXGEFW_RSS_MCP_SLOT_TYPE_MIN;
  906. (void)myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_RSS_MCP_SLOT_TYPE, &cmd, 0);
  907. /* Now exchange information about interrupts */
  908. bytes = mgp->max_intr_slots * sizeof(*mgp->ss[0].rx_done.entry);
  909. cmd.data0 = (u32) bytes;
  910. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_INTRQ_SIZE, &cmd, 0);
  911. /*
  912. * Even though we already know how many slices are supported
  913. * via myri10ge_probe_slices() MXGEFW_CMD_GET_MAX_RSS_QUEUES
  914. * has magic side effects, and must be called after a reset.
  915. * It must be called prior to calling any RSS related cmds,
  916. * including assigning an interrupt queue for anything but
  917. * slice 0. It must also be called *after*
  918. * MXGEFW_CMD_SET_INTRQ_SIZE, since the intrq size is used by
  919. * the firmware to compute offsets.
  920. */
  921. if (mgp->num_slices > 1) {
  922. /* ask the maximum number of slices it supports */
  923. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_MAX_RSS_QUEUES,
  924. &cmd, 0);
  925. if (status != 0) {
  926. dev_err(&mgp->pdev->dev,
  927. "failed to get number of slices\n");
  928. }
  929. /*
  930. * MXGEFW_CMD_ENABLE_RSS_QUEUES must be called prior
  931. * to setting up the interrupt queue DMA
  932. */
  933. cmd.data0 = mgp->num_slices;
  934. cmd.data1 = MXGEFW_SLICE_INTR_MODE_ONE_PER_SLICE;
  935. if (mgp->dev->real_num_tx_queues > 1)
  936. cmd.data1 |= MXGEFW_SLICE_ENABLE_MULTIPLE_TX_QUEUES;
  937. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_ENABLE_RSS_QUEUES,
  938. &cmd, 0);
  939. /* Firmware older than 1.4.32 only supports multiple
  940. * RX queues, so if we get an error, first retry using a
  941. * single TX queue before giving up */
  942. if (status != 0 && mgp->dev->real_num_tx_queues > 1) {
  943. netif_set_real_num_tx_queues(mgp->dev, 1);
  944. cmd.data0 = mgp->num_slices;
  945. cmd.data1 = MXGEFW_SLICE_INTR_MODE_ONE_PER_SLICE;
  946. status = myri10ge_send_cmd(mgp,
  947. MXGEFW_CMD_ENABLE_RSS_QUEUES,
  948. &cmd, 0);
  949. }
  950. if (status != 0) {
  951. dev_err(&mgp->pdev->dev,
  952. "failed to set number of slices\n");
  953. return status;
  954. }
  955. }
  956. for (i = 0; i < mgp->num_slices; i++) {
  957. ss = &mgp->ss[i];
  958. cmd.data0 = MYRI10GE_LOWPART_TO_U32(ss->rx_done.bus);
  959. cmd.data1 = MYRI10GE_HIGHPART_TO_U32(ss->rx_done.bus);
  960. cmd.data2 = i;
  961. status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_INTRQ_DMA,
  962. &cmd, 0);
  963. }
  964. status |=
  965. myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_IRQ_ACK_OFFSET, &cmd, 0);
  966. for (i = 0; i < mgp->num_slices; i++) {
  967. ss = &mgp->ss[i];
  968. ss->irq_claim =
  969. (__iomem __be32 *) (mgp->sram + cmd.data0 + 8 * i);
  970. }
  971. status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_IRQ_DEASSERT_OFFSET,
  972. &cmd, 0);
  973. mgp->irq_deassert = (__iomem __be32 *) (mgp->sram + cmd.data0);
  974. status |= myri10ge_send_cmd
  975. (mgp, MXGEFW_CMD_GET_INTR_COAL_DELAY_OFFSET, &cmd, 0);
  976. mgp->intr_coal_delay_ptr = (__iomem __be32 *) (mgp->sram + cmd.data0);
  977. if (status != 0) {
  978. dev_err(&mgp->pdev->dev, "failed set interrupt parameters\n");
  979. return status;
  980. }
  981. put_be32(htonl(mgp->intr_coal_delay), mgp->intr_coal_delay_ptr);
  982. #ifdef CONFIG_MYRI10GE_DCA
  983. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_DCA_OFFSET, &cmd, 0);
  984. dca_tag_off = cmd.data0;
  985. for (i = 0; i < mgp->num_slices; i++) {
  986. ss = &mgp->ss[i];
  987. if (status == 0) {
  988. ss->dca_tag = (__iomem __be32 *)
  989. (mgp->sram + dca_tag_off + 4 * i);
  990. } else {
  991. ss->dca_tag = NULL;
  992. }
  993. }
  994. #endif /* CONFIG_MYRI10GE_DCA */
  995. /* reset mcp/driver shared state back to 0 */
  996. mgp->link_changes = 0;
  997. for (i = 0; i < mgp->num_slices; i++) {
  998. ss = &mgp->ss[i];
  999. memset(ss->rx_done.entry, 0, bytes);
  1000. ss->tx.req = 0;
  1001. ss->tx.done = 0;
  1002. ss->tx.pkt_start = 0;
  1003. ss->tx.pkt_done = 0;
  1004. ss->rx_big.cnt = 0;
  1005. ss->rx_small.cnt = 0;
  1006. ss->rx_done.idx = 0;
  1007. ss->rx_done.cnt = 0;
  1008. ss->tx.wake_queue = 0;
  1009. ss->tx.stop_queue = 0;
  1010. }
  1011. status = myri10ge_update_mac_address(mgp, mgp->dev->dev_addr);
  1012. myri10ge_change_pause(mgp, mgp->pause);
  1013. myri10ge_set_multicast_list(mgp->dev);
  1014. return status;
  1015. }
  1016. #ifdef CONFIG_MYRI10GE_DCA
  1017. static int myri10ge_toggle_relaxed(struct pci_dev *pdev, int on)
  1018. {
  1019. int ret;
  1020. u16 ctl;
  1021. pcie_capability_read_word(pdev, PCI_EXP_DEVCTL, &ctl);
  1022. ret = (ctl & PCI_EXP_DEVCTL_RELAX_EN) >> 4;
  1023. if (ret != on) {
  1024. ctl &= ~PCI_EXP_DEVCTL_RELAX_EN;
  1025. ctl |= (on << 4);
  1026. pcie_capability_write_word(pdev, PCI_EXP_DEVCTL, ctl);
  1027. }
  1028. return ret;
  1029. }
  1030. static void
  1031. myri10ge_write_dca(struct myri10ge_slice_state *ss, int cpu, int tag)
  1032. {
  1033. ss->cached_dca_tag = tag;
  1034. put_be32(htonl(tag), ss->dca_tag);
  1035. }
  1036. static inline void myri10ge_update_dca(struct myri10ge_slice_state *ss)
  1037. {
  1038. int cpu = get_cpu();
  1039. int tag;
  1040. if (cpu != ss->cpu) {
  1041. tag = dca3_get_tag(&ss->mgp->pdev->dev, cpu);
  1042. if (ss->cached_dca_tag != tag)
  1043. myri10ge_write_dca(ss, cpu, tag);
  1044. ss->cpu = cpu;
  1045. }
  1046. put_cpu();
  1047. }
  1048. static void myri10ge_setup_dca(struct myri10ge_priv *mgp)
  1049. {
  1050. int err, i;
  1051. struct pci_dev *pdev = mgp->pdev;
  1052. if (mgp->ss[0].dca_tag == NULL || mgp->dca_enabled)
  1053. return;
  1054. if (!myri10ge_dca) {
  1055. dev_err(&pdev->dev, "dca disabled by administrator\n");
  1056. return;
  1057. }
  1058. err = dca_add_requester(&pdev->dev);
  1059. if (err) {
  1060. if (err != -ENODEV)
  1061. dev_err(&pdev->dev,
  1062. "dca_add_requester() failed, err=%d\n", err);
  1063. return;
  1064. }
  1065. mgp->relaxed_order = myri10ge_toggle_relaxed(pdev, 0);
  1066. mgp->dca_enabled = 1;
  1067. for (i = 0; i < mgp->num_slices; i++) {
  1068. mgp->ss[i].cpu = -1;
  1069. mgp->ss[i].cached_dca_tag = -1;
  1070. myri10ge_update_dca(&mgp->ss[i]);
  1071. }
  1072. }
  1073. static void myri10ge_teardown_dca(struct myri10ge_priv *mgp)
  1074. {
  1075. struct pci_dev *pdev = mgp->pdev;
  1076. if (!mgp->dca_enabled)
  1077. return;
  1078. mgp->dca_enabled = 0;
  1079. if (mgp->relaxed_order)
  1080. myri10ge_toggle_relaxed(pdev, 1);
  1081. dca_remove_requester(&pdev->dev);
  1082. }
  1083. static int myri10ge_notify_dca_device(struct device *dev, void *data)
  1084. {
  1085. struct myri10ge_priv *mgp;
  1086. unsigned long event;
  1087. mgp = dev_get_drvdata(dev);
  1088. event = *(unsigned long *)data;
  1089. if (event == DCA_PROVIDER_ADD)
  1090. myri10ge_setup_dca(mgp);
  1091. else if (event == DCA_PROVIDER_REMOVE)
  1092. myri10ge_teardown_dca(mgp);
  1093. return 0;
  1094. }
  1095. #endif /* CONFIG_MYRI10GE_DCA */
  1096. static inline void
  1097. myri10ge_submit_8rx(struct mcp_kreq_ether_recv __iomem * dst,
  1098. struct mcp_kreq_ether_recv *src)
  1099. {
  1100. __be32 low;
  1101. low = src->addr_low;
  1102. src->addr_low = htonl(DMA_BIT_MASK(32));
  1103. myri10ge_pio_copy(dst, src, 4 * sizeof(*src));
  1104. mb();
  1105. myri10ge_pio_copy(dst + 4, src + 4, 4 * sizeof(*src));
  1106. mb();
  1107. src->addr_low = low;
  1108. put_be32(low, &dst->addr_low);
  1109. mb();
  1110. }
  1111. static inline void myri10ge_vlan_ip_csum(struct sk_buff *skb, __wsum hw_csum)
  1112. {
  1113. struct vlan_hdr *vh = (struct vlan_hdr *)(skb->data);
  1114. if ((skb->protocol == htons(ETH_P_8021Q)) &&
  1115. (vh->h_vlan_encapsulated_proto == htons(ETH_P_IP) ||
  1116. vh->h_vlan_encapsulated_proto == htons(ETH_P_IPV6))) {
  1117. skb->csum = hw_csum;
  1118. skb->ip_summed = CHECKSUM_COMPLETE;
  1119. }
  1120. }
  1121. static void
  1122. myri10ge_alloc_rx_pages(struct myri10ge_priv *mgp, struct myri10ge_rx_buf *rx,
  1123. int bytes, int watchdog)
  1124. {
  1125. struct page *page;
  1126. int idx;
  1127. #if MYRI10GE_ALLOC_SIZE > 4096
  1128. int end_offset;
  1129. #endif
  1130. if (unlikely(rx->watchdog_needed && !watchdog))
  1131. return;
  1132. /* try to refill entire ring */
  1133. while (rx->fill_cnt != (rx->cnt + rx->mask + 1)) {
  1134. idx = rx->fill_cnt & rx->mask;
  1135. if (rx->page_offset + bytes <= MYRI10GE_ALLOC_SIZE) {
  1136. /* we can use part of previous page */
  1137. get_page(rx->page);
  1138. } else {
  1139. /* we need a new page */
  1140. page =
  1141. alloc_pages(GFP_ATOMIC | __GFP_COMP,
  1142. MYRI10GE_ALLOC_ORDER);
  1143. if (unlikely(page == NULL)) {
  1144. if (rx->fill_cnt - rx->cnt < 16)
  1145. rx->watchdog_needed = 1;
  1146. return;
  1147. }
  1148. rx->page = page;
  1149. rx->page_offset = 0;
  1150. rx->bus = pci_map_page(mgp->pdev, page, 0,
  1151. MYRI10GE_ALLOC_SIZE,
  1152. PCI_DMA_FROMDEVICE);
  1153. }
  1154. rx->info[idx].page = rx->page;
  1155. rx->info[idx].page_offset = rx->page_offset;
  1156. /* note that this is the address of the start of the
  1157. * page */
  1158. dma_unmap_addr_set(&rx->info[idx], bus, rx->bus);
  1159. rx->shadow[idx].addr_low =
  1160. htonl(MYRI10GE_LOWPART_TO_U32(rx->bus) + rx->page_offset);
  1161. rx->shadow[idx].addr_high =
  1162. htonl(MYRI10GE_HIGHPART_TO_U32(rx->bus));
  1163. /* start next packet on a cacheline boundary */
  1164. rx->page_offset += SKB_DATA_ALIGN(bytes);
  1165. #if MYRI10GE_ALLOC_SIZE > 4096
  1166. /* don't cross a 4KB boundary */
  1167. end_offset = rx->page_offset + bytes - 1;
  1168. if ((unsigned)(rx->page_offset ^ end_offset) > 4095)
  1169. rx->page_offset = end_offset & ~4095;
  1170. #endif
  1171. rx->fill_cnt++;
  1172. /* copy 8 descriptors to the firmware at a time */
  1173. if ((idx & 7) == 7) {
  1174. myri10ge_submit_8rx(&rx->lanai[idx - 7],
  1175. &rx->shadow[idx - 7]);
  1176. }
  1177. }
  1178. }
  1179. static inline void
  1180. myri10ge_unmap_rx_page(struct pci_dev *pdev,
  1181. struct myri10ge_rx_buffer_state *info, int bytes)
  1182. {
  1183. /* unmap the recvd page if we're the only or last user of it */
  1184. if (bytes >= MYRI10GE_ALLOC_SIZE / 2 ||
  1185. (info->page_offset + 2 * bytes) > MYRI10GE_ALLOC_SIZE) {
  1186. pci_unmap_page(pdev, (dma_unmap_addr(info, bus)
  1187. & ~(MYRI10GE_ALLOC_SIZE - 1)),
  1188. MYRI10GE_ALLOC_SIZE, PCI_DMA_FROMDEVICE);
  1189. }
  1190. }
  1191. /*
  1192. * GRO does not support acceleration of tagged vlan frames, and
  1193. * this NIC does not support vlan tag offload, so we must pop
  1194. * the tag ourselves to be able to achieve GRO performance that
  1195. * is comparable to LRO.
  1196. */
  1197. static inline void
  1198. myri10ge_vlan_rx(struct net_device *dev, void *addr, struct sk_buff *skb)
  1199. {
  1200. u8 *va;
  1201. struct vlan_ethhdr *veh;
  1202. struct skb_frag_struct *frag;
  1203. __wsum vsum;
  1204. va = addr;
  1205. va += MXGEFW_PAD;
  1206. veh = (struct vlan_ethhdr *)va;
  1207. if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) ==
  1208. NETIF_F_HW_VLAN_CTAG_RX &&
  1209. veh->h_vlan_proto == htons(ETH_P_8021Q)) {
  1210. /* fixup csum if needed */
  1211. if (skb->ip_summed == CHECKSUM_COMPLETE) {
  1212. vsum = csum_partial(va + ETH_HLEN, VLAN_HLEN, 0);
  1213. skb->csum = csum_sub(skb->csum, vsum);
  1214. }
  1215. /* pop tag */
  1216. __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), ntohs(veh->h_vlan_TCI));
  1217. memmove(va + VLAN_HLEN, va, 2 * ETH_ALEN);
  1218. skb->len -= VLAN_HLEN;
  1219. skb->data_len -= VLAN_HLEN;
  1220. frag = skb_shinfo(skb)->frags;
  1221. frag->page_offset += VLAN_HLEN;
  1222. skb_frag_size_set(frag, skb_frag_size(frag) - VLAN_HLEN);
  1223. }
  1224. }
  1225. #define MYRI10GE_HLEN 64 /* Bytes to copy from page to skb linear memory */
  1226. static inline int
  1227. myri10ge_rx_done(struct myri10ge_slice_state *ss, int len, __wsum csum)
  1228. {
  1229. struct myri10ge_priv *mgp = ss->mgp;
  1230. struct sk_buff *skb;
  1231. struct skb_frag_struct *rx_frags;
  1232. struct myri10ge_rx_buf *rx;
  1233. int i, idx, remainder, bytes;
  1234. struct pci_dev *pdev = mgp->pdev;
  1235. struct net_device *dev = mgp->dev;
  1236. u8 *va;
  1237. bool polling;
  1238. if (len <= mgp->small_bytes) {
  1239. rx = &ss->rx_small;
  1240. bytes = mgp->small_bytes;
  1241. } else {
  1242. rx = &ss->rx_big;
  1243. bytes = mgp->big_bytes;
  1244. }
  1245. len += MXGEFW_PAD;
  1246. idx = rx->cnt & rx->mask;
  1247. va = page_address(rx->info[idx].page) + rx->info[idx].page_offset;
  1248. prefetch(va);
  1249. /* When busy polling in user context, allocate skb and copy headers to
  1250. * skb's linear memory ourselves. When not busy polling, use the napi
  1251. * gro api.
  1252. */
  1253. polling = myri10ge_ss_busy_polling(ss);
  1254. if (polling)
  1255. skb = netdev_alloc_skb(dev, MYRI10GE_HLEN + 16);
  1256. else
  1257. skb = napi_get_frags(&ss->napi);
  1258. if (unlikely(skb == NULL)) {
  1259. ss->stats.rx_dropped++;
  1260. for (i = 0, remainder = len; remainder > 0; i++) {
  1261. myri10ge_unmap_rx_page(pdev, &rx->info[idx], bytes);
  1262. put_page(rx->info[idx].page);
  1263. rx->cnt++;
  1264. idx = rx->cnt & rx->mask;
  1265. remainder -= MYRI10GE_ALLOC_SIZE;
  1266. }
  1267. return 0;
  1268. }
  1269. rx_frags = skb_shinfo(skb)->frags;
  1270. /* Fill skb_frag_struct(s) with data from our receive */
  1271. for (i = 0, remainder = len; remainder > 0; i++) {
  1272. myri10ge_unmap_rx_page(pdev, &rx->info[idx], bytes);
  1273. skb_fill_page_desc(skb, i, rx->info[idx].page,
  1274. rx->info[idx].page_offset,
  1275. remainder < MYRI10GE_ALLOC_SIZE ?
  1276. remainder : MYRI10GE_ALLOC_SIZE);
  1277. rx->cnt++;
  1278. idx = rx->cnt & rx->mask;
  1279. remainder -= MYRI10GE_ALLOC_SIZE;
  1280. }
  1281. /* remove padding */
  1282. rx_frags[0].page_offset += MXGEFW_PAD;
  1283. rx_frags[0].size -= MXGEFW_PAD;
  1284. len -= MXGEFW_PAD;
  1285. skb->len = len;
  1286. skb->data_len = len;
  1287. skb->truesize += len;
  1288. if (dev->features & NETIF_F_RXCSUM) {
  1289. skb->ip_summed = CHECKSUM_COMPLETE;
  1290. skb->csum = csum;
  1291. }
  1292. myri10ge_vlan_rx(mgp->dev, va, skb);
  1293. skb_record_rx_queue(skb, ss - &mgp->ss[0]);
  1294. skb_mark_napi_id(skb, &ss->napi);
  1295. if (polling) {
  1296. int hlen;
  1297. /* myri10ge_vlan_rx might have moved the header, so compute
  1298. * length and address again.
  1299. */
  1300. hlen = MYRI10GE_HLEN > skb->len ? skb->len : MYRI10GE_HLEN;
  1301. va = page_address(skb_frag_page(&rx_frags[0])) +
  1302. rx_frags[0].page_offset;
  1303. /* Copy header into the skb linear memory */
  1304. skb_copy_to_linear_data(skb, va, hlen);
  1305. rx_frags[0].page_offset += hlen;
  1306. rx_frags[0].size -= hlen;
  1307. skb->data_len -= hlen;
  1308. skb->tail += hlen;
  1309. skb->protocol = eth_type_trans(skb, dev);
  1310. netif_receive_skb(skb);
  1311. }
  1312. else
  1313. napi_gro_frags(&ss->napi);
  1314. return 1;
  1315. }
  1316. static inline void
  1317. myri10ge_tx_done(struct myri10ge_slice_state *ss, int mcp_index)
  1318. {
  1319. struct pci_dev *pdev = ss->mgp->pdev;
  1320. struct myri10ge_tx_buf *tx = &ss->tx;
  1321. struct netdev_queue *dev_queue;
  1322. struct sk_buff *skb;
  1323. int idx, len;
  1324. while (tx->pkt_done != mcp_index) {
  1325. idx = tx->done & tx->mask;
  1326. skb = tx->info[idx].skb;
  1327. /* Mark as free */
  1328. tx->info[idx].skb = NULL;
  1329. if (tx->info[idx].last) {
  1330. tx->pkt_done++;
  1331. tx->info[idx].last = 0;
  1332. }
  1333. tx->done++;
  1334. len = dma_unmap_len(&tx->info[idx], len);
  1335. dma_unmap_len_set(&tx->info[idx], len, 0);
  1336. if (skb) {
  1337. ss->stats.tx_bytes += skb->len;
  1338. ss->stats.tx_packets++;
  1339. dev_kfree_skb_irq(skb);
  1340. if (len)
  1341. pci_unmap_single(pdev,
  1342. dma_unmap_addr(&tx->info[idx],
  1343. bus), len,
  1344. PCI_DMA_TODEVICE);
  1345. } else {
  1346. if (len)
  1347. pci_unmap_page(pdev,
  1348. dma_unmap_addr(&tx->info[idx],
  1349. bus), len,
  1350. PCI_DMA_TODEVICE);
  1351. }
  1352. }
  1353. dev_queue = netdev_get_tx_queue(ss->dev, ss - ss->mgp->ss);
  1354. /*
  1355. * Make a minimal effort to prevent the NIC from polling an
  1356. * idle tx queue. If we can't get the lock we leave the queue
  1357. * active. In this case, either a thread was about to start
  1358. * using the queue anyway, or we lost a race and the NIC will
  1359. * waste some of its resources polling an inactive queue for a
  1360. * while.
  1361. */
  1362. if ((ss->mgp->dev->real_num_tx_queues > 1) &&
  1363. __netif_tx_trylock(dev_queue)) {
  1364. if (tx->req == tx->done) {
  1365. tx->queue_active = 0;
  1366. put_be32(htonl(1), tx->send_stop);
  1367. mb();
  1368. mmiowb();
  1369. }
  1370. __netif_tx_unlock(dev_queue);
  1371. }
  1372. /* start the queue if we've stopped it */
  1373. if (netif_tx_queue_stopped(dev_queue) &&
  1374. tx->req - tx->done < (tx->mask >> 1) &&
  1375. ss->mgp->running == MYRI10GE_ETH_RUNNING) {
  1376. tx->wake_queue++;
  1377. netif_tx_wake_queue(dev_queue);
  1378. }
  1379. }
  1380. static inline int
  1381. myri10ge_clean_rx_done(struct myri10ge_slice_state *ss, int budget)
  1382. {
  1383. struct myri10ge_rx_done *rx_done = &ss->rx_done;
  1384. struct myri10ge_priv *mgp = ss->mgp;
  1385. unsigned long rx_bytes = 0;
  1386. unsigned long rx_packets = 0;
  1387. unsigned long rx_ok;
  1388. int idx = rx_done->idx;
  1389. int cnt = rx_done->cnt;
  1390. int work_done = 0;
  1391. u16 length;
  1392. __wsum checksum;
  1393. while (rx_done->entry[idx].length != 0 && work_done < budget) {
  1394. length = ntohs(rx_done->entry[idx].length);
  1395. rx_done->entry[idx].length = 0;
  1396. checksum = csum_unfold(rx_done->entry[idx].checksum);
  1397. rx_ok = myri10ge_rx_done(ss, length, checksum);
  1398. rx_packets += rx_ok;
  1399. rx_bytes += rx_ok * (unsigned long)length;
  1400. cnt++;
  1401. idx = cnt & (mgp->max_intr_slots - 1);
  1402. work_done++;
  1403. }
  1404. rx_done->idx = idx;
  1405. rx_done->cnt = cnt;
  1406. ss->stats.rx_packets += rx_packets;
  1407. ss->stats.rx_bytes += rx_bytes;
  1408. /* restock receive rings if needed */
  1409. if (ss->rx_small.fill_cnt - ss->rx_small.cnt < myri10ge_fill_thresh)
  1410. myri10ge_alloc_rx_pages(mgp, &ss->rx_small,
  1411. mgp->small_bytes + MXGEFW_PAD, 0);
  1412. if (ss->rx_big.fill_cnt - ss->rx_big.cnt < myri10ge_fill_thresh)
  1413. myri10ge_alloc_rx_pages(mgp, &ss->rx_big, mgp->big_bytes, 0);
  1414. return work_done;
  1415. }
  1416. static inline void myri10ge_check_statblock(struct myri10ge_priv *mgp)
  1417. {
  1418. struct mcp_irq_data *stats = mgp->ss[0].fw_stats;
  1419. if (unlikely(stats->stats_updated)) {
  1420. unsigned link_up = ntohl(stats->link_up);
  1421. if (mgp->link_state != link_up) {
  1422. mgp->link_state = link_up;
  1423. if (mgp->link_state == MXGEFW_LINK_UP) {
  1424. netif_info(mgp, link, mgp->dev, "link up\n");
  1425. netif_carrier_on(mgp->dev);
  1426. mgp->link_changes++;
  1427. } else {
  1428. netif_info(mgp, link, mgp->dev, "link %s\n",
  1429. (link_up == MXGEFW_LINK_MYRINET ?
  1430. "mismatch (Myrinet detected)" :
  1431. "down"));
  1432. netif_carrier_off(mgp->dev);
  1433. mgp->link_changes++;
  1434. }
  1435. }
  1436. if (mgp->rdma_tags_available !=
  1437. ntohl(stats->rdma_tags_available)) {
  1438. mgp->rdma_tags_available =
  1439. ntohl(stats->rdma_tags_available);
  1440. netdev_warn(mgp->dev, "RDMA timed out! %d tags left\n",
  1441. mgp->rdma_tags_available);
  1442. }
  1443. mgp->down_cnt += stats->link_down;
  1444. if (stats->link_down)
  1445. wake_up(&mgp->down_wq);
  1446. }
  1447. }
  1448. static int myri10ge_poll(struct napi_struct *napi, int budget)
  1449. {
  1450. struct myri10ge_slice_state *ss =
  1451. container_of(napi, struct myri10ge_slice_state, napi);
  1452. int work_done;
  1453. #ifdef CONFIG_MYRI10GE_DCA
  1454. if (ss->mgp->dca_enabled)
  1455. myri10ge_update_dca(ss);
  1456. #endif
  1457. /* Try later if the busy_poll handler is running. */
  1458. if (!myri10ge_ss_lock_napi(ss))
  1459. return budget;
  1460. /* process as many rx events as NAPI will allow */
  1461. work_done = myri10ge_clean_rx_done(ss, budget);
  1462. myri10ge_ss_unlock_napi(ss);
  1463. if (work_done < budget) {
  1464. napi_complete(napi);
  1465. put_be32(htonl(3), ss->irq_claim);
  1466. }
  1467. return work_done;
  1468. }
  1469. #ifdef CONFIG_NET_RX_BUSY_POLL
  1470. static int myri10ge_busy_poll(struct napi_struct *napi)
  1471. {
  1472. struct myri10ge_slice_state *ss =
  1473. container_of(napi, struct myri10ge_slice_state, napi);
  1474. struct myri10ge_priv *mgp = ss->mgp;
  1475. int work_done;
  1476. /* Poll only when the link is up */
  1477. if (mgp->link_state != MXGEFW_LINK_UP)
  1478. return LL_FLUSH_FAILED;
  1479. if (!myri10ge_ss_lock_poll(ss))
  1480. return LL_FLUSH_BUSY;
  1481. /* Process a small number of packets */
  1482. work_done = myri10ge_clean_rx_done(ss, 4);
  1483. if (work_done)
  1484. ss->busy_poll_cnt += work_done;
  1485. else
  1486. ss->busy_poll_miss++;
  1487. myri10ge_ss_unlock_poll(ss);
  1488. return work_done;
  1489. }
  1490. #endif /* CONFIG_NET_RX_BUSY_POLL */
  1491. static irqreturn_t myri10ge_intr(int irq, void *arg)
  1492. {
  1493. struct myri10ge_slice_state *ss = arg;
  1494. struct myri10ge_priv *mgp = ss->mgp;
  1495. struct mcp_irq_data *stats = ss->fw_stats;
  1496. struct myri10ge_tx_buf *tx = &ss->tx;
  1497. u32 send_done_count;
  1498. int i;
  1499. /* an interrupt on a non-zero receive-only slice is implicitly
  1500. * valid since MSI-X irqs are not shared */
  1501. if ((mgp->dev->real_num_tx_queues == 1) && (ss != mgp->ss)) {
  1502. napi_schedule(&ss->napi);
  1503. return IRQ_HANDLED;
  1504. }
  1505. /* make sure it is our IRQ, and that the DMA has finished */
  1506. if (unlikely(!stats->valid))
  1507. return IRQ_NONE;
  1508. /* low bit indicates receives are present, so schedule
  1509. * napi poll handler */
  1510. if (stats->valid & 1)
  1511. napi_schedule(&ss->napi);
  1512. if (!mgp->msi_enabled && !mgp->msix_enabled) {
  1513. put_be32(0, mgp->irq_deassert);
  1514. if (!myri10ge_deassert_wait)
  1515. stats->valid = 0;
  1516. mb();
  1517. } else
  1518. stats->valid = 0;
  1519. /* Wait for IRQ line to go low, if using INTx */
  1520. i = 0;
  1521. while (1) {
  1522. i++;
  1523. /* check for transmit completes and receives */
  1524. send_done_count = ntohl(stats->send_done_count);
  1525. if (send_done_count != tx->pkt_done)
  1526. myri10ge_tx_done(ss, (int)send_done_count);
  1527. if (unlikely(i > myri10ge_max_irq_loops)) {
  1528. netdev_warn(mgp->dev, "irq stuck?\n");
  1529. stats->valid = 0;
  1530. schedule_work(&mgp->watchdog_work);
  1531. }
  1532. if (likely(stats->valid == 0))
  1533. break;
  1534. cpu_relax();
  1535. barrier();
  1536. }
  1537. /* Only slice 0 updates stats */
  1538. if (ss == mgp->ss)
  1539. myri10ge_check_statblock(mgp);
  1540. put_be32(htonl(3), ss->irq_claim + 1);
  1541. return IRQ_HANDLED;
  1542. }
  1543. static int
  1544. myri10ge_get_settings(struct net_device *netdev, struct ethtool_cmd *cmd)
  1545. {
  1546. struct myri10ge_priv *mgp = netdev_priv(netdev);
  1547. char *ptr;
  1548. int i;
  1549. cmd->autoneg = AUTONEG_DISABLE;
  1550. ethtool_cmd_speed_set(cmd, SPEED_10000);
  1551. cmd->duplex = DUPLEX_FULL;
  1552. /*
  1553. * parse the product code to deterimine the interface type
  1554. * (CX4, XFP, Quad Ribbon Fiber) by looking at the character
  1555. * after the 3rd dash in the driver's cached copy of the
  1556. * EEPROM's product code string.
  1557. */
  1558. ptr = mgp->product_code_string;
  1559. if (ptr == NULL) {
  1560. netdev_err(netdev, "Missing product code\n");
  1561. return 0;
  1562. }
  1563. for (i = 0; i < 3; i++, ptr++) {
  1564. ptr = strchr(ptr, '-');
  1565. if (ptr == NULL) {
  1566. netdev_err(netdev, "Invalid product code %s\n",
  1567. mgp->product_code_string);
  1568. return 0;
  1569. }
  1570. }
  1571. if (*ptr == '2')
  1572. ptr++;
  1573. if (*ptr == 'R' || *ptr == 'Q' || *ptr == 'S') {
  1574. /* We've found either an XFP, quad ribbon fiber, or SFP+ */
  1575. cmd->port = PORT_FIBRE;
  1576. cmd->supported |= SUPPORTED_FIBRE;
  1577. cmd->advertising |= ADVERTISED_FIBRE;
  1578. } else {
  1579. cmd->port = PORT_OTHER;
  1580. }
  1581. if (*ptr == 'R' || *ptr == 'S')
  1582. cmd->transceiver = XCVR_EXTERNAL;
  1583. else
  1584. cmd->transceiver = XCVR_INTERNAL;
  1585. return 0;
  1586. }
  1587. static void
  1588. myri10ge_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *info)
  1589. {
  1590. struct myri10ge_priv *mgp = netdev_priv(netdev);
  1591. strlcpy(info->driver, "myri10ge", sizeof(info->driver));
  1592. strlcpy(info->version, MYRI10GE_VERSION_STR, sizeof(info->version));
  1593. strlcpy(info->fw_version, mgp->fw_version, sizeof(info->fw_version));
  1594. strlcpy(info->bus_info, pci_name(mgp->pdev), sizeof(info->bus_info));
  1595. }
  1596. static int
  1597. myri10ge_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coal)
  1598. {
  1599. struct myri10ge_priv *mgp = netdev_priv(netdev);
  1600. coal->rx_coalesce_usecs = mgp->intr_coal_delay;
  1601. return 0;
  1602. }
  1603. static int
  1604. myri10ge_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coal)
  1605. {
  1606. struct myri10ge_priv *mgp = netdev_priv(netdev);
  1607. mgp->intr_coal_delay = coal->rx_coalesce_usecs;
  1608. put_be32(htonl(mgp->intr_coal_delay), mgp->intr_coal_delay_ptr);
  1609. return 0;
  1610. }
  1611. static void
  1612. myri10ge_get_pauseparam(struct net_device *netdev,
  1613. struct ethtool_pauseparam *pause)
  1614. {
  1615. struct myri10ge_priv *mgp = netdev_priv(netdev);
  1616. pause->autoneg = 0;
  1617. pause->rx_pause = mgp->pause;
  1618. pause->tx_pause = mgp->pause;
  1619. }
  1620. static int
  1621. myri10ge_set_pauseparam(struct net_device *netdev,
  1622. struct ethtool_pauseparam *pause)
  1623. {
  1624. struct myri10ge_priv *mgp = netdev_priv(netdev);
  1625. if (pause->tx_pause != mgp->pause)
  1626. return myri10ge_change_pause(mgp, pause->tx_pause);
  1627. if (pause->rx_pause != mgp->pause)
  1628. return myri10ge_change_pause(mgp, pause->rx_pause);
  1629. if (pause->autoneg != 0)
  1630. return -EINVAL;
  1631. return 0;
  1632. }
  1633. static void
  1634. myri10ge_get_ringparam(struct net_device *netdev,
  1635. struct ethtool_ringparam *ring)
  1636. {
  1637. struct myri10ge_priv *mgp = netdev_priv(netdev);
  1638. ring->rx_mini_max_pending = mgp->ss[0].rx_small.mask + 1;
  1639. ring->rx_max_pending = mgp->ss[0].rx_big.mask + 1;
  1640. ring->rx_jumbo_max_pending = 0;
  1641. ring->tx_max_pending = mgp->ss[0].tx.mask + 1;
  1642. ring->rx_mini_pending = ring->rx_mini_max_pending;
  1643. ring->rx_pending = ring->rx_max_pending;
  1644. ring->rx_jumbo_pending = ring->rx_jumbo_max_pending;
  1645. ring->tx_pending = ring->tx_max_pending;
  1646. }
  1647. static const char myri10ge_gstrings_main_stats[][ETH_GSTRING_LEN] = {
  1648. "rx_packets", "tx_packets", "rx_bytes", "tx_bytes", "rx_errors",
  1649. "tx_errors", "rx_dropped", "tx_dropped", "multicast", "collisions",
  1650. "rx_length_errors", "rx_over_errors", "rx_crc_errors",
  1651. "rx_frame_errors", "rx_fifo_errors", "rx_missed_errors",
  1652. "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors",
  1653. "tx_heartbeat_errors", "tx_window_errors",
  1654. /* device-specific stats */
  1655. "tx_boundary", "WC", "irq", "MSI", "MSIX",
  1656. "read_dma_bw_MBs", "write_dma_bw_MBs", "read_write_dma_bw_MBs",
  1657. "serial_number", "watchdog_resets",
  1658. #ifdef CONFIG_MYRI10GE_DCA
  1659. "dca_capable_firmware", "dca_device_present",
  1660. #endif
  1661. "link_changes", "link_up", "dropped_link_overflow",
  1662. "dropped_link_error_or_filtered",
  1663. "dropped_pause", "dropped_bad_phy", "dropped_bad_crc32",
  1664. "dropped_unicast_filtered", "dropped_multicast_filtered",
  1665. "dropped_runt", "dropped_overrun", "dropped_no_small_buffer",
  1666. "dropped_no_big_buffer"
  1667. };
  1668. static const char myri10ge_gstrings_slice_stats[][ETH_GSTRING_LEN] = {
  1669. "----------- slice ---------",
  1670. "tx_pkt_start", "tx_pkt_done", "tx_req", "tx_done",
  1671. "rx_small_cnt", "rx_big_cnt",
  1672. "wake_queue", "stop_queue", "tx_linearized",
  1673. #ifdef CONFIG_NET_RX_BUSY_POLL
  1674. "rx_lock_napi_yield", "rx_lock_poll_yield", "rx_busy_poll_miss",
  1675. "rx_busy_poll_cnt",
  1676. #endif
  1677. };
  1678. #define MYRI10GE_NET_STATS_LEN 21
  1679. #define MYRI10GE_MAIN_STATS_LEN ARRAY_SIZE(myri10ge_gstrings_main_stats)
  1680. #define MYRI10GE_SLICE_STATS_LEN ARRAY_SIZE(myri10ge_gstrings_slice_stats)
  1681. static void
  1682. myri10ge_get_strings(struct net_device *netdev, u32 stringset, u8 * data)
  1683. {
  1684. struct myri10ge_priv *mgp = netdev_priv(netdev);
  1685. int i;
  1686. switch (stringset) {
  1687. case ETH_SS_STATS:
  1688. memcpy(data, *myri10ge_gstrings_main_stats,
  1689. sizeof(myri10ge_gstrings_main_stats));
  1690. data += sizeof(myri10ge_gstrings_main_stats);
  1691. for (i = 0; i < mgp->num_slices; i++) {
  1692. memcpy(data, *myri10ge_gstrings_slice_stats,
  1693. sizeof(myri10ge_gstrings_slice_stats));
  1694. data += sizeof(myri10ge_gstrings_slice_stats);
  1695. }
  1696. break;
  1697. }
  1698. }
  1699. static int myri10ge_get_sset_count(struct net_device *netdev, int sset)
  1700. {
  1701. struct myri10ge_priv *mgp = netdev_priv(netdev);
  1702. switch (sset) {
  1703. case ETH_SS_STATS:
  1704. return MYRI10GE_MAIN_STATS_LEN +
  1705. mgp->num_slices * MYRI10GE_SLICE_STATS_LEN;
  1706. default:
  1707. return -EOPNOTSUPP;
  1708. }
  1709. }
  1710. static void
  1711. myri10ge_get_ethtool_stats(struct net_device *netdev,
  1712. struct ethtool_stats *stats, u64 * data)
  1713. {
  1714. struct myri10ge_priv *mgp = netdev_priv(netdev);
  1715. struct myri10ge_slice_state *ss;
  1716. struct rtnl_link_stats64 link_stats;
  1717. int slice;
  1718. int i;
  1719. /* force stats update */
  1720. memset(&link_stats, 0, sizeof(link_stats));
  1721. (void)myri10ge_get_stats(netdev, &link_stats);
  1722. for (i = 0; i < MYRI10GE_NET_STATS_LEN; i++)
  1723. data[i] = ((u64 *)&link_stats)[i];
  1724. data[i++] = (unsigned int)mgp->tx_boundary;
  1725. data[i++] = (unsigned int)mgp->wc_enabled;
  1726. data[i++] = (unsigned int)mgp->pdev->irq;
  1727. data[i++] = (unsigned int)mgp->msi_enabled;
  1728. data[i++] = (unsigned int)mgp->msix_enabled;
  1729. data[i++] = (unsigned int)mgp->read_dma;
  1730. data[i++] = (unsigned int)mgp->write_dma;
  1731. data[i++] = (unsigned int)mgp->read_write_dma;
  1732. data[i++] = (unsigned int)mgp->serial_number;
  1733. data[i++] = (unsigned int)mgp->watchdog_resets;
  1734. #ifdef CONFIG_MYRI10GE_DCA
  1735. data[i++] = (unsigned int)(mgp->ss[0].dca_tag != NULL);
  1736. data[i++] = (unsigned int)(mgp->dca_enabled);
  1737. #endif
  1738. data[i++] = (unsigned int)mgp->link_changes;
  1739. /* firmware stats are useful only in the first slice */
  1740. ss = &mgp->ss[0];
  1741. data[i++] = (unsigned int)ntohl(ss->fw_stats->link_up);
  1742. data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_link_overflow);
  1743. data[i++] =
  1744. (unsigned int)ntohl(ss->fw_stats->dropped_link_error_or_filtered);
  1745. data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_pause);
  1746. data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_bad_phy);
  1747. data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_bad_crc32);
  1748. data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_unicast_filtered);
  1749. data[i++] =
  1750. (unsigned int)ntohl(ss->fw_stats->dropped_multicast_filtered);
  1751. data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_runt);
  1752. data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_overrun);
  1753. data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_no_small_buffer);
  1754. data[i++] = (unsigned int)ntohl(ss->fw_stats->dropped_no_big_buffer);
  1755. for (slice = 0; slice < mgp->num_slices; slice++) {
  1756. ss = &mgp->ss[slice];
  1757. data[i++] = slice;
  1758. data[i++] = (unsigned int)ss->tx.pkt_start;
  1759. data[i++] = (unsigned int)ss->tx.pkt_done;
  1760. data[i++] = (unsigned int)ss->tx.req;
  1761. data[i++] = (unsigned int)ss->tx.done;
  1762. data[i++] = (unsigned int)ss->rx_small.cnt;
  1763. data[i++] = (unsigned int)ss->rx_big.cnt;
  1764. data[i++] = (unsigned int)ss->tx.wake_queue;
  1765. data[i++] = (unsigned int)ss->tx.stop_queue;
  1766. data[i++] = (unsigned int)ss->tx.linearized;
  1767. #ifdef CONFIG_NET_RX_BUSY_POLL
  1768. data[i++] = ss->lock_napi_yield;
  1769. data[i++] = ss->lock_poll_yield;
  1770. data[i++] = ss->busy_poll_miss;
  1771. data[i++] = ss->busy_poll_cnt;
  1772. #endif
  1773. }
  1774. }
  1775. static void myri10ge_set_msglevel(struct net_device *netdev, u32 value)
  1776. {
  1777. struct myri10ge_priv *mgp = netdev_priv(netdev);
  1778. mgp->msg_enable = value;
  1779. }
  1780. static u32 myri10ge_get_msglevel(struct net_device *netdev)
  1781. {
  1782. struct myri10ge_priv *mgp = netdev_priv(netdev);
  1783. return mgp->msg_enable;
  1784. }
  1785. /*
  1786. * Use a low-level command to change the LED behavior. Rather than
  1787. * blinking (which is the normal case), when identify is used, the
  1788. * yellow LED turns solid.
  1789. */
  1790. static int myri10ge_led(struct myri10ge_priv *mgp, int on)
  1791. {
  1792. struct mcp_gen_header *hdr;
  1793. struct device *dev = &mgp->pdev->dev;
  1794. size_t hdr_off, pattern_off, hdr_len;
  1795. u32 pattern = 0xfffffffe;
  1796. /* find running firmware header */
  1797. hdr_off = swab32(readl(mgp->sram + MCP_HEADER_PTR_OFFSET));
  1798. if ((hdr_off & 3) || hdr_off + sizeof(*hdr) > mgp->sram_size) {
  1799. dev_err(dev, "Running firmware has bad header offset (%d)\n",
  1800. (int)hdr_off);
  1801. return -EIO;
  1802. }
  1803. hdr_len = swab32(readl(mgp->sram + hdr_off +
  1804. offsetof(struct mcp_gen_header, header_length)));
  1805. pattern_off = hdr_off + offsetof(struct mcp_gen_header, led_pattern);
  1806. if (pattern_off >= (hdr_len + hdr_off)) {
  1807. dev_info(dev, "Firmware does not support LED identification\n");
  1808. return -EINVAL;
  1809. }
  1810. if (!on)
  1811. pattern = swab32(readl(mgp->sram + pattern_off + 4));
  1812. writel(swab32(pattern), mgp->sram + pattern_off);
  1813. return 0;
  1814. }
  1815. static int
  1816. myri10ge_phys_id(struct net_device *netdev, enum ethtool_phys_id_state state)
  1817. {
  1818. struct myri10ge_priv *mgp = netdev_priv(netdev);
  1819. int rc;
  1820. switch (state) {
  1821. case ETHTOOL_ID_ACTIVE:
  1822. rc = myri10ge_led(mgp, 1);
  1823. break;
  1824. case ETHTOOL_ID_INACTIVE:
  1825. rc = myri10ge_led(mgp, 0);
  1826. break;
  1827. default:
  1828. rc = -EINVAL;
  1829. }
  1830. return rc;
  1831. }
  1832. static const struct ethtool_ops myri10ge_ethtool_ops = {
  1833. .get_settings = myri10ge_get_settings,
  1834. .get_drvinfo = myri10ge_get_drvinfo,
  1835. .get_coalesce = myri10ge_get_coalesce,
  1836. .set_coalesce = myri10ge_set_coalesce,
  1837. .get_pauseparam = myri10ge_get_pauseparam,
  1838. .set_pauseparam = myri10ge_set_pauseparam,
  1839. .get_ringparam = myri10ge_get_ringparam,
  1840. .get_link = ethtool_op_get_link,
  1841. .get_strings = myri10ge_get_strings,
  1842. .get_sset_count = myri10ge_get_sset_count,
  1843. .get_ethtool_stats = myri10ge_get_ethtool_stats,
  1844. .set_msglevel = myri10ge_set_msglevel,
  1845. .get_msglevel = myri10ge_get_msglevel,
  1846. .set_phys_id = myri10ge_phys_id,
  1847. };
  1848. static int myri10ge_allocate_rings(struct myri10ge_slice_state *ss)
  1849. {
  1850. struct myri10ge_priv *mgp = ss->mgp;
  1851. struct myri10ge_cmd cmd;
  1852. struct net_device *dev = mgp->dev;
  1853. int tx_ring_size, rx_ring_size;
  1854. int tx_ring_entries, rx_ring_entries;
  1855. int i, slice, status;
  1856. size_t bytes;
  1857. /* get ring sizes */
  1858. slice = ss - mgp->ss;
  1859. cmd.data0 = slice;
  1860. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_SEND_RING_SIZE, &cmd, 0);
  1861. tx_ring_size = cmd.data0;
  1862. cmd.data0 = slice;
  1863. status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_RX_RING_SIZE, &cmd, 0);
  1864. if (status != 0)
  1865. return status;
  1866. rx_ring_size = cmd.data0;
  1867. tx_ring_entries = tx_ring_size / sizeof(struct mcp_kreq_ether_send);
  1868. rx_ring_entries = rx_ring_size / sizeof(struct mcp_dma_addr);
  1869. ss->tx.mask = tx_ring_entries - 1;
  1870. ss->rx_small.mask = ss->rx_big.mask = rx_ring_entries - 1;
  1871. status = -ENOMEM;
  1872. /* allocate the host shadow rings */
  1873. bytes = 8 + (MYRI10GE_MAX_SEND_DESC_TSO + 4)
  1874. * sizeof(*ss->tx.req_list);
  1875. ss->tx.req_bytes = kzalloc(bytes, GFP_KERNEL);
  1876. if (ss->tx.req_bytes == NULL)
  1877. goto abort_with_nothing;
  1878. /* ensure req_list entries are aligned to 8 bytes */
  1879. ss->tx.req_list = (struct mcp_kreq_ether_send *)
  1880. ALIGN((unsigned long)ss->tx.req_bytes, 8);
  1881. ss->tx.queue_active = 0;
  1882. bytes = rx_ring_entries * sizeof(*ss->rx_small.shadow);
  1883. ss->rx_small.shadow = kzalloc(bytes, GFP_KERNEL);
  1884. if (ss->rx_small.shadow == NULL)
  1885. goto abort_with_tx_req_bytes;
  1886. bytes = rx_ring_entries * sizeof(*ss->rx_big.shadow);
  1887. ss->rx_big.shadow = kzalloc(bytes, GFP_KERNEL);
  1888. if (ss->rx_big.shadow == NULL)
  1889. goto abort_with_rx_small_shadow;
  1890. /* allocate the host info rings */
  1891. bytes = tx_ring_entries * sizeof(*ss->tx.info);
  1892. ss->tx.info = kzalloc(bytes, GFP_KERNEL);
  1893. if (ss->tx.info == NULL)
  1894. goto abort_with_rx_big_shadow;
  1895. bytes = rx_ring_entries * sizeof(*ss->rx_small.info);
  1896. ss->rx_small.info = kzalloc(bytes, GFP_KERNEL);
  1897. if (ss->rx_small.info == NULL)
  1898. goto abort_with_tx_info;
  1899. bytes = rx_ring_entries * sizeof(*ss->rx_big.info);
  1900. ss->rx_big.info = kzalloc(bytes, GFP_KERNEL);
  1901. if (ss->rx_big.info == NULL)
  1902. goto abort_with_rx_small_info;
  1903. /* Fill the receive rings */
  1904. ss->rx_big.cnt = 0;
  1905. ss->rx_small.cnt = 0;
  1906. ss->rx_big.fill_cnt = 0;
  1907. ss->rx_small.fill_cnt = 0;
  1908. ss->rx_small.page_offset = MYRI10GE_ALLOC_SIZE;
  1909. ss->rx_big.page_offset = MYRI10GE_ALLOC_SIZE;
  1910. ss->rx_small.watchdog_needed = 0;
  1911. ss->rx_big.watchdog_needed = 0;
  1912. if (mgp->small_bytes == 0) {
  1913. ss->rx_small.fill_cnt = ss->rx_small.mask + 1;
  1914. } else {
  1915. myri10ge_alloc_rx_pages(mgp, &ss->rx_small,
  1916. mgp->small_bytes + MXGEFW_PAD, 0);
  1917. }
  1918. if (ss->rx_small.fill_cnt < ss->rx_small.mask + 1) {
  1919. netdev_err(dev, "slice-%d: alloced only %d small bufs\n",
  1920. slice, ss->rx_small.fill_cnt);
  1921. goto abort_with_rx_small_ring;
  1922. }
  1923. myri10ge_alloc_rx_pages(mgp, &ss->rx_big, mgp->big_bytes, 0);
  1924. if (ss->rx_big.fill_cnt < ss->rx_big.mask + 1) {
  1925. netdev_err(dev, "slice-%d: alloced only %d big bufs\n",
  1926. slice, ss->rx_big.fill_cnt);
  1927. goto abort_with_rx_big_ring;
  1928. }
  1929. return 0;
  1930. abort_with_rx_big_ring:
  1931. for (i = ss->rx_big.cnt; i < ss->rx_big.fill_cnt; i++) {
  1932. int idx = i & ss->rx_big.mask;
  1933. myri10ge_unmap_rx_page(mgp->pdev, &ss->rx_big.info[idx],
  1934. mgp->big_bytes);
  1935. put_page(ss->rx_big.info[idx].page);
  1936. }
  1937. abort_with_rx_small_ring:
  1938. if (mgp->small_bytes == 0)
  1939. ss->rx_small.fill_cnt = ss->rx_small.cnt;
  1940. for (i = ss->rx_small.cnt; i < ss->rx_small.fill_cnt; i++) {
  1941. int idx = i & ss->rx_small.mask;
  1942. myri10ge_unmap_rx_page(mgp->pdev, &ss->rx_small.info[idx],
  1943. mgp->small_bytes + MXGEFW_PAD);
  1944. put_page(ss->rx_small.info[idx].page);
  1945. }
  1946. kfree(ss->rx_big.info);
  1947. abort_with_rx_small_info:
  1948. kfree(ss->rx_small.info);
  1949. abort_with_tx_info:
  1950. kfree(ss->tx.info);
  1951. abort_with_rx_big_shadow:
  1952. kfree(ss->rx_big.shadow);
  1953. abort_with_rx_small_shadow:
  1954. kfree(ss->rx_small.shadow);
  1955. abort_with_tx_req_bytes:
  1956. kfree(ss->tx.req_bytes);
  1957. ss->tx.req_bytes = NULL;
  1958. ss->tx.req_list = NULL;
  1959. abort_with_nothing:
  1960. return status;
  1961. }
  1962. static void myri10ge_free_rings(struct myri10ge_slice_state *ss)
  1963. {
  1964. struct myri10ge_priv *mgp = ss->mgp;
  1965. struct sk_buff *skb;
  1966. struct myri10ge_tx_buf *tx;
  1967. int i, len, idx;
  1968. /* If not allocated, skip it */
  1969. if (ss->tx.req_list == NULL)
  1970. return;
  1971. for (i = ss->rx_big.cnt; i < ss->rx_big.fill_cnt; i++) {
  1972. idx = i & ss->rx_big.mask;
  1973. if (i == ss->rx_big.fill_cnt - 1)
  1974. ss->rx_big.info[idx].page_offset = MYRI10GE_ALLOC_SIZE;
  1975. myri10ge_unmap_rx_page(mgp->pdev, &ss->rx_big.info[idx],
  1976. mgp->big_bytes);
  1977. put_page(ss->rx_big.info[idx].page);
  1978. }
  1979. if (mgp->small_bytes == 0)
  1980. ss->rx_small.fill_cnt = ss->rx_small.cnt;
  1981. for (i = ss->rx_small.cnt; i < ss->rx_small.fill_cnt; i++) {
  1982. idx = i & ss->rx_small.mask;
  1983. if (i == ss->rx_small.fill_cnt - 1)
  1984. ss->rx_small.info[idx].page_offset =
  1985. MYRI10GE_ALLOC_SIZE;
  1986. myri10ge_unmap_rx_page(mgp->pdev, &ss->rx_small.info[idx],
  1987. mgp->small_bytes + MXGEFW_PAD);
  1988. put_page(ss->rx_small.info[idx].page);
  1989. }
  1990. tx = &ss->tx;
  1991. while (tx->done != tx->req) {
  1992. idx = tx->done & tx->mask;
  1993. skb = tx->info[idx].skb;
  1994. /* Mark as free */
  1995. tx->info[idx].skb = NULL;
  1996. tx->done++;
  1997. len = dma_unmap_len(&tx->info[idx], len);
  1998. dma_unmap_len_set(&tx->info[idx], len, 0);
  1999. if (skb) {
  2000. ss->stats.tx_dropped++;
  2001. dev_kfree_skb_any(skb);
  2002. if (len)
  2003. pci_unmap_single(mgp->pdev,
  2004. dma_unmap_addr(&tx->info[idx],
  2005. bus), len,
  2006. PCI_DMA_TODEVICE);
  2007. } else {
  2008. if (len)
  2009. pci_unmap_page(mgp->pdev,
  2010. dma_unmap_addr(&tx->info[idx],
  2011. bus), len,
  2012. PCI_DMA_TODEVICE);
  2013. }
  2014. }
  2015. kfree(ss->rx_big.info);
  2016. kfree(ss->rx_small.info);
  2017. kfree(ss->tx.info);
  2018. kfree(ss->rx_big.shadow);
  2019. kfree(ss->rx_small.shadow);
  2020. kfree(ss->tx.req_bytes);
  2021. ss->tx.req_bytes = NULL;
  2022. ss->tx.req_list = NULL;
  2023. }
  2024. static int myri10ge_request_irq(struct myri10ge_priv *mgp)
  2025. {
  2026. struct pci_dev *pdev = mgp->pdev;
  2027. struct myri10ge_slice_state *ss;
  2028. struct net_device *netdev = mgp->dev;
  2029. int i;
  2030. int status;
  2031. mgp->msi_enabled = 0;
  2032. mgp->msix_enabled = 0;
  2033. status = 0;
  2034. if (myri10ge_msi) {
  2035. if (mgp->num_slices > 1) {
  2036. status =
  2037. pci_enable_msix(pdev, mgp->msix_vectors,
  2038. mgp->num_slices);
  2039. if (status == 0) {
  2040. mgp->msix_enabled = 1;
  2041. } else {
  2042. dev_err(&pdev->dev,
  2043. "Error %d setting up MSI-X\n", status);
  2044. return status;
  2045. }
  2046. }
  2047. if (mgp->msix_enabled == 0) {
  2048. status = pci_enable_msi(pdev);
  2049. if (status != 0) {
  2050. dev_err(&pdev->dev,
  2051. "Error %d setting up MSI; falling back to xPIC\n",
  2052. status);
  2053. } else {
  2054. mgp->msi_enabled = 1;
  2055. }
  2056. }
  2057. }
  2058. if (mgp->msix_enabled) {
  2059. for (i = 0; i < mgp->num_slices; i++) {
  2060. ss = &mgp->ss[i];
  2061. snprintf(ss->irq_desc, sizeof(ss->irq_desc),
  2062. "%s:slice-%d", netdev->name, i);
  2063. status = request_irq(mgp->msix_vectors[i].vector,
  2064. myri10ge_intr, 0, ss->irq_desc,
  2065. ss);
  2066. if (status != 0) {
  2067. dev_err(&pdev->dev,
  2068. "slice %d failed to allocate IRQ\n", i);
  2069. i--;
  2070. while (i >= 0) {
  2071. free_irq(mgp->msix_vectors[i].vector,
  2072. &mgp->ss[i]);
  2073. i--;
  2074. }
  2075. pci_disable_msix(pdev);
  2076. return status;
  2077. }
  2078. }
  2079. } else {
  2080. status = request_irq(pdev->irq, myri10ge_intr, IRQF_SHARED,
  2081. mgp->dev->name, &mgp->ss[0]);
  2082. if (status != 0) {
  2083. dev_err(&pdev->dev, "failed to allocate IRQ\n");
  2084. if (mgp->msi_enabled)
  2085. pci_disable_msi(pdev);
  2086. }
  2087. }
  2088. return status;
  2089. }
  2090. static void myri10ge_free_irq(struct myri10ge_priv *mgp)
  2091. {
  2092. struct pci_dev *pdev = mgp->pdev;
  2093. int i;
  2094. if (mgp->msix_enabled) {
  2095. for (i = 0; i < mgp->num_slices; i++)
  2096. free_irq(mgp->msix_vectors[i].vector, &mgp->ss[i]);
  2097. } else {
  2098. free_irq(pdev->irq, &mgp->ss[0]);
  2099. }
  2100. if (mgp->msi_enabled)
  2101. pci_disable_msi(pdev);
  2102. if (mgp->msix_enabled)
  2103. pci_disable_msix(pdev);
  2104. }
  2105. static int myri10ge_get_txrx(struct myri10ge_priv *mgp, int slice)
  2106. {
  2107. struct myri10ge_cmd cmd;
  2108. struct myri10ge_slice_state *ss;
  2109. int status;
  2110. ss = &mgp->ss[slice];
  2111. status = 0;
  2112. if (slice == 0 || (mgp->dev->real_num_tx_queues > 1)) {
  2113. cmd.data0 = slice;
  2114. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_SEND_OFFSET,
  2115. &cmd, 0);
  2116. ss->tx.lanai = (struct mcp_kreq_ether_send __iomem *)
  2117. (mgp->sram + cmd.data0);
  2118. }
  2119. cmd.data0 = slice;
  2120. status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_SMALL_RX_OFFSET,
  2121. &cmd, 0);
  2122. ss->rx_small.lanai = (struct mcp_kreq_ether_recv __iomem *)
  2123. (mgp->sram + cmd.data0);
  2124. cmd.data0 = slice;
  2125. status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_BIG_RX_OFFSET, &cmd, 0);
  2126. ss->rx_big.lanai = (struct mcp_kreq_ether_recv __iomem *)
  2127. (mgp->sram + cmd.data0);
  2128. ss->tx.send_go = (__iomem __be32 *)
  2129. (mgp->sram + MXGEFW_ETH_SEND_GO + 64 * slice);
  2130. ss->tx.send_stop = (__iomem __be32 *)
  2131. (mgp->sram + MXGEFW_ETH_SEND_STOP + 64 * slice);
  2132. return status;
  2133. }
  2134. static int myri10ge_set_stats(struct myri10ge_priv *mgp, int slice)
  2135. {
  2136. struct myri10ge_cmd cmd;
  2137. struct myri10ge_slice_state *ss;
  2138. int status;
  2139. ss = &mgp->ss[slice];
  2140. cmd.data0 = MYRI10GE_LOWPART_TO_U32(ss->fw_stats_bus);
  2141. cmd.data1 = MYRI10GE_HIGHPART_TO_U32(ss->fw_stats_bus);
  2142. cmd.data2 = sizeof(struct mcp_irq_data) | (slice << 16);
  2143. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_STATS_DMA_V2, &cmd, 0);
  2144. if (status == -ENOSYS) {
  2145. dma_addr_t bus = ss->fw_stats_bus;
  2146. if (slice != 0)
  2147. return -EINVAL;
  2148. bus += offsetof(struct mcp_irq_data, send_done_count);
  2149. cmd.data0 = MYRI10GE_LOWPART_TO_U32(bus);
  2150. cmd.data1 = MYRI10GE_HIGHPART_TO_U32(bus);
  2151. status = myri10ge_send_cmd(mgp,
  2152. MXGEFW_CMD_SET_STATS_DMA_OBSOLETE,
  2153. &cmd, 0);
  2154. /* Firmware cannot support multicast without STATS_DMA_V2 */
  2155. mgp->fw_multicast_support = 0;
  2156. } else {
  2157. mgp->fw_multicast_support = 1;
  2158. }
  2159. return 0;
  2160. }
  2161. static int myri10ge_open(struct net_device *dev)
  2162. {
  2163. struct myri10ge_slice_state *ss;
  2164. struct myri10ge_priv *mgp = netdev_priv(dev);
  2165. struct myri10ge_cmd cmd;
  2166. int i, status, big_pow2, slice;
  2167. u8 __iomem *itable;
  2168. if (mgp->running != MYRI10GE_ETH_STOPPED)
  2169. return -EBUSY;
  2170. mgp->running = MYRI10GE_ETH_STARTING;
  2171. status = myri10ge_reset(mgp);
  2172. if (status != 0) {
  2173. netdev_err(dev, "failed reset\n");
  2174. goto abort_with_nothing;
  2175. }
  2176. if (mgp->num_slices > 1) {
  2177. cmd.data0 = mgp->num_slices;
  2178. cmd.data1 = MXGEFW_SLICE_INTR_MODE_ONE_PER_SLICE;
  2179. if (mgp->dev->real_num_tx_queues > 1)
  2180. cmd.data1 |= MXGEFW_SLICE_ENABLE_MULTIPLE_TX_QUEUES;
  2181. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_ENABLE_RSS_QUEUES,
  2182. &cmd, 0);
  2183. if (status != 0) {
  2184. netdev_err(dev, "failed to set number of slices\n");
  2185. goto abort_with_nothing;
  2186. }
  2187. /* setup the indirection table */
  2188. cmd.data0 = mgp->num_slices;
  2189. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_RSS_TABLE_SIZE,
  2190. &cmd, 0);
  2191. status |= myri10ge_send_cmd(mgp,
  2192. MXGEFW_CMD_GET_RSS_TABLE_OFFSET,
  2193. &cmd, 0);
  2194. if (status != 0) {
  2195. netdev_err(dev, "failed to setup rss tables\n");
  2196. goto abort_with_nothing;
  2197. }
  2198. /* just enable an identity mapping */
  2199. itable = mgp->sram + cmd.data0;
  2200. for (i = 0; i < mgp->num_slices; i++)
  2201. __raw_writeb(i, &itable[i]);
  2202. cmd.data0 = 1;
  2203. cmd.data1 = myri10ge_rss_hash;
  2204. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_RSS_ENABLE,
  2205. &cmd, 0);
  2206. if (status != 0) {
  2207. netdev_err(dev, "failed to enable slices\n");
  2208. goto abort_with_nothing;
  2209. }
  2210. }
  2211. status = myri10ge_request_irq(mgp);
  2212. if (status != 0)
  2213. goto abort_with_nothing;
  2214. /* decide what small buffer size to use. For good TCP rx
  2215. * performance, it is important to not receive 1514 byte
  2216. * frames into jumbo buffers, as it confuses the socket buffer
  2217. * accounting code, leading to drops and erratic performance.
  2218. */
  2219. if (dev->mtu <= ETH_DATA_LEN)
  2220. /* enough for a TCP header */
  2221. mgp->small_bytes = (128 > SMP_CACHE_BYTES)
  2222. ? (128 - MXGEFW_PAD)
  2223. : (SMP_CACHE_BYTES - MXGEFW_PAD);
  2224. else
  2225. /* enough for a vlan encapsulated ETH_DATA_LEN frame */
  2226. mgp->small_bytes = VLAN_ETH_FRAME_LEN;
  2227. /* Override the small buffer size? */
  2228. if (myri10ge_small_bytes >= 0)
  2229. mgp->small_bytes = myri10ge_small_bytes;
  2230. /* Firmware needs the big buff size as a power of 2. Lie and
  2231. * tell him the buffer is larger, because we only use 1
  2232. * buffer/pkt, and the mtu will prevent overruns.
  2233. */
  2234. big_pow2 = dev->mtu + ETH_HLEN + VLAN_HLEN + MXGEFW_PAD;
  2235. if (big_pow2 < MYRI10GE_ALLOC_SIZE / 2) {
  2236. while (!is_power_of_2(big_pow2))
  2237. big_pow2++;
  2238. mgp->big_bytes = dev->mtu + ETH_HLEN + VLAN_HLEN + MXGEFW_PAD;
  2239. } else {
  2240. big_pow2 = MYRI10GE_ALLOC_SIZE;
  2241. mgp->big_bytes = big_pow2;
  2242. }
  2243. /* setup the per-slice data structures */
  2244. for (slice = 0; slice < mgp->num_slices; slice++) {
  2245. ss = &mgp->ss[slice];
  2246. status = myri10ge_get_txrx(mgp, slice);
  2247. if (status != 0) {
  2248. netdev_err(dev, "failed to get ring sizes or locations\n");
  2249. goto abort_with_rings;
  2250. }
  2251. status = myri10ge_allocate_rings(ss);
  2252. if (status != 0)
  2253. goto abort_with_rings;
  2254. /* only firmware which supports multiple TX queues
  2255. * supports setting up the tx stats on non-zero
  2256. * slices */
  2257. if (slice == 0 || mgp->dev->real_num_tx_queues > 1)
  2258. status = myri10ge_set_stats(mgp, slice);
  2259. if (status) {
  2260. netdev_err(dev, "Couldn't set stats DMA\n");
  2261. goto abort_with_rings;
  2262. }
  2263. /* Initialize the slice spinlock and state used for polling */
  2264. myri10ge_ss_init_lock(ss);
  2265. /* must happen prior to any irq */
  2266. napi_enable(&(ss)->napi);
  2267. }
  2268. /* now give firmware buffers sizes, and MTU */
  2269. cmd.data0 = dev->mtu + ETH_HLEN + VLAN_HLEN;
  2270. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_MTU, &cmd, 0);
  2271. cmd.data0 = mgp->small_bytes;
  2272. status |=
  2273. myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_SMALL_BUFFER_SIZE, &cmd, 0);
  2274. cmd.data0 = big_pow2;
  2275. status |=
  2276. myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_BIG_BUFFER_SIZE, &cmd, 0);
  2277. if (status) {
  2278. netdev_err(dev, "Couldn't set buffer sizes\n");
  2279. goto abort_with_rings;
  2280. }
  2281. /*
  2282. * Set Linux style TSO mode; this is needed only on newer
  2283. * firmware versions. Older versions default to Linux
  2284. * style TSO
  2285. */
  2286. cmd.data0 = 0;
  2287. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_TSO_MODE, &cmd, 0);
  2288. if (status && status != -ENOSYS) {
  2289. netdev_err(dev, "Couldn't set TSO mode\n");
  2290. goto abort_with_rings;
  2291. }
  2292. mgp->link_state = ~0U;
  2293. mgp->rdma_tags_available = 15;
  2294. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_ETHERNET_UP, &cmd, 0);
  2295. if (status) {
  2296. netdev_err(dev, "Couldn't bring up link\n");
  2297. goto abort_with_rings;
  2298. }
  2299. mgp->running = MYRI10GE_ETH_RUNNING;
  2300. mgp->watchdog_timer.expires = jiffies + myri10ge_watchdog_timeout * HZ;
  2301. add_timer(&mgp->watchdog_timer);
  2302. netif_tx_wake_all_queues(dev);
  2303. return 0;
  2304. abort_with_rings:
  2305. while (slice) {
  2306. slice--;
  2307. napi_disable(&mgp->ss[slice].napi);
  2308. }
  2309. for (i = 0; i < mgp->num_slices; i++)
  2310. myri10ge_free_rings(&mgp->ss[i]);
  2311. myri10ge_free_irq(mgp);
  2312. abort_with_nothing:
  2313. mgp->running = MYRI10GE_ETH_STOPPED;
  2314. return -ENOMEM;
  2315. }
  2316. static int myri10ge_close(struct net_device *dev)
  2317. {
  2318. struct myri10ge_priv *mgp = netdev_priv(dev);
  2319. struct myri10ge_cmd cmd;
  2320. int status, old_down_cnt;
  2321. int i;
  2322. if (mgp->running != MYRI10GE_ETH_RUNNING)
  2323. return 0;
  2324. if (mgp->ss[0].tx.req_bytes == NULL)
  2325. return 0;
  2326. del_timer_sync(&mgp->watchdog_timer);
  2327. mgp->running = MYRI10GE_ETH_STOPPING;
  2328. local_bh_disable(); /* myri10ge_ss_lock_napi needs bh disabled */
  2329. for (i = 0; i < mgp->num_slices; i++) {
  2330. napi_disable(&mgp->ss[i].napi);
  2331. /* Lock the slice to prevent the busy_poll handler from
  2332. * accessing it. Later when we bring the NIC up, myri10ge_open
  2333. * resets the slice including this lock.
  2334. */
  2335. while (!myri10ge_ss_lock_napi(&mgp->ss[i])) {
  2336. pr_info("Slice %d locked\n", i);
  2337. mdelay(1);
  2338. }
  2339. }
  2340. local_bh_enable();
  2341. netif_carrier_off(dev);
  2342. netif_tx_stop_all_queues(dev);
  2343. if (mgp->rebooted == 0) {
  2344. old_down_cnt = mgp->down_cnt;
  2345. mb();
  2346. status =
  2347. myri10ge_send_cmd(mgp, MXGEFW_CMD_ETHERNET_DOWN, &cmd, 0);
  2348. if (status)
  2349. netdev_err(dev, "Couldn't bring down link\n");
  2350. wait_event_timeout(mgp->down_wq, old_down_cnt != mgp->down_cnt,
  2351. HZ);
  2352. if (old_down_cnt == mgp->down_cnt)
  2353. netdev_err(dev, "never got down irq\n");
  2354. }
  2355. netif_tx_disable(dev);
  2356. myri10ge_free_irq(mgp);
  2357. for (i = 0; i < mgp->num_slices; i++)
  2358. myri10ge_free_rings(&mgp->ss[i]);
  2359. mgp->running = MYRI10GE_ETH_STOPPED;
  2360. return 0;
  2361. }
  2362. /* copy an array of struct mcp_kreq_ether_send's to the mcp. Copy
  2363. * backwards one at a time and handle ring wraps */
  2364. static inline void
  2365. myri10ge_submit_req_backwards(struct myri10ge_tx_buf *tx,
  2366. struct mcp_kreq_ether_send *src, int cnt)
  2367. {
  2368. int idx, starting_slot;
  2369. starting_slot = tx->req;
  2370. while (cnt > 1) {
  2371. cnt--;
  2372. idx = (starting_slot + cnt) & tx->mask;
  2373. myri10ge_pio_copy(&tx->lanai[idx], &src[cnt], sizeof(*src));
  2374. mb();
  2375. }
  2376. }
  2377. /*
  2378. * copy an array of struct mcp_kreq_ether_send's to the mcp. Copy
  2379. * at most 32 bytes at a time, so as to avoid involving the software
  2380. * pio handler in the nic. We re-write the first segment's flags
  2381. * to mark them valid only after writing the entire chain.
  2382. */
  2383. static inline void
  2384. myri10ge_submit_req(struct myri10ge_tx_buf *tx, struct mcp_kreq_ether_send *src,
  2385. int cnt)
  2386. {
  2387. int idx, i;
  2388. struct mcp_kreq_ether_send __iomem *dstp, *dst;
  2389. struct mcp_kreq_ether_send *srcp;
  2390. u8 last_flags;
  2391. idx = tx->req & tx->mask;
  2392. last_flags = src->flags;
  2393. src->flags = 0;
  2394. mb();
  2395. dst = dstp = &tx->lanai[idx];
  2396. srcp = src;
  2397. if ((idx + cnt) < tx->mask) {
  2398. for (i = 0; i < (cnt - 1); i += 2) {
  2399. myri10ge_pio_copy(dstp, srcp, 2 * sizeof(*src));
  2400. mb(); /* force write every 32 bytes */
  2401. srcp += 2;
  2402. dstp += 2;
  2403. }
  2404. } else {
  2405. /* submit all but the first request, and ensure
  2406. * that it is submitted below */
  2407. myri10ge_submit_req_backwards(tx, src, cnt);
  2408. i = 0;
  2409. }
  2410. if (i < cnt) {
  2411. /* submit the first request */
  2412. myri10ge_pio_copy(dstp, srcp, sizeof(*src));
  2413. mb(); /* barrier before setting valid flag */
  2414. }
  2415. /* re-write the last 32-bits with the valid flags */
  2416. src->flags = last_flags;
  2417. put_be32(*((__be32 *) src + 3), (__be32 __iomem *) dst + 3);
  2418. tx->req += cnt;
  2419. mb();
  2420. }
  2421. /*
  2422. * Transmit a packet. We need to split the packet so that a single
  2423. * segment does not cross myri10ge->tx_boundary, so this makes segment
  2424. * counting tricky. So rather than try to count segments up front, we
  2425. * just give up if there are too few segments to hold a reasonably
  2426. * fragmented packet currently available. If we run
  2427. * out of segments while preparing a packet for DMA, we just linearize
  2428. * it and try again.
  2429. */
  2430. static netdev_tx_t myri10ge_xmit(struct sk_buff *skb,
  2431. struct net_device *dev)
  2432. {
  2433. struct myri10ge_priv *mgp = netdev_priv(dev);
  2434. struct myri10ge_slice_state *ss;
  2435. struct mcp_kreq_ether_send *req;
  2436. struct myri10ge_tx_buf *tx;
  2437. struct skb_frag_struct *frag;
  2438. struct netdev_queue *netdev_queue;
  2439. dma_addr_t bus;
  2440. u32 low;
  2441. __be32 high_swapped;
  2442. unsigned int len;
  2443. int idx, last_idx, avail, frag_cnt, frag_idx, count, mss, max_segments;
  2444. u16 pseudo_hdr_offset, cksum_offset, queue;
  2445. int cum_len, seglen, boundary, rdma_count;
  2446. u8 flags, odd_flag;
  2447. queue = skb_get_queue_mapping(skb);
  2448. ss = &mgp->ss[queue];
  2449. netdev_queue = netdev_get_tx_queue(mgp->dev, queue);
  2450. tx = &ss->tx;
  2451. again:
  2452. req = tx->req_list;
  2453. avail = tx->mask - 1 - (tx->req - tx->done);
  2454. mss = 0;
  2455. max_segments = MXGEFW_MAX_SEND_DESC;
  2456. if (skb_is_gso(skb)) {
  2457. mss = skb_shinfo(skb)->gso_size;
  2458. max_segments = MYRI10GE_MAX_SEND_DESC_TSO;
  2459. }
  2460. if ((unlikely(avail < max_segments))) {
  2461. /* we are out of transmit resources */
  2462. tx->stop_queue++;
  2463. netif_tx_stop_queue(netdev_queue);
  2464. return NETDEV_TX_BUSY;
  2465. }
  2466. /* Setup checksum offloading, if needed */
  2467. cksum_offset = 0;
  2468. pseudo_hdr_offset = 0;
  2469. odd_flag = 0;
  2470. flags = (MXGEFW_FLAGS_NO_TSO | MXGEFW_FLAGS_FIRST);
  2471. if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
  2472. cksum_offset = skb_checksum_start_offset(skb);
  2473. pseudo_hdr_offset = cksum_offset + skb->csum_offset;
  2474. /* If the headers are excessively large, then we must
  2475. * fall back to a software checksum */
  2476. if (unlikely(!mss && (cksum_offset > 255 ||
  2477. pseudo_hdr_offset > 127))) {
  2478. if (skb_checksum_help(skb))
  2479. goto drop;
  2480. cksum_offset = 0;
  2481. pseudo_hdr_offset = 0;
  2482. } else {
  2483. odd_flag = MXGEFW_FLAGS_ALIGN_ODD;
  2484. flags |= MXGEFW_FLAGS_CKSUM;
  2485. }
  2486. }
  2487. cum_len = 0;
  2488. if (mss) { /* TSO */
  2489. /* this removes any CKSUM flag from before */
  2490. flags = (MXGEFW_FLAGS_TSO_HDR | MXGEFW_FLAGS_FIRST);
  2491. /* negative cum_len signifies to the
  2492. * send loop that we are still in the
  2493. * header portion of the TSO packet.
  2494. * TSO header can be at most 1KB long */
  2495. cum_len = -(skb_transport_offset(skb) + tcp_hdrlen(skb));
  2496. /* for IPv6 TSO, the checksum offset stores the
  2497. * TCP header length, to save the firmware from
  2498. * the need to parse the headers */
  2499. if (skb_is_gso_v6(skb)) {
  2500. cksum_offset = tcp_hdrlen(skb);
  2501. /* Can only handle headers <= max_tso6 long */
  2502. if (unlikely(-cum_len > mgp->max_tso6))
  2503. return myri10ge_sw_tso(skb, dev);
  2504. }
  2505. /* for TSO, pseudo_hdr_offset holds mss.
  2506. * The firmware figures out where to put
  2507. * the checksum by parsing the header. */
  2508. pseudo_hdr_offset = mss;
  2509. } else
  2510. /* Mark small packets, and pad out tiny packets */
  2511. if (skb->len <= MXGEFW_SEND_SMALL_SIZE) {
  2512. flags |= MXGEFW_FLAGS_SMALL;
  2513. /* pad frames to at least ETH_ZLEN bytes */
  2514. if (unlikely(skb->len < ETH_ZLEN)) {
  2515. if (skb_padto(skb, ETH_ZLEN)) {
  2516. /* The packet is gone, so we must
  2517. * return 0 */
  2518. ss->stats.tx_dropped += 1;
  2519. return NETDEV_TX_OK;
  2520. }
  2521. /* adjust the len to account for the zero pad
  2522. * so that the nic can know how long it is */
  2523. skb->len = ETH_ZLEN;
  2524. }
  2525. }
  2526. /* map the skb for DMA */
  2527. len = skb_headlen(skb);
  2528. idx = tx->req & tx->mask;
  2529. tx->info[idx].skb = skb;
  2530. bus = pci_map_single(mgp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  2531. dma_unmap_addr_set(&tx->info[idx], bus, bus);
  2532. dma_unmap_len_set(&tx->info[idx], len, len);
  2533. frag_cnt = skb_shinfo(skb)->nr_frags;
  2534. frag_idx = 0;
  2535. count = 0;
  2536. rdma_count = 0;
  2537. /* "rdma_count" is the number of RDMAs belonging to the
  2538. * current packet BEFORE the current send request. For
  2539. * non-TSO packets, this is equal to "count".
  2540. * For TSO packets, rdma_count needs to be reset
  2541. * to 0 after a segment cut.
  2542. *
  2543. * The rdma_count field of the send request is
  2544. * the number of RDMAs of the packet starting at
  2545. * that request. For TSO send requests with one ore more cuts
  2546. * in the middle, this is the number of RDMAs starting
  2547. * after the last cut in the request. All previous
  2548. * segments before the last cut implicitly have 1 RDMA.
  2549. *
  2550. * Since the number of RDMAs is not known beforehand,
  2551. * it must be filled-in retroactively - after each
  2552. * segmentation cut or at the end of the entire packet.
  2553. */
  2554. while (1) {
  2555. /* Break the SKB or Fragment up into pieces which
  2556. * do not cross mgp->tx_boundary */
  2557. low = MYRI10GE_LOWPART_TO_U32(bus);
  2558. high_swapped = htonl(MYRI10GE_HIGHPART_TO_U32(bus));
  2559. while (len) {
  2560. u8 flags_next;
  2561. int cum_len_next;
  2562. if (unlikely(count == max_segments))
  2563. goto abort_linearize;
  2564. boundary =
  2565. (low + mgp->tx_boundary) & ~(mgp->tx_boundary - 1);
  2566. seglen = boundary - low;
  2567. if (seglen > len)
  2568. seglen = len;
  2569. flags_next = flags & ~MXGEFW_FLAGS_FIRST;
  2570. cum_len_next = cum_len + seglen;
  2571. if (mss) { /* TSO */
  2572. (req - rdma_count)->rdma_count = rdma_count + 1;
  2573. if (likely(cum_len >= 0)) { /* payload */
  2574. int next_is_first, chop;
  2575. chop = (cum_len_next > mss);
  2576. cum_len_next = cum_len_next % mss;
  2577. next_is_first = (cum_len_next == 0);
  2578. flags |= chop * MXGEFW_FLAGS_TSO_CHOP;
  2579. flags_next |= next_is_first *
  2580. MXGEFW_FLAGS_FIRST;
  2581. rdma_count |= -(chop | next_is_first);
  2582. rdma_count += chop & ~next_is_first;
  2583. } else if (likely(cum_len_next >= 0)) { /* header ends */
  2584. int small;
  2585. rdma_count = -1;
  2586. cum_len_next = 0;
  2587. seglen = -cum_len;
  2588. small = (mss <= MXGEFW_SEND_SMALL_SIZE);
  2589. flags_next = MXGEFW_FLAGS_TSO_PLD |
  2590. MXGEFW_FLAGS_FIRST |
  2591. (small * MXGEFW_FLAGS_SMALL);
  2592. }
  2593. }
  2594. req->addr_high = high_swapped;
  2595. req->addr_low = htonl(low);
  2596. req->pseudo_hdr_offset = htons(pseudo_hdr_offset);
  2597. req->pad = 0; /* complete solid 16-byte block; does this matter? */
  2598. req->rdma_count = 1;
  2599. req->length = htons(seglen);
  2600. req->cksum_offset = cksum_offset;
  2601. req->flags = flags | ((cum_len & 1) * odd_flag);
  2602. low += seglen;
  2603. len -= seglen;
  2604. cum_len = cum_len_next;
  2605. flags = flags_next;
  2606. req++;
  2607. count++;
  2608. rdma_count++;
  2609. if (cksum_offset != 0 && !(mss && skb_is_gso_v6(skb))) {
  2610. if (unlikely(cksum_offset > seglen))
  2611. cksum_offset -= seglen;
  2612. else
  2613. cksum_offset = 0;
  2614. }
  2615. }
  2616. if (frag_idx == frag_cnt)
  2617. break;
  2618. /* map next fragment for DMA */
  2619. idx = (count + tx->req) & tx->mask;
  2620. frag = &skb_shinfo(skb)->frags[frag_idx];
  2621. frag_idx++;
  2622. len = skb_frag_size(frag);
  2623. bus = skb_frag_dma_map(&mgp->pdev->dev, frag, 0, len,
  2624. DMA_TO_DEVICE);
  2625. dma_unmap_addr_set(&tx->info[idx], bus, bus);
  2626. dma_unmap_len_set(&tx->info[idx], len, len);
  2627. }
  2628. (req - rdma_count)->rdma_count = rdma_count;
  2629. if (mss)
  2630. do {
  2631. req--;
  2632. req->flags |= MXGEFW_FLAGS_TSO_LAST;
  2633. } while (!(req->flags & (MXGEFW_FLAGS_TSO_CHOP |
  2634. MXGEFW_FLAGS_FIRST)));
  2635. idx = ((count - 1) + tx->req) & tx->mask;
  2636. tx->info[idx].last = 1;
  2637. myri10ge_submit_req(tx, tx->req_list, count);
  2638. /* if using multiple tx queues, make sure NIC polls the
  2639. * current slice */
  2640. if ((mgp->dev->real_num_tx_queues > 1) && tx->queue_active == 0) {
  2641. tx->queue_active = 1;
  2642. put_be32(htonl(1), tx->send_go);
  2643. mb();
  2644. mmiowb();
  2645. }
  2646. tx->pkt_start++;
  2647. if ((avail - count) < MXGEFW_MAX_SEND_DESC) {
  2648. tx->stop_queue++;
  2649. netif_tx_stop_queue(netdev_queue);
  2650. }
  2651. return NETDEV_TX_OK;
  2652. abort_linearize:
  2653. /* Free any DMA resources we've alloced and clear out the skb
  2654. * slot so as to not trip up assertions, and to avoid a
  2655. * double-free if linearizing fails */
  2656. last_idx = (idx + 1) & tx->mask;
  2657. idx = tx->req & tx->mask;
  2658. tx->info[idx].skb = NULL;
  2659. do {
  2660. len = dma_unmap_len(&tx->info[idx], len);
  2661. if (len) {
  2662. if (tx->info[idx].skb != NULL)
  2663. pci_unmap_single(mgp->pdev,
  2664. dma_unmap_addr(&tx->info[idx],
  2665. bus), len,
  2666. PCI_DMA_TODEVICE);
  2667. else
  2668. pci_unmap_page(mgp->pdev,
  2669. dma_unmap_addr(&tx->info[idx],
  2670. bus), len,
  2671. PCI_DMA_TODEVICE);
  2672. dma_unmap_len_set(&tx->info[idx], len, 0);
  2673. tx->info[idx].skb = NULL;
  2674. }
  2675. idx = (idx + 1) & tx->mask;
  2676. } while (idx != last_idx);
  2677. if (skb_is_gso(skb)) {
  2678. netdev_err(mgp->dev, "TSO but wanted to linearize?!?!?\n");
  2679. goto drop;
  2680. }
  2681. if (skb_linearize(skb))
  2682. goto drop;
  2683. tx->linearized++;
  2684. goto again;
  2685. drop:
  2686. dev_kfree_skb_any(skb);
  2687. ss->stats.tx_dropped += 1;
  2688. return NETDEV_TX_OK;
  2689. }
  2690. static netdev_tx_t myri10ge_sw_tso(struct sk_buff *skb,
  2691. struct net_device *dev)
  2692. {
  2693. struct sk_buff *segs, *curr;
  2694. struct myri10ge_priv *mgp = netdev_priv(dev);
  2695. struct myri10ge_slice_state *ss;
  2696. netdev_tx_t status;
  2697. segs = skb_gso_segment(skb, dev->features & ~NETIF_F_TSO6);
  2698. if (IS_ERR(segs))
  2699. goto drop;
  2700. while (segs) {
  2701. curr = segs;
  2702. segs = segs->next;
  2703. curr->next = NULL;
  2704. status = myri10ge_xmit(curr, dev);
  2705. if (status != 0) {
  2706. dev_kfree_skb_any(curr);
  2707. if (segs != NULL) {
  2708. curr = segs;
  2709. segs = segs->next;
  2710. curr->next = NULL;
  2711. dev_kfree_skb_any(segs);
  2712. }
  2713. goto drop;
  2714. }
  2715. }
  2716. dev_kfree_skb_any(skb);
  2717. return NETDEV_TX_OK;
  2718. drop:
  2719. ss = &mgp->ss[skb_get_queue_mapping(skb)];
  2720. dev_kfree_skb_any(skb);
  2721. ss->stats.tx_dropped += 1;
  2722. return NETDEV_TX_OK;
  2723. }
  2724. static struct rtnl_link_stats64 *myri10ge_get_stats(struct net_device *dev,
  2725. struct rtnl_link_stats64 *stats)
  2726. {
  2727. const struct myri10ge_priv *mgp = netdev_priv(dev);
  2728. const struct myri10ge_slice_netstats *slice_stats;
  2729. int i;
  2730. for (i = 0; i < mgp->num_slices; i++) {
  2731. slice_stats = &mgp->ss[i].stats;
  2732. stats->rx_packets += slice_stats->rx_packets;
  2733. stats->tx_packets += slice_stats->tx_packets;
  2734. stats->rx_bytes += slice_stats->rx_bytes;
  2735. stats->tx_bytes += slice_stats->tx_bytes;
  2736. stats->rx_dropped += slice_stats->rx_dropped;
  2737. stats->tx_dropped += slice_stats->tx_dropped;
  2738. }
  2739. return stats;
  2740. }
  2741. static void myri10ge_set_multicast_list(struct net_device *dev)
  2742. {
  2743. struct myri10ge_priv *mgp = netdev_priv(dev);
  2744. struct myri10ge_cmd cmd;
  2745. struct netdev_hw_addr *ha;
  2746. __be32 data[2] = { 0, 0 };
  2747. int err;
  2748. /* can be called from atomic contexts,
  2749. * pass 1 to force atomicity in myri10ge_send_cmd() */
  2750. myri10ge_change_promisc(mgp, dev->flags & IFF_PROMISC, 1);
  2751. /* This firmware is known to not support multicast */
  2752. if (!mgp->fw_multicast_support)
  2753. return;
  2754. /* Disable multicast filtering */
  2755. err = myri10ge_send_cmd(mgp, MXGEFW_ENABLE_ALLMULTI, &cmd, 1);
  2756. if (err != 0) {
  2757. netdev_err(dev, "Failed MXGEFW_ENABLE_ALLMULTI, error status: %d\n",
  2758. err);
  2759. goto abort;
  2760. }
  2761. if ((dev->flags & IFF_ALLMULTI) || mgp->adopted_rx_filter_bug) {
  2762. /* request to disable multicast filtering, so quit here */
  2763. return;
  2764. }
  2765. /* Flush the filters */
  2766. err = myri10ge_send_cmd(mgp, MXGEFW_LEAVE_ALL_MULTICAST_GROUPS,
  2767. &cmd, 1);
  2768. if (err != 0) {
  2769. netdev_err(dev, "Failed MXGEFW_LEAVE_ALL_MULTICAST_GROUPS, error status: %d\n",
  2770. err);
  2771. goto abort;
  2772. }
  2773. /* Walk the multicast list, and add each address */
  2774. netdev_for_each_mc_addr(ha, dev) {
  2775. memcpy(data, &ha->addr, 6);
  2776. cmd.data0 = ntohl(data[0]);
  2777. cmd.data1 = ntohl(data[1]);
  2778. err = myri10ge_send_cmd(mgp, MXGEFW_JOIN_MULTICAST_GROUP,
  2779. &cmd, 1);
  2780. if (err != 0) {
  2781. netdev_err(dev, "Failed MXGEFW_JOIN_MULTICAST_GROUP, error status:%d %pM\n",
  2782. err, ha->addr);
  2783. goto abort;
  2784. }
  2785. }
  2786. /* Enable multicast filtering */
  2787. err = myri10ge_send_cmd(mgp, MXGEFW_DISABLE_ALLMULTI, &cmd, 1);
  2788. if (err != 0) {
  2789. netdev_err(dev, "Failed MXGEFW_DISABLE_ALLMULTI, error status: %d\n",
  2790. err);
  2791. goto abort;
  2792. }
  2793. return;
  2794. abort:
  2795. return;
  2796. }
  2797. static int myri10ge_set_mac_address(struct net_device *dev, void *addr)
  2798. {
  2799. struct sockaddr *sa = addr;
  2800. struct myri10ge_priv *mgp = netdev_priv(dev);
  2801. int status;
  2802. if (!is_valid_ether_addr(sa->sa_data))
  2803. return -EADDRNOTAVAIL;
  2804. status = myri10ge_update_mac_address(mgp, sa->sa_data);
  2805. if (status != 0) {
  2806. netdev_err(dev, "changing mac address failed with %d\n",
  2807. status);
  2808. return status;
  2809. }
  2810. /* change the dev structure */
  2811. memcpy(dev->dev_addr, sa->sa_data, 6);
  2812. return 0;
  2813. }
  2814. static int myri10ge_change_mtu(struct net_device *dev, int new_mtu)
  2815. {
  2816. struct myri10ge_priv *mgp = netdev_priv(dev);
  2817. int error = 0;
  2818. if ((new_mtu < 68) || (ETH_HLEN + new_mtu > MYRI10GE_MAX_ETHER_MTU)) {
  2819. netdev_err(dev, "new mtu (%d) is not valid\n", new_mtu);
  2820. return -EINVAL;
  2821. }
  2822. netdev_info(dev, "changing mtu from %d to %d\n", dev->mtu, new_mtu);
  2823. if (mgp->running) {
  2824. /* if we change the mtu on an active device, we must
  2825. * reset the device so the firmware sees the change */
  2826. myri10ge_close(dev);
  2827. dev->mtu = new_mtu;
  2828. myri10ge_open(dev);
  2829. } else
  2830. dev->mtu = new_mtu;
  2831. return error;
  2832. }
  2833. /*
  2834. * Enable ECRC to align PCI-E Completion packets on an 8-byte boundary.
  2835. * Only do it if the bridge is a root port since we don't want to disturb
  2836. * any other device, except if forced with myri10ge_ecrc_enable > 1.
  2837. */
  2838. static void myri10ge_enable_ecrc(struct myri10ge_priv *mgp)
  2839. {
  2840. struct pci_dev *bridge = mgp->pdev->bus->self;
  2841. struct device *dev = &mgp->pdev->dev;
  2842. int cap;
  2843. unsigned err_cap;
  2844. int ret;
  2845. if (!myri10ge_ecrc_enable || !bridge)
  2846. return;
  2847. /* check that the bridge is a root port */
  2848. if (pci_pcie_type(bridge) != PCI_EXP_TYPE_ROOT_PORT) {
  2849. if (myri10ge_ecrc_enable > 1) {
  2850. struct pci_dev *prev_bridge, *old_bridge = bridge;
  2851. /* Walk the hierarchy up to the root port
  2852. * where ECRC has to be enabled */
  2853. do {
  2854. prev_bridge = bridge;
  2855. bridge = bridge->bus->self;
  2856. if (!bridge || prev_bridge == bridge) {
  2857. dev_err(dev,
  2858. "Failed to find root port"
  2859. " to force ECRC\n");
  2860. return;
  2861. }
  2862. } while (pci_pcie_type(bridge) !=
  2863. PCI_EXP_TYPE_ROOT_PORT);
  2864. dev_info(dev,
  2865. "Forcing ECRC on non-root port %s"
  2866. " (enabling on root port %s)\n",
  2867. pci_name(old_bridge), pci_name(bridge));
  2868. } else {
  2869. dev_err(dev,
  2870. "Not enabling ECRC on non-root port %s\n",
  2871. pci_name(bridge));
  2872. return;
  2873. }
  2874. }
  2875. cap = pci_find_ext_capability(bridge, PCI_EXT_CAP_ID_ERR);
  2876. if (!cap)
  2877. return;
  2878. ret = pci_read_config_dword(bridge, cap + PCI_ERR_CAP, &err_cap);
  2879. if (ret) {
  2880. dev_err(dev, "failed reading ext-conf-space of %s\n",
  2881. pci_name(bridge));
  2882. dev_err(dev, "\t pci=nommconf in use? "
  2883. "or buggy/incomplete/absent ACPI MCFG attr?\n");
  2884. return;
  2885. }
  2886. if (!(err_cap & PCI_ERR_CAP_ECRC_GENC))
  2887. return;
  2888. err_cap |= PCI_ERR_CAP_ECRC_GENE;
  2889. pci_write_config_dword(bridge, cap + PCI_ERR_CAP, err_cap);
  2890. dev_info(dev, "Enabled ECRC on upstream bridge %s\n", pci_name(bridge));
  2891. }
  2892. /*
  2893. * The Lanai Z8E PCI-E interface achieves higher Read-DMA throughput
  2894. * when the PCI-E Completion packets are aligned on an 8-byte
  2895. * boundary. Some PCI-E chip sets always align Completion packets; on
  2896. * the ones that do not, the alignment can be enforced by enabling
  2897. * ECRC generation (if supported).
  2898. *
  2899. * When PCI-E Completion packets are not aligned, it is actually more
  2900. * efficient to limit Read-DMA transactions to 2KB, rather than 4KB.
  2901. *
  2902. * If the driver can neither enable ECRC nor verify that it has
  2903. * already been enabled, then it must use a firmware image which works
  2904. * around unaligned completion packets (myri10ge_rss_ethp_z8e.dat), and it
  2905. * should also ensure that it never gives the device a Read-DMA which is
  2906. * larger than 2KB by setting the tx_boundary to 2KB. If ECRC is
  2907. * enabled, then the driver should use the aligned (myri10ge_rss_eth_z8e.dat)
  2908. * firmware image, and set tx_boundary to 4KB.
  2909. */
  2910. static void myri10ge_firmware_probe(struct myri10ge_priv *mgp)
  2911. {
  2912. struct pci_dev *pdev = mgp->pdev;
  2913. struct device *dev = &pdev->dev;
  2914. int status;
  2915. mgp->tx_boundary = 4096;
  2916. /*
  2917. * Verify the max read request size was set to 4KB
  2918. * before trying the test with 4KB.
  2919. */
  2920. status = pcie_get_readrq(pdev);
  2921. if (status < 0) {
  2922. dev_err(dev, "Couldn't read max read req size: %d\n", status);
  2923. goto abort;
  2924. }
  2925. if (status != 4096) {
  2926. dev_warn(dev, "Max Read Request size != 4096 (%d)\n", status);
  2927. mgp->tx_boundary = 2048;
  2928. }
  2929. /*
  2930. * load the optimized firmware (which assumes aligned PCIe
  2931. * completions) in order to see if it works on this host.
  2932. */
  2933. set_fw_name(mgp, myri10ge_fw_aligned, false);
  2934. status = myri10ge_load_firmware(mgp, 1);
  2935. if (status != 0) {
  2936. goto abort;
  2937. }
  2938. /*
  2939. * Enable ECRC if possible
  2940. */
  2941. myri10ge_enable_ecrc(mgp);
  2942. /*
  2943. * Run a DMA test which watches for unaligned completions and
  2944. * aborts on the first one seen.
  2945. */
  2946. status = myri10ge_dma_test(mgp, MXGEFW_CMD_UNALIGNED_TEST);
  2947. if (status == 0)
  2948. return; /* keep the aligned firmware */
  2949. if (status != -E2BIG)
  2950. dev_warn(dev, "DMA test failed: %d\n", status);
  2951. if (status == -ENOSYS)
  2952. dev_warn(dev, "Falling back to ethp! "
  2953. "Please install up to date fw\n");
  2954. abort:
  2955. /* fall back to using the unaligned firmware */
  2956. mgp->tx_boundary = 2048;
  2957. set_fw_name(mgp, myri10ge_fw_unaligned, false);
  2958. }
  2959. static void myri10ge_select_firmware(struct myri10ge_priv *mgp)
  2960. {
  2961. int overridden = 0;
  2962. if (myri10ge_force_firmware == 0) {
  2963. int link_width;
  2964. u16 lnk;
  2965. pcie_capability_read_word(mgp->pdev, PCI_EXP_LNKSTA, &lnk);
  2966. link_width = (lnk >> 4) & 0x3f;
  2967. /* Check to see if Link is less than 8 or if the
  2968. * upstream bridge is known to provide aligned
  2969. * completions */
  2970. if (link_width < 8) {
  2971. dev_info(&mgp->pdev->dev, "PCIE x%d Link\n",
  2972. link_width);
  2973. mgp->tx_boundary = 4096;
  2974. set_fw_name(mgp, myri10ge_fw_aligned, false);
  2975. } else {
  2976. myri10ge_firmware_probe(mgp);
  2977. }
  2978. } else {
  2979. if (myri10ge_force_firmware == 1) {
  2980. dev_info(&mgp->pdev->dev,
  2981. "Assuming aligned completions (forced)\n");
  2982. mgp->tx_boundary = 4096;
  2983. set_fw_name(mgp, myri10ge_fw_aligned, false);
  2984. } else {
  2985. dev_info(&mgp->pdev->dev,
  2986. "Assuming unaligned completions (forced)\n");
  2987. mgp->tx_boundary = 2048;
  2988. set_fw_name(mgp, myri10ge_fw_unaligned, false);
  2989. }
  2990. }
  2991. kparam_block_sysfs_write(myri10ge_fw_name);
  2992. if (myri10ge_fw_name != NULL) {
  2993. char *fw_name = kstrdup(myri10ge_fw_name, GFP_KERNEL);
  2994. if (fw_name) {
  2995. overridden = 1;
  2996. set_fw_name(mgp, fw_name, true);
  2997. }
  2998. }
  2999. kparam_unblock_sysfs_write(myri10ge_fw_name);
  3000. if (mgp->board_number < MYRI10GE_MAX_BOARDS &&
  3001. myri10ge_fw_names[mgp->board_number] != NULL &&
  3002. strlen(myri10ge_fw_names[mgp->board_number])) {
  3003. set_fw_name(mgp, myri10ge_fw_names[mgp->board_number], false);
  3004. overridden = 1;
  3005. }
  3006. if (overridden)
  3007. dev_info(&mgp->pdev->dev, "overriding firmware to %s\n",
  3008. mgp->fw_name);
  3009. }
  3010. static void myri10ge_mask_surprise_down(struct pci_dev *pdev)
  3011. {
  3012. struct pci_dev *bridge = pdev->bus->self;
  3013. int cap;
  3014. u32 mask;
  3015. if (bridge == NULL)
  3016. return;
  3017. cap = pci_find_ext_capability(bridge, PCI_EXT_CAP_ID_ERR);
  3018. if (cap) {
  3019. /* a sram parity error can cause a surprise link
  3020. * down; since we expect and can recover from sram
  3021. * parity errors, mask surprise link down events */
  3022. pci_read_config_dword(bridge, cap + PCI_ERR_UNCOR_MASK, &mask);
  3023. mask |= 0x20;
  3024. pci_write_config_dword(bridge, cap + PCI_ERR_UNCOR_MASK, mask);
  3025. }
  3026. }
  3027. #ifdef CONFIG_PM
  3028. static int myri10ge_suspend(struct pci_dev *pdev, pm_message_t state)
  3029. {
  3030. struct myri10ge_priv *mgp;
  3031. struct net_device *netdev;
  3032. mgp = pci_get_drvdata(pdev);
  3033. if (mgp == NULL)
  3034. return -EINVAL;
  3035. netdev = mgp->dev;
  3036. netif_device_detach(netdev);
  3037. if (netif_running(netdev)) {
  3038. netdev_info(netdev, "closing\n");
  3039. rtnl_lock();
  3040. myri10ge_close(netdev);
  3041. rtnl_unlock();
  3042. }
  3043. myri10ge_dummy_rdma(mgp, 0);
  3044. pci_save_state(pdev);
  3045. pci_disable_device(pdev);
  3046. return pci_set_power_state(pdev, pci_choose_state(pdev, state));
  3047. }
  3048. static int myri10ge_resume(struct pci_dev *pdev)
  3049. {
  3050. struct myri10ge_priv *mgp;
  3051. struct net_device *netdev;
  3052. int status;
  3053. u16 vendor;
  3054. mgp = pci_get_drvdata(pdev);
  3055. if (mgp == NULL)
  3056. return -EINVAL;
  3057. netdev = mgp->dev;
  3058. pci_set_power_state(pdev, PCI_D0); /* zeros conf space as a side effect */
  3059. msleep(5); /* give card time to respond */
  3060. pci_read_config_word(mgp->pdev, PCI_VENDOR_ID, &vendor);
  3061. if (vendor == 0xffff) {
  3062. netdev_err(mgp->dev, "device disappeared!\n");
  3063. return -EIO;
  3064. }
  3065. pci_restore_state(pdev);
  3066. status = pci_enable_device(pdev);
  3067. if (status) {
  3068. dev_err(&pdev->dev, "failed to enable device\n");
  3069. return status;
  3070. }
  3071. pci_set_master(pdev);
  3072. myri10ge_reset(mgp);
  3073. myri10ge_dummy_rdma(mgp, 1);
  3074. /* Save configuration space to be restored if the
  3075. * nic resets due to a parity error */
  3076. pci_save_state(pdev);
  3077. if (netif_running(netdev)) {
  3078. rtnl_lock();
  3079. status = myri10ge_open(netdev);
  3080. rtnl_unlock();
  3081. if (status != 0)
  3082. goto abort_with_enabled;
  3083. }
  3084. netif_device_attach(netdev);
  3085. return 0;
  3086. abort_with_enabled:
  3087. pci_disable_device(pdev);
  3088. return -EIO;
  3089. }
  3090. #endif /* CONFIG_PM */
  3091. static u32 myri10ge_read_reboot(struct myri10ge_priv *mgp)
  3092. {
  3093. struct pci_dev *pdev = mgp->pdev;
  3094. int vs = mgp->vendor_specific_offset;
  3095. u32 reboot;
  3096. /*enter read32 mode */
  3097. pci_write_config_byte(pdev, vs + 0x10, 0x3);
  3098. /*read REBOOT_STATUS (0xfffffff0) */
  3099. pci_write_config_dword(pdev, vs + 0x18, 0xfffffff0);
  3100. pci_read_config_dword(pdev, vs + 0x14, &reboot);
  3101. return reboot;
  3102. }
  3103. static void
  3104. myri10ge_check_slice(struct myri10ge_slice_state *ss, int *reset_needed,
  3105. int *busy_slice_cnt, u32 rx_pause_cnt)
  3106. {
  3107. struct myri10ge_priv *mgp = ss->mgp;
  3108. int slice = ss - mgp->ss;
  3109. if (ss->tx.req != ss->tx.done &&
  3110. ss->tx.done == ss->watchdog_tx_done &&
  3111. ss->watchdog_tx_req != ss->watchdog_tx_done) {
  3112. /* nic seems like it might be stuck.. */
  3113. if (rx_pause_cnt != mgp->watchdog_pause) {
  3114. if (net_ratelimit())
  3115. netdev_warn(mgp->dev, "slice %d: TX paused, "
  3116. "check link partner\n", slice);
  3117. } else {
  3118. netdev_warn(mgp->dev,
  3119. "slice %d: TX stuck %d %d %d %d %d %d\n",
  3120. slice, ss->tx.queue_active, ss->tx.req,
  3121. ss->tx.done, ss->tx.pkt_start,
  3122. ss->tx.pkt_done,
  3123. (int)ntohl(mgp->ss[slice].fw_stats->
  3124. send_done_count));
  3125. *reset_needed = 1;
  3126. ss->stuck = 1;
  3127. }
  3128. }
  3129. if (ss->watchdog_tx_done != ss->tx.done ||
  3130. ss->watchdog_rx_done != ss->rx_done.cnt) {
  3131. *busy_slice_cnt += 1;
  3132. }
  3133. ss->watchdog_tx_done = ss->tx.done;
  3134. ss->watchdog_tx_req = ss->tx.req;
  3135. ss->watchdog_rx_done = ss->rx_done.cnt;
  3136. }
  3137. /*
  3138. * This watchdog is used to check whether the board has suffered
  3139. * from a parity error and needs to be recovered.
  3140. */
  3141. static void myri10ge_watchdog(struct work_struct *work)
  3142. {
  3143. struct myri10ge_priv *mgp =
  3144. container_of(work, struct myri10ge_priv, watchdog_work);
  3145. struct myri10ge_slice_state *ss;
  3146. u32 reboot, rx_pause_cnt;
  3147. int status, rebooted;
  3148. int i;
  3149. int reset_needed = 0;
  3150. int busy_slice_cnt = 0;
  3151. u16 cmd, vendor;
  3152. mgp->watchdog_resets++;
  3153. pci_read_config_word(mgp->pdev, PCI_COMMAND, &cmd);
  3154. rebooted = 0;
  3155. if ((cmd & PCI_COMMAND_MASTER) == 0) {
  3156. /* Bus master DMA disabled? Check to see
  3157. * if the card rebooted due to a parity error
  3158. * For now, just report it */
  3159. reboot = myri10ge_read_reboot(mgp);
  3160. netdev_err(mgp->dev, "NIC rebooted (0x%x),%s resetting\n",
  3161. reboot, myri10ge_reset_recover ? "" : " not");
  3162. if (myri10ge_reset_recover == 0)
  3163. return;
  3164. rtnl_lock();
  3165. mgp->rebooted = 1;
  3166. rebooted = 1;
  3167. myri10ge_close(mgp->dev);
  3168. myri10ge_reset_recover--;
  3169. mgp->rebooted = 0;
  3170. /*
  3171. * A rebooted nic will come back with config space as
  3172. * it was after power was applied to PCIe bus.
  3173. * Attempt to restore config space which was saved
  3174. * when the driver was loaded, or the last time the
  3175. * nic was resumed from power saving mode.
  3176. */
  3177. pci_restore_state(mgp->pdev);
  3178. /* save state again for accounting reasons */
  3179. pci_save_state(mgp->pdev);
  3180. } else {
  3181. /* if we get back -1's from our slot, perhaps somebody
  3182. * powered off our card. Don't try to reset it in
  3183. * this case */
  3184. if (cmd == 0xffff) {
  3185. pci_read_config_word(mgp->pdev, PCI_VENDOR_ID, &vendor);
  3186. if (vendor == 0xffff) {
  3187. netdev_err(mgp->dev, "device disappeared!\n");
  3188. return;
  3189. }
  3190. }
  3191. /* Perhaps it is a software error. See if stuck slice
  3192. * has recovered, reset if not */
  3193. rx_pause_cnt = ntohl(mgp->ss[0].fw_stats->dropped_pause);
  3194. for (i = 0; i < mgp->num_slices; i++) {
  3195. ss = mgp->ss;
  3196. if (ss->stuck) {
  3197. myri10ge_check_slice(ss, &reset_needed,
  3198. &busy_slice_cnt,
  3199. rx_pause_cnt);
  3200. ss->stuck = 0;
  3201. }
  3202. }
  3203. if (!reset_needed) {
  3204. netdev_dbg(mgp->dev, "not resetting\n");
  3205. return;
  3206. }
  3207. netdev_err(mgp->dev, "device timeout, resetting\n");
  3208. }
  3209. if (!rebooted) {
  3210. rtnl_lock();
  3211. myri10ge_close(mgp->dev);
  3212. }
  3213. status = myri10ge_load_firmware(mgp, 1);
  3214. if (status != 0)
  3215. netdev_err(mgp->dev, "failed to load firmware\n");
  3216. else
  3217. myri10ge_open(mgp->dev);
  3218. rtnl_unlock();
  3219. }
  3220. /*
  3221. * We use our own timer routine rather than relying upon
  3222. * netdev->tx_timeout because we have a very large hardware transmit
  3223. * queue. Due to the large queue, the netdev->tx_timeout function
  3224. * cannot detect a NIC with a parity error in a timely fashion if the
  3225. * NIC is lightly loaded.
  3226. */
  3227. static void myri10ge_watchdog_timer(unsigned long arg)
  3228. {
  3229. struct myri10ge_priv *mgp;
  3230. struct myri10ge_slice_state *ss;
  3231. int i, reset_needed, busy_slice_cnt;
  3232. u32 rx_pause_cnt;
  3233. u16 cmd;
  3234. mgp = (struct myri10ge_priv *)arg;
  3235. rx_pause_cnt = ntohl(mgp->ss[0].fw_stats->dropped_pause);
  3236. busy_slice_cnt = 0;
  3237. for (i = 0, reset_needed = 0;
  3238. i < mgp->num_slices && reset_needed == 0; ++i) {
  3239. ss = &mgp->ss[i];
  3240. if (ss->rx_small.watchdog_needed) {
  3241. myri10ge_alloc_rx_pages(mgp, &ss->rx_small,
  3242. mgp->small_bytes + MXGEFW_PAD,
  3243. 1);
  3244. if (ss->rx_small.fill_cnt - ss->rx_small.cnt >=
  3245. myri10ge_fill_thresh)
  3246. ss->rx_small.watchdog_needed = 0;
  3247. }
  3248. if (ss->rx_big.watchdog_needed) {
  3249. myri10ge_alloc_rx_pages(mgp, &ss->rx_big,
  3250. mgp->big_bytes, 1);
  3251. if (ss->rx_big.fill_cnt - ss->rx_big.cnt >=
  3252. myri10ge_fill_thresh)
  3253. ss->rx_big.watchdog_needed = 0;
  3254. }
  3255. myri10ge_check_slice(ss, &reset_needed, &busy_slice_cnt,
  3256. rx_pause_cnt);
  3257. }
  3258. /* if we've sent or received no traffic, poll the NIC to
  3259. * ensure it is still there. Otherwise, we risk not noticing
  3260. * an error in a timely fashion */
  3261. if (busy_slice_cnt == 0) {
  3262. pci_read_config_word(mgp->pdev, PCI_COMMAND, &cmd);
  3263. if ((cmd & PCI_COMMAND_MASTER) == 0) {
  3264. reset_needed = 1;
  3265. }
  3266. }
  3267. mgp->watchdog_pause = rx_pause_cnt;
  3268. if (reset_needed) {
  3269. schedule_work(&mgp->watchdog_work);
  3270. } else {
  3271. /* rearm timer */
  3272. mod_timer(&mgp->watchdog_timer,
  3273. jiffies + myri10ge_watchdog_timeout * HZ);
  3274. }
  3275. }
  3276. static void myri10ge_free_slices(struct myri10ge_priv *mgp)
  3277. {
  3278. struct myri10ge_slice_state *ss;
  3279. struct pci_dev *pdev = mgp->pdev;
  3280. size_t bytes;
  3281. int i;
  3282. if (mgp->ss == NULL)
  3283. return;
  3284. for (i = 0; i < mgp->num_slices; i++) {
  3285. ss = &mgp->ss[i];
  3286. if (ss->rx_done.entry != NULL) {
  3287. bytes = mgp->max_intr_slots *
  3288. sizeof(*ss->rx_done.entry);
  3289. dma_free_coherent(&pdev->dev, bytes,
  3290. ss->rx_done.entry, ss->rx_done.bus);
  3291. ss->rx_done.entry = NULL;
  3292. }
  3293. if (ss->fw_stats != NULL) {
  3294. bytes = sizeof(*ss->fw_stats);
  3295. dma_free_coherent(&pdev->dev, bytes,
  3296. ss->fw_stats, ss->fw_stats_bus);
  3297. ss->fw_stats = NULL;
  3298. }
  3299. napi_hash_del(&ss->napi);
  3300. netif_napi_del(&ss->napi);
  3301. }
  3302. /* Wait till napi structs are no longer used, and then free ss. */
  3303. synchronize_rcu();
  3304. kfree(mgp->ss);
  3305. mgp->ss = NULL;
  3306. }
  3307. static int myri10ge_alloc_slices(struct myri10ge_priv *mgp)
  3308. {
  3309. struct myri10ge_slice_state *ss;
  3310. struct pci_dev *pdev = mgp->pdev;
  3311. size_t bytes;
  3312. int i;
  3313. bytes = sizeof(*mgp->ss) * mgp->num_slices;
  3314. mgp->ss = kzalloc(bytes, GFP_KERNEL);
  3315. if (mgp->ss == NULL) {
  3316. return -ENOMEM;
  3317. }
  3318. for (i = 0; i < mgp->num_slices; i++) {
  3319. ss = &mgp->ss[i];
  3320. bytes = mgp->max_intr_slots * sizeof(*ss->rx_done.entry);
  3321. ss->rx_done.entry = dma_zalloc_coherent(&pdev->dev, bytes,
  3322. &ss->rx_done.bus,
  3323. GFP_KERNEL);
  3324. if (ss->rx_done.entry == NULL)
  3325. goto abort;
  3326. bytes = sizeof(*ss->fw_stats);
  3327. ss->fw_stats = dma_alloc_coherent(&pdev->dev, bytes,
  3328. &ss->fw_stats_bus,
  3329. GFP_KERNEL);
  3330. if (ss->fw_stats == NULL)
  3331. goto abort;
  3332. ss->mgp = mgp;
  3333. ss->dev = mgp->dev;
  3334. netif_napi_add(ss->dev, &ss->napi, myri10ge_poll,
  3335. myri10ge_napi_weight);
  3336. napi_hash_add(&ss->napi);
  3337. }
  3338. return 0;
  3339. abort:
  3340. myri10ge_free_slices(mgp);
  3341. return -ENOMEM;
  3342. }
  3343. /*
  3344. * This function determines the number of slices supported.
  3345. * The number slices is the minimum of the number of CPUS,
  3346. * the number of MSI-X irqs supported, the number of slices
  3347. * supported by the firmware
  3348. */
  3349. static void myri10ge_probe_slices(struct myri10ge_priv *mgp)
  3350. {
  3351. struct myri10ge_cmd cmd;
  3352. struct pci_dev *pdev = mgp->pdev;
  3353. char *old_fw;
  3354. bool old_allocated;
  3355. int i, status, ncpus;
  3356. mgp->num_slices = 1;
  3357. ncpus = netif_get_num_default_rss_queues();
  3358. if (myri10ge_max_slices == 1 || !pdev->msix_cap ||
  3359. (myri10ge_max_slices == -1 && ncpus < 2))
  3360. return;
  3361. /* try to load the slice aware rss firmware */
  3362. old_fw = mgp->fw_name;
  3363. old_allocated = mgp->fw_name_allocated;
  3364. /* don't free old_fw if we override it. */
  3365. mgp->fw_name_allocated = false;
  3366. if (myri10ge_fw_name != NULL) {
  3367. dev_info(&mgp->pdev->dev, "overriding rss firmware to %s\n",
  3368. myri10ge_fw_name);
  3369. set_fw_name(mgp, myri10ge_fw_name, false);
  3370. } else if (old_fw == myri10ge_fw_aligned)
  3371. set_fw_name(mgp, myri10ge_fw_rss_aligned, false);
  3372. else
  3373. set_fw_name(mgp, myri10ge_fw_rss_unaligned, false);
  3374. status = myri10ge_load_firmware(mgp, 0);
  3375. if (status != 0) {
  3376. dev_info(&pdev->dev, "Rss firmware not found\n");
  3377. if (old_allocated)
  3378. kfree(old_fw);
  3379. return;
  3380. }
  3381. /* hit the board with a reset to ensure it is alive */
  3382. memset(&cmd, 0, sizeof(cmd));
  3383. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_RESET, &cmd, 0);
  3384. if (status != 0) {
  3385. dev_err(&mgp->pdev->dev, "failed reset\n");
  3386. goto abort_with_fw;
  3387. }
  3388. mgp->max_intr_slots = cmd.data0 / sizeof(struct mcp_slot);
  3389. /* tell it the size of the interrupt queues */
  3390. cmd.data0 = mgp->max_intr_slots * sizeof(struct mcp_slot);
  3391. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_INTRQ_SIZE, &cmd, 0);
  3392. if (status != 0) {
  3393. dev_err(&mgp->pdev->dev, "failed MXGEFW_CMD_SET_INTRQ_SIZE\n");
  3394. goto abort_with_fw;
  3395. }
  3396. /* ask the maximum number of slices it supports */
  3397. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_MAX_RSS_QUEUES, &cmd, 0);
  3398. if (status != 0)
  3399. goto abort_with_fw;
  3400. else
  3401. mgp->num_slices = cmd.data0;
  3402. /* Only allow multiple slices if MSI-X is usable */
  3403. if (!myri10ge_msi) {
  3404. goto abort_with_fw;
  3405. }
  3406. /* if the admin did not specify a limit to how many
  3407. * slices we should use, cap it automatically to the
  3408. * number of CPUs currently online */
  3409. if (myri10ge_max_slices == -1)
  3410. myri10ge_max_slices = ncpus;
  3411. if (mgp->num_slices > myri10ge_max_slices)
  3412. mgp->num_slices = myri10ge_max_slices;
  3413. /* Now try to allocate as many MSI-X vectors as we have
  3414. * slices. We give up on MSI-X if we can only get a single
  3415. * vector. */
  3416. mgp->msix_vectors = kcalloc(mgp->num_slices, sizeof(*mgp->msix_vectors),
  3417. GFP_KERNEL);
  3418. if (mgp->msix_vectors == NULL)
  3419. goto disable_msix;
  3420. for (i = 0; i < mgp->num_slices; i++) {
  3421. mgp->msix_vectors[i].entry = i;
  3422. }
  3423. while (mgp->num_slices > 1) {
  3424. /* make sure it is a power of two */
  3425. while (!is_power_of_2(mgp->num_slices))
  3426. mgp->num_slices--;
  3427. if (mgp->num_slices == 1)
  3428. goto disable_msix;
  3429. status = pci_enable_msix(pdev, mgp->msix_vectors,
  3430. mgp->num_slices);
  3431. if (status == 0) {
  3432. pci_disable_msix(pdev);
  3433. if (old_allocated)
  3434. kfree(old_fw);
  3435. return;
  3436. }
  3437. if (status > 0)
  3438. mgp->num_slices = status;
  3439. else
  3440. goto disable_msix;
  3441. }
  3442. disable_msix:
  3443. if (mgp->msix_vectors != NULL) {
  3444. kfree(mgp->msix_vectors);
  3445. mgp->msix_vectors = NULL;
  3446. }
  3447. abort_with_fw:
  3448. mgp->num_slices = 1;
  3449. set_fw_name(mgp, old_fw, old_allocated);
  3450. myri10ge_load_firmware(mgp, 0);
  3451. }
  3452. static const struct net_device_ops myri10ge_netdev_ops = {
  3453. .ndo_open = myri10ge_open,
  3454. .ndo_stop = myri10ge_close,
  3455. .ndo_start_xmit = myri10ge_xmit,
  3456. .ndo_get_stats64 = myri10ge_get_stats,
  3457. .ndo_validate_addr = eth_validate_addr,
  3458. .ndo_change_mtu = myri10ge_change_mtu,
  3459. .ndo_set_rx_mode = myri10ge_set_multicast_list,
  3460. .ndo_set_mac_address = myri10ge_set_mac_address,
  3461. #ifdef CONFIG_NET_RX_BUSY_POLL
  3462. .ndo_busy_poll = myri10ge_busy_poll,
  3463. #endif
  3464. };
  3465. static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  3466. {
  3467. struct net_device *netdev;
  3468. struct myri10ge_priv *mgp;
  3469. struct device *dev = &pdev->dev;
  3470. int i;
  3471. int status = -ENXIO;
  3472. int dac_enabled;
  3473. unsigned hdr_offset, ss_offset;
  3474. static int board_number;
  3475. netdev = alloc_etherdev_mq(sizeof(*mgp), MYRI10GE_MAX_SLICES);
  3476. if (netdev == NULL)
  3477. return -ENOMEM;
  3478. SET_NETDEV_DEV(netdev, &pdev->dev);
  3479. mgp = netdev_priv(netdev);
  3480. mgp->dev = netdev;
  3481. mgp->pdev = pdev;
  3482. mgp->pause = myri10ge_flow_control;
  3483. mgp->intr_coal_delay = myri10ge_intr_coal_delay;
  3484. mgp->msg_enable = netif_msg_init(myri10ge_debug, MYRI10GE_MSG_DEFAULT);
  3485. mgp->board_number = board_number;
  3486. init_waitqueue_head(&mgp->down_wq);
  3487. if (pci_enable_device(pdev)) {
  3488. dev_err(&pdev->dev, "pci_enable_device call failed\n");
  3489. status = -ENODEV;
  3490. goto abort_with_netdev;
  3491. }
  3492. /* Find the vendor-specific cap so we can check
  3493. * the reboot register later on */
  3494. mgp->vendor_specific_offset
  3495. = pci_find_capability(pdev, PCI_CAP_ID_VNDR);
  3496. /* Set our max read request to 4KB */
  3497. status = pcie_set_readrq(pdev, 4096);
  3498. if (status != 0) {
  3499. dev_err(&pdev->dev, "Error %d writing PCI_EXP_DEVCTL\n",
  3500. status);
  3501. goto abort_with_enabled;
  3502. }
  3503. myri10ge_mask_surprise_down(pdev);
  3504. pci_set_master(pdev);
  3505. dac_enabled = 1;
  3506. status = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
  3507. if (status != 0) {
  3508. dac_enabled = 0;
  3509. dev_err(&pdev->dev,
  3510. "64-bit pci address mask was refused, "
  3511. "trying 32-bit\n");
  3512. status = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  3513. }
  3514. if (status != 0) {
  3515. dev_err(&pdev->dev, "Error %d setting DMA mask\n", status);
  3516. goto abort_with_enabled;
  3517. }
  3518. (void)pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  3519. mgp->cmd = dma_alloc_coherent(&pdev->dev, sizeof(*mgp->cmd),
  3520. &mgp->cmd_bus, GFP_KERNEL);
  3521. if (mgp->cmd == NULL)
  3522. goto abort_with_enabled;
  3523. mgp->board_span = pci_resource_len(pdev, 0);
  3524. mgp->iomem_base = pci_resource_start(pdev, 0);
  3525. mgp->mtrr = -1;
  3526. mgp->wc_enabled = 0;
  3527. #ifdef CONFIG_MTRR
  3528. mgp->mtrr = mtrr_add(mgp->iomem_base, mgp->board_span,
  3529. MTRR_TYPE_WRCOMB, 1);
  3530. if (mgp->mtrr >= 0)
  3531. mgp->wc_enabled = 1;
  3532. #endif
  3533. mgp->sram = ioremap_wc(mgp->iomem_base, mgp->board_span);
  3534. if (mgp->sram == NULL) {
  3535. dev_err(&pdev->dev, "ioremap failed for %ld bytes at 0x%lx\n",
  3536. mgp->board_span, mgp->iomem_base);
  3537. status = -ENXIO;
  3538. goto abort_with_mtrr;
  3539. }
  3540. hdr_offset =
  3541. swab32(readl(mgp->sram + MCP_HEADER_PTR_OFFSET)) & 0xffffc;
  3542. ss_offset = hdr_offset + offsetof(struct mcp_gen_header, string_specs);
  3543. mgp->sram_size = swab32(readl(mgp->sram + ss_offset));
  3544. if (mgp->sram_size > mgp->board_span ||
  3545. mgp->sram_size <= MYRI10GE_FW_OFFSET) {
  3546. dev_err(&pdev->dev,
  3547. "invalid sram_size %dB or board span %ldB\n",
  3548. mgp->sram_size, mgp->board_span);
  3549. goto abort_with_ioremap;
  3550. }
  3551. memcpy_fromio(mgp->eeprom_strings,
  3552. mgp->sram + mgp->sram_size, MYRI10GE_EEPROM_STRINGS_SIZE);
  3553. memset(mgp->eeprom_strings + MYRI10GE_EEPROM_STRINGS_SIZE - 2, 0, 2);
  3554. status = myri10ge_read_mac_addr(mgp);
  3555. if (status)
  3556. goto abort_with_ioremap;
  3557. for (i = 0; i < ETH_ALEN; i++)
  3558. netdev->dev_addr[i] = mgp->mac_addr[i];
  3559. myri10ge_select_firmware(mgp);
  3560. status = myri10ge_load_firmware(mgp, 1);
  3561. if (status != 0) {
  3562. dev_err(&pdev->dev, "failed to load firmware\n");
  3563. goto abort_with_ioremap;
  3564. }
  3565. myri10ge_probe_slices(mgp);
  3566. status = myri10ge_alloc_slices(mgp);
  3567. if (status != 0) {
  3568. dev_err(&pdev->dev, "failed to alloc slice state\n");
  3569. goto abort_with_firmware;
  3570. }
  3571. netif_set_real_num_tx_queues(netdev, mgp->num_slices);
  3572. netif_set_real_num_rx_queues(netdev, mgp->num_slices);
  3573. status = myri10ge_reset(mgp);
  3574. if (status != 0) {
  3575. dev_err(&pdev->dev, "failed reset\n");
  3576. goto abort_with_slices;
  3577. }
  3578. #ifdef CONFIG_MYRI10GE_DCA
  3579. myri10ge_setup_dca(mgp);
  3580. #endif
  3581. pci_set_drvdata(pdev, mgp);
  3582. if ((myri10ge_initial_mtu + ETH_HLEN) > MYRI10GE_MAX_ETHER_MTU)
  3583. myri10ge_initial_mtu = MYRI10GE_MAX_ETHER_MTU - ETH_HLEN;
  3584. if ((myri10ge_initial_mtu + ETH_HLEN) < 68)
  3585. myri10ge_initial_mtu = 68;
  3586. netdev->netdev_ops = &myri10ge_netdev_ops;
  3587. netdev->mtu = myri10ge_initial_mtu;
  3588. netdev->hw_features = mgp->features | NETIF_F_RXCSUM;
  3589. /* fake NETIF_F_HW_VLAN_CTAG_RX for good GRO performance */
  3590. netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX;
  3591. netdev->features = netdev->hw_features;
  3592. if (dac_enabled)
  3593. netdev->features |= NETIF_F_HIGHDMA;
  3594. netdev->vlan_features |= mgp->features;
  3595. if (mgp->fw_ver_tiny < 37)
  3596. netdev->vlan_features &= ~NETIF_F_TSO6;
  3597. if (mgp->fw_ver_tiny < 32)
  3598. netdev->vlan_features &= ~NETIF_F_TSO;
  3599. /* make sure we can get an irq, and that MSI can be
  3600. * setup (if available). */
  3601. status = myri10ge_request_irq(mgp);
  3602. if (status != 0)
  3603. goto abort_with_firmware;
  3604. myri10ge_free_irq(mgp);
  3605. /* Save configuration space to be restored if the
  3606. * nic resets due to a parity error */
  3607. pci_save_state(pdev);
  3608. /* Setup the watchdog timer */
  3609. setup_timer(&mgp->watchdog_timer, myri10ge_watchdog_timer,
  3610. (unsigned long)mgp);
  3611. SET_ETHTOOL_OPS(netdev, &myri10ge_ethtool_ops);
  3612. INIT_WORK(&mgp->watchdog_work, myri10ge_watchdog);
  3613. status = register_netdev(netdev);
  3614. if (status != 0) {
  3615. dev_err(&pdev->dev, "register_netdev failed: %d\n", status);
  3616. goto abort_with_state;
  3617. }
  3618. if (mgp->msix_enabled)
  3619. dev_info(dev, "%d MSI-X IRQs, tx bndry %d, fw %s, WC %s\n",
  3620. mgp->num_slices, mgp->tx_boundary, mgp->fw_name,
  3621. (mgp->wc_enabled ? "Enabled" : "Disabled"));
  3622. else
  3623. dev_info(dev, "%s IRQ %d, tx bndry %d, fw %s, WC %s\n",
  3624. mgp->msi_enabled ? "MSI" : "xPIC",
  3625. pdev->irq, mgp->tx_boundary, mgp->fw_name,
  3626. (mgp->wc_enabled ? "Enabled" : "Disabled"));
  3627. board_number++;
  3628. return 0;
  3629. abort_with_state:
  3630. pci_restore_state(pdev);
  3631. abort_with_slices:
  3632. myri10ge_free_slices(mgp);
  3633. abort_with_firmware:
  3634. myri10ge_dummy_rdma(mgp, 0);
  3635. abort_with_ioremap:
  3636. if (mgp->mac_addr_string != NULL)
  3637. dev_err(&pdev->dev,
  3638. "myri10ge_probe() failed: MAC=%s, SN=%ld\n",
  3639. mgp->mac_addr_string, mgp->serial_number);
  3640. iounmap(mgp->sram);
  3641. abort_with_mtrr:
  3642. #ifdef CONFIG_MTRR
  3643. if (mgp->mtrr >= 0)
  3644. mtrr_del(mgp->mtrr, mgp->iomem_base, mgp->board_span);
  3645. #endif
  3646. dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd),
  3647. mgp->cmd, mgp->cmd_bus);
  3648. abort_with_enabled:
  3649. pci_disable_device(pdev);
  3650. abort_with_netdev:
  3651. set_fw_name(mgp, NULL, false);
  3652. free_netdev(netdev);
  3653. return status;
  3654. }
  3655. /*
  3656. * myri10ge_remove
  3657. *
  3658. * Does what is necessary to shutdown one Myrinet device. Called
  3659. * once for each Myrinet card by the kernel when a module is
  3660. * unloaded.
  3661. */
  3662. static void myri10ge_remove(struct pci_dev *pdev)
  3663. {
  3664. struct myri10ge_priv *mgp;
  3665. struct net_device *netdev;
  3666. mgp = pci_get_drvdata(pdev);
  3667. if (mgp == NULL)
  3668. return;
  3669. cancel_work_sync(&mgp->watchdog_work);
  3670. netdev = mgp->dev;
  3671. unregister_netdev(netdev);
  3672. #ifdef CONFIG_MYRI10GE_DCA
  3673. myri10ge_teardown_dca(mgp);
  3674. #endif
  3675. myri10ge_dummy_rdma(mgp, 0);
  3676. /* avoid a memory leak */
  3677. pci_restore_state(pdev);
  3678. iounmap(mgp->sram);
  3679. #ifdef CONFIG_MTRR
  3680. if (mgp->mtrr >= 0)
  3681. mtrr_del(mgp->mtrr, mgp->iomem_base, mgp->board_span);
  3682. #endif
  3683. myri10ge_free_slices(mgp);
  3684. if (mgp->msix_vectors != NULL)
  3685. kfree(mgp->msix_vectors);
  3686. dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd),
  3687. mgp->cmd, mgp->cmd_bus);
  3688. set_fw_name(mgp, NULL, false);
  3689. free_netdev(netdev);
  3690. pci_disable_device(pdev);
  3691. pci_set_drvdata(pdev, NULL);
  3692. }
  3693. #define PCI_DEVICE_ID_MYRICOM_MYRI10GE_Z8E 0x0008
  3694. #define PCI_DEVICE_ID_MYRICOM_MYRI10GE_Z8E_9 0x0009
  3695. static DEFINE_PCI_DEVICE_TABLE(myri10ge_pci_tbl) = {
  3696. {PCI_DEVICE(PCI_VENDOR_ID_MYRICOM, PCI_DEVICE_ID_MYRICOM_MYRI10GE_Z8E)},
  3697. {PCI_DEVICE
  3698. (PCI_VENDOR_ID_MYRICOM, PCI_DEVICE_ID_MYRICOM_MYRI10GE_Z8E_9)},
  3699. {0},
  3700. };
  3701. MODULE_DEVICE_TABLE(pci, myri10ge_pci_tbl);
  3702. static struct pci_driver myri10ge_driver = {
  3703. .name = "myri10ge",
  3704. .probe = myri10ge_probe,
  3705. .remove = myri10ge_remove,
  3706. .id_table = myri10ge_pci_tbl,
  3707. #ifdef CONFIG_PM
  3708. .suspend = myri10ge_suspend,
  3709. .resume = myri10ge_resume,
  3710. #endif
  3711. };
  3712. #ifdef CONFIG_MYRI10GE_DCA
  3713. static int
  3714. myri10ge_notify_dca(struct notifier_block *nb, unsigned long event, void *p)
  3715. {
  3716. int err = driver_for_each_device(&myri10ge_driver.driver,
  3717. NULL, &event,
  3718. myri10ge_notify_dca_device);
  3719. if (err)
  3720. return NOTIFY_BAD;
  3721. return NOTIFY_DONE;
  3722. }
  3723. static struct notifier_block myri10ge_dca_notifier = {
  3724. .notifier_call = myri10ge_notify_dca,
  3725. .next = NULL,
  3726. .priority = 0,
  3727. };
  3728. #endif /* CONFIG_MYRI10GE_DCA */
  3729. static __init int myri10ge_init_module(void)
  3730. {
  3731. pr_info("Version %s\n", MYRI10GE_VERSION_STR);
  3732. if (myri10ge_rss_hash > MXGEFW_RSS_HASH_TYPE_MAX) {
  3733. pr_err("Illegal rssh hash type %d, defaulting to source port\n",
  3734. myri10ge_rss_hash);
  3735. myri10ge_rss_hash = MXGEFW_RSS_HASH_TYPE_SRC_PORT;
  3736. }
  3737. #ifdef CONFIG_MYRI10GE_DCA
  3738. dca_register_notify(&myri10ge_dca_notifier);
  3739. #endif
  3740. if (myri10ge_max_slices > MYRI10GE_MAX_SLICES)
  3741. myri10ge_max_slices = MYRI10GE_MAX_SLICES;
  3742. return pci_register_driver(&myri10ge_driver);
  3743. }
  3744. module_init(myri10ge_init_module);
  3745. static __exit void myri10ge_cleanup_module(void)
  3746. {
  3747. #ifdef CONFIG_MYRI10GE_DCA
  3748. dca_unregister_notify(&myri10ge_dca_notifier);
  3749. #endif
  3750. pci_unregister_driver(&myri10ge_driver);
  3751. }
  3752. module_exit(myri10ge_cleanup_module);