myri10ge.c 117 KB

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