myri10ge.c 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223
  1. /*************************************************************************
  2. * myri10ge.c: Myricom Myri-10G Ethernet driver.
  3. *
  4. * Copyright (C) 2005 - 2007 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. #include <linux/tcp.h>
  41. #include <linux/netdevice.h>
  42. #include <linux/skbuff.h>
  43. #include <linux/string.h>
  44. #include <linux/module.h>
  45. #include <linux/pci.h>
  46. #include <linux/dma-mapping.h>
  47. #include <linux/etherdevice.h>
  48. #include <linux/if_ether.h>
  49. #include <linux/if_vlan.h>
  50. #include <linux/inet_lro.h>
  51. #include <linux/ip.h>
  52. #include <linux/inet.h>
  53. #include <linux/in.h>
  54. #include <linux/ethtool.h>
  55. #include <linux/firmware.h>
  56. #include <linux/delay.h>
  57. #include <linux/version.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 <net/checksum.h>
  65. #include <net/ip.h>
  66. #include <net/tcp.h>
  67. #include <asm/byteorder.h>
  68. #include <asm/io.h>
  69. #include <asm/processor.h>
  70. #ifdef CONFIG_MTRR
  71. #include <asm/mtrr.h>
  72. #endif
  73. #include "myri10ge_mcp.h"
  74. #include "myri10ge_mcp_gen_header.h"
  75. #define MYRI10GE_VERSION_STR "1.3.2-1.269"
  76. MODULE_DESCRIPTION("Myricom 10G driver (10GbE)");
  77. MODULE_AUTHOR("Maintainer: help@myri.com");
  78. MODULE_VERSION(MYRI10GE_VERSION_STR);
  79. MODULE_LICENSE("Dual BSD/GPL");
  80. #define MYRI10GE_MAX_ETHER_MTU 9014
  81. #define MYRI10GE_ETH_STOPPED 0
  82. #define MYRI10GE_ETH_STOPPING 1
  83. #define MYRI10GE_ETH_STARTING 2
  84. #define MYRI10GE_ETH_RUNNING 3
  85. #define MYRI10GE_ETH_OPEN_FAILED 4
  86. #define MYRI10GE_EEPROM_STRINGS_SIZE 256
  87. #define MYRI10GE_MAX_SEND_DESC_TSO ((65536 / 2048) * 2)
  88. #define MYRI10GE_MAX_LRO_DESCRIPTORS 8
  89. #define MYRI10GE_LRO_MAX_PKTS 64
  90. #define MYRI10GE_NO_CONFIRM_DATA htonl(0xffffffff)
  91. #define MYRI10GE_NO_RESPONSE_RESULT 0xffffffff
  92. #define MYRI10GE_ALLOC_ORDER 0
  93. #define MYRI10GE_ALLOC_SIZE ((1 << MYRI10GE_ALLOC_ORDER) * PAGE_SIZE)
  94. #define MYRI10GE_MAX_FRAGS_PER_FRAME (MYRI10GE_MAX_ETHER_MTU/MYRI10GE_ALLOC_SIZE + 1)
  95. struct myri10ge_rx_buffer_state {
  96. struct page *page;
  97. int page_offset;
  98. DECLARE_PCI_UNMAP_ADDR(bus)
  99. DECLARE_PCI_UNMAP_LEN(len)
  100. };
  101. struct myri10ge_tx_buffer_state {
  102. struct sk_buff *skb;
  103. int last;
  104. DECLARE_PCI_UNMAP_ADDR(bus)
  105. DECLARE_PCI_UNMAP_LEN(len)
  106. };
  107. struct myri10ge_cmd {
  108. u32 data0;
  109. u32 data1;
  110. u32 data2;
  111. };
  112. struct myri10ge_rx_buf {
  113. struct mcp_kreq_ether_recv __iomem *lanai; /* lanai ptr for recv ring */
  114. u8 __iomem *wc_fifo; /* w/c rx dma addr fifo address */
  115. struct mcp_kreq_ether_recv *shadow; /* host shadow of recv ring */
  116. struct myri10ge_rx_buffer_state *info;
  117. struct page *page;
  118. dma_addr_t bus;
  119. int page_offset;
  120. int cnt;
  121. int fill_cnt;
  122. int alloc_fail;
  123. int mask; /* number of rx slots -1 */
  124. int watchdog_needed;
  125. };
  126. struct myri10ge_tx_buf {
  127. struct mcp_kreq_ether_send __iomem *lanai; /* lanai ptr for sendq */
  128. u8 __iomem *wc_fifo; /* w/c send fifo address */
  129. struct mcp_kreq_ether_send *req_list; /* host shadow of sendq */
  130. char *req_bytes;
  131. struct myri10ge_tx_buffer_state *info;
  132. int mask; /* number of transmit slots -1 */
  133. int boundary; /* boundary transmits cannot cross */
  134. int req ____cacheline_aligned; /* transmit slots submitted */
  135. int pkt_start; /* packets started */
  136. int done ____cacheline_aligned; /* transmit slots completed */
  137. int pkt_done; /* packets completed */
  138. };
  139. struct myri10ge_rx_done {
  140. struct mcp_slot *entry;
  141. dma_addr_t bus;
  142. int cnt;
  143. int idx;
  144. struct net_lro_mgr lro_mgr;
  145. struct net_lro_desc lro_desc[MYRI10GE_MAX_LRO_DESCRIPTORS];
  146. };
  147. struct myri10ge_priv {
  148. int running; /* running? */
  149. int csum_flag; /* rx_csums? */
  150. struct myri10ge_tx_buf tx; /* transmit ring */
  151. struct myri10ge_rx_buf rx_small;
  152. struct myri10ge_rx_buf rx_big;
  153. struct myri10ge_rx_done rx_done;
  154. int small_bytes;
  155. int big_bytes;
  156. struct net_device *dev;
  157. struct napi_struct napi;
  158. struct net_device_stats stats;
  159. u8 __iomem *sram;
  160. int sram_size;
  161. unsigned long board_span;
  162. unsigned long iomem_base;
  163. __be32 __iomem *irq_claim;
  164. __be32 __iomem *irq_deassert;
  165. char *mac_addr_string;
  166. struct mcp_cmd_response *cmd;
  167. dma_addr_t cmd_bus;
  168. struct mcp_irq_data *fw_stats;
  169. dma_addr_t fw_stats_bus;
  170. struct pci_dev *pdev;
  171. int msi_enabled;
  172. __be32 link_state;
  173. unsigned int rdma_tags_available;
  174. int intr_coal_delay;
  175. __be32 __iomem *intr_coal_delay_ptr;
  176. int mtrr;
  177. int wc_enabled;
  178. int wake_queue;
  179. int stop_queue;
  180. int down_cnt;
  181. wait_queue_head_t down_wq;
  182. struct work_struct watchdog_work;
  183. struct timer_list watchdog_timer;
  184. int watchdog_tx_done;
  185. int watchdog_tx_req;
  186. int watchdog_pause;
  187. int watchdog_resets;
  188. int tx_linearized;
  189. int pause;
  190. char *fw_name;
  191. char eeprom_strings[MYRI10GE_EEPROM_STRINGS_SIZE];
  192. char fw_version[128];
  193. int fw_ver_major;
  194. int fw_ver_minor;
  195. int fw_ver_tiny;
  196. int adopted_rx_filter_bug;
  197. u8 mac_addr[6]; /* eeprom mac address */
  198. unsigned long serial_number;
  199. int vendor_specific_offset;
  200. int fw_multicast_support;
  201. u32 read_dma;
  202. u32 write_dma;
  203. u32 read_write_dma;
  204. u32 link_changes;
  205. u32 msg_enable;
  206. };
  207. static char *myri10ge_fw_unaligned = "myri10ge_ethp_z8e.dat";
  208. static char *myri10ge_fw_aligned = "myri10ge_eth_z8e.dat";
  209. static char *myri10ge_fw_name = NULL;
  210. module_param(myri10ge_fw_name, charp, S_IRUGO | S_IWUSR);
  211. MODULE_PARM_DESC(myri10ge_fw_name, "Firmware image name\n");
  212. static int myri10ge_ecrc_enable = 1;
  213. module_param(myri10ge_ecrc_enable, int, S_IRUGO);
  214. MODULE_PARM_DESC(myri10ge_ecrc_enable, "Enable Extended CRC on PCI-E\n");
  215. static int myri10ge_max_intr_slots = 1024;
  216. module_param(myri10ge_max_intr_slots, int, S_IRUGO);
  217. MODULE_PARM_DESC(myri10ge_max_intr_slots, "Interrupt queue slots\n");
  218. static int myri10ge_small_bytes = -1; /* -1 == auto */
  219. module_param(myri10ge_small_bytes, int, S_IRUGO | S_IWUSR);
  220. MODULE_PARM_DESC(myri10ge_small_bytes, "Threshold of small packets\n");
  221. static int myri10ge_msi = 1; /* enable msi by default */
  222. module_param(myri10ge_msi, int, S_IRUGO | S_IWUSR);
  223. MODULE_PARM_DESC(myri10ge_msi, "Enable Message Signalled Interrupts\n");
  224. static int myri10ge_intr_coal_delay = 75;
  225. module_param(myri10ge_intr_coal_delay, int, S_IRUGO);
  226. MODULE_PARM_DESC(myri10ge_intr_coal_delay, "Interrupt coalescing delay\n");
  227. static int myri10ge_flow_control = 1;
  228. module_param(myri10ge_flow_control, int, S_IRUGO);
  229. MODULE_PARM_DESC(myri10ge_flow_control, "Pause parameter\n");
  230. static int myri10ge_deassert_wait = 1;
  231. module_param(myri10ge_deassert_wait, int, S_IRUGO | S_IWUSR);
  232. MODULE_PARM_DESC(myri10ge_deassert_wait,
  233. "Wait when deasserting legacy interrupts\n");
  234. static int myri10ge_force_firmware = 0;
  235. module_param(myri10ge_force_firmware, int, S_IRUGO);
  236. MODULE_PARM_DESC(myri10ge_force_firmware,
  237. "Force firmware to assume aligned completions\n");
  238. static int myri10ge_initial_mtu = MYRI10GE_MAX_ETHER_MTU - ETH_HLEN;
  239. module_param(myri10ge_initial_mtu, int, S_IRUGO);
  240. MODULE_PARM_DESC(myri10ge_initial_mtu, "Initial MTU\n");
  241. static int myri10ge_napi_weight = 64;
  242. module_param(myri10ge_napi_weight, int, S_IRUGO);
  243. MODULE_PARM_DESC(myri10ge_napi_weight, "Set NAPI weight\n");
  244. static int myri10ge_watchdog_timeout = 1;
  245. module_param(myri10ge_watchdog_timeout, int, S_IRUGO);
  246. MODULE_PARM_DESC(myri10ge_watchdog_timeout, "Set watchdog timeout\n");
  247. static int myri10ge_max_irq_loops = 1048576;
  248. module_param(myri10ge_max_irq_loops, int, S_IRUGO);
  249. MODULE_PARM_DESC(myri10ge_max_irq_loops,
  250. "Set stuck legacy IRQ detection threshold\n");
  251. #define MYRI10GE_MSG_DEFAULT NETIF_MSG_LINK
  252. static int myri10ge_debug = -1; /* defaults above */
  253. module_param(myri10ge_debug, int, 0);
  254. MODULE_PARM_DESC(myri10ge_debug, "Debug level (0=none,...,16=all)");
  255. static int myri10ge_lro = 1;
  256. module_param(myri10ge_lro, int, S_IRUGO);
  257. MODULE_PARM_DESC(myri10ge_lro, "Enable large receive offload\n");
  258. static int myri10ge_lro_max_pkts = MYRI10GE_LRO_MAX_PKTS;
  259. module_param(myri10ge_lro_max_pkts, int, S_IRUGO);
  260. MODULE_PARM_DESC(myri10ge_lro, "Number of LRO packets to be aggregated\n");
  261. static int myri10ge_fill_thresh = 256;
  262. module_param(myri10ge_fill_thresh, int, S_IRUGO | S_IWUSR);
  263. MODULE_PARM_DESC(myri10ge_fill_thresh, "Number of empty rx slots allowed\n");
  264. static int myri10ge_reset_recover = 1;
  265. static int myri10ge_wcfifo = 0;
  266. module_param(myri10ge_wcfifo, int, S_IRUGO);
  267. MODULE_PARM_DESC(myri10ge_wcfifo, "Enable WC Fifo when WC is enabled\n");
  268. #define MYRI10GE_FW_OFFSET 1024*1024
  269. #define MYRI10GE_HIGHPART_TO_U32(X) \
  270. (sizeof (X) == 8) ? ((u32)((u64)(X) >> 32)) : (0)
  271. #define MYRI10GE_LOWPART_TO_U32(X) ((u32)(X))
  272. #define myri10ge_pio_copy(to,from,size) __iowrite64_copy(to,from,size/8)
  273. static void myri10ge_set_multicast_list(struct net_device *dev);
  274. static inline void put_be32(__be32 val, __be32 __iomem * p)
  275. {
  276. __raw_writel((__force __u32) val, (__force void __iomem *)p);
  277. }
  278. static int
  279. myri10ge_send_cmd(struct myri10ge_priv *mgp, u32 cmd,
  280. struct myri10ge_cmd *data, int atomic)
  281. {
  282. struct mcp_cmd *buf;
  283. char buf_bytes[sizeof(*buf) + 8];
  284. struct mcp_cmd_response *response = mgp->cmd;
  285. char __iomem *cmd_addr = mgp->sram + MXGEFW_ETH_CMD;
  286. u32 dma_low, dma_high, result, value;
  287. int sleep_total = 0;
  288. /* ensure buf is aligned to 8 bytes */
  289. buf = (struct mcp_cmd *)ALIGN((unsigned long)buf_bytes, 8);
  290. buf->data0 = htonl(data->data0);
  291. buf->data1 = htonl(data->data1);
  292. buf->data2 = htonl(data->data2);
  293. buf->cmd = htonl(cmd);
  294. dma_low = MYRI10GE_LOWPART_TO_U32(mgp->cmd_bus);
  295. dma_high = MYRI10GE_HIGHPART_TO_U32(mgp->cmd_bus);
  296. buf->response_addr.low = htonl(dma_low);
  297. buf->response_addr.high = htonl(dma_high);
  298. response->result = htonl(MYRI10GE_NO_RESPONSE_RESULT);
  299. mb();
  300. myri10ge_pio_copy(cmd_addr, buf, sizeof(*buf));
  301. /* wait up to 15ms. Longest command is the DMA benchmark,
  302. * which is capped at 5ms, but runs from a timeout handler
  303. * that runs every 7.8ms. So a 15ms timeout leaves us with
  304. * a 2.2ms margin
  305. */
  306. if (atomic) {
  307. /* if atomic is set, do not sleep,
  308. * and try to get the completion quickly
  309. * (1ms will be enough for those commands) */
  310. for (sleep_total = 0;
  311. sleep_total < 1000
  312. && response->result == htonl(MYRI10GE_NO_RESPONSE_RESULT);
  313. sleep_total += 10)
  314. udelay(10);
  315. } else {
  316. /* use msleep for most command */
  317. for (sleep_total = 0;
  318. sleep_total < 15
  319. && response->result == htonl(MYRI10GE_NO_RESPONSE_RESULT);
  320. sleep_total++)
  321. msleep(1);
  322. }
  323. result = ntohl(response->result);
  324. value = ntohl(response->data);
  325. if (result != MYRI10GE_NO_RESPONSE_RESULT) {
  326. if (result == 0) {
  327. data->data0 = value;
  328. return 0;
  329. } else if (result == MXGEFW_CMD_UNKNOWN) {
  330. return -ENOSYS;
  331. } else if (result == MXGEFW_CMD_ERROR_UNALIGNED) {
  332. return -E2BIG;
  333. } else {
  334. dev_err(&mgp->pdev->dev,
  335. "command %d failed, result = %d\n",
  336. cmd, result);
  337. return -ENXIO;
  338. }
  339. }
  340. dev_err(&mgp->pdev->dev, "command %d timed out, result = %d\n",
  341. cmd, result);
  342. return -EAGAIN;
  343. }
  344. /*
  345. * The eeprom strings on the lanaiX have the format
  346. * SN=x\0
  347. * MAC=x:x:x:x:x:x\0
  348. * PT:ddd mmm xx xx:xx:xx xx\0
  349. * PV:ddd mmm xx xx:xx:xx xx\0
  350. */
  351. static int myri10ge_read_mac_addr(struct myri10ge_priv *mgp)
  352. {
  353. char *ptr, *limit;
  354. int i;
  355. ptr = mgp->eeprom_strings;
  356. limit = mgp->eeprom_strings + MYRI10GE_EEPROM_STRINGS_SIZE;
  357. while (*ptr != '\0' && ptr < limit) {
  358. if (memcmp(ptr, "MAC=", 4) == 0) {
  359. ptr += 4;
  360. mgp->mac_addr_string = ptr;
  361. for (i = 0; i < 6; i++) {
  362. if ((ptr + 2) > limit)
  363. goto abort;
  364. mgp->mac_addr[i] =
  365. simple_strtoul(ptr, &ptr, 16);
  366. ptr += 1;
  367. }
  368. }
  369. if (memcmp((const void *)ptr, "SN=", 3) == 0) {
  370. ptr += 3;
  371. mgp->serial_number = simple_strtoul(ptr, &ptr, 10);
  372. }
  373. while (ptr < limit && *ptr++) ;
  374. }
  375. return 0;
  376. abort:
  377. dev_err(&mgp->pdev->dev, "failed to parse eeprom_strings\n");
  378. return -ENXIO;
  379. }
  380. /*
  381. * Enable or disable periodic RDMAs from the host to make certain
  382. * chipsets resend dropped PCIe messages
  383. */
  384. static void myri10ge_dummy_rdma(struct myri10ge_priv *mgp, int enable)
  385. {
  386. char __iomem *submit;
  387. __be32 buf[16];
  388. u32 dma_low, dma_high;
  389. int i;
  390. /* clear confirmation addr */
  391. mgp->cmd->data = 0;
  392. mb();
  393. /* send a rdma command to the PCIe engine, and wait for the
  394. * response in the confirmation address. The firmware should
  395. * write a -1 there to indicate it is alive and well
  396. */
  397. dma_low = MYRI10GE_LOWPART_TO_U32(mgp->cmd_bus);
  398. dma_high = MYRI10GE_HIGHPART_TO_U32(mgp->cmd_bus);
  399. buf[0] = htonl(dma_high); /* confirm addr MSW */
  400. buf[1] = htonl(dma_low); /* confirm addr LSW */
  401. buf[2] = MYRI10GE_NO_CONFIRM_DATA; /* confirm data */
  402. buf[3] = htonl(dma_high); /* dummy addr MSW */
  403. buf[4] = htonl(dma_low); /* dummy addr LSW */
  404. buf[5] = htonl(enable); /* enable? */
  405. submit = mgp->sram + MXGEFW_BOOT_DUMMY_RDMA;
  406. myri10ge_pio_copy(submit, &buf, sizeof(buf));
  407. for (i = 0; mgp->cmd->data != MYRI10GE_NO_CONFIRM_DATA && i < 20; i++)
  408. msleep(1);
  409. if (mgp->cmd->data != MYRI10GE_NO_CONFIRM_DATA)
  410. dev_err(&mgp->pdev->dev, "dummy rdma %s failed\n",
  411. (enable ? "enable" : "disable"));
  412. }
  413. static int
  414. myri10ge_validate_firmware(struct myri10ge_priv *mgp,
  415. struct mcp_gen_header *hdr)
  416. {
  417. struct device *dev = &mgp->pdev->dev;
  418. /* check firmware type */
  419. if (ntohl(hdr->mcp_type) != MCP_TYPE_ETH) {
  420. dev_err(dev, "Bad firmware type: 0x%x\n", ntohl(hdr->mcp_type));
  421. return -EINVAL;
  422. }
  423. /* save firmware version for ethtool */
  424. strncpy(mgp->fw_version, hdr->version, sizeof(mgp->fw_version));
  425. sscanf(mgp->fw_version, "%d.%d.%d", &mgp->fw_ver_major,
  426. &mgp->fw_ver_minor, &mgp->fw_ver_tiny);
  427. if (!(mgp->fw_ver_major == MXGEFW_VERSION_MAJOR
  428. && mgp->fw_ver_minor == MXGEFW_VERSION_MINOR)) {
  429. dev_err(dev, "Found firmware version %s\n", mgp->fw_version);
  430. dev_err(dev, "Driver needs %d.%d\n", MXGEFW_VERSION_MAJOR,
  431. MXGEFW_VERSION_MINOR);
  432. return -EINVAL;
  433. }
  434. return 0;
  435. }
  436. static int myri10ge_load_hotplug_firmware(struct myri10ge_priv *mgp, u32 * size)
  437. {
  438. unsigned crc, reread_crc;
  439. const struct firmware *fw;
  440. struct device *dev = &mgp->pdev->dev;
  441. struct mcp_gen_header *hdr;
  442. size_t hdr_offset;
  443. int status;
  444. unsigned i;
  445. if ((status = request_firmware(&fw, mgp->fw_name, dev)) < 0) {
  446. dev_err(dev, "Unable to load %s firmware image via hotplug\n",
  447. mgp->fw_name);
  448. status = -EINVAL;
  449. goto abort_with_nothing;
  450. }
  451. /* check size */
  452. if (fw->size >= mgp->sram_size - MYRI10GE_FW_OFFSET ||
  453. fw->size < MCP_HEADER_PTR_OFFSET + 4) {
  454. dev_err(dev, "Firmware size invalid:%d\n", (int)fw->size);
  455. status = -EINVAL;
  456. goto abort_with_fw;
  457. }
  458. /* check id */
  459. hdr_offset = ntohl(*(__be32 *) (fw->data + MCP_HEADER_PTR_OFFSET));
  460. if ((hdr_offset & 3) || hdr_offset + sizeof(*hdr) > fw->size) {
  461. dev_err(dev, "Bad firmware file\n");
  462. status = -EINVAL;
  463. goto abort_with_fw;
  464. }
  465. hdr = (void *)(fw->data + hdr_offset);
  466. status = myri10ge_validate_firmware(mgp, hdr);
  467. if (status != 0)
  468. goto abort_with_fw;
  469. crc = crc32(~0, fw->data, fw->size);
  470. for (i = 0; i < fw->size; i += 256) {
  471. myri10ge_pio_copy(mgp->sram + MYRI10GE_FW_OFFSET + i,
  472. fw->data + i,
  473. min(256U, (unsigned)(fw->size - i)));
  474. mb();
  475. readb(mgp->sram);
  476. }
  477. /* corruption checking is good for parity recovery and buggy chipset */
  478. memcpy_fromio(fw->data, mgp->sram + MYRI10GE_FW_OFFSET, fw->size);
  479. reread_crc = crc32(~0, fw->data, fw->size);
  480. if (crc != reread_crc) {
  481. dev_err(dev, "CRC failed(fw-len=%u), got 0x%x (expect 0x%x)\n",
  482. (unsigned)fw->size, reread_crc, crc);
  483. status = -EIO;
  484. goto abort_with_fw;
  485. }
  486. *size = (u32) fw->size;
  487. abort_with_fw:
  488. release_firmware(fw);
  489. abort_with_nothing:
  490. return status;
  491. }
  492. static int myri10ge_adopt_running_firmware(struct myri10ge_priv *mgp)
  493. {
  494. struct mcp_gen_header *hdr;
  495. struct device *dev = &mgp->pdev->dev;
  496. const size_t bytes = sizeof(struct mcp_gen_header);
  497. size_t hdr_offset;
  498. int status;
  499. /* find running firmware header */
  500. hdr_offset = ntohl(__raw_readl(mgp->sram + MCP_HEADER_PTR_OFFSET));
  501. if ((hdr_offset & 3) || hdr_offset + sizeof(*hdr) > mgp->sram_size) {
  502. dev_err(dev, "Running firmware has bad header offset (%d)\n",
  503. (int)hdr_offset);
  504. return -EIO;
  505. }
  506. /* copy header of running firmware from SRAM to host memory to
  507. * validate firmware */
  508. hdr = kmalloc(bytes, GFP_KERNEL);
  509. if (hdr == NULL) {
  510. dev_err(dev, "could not malloc firmware hdr\n");
  511. return -ENOMEM;
  512. }
  513. memcpy_fromio(hdr, mgp->sram + hdr_offset, bytes);
  514. status = myri10ge_validate_firmware(mgp, hdr);
  515. kfree(hdr);
  516. /* check to see if adopted firmware has bug where adopting
  517. * it will cause broadcasts to be filtered unless the NIC
  518. * is kept in ALLMULTI mode */
  519. if (mgp->fw_ver_major == 1 && mgp->fw_ver_minor == 4 &&
  520. mgp->fw_ver_tiny >= 4 && mgp->fw_ver_tiny <= 11) {
  521. mgp->adopted_rx_filter_bug = 1;
  522. dev_warn(dev, "Adopting fw %d.%d.%d: "
  523. "working around rx filter bug\n",
  524. mgp->fw_ver_major, mgp->fw_ver_minor,
  525. mgp->fw_ver_tiny);
  526. }
  527. return status;
  528. }
  529. static int myri10ge_load_firmware(struct myri10ge_priv *mgp)
  530. {
  531. char __iomem *submit;
  532. __be32 buf[16];
  533. u32 dma_low, dma_high, size;
  534. int status, i;
  535. size = 0;
  536. status = myri10ge_load_hotplug_firmware(mgp, &size);
  537. if (status) {
  538. dev_warn(&mgp->pdev->dev, "hotplug firmware loading failed\n");
  539. /* Do not attempt to adopt firmware if there
  540. * was a bad crc */
  541. if (status == -EIO)
  542. return status;
  543. status = myri10ge_adopt_running_firmware(mgp);
  544. if (status != 0) {
  545. dev_err(&mgp->pdev->dev,
  546. "failed to adopt running firmware\n");
  547. return status;
  548. }
  549. dev_info(&mgp->pdev->dev,
  550. "Successfully adopted running firmware\n");
  551. if (mgp->tx.boundary == 4096) {
  552. dev_warn(&mgp->pdev->dev,
  553. "Using firmware currently running on NIC"
  554. ". For optimal\n");
  555. dev_warn(&mgp->pdev->dev,
  556. "performance consider loading optimized "
  557. "firmware\n");
  558. dev_warn(&mgp->pdev->dev, "via hotplug\n");
  559. }
  560. mgp->fw_name = "adopted";
  561. mgp->tx.boundary = 2048;
  562. return status;
  563. }
  564. /* clear confirmation addr */
  565. mgp->cmd->data = 0;
  566. mb();
  567. /* send a reload command to the bootstrap MCP, and wait for the
  568. * response in the confirmation address. The firmware should
  569. * write a -1 there to indicate it is alive and well
  570. */
  571. dma_low = MYRI10GE_LOWPART_TO_U32(mgp->cmd_bus);
  572. dma_high = MYRI10GE_HIGHPART_TO_U32(mgp->cmd_bus);
  573. buf[0] = htonl(dma_high); /* confirm addr MSW */
  574. buf[1] = htonl(dma_low); /* confirm addr LSW */
  575. buf[2] = MYRI10GE_NO_CONFIRM_DATA; /* confirm data */
  576. /* FIX: All newest firmware should un-protect the bottom of
  577. * the sram before handoff. However, the very first interfaces
  578. * do not. Therefore the handoff copy must skip the first 8 bytes
  579. */
  580. buf[3] = htonl(MYRI10GE_FW_OFFSET + 8); /* where the code starts */
  581. buf[4] = htonl(size - 8); /* length of code */
  582. buf[5] = htonl(8); /* where to copy to */
  583. buf[6] = htonl(0); /* where to jump to */
  584. submit = mgp->sram + MXGEFW_BOOT_HANDOFF;
  585. myri10ge_pio_copy(submit, &buf, sizeof(buf));
  586. mb();
  587. msleep(1);
  588. mb();
  589. i = 0;
  590. while (mgp->cmd->data != MYRI10GE_NO_CONFIRM_DATA && i < 20) {
  591. msleep(1);
  592. i++;
  593. }
  594. if (mgp->cmd->data != MYRI10GE_NO_CONFIRM_DATA) {
  595. dev_err(&mgp->pdev->dev, "handoff failed\n");
  596. return -ENXIO;
  597. }
  598. dev_info(&mgp->pdev->dev, "handoff confirmed\n");
  599. myri10ge_dummy_rdma(mgp, 1);
  600. return 0;
  601. }
  602. static int myri10ge_update_mac_address(struct myri10ge_priv *mgp, u8 * addr)
  603. {
  604. struct myri10ge_cmd cmd;
  605. int status;
  606. cmd.data0 = ((addr[0] << 24) | (addr[1] << 16)
  607. | (addr[2] << 8) | addr[3]);
  608. cmd.data1 = ((addr[4] << 8) | (addr[5]));
  609. status = myri10ge_send_cmd(mgp, MXGEFW_SET_MAC_ADDRESS, &cmd, 0);
  610. return status;
  611. }
  612. static int myri10ge_change_pause(struct myri10ge_priv *mgp, int pause)
  613. {
  614. struct myri10ge_cmd cmd;
  615. int status, ctl;
  616. ctl = pause ? MXGEFW_ENABLE_FLOW_CONTROL : MXGEFW_DISABLE_FLOW_CONTROL;
  617. status = myri10ge_send_cmd(mgp, ctl, &cmd, 0);
  618. if (status) {
  619. printk(KERN_ERR
  620. "myri10ge: %s: Failed to set flow control mode\n",
  621. mgp->dev->name);
  622. return status;
  623. }
  624. mgp->pause = pause;
  625. return 0;
  626. }
  627. static void
  628. myri10ge_change_promisc(struct myri10ge_priv *mgp, int promisc, int atomic)
  629. {
  630. struct myri10ge_cmd cmd;
  631. int status, ctl;
  632. ctl = promisc ? MXGEFW_ENABLE_PROMISC : MXGEFW_DISABLE_PROMISC;
  633. status = myri10ge_send_cmd(mgp, ctl, &cmd, atomic);
  634. if (status)
  635. printk(KERN_ERR "myri10ge: %s: Failed to set promisc mode\n",
  636. mgp->dev->name);
  637. }
  638. static int myri10ge_dma_test(struct myri10ge_priv *mgp, int test_type)
  639. {
  640. struct myri10ge_cmd cmd;
  641. int status;
  642. u32 len;
  643. struct page *dmatest_page;
  644. dma_addr_t dmatest_bus;
  645. char *test = " ";
  646. dmatest_page = alloc_page(GFP_KERNEL);
  647. if (!dmatest_page)
  648. return -ENOMEM;
  649. dmatest_bus = pci_map_page(mgp->pdev, dmatest_page, 0, PAGE_SIZE,
  650. DMA_BIDIRECTIONAL);
  651. /* Run a small DMA test.
  652. * The magic multipliers to the length tell the firmware
  653. * to do DMA read, write, or read+write tests. The
  654. * results are returned in cmd.data0. The upper 16
  655. * bits or the return is the number of transfers completed.
  656. * The lower 16 bits is the time in 0.5us ticks that the
  657. * transfers took to complete.
  658. */
  659. len = mgp->tx.boundary;
  660. cmd.data0 = MYRI10GE_LOWPART_TO_U32(dmatest_bus);
  661. cmd.data1 = MYRI10GE_HIGHPART_TO_U32(dmatest_bus);
  662. cmd.data2 = len * 0x10000;
  663. status = myri10ge_send_cmd(mgp, test_type, &cmd, 0);
  664. if (status != 0) {
  665. test = "read";
  666. goto abort;
  667. }
  668. mgp->read_dma = ((cmd.data0 >> 16) * len * 2) / (cmd.data0 & 0xffff);
  669. cmd.data0 = MYRI10GE_LOWPART_TO_U32(dmatest_bus);
  670. cmd.data1 = MYRI10GE_HIGHPART_TO_U32(dmatest_bus);
  671. cmd.data2 = len * 0x1;
  672. status = myri10ge_send_cmd(mgp, test_type, &cmd, 0);
  673. if (status != 0) {
  674. test = "write";
  675. goto abort;
  676. }
  677. mgp->write_dma = ((cmd.data0 >> 16) * len * 2) / (cmd.data0 & 0xffff);
  678. cmd.data0 = MYRI10GE_LOWPART_TO_U32(dmatest_bus);
  679. cmd.data1 = MYRI10GE_HIGHPART_TO_U32(dmatest_bus);
  680. cmd.data2 = len * 0x10001;
  681. status = myri10ge_send_cmd(mgp, test_type, &cmd, 0);
  682. if (status != 0) {
  683. test = "read/write";
  684. goto abort;
  685. }
  686. mgp->read_write_dma = ((cmd.data0 >> 16) * len * 2 * 2) /
  687. (cmd.data0 & 0xffff);
  688. abort:
  689. pci_unmap_page(mgp->pdev, dmatest_bus, PAGE_SIZE, DMA_BIDIRECTIONAL);
  690. put_page(dmatest_page);
  691. if (status != 0 && test_type != MXGEFW_CMD_UNALIGNED_TEST)
  692. dev_warn(&mgp->pdev->dev, "DMA %s benchmark failed: %d\n",
  693. test, status);
  694. return status;
  695. }
  696. static int myri10ge_reset(struct myri10ge_priv *mgp)
  697. {
  698. struct myri10ge_cmd cmd;
  699. int status;
  700. size_t bytes;
  701. /* try to send a reset command to the card to see if it
  702. * is alive */
  703. memset(&cmd, 0, sizeof(cmd));
  704. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_RESET, &cmd, 0);
  705. if (status != 0) {
  706. dev_err(&mgp->pdev->dev, "failed reset\n");
  707. return -ENXIO;
  708. }
  709. (void)myri10ge_dma_test(mgp, MXGEFW_DMA_TEST);
  710. /* Now exchange information about interrupts */
  711. bytes = myri10ge_max_intr_slots * sizeof(*mgp->rx_done.entry);
  712. memset(mgp->rx_done.entry, 0, bytes);
  713. cmd.data0 = (u32) bytes;
  714. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_INTRQ_SIZE, &cmd, 0);
  715. cmd.data0 = MYRI10GE_LOWPART_TO_U32(mgp->rx_done.bus);
  716. cmd.data1 = MYRI10GE_HIGHPART_TO_U32(mgp->rx_done.bus);
  717. status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_INTRQ_DMA, &cmd, 0);
  718. status |=
  719. myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_IRQ_ACK_OFFSET, &cmd, 0);
  720. mgp->irq_claim = (__iomem __be32 *) (mgp->sram + cmd.data0);
  721. status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_IRQ_DEASSERT_OFFSET,
  722. &cmd, 0);
  723. mgp->irq_deassert = (__iomem __be32 *) (mgp->sram + cmd.data0);
  724. status |= myri10ge_send_cmd
  725. (mgp, MXGEFW_CMD_GET_INTR_COAL_DELAY_OFFSET, &cmd, 0);
  726. mgp->intr_coal_delay_ptr = (__iomem __be32 *) (mgp->sram + cmd.data0);
  727. if (status != 0) {
  728. dev_err(&mgp->pdev->dev, "failed set interrupt parameters\n");
  729. return status;
  730. }
  731. put_be32(htonl(mgp->intr_coal_delay), mgp->intr_coal_delay_ptr);
  732. memset(mgp->rx_done.entry, 0, bytes);
  733. /* reset mcp/driver shared state back to 0 */
  734. mgp->tx.req = 0;
  735. mgp->tx.done = 0;
  736. mgp->tx.pkt_start = 0;
  737. mgp->tx.pkt_done = 0;
  738. mgp->rx_big.cnt = 0;
  739. mgp->rx_small.cnt = 0;
  740. mgp->rx_done.idx = 0;
  741. mgp->rx_done.cnt = 0;
  742. mgp->link_changes = 0;
  743. status = myri10ge_update_mac_address(mgp, mgp->dev->dev_addr);
  744. myri10ge_change_pause(mgp, mgp->pause);
  745. myri10ge_set_multicast_list(mgp->dev);
  746. return status;
  747. }
  748. static inline void
  749. myri10ge_submit_8rx(struct mcp_kreq_ether_recv __iomem * dst,
  750. struct mcp_kreq_ether_recv *src)
  751. {
  752. __be32 low;
  753. low = src->addr_low;
  754. src->addr_low = htonl(DMA_32BIT_MASK);
  755. myri10ge_pio_copy(dst, src, 4 * sizeof(*src));
  756. mb();
  757. myri10ge_pio_copy(dst + 4, src + 4, 4 * sizeof(*src));
  758. mb();
  759. src->addr_low = low;
  760. put_be32(low, &dst->addr_low);
  761. mb();
  762. }
  763. static inline void myri10ge_vlan_ip_csum(struct sk_buff *skb, __wsum hw_csum)
  764. {
  765. struct vlan_hdr *vh = (struct vlan_hdr *)(skb->data);
  766. if ((skb->protocol == htons(ETH_P_8021Q)) &&
  767. (vh->h_vlan_encapsulated_proto == htons(ETH_P_IP) ||
  768. vh->h_vlan_encapsulated_proto == htons(ETH_P_IPV6))) {
  769. skb->csum = hw_csum;
  770. skb->ip_summed = CHECKSUM_COMPLETE;
  771. }
  772. }
  773. static inline void
  774. myri10ge_rx_skb_build(struct sk_buff *skb, u8 * va,
  775. struct skb_frag_struct *rx_frags, int len, int hlen)
  776. {
  777. struct skb_frag_struct *skb_frags;
  778. skb->len = skb->data_len = len;
  779. skb->truesize = len + sizeof(struct sk_buff);
  780. /* attach the page(s) */
  781. skb_frags = skb_shinfo(skb)->frags;
  782. while (len > 0) {
  783. memcpy(skb_frags, rx_frags, sizeof(*skb_frags));
  784. len -= rx_frags->size;
  785. skb_frags++;
  786. rx_frags++;
  787. skb_shinfo(skb)->nr_frags++;
  788. }
  789. /* pskb_may_pull is not available in irq context, but
  790. * skb_pull() (for ether_pad and eth_type_trans()) requires
  791. * the beginning of the packet in skb_headlen(), move it
  792. * manually */
  793. skb_copy_to_linear_data(skb, va, hlen);
  794. skb_shinfo(skb)->frags[0].page_offset += hlen;
  795. skb_shinfo(skb)->frags[0].size -= hlen;
  796. skb->data_len -= hlen;
  797. skb->tail += hlen;
  798. skb_pull(skb, MXGEFW_PAD);
  799. }
  800. static void
  801. myri10ge_alloc_rx_pages(struct myri10ge_priv *mgp, struct myri10ge_rx_buf *rx,
  802. int bytes, int watchdog)
  803. {
  804. struct page *page;
  805. int idx;
  806. if (unlikely(rx->watchdog_needed && !watchdog))
  807. return;
  808. /* try to refill entire ring */
  809. while (rx->fill_cnt != (rx->cnt + rx->mask + 1)) {
  810. idx = rx->fill_cnt & rx->mask;
  811. if (rx->page_offset + bytes <= MYRI10GE_ALLOC_SIZE) {
  812. /* we can use part of previous page */
  813. get_page(rx->page);
  814. } else {
  815. /* we need a new page */
  816. page =
  817. alloc_pages(GFP_ATOMIC | __GFP_COMP,
  818. MYRI10GE_ALLOC_ORDER);
  819. if (unlikely(page == NULL)) {
  820. if (rx->fill_cnt - rx->cnt < 16)
  821. rx->watchdog_needed = 1;
  822. return;
  823. }
  824. rx->page = page;
  825. rx->page_offset = 0;
  826. rx->bus = pci_map_page(mgp->pdev, page, 0,
  827. MYRI10GE_ALLOC_SIZE,
  828. PCI_DMA_FROMDEVICE);
  829. }
  830. rx->info[idx].page = rx->page;
  831. rx->info[idx].page_offset = rx->page_offset;
  832. /* note that this is the address of the start of the
  833. * page */
  834. pci_unmap_addr_set(&rx->info[idx], bus, rx->bus);
  835. rx->shadow[idx].addr_low =
  836. htonl(MYRI10GE_LOWPART_TO_U32(rx->bus) + rx->page_offset);
  837. rx->shadow[idx].addr_high =
  838. htonl(MYRI10GE_HIGHPART_TO_U32(rx->bus));
  839. /* start next packet on a cacheline boundary */
  840. rx->page_offset += SKB_DATA_ALIGN(bytes);
  841. #if MYRI10GE_ALLOC_SIZE > 4096
  842. /* don't cross a 4KB boundary */
  843. if ((rx->page_offset >> 12) !=
  844. ((rx->page_offset + bytes - 1) >> 12))
  845. rx->page_offset = (rx->page_offset + 4096) & ~4095;
  846. #endif
  847. rx->fill_cnt++;
  848. /* copy 8 descriptors to the firmware at a time */
  849. if ((idx & 7) == 7) {
  850. if (rx->wc_fifo == NULL)
  851. myri10ge_submit_8rx(&rx->lanai[idx - 7],
  852. &rx->shadow[idx - 7]);
  853. else {
  854. mb();
  855. myri10ge_pio_copy(rx->wc_fifo,
  856. &rx->shadow[idx - 7], 64);
  857. }
  858. }
  859. }
  860. }
  861. static inline void
  862. myri10ge_unmap_rx_page(struct pci_dev *pdev,
  863. struct myri10ge_rx_buffer_state *info, int bytes)
  864. {
  865. /* unmap the recvd page if we're the only or last user of it */
  866. if (bytes >= MYRI10GE_ALLOC_SIZE / 2 ||
  867. (info->page_offset + 2 * bytes) > MYRI10GE_ALLOC_SIZE) {
  868. pci_unmap_page(pdev, (pci_unmap_addr(info, bus)
  869. & ~(MYRI10GE_ALLOC_SIZE - 1)),
  870. MYRI10GE_ALLOC_SIZE, PCI_DMA_FROMDEVICE);
  871. }
  872. }
  873. #define MYRI10GE_HLEN 64 /* The number of bytes to copy from a
  874. * page into an skb */
  875. static inline int
  876. myri10ge_rx_done(struct myri10ge_priv *mgp, struct myri10ge_rx_buf *rx,
  877. int bytes, int len, __wsum csum)
  878. {
  879. struct sk_buff *skb;
  880. struct skb_frag_struct rx_frags[MYRI10GE_MAX_FRAGS_PER_FRAME];
  881. int i, idx, hlen, remainder;
  882. struct pci_dev *pdev = mgp->pdev;
  883. struct net_device *dev = mgp->dev;
  884. u8 *va;
  885. len += MXGEFW_PAD;
  886. idx = rx->cnt & rx->mask;
  887. va = page_address(rx->info[idx].page) + rx->info[idx].page_offset;
  888. prefetch(va);
  889. /* Fill skb_frag_struct(s) with data from our receive */
  890. for (i = 0, remainder = len; remainder > 0; i++) {
  891. myri10ge_unmap_rx_page(pdev, &rx->info[idx], bytes);
  892. rx_frags[i].page = rx->info[idx].page;
  893. rx_frags[i].page_offset = rx->info[idx].page_offset;
  894. if (remainder < MYRI10GE_ALLOC_SIZE)
  895. rx_frags[i].size = remainder;
  896. else
  897. rx_frags[i].size = MYRI10GE_ALLOC_SIZE;
  898. rx->cnt++;
  899. idx = rx->cnt & rx->mask;
  900. remainder -= MYRI10GE_ALLOC_SIZE;
  901. }
  902. if (mgp->csum_flag && myri10ge_lro) {
  903. rx_frags[0].page_offset += MXGEFW_PAD;
  904. rx_frags[0].size -= MXGEFW_PAD;
  905. len -= MXGEFW_PAD;
  906. lro_receive_frags(&mgp->rx_done.lro_mgr, rx_frags,
  907. len, len, (void *)(unsigned long)csum, csum);
  908. return 1;
  909. }
  910. hlen = MYRI10GE_HLEN > len ? len : MYRI10GE_HLEN;
  911. /* allocate an skb to attach the page(s) to. */
  912. skb = netdev_alloc_skb(dev, MYRI10GE_HLEN + 16);
  913. if (unlikely(skb == NULL)) {
  914. mgp->stats.rx_dropped++;
  915. do {
  916. i--;
  917. put_page(rx_frags[i].page);
  918. } while (i != 0);
  919. return 0;
  920. }
  921. /* Attach the pages to the skb, and trim off any padding */
  922. myri10ge_rx_skb_build(skb, va, rx_frags, len, hlen);
  923. if (skb_shinfo(skb)->frags[0].size <= 0) {
  924. put_page(skb_shinfo(skb)->frags[0].page);
  925. skb_shinfo(skb)->nr_frags = 0;
  926. }
  927. skb->protocol = eth_type_trans(skb, dev);
  928. if (mgp->csum_flag) {
  929. if ((skb->protocol == htons(ETH_P_IP)) ||
  930. (skb->protocol == htons(ETH_P_IPV6))) {
  931. skb->csum = csum;
  932. skb->ip_summed = CHECKSUM_COMPLETE;
  933. } else
  934. myri10ge_vlan_ip_csum(skb, csum);
  935. }
  936. netif_receive_skb(skb);
  937. dev->last_rx = jiffies;
  938. return 1;
  939. }
  940. static inline void myri10ge_tx_done(struct myri10ge_priv *mgp, int mcp_index)
  941. {
  942. struct pci_dev *pdev = mgp->pdev;
  943. struct myri10ge_tx_buf *tx = &mgp->tx;
  944. struct sk_buff *skb;
  945. int idx, len;
  946. while (tx->pkt_done != mcp_index) {
  947. idx = tx->done & tx->mask;
  948. skb = tx->info[idx].skb;
  949. /* Mark as free */
  950. tx->info[idx].skb = NULL;
  951. if (tx->info[idx].last) {
  952. tx->pkt_done++;
  953. tx->info[idx].last = 0;
  954. }
  955. tx->done++;
  956. len = pci_unmap_len(&tx->info[idx], len);
  957. pci_unmap_len_set(&tx->info[idx], len, 0);
  958. if (skb) {
  959. mgp->stats.tx_bytes += skb->len;
  960. mgp->stats.tx_packets++;
  961. dev_kfree_skb_irq(skb);
  962. if (len)
  963. pci_unmap_single(pdev,
  964. pci_unmap_addr(&tx->info[idx],
  965. bus), len,
  966. PCI_DMA_TODEVICE);
  967. } else {
  968. if (len)
  969. pci_unmap_page(pdev,
  970. pci_unmap_addr(&tx->info[idx],
  971. bus), len,
  972. PCI_DMA_TODEVICE);
  973. }
  974. }
  975. /* start the queue if we've stopped it */
  976. if (netif_queue_stopped(mgp->dev)
  977. && tx->req - tx->done < (tx->mask >> 1)) {
  978. mgp->wake_queue++;
  979. netif_wake_queue(mgp->dev);
  980. }
  981. }
  982. static inline int myri10ge_clean_rx_done(struct myri10ge_priv *mgp, int budget)
  983. {
  984. struct myri10ge_rx_done *rx_done = &mgp->rx_done;
  985. unsigned long rx_bytes = 0;
  986. unsigned long rx_packets = 0;
  987. unsigned long rx_ok;
  988. int idx = rx_done->idx;
  989. int cnt = rx_done->cnt;
  990. int work_done = 0;
  991. u16 length;
  992. __wsum checksum;
  993. while (rx_done->entry[idx].length != 0 && work_done++ < budget) {
  994. length = ntohs(rx_done->entry[idx].length);
  995. rx_done->entry[idx].length = 0;
  996. checksum = csum_unfold(rx_done->entry[idx].checksum);
  997. if (length <= mgp->small_bytes)
  998. rx_ok = myri10ge_rx_done(mgp, &mgp->rx_small,
  999. mgp->small_bytes,
  1000. length, checksum);
  1001. else
  1002. rx_ok = myri10ge_rx_done(mgp, &mgp->rx_big,
  1003. mgp->big_bytes,
  1004. length, checksum);
  1005. rx_packets += rx_ok;
  1006. rx_bytes += rx_ok * (unsigned long)length;
  1007. cnt++;
  1008. idx = cnt & (myri10ge_max_intr_slots - 1);
  1009. }
  1010. rx_done->idx = idx;
  1011. rx_done->cnt = cnt;
  1012. mgp->stats.rx_packets += rx_packets;
  1013. mgp->stats.rx_bytes += rx_bytes;
  1014. if (myri10ge_lro)
  1015. lro_flush_all(&rx_done->lro_mgr);
  1016. /* restock receive rings if needed */
  1017. if (mgp->rx_small.fill_cnt - mgp->rx_small.cnt < myri10ge_fill_thresh)
  1018. myri10ge_alloc_rx_pages(mgp, &mgp->rx_small,
  1019. mgp->small_bytes + MXGEFW_PAD, 0);
  1020. if (mgp->rx_big.fill_cnt - mgp->rx_big.cnt < myri10ge_fill_thresh)
  1021. myri10ge_alloc_rx_pages(mgp, &mgp->rx_big, mgp->big_bytes, 0);
  1022. return work_done;
  1023. }
  1024. static inline void myri10ge_check_statblock(struct myri10ge_priv *mgp)
  1025. {
  1026. struct mcp_irq_data *stats = mgp->fw_stats;
  1027. if (unlikely(stats->stats_updated)) {
  1028. unsigned link_up = ntohl(stats->link_up);
  1029. if (mgp->link_state != link_up) {
  1030. mgp->link_state = link_up;
  1031. if (mgp->link_state == MXGEFW_LINK_UP) {
  1032. if (netif_msg_link(mgp))
  1033. printk(KERN_INFO
  1034. "myri10ge: %s: link up\n",
  1035. mgp->dev->name);
  1036. netif_carrier_on(mgp->dev);
  1037. mgp->link_changes++;
  1038. } else {
  1039. if (netif_msg_link(mgp))
  1040. printk(KERN_INFO
  1041. "myri10ge: %s: link %s\n",
  1042. mgp->dev->name,
  1043. (link_up == MXGEFW_LINK_MYRINET ?
  1044. "mismatch (Myrinet detected)" :
  1045. "down"));
  1046. netif_carrier_off(mgp->dev);
  1047. mgp->link_changes++;
  1048. }
  1049. }
  1050. if (mgp->rdma_tags_available !=
  1051. ntohl(mgp->fw_stats->rdma_tags_available)) {
  1052. mgp->rdma_tags_available =
  1053. ntohl(mgp->fw_stats->rdma_tags_available);
  1054. printk(KERN_WARNING "myri10ge: %s: RDMA timed out! "
  1055. "%d tags left\n", mgp->dev->name,
  1056. mgp->rdma_tags_available);
  1057. }
  1058. mgp->down_cnt += stats->link_down;
  1059. if (stats->link_down)
  1060. wake_up(&mgp->down_wq);
  1061. }
  1062. }
  1063. static int myri10ge_poll(struct napi_struct *napi, int budget)
  1064. {
  1065. struct myri10ge_priv *mgp = container_of(napi, struct myri10ge_priv, napi);
  1066. struct net_device *netdev = mgp->dev;
  1067. struct myri10ge_rx_done *rx_done = &mgp->rx_done;
  1068. int work_done;
  1069. /* process as many rx events as NAPI will allow */
  1070. work_done = myri10ge_clean_rx_done(mgp, budget);
  1071. if (rx_done->entry[rx_done->idx].length == 0 || !netif_running(netdev)) {
  1072. netif_rx_complete(netdev, napi);
  1073. put_be32(htonl(3), mgp->irq_claim);
  1074. }
  1075. return work_done;
  1076. }
  1077. static irqreturn_t myri10ge_intr(int irq, void *arg)
  1078. {
  1079. struct myri10ge_priv *mgp = arg;
  1080. struct mcp_irq_data *stats = mgp->fw_stats;
  1081. struct myri10ge_tx_buf *tx = &mgp->tx;
  1082. u32 send_done_count;
  1083. int i;
  1084. /* make sure it is our IRQ, and that the DMA has finished */
  1085. if (unlikely(!stats->valid))
  1086. return (IRQ_NONE);
  1087. /* low bit indicates receives are present, so schedule
  1088. * napi poll handler */
  1089. if (stats->valid & 1)
  1090. netif_rx_schedule(mgp->dev, &mgp->napi);
  1091. if (!mgp->msi_enabled) {
  1092. put_be32(0, mgp->irq_deassert);
  1093. if (!myri10ge_deassert_wait)
  1094. stats->valid = 0;
  1095. mb();
  1096. } else
  1097. stats->valid = 0;
  1098. /* Wait for IRQ line to go low, if using INTx */
  1099. i = 0;
  1100. while (1) {
  1101. i++;
  1102. /* check for transmit completes and receives */
  1103. send_done_count = ntohl(stats->send_done_count);
  1104. if (send_done_count != tx->pkt_done)
  1105. myri10ge_tx_done(mgp, (int)send_done_count);
  1106. if (unlikely(i > myri10ge_max_irq_loops)) {
  1107. printk(KERN_WARNING "myri10ge: %s: irq stuck?\n",
  1108. mgp->dev->name);
  1109. stats->valid = 0;
  1110. schedule_work(&mgp->watchdog_work);
  1111. }
  1112. if (likely(stats->valid == 0))
  1113. break;
  1114. cpu_relax();
  1115. barrier();
  1116. }
  1117. myri10ge_check_statblock(mgp);
  1118. put_be32(htonl(3), mgp->irq_claim + 1);
  1119. return (IRQ_HANDLED);
  1120. }
  1121. static int
  1122. myri10ge_get_settings(struct net_device *netdev, struct ethtool_cmd *cmd)
  1123. {
  1124. cmd->autoneg = AUTONEG_DISABLE;
  1125. cmd->speed = SPEED_10000;
  1126. cmd->duplex = DUPLEX_FULL;
  1127. return 0;
  1128. }
  1129. static void
  1130. myri10ge_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *info)
  1131. {
  1132. struct myri10ge_priv *mgp = netdev_priv(netdev);
  1133. strlcpy(info->driver, "myri10ge", sizeof(info->driver));
  1134. strlcpy(info->version, MYRI10GE_VERSION_STR, sizeof(info->version));
  1135. strlcpy(info->fw_version, mgp->fw_version, sizeof(info->fw_version));
  1136. strlcpy(info->bus_info, pci_name(mgp->pdev), sizeof(info->bus_info));
  1137. }
  1138. static int
  1139. myri10ge_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coal)
  1140. {
  1141. struct myri10ge_priv *mgp = netdev_priv(netdev);
  1142. coal->rx_coalesce_usecs = mgp->intr_coal_delay;
  1143. return 0;
  1144. }
  1145. static int
  1146. myri10ge_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coal)
  1147. {
  1148. struct myri10ge_priv *mgp = netdev_priv(netdev);
  1149. mgp->intr_coal_delay = coal->rx_coalesce_usecs;
  1150. put_be32(htonl(mgp->intr_coal_delay), mgp->intr_coal_delay_ptr);
  1151. return 0;
  1152. }
  1153. static void
  1154. myri10ge_get_pauseparam(struct net_device *netdev,
  1155. struct ethtool_pauseparam *pause)
  1156. {
  1157. struct myri10ge_priv *mgp = netdev_priv(netdev);
  1158. pause->autoneg = 0;
  1159. pause->rx_pause = mgp->pause;
  1160. pause->tx_pause = mgp->pause;
  1161. }
  1162. static int
  1163. myri10ge_set_pauseparam(struct net_device *netdev,
  1164. struct ethtool_pauseparam *pause)
  1165. {
  1166. struct myri10ge_priv *mgp = netdev_priv(netdev);
  1167. if (pause->tx_pause != mgp->pause)
  1168. return myri10ge_change_pause(mgp, pause->tx_pause);
  1169. if (pause->rx_pause != mgp->pause)
  1170. return myri10ge_change_pause(mgp, pause->tx_pause);
  1171. if (pause->autoneg != 0)
  1172. return -EINVAL;
  1173. return 0;
  1174. }
  1175. static void
  1176. myri10ge_get_ringparam(struct net_device *netdev,
  1177. struct ethtool_ringparam *ring)
  1178. {
  1179. struct myri10ge_priv *mgp = netdev_priv(netdev);
  1180. ring->rx_mini_max_pending = mgp->rx_small.mask + 1;
  1181. ring->rx_max_pending = mgp->rx_big.mask + 1;
  1182. ring->rx_jumbo_max_pending = 0;
  1183. ring->tx_max_pending = mgp->rx_small.mask + 1;
  1184. ring->rx_mini_pending = ring->rx_mini_max_pending;
  1185. ring->rx_pending = ring->rx_max_pending;
  1186. ring->rx_jumbo_pending = ring->rx_jumbo_max_pending;
  1187. ring->tx_pending = ring->tx_max_pending;
  1188. }
  1189. static u32 myri10ge_get_rx_csum(struct net_device *netdev)
  1190. {
  1191. struct myri10ge_priv *mgp = netdev_priv(netdev);
  1192. if (mgp->csum_flag)
  1193. return 1;
  1194. else
  1195. return 0;
  1196. }
  1197. static int myri10ge_set_rx_csum(struct net_device *netdev, u32 csum_enabled)
  1198. {
  1199. struct myri10ge_priv *mgp = netdev_priv(netdev);
  1200. if (csum_enabled)
  1201. mgp->csum_flag = MXGEFW_FLAGS_CKSUM;
  1202. else
  1203. mgp->csum_flag = 0;
  1204. return 0;
  1205. }
  1206. static const char myri10ge_gstrings_stats[][ETH_GSTRING_LEN] = {
  1207. "rx_packets", "tx_packets", "rx_bytes", "tx_bytes", "rx_errors",
  1208. "tx_errors", "rx_dropped", "tx_dropped", "multicast", "collisions",
  1209. "rx_length_errors", "rx_over_errors", "rx_crc_errors",
  1210. "rx_frame_errors", "rx_fifo_errors", "rx_missed_errors",
  1211. "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors",
  1212. "tx_heartbeat_errors", "tx_window_errors",
  1213. /* device-specific stats */
  1214. "tx_boundary", "WC", "irq", "MSI",
  1215. "read_dma_bw_MBs", "write_dma_bw_MBs", "read_write_dma_bw_MBs",
  1216. "serial_number", "tx_pkt_start", "tx_pkt_done",
  1217. "tx_req", "tx_done", "rx_small_cnt", "rx_big_cnt",
  1218. "wake_queue", "stop_queue", "watchdog_resets", "tx_linearized",
  1219. "link_changes", "link_up", "dropped_link_overflow",
  1220. "dropped_link_error_or_filtered",
  1221. "dropped_pause", "dropped_bad_phy", "dropped_bad_crc32",
  1222. "dropped_unicast_filtered", "dropped_multicast_filtered",
  1223. "dropped_runt", "dropped_overrun", "dropped_no_small_buffer",
  1224. "dropped_no_big_buffer", "LRO aggregated", "LRO flushed",
  1225. "LRO avg aggr", "LRO no_desc"
  1226. };
  1227. #define MYRI10GE_NET_STATS_LEN 21
  1228. #define MYRI10GE_STATS_LEN sizeof(myri10ge_gstrings_stats) / ETH_GSTRING_LEN
  1229. static void
  1230. myri10ge_get_strings(struct net_device *netdev, u32 stringset, u8 * data)
  1231. {
  1232. switch (stringset) {
  1233. case ETH_SS_STATS:
  1234. memcpy(data, *myri10ge_gstrings_stats,
  1235. sizeof(myri10ge_gstrings_stats));
  1236. break;
  1237. }
  1238. }
  1239. static int myri10ge_get_stats_count(struct net_device *netdev)
  1240. {
  1241. return MYRI10GE_STATS_LEN;
  1242. }
  1243. static void
  1244. myri10ge_get_ethtool_stats(struct net_device *netdev,
  1245. struct ethtool_stats *stats, u64 * data)
  1246. {
  1247. struct myri10ge_priv *mgp = netdev_priv(netdev);
  1248. int i;
  1249. for (i = 0; i < MYRI10GE_NET_STATS_LEN; i++)
  1250. data[i] = ((unsigned long *)&mgp->stats)[i];
  1251. data[i++] = (unsigned int)mgp->tx.boundary;
  1252. data[i++] = (unsigned int)mgp->wc_enabled;
  1253. data[i++] = (unsigned int)mgp->pdev->irq;
  1254. data[i++] = (unsigned int)mgp->msi_enabled;
  1255. data[i++] = (unsigned int)mgp->read_dma;
  1256. data[i++] = (unsigned int)mgp->write_dma;
  1257. data[i++] = (unsigned int)mgp->read_write_dma;
  1258. data[i++] = (unsigned int)mgp->serial_number;
  1259. data[i++] = (unsigned int)mgp->tx.pkt_start;
  1260. data[i++] = (unsigned int)mgp->tx.pkt_done;
  1261. data[i++] = (unsigned int)mgp->tx.req;
  1262. data[i++] = (unsigned int)mgp->tx.done;
  1263. data[i++] = (unsigned int)mgp->rx_small.cnt;
  1264. data[i++] = (unsigned int)mgp->rx_big.cnt;
  1265. data[i++] = (unsigned int)mgp->wake_queue;
  1266. data[i++] = (unsigned int)mgp->stop_queue;
  1267. data[i++] = (unsigned int)mgp->watchdog_resets;
  1268. data[i++] = (unsigned int)mgp->tx_linearized;
  1269. data[i++] = (unsigned int)mgp->link_changes;
  1270. data[i++] = (unsigned int)ntohl(mgp->fw_stats->link_up);
  1271. data[i++] = (unsigned int)ntohl(mgp->fw_stats->dropped_link_overflow);
  1272. data[i++] =
  1273. (unsigned int)ntohl(mgp->fw_stats->dropped_link_error_or_filtered);
  1274. data[i++] = (unsigned int)ntohl(mgp->fw_stats->dropped_pause);
  1275. data[i++] = (unsigned int)ntohl(mgp->fw_stats->dropped_bad_phy);
  1276. data[i++] = (unsigned int)ntohl(mgp->fw_stats->dropped_bad_crc32);
  1277. data[i++] =
  1278. (unsigned int)ntohl(mgp->fw_stats->dropped_unicast_filtered);
  1279. data[i++] =
  1280. (unsigned int)ntohl(mgp->fw_stats->dropped_multicast_filtered);
  1281. data[i++] = (unsigned int)ntohl(mgp->fw_stats->dropped_runt);
  1282. data[i++] = (unsigned int)ntohl(mgp->fw_stats->dropped_overrun);
  1283. data[i++] = (unsigned int)ntohl(mgp->fw_stats->dropped_no_small_buffer);
  1284. data[i++] = (unsigned int)ntohl(mgp->fw_stats->dropped_no_big_buffer);
  1285. data[i++] = mgp->rx_done.lro_mgr.stats.aggregated;
  1286. data[i++] = mgp->rx_done.lro_mgr.stats.flushed;
  1287. if (mgp->rx_done.lro_mgr.stats.flushed)
  1288. data[i++] = mgp->rx_done.lro_mgr.stats.aggregated /
  1289. mgp->rx_done.lro_mgr.stats.flushed;
  1290. else
  1291. data[i++] = 0;
  1292. data[i++] = mgp->rx_done.lro_mgr.stats.no_desc;
  1293. }
  1294. static void myri10ge_set_msglevel(struct net_device *netdev, u32 value)
  1295. {
  1296. struct myri10ge_priv *mgp = netdev_priv(netdev);
  1297. mgp->msg_enable = value;
  1298. }
  1299. static u32 myri10ge_get_msglevel(struct net_device *netdev)
  1300. {
  1301. struct myri10ge_priv *mgp = netdev_priv(netdev);
  1302. return mgp->msg_enable;
  1303. }
  1304. static const struct ethtool_ops myri10ge_ethtool_ops = {
  1305. .get_settings = myri10ge_get_settings,
  1306. .get_drvinfo = myri10ge_get_drvinfo,
  1307. .get_coalesce = myri10ge_get_coalesce,
  1308. .set_coalesce = myri10ge_set_coalesce,
  1309. .get_pauseparam = myri10ge_get_pauseparam,
  1310. .set_pauseparam = myri10ge_set_pauseparam,
  1311. .get_ringparam = myri10ge_get_ringparam,
  1312. .get_rx_csum = myri10ge_get_rx_csum,
  1313. .set_rx_csum = myri10ge_set_rx_csum,
  1314. .set_tx_csum = ethtool_op_set_tx_hw_csum,
  1315. .set_sg = ethtool_op_set_sg,
  1316. .set_tso = ethtool_op_set_tso,
  1317. .get_link = ethtool_op_get_link,
  1318. .get_strings = myri10ge_get_strings,
  1319. .get_stats_count = myri10ge_get_stats_count,
  1320. .get_ethtool_stats = myri10ge_get_ethtool_stats,
  1321. .set_msglevel = myri10ge_set_msglevel,
  1322. .get_msglevel = myri10ge_get_msglevel
  1323. };
  1324. static int myri10ge_allocate_rings(struct net_device *dev)
  1325. {
  1326. struct myri10ge_priv *mgp;
  1327. struct myri10ge_cmd cmd;
  1328. int tx_ring_size, rx_ring_size;
  1329. int tx_ring_entries, rx_ring_entries;
  1330. int i, status;
  1331. size_t bytes;
  1332. mgp = netdev_priv(dev);
  1333. /* get ring sizes */
  1334. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_SEND_RING_SIZE, &cmd, 0);
  1335. tx_ring_size = cmd.data0;
  1336. status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_RX_RING_SIZE, &cmd, 0);
  1337. if (status != 0)
  1338. return status;
  1339. rx_ring_size = cmd.data0;
  1340. tx_ring_entries = tx_ring_size / sizeof(struct mcp_kreq_ether_send);
  1341. rx_ring_entries = rx_ring_size / sizeof(struct mcp_dma_addr);
  1342. mgp->tx.mask = tx_ring_entries - 1;
  1343. mgp->rx_small.mask = mgp->rx_big.mask = rx_ring_entries - 1;
  1344. status = -ENOMEM;
  1345. /* allocate the host shadow rings */
  1346. bytes = 8 + (MYRI10GE_MAX_SEND_DESC_TSO + 4)
  1347. * sizeof(*mgp->tx.req_list);
  1348. mgp->tx.req_bytes = kzalloc(bytes, GFP_KERNEL);
  1349. if (mgp->tx.req_bytes == NULL)
  1350. goto abort_with_nothing;
  1351. /* ensure req_list entries are aligned to 8 bytes */
  1352. mgp->tx.req_list = (struct mcp_kreq_ether_send *)
  1353. ALIGN((unsigned long)mgp->tx.req_bytes, 8);
  1354. bytes = rx_ring_entries * sizeof(*mgp->rx_small.shadow);
  1355. mgp->rx_small.shadow = kzalloc(bytes, GFP_KERNEL);
  1356. if (mgp->rx_small.shadow == NULL)
  1357. goto abort_with_tx_req_bytes;
  1358. bytes = rx_ring_entries * sizeof(*mgp->rx_big.shadow);
  1359. mgp->rx_big.shadow = kzalloc(bytes, GFP_KERNEL);
  1360. if (mgp->rx_big.shadow == NULL)
  1361. goto abort_with_rx_small_shadow;
  1362. /* allocate the host info rings */
  1363. bytes = tx_ring_entries * sizeof(*mgp->tx.info);
  1364. mgp->tx.info = kzalloc(bytes, GFP_KERNEL);
  1365. if (mgp->tx.info == NULL)
  1366. goto abort_with_rx_big_shadow;
  1367. bytes = rx_ring_entries * sizeof(*mgp->rx_small.info);
  1368. mgp->rx_small.info = kzalloc(bytes, GFP_KERNEL);
  1369. if (mgp->rx_small.info == NULL)
  1370. goto abort_with_tx_info;
  1371. bytes = rx_ring_entries * sizeof(*mgp->rx_big.info);
  1372. mgp->rx_big.info = kzalloc(bytes, GFP_KERNEL);
  1373. if (mgp->rx_big.info == NULL)
  1374. goto abort_with_rx_small_info;
  1375. /* Fill the receive rings */
  1376. mgp->rx_big.cnt = 0;
  1377. mgp->rx_small.cnt = 0;
  1378. mgp->rx_big.fill_cnt = 0;
  1379. mgp->rx_small.fill_cnt = 0;
  1380. mgp->rx_small.page_offset = MYRI10GE_ALLOC_SIZE;
  1381. mgp->rx_big.page_offset = MYRI10GE_ALLOC_SIZE;
  1382. mgp->rx_small.watchdog_needed = 0;
  1383. mgp->rx_big.watchdog_needed = 0;
  1384. myri10ge_alloc_rx_pages(mgp, &mgp->rx_small,
  1385. mgp->small_bytes + MXGEFW_PAD, 0);
  1386. if (mgp->rx_small.fill_cnt < mgp->rx_small.mask + 1) {
  1387. printk(KERN_ERR "myri10ge: %s: alloced only %d small bufs\n",
  1388. dev->name, mgp->rx_small.fill_cnt);
  1389. goto abort_with_rx_small_ring;
  1390. }
  1391. myri10ge_alloc_rx_pages(mgp, &mgp->rx_big, mgp->big_bytes, 0);
  1392. if (mgp->rx_big.fill_cnt < mgp->rx_big.mask + 1) {
  1393. printk(KERN_ERR "myri10ge: %s: alloced only %d big bufs\n",
  1394. dev->name, mgp->rx_big.fill_cnt);
  1395. goto abort_with_rx_big_ring;
  1396. }
  1397. return 0;
  1398. abort_with_rx_big_ring:
  1399. for (i = mgp->rx_big.cnt; i < mgp->rx_big.fill_cnt; i++) {
  1400. int idx = i & mgp->rx_big.mask;
  1401. myri10ge_unmap_rx_page(mgp->pdev, &mgp->rx_big.info[idx],
  1402. mgp->big_bytes);
  1403. put_page(mgp->rx_big.info[idx].page);
  1404. }
  1405. abort_with_rx_small_ring:
  1406. for (i = mgp->rx_small.cnt; i < mgp->rx_small.fill_cnt; i++) {
  1407. int idx = i & mgp->rx_small.mask;
  1408. myri10ge_unmap_rx_page(mgp->pdev, &mgp->rx_small.info[idx],
  1409. mgp->small_bytes + MXGEFW_PAD);
  1410. put_page(mgp->rx_small.info[idx].page);
  1411. }
  1412. kfree(mgp->rx_big.info);
  1413. abort_with_rx_small_info:
  1414. kfree(mgp->rx_small.info);
  1415. abort_with_tx_info:
  1416. kfree(mgp->tx.info);
  1417. abort_with_rx_big_shadow:
  1418. kfree(mgp->rx_big.shadow);
  1419. abort_with_rx_small_shadow:
  1420. kfree(mgp->rx_small.shadow);
  1421. abort_with_tx_req_bytes:
  1422. kfree(mgp->tx.req_bytes);
  1423. mgp->tx.req_bytes = NULL;
  1424. mgp->tx.req_list = NULL;
  1425. abort_with_nothing:
  1426. return status;
  1427. }
  1428. static void myri10ge_free_rings(struct net_device *dev)
  1429. {
  1430. struct myri10ge_priv *mgp;
  1431. struct sk_buff *skb;
  1432. struct myri10ge_tx_buf *tx;
  1433. int i, len, idx;
  1434. mgp = netdev_priv(dev);
  1435. for (i = mgp->rx_big.cnt; i < mgp->rx_big.fill_cnt; i++) {
  1436. idx = i & mgp->rx_big.mask;
  1437. if (i == mgp->rx_big.fill_cnt - 1)
  1438. mgp->rx_big.info[idx].page_offset = MYRI10GE_ALLOC_SIZE;
  1439. myri10ge_unmap_rx_page(mgp->pdev, &mgp->rx_big.info[idx],
  1440. mgp->big_bytes);
  1441. put_page(mgp->rx_big.info[idx].page);
  1442. }
  1443. for (i = mgp->rx_small.cnt; i < mgp->rx_small.fill_cnt; i++) {
  1444. idx = i & mgp->rx_small.mask;
  1445. if (i == mgp->rx_small.fill_cnt - 1)
  1446. mgp->rx_small.info[idx].page_offset =
  1447. MYRI10GE_ALLOC_SIZE;
  1448. myri10ge_unmap_rx_page(mgp->pdev, &mgp->rx_small.info[idx],
  1449. mgp->small_bytes + MXGEFW_PAD);
  1450. put_page(mgp->rx_small.info[idx].page);
  1451. }
  1452. tx = &mgp->tx;
  1453. while (tx->done != tx->req) {
  1454. idx = tx->done & tx->mask;
  1455. skb = tx->info[idx].skb;
  1456. /* Mark as free */
  1457. tx->info[idx].skb = NULL;
  1458. tx->done++;
  1459. len = pci_unmap_len(&tx->info[idx], len);
  1460. pci_unmap_len_set(&tx->info[idx], len, 0);
  1461. if (skb) {
  1462. mgp->stats.tx_dropped++;
  1463. dev_kfree_skb_any(skb);
  1464. if (len)
  1465. pci_unmap_single(mgp->pdev,
  1466. pci_unmap_addr(&tx->info[idx],
  1467. bus), len,
  1468. PCI_DMA_TODEVICE);
  1469. } else {
  1470. if (len)
  1471. pci_unmap_page(mgp->pdev,
  1472. pci_unmap_addr(&tx->info[idx],
  1473. bus), len,
  1474. PCI_DMA_TODEVICE);
  1475. }
  1476. }
  1477. kfree(mgp->rx_big.info);
  1478. kfree(mgp->rx_small.info);
  1479. kfree(mgp->tx.info);
  1480. kfree(mgp->rx_big.shadow);
  1481. kfree(mgp->rx_small.shadow);
  1482. kfree(mgp->tx.req_bytes);
  1483. mgp->tx.req_bytes = NULL;
  1484. mgp->tx.req_list = NULL;
  1485. }
  1486. static int myri10ge_request_irq(struct myri10ge_priv *mgp)
  1487. {
  1488. struct pci_dev *pdev = mgp->pdev;
  1489. int status;
  1490. if (myri10ge_msi) {
  1491. status = pci_enable_msi(pdev);
  1492. if (status != 0)
  1493. dev_err(&pdev->dev,
  1494. "Error %d setting up MSI; falling back to xPIC\n",
  1495. status);
  1496. else
  1497. mgp->msi_enabled = 1;
  1498. } else {
  1499. mgp->msi_enabled = 0;
  1500. }
  1501. status = request_irq(pdev->irq, myri10ge_intr, IRQF_SHARED,
  1502. mgp->dev->name, mgp);
  1503. if (status != 0) {
  1504. dev_err(&pdev->dev, "failed to allocate IRQ\n");
  1505. if (mgp->msi_enabled)
  1506. pci_disable_msi(pdev);
  1507. }
  1508. return status;
  1509. }
  1510. static void myri10ge_free_irq(struct myri10ge_priv *mgp)
  1511. {
  1512. struct pci_dev *pdev = mgp->pdev;
  1513. free_irq(pdev->irq, mgp);
  1514. if (mgp->msi_enabled)
  1515. pci_disable_msi(pdev);
  1516. }
  1517. static int
  1518. myri10ge_get_frag_header(struct skb_frag_struct *frag, void **mac_hdr,
  1519. void **ip_hdr, void **tcpudp_hdr,
  1520. u64 * hdr_flags, void *priv)
  1521. {
  1522. struct ethhdr *eh;
  1523. struct vlan_ethhdr *veh;
  1524. struct iphdr *iph;
  1525. u8 *va = page_address(frag->page) + frag->page_offset;
  1526. unsigned long ll_hlen;
  1527. __wsum csum = (__wsum) (unsigned long)priv;
  1528. /* find the mac header, aborting if not IPv4 */
  1529. eh = (struct ethhdr *)va;
  1530. *mac_hdr = eh;
  1531. ll_hlen = ETH_HLEN;
  1532. if (eh->h_proto != htons(ETH_P_IP)) {
  1533. if (eh->h_proto == htons(ETH_P_8021Q)) {
  1534. veh = (struct vlan_ethhdr *)va;
  1535. if (veh->h_vlan_encapsulated_proto != htons(ETH_P_IP))
  1536. return -1;
  1537. ll_hlen += VLAN_HLEN;
  1538. /*
  1539. * HW checksum starts ETH_HLEN bytes into
  1540. * frame, so we must subtract off the VLAN
  1541. * header's checksum before csum can be used
  1542. */
  1543. csum = csum_sub(csum, csum_partial(va + ETH_HLEN,
  1544. VLAN_HLEN, 0));
  1545. } else {
  1546. return -1;
  1547. }
  1548. }
  1549. *hdr_flags = LRO_IPV4;
  1550. iph = (struct iphdr *)(va + ll_hlen);
  1551. *ip_hdr = iph;
  1552. if (iph->protocol != IPPROTO_TCP)
  1553. return -1;
  1554. *hdr_flags |= LRO_TCP;
  1555. *tcpudp_hdr = (u8 *) (*ip_hdr) + (iph->ihl << 2);
  1556. /* verify the IP checksum */
  1557. if (unlikely(ip_fast_csum((u8 *) iph, iph->ihl)))
  1558. return -1;
  1559. /* verify the checksum */
  1560. if (unlikely(csum_tcpudp_magic(iph->saddr, iph->daddr,
  1561. ntohs(iph->tot_len) - (iph->ihl << 2),
  1562. IPPROTO_TCP, csum)))
  1563. return -1;
  1564. return 0;
  1565. }
  1566. static int myri10ge_open(struct net_device *dev)
  1567. {
  1568. struct myri10ge_priv *mgp;
  1569. struct myri10ge_cmd cmd;
  1570. struct net_lro_mgr *lro_mgr;
  1571. int status, big_pow2;
  1572. mgp = netdev_priv(dev);
  1573. if (mgp->running != MYRI10GE_ETH_STOPPED)
  1574. return -EBUSY;
  1575. mgp->running = MYRI10GE_ETH_STARTING;
  1576. status = myri10ge_reset(mgp);
  1577. if (status != 0) {
  1578. printk(KERN_ERR "myri10ge: %s: failed reset\n", dev->name);
  1579. goto abort_with_nothing;
  1580. }
  1581. status = myri10ge_request_irq(mgp);
  1582. if (status != 0)
  1583. goto abort_with_nothing;
  1584. /* decide what small buffer size to use. For good TCP rx
  1585. * performance, it is important to not receive 1514 byte
  1586. * frames into jumbo buffers, as it confuses the socket buffer
  1587. * accounting code, leading to drops and erratic performance.
  1588. */
  1589. if (dev->mtu <= ETH_DATA_LEN)
  1590. /* enough for a TCP header */
  1591. mgp->small_bytes = (128 > SMP_CACHE_BYTES)
  1592. ? (128 - MXGEFW_PAD)
  1593. : (SMP_CACHE_BYTES - MXGEFW_PAD);
  1594. else
  1595. /* enough for a vlan encapsulated ETH_DATA_LEN frame */
  1596. mgp->small_bytes = VLAN_ETH_FRAME_LEN;
  1597. /* Override the small buffer size? */
  1598. if (myri10ge_small_bytes > 0)
  1599. mgp->small_bytes = myri10ge_small_bytes;
  1600. /* get the lanai pointers to the send and receive rings */
  1601. status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_SEND_OFFSET, &cmd, 0);
  1602. mgp->tx.lanai =
  1603. (struct mcp_kreq_ether_send __iomem *)(mgp->sram + cmd.data0);
  1604. status |=
  1605. myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_SMALL_RX_OFFSET, &cmd, 0);
  1606. mgp->rx_small.lanai =
  1607. (struct mcp_kreq_ether_recv __iomem *)(mgp->sram + cmd.data0);
  1608. status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_BIG_RX_OFFSET, &cmd, 0);
  1609. mgp->rx_big.lanai =
  1610. (struct mcp_kreq_ether_recv __iomem *)(mgp->sram + cmd.data0);
  1611. if (status != 0) {
  1612. printk(KERN_ERR
  1613. "myri10ge: %s: failed to get ring sizes or locations\n",
  1614. dev->name);
  1615. mgp->running = MYRI10GE_ETH_STOPPED;
  1616. goto abort_with_irq;
  1617. }
  1618. if (myri10ge_wcfifo && mgp->wc_enabled) {
  1619. mgp->tx.wc_fifo = (u8 __iomem *) mgp->sram + MXGEFW_ETH_SEND_4;
  1620. mgp->rx_small.wc_fifo =
  1621. (u8 __iomem *) mgp->sram + MXGEFW_ETH_RECV_SMALL;
  1622. mgp->rx_big.wc_fifo =
  1623. (u8 __iomem *) mgp->sram + MXGEFW_ETH_RECV_BIG;
  1624. } else {
  1625. mgp->tx.wc_fifo = NULL;
  1626. mgp->rx_small.wc_fifo = NULL;
  1627. mgp->rx_big.wc_fifo = NULL;
  1628. }
  1629. /* Firmware needs the big buff size as a power of 2. Lie and
  1630. * tell him the buffer is larger, because we only use 1
  1631. * buffer/pkt, and the mtu will prevent overruns.
  1632. */
  1633. big_pow2 = dev->mtu + ETH_HLEN + VLAN_HLEN + MXGEFW_PAD;
  1634. if (big_pow2 < MYRI10GE_ALLOC_SIZE / 2) {
  1635. while (!is_power_of_2(big_pow2))
  1636. big_pow2++;
  1637. mgp->big_bytes = dev->mtu + ETH_HLEN + VLAN_HLEN + MXGEFW_PAD;
  1638. } else {
  1639. big_pow2 = MYRI10GE_ALLOC_SIZE;
  1640. mgp->big_bytes = big_pow2;
  1641. }
  1642. status = myri10ge_allocate_rings(dev);
  1643. if (status != 0)
  1644. goto abort_with_irq;
  1645. /* now give firmware buffers sizes, and MTU */
  1646. cmd.data0 = dev->mtu + ETH_HLEN + VLAN_HLEN;
  1647. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_MTU, &cmd, 0);
  1648. cmd.data0 = mgp->small_bytes;
  1649. status |=
  1650. myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_SMALL_BUFFER_SIZE, &cmd, 0);
  1651. cmd.data0 = big_pow2;
  1652. status |=
  1653. myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_BIG_BUFFER_SIZE, &cmd, 0);
  1654. if (status) {
  1655. printk(KERN_ERR "myri10ge: %s: Couldn't set buffer sizes\n",
  1656. dev->name);
  1657. goto abort_with_rings;
  1658. }
  1659. cmd.data0 = MYRI10GE_LOWPART_TO_U32(mgp->fw_stats_bus);
  1660. cmd.data1 = MYRI10GE_HIGHPART_TO_U32(mgp->fw_stats_bus);
  1661. cmd.data2 = sizeof(struct mcp_irq_data);
  1662. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_STATS_DMA_V2, &cmd, 0);
  1663. if (status == -ENOSYS) {
  1664. dma_addr_t bus = mgp->fw_stats_bus;
  1665. bus += offsetof(struct mcp_irq_data, send_done_count);
  1666. cmd.data0 = MYRI10GE_LOWPART_TO_U32(bus);
  1667. cmd.data1 = MYRI10GE_HIGHPART_TO_U32(bus);
  1668. status = myri10ge_send_cmd(mgp,
  1669. MXGEFW_CMD_SET_STATS_DMA_OBSOLETE,
  1670. &cmd, 0);
  1671. /* Firmware cannot support multicast without STATS_DMA_V2 */
  1672. mgp->fw_multicast_support = 0;
  1673. } else {
  1674. mgp->fw_multicast_support = 1;
  1675. }
  1676. if (status) {
  1677. printk(KERN_ERR "myri10ge: %s: Couldn't set stats DMA\n",
  1678. dev->name);
  1679. goto abort_with_rings;
  1680. }
  1681. mgp->link_state = htonl(~0U);
  1682. mgp->rdma_tags_available = 15;
  1683. lro_mgr = &mgp->rx_done.lro_mgr;
  1684. lro_mgr->dev = dev;
  1685. lro_mgr->features = LRO_F_NAPI;
  1686. lro_mgr->ip_summed = CHECKSUM_COMPLETE;
  1687. lro_mgr->ip_summed_aggr = CHECKSUM_UNNECESSARY;
  1688. lro_mgr->max_desc = MYRI10GE_MAX_LRO_DESCRIPTORS;
  1689. lro_mgr->lro_arr = mgp->rx_done.lro_desc;
  1690. lro_mgr->get_frag_header = myri10ge_get_frag_header;
  1691. lro_mgr->max_aggr = myri10ge_lro_max_pkts;
  1692. if (lro_mgr->max_aggr > MAX_SKB_FRAGS)
  1693. lro_mgr->max_aggr = MAX_SKB_FRAGS;
  1694. napi_enable(&mgp->napi); /* must happen prior to any irq */
  1695. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_ETHERNET_UP, &cmd, 0);
  1696. if (status) {
  1697. printk(KERN_ERR "myri10ge: %s: Couldn't bring up link\n",
  1698. dev->name);
  1699. goto abort_with_rings;
  1700. }
  1701. mgp->wake_queue = 0;
  1702. mgp->stop_queue = 0;
  1703. mgp->running = MYRI10GE_ETH_RUNNING;
  1704. mgp->watchdog_timer.expires = jiffies + myri10ge_watchdog_timeout * HZ;
  1705. add_timer(&mgp->watchdog_timer);
  1706. netif_wake_queue(dev);
  1707. return 0;
  1708. abort_with_rings:
  1709. myri10ge_free_rings(dev);
  1710. abort_with_irq:
  1711. myri10ge_free_irq(mgp);
  1712. abort_with_nothing:
  1713. mgp->running = MYRI10GE_ETH_STOPPED;
  1714. return -ENOMEM;
  1715. }
  1716. static int myri10ge_close(struct net_device *dev)
  1717. {
  1718. struct myri10ge_priv *mgp;
  1719. struct myri10ge_cmd cmd;
  1720. int status, old_down_cnt;
  1721. mgp = netdev_priv(dev);
  1722. if (mgp->running != MYRI10GE_ETH_RUNNING)
  1723. return 0;
  1724. if (mgp->tx.req_bytes == NULL)
  1725. return 0;
  1726. del_timer_sync(&mgp->watchdog_timer);
  1727. mgp->running = MYRI10GE_ETH_STOPPING;
  1728. napi_disable(&mgp->napi);
  1729. netif_carrier_off(dev);
  1730. netif_stop_queue(dev);
  1731. old_down_cnt = mgp->down_cnt;
  1732. mb();
  1733. status = myri10ge_send_cmd(mgp, MXGEFW_CMD_ETHERNET_DOWN, &cmd, 0);
  1734. if (status)
  1735. printk(KERN_ERR "myri10ge: %s: Couldn't bring down link\n",
  1736. dev->name);
  1737. wait_event_timeout(mgp->down_wq, old_down_cnt != mgp->down_cnt, HZ);
  1738. if (old_down_cnt == mgp->down_cnt)
  1739. printk(KERN_ERR "myri10ge: %s never got down irq\n", dev->name);
  1740. netif_tx_disable(dev);
  1741. myri10ge_free_irq(mgp);
  1742. myri10ge_free_rings(dev);
  1743. mgp->running = MYRI10GE_ETH_STOPPED;
  1744. return 0;
  1745. }
  1746. /* copy an array of struct mcp_kreq_ether_send's to the mcp. Copy
  1747. * backwards one at a time and handle ring wraps */
  1748. static inline void
  1749. myri10ge_submit_req_backwards(struct myri10ge_tx_buf *tx,
  1750. struct mcp_kreq_ether_send *src, int cnt)
  1751. {
  1752. int idx, starting_slot;
  1753. starting_slot = tx->req;
  1754. while (cnt > 1) {
  1755. cnt--;
  1756. idx = (starting_slot + cnt) & tx->mask;
  1757. myri10ge_pio_copy(&tx->lanai[idx], &src[cnt], sizeof(*src));
  1758. mb();
  1759. }
  1760. }
  1761. /*
  1762. * copy an array of struct mcp_kreq_ether_send's to the mcp. Copy
  1763. * at most 32 bytes at a time, so as to avoid involving the software
  1764. * pio handler in the nic. We re-write the first segment's flags
  1765. * to mark them valid only after writing the entire chain.
  1766. */
  1767. static inline void
  1768. myri10ge_submit_req(struct myri10ge_tx_buf *tx, struct mcp_kreq_ether_send *src,
  1769. int cnt)
  1770. {
  1771. int idx, i;
  1772. struct mcp_kreq_ether_send __iomem *dstp, *dst;
  1773. struct mcp_kreq_ether_send *srcp;
  1774. u8 last_flags;
  1775. idx = tx->req & tx->mask;
  1776. last_flags = src->flags;
  1777. src->flags = 0;
  1778. mb();
  1779. dst = dstp = &tx->lanai[idx];
  1780. srcp = src;
  1781. if ((idx + cnt) < tx->mask) {
  1782. for (i = 0; i < (cnt - 1); i += 2) {
  1783. myri10ge_pio_copy(dstp, srcp, 2 * sizeof(*src));
  1784. mb(); /* force write every 32 bytes */
  1785. srcp += 2;
  1786. dstp += 2;
  1787. }
  1788. } else {
  1789. /* submit all but the first request, and ensure
  1790. * that it is submitted below */
  1791. myri10ge_submit_req_backwards(tx, src, cnt);
  1792. i = 0;
  1793. }
  1794. if (i < cnt) {
  1795. /* submit the first request */
  1796. myri10ge_pio_copy(dstp, srcp, sizeof(*src));
  1797. mb(); /* barrier before setting valid flag */
  1798. }
  1799. /* re-write the last 32-bits with the valid flags */
  1800. src->flags = last_flags;
  1801. put_be32(*((__be32 *) src + 3), (__be32 __iomem *) dst + 3);
  1802. tx->req += cnt;
  1803. mb();
  1804. }
  1805. static inline void
  1806. myri10ge_submit_req_wc(struct myri10ge_tx_buf *tx,
  1807. struct mcp_kreq_ether_send *src, int cnt)
  1808. {
  1809. tx->req += cnt;
  1810. mb();
  1811. while (cnt >= 4) {
  1812. myri10ge_pio_copy(tx->wc_fifo, src, 64);
  1813. mb();
  1814. src += 4;
  1815. cnt -= 4;
  1816. }
  1817. if (cnt > 0) {
  1818. /* pad it to 64 bytes. The src is 64 bytes bigger than it
  1819. * needs to be so that we don't overrun it */
  1820. myri10ge_pio_copy(tx->wc_fifo + MXGEFW_ETH_SEND_OFFSET(cnt),
  1821. src, 64);
  1822. mb();
  1823. }
  1824. }
  1825. /*
  1826. * Transmit a packet. We need to split the packet so that a single
  1827. * segment does not cross myri10ge->tx.boundary, so this makes segment
  1828. * counting tricky. So rather than try to count segments up front, we
  1829. * just give up if there are too few segments to hold a reasonably
  1830. * fragmented packet currently available. If we run
  1831. * out of segments while preparing a packet for DMA, we just linearize
  1832. * it and try again.
  1833. */
  1834. static int myri10ge_xmit(struct sk_buff *skb, struct net_device *dev)
  1835. {
  1836. struct myri10ge_priv *mgp = netdev_priv(dev);
  1837. struct mcp_kreq_ether_send *req;
  1838. struct myri10ge_tx_buf *tx = &mgp->tx;
  1839. struct skb_frag_struct *frag;
  1840. dma_addr_t bus;
  1841. u32 low;
  1842. __be32 high_swapped;
  1843. unsigned int len;
  1844. int idx, last_idx, avail, frag_cnt, frag_idx, count, mss, max_segments;
  1845. u16 pseudo_hdr_offset, cksum_offset;
  1846. int cum_len, seglen, boundary, rdma_count;
  1847. u8 flags, odd_flag;
  1848. again:
  1849. req = tx->req_list;
  1850. avail = tx->mask - 1 - (tx->req - tx->done);
  1851. mss = 0;
  1852. max_segments = MXGEFW_MAX_SEND_DESC;
  1853. if (skb_is_gso(skb)) {
  1854. mss = skb_shinfo(skb)->gso_size;
  1855. max_segments = MYRI10GE_MAX_SEND_DESC_TSO;
  1856. }
  1857. if ((unlikely(avail < max_segments))) {
  1858. /* we are out of transmit resources */
  1859. mgp->stop_queue++;
  1860. netif_stop_queue(dev);
  1861. return 1;
  1862. }
  1863. /* Setup checksum offloading, if needed */
  1864. cksum_offset = 0;
  1865. pseudo_hdr_offset = 0;
  1866. odd_flag = 0;
  1867. flags = (MXGEFW_FLAGS_NO_TSO | MXGEFW_FLAGS_FIRST);
  1868. if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
  1869. cksum_offset = skb_transport_offset(skb);
  1870. pseudo_hdr_offset = cksum_offset + skb->csum_offset;
  1871. /* If the headers are excessively large, then we must
  1872. * fall back to a software checksum */
  1873. if (unlikely(cksum_offset > 255 || pseudo_hdr_offset > 127)) {
  1874. if (skb_checksum_help(skb))
  1875. goto drop;
  1876. cksum_offset = 0;
  1877. pseudo_hdr_offset = 0;
  1878. } else {
  1879. odd_flag = MXGEFW_FLAGS_ALIGN_ODD;
  1880. flags |= MXGEFW_FLAGS_CKSUM;
  1881. }
  1882. }
  1883. cum_len = 0;
  1884. if (mss) { /* TSO */
  1885. /* this removes any CKSUM flag from before */
  1886. flags = (MXGEFW_FLAGS_TSO_HDR | MXGEFW_FLAGS_FIRST);
  1887. /* negative cum_len signifies to the
  1888. * send loop that we are still in the
  1889. * header portion of the TSO packet.
  1890. * TSO header must be at most 134 bytes long */
  1891. cum_len = -(skb_transport_offset(skb) + tcp_hdrlen(skb));
  1892. /* for TSO, pseudo_hdr_offset holds mss.
  1893. * The firmware figures out where to put
  1894. * the checksum by parsing the header. */
  1895. pseudo_hdr_offset = mss;
  1896. } else
  1897. /* Mark small packets, and pad out tiny packets */
  1898. if (skb->len <= MXGEFW_SEND_SMALL_SIZE) {
  1899. flags |= MXGEFW_FLAGS_SMALL;
  1900. /* pad frames to at least ETH_ZLEN bytes */
  1901. if (unlikely(skb->len < ETH_ZLEN)) {
  1902. if (skb_padto(skb, ETH_ZLEN)) {
  1903. /* The packet is gone, so we must
  1904. * return 0 */
  1905. mgp->stats.tx_dropped += 1;
  1906. return 0;
  1907. }
  1908. /* adjust the len to account for the zero pad
  1909. * so that the nic can know how long it is */
  1910. skb->len = ETH_ZLEN;
  1911. }
  1912. }
  1913. /* map the skb for DMA */
  1914. len = skb->len - skb->data_len;
  1915. idx = tx->req & tx->mask;
  1916. tx->info[idx].skb = skb;
  1917. bus = pci_map_single(mgp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  1918. pci_unmap_addr_set(&tx->info[idx], bus, bus);
  1919. pci_unmap_len_set(&tx->info[idx], len, len);
  1920. frag_cnt = skb_shinfo(skb)->nr_frags;
  1921. frag_idx = 0;
  1922. count = 0;
  1923. rdma_count = 0;
  1924. /* "rdma_count" is the number of RDMAs belonging to the
  1925. * current packet BEFORE the current send request. For
  1926. * non-TSO packets, this is equal to "count".
  1927. * For TSO packets, rdma_count needs to be reset
  1928. * to 0 after a segment cut.
  1929. *
  1930. * The rdma_count field of the send request is
  1931. * the number of RDMAs of the packet starting at
  1932. * that request. For TSO send requests with one ore more cuts
  1933. * in the middle, this is the number of RDMAs starting
  1934. * after the last cut in the request. All previous
  1935. * segments before the last cut implicitly have 1 RDMA.
  1936. *
  1937. * Since the number of RDMAs is not known beforehand,
  1938. * it must be filled-in retroactively - after each
  1939. * segmentation cut or at the end of the entire packet.
  1940. */
  1941. while (1) {
  1942. /* Break the SKB or Fragment up into pieces which
  1943. * do not cross mgp->tx.boundary */
  1944. low = MYRI10GE_LOWPART_TO_U32(bus);
  1945. high_swapped = htonl(MYRI10GE_HIGHPART_TO_U32(bus));
  1946. while (len) {
  1947. u8 flags_next;
  1948. int cum_len_next;
  1949. if (unlikely(count == max_segments))
  1950. goto abort_linearize;
  1951. boundary = (low + tx->boundary) & ~(tx->boundary - 1);
  1952. seglen = boundary - low;
  1953. if (seglen > len)
  1954. seglen = len;
  1955. flags_next = flags & ~MXGEFW_FLAGS_FIRST;
  1956. cum_len_next = cum_len + seglen;
  1957. if (mss) { /* TSO */
  1958. (req - rdma_count)->rdma_count = rdma_count + 1;
  1959. if (likely(cum_len >= 0)) { /* payload */
  1960. int next_is_first, chop;
  1961. chop = (cum_len_next > mss);
  1962. cum_len_next = cum_len_next % mss;
  1963. next_is_first = (cum_len_next == 0);
  1964. flags |= chop * MXGEFW_FLAGS_TSO_CHOP;
  1965. flags_next |= next_is_first *
  1966. MXGEFW_FLAGS_FIRST;
  1967. rdma_count |= -(chop | next_is_first);
  1968. rdma_count += chop & !next_is_first;
  1969. } else if (likely(cum_len_next >= 0)) { /* header ends */
  1970. int small;
  1971. rdma_count = -1;
  1972. cum_len_next = 0;
  1973. seglen = -cum_len;
  1974. small = (mss <= MXGEFW_SEND_SMALL_SIZE);
  1975. flags_next = MXGEFW_FLAGS_TSO_PLD |
  1976. MXGEFW_FLAGS_FIRST |
  1977. (small * MXGEFW_FLAGS_SMALL);
  1978. }
  1979. }
  1980. req->addr_high = high_swapped;
  1981. req->addr_low = htonl(low);
  1982. req->pseudo_hdr_offset = htons(pseudo_hdr_offset);
  1983. req->pad = 0; /* complete solid 16-byte block; does this matter? */
  1984. req->rdma_count = 1;
  1985. req->length = htons(seglen);
  1986. req->cksum_offset = cksum_offset;
  1987. req->flags = flags | ((cum_len & 1) * odd_flag);
  1988. low += seglen;
  1989. len -= seglen;
  1990. cum_len = cum_len_next;
  1991. flags = flags_next;
  1992. req++;
  1993. count++;
  1994. rdma_count++;
  1995. if (unlikely(cksum_offset > seglen))
  1996. cksum_offset -= seglen;
  1997. else
  1998. cksum_offset = 0;
  1999. }
  2000. if (frag_idx == frag_cnt)
  2001. break;
  2002. /* map next fragment for DMA */
  2003. idx = (count + tx->req) & tx->mask;
  2004. frag = &skb_shinfo(skb)->frags[frag_idx];
  2005. frag_idx++;
  2006. len = frag->size;
  2007. bus = pci_map_page(mgp->pdev, frag->page, frag->page_offset,
  2008. len, PCI_DMA_TODEVICE);
  2009. pci_unmap_addr_set(&tx->info[idx], bus, bus);
  2010. pci_unmap_len_set(&tx->info[idx], len, len);
  2011. }
  2012. (req - rdma_count)->rdma_count = rdma_count;
  2013. if (mss)
  2014. do {
  2015. req--;
  2016. req->flags |= MXGEFW_FLAGS_TSO_LAST;
  2017. } while (!(req->flags & (MXGEFW_FLAGS_TSO_CHOP |
  2018. MXGEFW_FLAGS_FIRST)));
  2019. idx = ((count - 1) + tx->req) & tx->mask;
  2020. tx->info[idx].last = 1;
  2021. if (tx->wc_fifo == NULL)
  2022. myri10ge_submit_req(tx, tx->req_list, count);
  2023. else
  2024. myri10ge_submit_req_wc(tx, tx->req_list, count);
  2025. tx->pkt_start++;
  2026. if ((avail - count) < MXGEFW_MAX_SEND_DESC) {
  2027. mgp->stop_queue++;
  2028. netif_stop_queue(dev);
  2029. }
  2030. dev->trans_start = jiffies;
  2031. return 0;
  2032. abort_linearize:
  2033. /* Free any DMA resources we've alloced and clear out the skb
  2034. * slot so as to not trip up assertions, and to avoid a
  2035. * double-free if linearizing fails */
  2036. last_idx = (idx + 1) & tx->mask;
  2037. idx = tx->req & tx->mask;
  2038. tx->info[idx].skb = NULL;
  2039. do {
  2040. len = pci_unmap_len(&tx->info[idx], len);
  2041. if (len) {
  2042. if (tx->info[idx].skb != NULL)
  2043. pci_unmap_single(mgp->pdev,
  2044. pci_unmap_addr(&tx->info[idx],
  2045. bus), len,
  2046. PCI_DMA_TODEVICE);
  2047. else
  2048. pci_unmap_page(mgp->pdev,
  2049. pci_unmap_addr(&tx->info[idx],
  2050. bus), len,
  2051. PCI_DMA_TODEVICE);
  2052. pci_unmap_len_set(&tx->info[idx], len, 0);
  2053. tx->info[idx].skb = NULL;
  2054. }
  2055. idx = (idx + 1) & tx->mask;
  2056. } while (idx != last_idx);
  2057. if (skb_is_gso(skb)) {
  2058. printk(KERN_ERR
  2059. "myri10ge: %s: TSO but wanted to linearize?!?!?\n",
  2060. mgp->dev->name);
  2061. goto drop;
  2062. }
  2063. if (skb_linearize(skb))
  2064. goto drop;
  2065. mgp->tx_linearized++;
  2066. goto again;
  2067. drop:
  2068. dev_kfree_skb_any(skb);
  2069. mgp->stats.tx_dropped += 1;
  2070. return 0;
  2071. }
  2072. static struct net_device_stats *myri10ge_get_stats(struct net_device *dev)
  2073. {
  2074. struct myri10ge_priv *mgp = netdev_priv(dev);
  2075. return &mgp->stats;
  2076. }
  2077. static void myri10ge_set_multicast_list(struct net_device *dev)
  2078. {
  2079. struct myri10ge_cmd cmd;
  2080. struct myri10ge_priv *mgp;
  2081. struct dev_mc_list *mc_list;
  2082. __be32 data[2] = { 0, 0 };
  2083. int err;
  2084. DECLARE_MAC_BUF(mac);
  2085. mgp = netdev_priv(dev);
  2086. /* can be called from atomic contexts,
  2087. * pass 1 to force atomicity in myri10ge_send_cmd() */
  2088. myri10ge_change_promisc(mgp, dev->flags & IFF_PROMISC, 1);
  2089. /* This firmware is known to not support multicast */
  2090. if (!mgp->fw_multicast_support)
  2091. return;
  2092. /* Disable multicast filtering */
  2093. err = myri10ge_send_cmd(mgp, MXGEFW_ENABLE_ALLMULTI, &cmd, 1);
  2094. if (err != 0) {
  2095. printk(KERN_ERR "myri10ge: %s: Failed MXGEFW_ENABLE_ALLMULTI,"
  2096. " error status: %d\n", dev->name, err);
  2097. goto abort;
  2098. }
  2099. if ((dev->flags & IFF_ALLMULTI) || mgp->adopted_rx_filter_bug) {
  2100. /* request to disable multicast filtering, so quit here */
  2101. return;
  2102. }
  2103. /* Flush the filters */
  2104. err = myri10ge_send_cmd(mgp, MXGEFW_LEAVE_ALL_MULTICAST_GROUPS,
  2105. &cmd, 1);
  2106. if (err != 0) {
  2107. printk(KERN_ERR
  2108. "myri10ge: %s: Failed MXGEFW_LEAVE_ALL_MULTICAST_GROUPS"
  2109. ", error status: %d\n", dev->name, err);
  2110. goto abort;
  2111. }
  2112. /* Walk the multicast list, and add each address */
  2113. for (mc_list = dev->mc_list; mc_list != NULL; mc_list = mc_list->next) {
  2114. memcpy(data, &mc_list->dmi_addr, 6);
  2115. cmd.data0 = ntohl(data[0]);
  2116. cmd.data1 = ntohl(data[1]);
  2117. err = myri10ge_send_cmd(mgp, MXGEFW_JOIN_MULTICAST_GROUP,
  2118. &cmd, 1);
  2119. if (err != 0) {
  2120. printk(KERN_ERR "myri10ge: %s: Failed "
  2121. "MXGEFW_JOIN_MULTICAST_GROUP, error status:"
  2122. "%d\t", dev->name, err);
  2123. printk(KERN_ERR "MAC %s\n",
  2124. print_mac(mac, mc_list->dmi_addr));
  2125. goto abort;
  2126. }
  2127. }
  2128. /* Enable multicast filtering */
  2129. err = myri10ge_send_cmd(mgp, MXGEFW_DISABLE_ALLMULTI, &cmd, 1);
  2130. if (err != 0) {
  2131. printk(KERN_ERR "myri10ge: %s: Failed MXGEFW_DISABLE_ALLMULTI,"
  2132. "error status: %d\n", dev->name, err);
  2133. goto abort;
  2134. }
  2135. return;
  2136. abort:
  2137. return;
  2138. }
  2139. static int myri10ge_set_mac_address(struct net_device *dev, void *addr)
  2140. {
  2141. struct sockaddr *sa = addr;
  2142. struct myri10ge_priv *mgp = netdev_priv(dev);
  2143. int status;
  2144. if (!is_valid_ether_addr(sa->sa_data))
  2145. return -EADDRNOTAVAIL;
  2146. status = myri10ge_update_mac_address(mgp, sa->sa_data);
  2147. if (status != 0) {
  2148. printk(KERN_ERR
  2149. "myri10ge: %s: changing mac address failed with %d\n",
  2150. dev->name, status);
  2151. return status;
  2152. }
  2153. /* change the dev structure */
  2154. memcpy(dev->dev_addr, sa->sa_data, 6);
  2155. return 0;
  2156. }
  2157. static int myri10ge_change_mtu(struct net_device *dev, int new_mtu)
  2158. {
  2159. struct myri10ge_priv *mgp = netdev_priv(dev);
  2160. int error = 0;
  2161. if ((new_mtu < 68) || (ETH_HLEN + new_mtu > MYRI10GE_MAX_ETHER_MTU)) {
  2162. printk(KERN_ERR "myri10ge: %s: new mtu (%d) is not valid\n",
  2163. dev->name, new_mtu);
  2164. return -EINVAL;
  2165. }
  2166. printk(KERN_INFO "%s: changing mtu from %d to %d\n",
  2167. dev->name, dev->mtu, new_mtu);
  2168. if (mgp->running) {
  2169. /* if we change the mtu on an active device, we must
  2170. * reset the device so the firmware sees the change */
  2171. myri10ge_close(dev);
  2172. dev->mtu = new_mtu;
  2173. myri10ge_open(dev);
  2174. } else
  2175. dev->mtu = new_mtu;
  2176. return error;
  2177. }
  2178. /*
  2179. * Enable ECRC to align PCI-E Completion packets on an 8-byte boundary.
  2180. * Only do it if the bridge is a root port since we don't want to disturb
  2181. * any other device, except if forced with myri10ge_ecrc_enable > 1.
  2182. */
  2183. static void myri10ge_enable_ecrc(struct myri10ge_priv *mgp)
  2184. {
  2185. struct pci_dev *bridge = mgp->pdev->bus->self;
  2186. struct device *dev = &mgp->pdev->dev;
  2187. unsigned cap;
  2188. unsigned err_cap;
  2189. u16 val;
  2190. u8 ext_type;
  2191. int ret;
  2192. if (!myri10ge_ecrc_enable || !bridge)
  2193. return;
  2194. /* check that the bridge is a root port */
  2195. cap = pci_find_capability(bridge, PCI_CAP_ID_EXP);
  2196. pci_read_config_word(bridge, cap + PCI_CAP_FLAGS, &val);
  2197. ext_type = (val & PCI_EXP_FLAGS_TYPE) >> 4;
  2198. if (ext_type != PCI_EXP_TYPE_ROOT_PORT) {
  2199. if (myri10ge_ecrc_enable > 1) {
  2200. struct pci_dev *old_bridge = bridge;
  2201. /* Walk the hierarchy up to the root port
  2202. * where ECRC has to be enabled */
  2203. do {
  2204. bridge = bridge->bus->self;
  2205. if (!bridge) {
  2206. dev_err(dev,
  2207. "Failed to find root port"
  2208. " to force ECRC\n");
  2209. return;
  2210. }
  2211. cap =
  2212. pci_find_capability(bridge, PCI_CAP_ID_EXP);
  2213. pci_read_config_word(bridge,
  2214. cap + PCI_CAP_FLAGS, &val);
  2215. ext_type = (val & PCI_EXP_FLAGS_TYPE) >> 4;
  2216. } while (ext_type != PCI_EXP_TYPE_ROOT_PORT);
  2217. dev_info(dev,
  2218. "Forcing ECRC on non-root port %s"
  2219. " (enabling on root port %s)\n",
  2220. pci_name(old_bridge), pci_name(bridge));
  2221. } else {
  2222. dev_err(dev,
  2223. "Not enabling ECRC on non-root port %s\n",
  2224. pci_name(bridge));
  2225. return;
  2226. }
  2227. }
  2228. cap = pci_find_ext_capability(bridge, PCI_EXT_CAP_ID_ERR);
  2229. if (!cap)
  2230. return;
  2231. ret = pci_read_config_dword(bridge, cap + PCI_ERR_CAP, &err_cap);
  2232. if (ret) {
  2233. dev_err(dev, "failed reading ext-conf-space of %s\n",
  2234. pci_name(bridge));
  2235. dev_err(dev, "\t pci=nommconf in use? "
  2236. "or buggy/incomplete/absent ACPI MCFG attr?\n");
  2237. return;
  2238. }
  2239. if (!(err_cap & PCI_ERR_CAP_ECRC_GENC))
  2240. return;
  2241. err_cap |= PCI_ERR_CAP_ECRC_GENE;
  2242. pci_write_config_dword(bridge, cap + PCI_ERR_CAP, err_cap);
  2243. dev_info(dev, "Enabled ECRC on upstream bridge %s\n", pci_name(bridge));
  2244. }
  2245. /*
  2246. * The Lanai Z8E PCI-E interface achieves higher Read-DMA throughput
  2247. * when the PCI-E Completion packets are aligned on an 8-byte
  2248. * boundary. Some PCI-E chip sets always align Completion packets; on
  2249. * the ones that do not, the alignment can be enforced by enabling
  2250. * ECRC generation (if supported).
  2251. *
  2252. * When PCI-E Completion packets are not aligned, it is actually more
  2253. * efficient to limit Read-DMA transactions to 2KB, rather than 4KB.
  2254. *
  2255. * If the driver can neither enable ECRC nor verify that it has
  2256. * already been enabled, then it must use a firmware image which works
  2257. * around unaligned completion packets (myri10ge_ethp_z8e.dat), and it
  2258. * should also ensure that it never gives the device a Read-DMA which is
  2259. * larger than 2KB by setting the tx.boundary to 2KB. If ECRC is
  2260. * enabled, then the driver should use the aligned (myri10ge_eth_z8e.dat)
  2261. * firmware image, and set tx.boundary to 4KB.
  2262. */
  2263. static void myri10ge_firmware_probe(struct myri10ge_priv *mgp)
  2264. {
  2265. struct pci_dev *pdev = mgp->pdev;
  2266. struct device *dev = &pdev->dev;
  2267. int status;
  2268. mgp->tx.boundary = 4096;
  2269. /*
  2270. * Verify the max read request size was set to 4KB
  2271. * before trying the test with 4KB.
  2272. */
  2273. status = pcie_get_readrq(pdev);
  2274. if (status < 0) {
  2275. dev_err(dev, "Couldn't read max read req size: %d\n", status);
  2276. goto abort;
  2277. }
  2278. if (status != 4096) {
  2279. dev_warn(dev, "Max Read Request size != 4096 (%d)\n", status);
  2280. mgp->tx.boundary = 2048;
  2281. }
  2282. /*
  2283. * load the optimized firmware (which assumes aligned PCIe
  2284. * completions) in order to see if it works on this host.
  2285. */
  2286. mgp->fw_name = myri10ge_fw_aligned;
  2287. status = myri10ge_load_firmware(mgp);
  2288. if (status != 0) {
  2289. goto abort;
  2290. }
  2291. /*
  2292. * Enable ECRC if possible
  2293. */
  2294. myri10ge_enable_ecrc(mgp);
  2295. /*
  2296. * Run a DMA test which watches for unaligned completions and
  2297. * aborts on the first one seen.
  2298. */
  2299. status = myri10ge_dma_test(mgp, MXGEFW_CMD_UNALIGNED_TEST);
  2300. if (status == 0)
  2301. return; /* keep the aligned firmware */
  2302. if (status != -E2BIG)
  2303. dev_warn(dev, "DMA test failed: %d\n", status);
  2304. if (status == -ENOSYS)
  2305. dev_warn(dev, "Falling back to ethp! "
  2306. "Please install up to date fw\n");
  2307. abort:
  2308. /* fall back to using the unaligned firmware */
  2309. mgp->tx.boundary = 2048;
  2310. mgp->fw_name = myri10ge_fw_unaligned;
  2311. }
  2312. static void myri10ge_select_firmware(struct myri10ge_priv *mgp)
  2313. {
  2314. if (myri10ge_force_firmware == 0) {
  2315. int link_width, exp_cap;
  2316. u16 lnk;
  2317. exp_cap = pci_find_capability(mgp->pdev, PCI_CAP_ID_EXP);
  2318. pci_read_config_word(mgp->pdev, exp_cap + PCI_EXP_LNKSTA, &lnk);
  2319. link_width = (lnk >> 4) & 0x3f;
  2320. /* Check to see if Link is less than 8 or if the
  2321. * upstream bridge is known to provide aligned
  2322. * completions */
  2323. if (link_width < 8) {
  2324. dev_info(&mgp->pdev->dev, "PCIE x%d Link\n",
  2325. link_width);
  2326. mgp->tx.boundary = 4096;
  2327. mgp->fw_name = myri10ge_fw_aligned;
  2328. } else {
  2329. myri10ge_firmware_probe(mgp);
  2330. }
  2331. } else {
  2332. if (myri10ge_force_firmware == 1) {
  2333. dev_info(&mgp->pdev->dev,
  2334. "Assuming aligned completions (forced)\n");
  2335. mgp->tx.boundary = 4096;
  2336. mgp->fw_name = myri10ge_fw_aligned;
  2337. } else {
  2338. dev_info(&mgp->pdev->dev,
  2339. "Assuming unaligned completions (forced)\n");
  2340. mgp->tx.boundary = 2048;
  2341. mgp->fw_name = myri10ge_fw_unaligned;
  2342. }
  2343. }
  2344. if (myri10ge_fw_name != NULL) {
  2345. dev_info(&mgp->pdev->dev, "overriding firmware to %s\n",
  2346. myri10ge_fw_name);
  2347. mgp->fw_name = myri10ge_fw_name;
  2348. }
  2349. }
  2350. #ifdef CONFIG_PM
  2351. static int myri10ge_suspend(struct pci_dev *pdev, pm_message_t state)
  2352. {
  2353. struct myri10ge_priv *mgp;
  2354. struct net_device *netdev;
  2355. mgp = pci_get_drvdata(pdev);
  2356. if (mgp == NULL)
  2357. return -EINVAL;
  2358. netdev = mgp->dev;
  2359. netif_device_detach(netdev);
  2360. if (netif_running(netdev)) {
  2361. printk(KERN_INFO "myri10ge: closing %s\n", netdev->name);
  2362. rtnl_lock();
  2363. myri10ge_close(netdev);
  2364. rtnl_unlock();
  2365. }
  2366. myri10ge_dummy_rdma(mgp, 0);
  2367. pci_save_state(pdev);
  2368. pci_disable_device(pdev);
  2369. return pci_set_power_state(pdev, pci_choose_state(pdev, state));
  2370. }
  2371. static int myri10ge_resume(struct pci_dev *pdev)
  2372. {
  2373. struct myri10ge_priv *mgp;
  2374. struct net_device *netdev;
  2375. int status;
  2376. u16 vendor;
  2377. mgp = pci_get_drvdata(pdev);
  2378. if (mgp == NULL)
  2379. return -EINVAL;
  2380. netdev = mgp->dev;
  2381. pci_set_power_state(pdev, 0); /* zeros conf space as a side effect */
  2382. msleep(5); /* give card time to respond */
  2383. pci_read_config_word(mgp->pdev, PCI_VENDOR_ID, &vendor);
  2384. if (vendor == 0xffff) {
  2385. printk(KERN_ERR "myri10ge: %s: device disappeared!\n",
  2386. mgp->dev->name);
  2387. return -EIO;
  2388. }
  2389. status = pci_restore_state(pdev);
  2390. if (status)
  2391. return status;
  2392. status = pci_enable_device(pdev);
  2393. if (status) {
  2394. dev_err(&pdev->dev, "failed to enable device\n");
  2395. return status;
  2396. }
  2397. pci_set_master(pdev);
  2398. myri10ge_reset(mgp);
  2399. myri10ge_dummy_rdma(mgp, 1);
  2400. /* Save configuration space to be restored if the
  2401. * nic resets due to a parity error */
  2402. pci_save_state(pdev);
  2403. if (netif_running(netdev)) {
  2404. rtnl_lock();
  2405. status = myri10ge_open(netdev);
  2406. rtnl_unlock();
  2407. if (status != 0)
  2408. goto abort_with_enabled;
  2409. }
  2410. netif_device_attach(netdev);
  2411. return 0;
  2412. abort_with_enabled:
  2413. pci_disable_device(pdev);
  2414. return -EIO;
  2415. }
  2416. #endif /* CONFIG_PM */
  2417. static u32 myri10ge_read_reboot(struct myri10ge_priv *mgp)
  2418. {
  2419. struct pci_dev *pdev = mgp->pdev;
  2420. int vs = mgp->vendor_specific_offset;
  2421. u32 reboot;
  2422. /*enter read32 mode */
  2423. pci_write_config_byte(pdev, vs + 0x10, 0x3);
  2424. /*read REBOOT_STATUS (0xfffffff0) */
  2425. pci_write_config_dword(pdev, vs + 0x18, 0xfffffff0);
  2426. pci_read_config_dword(pdev, vs + 0x14, &reboot);
  2427. return reboot;
  2428. }
  2429. /*
  2430. * This watchdog is used to check whether the board has suffered
  2431. * from a parity error and needs to be recovered.
  2432. */
  2433. static void myri10ge_watchdog(struct work_struct *work)
  2434. {
  2435. struct myri10ge_priv *mgp =
  2436. container_of(work, struct myri10ge_priv, watchdog_work);
  2437. u32 reboot;
  2438. int status;
  2439. u16 cmd, vendor;
  2440. mgp->watchdog_resets++;
  2441. pci_read_config_word(mgp->pdev, PCI_COMMAND, &cmd);
  2442. if ((cmd & PCI_COMMAND_MASTER) == 0) {
  2443. /* Bus master DMA disabled? Check to see
  2444. * if the card rebooted due to a parity error
  2445. * For now, just report it */
  2446. reboot = myri10ge_read_reboot(mgp);
  2447. printk(KERN_ERR
  2448. "myri10ge: %s: NIC rebooted (0x%x),%s resetting\n",
  2449. mgp->dev->name, reboot,
  2450. myri10ge_reset_recover ? " " : " not");
  2451. if (myri10ge_reset_recover == 0)
  2452. return;
  2453. myri10ge_reset_recover--;
  2454. /*
  2455. * A rebooted nic will come back with config space as
  2456. * it was after power was applied to PCIe bus.
  2457. * Attempt to restore config space which was saved
  2458. * when the driver was loaded, or the last time the
  2459. * nic was resumed from power saving mode.
  2460. */
  2461. pci_restore_state(mgp->pdev);
  2462. /* save state again for accounting reasons */
  2463. pci_save_state(mgp->pdev);
  2464. } else {
  2465. /* if we get back -1's from our slot, perhaps somebody
  2466. * powered off our card. Don't try to reset it in
  2467. * this case */
  2468. if (cmd == 0xffff) {
  2469. pci_read_config_word(mgp->pdev, PCI_VENDOR_ID, &vendor);
  2470. if (vendor == 0xffff) {
  2471. printk(KERN_ERR
  2472. "myri10ge: %s: device disappeared!\n",
  2473. mgp->dev->name);
  2474. return;
  2475. }
  2476. }
  2477. /* Perhaps it is a software error. Try to reset */
  2478. printk(KERN_ERR "myri10ge: %s: device timeout, resetting\n",
  2479. mgp->dev->name);
  2480. printk(KERN_INFO "myri10ge: %s: %d %d %d %d %d\n",
  2481. mgp->dev->name, mgp->tx.req, mgp->tx.done,
  2482. mgp->tx.pkt_start, mgp->tx.pkt_done,
  2483. (int)ntohl(mgp->fw_stats->send_done_count));
  2484. msleep(2000);
  2485. printk(KERN_INFO "myri10ge: %s: %d %d %d %d %d\n",
  2486. mgp->dev->name, mgp->tx.req, mgp->tx.done,
  2487. mgp->tx.pkt_start, mgp->tx.pkt_done,
  2488. (int)ntohl(mgp->fw_stats->send_done_count));
  2489. }
  2490. rtnl_lock();
  2491. myri10ge_close(mgp->dev);
  2492. status = myri10ge_load_firmware(mgp);
  2493. if (status != 0)
  2494. printk(KERN_ERR "myri10ge: %s: failed to load firmware\n",
  2495. mgp->dev->name);
  2496. else
  2497. myri10ge_open(mgp->dev);
  2498. rtnl_unlock();
  2499. }
  2500. /*
  2501. * We use our own timer routine rather than relying upon
  2502. * netdev->tx_timeout because we have a very large hardware transmit
  2503. * queue. Due to the large queue, the netdev->tx_timeout function
  2504. * cannot detect a NIC with a parity error in a timely fashion if the
  2505. * NIC is lightly loaded.
  2506. */
  2507. static void myri10ge_watchdog_timer(unsigned long arg)
  2508. {
  2509. struct myri10ge_priv *mgp;
  2510. u32 rx_pause_cnt;
  2511. mgp = (struct myri10ge_priv *)arg;
  2512. if (mgp->rx_small.watchdog_needed) {
  2513. myri10ge_alloc_rx_pages(mgp, &mgp->rx_small,
  2514. mgp->small_bytes + MXGEFW_PAD, 1);
  2515. if (mgp->rx_small.fill_cnt - mgp->rx_small.cnt >=
  2516. myri10ge_fill_thresh)
  2517. mgp->rx_small.watchdog_needed = 0;
  2518. }
  2519. if (mgp->rx_big.watchdog_needed) {
  2520. myri10ge_alloc_rx_pages(mgp, &mgp->rx_big, mgp->big_bytes, 1);
  2521. if (mgp->rx_big.fill_cnt - mgp->rx_big.cnt >=
  2522. myri10ge_fill_thresh)
  2523. mgp->rx_big.watchdog_needed = 0;
  2524. }
  2525. rx_pause_cnt = ntohl(mgp->fw_stats->dropped_pause);
  2526. if (mgp->tx.req != mgp->tx.done &&
  2527. mgp->tx.done == mgp->watchdog_tx_done &&
  2528. mgp->watchdog_tx_req != mgp->watchdog_tx_done) {
  2529. /* nic seems like it might be stuck.. */
  2530. if (rx_pause_cnt != mgp->watchdog_pause) {
  2531. if (net_ratelimit())
  2532. printk(KERN_WARNING "myri10ge %s:"
  2533. "TX paused, check link partner\n",
  2534. mgp->dev->name);
  2535. } else {
  2536. schedule_work(&mgp->watchdog_work);
  2537. return;
  2538. }
  2539. }
  2540. /* rearm timer */
  2541. mod_timer(&mgp->watchdog_timer,
  2542. jiffies + myri10ge_watchdog_timeout * HZ);
  2543. mgp->watchdog_tx_done = mgp->tx.done;
  2544. mgp->watchdog_tx_req = mgp->tx.req;
  2545. mgp->watchdog_pause = rx_pause_cnt;
  2546. }
  2547. static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  2548. {
  2549. struct net_device *netdev;
  2550. struct myri10ge_priv *mgp;
  2551. struct device *dev = &pdev->dev;
  2552. size_t bytes;
  2553. int i;
  2554. int status = -ENXIO;
  2555. int dac_enabled;
  2556. netdev = alloc_etherdev(sizeof(*mgp));
  2557. if (netdev == NULL) {
  2558. dev_err(dev, "Could not allocate ethernet device\n");
  2559. return -ENOMEM;
  2560. }
  2561. SET_NETDEV_DEV(netdev, &pdev->dev);
  2562. mgp = netdev_priv(netdev);
  2563. mgp->dev = netdev;
  2564. netif_napi_add(netdev, &mgp->napi,
  2565. myri10ge_poll, myri10ge_napi_weight);
  2566. mgp->pdev = pdev;
  2567. mgp->csum_flag = MXGEFW_FLAGS_CKSUM;
  2568. mgp->pause = myri10ge_flow_control;
  2569. mgp->intr_coal_delay = myri10ge_intr_coal_delay;
  2570. mgp->msg_enable = netif_msg_init(myri10ge_debug, MYRI10GE_MSG_DEFAULT);
  2571. init_waitqueue_head(&mgp->down_wq);
  2572. if (pci_enable_device(pdev)) {
  2573. dev_err(&pdev->dev, "pci_enable_device call failed\n");
  2574. status = -ENODEV;
  2575. goto abort_with_netdev;
  2576. }
  2577. /* Find the vendor-specific cap so we can check
  2578. * the reboot register later on */
  2579. mgp->vendor_specific_offset
  2580. = pci_find_capability(pdev, PCI_CAP_ID_VNDR);
  2581. /* Set our max read request to 4KB */
  2582. status = pcie_set_readrq(pdev, 4096);
  2583. if (status != 0) {
  2584. dev_err(&pdev->dev, "Error %d writing PCI_EXP_DEVCTL\n",
  2585. status);
  2586. goto abort_with_netdev;
  2587. }
  2588. pci_set_master(pdev);
  2589. dac_enabled = 1;
  2590. status = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
  2591. if (status != 0) {
  2592. dac_enabled = 0;
  2593. dev_err(&pdev->dev,
  2594. "64-bit pci address mask was refused, trying 32-bit");
  2595. status = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  2596. }
  2597. if (status != 0) {
  2598. dev_err(&pdev->dev, "Error %d setting DMA mask\n", status);
  2599. goto abort_with_netdev;
  2600. }
  2601. mgp->cmd = dma_alloc_coherent(&pdev->dev, sizeof(*mgp->cmd),
  2602. &mgp->cmd_bus, GFP_KERNEL);
  2603. if (mgp->cmd == NULL)
  2604. goto abort_with_netdev;
  2605. mgp->fw_stats = dma_alloc_coherent(&pdev->dev, sizeof(*mgp->fw_stats),
  2606. &mgp->fw_stats_bus, GFP_KERNEL);
  2607. if (mgp->fw_stats == NULL)
  2608. goto abort_with_cmd;
  2609. mgp->board_span = pci_resource_len(pdev, 0);
  2610. mgp->iomem_base = pci_resource_start(pdev, 0);
  2611. mgp->mtrr = -1;
  2612. mgp->wc_enabled = 0;
  2613. #ifdef CONFIG_MTRR
  2614. mgp->mtrr = mtrr_add(mgp->iomem_base, mgp->board_span,
  2615. MTRR_TYPE_WRCOMB, 1);
  2616. if (mgp->mtrr >= 0)
  2617. mgp->wc_enabled = 1;
  2618. #endif
  2619. /* Hack. need to get rid of these magic numbers */
  2620. mgp->sram_size =
  2621. 2 * 1024 * 1024 - (2 * (48 * 1024) + (32 * 1024)) - 0x100;
  2622. if (mgp->sram_size > mgp->board_span) {
  2623. dev_err(&pdev->dev, "board span %ld bytes too small\n",
  2624. mgp->board_span);
  2625. goto abort_with_wc;
  2626. }
  2627. mgp->sram = ioremap(mgp->iomem_base, mgp->board_span);
  2628. if (mgp->sram == NULL) {
  2629. dev_err(&pdev->dev, "ioremap failed for %ld bytes at 0x%lx\n",
  2630. mgp->board_span, mgp->iomem_base);
  2631. status = -ENXIO;
  2632. goto abort_with_wc;
  2633. }
  2634. memcpy_fromio(mgp->eeprom_strings,
  2635. mgp->sram + mgp->sram_size - MYRI10GE_EEPROM_STRINGS_SIZE,
  2636. MYRI10GE_EEPROM_STRINGS_SIZE);
  2637. memset(mgp->eeprom_strings + MYRI10GE_EEPROM_STRINGS_SIZE - 2, 0, 2);
  2638. status = myri10ge_read_mac_addr(mgp);
  2639. if (status)
  2640. goto abort_with_ioremap;
  2641. for (i = 0; i < ETH_ALEN; i++)
  2642. netdev->dev_addr[i] = mgp->mac_addr[i];
  2643. /* allocate rx done ring */
  2644. bytes = myri10ge_max_intr_slots * sizeof(*mgp->rx_done.entry);
  2645. mgp->rx_done.entry = dma_alloc_coherent(&pdev->dev, bytes,
  2646. &mgp->rx_done.bus, GFP_KERNEL);
  2647. if (mgp->rx_done.entry == NULL)
  2648. goto abort_with_ioremap;
  2649. memset(mgp->rx_done.entry, 0, bytes);
  2650. myri10ge_select_firmware(mgp);
  2651. status = myri10ge_load_firmware(mgp);
  2652. if (status != 0) {
  2653. dev_err(&pdev->dev, "failed to load firmware\n");
  2654. goto abort_with_rx_done;
  2655. }
  2656. status = myri10ge_reset(mgp);
  2657. if (status != 0) {
  2658. dev_err(&pdev->dev, "failed reset\n");
  2659. goto abort_with_firmware;
  2660. }
  2661. pci_set_drvdata(pdev, mgp);
  2662. if ((myri10ge_initial_mtu + ETH_HLEN) > MYRI10GE_MAX_ETHER_MTU)
  2663. myri10ge_initial_mtu = MYRI10GE_MAX_ETHER_MTU - ETH_HLEN;
  2664. if ((myri10ge_initial_mtu + ETH_HLEN) < 68)
  2665. myri10ge_initial_mtu = 68;
  2666. netdev->mtu = myri10ge_initial_mtu;
  2667. netdev->open = myri10ge_open;
  2668. netdev->stop = myri10ge_close;
  2669. netdev->hard_start_xmit = myri10ge_xmit;
  2670. netdev->get_stats = myri10ge_get_stats;
  2671. netdev->base_addr = mgp->iomem_base;
  2672. netdev->change_mtu = myri10ge_change_mtu;
  2673. netdev->set_multicast_list = myri10ge_set_multicast_list;
  2674. netdev->set_mac_address = myri10ge_set_mac_address;
  2675. netdev->features = NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_TSO;
  2676. if (dac_enabled)
  2677. netdev->features |= NETIF_F_HIGHDMA;
  2678. /* make sure we can get an irq, and that MSI can be
  2679. * setup (if available). Also ensure netdev->irq
  2680. * is set to correct value if MSI is enabled */
  2681. status = myri10ge_request_irq(mgp);
  2682. if (status != 0)
  2683. goto abort_with_firmware;
  2684. netdev->irq = pdev->irq;
  2685. myri10ge_free_irq(mgp);
  2686. /* Save configuration space to be restored if the
  2687. * nic resets due to a parity error */
  2688. pci_save_state(pdev);
  2689. /* Setup the watchdog timer */
  2690. setup_timer(&mgp->watchdog_timer, myri10ge_watchdog_timer,
  2691. (unsigned long)mgp);
  2692. SET_ETHTOOL_OPS(netdev, &myri10ge_ethtool_ops);
  2693. INIT_WORK(&mgp->watchdog_work, myri10ge_watchdog);
  2694. status = register_netdev(netdev);
  2695. if (status != 0) {
  2696. dev_err(&pdev->dev, "register_netdev failed: %d\n", status);
  2697. goto abort_with_state;
  2698. }
  2699. dev_info(dev, "%s IRQ %d, tx bndry %d, fw %s, WC %s\n",
  2700. (mgp->msi_enabled ? "MSI" : "xPIC"),
  2701. netdev->irq, mgp->tx.boundary, mgp->fw_name,
  2702. (mgp->wc_enabled ? "Enabled" : "Disabled"));
  2703. return 0;
  2704. abort_with_state:
  2705. pci_restore_state(pdev);
  2706. abort_with_firmware:
  2707. myri10ge_dummy_rdma(mgp, 0);
  2708. abort_with_rx_done:
  2709. bytes = myri10ge_max_intr_slots * sizeof(*mgp->rx_done.entry);
  2710. dma_free_coherent(&pdev->dev, bytes,
  2711. mgp->rx_done.entry, mgp->rx_done.bus);
  2712. abort_with_ioremap:
  2713. iounmap(mgp->sram);
  2714. abort_with_wc:
  2715. #ifdef CONFIG_MTRR
  2716. if (mgp->mtrr >= 0)
  2717. mtrr_del(mgp->mtrr, mgp->iomem_base, mgp->board_span);
  2718. #endif
  2719. dma_free_coherent(&pdev->dev, sizeof(*mgp->fw_stats),
  2720. mgp->fw_stats, mgp->fw_stats_bus);
  2721. abort_with_cmd:
  2722. dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd),
  2723. mgp->cmd, mgp->cmd_bus);
  2724. abort_with_netdev:
  2725. free_netdev(netdev);
  2726. return status;
  2727. }
  2728. /*
  2729. * myri10ge_remove
  2730. *
  2731. * Does what is necessary to shutdown one Myrinet device. Called
  2732. * once for each Myrinet card by the kernel when a module is
  2733. * unloaded.
  2734. */
  2735. static void myri10ge_remove(struct pci_dev *pdev)
  2736. {
  2737. struct myri10ge_priv *mgp;
  2738. struct net_device *netdev;
  2739. size_t bytes;
  2740. mgp = pci_get_drvdata(pdev);
  2741. if (mgp == NULL)
  2742. return;
  2743. flush_scheduled_work();
  2744. netdev = mgp->dev;
  2745. unregister_netdev(netdev);
  2746. myri10ge_dummy_rdma(mgp, 0);
  2747. /* avoid a memory leak */
  2748. pci_restore_state(pdev);
  2749. bytes = myri10ge_max_intr_slots * sizeof(*mgp->rx_done.entry);
  2750. dma_free_coherent(&pdev->dev, bytes,
  2751. mgp->rx_done.entry, mgp->rx_done.bus);
  2752. iounmap(mgp->sram);
  2753. #ifdef CONFIG_MTRR
  2754. if (mgp->mtrr >= 0)
  2755. mtrr_del(mgp->mtrr, mgp->iomem_base, mgp->board_span);
  2756. #endif
  2757. dma_free_coherent(&pdev->dev, sizeof(*mgp->fw_stats),
  2758. mgp->fw_stats, mgp->fw_stats_bus);
  2759. dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd),
  2760. mgp->cmd, mgp->cmd_bus);
  2761. free_netdev(netdev);
  2762. pci_set_drvdata(pdev, NULL);
  2763. }
  2764. #define PCI_DEVICE_ID_MYRICOM_MYRI10GE_Z8E 0x0008
  2765. #define PCI_DEVICE_ID_MYRICOM_MYRI10GE_Z8E_9 0x0009
  2766. static struct pci_device_id myri10ge_pci_tbl[] = {
  2767. {PCI_DEVICE(PCI_VENDOR_ID_MYRICOM, PCI_DEVICE_ID_MYRICOM_MYRI10GE_Z8E)},
  2768. {PCI_DEVICE
  2769. (PCI_VENDOR_ID_MYRICOM, PCI_DEVICE_ID_MYRICOM_MYRI10GE_Z8E_9)},
  2770. {0},
  2771. };
  2772. static struct pci_driver myri10ge_driver = {
  2773. .name = "myri10ge",
  2774. .probe = myri10ge_probe,
  2775. .remove = myri10ge_remove,
  2776. .id_table = myri10ge_pci_tbl,
  2777. #ifdef CONFIG_PM
  2778. .suspend = myri10ge_suspend,
  2779. .resume = myri10ge_resume,
  2780. #endif
  2781. };
  2782. static __init int myri10ge_init_module(void)
  2783. {
  2784. printk(KERN_INFO "%s: Version %s\n", myri10ge_driver.name,
  2785. MYRI10GE_VERSION_STR);
  2786. return pci_register_driver(&myri10ge_driver);
  2787. }
  2788. module_init(myri10ge_init_module);
  2789. static __exit void myri10ge_cleanup_module(void)
  2790. {
  2791. pci_unregister_driver(&myri10ge_driver);
  2792. }
  2793. module_exit(myri10ge_cleanup_module);