pcnet32.c 76 KB

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