myri10ge.c 117 KB

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