pcnet32.c 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760
  1. /* pcnet32.c: An AMD PCnet32 ethernet driver for linux. */
  2. /*
  3. * Copyright 1996-1999 Thomas Bogendoerfer
  4. *
  5. * Derived from the lance driver written 1993,1994,1995 by Donald Becker.
  6. *
  7. * Copyright 1993 United States Government as represented by the
  8. * Director, National Security Agency.
  9. *
  10. * This software may be used and distributed according to the terms
  11. * of the GNU General Public License, incorporated herein by reference.
  12. *
  13. * This driver is for PCnet32 and PCnetPCI based ethercards
  14. */
  15. /**************************************************************************
  16. * 23 Oct, 2000.
  17. * Fixed a few bugs, related to running the controller in 32bit mode.
  18. *
  19. * Carsten Langgaard, carstenl@mips.com
  20. * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
  21. *
  22. *************************************************************************/
  23. #define DRV_NAME "pcnet32"
  24. #define DRV_VERSION "1.32"
  25. #define DRV_RELDATE "18.Mar.2006"
  26. #define PFX DRV_NAME ": "
  27. static const char *const version =
  28. DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE " tsbogend@alpha.franken.de\n";
  29. #include <linux/module.h>
  30. #include <linux/kernel.h>
  31. #include <linux/string.h>
  32. #include <linux/errno.h>
  33. #include <linux/ioport.h>
  34. #include <linux/slab.h>
  35. #include <linux/interrupt.h>
  36. #include <linux/pci.h>
  37. #include <linux/delay.h>
  38. #include <linux/init.h>
  39. #include <linux/ethtool.h>
  40. #include <linux/mii.h>
  41. #include <linux/crc32.h>
  42. #include <linux/netdevice.h>
  43. #include <linux/etherdevice.h>
  44. #include <linux/skbuff.h>
  45. #include <linux/spinlock.h>
  46. #include <linux/moduleparam.h>
  47. #include <linux/bitops.h>
  48. #include <asm/dma.h>
  49. #include <asm/io.h>
  50. #include <asm/uaccess.h>
  51. #include <asm/irq.h>
  52. /*
  53. * PCI device identifiers for "new style" Linux PCI Device Drivers
  54. */
  55. static struct pci_device_id pcnet32_pci_tbl[] = {
  56. { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LANCE_HOME), },
  57. { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_LANCE), },
  58. /*
  59. * Adapters that were sold with IBM's RS/6000 or pSeries hardware have
  60. * the incorrect vendor id.
  61. */
  62. { PCI_DEVICE(PCI_VENDOR_ID_TRIDENT, PCI_DEVICE_ID_AMD_LANCE),
  63. .class = (PCI_CLASS_NETWORK_ETHERNET << 8), .class_mask = 0xffff00, },
  64. { } /* terminate list */
  65. };
  66. MODULE_DEVICE_TABLE(pci, pcnet32_pci_tbl);
  67. static int cards_found;
  68. /*
  69. * VLB I/O addresses
  70. */
  71. static unsigned int pcnet32_portlist[] __initdata =
  72. { 0x300, 0x320, 0x340, 0x360, 0 };
  73. static int pcnet32_debug = 0;
  74. static int tx_start = 1; /* Mapping -- 0:20, 1:64, 2:128, 3:~220 (depends on chip vers) */
  75. static int pcnet32vlb; /* check for VLB cards ? */
  76. static struct net_device *pcnet32_dev;
  77. static int max_interrupt_work = 2;
  78. static int rx_copybreak = 200;
  79. #define PCNET32_PORT_AUI 0x00
  80. #define PCNET32_PORT_10BT 0x01
  81. #define PCNET32_PORT_GPSI 0x02
  82. #define PCNET32_PORT_MII 0x03
  83. #define PCNET32_PORT_PORTSEL 0x03
  84. #define PCNET32_PORT_ASEL 0x04
  85. #define PCNET32_PORT_100 0x40
  86. #define PCNET32_PORT_FD 0x80
  87. #define PCNET32_DMA_MASK 0xffffffff
  88. #define PCNET32_WATCHDOG_TIMEOUT (jiffies + (2 * HZ))
  89. #define PCNET32_BLINK_TIMEOUT (jiffies + (HZ/4))
  90. /*
  91. * table to translate option values from tulip
  92. * to internal options
  93. */
  94. static const unsigned char options_mapping[] = {
  95. PCNET32_PORT_ASEL, /* 0 Auto-select */
  96. PCNET32_PORT_AUI, /* 1 BNC/AUI */
  97. PCNET32_PORT_AUI, /* 2 AUI/BNC */
  98. PCNET32_PORT_ASEL, /* 3 not supported */
  99. PCNET32_PORT_10BT | PCNET32_PORT_FD, /* 4 10baseT-FD */
  100. PCNET32_PORT_ASEL, /* 5 not supported */
  101. PCNET32_PORT_ASEL, /* 6 not supported */
  102. PCNET32_PORT_ASEL, /* 7 not supported */
  103. PCNET32_PORT_ASEL, /* 8 not supported */
  104. PCNET32_PORT_MII, /* 9 MII 10baseT */
  105. PCNET32_PORT_MII | PCNET32_PORT_FD, /* 10 MII 10baseT-FD */
  106. PCNET32_PORT_MII, /* 11 MII (autosel) */
  107. PCNET32_PORT_10BT, /* 12 10BaseT */
  108. PCNET32_PORT_MII | PCNET32_PORT_100, /* 13 MII 100BaseTx */
  109. /* 14 MII 100BaseTx-FD */
  110. PCNET32_PORT_MII | PCNET32_PORT_100 | PCNET32_PORT_FD,
  111. PCNET32_PORT_ASEL /* 15 not supported */
  112. };
  113. static const char pcnet32_gstrings_test[][ETH_GSTRING_LEN] = {
  114. "Loopback test (offline)"
  115. };
  116. #define PCNET32_TEST_LEN (sizeof(pcnet32_gstrings_test) / ETH_GSTRING_LEN)
  117. #define PCNET32_NUM_REGS 136
  118. #define MAX_UNITS 8 /* More are supported, limit only on options */
  119. static int options[MAX_UNITS];
  120. static int full_duplex[MAX_UNITS];
  121. static int homepna[MAX_UNITS];
  122. /*
  123. * Theory of Operation
  124. *
  125. * This driver uses the same software structure as the normal lance
  126. * driver. So look for a verbose description in lance.c. The differences
  127. * to the normal lance driver is the use of the 32bit mode of PCnet32
  128. * and PCnetPCI chips. Because these chips are 32bit chips, there is no
  129. * 16MB limitation and we don't need bounce buffers.
  130. */
  131. /*
  132. * Set the number of Tx and Rx buffers, using Log_2(# buffers).
  133. * Reasonable default values are 4 Tx buffers, and 16 Rx buffers.
  134. * That translates to 2 (4 == 2^^2) and 4 (16 == 2^^4).
  135. */
  136. #ifndef PCNET32_LOG_TX_BUFFERS
  137. #define PCNET32_LOG_TX_BUFFERS 4
  138. #define PCNET32_LOG_RX_BUFFERS 5
  139. #define PCNET32_LOG_MAX_TX_BUFFERS 9 /* 2^9 == 512 */
  140. #define PCNET32_LOG_MAX_RX_BUFFERS 9
  141. #endif
  142. #define TX_RING_SIZE (1 << (PCNET32_LOG_TX_BUFFERS))
  143. #define TX_MAX_RING_SIZE (1 << (PCNET32_LOG_MAX_TX_BUFFERS))
  144. #define RX_RING_SIZE (1 << (PCNET32_LOG_RX_BUFFERS))
  145. #define RX_MAX_RING_SIZE (1 << (PCNET32_LOG_MAX_RX_BUFFERS))
  146. #define PKT_BUF_SZ 1544
  147. /* Offsets from base I/O address. */
  148. #define PCNET32_WIO_RDP 0x10
  149. #define PCNET32_WIO_RAP 0x12
  150. #define PCNET32_WIO_RESET 0x14
  151. #define PCNET32_WIO_BDP 0x16
  152. #define PCNET32_DWIO_RDP 0x10
  153. #define PCNET32_DWIO_RAP 0x14
  154. #define PCNET32_DWIO_RESET 0x18
  155. #define PCNET32_DWIO_BDP 0x1C
  156. #define PCNET32_TOTAL_SIZE 0x20
  157. /* The PCNET32 Rx and Tx ring descriptors. */
  158. struct pcnet32_rx_head {
  159. u32 base;
  160. s16 buf_length;
  161. s16 status;
  162. u32 msg_length;
  163. u32 reserved;
  164. };
  165. struct pcnet32_tx_head {
  166. u32 base;
  167. s16 length;
  168. s16 status;
  169. u32 misc;
  170. u32 reserved;
  171. };
  172. /* The PCNET32 32-Bit initialization block, described in databook. */
  173. struct pcnet32_init_block {
  174. u16 mode;
  175. u16 tlen_rlen;
  176. u8 phys_addr[6];
  177. u16 reserved;
  178. u32 filter[2];
  179. /* Receive and transmit ring base, along with extra bits. */
  180. u32 rx_ring;
  181. u32 tx_ring;
  182. };
  183. /* PCnet32 access functions */
  184. struct pcnet32_access {
  185. u16 (*read_csr) (unsigned long, int);
  186. void (*write_csr) (unsigned long, int, u16);
  187. u16 (*read_bcr) (unsigned long, int);
  188. void (*write_bcr) (unsigned long, int, u16);
  189. u16 (*read_rap) (unsigned long);
  190. void (*write_rap) (unsigned long, u16);
  191. void (*reset) (unsigned long);
  192. };
  193. /*
  194. * The first field of pcnet32_private is read by the ethernet device
  195. * so the structure should be allocated using pci_alloc_consistent().
  196. */
  197. struct pcnet32_private {
  198. struct pcnet32_init_block init_block;
  199. /* The Tx and Rx ring entries must be aligned on 16-byte boundaries in 32bit mode. */
  200. struct pcnet32_rx_head *rx_ring;
  201. struct pcnet32_tx_head *tx_ring;
  202. dma_addr_t dma_addr;/* DMA address of beginning of this
  203. object, returned by pci_alloc_consistent */
  204. struct pci_dev *pci_dev;
  205. const char *name;
  206. /* The saved address of a sent-in-place packet/buffer, for skfree(). */
  207. struct sk_buff **tx_skbuff;
  208. struct sk_buff **rx_skbuff;
  209. dma_addr_t *tx_dma_addr;
  210. dma_addr_t *rx_dma_addr;
  211. struct pcnet32_access a;
  212. spinlock_t lock; /* Guard lock */
  213. unsigned int cur_rx, cur_tx; /* The next free ring entry */
  214. unsigned int rx_ring_size; /* current rx ring size */
  215. unsigned int tx_ring_size; /* current tx ring size */
  216. unsigned int rx_mod_mask; /* rx ring modular mask */
  217. unsigned int tx_mod_mask; /* tx ring modular mask */
  218. unsigned short rx_len_bits;
  219. unsigned short tx_len_bits;
  220. dma_addr_t rx_ring_dma_addr;
  221. dma_addr_t tx_ring_dma_addr;
  222. unsigned int dirty_rx, /* ring entries to be freed. */
  223. dirty_tx;
  224. struct net_device_stats stats;
  225. char tx_full;
  226. char phycount; /* number of phys found */
  227. int options;
  228. unsigned int shared_irq:1, /* shared irq possible */
  229. dxsuflo:1, /* disable transmit stop on uflo */
  230. mii:1; /* mii port available */
  231. struct net_device *next;
  232. struct mii_if_info mii_if;
  233. struct timer_list watchdog_timer;
  234. struct timer_list blink_timer;
  235. u32 msg_enable; /* debug message level */
  236. /* each bit indicates an available PHY */
  237. u32 phymask;
  238. };
  239. static int pcnet32_probe_pci(struct pci_dev *, const struct pci_device_id *);
  240. static int pcnet32_probe1(unsigned long, int, struct pci_dev *);
  241. static int pcnet32_open(struct net_device *);
  242. static int pcnet32_init_ring(struct net_device *);
  243. static int pcnet32_start_xmit(struct sk_buff *, struct net_device *);
  244. static int pcnet32_rx(struct net_device *);
  245. static void pcnet32_tx_timeout(struct net_device *dev);
  246. static irqreturn_t pcnet32_interrupt(int, void *, struct pt_regs *);
  247. static int pcnet32_close(struct net_device *);
  248. static struct net_device_stats *pcnet32_get_stats(struct net_device *);
  249. static void pcnet32_load_multicast(struct net_device *dev);
  250. static void pcnet32_set_multicast_list(struct net_device *);
  251. static int pcnet32_ioctl(struct net_device *, struct ifreq *, int);
  252. static void pcnet32_watchdog(struct net_device *);
  253. static int mdio_read(struct net_device *dev, int phy_id, int reg_num);
  254. static void mdio_write(struct net_device *dev, int phy_id, int reg_num,
  255. int val);
  256. static void pcnet32_restart(struct net_device *dev, unsigned int csr0_bits);
  257. static void pcnet32_ethtool_test(struct net_device *dev,
  258. struct ethtool_test *eth_test, u64 * data);
  259. static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1);
  260. static int pcnet32_phys_id(struct net_device *dev, u32 data);
  261. static void pcnet32_led_blink_callback(struct net_device *dev);
  262. static int pcnet32_get_regs_len(struct net_device *dev);
  263. static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs,
  264. void *ptr);
  265. static void pcnet32_purge_tx_ring(struct net_device *dev);
  266. static int pcnet32_alloc_ring(struct net_device *dev, char *name);
  267. static void pcnet32_free_ring(struct net_device *dev);
  268. static void pcnet32_check_media(struct net_device *dev, int verbose);
  269. static u16 pcnet32_wio_read_csr(unsigned long addr, int index)
  270. {
  271. outw(index, addr + PCNET32_WIO_RAP);
  272. return inw(addr + PCNET32_WIO_RDP);
  273. }
  274. static void pcnet32_wio_write_csr(unsigned long addr, int index, u16 val)
  275. {
  276. outw(index, addr + PCNET32_WIO_RAP);
  277. outw(val, addr + PCNET32_WIO_RDP);
  278. }
  279. static u16 pcnet32_wio_read_bcr(unsigned long addr, int index)
  280. {
  281. outw(index, addr + PCNET32_WIO_RAP);
  282. return inw(addr + PCNET32_WIO_BDP);
  283. }
  284. static void pcnet32_wio_write_bcr(unsigned long addr, int index, u16 val)
  285. {
  286. outw(index, addr + PCNET32_WIO_RAP);
  287. outw(val, addr + PCNET32_WIO_BDP);
  288. }
  289. static u16 pcnet32_wio_read_rap(unsigned long addr)
  290. {
  291. return inw(addr + PCNET32_WIO_RAP);
  292. }
  293. static void pcnet32_wio_write_rap(unsigned long addr, u16 val)
  294. {
  295. outw(val, addr + PCNET32_WIO_RAP);
  296. }
  297. static void pcnet32_wio_reset(unsigned long addr)
  298. {
  299. inw(addr + PCNET32_WIO_RESET);
  300. }
  301. static int pcnet32_wio_check(unsigned long addr)
  302. {
  303. outw(88, addr + PCNET32_WIO_RAP);
  304. return (inw(addr + PCNET32_WIO_RAP) == 88);
  305. }
  306. static struct pcnet32_access pcnet32_wio = {
  307. .read_csr = pcnet32_wio_read_csr,
  308. .write_csr = pcnet32_wio_write_csr,
  309. .read_bcr = pcnet32_wio_read_bcr,
  310. .write_bcr = pcnet32_wio_write_bcr,
  311. .read_rap = pcnet32_wio_read_rap,
  312. .write_rap = pcnet32_wio_write_rap,
  313. .reset = pcnet32_wio_reset
  314. };
  315. static u16 pcnet32_dwio_read_csr(unsigned long addr, int index)
  316. {
  317. outl(index, addr + PCNET32_DWIO_RAP);
  318. return (inl(addr + PCNET32_DWIO_RDP) & 0xffff);
  319. }
  320. static void pcnet32_dwio_write_csr(unsigned long addr, int index, u16 val)
  321. {
  322. outl(index, addr + PCNET32_DWIO_RAP);
  323. outl(val, addr + PCNET32_DWIO_RDP);
  324. }
  325. static u16 pcnet32_dwio_read_bcr(unsigned long addr, int index)
  326. {
  327. outl(index, addr + PCNET32_DWIO_RAP);
  328. return (inl(addr + PCNET32_DWIO_BDP) & 0xffff);
  329. }
  330. static void pcnet32_dwio_write_bcr(unsigned long addr, int index, u16 val)
  331. {
  332. outl(index, addr + PCNET32_DWIO_RAP);
  333. outl(val, addr + PCNET32_DWIO_BDP);
  334. }
  335. static u16 pcnet32_dwio_read_rap(unsigned long addr)
  336. {
  337. return (inl(addr + PCNET32_DWIO_RAP) & 0xffff);
  338. }
  339. static void pcnet32_dwio_write_rap(unsigned long addr, u16 val)
  340. {
  341. outl(val, addr + PCNET32_DWIO_RAP);
  342. }
  343. static void pcnet32_dwio_reset(unsigned long addr)
  344. {
  345. inl(addr + PCNET32_DWIO_RESET);
  346. }
  347. static int pcnet32_dwio_check(unsigned long addr)
  348. {
  349. outl(88, addr + PCNET32_DWIO_RAP);
  350. return ((inl(addr + PCNET32_DWIO_RAP) & 0xffff) == 88);
  351. }
  352. static struct pcnet32_access pcnet32_dwio = {
  353. .read_csr = pcnet32_dwio_read_csr,
  354. .write_csr = pcnet32_dwio_write_csr,
  355. .read_bcr = pcnet32_dwio_read_bcr,
  356. .write_bcr = pcnet32_dwio_write_bcr,
  357. .read_rap = pcnet32_dwio_read_rap,
  358. .write_rap = pcnet32_dwio_write_rap,
  359. .reset = pcnet32_dwio_reset
  360. };
  361. #ifdef CONFIG_NET_POLL_CONTROLLER
  362. static void pcnet32_poll_controller(struct net_device *dev)
  363. {
  364. disable_irq(dev->irq);
  365. pcnet32_interrupt(0, dev, NULL);
  366. enable_irq(dev->irq);
  367. }
  368. #endif
  369. static int pcnet32_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  370. {
  371. struct pcnet32_private *lp = dev->priv;
  372. unsigned long flags;
  373. int r = -EOPNOTSUPP;
  374. if (lp->mii) {
  375. spin_lock_irqsave(&lp->lock, flags);
  376. mii_ethtool_gset(&lp->mii_if, cmd);
  377. spin_unlock_irqrestore(&lp->lock, flags);
  378. r = 0;
  379. }
  380. return r;
  381. }
  382. static int pcnet32_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  383. {
  384. struct pcnet32_private *lp = dev->priv;
  385. unsigned long flags;
  386. int r = -EOPNOTSUPP;
  387. if (lp->mii) {
  388. spin_lock_irqsave(&lp->lock, flags);
  389. r = mii_ethtool_sset(&lp->mii_if, cmd);
  390. spin_unlock_irqrestore(&lp->lock, flags);
  391. }
  392. return r;
  393. }
  394. static void pcnet32_get_drvinfo(struct net_device *dev,
  395. struct ethtool_drvinfo *info)
  396. {
  397. struct pcnet32_private *lp = dev->priv;
  398. strcpy(info->driver, DRV_NAME);
  399. strcpy(info->version, DRV_VERSION);
  400. if (lp->pci_dev)
  401. strcpy(info->bus_info, pci_name(lp->pci_dev));
  402. else
  403. sprintf(info->bus_info, "VLB 0x%lx", dev->base_addr);
  404. }
  405. static u32 pcnet32_get_link(struct net_device *dev)
  406. {
  407. struct pcnet32_private *lp = dev->priv;
  408. unsigned long flags;
  409. int r;
  410. spin_lock_irqsave(&lp->lock, flags);
  411. if (lp->mii) {
  412. r = mii_link_ok(&lp->mii_if);
  413. } else {
  414. ulong ioaddr = dev->base_addr; /* card base I/O address */
  415. r = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
  416. }
  417. spin_unlock_irqrestore(&lp->lock, flags);
  418. return r;
  419. }
  420. static u32 pcnet32_get_msglevel(struct net_device *dev)
  421. {
  422. struct pcnet32_private *lp = dev->priv;
  423. return lp->msg_enable;
  424. }
  425. static void pcnet32_set_msglevel(struct net_device *dev, u32 value)
  426. {
  427. struct pcnet32_private *lp = dev->priv;
  428. lp->msg_enable = value;
  429. }
  430. static int pcnet32_nway_reset(struct net_device *dev)
  431. {
  432. struct pcnet32_private *lp = dev->priv;
  433. unsigned long flags;
  434. int r = -EOPNOTSUPP;
  435. if (lp->mii) {
  436. spin_lock_irqsave(&lp->lock, flags);
  437. r = mii_nway_restart(&lp->mii_if);
  438. spin_unlock_irqrestore(&lp->lock, flags);
  439. }
  440. return r;
  441. }
  442. static void pcnet32_get_ringparam(struct net_device *dev,
  443. struct ethtool_ringparam *ering)
  444. {
  445. struct pcnet32_private *lp = dev->priv;
  446. ering->tx_max_pending = TX_MAX_RING_SIZE;
  447. ering->tx_pending = lp->tx_ring_size;
  448. ering->rx_max_pending = RX_MAX_RING_SIZE;
  449. ering->rx_pending = lp->rx_ring_size;
  450. }
  451. static int pcnet32_set_ringparam(struct net_device *dev,
  452. struct ethtool_ringparam *ering)
  453. {
  454. struct pcnet32_private *lp = dev->priv;
  455. unsigned long flags;
  456. int i;
  457. if (ering->rx_mini_pending || ering->rx_jumbo_pending)
  458. return -EINVAL;
  459. if (netif_running(dev))
  460. pcnet32_close(dev);
  461. spin_lock_irqsave(&lp->lock, flags);
  462. pcnet32_free_ring(dev);
  463. lp->tx_ring_size =
  464. min(ering->tx_pending, (unsigned int)TX_MAX_RING_SIZE);
  465. lp->rx_ring_size =
  466. min(ering->rx_pending, (unsigned int)RX_MAX_RING_SIZE);
  467. /* set the minimum ring size to 4, to allow the loopback test to work
  468. * unchanged.
  469. */
  470. for (i = 2; i <= PCNET32_LOG_MAX_TX_BUFFERS; i++) {
  471. if (lp->tx_ring_size <= (1 << i))
  472. break;
  473. }
  474. lp->tx_ring_size = (1 << i);
  475. lp->tx_mod_mask = lp->tx_ring_size - 1;
  476. lp->tx_len_bits = (i << 12);
  477. for (i = 2; i <= PCNET32_LOG_MAX_RX_BUFFERS; i++) {
  478. if (lp->rx_ring_size <= (1 << i))
  479. break;
  480. }
  481. lp->rx_ring_size = (1 << i);
  482. lp->rx_mod_mask = lp->rx_ring_size - 1;
  483. lp->rx_len_bits = (i << 4);
  484. if (pcnet32_alloc_ring(dev, dev->name)) {
  485. pcnet32_free_ring(dev);
  486. spin_unlock_irqrestore(&lp->lock, flags);
  487. return -ENOMEM;
  488. }
  489. spin_unlock_irqrestore(&lp->lock, flags);
  490. if (pcnet32_debug & NETIF_MSG_DRV)
  491. printk(KERN_INFO PFX
  492. "%s: Ring Param Settings: RX: %d, TX: %d\n", dev->name,
  493. lp->rx_ring_size, lp->tx_ring_size);
  494. if (netif_running(dev))
  495. pcnet32_open(dev);
  496. return 0;
  497. }
  498. static void pcnet32_get_strings(struct net_device *dev, u32 stringset,
  499. u8 * data)
  500. {
  501. memcpy(data, pcnet32_gstrings_test, sizeof(pcnet32_gstrings_test));
  502. }
  503. static int pcnet32_self_test_count(struct net_device *dev)
  504. {
  505. return PCNET32_TEST_LEN;
  506. }
  507. static void pcnet32_ethtool_test(struct net_device *dev,
  508. struct ethtool_test *test, u64 * data)
  509. {
  510. struct pcnet32_private *lp = dev->priv;
  511. int rc;
  512. if (test->flags == ETH_TEST_FL_OFFLINE) {
  513. rc = pcnet32_loopback_test(dev, data);
  514. if (rc) {
  515. if (netif_msg_hw(lp))
  516. printk(KERN_DEBUG "%s: Loopback test failed.\n",
  517. dev->name);
  518. test->flags |= ETH_TEST_FL_FAILED;
  519. } else if (netif_msg_hw(lp))
  520. printk(KERN_DEBUG "%s: Loopback test passed.\n",
  521. dev->name);
  522. } else if (netif_msg_hw(lp))
  523. printk(KERN_DEBUG
  524. "%s: No tests to run (specify 'Offline' on ethtool).",
  525. dev->name);
  526. } /* end pcnet32_ethtool_test */
  527. static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
  528. {
  529. struct pcnet32_private *lp = dev->priv;
  530. struct pcnet32_access *a = &lp->a; /* access to registers */
  531. ulong ioaddr = dev->base_addr; /* card base I/O address */
  532. struct sk_buff *skb; /* sk buff */
  533. int x, i; /* counters */
  534. int numbuffs = 4; /* number of TX/RX buffers and descs */
  535. u16 status = 0x8300; /* TX ring status */
  536. u16 teststatus; /* test of ring status */
  537. int rc; /* return code */
  538. int size; /* size of packets */
  539. unsigned char *packet; /* source packet data */
  540. static const int data_len = 60; /* length of source packets */
  541. unsigned long flags;
  542. unsigned long ticks;
  543. *data1 = 1; /* status of test, default to fail */
  544. rc = 1; /* default to fail */
  545. if (netif_running(dev))
  546. pcnet32_close(dev);
  547. spin_lock_irqsave(&lp->lock, flags);
  548. /* Reset the PCNET32 */
  549. lp->a.reset(ioaddr);
  550. /* switch pcnet32 to 32bit mode */
  551. lp->a.write_bcr(ioaddr, 20, 2);
  552. lp->init_block.mode =
  553. le16_to_cpu((lp->options & PCNET32_PORT_PORTSEL) << 7);
  554. lp->init_block.filter[0] = 0;
  555. lp->init_block.filter[1] = 0;
  556. /* purge & init rings but don't actually restart */
  557. pcnet32_restart(dev, 0x0000);
  558. lp->a.write_csr(ioaddr, 0, 0x0004); /* Set STOP bit */
  559. /* Initialize Transmit buffers. */
  560. size = data_len + 15;
  561. for (x = 0; x < numbuffs; x++) {
  562. if (!(skb = dev_alloc_skb(size))) {
  563. if (netif_msg_hw(lp))
  564. printk(KERN_DEBUG
  565. "%s: Cannot allocate skb at line: %d!\n",
  566. dev->name, __LINE__);
  567. goto clean_up;
  568. } else {
  569. packet = skb->data;
  570. skb_put(skb, size); /* create space for data */
  571. lp->tx_skbuff[x] = skb;
  572. lp->tx_ring[x].length = le16_to_cpu(-skb->len);
  573. lp->tx_ring[x].misc = 0;
  574. /* put DA and SA into the skb */
  575. for (i = 0; i < 6; i++)
  576. *packet++ = dev->dev_addr[i];
  577. for (i = 0; i < 6; i++)
  578. *packet++ = dev->dev_addr[i];
  579. /* type */
  580. *packet++ = 0x08;
  581. *packet++ = 0x06;
  582. /* packet number */
  583. *packet++ = x;
  584. /* fill packet with data */
  585. for (i = 0; i < data_len; i++)
  586. *packet++ = i;
  587. lp->tx_dma_addr[x] =
  588. pci_map_single(lp->pci_dev, skb->data, skb->len,
  589. PCI_DMA_TODEVICE);
  590. lp->tx_ring[x].base =
  591. (u32) le32_to_cpu(lp->tx_dma_addr[x]);
  592. wmb(); /* Make sure owner changes after all others are visible */
  593. lp->tx_ring[x].status = le16_to_cpu(status);
  594. }
  595. }
  596. x = a->read_bcr(ioaddr, 32); /* set internal loopback in BSR32 */
  597. x = x | 0x0002;
  598. a->write_bcr(ioaddr, 32, x);
  599. lp->a.write_csr(ioaddr, 15, 0x0044); /* set int loopback in CSR15 */
  600. teststatus = le16_to_cpu(0x8000);
  601. lp->a.write_csr(ioaddr, 0, 0x0002); /* Set STRT bit */
  602. /* Check status of descriptors */
  603. for (x = 0; x < numbuffs; x++) {
  604. ticks = 0;
  605. rmb();
  606. while ((lp->rx_ring[x].status & teststatus) && (ticks < 200)) {
  607. spin_unlock_irqrestore(&lp->lock, flags);
  608. mdelay(1);
  609. spin_lock_irqsave(&lp->lock, flags);
  610. rmb();
  611. ticks++;
  612. }
  613. if (ticks == 200) {
  614. if (netif_msg_hw(lp))
  615. printk("%s: Desc %d failed to reset!\n",
  616. dev->name, x);
  617. break;
  618. }
  619. }
  620. lp->a.write_csr(ioaddr, 0, 0x0004); /* Set STOP bit */
  621. wmb();
  622. if (netif_msg_hw(lp) && netif_msg_pktdata(lp)) {
  623. printk(KERN_DEBUG "%s: RX loopback packets:\n", dev->name);
  624. for (x = 0; x < numbuffs; x++) {
  625. printk(KERN_DEBUG "%s: Packet %d:\n", dev->name, x);
  626. skb = lp->rx_skbuff[x];
  627. for (i = 0; i < size; i++) {
  628. printk("%02x ", *(skb->data + i));
  629. }
  630. printk("\n");
  631. }
  632. }
  633. x = 0;
  634. rc = 0;
  635. while (x < numbuffs && !rc) {
  636. skb = lp->rx_skbuff[x];
  637. packet = lp->tx_skbuff[x]->data;
  638. for (i = 0; i < size; i++) {
  639. if (*(skb->data + i) != packet[i]) {
  640. if (netif_msg_hw(lp))
  641. printk(KERN_DEBUG
  642. "%s: Error in compare! %2x - %02x %02x\n",
  643. dev->name, i, *(skb->data + i),
  644. packet[i]);
  645. rc = 1;
  646. break;
  647. }
  648. }
  649. x++;
  650. }
  651. if (!rc) {
  652. *data1 = 0;
  653. }
  654. clean_up:
  655. pcnet32_purge_tx_ring(dev);
  656. x = a->read_csr(ioaddr, 15) & 0xFFFF;
  657. a->write_csr(ioaddr, 15, (x & ~0x0044)); /* reset bits 6 and 2 */
  658. x = a->read_bcr(ioaddr, 32); /* reset internal loopback */
  659. x = x & ~0x0002;
  660. a->write_bcr(ioaddr, 32, x);
  661. spin_unlock_irqrestore(&lp->lock, flags);
  662. if (netif_running(dev)) {
  663. pcnet32_open(dev);
  664. } else {
  665. lp->a.write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
  666. }
  667. return (rc);
  668. } /* end pcnet32_loopback_test */
  669. static void pcnet32_led_blink_callback(struct net_device *dev)
  670. {
  671. struct pcnet32_private *lp = dev->priv;
  672. struct pcnet32_access *a = &lp->a;
  673. ulong ioaddr = dev->base_addr;
  674. unsigned long flags;
  675. int i;
  676. spin_lock_irqsave(&lp->lock, flags);
  677. for (i = 4; i < 8; i++) {
  678. a->write_bcr(ioaddr, i, a->read_bcr(ioaddr, i) ^ 0x4000);
  679. }
  680. spin_unlock_irqrestore(&lp->lock, flags);
  681. mod_timer(&lp->blink_timer, PCNET32_BLINK_TIMEOUT);
  682. }
  683. static int pcnet32_phys_id(struct net_device *dev, u32 data)
  684. {
  685. struct pcnet32_private *lp = dev->priv;
  686. struct pcnet32_access *a = &lp->a;
  687. ulong ioaddr = dev->base_addr;
  688. unsigned long flags;
  689. int i, regs[4];
  690. if (!lp->blink_timer.function) {
  691. init_timer(&lp->blink_timer);
  692. lp->blink_timer.function = (void *)pcnet32_led_blink_callback;
  693. lp->blink_timer.data = (unsigned long)dev;
  694. }
  695. /* Save the current value of the bcrs */
  696. spin_lock_irqsave(&lp->lock, flags);
  697. for (i = 4; i < 8; i++) {
  698. regs[i - 4] = a->read_bcr(ioaddr, i);
  699. }
  700. spin_unlock_irqrestore(&lp->lock, flags);
  701. mod_timer(&lp->blink_timer, jiffies);
  702. set_current_state(TASK_INTERRUPTIBLE);
  703. if ((!data) || (data > (u32) (MAX_SCHEDULE_TIMEOUT / HZ)))
  704. data = (u32) (MAX_SCHEDULE_TIMEOUT / HZ);
  705. msleep_interruptible(data * 1000);
  706. del_timer_sync(&lp->blink_timer);
  707. /* Restore the original value of the bcrs */
  708. spin_lock_irqsave(&lp->lock, flags);
  709. for (i = 4; i < 8; i++) {
  710. a->write_bcr(ioaddr, i, regs[i - 4]);
  711. }
  712. spin_unlock_irqrestore(&lp->lock, flags);
  713. return 0;
  714. }
  715. #define PCNET32_REGS_PER_PHY 32
  716. #define PCNET32_MAX_PHYS 32
  717. static int pcnet32_get_regs_len(struct net_device *dev)
  718. {
  719. struct pcnet32_private *lp = dev->priv;
  720. int j = lp->phycount * PCNET32_REGS_PER_PHY;
  721. return ((PCNET32_NUM_REGS + j) * sizeof(u16));
  722. }
  723. static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs,
  724. void *ptr)
  725. {
  726. int i, csr0;
  727. u16 *buff = ptr;
  728. struct pcnet32_private *lp = dev->priv;
  729. struct pcnet32_access *a = &lp->a;
  730. ulong ioaddr = dev->base_addr;
  731. int ticks;
  732. unsigned long flags;
  733. spin_lock_irqsave(&lp->lock, flags);
  734. csr0 = a->read_csr(ioaddr, 0);
  735. if (!(csr0 & 0x0004)) { /* If not stopped */
  736. /* set SUSPEND (SPND) - CSR5 bit 0 */
  737. a->write_csr(ioaddr, 5, 0x0001);
  738. /* poll waiting for bit to be set */
  739. ticks = 0;
  740. while (!(a->read_csr(ioaddr, 5) & 0x0001)) {
  741. spin_unlock_irqrestore(&lp->lock, flags);
  742. mdelay(1);
  743. spin_lock_irqsave(&lp->lock, flags);
  744. ticks++;
  745. if (ticks > 200) {
  746. if (netif_msg_hw(lp))
  747. printk(KERN_DEBUG
  748. "%s: Error getting into suspend!\n",
  749. dev->name);
  750. break;
  751. }
  752. }
  753. }
  754. /* read address PROM */
  755. for (i = 0; i < 16; i += 2)
  756. *buff++ = inw(ioaddr + i);
  757. /* read control and status registers */
  758. for (i = 0; i < 90; i++) {
  759. *buff++ = a->read_csr(ioaddr, i);
  760. }
  761. *buff++ = a->read_csr(ioaddr, 112);
  762. *buff++ = a->read_csr(ioaddr, 114);
  763. /* read bus configuration registers */
  764. for (i = 0; i < 30; i++) {
  765. *buff++ = a->read_bcr(ioaddr, i);
  766. }
  767. *buff++ = 0; /* skip bcr30 so as not to hang 79C976 */
  768. for (i = 31; i < 36; i++) {
  769. *buff++ = a->read_bcr(ioaddr, i);
  770. }
  771. /* read mii phy registers */
  772. if (lp->mii) {
  773. int j;
  774. for (j = 0; j < PCNET32_MAX_PHYS; j++) {
  775. if (lp->phymask & (1 << j)) {
  776. for (i = 0; i < PCNET32_REGS_PER_PHY; i++) {
  777. lp->a.write_bcr(ioaddr, 33,
  778. (j << 5) | i);
  779. *buff++ = lp->a.read_bcr(ioaddr, 34);
  780. }
  781. }
  782. }
  783. }
  784. if (!(csr0 & 0x0004)) { /* If not stopped */
  785. /* clear SUSPEND (SPND) - CSR5 bit 0 */
  786. a->write_csr(ioaddr, 5, 0x0000);
  787. }
  788. spin_unlock_irqrestore(&lp->lock, flags);
  789. }
  790. static struct ethtool_ops pcnet32_ethtool_ops = {
  791. .get_settings = pcnet32_get_settings,
  792. .set_settings = pcnet32_set_settings,
  793. .get_drvinfo = pcnet32_get_drvinfo,
  794. .get_msglevel = pcnet32_get_msglevel,
  795. .set_msglevel = pcnet32_set_msglevel,
  796. .nway_reset = pcnet32_nway_reset,
  797. .get_link = pcnet32_get_link,
  798. .get_ringparam = pcnet32_get_ringparam,
  799. .set_ringparam = pcnet32_set_ringparam,
  800. .get_tx_csum = ethtool_op_get_tx_csum,
  801. .get_sg = ethtool_op_get_sg,
  802. .get_tso = ethtool_op_get_tso,
  803. .get_strings = pcnet32_get_strings,
  804. .self_test_count = pcnet32_self_test_count,
  805. .self_test = pcnet32_ethtool_test,
  806. .phys_id = pcnet32_phys_id,
  807. .get_regs_len = pcnet32_get_regs_len,
  808. .get_regs = pcnet32_get_regs,
  809. .get_perm_addr = ethtool_op_get_perm_addr,
  810. };
  811. /* only probes for non-PCI devices, the rest are handled by
  812. * pci_register_driver via pcnet32_probe_pci */
  813. static void __devinit pcnet32_probe_vlbus(unsigned int *pcnet32_portlist)
  814. {
  815. unsigned int *port, ioaddr;
  816. /* search for PCnet32 VLB cards at known addresses */
  817. for (port = pcnet32_portlist; (ioaddr = *port); port++) {
  818. if (request_region
  819. (ioaddr, PCNET32_TOTAL_SIZE, "pcnet32_probe_vlbus")) {
  820. /* check if there is really a pcnet chip on that ioaddr */
  821. if ((inb(ioaddr + 14) == 0x57)
  822. && (inb(ioaddr + 15) == 0x57)) {
  823. pcnet32_probe1(ioaddr, 0, NULL);
  824. } else {
  825. release_region(ioaddr, PCNET32_TOTAL_SIZE);
  826. }
  827. }
  828. }
  829. }
  830. static int __devinit
  831. pcnet32_probe_pci(struct pci_dev *pdev, const struct pci_device_id *ent)
  832. {
  833. unsigned long ioaddr;
  834. int err;
  835. err = pci_enable_device(pdev);
  836. if (err < 0) {
  837. if (pcnet32_debug & NETIF_MSG_PROBE)
  838. printk(KERN_ERR PFX
  839. "failed to enable device -- err=%d\n", err);
  840. return err;
  841. }
  842. pci_set_master(pdev);
  843. ioaddr = pci_resource_start(pdev, 0);
  844. if (!ioaddr) {
  845. if (pcnet32_debug & NETIF_MSG_PROBE)
  846. printk(KERN_ERR PFX
  847. "card has no PCI IO resources, aborting\n");
  848. return -ENODEV;
  849. }
  850. if (!pci_dma_supported(pdev, PCNET32_DMA_MASK)) {
  851. if (pcnet32_debug & NETIF_MSG_PROBE)
  852. printk(KERN_ERR PFX
  853. "architecture does not support 32bit PCI busmaster DMA\n");
  854. return -ENODEV;
  855. }
  856. if (request_region(ioaddr, PCNET32_TOTAL_SIZE, "pcnet32_probe_pci") ==
  857. NULL) {
  858. if (pcnet32_debug & NETIF_MSG_PROBE)
  859. printk(KERN_ERR PFX
  860. "io address range already allocated\n");
  861. return -EBUSY;
  862. }
  863. err = pcnet32_probe1(ioaddr, 1, pdev);
  864. if (err < 0) {
  865. pci_disable_device(pdev);
  866. }
  867. return err;
  868. }
  869. /* pcnet32_probe1
  870. * Called from both pcnet32_probe_vlbus and pcnet_probe_pci.
  871. * pdev will be NULL when called from pcnet32_probe_vlbus.
  872. */
  873. static int __devinit
  874. pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
  875. {
  876. struct pcnet32_private *lp;
  877. dma_addr_t lp_dma_addr;
  878. int i, media;
  879. int fdx, mii, fset, dxsuflo;
  880. int chip_version;
  881. char *chipname;
  882. struct net_device *dev;
  883. struct pcnet32_access *a = NULL;
  884. u8 promaddr[6];
  885. int ret = -ENODEV;
  886. /* reset the chip */
  887. pcnet32_wio_reset(ioaddr);
  888. /* NOTE: 16-bit check is first, otherwise some older PCnet chips fail */
  889. if (pcnet32_wio_read_csr(ioaddr, 0) == 4 && pcnet32_wio_check(ioaddr)) {
  890. a = &pcnet32_wio;
  891. } else {
  892. pcnet32_dwio_reset(ioaddr);
  893. if (pcnet32_dwio_read_csr(ioaddr, 0) == 4
  894. && pcnet32_dwio_check(ioaddr)) {
  895. a = &pcnet32_dwio;
  896. } else
  897. goto err_release_region;
  898. }
  899. chip_version =
  900. a->read_csr(ioaddr, 88) | (a->read_csr(ioaddr, 89) << 16);
  901. if ((pcnet32_debug & NETIF_MSG_PROBE) && (pcnet32_debug & NETIF_MSG_HW))
  902. printk(KERN_INFO " PCnet chip version is %#x.\n",
  903. chip_version);
  904. if ((chip_version & 0xfff) != 0x003) {
  905. if (pcnet32_debug & NETIF_MSG_PROBE)
  906. printk(KERN_INFO PFX "Unsupported chip version.\n");
  907. goto err_release_region;
  908. }
  909. /* initialize variables */
  910. fdx = mii = fset = dxsuflo = 0;
  911. chip_version = (chip_version >> 12) & 0xffff;
  912. switch (chip_version) {
  913. case 0x2420:
  914. chipname = "PCnet/PCI 79C970"; /* PCI */
  915. break;
  916. case 0x2430:
  917. if (shared)
  918. chipname = "PCnet/PCI 79C970"; /* 970 gives the wrong chip id back */
  919. else
  920. chipname = "PCnet/32 79C965"; /* 486/VL bus */
  921. break;
  922. case 0x2621:
  923. chipname = "PCnet/PCI II 79C970A"; /* PCI */
  924. fdx = 1;
  925. break;
  926. case 0x2623:
  927. chipname = "PCnet/FAST 79C971"; /* PCI */
  928. fdx = 1;
  929. mii = 1;
  930. fset = 1;
  931. break;
  932. case 0x2624:
  933. chipname = "PCnet/FAST+ 79C972"; /* PCI */
  934. fdx = 1;
  935. mii = 1;
  936. fset = 1;
  937. break;
  938. case 0x2625:
  939. chipname = "PCnet/FAST III 79C973"; /* PCI */
  940. fdx = 1;
  941. mii = 1;
  942. break;
  943. case 0x2626:
  944. chipname = "PCnet/Home 79C978"; /* PCI */
  945. fdx = 1;
  946. /*
  947. * This is based on specs published at www.amd.com. This section
  948. * assumes that a card with a 79C978 wants to go into standard
  949. * ethernet mode. The 79C978 can also go into 1Mb HomePNA mode,
  950. * and the module option homepna=1 can select this instead.
  951. */
  952. media = a->read_bcr(ioaddr, 49);
  953. media &= ~3; /* default to 10Mb ethernet */
  954. if (cards_found < MAX_UNITS && homepna[cards_found])
  955. media |= 1; /* switch to home wiring mode */
  956. if (pcnet32_debug & NETIF_MSG_PROBE)
  957. printk(KERN_DEBUG PFX "media set to %sMbit mode.\n",
  958. (media & 1) ? "1" : "10");
  959. a->write_bcr(ioaddr, 49, media);
  960. break;
  961. case 0x2627:
  962. chipname = "PCnet/FAST III 79C975"; /* PCI */
  963. fdx = 1;
  964. mii = 1;
  965. break;
  966. case 0x2628:
  967. chipname = "PCnet/PRO 79C976";
  968. fdx = 1;
  969. mii = 1;
  970. break;
  971. default:
  972. if (pcnet32_debug & NETIF_MSG_PROBE)
  973. printk(KERN_INFO PFX
  974. "PCnet version %#x, no PCnet32 chip.\n",
  975. chip_version);
  976. goto err_release_region;
  977. }
  978. /*
  979. * On selected chips turn on the BCR18:NOUFLO bit. This stops transmit
  980. * starting until the packet is loaded. Strike one for reliability, lose
  981. * one for latency - although on PCI this isnt a big loss. Older chips
  982. * have FIFO's smaller than a packet, so you can't do this.
  983. * Turn on BCR18:BurstRdEn and BCR18:BurstWrEn.
  984. */
  985. if (fset) {
  986. a->write_bcr(ioaddr, 18, (a->read_bcr(ioaddr, 18) | 0x0860));
  987. a->write_csr(ioaddr, 80,
  988. (a->read_csr(ioaddr, 80) & 0x0C00) | 0x0c00);
  989. dxsuflo = 1;
  990. }
  991. dev = alloc_etherdev(0);
  992. if (!dev) {
  993. if (pcnet32_debug & NETIF_MSG_PROBE)
  994. printk(KERN_ERR PFX "Memory allocation failed.\n");
  995. ret = -ENOMEM;
  996. goto err_release_region;
  997. }
  998. SET_NETDEV_DEV(dev, &pdev->dev);
  999. if (pcnet32_debug & NETIF_MSG_PROBE)
  1000. printk(KERN_INFO PFX "%s at %#3lx,", chipname, ioaddr);
  1001. /* In most chips, after a chip reset, the ethernet address is read from the
  1002. * station address PROM at the base address and programmed into the
  1003. * "Physical Address Registers" CSR12-14.
  1004. * As a precautionary measure, we read the PROM values and complain if
  1005. * they disagree with the CSRs. If they miscompare, and the PROM addr
  1006. * is valid, then the PROM addr is used.
  1007. */
  1008. for (i = 0; i < 3; i++) {
  1009. unsigned int val;
  1010. val = a->read_csr(ioaddr, i + 12) & 0x0ffff;
  1011. /* There may be endianness issues here. */
  1012. dev->dev_addr[2 * i] = val & 0x0ff;
  1013. dev->dev_addr[2 * i + 1] = (val >> 8) & 0x0ff;
  1014. }
  1015. /* read PROM address and compare with CSR address */
  1016. for (i = 0; i < 6; i++)
  1017. promaddr[i] = inb(ioaddr + i);
  1018. if (memcmp(promaddr, dev->dev_addr, 6)
  1019. || !is_valid_ether_addr(dev->dev_addr)) {
  1020. if (is_valid_ether_addr(promaddr)) {
  1021. if (pcnet32_debug & NETIF_MSG_PROBE) {
  1022. printk(" warning: CSR address invalid,\n");
  1023. printk(KERN_INFO
  1024. " using instead PROM address of");
  1025. }
  1026. memcpy(dev->dev_addr, promaddr, 6);
  1027. }
  1028. }
  1029. memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
  1030. /* if the ethernet address is not valid, force to 00:00:00:00:00:00 */
  1031. if (!is_valid_ether_addr(dev->perm_addr))
  1032. memset(dev->dev_addr, 0, sizeof(dev->dev_addr));
  1033. if (pcnet32_debug & NETIF_MSG_PROBE) {
  1034. for (i = 0; i < 6; i++)
  1035. printk(" %2.2x", dev->dev_addr[i]);
  1036. /* Version 0x2623 and 0x2624 */
  1037. if (((chip_version + 1) & 0xfffe) == 0x2624) {
  1038. i = a->read_csr(ioaddr, 80) & 0x0C00; /* Check tx_start_pt */
  1039. printk("\n" KERN_INFO " tx_start_pt(0x%04x):", i);
  1040. switch (i >> 10) {
  1041. case 0:
  1042. printk(" 20 bytes,");
  1043. break;
  1044. case 1:
  1045. printk(" 64 bytes,");
  1046. break;
  1047. case 2:
  1048. printk(" 128 bytes,");
  1049. break;
  1050. case 3:
  1051. printk("~220 bytes,");
  1052. break;
  1053. }
  1054. i = a->read_bcr(ioaddr, 18); /* Check Burst/Bus control */
  1055. printk(" BCR18(%x):", i & 0xffff);
  1056. if (i & (1 << 5))
  1057. printk("BurstWrEn ");
  1058. if (i & (1 << 6))
  1059. printk("BurstRdEn ");
  1060. if (i & (1 << 7))
  1061. printk("DWordIO ");
  1062. if (i & (1 << 11))
  1063. printk("NoUFlow ");
  1064. i = a->read_bcr(ioaddr, 25);
  1065. printk("\n" KERN_INFO " SRAMSIZE=0x%04x,", i << 8);
  1066. i = a->read_bcr(ioaddr, 26);
  1067. printk(" SRAM_BND=0x%04x,", i << 8);
  1068. i = a->read_bcr(ioaddr, 27);
  1069. if (i & (1 << 14))
  1070. printk("LowLatRx");
  1071. }
  1072. }
  1073. dev->base_addr = ioaddr;
  1074. /* pci_alloc_consistent returns page-aligned memory, so we do not have to check the alignment */
  1075. if ((lp =
  1076. pci_alloc_consistent(pdev, sizeof(*lp), &lp_dma_addr)) == NULL) {
  1077. if (pcnet32_debug & NETIF_MSG_PROBE)
  1078. printk(KERN_ERR PFX
  1079. "Consistent memory allocation failed.\n");
  1080. ret = -ENOMEM;
  1081. goto err_free_netdev;
  1082. }
  1083. memset(lp, 0, sizeof(*lp));
  1084. lp->dma_addr = lp_dma_addr;
  1085. lp->pci_dev = pdev;
  1086. spin_lock_init(&lp->lock);
  1087. SET_MODULE_OWNER(dev);
  1088. SET_NETDEV_DEV(dev, &pdev->dev);
  1089. dev->priv = lp;
  1090. lp->name = chipname;
  1091. lp->shared_irq = shared;
  1092. lp->tx_ring_size = TX_RING_SIZE; /* default tx ring size */
  1093. lp->rx_ring_size = RX_RING_SIZE; /* default rx ring size */
  1094. lp->tx_mod_mask = lp->tx_ring_size - 1;
  1095. lp->rx_mod_mask = lp->rx_ring_size - 1;
  1096. lp->tx_len_bits = (PCNET32_LOG_TX_BUFFERS << 12);
  1097. lp->rx_len_bits = (PCNET32_LOG_RX_BUFFERS << 4);
  1098. lp->mii_if.full_duplex = fdx;
  1099. lp->mii_if.phy_id_mask = 0x1f;
  1100. lp->mii_if.reg_num_mask = 0x1f;
  1101. lp->dxsuflo = dxsuflo;
  1102. lp->mii = mii;
  1103. lp->msg_enable = pcnet32_debug;
  1104. if ((cards_found >= MAX_UNITS)
  1105. || (options[cards_found] > sizeof(options_mapping)))
  1106. lp->options = PCNET32_PORT_ASEL;
  1107. else
  1108. lp->options = options_mapping[options[cards_found]];
  1109. lp->mii_if.dev = dev;
  1110. lp->mii_if.mdio_read = mdio_read;
  1111. lp->mii_if.mdio_write = mdio_write;
  1112. if (fdx && !(lp->options & PCNET32_PORT_ASEL) &&
  1113. ((cards_found >= MAX_UNITS) || full_duplex[cards_found]))
  1114. lp->options |= PCNET32_PORT_FD;
  1115. if (!a) {
  1116. if (pcnet32_debug & NETIF_MSG_PROBE)
  1117. printk(KERN_ERR PFX "No access methods\n");
  1118. ret = -ENODEV;
  1119. goto err_free_consistent;
  1120. }
  1121. lp->a = *a;
  1122. /* prior to register_netdev, dev->name is not yet correct */
  1123. if (pcnet32_alloc_ring(dev, pci_name(lp->pci_dev))) {
  1124. ret = -ENOMEM;
  1125. goto err_free_ring;
  1126. }
  1127. /* detect special T1/E1 WAN card by checking for MAC address */
  1128. if (dev->dev_addr[0] == 0x00 && dev->dev_addr[1] == 0xe0
  1129. && dev->dev_addr[2] == 0x75)
  1130. lp->options = PCNET32_PORT_FD | PCNET32_PORT_GPSI;
  1131. lp->init_block.mode = le16_to_cpu(0x0003); /* Disable Rx and Tx. */
  1132. lp->init_block.tlen_rlen =
  1133. le16_to_cpu(lp->tx_len_bits | lp->rx_len_bits);
  1134. for (i = 0; i < 6; i++)
  1135. lp->init_block.phys_addr[i] = dev->dev_addr[i];
  1136. lp->init_block.filter[0] = 0x00000000;
  1137. lp->init_block.filter[1] = 0x00000000;
  1138. lp->init_block.rx_ring = (u32) le32_to_cpu(lp->rx_ring_dma_addr);
  1139. lp->init_block.tx_ring = (u32) le32_to_cpu(lp->tx_ring_dma_addr);
  1140. /* switch pcnet32 to 32bit mode */
  1141. a->write_bcr(ioaddr, 20, 2);
  1142. a->write_csr(ioaddr, 1, (lp->dma_addr + offsetof(struct pcnet32_private,
  1143. init_block)) & 0xffff);
  1144. a->write_csr(ioaddr, 2, (lp->dma_addr + offsetof(struct pcnet32_private,
  1145. init_block)) >> 16);
  1146. if (pdev) { /* use the IRQ provided by PCI */
  1147. dev->irq = pdev->irq;
  1148. if (pcnet32_debug & NETIF_MSG_PROBE)
  1149. printk(" assigned IRQ %d.\n", dev->irq);
  1150. } else {
  1151. unsigned long irq_mask = probe_irq_on();
  1152. /*
  1153. * To auto-IRQ we enable the initialization-done and DMA error
  1154. * interrupts. For ISA boards we get a DMA error, but VLB and PCI
  1155. * boards will work.
  1156. */
  1157. /* Trigger an initialization just for the interrupt. */
  1158. a->write_csr(ioaddr, 0, 0x41);
  1159. mdelay(1);
  1160. dev->irq = probe_irq_off(irq_mask);
  1161. if (!dev->irq) {
  1162. if (pcnet32_debug & NETIF_MSG_PROBE)
  1163. printk(", failed to detect IRQ line.\n");
  1164. ret = -ENODEV;
  1165. goto err_free_ring;
  1166. }
  1167. if (pcnet32_debug & NETIF_MSG_PROBE)
  1168. printk(", probed IRQ %d.\n", dev->irq);
  1169. }
  1170. /* Set the mii phy_id so that we can query the link state */
  1171. if (lp->mii) {
  1172. /* lp->phycount and lp->phymask are set to 0 by memset above */
  1173. lp->mii_if.phy_id = ((lp->a.read_bcr(ioaddr, 33)) >> 5) & 0x1f;
  1174. /* scan for PHYs */
  1175. for (i = 0; i < PCNET32_MAX_PHYS; i++) {
  1176. unsigned short id1, id2;
  1177. id1 = mdio_read(dev, i, MII_PHYSID1);
  1178. if (id1 == 0xffff)
  1179. continue;
  1180. id2 = mdio_read(dev, i, MII_PHYSID2);
  1181. if (id2 == 0xffff)
  1182. continue;
  1183. if (i == 31 && ((chip_version + 1) & 0xfffe) == 0x2624)
  1184. continue; /* 79C971 & 79C972 have phantom phy at id 31 */
  1185. lp->phycount++;
  1186. lp->phymask |= (1 << i);
  1187. lp->mii_if.phy_id = i;
  1188. if (pcnet32_debug & NETIF_MSG_PROBE)
  1189. printk(KERN_INFO PFX
  1190. "Found PHY %04x:%04x at address %d.\n",
  1191. id1, id2, i);
  1192. }
  1193. lp->a.write_bcr(ioaddr, 33, (lp->mii_if.phy_id) << 5);
  1194. if (lp->phycount > 1) {
  1195. lp->options |= PCNET32_PORT_MII;
  1196. }
  1197. }
  1198. init_timer(&lp->watchdog_timer);
  1199. lp->watchdog_timer.data = (unsigned long)dev;
  1200. lp->watchdog_timer.function = (void *)&pcnet32_watchdog;
  1201. /* The PCNET32-specific entries in the device structure. */
  1202. dev->open = &pcnet32_open;
  1203. dev->hard_start_xmit = &pcnet32_start_xmit;
  1204. dev->stop = &pcnet32_close;
  1205. dev->get_stats = &pcnet32_get_stats;
  1206. dev->set_multicast_list = &pcnet32_set_multicast_list;
  1207. dev->do_ioctl = &pcnet32_ioctl;
  1208. dev->ethtool_ops = &pcnet32_ethtool_ops;
  1209. dev->tx_timeout = pcnet32_tx_timeout;
  1210. dev->watchdog_timeo = (5 * HZ);
  1211. #ifdef CONFIG_NET_POLL_CONTROLLER
  1212. dev->poll_controller = pcnet32_poll_controller;
  1213. #endif
  1214. /* Fill in the generic fields of the device structure. */
  1215. if (register_netdev(dev))
  1216. goto err_free_ring;
  1217. if (pdev) {
  1218. pci_set_drvdata(pdev, dev);
  1219. } else {
  1220. lp->next = pcnet32_dev;
  1221. pcnet32_dev = dev;
  1222. }
  1223. if (pcnet32_debug & NETIF_MSG_PROBE)
  1224. printk(KERN_INFO "%s: registered as %s\n", dev->name, lp->name);
  1225. cards_found++;
  1226. /* enable LED writes */
  1227. a->write_bcr(ioaddr, 2, a->read_bcr(ioaddr, 2) | 0x1000);
  1228. return 0;
  1229. err_free_ring:
  1230. pcnet32_free_ring(dev);
  1231. err_free_consistent:
  1232. pci_free_consistent(lp->pci_dev, sizeof(*lp), lp, lp->dma_addr);
  1233. err_free_netdev:
  1234. free_netdev(dev);
  1235. err_release_region:
  1236. release_region(ioaddr, PCNET32_TOTAL_SIZE);
  1237. return ret;
  1238. }
  1239. /* if any allocation fails, caller must also call pcnet32_free_ring */
  1240. static int pcnet32_alloc_ring(struct net_device *dev, char *name)
  1241. {
  1242. struct pcnet32_private *lp = dev->priv;
  1243. lp->tx_ring = pci_alloc_consistent(lp->pci_dev,
  1244. sizeof(struct pcnet32_tx_head) *
  1245. lp->tx_ring_size,
  1246. &lp->tx_ring_dma_addr);
  1247. if (lp->tx_ring == NULL) {
  1248. if (netif_msg_drv(lp))
  1249. printk("\n" KERN_ERR PFX
  1250. "%s: Consistent memory allocation failed.\n",
  1251. name);
  1252. return -ENOMEM;
  1253. }
  1254. lp->rx_ring = pci_alloc_consistent(lp->pci_dev,
  1255. sizeof(struct pcnet32_rx_head) *
  1256. lp->rx_ring_size,
  1257. &lp->rx_ring_dma_addr);
  1258. if (lp->rx_ring == NULL) {
  1259. if (netif_msg_drv(lp))
  1260. printk("\n" KERN_ERR PFX
  1261. "%s: Consistent memory allocation failed.\n",
  1262. name);
  1263. return -ENOMEM;
  1264. }
  1265. lp->tx_dma_addr = kcalloc(lp->tx_ring_size, sizeof(dma_addr_t),
  1266. GFP_ATOMIC);
  1267. if (!lp->tx_dma_addr) {
  1268. if (netif_msg_drv(lp))
  1269. printk("\n" KERN_ERR PFX
  1270. "%s: Memory allocation failed.\n", name);
  1271. return -ENOMEM;
  1272. }
  1273. lp->rx_dma_addr = kcalloc(lp->rx_ring_size, sizeof(dma_addr_t),
  1274. GFP_ATOMIC);
  1275. if (!lp->rx_dma_addr) {
  1276. if (netif_msg_drv(lp))
  1277. printk("\n" KERN_ERR PFX
  1278. "%s: Memory allocation failed.\n", name);
  1279. return -ENOMEM;
  1280. }
  1281. lp->tx_skbuff = kcalloc(lp->tx_ring_size, sizeof(struct sk_buff *),
  1282. GFP_ATOMIC);
  1283. if (!lp->tx_skbuff) {
  1284. if (netif_msg_drv(lp))
  1285. printk("\n" KERN_ERR PFX
  1286. "%s: Memory allocation failed.\n", name);
  1287. return -ENOMEM;
  1288. }
  1289. lp->rx_skbuff = kcalloc(lp->rx_ring_size, sizeof(struct sk_buff *),
  1290. GFP_ATOMIC);
  1291. if (!lp->rx_skbuff) {
  1292. if (netif_msg_drv(lp))
  1293. printk("\n" KERN_ERR PFX
  1294. "%s: Memory allocation failed.\n", name);
  1295. return -ENOMEM;
  1296. }
  1297. return 0;
  1298. }
  1299. static void pcnet32_free_ring(struct net_device *dev)
  1300. {
  1301. struct pcnet32_private *lp = dev->priv;
  1302. kfree(lp->tx_skbuff);
  1303. lp->tx_skbuff = NULL;
  1304. kfree(lp->rx_skbuff);
  1305. lp->rx_skbuff = NULL;
  1306. kfree(lp->tx_dma_addr);
  1307. lp->tx_dma_addr = NULL;
  1308. kfree(lp->rx_dma_addr);
  1309. lp->rx_dma_addr = NULL;
  1310. if (lp->tx_ring) {
  1311. pci_free_consistent(lp->pci_dev,
  1312. sizeof(struct pcnet32_tx_head) *
  1313. lp->tx_ring_size, lp->tx_ring,
  1314. lp->tx_ring_dma_addr);
  1315. lp->tx_ring = NULL;
  1316. }
  1317. if (lp->rx_ring) {
  1318. pci_free_consistent(lp->pci_dev,
  1319. sizeof(struct pcnet32_rx_head) *
  1320. lp->rx_ring_size, lp->rx_ring,
  1321. lp->rx_ring_dma_addr);
  1322. lp->rx_ring = NULL;
  1323. }
  1324. }
  1325. static int pcnet32_open(struct net_device *dev)
  1326. {
  1327. struct pcnet32_private *lp = dev->priv;
  1328. unsigned long ioaddr = dev->base_addr;
  1329. u16 val;
  1330. int i;
  1331. int rc;
  1332. unsigned long flags;
  1333. if (request_irq(dev->irq, &pcnet32_interrupt,
  1334. lp->shared_irq ? IRQF_SHARED : 0, dev->name,
  1335. (void *)dev)) {
  1336. return -EAGAIN;
  1337. }
  1338. spin_lock_irqsave(&lp->lock, flags);
  1339. /* Check for a valid station address */
  1340. if (!is_valid_ether_addr(dev->dev_addr)) {
  1341. rc = -EINVAL;
  1342. goto err_free_irq;
  1343. }
  1344. /* Reset the PCNET32 */
  1345. lp->a.reset(ioaddr);
  1346. /* switch pcnet32 to 32bit mode */
  1347. lp->a.write_bcr(ioaddr, 20, 2);
  1348. if (netif_msg_ifup(lp))
  1349. printk(KERN_DEBUG
  1350. "%s: pcnet32_open() irq %d tx/rx rings %#x/%#x init %#x.\n",
  1351. dev->name, dev->irq, (u32) (lp->tx_ring_dma_addr),
  1352. (u32) (lp->rx_ring_dma_addr),
  1353. (u32) (lp->dma_addr +
  1354. offsetof(struct pcnet32_private, init_block)));
  1355. /* set/reset autoselect bit */
  1356. val = lp->a.read_bcr(ioaddr, 2) & ~2;
  1357. if (lp->options & PCNET32_PORT_ASEL)
  1358. val |= 2;
  1359. lp->a.write_bcr(ioaddr, 2, val);
  1360. /* handle full duplex setting */
  1361. if (lp->mii_if.full_duplex) {
  1362. val = lp->a.read_bcr(ioaddr, 9) & ~3;
  1363. if (lp->options & PCNET32_PORT_FD) {
  1364. val |= 1;
  1365. if (lp->options == (PCNET32_PORT_FD | PCNET32_PORT_AUI))
  1366. val |= 2;
  1367. } else if (lp->options & PCNET32_PORT_ASEL) {
  1368. /* workaround of xSeries250, turn on for 79C975 only */
  1369. i = ((lp->a.read_csr(ioaddr, 88) |
  1370. (lp->a.
  1371. read_csr(ioaddr, 89) << 16)) >> 12) & 0xffff;
  1372. if (i == 0x2627)
  1373. val |= 3;
  1374. }
  1375. lp->a.write_bcr(ioaddr, 9, val);
  1376. }
  1377. /* set/reset GPSI bit in test register */
  1378. val = lp->a.read_csr(ioaddr, 124) & ~0x10;
  1379. if ((lp->options & PCNET32_PORT_PORTSEL) == PCNET32_PORT_GPSI)
  1380. val |= 0x10;
  1381. lp->a.write_csr(ioaddr, 124, val);
  1382. /* Allied Telesyn AT 2700/2701 FX are 100Mbit only and do not negotiate */
  1383. if (lp->pci_dev->subsystem_vendor == PCI_VENDOR_ID_AT &&
  1384. (lp->pci_dev->subsystem_device == PCI_SUBDEVICE_ID_AT_2700FX ||
  1385. lp->pci_dev->subsystem_device == PCI_SUBDEVICE_ID_AT_2701FX)) {
  1386. if (lp->options & PCNET32_PORT_ASEL) {
  1387. lp->options = PCNET32_PORT_FD | PCNET32_PORT_100;
  1388. if (netif_msg_link(lp))
  1389. printk(KERN_DEBUG
  1390. "%s: Setting 100Mb-Full Duplex.\n",
  1391. dev->name);
  1392. }
  1393. }
  1394. if (lp->phycount < 2) {
  1395. /*
  1396. * 24 Jun 2004 according AMD, in order to change the PHY,
  1397. * DANAS (or DISPM for 79C976) must be set; then select the speed,
  1398. * duplex, and/or enable auto negotiation, and clear DANAS
  1399. */
  1400. if (lp->mii && !(lp->options & PCNET32_PORT_ASEL)) {
  1401. lp->a.write_bcr(ioaddr, 32,
  1402. lp->a.read_bcr(ioaddr, 32) | 0x0080);
  1403. /* disable Auto Negotiation, set 10Mpbs, HD */
  1404. val = lp->a.read_bcr(ioaddr, 32) & ~0xb8;
  1405. if (lp->options & PCNET32_PORT_FD)
  1406. val |= 0x10;
  1407. if (lp->options & PCNET32_PORT_100)
  1408. val |= 0x08;
  1409. lp->a.write_bcr(ioaddr, 32, val);
  1410. } else {
  1411. if (lp->options & PCNET32_PORT_ASEL) {
  1412. lp->a.write_bcr(ioaddr, 32,
  1413. lp->a.read_bcr(ioaddr,
  1414. 32) | 0x0080);
  1415. /* enable auto negotiate, setup, disable fd */
  1416. val = lp->a.read_bcr(ioaddr, 32) & ~0x98;
  1417. val |= 0x20;
  1418. lp->a.write_bcr(ioaddr, 32, val);
  1419. }
  1420. }
  1421. } else {
  1422. int first_phy = -1;
  1423. u16 bmcr;
  1424. u32 bcr9;
  1425. struct ethtool_cmd ecmd;
  1426. /*
  1427. * There is really no good other way to handle multiple PHYs
  1428. * other than turning off all automatics
  1429. */
  1430. val = lp->a.read_bcr(ioaddr, 2);
  1431. lp->a.write_bcr(ioaddr, 2, val & ~2);
  1432. val = lp->a.read_bcr(ioaddr, 32);
  1433. lp->a.write_bcr(ioaddr, 32, val & ~(1 << 7)); /* stop MII manager */
  1434. if (!(lp->options & PCNET32_PORT_ASEL)) {
  1435. /* setup ecmd */
  1436. ecmd.port = PORT_MII;
  1437. ecmd.transceiver = XCVR_INTERNAL;
  1438. ecmd.autoneg = AUTONEG_DISABLE;
  1439. ecmd.speed =
  1440. lp->
  1441. options & PCNET32_PORT_100 ? SPEED_100 : SPEED_10;
  1442. bcr9 = lp->a.read_bcr(ioaddr, 9);
  1443. if (lp->options & PCNET32_PORT_FD) {
  1444. ecmd.duplex = DUPLEX_FULL;
  1445. bcr9 |= (1 << 0);
  1446. } else {
  1447. ecmd.duplex = DUPLEX_HALF;
  1448. bcr9 |= ~(1 << 0);
  1449. }
  1450. lp->a.write_bcr(ioaddr, 9, bcr9);
  1451. }
  1452. for (i = 0; i < PCNET32_MAX_PHYS; i++) {
  1453. if (lp->phymask & (1 << i)) {
  1454. /* isolate all but the first PHY */
  1455. bmcr = mdio_read(dev, i, MII_BMCR);
  1456. if (first_phy == -1) {
  1457. first_phy = i;
  1458. mdio_write(dev, i, MII_BMCR,
  1459. bmcr & ~BMCR_ISOLATE);
  1460. } else {
  1461. mdio_write(dev, i, MII_BMCR,
  1462. bmcr | BMCR_ISOLATE);
  1463. }
  1464. /* use mii_ethtool_sset to setup PHY */
  1465. lp->mii_if.phy_id = i;
  1466. ecmd.phy_address = i;
  1467. if (lp->options & PCNET32_PORT_ASEL) {
  1468. mii_ethtool_gset(&lp->mii_if, &ecmd);
  1469. ecmd.autoneg = AUTONEG_ENABLE;
  1470. }
  1471. mii_ethtool_sset(&lp->mii_if, &ecmd);
  1472. }
  1473. }
  1474. lp->mii_if.phy_id = first_phy;
  1475. if (netif_msg_link(lp))
  1476. printk(KERN_INFO "%s: Using PHY number %d.\n",
  1477. dev->name, first_phy);
  1478. }
  1479. #ifdef DO_DXSUFLO
  1480. if (lp->dxsuflo) { /* Disable transmit stop on underflow */
  1481. val = lp->a.read_csr(ioaddr, 3);
  1482. val |= 0x40;
  1483. lp->a.write_csr(ioaddr, 3, val);
  1484. }
  1485. #endif
  1486. lp->init_block.mode =
  1487. le16_to_cpu((lp->options & PCNET32_PORT_PORTSEL) << 7);
  1488. pcnet32_load_multicast(dev);
  1489. if (pcnet32_init_ring(dev)) {
  1490. rc = -ENOMEM;
  1491. goto err_free_ring;
  1492. }
  1493. /* Re-initialize the PCNET32, and start it when done. */
  1494. lp->a.write_csr(ioaddr, 1, (lp->dma_addr +
  1495. offsetof(struct pcnet32_private,
  1496. init_block)) & 0xffff);
  1497. lp->a.write_csr(ioaddr, 2,
  1498. (lp->dma_addr +
  1499. offsetof(struct pcnet32_private, init_block)) >> 16);
  1500. lp->a.write_csr(ioaddr, 4, 0x0915);
  1501. lp->a.write_csr(ioaddr, 0, 0x0001);
  1502. netif_start_queue(dev);
  1503. /* Print the link status and start the watchdog */
  1504. pcnet32_check_media(dev, 1);
  1505. mod_timer(&(lp->watchdog_timer), PCNET32_WATCHDOG_TIMEOUT);
  1506. i = 0;
  1507. while (i++ < 100)
  1508. if (lp->a.read_csr(ioaddr, 0) & 0x0100)
  1509. break;
  1510. /*
  1511. * We used to clear the InitDone bit, 0x0100, here but Mark Stockton
  1512. * reports that doing so triggers a bug in the '974.
  1513. */
  1514. lp->a.write_csr(ioaddr, 0, 0x0042);
  1515. if (netif_msg_ifup(lp))
  1516. printk(KERN_DEBUG
  1517. "%s: pcnet32 open after %d ticks, init block %#x csr0 %4.4x.\n",
  1518. dev->name, i,
  1519. (u32) (lp->dma_addr +
  1520. offsetof(struct pcnet32_private, init_block)),
  1521. lp->a.read_csr(ioaddr, 0));
  1522. spin_unlock_irqrestore(&lp->lock, flags);
  1523. return 0; /* Always succeed */
  1524. err_free_ring:
  1525. /* free any allocated skbuffs */
  1526. for (i = 0; i < lp->rx_ring_size; i++) {
  1527. lp->rx_ring[i].status = 0;
  1528. if (lp->rx_skbuff[i]) {
  1529. pci_unmap_single(lp->pci_dev, lp->rx_dma_addr[i],
  1530. PKT_BUF_SZ - 2, PCI_DMA_FROMDEVICE);
  1531. dev_kfree_skb(lp->rx_skbuff[i]);
  1532. }
  1533. lp->rx_skbuff[i] = NULL;
  1534. lp->rx_dma_addr[i] = 0;
  1535. }
  1536. /*
  1537. * Switch back to 16bit mode to avoid problems with dumb
  1538. * DOS packet driver after a warm reboot
  1539. */
  1540. lp->a.write_bcr(ioaddr, 20, 4);
  1541. err_free_irq:
  1542. spin_unlock_irqrestore(&lp->lock, flags);
  1543. free_irq(dev->irq, dev);
  1544. return rc;
  1545. }
  1546. /*
  1547. * The LANCE has been halted for one reason or another (busmaster memory
  1548. * arbitration error, Tx FIFO underflow, driver stopped it to reconfigure,
  1549. * etc.). Modern LANCE variants always reload their ring-buffer
  1550. * configuration when restarted, so we must reinitialize our ring
  1551. * context before restarting. As part of this reinitialization,
  1552. * find all packets still on the Tx ring and pretend that they had been
  1553. * sent (in effect, drop the packets on the floor) - the higher-level
  1554. * protocols will time out and retransmit. It'd be better to shuffle
  1555. * these skbs to a temp list and then actually re-Tx them after
  1556. * restarting the chip, but I'm too lazy to do so right now. dplatt@3do.com
  1557. */
  1558. static void pcnet32_purge_tx_ring(struct net_device *dev)
  1559. {
  1560. struct pcnet32_private *lp = dev->priv;
  1561. int i;
  1562. for (i = 0; i < lp->tx_ring_size; i++) {
  1563. lp->tx_ring[i].status = 0; /* CPU owns buffer */
  1564. wmb(); /* Make sure adapter sees owner change */
  1565. if (lp->tx_skbuff[i]) {
  1566. pci_unmap_single(lp->pci_dev, lp->tx_dma_addr[i],
  1567. lp->tx_skbuff[i]->len,
  1568. PCI_DMA_TODEVICE);
  1569. dev_kfree_skb_any(lp->tx_skbuff[i]);
  1570. }
  1571. lp->tx_skbuff[i] = NULL;
  1572. lp->tx_dma_addr[i] = 0;
  1573. }
  1574. }
  1575. /* Initialize the PCNET32 Rx and Tx rings. */
  1576. static int pcnet32_init_ring(struct net_device *dev)
  1577. {
  1578. struct pcnet32_private *lp = dev->priv;
  1579. int i;
  1580. lp->tx_full = 0;
  1581. lp->cur_rx = lp->cur_tx = 0;
  1582. lp->dirty_rx = lp->dirty_tx = 0;
  1583. for (i = 0; i < lp->rx_ring_size; i++) {
  1584. struct sk_buff *rx_skbuff = lp->rx_skbuff[i];
  1585. if (rx_skbuff == NULL) {
  1586. if (!
  1587. (rx_skbuff = lp->rx_skbuff[i] =
  1588. dev_alloc_skb(PKT_BUF_SZ))) {
  1589. /* there is not much, we can do at this point */
  1590. if (pcnet32_debug & NETIF_MSG_DRV)
  1591. printk(KERN_ERR
  1592. "%s: pcnet32_init_ring dev_alloc_skb failed.\n",
  1593. dev->name);
  1594. return -1;
  1595. }
  1596. skb_reserve(rx_skbuff, 2);
  1597. }
  1598. rmb();
  1599. if (lp->rx_dma_addr[i] == 0)
  1600. lp->rx_dma_addr[i] =
  1601. pci_map_single(lp->pci_dev, rx_skbuff->data,
  1602. PKT_BUF_SZ - 2, PCI_DMA_FROMDEVICE);
  1603. lp->rx_ring[i].base = (u32) le32_to_cpu(lp->rx_dma_addr[i]);
  1604. lp->rx_ring[i].buf_length = le16_to_cpu(2 - PKT_BUF_SZ);
  1605. wmb(); /* Make sure owner changes after all others are visible */
  1606. lp->rx_ring[i].status = le16_to_cpu(0x8000);
  1607. }
  1608. /* The Tx buffer address is filled in as needed, but we do need to clear
  1609. * the upper ownership bit. */
  1610. for (i = 0; i < lp->tx_ring_size; i++) {
  1611. lp->tx_ring[i].status = 0; /* CPU owns buffer */
  1612. wmb(); /* Make sure adapter sees owner change */
  1613. lp->tx_ring[i].base = 0;
  1614. lp->tx_dma_addr[i] = 0;
  1615. }
  1616. lp->init_block.tlen_rlen =
  1617. le16_to_cpu(lp->tx_len_bits | lp->rx_len_bits);
  1618. for (i = 0; i < 6; i++)
  1619. lp->init_block.phys_addr[i] = dev->dev_addr[i];
  1620. lp->init_block.rx_ring = (u32) le32_to_cpu(lp->rx_ring_dma_addr);
  1621. lp->init_block.tx_ring = (u32) le32_to_cpu(lp->tx_ring_dma_addr);
  1622. wmb(); /* Make sure all changes are visible */
  1623. return 0;
  1624. }
  1625. /* the pcnet32 has been issued a stop or reset. Wait for the stop bit
  1626. * then flush the pending transmit operations, re-initialize the ring,
  1627. * and tell the chip to initialize.
  1628. */
  1629. static void pcnet32_restart(struct net_device *dev, unsigned int csr0_bits)
  1630. {
  1631. struct pcnet32_private *lp = dev->priv;
  1632. unsigned long ioaddr = dev->base_addr;
  1633. int i;
  1634. /* wait for stop */
  1635. for (i = 0; i < 100; i++)
  1636. if (lp->a.read_csr(ioaddr, 0) & 0x0004)
  1637. break;
  1638. if (i >= 100 && netif_msg_drv(lp))
  1639. printk(KERN_ERR
  1640. "%s: pcnet32_restart timed out waiting for stop.\n",
  1641. dev->name);
  1642. pcnet32_purge_tx_ring(dev);
  1643. if (pcnet32_init_ring(dev))
  1644. return;
  1645. /* ReInit Ring */
  1646. lp->a.write_csr(ioaddr, 0, 1);
  1647. i = 0;
  1648. while (i++ < 1000)
  1649. if (lp->a.read_csr(ioaddr, 0) & 0x0100)
  1650. break;
  1651. lp->a.write_csr(ioaddr, 0, csr0_bits);
  1652. }
  1653. static void pcnet32_tx_timeout(struct net_device *dev)
  1654. {
  1655. struct pcnet32_private *lp = dev->priv;
  1656. unsigned long ioaddr = dev->base_addr, flags;
  1657. spin_lock_irqsave(&lp->lock, flags);
  1658. /* Transmitter timeout, serious problems. */
  1659. if (pcnet32_debug & NETIF_MSG_DRV)
  1660. printk(KERN_ERR
  1661. "%s: transmit timed out, status %4.4x, resetting.\n",
  1662. dev->name, lp->a.read_csr(ioaddr, 0));
  1663. lp->a.write_csr(ioaddr, 0, 0x0004);
  1664. lp->stats.tx_errors++;
  1665. if (netif_msg_tx_err(lp)) {
  1666. int i;
  1667. printk(KERN_DEBUG
  1668. " Ring data dump: dirty_tx %d cur_tx %d%s cur_rx %d.",
  1669. lp->dirty_tx, lp->cur_tx, lp->tx_full ? " (full)" : "",
  1670. lp->cur_rx);
  1671. for (i = 0; i < lp->rx_ring_size; i++)
  1672. printk("%s %08x %04x %08x %04x", i & 1 ? "" : "\n ",
  1673. le32_to_cpu(lp->rx_ring[i].base),
  1674. (-le16_to_cpu(lp->rx_ring[i].buf_length)) &
  1675. 0xffff, le32_to_cpu(lp->rx_ring[i].msg_length),
  1676. le16_to_cpu(lp->rx_ring[i].status));
  1677. for (i = 0; i < lp->tx_ring_size; i++)
  1678. printk("%s %08x %04x %08x %04x", i & 1 ? "" : "\n ",
  1679. le32_to_cpu(lp->tx_ring[i].base),
  1680. (-le16_to_cpu(lp->tx_ring[i].length)) & 0xffff,
  1681. le32_to_cpu(lp->tx_ring[i].misc),
  1682. le16_to_cpu(lp->tx_ring[i].status));
  1683. printk("\n");
  1684. }
  1685. pcnet32_restart(dev, 0x0042);
  1686. dev->trans_start = jiffies;
  1687. netif_wake_queue(dev);
  1688. spin_unlock_irqrestore(&lp->lock, flags);
  1689. }
  1690. static int pcnet32_start_xmit(struct sk_buff *skb, struct net_device *dev)
  1691. {
  1692. struct pcnet32_private *lp = dev->priv;
  1693. unsigned long ioaddr = dev->base_addr;
  1694. u16 status;
  1695. int entry;
  1696. unsigned long flags;
  1697. spin_lock_irqsave(&lp->lock, flags);
  1698. if (netif_msg_tx_queued(lp)) {
  1699. printk(KERN_DEBUG
  1700. "%s: pcnet32_start_xmit() called, csr0 %4.4x.\n",
  1701. dev->name, lp->a.read_csr(ioaddr, 0));
  1702. }
  1703. /* Default status -- will not enable Successful-TxDone
  1704. * interrupt when that option is available to us.
  1705. */
  1706. status = 0x8300;
  1707. /* Fill in a Tx ring entry */
  1708. /* Mask to ring buffer boundary. */
  1709. entry = lp->cur_tx & lp->tx_mod_mask;
  1710. /* Caution: the write order is important here, set the status
  1711. * with the "ownership" bits last. */
  1712. lp->tx_ring[entry].length = le16_to_cpu(-skb->len);
  1713. lp->tx_ring[entry].misc = 0x00000000;
  1714. lp->tx_skbuff[entry] = skb;
  1715. lp->tx_dma_addr[entry] =
  1716. pci_map_single(lp->pci_dev, skb->data, skb->len, PCI_DMA_TODEVICE);
  1717. lp->tx_ring[entry].base = (u32) le32_to_cpu(lp->tx_dma_addr[entry]);
  1718. wmb(); /* Make sure owner changes after all others are visible */
  1719. lp->tx_ring[entry].status = le16_to_cpu(status);
  1720. lp->cur_tx++;
  1721. lp->stats.tx_bytes += skb->len;
  1722. /* Trigger an immediate send poll. */
  1723. lp->a.write_csr(ioaddr, 0, 0x0048);
  1724. dev->trans_start = jiffies;
  1725. if (lp->tx_ring[(entry + 1) & lp->tx_mod_mask].base != 0) {
  1726. lp->tx_full = 1;
  1727. netif_stop_queue(dev);
  1728. }
  1729. spin_unlock_irqrestore(&lp->lock, flags);
  1730. return 0;
  1731. }
  1732. /* The PCNET32 interrupt handler. */
  1733. static irqreturn_t
  1734. pcnet32_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  1735. {
  1736. struct net_device *dev = dev_id;
  1737. struct pcnet32_private *lp;
  1738. unsigned long ioaddr;
  1739. u16 csr0, rap;
  1740. int boguscnt = max_interrupt_work;
  1741. int must_restart;
  1742. if (!dev) {
  1743. if (pcnet32_debug & NETIF_MSG_INTR)
  1744. printk(KERN_DEBUG "%s(): irq %d for unknown device\n",
  1745. __FUNCTION__, irq);
  1746. return IRQ_NONE;
  1747. }
  1748. ioaddr = dev->base_addr;
  1749. lp = dev->priv;
  1750. spin_lock(&lp->lock);
  1751. rap = lp->a.read_rap(ioaddr);
  1752. while ((csr0 = lp->a.read_csr(ioaddr, 0)) & 0x8f00 && --boguscnt >= 0) {
  1753. if (csr0 == 0xffff) {
  1754. break; /* PCMCIA remove happened */
  1755. }
  1756. /* Acknowledge all of the current interrupt sources ASAP. */
  1757. lp->a.write_csr(ioaddr, 0, csr0 & ~0x004f);
  1758. must_restart = 0;
  1759. if (netif_msg_intr(lp))
  1760. printk(KERN_DEBUG
  1761. "%s: interrupt csr0=%#2.2x new csr=%#2.2x.\n",
  1762. dev->name, csr0, lp->a.read_csr(ioaddr, 0));
  1763. if (csr0 & 0x0400) /* Rx interrupt */
  1764. pcnet32_rx(dev);
  1765. if (csr0 & 0x0200) { /* Tx-done interrupt */
  1766. unsigned int dirty_tx = lp->dirty_tx;
  1767. int delta;
  1768. while (dirty_tx != lp->cur_tx) {
  1769. int entry = dirty_tx & lp->tx_mod_mask;
  1770. int status =
  1771. (short)le16_to_cpu(lp->tx_ring[entry].
  1772. status);
  1773. if (status < 0)
  1774. break; /* It still hasn't been Txed */
  1775. lp->tx_ring[entry].base = 0;
  1776. if (status & 0x4000) {
  1777. /* There was an major error, log it. */
  1778. int err_status =
  1779. le32_to_cpu(lp->tx_ring[entry].
  1780. misc);
  1781. lp->stats.tx_errors++;
  1782. if (netif_msg_tx_err(lp))
  1783. printk(KERN_ERR
  1784. "%s: Tx error status=%04x err_status=%08x\n",
  1785. dev->name, status,
  1786. err_status);
  1787. if (err_status & 0x04000000)
  1788. lp->stats.tx_aborted_errors++;
  1789. if (err_status & 0x08000000)
  1790. lp->stats.tx_carrier_errors++;
  1791. if (err_status & 0x10000000)
  1792. lp->stats.tx_window_errors++;
  1793. #ifndef DO_DXSUFLO
  1794. if (err_status & 0x40000000) {
  1795. lp->stats.tx_fifo_errors++;
  1796. /* Ackk! On FIFO errors the Tx unit is turned off! */
  1797. /* Remove this verbosity later! */
  1798. if (netif_msg_tx_err(lp))
  1799. printk(KERN_ERR
  1800. "%s: Tx FIFO error! CSR0=%4.4x\n",
  1801. dev->name, csr0);
  1802. must_restart = 1;
  1803. }
  1804. #else
  1805. if (err_status & 0x40000000) {
  1806. lp->stats.tx_fifo_errors++;
  1807. if (!lp->dxsuflo) { /* If controller doesn't recover ... */
  1808. /* Ackk! On FIFO errors the Tx unit is turned off! */
  1809. /* Remove this verbosity later! */
  1810. if (netif_msg_tx_err
  1811. (lp))
  1812. printk(KERN_ERR
  1813. "%s: Tx FIFO error! CSR0=%4.4x\n",
  1814. dev->
  1815. name,
  1816. csr0);
  1817. must_restart = 1;
  1818. }
  1819. }
  1820. #endif
  1821. } else {
  1822. if (status & 0x1800)
  1823. lp->stats.collisions++;
  1824. lp->stats.tx_packets++;
  1825. }
  1826. /* We must free the original skb */
  1827. if (lp->tx_skbuff[entry]) {
  1828. pci_unmap_single(lp->pci_dev,
  1829. lp->tx_dma_addr[entry],
  1830. lp->tx_skbuff[entry]->
  1831. len, PCI_DMA_TODEVICE);
  1832. dev_kfree_skb_irq(lp->tx_skbuff[entry]);
  1833. lp->tx_skbuff[entry] = NULL;
  1834. lp->tx_dma_addr[entry] = 0;
  1835. }
  1836. dirty_tx++;
  1837. }
  1838. delta =
  1839. (lp->cur_tx - dirty_tx) & (lp->tx_mod_mask +
  1840. lp->tx_ring_size);
  1841. if (delta > lp->tx_ring_size) {
  1842. if (netif_msg_drv(lp))
  1843. printk(KERN_ERR
  1844. "%s: out-of-sync dirty pointer, %d vs. %d, full=%d.\n",
  1845. dev->name, dirty_tx, lp->cur_tx,
  1846. lp->tx_full);
  1847. dirty_tx += lp->tx_ring_size;
  1848. delta -= lp->tx_ring_size;
  1849. }
  1850. if (lp->tx_full &&
  1851. netif_queue_stopped(dev) &&
  1852. delta < lp->tx_ring_size - 2) {
  1853. /* The ring is no longer full, clear tbusy. */
  1854. lp->tx_full = 0;
  1855. netif_wake_queue(dev);
  1856. }
  1857. lp->dirty_tx = dirty_tx;
  1858. }
  1859. /* Log misc errors. */
  1860. if (csr0 & 0x4000)
  1861. lp->stats.tx_errors++; /* Tx babble. */
  1862. if (csr0 & 0x1000) {
  1863. /*
  1864. * this happens when our receive ring is full. This shouldn't
  1865. * be a problem as we will see normal rx interrupts for the frames
  1866. * in the receive ring. But there are some PCI chipsets (I can
  1867. * reproduce this on SP3G with Intel saturn chipset) which have
  1868. * sometimes problems and will fill up the receive ring with
  1869. * error descriptors. In this situation we don't get a rx
  1870. * interrupt, but a missed frame interrupt sooner or later.
  1871. * So we try to clean up our receive ring here.
  1872. */
  1873. pcnet32_rx(dev);
  1874. lp->stats.rx_errors++; /* Missed a Rx frame. */
  1875. }
  1876. if (csr0 & 0x0800) {
  1877. if (netif_msg_drv(lp))
  1878. printk(KERN_ERR
  1879. "%s: Bus master arbitration failure, status %4.4x.\n",
  1880. dev->name, csr0);
  1881. /* unlike for the lance, there is no restart needed */
  1882. }
  1883. if (must_restart) {
  1884. /* reset the chip to clear the error condition, then restart */
  1885. lp->a.reset(ioaddr);
  1886. lp->a.write_csr(ioaddr, 4, 0x0915);
  1887. pcnet32_restart(dev, 0x0002);
  1888. netif_wake_queue(dev);
  1889. }
  1890. }
  1891. /* Set interrupt enable. */
  1892. lp->a.write_csr(ioaddr, 0, 0x0040);
  1893. lp->a.write_rap(ioaddr, rap);
  1894. if (netif_msg_intr(lp))
  1895. printk(KERN_DEBUG "%s: exiting interrupt, csr0=%#4.4x.\n",
  1896. dev->name, lp->a.read_csr(ioaddr, 0));
  1897. spin_unlock(&lp->lock);
  1898. return IRQ_HANDLED;
  1899. }
  1900. static int pcnet32_rx(struct net_device *dev)
  1901. {
  1902. struct pcnet32_private *lp = dev->priv;
  1903. int entry = lp->cur_rx & lp->rx_mod_mask;
  1904. int boguscnt = lp->rx_ring_size / 2;
  1905. /* If we own the next entry, it's a new packet. Send it up. */
  1906. while ((short)le16_to_cpu(lp->rx_ring[entry].status) >= 0) {
  1907. int status = (short)le16_to_cpu(lp->rx_ring[entry].status) >> 8;
  1908. if (status != 0x03) { /* There was an error. */
  1909. /*
  1910. * There is a tricky error noted by John Murphy,
  1911. * <murf@perftech.com> to Russ Nelson: Even with full-sized
  1912. * buffers it's possible for a jabber packet to use two
  1913. * buffers, with only the last correctly noting the error.
  1914. */
  1915. if (status & 0x01) /* Only count a general error at the */
  1916. lp->stats.rx_errors++; /* end of a packet. */
  1917. if (status & 0x20)
  1918. lp->stats.rx_frame_errors++;
  1919. if (status & 0x10)
  1920. lp->stats.rx_over_errors++;
  1921. if (status & 0x08)
  1922. lp->stats.rx_crc_errors++;
  1923. if (status & 0x04)
  1924. lp->stats.rx_fifo_errors++;
  1925. lp->rx_ring[entry].status &= le16_to_cpu(0x03ff);
  1926. } else {
  1927. /* Malloc up new buffer, compatible with net-2e. */
  1928. short pkt_len =
  1929. (le32_to_cpu(lp->rx_ring[entry].msg_length) & 0xfff)
  1930. - 4;
  1931. struct sk_buff *skb;
  1932. /* Discard oversize frames. */
  1933. if (unlikely(pkt_len > PKT_BUF_SZ - 2)) {
  1934. if (netif_msg_drv(lp))
  1935. printk(KERN_ERR
  1936. "%s: Impossible packet size %d!\n",
  1937. dev->name, pkt_len);
  1938. lp->stats.rx_errors++;
  1939. } else if (pkt_len < 60) {
  1940. if (netif_msg_rx_err(lp))
  1941. printk(KERN_ERR "%s: Runt packet!\n",
  1942. dev->name);
  1943. lp->stats.rx_errors++;
  1944. } else {
  1945. int rx_in_place = 0;
  1946. if (pkt_len > rx_copybreak) {
  1947. struct sk_buff *newskb;
  1948. if ((newskb =
  1949. dev_alloc_skb(PKT_BUF_SZ))) {
  1950. skb_reserve(newskb, 2);
  1951. skb = lp->rx_skbuff[entry];
  1952. pci_unmap_single(lp->pci_dev,
  1953. lp->
  1954. rx_dma_addr
  1955. [entry],
  1956. PKT_BUF_SZ - 2,
  1957. PCI_DMA_FROMDEVICE);
  1958. skb_put(skb, pkt_len);
  1959. lp->rx_skbuff[entry] = newskb;
  1960. newskb->dev = dev;
  1961. lp->rx_dma_addr[entry] =
  1962. pci_map_single(lp->pci_dev,
  1963. newskb->data,
  1964. PKT_BUF_SZ -
  1965. 2,
  1966. PCI_DMA_FROMDEVICE);
  1967. lp->rx_ring[entry].base =
  1968. le32_to_cpu(lp->
  1969. rx_dma_addr
  1970. [entry]);
  1971. rx_in_place = 1;
  1972. } else
  1973. skb = NULL;
  1974. } else {
  1975. skb = dev_alloc_skb(pkt_len + 2);
  1976. }
  1977. if (skb == NULL) {
  1978. int i;
  1979. if (netif_msg_drv(lp))
  1980. printk(KERN_ERR
  1981. "%s: Memory squeeze, deferring packet.\n",
  1982. dev->name);
  1983. for (i = 0; i < lp->rx_ring_size; i++)
  1984. if ((short)
  1985. le16_to_cpu(lp->
  1986. rx_ring[(entry +
  1987. i)
  1988. & lp->
  1989. rx_mod_mask].
  1990. status) < 0)
  1991. break;
  1992. if (i > lp->rx_ring_size - 2) {
  1993. lp->stats.rx_dropped++;
  1994. lp->rx_ring[entry].status |=
  1995. le16_to_cpu(0x8000);
  1996. wmb(); /* Make sure adapter sees owner change */
  1997. lp->cur_rx++;
  1998. }
  1999. break;
  2000. }
  2001. skb->dev = dev;
  2002. if (!rx_in_place) {
  2003. skb_reserve(skb, 2); /* 16 byte align */
  2004. skb_put(skb, pkt_len); /* Make room */
  2005. pci_dma_sync_single_for_cpu(lp->pci_dev,
  2006. lp->
  2007. rx_dma_addr
  2008. [entry],
  2009. PKT_BUF_SZ -
  2010. 2,
  2011. PCI_DMA_FROMDEVICE);
  2012. eth_copy_and_sum(skb,
  2013. (unsigned char *)(lp->
  2014. rx_skbuff
  2015. [entry]->
  2016. data),
  2017. pkt_len, 0);
  2018. pci_dma_sync_single_for_device(lp->
  2019. pci_dev,
  2020. lp->
  2021. rx_dma_addr
  2022. [entry],
  2023. PKT_BUF_SZ
  2024. - 2,
  2025. PCI_DMA_FROMDEVICE);
  2026. }
  2027. lp->stats.rx_bytes += skb->len;
  2028. skb->protocol = eth_type_trans(skb, dev);
  2029. netif_rx(skb);
  2030. dev->last_rx = jiffies;
  2031. lp->stats.rx_packets++;
  2032. }
  2033. }
  2034. /*
  2035. * The docs say that the buffer length isn't touched, but Andrew Boyd
  2036. * of QNX reports that some revs of the 79C965 clear it.
  2037. */
  2038. lp->rx_ring[entry].buf_length = le16_to_cpu(2 - PKT_BUF_SZ);
  2039. wmb(); /* Make sure owner changes after all others are visible */
  2040. lp->rx_ring[entry].status |= le16_to_cpu(0x8000);
  2041. entry = (++lp->cur_rx) & lp->rx_mod_mask;
  2042. if (--boguscnt <= 0)
  2043. break; /* don't stay in loop forever */
  2044. }
  2045. return 0;
  2046. }
  2047. static int pcnet32_close(struct net_device *dev)
  2048. {
  2049. unsigned long ioaddr = dev->base_addr;
  2050. struct pcnet32_private *lp = dev->priv;
  2051. int i;
  2052. unsigned long flags;
  2053. del_timer_sync(&lp->watchdog_timer);
  2054. netif_stop_queue(dev);
  2055. spin_lock_irqsave(&lp->lock, flags);
  2056. lp->stats.rx_missed_errors = lp->a.read_csr(ioaddr, 112);
  2057. if (netif_msg_ifdown(lp))
  2058. printk(KERN_DEBUG
  2059. "%s: Shutting down ethercard, status was %2.2x.\n",
  2060. dev->name, lp->a.read_csr(ioaddr, 0));
  2061. /* We stop the PCNET32 here -- it occasionally polls memory if we don't. */
  2062. lp->a.write_csr(ioaddr, 0, 0x0004);
  2063. /*
  2064. * Switch back to 16bit mode to avoid problems with dumb
  2065. * DOS packet driver after a warm reboot
  2066. */
  2067. lp->a.write_bcr(ioaddr, 20, 4);
  2068. spin_unlock_irqrestore(&lp->lock, flags);
  2069. free_irq(dev->irq, dev);
  2070. spin_lock_irqsave(&lp->lock, flags);
  2071. /* free all allocated skbuffs */
  2072. for (i = 0; i < lp->rx_ring_size; i++) {
  2073. lp->rx_ring[i].status = 0;
  2074. wmb(); /* Make sure adapter sees owner change */
  2075. if (lp->rx_skbuff[i]) {
  2076. pci_unmap_single(lp->pci_dev, lp->rx_dma_addr[i],
  2077. PKT_BUF_SZ - 2, PCI_DMA_FROMDEVICE);
  2078. dev_kfree_skb(lp->rx_skbuff[i]);
  2079. }
  2080. lp->rx_skbuff[i] = NULL;
  2081. lp->rx_dma_addr[i] = 0;
  2082. }
  2083. for (i = 0; i < lp->tx_ring_size; i++) {
  2084. lp->tx_ring[i].status = 0; /* CPU owns buffer */
  2085. wmb(); /* Make sure adapter sees owner change */
  2086. if (lp->tx_skbuff[i]) {
  2087. pci_unmap_single(lp->pci_dev, lp->tx_dma_addr[i],
  2088. lp->tx_skbuff[i]->len,
  2089. PCI_DMA_TODEVICE);
  2090. dev_kfree_skb(lp->tx_skbuff[i]);
  2091. }
  2092. lp->tx_skbuff[i] = NULL;
  2093. lp->tx_dma_addr[i] = 0;
  2094. }
  2095. spin_unlock_irqrestore(&lp->lock, flags);
  2096. return 0;
  2097. }
  2098. static struct net_device_stats *pcnet32_get_stats(struct net_device *dev)
  2099. {
  2100. struct pcnet32_private *lp = dev->priv;
  2101. unsigned long ioaddr = dev->base_addr;
  2102. u16 saved_addr;
  2103. unsigned long flags;
  2104. spin_lock_irqsave(&lp->lock, flags);
  2105. saved_addr = lp->a.read_rap(ioaddr);
  2106. lp->stats.rx_missed_errors = lp->a.read_csr(ioaddr, 112);
  2107. lp->a.write_rap(ioaddr, saved_addr);
  2108. spin_unlock_irqrestore(&lp->lock, flags);
  2109. return &lp->stats;
  2110. }
  2111. /* taken from the sunlance driver, which it took from the depca driver */
  2112. static void pcnet32_load_multicast(struct net_device *dev)
  2113. {
  2114. struct pcnet32_private *lp = dev->priv;
  2115. volatile struct pcnet32_init_block *ib = &lp->init_block;
  2116. volatile u16 *mcast_table = (u16 *) & ib->filter;
  2117. struct dev_mc_list *dmi = dev->mc_list;
  2118. char *addrs;
  2119. int i;
  2120. u32 crc;
  2121. /* set all multicast bits */
  2122. if (dev->flags & IFF_ALLMULTI) {
  2123. ib->filter[0] = 0xffffffff;
  2124. ib->filter[1] = 0xffffffff;
  2125. return;
  2126. }
  2127. /* clear the multicast filter */
  2128. ib->filter[0] = 0;
  2129. ib->filter[1] = 0;
  2130. /* Add addresses */
  2131. for (i = 0; i < dev->mc_count; i++) {
  2132. addrs = dmi->dmi_addr;
  2133. dmi = dmi->next;
  2134. /* multicast address? */
  2135. if (!(*addrs & 1))
  2136. continue;
  2137. crc = ether_crc_le(6, addrs);
  2138. crc = crc >> 26;
  2139. mcast_table[crc >> 4] =
  2140. le16_to_cpu(le16_to_cpu(mcast_table[crc >> 4]) |
  2141. (1 << (crc & 0xf)));
  2142. }
  2143. return;
  2144. }
  2145. /*
  2146. * Set or clear the multicast filter for this adaptor.
  2147. */
  2148. static void pcnet32_set_multicast_list(struct net_device *dev)
  2149. {
  2150. unsigned long ioaddr = dev->base_addr, flags;
  2151. struct pcnet32_private *lp = dev->priv;
  2152. spin_lock_irqsave(&lp->lock, flags);
  2153. if (dev->flags & IFF_PROMISC) {
  2154. /* Log any net taps. */
  2155. if (netif_msg_hw(lp))
  2156. printk(KERN_INFO "%s: Promiscuous mode enabled.\n",
  2157. dev->name);
  2158. lp->init_block.mode =
  2159. le16_to_cpu(0x8000 | (lp->options & PCNET32_PORT_PORTSEL) <<
  2160. 7);
  2161. } else {
  2162. lp->init_block.mode =
  2163. le16_to_cpu((lp->options & PCNET32_PORT_PORTSEL) << 7);
  2164. pcnet32_load_multicast(dev);
  2165. }
  2166. lp->a.write_csr(ioaddr, 0, 0x0004); /* Temporarily stop the lance. */
  2167. pcnet32_restart(dev, 0x0042); /* Resume normal operation */
  2168. netif_wake_queue(dev);
  2169. spin_unlock_irqrestore(&lp->lock, flags);
  2170. }
  2171. /* This routine assumes that the lp->lock is held */
  2172. static int mdio_read(struct net_device *dev, int phy_id, int reg_num)
  2173. {
  2174. struct pcnet32_private *lp = dev->priv;
  2175. unsigned long ioaddr = dev->base_addr;
  2176. u16 val_out;
  2177. if (!lp->mii)
  2178. return 0;
  2179. lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
  2180. val_out = lp->a.read_bcr(ioaddr, 34);
  2181. return val_out;
  2182. }
  2183. /* This routine assumes that the lp->lock is held */
  2184. static void mdio_write(struct net_device *dev, int phy_id, int reg_num, int val)
  2185. {
  2186. struct pcnet32_private *lp = dev->priv;
  2187. unsigned long ioaddr = dev->base_addr;
  2188. if (!lp->mii)
  2189. return;
  2190. lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
  2191. lp->a.write_bcr(ioaddr, 34, val);
  2192. }
  2193. static int pcnet32_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  2194. {
  2195. struct pcnet32_private *lp = dev->priv;
  2196. int rc;
  2197. unsigned long flags;
  2198. /* SIOC[GS]MIIxxx ioctls */
  2199. if (lp->mii) {
  2200. spin_lock_irqsave(&lp->lock, flags);
  2201. rc = generic_mii_ioctl(&lp->mii_if, if_mii(rq), cmd, NULL);
  2202. spin_unlock_irqrestore(&lp->lock, flags);
  2203. } else {
  2204. rc = -EOPNOTSUPP;
  2205. }
  2206. return rc;
  2207. }
  2208. static int pcnet32_check_otherphy(struct net_device *dev)
  2209. {
  2210. struct pcnet32_private *lp = dev->priv;
  2211. struct mii_if_info mii = lp->mii_if;
  2212. u16 bmcr;
  2213. int i;
  2214. for (i = 0; i < PCNET32_MAX_PHYS; i++) {
  2215. if (i == lp->mii_if.phy_id)
  2216. continue; /* skip active phy */
  2217. if (lp->phymask & (1 << i)) {
  2218. mii.phy_id = i;
  2219. if (mii_link_ok(&mii)) {
  2220. /* found PHY with active link */
  2221. if (netif_msg_link(lp))
  2222. printk(KERN_INFO
  2223. "%s: Using PHY number %d.\n",
  2224. dev->name, i);
  2225. /* isolate inactive phy */
  2226. bmcr =
  2227. mdio_read(dev, lp->mii_if.phy_id, MII_BMCR);
  2228. mdio_write(dev, lp->mii_if.phy_id, MII_BMCR,
  2229. bmcr | BMCR_ISOLATE);
  2230. /* de-isolate new phy */
  2231. bmcr = mdio_read(dev, i, MII_BMCR);
  2232. mdio_write(dev, i, MII_BMCR,
  2233. bmcr & ~BMCR_ISOLATE);
  2234. /* set new phy address */
  2235. lp->mii_if.phy_id = i;
  2236. return 1;
  2237. }
  2238. }
  2239. }
  2240. return 0;
  2241. }
  2242. /*
  2243. * Show the status of the media. Similar to mii_check_media however it
  2244. * correctly shows the link speed for all (tested) pcnet32 variants.
  2245. * Devices with no mii just report link state without speed.
  2246. *
  2247. * Caller is assumed to hold and release the lp->lock.
  2248. */
  2249. static void pcnet32_check_media(struct net_device *dev, int verbose)
  2250. {
  2251. struct pcnet32_private *lp = dev->priv;
  2252. int curr_link;
  2253. int prev_link = netif_carrier_ok(dev) ? 1 : 0;
  2254. u32 bcr9;
  2255. if (lp->mii) {
  2256. curr_link = mii_link_ok(&lp->mii_if);
  2257. } else {
  2258. ulong ioaddr = dev->base_addr; /* card base I/O address */
  2259. curr_link = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
  2260. }
  2261. if (!curr_link) {
  2262. if (prev_link || verbose) {
  2263. netif_carrier_off(dev);
  2264. if (netif_msg_link(lp))
  2265. printk(KERN_INFO "%s: link down\n", dev->name);
  2266. }
  2267. if (lp->phycount > 1) {
  2268. curr_link = pcnet32_check_otherphy(dev);
  2269. prev_link = 0;
  2270. }
  2271. } else if (verbose || !prev_link) {
  2272. netif_carrier_on(dev);
  2273. if (lp->mii) {
  2274. if (netif_msg_link(lp)) {
  2275. struct ethtool_cmd ecmd;
  2276. mii_ethtool_gset(&lp->mii_if, &ecmd);
  2277. printk(KERN_INFO
  2278. "%s: link up, %sMbps, %s-duplex\n",
  2279. dev->name,
  2280. (ecmd.speed == SPEED_100) ? "100" : "10",
  2281. (ecmd.duplex ==
  2282. DUPLEX_FULL) ? "full" : "half");
  2283. }
  2284. bcr9 = lp->a.read_bcr(dev->base_addr, 9);
  2285. if ((bcr9 & (1 << 0)) != lp->mii_if.full_duplex) {
  2286. if (lp->mii_if.full_duplex)
  2287. bcr9 |= (1 << 0);
  2288. else
  2289. bcr9 &= ~(1 << 0);
  2290. lp->a.write_bcr(dev->base_addr, 9, bcr9);
  2291. }
  2292. } else {
  2293. if (netif_msg_link(lp))
  2294. printk(KERN_INFO "%s: link up\n", dev->name);
  2295. }
  2296. }
  2297. }
  2298. /*
  2299. * Check for loss of link and link establishment.
  2300. * Can not use mii_check_media because it does nothing if mode is forced.
  2301. */
  2302. static void pcnet32_watchdog(struct net_device *dev)
  2303. {
  2304. struct pcnet32_private *lp = dev->priv;
  2305. unsigned long flags;
  2306. /* Print the link status if it has changed */
  2307. spin_lock_irqsave(&lp->lock, flags);
  2308. pcnet32_check_media(dev, 0);
  2309. spin_unlock_irqrestore(&lp->lock, flags);
  2310. mod_timer(&(lp->watchdog_timer), PCNET32_WATCHDOG_TIMEOUT);
  2311. }
  2312. static void __devexit pcnet32_remove_one(struct pci_dev *pdev)
  2313. {
  2314. struct net_device *dev = pci_get_drvdata(pdev);
  2315. if (dev) {
  2316. struct pcnet32_private *lp = dev->priv;
  2317. unregister_netdev(dev);
  2318. pcnet32_free_ring(dev);
  2319. release_region(dev->base_addr, PCNET32_TOTAL_SIZE);
  2320. pci_free_consistent(lp->pci_dev, sizeof(*lp), lp, lp->dma_addr);
  2321. free_netdev(dev);
  2322. pci_disable_device(pdev);
  2323. pci_set_drvdata(pdev, NULL);
  2324. }
  2325. }
  2326. static struct pci_driver pcnet32_driver = {
  2327. .name = DRV_NAME,
  2328. .probe = pcnet32_probe_pci,
  2329. .remove = __devexit_p(pcnet32_remove_one),
  2330. .id_table = pcnet32_pci_tbl,
  2331. };
  2332. /* An additional parameter that may be passed in... */
  2333. static int debug = -1;
  2334. static int tx_start_pt = -1;
  2335. static int pcnet32_have_pci;
  2336. module_param(debug, int, 0);
  2337. MODULE_PARM_DESC(debug, DRV_NAME " debug level");
  2338. module_param(max_interrupt_work, int, 0);
  2339. MODULE_PARM_DESC(max_interrupt_work,
  2340. DRV_NAME " maximum events handled per interrupt");
  2341. module_param(rx_copybreak, int, 0);
  2342. MODULE_PARM_DESC(rx_copybreak,
  2343. DRV_NAME " copy breakpoint for copy-only-tiny-frames");
  2344. module_param(tx_start_pt, int, 0);
  2345. MODULE_PARM_DESC(tx_start_pt, DRV_NAME " transmit start point (0-3)");
  2346. module_param(pcnet32vlb, int, 0);
  2347. MODULE_PARM_DESC(pcnet32vlb, DRV_NAME " Vesa local bus (VLB) support (0/1)");
  2348. module_param_array(options, int, NULL, 0);
  2349. MODULE_PARM_DESC(options, DRV_NAME " initial option setting(s) (0-15)");
  2350. module_param_array(full_duplex, int, NULL, 0);
  2351. MODULE_PARM_DESC(full_duplex, DRV_NAME " full duplex setting(s) (1)");
  2352. /* Module Parameter for HomePNA cards added by Patrick Simmons, 2004 */
  2353. module_param_array(homepna, int, NULL, 0);
  2354. MODULE_PARM_DESC(homepna,
  2355. DRV_NAME
  2356. " mode for 79C978 cards (1 for HomePNA, 0 for Ethernet, default Ethernet");
  2357. MODULE_AUTHOR("Thomas Bogendoerfer");
  2358. MODULE_DESCRIPTION("Driver for PCnet32 and PCnetPCI based ethercards");
  2359. MODULE_LICENSE("GPL");
  2360. #define PCNET32_MSG_DEFAULT (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
  2361. static int __init pcnet32_init_module(void)
  2362. {
  2363. printk(KERN_INFO "%s", version);
  2364. pcnet32_debug = netif_msg_init(debug, PCNET32_MSG_DEFAULT);
  2365. if ((tx_start_pt >= 0) && (tx_start_pt <= 3))
  2366. tx_start = tx_start_pt;
  2367. /* find the PCI devices */
  2368. if (!pci_module_init(&pcnet32_driver))
  2369. pcnet32_have_pci = 1;
  2370. /* should we find any remaining VLbus devices ? */
  2371. if (pcnet32vlb)
  2372. pcnet32_probe_vlbus(pcnet32_portlist);
  2373. if (cards_found && (pcnet32_debug & NETIF_MSG_PROBE))
  2374. printk(KERN_INFO PFX "%d cards_found.\n", cards_found);
  2375. return (pcnet32_have_pci + cards_found) ? 0 : -ENODEV;
  2376. }
  2377. static void __exit pcnet32_cleanup_module(void)
  2378. {
  2379. struct net_device *next_dev;
  2380. while (pcnet32_dev) {
  2381. struct pcnet32_private *lp = pcnet32_dev->priv;
  2382. next_dev = lp->next;
  2383. unregister_netdev(pcnet32_dev);
  2384. pcnet32_free_ring(pcnet32_dev);
  2385. release_region(pcnet32_dev->base_addr, PCNET32_TOTAL_SIZE);
  2386. pci_free_consistent(lp->pci_dev, sizeof(*lp), lp, lp->dma_addr);
  2387. free_netdev(pcnet32_dev);
  2388. pcnet32_dev = next_dev;
  2389. }
  2390. if (pcnet32_have_pci)
  2391. pci_unregister_driver(&pcnet32_driver);
  2392. }
  2393. module_init(pcnet32_init_module);
  2394. module_exit(pcnet32_cleanup_module);
  2395. /*
  2396. * Local variables:
  2397. * c-indent-level: 4
  2398. * tab-width: 8
  2399. * End:
  2400. */