[jme] Protect vlgrp structure by pause RX actions.
[jme.git] / jme.h
CommitLineData
4330c2f2
GFT
1/*
2 * JMicron JMC2x0 series PCIe Ethernet Linux Device Driver
3 *
4 * Copyright 2008 JMicron Technology Corporation
5 * http://www.jmicron.com/
6 *
3bf61c55
GFT
7 * Author: Guo-Fu Tseng <cooldavid@cooldavid.org>
8 *
4330c2f2
GFT
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 */
23
cd0ff491 24#ifndef __JME_H_INCLUDED__
3b70a6fa 25#define __JME_H_INCLUDED__
d7699f87
GFT
26
27#define DRV_NAME "jme"
1e5ebebc 28#define DRV_VERSION "1.0.6.1-jmmod"
cd0ff491 29#define PFX DRV_NAME ": "
d7699f87 30
cd0ff491
GFT
31#define PCI_DEVICE_ID_JMICRON_JMC250 0x0250
32#define PCI_DEVICE_ID_JMICRON_JMC260 0x0260
8d27293f 33
cd0ff491
GFT
34/*
35 * Message related definitions
36 */
37#define JME_DEF_MSG_ENABLE \
38 (NETIF_MSG_PROBE | \
39 NETIF_MSG_LINK | \
40 NETIF_MSG_RX_ERR | \
41 NETIF_MSG_TX_ERR | \
42 NETIF_MSG_HW)
43
44#define jeprintk(pdev, fmt, args...) \
45 printk(KERN_ERR PFX fmt, ## args)
d7699f87 46
3bf61c55 47#ifdef TX_DEBUG
7ca9ebee
GFT
48#define tx_dbg(priv, fmt, args...) \
49 printk(KERN_DEBUG "%s: " fmt, (priv)->dev->name, ##args)
3bf61c55 50#else
7ca9ebee
GFT
51#define tx_dbg(priv, fmt, args...) \
52do { \
53 if (0) \
54 printk(KERN_DEBUG "%s: " fmt, (priv)->dev->name, ##args); \
55} while (0)
3bf61c55
GFT
56#endif
57
7ca9ebee
GFT
58#include <linux/version.h>
59#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,33)
cd0ff491
GFT
60#define jme_msg(msglvl, type, priv, fmt, args...) \
61 if (netif_msg_##type(priv)) \
62 printk(msglvl "%s: " fmt, (priv)->dev->name, ## args)
3bf61c55 63
cd0ff491
GFT
64#define msg_probe(priv, fmt, args...) \
65 jme_msg(KERN_INFO, probe, priv, fmt, ## args)
29bdd921 66
cd0ff491
GFT
67#define msg_link(priv, fmt, args...) \
68 jme_msg(KERN_INFO, link, priv, fmt, ## args)
79ce639c 69
cd0ff491
GFT
70#define msg_intr(priv, fmt, args...) \
71 jme_msg(KERN_INFO, intr, priv, fmt, ## args)
72
73#define msg_rx_err(priv, fmt, args...) \
74 jme_msg(KERN_ERR, rx_err, priv, fmt, ## args)
b3821cc5 75
cd0ff491
GFT
76#define msg_rx_status(priv, fmt, args...) \
77 jme_msg(KERN_INFO, rx_status, priv, fmt, ## args)
4330c2f2 78
cd0ff491
GFT
79#define msg_tx_err(priv, fmt, args...) \
80 jme_msg(KERN_ERR, tx_err, priv, fmt, ## args)
4330c2f2 81
cd0ff491
GFT
82#define msg_tx_done(priv, fmt, args...) \
83 jme_msg(KERN_INFO, tx_done, priv, fmt, ## args)
d7699f87 84
cd0ff491
GFT
85#define msg_tx_queued(priv, fmt, args...) \
86 jme_msg(KERN_INFO, tx_queued, priv, fmt, ## args)
87
88#define msg_hw(priv, fmt, args...) \
89 jme_msg(KERN_ERR, hw, priv, fmt, ## args)
7ca9ebee 90#endif
cd0ff491
GFT
91
92/*
93 * Extra PCI Configuration space interface
94 */
95#define PCI_DCSR_MRRS 0x59
96#define PCI_DCSR_MRRS_MASK 0x70
97
98enum pci_dcsr_mrrs_vals {
4330c2f2
GFT
99 MRRS_128B = 0x00,
100 MRRS_256B = 0x10,
101 MRRS_512B = 0x20,
102 MRRS_1024B = 0x30,
103 MRRS_2048B = 0x40,
104 MRRS_4096B = 0x50,
105};
d7699f87 106
cd0ff491
GFT
107#define PCI_SPI 0xB0
108
109enum pci_spi_bits {
110 SPI_EN = 0x10,
111 SPI_MISO = 0x08,
112 SPI_MOSI = 0x04,
113 SPI_SCLK = 0x02,
114 SPI_CS = 0x01,
115};
116
117struct jme_spi_op {
118 void __user *uwbuf;
119 void __user *urbuf;
120 __u8 wn; /* Number of write actions */
121 __u8 rn; /* Number of read actions */
122 __u8 bitn; /* Number of bits per action */
123 __u8 spd; /* The maxim acceptable speed of controller, in MHz.*/
124 __u8 mode; /* CPOL, CPHA, and Duplex mode of SPI */
125
126 /* Internal use only */
127 u8 *kwbuf;
128 u8 *krbuf;
129 u8 sr;
130 u16 halfclk; /* Half of clock cycle calculated from spd, in ns */
131};
79ce639c 132
cd0ff491
GFT
133enum jme_spi_op_bits {
134 SPI_MODE_CPHA = 0x01,
135 SPI_MODE_CPOL = 0x02,
136 SPI_MODE_DUP = 0x80,
137};
138
139#define HALF_US 500 /* 500 ns */
140#define JMESPIIOCTL SIOCDEVPRIVATE
141
142/*
143 * Dynamic(adaptive)/Static PCC values
144 */
3bf61c55 145enum dynamic_pcc_values {
192570e0 146 PCC_OFF = 0,
3bf61c55
GFT
147 PCC_P1 = 1,
148 PCC_P2 = 2,
149 PCC_P3 = 3,
150
192570e0 151 PCC_OFF_TO = 0,
3bf61c55 152 PCC_P1_TO = 1,
192570e0
GFT
153 PCC_P2_TO = 64,
154 PCC_P3_TO = 128,
3bf61c55 155
192570e0 156 PCC_OFF_CNT = 0,
3bf61c55 157 PCC_P1_CNT = 1,
192570e0
GFT
158 PCC_P2_CNT = 16,
159 PCC_P3_CNT = 32,
3bf61c55
GFT
160};
161struct dynpcc_info {
3bf61c55
GFT
162 unsigned long last_bytes;
163 unsigned long last_pkts;
79ce639c 164 unsigned long intr_cnt;
3bf61c55
GFT
165 unsigned char cur;
166 unsigned char attempt;
167 unsigned char cnt;
168};
79ce639c 169#define PCC_INTERVAL_US 100000
cd0ff491
GFT
170#define PCC_INTERVAL (HZ / (1000000 / PCC_INTERVAL_US))
171#define PCC_P3_THRESHOLD (2 * 1024 * 1024)
79ce639c
GFT
172#define PCC_P2_THRESHOLD 800
173#define PCC_INTR_THRESHOLD 800
47220951 174#define PCC_TX_TO 1000
b3821cc5 175#define PCC_TX_CNT 8
3bf61c55 176
d7699f87
GFT
177/*
178 * TX/RX Descriptors
4330c2f2 179 *
cd0ff491 180 * TX/RX Ring DESC Count Must be multiple of 16 and <= 1024
d7699f87 181 */
4330c2f2 182#define RING_DESC_ALIGN 16 /* Descriptor alignment */
d7699f87
GFT
183#define TX_DESC_SIZE 16
184#define TX_RING_NR 8
cd0ff491 185#define TX_RING_ALLOC_SIZE(s) ((s * TX_DESC_SIZE) + RING_DESC_ALIGN)
d7699f87 186
3bf61c55 187struct txdesc {
d7699f87 188 union {
cd0ff491
GFT
189 __u8 all[16];
190 __le32 dw[4];
d7699f87
GFT
191 struct {
192 /* DW0 */
cd0ff491
GFT
193 __le16 vlan;
194 __u8 rsv1;
195 __u8 flags;
d7699f87
GFT
196
197 /* DW1 */
cd0ff491
GFT
198 __le16 datalen;
199 __le16 mss;
d7699f87
GFT
200
201 /* DW2 */
cd0ff491
GFT
202 __le16 pktsize;
203 __le16 rsv2;
d7699f87
GFT
204
205 /* DW3 */
cd0ff491 206 __le32 bufaddr;
d7699f87 207 } desc1;
3bf61c55
GFT
208 struct {
209 /* DW0 */
cd0ff491
GFT
210 __le16 rsv1;
211 __u8 rsv2;
212 __u8 flags;
3bf61c55
GFT
213
214 /* DW1 */
cd0ff491
GFT
215 __le16 datalen;
216 __le16 rsv3;
3bf61c55
GFT
217
218 /* DW2 */
cd0ff491 219 __le32 bufaddrh;
3bf61c55
GFT
220
221 /* DW3 */
cd0ff491 222 __le32 bufaddrl;
3bf61c55 223 } desc2;
8c198884
GFT
224 struct {
225 /* DW0 */
cd0ff491
GFT
226 __u8 ehdrsz;
227 __u8 rsv1;
228 __u8 rsv2;
229 __u8 flags;
8c198884
GFT
230
231 /* DW1 */
cd0ff491
GFT
232 __le16 trycnt;
233 __le16 segcnt;
8c198884
GFT
234
235 /* DW2 */
cd0ff491
GFT
236 __le16 pktsz;
237 __le16 rsv3;
8c198884
GFT
238
239 /* DW3 */
cd0ff491 240 __le32 bufaddrl;
8c198884 241 } descwb;
d7699f87
GFT
242 };
243};
cd0ff491 244
8c198884 245enum jme_txdesc_flags_bits {
d7699f87
GFT
246 TXFLAG_OWN = 0x80,
247 TXFLAG_INT = 0x40,
3bf61c55 248 TXFLAG_64BIT = 0x20,
d7699f87
GFT
249 TXFLAG_TCPCS = 0x10,
250 TXFLAG_UDPCS = 0x08,
251 TXFLAG_IPCS = 0x04,
252 TXFLAG_LSEN = 0x02,
253 TXFLAG_TAGON = 0x01,
254};
cd0ff491 255
b3821cc5 256#define TXDESC_MSS_SHIFT 2
0ede469c 257enum jme_txwbdesc_flags_bits {
8c198884
GFT
258 TXWBFLAG_OWN = 0x80,
259 TXWBFLAG_INT = 0x40,
260 TXWBFLAG_TMOUT = 0x20,
261 TXWBFLAG_TRYOUT = 0x10,
262 TXWBFLAG_COL = 0x08,
263
264 TXWBFLAG_ALLERR = TXWBFLAG_TMOUT |
265 TXWBFLAG_TRYOUT |
266 TXWBFLAG_COL,
267};
d7699f87 268
d7699f87
GFT
269#define RX_DESC_SIZE 16
270#define RX_RING_NR 4
cd0ff491 271#define RX_RING_ALLOC_SIZE(s) ((s * RX_DESC_SIZE) + RING_DESC_ALIGN)
d7699f87 272#define RX_BUF_DMA_ALIGN 8
3bf61c55 273#define RX_PREPAD_SIZE 10
79ce639c
GFT
274#define ETH_CRC_LEN 2
275#define RX_VLANHDR_LEN 2
276#define RX_EXTRA_LEN (RX_PREPAD_SIZE + \
277 ETH_HLEN + \
278 ETH_CRC_LEN + \
279 RX_VLANHDR_LEN + \
280 RX_BUF_DMA_ALIGN)
d7699f87 281
3bf61c55 282struct rxdesc {
d7699f87 283 union {
cd0ff491
GFT
284 __u8 all[16];
285 __le32 dw[4];
d7699f87
GFT
286 struct {
287 /* DW0 */
cd0ff491
GFT
288 __le16 rsv2;
289 __u8 rsv1;
290 __u8 flags;
d7699f87
GFT
291
292 /* DW1 */
cd0ff491
GFT
293 __le16 datalen;
294 __le16 wbcpl;
d7699f87
GFT
295
296 /* DW2 */
cd0ff491 297 __le32 bufaddrh;
d7699f87
GFT
298
299 /* DW3 */
cd0ff491 300 __le32 bufaddrl;
d7699f87
GFT
301 } desc1;
302 struct {
303 /* DW0 */
cd0ff491
GFT
304 __le16 vlan;
305 __le16 flags;
d7699f87
GFT
306
307 /* DW1 */
cd0ff491
GFT
308 __le16 framesize;
309 __u8 errstat;
310 __u8 desccnt;
d7699f87
GFT
311
312 /* DW2 */
cd0ff491 313 __le32 rsshash;
d7699f87
GFT
314
315 /* DW3 */
cd0ff491
GFT
316 __u8 hashfun;
317 __u8 hashtype;
318 __le16 resrv;
d7699f87
GFT
319 } descwb;
320 };
321};
cd0ff491 322
d7699f87
GFT
323enum jme_rxdesc_flags_bits {
324 RXFLAG_OWN = 0x80,
325 RXFLAG_INT = 0x40,
326 RXFLAG_64BIT = 0x20,
327};
cd0ff491 328
d7699f87 329enum jme_rxwbdesc_flags_bits {
4330c2f2
GFT
330 RXWBFLAG_OWN = 0x8000,
331 RXWBFLAG_INT = 0x4000,
332 RXWBFLAG_MF = 0x2000,
333 RXWBFLAG_64BIT = 0x2000,
334 RXWBFLAG_TCPON = 0x1000,
335 RXWBFLAG_UDPON = 0x0800,
336 RXWBFLAG_IPCS = 0x0400,
337 RXWBFLAG_TCPCS = 0x0200,
338 RXWBFLAG_UDPCS = 0x0100,
339 RXWBFLAG_TAGON = 0x0080,
340 RXWBFLAG_IPV4 = 0x0040,
341 RXWBFLAG_IPV6 = 0x0020,
342 RXWBFLAG_PAUSE = 0x0010,
343 RXWBFLAG_MAGIC = 0x0008,
344 RXWBFLAG_WAKEUP = 0x0004,
345 RXWBFLAG_DEST = 0x0003,
346 RXWBFLAG_DEST_UNI = 0x0001,
347 RXWBFLAG_DEST_MUL = 0x0002,
348 RXWBFLAG_DEST_BRO = 0x0003,
d7699f87 349};
cd0ff491 350
d7699f87
GFT
351enum jme_rxwbdesc_desccnt_mask {
352 RXWBDCNT_WBCPL = 0x80,
353 RXWBDCNT_DCNT = 0x7F,
354};
cd0ff491 355
4330c2f2
GFT
356enum jme_rxwbdesc_errstat_bits {
357 RXWBERR_LIMIT = 0x80,
358 RXWBERR_MIIER = 0x40,
359 RXWBERR_NIBON = 0x20,
360 RXWBERR_COLON = 0x10,
361 RXWBERR_ABORT = 0x08,
362 RXWBERR_SHORT = 0x04,
363 RXWBERR_OVERUN = 0x02,
364 RXWBERR_CRCERR = 0x01,
365 RXWBERR_ALLERR = 0xFF,
366};
367
cd0ff491
GFT
368/*
369 * Buffer information corresponding to ring descriptors.
370 */
4330c2f2
GFT
371struct jme_buffer_info {
372 struct sk_buff *skb;
373 dma_addr_t mapping;
374 int len;
3bf61c55 375 int nr_desc;
cdcdc9eb 376 unsigned long start_xmit;
4330c2f2 377};
d7699f87 378
cd0ff491
GFT
379/*
380 * The structure holding buffer information and ring descriptors all together.
381 */
d7699f87 382struct jme_ring {
cd0ff491
GFT
383 void *alloc; /* pointer to allocated memory */
384 void *desc; /* pointer to ring memory */
385 dma_addr_t dmaalloc; /* phys address of ring alloc */
386 dma_addr_t dma; /* phys address for ring dma */
d7699f87 387
4330c2f2 388 /* Buffer information corresponding to each descriptor */
0ede469c 389 struct jme_buffer_info *bufinf;
d7699f87 390
cd0ff491
GFT
391 int next_to_use;
392 atomic_t next_to_clean;
79ce639c 393 atomic_t nr_free;
d7699f87
GFT
394};
395
3b70a6fa
GFT
396#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18)
397#define false 0
398#define true 0
399#define netdev_alloc_skb(dev, len) dev_alloc_skb(len)
400#define PCI_VENDOR_ID_JMICRON 0x197B
401#endif
402
403#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,19)
404#define PCI_VDEVICE(vendor, device) \
405 PCI_VENDOR_ID_##vendor, (device), \
406 PCI_ANY_ID, PCI_ANY_ID, 0, 0
407#endif
408
85776f33
GFT
409#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,21)
410#define NET_STAT(priv) priv->stats
411#define NETDEV_GET_STATS(netdev, fun_ptr) \
412 netdev->get_stats = fun_ptr
413#define DECLARE_NET_DEVICE_STATS struct net_device_stats stats;
3b70a6fa
GFT
414static inline struct iphdr *ip_hdr(const struct sk_buff *skb)
415{
416 return skb->nh.iph;
417}
418
419static inline struct ipv6hdr *ipv6_hdr(const struct sk_buff *skb)
420{
421 return skb->nh.ipv6h;
422}
423
424static inline struct tcphdr *tcp_hdr(const struct sk_buff *skb)
425{
426 return skb->h.th;
427}
85776f33 428#else
0ede469c 429#define NET_STAT(priv) (priv->dev->stats)
3bf61c55
GFT
430#define NETDEV_GET_STATS(netdev, fun_ptr)
431#define DECLARE_NET_DEVICE_STATS
85776f33 432#endif
3bf61c55 433
85776f33
GFT
434#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,23)
435#define DECLARE_NAPI_STRUCT
436#define NETIF_NAPI_SET(dev, napis, pollfn, q) \
437 dev->poll = pollfn; \
438 dev->weight = q;
439#define JME_NAPI_HOLDER(holder) struct net_device *holder
440#define JME_NAPI_WEIGHT(w) int *w
441#define JME_NAPI_WEIGHT_VAL(w) *w
442#define JME_NAPI_WEIGHT_SET(w, r) *w = r
3b70a6fa 443#define DECLARE_NETDEV struct net_device *netdev = jme->dev;
85776f33
GFT
444#define JME_RX_COMPLETE(dev, napis) netif_rx_complete(dev)
445#define JME_NAPI_ENABLE(priv) netif_poll_enable(priv->dev);
446#define JME_NAPI_DISABLE(priv) netif_poll_disable(priv->dev);
447#define JME_RX_SCHEDULE_PREP(priv) \
448 netif_rx_schedule_prep(priv->dev)
449#define JME_RX_SCHEDULE(priv) \
450 __netif_rx_schedule(priv->dev);
0ede469c 451#else
3b70a6fa
GFT
452#define DECLARE_NAPI_STRUCT struct napi_struct napi;
453#define NETIF_NAPI_SET(dev, napis, pollfn, q) \
454 netif_napi_add(dev, napis, pollfn, q);
455#define JME_NAPI_HOLDER(holder) struct napi_struct *holder
456#define JME_NAPI_WEIGHT(w) int w
457#define JME_NAPI_WEIGHT_VAL(w) w
458#define JME_NAPI_WEIGHT_SET(w, r)
459#define DECLARE_NETDEV
460#define JME_RX_COMPLETE(dev, napis) napi_complete(napis)
461#define JME_NAPI_ENABLE(priv) napi_enable(&priv->napi);
462#define JME_NAPI_DISABLE(priv) \
463 if (!napi_disable_pending(&priv->napi)) \
464 napi_disable(&priv->napi);
465#define JME_RX_SCHEDULE_PREP(priv) \
466 napi_schedule_prep(&priv->napi)
467#define JME_RX_SCHEDULE(priv) \
468 __napi_schedule(&priv->napi);
85776f33 469#endif
cdcdc9eb 470
d7699f87
GFT
471/*
472 * Jmac Adapter Private data
473 */
474struct jme_adapter {
cd0ff491
GFT
475 struct pci_dev *pdev;
476 struct net_device *dev;
477 void __iomem *regs;
d7699f87
GFT
478 struct mii_if_info mii_if;
479 struct jme_ring rxring[RX_RING_NR];
480 struct jme_ring txring[TX_RING_NR];
d7699f87 481 spinlock_t phy_lock;
fcf45b4c 482 spinlock_t macaddr_lock;
8c198884 483 spinlock_t rxmcs_lock;
fcf45b4c 484 struct tasklet_struct rxempty_task;
4330c2f2
GFT
485 struct tasklet_struct rxclean_task;
486 struct tasklet_struct txclean_task;
487 struct tasklet_struct linkch_task;
79ce639c 488 struct tasklet_struct pcc_task;
cd0ff491
GFT
489 unsigned long flags;
490 u32 reg_txcs;
491 u32 reg_txpfc;
492 u32 reg_rxcs;
493 u32 reg_rxmcs;
494 u32 reg_ghc;
495 u32 reg_pmcs;
496 u32 phylink;
497 u32 tx_ring_size;
498 u32 tx_ring_mask;
499 u32 tx_wake_threshold;
500 u32 rx_ring_size;
501 u32 rx_ring_mask;
502 u8 mrrs;
503 unsigned int fpgaver;
58c92f28 504 unsigned int chiprev;
cd0ff491
GFT
505 u8 rev;
506 u32 msg_enable;
29bdd921
GFT
507 struct ethtool_cmd old_ecmd;
508 unsigned int old_mtu;
cd0ff491 509 struct vlan_group *vlgrp;
3bf61c55
GFT
510 struct dynpcc_info dpi;
511 atomic_t intr_sem;
fcf45b4c
GFT
512 atomic_t link_changing;
513 atomic_t tx_cleaning;
514 atomic_t rx_cleaning;
192570e0 515 atomic_t rx_empty;
cdcdc9eb
GFT
516 int (*jme_rx)(struct sk_buff *skb);
517 int (*jme_vlan_rx)(struct sk_buff *skb,
518 struct vlan_group *grp,
519 unsigned short vlan_tag);
520 DECLARE_NAPI_STRUCT
3bf61c55 521 DECLARE_NET_DEVICE_STATS
d7699f87 522};
cd0ff491 523
3b70a6fa
GFT
524#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,21)
525static struct net_device_stats *
526jme_get_stats(struct net_device *netdev)
527{
528 struct jme_adapter *jme = netdev_priv(netdev);
529 return &jme->stats;
530}
531#endif
532
79ce639c 533enum jme_flags_bits {
cd0ff491
GFT
534 JME_FLAG_MSI = 1,
535 JME_FLAG_SSET = 2,
536 JME_FLAG_TXCSUM = 3,
537 JME_FLAG_TSO = 4,
538 JME_FLAG_POLL = 5,
539 JME_FLAG_SHUTDOWN = 6,
8c198884 540};
cd0ff491
GFT
541
542#define TX_TIMEOUT (5 * HZ)
186fc259 543#define JME_REG_LEN 0x500
cd0ff491 544#define MAX_ETHERNET_JUMBO_PACKET_SIZE 9216
8c198884 545
85776f33 546#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,23)
7ee473a3 547static inline struct jme_adapter*
85776f33
GFT
548jme_napi_priv(struct net_device *holder)
549{
7ee473a3 550 struct jme_adapter *jme;
85776f33
GFT
551 jme = netdev_priv(holder);
552 return jme;
553}
554#else
7ee473a3 555static inline struct jme_adapter*
cdcdc9eb
GFT
556jme_napi_priv(struct napi_struct *napi)
557{
7ee473a3 558 struct jme_adapter *jme;
cdcdc9eb
GFT
559 jme = container_of(napi, struct jme_adapter, napi);
560 return jme;
561}
85776f33 562#endif
d7699f87
GFT
563
564/*
565 * MMaped I/O Resters
566 */
567enum jme_iomap_offsets {
4330c2f2
GFT
568 JME_MAC = 0x0000,
569 JME_PHY = 0x0400,
d7699f87 570 JME_MISC = 0x0800,
4330c2f2 571 JME_RSS = 0x0C00,
d7699f87
GFT
572};
573
8c198884
GFT
574enum jme_iomap_lens {
575 JME_MAC_LEN = 0x80,
576 JME_PHY_LEN = 0x58,
577 JME_MISC_LEN = 0x98,
578 JME_RSS_LEN = 0xFF,
579};
580
d7699f87
GFT
581enum jme_iomap_regs {
582 JME_TXCS = JME_MAC | 0x00, /* Transmit Control and Status */
3bf61c55
GFT
583 JME_TXDBA_LO = JME_MAC | 0x04, /* Transmit Queue Desc Base Addr */
584 JME_TXDBA_HI = JME_MAC | 0x08, /* Transmit Queue Desc Base Addr */
d7699f87
GFT
585 JME_TXQDC = JME_MAC | 0x0C, /* Transmit Queue Desc Count */
586 JME_TXNDA = JME_MAC | 0x10, /* Transmit Queue Next Desc Addr */
587 JME_TXMCS = JME_MAC | 0x14, /* Transmit MAC Control Status */
588 JME_TXPFC = JME_MAC | 0x18, /* Transmit Pause Frame Control */
589 JME_TXTRHD = JME_MAC | 0x1C, /* Transmit Timer/Retry@Half-Dup */
590
591 JME_RXCS = JME_MAC | 0x20, /* Receive Control and Status */
3bf61c55
GFT
592 JME_RXDBA_LO = JME_MAC | 0x24, /* Receive Queue Desc Base Addr */
593 JME_RXDBA_HI = JME_MAC | 0x28, /* Receive Queue Desc Base Addr */
d7699f87
GFT
594 JME_RXQDC = JME_MAC | 0x2C, /* Receive Queue Desc Count */
595 JME_RXNDA = JME_MAC | 0x30, /* Receive Queue Next Desc Addr */
596 JME_RXMCS = JME_MAC | 0x34, /* Receive MAC Control Status */
4330c2f2
GFT
597 JME_RXUMA_LO = JME_MAC | 0x38, /* Receive Unicast MAC Address */
598 JME_RXUMA_HI = JME_MAC | 0x3C, /* Receive Unicast MAC Address */
3bf61c55
GFT
599 JME_RXMCHT_LO = JME_MAC | 0x40, /* Recv Multicast Addr HashTable */
600 JME_RXMCHT_HI = JME_MAC | 0x44, /* Recv Multicast Addr HashTable */
d7699f87
GFT
601 JME_WFODP = JME_MAC | 0x48, /* Wakeup Frame Output Data Port */
602 JME_WFOI = JME_MAC | 0x4C, /* Wakeup Frame Output Interface */
603
604 JME_SMI = JME_MAC | 0x50, /* Station Management Interface */
605 JME_GHC = JME_MAC | 0x54, /* Global Host Control */
606 JME_PMCS = JME_MAC | 0x60, /* Power Management Control/Stat */
607
608
3bf61c55 609 JME_PHY_CS = JME_PHY | 0x28, /* PHY Ctrl and Status Register */
d7699f87
GFT
610 JME_PHY_LINK = JME_PHY | 0x30, /* PHY Link Status Register */
611 JME_SMBCSR = JME_PHY | 0x40, /* SMB Control and Status */
186fc259 612 JME_SMBINTF = JME_PHY | 0x44, /* SMB Interface */
d7699f87
GFT
613
614
cd0ff491
GFT
615 JME_TMCSR = JME_MISC | 0x00, /* Timer Control/Status Register */
616 JME_GPREG0 = JME_MISC | 0x08, /* General purpose REG-0 */
617 JME_GPREG1 = JME_MISC | 0x0C, /* General purpose REG-1 */
618 JME_IEVE = JME_MISC | 0x20, /* Interrupt Event Status */
619 JME_IREQ = JME_MISC | 0x24, /* Intr Req Status(For Debug) */
620 JME_IENS = JME_MISC | 0x28, /* Intr Enable - Setting Port */
621 JME_IENC = JME_MISC | 0x2C, /* Interrupt Enable - Clear Port */
622 JME_PCCRX0 = JME_MISC | 0x30, /* PCC Control for RX Queue 0 */
623 JME_PCCTX = JME_MISC | 0x40, /* PCC Control for TX Queues */
624 JME_CHIPMODE = JME_MISC | 0x44, /* Identify FPGA Version */
625 JME_SHBA_HI = JME_MISC | 0x48, /* Shadow Register Base HI */
626 JME_SHBA_LO = JME_MISC | 0x4C, /* Shadow Register Base LO */
627 JME_TIMER1 = JME_MISC | 0x70, /* Timer1 */
628 JME_TIMER2 = JME_MISC | 0x74, /* Timer2 */
629 JME_APMC = JME_MISC | 0x7C, /* Aggressive Power Mode Control */
630 JME_PCCSRX0 = JME_MISC | 0x80, /* PCC Status of RX0 */
d7699f87
GFT
631};
632
633/*
634 * TX Control/Status Bits
635 */
636enum jme_txcs_bits {
637 TXCS_QUEUE7S = 0x00008000,
638 TXCS_QUEUE6S = 0x00004000,
639 TXCS_QUEUE5S = 0x00002000,
640 TXCS_QUEUE4S = 0x00001000,
641 TXCS_QUEUE3S = 0x00000800,
642 TXCS_QUEUE2S = 0x00000400,
643 TXCS_QUEUE1S = 0x00000200,
644 TXCS_QUEUE0S = 0x00000100,
645 TXCS_FIFOTH = 0x000000C0,
646 TXCS_DMASIZE = 0x00000030,
647 TXCS_BURST = 0x00000004,
648 TXCS_ENABLE = 0x00000001,
649};
cd0ff491 650
d7699f87
GFT
651enum jme_txcs_value {
652 TXCS_FIFOTH_16QW = 0x000000C0,
653 TXCS_FIFOTH_12QW = 0x00000080,
654 TXCS_FIFOTH_8QW = 0x00000040,
655 TXCS_FIFOTH_4QW = 0x00000000,
656
657 TXCS_DMASIZE_64B = 0x00000000,
658 TXCS_DMASIZE_128B = 0x00000010,
659 TXCS_DMASIZE_256B = 0x00000020,
660 TXCS_DMASIZE_512B = 0x00000030,
661
662 TXCS_SELECT_QUEUE0 = 0x00000000,
663 TXCS_SELECT_QUEUE1 = 0x00010000,
664 TXCS_SELECT_QUEUE2 = 0x00020000,
665 TXCS_SELECT_QUEUE3 = 0x00030000,
666 TXCS_SELECT_QUEUE4 = 0x00040000,
667 TXCS_SELECT_QUEUE5 = 0x00050000,
668 TXCS_SELECT_QUEUE6 = 0x00060000,
669 TXCS_SELECT_QUEUE7 = 0x00070000,
670
671 TXCS_DEFAULT = TXCS_FIFOTH_4QW |
d7699f87
GFT
672 TXCS_BURST,
673};
cd0ff491 674
29bdd921 675#define JME_TX_DISABLE_TIMEOUT 10 /* 10 msec */
d7699f87
GFT
676
677/*
678 * TX MAC Control/Status Bits
679 */
680enum jme_txmcs_bit_masks {
681 TXMCS_IFG2 = 0xC0000000,
682 TXMCS_IFG1 = 0x30000000,
683 TXMCS_TTHOLD = 0x00000300,
684 TXMCS_FBURST = 0x00000080,
685 TXMCS_CARRIEREXT = 0x00000040,
686 TXMCS_DEFER = 0x00000020,
687 TXMCS_BACKOFF = 0x00000010,
688 TXMCS_CARRIERSENSE = 0x00000008,
689 TXMCS_COLLISION = 0x00000004,
690 TXMCS_CRC = 0x00000002,
691 TXMCS_PADDING = 0x00000001,
692};
cd0ff491 693
d7699f87
GFT
694enum jme_txmcs_values {
695 TXMCS_IFG2_6_4 = 0x00000000,
696 TXMCS_IFG2_8_5 = 0x40000000,
697 TXMCS_IFG2_10_6 = 0x80000000,
698 TXMCS_IFG2_12_7 = 0xC0000000,
699
700 TXMCS_IFG1_8_4 = 0x00000000,
701 TXMCS_IFG1_12_6 = 0x10000000,
702 TXMCS_IFG1_16_8 = 0x20000000,
703 TXMCS_IFG1_20_10 = 0x30000000,
704
705 TXMCS_TTHOLD_1_8 = 0x00000000,
706 TXMCS_TTHOLD_1_4 = 0x00000100,
707 TXMCS_TTHOLD_1_2 = 0x00000200,
708 TXMCS_TTHOLD_FULL = 0x00000300,
709
710 TXMCS_DEFAULT = TXMCS_IFG2_8_5 |
711 TXMCS_IFG1_16_8 |
712 TXMCS_TTHOLD_FULL |
713 TXMCS_DEFER |
714 TXMCS_CRC |
715 TXMCS_PADDING,
716};
717
8c198884
GFT
718enum jme_txpfc_bits_masks {
719 TXPFC_VLAN_TAG = 0xFFFF0000,
720 TXPFC_VLAN_EN = 0x00008000,
721 TXPFC_PF_EN = 0x00000001,
722};
723
724enum jme_txtrhd_bits_masks {
725 TXTRHD_TXPEN = 0x80000000,
726 TXTRHD_TXP = 0x7FFFFF00,
727 TXTRHD_TXREN = 0x00000080,
728 TXTRHD_TXRL = 0x0000007F,
729};
cd0ff491 730
8c198884
GFT
731enum jme_txtrhd_shifts {
732 TXTRHD_TXP_SHIFT = 8,
733 TXTRHD_TXRL_SHIFT = 0,
734};
735
d7699f87
GFT
736/*
737 * RX Control/Status Bits
738 */
4330c2f2 739enum jme_rxcs_bit_masks {
3bf61c55
GFT
740 /* FIFO full threshold for transmitting Tx Pause Packet */
741 RXCS_FIFOTHTP = 0x30000000,
742 /* FIFO threshold for processing next packet */
743 RXCS_FIFOTHNP = 0x0C000000,
4330c2f2
GFT
744 RXCS_DMAREQSZ = 0x03000000, /* DMA Request Size */
745 RXCS_QUEUESEL = 0x00030000, /* Queue selection */
746 RXCS_RETRYGAP = 0x0000F000, /* RX Desc full retry gap */
747 RXCS_RETRYCNT = 0x00000F00, /* RX Desc full retry counter */
748 RXCS_WAKEUP = 0x00000040, /* Enable receive wakeup packet */
749 RXCS_MAGIC = 0x00000020, /* Enable receive magic packet */
750 RXCS_SHORT = 0x00000010, /* Enable receive short packet */
751 RXCS_ABORT = 0x00000008, /* Enable receive errorr packet */
752 RXCS_QST = 0x00000004, /* Receive queue start */
753 RXCS_SUSPEND = 0x00000002,
d7699f87
GFT
754 RXCS_ENABLE = 0x00000001,
755};
cd0ff491 756
4330c2f2
GFT
757enum jme_rxcs_values {
758 RXCS_FIFOTHTP_16T = 0x00000000,
759 RXCS_FIFOTHTP_32T = 0x10000000,
760 RXCS_FIFOTHTP_64T = 0x20000000,
761 RXCS_FIFOTHTP_128T = 0x30000000,
762
763 RXCS_FIFOTHNP_16QW = 0x00000000,
764 RXCS_FIFOTHNP_32QW = 0x04000000,
765 RXCS_FIFOTHNP_64QW = 0x08000000,
766 RXCS_FIFOTHNP_128QW = 0x0C000000,
767
768 RXCS_DMAREQSZ_16B = 0x00000000,
769 RXCS_DMAREQSZ_32B = 0x01000000,
770 RXCS_DMAREQSZ_64B = 0x02000000,
771 RXCS_DMAREQSZ_128B = 0x03000000,
772
773 RXCS_QUEUESEL_Q0 = 0x00000000,
774 RXCS_QUEUESEL_Q1 = 0x00010000,
775 RXCS_QUEUESEL_Q2 = 0x00020000,
776 RXCS_QUEUESEL_Q3 = 0x00030000,
777
778 RXCS_RETRYGAP_256ns = 0x00000000,
779 RXCS_RETRYGAP_512ns = 0x00001000,
780 RXCS_RETRYGAP_1024ns = 0x00002000,
781 RXCS_RETRYGAP_2048ns = 0x00003000,
782 RXCS_RETRYGAP_4096ns = 0x00004000,
783 RXCS_RETRYGAP_8192ns = 0x00005000,
784 RXCS_RETRYGAP_16384ns = 0x00006000,
785 RXCS_RETRYGAP_32768ns = 0x00007000,
786
787 RXCS_RETRYCNT_0 = 0x00000000,
788 RXCS_RETRYCNT_4 = 0x00000100,
789 RXCS_RETRYCNT_8 = 0x00000200,
790 RXCS_RETRYCNT_12 = 0x00000300,
791 RXCS_RETRYCNT_16 = 0x00000400,
792 RXCS_RETRYCNT_20 = 0x00000500,
793 RXCS_RETRYCNT_24 = 0x00000600,
794 RXCS_RETRYCNT_28 = 0x00000700,
795 RXCS_RETRYCNT_32 = 0x00000800,
796 RXCS_RETRYCNT_36 = 0x00000900,
797 RXCS_RETRYCNT_40 = 0x00000A00,
798 RXCS_RETRYCNT_44 = 0x00000B00,
799 RXCS_RETRYCNT_48 = 0x00000C00,
800 RXCS_RETRYCNT_52 = 0x00000D00,
801 RXCS_RETRYCNT_56 = 0x00000E00,
802 RXCS_RETRYCNT_60 = 0x00000F00,
803
804 RXCS_DEFAULT = RXCS_FIFOTHTP_128T |
79ce639c 805 RXCS_FIFOTHNP_128QW |
4330c2f2
GFT
806 RXCS_DMAREQSZ_128B |
807 RXCS_RETRYGAP_256ns |
808 RXCS_RETRYCNT_32,
809};
cd0ff491 810
29bdd921 811#define JME_RX_DISABLE_TIMEOUT 10 /* 10 msec */
d7699f87
GFT
812
813/*
814 * RX MAC Control/Status Bits
815 */
816enum jme_rxmcs_bits {
817 RXMCS_ALLFRAME = 0x00000800,
818 RXMCS_BRDFRAME = 0x00000400,
819 RXMCS_MULFRAME = 0x00000200,
820 RXMCS_UNIFRAME = 0x00000100,
821 RXMCS_ALLMULFRAME = 0x00000080,
822 RXMCS_MULFILTERED = 0x00000040,
3bf61c55
GFT
823 RXMCS_RXCOLLDEC = 0x00000020,
824 RXMCS_FLOWCTRL = 0x00000008,
825 RXMCS_VTAGRM = 0x00000004,
826 RXMCS_PREPAD = 0x00000002,
827 RXMCS_CHECKSUM = 0x00000001,
b3821cc5 828
8c198884
GFT
829 RXMCS_DEFAULT = RXMCS_VTAGRM |
830 RXMCS_PREPAD |
831 RXMCS_FLOWCTRL |
832 RXMCS_CHECKSUM,
d7699f87
GFT
833};
834
835/*
b3821cc5
GFT
836 * Wakeup Frame setup interface registers
837 */
838#define WAKEUP_FRAME_NR 8
839#define WAKEUP_FRAME_MASK_DWNR 4
cd0ff491 840
b3821cc5
GFT
841enum jme_wfoi_bit_masks {
842 WFOI_MASK_SEL = 0x00000070,
843 WFOI_CRC_SEL = 0x00000008,
844 WFOI_FRAME_SEL = 0x00000007,
845};
cd0ff491 846
b3821cc5
GFT
847enum jme_wfoi_shifts {
848 WFOI_MASK_SHIFT = 4,
849};
850
851/*
d7699f87
GFT
852 * SMI Related definitions
853 */
cd0ff491 854enum jme_smi_bit_mask {
d7699f87
GFT
855 SMI_DATA_MASK = 0xFFFF0000,
856 SMI_REG_ADDR_MASK = 0x0000F800,
857 SMI_PHY_ADDR_MASK = 0x000007C0,
858 SMI_OP_WRITE = 0x00000020,
3bf61c55
GFT
859 /* Set to 1, after req done it'll be cleared to 0 */
860 SMI_OP_REQ = 0x00000010,
d7699f87
GFT
861 SMI_OP_MDIO = 0x00000008, /* Software assess In/Out */
862 SMI_OP_MDOE = 0x00000004, /* Software Output Enable */
863 SMI_OP_MDC = 0x00000002, /* Software CLK Control */
864 SMI_OP_MDEN = 0x00000001, /* Software access Enable */
865};
cd0ff491
GFT
866
867enum jme_smi_bit_shift {
d7699f87
GFT
868 SMI_DATA_SHIFT = 16,
869 SMI_REG_ADDR_SHIFT = 11,
870 SMI_PHY_ADDR_SHIFT = 6,
871};
cd0ff491
GFT
872
873static inline u32 smi_reg_addr(int x)
d7699f87 874{
cd0ff491 875 return (x << SMI_REG_ADDR_SHIFT) & SMI_REG_ADDR_MASK;
d7699f87 876}
cd0ff491
GFT
877
878static inline u32 smi_phy_addr(int x)
d7699f87 879{
cd0ff491 880 return (x << SMI_PHY_ADDR_SHIFT) & SMI_PHY_ADDR_MASK;
d7699f87 881}
cd0ff491 882
8d27293f 883#define JME_PHY_TIMEOUT 100 /* 100 msec */
186fc259 884#define JME_PHY_REG_NR 32
d7699f87
GFT
885
886/*
887 * Global Host Control
888 */
889enum jme_ghc_bit_mask {
3b70a6fa
GFT
890 GHC_SWRST = 0x40000000,
891 GHC_DPX = 0x00000040,
892 GHC_SPEED = 0x00000030,
893 GHC_LINK_POLL = 0x00000001,
d7699f87 894};
cd0ff491 895
d7699f87 896enum jme_ghc_speed_val {
3b70a6fa
GFT
897 GHC_SPEED_10M = 0x00000010,
898 GHC_SPEED_100M = 0x00000020,
899 GHC_SPEED_1000M = 0x00000030,
900};
901
902enum jme_ghc_to_clk {
903 GHC_TO_CLK_OFF = 0x00000000,
904 GHC_TO_CLK_GPHY = 0x00400000,
905 GHC_TO_CLK_PCIE = 0x00800000,
906 GHC_TO_CLK_INVALID = 0x00C00000,
907};
908
909enum jme_ghc_txmac_clk {
910 GHC_TXMAC_CLK_OFF = 0x00000000,
911 GHC_TXMAC_CLK_GPHY = 0x00100000,
912 GHC_TXMAC_CLK_PCIE = 0x00200000,
913 GHC_TXMAC_CLK_INVALID = 0x00300000,
d7699f87
GFT
914};
915
916/*
29bdd921
GFT
917 * Power management control and status register
918 */
919enum jme_pmcs_bit_masks {
920 PMCS_WF7DET = 0x80000000,
921 PMCS_WF6DET = 0x40000000,
922 PMCS_WF5DET = 0x20000000,
923 PMCS_WF4DET = 0x10000000,
924 PMCS_WF3DET = 0x08000000,
925 PMCS_WF2DET = 0x04000000,
926 PMCS_WF1DET = 0x02000000,
927 PMCS_WF0DET = 0x01000000,
928 PMCS_LFDET = 0x00040000,
929 PMCS_LRDET = 0x00020000,
930 PMCS_MFDET = 0x00010000,
931 PMCS_WF7EN = 0x00008000,
932 PMCS_WF6EN = 0x00004000,
933 PMCS_WF5EN = 0x00002000,
934 PMCS_WF4EN = 0x00001000,
935 PMCS_WF3EN = 0x00000800,
936 PMCS_WF2EN = 0x00000400,
937 PMCS_WF1EN = 0x00000200,
938 PMCS_WF0EN = 0x00000100,
939 PMCS_LFEN = 0x00000004,
940 PMCS_LREN = 0x00000002,
941 PMCS_MFEN = 0x00000001,
942};
943
944/*
3bf61c55 945 * Giga PHY Status Registers
d7699f87
GFT
946 */
947enum jme_phy_link_bit_mask {
948 PHY_LINK_SPEED_MASK = 0x0000C000,
949 PHY_LINK_DUPLEX = 0x00002000,
950 PHY_LINK_SPEEDDPU_RESOLVED = 0x00000800,
951 PHY_LINK_UP = 0x00000400,
952 PHY_LINK_AUTONEG_COMPLETE = 0x00000200,
fcf45b4c 953 PHY_LINK_MDI_STAT = 0x00000040,
d7699f87 954};
cd0ff491 955
d7699f87
GFT
956enum jme_phy_link_speed_val {
957 PHY_LINK_SPEED_10M = 0x00000000,
958 PHY_LINK_SPEED_100M = 0x00004000,
959 PHY_LINK_SPEED_1000M = 0x00008000,
960};
cd0ff491 961
fcf45b4c 962#define JME_SPDRSV_TIMEOUT 500 /* 500 us */
d7699f87
GFT
963
964/*
965 * SMB Control and Status
966 */
79ce639c 967enum jme_smbcsr_bit_mask {
d7699f87
GFT
968 SMBCSR_CNACK = 0x00020000,
969 SMBCSR_RELOAD = 0x00010000,
970 SMBCSR_EEPROMD = 0x00000020,
186fc259
GFT
971 SMBCSR_INITDONE = 0x00000010,
972 SMBCSR_BUSY = 0x0000000F,
973};
cd0ff491 974
186fc259
GFT
975enum jme_smbintf_bit_mask {
976 SMBINTF_HWDATR = 0xFF000000,
977 SMBINTF_HWDATW = 0x00FF0000,
978 SMBINTF_HWADDR = 0x0000FF00,
979 SMBINTF_HWRWN = 0x00000020,
980 SMBINTF_HWCMD = 0x00000010,
981 SMBINTF_FASTM = 0x00000008,
982 SMBINTF_GPIOSCL = 0x00000004,
983 SMBINTF_GPIOSDA = 0x00000002,
984 SMBINTF_GPIOEN = 0x00000001,
985};
cd0ff491 986
186fc259
GFT
987enum jme_smbintf_vals {
988 SMBINTF_HWRWN_READ = 0x00000020,
989 SMBINTF_HWRWN_WRITE = 0x00000000,
990};
cd0ff491 991
186fc259
GFT
992enum jme_smbintf_shifts {
993 SMBINTF_HWDATR_SHIFT = 24,
994 SMBINTF_HWDATW_SHIFT = 16,
995 SMBINTF_HWADDR_SHIFT = 8,
996};
cd0ff491 997
186fc259
GFT
998#define JME_EEPROM_RELOAD_TIMEOUT 2000 /* 2000 msec */
999#define JME_SMB_BUSY_TIMEOUT 20 /* 20 msec */
1000#define JME_SMB_LEN 256
1001#define JME_EEPROM_MAGIC 0x250
d7699f87 1002
79ce639c
GFT
1003/*
1004 * Timer Control/Status Register
1005 */
1006enum jme_tmcsr_bit_masks {
1007 TMCSR_SWIT = 0x80000000,
1008 TMCSR_EN = 0x01000000,
1009 TMCSR_CNT = 0x00FFFFFF,
1010};
1011
d7699f87 1012/*
cd0ff491 1013 * General Purpose REG-0
4330c2f2
GFT
1014 */
1015enum jme_gpreg0_masks {
3bf61c55
GFT
1016 GPREG0_DISSH = 0xFF000000,
1017 GPREG0_PCIRLMT = 0x00300000,
1018 GPREG0_PCCNOMUTCLR = 0x00040000,
cdcdc9eb 1019 GPREG0_LNKINTPOLL = 0x00001000,
3bf61c55
GFT
1020 GPREG0_PCCTMR = 0x00000300,
1021 GPREG0_PHYADDR = 0x0000001F,
4330c2f2 1022};
cd0ff491 1023
4330c2f2
GFT
1024enum jme_gpreg0_vals {
1025 GPREG0_DISSH_DW7 = 0x80000000,
1026 GPREG0_DISSH_DW6 = 0x40000000,
1027 GPREG0_DISSH_DW5 = 0x20000000,
1028 GPREG0_DISSH_DW4 = 0x10000000,
1029 GPREG0_DISSH_DW3 = 0x08000000,
1030 GPREG0_DISSH_DW2 = 0x04000000,
1031 GPREG0_DISSH_DW1 = 0x02000000,
1032 GPREG0_DISSH_DW0 = 0x01000000,
1033 GPREG0_DISSH_ALL = 0xFF000000,
1034
1035 GPREG0_PCIRLMT_8 = 0x00000000,
1036 GPREG0_PCIRLMT_6 = 0x00100000,
1037 GPREG0_PCIRLMT_5 = 0x00200000,
1038 GPREG0_PCIRLMT_4 = 0x00300000,
1039
1040 GPREG0_PCCTMR_16ns = 0x00000000,
3bf61c55
GFT
1041 GPREG0_PCCTMR_256ns = 0x00000100,
1042 GPREG0_PCCTMR_1us = 0x00000200,
1043 GPREG0_PCCTMR_1ms = 0x00000300,
4330c2f2
GFT
1044
1045 GPREG0_PHYADDR_1 = 0x00000001,
1046
1047 GPREG0_DEFAULT = GPREG0_PCIRLMT_4 |
3bf61c55
GFT
1048 GPREG0_PCCTMR_1us |
1049 GPREG0_PHYADDR_1,
4330c2f2
GFT
1050};
1051
1052/*
7ee473a3
GFT
1053 * General Purpose REG-1
1054 * Note: All theses bits defined here are for
1055 * Chip mode revision 0x11 only
1056 */
1057enum jme_gpreg1_masks {
1058 GPREG1_INTRDELAYUNIT = 0x00000018,
1059 GPREG1_INTRDELAYENABLE = 0x00000007,
1060};
1061
1062enum jme_gpreg1_vals {
1063 GPREG1_RSSPATCH = 0x00000040,
1064 GPREG1_HALFMODEPATCH = 0x00000020,
1065
1066 GPREG1_INTDLYUNIT_16NS = 0x00000000,
1067 GPREG1_INTDLYUNIT_256NS = 0x00000008,
1068 GPREG1_INTDLYUNIT_1US = 0x00000010,
1069 GPREG1_INTDLYUNIT_16US = 0x00000018,
1070
1071 GPREG1_INTDLYEN_1U = 0x00000001,
1072 GPREG1_INTDLYEN_2U = 0x00000002,
1073 GPREG1_INTDLYEN_3U = 0x00000003,
1074 GPREG1_INTDLYEN_4U = 0x00000004,
1075 GPREG1_INTDLYEN_5U = 0x00000005,
1076 GPREG1_INTDLYEN_6U = 0x00000006,
1077 GPREG1_INTDLYEN_7U = 0x00000007,
1078
1079 GPREG1_DEFAULT = 0x00000000,
1080};
1081
1082/*
d7699f87
GFT
1083 * Interrupt Status Bits
1084 */
cd0ff491 1085enum jme_interrupt_bits {
d7699f87
GFT
1086 INTR_SWINTR = 0x80000000,
1087 INTR_TMINTR = 0x40000000,
1088 INTR_LINKCH = 0x20000000,
1089 INTR_PAUSERCV = 0x10000000,
1090 INTR_MAGICRCV = 0x08000000,
1091 INTR_WAKERCV = 0x04000000,
1092 INTR_PCCRX0TO = 0x02000000,
1093 INTR_PCCRX1TO = 0x01000000,
1094 INTR_PCCRX2TO = 0x00800000,
1095 INTR_PCCRX3TO = 0x00400000,
1096 INTR_PCCTXTO = 0x00200000,
1097 INTR_PCCRX0 = 0x00100000,
1098 INTR_PCCRX1 = 0x00080000,
1099 INTR_PCCRX2 = 0x00040000,
1100 INTR_PCCRX3 = 0x00020000,
1101 INTR_PCCTX = 0x00010000,
1102 INTR_RX3EMP = 0x00008000,
1103 INTR_RX2EMP = 0x00004000,
1104 INTR_RX1EMP = 0x00002000,
1105 INTR_RX0EMP = 0x00001000,
1106 INTR_RX3 = 0x00000800,
1107 INTR_RX2 = 0x00000400,
1108 INTR_RX1 = 0x00000200,
1109 INTR_RX0 = 0x00000100,
1110 INTR_TX7 = 0x00000080,
1111 INTR_TX6 = 0x00000040,
1112 INTR_TX5 = 0x00000020,
1113 INTR_TX4 = 0x00000010,
1114 INTR_TX3 = 0x00000008,
1115 INTR_TX2 = 0x00000004,
1116 INTR_TX1 = 0x00000002,
1117 INTR_TX0 = 0x00000001,
1118};
cd0ff491
GFT
1119
1120static const u32 INTR_ENABLE = INTR_SWINTR |
79ce639c
GFT
1121 INTR_TMINTR |
1122 INTR_LINKCH |
3bf61c55
GFT
1123 INTR_PCCRX0TO |
1124 INTR_PCCRX0 |
1125 INTR_PCCTXTO |
cdcdc9eb
GFT
1126 INTR_PCCTX |
1127 INTR_RX0EMP;
3bf61c55
GFT
1128
1129/*
1130 * PCC Control Registers
1131 */
1132enum jme_pccrx_masks {
1133 PCCRXTO_MASK = 0xFFFF0000,
1134 PCCRX_MASK = 0x0000FF00,
1135};
cd0ff491 1136
3bf61c55
GFT
1137enum jme_pcctx_masks {
1138 PCCTXTO_MASK = 0xFFFF0000,
1139 PCCTX_MASK = 0x0000FF00,
1140 PCCTX_QS_MASK = 0x000000FF,
1141};
cd0ff491 1142
3bf61c55
GFT
1143enum jme_pccrx_shifts {
1144 PCCRXTO_SHIFT = 16,
1145 PCCRX_SHIFT = 8,
1146};
cd0ff491 1147
3bf61c55
GFT
1148enum jme_pcctx_shifts {
1149 PCCTXTO_SHIFT = 16,
1150 PCCTX_SHIFT = 8,
1151};
cd0ff491 1152
3bf61c55
GFT
1153enum jme_pcctx_bits {
1154 PCCTXQ0_EN = 0x00000001,
1155 PCCTXQ1_EN = 0x00000002,
1156 PCCTXQ2_EN = 0x00000004,
1157 PCCTXQ3_EN = 0x00000008,
1158 PCCTXQ4_EN = 0x00000010,
1159 PCCTXQ5_EN = 0x00000020,
1160 PCCTXQ6_EN = 0x00000040,
1161 PCCTXQ7_EN = 0x00000080,
1162};
1163
cdcdc9eb
GFT
1164/*
1165 * Chip Mode Register
1166 */
1167enum jme_chipmode_bit_masks {
1168 CM_FPGAVER_MASK = 0xFFFF0000,
58c92f28 1169 CM_CHIPREV_MASK = 0x0000FF00,
cdcdc9eb
GFT
1170 CM_CHIPMODE_MASK = 0x0000000F,
1171};
cd0ff491 1172
cdcdc9eb
GFT
1173enum jme_chipmode_shifts {
1174 CM_FPGAVER_SHIFT = 16,
58c92f28 1175 CM_CHIPREV_SHIFT = 8,
cdcdc9eb 1176};
d7699f87
GFT
1177
1178/*
cd0ff491
GFT
1179 * Aggressive Power Mode Control
1180 */
1181enum jme_apmc_bits {
1182 JME_APMC_PCIE_SD_EN = 0x40000000,
1183 JME_APMC_PSEUDO_HP_EN = 0x20000000,
1184 JME_APMC_EPIEN = 0x04000000,
1185 JME_APMC_EPIEN_CTRL = 0x03000000,
1186};
1187
1188enum jme_apmc_values {
1189 JME_APMC_EPIEN_CTRL_EN = 0x02000000,
1190 JME_APMC_EPIEN_CTRL_DIS = 0x01000000,
1191};
1192
1193#define APMC_PHP_SHUTDOWN_DELAY (10 * 1000 * 1000)
1194
1195#ifdef REG_DEBUG
1196static char *MAC_REG_NAME[] = {
1197 "JME_TXCS", "JME_TXDBA_LO", "JME_TXDBA_HI", "JME_TXQDC",
1198 "JME_TXNDA", "JME_TXMCS", "JME_TXPFC", "JME_TXTRHD",
1199 "JME_RXCS", "JME_RXDBA_LO", "JME_RXDBA_HI", "JME_RXQDC",
1200 "JME_RXNDA", "JME_RXMCS", "JME_RXUMA_LO", "JME_RXUMA_HI",
1201 "JME_RXMCHT_LO", "JME_RXMCHT_HI", "JME_WFODP", "JME_WFOI",
1202 "JME_SMI", "JME_GHC", "UNKNOWN", "UNKNOWN",
1203 "JME_PMCS"};
7ee473a3 1204
cd0ff491
GFT
1205static char *PE_REG_NAME[] = {
1206 "UNKNOWN", "UNKNOWN", "UNKNOWN", "UNKNOWN",
1207 "UNKNOWN", "UNKNOWN", "UNKNOWN", "UNKNOWN",
1208 "UNKNOWN", "UNKNOWN", "JME_PHY_CS", "UNKNOWN",
1209 "JME_PHY_LINK", "UNKNOWN", "UNKNOWN", "UNKNOWN",
1210 "JME_SMBCSR", "JME_SMBINTF"};
7ee473a3 1211
cd0ff491
GFT
1212static char *MISC_REG_NAME[] = {
1213 "JME_TMCSR", "JME_GPIO", "JME_GPREG0", "JME_GPREG1",
1214 "JME_IEVE", "JME_IREQ", "JME_IENS", "JME_IENC",
1215 "JME_PCCRX0", "JME_PCCRX1", "JME_PCCRX2", "JME_PCCRX3",
1216 "JME_PCCTX0", "JME_CHIPMODE", "JME_SHBA_HI", "JME_SHBA_LO",
1217 "UNKNOWN", "UNKNOWN", "UNKNOWN", "UNKNOWN",
1218 "UNKNOWN", "UNKNOWN", "UNKNOWN", "UNKNOWN",
1219 "UNKNOWN", "UNKNOWN", "UNKNOWN", "UNKNOWN",
1220 "JME_TIMER1", "JME_TIMER2", "UNKNOWN", "JME_APMC",
1221 "JME_PCCSRX0"};
7ee473a3 1222
cd0ff491
GFT
1223static inline void reg_dbg(const struct jme_adapter *jme,
1224 const char *msg, u32 val, u32 reg)
1225{
1226 const char *regname;
58c92f28 1227 switch (reg & 0xF00) {
cd0ff491
GFT
1228 case 0x000:
1229 regname = MAC_REG_NAME[(reg & 0xFF) >> 2];
1230 break;
1231 case 0x400:
1232 regname = PE_REG_NAME[(reg & 0xFF) >> 2];
1233 break;
1234 case 0x800:
58c92f28 1235 regname = MISC_REG_NAME[(reg & 0xFF) >> 2];
cd0ff491
GFT
1236 break;
1237 default:
1238 regname = PE_REG_NAME[0];
1239 }
1240 printk(KERN_DEBUG "%s: %-20s %08x@%s\n", jme->dev->name,
1241 msg, val, regname);
1242}
1243#else
1244static inline void reg_dbg(const struct jme_adapter *jme,
1245 const char *msg, u32 val, u32 reg) {}
1246#endif
1247
1248/*
d7699f87
GFT
1249 * Read/Write MMaped I/O Registers
1250 */
cd0ff491 1251static inline u32 jread32(struct jme_adapter *jme, u32 reg)
d7699f87 1252{
cd0ff491 1253 return readl(jme->regs + reg);
d7699f87 1254}
cd0ff491
GFT
1255
1256static inline void jwrite32(struct jme_adapter *jme, u32 reg, u32 val)
d7699f87 1257{
cd0ff491
GFT
1258 reg_dbg(jme, "REG WRITE", val, reg);
1259 writel(val, jme->regs + reg);
1260 reg_dbg(jme, "VAL AFTER WRITE", readl(jme->regs + reg), reg);
d7699f87 1261}
cd0ff491
GFT
1262
1263static inline void jwrite32f(struct jme_adapter *jme, u32 reg, u32 val)
d7699f87
GFT
1264{
1265 /*
1266 * Read after write should cause flush
1267 */
cd0ff491
GFT
1268 reg_dbg(jme, "REG WRITE FLUSH", val, reg);
1269 writel(val, jme->regs + reg);
1270 readl(jme->regs + reg);
1271 reg_dbg(jme, "VAL AFTER WRITE", readl(jme->regs + reg), reg);
d7699f87
GFT
1272}
1273
1274/*
cdcdc9eb
GFT
1275 * PHY Regs
1276 */
1277enum jme_phy_reg17_bit_masks {
1278 PREG17_SPEED = 0xC000,
1279 PREG17_DUPLEX = 0x2000,
1280 PREG17_SPDRSV = 0x0800,
1281 PREG17_LNKUP = 0x0400,
1282 PREG17_MDI = 0x0040,
1283};
cd0ff491 1284
cdcdc9eb
GFT
1285enum jme_phy_reg17_vals {
1286 PREG17_SPEED_10M = 0x0000,
1287 PREG17_SPEED_100M = 0x4000,
1288 PREG17_SPEED_1000M = 0x8000,
1289};
cd0ff491 1290
8d27293f 1291#define BMSR_ANCOMP 0x0020
cdcdc9eb
GFT
1292
1293/*
58c92f28
GFT
1294 * Workaround
1295 */
1296static inline int is_buggy250(unsigned short device, unsigned int chiprev)
1297{
1298 return device == PCI_DEVICE_ID_JMICRON_JMC250 && chiprev == 0x11;
1299}
1300
1301/*
cd0ff491 1302 * Function prototypes
d7699f87 1303 */
d7699f87 1304static int jme_set_settings(struct net_device *netdev,
cd0ff491 1305 struct ethtool_cmd *ecmd);
d7699f87
GFT
1306static void jme_set_multi(struct net_device *netdev);
1307
cd0ff491 1308#endif