myri10ge.c 117 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289
  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_name, "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. skb_mark_napi_id(skb, &ss->napi);
  1303. if (polling) {
  1304. int hlen;
  1305. /* myri10ge_vlan_rx might have moved the header, so compute
  1306. * length and address again.
  1307. */
  1308. hlen = MYRI10GE_HLEN > skb->len ? skb->len : MYRI10GE_HLEN;
  1309. va = page_address(skb_frag_page(&rx_frags[0])) +
  1310. rx_frags[0].page_offset;
  1311. /* Copy header into the skb linear memory */
  1312. skb_copy_to_linear_data(skb, va, hlen);
  1313. rx_frags[0].page_offset += hlen;
  1314. rx_frags[0].size -= hlen;
  1315. skb->data_len -= hlen;
  1316. skb->tail += hlen;
  1317. skb->protocol = eth_type_trans(skb, dev);
  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. local_bh_disable(); /* myri10ge_ss_lock_napi needs bh disabled */
  2334. for (i = 0; i < mgp->num_slices; i++) {
  2335. napi_disable(&mgp->ss[i].napi);
  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. }
  2345. local_bh_enable();
  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. if ((new_mtu < 68) || (ETH_HLEN + new_mtu > MYRI10GE_MAX_ETHER_MTU)) {
  2829. netdev_err(dev, "new mtu (%d) is not valid\n", new_mtu);
  2830. return -EINVAL;
  2831. }
  2832. netdev_info(dev, "changing mtu from %d to %d\n", dev->mtu, new_mtu);
  2833. if (mgp->running) {
  2834. /* if we change the mtu on an active device, we must
  2835. * reset the device so the firmware sees the change */
  2836. myri10ge_close(dev);
  2837. dev->mtu = new_mtu;
  2838. myri10ge_open(dev);
  2839. } else
  2840. dev->mtu = new_mtu;
  2841. return error;
  2842. }
  2843. /*
  2844. * Enable ECRC to align PCI-E Completion packets on an 8-byte boundary.
  2845. * Only do it if the bridge is a root port since we don't want to disturb
  2846. * any other device, except if forced with myri10ge_ecrc_enable > 1.
  2847. */
  2848. static void myri10ge_enable_ecrc(struct myri10ge_priv *mgp)
  2849. {
  2850. struct pci_dev *bridge = mgp->pdev->bus->self;
  2851. struct device *dev = &mgp->pdev->dev;
  2852. int cap;
  2853. unsigned err_cap;
  2854. int ret;
  2855. if (!myri10ge_ecrc_enable || !bridge)
  2856. return;
  2857. /* check that the bridge is a root port */
  2858. if (pci_pcie_type(bridge) != PCI_EXP_TYPE_ROOT_PORT) {
  2859. if (myri10ge_ecrc_enable > 1) {
  2860. struct pci_dev *prev_bridge, *old_bridge = bridge;
  2861. /* Walk the hierarchy up to the root port
  2862. * where ECRC has to be enabled */
  2863. do {
  2864. prev_bridge = bridge;
  2865. bridge = bridge->bus->self;
  2866. if (!bridge || prev_bridge == bridge) {
  2867. dev_err(dev,
  2868. "Failed to find root port"
  2869. " to force ECRC\n");
  2870. return;
  2871. }
  2872. } while (pci_pcie_type(bridge) !=
  2873. PCI_EXP_TYPE_ROOT_PORT);
  2874. dev_info(dev,
  2875. "Forcing ECRC on non-root port %s"
  2876. " (enabling on root port %s)\n",
  2877. pci_name(old_bridge), pci_name(bridge));
  2878. } else {
  2879. dev_err(dev,
  2880. "Not enabling ECRC on non-root port %s\n",
  2881. pci_name(bridge));
  2882. return;
  2883. }
  2884. }
  2885. cap = pci_find_ext_capability(bridge, PCI_EXT_CAP_ID_ERR);
  2886. if (!cap)
  2887. return;
  2888. ret = pci_read_config_dword(bridge, cap + PCI_ERR_CAP, &err_cap);
  2889. if (ret) {
  2890. dev_err(dev, "failed reading ext-conf-space of %s\n",
  2891. pci_name(bridge));
  2892. dev_err(dev, "\t pci=nommconf in use? "
  2893. "or buggy/incomplete/absent ACPI MCFG attr?\n");
  2894. return;
  2895. }
  2896. if (!(err_cap & PCI_ERR_CAP_ECRC_GENC))
  2897. return;
  2898. err_cap |= PCI_ERR_CAP_ECRC_GENE;
  2899. pci_write_config_dword(bridge, cap + PCI_ERR_CAP, err_cap);
  2900. dev_info(dev, "Enabled ECRC on upstream bridge %s\n", pci_name(bridge));
  2901. }
  2902. /*
  2903. * The Lanai Z8E PCI-E interface achieves higher Read-DMA throughput
  2904. * when the PCI-E Completion packets are aligned on an 8-byte
  2905. * boundary. Some PCI-E chip sets always align Completion packets; on
  2906. * the ones that do not, the alignment can be enforced by enabling
  2907. * ECRC generation (if supported).
  2908. *
  2909. * When PCI-E Completion packets are not aligned, it is actually more
  2910. * efficient to limit Read-DMA transactions to 2KB, rather than 4KB.
  2911. *
  2912. * If the driver can neither enable ECRC nor verify that it has
  2913. * already been enabled, then it must use a firmware image which works
  2914. * around unaligned completion packets (myri10ge_rss_ethp_z8e.dat), and it
  2915. * should also ensure that it never gives the device a Read-DMA which is
  2916. * larger than 2KB by setting the tx_boundary to 2KB. If ECRC is
  2917. * enabled, then the driver should use the aligned (myri10ge_rss_eth_z8e.dat)
  2918. * firmware image, and set tx_boundary to 4KB.
  2919. */
  2920. static void myri10ge_firmware_probe(struct myri10ge_priv *mgp)
  2921. {
  2922. struct pci_dev *pdev = mgp->pdev;
  2923. struct device *dev = &pdev->dev;
  2924. int status;
  2925. mgp->tx_boundary = 4096;
  2926. /*
  2927. * Verify the max read request size was set to 4KB
  2928. * before trying the test with 4KB.
  2929. */
  2930. status = pcie_get_readrq(pdev);
  2931. if (status < 0) {
  2932. dev_err(dev, "Couldn't read max read req size: %d\n", status);
  2933. goto abort;
  2934. }
  2935. if (status != 4096) {
  2936. dev_warn(dev, "Max Read Request size != 4096 (%d)\n", status);
  2937. mgp->tx_boundary = 2048;
  2938. }
  2939. /*
  2940. * load the optimized firmware (which assumes aligned PCIe
  2941. * completions) in order to see if it works on this host.
  2942. */
  2943. set_fw_name(mgp, myri10ge_fw_aligned, false);
  2944. status = myri10ge_load_firmware(mgp, 1);
  2945. if (status != 0) {
  2946. goto abort;
  2947. }
  2948. /*
  2949. * Enable ECRC if possible
  2950. */
  2951. myri10ge_enable_ecrc(mgp);
  2952. /*
  2953. * Run a DMA test which watches for unaligned completions and
  2954. * aborts on the first one seen.
  2955. */
  2956. status = myri10ge_dma_test(mgp, MXGEFW_CMD_UNALIGNED_TEST);
  2957. if (status == 0)
  2958. return; /* keep the aligned firmware */
  2959. if (status != -E2BIG)
  2960. dev_warn(dev, "DMA test failed: %d\n", status);
  2961. if (status == -ENOSYS)
  2962. dev_warn(dev, "Falling back to ethp! "
  2963. "Please install up to date fw\n");
  2964. abort:
  2965. /* fall back to using the unaligned firmware */
  2966. mgp->tx_boundary = 2048;
  2967. set_fw_name(mgp, myri10ge_fw_unaligned, false);
  2968. }
  2969. static void myri10ge_select_firmware(struct myri10ge_priv *mgp)
  2970. {
  2971. int overridden = 0;
  2972. if (myri10ge_force_firmware == 0) {
  2973. int link_width;
  2974. u16 lnk;
  2975. pcie_capability_read_word(mgp->pdev, PCI_EXP_LNKSTA, &lnk);
  2976. link_width = (lnk >> 4) & 0x3f;
  2977. /* Check to see if Link is less than 8 or if the
  2978. * upstream bridge is known to provide aligned
  2979. * completions */
  2980. if (link_width < 8) {
  2981. dev_info(&mgp->pdev->dev, "PCIE x%d Link\n",
  2982. link_width);
  2983. mgp->tx_boundary = 4096;
  2984. set_fw_name(mgp, myri10ge_fw_aligned, false);
  2985. } else {
  2986. myri10ge_firmware_probe(mgp);
  2987. }
  2988. } else {
  2989. if (myri10ge_force_firmware == 1) {
  2990. dev_info(&mgp->pdev->dev,
  2991. "Assuming aligned completions (forced)\n");
  2992. mgp->tx_boundary = 4096;
  2993. set_fw_name(mgp, myri10ge_fw_aligned, false);
  2994. } else {
  2995. dev_info(&mgp->pdev->dev,
  2996. "Assuming unaligned completions (forced)\n");
  2997. mgp->tx_boundary = 2048;
  2998. set_fw_name(mgp, myri10ge_fw_unaligned, false);
  2999. }
  3000. }
  3001. kernel_param_lock(THIS_MODULE);
  3002. if (myri10ge_fw_name != NULL) {
  3003. char *fw_name = kstrdup(myri10ge_fw_name, GFP_KERNEL);
  3004. if (fw_name) {
  3005. overridden = 1;
  3006. set_fw_name(mgp, fw_name, true);
  3007. }
  3008. }
  3009. kernel_param_unlock(THIS_MODULE);
  3010. if (mgp->board_number < MYRI10GE_MAX_BOARDS &&
  3011. myri10ge_fw_names[mgp->board_number] != NULL &&
  3012. strlen(myri10ge_fw_names[mgp->board_number])) {
  3013. set_fw_name(mgp, myri10ge_fw_names[mgp->board_number], false);
  3014. overridden = 1;
  3015. }
  3016. if (overridden)
  3017. dev_info(&mgp->pdev->dev, "overriding firmware to %s\n",
  3018. mgp->fw_name);
  3019. }
  3020. static void myri10ge_mask_surprise_down(struct pci_dev *pdev)
  3021. {
  3022. struct pci_dev *bridge = pdev->bus->self;
  3023. int cap;
  3024. u32 mask;
  3025. if (bridge == NULL)
  3026. return;
  3027. cap = pci_find_ext_capability(bridge, PCI_EXT_CAP_ID_ERR);
  3028. if (cap) {
  3029. /* a sram parity error can cause a surprise link
  3030. * down; since we expect and can recover from sram
  3031. * parity errors, mask surprise link down events */
  3032. pci_read_config_dword(bridge, cap + PCI_ERR_UNCOR_MASK, &mask);
  3033. mask |= 0x20;
  3034. pci_write_config_dword(bridge, cap + PCI_ERR_UNCOR_MASK, mask);
  3035. }
  3036. }
  3037. #ifdef CONFIG_PM
  3038. static int myri10ge_suspend(struct pci_dev *pdev, pm_message_t state)
  3039. {
  3040. struct myri10ge_priv *mgp;
  3041. struct net_device *netdev;
  3042. mgp = pci_get_drvdata(pdev);
  3043. if (mgp == NULL)
  3044. return -EINVAL;
  3045. netdev = mgp->dev;
  3046. netif_device_detach(netdev);
  3047. if (netif_running(netdev)) {
  3048. netdev_info(netdev, "closing\n");
  3049. rtnl_lock();
  3050. myri10ge_close(netdev);
  3051. rtnl_unlock();
  3052. }
  3053. myri10ge_dummy_rdma(mgp, 0);
  3054. pci_save_state(pdev);
  3055. pci_disable_device(pdev);
  3056. return pci_set_power_state(pdev, pci_choose_state(pdev, state));
  3057. }
  3058. static int myri10ge_resume(struct pci_dev *pdev)
  3059. {
  3060. struct myri10ge_priv *mgp;
  3061. struct net_device *netdev;
  3062. int status;
  3063. u16 vendor;
  3064. mgp = pci_get_drvdata(pdev);
  3065. if (mgp == NULL)
  3066. return -EINVAL;
  3067. netdev = mgp->dev;
  3068. pci_set_power_state(pdev, PCI_D0); /* zeros conf space as a side effect */
  3069. msleep(5); /* give card time to respond */
  3070. pci_read_config_word(mgp->pdev, PCI_VENDOR_ID, &vendor);
  3071. if (vendor == 0xffff) {
  3072. netdev_err(mgp->dev, "device disappeared!\n");
  3073. return -EIO;
  3074. }
  3075. pci_restore_state(pdev);
  3076. status = pci_enable_device(pdev);
  3077. if (status) {
  3078. dev_err(&pdev->dev, "failed to enable device\n");
  3079. return status;
  3080. }
  3081. pci_set_master(pdev);
  3082. myri10ge_reset(mgp);
  3083. myri10ge_dummy_rdma(mgp, 1);
  3084. /* Save configuration space to be restored if the
  3085. * nic resets due to a parity error */
  3086. pci_save_state(pdev);
  3087. if (netif_running(netdev)) {
  3088. rtnl_lock();
  3089. status = myri10ge_open(netdev);
  3090. rtnl_unlock();
  3091. if (status != 0)
  3092. goto abort_with_enabled;
  3093. }
  3094. netif_device_attach(netdev);
  3095. return 0;
  3096. abort_with_enabled:
  3097. pci_disable_device(pdev);
  3098. return -EIO;
  3099. }
  3100. #endif /* CONFIG_PM */
  3101. static u32 myri10ge_read_reboot(struct myri10ge_priv *mgp)
  3102. {
  3103. struct pci_dev *pdev = mgp->pdev;
  3104. int vs = mgp->vendor_specific_offset;
  3105. u32 reboot;
  3106. /*enter read32 mode */
  3107. pci_write_config_byte(pdev, vs + 0x10, 0x3);
  3108. /*read REBOOT_STATUS (0xfffffff0) */
  3109. pci_write_config_dword(pdev, vs + 0x18, 0xfffffff0);
  3110. pci_read_config_dword(pdev, vs + 0x14, &reboot);
  3111. return reboot;
  3112. }
  3113. static void
  3114. myri10ge_check_slice(struct myri10ge_slice_state *ss, int *reset_needed,
  3115. int *busy_slice_cnt, u32 rx_pause_cnt)
  3116. {
  3117. struct myri10ge_priv *mgp = ss->mgp;
  3118. int slice = ss - mgp->ss;
  3119. if (ss->tx.req != ss->tx.done &&
  3120. ss->tx.done == ss->watchdog_tx_done &&
  3121. ss->watchdog_tx_req != ss->watchdog_tx_done) {
  3122. /* nic seems like it might be stuck.. */
  3123. if (rx_pause_cnt != mgp->watchdog_pause) {
  3124. if (net_ratelimit())
  3125. netdev_warn(mgp->dev, "slice %d: TX paused, "
  3126. "check link partner\n", slice);
  3127. } else {
  3128. netdev_warn(mgp->dev,
  3129. "slice %d: TX stuck %d %d %d %d %d %d\n",
  3130. slice, ss->tx.queue_active, ss->tx.req,
  3131. ss->tx.done, ss->tx.pkt_start,
  3132. ss->tx.pkt_done,
  3133. (int)ntohl(mgp->ss[slice].fw_stats->
  3134. send_done_count));
  3135. *reset_needed = 1;
  3136. ss->stuck = 1;
  3137. }
  3138. }
  3139. if (ss->watchdog_tx_done != ss->tx.done ||
  3140. ss->watchdog_rx_done != ss->rx_done.cnt) {
  3141. *busy_slice_cnt += 1;
  3142. }
  3143. ss->watchdog_tx_done = ss->tx.done;
  3144. ss->watchdog_tx_req = ss->tx.req;
  3145. ss->watchdog_rx_done = ss->rx_done.cnt;
  3146. }
  3147. /*
  3148. * This watchdog is used to check whether the board has suffered
  3149. * from a parity error and needs to be recovered.
  3150. */
  3151. static void myri10ge_watchdog(struct work_struct *work)
  3152. {
  3153. struct myri10ge_priv *mgp =
  3154. container_of(work, struct myri10ge_priv, watchdog_work);
  3155. struct myri10ge_slice_state *ss;
  3156. u32 reboot, rx_pause_cnt;
  3157. int status, rebooted;
  3158. int i;
  3159. int reset_needed = 0;
  3160. int busy_slice_cnt = 0;
  3161. u16 cmd, vendor;
  3162. mgp->watchdog_resets++;
  3163. pci_read_config_word(mgp->pdev, PCI_COMMAND, &cmd);
  3164. rebooted = 0;
  3165. if ((cmd & PCI_COMMAND_MASTER) == 0) {
  3166. /* Bus master DMA disabled? Check to see
  3167. * if the card rebooted due to a parity error
  3168. * For now, just report it */
  3169. reboot = myri10ge_read_reboot(mgp);
  3170. netdev_err(mgp->dev, "NIC rebooted (0x%x),%s resetting\n",
  3171. reboot, myri10ge_reset_recover ? "" : " not");
  3172. if (myri10ge_reset_recover == 0)
  3173. return;
  3174. rtnl_lock();
  3175. mgp->rebooted = 1;
  3176. rebooted = 1;
  3177. myri10ge_close(mgp->dev);
  3178. myri10ge_reset_recover--;
  3179. mgp->rebooted = 0;
  3180. /*
  3181. * A rebooted nic will come back with config space as
  3182. * it was after power was applied to PCIe bus.
  3183. * Attempt to restore config space which was saved
  3184. * when the driver was loaded, or the last time the
  3185. * nic was resumed from power saving mode.
  3186. */
  3187. pci_restore_state(mgp->pdev);
  3188. /* save state again for accounting reasons */
  3189. pci_save_state(mgp->pdev);
  3190. } else {
  3191. /* if we get back -1's from our slot, perhaps somebody
  3192. * powered off our card. Don't try to reset it in
  3193. * this case */
  3194. if (cmd == 0xffff) {
  3195. pci_read_config_word(mgp->pdev, PCI_VENDOR_ID, &vendor);
  3196. if (vendor == 0xffff) {
  3197. netdev_err(mgp->dev, "device disappeared!\n");
  3198. return;
  3199. }
  3200. }
  3201. /* Perhaps it is a software error. See if stuck slice
  3202. * has recovered, reset if not */
  3203. rx_pause_cnt = ntohl(mgp->ss[0].fw_stats->dropped_pause);
  3204. for (i = 0; i < mgp->num_slices; i++) {
  3205. ss = mgp->ss;
  3206. if (ss->stuck) {
  3207. myri10ge_check_slice(ss, &reset_needed,
  3208. &busy_slice_cnt,
  3209. rx_pause_cnt);
  3210. ss->stuck = 0;
  3211. }
  3212. }
  3213. if (!reset_needed) {
  3214. netdev_dbg(mgp->dev, "not resetting\n");
  3215. return;
  3216. }
  3217. netdev_err(mgp->dev, "device timeout, resetting\n");
  3218. }
  3219. if (!rebooted) {
  3220. rtnl_lock();
  3221. myri10ge_close(mgp->dev);
  3222. }
  3223. status = myri10ge_load_firmware(mgp, 1);
  3224. if (status != 0)
  3225. netdev_err(mgp->dev, "failed to load firmware\n");
  3226. else
  3227. myri10ge_open(mgp->dev);
  3228. rtnl_unlock();
  3229. }
  3230. /*
  3231. * We use our own timer routine rather than relying upon
  3232. * netdev->tx_timeout because we have a very large hardware transmit
  3233. * queue. Due to the large queue, the netdev->tx_timeout function
  3234. * cannot detect a NIC with a parity error in a timely fashion if the
  3235. * NIC is lightly loaded.
  3236. */
  3237. static void myri10ge_watchdog_timer(unsigned long arg)
  3238. {
  3239. struct myri10ge_priv *mgp;
  3240. struct myri10ge_slice_state *ss;
  3241. int i, reset_needed, busy_slice_cnt;
  3242. u32 rx_pause_cnt;
  3243. u16 cmd;
  3244. mgp = (struct myri10ge_priv *)arg;
  3245. rx_pause_cnt = ntohl(mgp->ss[0].fw_stats->dropped_pause);
  3246. busy_slice_cnt = 0;
  3247. for (i = 0, reset_needed = 0;
  3248. i < mgp->num_slices && reset_needed == 0; ++i) {
  3249. ss = &mgp->ss[i];
  3250. if (ss->rx_small.watchdog_needed) {
  3251. myri10ge_alloc_rx_pages(mgp, &ss->rx_small,
  3252. mgp->small_bytes + MXGEFW_PAD,
  3253. 1);
  3254. if (ss->rx_small.fill_cnt - ss->rx_small.cnt >=
  3255. myri10ge_fill_thresh)
  3256. ss->rx_small.watchdog_needed = 0;
  3257. }
  3258. if (ss->rx_big.watchdog_needed) {
  3259. myri10ge_alloc_rx_pages(mgp, &ss->rx_big,
  3260. mgp->big_bytes, 1);
  3261. if (ss->rx_big.fill_cnt - ss->rx_big.cnt >=
  3262. myri10ge_fill_thresh)
  3263. ss->rx_big.watchdog_needed = 0;
  3264. }
  3265. myri10ge_check_slice(ss, &reset_needed, &busy_slice_cnt,
  3266. rx_pause_cnt);
  3267. }
  3268. /* if we've sent or received no traffic, poll the NIC to
  3269. * ensure it is still there. Otherwise, we risk not noticing
  3270. * an error in a timely fashion */
  3271. if (busy_slice_cnt == 0) {
  3272. pci_read_config_word(mgp->pdev, PCI_COMMAND, &cmd);
  3273. if ((cmd & PCI_COMMAND_MASTER) == 0) {
  3274. reset_needed = 1;
  3275. }
  3276. }
  3277. mgp->watchdog_pause = rx_pause_cnt;
  3278. if (reset_needed) {
  3279. schedule_work(&mgp->watchdog_work);
  3280. } else {
  3281. /* rearm timer */
  3282. mod_timer(&mgp->watchdog_timer,
  3283. jiffies + myri10ge_watchdog_timeout * HZ);
  3284. }
  3285. }
  3286. static void myri10ge_free_slices(struct myri10ge_priv *mgp)
  3287. {
  3288. struct myri10ge_slice_state *ss;
  3289. struct pci_dev *pdev = mgp->pdev;
  3290. size_t bytes;
  3291. int i;
  3292. if (mgp->ss == NULL)
  3293. return;
  3294. for (i = 0; i < mgp->num_slices; i++) {
  3295. ss = &mgp->ss[i];
  3296. if (ss->rx_done.entry != NULL) {
  3297. bytes = mgp->max_intr_slots *
  3298. sizeof(*ss->rx_done.entry);
  3299. dma_free_coherent(&pdev->dev, bytes,
  3300. ss->rx_done.entry, ss->rx_done.bus);
  3301. ss->rx_done.entry = NULL;
  3302. }
  3303. if (ss->fw_stats != NULL) {
  3304. bytes = sizeof(*ss->fw_stats);
  3305. dma_free_coherent(&pdev->dev, bytes,
  3306. ss->fw_stats, ss->fw_stats_bus);
  3307. ss->fw_stats = NULL;
  3308. }
  3309. napi_hash_del(&ss->napi);
  3310. netif_napi_del(&ss->napi);
  3311. }
  3312. /* Wait till napi structs are no longer used, and then free ss. */
  3313. synchronize_rcu();
  3314. kfree(mgp->ss);
  3315. mgp->ss = NULL;
  3316. }
  3317. static int myri10ge_alloc_slices(struct myri10ge_priv *mgp)
  3318. {
  3319. struct myri10ge_slice_state *ss;
  3320. struct pci_dev *pdev = mgp->pdev;
  3321. size_t bytes;
  3322. int i;
  3323. bytes = sizeof(*mgp->ss) * mgp->num_slices;
  3324. mgp->ss = kzalloc(bytes, GFP_KERNEL);
  3325. if (mgp->ss == NULL) {
  3326. return -ENOMEM;
  3327. }
  3328. for (i = 0; i < mgp->num_slices; i++) {
  3329. ss = &mgp->ss[i];
  3330. bytes = mgp->max_intr_slots * sizeof(*ss->rx_done.entry);
  3331. ss->rx_done.entry = dma_zalloc_coherent(&pdev->dev, bytes,
  3332. &ss->rx_done.bus,
  3333. GFP_KERNEL);
  3334. if (ss->rx_done.entry == NULL)
  3335. goto abort;
  3336. bytes = sizeof(*ss->fw_stats);
  3337. ss->fw_stats = dma_alloc_coherent(&pdev->dev, bytes,
  3338. &ss->fw_stats_bus,
  3339. GFP_KERNEL);
  3340. if (ss->fw_stats == NULL)
  3341. goto abort;
  3342. ss->mgp = mgp;
  3343. ss->dev = mgp->dev;
  3344. netif_napi_add(ss->dev, &ss->napi, myri10ge_poll,
  3345. myri10ge_napi_weight);
  3346. napi_hash_add(&ss->napi);
  3347. }
  3348. return 0;
  3349. abort:
  3350. myri10ge_free_slices(mgp);
  3351. return -ENOMEM;
  3352. }
  3353. /*
  3354. * This function determines the number of slices supported.
  3355. * The number slices is the minimum of the number of CPUS,
  3356. * the number of MSI-X irqs supported, the number of slices
  3357. * supported by the firmware
  3358. */
  3359. static void myri10ge_probe_slices(struct myri10ge_priv *mgp)
  3360. {
  3361. struct myri10ge_cmd cmd;
  3362. struct pci_dev *pdev = mgp->pdev;
  3363. char *old_fw;
  3364. bool old_allocated;
  3365. int i, status, ncpus;
  3366. mgp->num_slices = 1;
  3367. ncpus = netif_get_num_default_rss_queues();
  3368. if (myri10ge_max_slices == 1 || !pdev->msix_cap ||
  3369. (myri10ge_max_slices == -1 && ncpus < 2))
  3370. return;
  3371. /* try to load the slice aware rss firmware */
  3372. old_fw = mgp->fw_name;
  3373. old_allocated = mgp->fw_name_allocated;
  3374. /* don't free old_fw if we override it. */
  3375. mgp->fw_name_allocated = false;
  3376. if (myri10ge_fw_name != NULL) {
  3377. dev_info(&mgp->pdev->dev, "overriding rss firmware to %s\n",
  3378. myri10ge_fw_name);
  3379. set_fw_name(mgp, myri10ge_fw_name, false);
  3380. } else if (old_fw == myri10ge_fw_aligned)
  3381. set_fw_name(mgp, myri10ge_fw_rss_aligned, false);
  3382. else
  3383. set_fw_name(mgp, myri10ge_fw_rss_unaligned, false);
  3384. status = myri10ge_load_firmware(mgp, 0);
  3385. if (status != 0) {
  3386. dev_info(&pdev->dev, "Rss firmware not found\n");
  3387. if (old_allocated)
  3388. kfree(old_fw);
  3389. return;
  3390. }
  3391. /* hit the board with a reset to ensure it is alive */
  3392. memset(&cmd, 0, sizeof(cmd));
  3393. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_RESET, &cmd, 0);
  3394. if (status != 0) {
  3395. dev_err(&mgp->pdev->dev, "failed reset\n");
  3396. goto abort_with_fw;
  3397. }
  3398. mgp->max_intr_slots = cmd.data0 / sizeof(struct mcp_slot);
  3399. /* tell it the size of the interrupt queues */
  3400. cmd.data0 = mgp->max_intr_slots * sizeof(struct mcp_slot);
  3401. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_INTRQ_SIZE, &cmd, 0);
  3402. if (status != 0) {
  3403. dev_err(&mgp->pdev->dev, "failed MXGEFW_CMD_SET_INTRQ_SIZE\n");
  3404. goto abort_with_fw;
  3405. }
  3406. /* ask the maximum number of slices it supports */
  3407. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_MAX_RSS_QUEUES, &cmd, 0);
  3408. if (status != 0)
  3409. goto abort_with_fw;
  3410. else
  3411. mgp->num_slices = cmd.data0;
  3412. /* Only allow multiple slices if MSI-X is usable */
  3413. if (!myri10ge_msi) {
  3414. goto abort_with_fw;
  3415. }
  3416. /* if the admin did not specify a limit to how many
  3417. * slices we should use, cap it automatically to the
  3418. * number of CPUs currently online */
  3419. if (myri10ge_max_slices == -1)
  3420. myri10ge_max_slices = ncpus;
  3421. if (mgp->num_slices > myri10ge_max_slices)
  3422. mgp->num_slices = myri10ge_max_slices;
  3423. /* Now try to allocate as many MSI-X vectors as we have
  3424. * slices. We give up on MSI-X if we can only get a single
  3425. * vector. */
  3426. mgp->msix_vectors = kcalloc(mgp->num_slices, sizeof(*mgp->msix_vectors),
  3427. GFP_KERNEL);
  3428. if (mgp->msix_vectors == NULL)
  3429. goto no_msix;
  3430. for (i = 0; i < mgp->num_slices; i++) {
  3431. mgp->msix_vectors[i].entry = i;
  3432. }
  3433. while (mgp->num_slices > 1) {
  3434. mgp->num_slices = rounddown_pow_of_two(mgp->num_slices);
  3435. if (mgp->num_slices == 1)
  3436. goto no_msix;
  3437. status = pci_enable_msix_range(pdev,
  3438. mgp->msix_vectors,
  3439. mgp->num_slices,
  3440. mgp->num_slices);
  3441. if (status < 0)
  3442. goto no_msix;
  3443. pci_disable_msix(pdev);
  3444. if (status == mgp->num_slices) {
  3445. if (old_allocated)
  3446. kfree(old_fw);
  3447. return;
  3448. } else {
  3449. mgp->num_slices = status;
  3450. }
  3451. }
  3452. no_msix:
  3453. if (mgp->msix_vectors != NULL) {
  3454. kfree(mgp->msix_vectors);
  3455. mgp->msix_vectors = NULL;
  3456. }
  3457. abort_with_fw:
  3458. mgp->num_slices = 1;
  3459. set_fw_name(mgp, old_fw, old_allocated);
  3460. myri10ge_load_firmware(mgp, 0);
  3461. }
  3462. static const struct net_device_ops myri10ge_netdev_ops = {
  3463. .ndo_open = myri10ge_open,
  3464. .ndo_stop = myri10ge_close,
  3465. .ndo_start_xmit = myri10ge_xmit,
  3466. .ndo_get_stats64 = myri10ge_get_stats,
  3467. .ndo_validate_addr = eth_validate_addr,
  3468. .ndo_change_mtu = myri10ge_change_mtu,
  3469. .ndo_set_rx_mode = myri10ge_set_multicast_list,
  3470. .ndo_set_mac_address = myri10ge_set_mac_address,
  3471. #ifdef CONFIG_NET_RX_BUSY_POLL
  3472. .ndo_busy_poll = myri10ge_busy_poll,
  3473. #endif
  3474. };
  3475. static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  3476. {
  3477. struct net_device *netdev;
  3478. struct myri10ge_priv *mgp;
  3479. struct device *dev = &pdev->dev;
  3480. int i;
  3481. int status = -ENXIO;
  3482. int dac_enabled;
  3483. unsigned hdr_offset, ss_offset;
  3484. static int board_number;
  3485. netdev = alloc_etherdev_mq(sizeof(*mgp), MYRI10GE_MAX_SLICES);
  3486. if (netdev == NULL)
  3487. return -ENOMEM;
  3488. SET_NETDEV_DEV(netdev, &pdev->dev);
  3489. mgp = netdev_priv(netdev);
  3490. mgp->dev = netdev;
  3491. mgp->pdev = pdev;
  3492. mgp->pause = myri10ge_flow_control;
  3493. mgp->intr_coal_delay = myri10ge_intr_coal_delay;
  3494. mgp->msg_enable = netif_msg_init(myri10ge_debug, MYRI10GE_MSG_DEFAULT);
  3495. mgp->board_number = board_number;
  3496. init_waitqueue_head(&mgp->down_wq);
  3497. if (pci_enable_device(pdev)) {
  3498. dev_err(&pdev->dev, "pci_enable_device call failed\n");
  3499. status = -ENODEV;
  3500. goto abort_with_netdev;
  3501. }
  3502. /* Find the vendor-specific cap so we can check
  3503. * the reboot register later on */
  3504. mgp->vendor_specific_offset
  3505. = pci_find_capability(pdev, PCI_CAP_ID_VNDR);
  3506. /* Set our max read request to 4KB */
  3507. status = pcie_set_readrq(pdev, 4096);
  3508. if (status != 0) {
  3509. dev_err(&pdev->dev, "Error %d writing PCI_EXP_DEVCTL\n",
  3510. status);
  3511. goto abort_with_enabled;
  3512. }
  3513. myri10ge_mask_surprise_down(pdev);
  3514. pci_set_master(pdev);
  3515. dac_enabled = 1;
  3516. status = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
  3517. if (status != 0) {
  3518. dac_enabled = 0;
  3519. dev_err(&pdev->dev,
  3520. "64-bit pci address mask was refused, "
  3521. "trying 32-bit\n");
  3522. status = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  3523. }
  3524. if (status != 0) {
  3525. dev_err(&pdev->dev, "Error %d setting DMA mask\n", status);
  3526. goto abort_with_enabled;
  3527. }
  3528. (void)pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  3529. mgp->cmd = dma_alloc_coherent(&pdev->dev, sizeof(*mgp->cmd),
  3530. &mgp->cmd_bus, GFP_KERNEL);
  3531. if (!mgp->cmd) {
  3532. status = -ENOMEM;
  3533. goto abort_with_enabled;
  3534. }
  3535. mgp->board_span = pci_resource_len(pdev, 0);
  3536. mgp->iomem_base = pci_resource_start(pdev, 0);
  3537. mgp->wc_cookie = arch_phys_wc_add(mgp->iomem_base, mgp->board_span);
  3538. mgp->sram = ioremap_wc(mgp->iomem_base, mgp->board_span);
  3539. if (mgp->sram == NULL) {
  3540. dev_err(&pdev->dev, "ioremap failed for %ld bytes at 0x%lx\n",
  3541. mgp->board_span, mgp->iomem_base);
  3542. status = -ENXIO;
  3543. goto abort_with_mtrr;
  3544. }
  3545. hdr_offset =
  3546. swab32(readl(mgp->sram + MCP_HEADER_PTR_OFFSET)) & 0xffffc;
  3547. ss_offset = hdr_offset + offsetof(struct mcp_gen_header, string_specs);
  3548. mgp->sram_size = swab32(readl(mgp->sram + ss_offset));
  3549. if (mgp->sram_size > mgp->board_span ||
  3550. mgp->sram_size <= MYRI10GE_FW_OFFSET) {
  3551. dev_err(&pdev->dev,
  3552. "invalid sram_size %dB or board span %ldB\n",
  3553. mgp->sram_size, mgp->board_span);
  3554. goto abort_with_ioremap;
  3555. }
  3556. memcpy_fromio(mgp->eeprom_strings,
  3557. mgp->sram + mgp->sram_size, MYRI10GE_EEPROM_STRINGS_SIZE);
  3558. memset(mgp->eeprom_strings + MYRI10GE_EEPROM_STRINGS_SIZE - 2, 0, 2);
  3559. status = myri10ge_read_mac_addr(mgp);
  3560. if (status)
  3561. goto abort_with_ioremap;
  3562. for (i = 0; i < ETH_ALEN; i++)
  3563. netdev->dev_addr[i] = mgp->mac_addr[i];
  3564. myri10ge_select_firmware(mgp);
  3565. status = myri10ge_load_firmware(mgp, 1);
  3566. if (status != 0) {
  3567. dev_err(&pdev->dev, "failed to load firmware\n");
  3568. goto abort_with_ioremap;
  3569. }
  3570. myri10ge_probe_slices(mgp);
  3571. status = myri10ge_alloc_slices(mgp);
  3572. if (status != 0) {
  3573. dev_err(&pdev->dev, "failed to alloc slice state\n");
  3574. goto abort_with_firmware;
  3575. }
  3576. netif_set_real_num_tx_queues(netdev, mgp->num_slices);
  3577. netif_set_real_num_rx_queues(netdev, mgp->num_slices);
  3578. status = myri10ge_reset(mgp);
  3579. if (status != 0) {
  3580. dev_err(&pdev->dev, "failed reset\n");
  3581. goto abort_with_slices;
  3582. }
  3583. #ifdef CONFIG_MYRI10GE_DCA
  3584. myri10ge_setup_dca(mgp);
  3585. #endif
  3586. pci_set_drvdata(pdev, mgp);
  3587. if ((myri10ge_initial_mtu + ETH_HLEN) > MYRI10GE_MAX_ETHER_MTU)
  3588. myri10ge_initial_mtu = MYRI10GE_MAX_ETHER_MTU - ETH_HLEN;
  3589. if ((myri10ge_initial_mtu + ETH_HLEN) < 68)
  3590. myri10ge_initial_mtu = 68;
  3591. netdev->netdev_ops = &myri10ge_netdev_ops;
  3592. netdev->mtu = myri10ge_initial_mtu;
  3593. netdev->hw_features = mgp->features | NETIF_F_RXCSUM;
  3594. /* fake NETIF_F_HW_VLAN_CTAG_RX for good GRO performance */
  3595. netdev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX;
  3596. netdev->features = netdev->hw_features;
  3597. if (dac_enabled)
  3598. netdev->features |= NETIF_F_HIGHDMA;
  3599. netdev->vlan_features |= mgp->features;
  3600. if (mgp->fw_ver_tiny < 37)
  3601. netdev->vlan_features &= ~NETIF_F_TSO6;
  3602. if (mgp->fw_ver_tiny < 32)
  3603. netdev->vlan_features &= ~NETIF_F_TSO;
  3604. /* make sure we can get an irq, and that MSI can be
  3605. * setup (if available). */
  3606. status = myri10ge_request_irq(mgp);
  3607. if (status != 0)
  3608. goto abort_with_firmware;
  3609. myri10ge_free_irq(mgp);
  3610. /* Save configuration space to be restored if the
  3611. * nic resets due to a parity error */
  3612. pci_save_state(pdev);
  3613. /* Setup the watchdog timer */
  3614. setup_timer(&mgp->watchdog_timer, myri10ge_watchdog_timer,
  3615. (unsigned long)mgp);
  3616. netdev->ethtool_ops = &myri10ge_ethtool_ops;
  3617. INIT_WORK(&mgp->watchdog_work, myri10ge_watchdog);
  3618. status = register_netdev(netdev);
  3619. if (status != 0) {
  3620. dev_err(&pdev->dev, "register_netdev failed: %d\n", status);
  3621. goto abort_with_state;
  3622. }
  3623. if (mgp->msix_enabled)
  3624. dev_info(dev, "%d MSI-X IRQs, tx bndry %d, fw %s, MTRR %s, WC Enabled\n",
  3625. mgp->num_slices, mgp->tx_boundary, mgp->fw_name,
  3626. (mgp->wc_cookie > 0 ? "Enabled" : "Disabled"));
  3627. else
  3628. dev_info(dev, "%s IRQ %d, tx bndry %d, fw %s, MTRR %s, WC Enabled\n",
  3629. mgp->msi_enabled ? "MSI" : "xPIC",
  3630. pdev->irq, mgp->tx_boundary, mgp->fw_name,
  3631. (mgp->wc_cookie > 0 ? "Enabled" : "Disabled"));
  3632. board_number++;
  3633. return 0;
  3634. abort_with_state:
  3635. pci_restore_state(pdev);
  3636. abort_with_slices:
  3637. myri10ge_free_slices(mgp);
  3638. abort_with_firmware:
  3639. myri10ge_dummy_rdma(mgp, 0);
  3640. abort_with_ioremap:
  3641. if (mgp->mac_addr_string != NULL)
  3642. dev_err(&pdev->dev,
  3643. "myri10ge_probe() failed: MAC=%s, SN=%ld\n",
  3644. mgp->mac_addr_string, mgp->serial_number);
  3645. iounmap(mgp->sram);
  3646. abort_with_mtrr:
  3647. arch_phys_wc_del(mgp->wc_cookie);
  3648. dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd),
  3649. mgp->cmd, mgp->cmd_bus);
  3650. abort_with_enabled:
  3651. pci_disable_device(pdev);
  3652. abort_with_netdev:
  3653. set_fw_name(mgp, NULL, false);
  3654. free_netdev(netdev);
  3655. return status;
  3656. }
  3657. /*
  3658. * myri10ge_remove
  3659. *
  3660. * Does what is necessary to shutdown one Myrinet device. Called
  3661. * once for each Myrinet card by the kernel when a module is
  3662. * unloaded.
  3663. */
  3664. static void myri10ge_remove(struct pci_dev *pdev)
  3665. {
  3666. struct myri10ge_priv *mgp;
  3667. struct net_device *netdev;
  3668. mgp = pci_get_drvdata(pdev);
  3669. if (mgp == NULL)
  3670. return;
  3671. cancel_work_sync(&mgp->watchdog_work);
  3672. netdev = mgp->dev;
  3673. unregister_netdev(netdev);
  3674. #ifdef CONFIG_MYRI10GE_DCA
  3675. myri10ge_teardown_dca(mgp);
  3676. #endif
  3677. myri10ge_dummy_rdma(mgp, 0);
  3678. /* avoid a memory leak */
  3679. pci_restore_state(pdev);
  3680. iounmap(mgp->sram);
  3681. arch_phys_wc_del(mgp->wc_cookie);
  3682. myri10ge_free_slices(mgp);
  3683. kfree(mgp->msix_vectors);
  3684. dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd),
  3685. mgp->cmd, mgp->cmd_bus);
  3686. set_fw_name(mgp, NULL, false);
  3687. free_netdev(netdev);
  3688. pci_disable_device(pdev);
  3689. }
  3690. #define PCI_DEVICE_ID_MYRICOM_MYRI10GE_Z8E 0x0008
  3691. #define PCI_DEVICE_ID_MYRICOM_MYRI10GE_Z8E_9 0x0009
  3692. static const struct pci_device_id myri10ge_pci_tbl[] = {
  3693. {PCI_DEVICE(PCI_VENDOR_ID_MYRICOM, PCI_DEVICE_ID_MYRICOM_MYRI10GE_Z8E)},
  3694. {PCI_DEVICE
  3695. (PCI_VENDOR_ID_MYRICOM, PCI_DEVICE_ID_MYRICOM_MYRI10GE_Z8E_9)},
  3696. {0},
  3697. };
  3698. MODULE_DEVICE_TABLE(pci, myri10ge_pci_tbl);
  3699. static struct pci_driver myri10ge_driver = {
  3700. .name = "myri10ge",
  3701. .probe = myri10ge_probe,
  3702. .remove = myri10ge_remove,
  3703. .id_table = myri10ge_pci_tbl,
  3704. #ifdef CONFIG_PM
  3705. .suspend = myri10ge_suspend,
  3706. .resume = myri10ge_resume,
  3707. #endif
  3708. };
  3709. #ifdef CONFIG_MYRI10GE_DCA
  3710. static int
  3711. myri10ge_notify_dca(struct notifier_block *nb, unsigned long event, void *p)
  3712. {
  3713. int err = driver_for_each_device(&myri10ge_driver.driver,
  3714. NULL, &event,
  3715. myri10ge_notify_dca_device);
  3716. if (err)
  3717. return NOTIFY_BAD;
  3718. return NOTIFY_DONE;
  3719. }
  3720. static struct notifier_block myri10ge_dca_notifier = {
  3721. .notifier_call = myri10ge_notify_dca,
  3722. .next = NULL,
  3723. .priority = 0,
  3724. };
  3725. #endif /* CONFIG_MYRI10GE_DCA */
  3726. static __init int myri10ge_init_module(void)
  3727. {
  3728. pr_info("Version %s\n", MYRI10GE_VERSION_STR);
  3729. if (myri10ge_rss_hash > MXGEFW_RSS_HASH_TYPE_MAX) {
  3730. pr_err("Illegal rssh hash type %d, defaulting to source port\n",
  3731. myri10ge_rss_hash);
  3732. myri10ge_rss_hash = MXGEFW_RSS_HASH_TYPE_SRC_PORT;
  3733. }
  3734. #ifdef CONFIG_MYRI10GE_DCA
  3735. dca_register_notify(&myri10ge_dca_notifier);
  3736. #endif
  3737. if (myri10ge_max_slices > MYRI10GE_MAX_SLICES)
  3738. myri10ge_max_slices = MYRI10GE_MAX_SLICES;
  3739. return pci_register_driver(&myri10ge_driver);
  3740. }
  3741. module_init(myri10ge_init_module);
  3742. static __exit void myri10ge_cleanup_module(void)
  3743. {
  3744. #ifdef CONFIG_MYRI10GE_DCA
  3745. dca_unregister_notify(&myri10ge_dca_notifier);
  3746. #endif
  3747. pci_unregister_driver(&myri10ge_driver);
  3748. }
  3749. module_exit(myri10ge_cleanup_module);