1 // SPDX-License-Identifier: GPL-2.0
2 /* niu.c: Neptune ethernet driver.
4 * Copyright (C) 2007, 2008 David S. Miller (davem@davemloft.net)
7 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/interrupt.h>
12 #include <linux/pci.h>
13 #include <linux/dma-mapping.h>
14 #include <linux/netdevice.h>
15 #include <linux/ethtool.h>
16 #include <linux/etherdevice.h>
17 #include <linux/platform_device.h>
18 #include <linux/delay.h>
19 #include <linux/bitops.h>
20 #include <linux/mii.h>
22 #include <linux/if_ether.h>
23 #include <linux/if_vlan.h>
26 #include <linux/ipv6.h>
27 #include <linux/log2.h>
28 #include <linux/jiffies.h>
29 #include <linux/crc32.h>
30 #include <linux/list.h>
31 #include <linux/slab.h>
38 /* This driver wants to store a link to a "next page" within the
39 * page struct itself by overloading the content of the "mapping"
40 * member. This is not expected by the page API, but does currently
41 * work. However, the randstruct plugin gets very bothered by this
42 * case because "mapping" (struct address_space) is randomized, so
43 * casts to/from it trigger warnings. Hide this by way of a union,
44 * to create a typed alias of "mapping", since that's how it is
45 * actually being used here.
50 unsigned long __flags
; /* unused alias of "flags" */
51 struct list_head __lru
; /* unused alias of "lru" */
52 struct page
*next
; /* alias of "mapping" */
55 #define niu_next_page(p) container_of(p, union niu_page, page)->next
57 #define DRV_MODULE_NAME "niu"
58 #define DRV_MODULE_VERSION "1.1"
59 #define DRV_MODULE_RELDATE "Apr 22, 2010"
61 static char version
[] =
62 DRV_MODULE_NAME
".c:v" DRV_MODULE_VERSION
" (" DRV_MODULE_RELDATE
")\n";
64 MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
65 MODULE_DESCRIPTION("NIU ethernet driver");
66 MODULE_LICENSE("GPL");
67 MODULE_VERSION(DRV_MODULE_VERSION
);
70 static u64
readq(void __iomem
*reg
)
72 return ((u64
) readl(reg
)) | (((u64
) readl(reg
+ 4UL)) << 32);
75 static void writeq(u64 val
, void __iomem
*reg
)
77 writel(val
& 0xffffffff, reg
);
78 writel(val
>> 32, reg
+ 0x4UL
);
82 static const struct pci_device_id niu_pci_tbl
[] = {
83 {PCI_DEVICE(PCI_VENDOR_ID_SUN
, 0xabcd)},
87 MODULE_DEVICE_TABLE(pci
, niu_pci_tbl
);
89 #define NIU_TX_TIMEOUT (5 * HZ)
91 #define nr64(reg) readq(np->regs + (reg))
92 #define nw64(reg, val) writeq((val), np->regs + (reg))
94 #define nr64_mac(reg) readq(np->mac_regs + (reg))
95 #define nw64_mac(reg, val) writeq((val), np->mac_regs + (reg))
97 #define nr64_ipp(reg) readq(np->regs + np->ipp_off + (reg))
98 #define nw64_ipp(reg, val) writeq((val), np->regs + np->ipp_off + (reg))
100 #define nr64_pcs(reg) readq(np->regs + np->pcs_off + (reg))
101 #define nw64_pcs(reg, val) writeq((val), np->regs + np->pcs_off + (reg))
103 #define nr64_xpcs(reg) readq(np->regs + np->xpcs_off + (reg))
104 #define nw64_xpcs(reg, val) writeq((val), np->regs + np->xpcs_off + (reg))
106 #define NIU_MSG_DEFAULT (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
108 static int niu_debug
;
109 static int debug
= -1;
110 module_param(debug
, int, 0);
111 MODULE_PARM_DESC(debug
, "NIU debug level");
113 #define niu_lock_parent(np, flags) \
114 spin_lock_irqsave(&np->parent->lock, flags)
115 #define niu_unlock_parent(np, flags) \
116 spin_unlock_irqrestore(&np->parent->lock, flags)
118 static int serdes_init_10g_serdes(struct niu
*np
);
120 static int __niu_wait_bits_clear_mac(struct niu
*np
, unsigned long reg
,
121 u64 bits
, int limit
, int delay
)
123 while (--limit
>= 0) {
124 u64 val
= nr64_mac(reg
);
135 static int __niu_set_and_wait_clear_mac(struct niu
*np
, unsigned long reg
,
136 u64 bits
, int limit
, int delay
,
137 const char *reg_name
)
142 err
= __niu_wait_bits_clear_mac(np
, reg
, bits
, limit
, delay
);
144 netdev_err(np
->dev
, "bits (%llx) of register %s would not clear, val[%llx]\n",
145 (unsigned long long)bits
, reg_name
,
146 (unsigned long long)nr64_mac(reg
));
150 #define niu_set_and_wait_clear_mac(NP, REG, BITS, LIMIT, DELAY, REG_NAME) \
151 ({ BUILD_BUG_ON(LIMIT <= 0 || DELAY < 0); \
152 __niu_set_and_wait_clear_mac(NP, REG, BITS, LIMIT, DELAY, REG_NAME); \
155 static int __niu_wait_bits_clear_ipp(struct niu
*np
, unsigned long reg
,
156 u64 bits
, int limit
, int delay
)
158 while (--limit
>= 0) {
159 u64 val
= nr64_ipp(reg
);
170 static int __niu_set_and_wait_clear_ipp(struct niu
*np
, unsigned long reg
,
171 u64 bits
, int limit
, int delay
,
172 const char *reg_name
)
181 err
= __niu_wait_bits_clear_ipp(np
, reg
, bits
, limit
, delay
);
183 netdev_err(np
->dev
, "bits (%llx) of register %s would not clear, val[%llx]\n",
184 (unsigned long long)bits
, reg_name
,
185 (unsigned long long)nr64_ipp(reg
));
189 #define niu_set_and_wait_clear_ipp(NP, REG, BITS, LIMIT, DELAY, REG_NAME) \
190 ({ BUILD_BUG_ON(LIMIT <= 0 || DELAY < 0); \
191 __niu_set_and_wait_clear_ipp(NP, REG, BITS, LIMIT, DELAY, REG_NAME); \
194 static int __niu_wait_bits_clear(struct niu
*np
, unsigned long reg
,
195 u64 bits
, int limit
, int delay
)
197 while (--limit
>= 0) {
209 #define niu_wait_bits_clear(NP, REG, BITS, LIMIT, DELAY) \
210 ({ BUILD_BUG_ON(LIMIT <= 0 || DELAY < 0); \
211 __niu_wait_bits_clear(NP, REG, BITS, LIMIT, DELAY); \
214 static int __niu_set_and_wait_clear(struct niu
*np
, unsigned long reg
,
215 u64 bits
, int limit
, int delay
,
216 const char *reg_name
)
221 err
= __niu_wait_bits_clear(np
, reg
, bits
, limit
, delay
);
223 netdev_err(np
->dev
, "bits (%llx) of register %s would not clear, val[%llx]\n",
224 (unsigned long long)bits
, reg_name
,
225 (unsigned long long)nr64(reg
));
229 #define niu_set_and_wait_clear(NP, REG, BITS, LIMIT, DELAY, REG_NAME) \
230 ({ BUILD_BUG_ON(LIMIT <= 0 || DELAY < 0); \
231 __niu_set_and_wait_clear(NP, REG, BITS, LIMIT, DELAY, REG_NAME); \
234 static void niu_ldg_rearm(struct niu
*np
, struct niu_ldg
*lp
, int on
)
236 u64 val
= (u64
) lp
->timer
;
239 val
|= LDG_IMGMT_ARM
;
241 nw64(LDG_IMGMT(lp
->ldg_num
), val
);
244 static int niu_ldn_irq_enable(struct niu
*np
, int ldn
, int on
)
246 unsigned long mask_reg
, bits
;
249 if (ldn
< 0 || ldn
> LDN_MAX
)
253 mask_reg
= LD_IM0(ldn
);
256 mask_reg
= LD_IM1(ldn
- 64);
260 val
= nr64(mask_reg
);
270 static int niu_enable_ldn_in_ldg(struct niu
*np
, struct niu_ldg
*lp
, int on
)
272 struct niu_parent
*parent
= np
->parent
;
275 for (i
= 0; i
<= LDN_MAX
; i
++) {
278 if (parent
->ldg_map
[i
] != lp
->ldg_num
)
281 err
= niu_ldn_irq_enable(np
, i
, on
);
288 static int niu_enable_interrupts(struct niu
*np
, int on
)
292 for (i
= 0; i
< np
->num_ldg
; i
++) {
293 struct niu_ldg
*lp
= &np
->ldg
[i
];
296 err
= niu_enable_ldn_in_ldg(np
, lp
, on
);
300 for (i
= 0; i
< np
->num_ldg
; i
++)
301 niu_ldg_rearm(np
, &np
->ldg
[i
], on
);
306 static u32
phy_encode(u32 type
, int port
)
308 return type
<< (port
* 2);
311 static u32
phy_decode(u32 val
, int port
)
313 return (val
>> (port
* 2)) & PORT_TYPE_MASK
;
316 static int mdio_wait(struct niu
*np
)
321 while (--limit
> 0) {
322 val
= nr64(MIF_FRAME_OUTPUT
);
323 if ((val
>> MIF_FRAME_OUTPUT_TA_SHIFT
) & 0x1)
324 return val
& MIF_FRAME_OUTPUT_DATA
;
332 static int mdio_read(struct niu
*np
, int port
, int dev
, int reg
)
336 nw64(MIF_FRAME_OUTPUT
, MDIO_ADDR_OP(port
, dev
, reg
));
341 nw64(MIF_FRAME_OUTPUT
, MDIO_READ_OP(port
, dev
));
342 return mdio_wait(np
);
345 static int mdio_write(struct niu
*np
, int port
, int dev
, int reg
, int data
)
349 nw64(MIF_FRAME_OUTPUT
, MDIO_ADDR_OP(port
, dev
, reg
));
354 nw64(MIF_FRAME_OUTPUT
, MDIO_WRITE_OP(port
, dev
, data
));
362 static int mii_read(struct niu
*np
, int port
, int reg
)
364 nw64(MIF_FRAME_OUTPUT
, MII_READ_OP(port
, reg
));
365 return mdio_wait(np
);
368 static int mii_write(struct niu
*np
, int port
, int reg
, int data
)
372 nw64(MIF_FRAME_OUTPUT
, MII_WRITE_OP(port
, reg
, data
));
380 static int esr2_set_tx_cfg(struct niu
*np
, unsigned long channel
, u32 val
)
384 err
= mdio_write(np
, np
->port
, NIU_ESR2_DEV_ADDR
,
385 ESR2_TI_PLL_TX_CFG_L(channel
),
388 err
= mdio_write(np
, np
->port
, NIU_ESR2_DEV_ADDR
,
389 ESR2_TI_PLL_TX_CFG_H(channel
),
394 static int esr2_set_rx_cfg(struct niu
*np
, unsigned long channel
, u32 val
)
398 err
= mdio_write(np
, np
->port
, NIU_ESR2_DEV_ADDR
,
399 ESR2_TI_PLL_RX_CFG_L(channel
),
402 err
= mdio_write(np
, np
->port
, NIU_ESR2_DEV_ADDR
,
403 ESR2_TI_PLL_RX_CFG_H(channel
),
408 /* Mode is always 10G fiber. */
409 static int serdes_init_niu_10g_fiber(struct niu
*np
)
411 struct niu_link_config
*lp
= &np
->link_config
;
415 tx_cfg
= (PLL_TX_CFG_ENTX
| PLL_TX_CFG_SWING_1375MV
);
416 rx_cfg
= (PLL_RX_CFG_ENRX
| PLL_RX_CFG_TERM_0P8VDDT
|
417 PLL_RX_CFG_ALIGN_ENA
| PLL_RX_CFG_LOS_LTHRESH
|
418 PLL_RX_CFG_EQ_LP_ADAPTIVE
);
420 if (lp
->loopback_mode
== LOOPBACK_PHY
) {
421 u16 test_cfg
= PLL_TEST_CFG_LOOPBACK_CML_DIS
;
423 mdio_write(np
, np
->port
, NIU_ESR2_DEV_ADDR
,
424 ESR2_TI_PLL_TEST_CFG_L
, test_cfg
);
426 tx_cfg
|= PLL_TX_CFG_ENTEST
;
427 rx_cfg
|= PLL_RX_CFG_ENTEST
;
430 /* Initialize all 4 lanes of the SERDES. */
431 for (i
= 0; i
< 4; i
++) {
432 int err
= esr2_set_tx_cfg(np
, i
, tx_cfg
);
437 for (i
= 0; i
< 4; i
++) {
438 int err
= esr2_set_rx_cfg(np
, i
, rx_cfg
);
446 static int serdes_init_niu_1g_serdes(struct niu
*np
)
448 struct niu_link_config
*lp
= &np
->link_config
;
449 u16 pll_cfg
, pll_sts
;
456 tx_cfg
= (PLL_TX_CFG_ENTX
| PLL_TX_CFG_SWING_1375MV
|
457 PLL_TX_CFG_RATE_HALF
);
458 rx_cfg
= (PLL_RX_CFG_ENRX
| PLL_RX_CFG_TERM_0P8VDDT
|
459 PLL_RX_CFG_ALIGN_ENA
| PLL_RX_CFG_LOS_LTHRESH
|
460 PLL_RX_CFG_RATE_HALF
);
463 rx_cfg
|= PLL_RX_CFG_EQ_LP_ADAPTIVE
;
465 if (lp
->loopback_mode
== LOOPBACK_PHY
) {
466 u16 test_cfg
= PLL_TEST_CFG_LOOPBACK_CML_DIS
;
468 mdio_write(np
, np
->port
, NIU_ESR2_DEV_ADDR
,
469 ESR2_TI_PLL_TEST_CFG_L
, test_cfg
);
471 tx_cfg
|= PLL_TX_CFG_ENTEST
;
472 rx_cfg
|= PLL_RX_CFG_ENTEST
;
475 /* Initialize PLL for 1G */
476 pll_cfg
= (PLL_CFG_ENPLL
| PLL_CFG_MPY_8X
);
478 err
= mdio_write(np
, np
->port
, NIU_ESR2_DEV_ADDR
,
479 ESR2_TI_PLL_CFG_L
, pll_cfg
);
481 netdev_err(np
->dev
, "NIU Port %d %s() mdio write to ESR2_TI_PLL_CFG_L failed\n",
486 pll_sts
= PLL_CFG_ENPLL
;
488 err
= mdio_write(np
, np
->port
, NIU_ESR2_DEV_ADDR
,
489 ESR2_TI_PLL_STS_L
, pll_sts
);
491 netdev_err(np
->dev
, "NIU Port %d %s() mdio write to ESR2_TI_PLL_STS_L failed\n",
498 /* Initialize all 4 lanes of the SERDES. */
499 for (i
= 0; i
< 4; i
++) {
500 err
= esr2_set_tx_cfg(np
, i
, tx_cfg
);
505 for (i
= 0; i
< 4; i
++) {
506 err
= esr2_set_rx_cfg(np
, i
, rx_cfg
);
513 val
= (ESR_INT_SRDY0_P0
| ESR_INT_DET0_P0
);
518 val
= (ESR_INT_SRDY0_P1
| ESR_INT_DET0_P1
);
526 while (max_retry
--) {
527 sig
= nr64(ESR_INT_SIGNALS
);
528 if ((sig
& mask
) == val
)
534 if ((sig
& mask
) != val
) {
535 netdev_err(np
->dev
, "Port %u signal bits [%08x] are not [%08x]\n",
536 np
->port
, (int)(sig
& mask
), (int)val
);
543 static int serdes_init_niu_10g_serdes(struct niu
*np
)
545 struct niu_link_config
*lp
= &np
->link_config
;
546 u32 tx_cfg
, rx_cfg
, pll_cfg
, pll_sts
;
552 tx_cfg
= (PLL_TX_CFG_ENTX
| PLL_TX_CFG_SWING_1375MV
);
553 rx_cfg
= (PLL_RX_CFG_ENRX
| PLL_RX_CFG_TERM_0P8VDDT
|
554 PLL_RX_CFG_ALIGN_ENA
| PLL_RX_CFG_LOS_LTHRESH
|
555 PLL_RX_CFG_EQ_LP_ADAPTIVE
);
557 if (lp
->loopback_mode
== LOOPBACK_PHY
) {
558 u16 test_cfg
= PLL_TEST_CFG_LOOPBACK_CML_DIS
;
560 mdio_write(np
, np
->port
, NIU_ESR2_DEV_ADDR
,
561 ESR2_TI_PLL_TEST_CFG_L
, test_cfg
);
563 tx_cfg
|= PLL_TX_CFG_ENTEST
;
564 rx_cfg
|= PLL_RX_CFG_ENTEST
;
567 /* Initialize PLL for 10G */
568 pll_cfg
= (PLL_CFG_ENPLL
| PLL_CFG_MPY_10X
);
570 err
= mdio_write(np
, np
->port
, NIU_ESR2_DEV_ADDR
,
571 ESR2_TI_PLL_CFG_L
, pll_cfg
& 0xffff);
573 netdev_err(np
->dev
, "NIU Port %d %s() mdio write to ESR2_TI_PLL_CFG_L failed\n",
578 pll_sts
= PLL_CFG_ENPLL
;
580 err
= mdio_write(np
, np
->port
, NIU_ESR2_DEV_ADDR
,
581 ESR2_TI_PLL_STS_L
, pll_sts
& 0xffff);
583 netdev_err(np
->dev
, "NIU Port %d %s() mdio write to ESR2_TI_PLL_STS_L failed\n",
590 /* Initialize all 4 lanes of the SERDES. */
591 for (i
= 0; i
< 4; i
++) {
592 err
= esr2_set_tx_cfg(np
, i
, tx_cfg
);
597 for (i
= 0; i
< 4; i
++) {
598 err
= esr2_set_rx_cfg(np
, i
, rx_cfg
);
603 /* check if serdes is ready */
607 mask
= ESR_INT_SIGNALS_P0_BITS
;
608 val
= (ESR_INT_SRDY0_P0
|
618 mask
= ESR_INT_SIGNALS_P1_BITS
;
619 val
= (ESR_INT_SRDY0_P1
|
632 while (max_retry
--) {
633 sig
= nr64(ESR_INT_SIGNALS
);
634 if ((sig
& mask
) == val
)
640 if ((sig
& mask
) != val
) {
641 pr_info("NIU Port %u signal bits [%08x] are not [%08x] for 10G...trying 1G\n",
642 np
->port
, (int)(sig
& mask
), (int)val
);
644 /* 10G failed, try initializing at 1G */
645 err
= serdes_init_niu_1g_serdes(np
);
647 np
->flags
&= ~NIU_FLAGS_10G
;
648 np
->mac_xcvr
= MAC_XCVR_PCS
;
650 netdev_err(np
->dev
, "Port %u 10G/1G SERDES Link Failed\n",
658 static int esr_read_rxtx_ctrl(struct niu
*np
, unsigned long chan
, u32
*val
)
662 err
= mdio_read(np
, np
->port
, NIU_ESR_DEV_ADDR
, ESR_RXTX_CTRL_L(chan
));
664 *val
= (err
& 0xffff);
665 err
= mdio_read(np
, np
->port
, NIU_ESR_DEV_ADDR
,
666 ESR_RXTX_CTRL_H(chan
));
668 *val
|= ((err
& 0xffff) << 16);
674 static int esr_read_glue0(struct niu
*np
, unsigned long chan
, u32
*val
)
678 err
= mdio_read(np
, np
->port
, NIU_ESR_DEV_ADDR
,
679 ESR_GLUE_CTRL0_L(chan
));
681 *val
= (err
& 0xffff);
682 err
= mdio_read(np
, np
->port
, NIU_ESR_DEV_ADDR
,
683 ESR_GLUE_CTRL0_H(chan
));
685 *val
|= ((err
& 0xffff) << 16);
692 static int esr_read_reset(struct niu
*np
, u32
*val
)
696 err
= mdio_read(np
, np
->port
, NIU_ESR_DEV_ADDR
,
697 ESR_RXTX_RESET_CTRL_L
);
699 *val
= (err
& 0xffff);
700 err
= mdio_read(np
, np
->port
, NIU_ESR_DEV_ADDR
,
701 ESR_RXTX_RESET_CTRL_H
);
703 *val
|= ((err
& 0xffff) << 16);
710 static int esr_write_rxtx_ctrl(struct niu
*np
, unsigned long chan
, u32 val
)
714 err
= mdio_write(np
, np
->port
, NIU_ESR_DEV_ADDR
,
715 ESR_RXTX_CTRL_L(chan
), val
& 0xffff);
717 err
= mdio_write(np
, np
->port
, NIU_ESR_DEV_ADDR
,
718 ESR_RXTX_CTRL_H(chan
), (val
>> 16));
722 static int esr_write_glue0(struct niu
*np
, unsigned long chan
, u32 val
)
726 err
= mdio_write(np
, np
->port
, NIU_ESR_DEV_ADDR
,
727 ESR_GLUE_CTRL0_L(chan
), val
& 0xffff);
729 err
= mdio_write(np
, np
->port
, NIU_ESR_DEV_ADDR
,
730 ESR_GLUE_CTRL0_H(chan
), (val
>> 16));
734 static int esr_reset(struct niu
*np
)
739 err
= mdio_write(np
, np
->port
, NIU_ESR_DEV_ADDR
,
740 ESR_RXTX_RESET_CTRL_L
, 0x0000);
743 err
= mdio_write(np
, np
->port
, NIU_ESR_DEV_ADDR
,
744 ESR_RXTX_RESET_CTRL_H
, 0xffff);
749 err
= mdio_write(np
, np
->port
, NIU_ESR_DEV_ADDR
,
750 ESR_RXTX_RESET_CTRL_L
, 0xffff);
755 err
= mdio_write(np
, np
->port
, NIU_ESR_DEV_ADDR
,
756 ESR_RXTX_RESET_CTRL_H
, 0x0000);
761 err
= esr_read_reset(np
, &reset
);
765 netdev_err(np
->dev
, "Port %u ESR_RESET did not clear [%08x]\n",
773 static int serdes_init_10g(struct niu
*np
)
775 struct niu_link_config
*lp
= &np
->link_config
;
776 unsigned long ctrl_reg
, test_cfg_reg
, i
;
777 u64 ctrl_val
, test_cfg_val
, sig
, mask
, val
;
782 ctrl_reg
= ENET_SERDES_0_CTRL_CFG
;
783 test_cfg_reg
= ENET_SERDES_0_TEST_CFG
;
786 ctrl_reg
= ENET_SERDES_1_CTRL_CFG
;
787 test_cfg_reg
= ENET_SERDES_1_TEST_CFG
;
793 ctrl_val
= (ENET_SERDES_CTRL_SDET_0
|
794 ENET_SERDES_CTRL_SDET_1
|
795 ENET_SERDES_CTRL_SDET_2
|
796 ENET_SERDES_CTRL_SDET_3
|
797 (0x5 << ENET_SERDES_CTRL_EMPH_0_SHIFT
) |
798 (0x5 << ENET_SERDES_CTRL_EMPH_1_SHIFT
) |
799 (0x5 << ENET_SERDES_CTRL_EMPH_2_SHIFT
) |
800 (0x5 << ENET_SERDES_CTRL_EMPH_3_SHIFT
) |
801 (0x1 << ENET_SERDES_CTRL_LADJ_0_SHIFT
) |
802 (0x1 << ENET_SERDES_CTRL_LADJ_1_SHIFT
) |
803 (0x1 << ENET_SERDES_CTRL_LADJ_2_SHIFT
) |
804 (0x1 << ENET_SERDES_CTRL_LADJ_3_SHIFT
));
807 if (lp
->loopback_mode
== LOOPBACK_PHY
) {
808 test_cfg_val
|= ((ENET_TEST_MD_PAD_LOOPBACK
<<
809 ENET_SERDES_TEST_MD_0_SHIFT
) |
810 (ENET_TEST_MD_PAD_LOOPBACK
<<
811 ENET_SERDES_TEST_MD_1_SHIFT
) |
812 (ENET_TEST_MD_PAD_LOOPBACK
<<
813 ENET_SERDES_TEST_MD_2_SHIFT
) |
814 (ENET_TEST_MD_PAD_LOOPBACK
<<
815 ENET_SERDES_TEST_MD_3_SHIFT
));
818 nw64(ctrl_reg
, ctrl_val
);
819 nw64(test_cfg_reg
, test_cfg_val
);
821 /* Initialize all 4 lanes of the SERDES. */
822 for (i
= 0; i
< 4; i
++) {
823 u32 rxtx_ctrl
, glue0
;
825 err
= esr_read_rxtx_ctrl(np
, i
, &rxtx_ctrl
);
828 err
= esr_read_glue0(np
, i
, &glue0
);
832 rxtx_ctrl
&= ~(ESR_RXTX_CTRL_VMUXLO
);
833 rxtx_ctrl
|= (ESR_RXTX_CTRL_ENSTRETCH
|
834 (2 << ESR_RXTX_CTRL_VMUXLO_SHIFT
));
836 glue0
&= ~(ESR_GLUE_CTRL0_SRATE
|
837 ESR_GLUE_CTRL0_THCNT
|
838 ESR_GLUE_CTRL0_BLTIME
);
839 glue0
|= (ESR_GLUE_CTRL0_RXLOSENAB
|
840 (0xf << ESR_GLUE_CTRL0_SRATE_SHIFT
) |
841 (0xff << ESR_GLUE_CTRL0_THCNT_SHIFT
) |
842 (BLTIME_300_CYCLES
<<
843 ESR_GLUE_CTRL0_BLTIME_SHIFT
));
845 err
= esr_write_rxtx_ctrl(np
, i
, rxtx_ctrl
);
848 err
= esr_write_glue0(np
, i
, glue0
);
857 sig
= nr64(ESR_INT_SIGNALS
);
860 mask
= ESR_INT_SIGNALS_P0_BITS
;
861 val
= (ESR_INT_SRDY0_P0
|
871 mask
= ESR_INT_SIGNALS_P1_BITS
;
872 val
= (ESR_INT_SRDY0_P1
|
885 if ((sig
& mask
) != val
) {
886 if (np
->flags
& NIU_FLAGS_HOTPLUG_PHY
) {
887 np
->flags
&= ~NIU_FLAGS_HOTPLUG_PHY_PRESENT
;
890 netdev_err(np
->dev
, "Port %u signal bits [%08x] are not [%08x]\n",
891 np
->port
, (int)(sig
& mask
), (int)val
);
894 if (np
->flags
& NIU_FLAGS_HOTPLUG_PHY
)
895 np
->flags
|= NIU_FLAGS_HOTPLUG_PHY_PRESENT
;
899 static int serdes_init_1g(struct niu
*np
)
903 val
= nr64(ENET_SERDES_1_PLL_CFG
);
904 val
&= ~ENET_SERDES_PLL_FBDIV2
;
907 val
|= ENET_SERDES_PLL_HRATE0
;
910 val
|= ENET_SERDES_PLL_HRATE1
;
913 val
|= ENET_SERDES_PLL_HRATE2
;
916 val
|= ENET_SERDES_PLL_HRATE3
;
921 nw64(ENET_SERDES_1_PLL_CFG
, val
);
926 static int serdes_init_1g_serdes(struct niu
*np
)
928 struct niu_link_config
*lp
= &np
->link_config
;
929 unsigned long ctrl_reg
, test_cfg_reg
, pll_cfg
, i
;
930 u64 ctrl_val
, test_cfg_val
, sig
, mask
, val
;
932 u64 reset_val
, val_rd
;
934 val
= ENET_SERDES_PLL_HRATE0
| ENET_SERDES_PLL_HRATE1
|
935 ENET_SERDES_PLL_HRATE2
| ENET_SERDES_PLL_HRATE3
|
936 ENET_SERDES_PLL_FBDIV0
;
939 reset_val
= ENET_SERDES_RESET_0
;
940 ctrl_reg
= ENET_SERDES_0_CTRL_CFG
;
941 test_cfg_reg
= ENET_SERDES_0_TEST_CFG
;
942 pll_cfg
= ENET_SERDES_0_PLL_CFG
;
945 reset_val
= ENET_SERDES_RESET_1
;
946 ctrl_reg
= ENET_SERDES_1_CTRL_CFG
;
947 test_cfg_reg
= ENET_SERDES_1_TEST_CFG
;
948 pll_cfg
= ENET_SERDES_1_PLL_CFG
;
954 ctrl_val
= (ENET_SERDES_CTRL_SDET_0
|
955 ENET_SERDES_CTRL_SDET_1
|
956 ENET_SERDES_CTRL_SDET_2
|
957 ENET_SERDES_CTRL_SDET_3
|
958 (0x5 << ENET_SERDES_CTRL_EMPH_0_SHIFT
) |
959 (0x5 << ENET_SERDES_CTRL_EMPH_1_SHIFT
) |
960 (0x5 << ENET_SERDES_CTRL_EMPH_2_SHIFT
) |
961 (0x5 << ENET_SERDES_CTRL_EMPH_3_SHIFT
) |
962 (0x1 << ENET_SERDES_CTRL_LADJ_0_SHIFT
) |
963 (0x1 << ENET_SERDES_CTRL_LADJ_1_SHIFT
) |
964 (0x1 << ENET_SERDES_CTRL_LADJ_2_SHIFT
) |
965 (0x1 << ENET_SERDES_CTRL_LADJ_3_SHIFT
));
968 if (lp
->loopback_mode
== LOOPBACK_PHY
) {
969 test_cfg_val
|= ((ENET_TEST_MD_PAD_LOOPBACK
<<
970 ENET_SERDES_TEST_MD_0_SHIFT
) |
971 (ENET_TEST_MD_PAD_LOOPBACK
<<
972 ENET_SERDES_TEST_MD_1_SHIFT
) |
973 (ENET_TEST_MD_PAD_LOOPBACK
<<
974 ENET_SERDES_TEST_MD_2_SHIFT
) |
975 (ENET_TEST_MD_PAD_LOOPBACK
<<
976 ENET_SERDES_TEST_MD_3_SHIFT
));
979 nw64(ENET_SERDES_RESET
, reset_val
);
981 val_rd
= nr64(ENET_SERDES_RESET
);
982 val_rd
&= ~reset_val
;
984 nw64(ctrl_reg
, ctrl_val
);
985 nw64(test_cfg_reg
, test_cfg_val
);
986 nw64(ENET_SERDES_RESET
, val_rd
);
989 /* Initialize all 4 lanes of the SERDES. */
990 for (i
= 0; i
< 4; i
++) {
991 u32 rxtx_ctrl
, glue0
;
993 err
= esr_read_rxtx_ctrl(np
, i
, &rxtx_ctrl
);
996 err
= esr_read_glue0(np
, i
, &glue0
);
1000 rxtx_ctrl
&= ~(ESR_RXTX_CTRL_VMUXLO
);
1001 rxtx_ctrl
|= (ESR_RXTX_CTRL_ENSTRETCH
|
1002 (2 << ESR_RXTX_CTRL_VMUXLO_SHIFT
));
1004 glue0
&= ~(ESR_GLUE_CTRL0_SRATE
|
1005 ESR_GLUE_CTRL0_THCNT
|
1006 ESR_GLUE_CTRL0_BLTIME
);
1007 glue0
|= (ESR_GLUE_CTRL0_RXLOSENAB
|
1008 (0xf << ESR_GLUE_CTRL0_SRATE_SHIFT
) |
1009 (0xff << ESR_GLUE_CTRL0_THCNT_SHIFT
) |
1010 (BLTIME_300_CYCLES
<<
1011 ESR_GLUE_CTRL0_BLTIME_SHIFT
));
1013 err
= esr_write_rxtx_ctrl(np
, i
, rxtx_ctrl
);
1016 err
= esr_write_glue0(np
, i
, glue0
);
1022 sig
= nr64(ESR_INT_SIGNALS
);
1025 val
= (ESR_INT_SRDY0_P0
| ESR_INT_DET0_P0
);
1030 val
= (ESR_INT_SRDY0_P1
| ESR_INT_DET0_P1
);
1038 if ((sig
& mask
) != val
) {
1039 netdev_err(np
->dev
, "Port %u signal bits [%08x] are not [%08x]\n",
1040 np
->port
, (int)(sig
& mask
), (int)val
);
1047 static int link_status_1g_serdes(struct niu
*np
, int *link_up_p
)
1049 struct niu_link_config
*lp
= &np
->link_config
;
1053 unsigned long flags
;
1057 current_speed
= SPEED_INVALID
;
1058 current_duplex
= DUPLEX_INVALID
;
1060 spin_lock_irqsave(&np
->lock
, flags
);
1062 val
= nr64_pcs(PCS_MII_STAT
);
1064 if (val
& PCS_MII_STAT_LINK_STATUS
) {
1066 current_speed
= SPEED_1000
;
1067 current_duplex
= DUPLEX_FULL
;
1070 lp
->active_speed
= current_speed
;
1071 lp
->active_duplex
= current_duplex
;
1072 spin_unlock_irqrestore(&np
->lock
, flags
);
1074 *link_up_p
= link_up
;
1078 static int link_status_10g_serdes(struct niu
*np
, int *link_up_p
)
1080 unsigned long flags
;
1081 struct niu_link_config
*lp
= &np
->link_config
;
1088 if (!(np
->flags
& NIU_FLAGS_10G
))
1089 return link_status_1g_serdes(np
, link_up_p
);
1091 current_speed
= SPEED_INVALID
;
1092 current_duplex
= DUPLEX_INVALID
;
1093 spin_lock_irqsave(&np
->lock
, flags
);
1095 val
= nr64_xpcs(XPCS_STATUS(0));
1096 val2
= nr64_mac(XMAC_INTER2
);
1097 if (val2
& 0x01000000)
1100 if ((val
& 0x1000ULL
) && link_ok
) {
1102 current_speed
= SPEED_10000
;
1103 current_duplex
= DUPLEX_FULL
;
1105 lp
->active_speed
= current_speed
;
1106 lp
->active_duplex
= current_duplex
;
1107 spin_unlock_irqrestore(&np
->lock
, flags
);
1108 *link_up_p
= link_up
;
1112 static int link_status_mii(struct niu
*np
, int *link_up_p
)
1114 struct niu_link_config
*lp
= &np
->link_config
;
1116 int bmsr
, advert
, ctrl1000
, stat1000
, lpa
, bmcr
, estatus
;
1117 int supported
, advertising
, active_speed
, active_duplex
;
1119 err
= mii_read(np
, np
->phy_addr
, MII_BMCR
);
1120 if (unlikely(err
< 0))
1124 err
= mii_read(np
, np
->phy_addr
, MII_BMSR
);
1125 if (unlikely(err
< 0))
1129 err
= mii_read(np
, np
->phy_addr
, MII_ADVERTISE
);
1130 if (unlikely(err
< 0))
1134 err
= mii_read(np
, np
->phy_addr
, MII_LPA
);
1135 if (unlikely(err
< 0))
1139 if (likely(bmsr
& BMSR_ESTATEN
)) {
1140 err
= mii_read(np
, np
->phy_addr
, MII_ESTATUS
);
1141 if (unlikely(err
< 0))
1145 err
= mii_read(np
, np
->phy_addr
, MII_CTRL1000
);
1146 if (unlikely(err
< 0))
1150 err
= mii_read(np
, np
->phy_addr
, MII_STAT1000
);
1151 if (unlikely(err
< 0))
1155 estatus
= ctrl1000
= stat1000
= 0;
1158 if (bmsr
& BMSR_ANEGCAPABLE
)
1159 supported
|= SUPPORTED_Autoneg
;
1160 if (bmsr
& BMSR_10HALF
)
1161 supported
|= SUPPORTED_10baseT_Half
;
1162 if (bmsr
& BMSR_10FULL
)
1163 supported
|= SUPPORTED_10baseT_Full
;
1164 if (bmsr
& BMSR_100HALF
)
1165 supported
|= SUPPORTED_100baseT_Half
;
1166 if (bmsr
& BMSR_100FULL
)
1167 supported
|= SUPPORTED_100baseT_Full
;
1168 if (estatus
& ESTATUS_1000_THALF
)
1169 supported
|= SUPPORTED_1000baseT_Half
;
1170 if (estatus
& ESTATUS_1000_TFULL
)
1171 supported
|= SUPPORTED_1000baseT_Full
;
1172 lp
->supported
= supported
;
1174 advertising
= mii_adv_to_ethtool_adv_t(advert
);
1175 advertising
|= mii_ctrl1000_to_ethtool_adv_t(ctrl1000
);
1177 if (bmcr
& BMCR_ANENABLE
) {
1180 lp
->active_autoneg
= 1;
1181 advertising
|= ADVERTISED_Autoneg
;
1184 neg1000
= (ctrl1000
<< 2) & stat1000
;
1186 if (neg1000
& (LPA_1000FULL
| LPA_1000HALF
))
1187 active_speed
= SPEED_1000
;
1188 else if (neg
& LPA_100
)
1189 active_speed
= SPEED_100
;
1190 else if (neg
& (LPA_10HALF
| LPA_10FULL
))
1191 active_speed
= SPEED_10
;
1193 active_speed
= SPEED_INVALID
;
1195 if ((neg1000
& LPA_1000FULL
) || (neg
& LPA_DUPLEX
))
1196 active_duplex
= DUPLEX_FULL
;
1197 else if (active_speed
!= SPEED_INVALID
)
1198 active_duplex
= DUPLEX_HALF
;
1200 active_duplex
= DUPLEX_INVALID
;
1202 lp
->active_autoneg
= 0;
1204 if ((bmcr
& BMCR_SPEED1000
) && !(bmcr
& BMCR_SPEED100
))
1205 active_speed
= SPEED_1000
;
1206 else if (bmcr
& BMCR_SPEED100
)
1207 active_speed
= SPEED_100
;
1209 active_speed
= SPEED_10
;
1211 if (bmcr
& BMCR_FULLDPLX
)
1212 active_duplex
= DUPLEX_FULL
;
1214 active_duplex
= DUPLEX_HALF
;
1217 lp
->active_advertising
= advertising
;
1218 lp
->active_speed
= active_speed
;
1219 lp
->active_duplex
= active_duplex
;
1220 *link_up_p
= !!(bmsr
& BMSR_LSTATUS
);
1225 static int link_status_1g_rgmii(struct niu
*np
, int *link_up_p
)
1227 struct niu_link_config
*lp
= &np
->link_config
;
1228 u16 current_speed
, bmsr
;
1229 unsigned long flags
;
1234 current_speed
= SPEED_INVALID
;
1235 current_duplex
= DUPLEX_INVALID
;
1237 spin_lock_irqsave(&np
->lock
, flags
);
1239 err
= mii_read(np
, np
->phy_addr
, MII_BMSR
);
1244 if (bmsr
& BMSR_LSTATUS
) {
1246 current_speed
= SPEED_1000
;
1247 current_duplex
= DUPLEX_FULL
;
1249 lp
->active_speed
= current_speed
;
1250 lp
->active_duplex
= current_duplex
;
1254 spin_unlock_irqrestore(&np
->lock
, flags
);
1256 *link_up_p
= link_up
;
1260 static int link_status_1g(struct niu
*np
, int *link_up_p
)
1262 struct niu_link_config
*lp
= &np
->link_config
;
1263 unsigned long flags
;
1266 spin_lock_irqsave(&np
->lock
, flags
);
1268 err
= link_status_mii(np
, link_up_p
);
1269 lp
->supported
|= SUPPORTED_TP
;
1270 lp
->active_advertising
|= ADVERTISED_TP
;
1272 spin_unlock_irqrestore(&np
->lock
, flags
);
1276 static int bcm8704_reset(struct niu
*np
)
1280 err
= mdio_read(np
, np
->phy_addr
,
1281 BCM8704_PHYXS_DEV_ADDR
, MII_BMCR
);
1282 if (err
< 0 || err
== 0xffff)
1285 err
= mdio_write(np
, np
->phy_addr
, BCM8704_PHYXS_DEV_ADDR
,
1291 while (--limit
>= 0) {
1292 err
= mdio_read(np
, np
->phy_addr
,
1293 BCM8704_PHYXS_DEV_ADDR
, MII_BMCR
);
1296 if (!(err
& BMCR_RESET
))
1300 netdev_err(np
->dev
, "Port %u PHY will not reset (bmcr=%04x)\n",
1301 np
->port
, (err
& 0xffff));
1307 /* When written, certain PHY registers need to be read back twice
1308 * in order for the bits to settle properly.
1310 static int bcm8704_user_dev3_readback(struct niu
*np
, int reg
)
1312 int err
= mdio_read(np
, np
->phy_addr
, BCM8704_USER_DEV3_ADDR
, reg
);
1315 err
= mdio_read(np
, np
->phy_addr
, BCM8704_USER_DEV3_ADDR
, reg
);
1321 static int bcm8706_init_user_dev3(struct niu
*np
)
1326 err
= mdio_read(np
, np
->phy_addr
, BCM8704_USER_DEV3_ADDR
,
1327 BCM8704_USER_OPT_DIGITAL_CTRL
);
1330 err
&= ~USER_ODIG_CTRL_GPIOS
;
1331 err
|= (0x3 << USER_ODIG_CTRL_GPIOS_SHIFT
);
1332 err
|= USER_ODIG_CTRL_RESV2
;
1333 err
= mdio_write(np
, np
->phy_addr
, BCM8704_USER_DEV3_ADDR
,
1334 BCM8704_USER_OPT_DIGITAL_CTRL
, err
);
1343 static int bcm8704_init_user_dev3(struct niu
*np
)
1347 err
= mdio_write(np
, np
->phy_addr
,
1348 BCM8704_USER_DEV3_ADDR
, BCM8704_USER_CONTROL
,
1349 (USER_CONTROL_OPTXRST_LVL
|
1350 USER_CONTROL_OPBIASFLT_LVL
|
1351 USER_CONTROL_OBTMPFLT_LVL
|
1352 USER_CONTROL_OPPRFLT_LVL
|
1353 USER_CONTROL_OPTXFLT_LVL
|
1354 USER_CONTROL_OPRXLOS_LVL
|
1355 USER_CONTROL_OPRXFLT_LVL
|
1356 USER_CONTROL_OPTXON_LVL
|
1357 (0x3f << USER_CONTROL_RES1_SHIFT
)));
1361 err
= mdio_write(np
, np
->phy_addr
,
1362 BCM8704_USER_DEV3_ADDR
, BCM8704_USER_PMD_TX_CONTROL
,
1363 (USER_PMD_TX_CTL_XFP_CLKEN
|
1364 (1 << USER_PMD_TX_CTL_TX_DAC_TXD_SH
) |
1365 (2 << USER_PMD_TX_CTL_TX_DAC_TXCK_SH
) |
1366 USER_PMD_TX_CTL_TSCK_LPWREN
));
1370 err
= bcm8704_user_dev3_readback(np
, BCM8704_USER_CONTROL
);
1373 err
= bcm8704_user_dev3_readback(np
, BCM8704_USER_PMD_TX_CONTROL
);
1377 err
= mdio_read(np
, np
->phy_addr
, BCM8704_USER_DEV3_ADDR
,
1378 BCM8704_USER_OPT_DIGITAL_CTRL
);
1381 err
&= ~USER_ODIG_CTRL_GPIOS
;
1382 err
|= (0x3 << USER_ODIG_CTRL_GPIOS_SHIFT
);
1383 err
= mdio_write(np
, np
->phy_addr
, BCM8704_USER_DEV3_ADDR
,
1384 BCM8704_USER_OPT_DIGITAL_CTRL
, err
);
1393 static int mrvl88x2011_act_led(struct niu
*np
, int val
)
1397 err
= mdio_read(np
, np
->phy_addr
, MRVL88X2011_USER_DEV2_ADDR
,
1398 MRVL88X2011_LED_8_TO_11_CTL
);
1402 err
&= ~MRVL88X2011_LED(MRVL88X2011_LED_ACT
,MRVL88X2011_LED_CTL_MASK
);
1403 err
|= MRVL88X2011_LED(MRVL88X2011_LED_ACT
,val
);
1405 return mdio_write(np
, np
->phy_addr
, MRVL88X2011_USER_DEV2_ADDR
,
1406 MRVL88X2011_LED_8_TO_11_CTL
, err
);
1409 static int mrvl88x2011_led_blink_rate(struct niu
*np
, int rate
)
1413 err
= mdio_read(np
, np
->phy_addr
, MRVL88X2011_USER_DEV2_ADDR
,
1414 MRVL88X2011_LED_BLINK_CTL
);
1416 err
&= ~MRVL88X2011_LED_BLKRATE_MASK
;
1419 err
= mdio_write(np
, np
->phy_addr
, MRVL88X2011_USER_DEV2_ADDR
,
1420 MRVL88X2011_LED_BLINK_CTL
, err
);
1426 static int xcvr_init_10g_mrvl88x2011(struct niu
*np
)
1430 /* Set LED functions */
1431 err
= mrvl88x2011_led_blink_rate(np
, MRVL88X2011_LED_BLKRATE_134MS
);
1436 err
= mrvl88x2011_act_led(np
, MRVL88X2011_LED_CTL_OFF
);
1440 err
= mdio_read(np
, np
->phy_addr
, MRVL88X2011_USER_DEV3_ADDR
,
1441 MRVL88X2011_GENERAL_CTL
);
1445 err
|= MRVL88X2011_ENA_XFPREFCLK
;
1447 err
= mdio_write(np
, np
->phy_addr
, MRVL88X2011_USER_DEV3_ADDR
,
1448 MRVL88X2011_GENERAL_CTL
, err
);
1452 err
= mdio_read(np
, np
->phy_addr
, MRVL88X2011_USER_DEV1_ADDR
,
1453 MRVL88X2011_PMA_PMD_CTL_1
);
1457 if (np
->link_config
.loopback_mode
== LOOPBACK_MAC
)
1458 err
|= MRVL88X2011_LOOPBACK
;
1460 err
&= ~MRVL88X2011_LOOPBACK
;
1462 err
= mdio_write(np
, np
->phy_addr
, MRVL88X2011_USER_DEV1_ADDR
,
1463 MRVL88X2011_PMA_PMD_CTL_1
, err
);
1468 return mdio_write(np
, np
->phy_addr
, MRVL88X2011_USER_DEV1_ADDR
,
1469 MRVL88X2011_10G_PMD_TX_DIS
, MRVL88X2011_ENA_PMDTX
);
1473 static int xcvr_diag_bcm870x(struct niu
*np
)
1475 u16 analog_stat0
, tx_alarm_status
;
1479 err
= mdio_read(np
, np
->phy_addr
, BCM8704_PMA_PMD_DEV_ADDR
,
1483 pr_info("Port %u PMA_PMD(MII_STAT1000) [%04x]\n", np
->port
, err
);
1485 err
= mdio_read(np
, np
->phy_addr
, BCM8704_USER_DEV3_ADDR
, 0x20);
1488 pr_info("Port %u USER_DEV3(0x20) [%04x]\n", np
->port
, err
);
1490 err
= mdio_read(np
, np
->phy_addr
, BCM8704_PHYXS_DEV_ADDR
,
1494 pr_info("Port %u PHYXS(MII_NWAYTEST) [%04x]\n", np
->port
, err
);
1497 /* XXX dig this out it might not be so useful XXX */
1498 err
= mdio_read(np
, np
->phy_addr
, BCM8704_USER_DEV3_ADDR
,
1499 BCM8704_USER_ANALOG_STATUS0
);
1502 err
= mdio_read(np
, np
->phy_addr
, BCM8704_USER_DEV3_ADDR
,
1503 BCM8704_USER_ANALOG_STATUS0
);
1508 err
= mdio_read(np
, np
->phy_addr
, BCM8704_USER_DEV3_ADDR
,
1509 BCM8704_USER_TX_ALARM_STATUS
);
1512 err
= mdio_read(np
, np
->phy_addr
, BCM8704_USER_DEV3_ADDR
,
1513 BCM8704_USER_TX_ALARM_STATUS
);
1516 tx_alarm_status
= err
;
1518 if (analog_stat0
!= 0x03fc) {
1519 if ((analog_stat0
== 0x43bc) && (tx_alarm_status
!= 0)) {
1520 pr_info("Port %u cable not connected or bad cable\n",
1522 } else if (analog_stat0
== 0x639c) {
1523 pr_info("Port %u optical module is bad or missing\n",
1531 static int xcvr_10g_set_lb_bcm870x(struct niu
*np
)
1533 struct niu_link_config
*lp
= &np
->link_config
;
1536 err
= mdio_read(np
, np
->phy_addr
, BCM8704_PCS_DEV_ADDR
,
1541 err
&= ~BMCR_LOOPBACK
;
1543 if (lp
->loopback_mode
== LOOPBACK_MAC
)
1544 err
|= BMCR_LOOPBACK
;
1546 err
= mdio_write(np
, np
->phy_addr
, BCM8704_PCS_DEV_ADDR
,
1554 static int xcvr_init_10g_bcm8706(struct niu
*np
)
1559 if ((np
->flags
& NIU_FLAGS_HOTPLUG_PHY
) &&
1560 (np
->flags
& NIU_FLAGS_HOTPLUG_PHY_PRESENT
) == 0)
1563 val
= nr64_mac(XMAC_CONFIG
);
1564 val
&= ~XMAC_CONFIG_LED_POLARITY
;
1565 val
|= XMAC_CONFIG_FORCE_LED_ON
;
1566 nw64_mac(XMAC_CONFIG
, val
);
1568 val
= nr64(MIF_CONFIG
);
1569 val
|= MIF_CONFIG_INDIRECT_MODE
;
1570 nw64(MIF_CONFIG
, val
);
1572 err
= bcm8704_reset(np
);
1576 err
= xcvr_10g_set_lb_bcm870x(np
);
1580 err
= bcm8706_init_user_dev3(np
);
1584 err
= xcvr_diag_bcm870x(np
);
1591 static int xcvr_init_10g_bcm8704(struct niu
*np
)
1595 err
= bcm8704_reset(np
);
1599 err
= bcm8704_init_user_dev3(np
);
1603 err
= xcvr_10g_set_lb_bcm870x(np
);
1607 err
= xcvr_diag_bcm870x(np
);
1614 static int xcvr_init_10g(struct niu
*np
)
1619 val
= nr64_mac(XMAC_CONFIG
);
1620 val
&= ~XMAC_CONFIG_LED_POLARITY
;
1621 val
|= XMAC_CONFIG_FORCE_LED_ON
;
1622 nw64_mac(XMAC_CONFIG
, val
);
1624 /* XXX shared resource, lock parent XXX */
1625 val
= nr64(MIF_CONFIG
);
1626 val
|= MIF_CONFIG_INDIRECT_MODE
;
1627 nw64(MIF_CONFIG
, val
);
1629 phy_id
= phy_decode(np
->parent
->port_phy
, np
->port
);
1630 phy_id
= np
->parent
->phy_probe_info
.phy_id
[phy_id
][np
->port
];
1632 /* handle different phy types */
1633 switch (phy_id
& NIU_PHY_ID_MASK
) {
1634 case NIU_PHY_ID_MRVL88X2011
:
1635 err
= xcvr_init_10g_mrvl88x2011(np
);
1638 default: /* bcom 8704 */
1639 err
= xcvr_init_10g_bcm8704(np
);
1646 static int mii_reset(struct niu
*np
)
1650 err
= mii_write(np
, np
->phy_addr
, MII_BMCR
, BMCR_RESET
);
1655 while (--limit
>= 0) {
1657 err
= mii_read(np
, np
->phy_addr
, MII_BMCR
);
1660 if (!(err
& BMCR_RESET
))
1664 netdev_err(np
->dev
, "Port %u MII would not reset, bmcr[%04x]\n",
1672 static int xcvr_init_1g_rgmii(struct niu
*np
)
1676 u16 bmcr
, bmsr
, estat
;
1678 val
= nr64(MIF_CONFIG
);
1679 val
&= ~MIF_CONFIG_INDIRECT_MODE
;
1680 nw64(MIF_CONFIG
, val
);
1682 err
= mii_reset(np
);
1686 err
= mii_read(np
, np
->phy_addr
, MII_BMSR
);
1692 if (bmsr
& BMSR_ESTATEN
) {
1693 err
= mii_read(np
, np
->phy_addr
, MII_ESTATUS
);
1700 err
= mii_write(np
, np
->phy_addr
, MII_BMCR
, bmcr
);
1704 if (bmsr
& BMSR_ESTATEN
) {
1707 if (estat
& ESTATUS_1000_TFULL
)
1708 ctrl1000
|= ADVERTISE_1000FULL
;
1709 err
= mii_write(np
, np
->phy_addr
, MII_CTRL1000
, ctrl1000
);
1714 bmcr
= (BMCR_SPEED1000
| BMCR_FULLDPLX
);
1716 err
= mii_write(np
, np
->phy_addr
, MII_BMCR
, bmcr
);
1720 err
= mii_read(np
, np
->phy_addr
, MII_BMCR
);
1723 bmcr
= mii_read(np
, np
->phy_addr
, MII_BMCR
);
1725 err
= mii_read(np
, np
->phy_addr
, MII_BMSR
);
1732 static int mii_init_common(struct niu
*np
)
1734 struct niu_link_config
*lp
= &np
->link_config
;
1735 u16 bmcr
, bmsr
, adv
, estat
;
1738 err
= mii_reset(np
);
1742 err
= mii_read(np
, np
->phy_addr
, MII_BMSR
);
1748 if (bmsr
& BMSR_ESTATEN
) {
1749 err
= mii_read(np
, np
->phy_addr
, MII_ESTATUS
);
1756 err
= mii_write(np
, np
->phy_addr
, MII_BMCR
, bmcr
);
1760 if (lp
->loopback_mode
== LOOPBACK_MAC
) {
1761 bmcr
|= BMCR_LOOPBACK
;
1762 if (lp
->active_speed
== SPEED_1000
)
1763 bmcr
|= BMCR_SPEED1000
;
1764 if (lp
->active_duplex
== DUPLEX_FULL
)
1765 bmcr
|= BMCR_FULLDPLX
;
1768 if (lp
->loopback_mode
== LOOPBACK_PHY
) {
1771 aux
= (BCM5464R_AUX_CTL_EXT_LB
|
1772 BCM5464R_AUX_CTL_WRITE_1
);
1773 err
= mii_write(np
, np
->phy_addr
, BCM5464R_AUX_CTL
, aux
);
1781 adv
= ADVERTISE_CSMA
| ADVERTISE_PAUSE_CAP
;
1782 if ((bmsr
& BMSR_10HALF
) &&
1783 (lp
->advertising
& ADVERTISED_10baseT_Half
))
1784 adv
|= ADVERTISE_10HALF
;
1785 if ((bmsr
& BMSR_10FULL
) &&
1786 (lp
->advertising
& ADVERTISED_10baseT_Full
))
1787 adv
|= ADVERTISE_10FULL
;
1788 if ((bmsr
& BMSR_100HALF
) &&
1789 (lp
->advertising
& ADVERTISED_100baseT_Half
))
1790 adv
|= ADVERTISE_100HALF
;
1791 if ((bmsr
& BMSR_100FULL
) &&
1792 (lp
->advertising
& ADVERTISED_100baseT_Full
))
1793 adv
|= ADVERTISE_100FULL
;
1794 err
= mii_write(np
, np
->phy_addr
, MII_ADVERTISE
, adv
);
1798 if (likely(bmsr
& BMSR_ESTATEN
)) {
1800 if ((estat
& ESTATUS_1000_THALF
) &&
1801 (lp
->advertising
& ADVERTISED_1000baseT_Half
))
1802 ctrl1000
|= ADVERTISE_1000HALF
;
1803 if ((estat
& ESTATUS_1000_TFULL
) &&
1804 (lp
->advertising
& ADVERTISED_1000baseT_Full
))
1805 ctrl1000
|= ADVERTISE_1000FULL
;
1806 err
= mii_write(np
, np
->phy_addr
,
1807 MII_CTRL1000
, ctrl1000
);
1812 bmcr
|= (BMCR_ANENABLE
| BMCR_ANRESTART
);
1817 if (lp
->duplex
== DUPLEX_FULL
) {
1818 bmcr
|= BMCR_FULLDPLX
;
1820 } else if (lp
->duplex
== DUPLEX_HALF
)
1825 if (lp
->speed
== SPEED_1000
) {
1826 /* if X-full requested while not supported, or
1827 X-half requested while not supported... */
1828 if ((fulldpx
&& !(estat
& ESTATUS_1000_TFULL
)) ||
1829 (!fulldpx
&& !(estat
& ESTATUS_1000_THALF
)))
1831 bmcr
|= BMCR_SPEED1000
;
1832 } else if (lp
->speed
== SPEED_100
) {
1833 if ((fulldpx
&& !(bmsr
& BMSR_100FULL
)) ||
1834 (!fulldpx
&& !(bmsr
& BMSR_100HALF
)))
1836 bmcr
|= BMCR_SPEED100
;
1837 } else if (lp
->speed
== SPEED_10
) {
1838 if ((fulldpx
&& !(bmsr
& BMSR_10FULL
)) ||
1839 (!fulldpx
&& !(bmsr
& BMSR_10HALF
)))
1845 err
= mii_write(np
, np
->phy_addr
, MII_BMCR
, bmcr
);
1850 err
= mii_read(np
, np
->phy_addr
, MII_BMCR
);
1855 err
= mii_read(np
, np
->phy_addr
, MII_BMSR
);
1860 pr_info("Port %u after MII init bmcr[%04x] bmsr[%04x]\n",
1861 np
->port
, bmcr
, bmsr
);
1867 static int xcvr_init_1g(struct niu
*np
)
1871 /* XXX shared resource, lock parent XXX */
1872 val
= nr64(MIF_CONFIG
);
1873 val
&= ~MIF_CONFIG_INDIRECT_MODE
;
1874 nw64(MIF_CONFIG
, val
);
1876 return mii_init_common(np
);
1879 static int niu_xcvr_init(struct niu
*np
)
1881 const struct niu_phy_ops
*ops
= np
->phy_ops
;
1886 err
= ops
->xcvr_init(np
);
1891 static int niu_serdes_init(struct niu
*np
)
1893 const struct niu_phy_ops
*ops
= np
->phy_ops
;
1897 if (ops
->serdes_init
)
1898 err
= ops
->serdes_init(np
);
1903 static void niu_init_xif(struct niu
*);
1904 static void niu_handle_led(struct niu
*, int status
);
1906 static int niu_link_status_common(struct niu
*np
, int link_up
)
1908 struct niu_link_config
*lp
= &np
->link_config
;
1909 struct net_device
*dev
= np
->dev
;
1910 unsigned long flags
;
1912 if (!netif_carrier_ok(dev
) && link_up
) {
1913 netif_info(np
, link
, dev
, "Link is up at %s, %s duplex\n",
1914 lp
->active_speed
== SPEED_10000
? "10Gb/sec" :
1915 lp
->active_speed
== SPEED_1000
? "1Gb/sec" :
1916 lp
->active_speed
== SPEED_100
? "100Mbit/sec" :
1918 lp
->active_duplex
== DUPLEX_FULL
? "full" : "half");
1920 spin_lock_irqsave(&np
->lock
, flags
);
1922 niu_handle_led(np
, 1);
1923 spin_unlock_irqrestore(&np
->lock
, flags
);
1925 netif_carrier_on(dev
);
1926 } else if (netif_carrier_ok(dev
) && !link_up
) {
1927 netif_warn(np
, link
, dev
, "Link is down\n");
1928 spin_lock_irqsave(&np
->lock
, flags
);
1929 niu_handle_led(np
, 0);
1930 spin_unlock_irqrestore(&np
->lock
, flags
);
1931 netif_carrier_off(dev
);
1937 static int link_status_10g_mrvl(struct niu
*np
, int *link_up_p
)
1939 int err
, link_up
, pma_status
, pcs_status
;
1943 err
= mdio_read(np
, np
->phy_addr
, MRVL88X2011_USER_DEV1_ADDR
,
1944 MRVL88X2011_10G_PMD_STATUS_2
);
1948 /* Check PMA/PMD Register: 1.0001.2 == 1 */
1949 err
= mdio_read(np
, np
->phy_addr
, MRVL88X2011_USER_DEV1_ADDR
,
1950 MRVL88X2011_PMA_PMD_STATUS_1
);
1954 pma_status
= ((err
& MRVL88X2011_LNK_STATUS_OK
) ? 1 : 0);
1956 /* Check PMC Register : 3.0001.2 == 1: read twice */
1957 err
= mdio_read(np
, np
->phy_addr
, MRVL88X2011_USER_DEV3_ADDR
,
1958 MRVL88X2011_PMA_PMD_STATUS_1
);
1962 err
= mdio_read(np
, np
->phy_addr
, MRVL88X2011_USER_DEV3_ADDR
,
1963 MRVL88X2011_PMA_PMD_STATUS_1
);
1967 pcs_status
= ((err
& MRVL88X2011_LNK_STATUS_OK
) ? 1 : 0);
1969 /* Check XGXS Register : 4.0018.[0-3,12] */
1970 err
= mdio_read(np
, np
->phy_addr
, MRVL88X2011_USER_DEV4_ADDR
,
1971 MRVL88X2011_10G_XGXS_LANE_STAT
);
1975 if (err
== (PHYXS_XGXS_LANE_STAT_ALINGED
| PHYXS_XGXS_LANE_STAT_LANE3
|
1976 PHYXS_XGXS_LANE_STAT_LANE2
| PHYXS_XGXS_LANE_STAT_LANE1
|
1977 PHYXS_XGXS_LANE_STAT_LANE0
| PHYXS_XGXS_LANE_STAT_MAGIC
|
1979 link_up
= (pma_status
&& pcs_status
) ? 1 : 0;
1981 np
->link_config
.active_speed
= SPEED_10000
;
1982 np
->link_config
.active_duplex
= DUPLEX_FULL
;
1985 mrvl88x2011_act_led(np
, (link_up
?
1986 MRVL88X2011_LED_CTL_PCS_ACT
:
1987 MRVL88X2011_LED_CTL_OFF
));
1989 *link_up_p
= link_up
;
1993 static int link_status_10g_bcm8706(struct niu
*np
, int *link_up_p
)
1998 err
= mdio_read(np
, np
->phy_addr
, BCM8704_PMA_PMD_DEV_ADDR
,
1999 BCM8704_PMD_RCV_SIGDET
);
2000 if (err
< 0 || err
== 0xffff)
2002 if (!(err
& PMD_RCV_SIGDET_GLOBAL
)) {
2007 err
= mdio_read(np
, np
->phy_addr
, BCM8704_PCS_DEV_ADDR
,
2008 BCM8704_PCS_10G_R_STATUS
);
2012 if (!(err
& PCS_10G_R_STATUS_BLK_LOCK
)) {
2017 err
= mdio_read(np
, np
->phy_addr
, BCM8704_PHYXS_DEV_ADDR
,
2018 BCM8704_PHYXS_XGXS_LANE_STAT
);
2021 if (err
!= (PHYXS_XGXS_LANE_STAT_ALINGED
|
2022 PHYXS_XGXS_LANE_STAT_MAGIC
|
2023 PHYXS_XGXS_LANE_STAT_PATTEST
|
2024 PHYXS_XGXS_LANE_STAT_LANE3
|
2025 PHYXS_XGXS_LANE_STAT_LANE2
|
2026 PHYXS_XGXS_LANE_STAT_LANE1
|
2027 PHYXS_XGXS_LANE_STAT_LANE0
)) {
2029 np
->link_config
.active_speed
= SPEED_INVALID
;
2030 np
->link_config
.active_duplex
= DUPLEX_INVALID
;
2035 np
->link_config
.active_speed
= SPEED_10000
;
2036 np
->link_config
.active_duplex
= DUPLEX_FULL
;
2040 *link_up_p
= link_up
;
2044 static int link_status_10g_bcom(struct niu
*np
, int *link_up_p
)
2050 err
= mdio_read(np
, np
->phy_addr
, BCM8704_PMA_PMD_DEV_ADDR
,
2051 BCM8704_PMD_RCV_SIGDET
);
2054 if (!(err
& PMD_RCV_SIGDET_GLOBAL
)) {
2059 err
= mdio_read(np
, np
->phy_addr
, BCM8704_PCS_DEV_ADDR
,
2060 BCM8704_PCS_10G_R_STATUS
);
2063 if (!(err
& PCS_10G_R_STATUS_BLK_LOCK
)) {
2068 err
= mdio_read(np
, np
->phy_addr
, BCM8704_PHYXS_DEV_ADDR
,
2069 BCM8704_PHYXS_XGXS_LANE_STAT
);
2073 if (err
!= (PHYXS_XGXS_LANE_STAT_ALINGED
|
2074 PHYXS_XGXS_LANE_STAT_MAGIC
|
2075 PHYXS_XGXS_LANE_STAT_LANE3
|
2076 PHYXS_XGXS_LANE_STAT_LANE2
|
2077 PHYXS_XGXS_LANE_STAT_LANE1
|
2078 PHYXS_XGXS_LANE_STAT_LANE0
)) {
2084 np
->link_config
.active_speed
= SPEED_10000
;
2085 np
->link_config
.active_duplex
= DUPLEX_FULL
;
2089 *link_up_p
= link_up
;
2093 static int link_status_10g(struct niu
*np
, int *link_up_p
)
2095 unsigned long flags
;
2098 spin_lock_irqsave(&np
->lock
, flags
);
2100 if (np
->link_config
.loopback_mode
== LOOPBACK_DISABLED
) {
2103 phy_id
= phy_decode(np
->parent
->port_phy
, np
->port
);
2104 phy_id
= np
->parent
->phy_probe_info
.phy_id
[phy_id
][np
->port
];
2106 /* handle different phy types */
2107 switch (phy_id
& NIU_PHY_ID_MASK
) {
2108 case NIU_PHY_ID_MRVL88X2011
:
2109 err
= link_status_10g_mrvl(np
, link_up_p
);
2112 default: /* bcom 8704 */
2113 err
= link_status_10g_bcom(np
, link_up_p
);
2118 spin_unlock_irqrestore(&np
->lock
, flags
);
2123 static int niu_10g_phy_present(struct niu
*np
)
2127 sig
= nr64(ESR_INT_SIGNALS
);
2130 mask
= ESR_INT_SIGNALS_P0_BITS
;
2131 val
= (ESR_INT_SRDY0_P0
|
2134 ESR_INT_XDP_P0_CH3
|
2135 ESR_INT_XDP_P0_CH2
|
2136 ESR_INT_XDP_P0_CH1
|
2137 ESR_INT_XDP_P0_CH0
);
2141 mask
= ESR_INT_SIGNALS_P1_BITS
;
2142 val
= (ESR_INT_SRDY0_P1
|
2145 ESR_INT_XDP_P1_CH3
|
2146 ESR_INT_XDP_P1_CH2
|
2147 ESR_INT_XDP_P1_CH1
|
2148 ESR_INT_XDP_P1_CH0
);
2155 if ((sig
& mask
) != val
)
2160 static int link_status_10g_hotplug(struct niu
*np
, int *link_up_p
)
2162 unsigned long flags
;
2165 int phy_present_prev
;
2167 spin_lock_irqsave(&np
->lock
, flags
);
2169 if (np
->link_config
.loopback_mode
== LOOPBACK_DISABLED
) {
2170 phy_present_prev
= (np
->flags
& NIU_FLAGS_HOTPLUG_PHY_PRESENT
) ?
2172 phy_present
= niu_10g_phy_present(np
);
2173 if (phy_present
!= phy_present_prev
) {
2176 /* A NEM was just plugged in */
2177 np
->flags
|= NIU_FLAGS_HOTPLUG_PHY_PRESENT
;
2178 if (np
->phy_ops
->xcvr_init
)
2179 err
= np
->phy_ops
->xcvr_init(np
);
2181 err
= mdio_read(np
, np
->phy_addr
,
2182 BCM8704_PHYXS_DEV_ADDR
, MII_BMCR
);
2183 if (err
== 0xffff) {
2184 /* No mdio, back-to-back XAUI */
2188 np
->flags
&= ~NIU_FLAGS_HOTPLUG_PHY_PRESENT
;
2191 np
->flags
&= ~NIU_FLAGS_HOTPLUG_PHY_PRESENT
;
2193 netif_warn(np
, link
, np
->dev
,
2194 "Hotplug PHY Removed\n");
2198 if (np
->flags
& NIU_FLAGS_HOTPLUG_PHY_PRESENT
) {
2199 err
= link_status_10g_bcm8706(np
, link_up_p
);
2200 if (err
== 0xffff) {
2201 /* No mdio, back-to-back XAUI: it is C10NEM */
2203 np
->link_config
.active_speed
= SPEED_10000
;
2204 np
->link_config
.active_duplex
= DUPLEX_FULL
;
2209 spin_unlock_irqrestore(&np
->lock
, flags
);
2214 static int niu_link_status(struct niu
*np
, int *link_up_p
)
2216 const struct niu_phy_ops
*ops
= np
->phy_ops
;
2220 if (ops
->link_status
)
2221 err
= ops
->link_status(np
, link_up_p
);
2226 static void niu_timer(struct timer_list
*t
)
2228 struct niu
*np
= from_timer(np
, t
, timer
);
2232 err
= niu_link_status(np
, &link_up
);
2234 niu_link_status_common(np
, link_up
);
2236 if (netif_carrier_ok(np
->dev
))
2240 np
->timer
.expires
= jiffies
+ off
;
2242 add_timer(&np
->timer
);
2245 static const struct niu_phy_ops phy_ops_10g_serdes
= {
2246 .serdes_init
= serdes_init_10g_serdes
,
2247 .link_status
= link_status_10g_serdes
,
2250 static const struct niu_phy_ops phy_ops_10g_serdes_niu
= {
2251 .serdes_init
= serdes_init_niu_10g_serdes
,
2252 .link_status
= link_status_10g_serdes
,
2255 static const struct niu_phy_ops phy_ops_1g_serdes_niu
= {
2256 .serdes_init
= serdes_init_niu_1g_serdes
,
2257 .link_status
= link_status_1g_serdes
,
2260 static const struct niu_phy_ops phy_ops_1g_rgmii
= {
2261 .xcvr_init
= xcvr_init_1g_rgmii
,
2262 .link_status
= link_status_1g_rgmii
,
2265 static const struct niu_phy_ops phy_ops_10g_fiber_niu
= {
2266 .serdes_init
= serdes_init_niu_10g_fiber
,
2267 .xcvr_init
= xcvr_init_10g
,
2268 .link_status
= link_status_10g
,
2271 static const struct niu_phy_ops phy_ops_10g_fiber
= {
2272 .serdes_init
= serdes_init_10g
,
2273 .xcvr_init
= xcvr_init_10g
,
2274 .link_status
= link_status_10g
,
2277 static const struct niu_phy_ops phy_ops_10g_fiber_hotplug
= {
2278 .serdes_init
= serdes_init_10g
,
2279 .xcvr_init
= xcvr_init_10g_bcm8706
,
2280 .link_status
= link_status_10g_hotplug
,
2283 static const struct niu_phy_ops phy_ops_niu_10g_hotplug
= {
2284 .serdes_init
= serdes_init_niu_10g_fiber
,
2285 .xcvr_init
= xcvr_init_10g_bcm8706
,
2286 .link_status
= link_status_10g_hotplug
,
2289 static const struct niu_phy_ops phy_ops_10g_copper
= {
2290 .serdes_init
= serdes_init_10g
,
2291 .link_status
= link_status_10g
, /* XXX */
2294 static const struct niu_phy_ops phy_ops_1g_fiber
= {
2295 .serdes_init
= serdes_init_1g
,
2296 .xcvr_init
= xcvr_init_1g
,
2297 .link_status
= link_status_1g
,
2300 static const struct niu_phy_ops phy_ops_1g_copper
= {
2301 .xcvr_init
= xcvr_init_1g
,
2302 .link_status
= link_status_1g
,
2305 struct niu_phy_template
{
2306 const struct niu_phy_ops
*ops
;
2310 static const struct niu_phy_template phy_template_niu_10g_fiber
= {
2311 .ops
= &phy_ops_10g_fiber_niu
,
2312 .phy_addr_base
= 16,
2315 static const struct niu_phy_template phy_template_niu_10g_serdes
= {
2316 .ops
= &phy_ops_10g_serdes_niu
,
2320 static const struct niu_phy_template phy_template_niu_1g_serdes
= {
2321 .ops
= &phy_ops_1g_serdes_niu
,
2325 static const struct niu_phy_template phy_template_10g_fiber
= {
2326 .ops
= &phy_ops_10g_fiber
,
2330 static const struct niu_phy_template phy_template_10g_fiber_hotplug
= {
2331 .ops
= &phy_ops_10g_fiber_hotplug
,
2335 static const struct niu_phy_template phy_template_niu_10g_hotplug
= {
2336 .ops
= &phy_ops_niu_10g_hotplug
,
2340 static const struct niu_phy_template phy_template_10g_copper
= {
2341 .ops
= &phy_ops_10g_copper
,
2342 .phy_addr_base
= 10,
2345 static const struct niu_phy_template phy_template_1g_fiber
= {
2346 .ops
= &phy_ops_1g_fiber
,
2350 static const struct niu_phy_template phy_template_1g_copper
= {
2351 .ops
= &phy_ops_1g_copper
,
2355 static const struct niu_phy_template phy_template_1g_rgmii
= {
2356 .ops
= &phy_ops_1g_rgmii
,
2360 static const struct niu_phy_template phy_template_10g_serdes
= {
2361 .ops
= &phy_ops_10g_serdes
,
2365 static int niu_atca_port_num
[4] = {
2369 static int serdes_init_10g_serdes(struct niu
*np
)
2371 struct niu_link_config
*lp
= &np
->link_config
;
2372 unsigned long ctrl_reg
, test_cfg_reg
, pll_cfg
, i
;
2373 u64 ctrl_val
, test_cfg_val
, sig
, mask
, val
;
2377 ctrl_reg
= ENET_SERDES_0_CTRL_CFG
;
2378 test_cfg_reg
= ENET_SERDES_0_TEST_CFG
;
2379 pll_cfg
= ENET_SERDES_0_PLL_CFG
;
2382 ctrl_reg
= ENET_SERDES_1_CTRL_CFG
;
2383 test_cfg_reg
= ENET_SERDES_1_TEST_CFG
;
2384 pll_cfg
= ENET_SERDES_1_PLL_CFG
;
2390 ctrl_val
= (ENET_SERDES_CTRL_SDET_0
|
2391 ENET_SERDES_CTRL_SDET_1
|
2392 ENET_SERDES_CTRL_SDET_2
|
2393 ENET_SERDES_CTRL_SDET_3
|
2394 (0x5 << ENET_SERDES_CTRL_EMPH_0_SHIFT
) |
2395 (0x5 << ENET_SERDES_CTRL_EMPH_1_SHIFT
) |
2396 (0x5 << ENET_SERDES_CTRL_EMPH_2_SHIFT
) |
2397 (0x5 << ENET_SERDES_CTRL_EMPH_3_SHIFT
) |
2398 (0x1 << ENET_SERDES_CTRL_LADJ_0_SHIFT
) |
2399 (0x1 << ENET_SERDES_CTRL_LADJ_1_SHIFT
) |
2400 (0x1 << ENET_SERDES_CTRL_LADJ_2_SHIFT
) |
2401 (0x1 << ENET_SERDES_CTRL_LADJ_3_SHIFT
));
2404 if (lp
->loopback_mode
== LOOPBACK_PHY
) {
2405 test_cfg_val
|= ((ENET_TEST_MD_PAD_LOOPBACK
<<
2406 ENET_SERDES_TEST_MD_0_SHIFT
) |
2407 (ENET_TEST_MD_PAD_LOOPBACK
<<
2408 ENET_SERDES_TEST_MD_1_SHIFT
) |
2409 (ENET_TEST_MD_PAD_LOOPBACK
<<
2410 ENET_SERDES_TEST_MD_2_SHIFT
) |
2411 (ENET_TEST_MD_PAD_LOOPBACK
<<
2412 ENET_SERDES_TEST_MD_3_SHIFT
));
2416 nw64(pll_cfg
, ENET_SERDES_PLL_FBDIV2
);
2417 nw64(ctrl_reg
, ctrl_val
);
2418 nw64(test_cfg_reg
, test_cfg_val
);
2420 /* Initialize all 4 lanes of the SERDES. */
2421 for (i
= 0; i
< 4; i
++) {
2422 u32 rxtx_ctrl
, glue0
;
2425 err
= esr_read_rxtx_ctrl(np
, i
, &rxtx_ctrl
);
2428 err
= esr_read_glue0(np
, i
, &glue0
);
2432 rxtx_ctrl
&= ~(ESR_RXTX_CTRL_VMUXLO
);
2433 rxtx_ctrl
|= (ESR_RXTX_CTRL_ENSTRETCH
|
2434 (2 << ESR_RXTX_CTRL_VMUXLO_SHIFT
));
2436 glue0
&= ~(ESR_GLUE_CTRL0_SRATE
|
2437 ESR_GLUE_CTRL0_THCNT
|
2438 ESR_GLUE_CTRL0_BLTIME
);
2439 glue0
|= (ESR_GLUE_CTRL0_RXLOSENAB
|
2440 (0xf << ESR_GLUE_CTRL0_SRATE_SHIFT
) |
2441 (0xff << ESR_GLUE_CTRL0_THCNT_SHIFT
) |
2442 (BLTIME_300_CYCLES
<<
2443 ESR_GLUE_CTRL0_BLTIME_SHIFT
));
2445 err
= esr_write_rxtx_ctrl(np
, i
, rxtx_ctrl
);
2448 err
= esr_write_glue0(np
, i
, glue0
);
2454 sig
= nr64(ESR_INT_SIGNALS
);
2457 mask
= ESR_INT_SIGNALS_P0_BITS
;
2458 val
= (ESR_INT_SRDY0_P0
|
2461 ESR_INT_XDP_P0_CH3
|
2462 ESR_INT_XDP_P0_CH2
|
2463 ESR_INT_XDP_P0_CH1
|
2464 ESR_INT_XDP_P0_CH0
);
2468 mask
= ESR_INT_SIGNALS_P1_BITS
;
2469 val
= (ESR_INT_SRDY0_P1
|
2472 ESR_INT_XDP_P1_CH3
|
2473 ESR_INT_XDP_P1_CH2
|
2474 ESR_INT_XDP_P1_CH1
|
2475 ESR_INT_XDP_P1_CH0
);
2482 if ((sig
& mask
) != val
) {
2484 err
= serdes_init_1g_serdes(np
);
2486 np
->flags
&= ~NIU_FLAGS_10G
;
2487 np
->mac_xcvr
= MAC_XCVR_PCS
;
2489 netdev_err(np
->dev
, "Port %u 10G/1G SERDES Link Failed\n",
2498 static int niu_determine_phy_disposition(struct niu
*np
)
2500 struct niu_parent
*parent
= np
->parent
;
2501 u8 plat_type
= parent
->plat_type
;
2502 const struct niu_phy_template
*tp
;
2503 u32 phy_addr_off
= 0;
2505 if (plat_type
== PLAT_TYPE_NIU
) {
2509 NIU_FLAGS_XCVR_SERDES
)) {
2510 case NIU_FLAGS_10G
| NIU_FLAGS_XCVR_SERDES
:
2512 tp
= &phy_template_niu_10g_serdes
;
2514 case NIU_FLAGS_XCVR_SERDES
:
2516 tp
= &phy_template_niu_1g_serdes
;
2518 case NIU_FLAGS_10G
| NIU_FLAGS_FIBER
:
2521 if (np
->flags
& NIU_FLAGS_HOTPLUG_PHY
) {
2522 tp
= &phy_template_niu_10g_hotplug
;
2528 tp
= &phy_template_niu_10g_fiber
;
2529 phy_addr_off
+= np
->port
;
2537 NIU_FLAGS_XCVR_SERDES
)) {
2540 tp
= &phy_template_1g_copper
;
2541 if (plat_type
== PLAT_TYPE_VF_P0
)
2543 else if (plat_type
== PLAT_TYPE_VF_P1
)
2546 phy_addr_off
+= (np
->port
^ 0x3);
2551 tp
= &phy_template_10g_copper
;
2554 case NIU_FLAGS_FIBER
:
2556 tp
= &phy_template_1g_fiber
;
2559 case NIU_FLAGS_10G
| NIU_FLAGS_FIBER
:
2561 tp
= &phy_template_10g_fiber
;
2562 if (plat_type
== PLAT_TYPE_VF_P0
||
2563 plat_type
== PLAT_TYPE_VF_P1
)
2565 phy_addr_off
+= np
->port
;
2566 if (np
->flags
& NIU_FLAGS_HOTPLUG_PHY
) {
2567 tp
= &phy_template_10g_fiber_hotplug
;
2575 case NIU_FLAGS_10G
| NIU_FLAGS_XCVR_SERDES
:
2576 case NIU_FLAGS_XCVR_SERDES
| NIU_FLAGS_FIBER
:
2577 case NIU_FLAGS_XCVR_SERDES
:
2581 tp
= &phy_template_10g_serdes
;
2585 tp
= &phy_template_1g_rgmii
;
2590 phy_addr_off
= niu_atca_port_num
[np
->port
];
2598 np
->phy_ops
= tp
->ops
;
2599 np
->phy_addr
= tp
->phy_addr_base
+ phy_addr_off
;
2604 static int niu_init_link(struct niu
*np
)
2606 struct niu_parent
*parent
= np
->parent
;
2609 if (parent
->plat_type
== PLAT_TYPE_NIU
) {
2610 err
= niu_xcvr_init(np
);
2615 err
= niu_serdes_init(np
);
2616 if (err
&& !(np
->flags
& NIU_FLAGS_HOTPLUG_PHY
))
2619 err
= niu_xcvr_init(np
);
2620 if (!err
|| (np
->flags
& NIU_FLAGS_HOTPLUG_PHY
))
2621 niu_link_status(np
, &ignore
);
2625 static void niu_set_primary_mac(struct niu
*np
, const unsigned char *addr
)
2627 u16 reg0
= addr
[4] << 8 | addr
[5];
2628 u16 reg1
= addr
[2] << 8 | addr
[3];
2629 u16 reg2
= addr
[0] << 8 | addr
[1];
2631 if (np
->flags
& NIU_FLAGS_XMAC
) {
2632 nw64_mac(XMAC_ADDR0
, reg0
);
2633 nw64_mac(XMAC_ADDR1
, reg1
);
2634 nw64_mac(XMAC_ADDR2
, reg2
);
2636 nw64_mac(BMAC_ADDR0
, reg0
);
2637 nw64_mac(BMAC_ADDR1
, reg1
);
2638 nw64_mac(BMAC_ADDR2
, reg2
);
2642 static int niu_num_alt_addr(struct niu
*np
)
2644 if (np
->flags
& NIU_FLAGS_XMAC
)
2645 return XMAC_NUM_ALT_ADDR
;
2647 return BMAC_NUM_ALT_ADDR
;
2650 static int niu_set_alt_mac(struct niu
*np
, int index
, unsigned char *addr
)
2652 u16 reg0
= addr
[4] << 8 | addr
[5];
2653 u16 reg1
= addr
[2] << 8 | addr
[3];
2654 u16 reg2
= addr
[0] << 8 | addr
[1];
2656 if (index
>= niu_num_alt_addr(np
))
2659 if (np
->flags
& NIU_FLAGS_XMAC
) {
2660 nw64_mac(XMAC_ALT_ADDR0(index
), reg0
);
2661 nw64_mac(XMAC_ALT_ADDR1(index
), reg1
);
2662 nw64_mac(XMAC_ALT_ADDR2(index
), reg2
);
2664 nw64_mac(BMAC_ALT_ADDR0(index
), reg0
);
2665 nw64_mac(BMAC_ALT_ADDR1(index
), reg1
);
2666 nw64_mac(BMAC_ALT_ADDR2(index
), reg2
);
2672 static int niu_enable_alt_mac(struct niu
*np
, int index
, int on
)
2677 if (index
>= niu_num_alt_addr(np
))
2680 if (np
->flags
& NIU_FLAGS_XMAC
) {
2681 reg
= XMAC_ADDR_CMPEN
;
2684 reg
= BMAC_ADDR_CMPEN
;
2685 mask
= 1 << (index
+ 1);
2688 val
= nr64_mac(reg
);
2698 static void __set_rdc_table_num_hw(struct niu
*np
, unsigned long reg
,
2699 int num
, int mac_pref
)
2701 u64 val
= nr64_mac(reg
);
2702 val
&= ~(HOST_INFO_MACRDCTBLN
| HOST_INFO_MPR
);
2705 val
|= HOST_INFO_MPR
;
2709 static int __set_rdc_table_num(struct niu
*np
,
2710 int xmac_index
, int bmac_index
,
2711 int rdc_table_num
, int mac_pref
)
2715 if (rdc_table_num
& ~HOST_INFO_MACRDCTBLN
)
2717 if (np
->flags
& NIU_FLAGS_XMAC
)
2718 reg
= XMAC_HOST_INFO(xmac_index
);
2720 reg
= BMAC_HOST_INFO(bmac_index
);
2721 __set_rdc_table_num_hw(np
, reg
, rdc_table_num
, mac_pref
);
2725 static int niu_set_primary_mac_rdc_table(struct niu
*np
, int table_num
,
2728 return __set_rdc_table_num(np
, 17, 0, table_num
, mac_pref
);
2731 static int niu_set_multicast_mac_rdc_table(struct niu
*np
, int table_num
,
2734 return __set_rdc_table_num(np
, 16, 8, table_num
, mac_pref
);
2737 static int niu_set_alt_mac_rdc_table(struct niu
*np
, int idx
,
2738 int table_num
, int mac_pref
)
2740 if (idx
>= niu_num_alt_addr(np
))
2742 return __set_rdc_table_num(np
, idx
, idx
+ 1, table_num
, mac_pref
);
2745 static u64
vlan_entry_set_parity(u64 reg_val
)
2750 port01_mask
= 0x00ff;
2751 port23_mask
= 0xff00;
2753 if (hweight64(reg_val
& port01_mask
) & 1)
2754 reg_val
|= ENET_VLAN_TBL_PARITY0
;
2756 reg_val
&= ~ENET_VLAN_TBL_PARITY0
;
2758 if (hweight64(reg_val
& port23_mask
) & 1)
2759 reg_val
|= ENET_VLAN_TBL_PARITY1
;
2761 reg_val
&= ~ENET_VLAN_TBL_PARITY1
;
2766 static void vlan_tbl_write(struct niu
*np
, unsigned long index
,
2767 int port
, int vpr
, int rdc_table
)
2769 u64 reg_val
= nr64(ENET_VLAN_TBL(index
));
2771 reg_val
&= ~((ENET_VLAN_TBL_VPR
|
2772 ENET_VLAN_TBL_VLANRDCTBLN
) <<
2773 ENET_VLAN_TBL_SHIFT(port
));
2775 reg_val
|= (ENET_VLAN_TBL_VPR
<<
2776 ENET_VLAN_TBL_SHIFT(port
));
2777 reg_val
|= (rdc_table
<< ENET_VLAN_TBL_SHIFT(port
));
2779 reg_val
= vlan_entry_set_parity(reg_val
);
2781 nw64(ENET_VLAN_TBL(index
), reg_val
);
2784 static void vlan_tbl_clear(struct niu
*np
)
2788 for (i
= 0; i
< ENET_VLAN_TBL_NUM_ENTRIES
; i
++)
2789 nw64(ENET_VLAN_TBL(i
), 0);
2792 static int tcam_wait_bit(struct niu
*np
, u64 bit
)
2796 while (--limit
> 0) {
2797 if (nr64(TCAM_CTL
) & bit
)
2807 static int tcam_flush(struct niu
*np
, int index
)
2809 nw64(TCAM_KEY_0
, 0x00);
2810 nw64(TCAM_KEY_MASK_0
, 0xff);
2811 nw64(TCAM_CTL
, (TCAM_CTL_RWC_TCAM_WRITE
| index
));
2813 return tcam_wait_bit(np
, TCAM_CTL_STAT
);
2817 static int tcam_read(struct niu
*np
, int index
,
2818 u64
*key
, u64
*mask
)
2822 nw64(TCAM_CTL
, (TCAM_CTL_RWC_TCAM_READ
| index
));
2823 err
= tcam_wait_bit(np
, TCAM_CTL_STAT
);
2825 key
[0] = nr64(TCAM_KEY_0
);
2826 key
[1] = nr64(TCAM_KEY_1
);
2827 key
[2] = nr64(TCAM_KEY_2
);
2828 key
[3] = nr64(TCAM_KEY_3
);
2829 mask
[0] = nr64(TCAM_KEY_MASK_0
);
2830 mask
[1] = nr64(TCAM_KEY_MASK_1
);
2831 mask
[2] = nr64(TCAM_KEY_MASK_2
);
2832 mask
[3] = nr64(TCAM_KEY_MASK_3
);
2838 static int tcam_write(struct niu
*np
, int index
,
2839 u64
*key
, u64
*mask
)
2841 nw64(TCAM_KEY_0
, key
[0]);
2842 nw64(TCAM_KEY_1
, key
[1]);
2843 nw64(TCAM_KEY_2
, key
[2]);
2844 nw64(TCAM_KEY_3
, key
[3]);
2845 nw64(TCAM_KEY_MASK_0
, mask
[0]);
2846 nw64(TCAM_KEY_MASK_1
, mask
[1]);
2847 nw64(TCAM_KEY_MASK_2
, mask
[2]);
2848 nw64(TCAM_KEY_MASK_3
, mask
[3]);
2849 nw64(TCAM_CTL
, (TCAM_CTL_RWC_TCAM_WRITE
| index
));
2851 return tcam_wait_bit(np
, TCAM_CTL_STAT
);
2855 static int tcam_assoc_read(struct niu
*np
, int index
, u64
*data
)
2859 nw64(TCAM_CTL
, (TCAM_CTL_RWC_RAM_READ
| index
));
2860 err
= tcam_wait_bit(np
, TCAM_CTL_STAT
);
2862 *data
= nr64(TCAM_KEY_1
);
2868 static int tcam_assoc_write(struct niu
*np
, int index
, u64 assoc_data
)
2870 nw64(TCAM_KEY_1
, assoc_data
);
2871 nw64(TCAM_CTL
, (TCAM_CTL_RWC_RAM_WRITE
| index
));
2873 return tcam_wait_bit(np
, TCAM_CTL_STAT
);
2876 static void tcam_enable(struct niu
*np
, int on
)
2878 u64 val
= nr64(FFLP_CFG_1
);
2881 val
&= ~FFLP_CFG_1_TCAM_DIS
;
2883 val
|= FFLP_CFG_1_TCAM_DIS
;
2884 nw64(FFLP_CFG_1
, val
);
2887 static void tcam_set_lat_and_ratio(struct niu
*np
, u64 latency
, u64 ratio
)
2889 u64 val
= nr64(FFLP_CFG_1
);
2891 val
&= ~(FFLP_CFG_1_FFLPINITDONE
|
2893 FFLP_CFG_1_CAMRATIO
);
2894 val
|= (latency
<< FFLP_CFG_1_CAMLAT_SHIFT
);
2895 val
|= (ratio
<< FFLP_CFG_1_CAMRATIO_SHIFT
);
2896 nw64(FFLP_CFG_1
, val
);
2898 val
= nr64(FFLP_CFG_1
);
2899 val
|= FFLP_CFG_1_FFLPINITDONE
;
2900 nw64(FFLP_CFG_1
, val
);
2903 static int tcam_user_eth_class_enable(struct niu
*np
, unsigned long class,
2909 if (class < CLASS_CODE_ETHERTYPE1
||
2910 class > CLASS_CODE_ETHERTYPE2
)
2913 reg
= L2_CLS(class - CLASS_CODE_ETHERTYPE1
);
2925 static int tcam_user_eth_class_set(struct niu
*np
, unsigned long class,
2931 if (class < CLASS_CODE_ETHERTYPE1
||
2932 class > CLASS_CODE_ETHERTYPE2
||
2933 (ether_type
& ~(u64
)0xffff) != 0)
2936 reg
= L2_CLS(class - CLASS_CODE_ETHERTYPE1
);
2938 val
&= ~L2_CLS_ETYPE
;
2939 val
|= (ether_type
<< L2_CLS_ETYPE_SHIFT
);
2946 static int tcam_user_ip_class_enable(struct niu
*np
, unsigned long class,
2952 if (class < CLASS_CODE_USER_PROG1
||
2953 class > CLASS_CODE_USER_PROG4
)
2956 reg
= L3_CLS(class - CLASS_CODE_USER_PROG1
);
2959 val
|= L3_CLS_VALID
;
2961 val
&= ~L3_CLS_VALID
;
2967 static int tcam_user_ip_class_set(struct niu
*np
, unsigned long class,
2968 int ipv6
, u64 protocol_id
,
2969 u64 tos_mask
, u64 tos_val
)
2974 if (class < CLASS_CODE_USER_PROG1
||
2975 class > CLASS_CODE_USER_PROG4
||
2976 (protocol_id
& ~(u64
)0xff) != 0 ||
2977 (tos_mask
& ~(u64
)0xff) != 0 ||
2978 (tos_val
& ~(u64
)0xff) != 0)
2981 reg
= L3_CLS(class - CLASS_CODE_USER_PROG1
);
2983 val
&= ~(L3_CLS_IPVER
| L3_CLS_PID
|
2984 L3_CLS_TOSMASK
| L3_CLS_TOS
);
2986 val
|= L3_CLS_IPVER
;
2987 val
|= (protocol_id
<< L3_CLS_PID_SHIFT
);
2988 val
|= (tos_mask
<< L3_CLS_TOSMASK_SHIFT
);
2989 val
|= (tos_val
<< L3_CLS_TOS_SHIFT
);
2995 static int tcam_early_init(struct niu
*np
)
3001 tcam_set_lat_and_ratio(np
,
3002 DEFAULT_TCAM_LATENCY
,
3003 DEFAULT_TCAM_ACCESS_RATIO
);
3004 for (i
= CLASS_CODE_ETHERTYPE1
; i
<= CLASS_CODE_ETHERTYPE2
; i
++) {
3005 err
= tcam_user_eth_class_enable(np
, i
, 0);
3009 for (i
= CLASS_CODE_USER_PROG1
; i
<= CLASS_CODE_USER_PROG4
; i
++) {
3010 err
= tcam_user_ip_class_enable(np
, i
, 0);
3018 static int tcam_flush_all(struct niu
*np
)
3022 for (i
= 0; i
< np
->parent
->tcam_num_entries
; i
++) {
3023 int err
= tcam_flush(np
, i
);
3030 static u64
hash_addr_regval(unsigned long index
, unsigned long num_entries
)
3032 return (u64
)index
| (num_entries
== 1 ? HASH_TBL_ADDR_AUTOINC
: 0);
3036 static int hash_read(struct niu
*np
, unsigned long partition
,
3037 unsigned long index
, unsigned long num_entries
,
3040 u64 val
= hash_addr_regval(index
, num_entries
);
3043 if (partition
>= FCRAM_NUM_PARTITIONS
||
3044 index
+ num_entries
> FCRAM_SIZE
)
3047 nw64(HASH_TBL_ADDR(partition
), val
);
3048 for (i
= 0; i
< num_entries
; i
++)
3049 data
[i
] = nr64(HASH_TBL_DATA(partition
));
3055 static int hash_write(struct niu
*np
, unsigned long partition
,
3056 unsigned long index
, unsigned long num_entries
,
3059 u64 val
= hash_addr_regval(index
, num_entries
);
3062 if (partition
>= FCRAM_NUM_PARTITIONS
||
3063 index
+ (num_entries
* 8) > FCRAM_SIZE
)
3066 nw64(HASH_TBL_ADDR(partition
), val
);
3067 for (i
= 0; i
< num_entries
; i
++)
3068 nw64(HASH_TBL_DATA(partition
), data
[i
]);
3073 static void fflp_reset(struct niu
*np
)
3077 nw64(FFLP_CFG_1
, FFLP_CFG_1_PIO_FIO_RST
);
3079 nw64(FFLP_CFG_1
, 0);
3081 val
= FFLP_CFG_1_FCRAMOUTDR_NORMAL
| FFLP_CFG_1_FFLPINITDONE
;
3082 nw64(FFLP_CFG_1
, val
);
3085 static void fflp_set_timings(struct niu
*np
)
3087 u64 val
= nr64(FFLP_CFG_1
);
3089 val
&= ~FFLP_CFG_1_FFLPINITDONE
;
3090 val
|= (DEFAULT_FCRAMRATIO
<< FFLP_CFG_1_FCRAMRATIO_SHIFT
);
3091 nw64(FFLP_CFG_1
, val
);
3093 val
= nr64(FFLP_CFG_1
);
3094 val
|= FFLP_CFG_1_FFLPINITDONE
;
3095 nw64(FFLP_CFG_1
, val
);
3097 val
= nr64(FCRAM_REF_TMR
);
3098 val
&= ~(FCRAM_REF_TMR_MAX
| FCRAM_REF_TMR_MIN
);
3099 val
|= (DEFAULT_FCRAM_REFRESH_MAX
<< FCRAM_REF_TMR_MAX_SHIFT
);
3100 val
|= (DEFAULT_FCRAM_REFRESH_MIN
<< FCRAM_REF_TMR_MIN_SHIFT
);
3101 nw64(FCRAM_REF_TMR
, val
);
3104 static int fflp_set_partition(struct niu
*np
, u64 partition
,
3105 u64 mask
, u64 base
, int enable
)
3110 if (partition
>= FCRAM_NUM_PARTITIONS
||
3111 (mask
& ~(u64
)0x1f) != 0 ||
3112 (base
& ~(u64
)0x1f) != 0)
3115 reg
= FLW_PRT_SEL(partition
);
3118 val
&= ~(FLW_PRT_SEL_EXT
| FLW_PRT_SEL_MASK
| FLW_PRT_SEL_BASE
);
3119 val
|= (mask
<< FLW_PRT_SEL_MASK_SHIFT
);
3120 val
|= (base
<< FLW_PRT_SEL_BASE_SHIFT
);
3122 val
|= FLW_PRT_SEL_EXT
;
3128 static int fflp_disable_all_partitions(struct niu
*np
)
3132 for (i
= 0; i
< FCRAM_NUM_PARTITIONS
; i
++) {
3133 int err
= fflp_set_partition(np
, 0, 0, 0, 0);
3140 static void fflp_llcsnap_enable(struct niu
*np
, int on
)
3142 u64 val
= nr64(FFLP_CFG_1
);
3145 val
|= FFLP_CFG_1_LLCSNAP
;
3147 val
&= ~FFLP_CFG_1_LLCSNAP
;
3148 nw64(FFLP_CFG_1
, val
);
3151 static void fflp_errors_enable(struct niu
*np
, int on
)
3153 u64 val
= nr64(FFLP_CFG_1
);
3156 val
&= ~FFLP_CFG_1_ERRORDIS
;
3158 val
|= FFLP_CFG_1_ERRORDIS
;
3159 nw64(FFLP_CFG_1
, val
);
3162 static int fflp_hash_clear(struct niu
*np
)
3164 struct fcram_hash_ipv4 ent
;
3167 /* IPV4 hash entry with valid bit clear, rest is don't care. */
3168 memset(&ent
, 0, sizeof(ent
));
3169 ent
.header
= HASH_HEADER_EXT
;
3171 for (i
= 0; i
< FCRAM_SIZE
; i
+= sizeof(ent
)) {
3172 int err
= hash_write(np
, 0, i
, 1, (u64
*) &ent
);
3179 static int fflp_early_init(struct niu
*np
)
3181 struct niu_parent
*parent
;
3182 unsigned long flags
;
3185 niu_lock_parent(np
, flags
);
3187 parent
= np
->parent
;
3189 if (!(parent
->flags
& PARENT_FLGS_CLS_HWINIT
)) {
3190 if (np
->parent
->plat_type
!= PLAT_TYPE_NIU
) {
3192 fflp_set_timings(np
);
3193 err
= fflp_disable_all_partitions(np
);
3195 netif_printk(np
, probe
, KERN_DEBUG
, np
->dev
,
3196 "fflp_disable_all_partitions failed, err=%d\n",
3202 err
= tcam_early_init(np
);
3204 netif_printk(np
, probe
, KERN_DEBUG
, np
->dev
,
3205 "tcam_early_init failed, err=%d\n", err
);
3208 fflp_llcsnap_enable(np
, 1);
3209 fflp_errors_enable(np
, 0);
3213 err
= tcam_flush_all(np
);
3215 netif_printk(np
, probe
, KERN_DEBUG
, np
->dev
,
3216 "tcam_flush_all failed, err=%d\n", err
);
3219 if (np
->parent
->plat_type
!= PLAT_TYPE_NIU
) {
3220 err
= fflp_hash_clear(np
);
3222 netif_printk(np
, probe
, KERN_DEBUG
, np
->dev
,
3223 "fflp_hash_clear failed, err=%d\n",
3231 parent
->flags
|= PARENT_FLGS_CLS_HWINIT
;
3234 niu_unlock_parent(np
, flags
);
3238 static int niu_set_flow_key(struct niu
*np
, unsigned long class_code
, u64 key
)
3240 if (class_code
< CLASS_CODE_USER_PROG1
||
3241 class_code
> CLASS_CODE_SCTP_IPV6
)
3244 nw64(FLOW_KEY(class_code
- CLASS_CODE_USER_PROG1
), key
);
3248 static int niu_set_tcam_key(struct niu
*np
, unsigned long class_code
, u64 key
)
3250 if (class_code
< CLASS_CODE_USER_PROG1
||
3251 class_code
> CLASS_CODE_SCTP_IPV6
)
3254 nw64(TCAM_KEY(class_code
- CLASS_CODE_USER_PROG1
), key
);
3258 /* Entries for the ports are interleaved in the TCAM */
3259 static u16
tcam_get_index(struct niu
*np
, u16 idx
)
3261 /* One entry reserved for IP fragment rule */
3262 if (idx
>= (np
->clas
.tcam_sz
- 1))
3264 return np
->clas
.tcam_top
+ ((idx
+1) * np
->parent
->num_ports
);
3267 static u16
tcam_get_size(struct niu
*np
)
3269 /* One entry reserved for IP fragment rule */
3270 return np
->clas
.tcam_sz
- 1;
3273 static u16
tcam_get_valid_entry_cnt(struct niu
*np
)
3275 /* One entry reserved for IP fragment rule */
3276 return np
->clas
.tcam_valid_entries
- 1;
3279 static void niu_rx_skb_append(struct sk_buff
*skb
, struct page
*page
,
3280 u32 offset
, u32 size
, u32 truesize
)
3282 skb_fill_page_desc(skb
, skb_shinfo(skb
)->nr_frags
, page
, offset
, size
);
3285 skb
->data_len
+= size
;
3286 skb
->truesize
+= truesize
;
3289 static unsigned int niu_hash_rxaddr(struct rx_ring_info
*rp
, u64 a
)
3292 a
^= (a
>> ilog2(MAX_RBR_RING_SIZE
));
3294 return a
& (MAX_RBR_RING_SIZE
- 1);
3297 static struct page
*niu_find_rxpage(struct rx_ring_info
*rp
, u64 addr
,
3298 struct page
***link
)
3300 unsigned int h
= niu_hash_rxaddr(rp
, addr
);
3301 struct page
*p
, **pp
;
3304 pp
= &rp
->rxhash
[h
];
3305 for (; (p
= *pp
) != NULL
; pp
= &niu_next_page(p
)) {
3306 if (p
->index
== addr
) {
3317 static void niu_hash_page(struct rx_ring_info
*rp
, struct page
*page
, u64 base
)
3319 unsigned int h
= niu_hash_rxaddr(rp
, base
);
3322 niu_next_page(page
) = rp
->rxhash
[h
];
3323 rp
->rxhash
[h
] = page
;
3326 static int niu_rbr_add_page(struct niu
*np
, struct rx_ring_info
*rp
,
3327 gfp_t mask
, int start_index
)
3333 page
= alloc_page(mask
);
3337 addr
= np
->ops
->map_page(np
->device
, page
, 0,
3338 PAGE_SIZE
, DMA_FROM_DEVICE
);
3344 niu_hash_page(rp
, page
, addr
);
3345 if (rp
->rbr_blocks_per_page
> 1)
3346 page_ref_add(page
, rp
->rbr_blocks_per_page
- 1);
3348 for (i
= 0; i
< rp
->rbr_blocks_per_page
; i
++) {
3349 __le32
*rbr
= &rp
->rbr
[start_index
+ i
];
3351 *rbr
= cpu_to_le32(addr
>> RBR_DESCR_ADDR_SHIFT
);
3352 addr
+= rp
->rbr_block_size
;
3358 static void niu_rbr_refill(struct niu
*np
, struct rx_ring_info
*rp
, gfp_t mask
)
3360 int index
= rp
->rbr_index
;
3363 if ((rp
->rbr_pending
% rp
->rbr_blocks_per_page
) == 0) {
3364 int err
= niu_rbr_add_page(np
, rp
, mask
, index
);
3366 if (unlikely(err
)) {
3371 rp
->rbr_index
+= rp
->rbr_blocks_per_page
;
3372 BUG_ON(rp
->rbr_index
> rp
->rbr_table_size
);
3373 if (rp
->rbr_index
== rp
->rbr_table_size
)
3376 if (rp
->rbr_pending
>= rp
->rbr_kick_thresh
) {
3377 nw64(RBR_KICK(rp
->rx_channel
), rp
->rbr_pending
);
3378 rp
->rbr_pending
= 0;
3383 static int niu_rx_pkt_ignore(struct niu
*np
, struct rx_ring_info
*rp
)
3385 unsigned int index
= rp
->rcr_index
;
3390 struct page
*page
, **link
;
3396 val
= le64_to_cpup(&rp
->rcr
[index
]);
3397 addr
= (val
& RCR_ENTRY_PKT_BUF_ADDR
) <<
3398 RCR_ENTRY_PKT_BUF_ADDR_SHIFT
;
3399 page
= niu_find_rxpage(rp
, addr
, &link
);
3401 rcr_size
= rp
->rbr_sizes
[(val
& RCR_ENTRY_PKTBUFSZ
) >>
3402 RCR_ENTRY_PKTBUFSZ_SHIFT
];
3403 if ((page
->index
+ PAGE_SIZE
) - rcr_size
== addr
) {
3404 *link
= niu_next_page(page
);
3405 np
->ops
->unmap_page(np
->device
, page
->index
,
3406 PAGE_SIZE
, DMA_FROM_DEVICE
);
3408 niu_next_page(page
) = NULL
;
3410 rp
->rbr_refill_pending
++;
3413 index
= NEXT_RCR(rp
, index
);
3414 if (!(val
& RCR_ENTRY_MULTI
))
3418 rp
->rcr_index
= index
;
3423 static int niu_process_rx_pkt(struct napi_struct
*napi
, struct niu
*np
,
3424 struct rx_ring_info
*rp
)
3426 unsigned int index
= rp
->rcr_index
;
3427 struct rx_pkt_hdr1
*rh
;
3428 struct sk_buff
*skb
;
3431 skb
= netdev_alloc_skb(np
->dev
, RX_SKB_ALLOC_SIZE
);
3433 return niu_rx_pkt_ignore(np
, rp
);
3437 struct page
*page
, **link
;
3438 u32 rcr_size
, append_size
;
3443 val
= le64_to_cpup(&rp
->rcr
[index
]);
3445 len
= (val
& RCR_ENTRY_L2_LEN
) >>
3446 RCR_ENTRY_L2_LEN_SHIFT
;
3447 append_size
= len
+ ETH_HLEN
+ ETH_FCS_LEN
;
3449 addr
= (val
& RCR_ENTRY_PKT_BUF_ADDR
) <<
3450 RCR_ENTRY_PKT_BUF_ADDR_SHIFT
;
3451 page
= niu_find_rxpage(rp
, addr
, &link
);
3453 rcr_size
= rp
->rbr_sizes
[(val
& RCR_ENTRY_PKTBUFSZ
) >>
3454 RCR_ENTRY_PKTBUFSZ_SHIFT
];
3456 off
= addr
& ~PAGE_MASK
;
3460 ptype
= (val
>> RCR_ENTRY_PKT_TYPE_SHIFT
);
3461 if ((ptype
== RCR_PKT_TYPE_TCP
||
3462 ptype
== RCR_PKT_TYPE_UDP
) &&
3463 !(val
& (RCR_ENTRY_NOPORT
|
3465 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
3467 skb_checksum_none_assert(skb
);
3468 } else if (!(val
& RCR_ENTRY_MULTI
))
3469 append_size
= append_size
- skb
->len
;
3471 niu_rx_skb_append(skb
, page
, off
, append_size
, rcr_size
);
3472 if ((page
->index
+ rp
->rbr_block_size
) - rcr_size
== addr
) {
3473 *link
= niu_next_page(page
);
3474 np
->ops
->unmap_page(np
->device
, page
->index
,
3475 PAGE_SIZE
, DMA_FROM_DEVICE
);
3477 niu_next_page(page
) = NULL
;
3478 rp
->rbr_refill_pending
++;
3482 index
= NEXT_RCR(rp
, index
);
3483 if (!(val
& RCR_ENTRY_MULTI
))
3487 rp
->rcr_index
= index
;
3490 len
= min_t(int, len
, sizeof(*rh
) + VLAN_ETH_HLEN
);
3491 __pskb_pull_tail(skb
, len
);
3493 rh
= (struct rx_pkt_hdr1
*) skb
->data
;
3494 if (np
->dev
->features
& NETIF_F_RXHASH
)
3496 ((u32
)rh
->hashval2_0
<< 24 |
3497 (u32
)rh
->hashval2_1
<< 16 |
3498 (u32
)rh
->hashval1_1
<< 8 |
3499 (u32
)rh
->hashval1_2
<< 0),
3501 skb_pull(skb
, sizeof(*rh
));
3504 rp
->rx_bytes
+= skb
->len
;
3506 skb
->protocol
= eth_type_trans(skb
, np
->dev
);
3507 skb_record_rx_queue(skb
, rp
->rx_channel
);
3508 napi_gro_receive(napi
, skb
);
3513 static int niu_rbr_fill(struct niu
*np
, struct rx_ring_info
*rp
, gfp_t mask
)
3515 int blocks_per_page
= rp
->rbr_blocks_per_page
;
3516 int err
, index
= rp
->rbr_index
;
3519 while (index
< (rp
->rbr_table_size
- blocks_per_page
)) {
3520 err
= niu_rbr_add_page(np
, rp
, mask
, index
);
3524 index
+= blocks_per_page
;
3527 rp
->rbr_index
= index
;
3531 static void niu_rbr_free(struct niu
*np
, struct rx_ring_info
*rp
)
3535 for (i
= 0; i
< MAX_RBR_RING_SIZE
; i
++) {
3538 page
= rp
->rxhash
[i
];
3540 struct page
*next
= niu_next_page(page
);
3541 u64 base
= page
->index
;
3543 np
->ops
->unmap_page(np
->device
, base
, PAGE_SIZE
,
3546 niu_next_page(page
) = NULL
;
3554 for (i
= 0; i
< rp
->rbr_table_size
; i
++)
3555 rp
->rbr
[i
] = cpu_to_le32(0);
3559 static int release_tx_packet(struct niu
*np
, struct tx_ring_info
*rp
, int idx
)
3561 struct tx_buff_info
*tb
= &rp
->tx_buffs
[idx
];
3562 struct sk_buff
*skb
= tb
->skb
;
3563 struct tx_pkt_hdr
*tp
;
3567 tp
= (struct tx_pkt_hdr
*) skb
->data
;
3568 tx_flags
= le64_to_cpup(&tp
->flags
);
3571 rp
->tx_bytes
+= (((tx_flags
& TXHDR_LEN
) >> TXHDR_LEN_SHIFT
) -
3572 ((tx_flags
& TXHDR_PAD
) / 2));
3574 len
= skb_headlen(skb
);
3575 np
->ops
->unmap_single(np
->device
, tb
->mapping
,
3576 len
, DMA_TO_DEVICE
);
3578 if (le64_to_cpu(rp
->descr
[idx
]) & TX_DESC_MARK
)
3583 idx
= NEXT_TX(rp
, idx
);
3584 len
-= MAX_TX_DESC_LEN
;
3587 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
3588 tb
= &rp
->tx_buffs
[idx
];
3589 BUG_ON(tb
->skb
!= NULL
);
3590 np
->ops
->unmap_page(np
->device
, tb
->mapping
,
3591 skb_frag_size(&skb_shinfo(skb
)->frags
[i
]),
3593 idx
= NEXT_TX(rp
, idx
);
3601 #define NIU_TX_WAKEUP_THRESH(rp) ((rp)->pending / 4)
3603 static void niu_tx_work(struct niu
*np
, struct tx_ring_info
*rp
)
3605 struct netdev_queue
*txq
;
3610 index
= (rp
- np
->tx_rings
);
3611 txq
= netdev_get_tx_queue(np
->dev
, index
);
3614 if (unlikely(!(cs
& (TX_CS_MK
| TX_CS_MMK
))))
3617 tmp
= pkt_cnt
= (cs
& TX_CS_PKT_CNT
) >> TX_CS_PKT_CNT_SHIFT
;
3618 pkt_cnt
= (pkt_cnt
- rp
->last_pkt_cnt
) &
3619 (TX_CS_PKT_CNT
>> TX_CS_PKT_CNT_SHIFT
);
3621 rp
->last_pkt_cnt
= tmp
;
3625 netif_printk(np
, tx_done
, KERN_DEBUG
, np
->dev
,
3626 "%s() pkt_cnt[%u] cons[%d]\n", __func__
, pkt_cnt
, cons
);
3629 cons
= release_tx_packet(np
, rp
, cons
);
3635 if (unlikely(netif_tx_queue_stopped(txq
) &&
3636 (niu_tx_avail(rp
) > NIU_TX_WAKEUP_THRESH(rp
)))) {
3637 __netif_tx_lock(txq
, smp_processor_id());
3638 if (netif_tx_queue_stopped(txq
) &&
3639 (niu_tx_avail(rp
) > NIU_TX_WAKEUP_THRESH(rp
)))
3640 netif_tx_wake_queue(txq
);
3641 __netif_tx_unlock(txq
);
3645 static inline void niu_sync_rx_discard_stats(struct niu
*np
,
3646 struct rx_ring_info
*rp
,
3649 /* This elaborate scheme is needed for reading the RX discard
3650 * counters, as they are only 16-bit and can overflow quickly,
3651 * and because the overflow indication bit is not usable as
3652 * the counter value does not wrap, but remains at max value
3655 * In theory and in practice counters can be lost in between
3656 * reading nr64() and clearing the counter nw64(). For this
3657 * reason, the number of counter clearings nw64() is
3658 * limited/reduced though the limit parameter.
3660 int rx_channel
= rp
->rx_channel
;
3663 /* RXMISC (Receive Miscellaneous Discard Count), covers the
3664 * following discard events: IPP (Input Port Process),
3665 * FFLP/TCAM, Full RCR (Receive Completion Ring) RBR (Receive
3666 * Block Ring) prefetch buffer is empty.
3668 misc
= nr64(RXMISC(rx_channel
));
3669 if (unlikely((misc
& RXMISC_COUNT
) > limit
)) {
3670 nw64(RXMISC(rx_channel
), 0);
3671 rp
->rx_errors
+= misc
& RXMISC_COUNT
;
3673 if (unlikely(misc
& RXMISC_OFLOW
))
3674 dev_err(np
->device
, "rx-%d: Counter overflow RXMISC discard\n",
3677 netif_printk(np
, rx_err
, KERN_DEBUG
, np
->dev
,
3678 "rx-%d: MISC drop=%u over=%u\n",
3679 rx_channel
, misc
, misc
-limit
);
3682 /* WRED (Weighted Random Early Discard) by hardware */
3683 wred
= nr64(RED_DIS_CNT(rx_channel
));
3684 if (unlikely((wred
& RED_DIS_CNT_COUNT
) > limit
)) {
3685 nw64(RED_DIS_CNT(rx_channel
), 0);
3686 rp
->rx_dropped
+= wred
& RED_DIS_CNT_COUNT
;
3688 if (unlikely(wred
& RED_DIS_CNT_OFLOW
))
3689 dev_err(np
->device
, "rx-%d: Counter overflow WRED discard\n", rx_channel
);
3691 netif_printk(np
, rx_err
, KERN_DEBUG
, np
->dev
,
3692 "rx-%d: WRED drop=%u over=%u\n",
3693 rx_channel
, wred
, wred
-limit
);
3697 static int niu_rx_work(struct napi_struct
*napi
, struct niu
*np
,
3698 struct rx_ring_info
*rp
, int budget
)
3700 int qlen
, rcr_done
= 0, work_done
= 0;
3701 struct rxdma_mailbox
*mbox
= rp
->mbox
;
3705 stat
= nr64(RX_DMA_CTL_STAT(rp
->rx_channel
));
3706 qlen
= nr64(RCRSTAT_A(rp
->rx_channel
)) & RCRSTAT_A_QLEN
;
3708 stat
= le64_to_cpup(&mbox
->rx_dma_ctl_stat
);
3709 qlen
= (le64_to_cpup(&mbox
->rcrstat_a
) & RCRSTAT_A_QLEN
);
3711 mbox
->rx_dma_ctl_stat
= 0;
3712 mbox
->rcrstat_a
= 0;
3714 netif_printk(np
, rx_status
, KERN_DEBUG
, np
->dev
,
3715 "%s(chan[%d]), stat[%llx] qlen=%d\n",
3716 __func__
, rp
->rx_channel
, (unsigned long long)stat
, qlen
);
3718 rcr_done
= work_done
= 0;
3719 qlen
= min(qlen
, budget
);
3720 while (work_done
< qlen
) {
3721 rcr_done
+= niu_process_rx_pkt(napi
, np
, rp
);
3725 if (rp
->rbr_refill_pending
>= rp
->rbr_kick_thresh
) {
3728 for (i
= 0; i
< rp
->rbr_refill_pending
; i
++)
3729 niu_rbr_refill(np
, rp
, GFP_ATOMIC
);
3730 rp
->rbr_refill_pending
= 0;
3733 stat
= (RX_DMA_CTL_STAT_MEX
|
3734 ((u64
)work_done
<< RX_DMA_CTL_STAT_PKTREAD_SHIFT
) |
3735 ((u64
)rcr_done
<< RX_DMA_CTL_STAT_PTRREAD_SHIFT
));
3737 nw64(RX_DMA_CTL_STAT(rp
->rx_channel
), stat
);
3739 /* Only sync discards stats when qlen indicate potential for drops */
3741 niu_sync_rx_discard_stats(np
, rp
, 0x7FFF);
3746 static int niu_poll_core(struct niu
*np
, struct niu_ldg
*lp
, int budget
)
3749 u32 tx_vec
= (v0
>> 32);
3750 u32 rx_vec
= (v0
& 0xffffffff);
3751 int i
, work_done
= 0;
3753 netif_printk(np
, intr
, KERN_DEBUG
, np
->dev
,
3754 "%s() v0[%016llx]\n", __func__
, (unsigned long long)v0
);
3756 for (i
= 0; i
< np
->num_tx_rings
; i
++) {
3757 struct tx_ring_info
*rp
= &np
->tx_rings
[i
];
3758 if (tx_vec
& (1 << rp
->tx_channel
))
3759 niu_tx_work(np
, rp
);
3760 nw64(LD_IM0(LDN_TXDMA(rp
->tx_channel
)), 0);
3763 for (i
= 0; i
< np
->num_rx_rings
; i
++) {
3764 struct rx_ring_info
*rp
= &np
->rx_rings
[i
];
3766 if (rx_vec
& (1 << rp
->rx_channel
)) {
3769 this_work_done
= niu_rx_work(&lp
->napi
, np
, rp
,
3772 budget
-= this_work_done
;
3773 work_done
+= this_work_done
;
3775 nw64(LD_IM0(LDN_RXDMA(rp
->rx_channel
)), 0);
3781 static int niu_poll(struct napi_struct
*napi
, int budget
)
3783 struct niu_ldg
*lp
= container_of(napi
, struct niu_ldg
, napi
);
3784 struct niu
*np
= lp
->np
;
3787 work_done
= niu_poll_core(np
, lp
, budget
);
3789 if (work_done
< budget
) {
3790 napi_complete_done(napi
, work_done
);
3791 niu_ldg_rearm(np
, lp
, 1);
3796 static void niu_log_rxchan_errors(struct niu
*np
, struct rx_ring_info
*rp
,
3799 netdev_err(np
->dev
, "RX channel %u errors ( ", rp
->rx_channel
);
3801 if (stat
& RX_DMA_CTL_STAT_RBR_TMOUT
)
3802 pr_cont("RBR_TMOUT ");
3803 if (stat
& RX_DMA_CTL_STAT_RSP_CNT_ERR
)
3804 pr_cont("RSP_CNT ");
3805 if (stat
& RX_DMA_CTL_STAT_BYTE_EN_BUS
)
3806 pr_cont("BYTE_EN_BUS ");
3807 if (stat
& RX_DMA_CTL_STAT_RSP_DAT_ERR
)
3808 pr_cont("RSP_DAT ");
3809 if (stat
& RX_DMA_CTL_STAT_RCR_ACK_ERR
)
3810 pr_cont("RCR_ACK ");
3811 if (stat
& RX_DMA_CTL_STAT_RCR_SHA_PAR
)
3812 pr_cont("RCR_SHA_PAR ");
3813 if (stat
& RX_DMA_CTL_STAT_RBR_PRE_PAR
)
3814 pr_cont("RBR_PRE_PAR ");
3815 if (stat
& RX_DMA_CTL_STAT_CONFIG_ERR
)
3817 if (stat
& RX_DMA_CTL_STAT_RCRINCON
)
3818 pr_cont("RCRINCON ");
3819 if (stat
& RX_DMA_CTL_STAT_RCRFULL
)
3820 pr_cont("RCRFULL ");
3821 if (stat
& RX_DMA_CTL_STAT_RBRFULL
)
3822 pr_cont("RBRFULL ");
3823 if (stat
& RX_DMA_CTL_STAT_RBRLOGPAGE
)
3824 pr_cont("RBRLOGPAGE ");
3825 if (stat
& RX_DMA_CTL_STAT_CFIGLOGPAGE
)
3826 pr_cont("CFIGLOGPAGE ");
3827 if (stat
& RX_DMA_CTL_STAT_DC_FIFO_ERR
)
3828 pr_cont("DC_FIDO ");
3833 static int niu_rx_error(struct niu
*np
, struct rx_ring_info
*rp
)
3835 u64 stat
= nr64(RX_DMA_CTL_STAT(rp
->rx_channel
));
3839 if (stat
& (RX_DMA_CTL_STAT_CHAN_FATAL
|
3840 RX_DMA_CTL_STAT_PORT_FATAL
))
3844 netdev_err(np
->dev
, "RX channel %u error, stat[%llx]\n",
3846 (unsigned long long) stat
);
3848 niu_log_rxchan_errors(np
, rp
, stat
);
3851 nw64(RX_DMA_CTL_STAT(rp
->rx_channel
),
3852 stat
& RX_DMA_CTL_WRITE_CLEAR_ERRS
);
3857 static void niu_log_txchan_errors(struct niu
*np
, struct tx_ring_info
*rp
,
3860 netdev_err(np
->dev
, "TX channel %u errors ( ", rp
->tx_channel
);
3862 if (cs
& TX_CS_MBOX_ERR
)
3864 if (cs
& TX_CS_PKT_SIZE_ERR
)
3865 pr_cont("PKT_SIZE ");
3866 if (cs
& TX_CS_TX_RING_OFLOW
)
3867 pr_cont("TX_RING_OFLOW ");
3868 if (cs
& TX_CS_PREF_BUF_PAR_ERR
)
3869 pr_cont("PREF_BUF_PAR ");
3870 if (cs
& TX_CS_NACK_PREF
)
3871 pr_cont("NACK_PREF ");
3872 if (cs
& TX_CS_NACK_PKT_RD
)
3873 pr_cont("NACK_PKT_RD ");
3874 if (cs
& TX_CS_CONF_PART_ERR
)
3875 pr_cont("CONF_PART ");
3876 if (cs
& TX_CS_PKT_PRT_ERR
)
3877 pr_cont("PKT_PTR ");
3882 static int niu_tx_error(struct niu
*np
, struct tx_ring_info
*rp
)
3886 cs
= nr64(TX_CS(rp
->tx_channel
));
3887 logh
= nr64(TX_RNG_ERR_LOGH(rp
->tx_channel
));
3888 logl
= nr64(TX_RNG_ERR_LOGL(rp
->tx_channel
));
3890 netdev_err(np
->dev
, "TX channel %u error, cs[%llx] logh[%llx] logl[%llx]\n",
3892 (unsigned long long)cs
,
3893 (unsigned long long)logh
,
3894 (unsigned long long)logl
);
3896 niu_log_txchan_errors(np
, rp
, cs
);
3901 static int niu_mif_interrupt(struct niu
*np
)
3903 u64 mif_status
= nr64(MIF_STATUS
);
3906 if (np
->flags
& NIU_FLAGS_XMAC
) {
3907 u64 xrxmac_stat
= nr64_mac(XRXMAC_STATUS
);
3909 if (xrxmac_stat
& XRXMAC_STATUS_PHY_MDINT
)
3913 netdev_err(np
->dev
, "MIF interrupt, stat[%llx] phy_mdint(%d)\n",
3914 (unsigned long long)mif_status
, phy_mdint
);
3919 static void niu_xmac_interrupt(struct niu
*np
)
3921 struct niu_xmac_stats
*mp
= &np
->mac_stats
.xmac
;
3924 val
= nr64_mac(XTXMAC_STATUS
);
3925 if (val
& XTXMAC_STATUS_FRAME_CNT_EXP
)
3926 mp
->tx_frames
+= TXMAC_FRM_CNT_COUNT
;
3927 if (val
& XTXMAC_STATUS_BYTE_CNT_EXP
)
3928 mp
->tx_bytes
+= TXMAC_BYTE_CNT_COUNT
;
3929 if (val
& XTXMAC_STATUS_TXFIFO_XFR_ERR
)
3930 mp
->tx_fifo_errors
++;
3931 if (val
& XTXMAC_STATUS_TXMAC_OFLOW
)
3932 mp
->tx_overflow_errors
++;
3933 if (val
& XTXMAC_STATUS_MAX_PSIZE_ERR
)
3934 mp
->tx_max_pkt_size_errors
++;
3935 if (val
& XTXMAC_STATUS_TXMAC_UFLOW
)
3936 mp
->tx_underflow_errors
++;
3938 val
= nr64_mac(XRXMAC_STATUS
);
3939 if (val
& XRXMAC_STATUS_LCL_FLT_STATUS
)
3940 mp
->rx_local_faults
++;
3941 if (val
& XRXMAC_STATUS_RFLT_DET
)
3942 mp
->rx_remote_faults
++;
3943 if (val
& XRXMAC_STATUS_LFLT_CNT_EXP
)
3944 mp
->rx_link_faults
+= LINK_FAULT_CNT_COUNT
;
3945 if (val
& XRXMAC_STATUS_ALIGNERR_CNT_EXP
)
3946 mp
->rx_align_errors
+= RXMAC_ALIGN_ERR_CNT_COUNT
;
3947 if (val
& XRXMAC_STATUS_RXFRAG_CNT_EXP
)
3948 mp
->rx_frags
+= RXMAC_FRAG_CNT_COUNT
;
3949 if (val
& XRXMAC_STATUS_RXMULTF_CNT_EXP
)
3950 mp
->rx_mcasts
+= RXMAC_MC_FRM_CNT_COUNT
;
3951 if (val
& XRXMAC_STATUS_RXBCAST_CNT_EXP
)
3952 mp
->rx_bcasts
+= RXMAC_BC_FRM_CNT_COUNT
;
3953 if (val
& XRXMAC_STATUS_RXHIST1_CNT_EXP
)
3954 mp
->rx_hist_cnt1
+= RXMAC_HIST_CNT1_COUNT
;
3955 if (val
& XRXMAC_STATUS_RXHIST2_CNT_EXP
)
3956 mp
->rx_hist_cnt2
+= RXMAC_HIST_CNT2_COUNT
;
3957 if (val
& XRXMAC_STATUS_RXHIST3_CNT_EXP
)
3958 mp
->rx_hist_cnt3
+= RXMAC_HIST_CNT3_COUNT
;
3959 if (val
& XRXMAC_STATUS_RXHIST4_CNT_EXP
)
3960 mp
->rx_hist_cnt4
+= RXMAC_HIST_CNT4_COUNT
;
3961 if (val
& XRXMAC_STATUS_RXHIST5_CNT_EXP
)
3962 mp
->rx_hist_cnt5
+= RXMAC_HIST_CNT5_COUNT
;
3963 if (val
& XRXMAC_STATUS_RXHIST6_CNT_EXP
)
3964 mp
->rx_hist_cnt6
+= RXMAC_HIST_CNT6_COUNT
;
3965 if (val
& XRXMAC_STATUS_RXHIST7_CNT_EXP
)
3966 mp
->rx_hist_cnt7
+= RXMAC_HIST_CNT7_COUNT
;
3967 if (val
& XRXMAC_STATUS_RXOCTET_CNT_EXP
)
3968 mp
->rx_octets
+= RXMAC_BT_CNT_COUNT
;
3969 if (val
& XRXMAC_STATUS_CVIOLERR_CNT_EXP
)
3970 mp
->rx_code_violations
+= RXMAC_CD_VIO_CNT_COUNT
;
3971 if (val
& XRXMAC_STATUS_LENERR_CNT_EXP
)
3972 mp
->rx_len_errors
+= RXMAC_MPSZER_CNT_COUNT
;
3973 if (val
& XRXMAC_STATUS_CRCERR_CNT_EXP
)
3974 mp
->rx_crc_errors
+= RXMAC_CRC_ER_CNT_COUNT
;
3975 if (val
& XRXMAC_STATUS_RXUFLOW
)
3976 mp
->rx_underflows
++;
3977 if (val
& XRXMAC_STATUS_RXOFLOW
)
3980 val
= nr64_mac(XMAC_FC_STAT
);
3981 if (val
& XMAC_FC_STAT_TX_MAC_NPAUSE
)
3982 mp
->pause_off_state
++;
3983 if (val
& XMAC_FC_STAT_TX_MAC_PAUSE
)
3984 mp
->pause_on_state
++;
3985 if (val
& XMAC_FC_STAT_RX_MAC_RPAUSE
)
3986 mp
->pause_received
++;
3989 static void niu_bmac_interrupt(struct niu
*np
)
3991 struct niu_bmac_stats
*mp
= &np
->mac_stats
.bmac
;
3994 val
= nr64_mac(BTXMAC_STATUS
);
3995 if (val
& BTXMAC_STATUS_UNDERRUN
)
3996 mp
->tx_underflow_errors
++;
3997 if (val
& BTXMAC_STATUS_MAX_PKT_ERR
)
3998 mp
->tx_max_pkt_size_errors
++;
3999 if (val
& BTXMAC_STATUS_BYTE_CNT_EXP
)
4000 mp
->tx_bytes
+= BTXMAC_BYTE_CNT_COUNT
;
4001 if (val
& BTXMAC_STATUS_FRAME_CNT_EXP
)
4002 mp
->tx_frames
+= BTXMAC_FRM_CNT_COUNT
;
4004 val
= nr64_mac(BRXMAC_STATUS
);
4005 if (val
& BRXMAC_STATUS_OVERFLOW
)
4007 if (val
& BRXMAC_STATUS_FRAME_CNT_EXP
)
4008 mp
->rx_frames
+= BRXMAC_FRAME_CNT_COUNT
;
4009 if (val
& BRXMAC_STATUS_ALIGN_ERR_EXP
)
4010 mp
->rx_align_errors
+= BRXMAC_ALIGN_ERR_CNT_COUNT
;
4011 if (val
& BRXMAC_STATUS_CRC_ERR_EXP
)
4012 mp
->rx_crc_errors
+= BRXMAC_ALIGN_ERR_CNT_COUNT
;
4013 if (val
& BRXMAC_STATUS_LEN_ERR_EXP
)
4014 mp
->rx_len_errors
+= BRXMAC_CODE_VIOL_ERR_CNT_COUNT
;
4016 val
= nr64_mac(BMAC_CTRL_STATUS
);
4017 if (val
& BMAC_CTRL_STATUS_NOPAUSE
)
4018 mp
->pause_off_state
++;
4019 if (val
& BMAC_CTRL_STATUS_PAUSE
)
4020 mp
->pause_on_state
++;
4021 if (val
& BMAC_CTRL_STATUS_PAUSE_RECV
)
4022 mp
->pause_received
++;
4025 static int niu_mac_interrupt(struct niu
*np
)
4027 if (np
->flags
& NIU_FLAGS_XMAC
)
4028 niu_xmac_interrupt(np
);
4030 niu_bmac_interrupt(np
);
4035 static void niu_log_device_error(struct niu
*np
, u64 stat
)
4037 netdev_err(np
->dev
, "Core device errors ( ");
4039 if (stat
& SYS_ERR_MASK_META2
)
4041 if (stat
& SYS_ERR_MASK_META1
)
4043 if (stat
& SYS_ERR_MASK_PEU
)
4045 if (stat
& SYS_ERR_MASK_TXC
)
4047 if (stat
& SYS_ERR_MASK_RDMC
)
4049 if (stat
& SYS_ERR_MASK_TDMC
)
4051 if (stat
& SYS_ERR_MASK_ZCP
)
4053 if (stat
& SYS_ERR_MASK_FFLP
)
4055 if (stat
& SYS_ERR_MASK_IPP
)
4057 if (stat
& SYS_ERR_MASK_MAC
)
4059 if (stat
& SYS_ERR_MASK_SMX
)
4065 static int niu_device_error(struct niu
*np
)
4067 u64 stat
= nr64(SYS_ERR_STAT
);
4069 netdev_err(np
->dev
, "Core device error, stat[%llx]\n",
4070 (unsigned long long)stat
);
4072 niu_log_device_error(np
, stat
);
4077 static int niu_slowpath_interrupt(struct niu
*np
, struct niu_ldg
*lp
,
4078 u64 v0
, u64 v1
, u64 v2
)
4087 if (v1
& 0x00000000ffffffffULL
) {
4088 u32 rx_vec
= (v1
& 0xffffffff);
4090 for (i
= 0; i
< np
->num_rx_rings
; i
++) {
4091 struct rx_ring_info
*rp
= &np
->rx_rings
[i
];
4093 if (rx_vec
& (1 << rp
->rx_channel
)) {
4094 int r
= niu_rx_error(np
, rp
);
4099 nw64(RX_DMA_CTL_STAT(rp
->rx_channel
),
4100 RX_DMA_CTL_STAT_MEX
);
4105 if (v1
& 0x7fffffff00000000ULL
) {
4106 u32 tx_vec
= (v1
>> 32) & 0x7fffffff;
4108 for (i
= 0; i
< np
->num_tx_rings
; i
++) {
4109 struct tx_ring_info
*rp
= &np
->tx_rings
[i
];
4111 if (tx_vec
& (1 << rp
->tx_channel
)) {
4112 int r
= niu_tx_error(np
, rp
);
4118 if ((v0
| v1
) & 0x8000000000000000ULL
) {
4119 int r
= niu_mif_interrupt(np
);
4125 int r
= niu_mac_interrupt(np
);
4130 int r
= niu_device_error(np
);
4137 niu_enable_interrupts(np
, 0);
4142 static void niu_rxchan_intr(struct niu
*np
, struct rx_ring_info
*rp
,
4145 struct rxdma_mailbox
*mbox
= rp
->mbox
;
4146 u64 stat_write
, stat
= le64_to_cpup(&mbox
->rx_dma_ctl_stat
);
4148 stat_write
= (RX_DMA_CTL_STAT_RCRTHRES
|
4149 RX_DMA_CTL_STAT_RCRTO
);
4150 nw64(RX_DMA_CTL_STAT(rp
->rx_channel
), stat_write
);
4152 netif_printk(np
, intr
, KERN_DEBUG
, np
->dev
,
4153 "%s() stat[%llx]\n", __func__
, (unsigned long long)stat
);
4156 static void niu_txchan_intr(struct niu
*np
, struct tx_ring_info
*rp
,
4159 rp
->tx_cs
= nr64(TX_CS(rp
->tx_channel
));
4161 netif_printk(np
, intr
, KERN_DEBUG
, np
->dev
,
4162 "%s() cs[%llx]\n", __func__
, (unsigned long long)rp
->tx_cs
);
4165 static void __niu_fastpath_interrupt(struct niu
*np
, int ldg
, u64 v0
)
4167 struct niu_parent
*parent
= np
->parent
;
4171 tx_vec
= (v0
>> 32);
4172 rx_vec
= (v0
& 0xffffffff);
4174 for (i
= 0; i
< np
->num_rx_rings
; i
++) {
4175 struct rx_ring_info
*rp
= &np
->rx_rings
[i
];
4176 int ldn
= LDN_RXDMA(rp
->rx_channel
);
4178 if (parent
->ldg_map
[ldn
] != ldg
)
4181 nw64(LD_IM0(ldn
), LD_IM0_MASK
);
4182 if (rx_vec
& (1 << rp
->rx_channel
))
4183 niu_rxchan_intr(np
, rp
, ldn
);
4186 for (i
= 0; i
< np
->num_tx_rings
; i
++) {
4187 struct tx_ring_info
*rp
= &np
->tx_rings
[i
];
4188 int ldn
= LDN_TXDMA(rp
->tx_channel
);
4190 if (parent
->ldg_map
[ldn
] != ldg
)
4193 nw64(LD_IM0(ldn
), LD_IM0_MASK
);
4194 if (tx_vec
& (1 << rp
->tx_channel
))
4195 niu_txchan_intr(np
, rp
, ldn
);
4199 static void niu_schedule_napi(struct niu
*np
, struct niu_ldg
*lp
,
4200 u64 v0
, u64 v1
, u64 v2
)
4202 if (likely(napi_schedule_prep(&lp
->napi
))) {
4206 __niu_fastpath_interrupt(np
, lp
->ldg_num
, v0
);
4207 __napi_schedule(&lp
->napi
);
4211 static irqreturn_t
niu_interrupt(int irq
, void *dev_id
)
4213 struct niu_ldg
*lp
= dev_id
;
4214 struct niu
*np
= lp
->np
;
4215 int ldg
= lp
->ldg_num
;
4216 unsigned long flags
;
4219 if (netif_msg_intr(np
))
4220 printk(KERN_DEBUG KBUILD_MODNAME
": " "%s() ldg[%p](%d)",
4223 spin_lock_irqsave(&np
->lock
, flags
);
4225 v0
= nr64(LDSV0(ldg
));
4226 v1
= nr64(LDSV1(ldg
));
4227 v2
= nr64(LDSV2(ldg
));
4229 if (netif_msg_intr(np
))
4230 pr_cont(" v0[%llx] v1[%llx] v2[%llx]\n",
4231 (unsigned long long) v0
,
4232 (unsigned long long) v1
,
4233 (unsigned long long) v2
);
4235 if (unlikely(!v0
&& !v1
&& !v2
)) {
4236 spin_unlock_irqrestore(&np
->lock
, flags
);
4240 if (unlikely((v0
& ((u64
)1 << LDN_MIF
)) || v1
|| v2
)) {
4241 int err
= niu_slowpath_interrupt(np
, lp
, v0
, v1
, v2
);
4245 if (likely(v0
& ~((u64
)1 << LDN_MIF
)))
4246 niu_schedule_napi(np
, lp
, v0
, v1
, v2
);
4248 niu_ldg_rearm(np
, lp
, 1);
4250 spin_unlock_irqrestore(&np
->lock
, flags
);
4255 static void niu_free_rx_ring_info(struct niu
*np
, struct rx_ring_info
*rp
)
4258 np
->ops
->free_coherent(np
->device
,
4259 sizeof(struct rxdma_mailbox
),
4260 rp
->mbox
, rp
->mbox_dma
);
4264 np
->ops
->free_coherent(np
->device
,
4265 MAX_RCR_RING_SIZE
* sizeof(__le64
),
4266 rp
->rcr
, rp
->rcr_dma
);
4268 rp
->rcr_table_size
= 0;
4272 niu_rbr_free(np
, rp
);
4274 np
->ops
->free_coherent(np
->device
,
4275 MAX_RBR_RING_SIZE
* sizeof(__le32
),
4276 rp
->rbr
, rp
->rbr_dma
);
4278 rp
->rbr_table_size
= 0;
4285 static void niu_free_tx_ring_info(struct niu
*np
, struct tx_ring_info
*rp
)
4288 np
->ops
->free_coherent(np
->device
,
4289 sizeof(struct txdma_mailbox
),
4290 rp
->mbox
, rp
->mbox_dma
);
4296 for (i
= 0; i
< MAX_TX_RING_SIZE
; i
++) {
4297 if (rp
->tx_buffs
[i
].skb
)
4298 (void) release_tx_packet(np
, rp
, i
);
4301 np
->ops
->free_coherent(np
->device
,
4302 MAX_TX_RING_SIZE
* sizeof(__le64
),
4303 rp
->descr
, rp
->descr_dma
);
4312 static void niu_free_channels(struct niu
*np
)
4317 for (i
= 0; i
< np
->num_rx_rings
; i
++) {
4318 struct rx_ring_info
*rp
= &np
->rx_rings
[i
];
4320 niu_free_rx_ring_info(np
, rp
);
4322 kfree(np
->rx_rings
);
4323 np
->rx_rings
= NULL
;
4324 np
->num_rx_rings
= 0;
4328 for (i
= 0; i
< np
->num_tx_rings
; i
++) {
4329 struct tx_ring_info
*rp
= &np
->tx_rings
[i
];
4331 niu_free_tx_ring_info(np
, rp
);
4333 kfree(np
->tx_rings
);
4334 np
->tx_rings
= NULL
;
4335 np
->num_tx_rings
= 0;
4339 static int niu_alloc_rx_ring_info(struct niu
*np
,
4340 struct rx_ring_info
*rp
)
4342 BUILD_BUG_ON(sizeof(struct rxdma_mailbox
) != 64);
4344 rp
->rxhash
= kcalloc(MAX_RBR_RING_SIZE
, sizeof(struct page
*),
4349 rp
->mbox
= np
->ops
->alloc_coherent(np
->device
,
4350 sizeof(struct rxdma_mailbox
),
4351 &rp
->mbox_dma
, GFP_KERNEL
);
4354 if ((unsigned long)rp
->mbox
& (64UL - 1)) {
4355 netdev_err(np
->dev
, "Coherent alloc gives misaligned RXDMA mailbox %p\n",
4360 rp
->rcr
= np
->ops
->alloc_coherent(np
->device
,
4361 MAX_RCR_RING_SIZE
* sizeof(__le64
),
4362 &rp
->rcr_dma
, GFP_KERNEL
);
4365 if ((unsigned long)rp
->rcr
& (64UL - 1)) {
4366 netdev_err(np
->dev
, "Coherent alloc gives misaligned RXDMA RCR table %p\n",
4370 rp
->rcr_table_size
= MAX_RCR_RING_SIZE
;
4373 rp
->rbr
= np
->ops
->alloc_coherent(np
->device
,
4374 MAX_RBR_RING_SIZE
* sizeof(__le32
),
4375 &rp
->rbr_dma
, GFP_KERNEL
);
4378 if ((unsigned long)rp
->rbr
& (64UL - 1)) {
4379 netdev_err(np
->dev
, "Coherent alloc gives misaligned RXDMA RBR table %p\n",
4383 rp
->rbr_table_size
= MAX_RBR_RING_SIZE
;
4385 rp
->rbr_pending
= 0;
4390 static void niu_set_max_burst(struct niu
*np
, struct tx_ring_info
*rp
)
4392 int mtu
= np
->dev
->mtu
;
4394 /* These values are recommended by the HW designers for fair
4395 * utilization of DRR amongst the rings.
4397 rp
->max_burst
= mtu
+ 32;
4398 if (rp
->max_burst
> 4096)
4399 rp
->max_burst
= 4096;
4402 static int niu_alloc_tx_ring_info(struct niu
*np
,
4403 struct tx_ring_info
*rp
)
4405 BUILD_BUG_ON(sizeof(struct txdma_mailbox
) != 64);
4407 rp
->mbox
= np
->ops
->alloc_coherent(np
->device
,
4408 sizeof(struct txdma_mailbox
),
4409 &rp
->mbox_dma
, GFP_KERNEL
);
4412 if ((unsigned long)rp
->mbox
& (64UL - 1)) {
4413 netdev_err(np
->dev
, "Coherent alloc gives misaligned TXDMA mailbox %p\n",
4418 rp
->descr
= np
->ops
->alloc_coherent(np
->device
,
4419 MAX_TX_RING_SIZE
* sizeof(__le64
),
4420 &rp
->descr_dma
, GFP_KERNEL
);
4423 if ((unsigned long)rp
->descr
& (64UL - 1)) {
4424 netdev_err(np
->dev
, "Coherent alloc gives misaligned TXDMA descr table %p\n",
4429 rp
->pending
= MAX_TX_RING_SIZE
;
4434 /* XXX make these configurable... XXX */
4435 rp
->mark_freq
= rp
->pending
/ 4;
4437 niu_set_max_burst(np
, rp
);
4442 static void niu_size_rbr(struct niu
*np
, struct rx_ring_info
*rp
)
4446 bss
= min(PAGE_SHIFT
, 15);
4448 rp
->rbr_block_size
= 1 << bss
;
4449 rp
->rbr_blocks_per_page
= 1 << (PAGE_SHIFT
-bss
);
4451 rp
->rbr_sizes
[0] = 256;
4452 rp
->rbr_sizes
[1] = 1024;
4453 if (np
->dev
->mtu
> ETH_DATA_LEN
) {
4454 switch (PAGE_SIZE
) {
4456 rp
->rbr_sizes
[2] = 4096;
4460 rp
->rbr_sizes
[2] = 8192;
4464 rp
->rbr_sizes
[2] = 2048;
4466 rp
->rbr_sizes
[3] = rp
->rbr_block_size
;
4469 static int niu_alloc_channels(struct niu
*np
)
4471 struct niu_parent
*parent
= np
->parent
;
4472 int first_rx_channel
, first_tx_channel
;
4473 int num_rx_rings
, num_tx_rings
;
4474 struct rx_ring_info
*rx_rings
;
4475 struct tx_ring_info
*tx_rings
;
4479 first_rx_channel
= first_tx_channel
= 0;
4480 for (i
= 0; i
< port
; i
++) {
4481 first_rx_channel
+= parent
->rxchan_per_port
[i
];
4482 first_tx_channel
+= parent
->txchan_per_port
[i
];
4485 num_rx_rings
= parent
->rxchan_per_port
[port
];
4486 num_tx_rings
= parent
->txchan_per_port
[port
];
4488 rx_rings
= kcalloc(num_rx_rings
, sizeof(struct rx_ring_info
),
4494 np
->num_rx_rings
= num_rx_rings
;
4496 np
->rx_rings
= rx_rings
;
4498 netif_set_real_num_rx_queues(np
->dev
, num_rx_rings
);
4500 for (i
= 0; i
< np
->num_rx_rings
; i
++) {
4501 struct rx_ring_info
*rp
= &np
->rx_rings
[i
];
4504 rp
->rx_channel
= first_rx_channel
+ i
;
4506 err
= niu_alloc_rx_ring_info(np
, rp
);
4510 niu_size_rbr(np
, rp
);
4512 /* XXX better defaults, configurable, etc... XXX */
4513 rp
->nonsyn_window
= 64;
4514 rp
->nonsyn_threshold
= rp
->rcr_table_size
- 64;
4515 rp
->syn_window
= 64;
4516 rp
->syn_threshold
= rp
->rcr_table_size
- 64;
4517 rp
->rcr_pkt_threshold
= 16;
4518 rp
->rcr_timeout
= 8;
4519 rp
->rbr_kick_thresh
= RBR_REFILL_MIN
;
4520 if (rp
->rbr_kick_thresh
< rp
->rbr_blocks_per_page
)
4521 rp
->rbr_kick_thresh
= rp
->rbr_blocks_per_page
;
4523 err
= niu_rbr_fill(np
, rp
, GFP_KERNEL
);
4528 tx_rings
= kcalloc(num_tx_rings
, sizeof(struct tx_ring_info
),
4534 np
->num_tx_rings
= num_tx_rings
;
4536 np
->tx_rings
= tx_rings
;
4538 netif_set_real_num_tx_queues(np
->dev
, num_tx_rings
);
4540 for (i
= 0; i
< np
->num_tx_rings
; i
++) {
4541 struct tx_ring_info
*rp
= &np
->tx_rings
[i
];
4544 rp
->tx_channel
= first_tx_channel
+ i
;
4546 err
= niu_alloc_tx_ring_info(np
, rp
);
4554 niu_free_channels(np
);
4558 static int niu_tx_cs_sng_poll(struct niu
*np
, int channel
)
4562 while (--limit
> 0) {
4563 u64 val
= nr64(TX_CS(channel
));
4564 if (val
& TX_CS_SNG_STATE
)
4570 static int niu_tx_channel_stop(struct niu
*np
, int channel
)
4572 u64 val
= nr64(TX_CS(channel
));
4574 val
|= TX_CS_STOP_N_GO
;
4575 nw64(TX_CS(channel
), val
);
4577 return niu_tx_cs_sng_poll(np
, channel
);
4580 static int niu_tx_cs_reset_poll(struct niu
*np
, int channel
)
4584 while (--limit
> 0) {
4585 u64 val
= nr64(TX_CS(channel
));
4586 if (!(val
& TX_CS_RST
))
4592 static int niu_tx_channel_reset(struct niu
*np
, int channel
)
4594 u64 val
= nr64(TX_CS(channel
));
4598 nw64(TX_CS(channel
), val
);
4600 err
= niu_tx_cs_reset_poll(np
, channel
);
4602 nw64(TX_RING_KICK(channel
), 0);
4607 static int niu_tx_channel_lpage_init(struct niu
*np
, int channel
)
4611 nw64(TX_LOG_MASK1(channel
), 0);
4612 nw64(TX_LOG_VAL1(channel
), 0);
4613 nw64(TX_LOG_MASK2(channel
), 0);
4614 nw64(TX_LOG_VAL2(channel
), 0);
4615 nw64(TX_LOG_PAGE_RELO1(channel
), 0);
4616 nw64(TX_LOG_PAGE_RELO2(channel
), 0);
4617 nw64(TX_LOG_PAGE_HDL(channel
), 0);
4619 val
= (u64
)np
->port
<< TX_LOG_PAGE_VLD_FUNC_SHIFT
;
4620 val
|= (TX_LOG_PAGE_VLD_PAGE0
| TX_LOG_PAGE_VLD_PAGE1
);
4621 nw64(TX_LOG_PAGE_VLD(channel
), val
);
4623 /* XXX TXDMA 32bit mode? XXX */
4628 static void niu_txc_enable_port(struct niu
*np
, int on
)
4630 unsigned long flags
;
4633 niu_lock_parent(np
, flags
);
4634 val
= nr64(TXC_CONTROL
);
4635 mask
= (u64
)1 << np
->port
;
4637 val
|= TXC_CONTROL_ENABLE
| mask
;
4640 if ((val
& ~TXC_CONTROL_ENABLE
) == 0)
4641 val
&= ~TXC_CONTROL_ENABLE
;
4643 nw64(TXC_CONTROL
, val
);
4644 niu_unlock_parent(np
, flags
);
4647 static void niu_txc_set_imask(struct niu
*np
, u64 imask
)
4649 unsigned long flags
;
4652 niu_lock_parent(np
, flags
);
4653 val
= nr64(TXC_INT_MASK
);
4654 val
&= ~TXC_INT_MASK_VAL(np
->port
);
4655 val
|= (imask
<< TXC_INT_MASK_VAL_SHIFT(np
->port
));
4656 niu_unlock_parent(np
, flags
);
4659 static void niu_txc_port_dma_enable(struct niu
*np
, int on
)
4666 for (i
= 0; i
< np
->num_tx_rings
; i
++)
4667 val
|= (1 << np
->tx_rings
[i
].tx_channel
);
4669 nw64(TXC_PORT_DMA(np
->port
), val
);
4672 static int niu_init_one_tx_channel(struct niu
*np
, struct tx_ring_info
*rp
)
4674 int err
, channel
= rp
->tx_channel
;
4677 err
= niu_tx_channel_stop(np
, channel
);
4681 err
= niu_tx_channel_reset(np
, channel
);
4685 err
= niu_tx_channel_lpage_init(np
, channel
);
4689 nw64(TXC_DMA_MAX(channel
), rp
->max_burst
);
4690 nw64(TX_ENT_MSK(channel
), 0);
4692 if (rp
->descr_dma
& ~(TX_RNG_CFIG_STADDR_BASE
|
4693 TX_RNG_CFIG_STADDR
)) {
4694 netdev_err(np
->dev
, "TX ring channel %d DMA addr (%llx) is not aligned\n",
4695 channel
, (unsigned long long)rp
->descr_dma
);
4699 /* The length field in TX_RNG_CFIG is measured in 64-byte
4700 * blocks. rp->pending is the number of TX descriptors in
4701 * our ring, 8 bytes each, thus we divide by 8 bytes more
4702 * to get the proper value the chip wants.
4704 ring_len
= (rp
->pending
/ 8);
4706 val
= ((ring_len
<< TX_RNG_CFIG_LEN_SHIFT
) |
4708 nw64(TX_RNG_CFIG(channel
), val
);
4710 if (((rp
->mbox_dma
>> 32) & ~TXDMA_MBH_MBADDR
) ||
4711 ((u32
)rp
->mbox_dma
& ~TXDMA_MBL_MBADDR
)) {
4712 netdev_err(np
->dev
, "TX ring channel %d MBOX addr (%llx) has invalid bits\n",
4713 channel
, (unsigned long long)rp
->mbox_dma
);
4716 nw64(TXDMA_MBH(channel
), rp
->mbox_dma
>> 32);
4717 nw64(TXDMA_MBL(channel
), rp
->mbox_dma
& TXDMA_MBL_MBADDR
);
4719 nw64(TX_CS(channel
), 0);
4721 rp
->last_pkt_cnt
= 0;
4726 static void niu_init_rdc_groups(struct niu
*np
)
4728 struct niu_rdc_tables
*tp
= &np
->parent
->rdc_group_cfg
[np
->port
];
4729 int i
, first_table_num
= tp
->first_table_num
;
4731 for (i
= 0; i
< tp
->num_tables
; i
++) {
4732 struct rdc_table
*tbl
= &tp
->tables
[i
];
4733 int this_table
= first_table_num
+ i
;
4736 for (slot
= 0; slot
< NIU_RDC_TABLE_SLOTS
; slot
++)
4737 nw64(RDC_TBL(this_table
, slot
),
4738 tbl
->rxdma_channel
[slot
]);
4741 nw64(DEF_RDC(np
->port
), np
->parent
->rdc_default
[np
->port
]);
4744 static void niu_init_drr_weight(struct niu
*np
)
4746 int type
= phy_decode(np
->parent
->port_phy
, np
->port
);
4751 val
= PT_DRR_WEIGHT_DEFAULT_10G
;
4756 val
= PT_DRR_WEIGHT_DEFAULT_1G
;
4759 nw64(PT_DRR_WT(np
->port
), val
);
4762 static int niu_init_hostinfo(struct niu
*np
)
4764 struct niu_parent
*parent
= np
->parent
;
4765 struct niu_rdc_tables
*tp
= &parent
->rdc_group_cfg
[np
->port
];
4766 int i
, err
, num_alt
= niu_num_alt_addr(np
);
4767 int first_rdc_table
= tp
->first_table_num
;
4769 err
= niu_set_primary_mac_rdc_table(np
, first_rdc_table
, 1);
4773 err
= niu_set_multicast_mac_rdc_table(np
, first_rdc_table
, 1);
4777 for (i
= 0; i
< num_alt
; i
++) {
4778 err
= niu_set_alt_mac_rdc_table(np
, i
, first_rdc_table
, 1);
4786 static int niu_rx_channel_reset(struct niu
*np
, int channel
)
4788 return niu_set_and_wait_clear(np
, RXDMA_CFIG1(channel
),
4789 RXDMA_CFIG1_RST
, 1000, 10,
4793 static int niu_rx_channel_lpage_init(struct niu
*np
, int channel
)
4797 nw64(RX_LOG_MASK1(channel
), 0);
4798 nw64(RX_LOG_VAL1(channel
), 0);
4799 nw64(RX_LOG_MASK2(channel
), 0);
4800 nw64(RX_LOG_VAL2(channel
), 0);
4801 nw64(RX_LOG_PAGE_RELO1(channel
), 0);
4802 nw64(RX_LOG_PAGE_RELO2(channel
), 0);
4803 nw64(RX_LOG_PAGE_HDL(channel
), 0);
4805 val
= (u64
)np
->port
<< RX_LOG_PAGE_VLD_FUNC_SHIFT
;
4806 val
|= (RX_LOG_PAGE_VLD_PAGE0
| RX_LOG_PAGE_VLD_PAGE1
);
4807 nw64(RX_LOG_PAGE_VLD(channel
), val
);
4812 static void niu_rx_channel_wred_init(struct niu
*np
, struct rx_ring_info
*rp
)
4816 val
= (((u64
)rp
->nonsyn_window
<< RDC_RED_PARA_WIN_SHIFT
) |
4817 ((u64
)rp
->nonsyn_threshold
<< RDC_RED_PARA_THRE_SHIFT
) |
4818 ((u64
)rp
->syn_window
<< RDC_RED_PARA_WIN_SYN_SHIFT
) |
4819 ((u64
)rp
->syn_threshold
<< RDC_RED_PARA_THRE_SYN_SHIFT
));
4820 nw64(RDC_RED_PARA(rp
->rx_channel
), val
);
4823 static int niu_compute_rbr_cfig_b(struct rx_ring_info
*rp
, u64
*ret
)
4828 switch (rp
->rbr_block_size
) {
4830 val
|= (RBR_BLKSIZE_4K
<< RBR_CFIG_B_BLKSIZE_SHIFT
);
4833 val
|= (RBR_BLKSIZE_8K
<< RBR_CFIG_B_BLKSIZE_SHIFT
);
4836 val
|= (RBR_BLKSIZE_16K
<< RBR_CFIG_B_BLKSIZE_SHIFT
);
4839 val
|= (RBR_BLKSIZE_32K
<< RBR_CFIG_B_BLKSIZE_SHIFT
);
4844 val
|= RBR_CFIG_B_VLD2
;
4845 switch (rp
->rbr_sizes
[2]) {
4847 val
|= (RBR_BUFSZ2_2K
<< RBR_CFIG_B_BUFSZ2_SHIFT
);
4850 val
|= (RBR_BUFSZ2_4K
<< RBR_CFIG_B_BUFSZ2_SHIFT
);
4853 val
|= (RBR_BUFSZ2_8K
<< RBR_CFIG_B_BUFSZ2_SHIFT
);
4856 val
|= (RBR_BUFSZ2_16K
<< RBR_CFIG_B_BUFSZ2_SHIFT
);
4862 val
|= RBR_CFIG_B_VLD1
;
4863 switch (rp
->rbr_sizes
[1]) {
4865 val
|= (RBR_BUFSZ1_1K
<< RBR_CFIG_B_BUFSZ1_SHIFT
);
4868 val
|= (RBR_BUFSZ1_2K
<< RBR_CFIG_B_BUFSZ1_SHIFT
);
4871 val
|= (RBR_BUFSZ1_4K
<< RBR_CFIG_B_BUFSZ1_SHIFT
);
4874 val
|= (RBR_BUFSZ1_8K
<< RBR_CFIG_B_BUFSZ1_SHIFT
);
4880 val
|= RBR_CFIG_B_VLD0
;
4881 switch (rp
->rbr_sizes
[0]) {
4883 val
|= (RBR_BUFSZ0_256
<< RBR_CFIG_B_BUFSZ0_SHIFT
);
4886 val
|= (RBR_BUFSZ0_512
<< RBR_CFIG_B_BUFSZ0_SHIFT
);
4889 val
|= (RBR_BUFSZ0_1K
<< RBR_CFIG_B_BUFSZ0_SHIFT
);
4892 val
|= (RBR_BUFSZ0_2K
<< RBR_CFIG_B_BUFSZ0_SHIFT
);
4903 static int niu_enable_rx_channel(struct niu
*np
, int channel
, int on
)
4905 u64 val
= nr64(RXDMA_CFIG1(channel
));
4909 val
|= RXDMA_CFIG1_EN
;
4911 val
&= ~RXDMA_CFIG1_EN
;
4912 nw64(RXDMA_CFIG1(channel
), val
);
4915 while (--limit
> 0) {
4916 if (nr64(RXDMA_CFIG1(channel
)) & RXDMA_CFIG1_QST
)
4925 static int niu_init_one_rx_channel(struct niu
*np
, struct rx_ring_info
*rp
)
4927 int err
, channel
= rp
->rx_channel
;
4930 err
= niu_rx_channel_reset(np
, channel
);
4934 err
= niu_rx_channel_lpage_init(np
, channel
);
4938 niu_rx_channel_wred_init(np
, rp
);
4940 nw64(RX_DMA_ENT_MSK(channel
), RX_DMA_ENT_MSK_RBR_EMPTY
);
4941 nw64(RX_DMA_CTL_STAT(channel
),
4942 (RX_DMA_CTL_STAT_MEX
|
4943 RX_DMA_CTL_STAT_RCRTHRES
|
4944 RX_DMA_CTL_STAT_RCRTO
|
4945 RX_DMA_CTL_STAT_RBR_EMPTY
));
4946 nw64(RXDMA_CFIG1(channel
), rp
->mbox_dma
>> 32);
4947 nw64(RXDMA_CFIG2(channel
),
4948 ((rp
->mbox_dma
& RXDMA_CFIG2_MBADDR_L
) |
4949 RXDMA_CFIG2_FULL_HDR
));
4950 nw64(RBR_CFIG_A(channel
),
4951 ((u64
)rp
->rbr_table_size
<< RBR_CFIG_A_LEN_SHIFT
) |
4952 (rp
->rbr_dma
& (RBR_CFIG_A_STADDR_BASE
| RBR_CFIG_A_STADDR
)));
4953 err
= niu_compute_rbr_cfig_b(rp
, &val
);
4956 nw64(RBR_CFIG_B(channel
), val
);
4957 nw64(RCRCFIG_A(channel
),
4958 ((u64
)rp
->rcr_table_size
<< RCRCFIG_A_LEN_SHIFT
) |
4959 (rp
->rcr_dma
& (RCRCFIG_A_STADDR_BASE
| RCRCFIG_A_STADDR
)));
4960 nw64(RCRCFIG_B(channel
),
4961 ((u64
)rp
->rcr_pkt_threshold
<< RCRCFIG_B_PTHRES_SHIFT
) |
4963 ((u64
)rp
->rcr_timeout
<< RCRCFIG_B_TIMEOUT_SHIFT
));
4965 err
= niu_enable_rx_channel(np
, channel
, 1);
4969 nw64(RBR_KICK(channel
), rp
->rbr_index
);
4971 val
= nr64(RX_DMA_CTL_STAT(channel
));
4972 val
|= RX_DMA_CTL_STAT_RBR_EMPTY
;
4973 nw64(RX_DMA_CTL_STAT(channel
), val
);
4978 static int niu_init_rx_channels(struct niu
*np
)
4980 unsigned long flags
;
4981 u64 seed
= jiffies_64
;
4984 niu_lock_parent(np
, flags
);
4985 nw64(RX_DMA_CK_DIV
, np
->parent
->rxdma_clock_divider
);
4986 nw64(RED_RAN_INIT
, RED_RAN_INIT_OPMODE
| (seed
& RED_RAN_INIT_VAL
));
4987 niu_unlock_parent(np
, flags
);
4989 /* XXX RXDMA 32bit mode? XXX */
4991 niu_init_rdc_groups(np
);
4992 niu_init_drr_weight(np
);
4994 err
= niu_init_hostinfo(np
);
4998 for (i
= 0; i
< np
->num_rx_rings
; i
++) {
4999 struct rx_ring_info
*rp
= &np
->rx_rings
[i
];
5001 err
= niu_init_one_rx_channel(np
, rp
);
5009 static int niu_set_ip_frag_rule(struct niu
*np
)
5011 struct niu_parent
*parent
= np
->parent
;
5012 struct niu_classifier
*cp
= &np
->clas
;
5013 struct niu_tcam_entry
*tp
;
5016 index
= cp
->tcam_top
;
5017 tp
= &parent
->tcam
[index
];
5019 /* Note that the noport bit is the same in both ipv4 and
5020 * ipv6 format TCAM entries.
5022 memset(tp
, 0, sizeof(*tp
));
5023 tp
->key
[1] = TCAM_V4KEY1_NOPORT
;
5024 tp
->key_mask
[1] = TCAM_V4KEY1_NOPORT
;
5025 tp
->assoc_data
= (TCAM_ASSOCDATA_TRES_USE_OFFSET
|
5026 ((u64
)0 << TCAM_ASSOCDATA_OFFSET_SHIFT
));
5027 err
= tcam_write(np
, index
, tp
->key
, tp
->key_mask
);
5030 err
= tcam_assoc_write(np
, index
, tp
->assoc_data
);
5034 cp
->tcam_valid_entries
++;
5039 static int niu_init_classifier_hw(struct niu
*np
)
5041 struct niu_parent
*parent
= np
->parent
;
5042 struct niu_classifier
*cp
= &np
->clas
;
5045 nw64(H1POLY
, cp
->h1_init
);
5046 nw64(H2POLY
, cp
->h2_init
);
5048 err
= niu_init_hostinfo(np
);
5052 for (i
= 0; i
< ENET_VLAN_TBL_NUM_ENTRIES
; i
++) {
5053 struct niu_vlan_rdc
*vp
= &cp
->vlan_mappings
[i
];
5055 vlan_tbl_write(np
, i
, np
->port
,
5056 vp
->vlan_pref
, vp
->rdc_num
);
5059 for (i
= 0; i
< cp
->num_alt_mac_mappings
; i
++) {
5060 struct niu_altmac_rdc
*ap
= &cp
->alt_mac_mappings
[i
];
5062 err
= niu_set_alt_mac_rdc_table(np
, ap
->alt_mac_num
,
5063 ap
->rdc_num
, ap
->mac_pref
);
5068 for (i
= CLASS_CODE_USER_PROG1
; i
<= CLASS_CODE_SCTP_IPV6
; i
++) {
5069 int index
= i
- CLASS_CODE_USER_PROG1
;
5071 err
= niu_set_tcam_key(np
, i
, parent
->tcam_key
[index
]);
5074 err
= niu_set_flow_key(np
, i
, parent
->flow_key
[index
]);
5079 err
= niu_set_ip_frag_rule(np
);
5088 static int niu_zcp_write(struct niu
*np
, int index
, u64
*data
)
5090 nw64(ZCP_RAM_DATA0
, data
[0]);
5091 nw64(ZCP_RAM_DATA1
, data
[1]);
5092 nw64(ZCP_RAM_DATA2
, data
[2]);
5093 nw64(ZCP_RAM_DATA3
, data
[3]);
5094 nw64(ZCP_RAM_DATA4
, data
[4]);
5095 nw64(ZCP_RAM_BE
, ZCP_RAM_BE_VAL
);
5097 (ZCP_RAM_ACC_WRITE
|
5098 (0 << ZCP_RAM_ACC_ZFCID_SHIFT
) |
5099 (ZCP_RAM_SEL_CFIFO(np
->port
) << ZCP_RAM_ACC_RAM_SEL_SHIFT
)));
5101 return niu_wait_bits_clear(np
, ZCP_RAM_ACC
, ZCP_RAM_ACC_BUSY
,
5105 static int niu_zcp_read(struct niu
*np
, int index
, u64
*data
)
5109 err
= niu_wait_bits_clear(np
, ZCP_RAM_ACC
, ZCP_RAM_ACC_BUSY
,
5112 netdev_err(np
->dev
, "ZCP read busy won't clear, ZCP_RAM_ACC[%llx]\n",
5113 (unsigned long long)nr64(ZCP_RAM_ACC
));
5119 (0 << ZCP_RAM_ACC_ZFCID_SHIFT
) |
5120 (ZCP_RAM_SEL_CFIFO(np
->port
) << ZCP_RAM_ACC_RAM_SEL_SHIFT
)));
5122 err
= niu_wait_bits_clear(np
, ZCP_RAM_ACC
, ZCP_RAM_ACC_BUSY
,
5125 netdev_err(np
->dev
, "ZCP read busy2 won't clear, ZCP_RAM_ACC[%llx]\n",
5126 (unsigned long long)nr64(ZCP_RAM_ACC
));
5130 data
[0] = nr64(ZCP_RAM_DATA0
);
5131 data
[1] = nr64(ZCP_RAM_DATA1
);
5132 data
[2] = nr64(ZCP_RAM_DATA2
);
5133 data
[3] = nr64(ZCP_RAM_DATA3
);
5134 data
[4] = nr64(ZCP_RAM_DATA4
);
5139 static void niu_zcp_cfifo_reset(struct niu
*np
)
5141 u64 val
= nr64(RESET_CFIFO
);
5143 val
|= RESET_CFIFO_RST(np
->port
);
5144 nw64(RESET_CFIFO
, val
);
5147 val
&= ~RESET_CFIFO_RST(np
->port
);
5148 nw64(RESET_CFIFO
, val
);
5151 static int niu_init_zcp(struct niu
*np
)
5153 u64 data
[5], rbuf
[5];
5156 if (np
->parent
->plat_type
!= PLAT_TYPE_NIU
) {
5157 if (np
->port
== 0 || np
->port
== 1)
5158 max
= ATLAS_P0_P1_CFIFO_ENTRIES
;
5160 max
= ATLAS_P2_P3_CFIFO_ENTRIES
;
5162 max
= NIU_CFIFO_ENTRIES
;
5170 for (i
= 0; i
< max
; i
++) {
5171 err
= niu_zcp_write(np
, i
, data
);
5174 err
= niu_zcp_read(np
, i
, rbuf
);
5179 niu_zcp_cfifo_reset(np
);
5180 nw64(CFIFO_ECC(np
->port
), 0);
5181 nw64(ZCP_INT_STAT
, ZCP_INT_STAT_ALL
);
5182 (void) nr64(ZCP_INT_STAT
);
5183 nw64(ZCP_INT_MASK
, ZCP_INT_MASK_ALL
);
5188 static void niu_ipp_write(struct niu
*np
, int index
, u64
*data
)
5190 u64 val
= nr64_ipp(IPP_CFIG
);
5192 nw64_ipp(IPP_CFIG
, val
| IPP_CFIG_DFIFO_PIO_W
);
5193 nw64_ipp(IPP_DFIFO_WR_PTR
, index
);
5194 nw64_ipp(IPP_DFIFO_WR0
, data
[0]);
5195 nw64_ipp(IPP_DFIFO_WR1
, data
[1]);
5196 nw64_ipp(IPP_DFIFO_WR2
, data
[2]);
5197 nw64_ipp(IPP_DFIFO_WR3
, data
[3]);
5198 nw64_ipp(IPP_DFIFO_WR4
, data
[4]);
5199 nw64_ipp(IPP_CFIG
, val
& ~IPP_CFIG_DFIFO_PIO_W
);
5202 static void niu_ipp_read(struct niu
*np
, int index
, u64
*data
)
5204 nw64_ipp(IPP_DFIFO_RD_PTR
, index
);
5205 data
[0] = nr64_ipp(IPP_DFIFO_RD0
);
5206 data
[1] = nr64_ipp(IPP_DFIFO_RD1
);
5207 data
[2] = nr64_ipp(IPP_DFIFO_RD2
);
5208 data
[3] = nr64_ipp(IPP_DFIFO_RD3
);
5209 data
[4] = nr64_ipp(IPP_DFIFO_RD4
);
5212 static int niu_ipp_reset(struct niu
*np
)
5214 return niu_set_and_wait_clear_ipp(np
, IPP_CFIG
, IPP_CFIG_SOFT_RST
,
5215 1000, 100, "IPP_CFIG");
5218 static int niu_init_ipp(struct niu
*np
)
5220 u64 data
[5], rbuf
[5], val
;
5223 if (np
->parent
->plat_type
!= PLAT_TYPE_NIU
) {
5224 if (np
->port
== 0 || np
->port
== 1)
5225 max
= ATLAS_P0_P1_DFIFO_ENTRIES
;
5227 max
= ATLAS_P2_P3_DFIFO_ENTRIES
;
5229 max
= NIU_DFIFO_ENTRIES
;
5237 for (i
= 0; i
< max
; i
++) {
5238 niu_ipp_write(np
, i
, data
);
5239 niu_ipp_read(np
, i
, rbuf
);
5242 (void) nr64_ipp(IPP_INT_STAT
);
5243 (void) nr64_ipp(IPP_INT_STAT
);
5245 err
= niu_ipp_reset(np
);
5249 (void) nr64_ipp(IPP_PKT_DIS
);
5250 (void) nr64_ipp(IPP_BAD_CS_CNT
);
5251 (void) nr64_ipp(IPP_ECC
);
5253 (void) nr64_ipp(IPP_INT_STAT
);
5255 nw64_ipp(IPP_MSK
, ~IPP_MSK_ALL
);
5257 val
= nr64_ipp(IPP_CFIG
);
5258 val
&= ~IPP_CFIG_IP_MAX_PKT
;
5259 val
|= (IPP_CFIG_IPP_ENABLE
|
5260 IPP_CFIG_DFIFO_ECC_EN
|
5261 IPP_CFIG_DROP_BAD_CRC
|
5263 (0x1ffff << IPP_CFIG_IP_MAX_PKT_SHIFT
));
5264 nw64_ipp(IPP_CFIG
, val
);
5269 static void niu_handle_led(struct niu
*np
, int status
)
5272 val
= nr64_mac(XMAC_CONFIG
);
5274 if ((np
->flags
& NIU_FLAGS_10G
) != 0 &&
5275 (np
->flags
& NIU_FLAGS_FIBER
) != 0) {
5277 val
|= XMAC_CONFIG_LED_POLARITY
;
5278 val
&= ~XMAC_CONFIG_FORCE_LED_ON
;
5280 val
|= XMAC_CONFIG_FORCE_LED_ON
;
5281 val
&= ~XMAC_CONFIG_LED_POLARITY
;
5285 nw64_mac(XMAC_CONFIG
, val
);
5288 static void niu_init_xif_xmac(struct niu
*np
)
5290 struct niu_link_config
*lp
= &np
->link_config
;
5293 if (np
->flags
& NIU_FLAGS_XCVR_SERDES
) {
5294 val
= nr64(MIF_CONFIG
);
5295 val
|= MIF_CONFIG_ATCA_GE
;
5296 nw64(MIF_CONFIG
, val
);
5299 val
= nr64_mac(XMAC_CONFIG
);
5300 val
&= ~XMAC_CONFIG_SEL_POR_CLK_SRC
;
5302 val
|= XMAC_CONFIG_TX_OUTPUT_EN
;
5304 if (lp
->loopback_mode
== LOOPBACK_MAC
) {
5305 val
&= ~XMAC_CONFIG_SEL_POR_CLK_SRC
;
5306 val
|= XMAC_CONFIG_LOOPBACK
;
5308 val
&= ~XMAC_CONFIG_LOOPBACK
;
5311 if (np
->flags
& NIU_FLAGS_10G
) {
5312 val
&= ~XMAC_CONFIG_LFS_DISABLE
;
5314 val
|= XMAC_CONFIG_LFS_DISABLE
;
5315 if (!(np
->flags
& NIU_FLAGS_FIBER
) &&
5316 !(np
->flags
& NIU_FLAGS_XCVR_SERDES
))
5317 val
|= XMAC_CONFIG_1G_PCS_BYPASS
;
5319 val
&= ~XMAC_CONFIG_1G_PCS_BYPASS
;
5322 val
&= ~XMAC_CONFIG_10G_XPCS_BYPASS
;
5324 if (lp
->active_speed
== SPEED_100
)
5325 val
|= XMAC_CONFIG_SEL_CLK_25MHZ
;
5327 val
&= ~XMAC_CONFIG_SEL_CLK_25MHZ
;
5329 nw64_mac(XMAC_CONFIG
, val
);
5331 val
= nr64_mac(XMAC_CONFIG
);
5332 val
&= ~XMAC_CONFIG_MODE_MASK
;
5333 if (np
->flags
& NIU_FLAGS_10G
) {
5334 val
|= XMAC_CONFIG_MODE_XGMII
;
5336 if (lp
->active_speed
== SPEED_1000
)
5337 val
|= XMAC_CONFIG_MODE_GMII
;
5339 val
|= XMAC_CONFIG_MODE_MII
;
5342 nw64_mac(XMAC_CONFIG
, val
);
5345 static void niu_init_xif_bmac(struct niu
*np
)
5347 struct niu_link_config
*lp
= &np
->link_config
;
5350 val
= BMAC_XIF_CONFIG_TX_OUTPUT_EN
;
5352 if (lp
->loopback_mode
== LOOPBACK_MAC
)
5353 val
|= BMAC_XIF_CONFIG_MII_LOOPBACK
;
5355 val
&= ~BMAC_XIF_CONFIG_MII_LOOPBACK
;
5357 if (lp
->active_speed
== SPEED_1000
)
5358 val
|= BMAC_XIF_CONFIG_GMII_MODE
;
5360 val
&= ~BMAC_XIF_CONFIG_GMII_MODE
;
5362 val
&= ~(BMAC_XIF_CONFIG_LINK_LED
|
5363 BMAC_XIF_CONFIG_LED_POLARITY
);
5365 if (!(np
->flags
& NIU_FLAGS_10G
) &&
5366 !(np
->flags
& NIU_FLAGS_FIBER
) &&
5367 lp
->active_speed
== SPEED_100
)
5368 val
|= BMAC_XIF_CONFIG_25MHZ_CLOCK
;
5370 val
&= ~BMAC_XIF_CONFIG_25MHZ_CLOCK
;
5372 nw64_mac(BMAC_XIF_CONFIG
, val
);
5375 static void niu_init_xif(struct niu
*np
)
5377 if (np
->flags
& NIU_FLAGS_XMAC
)
5378 niu_init_xif_xmac(np
);
5380 niu_init_xif_bmac(np
);
5383 static void niu_pcs_mii_reset(struct niu
*np
)
5386 u64 val
= nr64_pcs(PCS_MII_CTL
);
5387 val
|= PCS_MII_CTL_RST
;
5388 nw64_pcs(PCS_MII_CTL
, val
);
5389 while ((--limit
>= 0) && (val
& PCS_MII_CTL_RST
)) {
5391 val
= nr64_pcs(PCS_MII_CTL
);
5395 static void niu_xpcs_reset(struct niu
*np
)
5398 u64 val
= nr64_xpcs(XPCS_CONTROL1
);
5399 val
|= XPCS_CONTROL1_RESET
;
5400 nw64_xpcs(XPCS_CONTROL1
, val
);
5401 while ((--limit
>= 0) && (val
& XPCS_CONTROL1_RESET
)) {
5403 val
= nr64_xpcs(XPCS_CONTROL1
);
5407 static int niu_init_pcs(struct niu
*np
)
5409 struct niu_link_config
*lp
= &np
->link_config
;
5412 switch (np
->flags
& (NIU_FLAGS_10G
|
5414 NIU_FLAGS_XCVR_SERDES
)) {
5415 case NIU_FLAGS_FIBER
:
5417 nw64_pcs(PCS_CONF
, PCS_CONF_MASK
| PCS_CONF_ENABLE
);
5418 nw64_pcs(PCS_DPATH_MODE
, 0);
5419 niu_pcs_mii_reset(np
);
5423 case NIU_FLAGS_10G
| NIU_FLAGS_FIBER
:
5424 case NIU_FLAGS_10G
| NIU_FLAGS_XCVR_SERDES
:
5426 if (!(np
->flags
& NIU_FLAGS_XMAC
))
5429 /* 10G copper or fiber */
5430 val
= nr64_mac(XMAC_CONFIG
);
5431 val
&= ~XMAC_CONFIG_10G_XPCS_BYPASS
;
5432 nw64_mac(XMAC_CONFIG
, val
);
5436 val
= nr64_xpcs(XPCS_CONTROL1
);
5437 if (lp
->loopback_mode
== LOOPBACK_PHY
)
5438 val
|= XPCS_CONTROL1_LOOPBACK
;
5440 val
&= ~XPCS_CONTROL1_LOOPBACK
;
5441 nw64_xpcs(XPCS_CONTROL1
, val
);
5443 nw64_xpcs(XPCS_DESKEW_ERR_CNT
, 0);
5444 (void) nr64_xpcs(XPCS_SYMERR_CNT01
);
5445 (void) nr64_xpcs(XPCS_SYMERR_CNT23
);
5449 case NIU_FLAGS_XCVR_SERDES
:
5451 niu_pcs_mii_reset(np
);
5452 nw64_pcs(PCS_CONF
, PCS_CONF_MASK
| PCS_CONF_ENABLE
);
5453 nw64_pcs(PCS_DPATH_MODE
, 0);
5458 case NIU_FLAGS_XCVR_SERDES
| NIU_FLAGS_FIBER
:
5459 /* 1G RGMII FIBER */
5460 nw64_pcs(PCS_DPATH_MODE
, PCS_DPATH_MODE_MII
);
5461 niu_pcs_mii_reset(np
);
5471 static int niu_reset_tx_xmac(struct niu
*np
)
5473 return niu_set_and_wait_clear_mac(np
, XTXMAC_SW_RST
,
5474 (XTXMAC_SW_RST_REG_RS
|
5475 XTXMAC_SW_RST_SOFT_RST
),
5476 1000, 100, "XTXMAC_SW_RST");
5479 static int niu_reset_tx_bmac(struct niu
*np
)
5483 nw64_mac(BTXMAC_SW_RST
, BTXMAC_SW_RST_RESET
);
5485 while (--limit
>= 0) {
5486 if (!(nr64_mac(BTXMAC_SW_RST
) & BTXMAC_SW_RST_RESET
))
5491 dev_err(np
->device
, "Port %u TX BMAC would not reset, BTXMAC_SW_RST[%llx]\n",
5493 (unsigned long long) nr64_mac(BTXMAC_SW_RST
));
5500 static int niu_reset_tx_mac(struct niu
*np
)
5502 if (np
->flags
& NIU_FLAGS_XMAC
)
5503 return niu_reset_tx_xmac(np
);
5505 return niu_reset_tx_bmac(np
);
5508 static void niu_init_tx_xmac(struct niu
*np
, u64 min
, u64 max
)
5512 val
= nr64_mac(XMAC_MIN
);
5513 val
&= ~(XMAC_MIN_TX_MIN_PKT_SIZE
|
5514 XMAC_MIN_RX_MIN_PKT_SIZE
);
5515 val
|= (min
<< XMAC_MIN_RX_MIN_PKT_SIZE_SHFT
);
5516 val
|= (min
<< XMAC_MIN_TX_MIN_PKT_SIZE_SHFT
);
5517 nw64_mac(XMAC_MIN
, val
);
5519 nw64_mac(XMAC_MAX
, max
);
5521 nw64_mac(XTXMAC_STAT_MSK
, ~(u64
)0);
5523 val
= nr64_mac(XMAC_IPG
);
5524 if (np
->flags
& NIU_FLAGS_10G
) {
5525 val
&= ~XMAC_IPG_IPG_XGMII
;
5526 val
|= (IPG_12_15_XGMII
<< XMAC_IPG_IPG_XGMII_SHIFT
);
5528 val
&= ~XMAC_IPG_IPG_MII_GMII
;
5529 val
|= (IPG_12_MII_GMII
<< XMAC_IPG_IPG_MII_GMII_SHIFT
);
5531 nw64_mac(XMAC_IPG
, val
);
5533 val
= nr64_mac(XMAC_CONFIG
);
5534 val
&= ~(XMAC_CONFIG_ALWAYS_NO_CRC
|
5535 XMAC_CONFIG_STRETCH_MODE
|
5536 XMAC_CONFIG_VAR_MIN_IPG_EN
|
5537 XMAC_CONFIG_TX_ENABLE
);
5538 nw64_mac(XMAC_CONFIG
, val
);
5540 nw64_mac(TXMAC_FRM_CNT
, 0);
5541 nw64_mac(TXMAC_BYTE_CNT
, 0);
5544 static void niu_init_tx_bmac(struct niu
*np
, u64 min
, u64 max
)
5548 nw64_mac(BMAC_MIN_FRAME
, min
);
5549 nw64_mac(BMAC_MAX_FRAME
, max
);
5551 nw64_mac(BTXMAC_STATUS_MASK
, ~(u64
)0);
5552 nw64_mac(BMAC_CTRL_TYPE
, 0x8808);
5553 nw64_mac(BMAC_PREAMBLE_SIZE
, 7);
5555 val
= nr64_mac(BTXMAC_CONFIG
);
5556 val
&= ~(BTXMAC_CONFIG_FCS_DISABLE
|
5557 BTXMAC_CONFIG_ENABLE
);
5558 nw64_mac(BTXMAC_CONFIG
, val
);
5561 static void niu_init_tx_mac(struct niu
*np
)
5566 if (np
->dev
->mtu
> ETH_DATA_LEN
)
5571 /* The XMAC_MIN register only accepts values for TX min which
5572 * have the low 3 bits cleared.
5576 if (np
->flags
& NIU_FLAGS_XMAC
)
5577 niu_init_tx_xmac(np
, min
, max
);
5579 niu_init_tx_bmac(np
, min
, max
);
5582 static int niu_reset_rx_xmac(struct niu
*np
)
5586 nw64_mac(XRXMAC_SW_RST
,
5587 XRXMAC_SW_RST_REG_RS
| XRXMAC_SW_RST_SOFT_RST
);
5589 while (--limit
>= 0) {
5590 if (!(nr64_mac(XRXMAC_SW_RST
) & (XRXMAC_SW_RST_REG_RS
|
5591 XRXMAC_SW_RST_SOFT_RST
)))
5596 dev_err(np
->device
, "Port %u RX XMAC would not reset, XRXMAC_SW_RST[%llx]\n",
5598 (unsigned long long) nr64_mac(XRXMAC_SW_RST
));
5605 static int niu_reset_rx_bmac(struct niu
*np
)
5609 nw64_mac(BRXMAC_SW_RST
, BRXMAC_SW_RST_RESET
);
5611 while (--limit
>= 0) {
5612 if (!(nr64_mac(BRXMAC_SW_RST
) & BRXMAC_SW_RST_RESET
))
5617 dev_err(np
->device
, "Port %u RX BMAC would not reset, BRXMAC_SW_RST[%llx]\n",
5619 (unsigned long long) nr64_mac(BRXMAC_SW_RST
));
5626 static int niu_reset_rx_mac(struct niu
*np
)
5628 if (np
->flags
& NIU_FLAGS_XMAC
)
5629 return niu_reset_rx_xmac(np
);
5631 return niu_reset_rx_bmac(np
);
5634 static void niu_init_rx_xmac(struct niu
*np
)
5636 struct niu_parent
*parent
= np
->parent
;
5637 struct niu_rdc_tables
*tp
= &parent
->rdc_group_cfg
[np
->port
];
5638 int first_rdc_table
= tp
->first_table_num
;
5642 nw64_mac(XMAC_ADD_FILT0
, 0);
5643 nw64_mac(XMAC_ADD_FILT1
, 0);
5644 nw64_mac(XMAC_ADD_FILT2
, 0);
5645 nw64_mac(XMAC_ADD_FILT12_MASK
, 0);
5646 nw64_mac(XMAC_ADD_FILT00_MASK
, 0);
5647 for (i
= 0; i
< MAC_NUM_HASH
; i
++)
5648 nw64_mac(XMAC_HASH_TBL(i
), 0);
5649 nw64_mac(XRXMAC_STAT_MSK
, ~(u64
)0);
5650 niu_set_primary_mac_rdc_table(np
, first_rdc_table
, 1);
5651 niu_set_multicast_mac_rdc_table(np
, first_rdc_table
, 1);
5653 val
= nr64_mac(XMAC_CONFIG
);
5654 val
&= ~(XMAC_CONFIG_RX_MAC_ENABLE
|
5655 XMAC_CONFIG_PROMISCUOUS
|
5656 XMAC_CONFIG_PROMISC_GROUP
|
5657 XMAC_CONFIG_ERR_CHK_DIS
|
5658 XMAC_CONFIG_RX_CRC_CHK_DIS
|
5659 XMAC_CONFIG_RESERVED_MULTICAST
|
5660 XMAC_CONFIG_RX_CODEV_CHK_DIS
|
5661 XMAC_CONFIG_ADDR_FILTER_EN
|
5662 XMAC_CONFIG_RCV_PAUSE_ENABLE
|
5663 XMAC_CONFIG_STRIP_CRC
|
5664 XMAC_CONFIG_PASS_FLOW_CTRL
|
5665 XMAC_CONFIG_MAC2IPP_PKT_CNT_EN
);
5666 val
|= (XMAC_CONFIG_HASH_FILTER_EN
);
5667 nw64_mac(XMAC_CONFIG
, val
);
5669 nw64_mac(RXMAC_BT_CNT
, 0);
5670 nw64_mac(RXMAC_BC_FRM_CNT
, 0);
5671 nw64_mac(RXMAC_MC_FRM_CNT
, 0);
5672 nw64_mac(RXMAC_FRAG_CNT
, 0);
5673 nw64_mac(RXMAC_HIST_CNT1
, 0);
5674 nw64_mac(RXMAC_HIST_CNT2
, 0);
5675 nw64_mac(RXMAC_HIST_CNT3
, 0);
5676 nw64_mac(RXMAC_HIST_CNT4
, 0);
5677 nw64_mac(RXMAC_HIST_CNT5
, 0);
5678 nw64_mac(RXMAC_HIST_CNT6
, 0);
5679 nw64_mac(RXMAC_HIST_CNT7
, 0);
5680 nw64_mac(RXMAC_MPSZER_CNT
, 0);
5681 nw64_mac(RXMAC_CRC_ER_CNT
, 0);
5682 nw64_mac(RXMAC_CD_VIO_CNT
, 0);
5683 nw64_mac(LINK_FAULT_CNT
, 0);
5686 static void niu_init_rx_bmac(struct niu
*np
)
5688 struct niu_parent
*parent
= np
->parent
;
5689 struct niu_rdc_tables
*tp
= &parent
->rdc_group_cfg
[np
->port
];
5690 int first_rdc_table
= tp
->first_table_num
;
5694 nw64_mac(BMAC_ADD_FILT0
, 0);
5695 nw64_mac(BMAC_ADD_FILT1
, 0);
5696 nw64_mac(BMAC_ADD_FILT2
, 0);
5697 nw64_mac(BMAC_ADD_FILT12_MASK
, 0);
5698 nw64_mac(BMAC_ADD_FILT00_MASK
, 0);
5699 for (i
= 0; i
< MAC_NUM_HASH
; i
++)
5700 nw64_mac(BMAC_HASH_TBL(i
), 0);
5701 niu_set_primary_mac_rdc_table(np
, first_rdc_table
, 1);
5702 niu_set_multicast_mac_rdc_table(np
, first_rdc_table
, 1);
5703 nw64_mac(BRXMAC_STATUS_MASK
, ~(u64
)0);
5705 val
= nr64_mac(BRXMAC_CONFIG
);
5706 val
&= ~(BRXMAC_CONFIG_ENABLE
|
5707 BRXMAC_CONFIG_STRIP_PAD
|
5708 BRXMAC_CONFIG_STRIP_FCS
|
5709 BRXMAC_CONFIG_PROMISC
|
5710 BRXMAC_CONFIG_PROMISC_GRP
|
5711 BRXMAC_CONFIG_ADDR_FILT_EN
|
5712 BRXMAC_CONFIG_DISCARD_DIS
);
5713 val
|= (BRXMAC_CONFIG_HASH_FILT_EN
);
5714 nw64_mac(BRXMAC_CONFIG
, val
);
5716 val
= nr64_mac(BMAC_ADDR_CMPEN
);
5717 val
|= BMAC_ADDR_CMPEN_EN0
;
5718 nw64_mac(BMAC_ADDR_CMPEN
, val
);
5721 static void niu_init_rx_mac(struct niu
*np
)
5723 niu_set_primary_mac(np
, np
->dev
->dev_addr
);
5725 if (np
->flags
& NIU_FLAGS_XMAC
)
5726 niu_init_rx_xmac(np
);
5728 niu_init_rx_bmac(np
);
5731 static void niu_enable_tx_xmac(struct niu
*np
, int on
)
5733 u64 val
= nr64_mac(XMAC_CONFIG
);
5736 val
|= XMAC_CONFIG_TX_ENABLE
;
5738 val
&= ~XMAC_CONFIG_TX_ENABLE
;
5739 nw64_mac(XMAC_CONFIG
, val
);
5742 static void niu_enable_tx_bmac(struct niu
*np
, int on
)
5744 u64 val
= nr64_mac(BTXMAC_CONFIG
);
5747 val
|= BTXMAC_CONFIG_ENABLE
;
5749 val
&= ~BTXMAC_CONFIG_ENABLE
;
5750 nw64_mac(BTXMAC_CONFIG
, val
);
5753 static void niu_enable_tx_mac(struct niu
*np
, int on
)
5755 if (np
->flags
& NIU_FLAGS_XMAC
)
5756 niu_enable_tx_xmac(np
, on
);
5758 niu_enable_tx_bmac(np
, on
);
5761 static void niu_enable_rx_xmac(struct niu
*np
, int on
)
5763 u64 val
= nr64_mac(XMAC_CONFIG
);
5765 val
&= ~(XMAC_CONFIG_HASH_FILTER_EN
|
5766 XMAC_CONFIG_PROMISCUOUS
);
5768 if (np
->flags
& NIU_FLAGS_MCAST
)
5769 val
|= XMAC_CONFIG_HASH_FILTER_EN
;
5770 if (np
->flags
& NIU_FLAGS_PROMISC
)
5771 val
|= XMAC_CONFIG_PROMISCUOUS
;
5774 val
|= XMAC_CONFIG_RX_MAC_ENABLE
;
5776 val
&= ~XMAC_CONFIG_RX_MAC_ENABLE
;
5777 nw64_mac(XMAC_CONFIG
, val
);
5780 static void niu_enable_rx_bmac(struct niu
*np
, int on
)
5782 u64 val
= nr64_mac(BRXMAC_CONFIG
);
5784 val
&= ~(BRXMAC_CONFIG_HASH_FILT_EN
|
5785 BRXMAC_CONFIG_PROMISC
);
5787 if (np
->flags
& NIU_FLAGS_MCAST
)
5788 val
|= BRXMAC_CONFIG_HASH_FILT_EN
;
5789 if (np
->flags
& NIU_FLAGS_PROMISC
)
5790 val
|= BRXMAC_CONFIG_PROMISC
;
5793 val
|= BRXMAC_CONFIG_ENABLE
;
5795 val
&= ~BRXMAC_CONFIG_ENABLE
;
5796 nw64_mac(BRXMAC_CONFIG
, val
);
5799 static void niu_enable_rx_mac(struct niu
*np
, int on
)
5801 if (np
->flags
& NIU_FLAGS_XMAC
)
5802 niu_enable_rx_xmac(np
, on
);
5804 niu_enable_rx_bmac(np
, on
);
5807 static int niu_init_mac(struct niu
*np
)
5812 err
= niu_init_pcs(np
);
5816 err
= niu_reset_tx_mac(np
);
5819 niu_init_tx_mac(np
);
5820 err
= niu_reset_rx_mac(np
);
5823 niu_init_rx_mac(np
);
5825 /* This looks hookey but the RX MAC reset we just did will
5826 * undo some of the state we setup in niu_init_tx_mac() so we
5827 * have to call it again. In particular, the RX MAC reset will
5828 * set the XMAC_MAX register back to it's default value.
5830 niu_init_tx_mac(np
);
5831 niu_enable_tx_mac(np
, 1);
5833 niu_enable_rx_mac(np
, 1);
5838 static void niu_stop_one_tx_channel(struct niu
*np
, struct tx_ring_info
*rp
)
5840 (void) niu_tx_channel_stop(np
, rp
->tx_channel
);
5843 static void niu_stop_tx_channels(struct niu
*np
)
5847 for (i
= 0; i
< np
->num_tx_rings
; i
++) {
5848 struct tx_ring_info
*rp
= &np
->tx_rings
[i
];
5850 niu_stop_one_tx_channel(np
, rp
);
5854 static void niu_reset_one_tx_channel(struct niu
*np
, struct tx_ring_info
*rp
)
5856 (void) niu_tx_channel_reset(np
, rp
->tx_channel
);
5859 static void niu_reset_tx_channels(struct niu
*np
)
5863 for (i
= 0; i
< np
->num_tx_rings
; i
++) {
5864 struct tx_ring_info
*rp
= &np
->tx_rings
[i
];
5866 niu_reset_one_tx_channel(np
, rp
);
5870 static void niu_stop_one_rx_channel(struct niu
*np
, struct rx_ring_info
*rp
)
5872 (void) niu_enable_rx_channel(np
, rp
->rx_channel
, 0);
5875 static void niu_stop_rx_channels(struct niu
*np
)
5879 for (i
= 0; i
< np
->num_rx_rings
; i
++) {
5880 struct rx_ring_info
*rp
= &np
->rx_rings
[i
];
5882 niu_stop_one_rx_channel(np
, rp
);
5886 static void niu_reset_one_rx_channel(struct niu
*np
, struct rx_ring_info
*rp
)
5888 int channel
= rp
->rx_channel
;
5890 (void) niu_rx_channel_reset(np
, channel
);
5891 nw64(RX_DMA_ENT_MSK(channel
), RX_DMA_ENT_MSK_ALL
);
5892 nw64(RX_DMA_CTL_STAT(channel
), 0);
5893 (void) niu_enable_rx_channel(np
, channel
, 0);
5896 static void niu_reset_rx_channels(struct niu
*np
)
5900 for (i
= 0; i
< np
->num_rx_rings
; i
++) {
5901 struct rx_ring_info
*rp
= &np
->rx_rings
[i
];
5903 niu_reset_one_rx_channel(np
, rp
);
5907 static void niu_disable_ipp(struct niu
*np
)
5912 rd
= nr64_ipp(IPP_DFIFO_RD_PTR
);
5913 wr
= nr64_ipp(IPP_DFIFO_WR_PTR
);
5915 while (--limit
>= 0 && (rd
!= wr
)) {
5916 rd
= nr64_ipp(IPP_DFIFO_RD_PTR
);
5917 wr
= nr64_ipp(IPP_DFIFO_WR_PTR
);
5920 (rd
!= 0 && wr
!= 1)) {
5921 netdev_err(np
->dev
, "IPP would not quiesce, rd_ptr[%llx] wr_ptr[%llx]\n",
5922 (unsigned long long)nr64_ipp(IPP_DFIFO_RD_PTR
),
5923 (unsigned long long)nr64_ipp(IPP_DFIFO_WR_PTR
));
5926 val
= nr64_ipp(IPP_CFIG
);
5927 val
&= ~(IPP_CFIG_IPP_ENABLE
|
5928 IPP_CFIG_DFIFO_ECC_EN
|
5929 IPP_CFIG_DROP_BAD_CRC
|
5931 nw64_ipp(IPP_CFIG
, val
);
5933 (void) niu_ipp_reset(np
);
5936 static int niu_init_hw(struct niu
*np
)
5940 netif_printk(np
, ifup
, KERN_DEBUG
, np
->dev
, "Initialize TXC\n");
5941 niu_txc_enable_port(np
, 1);
5942 niu_txc_port_dma_enable(np
, 1);
5943 niu_txc_set_imask(np
, 0);
5945 netif_printk(np
, ifup
, KERN_DEBUG
, np
->dev
, "Initialize TX channels\n");
5946 for (i
= 0; i
< np
->num_tx_rings
; i
++) {
5947 struct tx_ring_info
*rp
= &np
->tx_rings
[i
];
5949 err
= niu_init_one_tx_channel(np
, rp
);
5954 netif_printk(np
, ifup
, KERN_DEBUG
, np
->dev
, "Initialize RX channels\n");
5955 err
= niu_init_rx_channels(np
);
5957 goto out_uninit_tx_channels
;
5959 netif_printk(np
, ifup
, KERN_DEBUG
, np
->dev
, "Initialize classifier\n");
5960 err
= niu_init_classifier_hw(np
);
5962 goto out_uninit_rx_channels
;
5964 netif_printk(np
, ifup
, KERN_DEBUG
, np
->dev
, "Initialize ZCP\n");
5965 err
= niu_init_zcp(np
);
5967 goto out_uninit_rx_channels
;
5969 netif_printk(np
, ifup
, KERN_DEBUG
, np
->dev
, "Initialize IPP\n");
5970 err
= niu_init_ipp(np
);
5972 goto out_uninit_rx_channels
;
5974 netif_printk(np
, ifup
, KERN_DEBUG
, np
->dev
, "Initialize MAC\n");
5975 err
= niu_init_mac(np
);
5977 goto out_uninit_ipp
;
5982 netif_printk(np
, ifup
, KERN_DEBUG
, np
->dev
, "Uninit IPP\n");
5983 niu_disable_ipp(np
);
5985 out_uninit_rx_channels
:
5986 netif_printk(np
, ifup
, KERN_DEBUG
, np
->dev
, "Uninit RX channels\n");
5987 niu_stop_rx_channels(np
);
5988 niu_reset_rx_channels(np
);
5990 out_uninit_tx_channels
:
5991 netif_printk(np
, ifup
, KERN_DEBUG
, np
->dev
, "Uninit TX channels\n");
5992 niu_stop_tx_channels(np
);
5993 niu_reset_tx_channels(np
);
5998 static void niu_stop_hw(struct niu
*np
)
6000 netif_printk(np
, ifdown
, KERN_DEBUG
, np
->dev
, "Disable interrupts\n");
6001 niu_enable_interrupts(np
, 0);
6003 netif_printk(np
, ifdown
, KERN_DEBUG
, np
->dev
, "Disable RX MAC\n");
6004 niu_enable_rx_mac(np
, 0);
6006 netif_printk(np
, ifdown
, KERN_DEBUG
, np
->dev
, "Disable IPP\n");
6007 niu_disable_ipp(np
);
6009 netif_printk(np
, ifdown
, KERN_DEBUG
, np
->dev
, "Stop TX channels\n");
6010 niu_stop_tx_channels(np
);
6012 netif_printk(np
, ifdown
, KERN_DEBUG
, np
->dev
, "Stop RX channels\n");
6013 niu_stop_rx_channels(np
);
6015 netif_printk(np
, ifdown
, KERN_DEBUG
, np
->dev
, "Reset TX channels\n");
6016 niu_reset_tx_channels(np
);
6018 netif_printk(np
, ifdown
, KERN_DEBUG
, np
->dev
, "Reset RX channels\n");
6019 niu_reset_rx_channels(np
);
6022 static void niu_set_irq_name(struct niu
*np
)
6024 int port
= np
->port
;
6027 sprintf(np
->irq_name
[0], "%s:MAC", np
->dev
->name
);
6030 sprintf(np
->irq_name
[1], "%s:MIF", np
->dev
->name
);
6031 sprintf(np
->irq_name
[2], "%s:SYSERR", np
->dev
->name
);
6035 for (i
= 0; i
< np
->num_ldg
- j
; i
++) {
6036 if (i
< np
->num_rx_rings
)
6037 sprintf(np
->irq_name
[i
+j
], "%s-rx-%d",
6039 else if (i
< np
->num_tx_rings
+ np
->num_rx_rings
)
6040 sprintf(np
->irq_name
[i
+j
], "%s-tx-%d", np
->dev
->name
,
6041 i
- np
->num_rx_rings
);
6045 static int niu_request_irq(struct niu
*np
)
6049 niu_set_irq_name(np
);
6052 for (i
= 0; i
< np
->num_ldg
; i
++) {
6053 struct niu_ldg
*lp
= &np
->ldg
[i
];
6055 err
= request_irq(lp
->irq
, niu_interrupt
, IRQF_SHARED
,
6056 np
->irq_name
[i
], lp
);
6065 for (j
= 0; j
< i
; j
++) {
6066 struct niu_ldg
*lp
= &np
->ldg
[j
];
6068 free_irq(lp
->irq
, lp
);
6073 static void niu_free_irq(struct niu
*np
)
6077 for (i
= 0; i
< np
->num_ldg
; i
++) {
6078 struct niu_ldg
*lp
= &np
->ldg
[i
];
6080 free_irq(lp
->irq
, lp
);
6084 static void niu_enable_napi(struct niu
*np
)
6088 for (i
= 0; i
< np
->num_ldg
; i
++)
6089 napi_enable(&np
->ldg
[i
].napi
);
6092 static void niu_disable_napi(struct niu
*np
)
6096 for (i
= 0; i
< np
->num_ldg
; i
++)
6097 napi_disable(&np
->ldg
[i
].napi
);
6100 static int niu_open(struct net_device
*dev
)
6102 struct niu
*np
= netdev_priv(dev
);
6105 netif_carrier_off(dev
);
6107 err
= niu_alloc_channels(np
);
6111 err
= niu_enable_interrupts(np
, 0);
6113 goto out_free_channels
;
6115 err
= niu_request_irq(np
);
6117 goto out_free_channels
;
6119 niu_enable_napi(np
);
6121 spin_lock_irq(&np
->lock
);
6123 err
= niu_init_hw(np
);
6125 timer_setup(&np
->timer
, niu_timer
, 0);
6126 np
->timer
.expires
= jiffies
+ HZ
;
6128 err
= niu_enable_interrupts(np
, 1);
6133 spin_unlock_irq(&np
->lock
);
6136 niu_disable_napi(np
);
6140 netif_tx_start_all_queues(dev
);
6142 if (np
->link_config
.loopback_mode
!= LOOPBACK_DISABLED
)
6143 netif_carrier_on(dev
);
6145 add_timer(&np
->timer
);
6153 niu_free_channels(np
);
6159 static void niu_full_shutdown(struct niu
*np
, struct net_device
*dev
)
6161 cancel_work_sync(&np
->reset_task
);
6163 niu_disable_napi(np
);
6164 netif_tx_stop_all_queues(dev
);
6166 del_timer_sync(&np
->timer
);
6168 spin_lock_irq(&np
->lock
);
6172 spin_unlock_irq(&np
->lock
);
6175 static int niu_close(struct net_device
*dev
)
6177 struct niu
*np
= netdev_priv(dev
);
6179 niu_full_shutdown(np
, dev
);
6183 niu_free_channels(np
);
6185 niu_handle_led(np
, 0);
6190 static void niu_sync_xmac_stats(struct niu
*np
)
6192 struct niu_xmac_stats
*mp
= &np
->mac_stats
.xmac
;
6194 mp
->tx_frames
+= nr64_mac(TXMAC_FRM_CNT
);
6195 mp
->tx_bytes
+= nr64_mac(TXMAC_BYTE_CNT
);
6197 mp
->rx_link_faults
+= nr64_mac(LINK_FAULT_CNT
);
6198 mp
->rx_align_errors
+= nr64_mac(RXMAC_ALIGN_ERR_CNT
);
6199 mp
->rx_frags
+= nr64_mac(RXMAC_FRAG_CNT
);
6200 mp
->rx_mcasts
+= nr64_mac(RXMAC_MC_FRM_CNT
);
6201 mp
->rx_bcasts
+= nr64_mac(RXMAC_BC_FRM_CNT
);
6202 mp
->rx_hist_cnt1
+= nr64_mac(RXMAC_HIST_CNT1
);
6203 mp
->rx_hist_cnt2
+= nr64_mac(RXMAC_HIST_CNT2
);
6204 mp
->rx_hist_cnt3
+= nr64_mac(RXMAC_HIST_CNT3
);
6205 mp
->rx_hist_cnt4
+= nr64_mac(RXMAC_HIST_CNT4
);
6206 mp
->rx_hist_cnt5
+= nr64_mac(RXMAC_HIST_CNT5
);
6207 mp
->rx_hist_cnt6
+= nr64_mac(RXMAC_HIST_CNT6
);
6208 mp
->rx_hist_cnt7
+= nr64_mac(RXMAC_HIST_CNT7
);
6209 mp
->rx_octets
+= nr64_mac(RXMAC_BT_CNT
);
6210 mp
->rx_code_violations
+= nr64_mac(RXMAC_CD_VIO_CNT
);
6211 mp
->rx_len_errors
+= nr64_mac(RXMAC_MPSZER_CNT
);
6212 mp
->rx_crc_errors
+= nr64_mac(RXMAC_CRC_ER_CNT
);
6215 static void niu_sync_bmac_stats(struct niu
*np
)
6217 struct niu_bmac_stats
*mp
= &np
->mac_stats
.bmac
;
6219 mp
->tx_bytes
+= nr64_mac(BTXMAC_BYTE_CNT
);
6220 mp
->tx_frames
+= nr64_mac(BTXMAC_FRM_CNT
);
6222 mp
->rx_frames
+= nr64_mac(BRXMAC_FRAME_CNT
);
6223 mp
->rx_align_errors
+= nr64_mac(BRXMAC_ALIGN_ERR_CNT
);
6224 mp
->rx_crc_errors
+= nr64_mac(BRXMAC_ALIGN_ERR_CNT
);
6225 mp
->rx_len_errors
+= nr64_mac(BRXMAC_CODE_VIOL_ERR_CNT
);
6228 static void niu_sync_mac_stats(struct niu
*np
)
6230 if (np
->flags
& NIU_FLAGS_XMAC
)
6231 niu_sync_xmac_stats(np
);
6233 niu_sync_bmac_stats(np
);
6236 static void niu_get_rx_stats(struct niu
*np
,
6237 struct rtnl_link_stats64
*stats
)
6239 u64 pkts
, dropped
, errors
, bytes
;
6240 struct rx_ring_info
*rx_rings
;
6243 pkts
= dropped
= errors
= bytes
= 0;
6245 rx_rings
= READ_ONCE(np
->rx_rings
);
6249 for (i
= 0; i
< np
->num_rx_rings
; i
++) {
6250 struct rx_ring_info
*rp
= &rx_rings
[i
];
6252 niu_sync_rx_discard_stats(np
, rp
, 0);
6254 pkts
+= rp
->rx_packets
;
6255 bytes
+= rp
->rx_bytes
;
6256 dropped
+= rp
->rx_dropped
;
6257 errors
+= rp
->rx_errors
;
6261 stats
->rx_packets
= pkts
;
6262 stats
->rx_bytes
= bytes
;
6263 stats
->rx_dropped
= dropped
;
6264 stats
->rx_errors
= errors
;
6267 static void niu_get_tx_stats(struct niu
*np
,
6268 struct rtnl_link_stats64
*stats
)
6270 u64 pkts
, errors
, bytes
;
6271 struct tx_ring_info
*tx_rings
;
6274 pkts
= errors
= bytes
= 0;
6276 tx_rings
= READ_ONCE(np
->tx_rings
);
6280 for (i
= 0; i
< np
->num_tx_rings
; i
++) {
6281 struct tx_ring_info
*rp
= &tx_rings
[i
];
6283 pkts
+= rp
->tx_packets
;
6284 bytes
+= rp
->tx_bytes
;
6285 errors
+= rp
->tx_errors
;
6289 stats
->tx_packets
= pkts
;
6290 stats
->tx_bytes
= bytes
;
6291 stats
->tx_errors
= errors
;
6294 static void niu_get_stats(struct net_device
*dev
,
6295 struct rtnl_link_stats64
*stats
)
6297 struct niu
*np
= netdev_priv(dev
);
6299 if (netif_running(dev
)) {
6300 niu_get_rx_stats(np
, stats
);
6301 niu_get_tx_stats(np
, stats
);
6305 static void niu_load_hash_xmac(struct niu
*np
, u16
*hash
)
6309 for (i
= 0; i
< 16; i
++)
6310 nw64_mac(XMAC_HASH_TBL(i
), hash
[i
]);
6313 static void niu_load_hash_bmac(struct niu
*np
, u16
*hash
)
6317 for (i
= 0; i
< 16; i
++)
6318 nw64_mac(BMAC_HASH_TBL(i
), hash
[i
]);
6321 static void niu_load_hash(struct niu
*np
, u16
*hash
)
6323 if (np
->flags
& NIU_FLAGS_XMAC
)
6324 niu_load_hash_xmac(np
, hash
);
6326 niu_load_hash_bmac(np
, hash
);
6329 static void niu_set_rx_mode(struct net_device
*dev
)
6331 struct niu
*np
= netdev_priv(dev
);
6332 int i
, alt_cnt
, err
;
6333 struct netdev_hw_addr
*ha
;
6334 unsigned long flags
;
6335 u16 hash
[16] = { 0, };
6337 spin_lock_irqsave(&np
->lock
, flags
);
6338 niu_enable_rx_mac(np
, 0);
6340 np
->flags
&= ~(NIU_FLAGS_MCAST
| NIU_FLAGS_PROMISC
);
6341 if (dev
->flags
& IFF_PROMISC
)
6342 np
->flags
|= NIU_FLAGS_PROMISC
;
6343 if ((dev
->flags
& IFF_ALLMULTI
) || (!netdev_mc_empty(dev
)))
6344 np
->flags
|= NIU_FLAGS_MCAST
;
6346 alt_cnt
= netdev_uc_count(dev
);
6347 if (alt_cnt
> niu_num_alt_addr(np
)) {
6349 np
->flags
|= NIU_FLAGS_PROMISC
;
6355 netdev_for_each_uc_addr(ha
, dev
) {
6356 err
= niu_set_alt_mac(np
, index
, ha
->addr
);
6358 netdev_warn(dev
, "Error %d adding alt mac %d\n",
6360 err
= niu_enable_alt_mac(np
, index
, 1);
6362 netdev_warn(dev
, "Error %d enabling alt mac %d\n",
6369 if (np
->flags
& NIU_FLAGS_XMAC
)
6373 for (i
= alt_start
; i
< niu_num_alt_addr(np
); i
++) {
6374 err
= niu_enable_alt_mac(np
, i
, 0);
6376 netdev_warn(dev
, "Error %d disabling alt mac %d\n",
6380 if (dev
->flags
& IFF_ALLMULTI
) {
6381 for (i
= 0; i
< 16; i
++)
6383 } else if (!netdev_mc_empty(dev
)) {
6384 netdev_for_each_mc_addr(ha
, dev
) {
6385 u32 crc
= ether_crc_le(ETH_ALEN
, ha
->addr
);
6388 hash
[crc
>> 4] |= (1 << (15 - (crc
& 0xf)));
6392 if (np
->flags
& NIU_FLAGS_MCAST
)
6393 niu_load_hash(np
, hash
);
6395 niu_enable_rx_mac(np
, 1);
6396 spin_unlock_irqrestore(&np
->lock
, flags
);
6399 static int niu_set_mac_addr(struct net_device
*dev
, void *p
)
6401 struct niu
*np
= netdev_priv(dev
);
6402 struct sockaddr
*addr
= p
;
6403 unsigned long flags
;
6405 if (!is_valid_ether_addr(addr
->sa_data
))
6406 return -EADDRNOTAVAIL
;
6408 eth_hw_addr_set(dev
, addr
->sa_data
);
6410 if (!netif_running(dev
))
6413 spin_lock_irqsave(&np
->lock
, flags
);
6414 niu_enable_rx_mac(np
, 0);
6415 niu_set_primary_mac(np
, dev
->dev_addr
);
6416 niu_enable_rx_mac(np
, 1);
6417 spin_unlock_irqrestore(&np
->lock
, flags
);
6422 static int niu_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
6427 static void niu_netif_stop(struct niu
*np
)
6429 netif_trans_update(np
->dev
); /* prevent tx timeout */
6431 niu_disable_napi(np
);
6433 netif_tx_disable(np
->dev
);
6436 static void niu_netif_start(struct niu
*np
)
6438 /* NOTE: unconditional netif_wake_queue is only appropriate
6439 * so long as all callers are assured to have free tx slots
6440 * (such as after niu_init_hw).
6442 netif_tx_wake_all_queues(np
->dev
);
6444 niu_enable_napi(np
);
6446 niu_enable_interrupts(np
, 1);
6449 static void niu_reset_buffers(struct niu
*np
)
6454 for (i
= 0; i
< np
->num_rx_rings
; i
++) {
6455 struct rx_ring_info
*rp
= &np
->rx_rings
[i
];
6457 for (j
= 0, k
= 0; j
< MAX_RBR_RING_SIZE
; j
++) {
6460 page
= rp
->rxhash
[j
];
6462 struct page
*next
= niu_next_page(page
);
6463 u64 base
= page
->index
;
6464 base
= base
>> RBR_DESCR_ADDR_SHIFT
;
6465 rp
->rbr
[k
++] = cpu_to_le32(base
);
6469 for (; k
< MAX_RBR_RING_SIZE
; k
++) {
6470 err
= niu_rbr_add_page(np
, rp
, GFP_ATOMIC
, k
);
6475 rp
->rbr_index
= rp
->rbr_table_size
- 1;
6477 rp
->rbr_pending
= 0;
6478 rp
->rbr_refill_pending
= 0;
6482 for (i
= 0; i
< np
->num_tx_rings
; i
++) {
6483 struct tx_ring_info
*rp
= &np
->tx_rings
[i
];
6485 for (j
= 0; j
< MAX_TX_RING_SIZE
; j
++) {
6486 if (rp
->tx_buffs
[j
].skb
)
6487 (void) release_tx_packet(np
, rp
, j
);
6490 rp
->pending
= MAX_TX_RING_SIZE
;
6498 static void niu_reset_task(struct work_struct
*work
)
6500 struct niu
*np
= container_of(work
, struct niu
, reset_task
);
6501 unsigned long flags
;
6504 spin_lock_irqsave(&np
->lock
, flags
);
6505 if (!netif_running(np
->dev
)) {
6506 spin_unlock_irqrestore(&np
->lock
, flags
);
6510 spin_unlock_irqrestore(&np
->lock
, flags
);
6512 del_timer_sync(&np
->timer
);
6516 spin_lock_irqsave(&np
->lock
, flags
);
6520 spin_unlock_irqrestore(&np
->lock
, flags
);
6522 niu_reset_buffers(np
);
6524 spin_lock_irqsave(&np
->lock
, flags
);
6526 err
= niu_init_hw(np
);
6528 np
->timer
.expires
= jiffies
+ HZ
;
6529 add_timer(&np
->timer
);
6530 niu_netif_start(np
);
6533 spin_unlock_irqrestore(&np
->lock
, flags
);
6536 static void niu_tx_timeout(struct net_device
*dev
, unsigned int txqueue
)
6538 struct niu
*np
= netdev_priv(dev
);
6540 dev_err(np
->device
, "%s: Transmit timed out, resetting\n",
6543 schedule_work(&np
->reset_task
);
6546 static void niu_set_txd(struct tx_ring_info
*rp
, int index
,
6547 u64 mapping
, u64 len
, u64 mark
,
6550 __le64
*desc
= &rp
->descr
[index
];
6552 *desc
= cpu_to_le64(mark
|
6553 (n_frags
<< TX_DESC_NUM_PTR_SHIFT
) |
6554 (len
<< TX_DESC_TR_LEN_SHIFT
) |
6555 (mapping
& TX_DESC_SAD
));
6558 static u64
niu_compute_tx_flags(struct sk_buff
*skb
, struct ethhdr
*ehdr
,
6559 u64 pad_bytes
, u64 len
)
6561 u16 eth_proto
, eth_proto_inner
;
6562 u64 csum_bits
, l3off
, ihl
, ret
;
6566 eth_proto
= be16_to_cpu(ehdr
->h_proto
);
6567 eth_proto_inner
= eth_proto
;
6568 if (eth_proto
== ETH_P_8021Q
) {
6569 struct vlan_ethhdr
*vp
= (struct vlan_ethhdr
*) ehdr
;
6570 __be16 val
= vp
->h_vlan_encapsulated_proto
;
6572 eth_proto_inner
= be16_to_cpu(val
);
6576 switch (skb
->protocol
) {
6577 case cpu_to_be16(ETH_P_IP
):
6578 ip_proto
= ip_hdr(skb
)->protocol
;
6579 ihl
= ip_hdr(skb
)->ihl
;
6581 case cpu_to_be16(ETH_P_IPV6
):
6582 ip_proto
= ipv6_hdr(skb
)->nexthdr
;
6591 csum_bits
= TXHDR_CSUM_NONE
;
6592 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
6595 csum_bits
= (ip_proto
== IPPROTO_TCP
?
6597 (ip_proto
== IPPROTO_UDP
?
6598 TXHDR_CSUM_UDP
: TXHDR_CSUM_SCTP
));
6600 start
= skb_checksum_start_offset(skb
) -
6601 (pad_bytes
+ sizeof(struct tx_pkt_hdr
));
6602 stuff
= start
+ skb
->csum_offset
;
6604 csum_bits
|= (start
/ 2) << TXHDR_L4START_SHIFT
;
6605 csum_bits
|= (stuff
/ 2) << TXHDR_L4STUFF_SHIFT
;
6608 l3off
= skb_network_offset(skb
) -
6609 (pad_bytes
+ sizeof(struct tx_pkt_hdr
));
6611 ret
= (((pad_bytes
/ 2) << TXHDR_PAD_SHIFT
) |
6612 (len
<< TXHDR_LEN_SHIFT
) |
6613 ((l3off
/ 2) << TXHDR_L3START_SHIFT
) |
6614 (ihl
<< TXHDR_IHL_SHIFT
) |
6615 ((eth_proto_inner
< ETH_P_802_3_MIN
) ? TXHDR_LLC
: 0) |
6616 ((eth_proto
== ETH_P_8021Q
) ? TXHDR_VLAN
: 0) |
6617 (ipv6
? TXHDR_IP_VER
: 0) |
6623 static netdev_tx_t
niu_start_xmit(struct sk_buff
*skb
,
6624 struct net_device
*dev
)
6626 struct niu
*np
= netdev_priv(dev
);
6627 unsigned long align
, headroom
;
6628 struct netdev_queue
*txq
;
6629 struct tx_ring_info
*rp
;
6630 struct tx_pkt_hdr
*tp
;
6631 unsigned int len
, nfg
;
6632 struct ethhdr
*ehdr
;
6636 i
= skb_get_queue_mapping(skb
);
6637 rp
= &np
->tx_rings
[i
];
6638 txq
= netdev_get_tx_queue(dev
, i
);
6640 if (niu_tx_avail(rp
) <= (skb_shinfo(skb
)->nr_frags
+ 1)) {
6641 netif_tx_stop_queue(txq
);
6642 dev_err(np
->device
, "%s: BUG! Tx ring full when queue awake!\n", dev
->name
);
6644 return NETDEV_TX_BUSY
;
6647 if (eth_skb_pad(skb
))
6650 len
= sizeof(struct tx_pkt_hdr
) + 15;
6651 if (skb_headroom(skb
) < len
) {
6652 struct sk_buff
*skb_new
;
6654 skb_new
= skb_realloc_headroom(skb
, len
);
6662 align
= ((unsigned long) skb
->data
& (16 - 1));
6663 headroom
= align
+ sizeof(struct tx_pkt_hdr
);
6665 ehdr
= (struct ethhdr
*) skb
->data
;
6666 tp
= skb_push(skb
, headroom
);
6668 len
= skb
->len
- sizeof(struct tx_pkt_hdr
);
6669 tp
->flags
= cpu_to_le64(niu_compute_tx_flags(skb
, ehdr
, align
, len
));
6672 len
= skb_headlen(skb
);
6673 mapping
= np
->ops
->map_single(np
->device
, skb
->data
,
6674 len
, DMA_TO_DEVICE
);
6678 rp
->tx_buffs
[prod
].skb
= skb
;
6679 rp
->tx_buffs
[prod
].mapping
= mapping
;
6682 if (++rp
->mark_counter
== rp
->mark_freq
) {
6683 rp
->mark_counter
= 0;
6684 mrk
|= TX_DESC_MARK
;
6689 nfg
= skb_shinfo(skb
)->nr_frags
;
6691 tlen
-= MAX_TX_DESC_LEN
;
6696 unsigned int this_len
= len
;
6698 if (this_len
> MAX_TX_DESC_LEN
)
6699 this_len
= MAX_TX_DESC_LEN
;
6701 niu_set_txd(rp
, prod
, mapping
, this_len
, mrk
, nfg
);
6704 prod
= NEXT_TX(rp
, prod
);
6705 mapping
+= this_len
;
6709 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
6710 const skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
6712 len
= skb_frag_size(frag
);
6713 mapping
= np
->ops
->map_page(np
->device
, skb_frag_page(frag
),
6714 skb_frag_off(frag
), len
,
6717 rp
->tx_buffs
[prod
].skb
= NULL
;
6718 rp
->tx_buffs
[prod
].mapping
= mapping
;
6720 niu_set_txd(rp
, prod
, mapping
, len
, 0, 0);
6722 prod
= NEXT_TX(rp
, prod
);
6725 if (prod
< rp
->prod
)
6726 rp
->wrap_bit
^= TX_RING_KICK_WRAP
;
6729 nw64(TX_RING_KICK(rp
->tx_channel
), rp
->wrap_bit
| (prod
<< 3));
6731 if (unlikely(niu_tx_avail(rp
) <= (MAX_SKB_FRAGS
+ 1))) {
6732 netif_tx_stop_queue(txq
);
6733 if (niu_tx_avail(rp
) > NIU_TX_WAKEUP_THRESH(rp
))
6734 netif_tx_wake_queue(txq
);
6738 return NETDEV_TX_OK
;
6746 static int niu_change_mtu(struct net_device
*dev
, int new_mtu
)
6748 struct niu
*np
= netdev_priv(dev
);
6749 int err
, orig_jumbo
, new_jumbo
;
6751 orig_jumbo
= (dev
->mtu
> ETH_DATA_LEN
);
6752 new_jumbo
= (new_mtu
> ETH_DATA_LEN
);
6754 WRITE_ONCE(dev
->mtu
, new_mtu
);
6756 if (!netif_running(dev
) ||
6757 (orig_jumbo
== new_jumbo
))
6760 niu_full_shutdown(np
, dev
);
6762 niu_free_channels(np
);
6764 niu_enable_napi(np
);
6766 err
= niu_alloc_channels(np
);
6770 spin_lock_irq(&np
->lock
);
6772 err
= niu_init_hw(np
);
6774 timer_setup(&np
->timer
, niu_timer
, 0);
6775 np
->timer
.expires
= jiffies
+ HZ
;
6777 err
= niu_enable_interrupts(np
, 1);
6782 spin_unlock_irq(&np
->lock
);
6785 netif_tx_start_all_queues(dev
);
6786 if (np
->link_config
.loopback_mode
!= LOOPBACK_DISABLED
)
6787 netif_carrier_on(dev
);
6789 add_timer(&np
->timer
);
6795 static void niu_get_drvinfo(struct net_device
*dev
,
6796 struct ethtool_drvinfo
*info
)
6798 struct niu
*np
= netdev_priv(dev
);
6799 struct niu_vpd
*vpd
= &np
->vpd
;
6801 strscpy(info
->driver
, DRV_MODULE_NAME
, sizeof(info
->driver
));
6802 strscpy(info
->version
, DRV_MODULE_VERSION
, sizeof(info
->version
));
6803 snprintf(info
->fw_version
, sizeof(info
->fw_version
), "%d.%d",
6804 vpd
->fcode_major
, vpd
->fcode_minor
);
6805 if (np
->parent
->plat_type
!= PLAT_TYPE_NIU
)
6806 strscpy(info
->bus_info
, pci_name(np
->pdev
),
6807 sizeof(info
->bus_info
));
6810 static int niu_get_link_ksettings(struct net_device
*dev
,
6811 struct ethtool_link_ksettings
*cmd
)
6813 struct niu
*np
= netdev_priv(dev
);
6814 struct niu_link_config
*lp
;
6816 lp
= &np
->link_config
;
6818 memset(cmd
, 0, sizeof(*cmd
));
6819 cmd
->base
.phy_address
= np
->phy_addr
;
6820 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.supported
,
6822 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.advertising
,
6823 lp
->active_advertising
);
6824 cmd
->base
.autoneg
= lp
->active_autoneg
;
6825 cmd
->base
.speed
= lp
->active_speed
;
6826 cmd
->base
.duplex
= lp
->active_duplex
;
6827 cmd
->base
.port
= (np
->flags
& NIU_FLAGS_FIBER
) ? PORT_FIBRE
: PORT_TP
;
6832 static int niu_set_link_ksettings(struct net_device
*dev
,
6833 const struct ethtool_link_ksettings
*cmd
)
6835 struct niu
*np
= netdev_priv(dev
);
6836 struct niu_link_config
*lp
= &np
->link_config
;
6838 ethtool_convert_link_mode_to_legacy_u32(&lp
->advertising
,
6839 cmd
->link_modes
.advertising
);
6840 lp
->speed
= cmd
->base
.speed
;
6841 lp
->duplex
= cmd
->base
.duplex
;
6842 lp
->autoneg
= cmd
->base
.autoneg
;
6843 return niu_init_link(np
);
6846 static u32
niu_get_msglevel(struct net_device
*dev
)
6848 struct niu
*np
= netdev_priv(dev
);
6849 return np
->msg_enable
;
6852 static void niu_set_msglevel(struct net_device
*dev
, u32 value
)
6854 struct niu
*np
= netdev_priv(dev
);
6855 np
->msg_enable
= value
;
6858 static int niu_nway_reset(struct net_device
*dev
)
6860 struct niu
*np
= netdev_priv(dev
);
6862 if (np
->link_config
.autoneg
)
6863 return niu_init_link(np
);
6868 static int niu_get_eeprom_len(struct net_device
*dev
)
6870 struct niu
*np
= netdev_priv(dev
);
6872 return np
->eeprom_len
;
6875 static int niu_get_eeprom(struct net_device
*dev
,
6876 struct ethtool_eeprom
*eeprom
, u8
*data
)
6878 struct niu
*np
= netdev_priv(dev
);
6879 u32 offset
, len
, val
;
6881 offset
= eeprom
->offset
;
6884 if (offset
+ len
< offset
)
6886 if (offset
>= np
->eeprom_len
)
6888 if (offset
+ len
> np
->eeprom_len
)
6889 len
= eeprom
->len
= np
->eeprom_len
- offset
;
6892 u32 b_offset
, b_count
;
6894 b_offset
= offset
& 3;
6895 b_count
= 4 - b_offset
;
6899 val
= nr64(ESPC_NCR((offset
- b_offset
) / 4));
6900 memcpy(data
, ((char *)&val
) + b_offset
, b_count
);
6906 val
= nr64(ESPC_NCR(offset
/ 4));
6907 memcpy(data
, &val
, 4);
6913 val
= nr64(ESPC_NCR(offset
/ 4));
6914 memcpy(data
, &val
, len
);
6919 static void niu_ethflow_to_l3proto(int flow_type
, u8
*pid
)
6921 switch (flow_type
) {
6932 *pid
= IPPROTO_SCTP
;
6948 static int niu_class_to_ethflow(u64
class, int *flow_type
)
6951 case CLASS_CODE_TCP_IPV4
:
6952 *flow_type
= TCP_V4_FLOW
;
6954 case CLASS_CODE_UDP_IPV4
:
6955 *flow_type
= UDP_V4_FLOW
;
6957 case CLASS_CODE_AH_ESP_IPV4
:
6958 *flow_type
= AH_V4_FLOW
;
6960 case CLASS_CODE_SCTP_IPV4
:
6961 *flow_type
= SCTP_V4_FLOW
;
6963 case CLASS_CODE_TCP_IPV6
:
6964 *flow_type
= TCP_V6_FLOW
;
6966 case CLASS_CODE_UDP_IPV6
:
6967 *flow_type
= UDP_V6_FLOW
;
6969 case CLASS_CODE_AH_ESP_IPV6
:
6970 *flow_type
= AH_V6_FLOW
;
6972 case CLASS_CODE_SCTP_IPV6
:
6973 *flow_type
= SCTP_V6_FLOW
;
6975 case CLASS_CODE_USER_PROG1
:
6976 case CLASS_CODE_USER_PROG2
:
6977 case CLASS_CODE_USER_PROG3
:
6978 case CLASS_CODE_USER_PROG4
:
6979 *flow_type
= IP_USER_FLOW
;
6988 static int niu_ethflow_to_class(int flow_type
, u64
*class)
6990 switch (flow_type
) {
6992 *class = CLASS_CODE_TCP_IPV4
;
6995 *class = CLASS_CODE_UDP_IPV4
;
6997 case AH_ESP_V4_FLOW
:
7000 *class = CLASS_CODE_AH_ESP_IPV4
;
7003 *class = CLASS_CODE_SCTP_IPV4
;
7006 *class = CLASS_CODE_TCP_IPV6
;
7009 *class = CLASS_CODE_UDP_IPV6
;
7011 case AH_ESP_V6_FLOW
:
7014 *class = CLASS_CODE_AH_ESP_IPV6
;
7017 *class = CLASS_CODE_SCTP_IPV6
;
7026 static u64
niu_flowkey_to_ethflow(u64 flow_key
)
7030 if (flow_key
& FLOW_KEY_L2DA
)
7031 ethflow
|= RXH_L2DA
;
7032 if (flow_key
& FLOW_KEY_VLAN
)
7033 ethflow
|= RXH_VLAN
;
7034 if (flow_key
& FLOW_KEY_IPSA
)
7035 ethflow
|= RXH_IP_SRC
;
7036 if (flow_key
& FLOW_KEY_IPDA
)
7037 ethflow
|= RXH_IP_DST
;
7038 if (flow_key
& FLOW_KEY_PROTO
)
7039 ethflow
|= RXH_L3_PROTO
;
7040 if (flow_key
& (FLOW_KEY_L4_BYTE12
<< FLOW_KEY_L4_0_SHIFT
))
7041 ethflow
|= RXH_L4_B_0_1
;
7042 if (flow_key
& (FLOW_KEY_L4_BYTE12
<< FLOW_KEY_L4_1_SHIFT
))
7043 ethflow
|= RXH_L4_B_2_3
;
7049 static int niu_ethflow_to_flowkey(u64 ethflow
, u64
*flow_key
)
7053 if (ethflow
& RXH_L2DA
)
7054 key
|= FLOW_KEY_L2DA
;
7055 if (ethflow
& RXH_VLAN
)
7056 key
|= FLOW_KEY_VLAN
;
7057 if (ethflow
& RXH_IP_SRC
)
7058 key
|= FLOW_KEY_IPSA
;
7059 if (ethflow
& RXH_IP_DST
)
7060 key
|= FLOW_KEY_IPDA
;
7061 if (ethflow
& RXH_L3_PROTO
)
7062 key
|= FLOW_KEY_PROTO
;
7063 if (ethflow
& RXH_L4_B_0_1
)
7064 key
|= (FLOW_KEY_L4_BYTE12
<< FLOW_KEY_L4_0_SHIFT
);
7065 if (ethflow
& RXH_L4_B_2_3
)
7066 key
|= (FLOW_KEY_L4_BYTE12
<< FLOW_KEY_L4_1_SHIFT
);
7074 static int niu_get_hash_opts(struct niu
*np
, struct ethtool_rxnfc
*nfc
)
7080 if (!niu_ethflow_to_class(nfc
->flow_type
, &class))
7083 if (np
->parent
->tcam_key
[class - CLASS_CODE_USER_PROG1
] &
7085 nfc
->data
= RXH_DISCARD
;
7087 nfc
->data
= niu_flowkey_to_ethflow(np
->parent
->flow_key
[class -
7088 CLASS_CODE_USER_PROG1
]);
7092 static void niu_get_ip4fs_from_tcam_key(struct niu_tcam_entry
*tp
,
7093 struct ethtool_rx_flow_spec
*fsp
)
7098 tmp
= (tp
->key
[3] & TCAM_V4KEY3_SADDR
) >> TCAM_V4KEY3_SADDR_SHIFT
;
7099 fsp
->h_u
.tcp_ip4_spec
.ip4src
= cpu_to_be32(tmp
);
7101 tmp
= (tp
->key
[3] & TCAM_V4KEY3_DADDR
) >> TCAM_V4KEY3_DADDR_SHIFT
;
7102 fsp
->h_u
.tcp_ip4_spec
.ip4dst
= cpu_to_be32(tmp
);
7104 tmp
= (tp
->key_mask
[3] & TCAM_V4KEY3_SADDR
) >> TCAM_V4KEY3_SADDR_SHIFT
;
7105 fsp
->m_u
.tcp_ip4_spec
.ip4src
= cpu_to_be32(tmp
);
7107 tmp
= (tp
->key_mask
[3] & TCAM_V4KEY3_DADDR
) >> TCAM_V4KEY3_DADDR_SHIFT
;
7108 fsp
->m_u
.tcp_ip4_spec
.ip4dst
= cpu_to_be32(tmp
);
7110 fsp
->h_u
.tcp_ip4_spec
.tos
= (tp
->key
[2] & TCAM_V4KEY2_TOS
) >>
7111 TCAM_V4KEY2_TOS_SHIFT
;
7112 fsp
->m_u
.tcp_ip4_spec
.tos
= (tp
->key_mask
[2] & TCAM_V4KEY2_TOS
) >>
7113 TCAM_V4KEY2_TOS_SHIFT
;
7115 switch (fsp
->flow_type
) {
7119 prt
= ((tp
->key
[2] & TCAM_V4KEY2_PORT_SPI
) >>
7120 TCAM_V4KEY2_PORT_SPI_SHIFT
) >> 16;
7121 fsp
->h_u
.tcp_ip4_spec
.psrc
= cpu_to_be16(prt
);
7123 prt
= ((tp
->key
[2] & TCAM_V4KEY2_PORT_SPI
) >>
7124 TCAM_V4KEY2_PORT_SPI_SHIFT
) & 0xffff;
7125 fsp
->h_u
.tcp_ip4_spec
.pdst
= cpu_to_be16(prt
);
7127 prt
= ((tp
->key_mask
[2] & TCAM_V4KEY2_PORT_SPI
) >>
7128 TCAM_V4KEY2_PORT_SPI_SHIFT
) >> 16;
7129 fsp
->m_u
.tcp_ip4_spec
.psrc
= cpu_to_be16(prt
);
7131 prt
= ((tp
->key_mask
[2] & TCAM_V4KEY2_PORT_SPI
) >>
7132 TCAM_V4KEY2_PORT_SPI_SHIFT
) & 0xffff;
7133 fsp
->m_u
.tcp_ip4_spec
.pdst
= cpu_to_be16(prt
);
7137 tmp
= (tp
->key
[2] & TCAM_V4KEY2_PORT_SPI
) >>
7138 TCAM_V4KEY2_PORT_SPI_SHIFT
;
7139 fsp
->h_u
.ah_ip4_spec
.spi
= cpu_to_be32(tmp
);
7141 tmp
= (tp
->key_mask
[2] & TCAM_V4KEY2_PORT_SPI
) >>
7142 TCAM_V4KEY2_PORT_SPI_SHIFT
;
7143 fsp
->m_u
.ah_ip4_spec
.spi
= cpu_to_be32(tmp
);
7146 tmp
= (tp
->key
[2] & TCAM_V4KEY2_PORT_SPI
) >>
7147 TCAM_V4KEY2_PORT_SPI_SHIFT
;
7148 fsp
->h_u
.usr_ip4_spec
.l4_4_bytes
= cpu_to_be32(tmp
);
7150 tmp
= (tp
->key_mask
[2] & TCAM_V4KEY2_PORT_SPI
) >>
7151 TCAM_V4KEY2_PORT_SPI_SHIFT
;
7152 fsp
->m_u
.usr_ip4_spec
.l4_4_bytes
= cpu_to_be32(tmp
);
7154 fsp
->h_u
.usr_ip4_spec
.proto
=
7155 (tp
->key
[2] & TCAM_V4KEY2_PROTO
) >>
7156 TCAM_V4KEY2_PROTO_SHIFT
;
7157 fsp
->m_u
.usr_ip4_spec
.proto
=
7158 (tp
->key_mask
[2] & TCAM_V4KEY2_PROTO
) >>
7159 TCAM_V4KEY2_PROTO_SHIFT
;
7161 fsp
->h_u
.usr_ip4_spec
.ip_ver
= ETH_RX_NFC_IP4
;
7168 static int niu_get_ethtool_tcam_entry(struct niu
*np
,
7169 struct ethtool_rxnfc
*nfc
)
7171 struct niu_parent
*parent
= np
->parent
;
7172 struct niu_tcam_entry
*tp
;
7173 struct ethtool_rx_flow_spec
*fsp
= &nfc
->fs
;
7178 idx
= tcam_get_index(np
, (u16
)nfc
->fs
.location
);
7180 tp
= &parent
->tcam
[idx
];
7182 netdev_info(np
->dev
, "niu%d: entry [%d] invalid for idx[%d]\n",
7183 parent
->index
, (u16
)nfc
->fs
.location
, idx
);
7187 /* fill the flow spec entry */
7188 class = (tp
->key
[0] & TCAM_V4KEY0_CLASS_CODE
) >>
7189 TCAM_V4KEY0_CLASS_CODE_SHIFT
;
7190 ret
= niu_class_to_ethflow(class, &fsp
->flow_type
);
7192 netdev_info(np
->dev
, "niu%d: niu_class_to_ethflow failed\n",
7197 if (fsp
->flow_type
== AH_V4_FLOW
|| fsp
->flow_type
== AH_V6_FLOW
) {
7198 u32 proto
= (tp
->key
[2] & TCAM_V4KEY2_PROTO
) >>
7199 TCAM_V4KEY2_PROTO_SHIFT
;
7200 if (proto
== IPPROTO_ESP
) {
7201 if (fsp
->flow_type
== AH_V4_FLOW
)
7202 fsp
->flow_type
= ESP_V4_FLOW
;
7204 fsp
->flow_type
= ESP_V6_FLOW
;
7208 switch (fsp
->flow_type
) {
7214 niu_get_ip4fs_from_tcam_key(tp
, fsp
);
7221 /* Not yet implemented */
7225 niu_get_ip4fs_from_tcam_key(tp
, fsp
);
7235 if (tp
->assoc_data
& TCAM_ASSOCDATA_DISC
)
7236 fsp
->ring_cookie
= RX_CLS_FLOW_DISC
;
7238 fsp
->ring_cookie
= (tp
->assoc_data
& TCAM_ASSOCDATA_OFFSET
) >>
7239 TCAM_ASSOCDATA_OFFSET_SHIFT
;
7241 /* put the tcam size here */
7242 nfc
->data
= tcam_get_size(np
);
7247 static int niu_get_ethtool_tcam_all(struct niu
*np
,
7248 struct ethtool_rxnfc
*nfc
,
7251 struct niu_parent
*parent
= np
->parent
;
7252 struct niu_tcam_entry
*tp
;
7254 unsigned long flags
;
7257 /* put the tcam size here */
7258 nfc
->data
= tcam_get_size(np
);
7260 niu_lock_parent(np
, flags
);
7261 for (cnt
= 0, i
= 0; i
< nfc
->data
; i
++) {
7262 idx
= tcam_get_index(np
, i
);
7263 tp
= &parent
->tcam
[idx
];
7266 if (cnt
== nfc
->rule_cnt
) {
7273 niu_unlock_parent(np
, flags
);
7275 nfc
->rule_cnt
= cnt
;
7280 static int niu_get_nfc(struct net_device
*dev
, struct ethtool_rxnfc
*cmd
,
7283 struct niu
*np
= netdev_priv(dev
);
7288 ret
= niu_get_hash_opts(np
, cmd
);
7290 case ETHTOOL_GRXRINGS
:
7291 cmd
->data
= np
->num_rx_rings
;
7293 case ETHTOOL_GRXCLSRLCNT
:
7294 cmd
->rule_cnt
= tcam_get_valid_entry_cnt(np
);
7296 case ETHTOOL_GRXCLSRULE
:
7297 ret
= niu_get_ethtool_tcam_entry(np
, cmd
);
7299 case ETHTOOL_GRXCLSRLALL
:
7300 ret
= niu_get_ethtool_tcam_all(np
, cmd
, rule_locs
);
7310 static int niu_set_hash_opts(struct niu
*np
, struct ethtool_rxnfc
*nfc
)
7314 unsigned long flags
;
7316 if (!niu_ethflow_to_class(nfc
->flow_type
, &class))
7319 if (class < CLASS_CODE_USER_PROG1
||
7320 class > CLASS_CODE_SCTP_IPV6
)
7323 if (nfc
->data
& RXH_DISCARD
) {
7324 niu_lock_parent(np
, flags
);
7325 flow_key
= np
->parent
->tcam_key
[class -
7326 CLASS_CODE_USER_PROG1
];
7327 flow_key
|= TCAM_KEY_DISC
;
7328 nw64(TCAM_KEY(class - CLASS_CODE_USER_PROG1
), flow_key
);
7329 np
->parent
->tcam_key
[class - CLASS_CODE_USER_PROG1
] = flow_key
;
7330 niu_unlock_parent(np
, flags
);
7333 /* Discard was set before, but is not set now */
7334 if (np
->parent
->tcam_key
[class - CLASS_CODE_USER_PROG1
] &
7336 niu_lock_parent(np
, flags
);
7337 flow_key
= np
->parent
->tcam_key
[class -
7338 CLASS_CODE_USER_PROG1
];
7339 flow_key
&= ~TCAM_KEY_DISC
;
7340 nw64(TCAM_KEY(class - CLASS_CODE_USER_PROG1
),
7342 np
->parent
->tcam_key
[class - CLASS_CODE_USER_PROG1
] =
7344 niu_unlock_parent(np
, flags
);
7348 if (!niu_ethflow_to_flowkey(nfc
->data
, &flow_key
))
7351 niu_lock_parent(np
, flags
);
7352 nw64(FLOW_KEY(class - CLASS_CODE_USER_PROG1
), flow_key
);
7353 np
->parent
->flow_key
[class - CLASS_CODE_USER_PROG1
] = flow_key
;
7354 niu_unlock_parent(np
, flags
);
7359 static void niu_get_tcamkey_from_ip4fs(struct ethtool_rx_flow_spec
*fsp
,
7360 struct niu_tcam_entry
*tp
,
7361 int l2_rdc_tab
, u64
class)
7364 u32 sip
, dip
, sipm
, dipm
, spi
, spim
;
7365 u16 sport
, dport
, spm
, dpm
;
7367 sip
= be32_to_cpu(fsp
->h_u
.tcp_ip4_spec
.ip4src
);
7368 sipm
= be32_to_cpu(fsp
->m_u
.tcp_ip4_spec
.ip4src
);
7369 dip
= be32_to_cpu(fsp
->h_u
.tcp_ip4_spec
.ip4dst
);
7370 dipm
= be32_to_cpu(fsp
->m_u
.tcp_ip4_spec
.ip4dst
);
7372 tp
->key
[0] = class << TCAM_V4KEY0_CLASS_CODE_SHIFT
;
7373 tp
->key_mask
[0] = TCAM_V4KEY0_CLASS_CODE
;
7374 tp
->key
[1] = (u64
)l2_rdc_tab
<< TCAM_V4KEY1_L2RDCNUM_SHIFT
;
7375 tp
->key_mask
[1] = TCAM_V4KEY1_L2RDCNUM
;
7377 tp
->key
[3] = (u64
)sip
<< TCAM_V4KEY3_SADDR_SHIFT
;
7380 tp
->key_mask
[3] = (u64
)sipm
<< TCAM_V4KEY3_SADDR_SHIFT
;
7381 tp
->key_mask
[3] |= dipm
;
7383 tp
->key
[2] |= ((u64
)fsp
->h_u
.tcp_ip4_spec
.tos
<<
7384 TCAM_V4KEY2_TOS_SHIFT
);
7385 tp
->key_mask
[2] |= ((u64
)fsp
->m_u
.tcp_ip4_spec
.tos
<<
7386 TCAM_V4KEY2_TOS_SHIFT
);
7387 switch (fsp
->flow_type
) {
7391 sport
= be16_to_cpu(fsp
->h_u
.tcp_ip4_spec
.psrc
);
7392 spm
= be16_to_cpu(fsp
->m_u
.tcp_ip4_spec
.psrc
);
7393 dport
= be16_to_cpu(fsp
->h_u
.tcp_ip4_spec
.pdst
);
7394 dpm
= be16_to_cpu(fsp
->m_u
.tcp_ip4_spec
.pdst
);
7396 tp
->key
[2] |= (((u64
)sport
<< 16) | dport
);
7397 tp
->key_mask
[2] |= (((u64
)spm
<< 16) | dpm
);
7398 niu_ethflow_to_l3proto(fsp
->flow_type
, &pid
);
7402 spi
= be32_to_cpu(fsp
->h_u
.ah_ip4_spec
.spi
);
7403 spim
= be32_to_cpu(fsp
->m_u
.ah_ip4_spec
.spi
);
7406 tp
->key_mask
[2] |= spim
;
7407 niu_ethflow_to_l3proto(fsp
->flow_type
, &pid
);
7410 spi
= be32_to_cpu(fsp
->h_u
.usr_ip4_spec
.l4_4_bytes
);
7411 spim
= be32_to_cpu(fsp
->m_u
.usr_ip4_spec
.l4_4_bytes
);
7414 tp
->key_mask
[2] |= spim
;
7415 pid
= fsp
->h_u
.usr_ip4_spec
.proto
;
7421 tp
->key
[2] |= ((u64
)pid
<< TCAM_V4KEY2_PROTO_SHIFT
);
7423 tp
->key_mask
[2] |= TCAM_V4KEY2_PROTO
;
7427 static int niu_add_ethtool_tcam_entry(struct niu
*np
,
7428 struct ethtool_rxnfc
*nfc
)
7430 struct niu_parent
*parent
= np
->parent
;
7431 struct niu_tcam_entry
*tp
;
7432 struct ethtool_rx_flow_spec
*fsp
= &nfc
->fs
;
7433 struct niu_rdc_tables
*rdc_table
= &parent
->rdc_group_cfg
[np
->port
];
7434 int l2_rdc_table
= rdc_table
->first_table_num
;
7437 unsigned long flags
;
7442 idx
= nfc
->fs
.location
;
7443 if (idx
>= tcam_get_size(np
))
7446 if (fsp
->flow_type
== IP_USER_FLOW
) {
7448 int add_usr_cls
= 0;
7449 struct ethtool_usrip4_spec
*uspec
= &fsp
->h_u
.usr_ip4_spec
;
7450 struct ethtool_usrip4_spec
*umask
= &fsp
->m_u
.usr_ip4_spec
;
7452 if (uspec
->ip_ver
!= ETH_RX_NFC_IP4
)
7455 niu_lock_parent(np
, flags
);
7457 for (i
= 0; i
< NIU_L3_PROG_CLS
; i
++) {
7458 if (parent
->l3_cls
[i
]) {
7459 if (uspec
->proto
== parent
->l3_cls_pid
[i
]) {
7460 class = parent
->l3_cls
[i
];
7461 parent
->l3_cls_refcnt
[i
]++;
7466 /* Program new user IP class */
7469 class = CLASS_CODE_USER_PROG1
;
7472 class = CLASS_CODE_USER_PROG2
;
7475 class = CLASS_CODE_USER_PROG3
;
7478 class = CLASS_CODE_USER_PROG4
;
7481 class = CLASS_CODE_UNRECOG
;
7484 ret
= tcam_user_ip_class_set(np
, class, 0,
7491 ret
= tcam_user_ip_class_enable(np
, class, 1);
7494 parent
->l3_cls
[i
] = class;
7495 parent
->l3_cls_pid
[i
] = uspec
->proto
;
7496 parent
->l3_cls_refcnt
[i
]++;
7502 netdev_info(np
->dev
, "niu%d: %s(): Could not find/insert class for pid %d\n",
7503 parent
->index
, __func__
, uspec
->proto
);
7507 niu_unlock_parent(np
, flags
);
7509 if (!niu_ethflow_to_class(fsp
->flow_type
, &class)) {
7514 niu_lock_parent(np
, flags
);
7516 idx
= tcam_get_index(np
, idx
);
7517 tp
= &parent
->tcam
[idx
];
7519 memset(tp
, 0, sizeof(*tp
));
7521 /* fill in the tcam key and mask */
7522 switch (fsp
->flow_type
) {
7528 niu_get_tcamkey_from_ip4fs(fsp
, tp
, l2_rdc_table
, class);
7535 /* Not yet implemented */
7536 netdev_info(np
->dev
, "niu%d: In %s(): flow %d for IPv6 not implemented\n",
7537 parent
->index
, __func__
, fsp
->flow_type
);
7541 niu_get_tcamkey_from_ip4fs(fsp
, tp
, l2_rdc_table
, class);
7544 netdev_info(np
->dev
, "niu%d: In %s(): Unknown flow type %d\n",
7545 parent
->index
, __func__
, fsp
->flow_type
);
7550 /* fill in the assoc data */
7551 if (fsp
->ring_cookie
== RX_CLS_FLOW_DISC
) {
7552 tp
->assoc_data
= TCAM_ASSOCDATA_DISC
;
7554 if (fsp
->ring_cookie
>= np
->num_rx_rings
) {
7555 netdev_info(np
->dev
, "niu%d: In %s(): Invalid RX ring %lld\n",
7556 parent
->index
, __func__
,
7557 (long long)fsp
->ring_cookie
);
7561 tp
->assoc_data
= (TCAM_ASSOCDATA_TRES_USE_OFFSET
|
7562 (fsp
->ring_cookie
<<
7563 TCAM_ASSOCDATA_OFFSET_SHIFT
));
7566 err
= tcam_write(np
, idx
, tp
->key
, tp
->key_mask
);
7571 err
= tcam_assoc_write(np
, idx
, tp
->assoc_data
);
7577 /* validate the entry */
7579 np
->clas
.tcam_valid_entries
++;
7581 niu_unlock_parent(np
, flags
);
7586 static int niu_del_ethtool_tcam_entry(struct niu
*np
, u32 loc
)
7588 struct niu_parent
*parent
= np
->parent
;
7589 struct niu_tcam_entry
*tp
;
7591 unsigned long flags
;
7595 if (loc
>= tcam_get_size(np
))
7598 niu_lock_parent(np
, flags
);
7600 idx
= tcam_get_index(np
, loc
);
7601 tp
= &parent
->tcam
[idx
];
7603 /* if the entry is of a user defined class, then update*/
7604 class = (tp
->key
[0] & TCAM_V4KEY0_CLASS_CODE
) >>
7605 TCAM_V4KEY0_CLASS_CODE_SHIFT
;
7607 if (class >= CLASS_CODE_USER_PROG1
&& class <= CLASS_CODE_USER_PROG4
) {
7609 for (i
= 0; i
< NIU_L3_PROG_CLS
; i
++) {
7610 if (parent
->l3_cls
[i
] == class) {
7611 parent
->l3_cls_refcnt
[i
]--;
7612 if (!parent
->l3_cls_refcnt
[i
]) {
7614 ret
= tcam_user_ip_class_enable(np
,
7619 parent
->l3_cls
[i
] = 0;
7620 parent
->l3_cls_pid
[i
] = 0;
7625 if (i
== NIU_L3_PROG_CLS
) {
7626 netdev_info(np
->dev
, "niu%d: In %s(): Usr class 0x%llx not found\n",
7627 parent
->index
, __func__
,
7628 (unsigned long long)class);
7634 ret
= tcam_flush(np
, idx
);
7638 /* invalidate the entry */
7640 np
->clas
.tcam_valid_entries
--;
7642 niu_unlock_parent(np
, flags
);
7647 static int niu_set_nfc(struct net_device
*dev
, struct ethtool_rxnfc
*cmd
)
7649 struct niu
*np
= netdev_priv(dev
);
7654 ret
= niu_set_hash_opts(np
, cmd
);
7656 case ETHTOOL_SRXCLSRLINS
:
7657 ret
= niu_add_ethtool_tcam_entry(np
, cmd
);
7659 case ETHTOOL_SRXCLSRLDEL
:
7660 ret
= niu_del_ethtool_tcam_entry(np
, cmd
->fs
.location
);
7670 static const struct {
7671 const char string
[ETH_GSTRING_LEN
];
7672 } niu_xmac_stat_keys
[] = {
7675 { "tx_fifo_errors" },
7676 { "tx_overflow_errors" },
7677 { "tx_max_pkt_size_errors" },
7678 { "tx_underflow_errors" },
7679 { "rx_local_faults" },
7680 { "rx_remote_faults" },
7681 { "rx_link_faults" },
7682 { "rx_align_errors" },
7694 { "rx_code_violations" },
7695 { "rx_len_errors" },
7696 { "rx_crc_errors" },
7697 { "rx_underflows" },
7699 { "pause_off_state" },
7700 { "pause_on_state" },
7701 { "pause_received" },
7704 #define NUM_XMAC_STAT_KEYS ARRAY_SIZE(niu_xmac_stat_keys)
7706 static const struct {
7707 const char string
[ETH_GSTRING_LEN
];
7708 } niu_bmac_stat_keys
[] = {
7709 { "tx_underflow_errors" },
7710 { "tx_max_pkt_size_errors" },
7715 { "rx_align_errors" },
7716 { "rx_crc_errors" },
7717 { "rx_len_errors" },
7718 { "pause_off_state" },
7719 { "pause_on_state" },
7720 { "pause_received" },
7723 #define NUM_BMAC_STAT_KEYS ARRAY_SIZE(niu_bmac_stat_keys)
7725 static const struct {
7726 const char string
[ETH_GSTRING_LEN
];
7727 } niu_rxchan_stat_keys
[] = {
7735 #define NUM_RXCHAN_STAT_KEYS ARRAY_SIZE(niu_rxchan_stat_keys)
7737 static const struct {
7738 const char string
[ETH_GSTRING_LEN
];
7739 } niu_txchan_stat_keys
[] = {
7746 #define NUM_TXCHAN_STAT_KEYS ARRAY_SIZE(niu_txchan_stat_keys)
7748 static void niu_get_strings(struct net_device
*dev
, u32 stringset
, u8
*data
)
7750 struct niu
*np
= netdev_priv(dev
);
7753 if (stringset
!= ETH_SS_STATS
)
7756 if (np
->flags
& NIU_FLAGS_XMAC
) {
7757 memcpy(data
, niu_xmac_stat_keys
,
7758 sizeof(niu_xmac_stat_keys
));
7759 data
+= sizeof(niu_xmac_stat_keys
);
7761 memcpy(data
, niu_bmac_stat_keys
,
7762 sizeof(niu_bmac_stat_keys
));
7763 data
+= sizeof(niu_bmac_stat_keys
);
7765 for (i
= 0; i
< np
->num_rx_rings
; i
++) {
7766 memcpy(data
, niu_rxchan_stat_keys
,
7767 sizeof(niu_rxchan_stat_keys
));
7768 data
+= sizeof(niu_rxchan_stat_keys
);
7770 for (i
= 0; i
< np
->num_tx_rings
; i
++) {
7771 memcpy(data
, niu_txchan_stat_keys
,
7772 sizeof(niu_txchan_stat_keys
));
7773 data
+= sizeof(niu_txchan_stat_keys
);
7777 static int niu_get_sset_count(struct net_device
*dev
, int stringset
)
7779 struct niu
*np
= netdev_priv(dev
);
7781 if (stringset
!= ETH_SS_STATS
)
7784 return (np
->flags
& NIU_FLAGS_XMAC
?
7785 NUM_XMAC_STAT_KEYS
:
7786 NUM_BMAC_STAT_KEYS
) +
7787 (np
->num_rx_rings
* NUM_RXCHAN_STAT_KEYS
) +
7788 (np
->num_tx_rings
* NUM_TXCHAN_STAT_KEYS
);
7791 static void niu_get_ethtool_stats(struct net_device
*dev
,
7792 struct ethtool_stats
*stats
, u64
*data
)
7794 struct niu
*np
= netdev_priv(dev
);
7797 niu_sync_mac_stats(np
);
7798 if (np
->flags
& NIU_FLAGS_XMAC
) {
7799 memcpy(data
, &np
->mac_stats
.xmac
,
7800 sizeof(struct niu_xmac_stats
));
7801 data
+= (sizeof(struct niu_xmac_stats
) / sizeof(u64
));
7803 memcpy(data
, &np
->mac_stats
.bmac
,
7804 sizeof(struct niu_bmac_stats
));
7805 data
+= (sizeof(struct niu_bmac_stats
) / sizeof(u64
));
7807 for (i
= 0; i
< np
->num_rx_rings
; i
++) {
7808 struct rx_ring_info
*rp
= &np
->rx_rings
[i
];
7810 niu_sync_rx_discard_stats(np
, rp
, 0);
7812 data
[0] = rp
->rx_channel
;
7813 data
[1] = rp
->rx_packets
;
7814 data
[2] = rp
->rx_bytes
;
7815 data
[3] = rp
->rx_dropped
;
7816 data
[4] = rp
->rx_errors
;
7819 for (i
= 0; i
< np
->num_tx_rings
; i
++) {
7820 struct tx_ring_info
*rp
= &np
->tx_rings
[i
];
7822 data
[0] = rp
->tx_channel
;
7823 data
[1] = rp
->tx_packets
;
7824 data
[2] = rp
->tx_bytes
;
7825 data
[3] = rp
->tx_errors
;
7830 static u64
niu_led_state_save(struct niu
*np
)
7832 if (np
->flags
& NIU_FLAGS_XMAC
)
7833 return nr64_mac(XMAC_CONFIG
);
7835 return nr64_mac(BMAC_XIF_CONFIG
);
7838 static void niu_led_state_restore(struct niu
*np
, u64 val
)
7840 if (np
->flags
& NIU_FLAGS_XMAC
)
7841 nw64_mac(XMAC_CONFIG
, val
);
7843 nw64_mac(BMAC_XIF_CONFIG
, val
);
7846 static void niu_force_led(struct niu
*np
, int on
)
7850 if (np
->flags
& NIU_FLAGS_XMAC
) {
7852 bit
= XMAC_CONFIG_FORCE_LED_ON
;
7854 reg
= BMAC_XIF_CONFIG
;
7855 bit
= BMAC_XIF_CONFIG_LINK_LED
;
7858 val
= nr64_mac(reg
);
7866 static int niu_set_phys_id(struct net_device
*dev
,
7867 enum ethtool_phys_id_state state
)
7870 struct niu
*np
= netdev_priv(dev
);
7872 if (!netif_running(dev
))
7876 case ETHTOOL_ID_ACTIVE
:
7877 np
->orig_led_state
= niu_led_state_save(np
);
7878 return 1; /* cycle on/off once per second */
7881 niu_force_led(np
, 1);
7884 case ETHTOOL_ID_OFF
:
7885 niu_force_led(np
, 0);
7888 case ETHTOOL_ID_INACTIVE
:
7889 niu_led_state_restore(np
, np
->orig_led_state
);
7895 static const struct ethtool_ops niu_ethtool_ops
= {
7896 .get_drvinfo
= niu_get_drvinfo
,
7897 .get_link
= ethtool_op_get_link
,
7898 .get_msglevel
= niu_get_msglevel
,
7899 .set_msglevel
= niu_set_msglevel
,
7900 .nway_reset
= niu_nway_reset
,
7901 .get_eeprom_len
= niu_get_eeprom_len
,
7902 .get_eeprom
= niu_get_eeprom
,
7903 .get_strings
= niu_get_strings
,
7904 .get_sset_count
= niu_get_sset_count
,
7905 .get_ethtool_stats
= niu_get_ethtool_stats
,
7906 .set_phys_id
= niu_set_phys_id
,
7907 .get_rxnfc
= niu_get_nfc
,
7908 .set_rxnfc
= niu_set_nfc
,
7909 .get_link_ksettings
= niu_get_link_ksettings
,
7910 .set_link_ksettings
= niu_set_link_ksettings
,
7913 static int niu_ldg_assign_ldn(struct niu
*np
, struct niu_parent
*parent
,
7916 if (ldg
< NIU_LDG_MIN
|| ldg
> NIU_LDG_MAX
)
7918 if (ldn
< 0 || ldn
> LDN_MAX
)
7921 parent
->ldg_map
[ldn
] = ldg
;
7923 if (np
->parent
->plat_type
== PLAT_TYPE_NIU
) {
7924 /* On N2 NIU, the ldn-->ldg assignments are setup and fixed by
7925 * the firmware, and we're not supposed to change them.
7926 * Validate the mapping, because if it's wrong we probably
7927 * won't get any interrupts and that's painful to debug.
7929 if (nr64(LDG_NUM(ldn
)) != ldg
) {
7930 dev_err(np
->device
, "Port %u, mismatched LDG assignment for ldn %d, should be %d is %llu\n",
7932 (unsigned long long) nr64(LDG_NUM(ldn
)));
7936 nw64(LDG_NUM(ldn
), ldg
);
7941 static int niu_set_ldg_timer_res(struct niu
*np
, int res
)
7943 if (res
< 0 || res
> LDG_TIMER_RES_VAL
)
7947 nw64(LDG_TIMER_RES
, res
);
7952 static int niu_set_ldg_sid(struct niu
*np
, int ldg
, int func
, int vector
)
7954 if ((ldg
< NIU_LDG_MIN
|| ldg
> NIU_LDG_MAX
) ||
7955 (func
< 0 || func
> 3) ||
7956 (vector
< 0 || vector
> 0x1f))
7959 nw64(SID(ldg
), (func
<< SID_FUNC_SHIFT
) | vector
);
7964 static int niu_pci_eeprom_read(struct niu
*np
, u32 addr
)
7966 u64 frame
, frame_base
= (ESPC_PIO_STAT_READ_START
|
7967 (addr
<< ESPC_PIO_STAT_ADDR_SHIFT
));
7970 if (addr
> (ESPC_PIO_STAT_ADDR
>> ESPC_PIO_STAT_ADDR_SHIFT
))
7974 nw64(ESPC_PIO_STAT
, frame
);
7978 frame
= nr64(ESPC_PIO_STAT
);
7979 if (frame
& ESPC_PIO_STAT_READ_END
)
7982 if (!(frame
& ESPC_PIO_STAT_READ_END
)) {
7983 dev_err(np
->device
, "EEPROM read timeout frame[%llx]\n",
7984 (unsigned long long) frame
);
7989 nw64(ESPC_PIO_STAT
, frame
);
7993 frame
= nr64(ESPC_PIO_STAT
);
7994 if (frame
& ESPC_PIO_STAT_READ_END
)
7997 if (!(frame
& ESPC_PIO_STAT_READ_END
)) {
7998 dev_err(np
->device
, "EEPROM read timeout frame[%llx]\n",
7999 (unsigned long long) frame
);
8003 frame
= nr64(ESPC_PIO_STAT
);
8004 return (frame
& ESPC_PIO_STAT_DATA
) >> ESPC_PIO_STAT_DATA_SHIFT
;
8007 static int niu_pci_eeprom_read16(struct niu
*np
, u32 off
)
8009 int err
= niu_pci_eeprom_read(np
, off
);
8015 err
= niu_pci_eeprom_read(np
, off
+ 1);
8018 val
|= (err
& 0xff);
8023 static int niu_pci_eeprom_read16_swp(struct niu
*np
, u32 off
)
8025 int err
= niu_pci_eeprom_read(np
, off
);
8032 err
= niu_pci_eeprom_read(np
, off
+ 1);
8036 val
|= (err
& 0xff) << 8;
8041 static int niu_pci_vpd_get_propname(struct niu
*np
, u32 off
, char *namebuf
,
8046 for (i
= 0; i
< namebuf_len
; i
++) {
8047 int err
= niu_pci_eeprom_read(np
, off
+ i
);
8054 if (i
>= namebuf_len
)
8060 static void niu_vpd_parse_version(struct niu
*np
)
8062 struct niu_vpd
*vpd
= &np
->vpd
;
8063 int len
= strlen(vpd
->version
) + 1;
8064 const char *s
= vpd
->version
;
8067 for (i
= 0; i
< len
- 5; i
++) {
8068 if (!strncmp(s
+ i
, "FCode ", 6))
8075 sscanf(s
, "%d.%d", &vpd
->fcode_major
, &vpd
->fcode_minor
);
8077 netif_printk(np
, probe
, KERN_DEBUG
, np
->dev
,
8078 "VPD_SCAN: FCODE major(%d) minor(%d)\n",
8079 vpd
->fcode_major
, vpd
->fcode_minor
);
8080 if (vpd
->fcode_major
> NIU_VPD_MIN_MAJOR
||
8081 (vpd
->fcode_major
== NIU_VPD_MIN_MAJOR
&&
8082 vpd
->fcode_minor
>= NIU_VPD_MIN_MINOR
))
8083 np
->flags
|= NIU_FLAGS_VPD_VALID
;
8086 /* ESPC_PIO_EN_ENABLE must be set */
8087 static int niu_pci_vpd_scan_props(struct niu
*np
, u32 start
, u32 end
)
8089 unsigned int found_mask
= 0;
8090 #define FOUND_MASK_MODEL 0x00000001
8091 #define FOUND_MASK_BMODEL 0x00000002
8092 #define FOUND_MASK_VERS 0x00000004
8093 #define FOUND_MASK_MAC 0x00000008
8094 #define FOUND_MASK_NMAC 0x00000010
8095 #define FOUND_MASK_PHY 0x00000020
8096 #define FOUND_MASK_ALL 0x0000003f
8098 netif_printk(np
, probe
, KERN_DEBUG
, np
->dev
,
8099 "VPD_SCAN: start[%x] end[%x]\n", start
, end
);
8100 while (start
< end
) {
8101 int len
, err
, prop_len
;
8106 if (found_mask
== FOUND_MASK_ALL
) {
8107 niu_vpd_parse_version(np
);
8111 err
= niu_pci_eeprom_read(np
, start
+ 2);
8117 prop_len
= niu_pci_eeprom_read(np
, start
+ 4);
8120 err
= niu_pci_vpd_get_propname(np
, start
+ 5, namebuf
, 64);
8126 if (!strcmp(namebuf
, "model")) {
8127 prop_buf
= np
->vpd
.model
;
8128 max_len
= NIU_VPD_MODEL_MAX
;
8129 found_mask
|= FOUND_MASK_MODEL
;
8130 } else if (!strcmp(namebuf
, "board-model")) {
8131 prop_buf
= np
->vpd
.board_model
;
8132 max_len
= NIU_VPD_BD_MODEL_MAX
;
8133 found_mask
|= FOUND_MASK_BMODEL
;
8134 } else if (!strcmp(namebuf
, "version")) {
8135 prop_buf
= np
->vpd
.version
;
8136 max_len
= NIU_VPD_VERSION_MAX
;
8137 found_mask
|= FOUND_MASK_VERS
;
8138 } else if (!strcmp(namebuf
, "local-mac-address")) {
8139 prop_buf
= np
->vpd
.local_mac
;
8141 found_mask
|= FOUND_MASK_MAC
;
8142 } else if (!strcmp(namebuf
, "num-mac-addresses")) {
8143 prop_buf
= &np
->vpd
.mac_num
;
8145 found_mask
|= FOUND_MASK_NMAC
;
8146 } else if (!strcmp(namebuf
, "phy-type")) {
8147 prop_buf
= np
->vpd
.phy_type
;
8148 max_len
= NIU_VPD_PHY_TYPE_MAX
;
8149 found_mask
|= FOUND_MASK_PHY
;
8152 if (max_len
&& prop_len
> max_len
) {
8153 dev_err(np
->device
, "Property '%s' length (%d) is too long\n", namebuf
, prop_len
);
8158 u32 off
= start
+ 5 + err
;
8161 netif_printk(np
, probe
, KERN_DEBUG
, np
->dev
,
8162 "VPD_SCAN: Reading in property [%s] len[%d]\n",
8164 for (i
= 0; i
< prop_len
; i
++) {
8165 err
= niu_pci_eeprom_read(np
, off
+ i
);
8178 /* ESPC_PIO_EN_ENABLE must be set */
8179 static int niu_pci_vpd_fetch(struct niu
*np
, u32 start
)
8184 err
= niu_pci_eeprom_read16_swp(np
, start
+ 1);
8190 while (start
+ offset
< ESPC_EEPROM_SIZE
) {
8191 u32 here
= start
+ offset
;
8194 err
= niu_pci_eeprom_read(np
, here
);
8200 err
= niu_pci_eeprom_read16_swp(np
, here
+ 1);
8204 here
= start
+ offset
+ 3;
8205 end
= start
+ offset
+ err
;
8209 err
= niu_pci_vpd_scan_props(np
, here
, end
);
8212 /* ret == 1 is not an error */
8219 /* ESPC_PIO_EN_ENABLE must be set */
8220 static u32
niu_pci_vpd_offset(struct niu
*np
)
8222 u32 start
= 0, end
= ESPC_EEPROM_SIZE
, ret
;
8225 while (start
< end
) {
8228 /* ROM header signature? */
8229 err
= niu_pci_eeprom_read16(np
, start
+ 0);
8233 /* Apply offset to PCI data structure. */
8234 err
= niu_pci_eeprom_read16(np
, start
+ 23);
8239 /* Check for "PCIR" signature. */
8240 err
= niu_pci_eeprom_read16(np
, start
+ 0);
8243 err
= niu_pci_eeprom_read16(np
, start
+ 2);
8247 /* Check for OBP image type. */
8248 err
= niu_pci_eeprom_read(np
, start
+ 20);
8252 err
= niu_pci_eeprom_read(np
, ret
+ 2);
8256 start
= ret
+ (err
* 512);
8260 err
= niu_pci_eeprom_read16_swp(np
, start
+ 8);
8265 err
= niu_pci_eeprom_read(np
, ret
+ 0);
8275 static int niu_phy_type_prop_decode(struct niu
*np
, const char *phy_prop
)
8277 if (!strcmp(phy_prop
, "mif")) {
8278 /* 1G copper, MII */
8279 np
->flags
&= ~(NIU_FLAGS_FIBER
|
8281 np
->mac_xcvr
= MAC_XCVR_MII
;
8282 } else if (!strcmp(phy_prop
, "xgf")) {
8283 /* 10G fiber, XPCS */
8284 np
->flags
|= (NIU_FLAGS_10G
|
8286 np
->mac_xcvr
= MAC_XCVR_XPCS
;
8287 } else if (!strcmp(phy_prop
, "pcs")) {
8289 np
->flags
&= ~NIU_FLAGS_10G
;
8290 np
->flags
|= NIU_FLAGS_FIBER
;
8291 np
->mac_xcvr
= MAC_XCVR_PCS
;
8292 } else if (!strcmp(phy_prop
, "xgc")) {
8293 /* 10G copper, XPCS */
8294 np
->flags
|= NIU_FLAGS_10G
;
8295 np
->flags
&= ~NIU_FLAGS_FIBER
;
8296 np
->mac_xcvr
= MAC_XCVR_XPCS
;
8297 } else if (!strcmp(phy_prop
, "xgsd") || !strcmp(phy_prop
, "gsd")) {
8298 /* 10G Serdes or 1G Serdes, default to 10G */
8299 np
->flags
|= NIU_FLAGS_10G
;
8300 np
->flags
&= ~NIU_FLAGS_FIBER
;
8301 np
->flags
|= NIU_FLAGS_XCVR_SERDES
;
8302 np
->mac_xcvr
= MAC_XCVR_XPCS
;
8309 static int niu_pci_vpd_get_nports(struct niu
*np
)
8313 if ((!strcmp(np
->vpd
.model
, NIU_QGC_LP_MDL_STR
)) ||
8314 (!strcmp(np
->vpd
.model
, NIU_QGC_PEM_MDL_STR
)) ||
8315 (!strcmp(np
->vpd
.model
, NIU_MARAMBA_MDL_STR
)) ||
8316 (!strcmp(np
->vpd
.model
, NIU_KIMI_MDL_STR
)) ||
8317 (!strcmp(np
->vpd
.model
, NIU_ALONSO_MDL_STR
))) {
8319 } else if ((!strcmp(np
->vpd
.model
, NIU_2XGF_LP_MDL_STR
)) ||
8320 (!strcmp(np
->vpd
.model
, NIU_2XGF_PEM_MDL_STR
)) ||
8321 (!strcmp(np
->vpd
.model
, NIU_FOXXY_MDL_STR
)) ||
8322 (!strcmp(np
->vpd
.model
, NIU_2XGF_MRVL_MDL_STR
))) {
8329 static void niu_pci_vpd_validate(struct niu
*np
)
8331 struct net_device
*dev
= np
->dev
;
8332 struct niu_vpd
*vpd
= &np
->vpd
;
8336 if (!is_valid_ether_addr(&vpd
->local_mac
[0])) {
8337 dev_err(np
->device
, "VPD MAC invalid, falling back to SPROM\n");
8339 np
->flags
&= ~NIU_FLAGS_VPD_VALID
;
8343 if (!strcmp(np
->vpd
.model
, NIU_ALONSO_MDL_STR
) ||
8344 !strcmp(np
->vpd
.model
, NIU_KIMI_MDL_STR
)) {
8345 np
->flags
|= NIU_FLAGS_10G
;
8346 np
->flags
&= ~NIU_FLAGS_FIBER
;
8347 np
->flags
|= NIU_FLAGS_XCVR_SERDES
;
8348 np
->mac_xcvr
= MAC_XCVR_PCS
;
8350 np
->flags
|= NIU_FLAGS_FIBER
;
8351 np
->flags
&= ~NIU_FLAGS_10G
;
8353 if (np
->flags
& NIU_FLAGS_10G
)
8354 np
->mac_xcvr
= MAC_XCVR_XPCS
;
8355 } else if (!strcmp(np
->vpd
.model
, NIU_FOXXY_MDL_STR
)) {
8356 np
->flags
|= (NIU_FLAGS_10G
| NIU_FLAGS_FIBER
|
8357 NIU_FLAGS_HOTPLUG_PHY
);
8358 } else if (niu_phy_type_prop_decode(np
, np
->vpd
.phy_type
)) {
8359 dev_err(np
->device
, "Illegal phy string [%s]\n",
8361 dev_err(np
->device
, "Falling back to SPROM\n");
8362 np
->flags
&= ~NIU_FLAGS_VPD_VALID
;
8366 ether_addr_copy(addr
, vpd
->local_mac
);
8369 addr
[5] += np
->port
;
8373 eth_hw_addr_set(dev
, addr
);
8376 static int niu_pci_probe_sprom(struct niu
*np
)
8378 struct net_device
*dev
= np
->dev
;
8384 val
= (nr64(ESPC_VER_IMGSZ
) & ESPC_VER_IMGSZ_IMGSZ
);
8385 val
>>= ESPC_VER_IMGSZ_IMGSZ_SHIFT
;
8388 np
->eeprom_len
= len
;
8390 netif_printk(np
, probe
, KERN_DEBUG
, np
->dev
,
8391 "SPROM: Image size %llu\n", (unsigned long long)val
);
8394 for (i
= 0; i
< len
; i
++) {
8395 val
= nr64(ESPC_NCR(i
));
8396 sum
+= (val
>> 0) & 0xff;
8397 sum
+= (val
>> 8) & 0xff;
8398 sum
+= (val
>> 16) & 0xff;
8399 sum
+= (val
>> 24) & 0xff;
8401 netif_printk(np
, probe
, KERN_DEBUG
, np
->dev
,
8402 "SPROM: Checksum %x\n", (int)(sum
& 0xff));
8403 if ((sum
& 0xff) != 0xab) {
8404 dev_err(np
->device
, "Bad SPROM checksum (%x, should be 0xab)\n", (int)(sum
& 0xff));
8408 val
= nr64(ESPC_PHY_TYPE
);
8411 val8
= (val
& ESPC_PHY_TYPE_PORT0
) >>
8412 ESPC_PHY_TYPE_PORT0_SHIFT
;
8415 val8
= (val
& ESPC_PHY_TYPE_PORT1
) >>
8416 ESPC_PHY_TYPE_PORT1_SHIFT
;
8419 val8
= (val
& ESPC_PHY_TYPE_PORT2
) >>
8420 ESPC_PHY_TYPE_PORT2_SHIFT
;
8423 val8
= (val
& ESPC_PHY_TYPE_PORT3
) >>
8424 ESPC_PHY_TYPE_PORT3_SHIFT
;
8427 dev_err(np
->device
, "Bogus port number %u\n",
8431 netif_printk(np
, probe
, KERN_DEBUG
, np
->dev
,
8432 "SPROM: PHY type %x\n", val8
);
8435 case ESPC_PHY_TYPE_1G_COPPER
:
8436 /* 1G copper, MII */
8437 np
->flags
&= ~(NIU_FLAGS_FIBER
|
8439 np
->mac_xcvr
= MAC_XCVR_MII
;
8442 case ESPC_PHY_TYPE_1G_FIBER
:
8444 np
->flags
&= ~NIU_FLAGS_10G
;
8445 np
->flags
|= NIU_FLAGS_FIBER
;
8446 np
->mac_xcvr
= MAC_XCVR_PCS
;
8449 case ESPC_PHY_TYPE_10G_COPPER
:
8450 /* 10G copper, XPCS */
8451 np
->flags
|= NIU_FLAGS_10G
;
8452 np
->flags
&= ~NIU_FLAGS_FIBER
;
8453 np
->mac_xcvr
= MAC_XCVR_XPCS
;
8456 case ESPC_PHY_TYPE_10G_FIBER
:
8457 /* 10G fiber, XPCS */
8458 np
->flags
|= (NIU_FLAGS_10G
|
8460 np
->mac_xcvr
= MAC_XCVR_XPCS
;
8464 dev_err(np
->device
, "Bogus SPROM phy type %u\n", val8
);
8468 val
= nr64(ESPC_MAC_ADDR0
);
8469 netif_printk(np
, probe
, KERN_DEBUG
, np
->dev
,
8470 "SPROM: MAC_ADDR0[%08llx]\n", (unsigned long long)val
);
8471 addr
[0] = (val
>> 0) & 0xff;
8472 addr
[1] = (val
>> 8) & 0xff;
8473 addr
[2] = (val
>> 16) & 0xff;
8474 addr
[3] = (val
>> 24) & 0xff;
8476 val
= nr64(ESPC_MAC_ADDR1
);
8477 netif_printk(np
, probe
, KERN_DEBUG
, np
->dev
,
8478 "SPROM: MAC_ADDR1[%08llx]\n", (unsigned long long)val
);
8479 addr
[4] = (val
>> 0) & 0xff;
8480 addr
[5] = (val
>> 8) & 0xff;
8482 if (!is_valid_ether_addr(addr
)) {
8483 dev_err(np
->device
, "SPROM MAC address invalid [ %pM ]\n",
8489 addr
[5] += np
->port
;
8493 eth_hw_addr_set(dev
, addr
);
8495 val
= nr64(ESPC_MOD_STR_LEN
);
8496 netif_printk(np
, probe
, KERN_DEBUG
, np
->dev
,
8497 "SPROM: MOD_STR_LEN[%llu]\n", (unsigned long long)val
);
8501 for (i
= 0; i
< val
; i
+= 4) {
8502 u64 tmp
= nr64(ESPC_NCR(5 + (i
/ 4)));
8504 np
->vpd
.model
[i
+ 3] = (tmp
>> 0) & 0xff;
8505 np
->vpd
.model
[i
+ 2] = (tmp
>> 8) & 0xff;
8506 np
->vpd
.model
[i
+ 1] = (tmp
>> 16) & 0xff;
8507 np
->vpd
.model
[i
+ 0] = (tmp
>> 24) & 0xff;
8509 np
->vpd
.model
[val
] = '\0';
8511 val
= nr64(ESPC_BD_MOD_STR_LEN
);
8512 netif_printk(np
, probe
, KERN_DEBUG
, np
->dev
,
8513 "SPROM: BD_MOD_STR_LEN[%llu]\n", (unsigned long long)val
);
8517 for (i
= 0; i
< val
; i
+= 4) {
8518 u64 tmp
= nr64(ESPC_NCR(14 + (i
/ 4)));
8520 np
->vpd
.board_model
[i
+ 3] = (tmp
>> 0) & 0xff;
8521 np
->vpd
.board_model
[i
+ 2] = (tmp
>> 8) & 0xff;
8522 np
->vpd
.board_model
[i
+ 1] = (tmp
>> 16) & 0xff;
8523 np
->vpd
.board_model
[i
+ 0] = (tmp
>> 24) & 0xff;
8525 np
->vpd
.board_model
[val
] = '\0';
8528 nr64(ESPC_NUM_PORTS_MACS
) & ESPC_NUM_PORTS_MACS_VAL
;
8529 netif_printk(np
, probe
, KERN_DEBUG
, np
->dev
,
8530 "SPROM: NUM_PORTS_MACS[%d]\n", np
->vpd
.mac_num
);
8535 static int niu_get_and_validate_port(struct niu
*np
)
8537 struct niu_parent
*parent
= np
->parent
;
8540 np
->flags
|= NIU_FLAGS_XMAC
;
8542 if (!parent
->num_ports
) {
8543 if (parent
->plat_type
== PLAT_TYPE_NIU
) {
8544 parent
->num_ports
= 2;
8546 parent
->num_ports
= niu_pci_vpd_get_nports(np
);
8547 if (!parent
->num_ports
) {
8548 /* Fall back to SPROM as last resort.
8549 * This will fail on most cards.
8551 parent
->num_ports
= nr64(ESPC_NUM_PORTS_MACS
) &
8552 ESPC_NUM_PORTS_MACS_VAL
;
8554 /* All of the current probing methods fail on
8555 * Maramba on-board parts.
8557 if (!parent
->num_ports
)
8558 parent
->num_ports
= 4;
8563 if (np
->port
>= parent
->num_ports
)
8569 static int phy_record(struct niu_parent
*parent
, struct phy_probe_info
*p
,
8570 int dev_id_1
, int dev_id_2
, u8 phy_port
, int type
)
8572 u32 id
= (dev_id_1
<< 16) | dev_id_2
;
8575 if (dev_id_1
< 0 || dev_id_2
< 0)
8577 if (type
== PHY_TYPE_PMA_PMD
|| type
== PHY_TYPE_PCS
) {
8578 /* Because of the NIU_PHY_ID_MASK being applied, the 8704
8579 * test covers the 8706 as well.
8581 if (((id
& NIU_PHY_ID_MASK
) != NIU_PHY_ID_BCM8704
) &&
8582 ((id
& NIU_PHY_ID_MASK
) != NIU_PHY_ID_MRVL88X2011
))
8585 if ((id
& NIU_PHY_ID_MASK
) != NIU_PHY_ID_BCM5464R
)
8589 pr_info("niu%d: Found PHY %08x type %s at phy_port %u\n",
8591 type
== PHY_TYPE_PMA_PMD
? "PMA/PMD" :
8592 type
== PHY_TYPE_PCS
? "PCS" : "MII",
8595 if (p
->cur
[type
] >= NIU_MAX_PORTS
) {
8596 pr_err("Too many PHY ports\n");
8600 p
->phy_id
[type
][idx
] = id
;
8601 p
->phy_port
[type
][idx
] = phy_port
;
8602 p
->cur
[type
] = idx
+ 1;
8606 static int port_has_10g(struct phy_probe_info
*p
, int port
)
8610 for (i
= 0; i
< p
->cur
[PHY_TYPE_PMA_PMD
]; i
++) {
8611 if (p
->phy_port
[PHY_TYPE_PMA_PMD
][i
] == port
)
8614 for (i
= 0; i
< p
->cur
[PHY_TYPE_PCS
]; i
++) {
8615 if (p
->phy_port
[PHY_TYPE_PCS
][i
] == port
)
8622 static int count_10g_ports(struct phy_probe_info
*p
, int *lowest
)
8628 for (port
= 8; port
< 32; port
++) {
8629 if (port_has_10g(p
, port
)) {
8639 static int count_1g_ports(struct phy_probe_info
*p
, int *lowest
)
8642 if (p
->cur
[PHY_TYPE_MII
])
8643 *lowest
= p
->phy_port
[PHY_TYPE_MII
][0];
8645 return p
->cur
[PHY_TYPE_MII
];
8648 static void niu_n2_divide_channels(struct niu_parent
*parent
)
8650 int num_ports
= parent
->num_ports
;
8653 for (i
= 0; i
< num_ports
; i
++) {
8654 parent
->rxchan_per_port
[i
] = (16 / num_ports
);
8655 parent
->txchan_per_port
[i
] = (16 / num_ports
);
8657 pr_info("niu%d: Port %u [%u RX chans] [%u TX chans]\n",
8659 parent
->rxchan_per_port
[i
],
8660 parent
->txchan_per_port
[i
]);
8664 static void niu_divide_channels(struct niu_parent
*parent
,
8665 int num_10g
, int num_1g
)
8667 int num_ports
= parent
->num_ports
;
8668 int rx_chans_per_10g
, rx_chans_per_1g
;
8669 int tx_chans_per_10g
, tx_chans_per_1g
;
8670 int i
, tot_rx
, tot_tx
;
8672 if (!num_10g
|| !num_1g
) {
8673 rx_chans_per_10g
= rx_chans_per_1g
=
8674 (NIU_NUM_RXCHAN
/ num_ports
);
8675 tx_chans_per_10g
= tx_chans_per_1g
=
8676 (NIU_NUM_TXCHAN
/ num_ports
);
8678 rx_chans_per_1g
= NIU_NUM_RXCHAN
/ 8;
8679 rx_chans_per_10g
= (NIU_NUM_RXCHAN
-
8680 (rx_chans_per_1g
* num_1g
)) /
8683 tx_chans_per_1g
= NIU_NUM_TXCHAN
/ 6;
8684 tx_chans_per_10g
= (NIU_NUM_TXCHAN
-
8685 (tx_chans_per_1g
* num_1g
)) /
8689 tot_rx
= tot_tx
= 0;
8690 for (i
= 0; i
< num_ports
; i
++) {
8691 int type
= phy_decode(parent
->port_phy
, i
);
8693 if (type
== PORT_TYPE_10G
) {
8694 parent
->rxchan_per_port
[i
] = rx_chans_per_10g
;
8695 parent
->txchan_per_port
[i
] = tx_chans_per_10g
;
8697 parent
->rxchan_per_port
[i
] = rx_chans_per_1g
;
8698 parent
->txchan_per_port
[i
] = tx_chans_per_1g
;
8700 pr_info("niu%d: Port %u [%u RX chans] [%u TX chans]\n",
8702 parent
->rxchan_per_port
[i
],
8703 parent
->txchan_per_port
[i
]);
8704 tot_rx
+= parent
->rxchan_per_port
[i
];
8705 tot_tx
+= parent
->txchan_per_port
[i
];
8708 if (tot_rx
> NIU_NUM_RXCHAN
) {
8709 pr_err("niu%d: Too many RX channels (%d), resetting to one per port\n",
8710 parent
->index
, tot_rx
);
8711 for (i
= 0; i
< num_ports
; i
++)
8712 parent
->rxchan_per_port
[i
] = 1;
8714 if (tot_tx
> NIU_NUM_TXCHAN
) {
8715 pr_err("niu%d: Too many TX channels (%d), resetting to one per port\n",
8716 parent
->index
, tot_tx
);
8717 for (i
= 0; i
< num_ports
; i
++)
8718 parent
->txchan_per_port
[i
] = 1;
8720 if (tot_rx
< NIU_NUM_RXCHAN
|| tot_tx
< NIU_NUM_TXCHAN
) {
8721 pr_warn("niu%d: Driver bug, wasted channels, RX[%d] TX[%d]\n",
8722 parent
->index
, tot_rx
, tot_tx
);
8726 static void niu_divide_rdc_groups(struct niu_parent
*parent
,
8727 int num_10g
, int num_1g
)
8729 int i
, num_ports
= parent
->num_ports
;
8730 int rdc_group
, rdc_groups_per_port
;
8731 int rdc_channel_base
;
8734 rdc_groups_per_port
= NIU_NUM_RDC_TABLES
/ num_ports
;
8736 rdc_channel_base
= 0;
8738 for (i
= 0; i
< num_ports
; i
++) {
8739 struct niu_rdc_tables
*tp
= &parent
->rdc_group_cfg
[i
];
8740 int grp
, num_channels
= parent
->rxchan_per_port
[i
];
8741 int this_channel_offset
;
8743 tp
->first_table_num
= rdc_group
;
8744 tp
->num_tables
= rdc_groups_per_port
;
8745 this_channel_offset
= 0;
8746 for (grp
= 0; grp
< tp
->num_tables
; grp
++) {
8747 struct rdc_table
*rt
= &tp
->tables
[grp
];
8750 pr_info("niu%d: Port %d RDC tbl(%d) [ ",
8751 parent
->index
, i
, tp
->first_table_num
+ grp
);
8752 for (slot
= 0; slot
< NIU_RDC_TABLE_SLOTS
; slot
++) {
8753 rt
->rxdma_channel
[slot
] =
8754 rdc_channel_base
+ this_channel_offset
;
8756 pr_cont("%d ", rt
->rxdma_channel
[slot
]);
8758 if (++this_channel_offset
== num_channels
)
8759 this_channel_offset
= 0;
8764 parent
->rdc_default
[i
] = rdc_channel_base
;
8766 rdc_channel_base
+= num_channels
;
8767 rdc_group
+= rdc_groups_per_port
;
8771 static int fill_phy_probe_info(struct niu
*np
, struct niu_parent
*parent
,
8772 struct phy_probe_info
*info
)
8774 unsigned long flags
;
8777 memset(info
, 0, sizeof(*info
));
8779 /* Port 0 to 7 are reserved for onboard Serdes, probe the rest. */
8780 niu_lock_parent(np
, flags
);
8782 for (port
= 8; port
< 32; port
++) {
8783 int dev_id_1
, dev_id_2
;
8785 dev_id_1
= mdio_read(np
, port
,
8786 NIU_PMA_PMD_DEV_ADDR
, MII_PHYSID1
);
8787 dev_id_2
= mdio_read(np
, port
,
8788 NIU_PMA_PMD_DEV_ADDR
, MII_PHYSID2
);
8789 err
= phy_record(parent
, info
, dev_id_1
, dev_id_2
, port
,
8793 dev_id_1
= mdio_read(np
, port
,
8794 NIU_PCS_DEV_ADDR
, MII_PHYSID1
);
8795 dev_id_2
= mdio_read(np
, port
,
8796 NIU_PCS_DEV_ADDR
, MII_PHYSID2
);
8797 err
= phy_record(parent
, info
, dev_id_1
, dev_id_2
, port
,
8801 dev_id_1
= mii_read(np
, port
, MII_PHYSID1
);
8802 dev_id_2
= mii_read(np
, port
, MII_PHYSID2
);
8803 err
= phy_record(parent
, info
, dev_id_1
, dev_id_2
, port
,
8808 niu_unlock_parent(np
, flags
);
8813 static int walk_phys(struct niu
*np
, struct niu_parent
*parent
)
8815 struct phy_probe_info
*info
= &parent
->phy_probe_info
;
8816 int lowest_10g
, lowest_1g
;
8817 int num_10g
, num_1g
;
8821 num_10g
= num_1g
= 0;
8823 if (!strcmp(np
->vpd
.model
, NIU_ALONSO_MDL_STR
) ||
8824 !strcmp(np
->vpd
.model
, NIU_KIMI_MDL_STR
)) {
8827 parent
->plat_type
= PLAT_TYPE_ATCA_CP3220
;
8828 parent
->num_ports
= 4;
8829 val
= (phy_encode(PORT_TYPE_1G
, 0) |
8830 phy_encode(PORT_TYPE_1G
, 1) |
8831 phy_encode(PORT_TYPE_1G
, 2) |
8832 phy_encode(PORT_TYPE_1G
, 3));
8833 } else if (!strcmp(np
->vpd
.model
, NIU_FOXXY_MDL_STR
)) {
8836 parent
->num_ports
= 2;
8837 val
= (phy_encode(PORT_TYPE_10G
, 0) |
8838 phy_encode(PORT_TYPE_10G
, 1));
8839 } else if ((np
->flags
& NIU_FLAGS_XCVR_SERDES
) &&
8840 (parent
->plat_type
== PLAT_TYPE_NIU
)) {
8841 /* this is the Monza case */
8842 if (np
->flags
& NIU_FLAGS_10G
) {
8843 val
= (phy_encode(PORT_TYPE_10G
, 0) |
8844 phy_encode(PORT_TYPE_10G
, 1));
8846 val
= (phy_encode(PORT_TYPE_1G
, 0) |
8847 phy_encode(PORT_TYPE_1G
, 1));
8850 err
= fill_phy_probe_info(np
, parent
, info
);
8854 num_10g
= count_10g_ports(info
, &lowest_10g
);
8855 num_1g
= count_1g_ports(info
, &lowest_1g
);
8857 switch ((num_10g
<< 4) | num_1g
) {
8859 if (lowest_1g
== 10)
8860 parent
->plat_type
= PLAT_TYPE_VF_P0
;
8861 else if (lowest_1g
== 26)
8862 parent
->plat_type
= PLAT_TYPE_VF_P1
;
8864 goto unknown_vg_1g_port
;
8868 val
= (phy_encode(PORT_TYPE_10G
, 0) |
8869 phy_encode(PORT_TYPE_10G
, 1) |
8870 phy_encode(PORT_TYPE_1G
, 2) |
8871 phy_encode(PORT_TYPE_1G
, 3));
8875 val
= (phy_encode(PORT_TYPE_10G
, 0) |
8876 phy_encode(PORT_TYPE_10G
, 1));
8880 val
= phy_encode(PORT_TYPE_10G
, np
->port
);
8884 if (lowest_1g
== 10)
8885 parent
->plat_type
= PLAT_TYPE_VF_P0
;
8886 else if (lowest_1g
== 26)
8887 parent
->plat_type
= PLAT_TYPE_VF_P1
;
8889 goto unknown_vg_1g_port
;
8893 if ((lowest_10g
& 0x7) == 0)
8894 val
= (phy_encode(PORT_TYPE_10G
, 0) |
8895 phy_encode(PORT_TYPE_1G
, 1) |
8896 phy_encode(PORT_TYPE_1G
, 2) |
8897 phy_encode(PORT_TYPE_1G
, 3));
8899 val
= (phy_encode(PORT_TYPE_1G
, 0) |
8900 phy_encode(PORT_TYPE_10G
, 1) |
8901 phy_encode(PORT_TYPE_1G
, 2) |
8902 phy_encode(PORT_TYPE_1G
, 3));
8906 if (lowest_1g
== 10)
8907 parent
->plat_type
= PLAT_TYPE_VF_P0
;
8908 else if (lowest_1g
== 26)
8909 parent
->plat_type
= PLAT_TYPE_VF_P1
;
8911 goto unknown_vg_1g_port
;
8913 val
= (phy_encode(PORT_TYPE_1G
, 0) |
8914 phy_encode(PORT_TYPE_1G
, 1) |
8915 phy_encode(PORT_TYPE_1G
, 2) |
8916 phy_encode(PORT_TYPE_1G
, 3));
8920 pr_err("Unsupported port config 10G[%d] 1G[%d]\n",
8926 parent
->port_phy
= val
;
8928 if (parent
->plat_type
== PLAT_TYPE_NIU
)
8929 niu_n2_divide_channels(parent
);
8931 niu_divide_channels(parent
, num_10g
, num_1g
);
8933 niu_divide_rdc_groups(parent
, num_10g
, num_1g
);
8938 pr_err("Cannot identify platform type, 1gport=%d\n", lowest_1g
);
8942 static int niu_probe_ports(struct niu
*np
)
8944 struct niu_parent
*parent
= np
->parent
;
8947 if (parent
->port_phy
== PORT_PHY_UNKNOWN
) {
8948 err
= walk_phys(np
, parent
);
8952 niu_set_ldg_timer_res(np
, 2);
8953 for (i
= 0; i
<= LDN_MAX
; i
++)
8954 niu_ldn_irq_enable(np
, i
, 0);
8957 if (parent
->port_phy
== PORT_PHY_INVALID
)
8963 static int niu_classifier_swstate_init(struct niu
*np
)
8965 struct niu_classifier
*cp
= &np
->clas
;
8967 cp
->tcam_top
= (u16
) np
->port
;
8968 cp
->tcam_sz
= np
->parent
->tcam_num_entries
/ np
->parent
->num_ports
;
8969 cp
->h1_init
= 0xffffffff;
8970 cp
->h2_init
= 0xffff;
8972 return fflp_early_init(np
);
8975 static void niu_link_config_init(struct niu
*np
)
8977 struct niu_link_config
*lp
= &np
->link_config
;
8979 lp
->advertising
= (ADVERTISED_10baseT_Half
|
8980 ADVERTISED_10baseT_Full
|
8981 ADVERTISED_100baseT_Half
|
8982 ADVERTISED_100baseT_Full
|
8983 ADVERTISED_1000baseT_Half
|
8984 ADVERTISED_1000baseT_Full
|
8985 ADVERTISED_10000baseT_Full
|
8986 ADVERTISED_Autoneg
);
8987 lp
->speed
= lp
->active_speed
= SPEED_INVALID
;
8988 lp
->duplex
= DUPLEX_FULL
;
8989 lp
->active_duplex
= DUPLEX_INVALID
;
8992 lp
->loopback_mode
= LOOPBACK_MAC
;
8993 lp
->active_speed
= SPEED_10000
;
8994 lp
->active_duplex
= DUPLEX_FULL
;
8996 lp
->loopback_mode
= LOOPBACK_DISABLED
;
9000 static int niu_init_mac_ipp_pcs_base(struct niu
*np
)
9004 np
->mac_regs
= np
->regs
+ XMAC_PORT0_OFF
;
9005 np
->ipp_off
= 0x00000;
9006 np
->pcs_off
= 0x04000;
9007 np
->xpcs_off
= 0x02000;
9011 np
->mac_regs
= np
->regs
+ XMAC_PORT1_OFF
;
9012 np
->ipp_off
= 0x08000;
9013 np
->pcs_off
= 0x0a000;
9014 np
->xpcs_off
= 0x08000;
9018 np
->mac_regs
= np
->regs
+ BMAC_PORT2_OFF
;
9019 np
->ipp_off
= 0x04000;
9020 np
->pcs_off
= 0x0e000;
9021 np
->xpcs_off
= ~0UL;
9025 np
->mac_regs
= np
->regs
+ BMAC_PORT3_OFF
;
9026 np
->ipp_off
= 0x0c000;
9027 np
->pcs_off
= 0x12000;
9028 np
->xpcs_off
= ~0UL;
9032 dev_err(np
->device
, "Port %u is invalid, cannot compute MAC block offset\n", np
->port
);
9039 static void niu_try_msix(struct niu
*np
, u8
*ldg_num_map
)
9041 struct msix_entry msi_vec
[NIU_NUM_LDG
];
9042 struct niu_parent
*parent
= np
->parent
;
9043 struct pci_dev
*pdev
= np
->pdev
;
9047 first_ldg
= (NIU_NUM_LDG
/ parent
->num_ports
) * np
->port
;
9048 for (i
= 0; i
< (NIU_NUM_LDG
/ parent
->num_ports
); i
++)
9049 ldg_num_map
[i
] = first_ldg
+ i
;
9051 num_irqs
= (parent
->rxchan_per_port
[np
->port
] +
9052 parent
->txchan_per_port
[np
->port
] +
9053 (np
->port
== 0 ? 3 : 1));
9054 BUG_ON(num_irqs
> (NIU_NUM_LDG
/ parent
->num_ports
));
9056 for (i
= 0; i
< num_irqs
; i
++) {
9057 msi_vec
[i
].vector
= 0;
9058 msi_vec
[i
].entry
= i
;
9061 num_irqs
= pci_enable_msix_range(pdev
, msi_vec
, 1, num_irqs
);
9063 np
->flags
&= ~NIU_FLAGS_MSIX
;
9067 np
->flags
|= NIU_FLAGS_MSIX
;
9068 for (i
= 0; i
< num_irqs
; i
++)
9069 np
->ldg
[i
].irq
= msi_vec
[i
].vector
;
9070 np
->num_ldg
= num_irqs
;
9073 static int niu_n2_irq_init(struct niu
*np
, u8
*ldg_num_map
)
9075 #ifdef CONFIG_SPARC64
9076 struct platform_device
*op
= np
->op
;
9077 const u32
*int_prop
;
9080 int_prop
= of_get_property(op
->dev
.of_node
, "interrupts", NULL
);
9084 for (i
= 0; i
< op
->archdata
.num_irqs
; i
++) {
9085 ldg_num_map
[i
] = int_prop
[i
];
9086 np
->ldg
[i
].irq
= op
->archdata
.irqs
[i
];
9089 np
->num_ldg
= op
->archdata
.num_irqs
;
9097 static int niu_ldg_init(struct niu
*np
)
9099 struct niu_parent
*parent
= np
->parent
;
9100 u8 ldg_num_map
[NIU_NUM_LDG
];
9101 int first_chan
, num_chan
;
9102 int i
, err
, ldg_rotor
;
9106 np
->ldg
[0].irq
= np
->dev
->irq
;
9107 if (parent
->plat_type
== PLAT_TYPE_NIU
) {
9108 err
= niu_n2_irq_init(np
, ldg_num_map
);
9112 niu_try_msix(np
, ldg_num_map
);
9115 for (i
= 0; i
< np
->num_ldg
; i
++) {
9116 struct niu_ldg
*lp
= &np
->ldg
[i
];
9118 netif_napi_add(np
->dev
, &lp
->napi
, niu_poll
);
9121 lp
->ldg_num
= ldg_num_map
[i
];
9122 lp
->timer
= 2; /* XXX */
9124 /* On N2 NIU the firmware has setup the SID mappings so they go
9125 * to the correct values that will route the LDG to the proper
9126 * interrupt in the NCU interrupt table.
9128 if (np
->parent
->plat_type
!= PLAT_TYPE_NIU
) {
9129 err
= niu_set_ldg_sid(np
, lp
->ldg_num
, port
, i
);
9135 /* We adopt the LDG assignment ordering used by the N2 NIU
9136 * 'interrupt' properties because that simplifies a lot of
9137 * things. This ordering is:
9140 * MIF (if port zero)
9141 * SYSERR (if port zero)
9148 err
= niu_ldg_assign_ldn(np
, parent
, ldg_num_map
[ldg_rotor
],
9154 if (ldg_rotor
== np
->num_ldg
)
9158 err
= niu_ldg_assign_ldn(np
, parent
,
9159 ldg_num_map
[ldg_rotor
],
9165 if (ldg_rotor
== np
->num_ldg
)
9168 err
= niu_ldg_assign_ldn(np
, parent
,
9169 ldg_num_map
[ldg_rotor
],
9175 if (ldg_rotor
== np
->num_ldg
)
9181 for (i
= 0; i
< port
; i
++)
9182 first_chan
+= parent
->rxchan_per_port
[i
];
9183 num_chan
= parent
->rxchan_per_port
[port
];
9185 for (i
= first_chan
; i
< (first_chan
+ num_chan
); i
++) {
9186 err
= niu_ldg_assign_ldn(np
, parent
,
9187 ldg_num_map
[ldg_rotor
],
9192 if (ldg_rotor
== np
->num_ldg
)
9197 for (i
= 0; i
< port
; i
++)
9198 first_chan
+= parent
->txchan_per_port
[i
];
9199 num_chan
= parent
->txchan_per_port
[port
];
9200 for (i
= first_chan
; i
< (first_chan
+ num_chan
); i
++) {
9201 err
= niu_ldg_assign_ldn(np
, parent
,
9202 ldg_num_map
[ldg_rotor
],
9207 if (ldg_rotor
== np
->num_ldg
)
9214 static void niu_ldg_free(struct niu
*np
)
9216 if (np
->flags
& NIU_FLAGS_MSIX
)
9217 pci_disable_msix(np
->pdev
);
9220 static int niu_get_of_props(struct niu
*np
)
9222 #ifdef CONFIG_SPARC64
9223 struct net_device
*dev
= np
->dev
;
9224 struct device_node
*dp
;
9225 const char *phy_type
;
9230 if (np
->parent
->plat_type
== PLAT_TYPE_NIU
)
9231 dp
= np
->op
->dev
.of_node
;
9233 dp
= pci_device_to_OF_node(np
->pdev
);
9235 phy_type
= of_get_property(dp
, "phy-type", NULL
);
9237 netdev_err(dev
, "%pOF: OF node lacks phy-type property\n", dp
);
9241 if (!strcmp(phy_type
, "none"))
9244 strcpy(np
->vpd
.phy_type
, phy_type
);
9246 if (niu_phy_type_prop_decode(np
, np
->vpd
.phy_type
)) {
9247 netdev_err(dev
, "%pOF: Illegal phy string [%s]\n",
9248 dp
, np
->vpd
.phy_type
);
9252 mac_addr
= of_get_property(dp
, "local-mac-address", &prop_len
);
9254 netdev_err(dev
, "%pOF: OF node lacks local-mac-address property\n",
9258 if (prop_len
!= dev
->addr_len
) {
9259 netdev_err(dev
, "%pOF: OF MAC address prop len (%d) is wrong\n",
9262 eth_hw_addr_set(dev
, mac_addr
);
9263 if (!is_valid_ether_addr(&dev
->dev_addr
[0])) {
9264 netdev_err(dev
, "%pOF: OF MAC address is invalid\n", dp
);
9265 netdev_err(dev
, "%pOF: [ %pM ]\n", dp
, dev
->dev_addr
);
9269 model
= of_get_property(dp
, "model", NULL
);
9272 strcpy(np
->vpd
.model
, model
);
9274 if (of_property_read_bool(dp
, "hot-swappable-phy")) {
9275 np
->flags
|= (NIU_FLAGS_10G
| NIU_FLAGS_FIBER
|
9276 NIU_FLAGS_HOTPLUG_PHY
);
9285 static int niu_get_invariants(struct niu
*np
)
9287 int err
, have_props
;
9290 err
= niu_get_of_props(np
);
9296 err
= niu_init_mac_ipp_pcs_base(np
);
9301 err
= niu_get_and_validate_port(np
);
9306 if (np
->parent
->plat_type
== PLAT_TYPE_NIU
)
9309 nw64(ESPC_PIO_EN
, ESPC_PIO_EN_ENABLE
);
9310 offset
= niu_pci_vpd_offset(np
);
9311 netif_printk(np
, probe
, KERN_DEBUG
, np
->dev
,
9312 "%s() VPD offset [%08x]\n", __func__
, offset
);
9314 err
= niu_pci_vpd_fetch(np
, offset
);
9318 nw64(ESPC_PIO_EN
, 0);
9320 if (np
->flags
& NIU_FLAGS_VPD_VALID
) {
9321 niu_pci_vpd_validate(np
);
9322 err
= niu_get_and_validate_port(np
);
9327 if (!(np
->flags
& NIU_FLAGS_VPD_VALID
)) {
9328 err
= niu_get_and_validate_port(np
);
9331 err
= niu_pci_probe_sprom(np
);
9337 err
= niu_probe_ports(np
);
9343 niu_classifier_swstate_init(np
);
9344 niu_link_config_init(np
);
9346 err
= niu_determine_phy_disposition(np
);
9348 err
= niu_init_link(np
);
9353 static LIST_HEAD(niu_parent_list
);
9354 static DEFINE_MUTEX(niu_parent_lock
);
9355 static int niu_parent_index
;
9357 static ssize_t
show_port_phy(struct device
*dev
,
9358 struct device_attribute
*attr
, char *buf
)
9360 struct platform_device
*plat_dev
= to_platform_device(dev
);
9361 struct niu_parent
*p
= dev_get_platdata(&plat_dev
->dev
);
9362 u32 port_phy
= p
->port_phy
;
9363 char *orig_buf
= buf
;
9366 if (port_phy
== PORT_PHY_UNKNOWN
||
9367 port_phy
== PORT_PHY_INVALID
)
9370 for (i
= 0; i
< p
->num_ports
; i
++) {
9371 const char *type_str
;
9374 type
= phy_decode(port_phy
, i
);
9375 if (type
== PORT_TYPE_10G
)
9380 (i
== 0) ? "%s" : " %s",
9383 buf
+= sprintf(buf
, "\n");
9384 return buf
- orig_buf
;
9387 static ssize_t
show_plat_type(struct device
*dev
,
9388 struct device_attribute
*attr
, char *buf
)
9390 struct platform_device
*plat_dev
= to_platform_device(dev
);
9391 struct niu_parent
*p
= dev_get_platdata(&plat_dev
->dev
);
9392 const char *type_str
;
9394 switch (p
->plat_type
) {
9395 case PLAT_TYPE_ATLAS
:
9401 case PLAT_TYPE_VF_P0
:
9404 case PLAT_TYPE_VF_P1
:
9408 type_str
= "unknown";
9412 return sprintf(buf
, "%s\n", type_str
);
9415 static ssize_t
__show_chan_per_port(struct device
*dev
,
9416 struct device_attribute
*attr
, char *buf
,
9419 struct platform_device
*plat_dev
= to_platform_device(dev
);
9420 struct niu_parent
*p
= dev_get_platdata(&plat_dev
->dev
);
9421 char *orig_buf
= buf
;
9425 arr
= (rx
? p
->rxchan_per_port
: p
->txchan_per_port
);
9427 for (i
= 0; i
< p
->num_ports
; i
++) {
9429 (i
== 0) ? "%d" : " %d",
9432 buf
+= sprintf(buf
, "\n");
9434 return buf
- orig_buf
;
9437 static ssize_t
show_rxchan_per_port(struct device
*dev
,
9438 struct device_attribute
*attr
, char *buf
)
9440 return __show_chan_per_port(dev
, attr
, buf
, 1);
9443 static ssize_t
show_txchan_per_port(struct device
*dev
,
9444 struct device_attribute
*attr
, char *buf
)
9446 return __show_chan_per_port(dev
, attr
, buf
, 1);
9449 static ssize_t
show_num_ports(struct device
*dev
,
9450 struct device_attribute
*attr
, char *buf
)
9452 struct platform_device
*plat_dev
= to_platform_device(dev
);
9453 struct niu_parent
*p
= dev_get_platdata(&plat_dev
->dev
);
9455 return sprintf(buf
, "%d\n", p
->num_ports
);
9458 static struct device_attribute niu_parent_attributes
[] = {
9459 __ATTR(port_phy
, 0444, show_port_phy
, NULL
),
9460 __ATTR(plat_type
, 0444, show_plat_type
, NULL
),
9461 __ATTR(rxchan_per_port
, 0444, show_rxchan_per_port
, NULL
),
9462 __ATTR(txchan_per_port
, 0444, show_txchan_per_port
, NULL
),
9463 __ATTR(num_ports
, 0444, show_num_ports
, NULL
),
9467 static struct niu_parent
*niu_new_parent(struct niu
*np
,
9468 union niu_parent_id
*id
, u8 ptype
)
9470 struct platform_device
*plat_dev
;
9471 struct niu_parent
*p
;
9474 plat_dev
= platform_device_register_simple("niu-board", niu_parent_index
,
9476 if (IS_ERR(plat_dev
))
9479 for (i
= 0; niu_parent_attributes
[i
].attr
.name
; i
++) {
9480 int err
= device_create_file(&plat_dev
->dev
,
9481 &niu_parent_attributes
[i
]);
9483 goto fail_unregister
;
9486 p
= kzalloc(sizeof(*p
), GFP_KERNEL
);
9488 goto fail_unregister
;
9490 p
->index
= niu_parent_index
++;
9492 plat_dev
->dev
.platform_data
= p
;
9493 p
->plat_dev
= plat_dev
;
9495 memcpy(&p
->id
, id
, sizeof(*id
));
9496 p
->plat_type
= ptype
;
9497 INIT_LIST_HEAD(&p
->list
);
9498 atomic_set(&p
->refcnt
, 0);
9499 list_add(&p
->list
, &niu_parent_list
);
9500 spin_lock_init(&p
->lock
);
9502 p
->rxdma_clock_divider
= 7500;
9504 p
->tcam_num_entries
= NIU_PCI_TCAM_ENTRIES
;
9505 if (p
->plat_type
== PLAT_TYPE_NIU
)
9506 p
->tcam_num_entries
= NIU_NONPCI_TCAM_ENTRIES
;
9508 for (i
= CLASS_CODE_USER_PROG1
; i
<= CLASS_CODE_SCTP_IPV6
; i
++) {
9509 int index
= i
- CLASS_CODE_USER_PROG1
;
9511 p
->tcam_key
[index
] = TCAM_KEY_TSEL
;
9512 p
->flow_key
[index
] = (FLOW_KEY_IPSA
|
9515 (FLOW_KEY_L4_BYTE12
<<
9516 FLOW_KEY_L4_0_SHIFT
) |
9517 (FLOW_KEY_L4_BYTE12
<<
9518 FLOW_KEY_L4_1_SHIFT
));
9521 for (i
= 0; i
< LDN_MAX
+ 1; i
++)
9522 p
->ldg_map
[i
] = LDG_INVALID
;
9527 platform_device_unregister(plat_dev
);
9531 static struct niu_parent
*niu_get_parent(struct niu
*np
,
9532 union niu_parent_id
*id
, u8 ptype
)
9534 struct niu_parent
*p
, *tmp
;
9535 int port
= np
->port
;
9537 mutex_lock(&niu_parent_lock
);
9539 list_for_each_entry(tmp
, &niu_parent_list
, list
) {
9540 if (!memcmp(id
, &tmp
->id
, sizeof(*id
))) {
9546 p
= niu_new_parent(np
, id
, ptype
);
9552 sprintf(port_name
, "port%d", port
);
9553 err
= sysfs_create_link(&p
->plat_dev
->dev
.kobj
,
9557 p
->ports
[port
] = np
;
9558 atomic_inc(&p
->refcnt
);
9561 mutex_unlock(&niu_parent_lock
);
9566 static void niu_put_parent(struct niu
*np
)
9568 struct niu_parent
*p
= np
->parent
;
9572 BUG_ON(!p
|| p
->ports
[port
] != np
);
9574 netif_printk(np
, probe
, KERN_DEBUG
, np
->dev
,
9575 "%s() port[%u]\n", __func__
, port
);
9577 sprintf(port_name
, "port%d", port
);
9579 mutex_lock(&niu_parent_lock
);
9581 sysfs_remove_link(&p
->plat_dev
->dev
.kobj
, port_name
);
9583 p
->ports
[port
] = NULL
;
9586 if (atomic_dec_and_test(&p
->refcnt
)) {
9588 platform_device_unregister(p
->plat_dev
);
9591 mutex_unlock(&niu_parent_lock
);
9594 static void *niu_pci_alloc_coherent(struct device
*dev
, size_t size
,
9595 u64
*handle
, gfp_t flag
)
9600 ret
= dma_alloc_coherent(dev
, size
, &dh
, flag
);
9606 static void niu_pci_free_coherent(struct device
*dev
, size_t size
,
9607 void *cpu_addr
, u64 handle
)
9609 dma_free_coherent(dev
, size
, cpu_addr
, handle
);
9612 static u64
niu_pci_map_page(struct device
*dev
, struct page
*page
,
9613 unsigned long offset
, size_t size
,
9614 enum dma_data_direction direction
)
9616 return dma_map_page(dev
, page
, offset
, size
, direction
);
9619 static void niu_pci_unmap_page(struct device
*dev
, u64 dma_address
,
9620 size_t size
, enum dma_data_direction direction
)
9622 dma_unmap_page(dev
, dma_address
, size
, direction
);
9625 static u64
niu_pci_map_single(struct device
*dev
, void *cpu_addr
,
9627 enum dma_data_direction direction
)
9629 return dma_map_single(dev
, cpu_addr
, size
, direction
);
9632 static void niu_pci_unmap_single(struct device
*dev
, u64 dma_address
,
9634 enum dma_data_direction direction
)
9636 dma_unmap_single(dev
, dma_address
, size
, direction
);
9639 static const struct niu_ops niu_pci_ops
= {
9640 .alloc_coherent
= niu_pci_alloc_coherent
,
9641 .free_coherent
= niu_pci_free_coherent
,
9642 .map_page
= niu_pci_map_page
,
9643 .unmap_page
= niu_pci_unmap_page
,
9644 .map_single
= niu_pci_map_single
,
9645 .unmap_single
= niu_pci_unmap_single
,
9648 static void niu_driver_version(void)
9650 static int niu_version_printed
;
9652 if (niu_version_printed
++ == 0)
9653 pr_info("%s", version
);
9656 static struct net_device
*niu_alloc_and_init(struct device
*gen_dev
,
9657 struct pci_dev
*pdev
,
9658 struct platform_device
*op
,
9659 const struct niu_ops
*ops
, u8 port
)
9661 struct net_device
*dev
;
9664 dev
= alloc_etherdev_mq(sizeof(struct niu
), NIU_NUM_TXCHAN
);
9668 SET_NETDEV_DEV(dev
, gen_dev
);
9670 np
= netdev_priv(dev
);
9674 np
->device
= gen_dev
;
9677 np
->msg_enable
= niu_debug
;
9679 spin_lock_init(&np
->lock
);
9680 INIT_WORK(&np
->reset_task
, niu_reset_task
);
9687 static const struct net_device_ops niu_netdev_ops
= {
9688 .ndo_open
= niu_open
,
9689 .ndo_stop
= niu_close
,
9690 .ndo_start_xmit
= niu_start_xmit
,
9691 .ndo_get_stats64
= niu_get_stats
,
9692 .ndo_set_rx_mode
= niu_set_rx_mode
,
9693 .ndo_validate_addr
= eth_validate_addr
,
9694 .ndo_set_mac_address
= niu_set_mac_addr
,
9695 .ndo_eth_ioctl
= niu_ioctl
,
9696 .ndo_tx_timeout
= niu_tx_timeout
,
9697 .ndo_change_mtu
= niu_change_mtu
,
9700 static void niu_assign_netdev_ops(struct net_device
*dev
)
9702 dev
->netdev_ops
= &niu_netdev_ops
;
9703 dev
->ethtool_ops
= &niu_ethtool_ops
;
9704 dev
->watchdog_timeo
= NIU_TX_TIMEOUT
;
9707 static void niu_device_announce(struct niu
*np
)
9709 struct net_device
*dev
= np
->dev
;
9711 pr_info("%s: NIU Ethernet %pM\n", dev
->name
, dev
->dev_addr
);
9713 if (np
->parent
->plat_type
== PLAT_TYPE_ATCA_CP3220
) {
9714 pr_info("%s: Port type[%s] mode[%s:%s] XCVR[%s] phy[%s]\n",
9716 (np
->flags
& NIU_FLAGS_XMAC
? "XMAC" : "BMAC"),
9717 (np
->flags
& NIU_FLAGS_10G
? "10G" : "1G"),
9718 (np
->flags
& NIU_FLAGS_FIBER
? "RGMII FIBER" : "SERDES"),
9719 (np
->mac_xcvr
== MAC_XCVR_MII
? "MII" :
9720 (np
->mac_xcvr
== MAC_XCVR_PCS
? "PCS" : "XPCS")),
9723 pr_info("%s: Port type[%s] mode[%s:%s] XCVR[%s] phy[%s]\n",
9725 (np
->flags
& NIU_FLAGS_XMAC
? "XMAC" : "BMAC"),
9726 (np
->flags
& NIU_FLAGS_10G
? "10G" : "1G"),
9727 (np
->flags
& NIU_FLAGS_FIBER
? "FIBER" :
9728 (np
->flags
& NIU_FLAGS_XCVR_SERDES
? "SERDES" :
9730 (np
->mac_xcvr
== MAC_XCVR_MII
? "MII" :
9731 (np
->mac_xcvr
== MAC_XCVR_PCS
? "PCS" : "XPCS")),
9736 static void niu_set_basic_features(struct net_device
*dev
)
9738 dev
->hw_features
= NETIF_F_SG
| NETIF_F_HW_CSUM
| NETIF_F_RXHASH
;
9739 dev
->features
|= dev
->hw_features
| NETIF_F_RXCSUM
;
9742 static int niu_pci_init_one(struct pci_dev
*pdev
,
9743 const struct pci_device_id
*ent
)
9745 union niu_parent_id parent_id
;
9746 struct net_device
*dev
;
9750 niu_driver_version();
9752 err
= pci_enable_device(pdev
);
9754 dev_err(&pdev
->dev
, "Cannot enable PCI device, aborting\n");
9758 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
) ||
9759 !(pci_resource_flags(pdev
, 2) & IORESOURCE_MEM
)) {
9760 dev_err(&pdev
->dev
, "Cannot find proper PCI device base addresses, aborting\n");
9762 goto err_out_disable_pdev
;
9765 err
= pci_request_regions(pdev
, DRV_MODULE_NAME
);
9767 dev_err(&pdev
->dev
, "Cannot obtain PCI resources, aborting\n");
9768 goto err_out_disable_pdev
;
9771 if (!pci_is_pcie(pdev
)) {
9772 dev_err(&pdev
->dev
, "Cannot find PCI Express capability, aborting\n");
9774 goto err_out_free_res
;
9777 dev
= niu_alloc_and_init(&pdev
->dev
, pdev
, NULL
,
9778 &niu_pci_ops
, PCI_FUNC(pdev
->devfn
));
9781 goto err_out_free_res
;
9783 np
= netdev_priv(dev
);
9785 memset(&parent_id
, 0, sizeof(parent_id
));
9786 parent_id
.pci
.domain
= pci_domain_nr(pdev
->bus
);
9787 parent_id
.pci
.bus
= pdev
->bus
->number
;
9788 parent_id
.pci
.device
= PCI_SLOT(pdev
->devfn
);
9790 np
->parent
= niu_get_parent(np
, &parent_id
,
9794 goto err_out_free_dev
;
9797 pcie_capability_clear_and_set_word(pdev
, PCI_EXP_DEVCTL
,
9798 PCI_EXP_DEVCTL_NOSNOOP_EN
,
9799 PCI_EXP_DEVCTL_CERE
| PCI_EXP_DEVCTL_NFERE
|
9800 PCI_EXP_DEVCTL_FERE
| PCI_EXP_DEVCTL_URRE
|
9801 PCI_EXP_DEVCTL_RELAX_EN
);
9803 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(44));
9805 dev
->features
|= NETIF_F_HIGHDMA
;
9807 err
= dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(32));
9809 dev_err(&pdev
->dev
, "No usable DMA configuration, aborting\n");
9810 goto err_out_release_parent
;
9814 niu_set_basic_features(dev
);
9816 dev
->priv_flags
|= IFF_UNICAST_FLT
;
9818 np
->regs
= pci_ioremap_bar(pdev
, 0);
9820 dev_err(&pdev
->dev
, "Cannot map device registers, aborting\n");
9822 goto err_out_release_parent
;
9825 pci_set_master(pdev
);
9826 pci_save_state(pdev
);
9828 dev
->irq
= pdev
->irq
;
9830 /* MTU range: 68 - 9216 */
9831 dev
->min_mtu
= ETH_MIN_MTU
;
9832 dev
->max_mtu
= NIU_MAX_MTU
;
9834 niu_assign_netdev_ops(dev
);
9836 err
= niu_get_invariants(np
);
9839 dev_err(&pdev
->dev
, "Problem fetching invariants of chip, aborting\n");
9840 goto err_out_iounmap
;
9843 err
= register_netdev(dev
);
9845 dev_err(&pdev
->dev
, "Cannot register net device, aborting\n");
9846 goto err_out_iounmap
;
9849 pci_set_drvdata(pdev
, dev
);
9851 niu_device_announce(np
);
9861 err_out_release_parent
:
9868 pci_release_regions(pdev
);
9870 err_out_disable_pdev
:
9871 pci_disable_device(pdev
);
9876 static void niu_pci_remove_one(struct pci_dev
*pdev
)
9878 struct net_device
*dev
= pci_get_drvdata(pdev
);
9881 struct niu
*np
= netdev_priv(dev
);
9883 unregister_netdev(dev
);
9894 pci_release_regions(pdev
);
9895 pci_disable_device(pdev
);
9899 static int __maybe_unused
niu_suspend(struct device
*dev_d
)
9901 struct net_device
*dev
= dev_get_drvdata(dev_d
);
9902 struct niu
*np
= netdev_priv(dev
);
9903 unsigned long flags
;
9905 if (!netif_running(dev
))
9908 flush_work(&np
->reset_task
);
9911 del_timer_sync(&np
->timer
);
9913 spin_lock_irqsave(&np
->lock
, flags
);
9914 niu_enable_interrupts(np
, 0);
9915 spin_unlock_irqrestore(&np
->lock
, flags
);
9917 netif_device_detach(dev
);
9919 spin_lock_irqsave(&np
->lock
, flags
);
9921 spin_unlock_irqrestore(&np
->lock
, flags
);
9926 static int __maybe_unused
niu_resume(struct device
*dev_d
)
9928 struct net_device
*dev
= dev_get_drvdata(dev_d
);
9929 struct niu
*np
= netdev_priv(dev
);
9930 unsigned long flags
;
9933 if (!netif_running(dev
))
9936 netif_device_attach(dev
);
9938 spin_lock_irqsave(&np
->lock
, flags
);
9940 err
= niu_init_hw(np
);
9942 np
->timer
.expires
= jiffies
+ HZ
;
9943 add_timer(&np
->timer
);
9944 niu_netif_start(np
);
9947 spin_unlock_irqrestore(&np
->lock
, flags
);
9952 static SIMPLE_DEV_PM_OPS(niu_pm_ops
, niu_suspend
, niu_resume
);
9954 static struct pci_driver niu_pci_driver
= {
9955 .name
= DRV_MODULE_NAME
,
9956 .id_table
= niu_pci_tbl
,
9957 .probe
= niu_pci_init_one
,
9958 .remove
= niu_pci_remove_one
,
9959 .driver
.pm
= &niu_pm_ops
,
9962 #ifdef CONFIG_SPARC64
9963 static void *niu_phys_alloc_coherent(struct device
*dev
, size_t size
,
9964 u64
*dma_addr
, gfp_t flag
)
9966 unsigned long order
= get_order(size
);
9967 unsigned long page
= __get_free_pages(flag
, order
);
9971 memset((char *)page
, 0, PAGE_SIZE
<< order
);
9972 *dma_addr
= __pa(page
);
9974 return (void *) page
;
9977 static void niu_phys_free_coherent(struct device
*dev
, size_t size
,
9978 void *cpu_addr
, u64 handle
)
9980 unsigned long order
= get_order(size
);
9982 free_pages((unsigned long) cpu_addr
, order
);
9985 static u64
niu_phys_map_page(struct device
*dev
, struct page
*page
,
9986 unsigned long offset
, size_t size
,
9987 enum dma_data_direction direction
)
9989 return page_to_phys(page
) + offset
;
9992 static void niu_phys_unmap_page(struct device
*dev
, u64 dma_address
,
9993 size_t size
, enum dma_data_direction direction
)
9995 /* Nothing to do. */
9998 static u64
niu_phys_map_single(struct device
*dev
, void *cpu_addr
,
10000 enum dma_data_direction direction
)
10002 return __pa(cpu_addr
);
10005 static void niu_phys_unmap_single(struct device
*dev
, u64 dma_address
,
10007 enum dma_data_direction direction
)
10009 /* Nothing to do. */
10012 static const struct niu_ops niu_phys_ops
= {
10013 .alloc_coherent
= niu_phys_alloc_coherent
,
10014 .free_coherent
= niu_phys_free_coherent
,
10015 .map_page
= niu_phys_map_page
,
10016 .unmap_page
= niu_phys_unmap_page
,
10017 .map_single
= niu_phys_map_single
,
10018 .unmap_single
= niu_phys_unmap_single
,
10021 static int niu_of_probe(struct platform_device
*op
)
10023 union niu_parent_id parent_id
;
10024 struct net_device
*dev
;
10029 niu_driver_version();
10031 reg
= of_get_property(op
->dev
.of_node
, "reg", NULL
);
10033 dev_err(&op
->dev
, "%pOF: No 'reg' property, aborting\n",
10038 dev
= niu_alloc_and_init(&op
->dev
, NULL
, op
,
10039 &niu_phys_ops
, reg
[0] & 0x1);
10044 np
= netdev_priv(dev
);
10046 memset(&parent_id
, 0, sizeof(parent_id
));
10047 parent_id
.of
= of_get_parent(op
->dev
.of_node
);
10049 np
->parent
= niu_get_parent(np
, &parent_id
,
10053 goto err_out_free_dev
;
10056 niu_set_basic_features(dev
);
10058 np
->regs
= of_ioremap(&op
->resource
[1], 0,
10059 resource_size(&op
->resource
[1]),
10062 dev_err(&op
->dev
, "Cannot map device registers, aborting\n");
10064 goto err_out_release_parent
;
10067 np
->vir_regs_1
= of_ioremap(&op
->resource
[2], 0,
10068 resource_size(&op
->resource
[2]),
10070 if (!np
->vir_regs_1
) {
10071 dev_err(&op
->dev
, "Cannot map device vir registers 1, aborting\n");
10073 goto err_out_iounmap
;
10076 np
->vir_regs_2
= of_ioremap(&op
->resource
[3], 0,
10077 resource_size(&op
->resource
[3]),
10079 if (!np
->vir_regs_2
) {
10080 dev_err(&op
->dev
, "Cannot map device vir registers 2, aborting\n");
10082 goto err_out_iounmap
;
10085 niu_assign_netdev_ops(dev
);
10087 err
= niu_get_invariants(np
);
10089 if (err
!= -ENODEV
)
10090 dev_err(&op
->dev
, "Problem fetching invariants of chip, aborting\n");
10091 goto err_out_iounmap
;
10094 err
= register_netdev(dev
);
10096 dev_err(&op
->dev
, "Cannot register net device, aborting\n");
10097 goto err_out_iounmap
;
10100 platform_set_drvdata(op
, dev
);
10102 niu_device_announce(np
);
10107 if (np
->vir_regs_1
) {
10108 of_iounmap(&op
->resource
[2], np
->vir_regs_1
,
10109 resource_size(&op
->resource
[2]));
10110 np
->vir_regs_1
= NULL
;
10113 if (np
->vir_regs_2
) {
10114 of_iounmap(&op
->resource
[3], np
->vir_regs_2
,
10115 resource_size(&op
->resource
[3]));
10116 np
->vir_regs_2
= NULL
;
10120 of_iounmap(&op
->resource
[1], np
->regs
,
10121 resource_size(&op
->resource
[1]));
10125 err_out_release_parent
:
10126 niu_put_parent(np
);
10135 static void niu_of_remove(struct platform_device
*op
)
10137 struct net_device
*dev
= platform_get_drvdata(op
);
10140 struct niu
*np
= netdev_priv(dev
);
10142 unregister_netdev(dev
);
10144 if (np
->vir_regs_1
) {
10145 of_iounmap(&op
->resource
[2], np
->vir_regs_1
,
10146 resource_size(&op
->resource
[2]));
10147 np
->vir_regs_1
= NULL
;
10150 if (np
->vir_regs_2
) {
10151 of_iounmap(&op
->resource
[3], np
->vir_regs_2
,
10152 resource_size(&op
->resource
[3]));
10153 np
->vir_regs_2
= NULL
;
10157 of_iounmap(&op
->resource
[1], np
->regs
,
10158 resource_size(&op
->resource
[1]));
10164 niu_put_parent(np
);
10170 static const struct of_device_id niu_match
[] = {
10173 .compatible
= "SUNW,niusl",
10177 MODULE_DEVICE_TABLE(of
, niu_match
);
10179 static struct platform_driver niu_of_driver
= {
10182 .of_match_table
= niu_match
,
10184 .probe
= niu_of_probe
,
10185 .remove
= niu_of_remove
,
10188 #endif /* CONFIG_SPARC64 */
10190 static int __init
niu_init(void)
10194 BUILD_BUG_ON(PAGE_SIZE
< 4 * 1024);
10196 BUILD_BUG_ON(offsetof(struct page
, mapping
) !=
10197 offsetof(union niu_page
, next
));
10199 niu_debug
= netif_msg_init(debug
, NIU_MSG_DEFAULT
);
10201 #ifdef CONFIG_SPARC64
10202 err
= platform_driver_register(&niu_of_driver
);
10206 err
= pci_register_driver(&niu_pci_driver
);
10207 #ifdef CONFIG_SPARC64
10209 platform_driver_unregister(&niu_of_driver
);
10216 static void __exit
niu_exit(void)
10218 pci_unregister_driver(&niu_pci_driver
);
10219 #ifdef CONFIG_SPARC64
10220 platform_driver_unregister(&niu_of_driver
);
10224 module_init(niu_init
);
10225 module_exit(niu_exit
);