blob: 40ba6e02988c9842f31b816c955049865f654c24 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* D-Link DL2000-based Gigabit Ethernet Adapter Linux driver */
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 Copyright (c) 2001, 2002 by D-Link Corporation
4 Written by Edward Peng.<edward_peng@dlink.com.tw>
5 Created 03-May-2001, base on Linux' sundance.c.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11*/
12
13#ifndef __DL2K_H__
14#define __DL2K_H__
15
16#include <linux/module.h>
17#include <linux/kernel.h>
18#include <linux/string.h>
19#include <linux/timer.h>
20#include <linux/errno.h>
21#include <linux/ioport.h>
22#include <linux/slab.h>
23#include <linux/interrupt.h>
24#include <linux/pci.h>
25#include <linux/netdevice.h>
26#include <linux/etherdevice.h>
27#include <linux/skbuff.h>
28#include <linux/init.h>
29#include <linux/crc32.h>
30#include <linux/ethtool.h>
Francois Romieu78f6a6b2011-08-21 18:32:05 +020031#include <linux/mii.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/bitops.h>
33#include <asm/processor.h> /* Processor type for cache alignment. */
34#include <asm/io.h>
35#include <asm/uaccess.h>
36#include <linux/delay.h>
37#include <linux/spinlock.h>
38#include <linux/time.h>
39#define TX_RING_SIZE 256
40#define TX_QUEUE_LEN (TX_RING_SIZE - 1) /* Limit ring entries actually used.*/
41#define RX_RING_SIZE 256
42#define TX_TOTAL_SIZE TX_RING_SIZE*sizeof(struct netdev_desc)
43#define RX_TOTAL_SIZE RX_RING_SIZE*sizeof(struct netdev_desc)
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045/* Offsets to the device registers.
46 Unlike software-only systems, device drivers interact with complex hardware.
47 It's not useful to define symbolic names for every register bit in the
48 device. The name can only partially document the semantics and make
49 the driver longer and more difficult to read.
50 In general, only the important configuration values or bits changed
51 multiple times should be defined symbolically.
52*/
53enum dl2x_offsets {
54 /* I/O register offsets */
55 DMACtrl = 0x00,
56 RxDMAStatus = 0x08,
57 TFDListPtr0 = 0x10,
58 TFDListPtr1 = 0x14,
59 TxDMABurstThresh = 0x18,
60 TxDMAUrgentThresh = 0x19,
61 TxDMAPollPeriod = 0x1a,
62 RFDListPtr0 = 0x1c,
63 RFDListPtr1 = 0x20,
64 RxDMABurstThresh = 0x24,
65 RxDMAUrgentThresh = 0x25,
66 RxDMAPollPeriod = 0x26,
67 RxDMAIntCtrl = 0x28,
68 DebugCtrl = 0x2c,
69 ASICCtrl = 0x30,
70 FifoCtrl = 0x38,
71 RxEarlyThresh = 0x3a,
72 FlowOffThresh = 0x3c,
73 FlowOnThresh = 0x3e,
74 TxStartThresh = 0x44,
75 EepromData = 0x48,
76 EepromCtrl = 0x4a,
77 ExpromAddr = 0x4c,
78 Exprodata = 0x50,
79 WakeEvent = 0x51,
80 CountDown = 0x54,
81 IntStatusAck = 0x5a,
82 IntEnable = 0x5c,
83 IntStatus = 0x5e,
84 TxStatus = 0x60,
85 MACCtrl = 0x6c,
86 VLANTag = 0x70,
87 PhyCtrl = 0x76,
88 StationAddr0 = 0x78,
89 StationAddr1 = 0x7a,
90 StationAddr2 = 0x7c,
91 VLANId = 0x80,
92 MaxFrameSize = 0x86,
93 ReceiveMode = 0x88,
94 HashTable0 = 0x8c,
95 HashTable1 = 0x90,
96 RmonStatMask = 0x98,
97 StatMask = 0x9c,
98 RxJumboFrames = 0xbc,
99 TCPCheckSumErrors = 0xc0,
100 IPCheckSumErrors = 0xc2,
101 UDPCheckSumErrors = 0xc4,
102 TxJumboFrames = 0xf4,
103 /* Ethernet MIB statistic register offsets */
104 OctetRcvOk = 0xa8,
105 McstOctetRcvOk = 0xac,
106 BcstOctetRcvOk = 0xb0,
107 FramesRcvOk = 0xb4,
108 McstFramesRcvdOk = 0xb8,
109 BcstFramesRcvdOk = 0xbe,
110 MacControlFramesRcvd = 0xc6,
111 FrameTooLongErrors = 0xc8,
112 InRangeLengthErrors = 0xca,
113 FramesCheckSeqErrors = 0xcc,
114 FramesLostRxErrors = 0xce,
115 OctetXmtOk = 0xd0,
116 McstOctetXmtOk = 0xd4,
117 BcstOctetXmtOk = 0xd8,
118 FramesXmtOk = 0xdc,
119 McstFramesXmtdOk = 0xe0,
120 FramesWDeferredXmt = 0xe4,
121 LateCollisions = 0xe8,
122 MultiColFrames = 0xec,
123 SingleColFrames = 0xf0,
124 BcstFramesXmtdOk = 0xf6,
125 CarrierSenseErrors = 0xf8,
126 MacControlFramesXmtd = 0xfa,
127 FramesAbortXSColls = 0xfc,
128 FramesWEXDeferal = 0xfe,
129 /* RMON statistic register offsets */
130 EtherStatsCollisions = 0x100,
131 EtherStatsOctetsTransmit = 0x104,
132 EtherStatsPktsTransmit = 0x108,
133 EtherStatsPkts64OctetTransmit = 0x10c,
134 EtherStats65to127OctetsTransmit = 0x110,
135 EtherStatsPkts128to255OctetsTransmit = 0x114,
136 EtherStatsPkts256to511OctetsTransmit = 0x118,
137 EtherStatsPkts512to1023OctetsTransmit = 0x11c,
138 EtherStatsPkts1024to1518OctetsTransmit = 0x120,
139 EtherStatsCRCAlignErrors = 0x124,
140 EtherStatsUndersizePkts = 0x128,
141 EtherStatsFragments = 0x12c,
142 EtherStatsJabbers = 0x130,
143 EtherStatsOctets = 0x134,
144 EtherStatsPkts = 0x138,
145 EtherStats64Octets = 0x13c,
146 EtherStatsPkts65to127Octets = 0x140,
147 EtherStatsPkts128to255Octets = 0x144,
148 EtherStatsPkts256to511Octets = 0x148,
149 EtherStatsPkts512to1023Octets = 0x14c,
150 EtherStatsPkts1024to1518Octets = 0x150,
151};
152
153/* Bits in the interrupt status/mask registers. */
154enum IntStatus_bits {
155 InterruptStatus = 0x0001,
156 HostError = 0x0002,
157 MACCtrlFrame = 0x0008,
158 TxComplete = 0x0004,
159 RxComplete = 0x0010,
160 RxEarly = 0x0020,
161 IntRequested = 0x0040,
162 UpdateStats = 0x0080,
163 LinkEvent = 0x0100,
164 TxDMAComplete = 0x0200,
165 RxDMAComplete = 0x0400,
166 RFDListEnd = 0x0800,
167 RxDMAPriority = 0x1000,
168};
169
170/* Bits in the ReceiveMode register. */
171enum ReceiveMode_bits {
172 ReceiveUnicast = 0x0001,
173 ReceiveMulticast = 0x0002,
174 ReceiveBroadcast = 0x0004,
175 ReceiveAllFrames = 0x0008,
176 ReceiveMulticastHash = 0x0010,
177 ReceiveIPMulticast = 0x0020,
178 ReceiveVLANMatch = 0x0100,
179 ReceiveVLANHash = 0x0200,
180};
181/* Bits in MACCtrl. */
182enum MACCtrl_bits {
183 DuplexSelect = 0x20,
184 TxFlowControlEnable = 0x80,
185 RxFlowControlEnable = 0x0100,
186 RcvFCS = 0x200,
187 AutoVLANtagging = 0x1000,
188 AutoVLANuntagging = 0x2000,
189 StatsEnable = 0x00200000,
190 StatsDisable = 0x00400000,
191 StatsEnabled = 0x00800000,
192 TxEnable = 0x01000000,
193 TxDisable = 0x02000000,
194 TxEnabled = 0x04000000,
195 RxEnable = 0x08000000,
196 RxDisable = 0x10000000,
197 RxEnabled = 0x20000000,
198};
199
200enum ASICCtrl_LoWord_bits {
201 PhyMedia = 0x0080,
202};
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204enum ASICCtrl_HiWord_bits {
205 GlobalReset = 0x0001,
206 RxReset = 0x0002,
207 TxReset = 0x0004,
208 DMAReset = 0x0008,
209 FIFOReset = 0x0010,
210 NetworkReset = 0x0020,
211 HostReset = 0x0040,
212 ResetBusy = 0x0400,
213};
214
215/* Transmit Frame Control bits */
216enum TFC_bits {
217 DwordAlign = 0x00000000,
218 WordAlignDisable = 0x00030000,
219 WordAlign = 0x00020000,
220 TCPChecksumEnable = 0x00040000,
221 UDPChecksumEnable = 0x00080000,
222 IPChecksumEnable = 0x00100000,
223 FCSAppendDisable = 0x00200000,
224 TxIndicate = 0x00400000,
225 TxDMAIndicate = 0x00800000,
226 FragCountShift = 24,
227 VLANTagInsert = 0x0000000010000000,
228 TFDDone = 0x80000000,
229 VIDShift = 32,
230 UsePriorityShift = 48,
231};
232
233/* Receive Frames Status bits */
234enum RFS_bits {
235 RxFIFOOverrun = 0x00010000,
236 RxRuntFrame = 0x00020000,
237 RxAlignmentError = 0x00040000,
238 RxFCSError = 0x00080000,
239 RxOverSizedFrame = 0x00100000,
240 RxLengthError = 0x00200000,
241 VLANDetected = 0x00400000,
242 TCPDetected = 0x00800000,
243 TCPError = 0x01000000,
244 UDPDetected = 0x02000000,
245 UDPError = 0x04000000,
246 IPDetected = 0x08000000,
247 IPError = 0x10000000,
248 FrameStart = 0x20000000,
249 FrameEnd = 0x40000000,
250 RFDDone = 0x80000000,
251 TCIShift = 32,
252 RFS_Errors = 0x003f0000,
253};
254
255#define MII_RESET_TIME_OUT 10000
256/* MII register */
257enum _mii_reg {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 MII_PHY_SCR = 16,
259};
Francois Romieu78f6a6b2011-08-21 18:32:05 +0200260
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261/* PCS register */
262enum _pcs_reg {
263 PCS_BMCR = 0,
264 PCS_BMSR = 1,
265 PCS_ANAR = 4,
266 PCS_ANLPAR = 5,
267 PCS_ANER = 6,
268 PCS_ANNPT = 7,
269 PCS_ANLPRNP = 8,
270 PCS_ESR = 15,
271};
272
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273/* IEEE Extened Status Register */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274enum _mii_esr {
275 MII_ESR_1000BX_FD = 0x8000,
276 MII_ESR_1000BX_HD = 0x4000,
277 MII_ESR_1000BT_FD = 0x2000,
278 MII_ESR_1000BT_HD = 0x1000,
279};
280/* PHY Specific Control Register */
Al Viro5b511912008-01-13 14:18:15 +0000281#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282typedef union t_MII_PHY_SCR {
283 u16 image;
284 struct {
285 u16 disable_jabber:1; // bit 0
286 u16 polarity_reversal:1; // bit 1
287 u16 SEQ_test:1; // bit 2
288 u16 _bit_3:1; // bit 3
289 u16 disable_CLK125:1; // bit 4
290 u16 mdi_crossover_mode:2; // bit 6:5
291 u16 enable_ext_dist:1; // bit 7
292 u16 _bit_8_9:2; // bit 9:8
293 u16 force_link:1; // bit 10
294 u16 assert_CRS:1; // bit 11
295 u16 rcv_fifo_depth:2; // bit 13:12
296 u16 xmit_fifo_depth:2; // bit 15:14
297 } bits;
298} PHY_SCR_t, *PPHY_SCR_t;
Al Viro5b511912008-01-13 14:18:15 +0000299#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
301typedef enum t_MII_ADMIN_STATUS {
302 adm_reset,
303 adm_operational,
304 adm_loopback,
305 adm_power_down,
306 adm_isolate
307} MII_ADMIN_t, *PMII_ADMIN_t;
308
309/* Physical Coding Sublayer Management (PCS) */
310/* PCS control and status registers bitmap as the same as MII */
311/* PCS Extended Status register bitmap as the same as MII */
312/* PCS ANAR */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313enum _pcs_anar {
314 PCS_ANAR_NEXT_PAGE = 0x8000,
315 PCS_ANAR_REMOTE_FAULT = 0x3000,
316 PCS_ANAR_ASYMMETRIC = 0x0100,
317 PCS_ANAR_PAUSE = 0x0080,
318 PCS_ANAR_HALF_DUPLEX = 0x0040,
319 PCS_ANAR_FULL_DUPLEX = 0x0020,
320};
321/* PCS ANLPAR */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322enum _pcs_anlpar {
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400323 PCS_ANLPAR_NEXT_PAGE = PCS_ANAR_NEXT_PAGE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 PCS_ANLPAR_REMOTE_FAULT = PCS_ANAR_REMOTE_FAULT,
325 PCS_ANLPAR_ASYMMETRIC = PCS_ANAR_ASYMMETRIC,
326 PCS_ANLPAR_PAUSE = PCS_ANAR_PAUSE,
327 PCS_ANLPAR_HALF_DUPLEX = PCS_ANAR_HALF_DUPLEX,
328 PCS_ANLPAR_FULL_DUPLEX = PCS_ANAR_FULL_DUPLEX,
329};
330
331typedef struct t_SROM {
332 u16 config_param; /* 0x00 */
333 u16 asic_ctrl; /* 0x02 */
334 u16 sub_vendor_id; /* 0x04 */
335 u16 sub_system_id; /* 0x06 */
336 u16 reserved1[12]; /* 0x08-0x1f */
337 u8 mac_addr[6]; /* 0x20-0x25 */
338 u8 reserved2[10]; /* 0x26-0x2f */
339 u8 sib[204]; /* 0x30-0xfb */
340 u32 crc; /* 0xfc-0xff */
341} SROM_t, *PSROM_t;
342
343/* Ioctl custom data */
344struct ioctl_data {
345 char signature[10];
346 int cmd;
347 int len;
348 char *data;
349};
350
351struct mii_data {
352 __u16 reserved;
353 __u16 reg_num;
354 __u16 in_value;
355 __u16 out_value;
356};
357
358/* The Rx and Tx buffer descriptors. */
359struct netdev_desc {
Al Viro78ce8d32007-12-22 18:11:18 +0000360 __le64 next_desc;
361 __le64 status;
362 __le64 fraginfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363};
364
365#define PRIV_ALIGN 15 /* Required alignment mask */
366/* Use __attribute__((aligned (L1_CACHE_BYTES))) to maintain alignment
367 within the structure. */
368struct netdev_private {
369 /* Descriptor rings first for alignment. */
370 struct netdev_desc *rx_ring;
371 struct netdev_desc *tx_ring;
372 struct sk_buff *rx_skbuff[RX_RING_SIZE];
373 struct sk_buff *tx_skbuff[TX_RING_SIZE];
374 dma_addr_t tx_ring_dma;
375 dma_addr_t rx_ring_dma;
376 struct pci_dev *pdev;
Francois Romieu5e3cc4e2012-03-09 18:09:35 +0100377 void __iomem *ioaddr;
378 void __iomem *eeprom_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 spinlock_t tx_lock;
380 spinlock_t rx_lock;
381 struct net_device_stats stats;
382 unsigned int rx_buf_sz; /* Based on MTU+slack. */
383 unsigned int speed; /* Operating speed */
384 unsigned int vlan; /* VLAN Id */
385 unsigned int chip_id; /* PCI table chip id */
386 unsigned int rx_coalesce; /* Maximum frames each RxDMAComplete intr */
387 unsigned int rx_timeout; /* Wait time between RxDMAComplete intr */
388 unsigned int tx_coalesce; /* Maximum frames each tx interrupt */
389 unsigned int full_duplex:1; /* Full-duplex operation requested. */
390 unsigned int an_enable:2; /* Auto-Negotiated Enable */
391 unsigned int jumbo:1; /* Jumbo frame enable */
392 unsigned int coalesce:1; /* Rx coalescing enable */
393 unsigned int tx_flow:1; /* Tx flow control enable */
394 unsigned int rx_flow:1; /* Rx flow control enable */
395 unsigned int phy_media:1; /* 1: fiber, 0: copper */
396 unsigned int link_status:1; /* Current link status */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 struct netdev_desc *last_tx; /* Last Tx descriptor used. */
398 unsigned long cur_rx, old_rx; /* Producer/consumer ring indices */
399 unsigned long cur_tx, old_tx;
400 struct timer_list timer;
401 int wake_polarity;
402 char name[256]; /* net device description */
403 u8 duplex_polarity;
404 u16 mcast_filter[4];
405 u16 advertising; /* NWay media advertisement */
406 u16 negotiate; /* Negotiated media */
407 int phy_addr; /* PHY addresses. */
408};
409
410/* The station address location in the EEPROM. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411/* The struct pci_device_id consist of:
412 vendor, device Vendor and device ID to match (or PCI_ANY_ID)
413 subvendor, subdevice Subsystem vendor and device ID to match (or PCI_ANY_ID)
414 class Device class to match. The class_mask tells which bits
415 class_mask of the class are honored during the comparison.
416 driver_data Data private to the driver.
417*/
Jeff Garzik1f1bd5f2006-06-26 23:47:50 -0400418
Alexey Dobriyana3aa1882010-01-07 11:58:11 +0000419static DEFINE_PCI_DEVICE_TABLE(rio_pci_tbl) = {
Jeff Garzik1f1bd5f2006-06-26 23:47:50 -0400420 {0x1186, 0x4000, PCI_ANY_ID, PCI_ANY_ID, },
Komurodf950822007-08-13 09:45:41 +0900421 {0x13f0, 0x1021, PCI_ANY_ID, PCI_ANY_ID, },
Jeff Garzik1f1bd5f2006-06-26 23:47:50 -0400422 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423};
424MODULE_DEVICE_TABLE (pci, rio_pci_tbl);
425#define TX_TIMEOUT (4*HZ)
426#define PACKET_SIZE 1536
427#define MAX_JUMBO 8000
428#define RIO_IO_SIZE 340
429#define DEFAULT_RXC 5
430#define DEFAULT_RXT 750
431#define DEFAULT_TXC 1
432#define MAX_TXC 8
433#endif /* __DL2K_H__ */