typhoon.c 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691
  1. /* typhoon.c: A Linux Ethernet device driver for 3Com 3CR990 family of NICs */
  2. /*
  3. Written 2002-2004 by David Dillow <dave@thedillows.org>
  4. Based on code written 1998-2000 by Donald Becker <becker@scyld.com> and
  5. Linux 2.2.x driver by David P. McLean <davidpmclean@yahoo.com>.
  6. This software may be used and distributed according to the terms of
  7. the GNU General Public License (GPL), incorporated herein by reference.
  8. Drivers based on or derived from this code fall under the GPL and must
  9. retain the authorship, copyright and license notice. This file is not
  10. a complete program and may only be used when the entire operating
  11. system is licensed under the GPL.
  12. This software is available on a public web site. It may enable
  13. cryptographic capabilities of the 3Com hardware, and may be
  14. exported from the United States under License Exception "TSU"
  15. pursuant to 15 C.F.R. Section 740.13(e).
  16. This work was funded by the National Library of Medicine under
  17. the Department of Energy project number 0274DD06D1 and NLM project
  18. number Y1-LM-2015-01.
  19. This driver is designed for the 3Com 3CR990 Family of cards with the
  20. 3XP Processor. It has been tested on x86 and sparc64.
  21. KNOWN ISSUES:
  22. *) The current firmware always strips the VLAN tag off, even if
  23. we tell it not to. You should filter VLANs at the switch
  24. as a workaround (good practice in any event) until we can
  25. get this fixed.
  26. *) Cannot DMA Rx packets to a 2 byte aligned address. Also firmware
  27. issue. Hopefully 3Com will fix it.
  28. *) Waiting for a command response takes 8ms due to non-preemptable
  29. polling. Only significant for getting stats and creating
  30. SAs, but an ugly wart never the less.
  31. TODO:
  32. *) Doesn't do IPSEC offloading. Yet. Keep yer pants on, it's coming.
  33. *) Add more support for ethtool (especially for NIC stats)
  34. *) Allow disabling of RX checksum offloading
  35. *) Fix MAC changing to work while the interface is up
  36. (Need to put commands on the TX ring, which changes
  37. the locking)
  38. *) Add in FCS to {rx,tx}_bytes, since the hardware doesn't. See
  39. http://oss.sgi.com/cgi-bin/mesg.cgi?a=netdev&i=20031215152211.7003fe8e.rddunlap%40osdl.org
  40. */
  41. /* Set the copy breakpoint for the copy-only-tiny-frames scheme.
  42. * Setting to > 1518 effectively disables this feature.
  43. */
  44. static int rx_copybreak = 200;
  45. /* Should we use MMIO or Port IO?
  46. * 0: Port IO
  47. * 1: MMIO
  48. * 2: Try MMIO, fallback to Port IO
  49. */
  50. static unsigned int use_mmio = 2;
  51. /* end user-configurable values */
  52. /* Maximum number of multicast addresses to filter (vs. rx-all-multicast).
  53. */
  54. static const int multicast_filter_limit = 32;
  55. /* Operational parameters that are set at compile time. */
  56. /* Keep the ring sizes a power of two for compile efficiency.
  57. * The compiler will convert <unsigned>'%'<2^N> into a bit mask.
  58. * Making the Tx ring too large decreases the effectiveness of channel
  59. * bonding and packet priority.
  60. * There are no ill effects from too-large receive rings.
  61. *
  62. * We don't currently use the Hi Tx ring so, don't make it very big.
  63. *
  64. * Beware that if we start using the Hi Tx ring, we will need to change
  65. * typhoon_num_free_tx() and typhoon_tx_complete() to account for that.
  66. */
  67. #define TXHI_ENTRIES 2
  68. #define TXLO_ENTRIES 128
  69. #define RX_ENTRIES 32
  70. #define COMMAND_ENTRIES 16
  71. #define RESPONSE_ENTRIES 32
  72. #define COMMAND_RING_SIZE (COMMAND_ENTRIES * sizeof(struct cmd_desc))
  73. #define RESPONSE_RING_SIZE (RESPONSE_ENTRIES * sizeof(struct resp_desc))
  74. /* The 3XP will preload and remove 64 entries from the free buffer
  75. * list, and we need one entry to keep the ring from wrapping, so
  76. * to keep this a power of two, we use 128 entries.
  77. */
  78. #define RXFREE_ENTRIES 128
  79. #define RXENT_ENTRIES (RXFREE_ENTRIES - 1)
  80. /* Operational parameters that usually are not changed. */
  81. /* Time in jiffies before concluding the transmitter is hung. */
  82. #define TX_TIMEOUT (2*HZ)
  83. #define PKT_BUF_SZ 1536
  84. #define DRV_MODULE_NAME "typhoon"
  85. #define DRV_MODULE_VERSION "1.5.9"
  86. #define DRV_MODULE_RELDATE "Mar 2, 2009"
  87. #define PFX DRV_MODULE_NAME ": "
  88. #define ERR_PFX KERN_ERR PFX
  89. #define FIRMWARE_NAME "3com/typhoon.bin"
  90. #include <linux/module.h>
  91. #include <linux/kernel.h>
  92. #include <linux/string.h>
  93. #include <linux/timer.h>
  94. #include <linux/errno.h>
  95. #include <linux/ioport.h>
  96. #include <linux/slab.h>
  97. #include <linux/interrupt.h>
  98. #include <linux/pci.h>
  99. #include <linux/netdevice.h>
  100. #include <linux/etherdevice.h>
  101. #include <linux/skbuff.h>
  102. #include <linux/mm.h>
  103. #include <linux/init.h>
  104. #include <linux/delay.h>
  105. #include <linux/ethtool.h>
  106. #include <linux/if_vlan.h>
  107. #include <linux/crc32.h>
  108. #include <linux/bitops.h>
  109. #include <asm/processor.h>
  110. #include <asm/io.h>
  111. #include <asm/uaccess.h>
  112. #include <linux/in6.h>
  113. #include <linux/dma-mapping.h>
  114. #include <linux/firmware.h>
  115. #include "typhoon.h"
  116. static char version[] __devinitdata =
  117. "typhoon.c: version " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  118. MODULE_AUTHOR("David Dillow <dave@thedillows.org>");
  119. MODULE_VERSION(DRV_MODULE_VERSION);
  120. MODULE_LICENSE("GPL");
  121. MODULE_FIRMWARE(FIRMWARE_NAME);
  122. MODULE_DESCRIPTION("3Com Typhoon Family (3C990, 3CR990, and variants)");
  123. MODULE_PARM_DESC(rx_copybreak, "Packets smaller than this are copied and "
  124. "the buffer given back to the NIC. Default "
  125. "is 200.");
  126. MODULE_PARM_DESC(use_mmio, "Use MMIO (1) or PIO(0) to access the NIC. "
  127. "Default is to try MMIO and fallback to PIO.");
  128. module_param(rx_copybreak, int, 0);
  129. module_param(use_mmio, int, 0);
  130. #if defined(NETIF_F_TSO) && MAX_SKB_FRAGS > 32
  131. #warning Typhoon only supports 32 entries in its SG list for TSO, disabling TSO
  132. #undef NETIF_F_TSO
  133. #endif
  134. #if TXLO_ENTRIES <= (2 * MAX_SKB_FRAGS)
  135. #error TX ring too small!
  136. #endif
  137. struct typhoon_card_info {
  138. char *name;
  139. int capabilities;
  140. };
  141. #define TYPHOON_CRYPTO_NONE 0x00
  142. #define TYPHOON_CRYPTO_DES 0x01
  143. #define TYPHOON_CRYPTO_3DES 0x02
  144. #define TYPHOON_CRYPTO_VARIABLE 0x04
  145. #define TYPHOON_FIBER 0x08
  146. #define TYPHOON_WAKEUP_NEEDS_RESET 0x10
  147. enum typhoon_cards {
  148. TYPHOON_TX = 0, TYPHOON_TX95, TYPHOON_TX97, TYPHOON_SVR,
  149. TYPHOON_SVR95, TYPHOON_SVR97, TYPHOON_TXM, TYPHOON_BSVR,
  150. TYPHOON_FX95, TYPHOON_FX97, TYPHOON_FX95SVR, TYPHOON_FX97SVR,
  151. TYPHOON_FXM,
  152. };
  153. /* directly indexed by enum typhoon_cards, above */
  154. static struct typhoon_card_info typhoon_card_info[] __devinitdata = {
  155. { "3Com Typhoon (3C990-TX)",
  156. TYPHOON_CRYPTO_NONE},
  157. { "3Com Typhoon (3CR990-TX-95)",
  158. TYPHOON_CRYPTO_DES},
  159. { "3Com Typhoon (3CR990-TX-97)",
  160. TYPHOON_CRYPTO_DES | TYPHOON_CRYPTO_3DES},
  161. { "3Com Typhoon (3C990SVR)",
  162. TYPHOON_CRYPTO_NONE},
  163. { "3Com Typhoon (3CR990SVR95)",
  164. TYPHOON_CRYPTO_DES},
  165. { "3Com Typhoon (3CR990SVR97)",
  166. TYPHOON_CRYPTO_DES | TYPHOON_CRYPTO_3DES},
  167. { "3Com Typhoon2 (3C990B-TX-M)",
  168. TYPHOON_CRYPTO_VARIABLE},
  169. { "3Com Typhoon2 (3C990BSVR)",
  170. TYPHOON_CRYPTO_VARIABLE},
  171. { "3Com Typhoon (3CR990-FX-95)",
  172. TYPHOON_CRYPTO_DES | TYPHOON_FIBER},
  173. { "3Com Typhoon (3CR990-FX-97)",
  174. TYPHOON_CRYPTO_DES | TYPHOON_CRYPTO_3DES | TYPHOON_FIBER},
  175. { "3Com Typhoon (3CR990-FX-95 Server)",
  176. TYPHOON_CRYPTO_DES | TYPHOON_FIBER},
  177. { "3Com Typhoon (3CR990-FX-97 Server)",
  178. TYPHOON_CRYPTO_DES | TYPHOON_CRYPTO_3DES | TYPHOON_FIBER},
  179. { "3Com Typhoon2 (3C990B-FX-97)",
  180. TYPHOON_CRYPTO_VARIABLE | TYPHOON_FIBER},
  181. };
  182. /* Notes on the new subsystem numbering scheme:
  183. * bits 0-1 indicate crypto capabilities: (0) variable, (1) DES, or (2) 3DES
  184. * bit 4 indicates if this card has secured firmware (we don't support it)
  185. * bit 8 indicates if this is a (0) copper or (1) fiber card
  186. * bits 12-16 indicate card type: (0) client and (1) server
  187. */
  188. static struct pci_device_id typhoon_pci_tbl[] = {
  189. { PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3CR990,
  190. PCI_ANY_ID, PCI_ANY_ID, 0, 0,TYPHOON_TX },
  191. { PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3CR990_TX_95,
  192. PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPHOON_TX95 },
  193. { PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3CR990_TX_97,
  194. PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPHOON_TX97 },
  195. { PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3CR990B,
  196. PCI_ANY_ID, 0x1000, 0, 0, TYPHOON_TXM },
  197. { PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3CR990B,
  198. PCI_ANY_ID, 0x1102, 0, 0, TYPHOON_FXM },
  199. { PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3CR990B,
  200. PCI_ANY_ID, 0x2000, 0, 0, TYPHOON_BSVR },
  201. { PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3CR990_FX,
  202. PCI_ANY_ID, 0x1101, 0, 0, TYPHOON_FX95 },
  203. { PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3CR990_FX,
  204. PCI_ANY_ID, 0x1102, 0, 0, TYPHOON_FX97 },
  205. { PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3CR990_FX,
  206. PCI_ANY_ID, 0x2101, 0, 0, TYPHOON_FX95SVR },
  207. { PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3CR990_FX,
  208. PCI_ANY_ID, 0x2102, 0, 0, TYPHOON_FX97SVR },
  209. { PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3CR990SVR95,
  210. PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPHOON_SVR95 },
  211. { PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3CR990SVR97,
  212. PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPHOON_SVR97 },
  213. { PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3CR990SVR,
  214. PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPHOON_SVR },
  215. { 0, }
  216. };
  217. MODULE_DEVICE_TABLE(pci, typhoon_pci_tbl);
  218. /* Define the shared memory area
  219. * Align everything the 3XP will normally be using.
  220. * We'll need to move/align txHi if we start using that ring.
  221. */
  222. #define __3xp_aligned ____cacheline_aligned
  223. struct typhoon_shared {
  224. struct typhoon_interface iface;
  225. struct typhoon_indexes indexes __3xp_aligned;
  226. struct tx_desc txLo[TXLO_ENTRIES] __3xp_aligned;
  227. struct rx_desc rxLo[RX_ENTRIES] __3xp_aligned;
  228. struct rx_desc rxHi[RX_ENTRIES] __3xp_aligned;
  229. struct cmd_desc cmd[COMMAND_ENTRIES] __3xp_aligned;
  230. struct resp_desc resp[RESPONSE_ENTRIES] __3xp_aligned;
  231. struct rx_free rxBuff[RXFREE_ENTRIES] __3xp_aligned;
  232. u32 zeroWord;
  233. struct tx_desc txHi[TXHI_ENTRIES];
  234. } __attribute__ ((packed));
  235. struct rxbuff_ent {
  236. struct sk_buff *skb;
  237. dma_addr_t dma_addr;
  238. };
  239. struct typhoon {
  240. /* Tx cache line section */
  241. struct transmit_ring txLoRing ____cacheline_aligned;
  242. struct pci_dev * tx_pdev;
  243. void __iomem *tx_ioaddr;
  244. u32 txlo_dma_addr;
  245. /* Irq/Rx cache line section */
  246. void __iomem *ioaddr ____cacheline_aligned;
  247. struct typhoon_indexes *indexes;
  248. u8 awaiting_resp;
  249. u8 duplex;
  250. u8 speed;
  251. u8 card_state;
  252. struct basic_ring rxLoRing;
  253. struct pci_dev * pdev;
  254. struct net_device * dev;
  255. struct napi_struct napi;
  256. spinlock_t state_lock;
  257. struct vlan_group * vlgrp;
  258. struct basic_ring rxHiRing;
  259. struct basic_ring rxBuffRing;
  260. struct rxbuff_ent rxbuffers[RXENT_ENTRIES];
  261. /* general section */
  262. spinlock_t command_lock ____cacheline_aligned;
  263. struct basic_ring cmdRing;
  264. struct basic_ring respRing;
  265. struct net_device_stats stats;
  266. struct net_device_stats stats_saved;
  267. const char * name;
  268. struct typhoon_shared * shared;
  269. dma_addr_t shared_dma;
  270. __le16 xcvr_select;
  271. __le16 wol_events;
  272. __le32 offload;
  273. /* unused stuff (future use) */
  274. int capabilities;
  275. struct transmit_ring txHiRing;
  276. };
  277. enum completion_wait_values {
  278. NoWait = 0, WaitNoSleep, WaitSleep,
  279. };
  280. /* These are the values for the typhoon.card_state variable.
  281. * These determine where the statistics will come from in get_stats().
  282. * The sleep image does not support the statistics we need.
  283. */
  284. enum state_values {
  285. Sleeping = 0, Running,
  286. };
  287. /* PCI writes are not guaranteed to be posted in order, but outstanding writes
  288. * cannot pass a read, so this forces current writes to post.
  289. */
  290. #define typhoon_post_pci_writes(x) \
  291. do { if(likely(use_mmio)) ioread32(x+TYPHOON_REG_HEARTBEAT); } while(0)
  292. /* We'll wait up to six seconds for a reset, and half a second normally.
  293. */
  294. #define TYPHOON_UDELAY 50
  295. #define TYPHOON_RESET_TIMEOUT_SLEEP (6 * HZ)
  296. #define TYPHOON_RESET_TIMEOUT_NOSLEEP ((6 * 1000000) / TYPHOON_UDELAY)
  297. #define TYPHOON_WAIT_TIMEOUT ((1000000 / 2) / TYPHOON_UDELAY)
  298. #if defined(NETIF_F_TSO)
  299. #define skb_tso_size(x) (skb_shinfo(x)->gso_size)
  300. #define TSO_NUM_DESCRIPTORS 2
  301. #define TSO_OFFLOAD_ON TYPHOON_OFFLOAD_TCP_SEGMENT
  302. #else
  303. #define NETIF_F_TSO 0
  304. #define skb_tso_size(x) 0
  305. #define TSO_NUM_DESCRIPTORS 0
  306. #define TSO_OFFLOAD_ON 0
  307. #endif
  308. static inline void
  309. typhoon_inc_index(u32 *index, const int count, const int num_entries)
  310. {
  311. /* Increment a ring index -- we can use this for all rings execept
  312. * the Rx rings, as they use different size descriptors
  313. * otherwise, everything is the same size as a cmd_desc
  314. */
  315. *index += count * sizeof(struct cmd_desc);
  316. *index %= num_entries * sizeof(struct cmd_desc);
  317. }
  318. static inline void
  319. typhoon_inc_cmd_index(u32 *index, const int count)
  320. {
  321. typhoon_inc_index(index, count, COMMAND_ENTRIES);
  322. }
  323. static inline void
  324. typhoon_inc_resp_index(u32 *index, const int count)
  325. {
  326. typhoon_inc_index(index, count, RESPONSE_ENTRIES);
  327. }
  328. static inline void
  329. typhoon_inc_rxfree_index(u32 *index, const int count)
  330. {
  331. typhoon_inc_index(index, count, RXFREE_ENTRIES);
  332. }
  333. static inline void
  334. typhoon_inc_tx_index(u32 *index, const int count)
  335. {
  336. /* if we start using the Hi Tx ring, this needs updateing */
  337. typhoon_inc_index(index, count, TXLO_ENTRIES);
  338. }
  339. static inline void
  340. typhoon_inc_rx_index(u32 *index, const int count)
  341. {
  342. /* sizeof(struct rx_desc) != sizeof(struct cmd_desc) */
  343. *index += count * sizeof(struct rx_desc);
  344. *index %= RX_ENTRIES * sizeof(struct rx_desc);
  345. }
  346. static int
  347. typhoon_reset(void __iomem *ioaddr, int wait_type)
  348. {
  349. int i, err = 0;
  350. int timeout;
  351. if(wait_type == WaitNoSleep)
  352. timeout = TYPHOON_RESET_TIMEOUT_NOSLEEP;
  353. else
  354. timeout = TYPHOON_RESET_TIMEOUT_SLEEP;
  355. iowrite32(TYPHOON_INTR_ALL, ioaddr + TYPHOON_REG_INTR_MASK);
  356. iowrite32(TYPHOON_INTR_ALL, ioaddr + TYPHOON_REG_INTR_STATUS);
  357. iowrite32(TYPHOON_RESET_ALL, ioaddr + TYPHOON_REG_SOFT_RESET);
  358. typhoon_post_pci_writes(ioaddr);
  359. udelay(1);
  360. iowrite32(TYPHOON_RESET_NONE, ioaddr + TYPHOON_REG_SOFT_RESET);
  361. if(wait_type != NoWait) {
  362. for(i = 0; i < timeout; i++) {
  363. if(ioread32(ioaddr + TYPHOON_REG_STATUS) ==
  364. TYPHOON_STATUS_WAITING_FOR_HOST)
  365. goto out;
  366. if(wait_type == WaitSleep)
  367. schedule_timeout_uninterruptible(1);
  368. else
  369. udelay(TYPHOON_UDELAY);
  370. }
  371. err = -ETIMEDOUT;
  372. }
  373. out:
  374. iowrite32(TYPHOON_INTR_ALL, ioaddr + TYPHOON_REG_INTR_MASK);
  375. iowrite32(TYPHOON_INTR_ALL, ioaddr + TYPHOON_REG_INTR_STATUS);
  376. /* The 3XP seems to need a little extra time to complete the load
  377. * of the sleep image before we can reliably boot it. Failure to
  378. * do this occasionally results in a hung adapter after boot in
  379. * typhoon_init_one() while trying to read the MAC address or
  380. * putting the card to sleep. 3Com's driver waits 5ms, but
  381. * that seems to be overkill. However, if we can sleep, we might
  382. * as well give it that much time. Otherwise, we'll give it 500us,
  383. * which should be enough (I've see it work well at 100us, but still
  384. * saw occasional problems.)
  385. */
  386. if(wait_type == WaitSleep)
  387. msleep(5);
  388. else
  389. udelay(500);
  390. return err;
  391. }
  392. static int
  393. typhoon_wait_status(void __iomem *ioaddr, u32 wait_value)
  394. {
  395. int i, err = 0;
  396. for(i = 0; i < TYPHOON_WAIT_TIMEOUT; i++) {
  397. if(ioread32(ioaddr + TYPHOON_REG_STATUS) == wait_value)
  398. goto out;
  399. udelay(TYPHOON_UDELAY);
  400. }
  401. err = -ETIMEDOUT;
  402. out:
  403. return err;
  404. }
  405. static inline void
  406. typhoon_media_status(struct net_device *dev, struct resp_desc *resp)
  407. {
  408. if(resp->parm1 & TYPHOON_MEDIA_STAT_NO_LINK)
  409. netif_carrier_off(dev);
  410. else
  411. netif_carrier_on(dev);
  412. }
  413. static inline void
  414. typhoon_hello(struct typhoon *tp)
  415. {
  416. struct basic_ring *ring = &tp->cmdRing;
  417. struct cmd_desc *cmd;
  418. /* We only get a hello request if we've not sent anything to the
  419. * card in a long while. If the lock is held, then we're in the
  420. * process of issuing a command, so we don't need to respond.
  421. */
  422. if(spin_trylock(&tp->command_lock)) {
  423. cmd = (struct cmd_desc *)(ring->ringBase + ring->lastWrite);
  424. typhoon_inc_cmd_index(&ring->lastWrite, 1);
  425. INIT_COMMAND_NO_RESPONSE(cmd, TYPHOON_CMD_HELLO_RESP);
  426. smp_wmb();
  427. iowrite32(ring->lastWrite, tp->ioaddr + TYPHOON_REG_CMD_READY);
  428. spin_unlock(&tp->command_lock);
  429. }
  430. }
  431. static int
  432. typhoon_process_response(struct typhoon *tp, int resp_size,
  433. struct resp_desc *resp_save)
  434. {
  435. struct typhoon_indexes *indexes = tp->indexes;
  436. struct resp_desc *resp;
  437. u8 *base = tp->respRing.ringBase;
  438. int count, len, wrap_len;
  439. u32 cleared;
  440. u32 ready;
  441. cleared = le32_to_cpu(indexes->respCleared);
  442. ready = le32_to_cpu(indexes->respReady);
  443. while(cleared != ready) {
  444. resp = (struct resp_desc *)(base + cleared);
  445. count = resp->numDesc + 1;
  446. if(resp_save && resp->seqNo) {
  447. if(count > resp_size) {
  448. resp_save->flags = TYPHOON_RESP_ERROR;
  449. goto cleanup;
  450. }
  451. wrap_len = 0;
  452. len = count * sizeof(*resp);
  453. if(unlikely(cleared + len > RESPONSE_RING_SIZE)) {
  454. wrap_len = cleared + len - RESPONSE_RING_SIZE;
  455. len = RESPONSE_RING_SIZE - cleared;
  456. }
  457. memcpy(resp_save, resp, len);
  458. if(unlikely(wrap_len)) {
  459. resp_save += len / sizeof(*resp);
  460. memcpy(resp_save, base, wrap_len);
  461. }
  462. resp_save = NULL;
  463. } else if(resp->cmd == TYPHOON_CMD_READ_MEDIA_STATUS) {
  464. typhoon_media_status(tp->dev, resp);
  465. } else if(resp->cmd == TYPHOON_CMD_HELLO_RESP) {
  466. typhoon_hello(tp);
  467. } else {
  468. printk(KERN_ERR "%s: dumping unexpected response "
  469. "0x%04x:%d:0x%02x:0x%04x:%08x:%08x\n",
  470. tp->name, le16_to_cpu(resp->cmd),
  471. resp->numDesc, resp->flags,
  472. le16_to_cpu(resp->parm1),
  473. le32_to_cpu(resp->parm2),
  474. le32_to_cpu(resp->parm3));
  475. }
  476. cleanup:
  477. typhoon_inc_resp_index(&cleared, count);
  478. }
  479. indexes->respCleared = cpu_to_le32(cleared);
  480. wmb();
  481. return (resp_save == NULL);
  482. }
  483. static inline int
  484. typhoon_num_free(int lastWrite, int lastRead, int ringSize)
  485. {
  486. /* this works for all descriptors but rx_desc, as they are a
  487. * different size than the cmd_desc -- everyone else is the same
  488. */
  489. lastWrite /= sizeof(struct cmd_desc);
  490. lastRead /= sizeof(struct cmd_desc);
  491. return (ringSize + lastRead - lastWrite - 1) % ringSize;
  492. }
  493. static inline int
  494. typhoon_num_free_cmd(struct typhoon *tp)
  495. {
  496. int lastWrite = tp->cmdRing.lastWrite;
  497. int cmdCleared = le32_to_cpu(tp->indexes->cmdCleared);
  498. return typhoon_num_free(lastWrite, cmdCleared, COMMAND_ENTRIES);
  499. }
  500. static inline int
  501. typhoon_num_free_resp(struct typhoon *tp)
  502. {
  503. int respReady = le32_to_cpu(tp->indexes->respReady);
  504. int respCleared = le32_to_cpu(tp->indexes->respCleared);
  505. return typhoon_num_free(respReady, respCleared, RESPONSE_ENTRIES);
  506. }
  507. static inline int
  508. typhoon_num_free_tx(struct transmit_ring *ring)
  509. {
  510. /* if we start using the Hi Tx ring, this needs updating */
  511. return typhoon_num_free(ring->lastWrite, ring->lastRead, TXLO_ENTRIES);
  512. }
  513. static int
  514. typhoon_issue_command(struct typhoon *tp, int num_cmd, struct cmd_desc *cmd,
  515. int num_resp, struct resp_desc *resp)
  516. {
  517. struct typhoon_indexes *indexes = tp->indexes;
  518. struct basic_ring *ring = &tp->cmdRing;
  519. struct resp_desc local_resp;
  520. int i, err = 0;
  521. int got_resp;
  522. int freeCmd, freeResp;
  523. int len, wrap_len;
  524. spin_lock(&tp->command_lock);
  525. freeCmd = typhoon_num_free_cmd(tp);
  526. freeResp = typhoon_num_free_resp(tp);
  527. if(freeCmd < num_cmd || freeResp < num_resp) {
  528. printk("%s: no descs for cmd, had (needed) %d (%d) cmd, "
  529. "%d (%d) resp\n", tp->name, freeCmd, num_cmd,
  530. freeResp, num_resp);
  531. err = -ENOMEM;
  532. goto out;
  533. }
  534. if(cmd->flags & TYPHOON_CMD_RESPOND) {
  535. /* If we're expecting a response, but the caller hasn't given
  536. * us a place to put it, we'll provide one.
  537. */
  538. tp->awaiting_resp = 1;
  539. if(resp == NULL) {
  540. resp = &local_resp;
  541. num_resp = 1;
  542. }
  543. }
  544. wrap_len = 0;
  545. len = num_cmd * sizeof(*cmd);
  546. if(unlikely(ring->lastWrite + len > COMMAND_RING_SIZE)) {
  547. wrap_len = ring->lastWrite + len - COMMAND_RING_SIZE;
  548. len = COMMAND_RING_SIZE - ring->lastWrite;
  549. }
  550. memcpy(ring->ringBase + ring->lastWrite, cmd, len);
  551. if(unlikely(wrap_len)) {
  552. struct cmd_desc *wrap_ptr = cmd;
  553. wrap_ptr += len / sizeof(*cmd);
  554. memcpy(ring->ringBase, wrap_ptr, wrap_len);
  555. }
  556. typhoon_inc_cmd_index(&ring->lastWrite, num_cmd);
  557. /* "I feel a presence... another warrior is on the mesa."
  558. */
  559. wmb();
  560. iowrite32(ring->lastWrite, tp->ioaddr + TYPHOON_REG_CMD_READY);
  561. typhoon_post_pci_writes(tp->ioaddr);
  562. if((cmd->flags & TYPHOON_CMD_RESPOND) == 0)
  563. goto out;
  564. /* Ugh. We'll be here about 8ms, spinning our thumbs, unable to
  565. * preempt or do anything other than take interrupts. So, don't
  566. * wait for a response unless you have to.
  567. *
  568. * I've thought about trying to sleep here, but we're called
  569. * from many contexts that don't allow that. Also, given the way
  570. * 3Com has implemented irq coalescing, we would likely timeout --
  571. * this has been observed in real life!
  572. *
  573. * The big killer is we have to wait to get stats from the card,
  574. * though we could go to a periodic refresh of those if we don't
  575. * mind them getting somewhat stale. The rest of the waiting
  576. * commands occur during open/close/suspend/resume, so they aren't
  577. * time critical. Creating SAs in the future will also have to
  578. * wait here.
  579. */
  580. got_resp = 0;
  581. for(i = 0; i < TYPHOON_WAIT_TIMEOUT && !got_resp; i++) {
  582. if(indexes->respCleared != indexes->respReady)
  583. got_resp = typhoon_process_response(tp, num_resp,
  584. resp);
  585. udelay(TYPHOON_UDELAY);
  586. }
  587. if(!got_resp) {
  588. err = -ETIMEDOUT;
  589. goto out;
  590. }
  591. /* Collect the error response even if we don't care about the
  592. * rest of the response
  593. */
  594. if(resp->flags & TYPHOON_RESP_ERROR)
  595. err = -EIO;
  596. out:
  597. if(tp->awaiting_resp) {
  598. tp->awaiting_resp = 0;
  599. smp_wmb();
  600. /* Ugh. If a response was added to the ring between
  601. * the call to typhoon_process_response() and the clearing
  602. * of tp->awaiting_resp, we could have missed the interrupt
  603. * and it could hang in the ring an indeterminate amount of
  604. * time. So, check for it, and interrupt ourselves if this
  605. * is the case.
  606. */
  607. if(indexes->respCleared != indexes->respReady)
  608. iowrite32(1, tp->ioaddr + TYPHOON_REG_SELF_INTERRUPT);
  609. }
  610. spin_unlock(&tp->command_lock);
  611. return err;
  612. }
  613. static void
  614. typhoon_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
  615. {
  616. struct typhoon *tp = netdev_priv(dev);
  617. struct cmd_desc xp_cmd;
  618. int err;
  619. spin_lock_bh(&tp->state_lock);
  620. if(!tp->vlgrp != !grp) {
  621. /* We've either been turned on for the first time, or we've
  622. * been turned off. Update the 3XP.
  623. */
  624. if(grp)
  625. tp->offload |= TYPHOON_OFFLOAD_VLAN;
  626. else
  627. tp->offload &= ~TYPHOON_OFFLOAD_VLAN;
  628. /* If the interface is up, the runtime is running -- and we
  629. * must be up for the vlan core to call us.
  630. *
  631. * Do the command outside of the spin lock, as it is slow.
  632. */
  633. INIT_COMMAND_WITH_RESPONSE(&xp_cmd,
  634. TYPHOON_CMD_SET_OFFLOAD_TASKS);
  635. xp_cmd.parm2 = tp->offload;
  636. xp_cmd.parm3 = tp->offload;
  637. spin_unlock_bh(&tp->state_lock);
  638. err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
  639. if(err < 0)
  640. printk("%s: vlan offload error %d\n", tp->name, -err);
  641. spin_lock_bh(&tp->state_lock);
  642. }
  643. /* now make the change visible */
  644. tp->vlgrp = grp;
  645. spin_unlock_bh(&tp->state_lock);
  646. }
  647. static inline void
  648. typhoon_tso_fill(struct sk_buff *skb, struct transmit_ring *txRing,
  649. u32 ring_dma)
  650. {
  651. struct tcpopt_desc *tcpd;
  652. u32 tcpd_offset = ring_dma;
  653. tcpd = (struct tcpopt_desc *) (txRing->ringBase + txRing->lastWrite);
  654. tcpd_offset += txRing->lastWrite;
  655. tcpd_offset += offsetof(struct tcpopt_desc, bytesTx);
  656. typhoon_inc_tx_index(&txRing->lastWrite, 1);
  657. tcpd->flags = TYPHOON_OPT_DESC | TYPHOON_OPT_TCP_SEG;
  658. tcpd->numDesc = 1;
  659. tcpd->mss_flags = cpu_to_le16(skb_tso_size(skb));
  660. tcpd->mss_flags |= TYPHOON_TSO_FIRST | TYPHOON_TSO_LAST;
  661. tcpd->respAddrLo = cpu_to_le32(tcpd_offset);
  662. tcpd->bytesTx = cpu_to_le32(skb->len);
  663. tcpd->status = 0;
  664. }
  665. static int
  666. typhoon_start_tx(struct sk_buff *skb, struct net_device *dev)
  667. {
  668. struct typhoon *tp = netdev_priv(dev);
  669. struct transmit_ring *txRing;
  670. struct tx_desc *txd, *first_txd;
  671. dma_addr_t skb_dma;
  672. int numDesc;
  673. /* we have two rings to choose from, but we only use txLo for now
  674. * If we start using the Hi ring as well, we'll need to update
  675. * typhoon_stop_runtime(), typhoon_interrupt(), typhoon_num_free_tx(),
  676. * and TXHI_ENTRIES to match, as well as update the TSO code below
  677. * to get the right DMA address
  678. */
  679. txRing = &tp->txLoRing;
  680. /* We need one descriptor for each fragment of the sk_buff, plus the
  681. * one for the ->data area of it.
  682. *
  683. * The docs say a maximum of 16 fragment descriptors per TCP option
  684. * descriptor, then make a new packet descriptor and option descriptor
  685. * for the next 16 fragments. The engineers say just an option
  686. * descriptor is needed. I've tested up to 26 fragments with a single
  687. * packet descriptor/option descriptor combo, so I use that for now.
  688. *
  689. * If problems develop with TSO, check this first.
  690. */
  691. numDesc = skb_shinfo(skb)->nr_frags + 1;
  692. if (skb_is_gso(skb))
  693. numDesc++;
  694. /* When checking for free space in the ring, we need to also
  695. * account for the initial Tx descriptor, and we always must leave
  696. * at least one descriptor unused in the ring so that it doesn't
  697. * wrap and look empty.
  698. *
  699. * The only time we should loop here is when we hit the race
  700. * between marking the queue awake and updating the cleared index.
  701. * Just loop and it will appear. This comes from the acenic driver.
  702. */
  703. while(unlikely(typhoon_num_free_tx(txRing) < (numDesc + 2)))
  704. smp_rmb();
  705. first_txd = (struct tx_desc *) (txRing->ringBase + txRing->lastWrite);
  706. typhoon_inc_tx_index(&txRing->lastWrite, 1);
  707. first_txd->flags = TYPHOON_TX_DESC | TYPHOON_DESC_VALID;
  708. first_txd->numDesc = 0;
  709. first_txd->len = 0;
  710. first_txd->tx_addr = (u64)((unsigned long) skb);
  711. first_txd->processFlags = 0;
  712. if(skb->ip_summed == CHECKSUM_PARTIAL) {
  713. /* The 3XP will figure out if this is UDP/TCP */
  714. first_txd->processFlags |= TYPHOON_TX_PF_TCP_CHKSUM;
  715. first_txd->processFlags |= TYPHOON_TX_PF_UDP_CHKSUM;
  716. first_txd->processFlags |= TYPHOON_TX_PF_IP_CHKSUM;
  717. }
  718. if(vlan_tx_tag_present(skb)) {
  719. first_txd->processFlags |=
  720. TYPHOON_TX_PF_INSERT_VLAN | TYPHOON_TX_PF_VLAN_PRIORITY;
  721. first_txd->processFlags |=
  722. cpu_to_le32(ntohs(vlan_tx_tag_get(skb)) <<
  723. TYPHOON_TX_PF_VLAN_TAG_SHIFT);
  724. }
  725. if (skb_is_gso(skb)) {
  726. first_txd->processFlags |= TYPHOON_TX_PF_TCP_SEGMENT;
  727. first_txd->numDesc++;
  728. typhoon_tso_fill(skb, txRing, tp->txlo_dma_addr);
  729. }
  730. txd = (struct tx_desc *) (txRing->ringBase + txRing->lastWrite);
  731. typhoon_inc_tx_index(&txRing->lastWrite, 1);
  732. /* No need to worry about padding packet -- the firmware pads
  733. * it with zeros to ETH_ZLEN for us.
  734. */
  735. if(skb_shinfo(skb)->nr_frags == 0) {
  736. skb_dma = pci_map_single(tp->tx_pdev, skb->data, skb->len,
  737. PCI_DMA_TODEVICE);
  738. txd->flags = TYPHOON_FRAG_DESC | TYPHOON_DESC_VALID;
  739. txd->len = cpu_to_le16(skb->len);
  740. txd->frag.addr = cpu_to_le32(skb_dma);
  741. txd->frag.addrHi = 0;
  742. first_txd->numDesc++;
  743. } else {
  744. int i, len;
  745. len = skb_headlen(skb);
  746. skb_dma = pci_map_single(tp->tx_pdev, skb->data, len,
  747. PCI_DMA_TODEVICE);
  748. txd->flags = TYPHOON_FRAG_DESC | TYPHOON_DESC_VALID;
  749. txd->len = cpu_to_le16(len);
  750. txd->frag.addr = cpu_to_le32(skb_dma);
  751. txd->frag.addrHi = 0;
  752. first_txd->numDesc++;
  753. for(i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  754. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  755. void *frag_addr;
  756. txd = (struct tx_desc *) (txRing->ringBase +
  757. txRing->lastWrite);
  758. typhoon_inc_tx_index(&txRing->lastWrite, 1);
  759. len = frag->size;
  760. frag_addr = (void *) page_address(frag->page) +
  761. frag->page_offset;
  762. skb_dma = pci_map_single(tp->tx_pdev, frag_addr, len,
  763. PCI_DMA_TODEVICE);
  764. txd->flags = TYPHOON_FRAG_DESC | TYPHOON_DESC_VALID;
  765. txd->len = cpu_to_le16(len);
  766. txd->frag.addr = cpu_to_le32(skb_dma);
  767. txd->frag.addrHi = 0;
  768. first_txd->numDesc++;
  769. }
  770. }
  771. /* Kick the 3XP
  772. */
  773. wmb();
  774. iowrite32(txRing->lastWrite, tp->tx_ioaddr + txRing->writeRegister);
  775. dev->trans_start = jiffies;
  776. /* If we don't have room to put the worst case packet on the
  777. * queue, then we must stop the queue. We need 2 extra
  778. * descriptors -- one to prevent ring wrap, and one for the
  779. * Tx header.
  780. */
  781. numDesc = MAX_SKB_FRAGS + TSO_NUM_DESCRIPTORS + 1;
  782. if(typhoon_num_free_tx(txRing) < (numDesc + 2)) {
  783. netif_stop_queue(dev);
  784. /* A Tx complete IRQ could have gotten inbetween, making
  785. * the ring free again. Only need to recheck here, since
  786. * Tx is serialized.
  787. */
  788. if(typhoon_num_free_tx(txRing) >= (numDesc + 2))
  789. netif_wake_queue(dev);
  790. }
  791. return 0;
  792. }
  793. static void
  794. typhoon_set_rx_mode(struct net_device *dev)
  795. {
  796. struct typhoon *tp = netdev_priv(dev);
  797. struct cmd_desc xp_cmd;
  798. u32 mc_filter[2];
  799. __le16 filter;
  800. filter = TYPHOON_RX_FILTER_DIRECTED | TYPHOON_RX_FILTER_BROADCAST;
  801. if(dev->flags & IFF_PROMISC) {
  802. filter |= TYPHOON_RX_FILTER_PROMISCOUS;
  803. } else if((dev->mc_count > multicast_filter_limit) ||
  804. (dev->flags & IFF_ALLMULTI)) {
  805. /* Too many to match, or accept all multicasts. */
  806. filter |= TYPHOON_RX_FILTER_ALL_MCAST;
  807. } else if(dev->mc_count) {
  808. struct dev_mc_list *mclist;
  809. int i;
  810. memset(mc_filter, 0, sizeof(mc_filter));
  811. for(i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
  812. i++, mclist = mclist->next) {
  813. int bit = ether_crc(ETH_ALEN, mclist->dmi_addr) & 0x3f;
  814. mc_filter[bit >> 5] |= 1 << (bit & 0x1f);
  815. }
  816. INIT_COMMAND_NO_RESPONSE(&xp_cmd,
  817. TYPHOON_CMD_SET_MULTICAST_HASH);
  818. xp_cmd.parm1 = TYPHOON_MCAST_HASH_SET;
  819. xp_cmd.parm2 = cpu_to_le32(mc_filter[0]);
  820. xp_cmd.parm3 = cpu_to_le32(mc_filter[1]);
  821. typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
  822. filter |= TYPHOON_RX_FILTER_MCAST_HASH;
  823. }
  824. INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_SET_RX_FILTER);
  825. xp_cmd.parm1 = filter;
  826. typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
  827. }
  828. static int
  829. typhoon_do_get_stats(struct typhoon *tp)
  830. {
  831. struct net_device_stats *stats = &tp->stats;
  832. struct net_device_stats *saved = &tp->stats_saved;
  833. struct cmd_desc xp_cmd;
  834. struct resp_desc xp_resp[7];
  835. struct stats_resp *s = (struct stats_resp *) xp_resp;
  836. int err;
  837. INIT_COMMAND_WITH_RESPONSE(&xp_cmd, TYPHOON_CMD_READ_STATS);
  838. err = typhoon_issue_command(tp, 1, &xp_cmd, 7, xp_resp);
  839. if(err < 0)
  840. return err;
  841. /* 3Com's Linux driver uses txMultipleCollisions as it's
  842. * collisions value, but there is some other collision info as well...
  843. *
  844. * The extra status reported would be a good candidate for
  845. * ethtool_ops->get_{strings,stats}()
  846. */
  847. stats->tx_packets = le32_to_cpu(s->txPackets);
  848. stats->tx_bytes = le64_to_cpu(s->txBytes);
  849. stats->tx_errors = le32_to_cpu(s->txCarrierLost);
  850. stats->tx_carrier_errors = le32_to_cpu(s->txCarrierLost);
  851. stats->collisions = le32_to_cpu(s->txMultipleCollisions);
  852. stats->rx_packets = le32_to_cpu(s->rxPacketsGood);
  853. stats->rx_bytes = le64_to_cpu(s->rxBytesGood);
  854. stats->rx_fifo_errors = le32_to_cpu(s->rxFifoOverruns);
  855. stats->rx_errors = le32_to_cpu(s->rxFifoOverruns) +
  856. le32_to_cpu(s->BadSSD) + le32_to_cpu(s->rxCrcErrors);
  857. stats->rx_crc_errors = le32_to_cpu(s->rxCrcErrors);
  858. stats->rx_length_errors = le32_to_cpu(s->rxOversized);
  859. tp->speed = (s->linkStatus & TYPHOON_LINK_100MBPS) ?
  860. SPEED_100 : SPEED_10;
  861. tp->duplex = (s->linkStatus & TYPHOON_LINK_FULL_DUPLEX) ?
  862. DUPLEX_FULL : DUPLEX_HALF;
  863. /* add in the saved statistics
  864. */
  865. stats->tx_packets += saved->tx_packets;
  866. stats->tx_bytes += saved->tx_bytes;
  867. stats->tx_errors += saved->tx_errors;
  868. stats->collisions += saved->collisions;
  869. stats->rx_packets += saved->rx_packets;
  870. stats->rx_bytes += saved->rx_bytes;
  871. stats->rx_fifo_errors += saved->rx_fifo_errors;
  872. stats->rx_errors += saved->rx_errors;
  873. stats->rx_crc_errors += saved->rx_crc_errors;
  874. stats->rx_length_errors += saved->rx_length_errors;
  875. return 0;
  876. }
  877. static struct net_device_stats *
  878. typhoon_get_stats(struct net_device *dev)
  879. {
  880. struct typhoon *tp = netdev_priv(dev);
  881. struct net_device_stats *stats = &tp->stats;
  882. struct net_device_stats *saved = &tp->stats_saved;
  883. smp_rmb();
  884. if(tp->card_state == Sleeping)
  885. return saved;
  886. if(typhoon_do_get_stats(tp) < 0) {
  887. printk(KERN_ERR "%s: error getting stats\n", dev->name);
  888. return saved;
  889. }
  890. return stats;
  891. }
  892. static int
  893. typhoon_set_mac_address(struct net_device *dev, void *addr)
  894. {
  895. struct sockaddr *saddr = (struct sockaddr *) addr;
  896. if(netif_running(dev))
  897. return -EBUSY;
  898. memcpy(dev->dev_addr, saddr->sa_data, dev->addr_len);
  899. return 0;
  900. }
  901. static void
  902. typhoon_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  903. {
  904. struct typhoon *tp = netdev_priv(dev);
  905. struct pci_dev *pci_dev = tp->pdev;
  906. struct cmd_desc xp_cmd;
  907. struct resp_desc xp_resp[3];
  908. smp_rmb();
  909. if(tp->card_state == Sleeping) {
  910. strcpy(info->fw_version, "Sleep image");
  911. } else {
  912. INIT_COMMAND_WITH_RESPONSE(&xp_cmd, TYPHOON_CMD_READ_VERSIONS);
  913. if(typhoon_issue_command(tp, 1, &xp_cmd, 3, xp_resp) < 0) {
  914. strcpy(info->fw_version, "Unknown runtime");
  915. } else {
  916. u32 sleep_ver = le32_to_cpu(xp_resp[0].parm2);
  917. snprintf(info->fw_version, 32, "%02x.%03x.%03x",
  918. sleep_ver >> 24, (sleep_ver >> 12) & 0xfff,
  919. sleep_ver & 0xfff);
  920. }
  921. }
  922. strcpy(info->driver, DRV_MODULE_NAME);
  923. strcpy(info->version, DRV_MODULE_VERSION);
  924. strcpy(info->bus_info, pci_name(pci_dev));
  925. }
  926. static int
  927. typhoon_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  928. {
  929. struct typhoon *tp = netdev_priv(dev);
  930. cmd->supported = SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
  931. SUPPORTED_Autoneg;
  932. switch (tp->xcvr_select) {
  933. case TYPHOON_XCVR_10HALF:
  934. cmd->advertising = ADVERTISED_10baseT_Half;
  935. break;
  936. case TYPHOON_XCVR_10FULL:
  937. cmd->advertising = ADVERTISED_10baseT_Full;
  938. break;
  939. case TYPHOON_XCVR_100HALF:
  940. cmd->advertising = ADVERTISED_100baseT_Half;
  941. break;
  942. case TYPHOON_XCVR_100FULL:
  943. cmd->advertising = ADVERTISED_100baseT_Full;
  944. break;
  945. case TYPHOON_XCVR_AUTONEG:
  946. cmd->advertising = ADVERTISED_10baseT_Half |
  947. ADVERTISED_10baseT_Full |
  948. ADVERTISED_100baseT_Half |
  949. ADVERTISED_100baseT_Full |
  950. ADVERTISED_Autoneg;
  951. break;
  952. }
  953. if(tp->capabilities & TYPHOON_FIBER) {
  954. cmd->supported |= SUPPORTED_FIBRE;
  955. cmd->advertising |= ADVERTISED_FIBRE;
  956. cmd->port = PORT_FIBRE;
  957. } else {
  958. cmd->supported |= SUPPORTED_10baseT_Half |
  959. SUPPORTED_10baseT_Full |
  960. SUPPORTED_TP;
  961. cmd->advertising |= ADVERTISED_TP;
  962. cmd->port = PORT_TP;
  963. }
  964. /* need to get stats to make these link speed/duplex valid */
  965. typhoon_do_get_stats(tp);
  966. cmd->speed = tp->speed;
  967. cmd->duplex = tp->duplex;
  968. cmd->phy_address = 0;
  969. cmd->transceiver = XCVR_INTERNAL;
  970. if(tp->xcvr_select == TYPHOON_XCVR_AUTONEG)
  971. cmd->autoneg = AUTONEG_ENABLE;
  972. else
  973. cmd->autoneg = AUTONEG_DISABLE;
  974. cmd->maxtxpkt = 1;
  975. cmd->maxrxpkt = 1;
  976. return 0;
  977. }
  978. static int
  979. typhoon_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  980. {
  981. struct typhoon *tp = netdev_priv(dev);
  982. struct cmd_desc xp_cmd;
  983. __le16 xcvr;
  984. int err;
  985. err = -EINVAL;
  986. if(cmd->autoneg == AUTONEG_ENABLE) {
  987. xcvr = TYPHOON_XCVR_AUTONEG;
  988. } else {
  989. if(cmd->duplex == DUPLEX_HALF) {
  990. if(cmd->speed == SPEED_10)
  991. xcvr = TYPHOON_XCVR_10HALF;
  992. else if(cmd->speed == SPEED_100)
  993. xcvr = TYPHOON_XCVR_100HALF;
  994. else
  995. goto out;
  996. } else if(cmd->duplex == DUPLEX_FULL) {
  997. if(cmd->speed == SPEED_10)
  998. xcvr = TYPHOON_XCVR_10FULL;
  999. else if(cmd->speed == SPEED_100)
  1000. xcvr = TYPHOON_XCVR_100FULL;
  1001. else
  1002. goto out;
  1003. } else
  1004. goto out;
  1005. }
  1006. INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_XCVR_SELECT);
  1007. xp_cmd.parm1 = xcvr;
  1008. err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
  1009. if(err < 0)
  1010. goto out;
  1011. tp->xcvr_select = xcvr;
  1012. if(cmd->autoneg == AUTONEG_ENABLE) {
  1013. tp->speed = 0xff; /* invalid */
  1014. tp->duplex = 0xff; /* invalid */
  1015. } else {
  1016. tp->speed = cmd->speed;
  1017. tp->duplex = cmd->duplex;
  1018. }
  1019. out:
  1020. return err;
  1021. }
  1022. static void
  1023. typhoon_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  1024. {
  1025. struct typhoon *tp = netdev_priv(dev);
  1026. wol->supported = WAKE_PHY | WAKE_MAGIC;
  1027. wol->wolopts = 0;
  1028. if(tp->wol_events & TYPHOON_WAKE_LINK_EVENT)
  1029. wol->wolopts |= WAKE_PHY;
  1030. if(tp->wol_events & TYPHOON_WAKE_MAGIC_PKT)
  1031. wol->wolopts |= WAKE_MAGIC;
  1032. memset(&wol->sopass, 0, sizeof(wol->sopass));
  1033. }
  1034. static int
  1035. typhoon_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  1036. {
  1037. struct typhoon *tp = netdev_priv(dev);
  1038. if(wol->wolopts & ~(WAKE_PHY | WAKE_MAGIC))
  1039. return -EINVAL;
  1040. tp->wol_events = 0;
  1041. if(wol->wolopts & WAKE_PHY)
  1042. tp->wol_events |= TYPHOON_WAKE_LINK_EVENT;
  1043. if(wol->wolopts & WAKE_MAGIC)
  1044. tp->wol_events |= TYPHOON_WAKE_MAGIC_PKT;
  1045. return 0;
  1046. }
  1047. static u32
  1048. typhoon_get_rx_csum(struct net_device *dev)
  1049. {
  1050. /* For now, we don't allow turning off RX checksums.
  1051. */
  1052. return 1;
  1053. }
  1054. static void
  1055. typhoon_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  1056. {
  1057. ering->rx_max_pending = RXENT_ENTRIES;
  1058. ering->rx_mini_max_pending = 0;
  1059. ering->rx_jumbo_max_pending = 0;
  1060. ering->tx_max_pending = TXLO_ENTRIES - 1;
  1061. ering->rx_pending = RXENT_ENTRIES;
  1062. ering->rx_mini_pending = 0;
  1063. ering->rx_jumbo_pending = 0;
  1064. ering->tx_pending = TXLO_ENTRIES - 1;
  1065. }
  1066. static const struct ethtool_ops typhoon_ethtool_ops = {
  1067. .get_settings = typhoon_get_settings,
  1068. .set_settings = typhoon_set_settings,
  1069. .get_drvinfo = typhoon_get_drvinfo,
  1070. .get_wol = typhoon_get_wol,
  1071. .set_wol = typhoon_set_wol,
  1072. .get_link = ethtool_op_get_link,
  1073. .get_rx_csum = typhoon_get_rx_csum,
  1074. .set_tx_csum = ethtool_op_set_tx_csum,
  1075. .set_sg = ethtool_op_set_sg,
  1076. .set_tso = ethtool_op_set_tso,
  1077. .get_ringparam = typhoon_get_ringparam,
  1078. };
  1079. static int
  1080. typhoon_wait_interrupt(void __iomem *ioaddr)
  1081. {
  1082. int i, err = 0;
  1083. for(i = 0; i < TYPHOON_WAIT_TIMEOUT; i++) {
  1084. if(ioread32(ioaddr + TYPHOON_REG_INTR_STATUS) &
  1085. TYPHOON_INTR_BOOTCMD)
  1086. goto out;
  1087. udelay(TYPHOON_UDELAY);
  1088. }
  1089. err = -ETIMEDOUT;
  1090. out:
  1091. iowrite32(TYPHOON_INTR_BOOTCMD, ioaddr + TYPHOON_REG_INTR_STATUS);
  1092. return err;
  1093. }
  1094. #define shared_offset(x) offsetof(struct typhoon_shared, x)
  1095. static void
  1096. typhoon_init_interface(struct typhoon *tp)
  1097. {
  1098. struct typhoon_interface *iface = &tp->shared->iface;
  1099. dma_addr_t shared_dma;
  1100. memset(tp->shared, 0, sizeof(struct typhoon_shared));
  1101. /* The *Hi members of iface are all init'd to zero by the memset().
  1102. */
  1103. shared_dma = tp->shared_dma + shared_offset(indexes);
  1104. iface->ringIndex = cpu_to_le32(shared_dma);
  1105. shared_dma = tp->shared_dma + shared_offset(txLo);
  1106. iface->txLoAddr = cpu_to_le32(shared_dma);
  1107. iface->txLoSize = cpu_to_le32(TXLO_ENTRIES * sizeof(struct tx_desc));
  1108. shared_dma = tp->shared_dma + shared_offset(txHi);
  1109. iface->txHiAddr = cpu_to_le32(shared_dma);
  1110. iface->txHiSize = cpu_to_le32(TXHI_ENTRIES * sizeof(struct tx_desc));
  1111. shared_dma = tp->shared_dma + shared_offset(rxBuff);
  1112. iface->rxBuffAddr = cpu_to_le32(shared_dma);
  1113. iface->rxBuffSize = cpu_to_le32(RXFREE_ENTRIES *
  1114. sizeof(struct rx_free));
  1115. shared_dma = tp->shared_dma + shared_offset(rxLo);
  1116. iface->rxLoAddr = cpu_to_le32(shared_dma);
  1117. iface->rxLoSize = cpu_to_le32(RX_ENTRIES * sizeof(struct rx_desc));
  1118. shared_dma = tp->shared_dma + shared_offset(rxHi);
  1119. iface->rxHiAddr = cpu_to_le32(shared_dma);
  1120. iface->rxHiSize = cpu_to_le32(RX_ENTRIES * sizeof(struct rx_desc));
  1121. shared_dma = tp->shared_dma + shared_offset(cmd);
  1122. iface->cmdAddr = cpu_to_le32(shared_dma);
  1123. iface->cmdSize = cpu_to_le32(COMMAND_RING_SIZE);
  1124. shared_dma = tp->shared_dma + shared_offset(resp);
  1125. iface->respAddr = cpu_to_le32(shared_dma);
  1126. iface->respSize = cpu_to_le32(RESPONSE_RING_SIZE);
  1127. shared_dma = tp->shared_dma + shared_offset(zeroWord);
  1128. iface->zeroAddr = cpu_to_le32(shared_dma);
  1129. tp->indexes = &tp->shared->indexes;
  1130. tp->txLoRing.ringBase = (u8 *) tp->shared->txLo;
  1131. tp->txHiRing.ringBase = (u8 *) tp->shared->txHi;
  1132. tp->rxLoRing.ringBase = (u8 *) tp->shared->rxLo;
  1133. tp->rxHiRing.ringBase = (u8 *) tp->shared->rxHi;
  1134. tp->rxBuffRing.ringBase = (u8 *) tp->shared->rxBuff;
  1135. tp->cmdRing.ringBase = (u8 *) tp->shared->cmd;
  1136. tp->respRing.ringBase = (u8 *) tp->shared->resp;
  1137. tp->txLoRing.writeRegister = TYPHOON_REG_TX_LO_READY;
  1138. tp->txHiRing.writeRegister = TYPHOON_REG_TX_HI_READY;
  1139. tp->txlo_dma_addr = le32_to_cpu(iface->txLoAddr);
  1140. tp->card_state = Sleeping;
  1141. smp_wmb();
  1142. tp->offload = TYPHOON_OFFLOAD_IP_CHKSUM | TYPHOON_OFFLOAD_TCP_CHKSUM;
  1143. tp->offload |= TYPHOON_OFFLOAD_UDP_CHKSUM | TSO_OFFLOAD_ON;
  1144. spin_lock_init(&tp->command_lock);
  1145. spin_lock_init(&tp->state_lock);
  1146. }
  1147. static void
  1148. typhoon_init_rings(struct typhoon *tp)
  1149. {
  1150. memset(tp->indexes, 0, sizeof(struct typhoon_indexes));
  1151. tp->txLoRing.lastWrite = 0;
  1152. tp->txHiRing.lastWrite = 0;
  1153. tp->rxLoRing.lastWrite = 0;
  1154. tp->rxHiRing.lastWrite = 0;
  1155. tp->rxBuffRing.lastWrite = 0;
  1156. tp->cmdRing.lastWrite = 0;
  1157. tp->cmdRing.lastWrite = 0;
  1158. tp->txLoRing.lastRead = 0;
  1159. tp->txHiRing.lastRead = 0;
  1160. }
  1161. static const struct firmware *typhoon_fw;
  1162. static int
  1163. typhoon_request_firmware(struct typhoon *tp)
  1164. {
  1165. const struct typhoon_file_header *fHdr;
  1166. const struct typhoon_section_header *sHdr;
  1167. const u8 *image_data;
  1168. u32 numSections;
  1169. u32 section_len;
  1170. u32 remaining;
  1171. int err;
  1172. if (typhoon_fw)
  1173. return 0;
  1174. err = request_firmware(&typhoon_fw, FIRMWARE_NAME, &tp->pdev->dev);
  1175. if (err) {
  1176. printk(KERN_ERR "%s: Failed to load firmware \"%s\"\n",
  1177. tp->name, FIRMWARE_NAME);
  1178. return err;
  1179. }
  1180. image_data = (u8 *) typhoon_fw->data;
  1181. remaining = typhoon_fw->size;
  1182. if (remaining < sizeof(struct typhoon_file_header))
  1183. goto invalid_fw;
  1184. fHdr = (struct typhoon_file_header *) image_data;
  1185. if (memcmp(fHdr->tag, "TYPHOON", 8))
  1186. goto invalid_fw;
  1187. numSections = le32_to_cpu(fHdr->numSections);
  1188. image_data += sizeof(struct typhoon_file_header);
  1189. remaining -= sizeof(struct typhoon_file_header);
  1190. while (numSections--) {
  1191. if (remaining < sizeof(struct typhoon_section_header))
  1192. goto invalid_fw;
  1193. sHdr = (struct typhoon_section_header *) image_data;
  1194. image_data += sizeof(struct typhoon_section_header);
  1195. section_len = le32_to_cpu(sHdr->len);
  1196. if (remaining < section_len)
  1197. goto invalid_fw;
  1198. image_data += section_len;
  1199. remaining -= section_len;
  1200. }
  1201. return 0;
  1202. invalid_fw:
  1203. printk(KERN_ERR "%s: Invalid firmware image\n", tp->name);
  1204. release_firmware(typhoon_fw);
  1205. typhoon_fw = NULL;
  1206. return -EINVAL;
  1207. }
  1208. static int
  1209. typhoon_download_firmware(struct typhoon *tp)
  1210. {
  1211. void __iomem *ioaddr = tp->ioaddr;
  1212. struct pci_dev *pdev = tp->pdev;
  1213. const struct typhoon_file_header *fHdr;
  1214. const struct typhoon_section_header *sHdr;
  1215. const u8 *image_data;
  1216. void *dpage;
  1217. dma_addr_t dpage_dma;
  1218. __sum16 csum;
  1219. u32 irqEnabled;
  1220. u32 irqMasked;
  1221. u32 numSections;
  1222. u32 section_len;
  1223. u32 len;
  1224. u32 load_addr;
  1225. u32 hmac;
  1226. int i;
  1227. int err;
  1228. image_data = (u8 *) typhoon_fw->data;
  1229. fHdr = (struct typhoon_file_header *) image_data;
  1230. /* Cannot just map the firmware image using pci_map_single() as
  1231. * the firmware is vmalloc()'d and may not be physically contiguous,
  1232. * so we allocate some consistent memory to copy the sections into.
  1233. */
  1234. err = -ENOMEM;
  1235. dpage = pci_alloc_consistent(pdev, PAGE_SIZE, &dpage_dma);
  1236. if(!dpage) {
  1237. printk(KERN_ERR "%s: no DMA mem for firmware\n", tp->name);
  1238. goto err_out;
  1239. }
  1240. irqEnabled = ioread32(ioaddr + TYPHOON_REG_INTR_ENABLE);
  1241. iowrite32(irqEnabled | TYPHOON_INTR_BOOTCMD,
  1242. ioaddr + TYPHOON_REG_INTR_ENABLE);
  1243. irqMasked = ioread32(ioaddr + TYPHOON_REG_INTR_MASK);
  1244. iowrite32(irqMasked | TYPHOON_INTR_BOOTCMD,
  1245. ioaddr + TYPHOON_REG_INTR_MASK);
  1246. err = -ETIMEDOUT;
  1247. if(typhoon_wait_status(ioaddr, TYPHOON_STATUS_WAITING_FOR_HOST) < 0) {
  1248. printk(KERN_ERR "%s: card ready timeout\n", tp->name);
  1249. goto err_out_irq;
  1250. }
  1251. numSections = le32_to_cpu(fHdr->numSections);
  1252. load_addr = le32_to_cpu(fHdr->startAddr);
  1253. iowrite32(TYPHOON_INTR_BOOTCMD, ioaddr + TYPHOON_REG_INTR_STATUS);
  1254. iowrite32(load_addr, ioaddr + TYPHOON_REG_DOWNLOAD_BOOT_ADDR);
  1255. hmac = le32_to_cpu(fHdr->hmacDigest[0]);
  1256. iowrite32(hmac, ioaddr + TYPHOON_REG_DOWNLOAD_HMAC_0);
  1257. hmac = le32_to_cpu(fHdr->hmacDigest[1]);
  1258. iowrite32(hmac, ioaddr + TYPHOON_REG_DOWNLOAD_HMAC_1);
  1259. hmac = le32_to_cpu(fHdr->hmacDigest[2]);
  1260. iowrite32(hmac, ioaddr + TYPHOON_REG_DOWNLOAD_HMAC_2);
  1261. hmac = le32_to_cpu(fHdr->hmacDigest[3]);
  1262. iowrite32(hmac, ioaddr + TYPHOON_REG_DOWNLOAD_HMAC_3);
  1263. hmac = le32_to_cpu(fHdr->hmacDigest[4]);
  1264. iowrite32(hmac, ioaddr + TYPHOON_REG_DOWNLOAD_HMAC_4);
  1265. typhoon_post_pci_writes(ioaddr);
  1266. iowrite32(TYPHOON_BOOTCMD_RUNTIME_IMAGE, ioaddr + TYPHOON_REG_COMMAND);
  1267. image_data += sizeof(struct typhoon_file_header);
  1268. /* The ioread32() in typhoon_wait_interrupt() will force the
  1269. * last write to the command register to post, so
  1270. * we don't need a typhoon_post_pci_writes() after it.
  1271. */
  1272. for(i = 0; i < numSections; i++) {
  1273. sHdr = (struct typhoon_section_header *) image_data;
  1274. image_data += sizeof(struct typhoon_section_header);
  1275. load_addr = le32_to_cpu(sHdr->startAddr);
  1276. section_len = le32_to_cpu(sHdr->len);
  1277. while(section_len) {
  1278. len = min_t(u32, section_len, PAGE_SIZE);
  1279. if(typhoon_wait_interrupt(ioaddr) < 0 ||
  1280. ioread32(ioaddr + TYPHOON_REG_STATUS) !=
  1281. TYPHOON_STATUS_WAITING_FOR_SEGMENT) {
  1282. printk(KERN_ERR "%s: segment ready timeout\n",
  1283. tp->name);
  1284. goto err_out_irq;
  1285. }
  1286. /* Do an pseudo IPv4 checksum on the data -- first
  1287. * need to convert each u16 to cpu order before
  1288. * summing. Fortunately, due to the properties of
  1289. * the checksum, we can do this once, at the end.
  1290. */
  1291. csum = csum_fold(csum_partial_copy_nocheck(image_data,
  1292. dpage, len,
  1293. 0));
  1294. iowrite32(len, ioaddr + TYPHOON_REG_BOOT_LENGTH);
  1295. iowrite32(le16_to_cpu((__force __le16)csum),
  1296. ioaddr + TYPHOON_REG_BOOT_CHECKSUM);
  1297. iowrite32(load_addr,
  1298. ioaddr + TYPHOON_REG_BOOT_DEST_ADDR);
  1299. iowrite32(0, ioaddr + TYPHOON_REG_BOOT_DATA_HI);
  1300. iowrite32(dpage_dma, ioaddr + TYPHOON_REG_BOOT_DATA_LO);
  1301. typhoon_post_pci_writes(ioaddr);
  1302. iowrite32(TYPHOON_BOOTCMD_SEG_AVAILABLE,
  1303. ioaddr + TYPHOON_REG_COMMAND);
  1304. image_data += len;
  1305. load_addr += len;
  1306. section_len -= len;
  1307. }
  1308. }
  1309. if(typhoon_wait_interrupt(ioaddr) < 0 ||
  1310. ioread32(ioaddr + TYPHOON_REG_STATUS) !=
  1311. TYPHOON_STATUS_WAITING_FOR_SEGMENT) {
  1312. printk(KERN_ERR "%s: final segment ready timeout\n", tp->name);
  1313. goto err_out_irq;
  1314. }
  1315. iowrite32(TYPHOON_BOOTCMD_DNLD_COMPLETE, ioaddr + TYPHOON_REG_COMMAND);
  1316. if(typhoon_wait_status(ioaddr, TYPHOON_STATUS_WAITING_FOR_BOOT) < 0) {
  1317. printk(KERN_ERR "%s: boot ready timeout, status 0x%0x\n",
  1318. tp->name, ioread32(ioaddr + TYPHOON_REG_STATUS));
  1319. goto err_out_irq;
  1320. }
  1321. err = 0;
  1322. err_out_irq:
  1323. iowrite32(irqMasked, ioaddr + TYPHOON_REG_INTR_MASK);
  1324. iowrite32(irqEnabled, ioaddr + TYPHOON_REG_INTR_ENABLE);
  1325. pci_free_consistent(pdev, PAGE_SIZE, dpage, dpage_dma);
  1326. err_out:
  1327. return err;
  1328. }
  1329. static int
  1330. typhoon_boot_3XP(struct typhoon *tp, u32 initial_status)
  1331. {
  1332. void __iomem *ioaddr = tp->ioaddr;
  1333. if(typhoon_wait_status(ioaddr, initial_status) < 0) {
  1334. printk(KERN_ERR "%s: boot ready timeout\n", tp->name);
  1335. goto out_timeout;
  1336. }
  1337. iowrite32(0, ioaddr + TYPHOON_REG_BOOT_RECORD_ADDR_HI);
  1338. iowrite32(tp->shared_dma, ioaddr + TYPHOON_REG_BOOT_RECORD_ADDR_LO);
  1339. typhoon_post_pci_writes(ioaddr);
  1340. iowrite32(TYPHOON_BOOTCMD_REG_BOOT_RECORD,
  1341. ioaddr + TYPHOON_REG_COMMAND);
  1342. if(typhoon_wait_status(ioaddr, TYPHOON_STATUS_RUNNING) < 0) {
  1343. printk(KERN_ERR "%s: boot finish timeout (status 0x%x)\n",
  1344. tp->name, ioread32(ioaddr + TYPHOON_REG_STATUS));
  1345. goto out_timeout;
  1346. }
  1347. /* Clear the Transmit and Command ready registers
  1348. */
  1349. iowrite32(0, ioaddr + TYPHOON_REG_TX_HI_READY);
  1350. iowrite32(0, ioaddr + TYPHOON_REG_CMD_READY);
  1351. iowrite32(0, ioaddr + TYPHOON_REG_TX_LO_READY);
  1352. typhoon_post_pci_writes(ioaddr);
  1353. iowrite32(TYPHOON_BOOTCMD_BOOT, ioaddr + TYPHOON_REG_COMMAND);
  1354. return 0;
  1355. out_timeout:
  1356. return -ETIMEDOUT;
  1357. }
  1358. static u32
  1359. typhoon_clean_tx(struct typhoon *tp, struct transmit_ring *txRing,
  1360. volatile __le32 * index)
  1361. {
  1362. u32 lastRead = txRing->lastRead;
  1363. struct tx_desc *tx;
  1364. dma_addr_t skb_dma;
  1365. int dma_len;
  1366. int type;
  1367. while(lastRead != le32_to_cpu(*index)) {
  1368. tx = (struct tx_desc *) (txRing->ringBase + lastRead);
  1369. type = tx->flags & TYPHOON_TYPE_MASK;
  1370. if(type == TYPHOON_TX_DESC) {
  1371. /* This tx_desc describes a packet.
  1372. */
  1373. unsigned long ptr = tx->tx_addr;
  1374. struct sk_buff *skb = (struct sk_buff *) ptr;
  1375. dev_kfree_skb_irq(skb);
  1376. } else if(type == TYPHOON_FRAG_DESC) {
  1377. /* This tx_desc describes a memory mapping. Free it.
  1378. */
  1379. skb_dma = (dma_addr_t) le32_to_cpu(tx->frag.addr);
  1380. dma_len = le16_to_cpu(tx->len);
  1381. pci_unmap_single(tp->pdev, skb_dma, dma_len,
  1382. PCI_DMA_TODEVICE);
  1383. }
  1384. tx->flags = 0;
  1385. typhoon_inc_tx_index(&lastRead, 1);
  1386. }
  1387. return lastRead;
  1388. }
  1389. static void
  1390. typhoon_tx_complete(struct typhoon *tp, struct transmit_ring *txRing,
  1391. volatile __le32 * index)
  1392. {
  1393. u32 lastRead;
  1394. int numDesc = MAX_SKB_FRAGS + 1;
  1395. /* This will need changing if we start to use the Hi Tx ring. */
  1396. lastRead = typhoon_clean_tx(tp, txRing, index);
  1397. if(netif_queue_stopped(tp->dev) && typhoon_num_free(txRing->lastWrite,
  1398. lastRead, TXLO_ENTRIES) > (numDesc + 2))
  1399. netif_wake_queue(tp->dev);
  1400. txRing->lastRead = lastRead;
  1401. smp_wmb();
  1402. }
  1403. static void
  1404. typhoon_recycle_rx_skb(struct typhoon *tp, u32 idx)
  1405. {
  1406. struct typhoon_indexes *indexes = tp->indexes;
  1407. struct rxbuff_ent *rxb = &tp->rxbuffers[idx];
  1408. struct basic_ring *ring = &tp->rxBuffRing;
  1409. struct rx_free *r;
  1410. if((ring->lastWrite + sizeof(*r)) % (RXFREE_ENTRIES * sizeof(*r)) ==
  1411. le32_to_cpu(indexes->rxBuffCleared)) {
  1412. /* no room in ring, just drop the skb
  1413. */
  1414. dev_kfree_skb_any(rxb->skb);
  1415. rxb->skb = NULL;
  1416. return;
  1417. }
  1418. r = (struct rx_free *) (ring->ringBase + ring->lastWrite);
  1419. typhoon_inc_rxfree_index(&ring->lastWrite, 1);
  1420. r->virtAddr = idx;
  1421. r->physAddr = cpu_to_le32(rxb->dma_addr);
  1422. /* Tell the card about it */
  1423. wmb();
  1424. indexes->rxBuffReady = cpu_to_le32(ring->lastWrite);
  1425. }
  1426. static int
  1427. typhoon_alloc_rx_skb(struct typhoon *tp, u32 idx)
  1428. {
  1429. struct typhoon_indexes *indexes = tp->indexes;
  1430. struct rxbuff_ent *rxb = &tp->rxbuffers[idx];
  1431. struct basic_ring *ring = &tp->rxBuffRing;
  1432. struct rx_free *r;
  1433. struct sk_buff *skb;
  1434. dma_addr_t dma_addr;
  1435. rxb->skb = NULL;
  1436. if((ring->lastWrite + sizeof(*r)) % (RXFREE_ENTRIES * sizeof(*r)) ==
  1437. le32_to_cpu(indexes->rxBuffCleared))
  1438. return -ENOMEM;
  1439. skb = dev_alloc_skb(PKT_BUF_SZ);
  1440. if(!skb)
  1441. return -ENOMEM;
  1442. #if 0
  1443. /* Please, 3com, fix the firmware to allow DMA to a unaligned
  1444. * address! Pretty please?
  1445. */
  1446. skb_reserve(skb, 2);
  1447. #endif
  1448. skb->dev = tp->dev;
  1449. dma_addr = pci_map_single(tp->pdev, skb->data,
  1450. PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
  1451. /* Since no card does 64 bit DAC, the high bits will never
  1452. * change from zero.
  1453. */
  1454. r = (struct rx_free *) (ring->ringBase + ring->lastWrite);
  1455. typhoon_inc_rxfree_index(&ring->lastWrite, 1);
  1456. r->virtAddr = idx;
  1457. r->physAddr = cpu_to_le32(dma_addr);
  1458. rxb->skb = skb;
  1459. rxb->dma_addr = dma_addr;
  1460. /* Tell the card about it */
  1461. wmb();
  1462. indexes->rxBuffReady = cpu_to_le32(ring->lastWrite);
  1463. return 0;
  1464. }
  1465. static int
  1466. typhoon_rx(struct typhoon *tp, struct basic_ring *rxRing, volatile __le32 * ready,
  1467. volatile __le32 * cleared, int budget)
  1468. {
  1469. struct rx_desc *rx;
  1470. struct sk_buff *skb, *new_skb;
  1471. struct rxbuff_ent *rxb;
  1472. dma_addr_t dma_addr;
  1473. u32 local_ready;
  1474. u32 rxaddr;
  1475. int pkt_len;
  1476. u32 idx;
  1477. __le32 csum_bits;
  1478. int received;
  1479. received = 0;
  1480. local_ready = le32_to_cpu(*ready);
  1481. rxaddr = le32_to_cpu(*cleared);
  1482. while(rxaddr != local_ready && budget > 0) {
  1483. rx = (struct rx_desc *) (rxRing->ringBase + rxaddr);
  1484. idx = rx->addr;
  1485. rxb = &tp->rxbuffers[idx];
  1486. skb = rxb->skb;
  1487. dma_addr = rxb->dma_addr;
  1488. typhoon_inc_rx_index(&rxaddr, 1);
  1489. if(rx->flags & TYPHOON_RX_ERROR) {
  1490. typhoon_recycle_rx_skb(tp, idx);
  1491. continue;
  1492. }
  1493. pkt_len = le16_to_cpu(rx->frameLen);
  1494. if(pkt_len < rx_copybreak &&
  1495. (new_skb = dev_alloc_skb(pkt_len + 2)) != NULL) {
  1496. skb_reserve(new_skb, 2);
  1497. pci_dma_sync_single_for_cpu(tp->pdev, dma_addr,
  1498. PKT_BUF_SZ,
  1499. PCI_DMA_FROMDEVICE);
  1500. skb_copy_to_linear_data(new_skb, skb->data, pkt_len);
  1501. pci_dma_sync_single_for_device(tp->pdev, dma_addr,
  1502. PKT_BUF_SZ,
  1503. PCI_DMA_FROMDEVICE);
  1504. skb_put(new_skb, pkt_len);
  1505. typhoon_recycle_rx_skb(tp, idx);
  1506. } else {
  1507. new_skb = skb;
  1508. skb_put(new_skb, pkt_len);
  1509. pci_unmap_single(tp->pdev, dma_addr, PKT_BUF_SZ,
  1510. PCI_DMA_FROMDEVICE);
  1511. typhoon_alloc_rx_skb(tp, idx);
  1512. }
  1513. new_skb->protocol = eth_type_trans(new_skb, tp->dev);
  1514. csum_bits = rx->rxStatus & (TYPHOON_RX_IP_CHK_GOOD |
  1515. TYPHOON_RX_UDP_CHK_GOOD | TYPHOON_RX_TCP_CHK_GOOD);
  1516. if(csum_bits ==
  1517. (TYPHOON_RX_IP_CHK_GOOD | TYPHOON_RX_TCP_CHK_GOOD)
  1518. || csum_bits ==
  1519. (TYPHOON_RX_IP_CHK_GOOD | TYPHOON_RX_UDP_CHK_GOOD)) {
  1520. new_skb->ip_summed = CHECKSUM_UNNECESSARY;
  1521. } else
  1522. new_skb->ip_summed = CHECKSUM_NONE;
  1523. spin_lock(&tp->state_lock);
  1524. if(tp->vlgrp != NULL && rx->rxStatus & TYPHOON_RX_VLAN)
  1525. vlan_hwaccel_receive_skb(new_skb, tp->vlgrp,
  1526. ntohl(rx->vlanTag) & 0xffff);
  1527. else
  1528. netif_receive_skb(new_skb);
  1529. spin_unlock(&tp->state_lock);
  1530. received++;
  1531. budget--;
  1532. }
  1533. *cleared = cpu_to_le32(rxaddr);
  1534. return received;
  1535. }
  1536. static void
  1537. typhoon_fill_free_ring(struct typhoon *tp)
  1538. {
  1539. u32 i;
  1540. for(i = 0; i < RXENT_ENTRIES; i++) {
  1541. struct rxbuff_ent *rxb = &tp->rxbuffers[i];
  1542. if(rxb->skb)
  1543. continue;
  1544. if(typhoon_alloc_rx_skb(tp, i) < 0)
  1545. break;
  1546. }
  1547. }
  1548. static int
  1549. typhoon_poll(struct napi_struct *napi, int budget)
  1550. {
  1551. struct typhoon *tp = container_of(napi, struct typhoon, napi);
  1552. struct typhoon_indexes *indexes = tp->indexes;
  1553. int work_done;
  1554. rmb();
  1555. if(!tp->awaiting_resp && indexes->respReady != indexes->respCleared)
  1556. typhoon_process_response(tp, 0, NULL);
  1557. if(le32_to_cpu(indexes->txLoCleared) != tp->txLoRing.lastRead)
  1558. typhoon_tx_complete(tp, &tp->txLoRing, &indexes->txLoCleared);
  1559. work_done = 0;
  1560. if(indexes->rxHiCleared != indexes->rxHiReady) {
  1561. work_done += typhoon_rx(tp, &tp->rxHiRing, &indexes->rxHiReady,
  1562. &indexes->rxHiCleared, budget);
  1563. }
  1564. if(indexes->rxLoCleared != indexes->rxLoReady) {
  1565. work_done += typhoon_rx(tp, &tp->rxLoRing, &indexes->rxLoReady,
  1566. &indexes->rxLoCleared, budget - work_done);
  1567. }
  1568. if(le32_to_cpu(indexes->rxBuffCleared) == tp->rxBuffRing.lastWrite) {
  1569. /* rxBuff ring is empty, try to fill it. */
  1570. typhoon_fill_free_ring(tp);
  1571. }
  1572. if (work_done < budget) {
  1573. napi_complete(napi);
  1574. iowrite32(TYPHOON_INTR_NONE,
  1575. tp->ioaddr + TYPHOON_REG_INTR_MASK);
  1576. typhoon_post_pci_writes(tp->ioaddr);
  1577. }
  1578. return work_done;
  1579. }
  1580. static irqreturn_t
  1581. typhoon_interrupt(int irq, void *dev_instance)
  1582. {
  1583. struct net_device *dev = dev_instance;
  1584. struct typhoon *tp = netdev_priv(dev);
  1585. void __iomem *ioaddr = tp->ioaddr;
  1586. u32 intr_status;
  1587. intr_status = ioread32(ioaddr + TYPHOON_REG_INTR_STATUS);
  1588. if(!(intr_status & TYPHOON_INTR_HOST_INT))
  1589. return IRQ_NONE;
  1590. iowrite32(intr_status, ioaddr + TYPHOON_REG_INTR_STATUS);
  1591. if (napi_schedule_prep(&tp->napi)) {
  1592. iowrite32(TYPHOON_INTR_ALL, ioaddr + TYPHOON_REG_INTR_MASK);
  1593. typhoon_post_pci_writes(ioaddr);
  1594. __napi_schedule(&tp->napi);
  1595. } else {
  1596. printk(KERN_ERR "%s: Error, poll already scheduled\n",
  1597. dev->name);
  1598. }
  1599. return IRQ_HANDLED;
  1600. }
  1601. static void
  1602. typhoon_free_rx_rings(struct typhoon *tp)
  1603. {
  1604. u32 i;
  1605. for(i = 0; i < RXENT_ENTRIES; i++) {
  1606. struct rxbuff_ent *rxb = &tp->rxbuffers[i];
  1607. if(rxb->skb) {
  1608. pci_unmap_single(tp->pdev, rxb->dma_addr, PKT_BUF_SZ,
  1609. PCI_DMA_FROMDEVICE);
  1610. dev_kfree_skb(rxb->skb);
  1611. rxb->skb = NULL;
  1612. }
  1613. }
  1614. }
  1615. static int
  1616. typhoon_sleep(struct typhoon *tp, pci_power_t state, __le16 events)
  1617. {
  1618. struct pci_dev *pdev = tp->pdev;
  1619. void __iomem *ioaddr = tp->ioaddr;
  1620. struct cmd_desc xp_cmd;
  1621. int err;
  1622. INIT_COMMAND_WITH_RESPONSE(&xp_cmd, TYPHOON_CMD_ENABLE_WAKE_EVENTS);
  1623. xp_cmd.parm1 = events;
  1624. err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
  1625. if(err < 0) {
  1626. printk(KERN_ERR "%s: typhoon_sleep(): wake events cmd err %d\n",
  1627. tp->name, err);
  1628. return err;
  1629. }
  1630. INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_GOTO_SLEEP);
  1631. err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
  1632. if(err < 0) {
  1633. printk(KERN_ERR "%s: typhoon_sleep(): sleep cmd err %d\n",
  1634. tp->name, err);
  1635. return err;
  1636. }
  1637. if(typhoon_wait_status(ioaddr, TYPHOON_STATUS_SLEEPING) < 0)
  1638. return -ETIMEDOUT;
  1639. /* Since we cannot monitor the status of the link while sleeping,
  1640. * tell the world it went away.
  1641. */
  1642. netif_carrier_off(tp->dev);
  1643. pci_enable_wake(tp->pdev, state, 1);
  1644. pci_disable_device(pdev);
  1645. return pci_set_power_state(pdev, state);
  1646. }
  1647. static int
  1648. typhoon_wakeup(struct typhoon *tp, int wait_type)
  1649. {
  1650. struct pci_dev *pdev = tp->pdev;
  1651. void __iomem *ioaddr = tp->ioaddr;
  1652. pci_set_power_state(pdev, PCI_D0);
  1653. pci_restore_state(pdev);
  1654. /* Post 2.x.x versions of the Sleep Image require a reset before
  1655. * we can download the Runtime Image. But let's not make users of
  1656. * the old firmware pay for the reset.
  1657. */
  1658. iowrite32(TYPHOON_BOOTCMD_WAKEUP, ioaddr + TYPHOON_REG_COMMAND);
  1659. if(typhoon_wait_status(ioaddr, TYPHOON_STATUS_WAITING_FOR_HOST) < 0 ||
  1660. (tp->capabilities & TYPHOON_WAKEUP_NEEDS_RESET))
  1661. return typhoon_reset(ioaddr, wait_type);
  1662. return 0;
  1663. }
  1664. static int
  1665. typhoon_start_runtime(struct typhoon *tp)
  1666. {
  1667. struct net_device *dev = tp->dev;
  1668. void __iomem *ioaddr = tp->ioaddr;
  1669. struct cmd_desc xp_cmd;
  1670. int err;
  1671. typhoon_init_rings(tp);
  1672. typhoon_fill_free_ring(tp);
  1673. err = typhoon_download_firmware(tp);
  1674. if(err < 0) {
  1675. printk("%s: cannot load runtime on 3XP\n", tp->name);
  1676. goto error_out;
  1677. }
  1678. if(typhoon_boot_3XP(tp, TYPHOON_STATUS_WAITING_FOR_BOOT) < 0) {
  1679. printk("%s: cannot boot 3XP\n", tp->name);
  1680. err = -EIO;
  1681. goto error_out;
  1682. }
  1683. INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_SET_MAX_PKT_SIZE);
  1684. xp_cmd.parm1 = cpu_to_le16(PKT_BUF_SZ);
  1685. err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
  1686. if(err < 0)
  1687. goto error_out;
  1688. INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_SET_MAC_ADDRESS);
  1689. xp_cmd.parm1 = cpu_to_le16(ntohs(*(__be16 *)&dev->dev_addr[0]));
  1690. xp_cmd.parm2 = cpu_to_le32(ntohl(*(__be32 *)&dev->dev_addr[2]));
  1691. err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
  1692. if(err < 0)
  1693. goto error_out;
  1694. /* Disable IRQ coalescing -- we can reenable it when 3Com gives
  1695. * us some more information on how to control it.
  1696. */
  1697. INIT_COMMAND_WITH_RESPONSE(&xp_cmd, TYPHOON_CMD_IRQ_COALESCE_CTRL);
  1698. xp_cmd.parm1 = 0;
  1699. err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
  1700. if(err < 0)
  1701. goto error_out;
  1702. INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_XCVR_SELECT);
  1703. xp_cmd.parm1 = tp->xcvr_select;
  1704. err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
  1705. if(err < 0)
  1706. goto error_out;
  1707. INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_VLAN_TYPE_WRITE);
  1708. xp_cmd.parm1 = cpu_to_le16(ETH_P_8021Q);
  1709. err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
  1710. if(err < 0)
  1711. goto error_out;
  1712. INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_SET_OFFLOAD_TASKS);
  1713. spin_lock_bh(&tp->state_lock);
  1714. xp_cmd.parm2 = tp->offload;
  1715. xp_cmd.parm3 = tp->offload;
  1716. err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
  1717. spin_unlock_bh(&tp->state_lock);
  1718. if(err < 0)
  1719. goto error_out;
  1720. typhoon_set_rx_mode(dev);
  1721. INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_TX_ENABLE);
  1722. err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
  1723. if(err < 0)
  1724. goto error_out;
  1725. INIT_COMMAND_WITH_RESPONSE(&xp_cmd, TYPHOON_CMD_RX_ENABLE);
  1726. err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
  1727. if(err < 0)
  1728. goto error_out;
  1729. tp->card_state = Running;
  1730. smp_wmb();
  1731. iowrite32(TYPHOON_INTR_ENABLE_ALL, ioaddr + TYPHOON_REG_INTR_ENABLE);
  1732. iowrite32(TYPHOON_INTR_NONE, ioaddr + TYPHOON_REG_INTR_MASK);
  1733. typhoon_post_pci_writes(ioaddr);
  1734. return 0;
  1735. error_out:
  1736. typhoon_reset(ioaddr, WaitNoSleep);
  1737. typhoon_free_rx_rings(tp);
  1738. typhoon_init_rings(tp);
  1739. return err;
  1740. }
  1741. static int
  1742. typhoon_stop_runtime(struct typhoon *tp, int wait_type)
  1743. {
  1744. struct typhoon_indexes *indexes = tp->indexes;
  1745. struct transmit_ring *txLo = &tp->txLoRing;
  1746. void __iomem *ioaddr = tp->ioaddr;
  1747. struct cmd_desc xp_cmd;
  1748. int i;
  1749. /* Disable interrupts early, since we can't schedule a poll
  1750. * when called with !netif_running(). This will be posted
  1751. * when we force the posting of the command.
  1752. */
  1753. iowrite32(TYPHOON_INTR_NONE, ioaddr + TYPHOON_REG_INTR_ENABLE);
  1754. INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_RX_DISABLE);
  1755. typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
  1756. /* Wait 1/2 sec for any outstanding transmits to occur
  1757. * We'll cleanup after the reset if this times out.
  1758. */
  1759. for(i = 0; i < TYPHOON_WAIT_TIMEOUT; i++) {
  1760. if(indexes->txLoCleared == cpu_to_le32(txLo->lastWrite))
  1761. break;
  1762. udelay(TYPHOON_UDELAY);
  1763. }
  1764. if(i == TYPHOON_WAIT_TIMEOUT)
  1765. printk(KERN_ERR
  1766. "%s: halt timed out waiting for Tx to complete\n",
  1767. tp->name);
  1768. INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_TX_DISABLE);
  1769. typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
  1770. /* save the statistics so when we bring the interface up again,
  1771. * the values reported to userspace are correct.
  1772. */
  1773. tp->card_state = Sleeping;
  1774. smp_wmb();
  1775. typhoon_do_get_stats(tp);
  1776. memcpy(&tp->stats_saved, &tp->stats, sizeof(struct net_device_stats));
  1777. INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_HALT);
  1778. typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
  1779. if(typhoon_wait_status(ioaddr, TYPHOON_STATUS_HALTED) < 0)
  1780. printk(KERN_ERR "%s: timed out waiting for 3XP to halt\n",
  1781. tp->name);
  1782. if(typhoon_reset(ioaddr, wait_type) < 0) {
  1783. printk(KERN_ERR "%s: unable to reset 3XP\n", tp->name);
  1784. return -ETIMEDOUT;
  1785. }
  1786. /* cleanup any outstanding Tx packets */
  1787. if(indexes->txLoCleared != cpu_to_le32(txLo->lastWrite)) {
  1788. indexes->txLoCleared = cpu_to_le32(txLo->lastWrite);
  1789. typhoon_clean_tx(tp, &tp->txLoRing, &indexes->txLoCleared);
  1790. }
  1791. return 0;
  1792. }
  1793. static void
  1794. typhoon_tx_timeout(struct net_device *dev)
  1795. {
  1796. struct typhoon *tp = netdev_priv(dev);
  1797. if(typhoon_reset(tp->ioaddr, WaitNoSleep) < 0) {
  1798. printk(KERN_WARNING "%s: could not reset in tx timeout\n",
  1799. dev->name);
  1800. goto truely_dead;
  1801. }
  1802. /* If we ever start using the Hi ring, it will need cleaning too */
  1803. typhoon_clean_tx(tp, &tp->txLoRing, &tp->indexes->txLoCleared);
  1804. typhoon_free_rx_rings(tp);
  1805. if(typhoon_start_runtime(tp) < 0) {
  1806. printk(KERN_ERR "%s: could not start runtime in tx timeout\n",
  1807. dev->name);
  1808. goto truely_dead;
  1809. }
  1810. netif_wake_queue(dev);
  1811. return;
  1812. truely_dead:
  1813. /* Reset the hardware, and turn off carrier to avoid more timeouts */
  1814. typhoon_reset(tp->ioaddr, NoWait);
  1815. netif_carrier_off(dev);
  1816. }
  1817. static int
  1818. typhoon_open(struct net_device *dev)
  1819. {
  1820. struct typhoon *tp = netdev_priv(dev);
  1821. int err;
  1822. err = typhoon_request_firmware(tp);
  1823. if (err)
  1824. goto out;
  1825. err = typhoon_wakeup(tp, WaitSleep);
  1826. if(err < 0) {
  1827. printk(KERN_ERR "%s: unable to wakeup device\n", dev->name);
  1828. goto out_sleep;
  1829. }
  1830. err = request_irq(dev->irq, &typhoon_interrupt, IRQF_SHARED,
  1831. dev->name, dev);
  1832. if(err < 0)
  1833. goto out_sleep;
  1834. napi_enable(&tp->napi);
  1835. err = typhoon_start_runtime(tp);
  1836. if(err < 0) {
  1837. napi_disable(&tp->napi);
  1838. goto out_irq;
  1839. }
  1840. netif_start_queue(dev);
  1841. return 0;
  1842. out_irq:
  1843. free_irq(dev->irq, dev);
  1844. out_sleep:
  1845. if(typhoon_boot_3XP(tp, TYPHOON_STATUS_WAITING_FOR_HOST) < 0) {
  1846. printk(KERN_ERR "%s: unable to reboot into sleep img\n",
  1847. dev->name);
  1848. typhoon_reset(tp->ioaddr, NoWait);
  1849. goto out;
  1850. }
  1851. if(typhoon_sleep(tp, PCI_D3hot, 0) < 0)
  1852. printk(KERN_ERR "%s: unable to go back to sleep\n", dev->name);
  1853. out:
  1854. return err;
  1855. }
  1856. static int
  1857. typhoon_close(struct net_device *dev)
  1858. {
  1859. struct typhoon *tp = netdev_priv(dev);
  1860. netif_stop_queue(dev);
  1861. napi_disable(&tp->napi);
  1862. if(typhoon_stop_runtime(tp, WaitSleep) < 0)
  1863. printk(KERN_ERR "%s: unable to stop runtime\n", dev->name);
  1864. /* Make sure there is no irq handler running on a different CPU. */
  1865. free_irq(dev->irq, dev);
  1866. typhoon_free_rx_rings(tp);
  1867. typhoon_init_rings(tp);
  1868. if(typhoon_boot_3XP(tp, TYPHOON_STATUS_WAITING_FOR_HOST) < 0)
  1869. printk(KERN_ERR "%s: unable to boot sleep image\n", dev->name);
  1870. if(typhoon_sleep(tp, PCI_D3hot, 0) < 0)
  1871. printk(KERN_ERR "%s: unable to put card to sleep\n", dev->name);
  1872. return 0;
  1873. }
  1874. #ifdef CONFIG_PM
  1875. static int
  1876. typhoon_resume(struct pci_dev *pdev)
  1877. {
  1878. struct net_device *dev = pci_get_drvdata(pdev);
  1879. struct typhoon *tp = netdev_priv(dev);
  1880. /* If we're down, resume when we are upped.
  1881. */
  1882. if(!netif_running(dev))
  1883. return 0;
  1884. if(typhoon_wakeup(tp, WaitNoSleep) < 0) {
  1885. printk(KERN_ERR "%s: critical: could not wake up in resume\n",
  1886. dev->name);
  1887. goto reset;
  1888. }
  1889. if(typhoon_start_runtime(tp) < 0) {
  1890. printk(KERN_ERR "%s: critical: could not start runtime in "
  1891. "resume\n", dev->name);
  1892. goto reset;
  1893. }
  1894. netif_device_attach(dev);
  1895. return 0;
  1896. reset:
  1897. typhoon_reset(tp->ioaddr, NoWait);
  1898. return -EBUSY;
  1899. }
  1900. static int
  1901. typhoon_suspend(struct pci_dev *pdev, pm_message_t state)
  1902. {
  1903. struct net_device *dev = pci_get_drvdata(pdev);
  1904. struct typhoon *tp = netdev_priv(dev);
  1905. struct cmd_desc xp_cmd;
  1906. /* If we're down, we're already suspended.
  1907. */
  1908. if(!netif_running(dev))
  1909. return 0;
  1910. spin_lock_bh(&tp->state_lock);
  1911. if(tp->vlgrp && tp->wol_events & TYPHOON_WAKE_MAGIC_PKT) {
  1912. spin_unlock_bh(&tp->state_lock);
  1913. printk(KERN_ERR "%s: cannot do WAKE_MAGIC with VLANS\n",
  1914. dev->name);
  1915. return -EBUSY;
  1916. }
  1917. spin_unlock_bh(&tp->state_lock);
  1918. netif_device_detach(dev);
  1919. if(typhoon_stop_runtime(tp, WaitNoSleep) < 0) {
  1920. printk(KERN_ERR "%s: unable to stop runtime\n", dev->name);
  1921. goto need_resume;
  1922. }
  1923. typhoon_free_rx_rings(tp);
  1924. typhoon_init_rings(tp);
  1925. if(typhoon_boot_3XP(tp, TYPHOON_STATUS_WAITING_FOR_HOST) < 0) {
  1926. printk(KERN_ERR "%s: unable to boot sleep image\n", dev->name);
  1927. goto need_resume;
  1928. }
  1929. INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_SET_MAC_ADDRESS);
  1930. xp_cmd.parm1 = cpu_to_le16(ntohs(*(__be16 *)&dev->dev_addr[0]));
  1931. xp_cmd.parm2 = cpu_to_le32(ntohl(*(__be32 *)&dev->dev_addr[2]));
  1932. if(typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL) < 0) {
  1933. printk(KERN_ERR "%s: unable to set mac address in suspend\n",
  1934. dev->name);
  1935. goto need_resume;
  1936. }
  1937. INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_SET_RX_FILTER);
  1938. xp_cmd.parm1 = TYPHOON_RX_FILTER_DIRECTED | TYPHOON_RX_FILTER_BROADCAST;
  1939. if(typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL) < 0) {
  1940. printk(KERN_ERR "%s: unable to set rx filter in suspend\n",
  1941. dev->name);
  1942. goto need_resume;
  1943. }
  1944. if(typhoon_sleep(tp, pci_choose_state(pdev, state), tp->wol_events) < 0) {
  1945. printk(KERN_ERR "%s: unable to put card to sleep\n", dev->name);
  1946. goto need_resume;
  1947. }
  1948. return 0;
  1949. need_resume:
  1950. typhoon_resume(pdev);
  1951. return -EBUSY;
  1952. }
  1953. #endif
  1954. static int __devinit
  1955. typhoon_test_mmio(struct pci_dev *pdev)
  1956. {
  1957. void __iomem *ioaddr = pci_iomap(pdev, 1, 128);
  1958. int mode = 0;
  1959. u32 val;
  1960. if(!ioaddr)
  1961. goto out;
  1962. if(ioread32(ioaddr + TYPHOON_REG_STATUS) !=
  1963. TYPHOON_STATUS_WAITING_FOR_HOST)
  1964. goto out_unmap;
  1965. iowrite32(TYPHOON_INTR_ALL, ioaddr + TYPHOON_REG_INTR_MASK);
  1966. iowrite32(TYPHOON_INTR_ALL, ioaddr + TYPHOON_REG_INTR_STATUS);
  1967. iowrite32(TYPHOON_INTR_ALL, ioaddr + TYPHOON_REG_INTR_ENABLE);
  1968. /* Ok, see if we can change our interrupt status register by
  1969. * sending ourselves an interrupt. If so, then MMIO works.
  1970. * The 50usec delay is arbitrary -- it could probably be smaller.
  1971. */
  1972. val = ioread32(ioaddr + TYPHOON_REG_INTR_STATUS);
  1973. if((val & TYPHOON_INTR_SELF) == 0) {
  1974. iowrite32(1, ioaddr + TYPHOON_REG_SELF_INTERRUPT);
  1975. ioread32(ioaddr + TYPHOON_REG_INTR_STATUS);
  1976. udelay(50);
  1977. val = ioread32(ioaddr + TYPHOON_REG_INTR_STATUS);
  1978. if(val & TYPHOON_INTR_SELF)
  1979. mode = 1;
  1980. }
  1981. iowrite32(TYPHOON_INTR_ALL, ioaddr + TYPHOON_REG_INTR_MASK);
  1982. iowrite32(TYPHOON_INTR_ALL, ioaddr + TYPHOON_REG_INTR_STATUS);
  1983. iowrite32(TYPHOON_INTR_NONE, ioaddr + TYPHOON_REG_INTR_ENABLE);
  1984. ioread32(ioaddr + TYPHOON_REG_INTR_STATUS);
  1985. out_unmap:
  1986. pci_iounmap(pdev, ioaddr);
  1987. out:
  1988. if(!mode)
  1989. printk(KERN_INFO PFX "falling back to port IO\n");
  1990. return mode;
  1991. }
  1992. static const struct net_device_ops typhoon_netdev_ops = {
  1993. .ndo_open = typhoon_open,
  1994. .ndo_stop = typhoon_close,
  1995. .ndo_start_xmit = typhoon_start_tx,
  1996. .ndo_set_multicast_list = typhoon_set_rx_mode,
  1997. .ndo_tx_timeout = typhoon_tx_timeout,
  1998. .ndo_get_stats = typhoon_get_stats,
  1999. .ndo_validate_addr = eth_validate_addr,
  2000. .ndo_set_mac_address = typhoon_set_mac_address,
  2001. .ndo_change_mtu = eth_change_mtu,
  2002. .ndo_vlan_rx_register = typhoon_vlan_rx_register,
  2003. };
  2004. static int __devinit
  2005. typhoon_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  2006. {
  2007. static int did_version = 0;
  2008. struct net_device *dev;
  2009. struct typhoon *tp;
  2010. int card_id = (int) ent->driver_data;
  2011. void __iomem *ioaddr;
  2012. void *shared;
  2013. dma_addr_t shared_dma;
  2014. struct cmd_desc xp_cmd;
  2015. struct resp_desc xp_resp[3];
  2016. int err = 0;
  2017. if(!did_version++)
  2018. printk(KERN_INFO "%s", version);
  2019. dev = alloc_etherdev(sizeof(*tp));
  2020. if(dev == NULL) {
  2021. printk(ERR_PFX "%s: unable to alloc new net device\n",
  2022. pci_name(pdev));
  2023. err = -ENOMEM;
  2024. goto error_out;
  2025. }
  2026. SET_NETDEV_DEV(dev, &pdev->dev);
  2027. err = pci_enable_device(pdev);
  2028. if(err < 0) {
  2029. printk(ERR_PFX "%s: unable to enable device\n",
  2030. pci_name(pdev));
  2031. goto error_out_dev;
  2032. }
  2033. err = pci_set_mwi(pdev);
  2034. if(err < 0) {
  2035. printk(ERR_PFX "%s: unable to set MWI\n", pci_name(pdev));
  2036. goto error_out_disable;
  2037. }
  2038. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  2039. if(err < 0) {
  2040. printk(ERR_PFX "%s: No usable DMA configuration\n",
  2041. pci_name(pdev));
  2042. goto error_out_mwi;
  2043. }
  2044. /* sanity checks on IO and MMIO BARs
  2045. */
  2046. if(!(pci_resource_flags(pdev, 0) & IORESOURCE_IO)) {
  2047. printk(ERR_PFX
  2048. "%s: region #1 not a PCI IO resource, aborting\n",
  2049. pci_name(pdev));
  2050. err = -ENODEV;
  2051. goto error_out_mwi;
  2052. }
  2053. if(pci_resource_len(pdev, 0) < 128) {
  2054. printk(ERR_PFX "%s: Invalid PCI IO region size, aborting\n",
  2055. pci_name(pdev));
  2056. err = -ENODEV;
  2057. goto error_out_mwi;
  2058. }
  2059. if(!(pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
  2060. printk(ERR_PFX
  2061. "%s: region #1 not a PCI MMIO resource, aborting\n",
  2062. pci_name(pdev));
  2063. err = -ENODEV;
  2064. goto error_out_mwi;
  2065. }
  2066. if(pci_resource_len(pdev, 1) < 128) {
  2067. printk(ERR_PFX "%s: Invalid PCI MMIO region size, aborting\n",
  2068. pci_name(pdev));
  2069. err = -ENODEV;
  2070. goto error_out_mwi;
  2071. }
  2072. err = pci_request_regions(pdev, "typhoon");
  2073. if(err < 0) {
  2074. printk(ERR_PFX "%s: could not request regions\n",
  2075. pci_name(pdev));
  2076. goto error_out_mwi;
  2077. }
  2078. /* map our registers
  2079. */
  2080. if(use_mmio != 0 && use_mmio != 1)
  2081. use_mmio = typhoon_test_mmio(pdev);
  2082. ioaddr = pci_iomap(pdev, use_mmio, 128);
  2083. if (!ioaddr) {
  2084. printk(ERR_PFX "%s: cannot remap registers, aborting\n",
  2085. pci_name(pdev));
  2086. err = -EIO;
  2087. goto error_out_regions;
  2088. }
  2089. /* allocate pci dma space for rx and tx descriptor rings
  2090. */
  2091. shared = pci_alloc_consistent(pdev, sizeof(struct typhoon_shared),
  2092. &shared_dma);
  2093. if(!shared) {
  2094. printk(ERR_PFX "%s: could not allocate DMA memory\n",
  2095. pci_name(pdev));
  2096. err = -ENOMEM;
  2097. goto error_out_remap;
  2098. }
  2099. dev->irq = pdev->irq;
  2100. tp = netdev_priv(dev);
  2101. tp->shared = (struct typhoon_shared *) shared;
  2102. tp->shared_dma = shared_dma;
  2103. tp->pdev = pdev;
  2104. tp->tx_pdev = pdev;
  2105. tp->ioaddr = ioaddr;
  2106. tp->tx_ioaddr = ioaddr;
  2107. tp->dev = dev;
  2108. /* Init sequence:
  2109. * 1) Reset the adapter to clear any bad juju
  2110. * 2) Reload the sleep image
  2111. * 3) Boot the sleep image
  2112. * 4) Get the hardware address.
  2113. * 5) Put the card to sleep.
  2114. */
  2115. if (typhoon_reset(ioaddr, WaitSleep) < 0) {
  2116. printk(ERR_PFX "%s: could not reset 3XP\n", pci_name(pdev));
  2117. err = -EIO;
  2118. goto error_out_dma;
  2119. }
  2120. /* Now that we've reset the 3XP and are sure it's not going to
  2121. * write all over memory, enable bus mastering, and save our
  2122. * state for resuming after a suspend.
  2123. */
  2124. pci_set_master(pdev);
  2125. pci_save_state(pdev);
  2126. /* dev->name is not valid until we register, but we need to
  2127. * use some common routines to initialize the card. So that those
  2128. * routines print the right name, we keep our oun pointer to the name
  2129. */
  2130. tp->name = pci_name(pdev);
  2131. typhoon_init_interface(tp);
  2132. typhoon_init_rings(tp);
  2133. if(typhoon_boot_3XP(tp, TYPHOON_STATUS_WAITING_FOR_HOST) < 0) {
  2134. printk(ERR_PFX "%s: cannot boot 3XP sleep image\n",
  2135. pci_name(pdev));
  2136. err = -EIO;
  2137. goto error_out_reset;
  2138. }
  2139. INIT_COMMAND_WITH_RESPONSE(&xp_cmd, TYPHOON_CMD_READ_MAC_ADDRESS);
  2140. if(typhoon_issue_command(tp, 1, &xp_cmd, 1, xp_resp) < 0) {
  2141. printk(ERR_PFX "%s: cannot read MAC address\n",
  2142. pci_name(pdev));
  2143. err = -EIO;
  2144. goto error_out_reset;
  2145. }
  2146. *(__be16 *)&dev->dev_addr[0] = htons(le16_to_cpu(xp_resp[0].parm1));
  2147. *(__be32 *)&dev->dev_addr[2] = htonl(le32_to_cpu(xp_resp[0].parm2));
  2148. if(!is_valid_ether_addr(dev->dev_addr)) {
  2149. printk(ERR_PFX "%s: Could not obtain valid ethernet address, "
  2150. "aborting\n", pci_name(pdev));
  2151. goto error_out_reset;
  2152. }
  2153. /* Read the Sleep Image version last, so the response is valid
  2154. * later when we print out the version reported.
  2155. */
  2156. INIT_COMMAND_WITH_RESPONSE(&xp_cmd, TYPHOON_CMD_READ_VERSIONS);
  2157. if(typhoon_issue_command(tp, 1, &xp_cmd, 3, xp_resp) < 0) {
  2158. printk(ERR_PFX "%s: Could not get Sleep Image version\n",
  2159. pci_name(pdev));
  2160. goto error_out_reset;
  2161. }
  2162. tp->capabilities = typhoon_card_info[card_id].capabilities;
  2163. tp->xcvr_select = TYPHOON_XCVR_AUTONEG;
  2164. /* Typhoon 1.0 Sleep Images return one response descriptor to the
  2165. * READ_VERSIONS command. Those versions are OK after waking up
  2166. * from sleep without needing a reset. Typhoon 1.1+ Sleep Images
  2167. * seem to need a little extra help to get started. Since we don't
  2168. * know how to nudge it along, just kick it.
  2169. */
  2170. if(xp_resp[0].numDesc != 0)
  2171. tp->capabilities |= TYPHOON_WAKEUP_NEEDS_RESET;
  2172. if(typhoon_sleep(tp, PCI_D3hot, 0) < 0) {
  2173. printk(ERR_PFX "%s: cannot put adapter to sleep\n",
  2174. pci_name(pdev));
  2175. err = -EIO;
  2176. goto error_out_reset;
  2177. }
  2178. /* The chip-specific entries in the device structure. */
  2179. dev->netdev_ops = &typhoon_netdev_ops;
  2180. netif_napi_add(dev, &tp->napi, typhoon_poll, 16);
  2181. dev->watchdog_timeo = TX_TIMEOUT;
  2182. SET_ETHTOOL_OPS(dev, &typhoon_ethtool_ops);
  2183. /* We can handle scatter gather, up to 16 entries, and
  2184. * we can do IP checksumming (only version 4, doh...)
  2185. */
  2186. dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
  2187. dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  2188. dev->features |= NETIF_F_TSO;
  2189. if(register_netdev(dev) < 0)
  2190. goto error_out_reset;
  2191. /* fixup our local name */
  2192. tp->name = dev->name;
  2193. pci_set_drvdata(pdev, dev);
  2194. printk(KERN_INFO "%s: %s at %s 0x%llx, %pM\n",
  2195. dev->name, typhoon_card_info[card_id].name,
  2196. use_mmio ? "MMIO" : "IO",
  2197. (unsigned long long)pci_resource_start(pdev, use_mmio),
  2198. dev->dev_addr);
  2199. /* xp_resp still contains the response to the READ_VERSIONS command.
  2200. * For debugging, let the user know what version he has.
  2201. */
  2202. if(xp_resp[0].numDesc == 0) {
  2203. /* This is the Typhoon 1.0 type Sleep Image, last 16 bits
  2204. * of version is Month/Day of build.
  2205. */
  2206. u16 monthday = le32_to_cpu(xp_resp[0].parm2) & 0xffff;
  2207. printk(KERN_INFO "%s: Typhoon 1.0 Sleep Image built "
  2208. "%02u/%02u/2000\n", dev->name, monthday >> 8,
  2209. monthday & 0xff);
  2210. } else if(xp_resp[0].numDesc == 2) {
  2211. /* This is the Typhoon 1.1+ type Sleep Image
  2212. */
  2213. u32 sleep_ver = le32_to_cpu(xp_resp[0].parm2);
  2214. u8 *ver_string = (u8 *) &xp_resp[1];
  2215. ver_string[25] = 0;
  2216. printk(KERN_INFO "%s: Typhoon 1.1+ Sleep Image version "
  2217. "%02x.%03x.%03x %s\n", dev->name, sleep_ver >> 24,
  2218. (sleep_ver >> 12) & 0xfff, sleep_ver & 0xfff,
  2219. ver_string);
  2220. } else {
  2221. printk(KERN_WARNING "%s: Unknown Sleep Image version "
  2222. "(%u:%04x)\n", dev->name, xp_resp[0].numDesc,
  2223. le32_to_cpu(xp_resp[0].parm2));
  2224. }
  2225. return 0;
  2226. error_out_reset:
  2227. typhoon_reset(ioaddr, NoWait);
  2228. error_out_dma:
  2229. pci_free_consistent(pdev, sizeof(struct typhoon_shared),
  2230. shared, shared_dma);
  2231. error_out_remap:
  2232. pci_iounmap(pdev, ioaddr);
  2233. error_out_regions:
  2234. pci_release_regions(pdev);
  2235. error_out_mwi:
  2236. pci_clear_mwi(pdev);
  2237. error_out_disable:
  2238. pci_disable_device(pdev);
  2239. error_out_dev:
  2240. free_netdev(dev);
  2241. error_out:
  2242. return err;
  2243. }
  2244. static void __devexit
  2245. typhoon_remove_one(struct pci_dev *pdev)
  2246. {
  2247. struct net_device *dev = pci_get_drvdata(pdev);
  2248. struct typhoon *tp = netdev_priv(dev);
  2249. unregister_netdev(dev);
  2250. pci_set_power_state(pdev, PCI_D0);
  2251. pci_restore_state(pdev);
  2252. typhoon_reset(tp->ioaddr, NoWait);
  2253. pci_iounmap(pdev, tp->ioaddr);
  2254. pci_free_consistent(pdev, sizeof(struct typhoon_shared),
  2255. tp->shared, tp->shared_dma);
  2256. pci_release_regions(pdev);
  2257. pci_clear_mwi(pdev);
  2258. pci_disable_device(pdev);
  2259. pci_set_drvdata(pdev, NULL);
  2260. free_netdev(dev);
  2261. }
  2262. static struct pci_driver typhoon_driver = {
  2263. .name = DRV_MODULE_NAME,
  2264. .id_table = typhoon_pci_tbl,
  2265. .probe = typhoon_init_one,
  2266. .remove = __devexit_p(typhoon_remove_one),
  2267. #ifdef CONFIG_PM
  2268. .suspend = typhoon_suspend,
  2269. .resume = typhoon_resume,
  2270. #endif
  2271. };
  2272. static int __init
  2273. typhoon_init(void)
  2274. {
  2275. return pci_register_driver(&typhoon_driver);
  2276. }
  2277. static void __exit
  2278. typhoon_cleanup(void)
  2279. {
  2280. if (typhoon_fw)
  2281. release_firmware(typhoon_fw);
  2282. pci_unregister_driver(&typhoon_driver);
  2283. }
  2284. module_init(typhoon_init);
  2285. module_exit(typhoon_cleanup);