pcnet32.c 76 KB

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