1 /* niu.c: Neptune ethernet driver.
3 * Copyright (C) 2007 David S. Miller (davem@davemloft.net)
6 #include <linux/module.h>
7 #include <linux/init.h>
9 #include <linux/dma-mapping.h>
10 #include <linux/netdevice.h>
11 #include <linux/ethtool.h>
12 #include <linux/etherdevice.h>
13 #include <linux/platform_device.h>
14 #include <linux/delay.h>
15 #include <linux/bitops.h>
16 #include <linux/mii.h>
17 #include <linux/if_ether.h>
18 #include <linux/if_vlan.h>
21 #include <linux/ipv6.h>
22 #include <linux/log2.h>
23 #include <linux/jiffies.h>
24 #include <linux/crc32.h>
29 #include <linux/of_device.h>
34 #define DRV_MODULE_NAME "niu"
35 #define PFX DRV_MODULE_NAME ": "
36 #define DRV_MODULE_VERSION "0.7"
37 #define DRV_MODULE_RELDATE "February 18, 2008"
39 static char version
[] __devinitdata
=
40 DRV_MODULE_NAME
".c:v" DRV_MODULE_VERSION
" (" DRV_MODULE_RELDATE
")\n";
42 MODULE_AUTHOR("David S. Miller (davem@davemloft.net)");
43 MODULE_DESCRIPTION("NIU ethernet driver");
44 MODULE_LICENSE("GPL");
45 MODULE_VERSION(DRV_MODULE_VERSION
);
47 #ifndef DMA_44BIT_MASK
48 #define DMA_44BIT_MASK 0x00000fffffffffffULL
52 static u64
readq(void __iomem
*reg
)
54 return (((u64
)readl(reg
+ 0x4UL
) << 32) |
58 static void writeq(u64 val
, void __iomem
*reg
)
60 writel(val
& 0xffffffff, reg
);
61 writel(val
>> 32, reg
+ 0x4UL
);
65 static struct pci_device_id niu_pci_tbl
[] = {
66 {PCI_DEVICE(PCI_VENDOR_ID_SUN
, 0xabcd)},
70 MODULE_DEVICE_TABLE(pci
, niu_pci_tbl
);
72 #define NIU_TX_TIMEOUT (5 * HZ)
74 #define nr64(reg) readq(np->regs + (reg))
75 #define nw64(reg, val) writeq((val), np->regs + (reg))
77 #define nr64_mac(reg) readq(np->mac_regs + (reg))
78 #define nw64_mac(reg, val) writeq((val), np->mac_regs + (reg))
80 #define nr64_ipp(reg) readq(np->regs + np->ipp_off + (reg))
81 #define nw64_ipp(reg, val) writeq((val), np->regs + np->ipp_off + (reg))
83 #define nr64_pcs(reg) readq(np->regs + np->pcs_off + (reg))
84 #define nw64_pcs(reg, val) writeq((val), np->regs + np->pcs_off + (reg))
86 #define nr64_xpcs(reg) readq(np->regs + np->xpcs_off + (reg))
87 #define nw64_xpcs(reg, val) writeq((val), np->regs + np->xpcs_off + (reg))
89 #define NIU_MSG_DEFAULT (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
92 static int debug
= -1;
93 module_param(debug
, int, 0);
94 MODULE_PARM_DESC(debug
, "NIU debug level");
96 #define niudbg(TYPE, f, a...) \
97 do { if ((np)->msg_enable & NETIF_MSG_##TYPE) \
98 printk(KERN_DEBUG PFX f, ## a); \
101 #define niuinfo(TYPE, f, a...) \
102 do { if ((np)->msg_enable & NETIF_MSG_##TYPE) \
103 printk(KERN_INFO PFX f, ## a); \
106 #define niuwarn(TYPE, f, a...) \
107 do { if ((np)->msg_enable & NETIF_MSG_##TYPE) \
108 printk(KERN_WARNING PFX f, ## a); \
111 #define niu_lock_parent(np, flags) \
112 spin_lock_irqsave(&np->parent->lock, flags)
113 #define niu_unlock_parent(np, flags) \
114 spin_unlock_irqrestore(&np->parent->lock, flags)
116 static int serdes_init_10g_serdes(struct niu
*np
);
118 static int __niu_wait_bits_clear_mac(struct niu
*np
, unsigned long reg
,
119 u64 bits
, int limit
, int delay
)
121 while (--limit
>= 0) {
122 u64 val
= nr64_mac(reg
);
133 static int __niu_set_and_wait_clear_mac(struct niu
*np
, unsigned long reg
,
134 u64 bits
, int limit
, int delay
,
135 const char *reg_name
)
140 err
= __niu_wait_bits_clear_mac(np
, reg
, bits
, limit
, delay
);
142 dev_err(np
->device
, PFX
"%s: bits (%llx) of register %s "
143 "would not clear, val[%llx]\n",
144 np
->dev
->name
, (unsigned long long) bits
, reg_name
,
145 (unsigned long long) nr64_mac(reg
));
149 #define niu_set_and_wait_clear_mac(NP, REG, BITS, LIMIT, DELAY, REG_NAME) \
150 ({ BUILD_BUG_ON(LIMIT <= 0 || DELAY < 0); \
151 __niu_set_and_wait_clear_mac(NP, REG, BITS, LIMIT, DELAY, REG_NAME); \
154 static int __niu_wait_bits_clear_ipp(struct niu
*np
, unsigned long reg
,
155 u64 bits
, int limit
, int delay
)
157 while (--limit
>= 0) {
158 u64 val
= nr64_ipp(reg
);
169 static int __niu_set_and_wait_clear_ipp(struct niu
*np
, unsigned long reg
,
170 u64 bits
, int limit
, int delay
,
171 const char *reg_name
)
180 err
= __niu_wait_bits_clear_ipp(np
, reg
, bits
, limit
, delay
);
182 dev_err(np
->device
, PFX
"%s: bits (%llx) of register %s "
183 "would not clear, val[%llx]\n",
184 np
->dev
->name
, (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 dev_err(np
->device
, PFX
"%s: bits (%llx) of register %s "
224 "would not clear, val[%llx]\n",
225 np
->dev
->name
, (unsigned long long) bits
, reg_name
,
226 (unsigned long long) nr64(reg
));
230 #define niu_set_and_wait_clear(NP, REG, BITS, LIMIT, DELAY, REG_NAME) \
231 ({ BUILD_BUG_ON(LIMIT <= 0 || DELAY < 0); \
232 __niu_set_and_wait_clear(NP, REG, BITS, LIMIT, DELAY, REG_NAME); \
235 static void niu_ldg_rearm(struct niu
*np
, struct niu_ldg
*lp
, int on
)
237 u64 val
= (u64
) lp
->timer
;
240 val
|= LDG_IMGMT_ARM
;
242 nw64(LDG_IMGMT(lp
->ldg_num
), val
);
245 static int niu_ldn_irq_enable(struct niu
*np
, int ldn
, int on
)
247 unsigned long mask_reg
, bits
;
250 if (ldn
< 0 || ldn
> LDN_MAX
)
254 mask_reg
= LD_IM0(ldn
);
257 mask_reg
= LD_IM1(ldn
- 64);
261 val
= nr64(mask_reg
);
271 static int niu_enable_ldn_in_ldg(struct niu
*np
, struct niu_ldg
*lp
, int on
)
273 struct niu_parent
*parent
= np
->parent
;
276 for (i
= 0; i
<= LDN_MAX
; i
++) {
279 if (parent
->ldg_map
[i
] != lp
->ldg_num
)
282 err
= niu_ldn_irq_enable(np
, i
, on
);
289 static int niu_enable_interrupts(struct niu
*np
, int on
)
293 for (i
= 0; i
< np
->num_ldg
; i
++) {
294 struct niu_ldg
*lp
= &np
->ldg
[i
];
297 err
= niu_enable_ldn_in_ldg(np
, lp
, on
);
301 for (i
= 0; i
< np
->num_ldg
; i
++)
302 niu_ldg_rearm(np
, &np
->ldg
[i
], on
);
307 static u32
phy_encode(u32 type
, int port
)
309 return (type
<< (port
* 2));
312 static u32
phy_decode(u32 val
, int port
)
314 return (val
>> (port
* 2)) & PORT_TYPE_MASK
;
317 static int mdio_wait(struct niu
*np
)
322 while (--limit
> 0) {
323 val
= nr64(MIF_FRAME_OUTPUT
);
324 if ((val
>> MIF_FRAME_OUTPUT_TA_SHIFT
) & 0x1)
325 return val
& MIF_FRAME_OUTPUT_DATA
;
333 static int mdio_read(struct niu
*np
, int port
, int dev
, int reg
)
337 nw64(MIF_FRAME_OUTPUT
, MDIO_ADDR_OP(port
, dev
, reg
));
342 nw64(MIF_FRAME_OUTPUT
, MDIO_READ_OP(port
, dev
));
343 return mdio_wait(np
);
346 static int mdio_write(struct niu
*np
, int port
, int dev
, int reg
, int data
)
350 nw64(MIF_FRAME_OUTPUT
, MDIO_ADDR_OP(port
, dev
, reg
));
355 nw64(MIF_FRAME_OUTPUT
, MDIO_WRITE_OP(port
, dev
, data
));
363 static int mii_read(struct niu
*np
, int port
, int reg
)
365 nw64(MIF_FRAME_OUTPUT
, MII_READ_OP(port
, reg
));
366 return mdio_wait(np
);
369 static int mii_write(struct niu
*np
, int port
, int reg
, int data
)
373 nw64(MIF_FRAME_OUTPUT
, MII_WRITE_OP(port
, reg
, data
));
381 static int esr2_set_tx_cfg(struct niu
*np
, unsigned long channel
, u32 val
)
385 err
= mdio_write(np
, np
->port
, NIU_ESR2_DEV_ADDR
,
386 ESR2_TI_PLL_TX_CFG_L(channel
),
389 err
= mdio_write(np
, np
->port
, NIU_ESR2_DEV_ADDR
,
390 ESR2_TI_PLL_TX_CFG_H(channel
),
395 static int esr2_set_rx_cfg(struct niu
*np
, unsigned long channel
, u32 val
)
399 err
= mdio_write(np
, np
->port
, NIU_ESR2_DEV_ADDR
,
400 ESR2_TI_PLL_RX_CFG_L(channel
),
403 err
= mdio_write(np
, np
->port
, NIU_ESR2_DEV_ADDR
,
404 ESR2_TI_PLL_RX_CFG_H(channel
),
409 /* Mode is always 10G fiber. */
410 static int serdes_init_niu(struct niu
*np
)
412 struct niu_link_config
*lp
= &np
->link_config
;
416 tx_cfg
= (PLL_TX_CFG_ENTX
| PLL_TX_CFG_SWING_1375MV
);
417 rx_cfg
= (PLL_RX_CFG_ENRX
| PLL_RX_CFG_TERM_0P8VDDT
|
418 PLL_RX_CFG_ALIGN_ENA
| PLL_RX_CFG_LOS_LTHRESH
|
419 PLL_RX_CFG_EQ_LP_ADAPTIVE
);
421 if (lp
->loopback_mode
== LOOPBACK_PHY
) {
422 u16 test_cfg
= PLL_TEST_CFG_LOOPBACK_CML_DIS
;
424 mdio_write(np
, np
->port
, NIU_ESR2_DEV_ADDR
,
425 ESR2_TI_PLL_TEST_CFG_L
, test_cfg
);
427 tx_cfg
|= PLL_TX_CFG_ENTEST
;
428 rx_cfg
|= PLL_RX_CFG_ENTEST
;
431 /* Initialize all 4 lanes of the SERDES. */
432 for (i
= 0; i
< 4; i
++) {
433 int err
= esr2_set_tx_cfg(np
, i
, tx_cfg
);
438 for (i
= 0; i
< 4; i
++) {
439 int err
= esr2_set_rx_cfg(np
, i
, rx_cfg
);
447 static int esr_read_rxtx_ctrl(struct niu
*np
, unsigned long chan
, u32
*val
)
451 err
= mdio_read(np
, np
->port
, NIU_ESR_DEV_ADDR
, ESR_RXTX_CTRL_L(chan
));
453 *val
= (err
& 0xffff);
454 err
= mdio_read(np
, np
->port
, NIU_ESR_DEV_ADDR
,
455 ESR_RXTX_CTRL_H(chan
));
457 *val
|= ((err
& 0xffff) << 16);
463 static int esr_read_glue0(struct niu
*np
, unsigned long chan
, u32
*val
)
467 err
= mdio_read(np
, np
->port
, NIU_ESR_DEV_ADDR
,
468 ESR_GLUE_CTRL0_L(chan
));
470 *val
= (err
& 0xffff);
471 err
= mdio_read(np
, np
->port
, NIU_ESR_DEV_ADDR
,
472 ESR_GLUE_CTRL0_H(chan
));
474 *val
|= ((err
& 0xffff) << 16);
481 static int esr_read_reset(struct niu
*np
, u32
*val
)
485 err
= mdio_read(np
, np
->port
, NIU_ESR_DEV_ADDR
,
486 ESR_RXTX_RESET_CTRL_L
);
488 *val
= (err
& 0xffff);
489 err
= mdio_read(np
, np
->port
, NIU_ESR_DEV_ADDR
,
490 ESR_RXTX_RESET_CTRL_H
);
492 *val
|= ((err
& 0xffff) << 16);
499 static int esr_write_rxtx_ctrl(struct niu
*np
, unsigned long chan
, u32 val
)
503 err
= mdio_write(np
, np
->port
, NIU_ESR_DEV_ADDR
,
504 ESR_RXTX_CTRL_L(chan
), val
& 0xffff);
506 err
= mdio_write(np
, np
->port
, NIU_ESR_DEV_ADDR
,
507 ESR_RXTX_CTRL_H(chan
), (val
>> 16));
511 static int esr_write_glue0(struct niu
*np
, unsigned long chan
, u32 val
)
515 err
= mdio_write(np
, np
->port
, NIU_ESR_DEV_ADDR
,
516 ESR_GLUE_CTRL0_L(chan
), val
& 0xffff);
518 err
= mdio_write(np
, np
->port
, NIU_ESR_DEV_ADDR
,
519 ESR_GLUE_CTRL0_H(chan
), (val
>> 16));
523 static int esr_reset(struct niu
*np
)
528 err
= mdio_write(np
, np
->port
, NIU_ESR_DEV_ADDR
,
529 ESR_RXTX_RESET_CTRL_L
, 0x0000);
532 err
= mdio_write(np
, np
->port
, NIU_ESR_DEV_ADDR
,
533 ESR_RXTX_RESET_CTRL_H
, 0xffff);
538 err
= mdio_write(np
, np
->port
, NIU_ESR_DEV_ADDR
,
539 ESR_RXTX_RESET_CTRL_L
, 0xffff);
544 err
= mdio_write(np
, np
->port
, NIU_ESR_DEV_ADDR
,
545 ESR_RXTX_RESET_CTRL_H
, 0x0000);
550 err
= esr_read_reset(np
, &reset
);
554 dev_err(np
->device
, PFX
"Port %u ESR_RESET "
555 "did not clear [%08x]\n",
563 static int serdes_init_10g(struct niu
*np
)
565 struct niu_link_config
*lp
= &np
->link_config
;
566 unsigned long ctrl_reg
, test_cfg_reg
, i
;
567 u64 ctrl_val
, test_cfg_val
, sig
, mask
, val
;
572 ctrl_reg
= ENET_SERDES_0_CTRL_CFG
;
573 test_cfg_reg
= ENET_SERDES_0_TEST_CFG
;
576 ctrl_reg
= ENET_SERDES_1_CTRL_CFG
;
577 test_cfg_reg
= ENET_SERDES_1_TEST_CFG
;
583 ctrl_val
= (ENET_SERDES_CTRL_SDET_0
|
584 ENET_SERDES_CTRL_SDET_1
|
585 ENET_SERDES_CTRL_SDET_2
|
586 ENET_SERDES_CTRL_SDET_3
|
587 (0x5 << ENET_SERDES_CTRL_EMPH_0_SHIFT
) |
588 (0x5 << ENET_SERDES_CTRL_EMPH_1_SHIFT
) |
589 (0x5 << ENET_SERDES_CTRL_EMPH_2_SHIFT
) |
590 (0x5 << ENET_SERDES_CTRL_EMPH_3_SHIFT
) |
591 (0x1 << ENET_SERDES_CTRL_LADJ_0_SHIFT
) |
592 (0x1 << ENET_SERDES_CTRL_LADJ_1_SHIFT
) |
593 (0x1 << ENET_SERDES_CTRL_LADJ_2_SHIFT
) |
594 (0x1 << ENET_SERDES_CTRL_LADJ_3_SHIFT
));
597 if (lp
->loopback_mode
== LOOPBACK_PHY
) {
598 test_cfg_val
|= ((ENET_TEST_MD_PAD_LOOPBACK
<<
599 ENET_SERDES_TEST_MD_0_SHIFT
) |
600 (ENET_TEST_MD_PAD_LOOPBACK
<<
601 ENET_SERDES_TEST_MD_1_SHIFT
) |
602 (ENET_TEST_MD_PAD_LOOPBACK
<<
603 ENET_SERDES_TEST_MD_2_SHIFT
) |
604 (ENET_TEST_MD_PAD_LOOPBACK
<<
605 ENET_SERDES_TEST_MD_3_SHIFT
));
608 nw64(ctrl_reg
, ctrl_val
);
609 nw64(test_cfg_reg
, test_cfg_val
);
611 /* Initialize all 4 lanes of the SERDES. */
612 for (i
= 0; i
< 4; i
++) {
613 u32 rxtx_ctrl
, glue0
;
615 err
= esr_read_rxtx_ctrl(np
, i
, &rxtx_ctrl
);
618 err
= esr_read_glue0(np
, i
, &glue0
);
622 rxtx_ctrl
&= ~(ESR_RXTX_CTRL_VMUXLO
);
623 rxtx_ctrl
|= (ESR_RXTX_CTRL_ENSTRETCH
|
624 (2 << ESR_RXTX_CTRL_VMUXLO_SHIFT
));
626 glue0
&= ~(ESR_GLUE_CTRL0_SRATE
|
627 ESR_GLUE_CTRL0_THCNT
|
628 ESR_GLUE_CTRL0_BLTIME
);
629 glue0
|= (ESR_GLUE_CTRL0_RXLOSENAB
|
630 (0xf << ESR_GLUE_CTRL0_SRATE_SHIFT
) |
631 (0xff << ESR_GLUE_CTRL0_THCNT_SHIFT
) |
632 (BLTIME_300_CYCLES
<<
633 ESR_GLUE_CTRL0_BLTIME_SHIFT
));
635 err
= esr_write_rxtx_ctrl(np
, i
, rxtx_ctrl
);
638 err
= esr_write_glue0(np
, i
, glue0
);
647 sig
= nr64(ESR_INT_SIGNALS
);
650 mask
= ESR_INT_SIGNALS_P0_BITS
;
651 val
= (ESR_INT_SRDY0_P0
|
661 mask
= ESR_INT_SIGNALS_P1_BITS
;
662 val
= (ESR_INT_SRDY0_P1
|
675 if ((sig
& mask
) != val
) {
676 dev_err(np
->device
, PFX
"Port %u signal bits [%08x] are not "
677 "[%08x]\n", np
->port
, (int) (sig
& mask
), (int) val
);
684 static int serdes_init_1g(struct niu
*np
)
688 val
= nr64(ENET_SERDES_1_PLL_CFG
);
689 val
&= ~ENET_SERDES_PLL_FBDIV2
;
692 val
|= ENET_SERDES_PLL_HRATE0
;
695 val
|= ENET_SERDES_PLL_HRATE1
;
698 val
|= ENET_SERDES_PLL_HRATE2
;
701 val
|= ENET_SERDES_PLL_HRATE3
;
706 nw64(ENET_SERDES_1_PLL_CFG
, val
);
711 static int serdes_init_1g_serdes(struct niu
*np
)
713 struct niu_link_config
*lp
= &np
->link_config
;
714 unsigned long ctrl_reg
, test_cfg_reg
, pll_cfg
, i
;
715 u64 ctrl_val
, test_cfg_val
, sig
, mask
, val
;
717 u64 reset_val
, val_rd
;
719 val
= ENET_SERDES_PLL_HRATE0
| ENET_SERDES_PLL_HRATE1
|
720 ENET_SERDES_PLL_HRATE2
| ENET_SERDES_PLL_HRATE3
|
721 ENET_SERDES_PLL_FBDIV0
;
724 reset_val
= ENET_SERDES_RESET_0
;
725 ctrl_reg
= ENET_SERDES_0_CTRL_CFG
;
726 test_cfg_reg
= ENET_SERDES_0_TEST_CFG
;
727 pll_cfg
= ENET_SERDES_0_PLL_CFG
;
730 reset_val
= ENET_SERDES_RESET_1
;
731 ctrl_reg
= ENET_SERDES_1_CTRL_CFG
;
732 test_cfg_reg
= ENET_SERDES_1_TEST_CFG
;
733 pll_cfg
= ENET_SERDES_1_PLL_CFG
;
739 ctrl_val
= (ENET_SERDES_CTRL_SDET_0
|
740 ENET_SERDES_CTRL_SDET_1
|
741 ENET_SERDES_CTRL_SDET_2
|
742 ENET_SERDES_CTRL_SDET_3
|
743 (0x5 << ENET_SERDES_CTRL_EMPH_0_SHIFT
) |
744 (0x5 << ENET_SERDES_CTRL_EMPH_1_SHIFT
) |
745 (0x5 << ENET_SERDES_CTRL_EMPH_2_SHIFT
) |
746 (0x5 << ENET_SERDES_CTRL_EMPH_3_SHIFT
) |
747 (0x1 << ENET_SERDES_CTRL_LADJ_0_SHIFT
) |
748 (0x1 << ENET_SERDES_CTRL_LADJ_1_SHIFT
) |
749 (0x1 << ENET_SERDES_CTRL_LADJ_2_SHIFT
) |
750 (0x1 << ENET_SERDES_CTRL_LADJ_3_SHIFT
));
753 if (lp
->loopback_mode
== LOOPBACK_PHY
) {
754 test_cfg_val
|= ((ENET_TEST_MD_PAD_LOOPBACK
<<
755 ENET_SERDES_TEST_MD_0_SHIFT
) |
756 (ENET_TEST_MD_PAD_LOOPBACK
<<
757 ENET_SERDES_TEST_MD_1_SHIFT
) |
758 (ENET_TEST_MD_PAD_LOOPBACK
<<
759 ENET_SERDES_TEST_MD_2_SHIFT
) |
760 (ENET_TEST_MD_PAD_LOOPBACK
<<
761 ENET_SERDES_TEST_MD_3_SHIFT
));
764 nw64(ENET_SERDES_RESET
, reset_val
);
766 val_rd
= nr64(ENET_SERDES_RESET
);
767 val_rd
&= ~reset_val
;
769 nw64(ctrl_reg
, ctrl_val
);
770 nw64(test_cfg_reg
, test_cfg_val
);
771 nw64(ENET_SERDES_RESET
, val_rd
);
774 /* Initialize all 4 lanes of the SERDES. */
775 for (i
= 0; i
< 4; i
++) {
776 u32 rxtx_ctrl
, glue0
;
778 err
= esr_read_rxtx_ctrl(np
, i
, &rxtx_ctrl
);
781 err
= esr_read_glue0(np
, i
, &glue0
);
785 rxtx_ctrl
&= ~(ESR_RXTX_CTRL_VMUXLO
);
786 rxtx_ctrl
|= (ESR_RXTX_CTRL_ENSTRETCH
|
787 (2 << ESR_RXTX_CTRL_VMUXLO_SHIFT
));
789 glue0
&= ~(ESR_GLUE_CTRL0_SRATE
|
790 ESR_GLUE_CTRL0_THCNT
|
791 ESR_GLUE_CTRL0_BLTIME
);
792 glue0
|= (ESR_GLUE_CTRL0_RXLOSENAB
|
793 (0xf << ESR_GLUE_CTRL0_SRATE_SHIFT
) |
794 (0xff << ESR_GLUE_CTRL0_THCNT_SHIFT
) |
795 (BLTIME_300_CYCLES
<<
796 ESR_GLUE_CTRL0_BLTIME_SHIFT
));
798 err
= esr_write_rxtx_ctrl(np
, i
, rxtx_ctrl
);
801 err
= esr_write_glue0(np
, i
, glue0
);
807 sig
= nr64(ESR_INT_SIGNALS
);
810 val
= (ESR_INT_SRDY0_P0
| ESR_INT_DET0_P0
);
815 val
= (ESR_INT_SRDY0_P1
| ESR_INT_DET0_P1
);
823 if ((sig
& mask
) != val
) {
824 dev_err(np
->device
, PFX
"Port %u signal bits [%08x] are not "
825 "[%08x]\n", np
->port
, (int) (sig
& mask
), (int) val
);
832 static int link_status_1g_serdes(struct niu
*np
, int *link_up_p
)
834 struct niu_link_config
*lp
= &np
->link_config
;
842 current_speed
= SPEED_INVALID
;
843 current_duplex
= DUPLEX_INVALID
;
845 spin_lock_irqsave(&np
->lock
, flags
);
847 val
= nr64_pcs(PCS_MII_STAT
);
849 if (val
& PCS_MII_STAT_LINK_STATUS
) {
851 current_speed
= SPEED_1000
;
852 current_duplex
= DUPLEX_FULL
;
855 lp
->active_speed
= current_speed
;
856 lp
->active_duplex
= current_duplex
;
857 spin_unlock_irqrestore(&np
->lock
, flags
);
859 *link_up_p
= link_up
;
864 static int link_status_10g_serdes(struct niu
*np
, int *link_up_p
)
867 struct niu_link_config
*lp
= &np
->link_config
;
874 if (!(np
->flags
& NIU_FLAGS_10G
))
875 return link_status_1g_serdes(np
, link_up_p
);
877 current_speed
= SPEED_INVALID
;
878 current_duplex
= DUPLEX_INVALID
;
879 spin_lock_irqsave(&np
->lock
, flags
);
881 val
= nr64_xpcs(XPCS_STATUS(0));
882 val2
= nr64_mac(XMAC_INTER2
);
883 if (val2
& 0x01000000)
886 if ((val
& 0x1000ULL
) && link_ok
) {
888 current_speed
= SPEED_10000
;
889 current_duplex
= DUPLEX_FULL
;
891 lp
->active_speed
= current_speed
;
892 lp
->active_duplex
= current_duplex
;
893 spin_unlock_irqrestore(&np
->lock
, flags
);
894 *link_up_p
= link_up
;
899 static int link_status_1g_rgmii(struct niu
*np
, int *link_up_p
)
901 struct niu_link_config
*lp
= &np
->link_config
;
902 u16 current_speed
, bmsr
;
908 current_speed
= SPEED_INVALID
;
909 current_duplex
= DUPLEX_INVALID
;
911 spin_lock_irqsave(&np
->lock
, flags
);
915 err
= mii_read(np
, np
->phy_addr
, MII_BMSR
);
920 if (bmsr
& BMSR_LSTATUS
) {
921 u16 adv
, lpa
, common
, estat
;
923 err
= mii_read(np
, np
->phy_addr
, MII_ADVERTISE
);
928 err
= mii_read(np
, np
->phy_addr
, MII_LPA
);
935 err
= mii_read(np
, np
->phy_addr
, MII_ESTATUS
);
940 current_speed
= SPEED_1000
;
941 current_duplex
= DUPLEX_FULL
;
944 lp
->active_speed
= current_speed
;
945 lp
->active_duplex
= current_duplex
;
949 spin_unlock_irqrestore(&np
->lock
, flags
);
951 *link_up_p
= link_up
;
956 static int bcm8704_reset(struct niu
*np
)
960 err
= mdio_read(np
, np
->phy_addr
,
961 BCM8704_PHYXS_DEV_ADDR
, MII_BMCR
);
965 err
= mdio_write(np
, np
->phy_addr
, BCM8704_PHYXS_DEV_ADDR
,
971 while (--limit
>= 0) {
972 err
= mdio_read(np
, np
->phy_addr
,
973 BCM8704_PHYXS_DEV_ADDR
, MII_BMCR
);
976 if (!(err
& BMCR_RESET
))
980 dev_err(np
->device
, PFX
"Port %u PHY will not reset "
981 "(bmcr=%04x)\n", np
->port
, (err
& 0xffff));
987 /* When written, certain PHY registers need to be read back twice
988 * in order for the bits to settle properly.
990 static int bcm8704_user_dev3_readback(struct niu
*np
, int reg
)
992 int err
= mdio_read(np
, np
->phy_addr
, BCM8704_USER_DEV3_ADDR
, reg
);
995 err
= mdio_read(np
, np
->phy_addr
, BCM8704_USER_DEV3_ADDR
, reg
);
1001 static int bcm8704_init_user_dev3(struct niu
*np
)
1005 err
= mdio_write(np
, np
->phy_addr
,
1006 BCM8704_USER_DEV3_ADDR
, BCM8704_USER_CONTROL
,
1007 (USER_CONTROL_OPTXRST_LVL
|
1008 USER_CONTROL_OPBIASFLT_LVL
|
1009 USER_CONTROL_OBTMPFLT_LVL
|
1010 USER_CONTROL_OPPRFLT_LVL
|
1011 USER_CONTROL_OPTXFLT_LVL
|
1012 USER_CONTROL_OPRXLOS_LVL
|
1013 USER_CONTROL_OPRXFLT_LVL
|
1014 USER_CONTROL_OPTXON_LVL
|
1015 (0x3f << USER_CONTROL_RES1_SHIFT
)));
1019 err
= mdio_write(np
, np
->phy_addr
,
1020 BCM8704_USER_DEV3_ADDR
, BCM8704_USER_PMD_TX_CONTROL
,
1021 (USER_PMD_TX_CTL_XFP_CLKEN
|
1022 (1 << USER_PMD_TX_CTL_TX_DAC_TXD_SH
) |
1023 (2 << USER_PMD_TX_CTL_TX_DAC_TXCK_SH
) |
1024 USER_PMD_TX_CTL_TSCK_LPWREN
));
1028 err
= bcm8704_user_dev3_readback(np
, BCM8704_USER_CONTROL
);
1031 err
= bcm8704_user_dev3_readback(np
, BCM8704_USER_PMD_TX_CONTROL
);
1035 err
= mdio_read(np
, np
->phy_addr
, BCM8704_USER_DEV3_ADDR
,
1036 BCM8704_USER_OPT_DIGITAL_CTRL
);
1039 err
&= ~USER_ODIG_CTRL_GPIOS
;
1040 err
|= (0x3 << USER_ODIG_CTRL_GPIOS_SHIFT
);
1041 err
= mdio_write(np
, np
->phy_addr
, BCM8704_USER_DEV3_ADDR
,
1042 BCM8704_USER_OPT_DIGITAL_CTRL
, err
);
1051 static int mrvl88x2011_act_led(struct niu
*np
, int val
)
1055 err
= mdio_read(np
, np
->phy_addr
, MRVL88X2011_USER_DEV2_ADDR
,
1056 MRVL88X2011_LED_8_TO_11_CTL
);
1060 err
&= ~MRVL88X2011_LED(MRVL88X2011_LED_ACT
,MRVL88X2011_LED_CTL_MASK
);
1061 err
|= MRVL88X2011_LED(MRVL88X2011_LED_ACT
,val
);
1063 return mdio_write(np
, np
->phy_addr
, MRVL88X2011_USER_DEV2_ADDR
,
1064 MRVL88X2011_LED_8_TO_11_CTL
, err
);
1067 static int mrvl88x2011_led_blink_rate(struct niu
*np
, int rate
)
1071 err
= mdio_read(np
, np
->phy_addr
, MRVL88X2011_USER_DEV2_ADDR
,
1072 MRVL88X2011_LED_BLINK_CTL
);
1074 err
&= ~MRVL88X2011_LED_BLKRATE_MASK
;
1077 err
= mdio_write(np
, np
->phy_addr
, MRVL88X2011_USER_DEV2_ADDR
,
1078 MRVL88X2011_LED_BLINK_CTL
, err
);
1084 static int xcvr_init_10g_mrvl88x2011(struct niu
*np
)
1088 /* Set LED functions */
1089 err
= mrvl88x2011_led_blink_rate(np
, MRVL88X2011_LED_BLKRATE_134MS
);
1094 err
= mrvl88x2011_act_led(np
, MRVL88X2011_LED_CTL_OFF
);
1098 err
= mdio_read(np
, np
->phy_addr
, MRVL88X2011_USER_DEV3_ADDR
,
1099 MRVL88X2011_GENERAL_CTL
);
1103 err
|= MRVL88X2011_ENA_XFPREFCLK
;
1105 err
= mdio_write(np
, np
->phy_addr
, MRVL88X2011_USER_DEV3_ADDR
,
1106 MRVL88X2011_GENERAL_CTL
, err
);
1110 err
= mdio_read(np
, np
->phy_addr
, MRVL88X2011_USER_DEV1_ADDR
,
1111 MRVL88X2011_PMA_PMD_CTL_1
);
1115 if (np
->link_config
.loopback_mode
== LOOPBACK_MAC
)
1116 err
|= MRVL88X2011_LOOPBACK
;
1118 err
&= ~MRVL88X2011_LOOPBACK
;
1120 err
= mdio_write(np
, np
->phy_addr
, MRVL88X2011_USER_DEV1_ADDR
,
1121 MRVL88X2011_PMA_PMD_CTL_1
, err
);
1126 return mdio_write(np
, np
->phy_addr
, MRVL88X2011_USER_DEV1_ADDR
,
1127 MRVL88X2011_10G_PMD_TX_DIS
, MRVL88X2011_ENA_PMDTX
);
1130 static int xcvr_init_10g_bcm8704(struct niu
*np
)
1132 struct niu_link_config
*lp
= &np
->link_config
;
1133 u16 analog_stat0
, tx_alarm_status
;
1136 err
= bcm8704_reset(np
);
1140 err
= bcm8704_init_user_dev3(np
);
1144 err
= mdio_read(np
, np
->phy_addr
, BCM8704_PCS_DEV_ADDR
,
1148 err
&= ~BMCR_LOOPBACK
;
1150 if (lp
->loopback_mode
== LOOPBACK_MAC
)
1151 err
|= BMCR_LOOPBACK
;
1153 err
= mdio_write(np
, np
->phy_addr
, BCM8704_PCS_DEV_ADDR
,
1159 err
= mdio_read(np
, np
->phy_addr
, BCM8704_PMA_PMD_DEV_ADDR
,
1163 pr_info(PFX
"Port %u PMA_PMD(MII_STAT1000) [%04x]\n",
1166 err
= mdio_read(np
, np
->phy_addr
, BCM8704_USER_DEV3_ADDR
, 0x20);
1169 pr_info(PFX
"Port %u USER_DEV3(0x20) [%04x]\n",
1172 err
= mdio_read(np
, np
->phy_addr
, BCM8704_PHYXS_DEV_ADDR
,
1176 pr_info(PFX
"Port %u PHYXS(MII_NWAYTEST) [%04x]\n",
1180 /* XXX dig this out it might not be so useful XXX */
1181 err
= mdio_read(np
, np
->phy_addr
, BCM8704_USER_DEV3_ADDR
,
1182 BCM8704_USER_ANALOG_STATUS0
);
1185 err
= mdio_read(np
, np
->phy_addr
, BCM8704_USER_DEV3_ADDR
,
1186 BCM8704_USER_ANALOG_STATUS0
);
1191 err
= mdio_read(np
, np
->phy_addr
, BCM8704_USER_DEV3_ADDR
,
1192 BCM8704_USER_TX_ALARM_STATUS
);
1195 err
= mdio_read(np
, np
->phy_addr
, BCM8704_USER_DEV3_ADDR
,
1196 BCM8704_USER_TX_ALARM_STATUS
);
1199 tx_alarm_status
= err
;
1201 if (analog_stat0
!= 0x03fc) {
1202 if ((analog_stat0
== 0x43bc) && (tx_alarm_status
!= 0)) {
1203 pr_info(PFX
"Port %u cable not connected "
1204 "or bad cable.\n", np
->port
);
1205 } else if (analog_stat0
== 0x639c) {
1206 pr_info(PFX
"Port %u optical module is bad "
1207 "or missing.\n", np
->port
);
1214 static int xcvr_init_10g(struct niu
*np
)
1219 val
= nr64_mac(XMAC_CONFIG
);
1220 val
&= ~XMAC_CONFIG_LED_POLARITY
;
1221 val
|= XMAC_CONFIG_FORCE_LED_ON
;
1222 nw64_mac(XMAC_CONFIG
, val
);
1224 /* XXX shared resource, lock parent XXX */
1225 val
= nr64(MIF_CONFIG
);
1226 val
|= MIF_CONFIG_INDIRECT_MODE
;
1227 nw64(MIF_CONFIG
, val
);
1229 phy_id
= phy_decode(np
->parent
->port_phy
, np
->port
);
1230 phy_id
= np
->parent
->phy_probe_info
.phy_id
[phy_id
][np
->port
];
1232 /* handle different phy types */
1233 switch (phy_id
& NIU_PHY_ID_MASK
) {
1234 case NIU_PHY_ID_MRVL88X2011
:
1235 err
= xcvr_init_10g_mrvl88x2011(np
);
1238 default: /* bcom 8704 */
1239 err
= xcvr_init_10g_bcm8704(np
);
1246 static int mii_reset(struct niu
*np
)
1250 err
= mii_write(np
, np
->phy_addr
, MII_BMCR
, BMCR_RESET
);
1255 while (--limit
>= 0) {
1257 err
= mii_read(np
, np
->phy_addr
, MII_BMCR
);
1260 if (!(err
& BMCR_RESET
))
1264 dev_err(np
->device
, PFX
"Port %u MII would not reset, "
1265 "bmcr[%04x]\n", np
->port
, err
);
1274 static int xcvr_init_1g_rgmii(struct niu
*np
)
1278 u16 bmcr
, bmsr
, estat
;
1280 val
= nr64(MIF_CONFIG
);
1281 val
&= ~MIF_CONFIG_INDIRECT_MODE
;
1282 nw64(MIF_CONFIG
, val
);
1284 err
= mii_reset(np
);
1288 err
= mii_read(np
, np
->phy_addr
, MII_BMSR
);
1294 if (bmsr
& BMSR_ESTATEN
) {
1295 err
= mii_read(np
, np
->phy_addr
, MII_ESTATUS
);
1302 err
= mii_write(np
, np
->phy_addr
, MII_BMCR
, bmcr
);
1306 if (bmsr
& BMSR_ESTATEN
) {
1309 if (estat
& ESTATUS_1000_TFULL
)
1310 ctrl1000
|= ADVERTISE_1000FULL
;
1311 err
= mii_write(np
, np
->phy_addr
, MII_CTRL1000
, ctrl1000
);
1316 bmcr
= (BMCR_SPEED1000
| BMCR_FULLDPLX
);
1318 err
= mii_write(np
, np
->phy_addr
, MII_BMCR
, bmcr
);
1322 err
= mii_read(np
, np
->phy_addr
, MII_BMCR
);
1325 bmcr
= mii_read(np
, np
->phy_addr
, MII_BMCR
);
1327 err
= mii_read(np
, np
->phy_addr
, MII_BMSR
);
1335 static int mii_init_common(struct niu
*np
)
1337 struct niu_link_config
*lp
= &np
->link_config
;
1338 u16 bmcr
, bmsr
, adv
, estat
;
1341 err
= mii_reset(np
);
1345 err
= mii_read(np
, np
->phy_addr
, MII_BMSR
);
1351 if (bmsr
& BMSR_ESTATEN
) {
1352 err
= mii_read(np
, np
->phy_addr
, MII_ESTATUS
);
1359 err
= mii_write(np
, np
->phy_addr
, MII_BMCR
, bmcr
);
1363 if (lp
->loopback_mode
== LOOPBACK_MAC
) {
1364 bmcr
|= BMCR_LOOPBACK
;
1365 if (lp
->active_speed
== SPEED_1000
)
1366 bmcr
|= BMCR_SPEED1000
;
1367 if (lp
->active_duplex
== DUPLEX_FULL
)
1368 bmcr
|= BMCR_FULLDPLX
;
1371 if (lp
->loopback_mode
== LOOPBACK_PHY
) {
1374 aux
= (BCM5464R_AUX_CTL_EXT_LB
|
1375 BCM5464R_AUX_CTL_WRITE_1
);
1376 err
= mii_write(np
, np
->phy_addr
, BCM5464R_AUX_CTL
, aux
);
1381 /* XXX configurable XXX */
1382 /* XXX for now don't advertise half-duplex or asym pause... XXX */
1383 adv
= ADVERTISE_CSMA
| ADVERTISE_PAUSE_CAP
;
1384 if (bmsr
& BMSR_10FULL
)
1385 adv
|= ADVERTISE_10FULL
;
1386 if (bmsr
& BMSR_100FULL
)
1387 adv
|= ADVERTISE_100FULL
;
1388 err
= mii_write(np
, np
->phy_addr
, MII_ADVERTISE
, adv
);
1392 if (bmsr
& BMSR_ESTATEN
) {
1395 if (estat
& ESTATUS_1000_TFULL
)
1396 ctrl1000
|= ADVERTISE_1000FULL
;
1397 err
= mii_write(np
, np
->phy_addr
, MII_CTRL1000
, ctrl1000
);
1401 bmcr
|= (BMCR_ANENABLE
| BMCR_ANRESTART
);
1403 err
= mii_write(np
, np
->phy_addr
, MII_BMCR
, bmcr
);
1407 err
= mii_read(np
, np
->phy_addr
, MII_BMCR
);
1410 err
= mii_read(np
, np
->phy_addr
, MII_BMSR
);
1414 pr_info(PFX
"Port %u after MII init bmcr[%04x] bmsr[%04x]\n",
1415 np
->port
, bmcr
, bmsr
);
1421 static int xcvr_init_1g(struct niu
*np
)
1425 /* XXX shared resource, lock parent XXX */
1426 val
= nr64(MIF_CONFIG
);
1427 val
&= ~MIF_CONFIG_INDIRECT_MODE
;
1428 nw64(MIF_CONFIG
, val
);
1430 return mii_init_common(np
);
1433 static int niu_xcvr_init(struct niu
*np
)
1435 const struct niu_phy_ops
*ops
= np
->phy_ops
;
1440 err
= ops
->xcvr_init(np
);
1445 static int niu_serdes_init(struct niu
*np
)
1447 const struct niu_phy_ops
*ops
= np
->phy_ops
;
1451 if (ops
->serdes_init
)
1452 err
= ops
->serdes_init(np
);
1457 static void niu_init_xif(struct niu
*);
1458 static void niu_handle_led(struct niu
*, int status
);
1460 static int niu_link_status_common(struct niu
*np
, int link_up
)
1462 struct niu_link_config
*lp
= &np
->link_config
;
1463 struct net_device
*dev
= np
->dev
;
1464 unsigned long flags
;
1466 if (!netif_carrier_ok(dev
) && link_up
) {
1467 niuinfo(LINK
, "%s: Link is up at %s, %s duplex\n",
1469 (lp
->active_speed
== SPEED_10000
?
1471 (lp
->active_speed
== SPEED_1000
?
1473 (lp
->active_speed
== SPEED_100
?
1474 "100Mbit/sec" : "10Mbit/sec"))),
1475 (lp
->active_duplex
== DUPLEX_FULL
?
1478 spin_lock_irqsave(&np
->lock
, flags
);
1480 niu_handle_led(np
, 1);
1481 spin_unlock_irqrestore(&np
->lock
, flags
);
1483 netif_carrier_on(dev
);
1484 } else if (netif_carrier_ok(dev
) && !link_up
) {
1485 niuwarn(LINK
, "%s: Link is down\n", dev
->name
);
1486 spin_lock_irqsave(&np
->lock
, flags
);
1487 niu_handle_led(np
, 0);
1488 spin_unlock_irqrestore(&np
->lock
, flags
);
1489 netif_carrier_off(dev
);
1495 static int link_status_10g_mrvl(struct niu
*np
, int *link_up_p
)
1497 int err
, link_up
, pma_status
, pcs_status
;
1501 err
= mdio_read(np
, np
->phy_addr
, MRVL88X2011_USER_DEV1_ADDR
,
1502 MRVL88X2011_10G_PMD_STATUS_2
);
1506 /* Check PMA/PMD Register: 1.0001.2 == 1 */
1507 err
= mdio_read(np
, np
->phy_addr
, MRVL88X2011_USER_DEV1_ADDR
,
1508 MRVL88X2011_PMA_PMD_STATUS_1
);
1512 pma_status
= ((err
& MRVL88X2011_LNK_STATUS_OK
) ? 1 : 0);
1514 /* Check PMC Register : 3.0001.2 == 1: read twice */
1515 err
= mdio_read(np
, np
->phy_addr
, MRVL88X2011_USER_DEV3_ADDR
,
1516 MRVL88X2011_PMA_PMD_STATUS_1
);
1520 err
= mdio_read(np
, np
->phy_addr
, MRVL88X2011_USER_DEV3_ADDR
,
1521 MRVL88X2011_PMA_PMD_STATUS_1
);
1525 pcs_status
= ((err
& MRVL88X2011_LNK_STATUS_OK
) ? 1 : 0);
1527 /* Check XGXS Register : 4.0018.[0-3,12] */
1528 err
= mdio_read(np
, np
->phy_addr
, MRVL88X2011_USER_DEV4_ADDR
,
1529 MRVL88X2011_10G_XGXS_LANE_STAT
);
1533 if (err
== (PHYXS_XGXS_LANE_STAT_ALINGED
| PHYXS_XGXS_LANE_STAT_LANE3
|
1534 PHYXS_XGXS_LANE_STAT_LANE2
| PHYXS_XGXS_LANE_STAT_LANE1
|
1535 PHYXS_XGXS_LANE_STAT_LANE0
| PHYXS_XGXS_LANE_STAT_MAGIC
|
1537 link_up
= (pma_status
&& pcs_status
) ? 1 : 0;
1539 np
->link_config
.active_speed
= SPEED_10000
;
1540 np
->link_config
.active_duplex
= DUPLEX_FULL
;
1543 mrvl88x2011_act_led(np
, (link_up
?
1544 MRVL88X2011_LED_CTL_PCS_ACT
:
1545 MRVL88X2011_LED_CTL_OFF
));
1547 *link_up_p
= link_up
;
1551 static int link_status_10g_bcom(struct niu
*np
, int *link_up_p
)
1557 err
= mdio_read(np
, np
->phy_addr
, BCM8704_PMA_PMD_DEV_ADDR
,
1558 BCM8704_PMD_RCV_SIGDET
);
1561 if (!(err
& PMD_RCV_SIGDET_GLOBAL
)) {
1566 err
= mdio_read(np
, np
->phy_addr
, BCM8704_PCS_DEV_ADDR
,
1567 BCM8704_PCS_10G_R_STATUS
);
1570 if (!(err
& PCS_10G_R_STATUS_BLK_LOCK
)) {
1575 err
= mdio_read(np
, np
->phy_addr
, BCM8704_PHYXS_DEV_ADDR
,
1576 BCM8704_PHYXS_XGXS_LANE_STAT
);
1580 if (err
!= (PHYXS_XGXS_LANE_STAT_ALINGED
|
1581 PHYXS_XGXS_LANE_STAT_MAGIC
|
1582 PHYXS_XGXS_LANE_STAT_LANE3
|
1583 PHYXS_XGXS_LANE_STAT_LANE2
|
1584 PHYXS_XGXS_LANE_STAT_LANE1
|
1585 PHYXS_XGXS_LANE_STAT_LANE0
)) {
1591 np
->link_config
.active_speed
= SPEED_10000
;
1592 np
->link_config
.active_duplex
= DUPLEX_FULL
;
1596 *link_up_p
= link_up
;
1600 static int link_status_10g(struct niu
*np
, int *link_up_p
)
1602 unsigned long flags
;
1605 spin_lock_irqsave(&np
->lock
, flags
);
1607 if (np
->link_config
.loopback_mode
== LOOPBACK_DISABLED
) {
1610 phy_id
= phy_decode(np
->parent
->port_phy
, np
->port
);
1611 phy_id
= np
->parent
->phy_probe_info
.phy_id
[phy_id
][np
->port
];
1613 /* handle different phy types */
1614 switch (phy_id
& NIU_PHY_ID_MASK
) {
1615 case NIU_PHY_ID_MRVL88X2011
:
1616 err
= link_status_10g_mrvl(np
, link_up_p
);
1619 default: /* bcom 8704 */
1620 err
= link_status_10g_bcom(np
, link_up_p
);
1625 spin_unlock_irqrestore(&np
->lock
, flags
);
1630 static int link_status_1g(struct niu
*np
, int *link_up_p
)
1632 struct niu_link_config
*lp
= &np
->link_config
;
1633 u16 current_speed
, bmsr
;
1634 unsigned long flags
;
1639 current_speed
= SPEED_INVALID
;
1640 current_duplex
= DUPLEX_INVALID
;
1642 spin_lock_irqsave(&np
->lock
, flags
);
1645 if (np
->link_config
.loopback_mode
!= LOOPBACK_DISABLED
)
1648 err
= mii_read(np
, np
->phy_addr
, MII_BMSR
);
1653 if (bmsr
& BMSR_LSTATUS
) {
1654 u16 adv
, lpa
, common
, estat
;
1656 err
= mii_read(np
, np
->phy_addr
, MII_ADVERTISE
);
1661 err
= mii_read(np
, np
->phy_addr
, MII_LPA
);
1668 err
= mii_read(np
, np
->phy_addr
, MII_ESTATUS
);
1674 if (estat
& (ESTATUS_1000_TFULL
| ESTATUS_1000_THALF
)) {
1675 current_speed
= SPEED_1000
;
1676 if (estat
& ESTATUS_1000_TFULL
)
1677 current_duplex
= DUPLEX_FULL
;
1679 current_duplex
= DUPLEX_HALF
;
1681 if (common
& ADVERTISE_100BASE4
) {
1682 current_speed
= SPEED_100
;
1683 current_duplex
= DUPLEX_HALF
;
1684 } else if (common
& ADVERTISE_100FULL
) {
1685 current_speed
= SPEED_100
;
1686 current_duplex
= DUPLEX_FULL
;
1687 } else if (common
& ADVERTISE_100HALF
) {
1688 current_speed
= SPEED_100
;
1689 current_duplex
= DUPLEX_HALF
;
1690 } else if (common
& ADVERTISE_10FULL
) {
1691 current_speed
= SPEED_10
;
1692 current_duplex
= DUPLEX_FULL
;
1693 } else if (common
& ADVERTISE_10HALF
) {
1694 current_speed
= SPEED_10
;
1695 current_duplex
= DUPLEX_HALF
;
1700 lp
->active_speed
= current_speed
;
1701 lp
->active_duplex
= current_duplex
;
1705 spin_unlock_irqrestore(&np
->lock
, flags
);
1707 *link_up_p
= link_up
;
1711 static int niu_link_status(struct niu
*np
, int *link_up_p
)
1713 const struct niu_phy_ops
*ops
= np
->phy_ops
;
1717 if (ops
->link_status
)
1718 err
= ops
->link_status(np
, link_up_p
);
1723 static void niu_timer(unsigned long __opaque
)
1725 struct niu
*np
= (struct niu
*) __opaque
;
1729 err
= niu_link_status(np
, &link_up
);
1731 niu_link_status_common(np
, link_up
);
1733 if (netif_carrier_ok(np
->dev
))
1737 np
->timer
.expires
= jiffies
+ off
;
1739 add_timer(&np
->timer
);
1742 static const struct niu_phy_ops phy_ops_10g_serdes
= {
1743 .serdes_init
= serdes_init_10g_serdes
,
1744 .link_status
= link_status_10g_serdes
,
1747 static const struct niu_phy_ops phy_ops_1g_rgmii
= {
1748 .xcvr_init
= xcvr_init_1g_rgmii
,
1749 .link_status
= link_status_1g_rgmii
,
1752 static const struct niu_phy_ops phy_ops_10g_fiber_niu
= {
1753 .serdes_init
= serdes_init_niu
,
1754 .xcvr_init
= xcvr_init_10g
,
1755 .link_status
= link_status_10g
,
1758 static const struct niu_phy_ops phy_ops_10g_fiber
= {
1759 .serdes_init
= serdes_init_10g
,
1760 .xcvr_init
= xcvr_init_10g
,
1761 .link_status
= link_status_10g
,
1764 static const struct niu_phy_ops phy_ops_10g_copper
= {
1765 .serdes_init
= serdes_init_10g
,
1766 .link_status
= link_status_10g
, /* XXX */
1769 static const struct niu_phy_ops phy_ops_1g_fiber
= {
1770 .serdes_init
= serdes_init_1g
,
1771 .xcvr_init
= xcvr_init_1g
,
1772 .link_status
= link_status_1g
,
1775 static const struct niu_phy_ops phy_ops_1g_copper
= {
1776 .xcvr_init
= xcvr_init_1g
,
1777 .link_status
= link_status_1g
,
1780 struct niu_phy_template
{
1781 const struct niu_phy_ops
*ops
;
1785 static const struct niu_phy_template phy_template_niu
= {
1786 .ops
= &phy_ops_10g_fiber_niu
,
1787 .phy_addr_base
= 16,
1790 static const struct niu_phy_template phy_template_10g_fiber
= {
1791 .ops
= &phy_ops_10g_fiber
,
1795 static const struct niu_phy_template phy_template_10g_copper
= {
1796 .ops
= &phy_ops_10g_copper
,
1797 .phy_addr_base
= 10,
1800 static const struct niu_phy_template phy_template_1g_fiber
= {
1801 .ops
= &phy_ops_1g_fiber
,
1805 static const struct niu_phy_template phy_template_1g_copper
= {
1806 .ops
= &phy_ops_1g_copper
,
1810 static const struct niu_phy_template phy_template_1g_rgmii
= {
1811 .ops
= &phy_ops_1g_rgmii
,
1815 static const struct niu_phy_template phy_template_10g_serdes
= {
1816 .ops
= &phy_ops_10g_serdes
,
1820 static int niu_atca_port_num
[4] = {
1824 static int serdes_init_10g_serdes(struct niu
*np
)
1826 struct niu_link_config
*lp
= &np
->link_config
;
1827 unsigned long ctrl_reg
, test_cfg_reg
, pll_cfg
, i
;
1828 u64 ctrl_val
, test_cfg_val
, sig
, mask
, val
;
1834 reset_val
= ENET_SERDES_RESET_0
;
1835 ctrl_reg
= ENET_SERDES_0_CTRL_CFG
;
1836 test_cfg_reg
= ENET_SERDES_0_TEST_CFG
;
1837 pll_cfg
= ENET_SERDES_0_PLL_CFG
;
1840 reset_val
= ENET_SERDES_RESET_1
;
1841 ctrl_reg
= ENET_SERDES_1_CTRL_CFG
;
1842 test_cfg_reg
= ENET_SERDES_1_TEST_CFG
;
1843 pll_cfg
= ENET_SERDES_1_PLL_CFG
;
1849 ctrl_val
= (ENET_SERDES_CTRL_SDET_0
|
1850 ENET_SERDES_CTRL_SDET_1
|
1851 ENET_SERDES_CTRL_SDET_2
|
1852 ENET_SERDES_CTRL_SDET_3
|
1853 (0x5 << ENET_SERDES_CTRL_EMPH_0_SHIFT
) |
1854 (0x5 << ENET_SERDES_CTRL_EMPH_1_SHIFT
) |
1855 (0x5 << ENET_SERDES_CTRL_EMPH_2_SHIFT
) |
1856 (0x5 << ENET_SERDES_CTRL_EMPH_3_SHIFT
) |
1857 (0x1 << ENET_SERDES_CTRL_LADJ_0_SHIFT
) |
1858 (0x1 << ENET_SERDES_CTRL_LADJ_1_SHIFT
) |
1859 (0x1 << ENET_SERDES_CTRL_LADJ_2_SHIFT
) |
1860 (0x1 << ENET_SERDES_CTRL_LADJ_3_SHIFT
));
1863 if (lp
->loopback_mode
== LOOPBACK_PHY
) {
1864 test_cfg_val
|= ((ENET_TEST_MD_PAD_LOOPBACK
<<
1865 ENET_SERDES_TEST_MD_0_SHIFT
) |
1866 (ENET_TEST_MD_PAD_LOOPBACK
<<
1867 ENET_SERDES_TEST_MD_1_SHIFT
) |
1868 (ENET_TEST_MD_PAD_LOOPBACK
<<
1869 ENET_SERDES_TEST_MD_2_SHIFT
) |
1870 (ENET_TEST_MD_PAD_LOOPBACK
<<
1871 ENET_SERDES_TEST_MD_3_SHIFT
));
1875 nw64(pll_cfg
, ENET_SERDES_PLL_FBDIV2
);
1876 nw64(ctrl_reg
, ctrl_val
);
1877 nw64(test_cfg_reg
, test_cfg_val
);
1879 /* Initialize all 4 lanes of the SERDES. */
1880 for (i
= 0; i
< 4; i
++) {
1881 u32 rxtx_ctrl
, glue0
;
1883 err
= esr_read_rxtx_ctrl(np
, i
, &rxtx_ctrl
);
1886 err
= esr_read_glue0(np
, i
, &glue0
);
1890 rxtx_ctrl
&= ~(ESR_RXTX_CTRL_VMUXLO
);
1891 rxtx_ctrl
|= (ESR_RXTX_CTRL_ENSTRETCH
|
1892 (2 << ESR_RXTX_CTRL_VMUXLO_SHIFT
));
1894 glue0
&= ~(ESR_GLUE_CTRL0_SRATE
|
1895 ESR_GLUE_CTRL0_THCNT
|
1896 ESR_GLUE_CTRL0_BLTIME
);
1897 glue0
|= (ESR_GLUE_CTRL0_RXLOSENAB
|
1898 (0xf << ESR_GLUE_CTRL0_SRATE_SHIFT
) |
1899 (0xff << ESR_GLUE_CTRL0_THCNT_SHIFT
) |
1900 (BLTIME_300_CYCLES
<<
1901 ESR_GLUE_CTRL0_BLTIME_SHIFT
));
1903 err
= esr_write_rxtx_ctrl(np
, i
, rxtx_ctrl
);
1906 err
= esr_write_glue0(np
, i
, glue0
);
1912 sig
= nr64(ESR_INT_SIGNALS
);
1915 mask
= ESR_INT_SIGNALS_P0_BITS
;
1916 val
= (ESR_INT_SRDY0_P0
|
1919 ESR_INT_XDP_P0_CH3
|
1920 ESR_INT_XDP_P0_CH2
|
1921 ESR_INT_XDP_P0_CH1
|
1922 ESR_INT_XDP_P0_CH0
);
1926 mask
= ESR_INT_SIGNALS_P1_BITS
;
1927 val
= (ESR_INT_SRDY0_P1
|
1930 ESR_INT_XDP_P1_CH3
|
1931 ESR_INT_XDP_P1_CH2
|
1932 ESR_INT_XDP_P1_CH1
|
1933 ESR_INT_XDP_P1_CH0
);
1940 if ((sig
& mask
) != val
) {
1942 err
= serdes_init_1g_serdes(np
);
1944 np
->flags
&= ~NIU_FLAGS_10G
;
1945 np
->mac_xcvr
= MAC_XCVR_PCS
;
1947 dev_err(np
->device
, PFX
"Port %u 10G/1G SERDES Link Failed \n",
1956 static int niu_determine_phy_disposition(struct niu
*np
)
1958 struct niu_parent
*parent
= np
->parent
;
1959 u8 plat_type
= parent
->plat_type
;
1960 const struct niu_phy_template
*tp
;
1961 u32 phy_addr_off
= 0;
1963 if (plat_type
== PLAT_TYPE_NIU
) {
1964 tp
= &phy_template_niu
;
1965 phy_addr_off
+= np
->port
;
1970 NIU_FLAGS_XCVR_SERDES
)) {
1973 tp
= &phy_template_1g_copper
;
1974 if (plat_type
== PLAT_TYPE_VF_P0
)
1976 else if (plat_type
== PLAT_TYPE_VF_P1
)
1979 phy_addr_off
+= (np
->port
^ 0x3);
1984 tp
= &phy_template_1g_copper
;
1987 case NIU_FLAGS_FIBER
:
1989 tp
= &phy_template_1g_fiber
;
1992 case NIU_FLAGS_10G
| NIU_FLAGS_FIBER
:
1994 tp
= &phy_template_10g_fiber
;
1995 if (plat_type
== PLAT_TYPE_VF_P0
||
1996 plat_type
== PLAT_TYPE_VF_P1
)
1998 phy_addr_off
+= np
->port
;
2001 case NIU_FLAGS_10G
| NIU_FLAGS_XCVR_SERDES
:
2002 case NIU_FLAGS_XCVR_SERDES
| NIU_FLAGS_FIBER
:
2003 case NIU_FLAGS_XCVR_SERDES
:
2007 tp
= &phy_template_10g_serdes
;
2011 tp
= &phy_template_1g_rgmii
;
2017 phy_addr_off
= niu_atca_port_num
[np
->port
];
2025 np
->phy_ops
= tp
->ops
;
2026 np
->phy_addr
= tp
->phy_addr_base
+ phy_addr_off
;
2031 static int niu_init_link(struct niu
*np
)
2033 struct niu_parent
*parent
= np
->parent
;
2036 if (parent
->plat_type
== PLAT_TYPE_NIU
) {
2037 err
= niu_xcvr_init(np
);
2042 err
= niu_serdes_init(np
);
2046 err
= niu_xcvr_init(np
);
2048 niu_link_status(np
, &ignore
);
2052 static void niu_set_primary_mac(struct niu
*np
, unsigned char *addr
)
2054 u16 reg0
= addr
[4] << 8 | addr
[5];
2055 u16 reg1
= addr
[2] << 8 | addr
[3];
2056 u16 reg2
= addr
[0] << 8 | addr
[1];
2058 if (np
->flags
& NIU_FLAGS_XMAC
) {
2059 nw64_mac(XMAC_ADDR0
, reg0
);
2060 nw64_mac(XMAC_ADDR1
, reg1
);
2061 nw64_mac(XMAC_ADDR2
, reg2
);
2063 nw64_mac(BMAC_ADDR0
, reg0
);
2064 nw64_mac(BMAC_ADDR1
, reg1
);
2065 nw64_mac(BMAC_ADDR2
, reg2
);
2069 static int niu_num_alt_addr(struct niu
*np
)
2071 if (np
->flags
& NIU_FLAGS_XMAC
)
2072 return XMAC_NUM_ALT_ADDR
;
2074 return BMAC_NUM_ALT_ADDR
;
2077 static int niu_set_alt_mac(struct niu
*np
, int index
, unsigned char *addr
)
2079 u16 reg0
= addr
[4] << 8 | addr
[5];
2080 u16 reg1
= addr
[2] << 8 | addr
[3];
2081 u16 reg2
= addr
[0] << 8 | addr
[1];
2083 if (index
>= niu_num_alt_addr(np
))
2086 if (np
->flags
& NIU_FLAGS_XMAC
) {
2087 nw64_mac(XMAC_ALT_ADDR0(index
), reg0
);
2088 nw64_mac(XMAC_ALT_ADDR1(index
), reg1
);
2089 nw64_mac(XMAC_ALT_ADDR2(index
), reg2
);
2091 nw64_mac(BMAC_ALT_ADDR0(index
), reg0
);
2092 nw64_mac(BMAC_ALT_ADDR1(index
), reg1
);
2093 nw64_mac(BMAC_ALT_ADDR2(index
), reg2
);
2099 static int niu_enable_alt_mac(struct niu
*np
, int index
, int on
)
2104 if (index
>= niu_num_alt_addr(np
))
2107 if (np
->flags
& NIU_FLAGS_XMAC
) {
2108 reg
= XMAC_ADDR_CMPEN
;
2111 reg
= BMAC_ADDR_CMPEN
;
2112 mask
= 1 << (index
+ 1);
2115 val
= nr64_mac(reg
);
2125 static void __set_rdc_table_num_hw(struct niu
*np
, unsigned long reg
,
2126 int num
, int mac_pref
)
2128 u64 val
= nr64_mac(reg
);
2129 val
&= ~(HOST_INFO_MACRDCTBLN
| HOST_INFO_MPR
);
2132 val
|= HOST_INFO_MPR
;
2136 static int __set_rdc_table_num(struct niu
*np
,
2137 int xmac_index
, int bmac_index
,
2138 int rdc_table_num
, int mac_pref
)
2142 if (rdc_table_num
& ~HOST_INFO_MACRDCTBLN
)
2144 if (np
->flags
& NIU_FLAGS_XMAC
)
2145 reg
= XMAC_HOST_INFO(xmac_index
);
2147 reg
= BMAC_HOST_INFO(bmac_index
);
2148 __set_rdc_table_num_hw(np
, reg
, rdc_table_num
, mac_pref
);
2152 static int niu_set_primary_mac_rdc_table(struct niu
*np
, int table_num
,
2155 return __set_rdc_table_num(np
, 17, 0, table_num
, mac_pref
);
2158 static int niu_set_multicast_mac_rdc_table(struct niu
*np
, int table_num
,
2161 return __set_rdc_table_num(np
, 16, 8, table_num
, mac_pref
);
2164 static int niu_set_alt_mac_rdc_table(struct niu
*np
, int idx
,
2165 int table_num
, int mac_pref
)
2167 if (idx
>= niu_num_alt_addr(np
))
2169 return __set_rdc_table_num(np
, idx
, idx
+ 1, table_num
, mac_pref
);
2172 static u64
vlan_entry_set_parity(u64 reg_val
)
2177 port01_mask
= 0x00ff;
2178 port23_mask
= 0xff00;
2180 if (hweight64(reg_val
& port01_mask
) & 1)
2181 reg_val
|= ENET_VLAN_TBL_PARITY0
;
2183 reg_val
&= ~ENET_VLAN_TBL_PARITY0
;
2185 if (hweight64(reg_val
& port23_mask
) & 1)
2186 reg_val
|= ENET_VLAN_TBL_PARITY1
;
2188 reg_val
&= ~ENET_VLAN_TBL_PARITY1
;
2193 static void vlan_tbl_write(struct niu
*np
, unsigned long index
,
2194 int port
, int vpr
, int rdc_table
)
2196 u64 reg_val
= nr64(ENET_VLAN_TBL(index
));
2198 reg_val
&= ~((ENET_VLAN_TBL_VPR
|
2199 ENET_VLAN_TBL_VLANRDCTBLN
) <<
2200 ENET_VLAN_TBL_SHIFT(port
));
2202 reg_val
|= (ENET_VLAN_TBL_VPR
<<
2203 ENET_VLAN_TBL_SHIFT(port
));
2204 reg_val
|= (rdc_table
<< ENET_VLAN_TBL_SHIFT(port
));
2206 reg_val
= vlan_entry_set_parity(reg_val
);
2208 nw64(ENET_VLAN_TBL(index
), reg_val
);
2211 static void vlan_tbl_clear(struct niu
*np
)
2215 for (i
= 0; i
< ENET_VLAN_TBL_NUM_ENTRIES
; i
++)
2216 nw64(ENET_VLAN_TBL(i
), 0);
2219 static int tcam_wait_bit(struct niu
*np
, u64 bit
)
2223 while (--limit
> 0) {
2224 if (nr64(TCAM_CTL
) & bit
)
2234 static int tcam_flush(struct niu
*np
, int index
)
2236 nw64(TCAM_KEY_0
, 0x00);
2237 nw64(TCAM_KEY_MASK_0
, 0xff);
2238 nw64(TCAM_CTL
, (TCAM_CTL_RWC_TCAM_WRITE
| index
));
2240 return tcam_wait_bit(np
, TCAM_CTL_STAT
);
2244 static int tcam_read(struct niu
*np
, int index
,
2245 u64
*key
, u64
*mask
)
2249 nw64(TCAM_CTL
, (TCAM_CTL_RWC_TCAM_READ
| index
));
2250 err
= tcam_wait_bit(np
, TCAM_CTL_STAT
);
2252 key
[0] = nr64(TCAM_KEY_0
);
2253 key
[1] = nr64(TCAM_KEY_1
);
2254 key
[2] = nr64(TCAM_KEY_2
);
2255 key
[3] = nr64(TCAM_KEY_3
);
2256 mask
[0] = nr64(TCAM_KEY_MASK_0
);
2257 mask
[1] = nr64(TCAM_KEY_MASK_1
);
2258 mask
[2] = nr64(TCAM_KEY_MASK_2
);
2259 mask
[3] = nr64(TCAM_KEY_MASK_3
);
2265 static int tcam_write(struct niu
*np
, int index
,
2266 u64
*key
, u64
*mask
)
2268 nw64(TCAM_KEY_0
, key
[0]);
2269 nw64(TCAM_KEY_1
, key
[1]);
2270 nw64(TCAM_KEY_2
, key
[2]);
2271 nw64(TCAM_KEY_3
, key
[3]);
2272 nw64(TCAM_KEY_MASK_0
, mask
[0]);
2273 nw64(TCAM_KEY_MASK_1
, mask
[1]);
2274 nw64(TCAM_KEY_MASK_2
, mask
[2]);
2275 nw64(TCAM_KEY_MASK_3
, mask
[3]);
2276 nw64(TCAM_CTL
, (TCAM_CTL_RWC_TCAM_WRITE
| index
));
2278 return tcam_wait_bit(np
, TCAM_CTL_STAT
);
2282 static int tcam_assoc_read(struct niu
*np
, int index
, u64
*data
)
2286 nw64(TCAM_CTL
, (TCAM_CTL_RWC_RAM_READ
| index
));
2287 err
= tcam_wait_bit(np
, TCAM_CTL_STAT
);
2289 *data
= nr64(TCAM_KEY_1
);
2295 static int tcam_assoc_write(struct niu
*np
, int index
, u64 assoc_data
)
2297 nw64(TCAM_KEY_1
, assoc_data
);
2298 nw64(TCAM_CTL
, (TCAM_CTL_RWC_RAM_WRITE
| index
));
2300 return tcam_wait_bit(np
, TCAM_CTL_STAT
);
2303 static void tcam_enable(struct niu
*np
, int on
)
2305 u64 val
= nr64(FFLP_CFG_1
);
2308 val
&= ~FFLP_CFG_1_TCAM_DIS
;
2310 val
|= FFLP_CFG_1_TCAM_DIS
;
2311 nw64(FFLP_CFG_1
, val
);
2314 static void tcam_set_lat_and_ratio(struct niu
*np
, u64 latency
, u64 ratio
)
2316 u64 val
= nr64(FFLP_CFG_1
);
2318 val
&= ~(FFLP_CFG_1_FFLPINITDONE
|
2320 FFLP_CFG_1_CAMRATIO
);
2321 val
|= (latency
<< FFLP_CFG_1_CAMLAT_SHIFT
);
2322 val
|= (ratio
<< FFLP_CFG_1_CAMRATIO_SHIFT
);
2323 nw64(FFLP_CFG_1
, val
);
2325 val
= nr64(FFLP_CFG_1
);
2326 val
|= FFLP_CFG_1_FFLPINITDONE
;
2327 nw64(FFLP_CFG_1
, val
);
2330 static int tcam_user_eth_class_enable(struct niu
*np
, unsigned long class,
2336 if (class < CLASS_CODE_ETHERTYPE1
||
2337 class > CLASS_CODE_ETHERTYPE2
)
2340 reg
= L2_CLS(class - CLASS_CODE_ETHERTYPE1
);
2352 static int tcam_user_eth_class_set(struct niu
*np
, unsigned long class,
2358 if (class < CLASS_CODE_ETHERTYPE1
||
2359 class > CLASS_CODE_ETHERTYPE2
||
2360 (ether_type
& ~(u64
)0xffff) != 0)
2363 reg
= L2_CLS(class - CLASS_CODE_ETHERTYPE1
);
2365 val
&= ~L2_CLS_ETYPE
;
2366 val
|= (ether_type
<< L2_CLS_ETYPE_SHIFT
);
2373 static int tcam_user_ip_class_enable(struct niu
*np
, unsigned long class,
2379 if (class < CLASS_CODE_USER_PROG1
||
2380 class > CLASS_CODE_USER_PROG4
)
2383 reg
= L3_CLS(class - CLASS_CODE_USER_PROG1
);
2386 val
|= L3_CLS_VALID
;
2388 val
&= ~L3_CLS_VALID
;
2395 static int tcam_user_ip_class_set(struct niu
*np
, unsigned long class,
2396 int ipv6
, u64 protocol_id
,
2397 u64 tos_mask
, u64 tos_val
)
2402 if (class < CLASS_CODE_USER_PROG1
||
2403 class > CLASS_CODE_USER_PROG4
||
2404 (protocol_id
& ~(u64
)0xff) != 0 ||
2405 (tos_mask
& ~(u64
)0xff) != 0 ||
2406 (tos_val
& ~(u64
)0xff) != 0)
2409 reg
= L3_CLS(class - CLASS_CODE_USER_PROG1
);
2411 val
&= ~(L3_CLS_IPVER
| L3_CLS_PID
|
2412 L3_CLS_TOSMASK
| L3_CLS_TOS
);
2414 val
|= L3_CLS_IPVER
;
2415 val
|= (protocol_id
<< L3_CLS_PID_SHIFT
);
2416 val
|= (tos_mask
<< L3_CLS_TOSMASK_SHIFT
);
2417 val
|= (tos_val
<< L3_CLS_TOS_SHIFT
);
2424 static int tcam_early_init(struct niu
*np
)
2430 tcam_set_lat_and_ratio(np
,
2431 DEFAULT_TCAM_LATENCY
,
2432 DEFAULT_TCAM_ACCESS_RATIO
);
2433 for (i
= CLASS_CODE_ETHERTYPE1
; i
<= CLASS_CODE_ETHERTYPE2
; i
++) {
2434 err
= tcam_user_eth_class_enable(np
, i
, 0);
2438 for (i
= CLASS_CODE_USER_PROG1
; i
<= CLASS_CODE_USER_PROG4
; i
++) {
2439 err
= tcam_user_ip_class_enable(np
, i
, 0);
2447 static int tcam_flush_all(struct niu
*np
)
2451 for (i
= 0; i
< np
->parent
->tcam_num_entries
; i
++) {
2452 int err
= tcam_flush(np
, i
);
2459 static u64
hash_addr_regval(unsigned long index
, unsigned long num_entries
)
2461 return ((u64
)index
| (num_entries
== 1 ?
2462 HASH_TBL_ADDR_AUTOINC
: 0));
2466 static int hash_read(struct niu
*np
, unsigned long partition
,
2467 unsigned long index
, unsigned long num_entries
,
2470 u64 val
= hash_addr_regval(index
, num_entries
);
2473 if (partition
>= FCRAM_NUM_PARTITIONS
||
2474 index
+ num_entries
> FCRAM_SIZE
)
2477 nw64(HASH_TBL_ADDR(partition
), val
);
2478 for (i
= 0; i
< num_entries
; i
++)
2479 data
[i
] = nr64(HASH_TBL_DATA(partition
));
2485 static int hash_write(struct niu
*np
, unsigned long partition
,
2486 unsigned long index
, unsigned long num_entries
,
2489 u64 val
= hash_addr_regval(index
, num_entries
);
2492 if (partition
>= FCRAM_NUM_PARTITIONS
||
2493 index
+ (num_entries
* 8) > FCRAM_SIZE
)
2496 nw64(HASH_TBL_ADDR(partition
), val
);
2497 for (i
= 0; i
< num_entries
; i
++)
2498 nw64(HASH_TBL_DATA(partition
), data
[i
]);
2503 static void fflp_reset(struct niu
*np
)
2507 nw64(FFLP_CFG_1
, FFLP_CFG_1_PIO_FIO_RST
);
2509 nw64(FFLP_CFG_1
, 0);
2511 val
= FFLP_CFG_1_FCRAMOUTDR_NORMAL
| FFLP_CFG_1_FFLPINITDONE
;
2512 nw64(FFLP_CFG_1
, val
);
2515 static void fflp_set_timings(struct niu
*np
)
2517 u64 val
= nr64(FFLP_CFG_1
);
2519 val
&= ~FFLP_CFG_1_FFLPINITDONE
;
2520 val
|= (DEFAULT_FCRAMRATIO
<< FFLP_CFG_1_FCRAMRATIO_SHIFT
);
2521 nw64(FFLP_CFG_1
, val
);
2523 val
= nr64(FFLP_CFG_1
);
2524 val
|= FFLP_CFG_1_FFLPINITDONE
;
2525 nw64(FFLP_CFG_1
, val
);
2527 val
= nr64(FCRAM_REF_TMR
);
2528 val
&= ~(FCRAM_REF_TMR_MAX
| FCRAM_REF_TMR_MIN
);
2529 val
|= (DEFAULT_FCRAM_REFRESH_MAX
<< FCRAM_REF_TMR_MAX_SHIFT
);
2530 val
|= (DEFAULT_FCRAM_REFRESH_MIN
<< FCRAM_REF_TMR_MIN_SHIFT
);
2531 nw64(FCRAM_REF_TMR
, val
);
2534 static int fflp_set_partition(struct niu
*np
, u64 partition
,
2535 u64 mask
, u64 base
, int enable
)
2540 if (partition
>= FCRAM_NUM_PARTITIONS
||
2541 (mask
& ~(u64
)0x1f) != 0 ||
2542 (base
& ~(u64
)0x1f) != 0)
2545 reg
= FLW_PRT_SEL(partition
);
2548 val
&= ~(FLW_PRT_SEL_EXT
| FLW_PRT_SEL_MASK
| FLW_PRT_SEL_BASE
);
2549 val
|= (mask
<< FLW_PRT_SEL_MASK_SHIFT
);
2550 val
|= (base
<< FLW_PRT_SEL_BASE_SHIFT
);
2552 val
|= FLW_PRT_SEL_EXT
;
2558 static int fflp_disable_all_partitions(struct niu
*np
)
2562 for (i
= 0; i
< FCRAM_NUM_PARTITIONS
; i
++) {
2563 int err
= fflp_set_partition(np
, 0, 0, 0, 0);
2570 static void fflp_llcsnap_enable(struct niu
*np
, int on
)
2572 u64 val
= nr64(FFLP_CFG_1
);
2575 val
|= FFLP_CFG_1_LLCSNAP
;
2577 val
&= ~FFLP_CFG_1_LLCSNAP
;
2578 nw64(FFLP_CFG_1
, val
);
2581 static void fflp_errors_enable(struct niu
*np
, int on
)
2583 u64 val
= nr64(FFLP_CFG_1
);
2586 val
&= ~FFLP_CFG_1_ERRORDIS
;
2588 val
|= FFLP_CFG_1_ERRORDIS
;
2589 nw64(FFLP_CFG_1
, val
);
2592 static int fflp_hash_clear(struct niu
*np
)
2594 struct fcram_hash_ipv4 ent
;
2597 /* IPV4 hash entry with valid bit clear, rest is don't care. */
2598 memset(&ent
, 0, sizeof(ent
));
2599 ent
.header
= HASH_HEADER_EXT
;
2601 for (i
= 0; i
< FCRAM_SIZE
; i
+= sizeof(ent
)) {
2602 int err
= hash_write(np
, 0, i
, 1, (u64
*) &ent
);
2609 static int fflp_early_init(struct niu
*np
)
2611 struct niu_parent
*parent
;
2612 unsigned long flags
;
2615 niu_lock_parent(np
, flags
);
2617 parent
= np
->parent
;
2619 if (!(parent
->flags
& PARENT_FLGS_CLS_HWINIT
)) {
2620 niudbg(PROBE
, "fflp_early_init: Initting hw on port %u\n",
2622 if (np
->parent
->plat_type
!= PLAT_TYPE_NIU
) {
2624 fflp_set_timings(np
);
2625 err
= fflp_disable_all_partitions(np
);
2627 niudbg(PROBE
, "fflp_disable_all_partitions "
2628 "failed, err=%d\n", err
);
2633 err
= tcam_early_init(np
);
2635 niudbg(PROBE
, "tcam_early_init failed, err=%d\n",
2639 fflp_llcsnap_enable(np
, 1);
2640 fflp_errors_enable(np
, 0);
2644 err
= tcam_flush_all(np
);
2646 niudbg(PROBE
, "tcam_flush_all failed, err=%d\n",
2650 if (np
->parent
->plat_type
!= PLAT_TYPE_NIU
) {
2651 err
= fflp_hash_clear(np
);
2653 niudbg(PROBE
, "fflp_hash_clear failed, "
2661 niudbg(PROBE
, "fflp_early_init: Success\n");
2662 parent
->flags
|= PARENT_FLGS_CLS_HWINIT
;
2665 niu_unlock_parent(np
, flags
);
2669 static int niu_set_flow_key(struct niu
*np
, unsigned long class_code
, u64 key
)
2671 if (class_code
< CLASS_CODE_USER_PROG1
||
2672 class_code
> CLASS_CODE_SCTP_IPV6
)
2675 nw64(FLOW_KEY(class_code
- CLASS_CODE_USER_PROG1
), key
);
2679 static int niu_set_tcam_key(struct niu
*np
, unsigned long class_code
, u64 key
)
2681 if (class_code
< CLASS_CODE_USER_PROG1
||
2682 class_code
> CLASS_CODE_SCTP_IPV6
)
2685 nw64(TCAM_KEY(class_code
- CLASS_CODE_USER_PROG1
), key
);
2689 static void niu_rx_skb_append(struct sk_buff
*skb
, struct page
*page
,
2690 u32 offset
, u32 size
)
2692 int i
= skb_shinfo(skb
)->nr_frags
;
2693 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
2696 frag
->page_offset
= offset
;
2700 skb
->data_len
+= size
;
2701 skb
->truesize
+= size
;
2703 skb_shinfo(skb
)->nr_frags
= i
+ 1;
2706 static unsigned int niu_hash_rxaddr(struct rx_ring_info
*rp
, u64 a
)
2709 a
^= (a
>> ilog2(MAX_RBR_RING_SIZE
));
2711 return (a
& (MAX_RBR_RING_SIZE
- 1));
2714 static struct page
*niu_find_rxpage(struct rx_ring_info
*rp
, u64 addr
,
2715 struct page
***link
)
2717 unsigned int h
= niu_hash_rxaddr(rp
, addr
);
2718 struct page
*p
, **pp
;
2721 pp
= &rp
->rxhash
[h
];
2722 for (; (p
= *pp
) != NULL
; pp
= (struct page
**) &p
->mapping
) {
2723 if (p
->index
== addr
) {
2732 static void niu_hash_page(struct rx_ring_info
*rp
, struct page
*page
, u64 base
)
2734 unsigned int h
= niu_hash_rxaddr(rp
, base
);
2737 page
->mapping
= (struct address_space
*) rp
->rxhash
[h
];
2738 rp
->rxhash
[h
] = page
;
2741 static int niu_rbr_add_page(struct niu
*np
, struct rx_ring_info
*rp
,
2742 gfp_t mask
, int start_index
)
2748 page
= alloc_page(mask
);
2752 addr
= np
->ops
->map_page(np
->device
, page
, 0,
2753 PAGE_SIZE
, DMA_FROM_DEVICE
);
2755 niu_hash_page(rp
, page
, addr
);
2756 if (rp
->rbr_blocks_per_page
> 1)
2757 atomic_add(rp
->rbr_blocks_per_page
- 1,
2758 &compound_head(page
)->_count
);
2760 for (i
= 0; i
< rp
->rbr_blocks_per_page
; i
++) {
2761 __le32
*rbr
= &rp
->rbr
[start_index
+ i
];
2763 *rbr
= cpu_to_le32(addr
>> RBR_DESCR_ADDR_SHIFT
);
2764 addr
+= rp
->rbr_block_size
;
2770 static void niu_rbr_refill(struct niu
*np
, struct rx_ring_info
*rp
, gfp_t mask
)
2772 int index
= rp
->rbr_index
;
2775 if ((rp
->rbr_pending
% rp
->rbr_blocks_per_page
) == 0) {
2776 int err
= niu_rbr_add_page(np
, rp
, mask
, index
);
2778 if (unlikely(err
)) {
2783 rp
->rbr_index
+= rp
->rbr_blocks_per_page
;
2784 BUG_ON(rp
->rbr_index
> rp
->rbr_table_size
);
2785 if (rp
->rbr_index
== rp
->rbr_table_size
)
2788 if (rp
->rbr_pending
>= rp
->rbr_kick_thresh
) {
2789 nw64(RBR_KICK(rp
->rx_channel
), rp
->rbr_pending
);
2790 rp
->rbr_pending
= 0;
2795 static int niu_rx_pkt_ignore(struct niu
*np
, struct rx_ring_info
*rp
)
2797 unsigned int index
= rp
->rcr_index
;
2802 struct page
*page
, **link
;
2808 val
= le64_to_cpup(&rp
->rcr
[index
]);
2809 addr
= (val
& RCR_ENTRY_PKT_BUF_ADDR
) <<
2810 RCR_ENTRY_PKT_BUF_ADDR_SHIFT
;
2811 page
= niu_find_rxpage(rp
, addr
, &link
);
2813 rcr_size
= rp
->rbr_sizes
[(val
& RCR_ENTRY_PKTBUFSZ
) >>
2814 RCR_ENTRY_PKTBUFSZ_SHIFT
];
2815 if ((page
->index
+ PAGE_SIZE
) - rcr_size
== addr
) {
2816 *link
= (struct page
*) page
->mapping
;
2817 np
->ops
->unmap_page(np
->device
, page
->index
,
2818 PAGE_SIZE
, DMA_FROM_DEVICE
);
2820 page
->mapping
= NULL
;
2822 rp
->rbr_refill_pending
++;
2825 index
= NEXT_RCR(rp
, index
);
2826 if (!(val
& RCR_ENTRY_MULTI
))
2830 rp
->rcr_index
= index
;
2835 static int niu_process_rx_pkt(struct niu
*np
, struct rx_ring_info
*rp
)
2837 unsigned int index
= rp
->rcr_index
;
2838 struct sk_buff
*skb
;
2841 skb
= netdev_alloc_skb(np
->dev
, RX_SKB_ALLOC_SIZE
);
2843 return niu_rx_pkt_ignore(np
, rp
);
2847 struct page
*page
, **link
;
2848 u32 rcr_size
, append_size
;
2853 val
= le64_to_cpup(&rp
->rcr
[index
]);
2855 len
= (val
& RCR_ENTRY_L2_LEN
) >>
2856 RCR_ENTRY_L2_LEN_SHIFT
;
2859 addr
= (val
& RCR_ENTRY_PKT_BUF_ADDR
) <<
2860 RCR_ENTRY_PKT_BUF_ADDR_SHIFT
;
2861 page
= niu_find_rxpage(rp
, addr
, &link
);
2863 rcr_size
= rp
->rbr_sizes
[(val
& RCR_ENTRY_PKTBUFSZ
) >>
2864 RCR_ENTRY_PKTBUFSZ_SHIFT
];
2866 off
= addr
& ~PAGE_MASK
;
2867 append_size
= rcr_size
;
2874 ptype
= (val
>> RCR_ENTRY_PKT_TYPE_SHIFT
);
2875 if ((ptype
== RCR_PKT_TYPE_TCP
||
2876 ptype
== RCR_PKT_TYPE_UDP
) &&
2877 !(val
& (RCR_ENTRY_NOPORT
|
2879 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
2881 skb
->ip_summed
= CHECKSUM_NONE
;
2883 if (!(val
& RCR_ENTRY_MULTI
))
2884 append_size
= len
- skb
->len
;
2886 niu_rx_skb_append(skb
, page
, off
, append_size
);
2887 if ((page
->index
+ rp
->rbr_block_size
) - rcr_size
== addr
) {
2888 *link
= (struct page
*) page
->mapping
;
2889 np
->ops
->unmap_page(np
->device
, page
->index
,
2890 PAGE_SIZE
, DMA_FROM_DEVICE
);
2892 page
->mapping
= NULL
;
2893 rp
->rbr_refill_pending
++;
2897 index
= NEXT_RCR(rp
, index
);
2898 if (!(val
& RCR_ENTRY_MULTI
))
2902 rp
->rcr_index
= index
;
2904 skb_reserve(skb
, NET_IP_ALIGN
);
2905 __pskb_pull_tail(skb
, min(len
, NIU_RXPULL_MAX
));
2908 rp
->rx_bytes
+= skb
->len
;
2910 skb
->protocol
= eth_type_trans(skb
, np
->dev
);
2911 netif_receive_skb(skb
);
2913 np
->dev
->last_rx
= jiffies
;
2918 static int niu_rbr_fill(struct niu
*np
, struct rx_ring_info
*rp
, gfp_t mask
)
2920 int blocks_per_page
= rp
->rbr_blocks_per_page
;
2921 int err
, index
= rp
->rbr_index
;
2924 while (index
< (rp
->rbr_table_size
- blocks_per_page
)) {
2925 err
= niu_rbr_add_page(np
, rp
, mask
, index
);
2929 index
+= blocks_per_page
;
2932 rp
->rbr_index
= index
;
2936 static void niu_rbr_free(struct niu
*np
, struct rx_ring_info
*rp
)
2940 for (i
= 0; i
< MAX_RBR_RING_SIZE
; i
++) {
2943 page
= rp
->rxhash
[i
];
2945 struct page
*next
= (struct page
*) page
->mapping
;
2946 u64 base
= page
->index
;
2948 np
->ops
->unmap_page(np
->device
, base
, PAGE_SIZE
,
2951 page
->mapping
= NULL
;
2959 for (i
= 0; i
< rp
->rbr_table_size
; i
++)
2960 rp
->rbr
[i
] = cpu_to_le32(0);
2964 static int release_tx_packet(struct niu
*np
, struct tx_ring_info
*rp
, int idx
)
2966 struct tx_buff_info
*tb
= &rp
->tx_buffs
[idx
];
2967 struct sk_buff
*skb
= tb
->skb
;
2968 struct tx_pkt_hdr
*tp
;
2972 tp
= (struct tx_pkt_hdr
*) skb
->data
;
2973 tx_flags
= le64_to_cpup(&tp
->flags
);
2976 rp
->tx_bytes
+= (((tx_flags
& TXHDR_LEN
) >> TXHDR_LEN_SHIFT
) -
2977 ((tx_flags
& TXHDR_PAD
) / 2));
2979 len
= skb_headlen(skb
);
2980 np
->ops
->unmap_single(np
->device
, tb
->mapping
,
2981 len
, DMA_TO_DEVICE
);
2983 if (le64_to_cpu(rp
->descr
[idx
]) & TX_DESC_MARK
)
2988 idx
= NEXT_TX(rp
, idx
);
2989 len
-= MAX_TX_DESC_LEN
;
2992 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
2993 tb
= &rp
->tx_buffs
[idx
];
2994 BUG_ON(tb
->skb
!= NULL
);
2995 np
->ops
->unmap_page(np
->device
, tb
->mapping
,
2996 skb_shinfo(skb
)->frags
[i
].size
,
2998 idx
= NEXT_TX(rp
, idx
);
3006 #define NIU_TX_WAKEUP_THRESH(rp) ((rp)->pending / 4)
3008 static void niu_tx_work(struct niu
*np
, struct tx_ring_info
*rp
)
3015 if (unlikely(!(cs
& (TX_CS_MK
| TX_CS_MMK
))))
3018 tmp
= pkt_cnt
= (cs
& TX_CS_PKT_CNT
) >> TX_CS_PKT_CNT_SHIFT
;
3019 pkt_cnt
= (pkt_cnt
- rp
->last_pkt_cnt
) &
3020 (TX_CS_PKT_CNT
>> TX_CS_PKT_CNT_SHIFT
);
3022 rp
->last_pkt_cnt
= tmp
;
3026 niudbg(TX_DONE
, "%s: niu_tx_work() pkt_cnt[%u] cons[%d]\n",
3027 np
->dev
->name
, pkt_cnt
, cons
);
3030 cons
= release_tx_packet(np
, rp
, cons
);
3036 if (unlikely(netif_queue_stopped(np
->dev
) &&
3037 (niu_tx_avail(rp
) > NIU_TX_WAKEUP_THRESH(rp
)))) {
3038 netif_tx_lock(np
->dev
);
3039 if (netif_queue_stopped(np
->dev
) &&
3040 (niu_tx_avail(rp
) > NIU_TX_WAKEUP_THRESH(rp
)))
3041 netif_wake_queue(np
->dev
);
3042 netif_tx_unlock(np
->dev
);
3046 static int niu_rx_work(struct niu
*np
, struct rx_ring_info
*rp
, int budget
)
3048 int qlen
, rcr_done
= 0, work_done
= 0;
3049 struct rxdma_mailbox
*mbox
= rp
->mbox
;
3053 stat
= nr64(RX_DMA_CTL_STAT(rp
->rx_channel
));
3054 qlen
= nr64(RCRSTAT_A(rp
->rx_channel
)) & RCRSTAT_A_QLEN
;
3056 stat
= le64_to_cpup(&mbox
->rx_dma_ctl_stat
);
3057 qlen
= (le64_to_cpup(&mbox
->rcrstat_a
) & RCRSTAT_A_QLEN
);
3059 mbox
->rx_dma_ctl_stat
= 0;
3060 mbox
->rcrstat_a
= 0;
3062 niudbg(RX_STATUS
, "%s: niu_rx_work(chan[%d]), stat[%llx] qlen=%d\n",
3063 np
->dev
->name
, rp
->rx_channel
, (unsigned long long) stat
, qlen
);
3065 rcr_done
= work_done
= 0;
3066 qlen
= min(qlen
, budget
);
3067 while (work_done
< qlen
) {
3068 rcr_done
+= niu_process_rx_pkt(np
, rp
);
3072 if (rp
->rbr_refill_pending
>= rp
->rbr_kick_thresh
) {
3075 for (i
= 0; i
< rp
->rbr_refill_pending
; i
++)
3076 niu_rbr_refill(np
, rp
, GFP_ATOMIC
);
3077 rp
->rbr_refill_pending
= 0;
3080 stat
= (RX_DMA_CTL_STAT_MEX
|
3081 ((u64
)work_done
<< RX_DMA_CTL_STAT_PKTREAD_SHIFT
) |
3082 ((u64
)rcr_done
<< RX_DMA_CTL_STAT_PTRREAD_SHIFT
));
3084 nw64(RX_DMA_CTL_STAT(rp
->rx_channel
), stat
);
3089 static int niu_poll_core(struct niu
*np
, struct niu_ldg
*lp
, int budget
)
3092 u32 tx_vec
= (v0
>> 32);
3093 u32 rx_vec
= (v0
& 0xffffffff);
3094 int i
, work_done
= 0;
3096 niudbg(INTR
, "%s: niu_poll_core() v0[%016llx]\n",
3097 np
->dev
->name
, (unsigned long long) v0
);
3099 for (i
= 0; i
< np
->num_tx_rings
; i
++) {
3100 struct tx_ring_info
*rp
= &np
->tx_rings
[i
];
3101 if (tx_vec
& (1 << rp
->tx_channel
))
3102 niu_tx_work(np
, rp
);
3103 nw64(LD_IM0(LDN_TXDMA(rp
->tx_channel
)), 0);
3106 for (i
= 0; i
< np
->num_rx_rings
; i
++) {
3107 struct rx_ring_info
*rp
= &np
->rx_rings
[i
];
3109 if (rx_vec
& (1 << rp
->rx_channel
)) {
3112 this_work_done
= niu_rx_work(np
, rp
,
3115 budget
-= this_work_done
;
3116 work_done
+= this_work_done
;
3118 nw64(LD_IM0(LDN_RXDMA(rp
->rx_channel
)), 0);
3124 static int niu_poll(struct napi_struct
*napi
, int budget
)
3126 struct niu_ldg
*lp
= container_of(napi
, struct niu_ldg
, napi
);
3127 struct niu
*np
= lp
->np
;
3130 work_done
= niu_poll_core(np
, lp
, budget
);
3132 if (work_done
< budget
) {
3133 netif_rx_complete(np
->dev
, napi
);
3134 niu_ldg_rearm(np
, lp
, 1);
3139 static void niu_log_rxchan_errors(struct niu
*np
, struct rx_ring_info
*rp
,
3142 dev_err(np
->device
, PFX
"%s: RX channel %u errors ( ",
3143 np
->dev
->name
, rp
->rx_channel
);
3145 if (stat
& RX_DMA_CTL_STAT_RBR_TMOUT
)
3146 printk("RBR_TMOUT ");
3147 if (stat
& RX_DMA_CTL_STAT_RSP_CNT_ERR
)
3149 if (stat
& RX_DMA_CTL_STAT_BYTE_EN_BUS
)
3150 printk("BYTE_EN_BUS ");
3151 if (stat
& RX_DMA_CTL_STAT_RSP_DAT_ERR
)
3153 if (stat
& RX_DMA_CTL_STAT_RCR_ACK_ERR
)
3155 if (stat
& RX_DMA_CTL_STAT_RCR_SHA_PAR
)
3156 printk("RCR_SHA_PAR ");
3157 if (stat
& RX_DMA_CTL_STAT_RBR_PRE_PAR
)
3158 printk("RBR_PRE_PAR ");
3159 if (stat
& RX_DMA_CTL_STAT_CONFIG_ERR
)
3161 if (stat
& RX_DMA_CTL_STAT_RCRINCON
)
3162 printk("RCRINCON ");
3163 if (stat
& RX_DMA_CTL_STAT_RCRFULL
)
3165 if (stat
& RX_DMA_CTL_STAT_RBRFULL
)
3167 if (stat
& RX_DMA_CTL_STAT_RBRLOGPAGE
)
3168 printk("RBRLOGPAGE ");
3169 if (stat
& RX_DMA_CTL_STAT_CFIGLOGPAGE
)
3170 printk("CFIGLOGPAGE ");
3171 if (stat
& RX_DMA_CTL_STAT_DC_FIFO_ERR
)
3177 static int niu_rx_error(struct niu
*np
, struct rx_ring_info
*rp
)
3179 u64 stat
= nr64(RX_DMA_CTL_STAT(rp
->rx_channel
));
3183 if (stat
& (RX_DMA_CTL_STAT_CHAN_FATAL
|
3184 RX_DMA_CTL_STAT_PORT_FATAL
))
3188 dev_err(np
->device
, PFX
"%s: RX channel %u error, stat[%llx]\n",
3189 np
->dev
->name
, rp
->rx_channel
,
3190 (unsigned long long) stat
);
3192 niu_log_rxchan_errors(np
, rp
, stat
);
3195 nw64(RX_DMA_CTL_STAT(rp
->rx_channel
),
3196 stat
& RX_DMA_CTL_WRITE_CLEAR_ERRS
);
3201 static void niu_log_txchan_errors(struct niu
*np
, struct tx_ring_info
*rp
,
3204 dev_err(np
->device
, PFX
"%s: TX channel %u errors ( ",
3205 np
->dev
->name
, rp
->tx_channel
);
3207 if (cs
& TX_CS_MBOX_ERR
)
3209 if (cs
& TX_CS_PKT_SIZE_ERR
)
3210 printk("PKT_SIZE ");
3211 if (cs
& TX_CS_TX_RING_OFLOW
)
3212 printk("TX_RING_OFLOW ");
3213 if (cs
& TX_CS_PREF_BUF_PAR_ERR
)
3214 printk("PREF_BUF_PAR ");
3215 if (cs
& TX_CS_NACK_PREF
)
3216 printk("NACK_PREF ");
3217 if (cs
& TX_CS_NACK_PKT_RD
)
3218 printk("NACK_PKT_RD ");
3219 if (cs
& TX_CS_CONF_PART_ERR
)
3220 printk("CONF_PART ");
3221 if (cs
& TX_CS_PKT_PRT_ERR
)
3227 static int niu_tx_error(struct niu
*np
, struct tx_ring_info
*rp
)
3231 cs
= nr64(TX_CS(rp
->tx_channel
));
3232 logh
= nr64(TX_RNG_ERR_LOGH(rp
->tx_channel
));
3233 logl
= nr64(TX_RNG_ERR_LOGL(rp
->tx_channel
));
3235 dev_err(np
->device
, PFX
"%s: TX channel %u error, "
3236 "cs[%llx] logh[%llx] logl[%llx]\n",
3237 np
->dev
->name
, rp
->tx_channel
,
3238 (unsigned long long) cs
,
3239 (unsigned long long) logh
,
3240 (unsigned long long) logl
);
3242 niu_log_txchan_errors(np
, rp
, cs
);
3247 static int niu_mif_interrupt(struct niu
*np
)
3249 u64 mif_status
= nr64(MIF_STATUS
);
3252 if (np
->flags
& NIU_FLAGS_XMAC
) {
3253 u64 xrxmac_stat
= nr64_mac(XRXMAC_STATUS
);
3255 if (xrxmac_stat
& XRXMAC_STATUS_PHY_MDINT
)
3259 dev_err(np
->device
, PFX
"%s: MIF interrupt, "
3260 "stat[%llx] phy_mdint(%d)\n",
3261 np
->dev
->name
, (unsigned long long) mif_status
, phy_mdint
);
3266 static void niu_xmac_interrupt(struct niu
*np
)
3268 struct niu_xmac_stats
*mp
= &np
->mac_stats
.xmac
;
3271 val
= nr64_mac(XTXMAC_STATUS
);
3272 if (val
& XTXMAC_STATUS_FRAME_CNT_EXP
)
3273 mp
->tx_frames
+= TXMAC_FRM_CNT_COUNT
;
3274 if (val
& XTXMAC_STATUS_BYTE_CNT_EXP
)
3275 mp
->tx_bytes
+= TXMAC_BYTE_CNT_COUNT
;
3276 if (val
& XTXMAC_STATUS_TXFIFO_XFR_ERR
)
3277 mp
->tx_fifo_errors
++;
3278 if (val
& XTXMAC_STATUS_TXMAC_OFLOW
)
3279 mp
->tx_overflow_errors
++;
3280 if (val
& XTXMAC_STATUS_MAX_PSIZE_ERR
)
3281 mp
->tx_max_pkt_size_errors
++;
3282 if (val
& XTXMAC_STATUS_TXMAC_UFLOW
)
3283 mp
->tx_underflow_errors
++;
3285 val
= nr64_mac(XRXMAC_STATUS
);
3286 if (val
& XRXMAC_STATUS_LCL_FLT_STATUS
)
3287 mp
->rx_local_faults
++;
3288 if (val
& XRXMAC_STATUS_RFLT_DET
)
3289 mp
->rx_remote_faults
++;
3290 if (val
& XRXMAC_STATUS_LFLT_CNT_EXP
)
3291 mp
->rx_link_faults
+= LINK_FAULT_CNT_COUNT
;
3292 if (val
& XRXMAC_STATUS_ALIGNERR_CNT_EXP
)
3293 mp
->rx_align_errors
+= RXMAC_ALIGN_ERR_CNT_COUNT
;
3294 if (val
& XRXMAC_STATUS_RXFRAG_CNT_EXP
)
3295 mp
->rx_frags
+= RXMAC_FRAG_CNT_COUNT
;
3296 if (val
& XRXMAC_STATUS_RXMULTF_CNT_EXP
)
3297 mp
->rx_mcasts
+= RXMAC_MC_FRM_CNT_COUNT
;
3298 if (val
& XRXMAC_STATUS_RXBCAST_CNT_EXP
)
3299 mp
->rx_bcasts
+= RXMAC_BC_FRM_CNT_COUNT
;
3300 if (val
& XRXMAC_STATUS_RXBCAST_CNT_EXP
)
3301 mp
->rx_bcasts
+= RXMAC_BC_FRM_CNT_COUNT
;
3302 if (val
& XRXMAC_STATUS_RXHIST1_CNT_EXP
)
3303 mp
->rx_hist_cnt1
+= RXMAC_HIST_CNT1_COUNT
;
3304 if (val
& XRXMAC_STATUS_RXHIST2_CNT_EXP
)
3305 mp
->rx_hist_cnt2
+= RXMAC_HIST_CNT2_COUNT
;
3306 if (val
& XRXMAC_STATUS_RXHIST3_CNT_EXP
)
3307 mp
->rx_hist_cnt3
+= RXMAC_HIST_CNT3_COUNT
;
3308 if (val
& XRXMAC_STATUS_RXHIST4_CNT_EXP
)
3309 mp
->rx_hist_cnt4
+= RXMAC_HIST_CNT4_COUNT
;
3310 if (val
& XRXMAC_STATUS_RXHIST5_CNT_EXP
)
3311 mp
->rx_hist_cnt5
+= RXMAC_HIST_CNT5_COUNT
;
3312 if (val
& XRXMAC_STATUS_RXHIST6_CNT_EXP
)
3313 mp
->rx_hist_cnt6
+= RXMAC_HIST_CNT6_COUNT
;
3314 if (val
& XRXMAC_STATUS_RXHIST7_CNT_EXP
)
3315 mp
->rx_hist_cnt7
+= RXMAC_HIST_CNT7_COUNT
;
3316 if (val
& XRXMAC_STAT_MSK_RXOCTET_CNT_EXP
)
3317 mp
->rx_octets
+= RXMAC_BT_CNT_COUNT
;
3318 if (val
& XRXMAC_STATUS_CVIOLERR_CNT_EXP
)
3319 mp
->rx_code_violations
+= RXMAC_CD_VIO_CNT_COUNT
;
3320 if (val
& XRXMAC_STATUS_LENERR_CNT_EXP
)
3321 mp
->rx_len_errors
+= RXMAC_MPSZER_CNT_COUNT
;
3322 if (val
& XRXMAC_STATUS_CRCERR_CNT_EXP
)
3323 mp
->rx_crc_errors
+= RXMAC_CRC_ER_CNT_COUNT
;
3324 if (val
& XRXMAC_STATUS_RXUFLOW
)
3325 mp
->rx_underflows
++;
3326 if (val
& XRXMAC_STATUS_RXOFLOW
)
3329 val
= nr64_mac(XMAC_FC_STAT
);
3330 if (val
& XMAC_FC_STAT_TX_MAC_NPAUSE
)
3331 mp
->pause_off_state
++;
3332 if (val
& XMAC_FC_STAT_TX_MAC_PAUSE
)
3333 mp
->pause_on_state
++;
3334 if (val
& XMAC_FC_STAT_RX_MAC_RPAUSE
)
3335 mp
->pause_received
++;
3338 static void niu_bmac_interrupt(struct niu
*np
)
3340 struct niu_bmac_stats
*mp
= &np
->mac_stats
.bmac
;
3343 val
= nr64_mac(BTXMAC_STATUS
);
3344 if (val
& BTXMAC_STATUS_UNDERRUN
)
3345 mp
->tx_underflow_errors
++;
3346 if (val
& BTXMAC_STATUS_MAX_PKT_ERR
)
3347 mp
->tx_max_pkt_size_errors
++;
3348 if (val
& BTXMAC_STATUS_BYTE_CNT_EXP
)
3349 mp
->tx_bytes
+= BTXMAC_BYTE_CNT_COUNT
;
3350 if (val
& BTXMAC_STATUS_FRAME_CNT_EXP
)
3351 mp
->tx_frames
+= BTXMAC_FRM_CNT_COUNT
;
3353 val
= nr64_mac(BRXMAC_STATUS
);
3354 if (val
& BRXMAC_STATUS_OVERFLOW
)
3356 if (val
& BRXMAC_STATUS_FRAME_CNT_EXP
)
3357 mp
->rx_frames
+= BRXMAC_FRAME_CNT_COUNT
;
3358 if (val
& BRXMAC_STATUS_ALIGN_ERR_EXP
)
3359 mp
->rx_align_errors
+= BRXMAC_ALIGN_ERR_CNT_COUNT
;
3360 if (val
& BRXMAC_STATUS_CRC_ERR_EXP
)
3361 mp
->rx_crc_errors
+= BRXMAC_ALIGN_ERR_CNT_COUNT
;
3362 if (val
& BRXMAC_STATUS_LEN_ERR_EXP
)
3363 mp
->rx_len_errors
+= BRXMAC_CODE_VIOL_ERR_CNT_COUNT
;
3365 val
= nr64_mac(BMAC_CTRL_STATUS
);
3366 if (val
& BMAC_CTRL_STATUS_NOPAUSE
)
3367 mp
->pause_off_state
++;
3368 if (val
& BMAC_CTRL_STATUS_PAUSE
)
3369 mp
->pause_on_state
++;
3370 if (val
& BMAC_CTRL_STATUS_PAUSE_RECV
)
3371 mp
->pause_received
++;
3374 static int niu_mac_interrupt(struct niu
*np
)
3376 if (np
->flags
& NIU_FLAGS_XMAC
)
3377 niu_xmac_interrupt(np
);
3379 niu_bmac_interrupt(np
);
3384 static void niu_log_device_error(struct niu
*np
, u64 stat
)
3386 dev_err(np
->device
, PFX
"%s: Core device errors ( ",
3389 if (stat
& SYS_ERR_MASK_META2
)
3391 if (stat
& SYS_ERR_MASK_META1
)
3393 if (stat
& SYS_ERR_MASK_PEU
)
3395 if (stat
& SYS_ERR_MASK_TXC
)
3397 if (stat
& SYS_ERR_MASK_RDMC
)
3399 if (stat
& SYS_ERR_MASK_TDMC
)
3401 if (stat
& SYS_ERR_MASK_ZCP
)
3403 if (stat
& SYS_ERR_MASK_FFLP
)
3405 if (stat
& SYS_ERR_MASK_IPP
)
3407 if (stat
& SYS_ERR_MASK_MAC
)
3409 if (stat
& SYS_ERR_MASK_SMX
)
3415 static int niu_device_error(struct niu
*np
)
3417 u64 stat
= nr64(SYS_ERR_STAT
);
3419 dev_err(np
->device
, PFX
"%s: Core device error, stat[%llx]\n",
3420 np
->dev
->name
, (unsigned long long) stat
);
3422 niu_log_device_error(np
, stat
);
3427 static int niu_slowpath_interrupt(struct niu
*np
, struct niu_ldg
*lp
,
3428 u64 v0
, u64 v1
, u64 v2
)
3437 if (v1
& 0x00000000ffffffffULL
) {
3438 u32 rx_vec
= (v1
& 0xffffffff);
3440 for (i
= 0; i
< np
->num_rx_rings
; i
++) {
3441 struct rx_ring_info
*rp
= &np
->rx_rings
[i
];
3443 if (rx_vec
& (1 << rp
->rx_channel
)) {
3444 int r
= niu_rx_error(np
, rp
);
3449 nw64(RX_DMA_CTL_STAT(rp
->rx_channel
),
3450 RX_DMA_CTL_STAT_MEX
);
3455 if (v1
& 0x7fffffff00000000ULL
) {
3456 u32 tx_vec
= (v1
>> 32) & 0x7fffffff;
3458 for (i
= 0; i
< np
->num_tx_rings
; i
++) {
3459 struct tx_ring_info
*rp
= &np
->tx_rings
[i
];
3461 if (tx_vec
& (1 << rp
->tx_channel
)) {
3462 int r
= niu_tx_error(np
, rp
);
3468 if ((v0
| v1
) & 0x8000000000000000ULL
) {
3469 int r
= niu_mif_interrupt(np
);
3475 int r
= niu_mac_interrupt(np
);
3480 int r
= niu_device_error(np
);
3487 niu_enable_interrupts(np
, 0);
3492 static void niu_rxchan_intr(struct niu
*np
, struct rx_ring_info
*rp
,
3495 struct rxdma_mailbox
*mbox
= rp
->mbox
;
3496 u64 stat_write
, stat
= le64_to_cpup(&mbox
->rx_dma_ctl_stat
);
3498 stat_write
= (RX_DMA_CTL_STAT_RCRTHRES
|
3499 RX_DMA_CTL_STAT_RCRTO
);
3500 nw64(RX_DMA_CTL_STAT(rp
->rx_channel
), stat_write
);
3502 niudbg(INTR
, "%s: rxchan_intr stat[%llx]\n",
3503 np
->dev
->name
, (unsigned long long) stat
);
3506 static void niu_txchan_intr(struct niu
*np
, struct tx_ring_info
*rp
,
3509 rp
->tx_cs
= nr64(TX_CS(rp
->tx_channel
));
3511 niudbg(INTR
, "%s: txchan_intr cs[%llx]\n",
3512 np
->dev
->name
, (unsigned long long) rp
->tx_cs
);
3515 static void __niu_fastpath_interrupt(struct niu
*np
, int ldg
, u64 v0
)
3517 struct niu_parent
*parent
= np
->parent
;
3521 tx_vec
= (v0
>> 32);
3522 rx_vec
= (v0
& 0xffffffff);
3524 for (i
= 0; i
< np
->num_rx_rings
; i
++) {
3525 struct rx_ring_info
*rp
= &np
->rx_rings
[i
];
3526 int ldn
= LDN_RXDMA(rp
->rx_channel
);
3528 if (parent
->ldg_map
[ldn
] != ldg
)
3531 nw64(LD_IM0(ldn
), LD_IM0_MASK
);
3532 if (rx_vec
& (1 << rp
->rx_channel
))
3533 niu_rxchan_intr(np
, rp
, ldn
);
3536 for (i
= 0; i
< np
->num_tx_rings
; i
++) {
3537 struct tx_ring_info
*rp
= &np
->tx_rings
[i
];
3538 int ldn
= LDN_TXDMA(rp
->tx_channel
);
3540 if (parent
->ldg_map
[ldn
] != ldg
)
3543 nw64(LD_IM0(ldn
), LD_IM0_MASK
);
3544 if (tx_vec
& (1 << rp
->tx_channel
))
3545 niu_txchan_intr(np
, rp
, ldn
);
3549 static void niu_schedule_napi(struct niu
*np
, struct niu_ldg
*lp
,
3550 u64 v0
, u64 v1
, u64 v2
)
3552 if (likely(netif_rx_schedule_prep(np
->dev
, &lp
->napi
))) {
3556 __niu_fastpath_interrupt(np
, lp
->ldg_num
, v0
);
3557 __netif_rx_schedule(np
->dev
, &lp
->napi
);
3561 static irqreturn_t
niu_interrupt(int irq
, void *dev_id
)
3563 struct niu_ldg
*lp
= dev_id
;
3564 struct niu
*np
= lp
->np
;
3565 int ldg
= lp
->ldg_num
;
3566 unsigned long flags
;
3569 if (netif_msg_intr(np
))
3570 printk(KERN_DEBUG PFX
"niu_interrupt() ldg[%p](%d) ",
3573 spin_lock_irqsave(&np
->lock
, flags
);
3575 v0
= nr64(LDSV0(ldg
));
3576 v1
= nr64(LDSV1(ldg
));
3577 v2
= nr64(LDSV2(ldg
));
3579 if (netif_msg_intr(np
))
3580 printk("v0[%llx] v1[%llx] v2[%llx]\n",
3581 (unsigned long long) v0
,
3582 (unsigned long long) v1
,
3583 (unsigned long long) v2
);
3585 if (unlikely(!v0
&& !v1
&& !v2
)) {
3586 spin_unlock_irqrestore(&np
->lock
, flags
);
3590 if (unlikely((v0
& ((u64
)1 << LDN_MIF
)) || v1
|| v2
)) {
3591 int err
= niu_slowpath_interrupt(np
, lp
, v0
, v1
, v2
);
3595 if (likely(v0
& ~((u64
)1 << LDN_MIF
)))
3596 niu_schedule_napi(np
, lp
, v0
, v1
, v2
);
3598 niu_ldg_rearm(np
, lp
, 1);
3600 spin_unlock_irqrestore(&np
->lock
, flags
);
3605 static void niu_free_rx_ring_info(struct niu
*np
, struct rx_ring_info
*rp
)
3608 np
->ops
->free_coherent(np
->device
,
3609 sizeof(struct rxdma_mailbox
),
3610 rp
->mbox
, rp
->mbox_dma
);
3614 np
->ops
->free_coherent(np
->device
,
3615 MAX_RCR_RING_SIZE
* sizeof(__le64
),
3616 rp
->rcr
, rp
->rcr_dma
);
3618 rp
->rcr_table_size
= 0;
3622 niu_rbr_free(np
, rp
);
3624 np
->ops
->free_coherent(np
->device
,
3625 MAX_RBR_RING_SIZE
* sizeof(__le32
),
3626 rp
->rbr
, rp
->rbr_dma
);
3628 rp
->rbr_table_size
= 0;
3635 static void niu_free_tx_ring_info(struct niu
*np
, struct tx_ring_info
*rp
)
3638 np
->ops
->free_coherent(np
->device
,
3639 sizeof(struct txdma_mailbox
),
3640 rp
->mbox
, rp
->mbox_dma
);
3646 for (i
= 0; i
< MAX_TX_RING_SIZE
; i
++) {
3647 if (rp
->tx_buffs
[i
].skb
)
3648 (void) release_tx_packet(np
, rp
, i
);
3651 np
->ops
->free_coherent(np
->device
,
3652 MAX_TX_RING_SIZE
* sizeof(__le64
),
3653 rp
->descr
, rp
->descr_dma
);
3662 static void niu_free_channels(struct niu
*np
)
3667 for (i
= 0; i
< np
->num_rx_rings
; i
++) {
3668 struct rx_ring_info
*rp
= &np
->rx_rings
[i
];
3670 niu_free_rx_ring_info(np
, rp
);
3672 kfree(np
->rx_rings
);
3673 np
->rx_rings
= NULL
;
3674 np
->num_rx_rings
= 0;
3678 for (i
= 0; i
< np
->num_tx_rings
; i
++) {
3679 struct tx_ring_info
*rp
= &np
->tx_rings
[i
];
3681 niu_free_tx_ring_info(np
, rp
);
3683 kfree(np
->tx_rings
);
3684 np
->tx_rings
= NULL
;
3685 np
->num_tx_rings
= 0;
3689 static int niu_alloc_rx_ring_info(struct niu
*np
,
3690 struct rx_ring_info
*rp
)
3692 BUILD_BUG_ON(sizeof(struct rxdma_mailbox
) != 64);
3694 rp
->rxhash
= kzalloc(MAX_RBR_RING_SIZE
* sizeof(struct page
*),
3699 rp
->mbox
= np
->ops
->alloc_coherent(np
->device
,
3700 sizeof(struct rxdma_mailbox
),
3701 &rp
->mbox_dma
, GFP_KERNEL
);
3704 if ((unsigned long)rp
->mbox
& (64UL - 1)) {
3705 dev_err(np
->device
, PFX
"%s: Coherent alloc gives misaligned "
3706 "RXDMA mailbox %p\n", np
->dev
->name
, rp
->mbox
);
3710 rp
->rcr
= np
->ops
->alloc_coherent(np
->device
,
3711 MAX_RCR_RING_SIZE
* sizeof(__le64
),
3712 &rp
->rcr_dma
, GFP_KERNEL
);
3715 if ((unsigned long)rp
->rcr
& (64UL - 1)) {
3716 dev_err(np
->device
, PFX
"%s: Coherent alloc gives misaligned "
3717 "RXDMA RCR table %p\n", np
->dev
->name
, rp
->rcr
);
3720 rp
->rcr_table_size
= MAX_RCR_RING_SIZE
;
3723 rp
->rbr
= np
->ops
->alloc_coherent(np
->device
,
3724 MAX_RBR_RING_SIZE
* sizeof(__le32
),
3725 &rp
->rbr_dma
, GFP_KERNEL
);
3728 if ((unsigned long)rp
->rbr
& (64UL - 1)) {
3729 dev_err(np
->device
, PFX
"%s: Coherent alloc gives misaligned "
3730 "RXDMA RBR table %p\n", np
->dev
->name
, rp
->rbr
);
3733 rp
->rbr_table_size
= MAX_RBR_RING_SIZE
;
3735 rp
->rbr_pending
= 0;
3740 static void niu_set_max_burst(struct niu
*np
, struct tx_ring_info
*rp
)
3742 int mtu
= np
->dev
->mtu
;
3744 /* These values are recommended by the HW designers for fair
3745 * utilization of DRR amongst the rings.
3747 rp
->max_burst
= mtu
+ 32;
3748 if (rp
->max_burst
> 4096)
3749 rp
->max_burst
= 4096;
3752 static int niu_alloc_tx_ring_info(struct niu
*np
,
3753 struct tx_ring_info
*rp
)
3755 BUILD_BUG_ON(sizeof(struct txdma_mailbox
) != 64);
3757 rp
->mbox
= np
->ops
->alloc_coherent(np
->device
,
3758 sizeof(struct txdma_mailbox
),
3759 &rp
->mbox_dma
, GFP_KERNEL
);
3762 if ((unsigned long)rp
->mbox
& (64UL - 1)) {
3763 dev_err(np
->device
, PFX
"%s: Coherent alloc gives misaligned "
3764 "TXDMA mailbox %p\n", np
->dev
->name
, rp
->mbox
);
3768 rp
->descr
= np
->ops
->alloc_coherent(np
->device
,
3769 MAX_TX_RING_SIZE
* sizeof(__le64
),
3770 &rp
->descr_dma
, GFP_KERNEL
);
3773 if ((unsigned long)rp
->descr
& (64UL - 1)) {
3774 dev_err(np
->device
, PFX
"%s: Coherent alloc gives misaligned "
3775 "TXDMA descr table %p\n", np
->dev
->name
, rp
->descr
);
3779 rp
->pending
= MAX_TX_RING_SIZE
;
3784 /* XXX make these configurable... XXX */
3785 rp
->mark_freq
= rp
->pending
/ 4;
3787 niu_set_max_burst(np
, rp
);
3792 static void niu_size_rbr(struct niu
*np
, struct rx_ring_info
*rp
)
3796 bss
= min(PAGE_SHIFT
, 15);
3798 rp
->rbr_block_size
= 1 << bss
;
3799 rp
->rbr_blocks_per_page
= 1 << (PAGE_SHIFT
-bss
);
3801 rp
->rbr_sizes
[0] = 256;
3802 rp
->rbr_sizes
[1] = 1024;
3803 if (np
->dev
->mtu
> ETH_DATA_LEN
) {
3804 switch (PAGE_SIZE
) {
3806 rp
->rbr_sizes
[2] = 4096;
3810 rp
->rbr_sizes
[2] = 8192;
3814 rp
->rbr_sizes
[2] = 2048;
3816 rp
->rbr_sizes
[3] = rp
->rbr_block_size
;
3819 static int niu_alloc_channels(struct niu
*np
)
3821 struct niu_parent
*parent
= np
->parent
;
3822 int first_rx_channel
, first_tx_channel
;
3826 first_rx_channel
= first_tx_channel
= 0;
3827 for (i
= 0; i
< port
; i
++) {
3828 first_rx_channel
+= parent
->rxchan_per_port
[i
];
3829 first_tx_channel
+= parent
->txchan_per_port
[i
];
3832 np
->num_rx_rings
= parent
->rxchan_per_port
[port
];
3833 np
->num_tx_rings
= parent
->txchan_per_port
[port
];
3835 np
->rx_rings
= kzalloc(np
->num_rx_rings
* sizeof(struct rx_ring_info
),
3841 for (i
= 0; i
< np
->num_rx_rings
; i
++) {
3842 struct rx_ring_info
*rp
= &np
->rx_rings
[i
];
3845 rp
->rx_channel
= first_rx_channel
+ i
;
3847 err
= niu_alloc_rx_ring_info(np
, rp
);
3851 niu_size_rbr(np
, rp
);
3853 /* XXX better defaults, configurable, etc... XXX */
3854 rp
->nonsyn_window
= 64;
3855 rp
->nonsyn_threshold
= rp
->rcr_table_size
- 64;
3856 rp
->syn_window
= 64;
3857 rp
->syn_threshold
= rp
->rcr_table_size
- 64;
3858 rp
->rcr_pkt_threshold
= 16;
3859 rp
->rcr_timeout
= 8;
3860 rp
->rbr_kick_thresh
= RBR_REFILL_MIN
;
3861 if (rp
->rbr_kick_thresh
< rp
->rbr_blocks_per_page
)
3862 rp
->rbr_kick_thresh
= rp
->rbr_blocks_per_page
;
3864 err
= niu_rbr_fill(np
, rp
, GFP_KERNEL
);
3869 np
->tx_rings
= kzalloc(np
->num_tx_rings
* sizeof(struct tx_ring_info
),
3875 for (i
= 0; i
< np
->num_tx_rings
; i
++) {
3876 struct tx_ring_info
*rp
= &np
->tx_rings
[i
];
3879 rp
->tx_channel
= first_tx_channel
+ i
;
3881 err
= niu_alloc_tx_ring_info(np
, rp
);
3889 niu_free_channels(np
);
3893 static int niu_tx_cs_sng_poll(struct niu
*np
, int channel
)
3897 while (--limit
> 0) {
3898 u64 val
= nr64(TX_CS(channel
));
3899 if (val
& TX_CS_SNG_STATE
)
3905 static int niu_tx_channel_stop(struct niu
*np
, int channel
)
3907 u64 val
= nr64(TX_CS(channel
));
3909 val
|= TX_CS_STOP_N_GO
;
3910 nw64(TX_CS(channel
), val
);
3912 return niu_tx_cs_sng_poll(np
, channel
);
3915 static int niu_tx_cs_reset_poll(struct niu
*np
, int channel
)
3919 while (--limit
> 0) {
3920 u64 val
= nr64(TX_CS(channel
));
3921 if (!(val
& TX_CS_RST
))
3927 static int niu_tx_channel_reset(struct niu
*np
, int channel
)
3929 u64 val
= nr64(TX_CS(channel
));
3933 nw64(TX_CS(channel
), val
);
3935 err
= niu_tx_cs_reset_poll(np
, channel
);
3937 nw64(TX_RING_KICK(channel
), 0);
3942 static int niu_tx_channel_lpage_init(struct niu
*np
, int channel
)
3946 nw64(TX_LOG_MASK1(channel
), 0);
3947 nw64(TX_LOG_VAL1(channel
), 0);
3948 nw64(TX_LOG_MASK2(channel
), 0);
3949 nw64(TX_LOG_VAL2(channel
), 0);
3950 nw64(TX_LOG_PAGE_RELO1(channel
), 0);
3951 nw64(TX_LOG_PAGE_RELO2(channel
), 0);
3952 nw64(TX_LOG_PAGE_HDL(channel
), 0);
3954 val
= (u64
)np
->port
<< TX_LOG_PAGE_VLD_FUNC_SHIFT
;
3955 val
|= (TX_LOG_PAGE_VLD_PAGE0
| TX_LOG_PAGE_VLD_PAGE1
);
3956 nw64(TX_LOG_PAGE_VLD(channel
), val
);
3958 /* XXX TXDMA 32bit mode? XXX */
3963 static void niu_txc_enable_port(struct niu
*np
, int on
)
3965 unsigned long flags
;
3968 niu_lock_parent(np
, flags
);
3969 val
= nr64(TXC_CONTROL
);
3970 mask
= (u64
)1 << np
->port
;
3972 val
|= TXC_CONTROL_ENABLE
| mask
;
3975 if ((val
& ~TXC_CONTROL_ENABLE
) == 0)
3976 val
&= ~TXC_CONTROL_ENABLE
;
3978 nw64(TXC_CONTROL
, val
);
3979 niu_unlock_parent(np
, flags
);
3982 static void niu_txc_set_imask(struct niu
*np
, u64 imask
)
3984 unsigned long flags
;
3987 niu_lock_parent(np
, flags
);
3988 val
= nr64(TXC_INT_MASK
);
3989 val
&= ~TXC_INT_MASK_VAL(np
->port
);
3990 val
|= (imask
<< TXC_INT_MASK_VAL_SHIFT(np
->port
));
3991 niu_unlock_parent(np
, flags
);
3994 static void niu_txc_port_dma_enable(struct niu
*np
, int on
)
4001 for (i
= 0; i
< np
->num_tx_rings
; i
++)
4002 val
|= (1 << np
->tx_rings
[i
].tx_channel
);
4004 nw64(TXC_PORT_DMA(np
->port
), val
);
4007 static int niu_init_one_tx_channel(struct niu
*np
, struct tx_ring_info
*rp
)
4009 int err
, channel
= rp
->tx_channel
;
4012 err
= niu_tx_channel_stop(np
, channel
);
4016 err
= niu_tx_channel_reset(np
, channel
);
4020 err
= niu_tx_channel_lpage_init(np
, channel
);
4024 nw64(TXC_DMA_MAX(channel
), rp
->max_burst
);
4025 nw64(TX_ENT_MSK(channel
), 0);
4027 if (rp
->descr_dma
& ~(TX_RNG_CFIG_STADDR_BASE
|
4028 TX_RNG_CFIG_STADDR
)) {
4029 dev_err(np
->device
, PFX
"%s: TX ring channel %d "
4030 "DMA addr (%llx) is not aligned.\n",
4031 np
->dev
->name
, channel
,
4032 (unsigned long long) rp
->descr_dma
);
4036 /* The length field in TX_RNG_CFIG is measured in 64-byte
4037 * blocks. rp->pending is the number of TX descriptors in
4038 * our ring, 8 bytes each, thus we divide by 8 bytes more
4039 * to get the proper value the chip wants.
4041 ring_len
= (rp
->pending
/ 8);
4043 val
= ((ring_len
<< TX_RNG_CFIG_LEN_SHIFT
) |
4045 nw64(TX_RNG_CFIG(channel
), val
);
4047 if (((rp
->mbox_dma
>> 32) & ~TXDMA_MBH_MBADDR
) ||
4048 ((u32
)rp
->mbox_dma
& ~TXDMA_MBL_MBADDR
)) {
4049 dev_err(np
->device
, PFX
"%s: TX ring channel %d "
4050 "MBOX addr (%llx) is has illegal bits.\n",
4051 np
->dev
->name
, channel
,
4052 (unsigned long long) rp
->mbox_dma
);
4055 nw64(TXDMA_MBH(channel
), rp
->mbox_dma
>> 32);
4056 nw64(TXDMA_MBL(channel
), rp
->mbox_dma
& TXDMA_MBL_MBADDR
);
4058 nw64(TX_CS(channel
), 0);
4060 rp
->last_pkt_cnt
= 0;
4065 static void niu_init_rdc_groups(struct niu
*np
)
4067 struct niu_rdc_tables
*tp
= &np
->parent
->rdc_group_cfg
[np
->port
];
4068 int i
, first_table_num
= tp
->first_table_num
;
4070 for (i
= 0; i
< tp
->num_tables
; i
++) {
4071 struct rdc_table
*tbl
= &tp
->tables
[i
];
4072 int this_table
= first_table_num
+ i
;
4075 for (slot
= 0; slot
< NIU_RDC_TABLE_SLOTS
; slot
++)
4076 nw64(RDC_TBL(this_table
, slot
),
4077 tbl
->rxdma_channel
[slot
]);
4080 nw64(DEF_RDC(np
->port
), np
->parent
->rdc_default
[np
->port
]);
4083 static void niu_init_drr_weight(struct niu
*np
)
4085 int type
= phy_decode(np
->parent
->port_phy
, np
->port
);
4090 val
= PT_DRR_WEIGHT_DEFAULT_10G
;
4095 val
= PT_DRR_WEIGHT_DEFAULT_1G
;
4098 nw64(PT_DRR_WT(np
->port
), val
);
4101 static int niu_init_hostinfo(struct niu
*np
)
4103 struct niu_parent
*parent
= np
->parent
;
4104 struct niu_rdc_tables
*tp
= &parent
->rdc_group_cfg
[np
->port
];
4105 int i
, err
, num_alt
= niu_num_alt_addr(np
);
4106 int first_rdc_table
= tp
->first_table_num
;
4108 err
= niu_set_primary_mac_rdc_table(np
, first_rdc_table
, 1);
4112 err
= niu_set_multicast_mac_rdc_table(np
, first_rdc_table
, 1);
4116 for (i
= 0; i
< num_alt
; i
++) {
4117 err
= niu_set_alt_mac_rdc_table(np
, i
, first_rdc_table
, 1);
4125 static int niu_rx_channel_reset(struct niu
*np
, int channel
)
4127 return niu_set_and_wait_clear(np
, RXDMA_CFIG1(channel
),
4128 RXDMA_CFIG1_RST
, 1000, 10,
4132 static int niu_rx_channel_lpage_init(struct niu
*np
, int channel
)
4136 nw64(RX_LOG_MASK1(channel
), 0);
4137 nw64(RX_LOG_VAL1(channel
), 0);
4138 nw64(RX_LOG_MASK2(channel
), 0);
4139 nw64(RX_LOG_VAL2(channel
), 0);
4140 nw64(RX_LOG_PAGE_RELO1(channel
), 0);
4141 nw64(RX_LOG_PAGE_RELO2(channel
), 0);
4142 nw64(RX_LOG_PAGE_HDL(channel
), 0);
4144 val
= (u64
)np
->port
<< RX_LOG_PAGE_VLD_FUNC_SHIFT
;
4145 val
|= (RX_LOG_PAGE_VLD_PAGE0
| RX_LOG_PAGE_VLD_PAGE1
);
4146 nw64(RX_LOG_PAGE_VLD(channel
), val
);
4151 static void niu_rx_channel_wred_init(struct niu
*np
, struct rx_ring_info
*rp
)
4155 val
= (((u64
)rp
->nonsyn_window
<< RDC_RED_PARA_WIN_SHIFT
) |
4156 ((u64
)rp
->nonsyn_threshold
<< RDC_RED_PARA_THRE_SHIFT
) |
4157 ((u64
)rp
->syn_window
<< RDC_RED_PARA_WIN_SYN_SHIFT
) |
4158 ((u64
)rp
->syn_threshold
<< RDC_RED_PARA_THRE_SYN_SHIFT
));
4159 nw64(RDC_RED_PARA(rp
->rx_channel
), val
);
4162 static int niu_compute_rbr_cfig_b(struct rx_ring_info
*rp
, u64
*ret
)
4166 switch (rp
->rbr_block_size
) {
4168 val
|= (RBR_BLKSIZE_4K
<< RBR_CFIG_B_BLKSIZE_SHIFT
);
4171 val
|= (RBR_BLKSIZE_8K
<< RBR_CFIG_B_BLKSIZE_SHIFT
);
4174 val
|= (RBR_BLKSIZE_16K
<< RBR_CFIG_B_BLKSIZE_SHIFT
);
4177 val
|= (RBR_BLKSIZE_32K
<< RBR_CFIG_B_BLKSIZE_SHIFT
);
4182 val
|= RBR_CFIG_B_VLD2
;
4183 switch (rp
->rbr_sizes
[2]) {
4185 val
|= (RBR_BUFSZ2_2K
<< RBR_CFIG_B_BUFSZ2_SHIFT
);
4188 val
|= (RBR_BUFSZ2_4K
<< RBR_CFIG_B_BUFSZ2_SHIFT
);
4191 val
|= (RBR_BUFSZ2_8K
<< RBR_CFIG_B_BUFSZ2_SHIFT
);
4194 val
|= (RBR_BUFSZ2_16K
<< RBR_CFIG_B_BUFSZ2_SHIFT
);
4200 val
|= RBR_CFIG_B_VLD1
;
4201 switch (rp
->rbr_sizes
[1]) {
4203 val
|= (RBR_BUFSZ1_1K
<< RBR_CFIG_B_BUFSZ1_SHIFT
);
4206 val
|= (RBR_BUFSZ1_2K
<< RBR_CFIG_B_BUFSZ1_SHIFT
);
4209 val
|= (RBR_BUFSZ1_4K
<< RBR_CFIG_B_BUFSZ1_SHIFT
);
4212 val
|= (RBR_BUFSZ1_8K
<< RBR_CFIG_B_BUFSZ1_SHIFT
);
4218 val
|= RBR_CFIG_B_VLD0
;
4219 switch (rp
->rbr_sizes
[0]) {
4221 val
|= (RBR_BUFSZ0_256
<< RBR_CFIG_B_BUFSZ0_SHIFT
);
4224 val
|= (RBR_BUFSZ0_512
<< RBR_CFIG_B_BUFSZ0_SHIFT
);
4227 val
|= (RBR_BUFSZ0_1K
<< RBR_CFIG_B_BUFSZ0_SHIFT
);
4230 val
|= (RBR_BUFSZ0_2K
<< RBR_CFIG_B_BUFSZ0_SHIFT
);
4241 static int niu_enable_rx_channel(struct niu
*np
, int channel
, int on
)
4243 u64 val
= nr64(RXDMA_CFIG1(channel
));
4247 val
|= RXDMA_CFIG1_EN
;
4249 val
&= ~RXDMA_CFIG1_EN
;
4250 nw64(RXDMA_CFIG1(channel
), val
);
4253 while (--limit
> 0) {
4254 if (nr64(RXDMA_CFIG1(channel
)) & RXDMA_CFIG1_QST
)
4263 static int niu_init_one_rx_channel(struct niu
*np
, struct rx_ring_info
*rp
)
4265 int err
, channel
= rp
->rx_channel
;
4268 err
= niu_rx_channel_reset(np
, channel
);
4272 err
= niu_rx_channel_lpage_init(np
, channel
);
4276 niu_rx_channel_wred_init(np
, rp
);
4278 nw64(RX_DMA_ENT_MSK(channel
), RX_DMA_ENT_MSK_RBR_EMPTY
);
4279 nw64(RX_DMA_CTL_STAT(channel
),
4280 (RX_DMA_CTL_STAT_MEX
|
4281 RX_DMA_CTL_STAT_RCRTHRES
|
4282 RX_DMA_CTL_STAT_RCRTO
|
4283 RX_DMA_CTL_STAT_RBR_EMPTY
));
4284 nw64(RXDMA_CFIG1(channel
), rp
->mbox_dma
>> 32);
4285 nw64(RXDMA_CFIG2(channel
), (rp
->mbox_dma
& 0x00000000ffffffc0));
4286 nw64(RBR_CFIG_A(channel
),
4287 ((u64
)rp
->rbr_table_size
<< RBR_CFIG_A_LEN_SHIFT
) |
4288 (rp
->rbr_dma
& (RBR_CFIG_A_STADDR_BASE
| RBR_CFIG_A_STADDR
)));
4289 err
= niu_compute_rbr_cfig_b(rp
, &val
);
4292 nw64(RBR_CFIG_B(channel
), val
);
4293 nw64(RCRCFIG_A(channel
),
4294 ((u64
)rp
->rcr_table_size
<< RCRCFIG_A_LEN_SHIFT
) |
4295 (rp
->rcr_dma
& (RCRCFIG_A_STADDR_BASE
| RCRCFIG_A_STADDR
)));
4296 nw64(RCRCFIG_B(channel
),
4297 ((u64
)rp
->rcr_pkt_threshold
<< RCRCFIG_B_PTHRES_SHIFT
) |
4299 ((u64
)rp
->rcr_timeout
<< RCRCFIG_B_TIMEOUT_SHIFT
));
4301 err
= niu_enable_rx_channel(np
, channel
, 1);
4305 nw64(RBR_KICK(channel
), rp
->rbr_index
);
4307 val
= nr64(RX_DMA_CTL_STAT(channel
));
4308 val
|= RX_DMA_CTL_STAT_RBR_EMPTY
;
4309 nw64(RX_DMA_CTL_STAT(channel
), val
);
4314 static int niu_init_rx_channels(struct niu
*np
)
4316 unsigned long flags
;
4317 u64 seed
= jiffies_64
;
4320 niu_lock_parent(np
, flags
);
4321 nw64(RX_DMA_CK_DIV
, np
->parent
->rxdma_clock_divider
);
4322 nw64(RED_RAN_INIT
, RED_RAN_INIT_OPMODE
| (seed
& RED_RAN_INIT_VAL
));
4323 niu_unlock_parent(np
, flags
);
4325 /* XXX RXDMA 32bit mode? XXX */
4327 niu_init_rdc_groups(np
);
4328 niu_init_drr_weight(np
);
4330 err
= niu_init_hostinfo(np
);
4334 for (i
= 0; i
< np
->num_rx_rings
; i
++) {
4335 struct rx_ring_info
*rp
= &np
->rx_rings
[i
];
4337 err
= niu_init_one_rx_channel(np
, rp
);
4345 static int niu_set_ip_frag_rule(struct niu
*np
)
4347 struct niu_parent
*parent
= np
->parent
;
4348 struct niu_classifier
*cp
= &np
->clas
;
4349 struct niu_tcam_entry
*tp
;
4352 /* XXX fix this allocation scheme XXX */
4353 index
= cp
->tcam_index
;
4354 tp
= &parent
->tcam
[index
];
4356 /* Note that the noport bit is the same in both ipv4 and
4357 * ipv6 format TCAM entries.
4359 memset(tp
, 0, sizeof(*tp
));
4360 tp
->key
[1] = TCAM_V4KEY1_NOPORT
;
4361 tp
->key_mask
[1] = TCAM_V4KEY1_NOPORT
;
4362 tp
->assoc_data
= (TCAM_ASSOCDATA_TRES_USE_OFFSET
|
4363 ((u64
)0 << TCAM_ASSOCDATA_OFFSET_SHIFT
));
4364 err
= tcam_write(np
, index
, tp
->key
, tp
->key_mask
);
4367 err
= tcam_assoc_write(np
, index
, tp
->assoc_data
);
4374 static int niu_init_classifier_hw(struct niu
*np
)
4376 struct niu_parent
*parent
= np
->parent
;
4377 struct niu_classifier
*cp
= &np
->clas
;
4380 nw64(H1POLY
, cp
->h1_init
);
4381 nw64(H2POLY
, cp
->h2_init
);
4383 err
= niu_init_hostinfo(np
);
4387 for (i
= 0; i
< ENET_VLAN_TBL_NUM_ENTRIES
; i
++) {
4388 struct niu_vlan_rdc
*vp
= &cp
->vlan_mappings
[i
];
4390 vlan_tbl_write(np
, i
, np
->port
,
4391 vp
->vlan_pref
, vp
->rdc_num
);
4394 for (i
= 0; i
< cp
->num_alt_mac_mappings
; i
++) {
4395 struct niu_altmac_rdc
*ap
= &cp
->alt_mac_mappings
[i
];
4397 err
= niu_set_alt_mac_rdc_table(np
, ap
->alt_mac_num
,
4398 ap
->rdc_num
, ap
->mac_pref
);
4403 for (i
= CLASS_CODE_USER_PROG1
; i
<= CLASS_CODE_SCTP_IPV6
; i
++) {
4404 int index
= i
- CLASS_CODE_USER_PROG1
;
4406 err
= niu_set_tcam_key(np
, i
, parent
->tcam_key
[index
]);
4409 err
= niu_set_flow_key(np
, i
, parent
->flow_key
[index
]);
4414 err
= niu_set_ip_frag_rule(np
);
4423 static int niu_zcp_write(struct niu
*np
, int index
, u64
*data
)
4425 nw64(ZCP_RAM_DATA0
, data
[0]);
4426 nw64(ZCP_RAM_DATA1
, data
[1]);
4427 nw64(ZCP_RAM_DATA2
, data
[2]);
4428 nw64(ZCP_RAM_DATA3
, data
[3]);
4429 nw64(ZCP_RAM_DATA4
, data
[4]);
4430 nw64(ZCP_RAM_BE
, ZCP_RAM_BE_VAL
);
4432 (ZCP_RAM_ACC_WRITE
|
4433 (0 << ZCP_RAM_ACC_ZFCID_SHIFT
) |
4434 (ZCP_RAM_SEL_CFIFO(np
->port
) << ZCP_RAM_ACC_RAM_SEL_SHIFT
)));
4436 return niu_wait_bits_clear(np
, ZCP_RAM_ACC
, ZCP_RAM_ACC_BUSY
,
4440 static int niu_zcp_read(struct niu
*np
, int index
, u64
*data
)
4444 err
= niu_wait_bits_clear(np
, ZCP_RAM_ACC
, ZCP_RAM_ACC_BUSY
,
4447 dev_err(np
->device
, PFX
"%s: ZCP read busy won't clear, "
4448 "ZCP_RAM_ACC[%llx]\n", np
->dev
->name
,
4449 (unsigned long long) nr64(ZCP_RAM_ACC
));
4455 (0 << ZCP_RAM_ACC_ZFCID_SHIFT
) |
4456 (ZCP_RAM_SEL_CFIFO(np
->port
) << ZCP_RAM_ACC_RAM_SEL_SHIFT
)));
4458 err
= niu_wait_bits_clear(np
, ZCP_RAM_ACC
, ZCP_RAM_ACC_BUSY
,
4461 dev_err(np
->device
, PFX
"%s: ZCP read busy2 won't clear, "
4462 "ZCP_RAM_ACC[%llx]\n", np
->dev
->name
,
4463 (unsigned long long) nr64(ZCP_RAM_ACC
));
4467 data
[0] = nr64(ZCP_RAM_DATA0
);
4468 data
[1] = nr64(ZCP_RAM_DATA1
);
4469 data
[2] = nr64(ZCP_RAM_DATA2
);
4470 data
[3] = nr64(ZCP_RAM_DATA3
);
4471 data
[4] = nr64(ZCP_RAM_DATA4
);
4476 static void niu_zcp_cfifo_reset(struct niu
*np
)
4478 u64 val
= nr64(RESET_CFIFO
);
4480 val
|= RESET_CFIFO_RST(np
->port
);
4481 nw64(RESET_CFIFO
, val
);
4484 val
&= ~RESET_CFIFO_RST(np
->port
);
4485 nw64(RESET_CFIFO
, val
);
4488 static int niu_init_zcp(struct niu
*np
)
4490 u64 data
[5], rbuf
[5];
4493 if (np
->parent
->plat_type
!= PLAT_TYPE_NIU
) {
4494 if (np
->port
== 0 || np
->port
== 1)
4495 max
= ATLAS_P0_P1_CFIFO_ENTRIES
;
4497 max
= ATLAS_P2_P3_CFIFO_ENTRIES
;
4499 max
= NIU_CFIFO_ENTRIES
;
4507 for (i
= 0; i
< max
; i
++) {
4508 err
= niu_zcp_write(np
, i
, data
);
4511 err
= niu_zcp_read(np
, i
, rbuf
);
4516 niu_zcp_cfifo_reset(np
);
4517 nw64(CFIFO_ECC(np
->port
), 0);
4518 nw64(ZCP_INT_STAT
, ZCP_INT_STAT_ALL
);
4519 (void) nr64(ZCP_INT_STAT
);
4520 nw64(ZCP_INT_MASK
, ZCP_INT_MASK_ALL
);
4525 static void niu_ipp_write(struct niu
*np
, int index
, u64
*data
)
4527 u64 val
= nr64_ipp(IPP_CFIG
);
4529 nw64_ipp(IPP_CFIG
, val
| IPP_CFIG_DFIFO_PIO_W
);
4530 nw64_ipp(IPP_DFIFO_WR_PTR
, index
);
4531 nw64_ipp(IPP_DFIFO_WR0
, data
[0]);
4532 nw64_ipp(IPP_DFIFO_WR1
, data
[1]);
4533 nw64_ipp(IPP_DFIFO_WR2
, data
[2]);
4534 nw64_ipp(IPP_DFIFO_WR3
, data
[3]);
4535 nw64_ipp(IPP_DFIFO_WR4
, data
[4]);
4536 nw64_ipp(IPP_CFIG
, val
& ~IPP_CFIG_DFIFO_PIO_W
);
4539 static void niu_ipp_read(struct niu
*np
, int index
, u64
*data
)
4541 nw64_ipp(IPP_DFIFO_RD_PTR
, index
);
4542 data
[0] = nr64_ipp(IPP_DFIFO_RD0
);
4543 data
[1] = nr64_ipp(IPP_DFIFO_RD1
);
4544 data
[2] = nr64_ipp(IPP_DFIFO_RD2
);
4545 data
[3] = nr64_ipp(IPP_DFIFO_RD3
);
4546 data
[4] = nr64_ipp(IPP_DFIFO_RD4
);
4549 static int niu_ipp_reset(struct niu
*np
)
4551 return niu_set_and_wait_clear_ipp(np
, IPP_CFIG
, IPP_CFIG_SOFT_RST
,
4552 1000, 100, "IPP_CFIG");
4555 static int niu_init_ipp(struct niu
*np
)
4557 u64 data
[5], rbuf
[5], val
;
4560 if (np
->parent
->plat_type
!= PLAT_TYPE_NIU
) {
4561 if (np
->port
== 0 || np
->port
== 1)
4562 max
= ATLAS_P0_P1_DFIFO_ENTRIES
;
4564 max
= ATLAS_P2_P3_DFIFO_ENTRIES
;
4566 max
= NIU_DFIFO_ENTRIES
;
4574 for (i
= 0; i
< max
; i
++) {
4575 niu_ipp_write(np
, i
, data
);
4576 niu_ipp_read(np
, i
, rbuf
);
4579 (void) nr64_ipp(IPP_INT_STAT
);
4580 (void) nr64_ipp(IPP_INT_STAT
);
4582 err
= niu_ipp_reset(np
);
4586 (void) nr64_ipp(IPP_PKT_DIS
);
4587 (void) nr64_ipp(IPP_BAD_CS_CNT
);
4588 (void) nr64_ipp(IPP_ECC
);
4590 (void) nr64_ipp(IPP_INT_STAT
);
4592 nw64_ipp(IPP_MSK
, ~IPP_MSK_ALL
);
4594 val
= nr64_ipp(IPP_CFIG
);
4595 val
&= ~IPP_CFIG_IP_MAX_PKT
;
4596 val
|= (IPP_CFIG_IPP_ENABLE
|
4597 IPP_CFIG_DFIFO_ECC_EN
|
4598 IPP_CFIG_DROP_BAD_CRC
|
4600 (0x1ffff << IPP_CFIG_IP_MAX_PKT_SHIFT
));
4601 nw64_ipp(IPP_CFIG
, val
);
4606 static void niu_handle_led(struct niu
*np
, int status
)
4609 val
= nr64_mac(XMAC_CONFIG
);
4611 if ((np
->flags
& NIU_FLAGS_10G
) != 0 &&
4612 (np
->flags
& NIU_FLAGS_FIBER
) != 0) {
4614 val
|= XMAC_CONFIG_LED_POLARITY
;
4615 val
&= ~XMAC_CONFIG_FORCE_LED_ON
;
4617 val
|= XMAC_CONFIG_FORCE_LED_ON
;
4618 val
&= ~XMAC_CONFIG_LED_POLARITY
;
4622 nw64_mac(XMAC_CONFIG
, val
);
4625 static void niu_init_xif_xmac(struct niu
*np
)
4627 struct niu_link_config
*lp
= &np
->link_config
;
4630 if (np
->flags
& NIU_FLAGS_XCVR_SERDES
) {
4631 val
= nr64(MIF_CONFIG
);
4632 val
|= MIF_CONFIG_ATCA_GE
;
4633 nw64(MIF_CONFIG
, val
);
4636 val
= nr64_mac(XMAC_CONFIG
);
4637 val
&= ~XMAC_CONFIG_SEL_POR_CLK_SRC
;
4639 val
|= XMAC_CONFIG_TX_OUTPUT_EN
;
4641 if (lp
->loopback_mode
== LOOPBACK_MAC
) {
4642 val
&= ~XMAC_CONFIG_SEL_POR_CLK_SRC
;
4643 val
|= XMAC_CONFIG_LOOPBACK
;
4645 val
&= ~XMAC_CONFIG_LOOPBACK
;
4648 if (np
->flags
& NIU_FLAGS_10G
) {
4649 val
&= ~XMAC_CONFIG_LFS_DISABLE
;
4651 val
|= XMAC_CONFIG_LFS_DISABLE
;
4652 if (!(np
->flags
& NIU_FLAGS_FIBER
) &&
4653 !(np
->flags
& NIU_FLAGS_XCVR_SERDES
))
4654 val
|= XMAC_CONFIG_1G_PCS_BYPASS
;
4656 val
&= ~XMAC_CONFIG_1G_PCS_BYPASS
;
4659 val
&= ~XMAC_CONFIG_10G_XPCS_BYPASS
;
4661 if (lp
->active_speed
== SPEED_100
)
4662 val
|= XMAC_CONFIG_SEL_CLK_25MHZ
;
4664 val
&= ~XMAC_CONFIG_SEL_CLK_25MHZ
;
4666 nw64_mac(XMAC_CONFIG
, val
);
4668 val
= nr64_mac(XMAC_CONFIG
);
4669 val
&= ~XMAC_CONFIG_MODE_MASK
;
4670 if (np
->flags
& NIU_FLAGS_10G
) {
4671 val
|= XMAC_CONFIG_MODE_XGMII
;
4673 if (lp
->active_speed
== SPEED_100
)
4674 val
|= XMAC_CONFIG_MODE_MII
;
4676 val
|= XMAC_CONFIG_MODE_GMII
;
4679 nw64_mac(XMAC_CONFIG
, val
);
4682 static void niu_init_xif_bmac(struct niu
*np
)
4684 struct niu_link_config
*lp
= &np
->link_config
;
4687 val
= BMAC_XIF_CONFIG_TX_OUTPUT_EN
;
4689 if (lp
->loopback_mode
== LOOPBACK_MAC
)
4690 val
|= BMAC_XIF_CONFIG_MII_LOOPBACK
;
4692 val
&= ~BMAC_XIF_CONFIG_MII_LOOPBACK
;
4694 if (lp
->active_speed
== SPEED_1000
)
4695 val
|= BMAC_XIF_CONFIG_GMII_MODE
;
4697 val
&= ~BMAC_XIF_CONFIG_GMII_MODE
;
4699 val
&= ~(BMAC_XIF_CONFIG_LINK_LED
|
4700 BMAC_XIF_CONFIG_LED_POLARITY
);
4702 if (!(np
->flags
& NIU_FLAGS_10G
) &&
4703 !(np
->flags
& NIU_FLAGS_FIBER
) &&
4704 lp
->active_speed
== SPEED_100
)
4705 val
|= BMAC_XIF_CONFIG_25MHZ_CLOCK
;
4707 val
&= ~BMAC_XIF_CONFIG_25MHZ_CLOCK
;
4709 nw64_mac(BMAC_XIF_CONFIG
, val
);
4712 static void niu_init_xif(struct niu
*np
)
4714 if (np
->flags
& NIU_FLAGS_XMAC
)
4715 niu_init_xif_xmac(np
);
4717 niu_init_xif_bmac(np
);
4720 static void niu_pcs_mii_reset(struct niu
*np
)
4723 u64 val
= nr64_pcs(PCS_MII_CTL
);
4724 val
|= PCS_MII_CTL_RST
;
4725 nw64_pcs(PCS_MII_CTL
, val
);
4726 while ((--limit
>= 0) && (val
& PCS_MII_CTL_RST
)) {
4728 val
= nr64_pcs(PCS_MII_CTL
);
4732 static void niu_xpcs_reset(struct niu
*np
)
4735 u64 val
= nr64_xpcs(XPCS_CONTROL1
);
4736 val
|= XPCS_CONTROL1_RESET
;
4737 nw64_xpcs(XPCS_CONTROL1
, val
);
4738 while ((--limit
>= 0) && (val
& XPCS_CONTROL1_RESET
)) {
4740 val
= nr64_xpcs(XPCS_CONTROL1
);
4744 static int niu_init_pcs(struct niu
*np
)
4746 struct niu_link_config
*lp
= &np
->link_config
;
4749 switch (np
->flags
& (NIU_FLAGS_10G
|
4751 NIU_FLAGS_XCVR_SERDES
)) {
4752 case NIU_FLAGS_FIBER
:
4754 nw64_pcs(PCS_CONF
, PCS_CONF_MASK
| PCS_CONF_ENABLE
);
4755 nw64_pcs(PCS_DPATH_MODE
, 0);
4756 niu_pcs_mii_reset(np
);
4760 case NIU_FLAGS_10G
| NIU_FLAGS_FIBER
:
4761 case NIU_FLAGS_10G
| NIU_FLAGS_XCVR_SERDES
:
4763 if (!(np
->flags
& NIU_FLAGS_XMAC
))
4766 /* 10G copper or fiber */
4767 val
= nr64_mac(XMAC_CONFIG
);
4768 val
&= ~XMAC_CONFIG_10G_XPCS_BYPASS
;
4769 nw64_mac(XMAC_CONFIG
, val
);
4773 val
= nr64_xpcs(XPCS_CONTROL1
);
4774 if (lp
->loopback_mode
== LOOPBACK_PHY
)
4775 val
|= XPCS_CONTROL1_LOOPBACK
;
4777 val
&= ~XPCS_CONTROL1_LOOPBACK
;
4778 nw64_xpcs(XPCS_CONTROL1
, val
);
4780 nw64_xpcs(XPCS_DESKEW_ERR_CNT
, 0);
4781 (void) nr64_xpcs(XPCS_SYMERR_CNT01
);
4782 (void) nr64_xpcs(XPCS_SYMERR_CNT23
);
4786 case NIU_FLAGS_XCVR_SERDES
:
4788 niu_pcs_mii_reset(np
);
4789 nw64_pcs(PCS_CONF
, PCS_CONF_MASK
| PCS_CONF_ENABLE
);
4790 nw64_pcs(PCS_DPATH_MODE
, 0);
4795 case NIU_FLAGS_XCVR_SERDES
| NIU_FLAGS_FIBER
:
4796 /* 1G RGMII FIBER */
4797 nw64_pcs(PCS_DPATH_MODE
, PCS_DPATH_MODE_MII
);
4798 niu_pcs_mii_reset(np
);
4808 static int niu_reset_tx_xmac(struct niu
*np
)
4810 return niu_set_and_wait_clear_mac(np
, XTXMAC_SW_RST
,
4811 (XTXMAC_SW_RST_REG_RS
|
4812 XTXMAC_SW_RST_SOFT_RST
),
4813 1000, 100, "XTXMAC_SW_RST");
4816 static int niu_reset_tx_bmac(struct niu
*np
)
4820 nw64_mac(BTXMAC_SW_RST
, BTXMAC_SW_RST_RESET
);
4822 while (--limit
>= 0) {
4823 if (!(nr64_mac(BTXMAC_SW_RST
) & BTXMAC_SW_RST_RESET
))
4828 dev_err(np
->device
, PFX
"Port %u TX BMAC would not reset, "
4829 "BTXMAC_SW_RST[%llx]\n",
4831 (unsigned long long) nr64_mac(BTXMAC_SW_RST
));
4838 static int niu_reset_tx_mac(struct niu
*np
)
4840 if (np
->flags
& NIU_FLAGS_XMAC
)
4841 return niu_reset_tx_xmac(np
);
4843 return niu_reset_tx_bmac(np
);
4846 static void niu_init_tx_xmac(struct niu
*np
, u64 min
, u64 max
)
4850 val
= nr64_mac(XMAC_MIN
);
4851 val
&= ~(XMAC_MIN_TX_MIN_PKT_SIZE
|
4852 XMAC_MIN_RX_MIN_PKT_SIZE
);
4853 val
|= (min
<< XMAC_MIN_RX_MIN_PKT_SIZE_SHFT
);
4854 val
|= (min
<< XMAC_MIN_TX_MIN_PKT_SIZE_SHFT
);
4855 nw64_mac(XMAC_MIN
, val
);
4857 nw64_mac(XMAC_MAX
, max
);
4859 nw64_mac(XTXMAC_STAT_MSK
, ~(u64
)0);
4861 val
= nr64_mac(XMAC_IPG
);
4862 if (np
->flags
& NIU_FLAGS_10G
) {
4863 val
&= ~XMAC_IPG_IPG_XGMII
;
4864 val
|= (IPG_12_15_XGMII
<< XMAC_IPG_IPG_XGMII_SHIFT
);
4866 val
&= ~XMAC_IPG_IPG_MII_GMII
;
4867 val
|= (IPG_12_MII_GMII
<< XMAC_IPG_IPG_MII_GMII_SHIFT
);
4869 nw64_mac(XMAC_IPG
, val
);
4871 val
= nr64_mac(XMAC_CONFIG
);
4872 val
&= ~(XMAC_CONFIG_ALWAYS_NO_CRC
|
4873 XMAC_CONFIG_STRETCH_MODE
|
4874 XMAC_CONFIG_VAR_MIN_IPG_EN
|
4875 XMAC_CONFIG_TX_ENABLE
);
4876 nw64_mac(XMAC_CONFIG
, val
);
4878 nw64_mac(TXMAC_FRM_CNT
, 0);
4879 nw64_mac(TXMAC_BYTE_CNT
, 0);
4882 static void niu_init_tx_bmac(struct niu
*np
, u64 min
, u64 max
)
4886 nw64_mac(BMAC_MIN_FRAME
, min
);
4887 nw64_mac(BMAC_MAX_FRAME
, max
);
4889 nw64_mac(BTXMAC_STATUS_MASK
, ~(u64
)0);
4890 nw64_mac(BMAC_CTRL_TYPE
, 0x8808);
4891 nw64_mac(BMAC_PREAMBLE_SIZE
, 7);
4893 val
= nr64_mac(BTXMAC_CONFIG
);
4894 val
&= ~(BTXMAC_CONFIG_FCS_DISABLE
|
4895 BTXMAC_CONFIG_ENABLE
);
4896 nw64_mac(BTXMAC_CONFIG
, val
);
4899 static void niu_init_tx_mac(struct niu
*np
)
4904 if (np
->dev
->mtu
> ETH_DATA_LEN
)
4909 /* The XMAC_MIN register only accepts values for TX min which
4910 * have the low 3 bits cleared.
4912 BUILD_BUG_ON(min
& 0x7);
4914 if (np
->flags
& NIU_FLAGS_XMAC
)
4915 niu_init_tx_xmac(np
, min
, max
);
4917 niu_init_tx_bmac(np
, min
, max
);
4920 static int niu_reset_rx_xmac(struct niu
*np
)
4924 nw64_mac(XRXMAC_SW_RST
,
4925 XRXMAC_SW_RST_REG_RS
| XRXMAC_SW_RST_SOFT_RST
);
4927 while (--limit
>= 0) {
4928 if (!(nr64_mac(XRXMAC_SW_RST
) & (XRXMAC_SW_RST_REG_RS
|
4929 XRXMAC_SW_RST_SOFT_RST
)))
4934 dev_err(np
->device
, PFX
"Port %u RX XMAC would not reset, "
4935 "XRXMAC_SW_RST[%llx]\n",
4937 (unsigned long long) nr64_mac(XRXMAC_SW_RST
));
4944 static int niu_reset_rx_bmac(struct niu
*np
)
4948 nw64_mac(BRXMAC_SW_RST
, BRXMAC_SW_RST_RESET
);
4950 while (--limit
>= 0) {
4951 if (!(nr64_mac(BRXMAC_SW_RST
) & BRXMAC_SW_RST_RESET
))
4956 dev_err(np
->device
, PFX
"Port %u RX BMAC would not reset, "
4957 "BRXMAC_SW_RST[%llx]\n",
4959 (unsigned long long) nr64_mac(BRXMAC_SW_RST
));
4966 static int niu_reset_rx_mac(struct niu
*np
)
4968 if (np
->flags
& NIU_FLAGS_XMAC
)
4969 return niu_reset_rx_xmac(np
);
4971 return niu_reset_rx_bmac(np
);
4974 static void niu_init_rx_xmac(struct niu
*np
)
4976 struct niu_parent
*parent
= np
->parent
;
4977 struct niu_rdc_tables
*tp
= &parent
->rdc_group_cfg
[np
->port
];
4978 int first_rdc_table
= tp
->first_table_num
;
4982 nw64_mac(XMAC_ADD_FILT0
, 0);
4983 nw64_mac(XMAC_ADD_FILT1
, 0);
4984 nw64_mac(XMAC_ADD_FILT2
, 0);
4985 nw64_mac(XMAC_ADD_FILT12_MASK
, 0);
4986 nw64_mac(XMAC_ADD_FILT00_MASK
, 0);
4987 for (i
= 0; i
< MAC_NUM_HASH
; i
++)
4988 nw64_mac(XMAC_HASH_TBL(i
), 0);
4989 nw64_mac(XRXMAC_STAT_MSK
, ~(u64
)0);
4990 niu_set_primary_mac_rdc_table(np
, first_rdc_table
, 1);
4991 niu_set_multicast_mac_rdc_table(np
, first_rdc_table
, 1);
4993 val
= nr64_mac(XMAC_CONFIG
);
4994 val
&= ~(XMAC_CONFIG_RX_MAC_ENABLE
|
4995 XMAC_CONFIG_PROMISCUOUS
|
4996 XMAC_CONFIG_PROMISC_GROUP
|
4997 XMAC_CONFIG_ERR_CHK_DIS
|
4998 XMAC_CONFIG_RX_CRC_CHK_DIS
|
4999 XMAC_CONFIG_RESERVED_MULTICAST
|
5000 XMAC_CONFIG_RX_CODEV_CHK_DIS
|
5001 XMAC_CONFIG_ADDR_FILTER_EN
|
5002 XMAC_CONFIG_RCV_PAUSE_ENABLE
|
5003 XMAC_CONFIG_STRIP_CRC
|
5004 XMAC_CONFIG_PASS_FLOW_CTRL
|
5005 XMAC_CONFIG_MAC2IPP_PKT_CNT_EN
);
5006 val
|= (XMAC_CONFIG_HASH_FILTER_EN
);
5007 nw64_mac(XMAC_CONFIG
, val
);
5009 nw64_mac(RXMAC_BT_CNT
, 0);
5010 nw64_mac(RXMAC_BC_FRM_CNT
, 0);
5011 nw64_mac(RXMAC_MC_FRM_CNT
, 0);
5012 nw64_mac(RXMAC_FRAG_CNT
, 0);
5013 nw64_mac(RXMAC_HIST_CNT1
, 0);
5014 nw64_mac(RXMAC_HIST_CNT2
, 0);
5015 nw64_mac(RXMAC_HIST_CNT3
, 0);
5016 nw64_mac(RXMAC_HIST_CNT4
, 0);
5017 nw64_mac(RXMAC_HIST_CNT5
, 0);
5018 nw64_mac(RXMAC_HIST_CNT6
, 0);
5019 nw64_mac(RXMAC_HIST_CNT7
, 0);
5020 nw64_mac(RXMAC_MPSZER_CNT
, 0);
5021 nw64_mac(RXMAC_CRC_ER_CNT
, 0);
5022 nw64_mac(RXMAC_CD_VIO_CNT
, 0);
5023 nw64_mac(LINK_FAULT_CNT
, 0);
5026 static void niu_init_rx_bmac(struct niu
*np
)
5028 struct niu_parent
*parent
= np
->parent
;
5029 struct niu_rdc_tables
*tp
= &parent
->rdc_group_cfg
[np
->port
];
5030 int first_rdc_table
= tp
->first_table_num
;
5034 nw64_mac(BMAC_ADD_FILT0
, 0);
5035 nw64_mac(BMAC_ADD_FILT1
, 0);
5036 nw64_mac(BMAC_ADD_FILT2
, 0);
5037 nw64_mac(BMAC_ADD_FILT12_MASK
, 0);
5038 nw64_mac(BMAC_ADD_FILT00_MASK
, 0);
5039 for (i
= 0; i
< MAC_NUM_HASH
; i
++)
5040 nw64_mac(BMAC_HASH_TBL(i
), 0);
5041 niu_set_primary_mac_rdc_table(np
, first_rdc_table
, 1);
5042 niu_set_multicast_mac_rdc_table(np
, first_rdc_table
, 1);
5043 nw64_mac(BRXMAC_STATUS_MASK
, ~(u64
)0);
5045 val
= nr64_mac(BRXMAC_CONFIG
);
5046 val
&= ~(BRXMAC_CONFIG_ENABLE
|
5047 BRXMAC_CONFIG_STRIP_PAD
|
5048 BRXMAC_CONFIG_STRIP_FCS
|
5049 BRXMAC_CONFIG_PROMISC
|
5050 BRXMAC_CONFIG_PROMISC_GRP
|
5051 BRXMAC_CONFIG_ADDR_FILT_EN
|
5052 BRXMAC_CONFIG_DISCARD_DIS
);
5053 val
|= (BRXMAC_CONFIG_HASH_FILT_EN
);
5054 nw64_mac(BRXMAC_CONFIG
, val
);
5056 val
= nr64_mac(BMAC_ADDR_CMPEN
);
5057 val
|= BMAC_ADDR_CMPEN_EN0
;
5058 nw64_mac(BMAC_ADDR_CMPEN
, val
);
5061 static void niu_init_rx_mac(struct niu
*np
)
5063 niu_set_primary_mac(np
, np
->dev
->dev_addr
);
5065 if (np
->flags
& NIU_FLAGS_XMAC
)
5066 niu_init_rx_xmac(np
);
5068 niu_init_rx_bmac(np
);
5071 static void niu_enable_tx_xmac(struct niu
*np
, int on
)
5073 u64 val
= nr64_mac(XMAC_CONFIG
);
5076 val
|= XMAC_CONFIG_TX_ENABLE
;
5078 val
&= ~XMAC_CONFIG_TX_ENABLE
;
5079 nw64_mac(XMAC_CONFIG
, val
);
5082 static void niu_enable_tx_bmac(struct niu
*np
, int on
)
5084 u64 val
= nr64_mac(BTXMAC_CONFIG
);
5087 val
|= BTXMAC_CONFIG_ENABLE
;
5089 val
&= ~BTXMAC_CONFIG_ENABLE
;
5090 nw64_mac(BTXMAC_CONFIG
, val
);
5093 static void niu_enable_tx_mac(struct niu
*np
, int on
)
5095 if (np
->flags
& NIU_FLAGS_XMAC
)
5096 niu_enable_tx_xmac(np
, on
);
5098 niu_enable_tx_bmac(np
, on
);
5101 static void niu_enable_rx_xmac(struct niu
*np
, int on
)
5103 u64 val
= nr64_mac(XMAC_CONFIG
);
5105 val
&= ~(XMAC_CONFIG_HASH_FILTER_EN
|
5106 XMAC_CONFIG_PROMISCUOUS
);
5108 if (np
->flags
& NIU_FLAGS_MCAST
)
5109 val
|= XMAC_CONFIG_HASH_FILTER_EN
;
5110 if (np
->flags
& NIU_FLAGS_PROMISC
)
5111 val
|= XMAC_CONFIG_PROMISCUOUS
;
5114 val
|= XMAC_CONFIG_RX_MAC_ENABLE
;
5116 val
&= ~XMAC_CONFIG_RX_MAC_ENABLE
;
5117 nw64_mac(XMAC_CONFIG
, val
);
5120 static void niu_enable_rx_bmac(struct niu
*np
, int on
)
5122 u64 val
= nr64_mac(BRXMAC_CONFIG
);
5124 val
&= ~(BRXMAC_CONFIG_HASH_FILT_EN
|
5125 BRXMAC_CONFIG_PROMISC
);
5127 if (np
->flags
& NIU_FLAGS_MCAST
)
5128 val
|= BRXMAC_CONFIG_HASH_FILT_EN
;
5129 if (np
->flags
& NIU_FLAGS_PROMISC
)
5130 val
|= BRXMAC_CONFIG_PROMISC
;
5133 val
|= BRXMAC_CONFIG_ENABLE
;
5135 val
&= ~BRXMAC_CONFIG_ENABLE
;
5136 nw64_mac(BRXMAC_CONFIG
, val
);
5139 static void niu_enable_rx_mac(struct niu
*np
, int on
)
5141 if (np
->flags
& NIU_FLAGS_XMAC
)
5142 niu_enable_rx_xmac(np
, on
);
5144 niu_enable_rx_bmac(np
, on
);
5147 static int niu_init_mac(struct niu
*np
)
5152 err
= niu_init_pcs(np
);
5156 err
= niu_reset_tx_mac(np
);
5159 niu_init_tx_mac(np
);
5160 err
= niu_reset_rx_mac(np
);
5163 niu_init_rx_mac(np
);
5165 /* This looks hookey but the RX MAC reset we just did will
5166 * undo some of the state we setup in niu_init_tx_mac() so we
5167 * have to call it again. In particular, the RX MAC reset will
5168 * set the XMAC_MAX register back to it's default value.
5170 niu_init_tx_mac(np
);
5171 niu_enable_tx_mac(np
, 1);
5173 niu_enable_rx_mac(np
, 1);
5178 static void niu_stop_one_tx_channel(struct niu
*np
, struct tx_ring_info
*rp
)
5180 (void) niu_tx_channel_stop(np
, rp
->tx_channel
);
5183 static void niu_stop_tx_channels(struct niu
*np
)
5187 for (i
= 0; i
< np
->num_tx_rings
; i
++) {
5188 struct tx_ring_info
*rp
= &np
->tx_rings
[i
];
5190 niu_stop_one_tx_channel(np
, rp
);
5194 static void niu_reset_one_tx_channel(struct niu
*np
, struct tx_ring_info
*rp
)
5196 (void) niu_tx_channel_reset(np
, rp
->tx_channel
);
5199 static void niu_reset_tx_channels(struct niu
*np
)
5203 for (i
= 0; i
< np
->num_tx_rings
; i
++) {
5204 struct tx_ring_info
*rp
= &np
->tx_rings
[i
];
5206 niu_reset_one_tx_channel(np
, rp
);
5210 static void niu_stop_one_rx_channel(struct niu
*np
, struct rx_ring_info
*rp
)
5212 (void) niu_enable_rx_channel(np
, rp
->rx_channel
, 0);
5215 static void niu_stop_rx_channels(struct niu
*np
)
5219 for (i
= 0; i
< np
->num_rx_rings
; i
++) {
5220 struct rx_ring_info
*rp
= &np
->rx_rings
[i
];
5222 niu_stop_one_rx_channel(np
, rp
);
5226 static void niu_reset_one_rx_channel(struct niu
*np
, struct rx_ring_info
*rp
)
5228 int channel
= rp
->rx_channel
;
5230 (void) niu_rx_channel_reset(np
, channel
);
5231 nw64(RX_DMA_ENT_MSK(channel
), RX_DMA_ENT_MSK_ALL
);
5232 nw64(RX_DMA_CTL_STAT(channel
), 0);
5233 (void) niu_enable_rx_channel(np
, channel
, 0);
5236 static void niu_reset_rx_channels(struct niu
*np
)
5240 for (i
= 0; i
< np
->num_rx_rings
; i
++) {
5241 struct rx_ring_info
*rp
= &np
->rx_rings
[i
];
5243 niu_reset_one_rx_channel(np
, rp
);
5247 static void niu_disable_ipp(struct niu
*np
)
5252 rd
= nr64_ipp(IPP_DFIFO_RD_PTR
);
5253 wr
= nr64_ipp(IPP_DFIFO_WR_PTR
);
5255 while (--limit
>= 0 && (rd
!= wr
)) {
5256 rd
= nr64_ipp(IPP_DFIFO_RD_PTR
);
5257 wr
= nr64_ipp(IPP_DFIFO_WR_PTR
);
5260 (rd
!= 0 && wr
!= 1)) {
5261 dev_err(np
->device
, PFX
"%s: IPP would not quiesce, "
5262 "rd_ptr[%llx] wr_ptr[%llx]\n",
5264 (unsigned long long) nr64_ipp(IPP_DFIFO_RD_PTR
),
5265 (unsigned long long) nr64_ipp(IPP_DFIFO_WR_PTR
));
5268 val
= nr64_ipp(IPP_CFIG
);
5269 val
&= ~(IPP_CFIG_IPP_ENABLE
|
5270 IPP_CFIG_DFIFO_ECC_EN
|
5271 IPP_CFIG_DROP_BAD_CRC
|
5273 nw64_ipp(IPP_CFIG
, val
);
5275 (void) niu_ipp_reset(np
);
5278 static int niu_init_hw(struct niu
*np
)
5282 niudbg(IFUP
, "%s: Initialize TXC\n", np
->dev
->name
);
5283 niu_txc_enable_port(np
, 1);
5284 niu_txc_port_dma_enable(np
, 1);
5285 niu_txc_set_imask(np
, 0);
5287 niudbg(IFUP
, "%s: Initialize TX channels\n", np
->dev
->name
);
5288 for (i
= 0; i
< np
->num_tx_rings
; i
++) {
5289 struct tx_ring_info
*rp
= &np
->tx_rings
[i
];
5291 err
= niu_init_one_tx_channel(np
, rp
);
5296 niudbg(IFUP
, "%s: Initialize RX channels\n", np
->dev
->name
);
5297 err
= niu_init_rx_channels(np
);
5299 goto out_uninit_tx_channels
;
5301 niudbg(IFUP
, "%s: Initialize classifier\n", np
->dev
->name
);
5302 err
= niu_init_classifier_hw(np
);
5304 goto out_uninit_rx_channels
;
5306 niudbg(IFUP
, "%s: Initialize ZCP\n", np
->dev
->name
);
5307 err
= niu_init_zcp(np
);
5309 goto out_uninit_rx_channels
;
5311 niudbg(IFUP
, "%s: Initialize IPP\n", np
->dev
->name
);
5312 err
= niu_init_ipp(np
);
5314 goto out_uninit_rx_channels
;
5316 niudbg(IFUP
, "%s: Initialize MAC\n", np
->dev
->name
);
5317 err
= niu_init_mac(np
);
5319 goto out_uninit_ipp
;
5324 niudbg(IFUP
, "%s: Uninit IPP\n", np
->dev
->name
);
5325 niu_disable_ipp(np
);
5327 out_uninit_rx_channels
:
5328 niudbg(IFUP
, "%s: Uninit RX channels\n", np
->dev
->name
);
5329 niu_stop_rx_channels(np
);
5330 niu_reset_rx_channels(np
);
5332 out_uninit_tx_channels
:
5333 niudbg(IFUP
, "%s: Uninit TX channels\n", np
->dev
->name
);
5334 niu_stop_tx_channels(np
);
5335 niu_reset_tx_channels(np
);
5340 static void niu_stop_hw(struct niu
*np
)
5342 niudbg(IFDOWN
, "%s: Disable interrupts\n", np
->dev
->name
);
5343 niu_enable_interrupts(np
, 0);
5345 niudbg(IFDOWN
, "%s: Disable RX MAC\n", np
->dev
->name
);
5346 niu_enable_rx_mac(np
, 0);
5348 niudbg(IFDOWN
, "%s: Disable IPP\n", np
->dev
->name
);
5349 niu_disable_ipp(np
);
5351 niudbg(IFDOWN
, "%s: Stop TX channels\n", np
->dev
->name
);
5352 niu_stop_tx_channels(np
);
5354 niudbg(IFDOWN
, "%s: Stop RX channels\n", np
->dev
->name
);
5355 niu_stop_rx_channels(np
);
5357 niudbg(IFDOWN
, "%s: Reset TX channels\n", np
->dev
->name
);
5358 niu_reset_tx_channels(np
);
5360 niudbg(IFDOWN
, "%s: Reset RX channels\n", np
->dev
->name
);
5361 niu_reset_rx_channels(np
);
5364 static int niu_request_irq(struct niu
*np
)
5369 for (i
= 0; i
< np
->num_ldg
; i
++) {
5370 struct niu_ldg
*lp
= &np
->ldg
[i
];
5372 err
= request_irq(lp
->irq
, niu_interrupt
,
5373 IRQF_SHARED
| IRQF_SAMPLE_RANDOM
,
5383 for (j
= 0; j
< i
; j
++) {
5384 struct niu_ldg
*lp
= &np
->ldg
[j
];
5386 free_irq(lp
->irq
, lp
);
5391 static void niu_free_irq(struct niu
*np
)
5395 for (i
= 0; i
< np
->num_ldg
; i
++) {
5396 struct niu_ldg
*lp
= &np
->ldg
[i
];
5398 free_irq(lp
->irq
, lp
);
5402 static void niu_enable_napi(struct niu
*np
)
5406 for (i
= 0; i
< np
->num_ldg
; i
++)
5407 napi_enable(&np
->ldg
[i
].napi
);
5410 static void niu_disable_napi(struct niu
*np
)
5414 for (i
= 0; i
< np
->num_ldg
; i
++)
5415 napi_disable(&np
->ldg
[i
].napi
);
5418 static int niu_open(struct net_device
*dev
)
5420 struct niu
*np
= netdev_priv(dev
);
5423 netif_carrier_off(dev
);
5425 err
= niu_alloc_channels(np
);
5429 err
= niu_enable_interrupts(np
, 0);
5431 goto out_free_channels
;
5433 err
= niu_request_irq(np
);
5435 goto out_free_channels
;
5437 niu_enable_napi(np
);
5439 spin_lock_irq(&np
->lock
);
5441 err
= niu_init_hw(np
);
5443 init_timer(&np
->timer
);
5444 np
->timer
.expires
= jiffies
+ HZ
;
5445 np
->timer
.data
= (unsigned long) np
;
5446 np
->timer
.function
= niu_timer
;
5448 err
= niu_enable_interrupts(np
, 1);
5453 spin_unlock_irq(&np
->lock
);
5456 niu_disable_napi(np
);
5460 netif_start_queue(dev
);
5462 if (np
->link_config
.loopback_mode
!= LOOPBACK_DISABLED
)
5463 netif_carrier_on(dev
);
5465 add_timer(&np
->timer
);
5473 niu_free_channels(np
);
5479 static void niu_full_shutdown(struct niu
*np
, struct net_device
*dev
)
5481 cancel_work_sync(&np
->reset_task
);
5483 niu_disable_napi(np
);
5484 netif_stop_queue(dev
);
5486 del_timer_sync(&np
->timer
);
5488 spin_lock_irq(&np
->lock
);
5492 spin_unlock_irq(&np
->lock
);
5495 static int niu_close(struct net_device
*dev
)
5497 struct niu
*np
= netdev_priv(dev
);
5499 niu_full_shutdown(np
, dev
);
5503 niu_free_channels(np
);
5505 niu_handle_led(np
, 0);
5510 static void niu_sync_xmac_stats(struct niu
*np
)
5512 struct niu_xmac_stats
*mp
= &np
->mac_stats
.xmac
;
5514 mp
->tx_frames
+= nr64_mac(TXMAC_FRM_CNT
);
5515 mp
->tx_bytes
+= nr64_mac(TXMAC_BYTE_CNT
);
5517 mp
->rx_link_faults
+= nr64_mac(LINK_FAULT_CNT
);
5518 mp
->rx_align_errors
+= nr64_mac(RXMAC_ALIGN_ERR_CNT
);
5519 mp
->rx_frags
+= nr64_mac(RXMAC_FRAG_CNT
);
5520 mp
->rx_mcasts
+= nr64_mac(RXMAC_MC_FRM_CNT
);
5521 mp
->rx_bcasts
+= nr64_mac(RXMAC_BC_FRM_CNT
);
5522 mp
->rx_hist_cnt1
+= nr64_mac(RXMAC_HIST_CNT1
);
5523 mp
->rx_hist_cnt2
+= nr64_mac(RXMAC_HIST_CNT2
);
5524 mp
->rx_hist_cnt3
+= nr64_mac(RXMAC_HIST_CNT3
);
5525 mp
->rx_hist_cnt4
+= nr64_mac(RXMAC_HIST_CNT4
);
5526 mp
->rx_hist_cnt5
+= nr64_mac(RXMAC_HIST_CNT5
);
5527 mp
->rx_hist_cnt6
+= nr64_mac(RXMAC_HIST_CNT6
);
5528 mp
->rx_hist_cnt7
+= nr64_mac(RXMAC_HIST_CNT7
);
5529 mp
->rx_octets
+= nr64_mac(RXMAC_BT_CNT
);
5530 mp
->rx_code_violations
+= nr64_mac(RXMAC_CD_VIO_CNT
);
5531 mp
->rx_len_errors
+= nr64_mac(RXMAC_MPSZER_CNT
);
5532 mp
->rx_crc_errors
+= nr64_mac(RXMAC_CRC_ER_CNT
);
5535 static void niu_sync_bmac_stats(struct niu
*np
)
5537 struct niu_bmac_stats
*mp
= &np
->mac_stats
.bmac
;
5539 mp
->tx_bytes
+= nr64_mac(BTXMAC_BYTE_CNT
);
5540 mp
->tx_frames
+= nr64_mac(BTXMAC_FRM_CNT
);
5542 mp
->rx_frames
+= nr64_mac(BRXMAC_FRAME_CNT
);
5543 mp
->rx_align_errors
+= nr64_mac(BRXMAC_ALIGN_ERR_CNT
);
5544 mp
->rx_crc_errors
+= nr64_mac(BRXMAC_ALIGN_ERR_CNT
);
5545 mp
->rx_len_errors
+= nr64_mac(BRXMAC_CODE_VIOL_ERR_CNT
);
5548 static void niu_sync_mac_stats(struct niu
*np
)
5550 if (np
->flags
& NIU_FLAGS_XMAC
)
5551 niu_sync_xmac_stats(np
);
5553 niu_sync_bmac_stats(np
);
5556 static void niu_get_rx_stats(struct niu
*np
)
5558 unsigned long pkts
, dropped
, errors
, bytes
;
5561 pkts
= dropped
= errors
= bytes
= 0;
5562 for (i
= 0; i
< np
->num_rx_rings
; i
++) {
5563 struct rx_ring_info
*rp
= &np
->rx_rings
[i
];
5565 pkts
+= rp
->rx_packets
;
5566 bytes
+= rp
->rx_bytes
;
5567 dropped
+= rp
->rx_dropped
;
5568 errors
+= rp
->rx_errors
;
5570 np
->net_stats
.rx_packets
= pkts
;
5571 np
->net_stats
.rx_bytes
= bytes
;
5572 np
->net_stats
.rx_dropped
= dropped
;
5573 np
->net_stats
.rx_errors
= errors
;
5576 static void niu_get_tx_stats(struct niu
*np
)
5578 unsigned long pkts
, errors
, bytes
;
5581 pkts
= errors
= bytes
= 0;
5582 for (i
= 0; i
< np
->num_tx_rings
; i
++) {
5583 struct tx_ring_info
*rp
= &np
->tx_rings
[i
];
5585 pkts
+= rp
->tx_packets
;
5586 bytes
+= rp
->tx_bytes
;
5587 errors
+= rp
->tx_errors
;
5589 np
->net_stats
.tx_packets
= pkts
;
5590 np
->net_stats
.tx_bytes
= bytes
;
5591 np
->net_stats
.tx_errors
= errors
;
5594 static struct net_device_stats
*niu_get_stats(struct net_device
*dev
)
5596 struct niu
*np
= netdev_priv(dev
);
5598 niu_get_rx_stats(np
);
5599 niu_get_tx_stats(np
);
5601 return &np
->net_stats
;
5604 static void niu_load_hash_xmac(struct niu
*np
, u16
*hash
)
5608 for (i
= 0; i
< 16; i
++)
5609 nw64_mac(XMAC_HASH_TBL(i
), hash
[i
]);
5612 static void niu_load_hash_bmac(struct niu
*np
, u16
*hash
)
5616 for (i
= 0; i
< 16; i
++)
5617 nw64_mac(BMAC_HASH_TBL(i
), hash
[i
]);
5620 static void niu_load_hash(struct niu
*np
, u16
*hash
)
5622 if (np
->flags
& NIU_FLAGS_XMAC
)
5623 niu_load_hash_xmac(np
, hash
);
5625 niu_load_hash_bmac(np
, hash
);
5628 static void niu_set_rx_mode(struct net_device
*dev
)
5630 struct niu
*np
= netdev_priv(dev
);
5631 int i
, alt_cnt
, err
;
5632 struct dev_addr_list
*addr
;
5633 unsigned long flags
;
5634 u16 hash
[16] = { 0, };
5636 spin_lock_irqsave(&np
->lock
, flags
);
5637 niu_enable_rx_mac(np
, 0);
5639 np
->flags
&= ~(NIU_FLAGS_MCAST
| NIU_FLAGS_PROMISC
);
5640 if (dev
->flags
& IFF_PROMISC
)
5641 np
->flags
|= NIU_FLAGS_PROMISC
;
5642 if ((dev
->flags
& IFF_ALLMULTI
) || (dev
->mc_count
> 0))
5643 np
->flags
|= NIU_FLAGS_MCAST
;
5645 alt_cnt
= dev
->uc_count
;
5646 if (alt_cnt
> niu_num_alt_addr(np
)) {
5648 np
->flags
|= NIU_FLAGS_PROMISC
;
5654 for (addr
= dev
->uc_list
; addr
; addr
= addr
->next
) {
5655 err
= niu_set_alt_mac(np
, index
,
5658 printk(KERN_WARNING PFX
"%s: Error %d "
5659 "adding alt mac %d\n",
5660 dev
->name
, err
, index
);
5661 err
= niu_enable_alt_mac(np
, index
, 1);
5663 printk(KERN_WARNING PFX
"%s: Error %d "
5664 "enabling alt mac %d\n",
5665 dev
->name
, err
, index
);
5671 if (np
->flags
& NIU_FLAGS_XMAC
)
5675 for (i
= alt_start
; i
< niu_num_alt_addr(np
); i
++) {
5676 err
= niu_enable_alt_mac(np
, i
, 0);
5678 printk(KERN_WARNING PFX
"%s: Error %d "
5679 "disabling alt mac %d\n",
5683 if (dev
->flags
& IFF_ALLMULTI
) {
5684 for (i
= 0; i
< 16; i
++)
5686 } else if (dev
->mc_count
> 0) {
5687 for (addr
= dev
->mc_list
; addr
; addr
= addr
->next
) {
5688 u32 crc
= ether_crc_le(ETH_ALEN
, addr
->da_addr
);
5691 hash
[crc
>> 4] |= (1 << (15 - (crc
& 0xf)));
5695 if (np
->flags
& NIU_FLAGS_MCAST
)
5696 niu_load_hash(np
, hash
);
5698 niu_enable_rx_mac(np
, 1);
5699 spin_unlock_irqrestore(&np
->lock
, flags
);
5702 static int niu_set_mac_addr(struct net_device
*dev
, void *p
)
5704 struct niu
*np
= netdev_priv(dev
);
5705 struct sockaddr
*addr
= p
;
5706 unsigned long flags
;
5708 if (!is_valid_ether_addr(addr
->sa_data
))
5711 memcpy(dev
->dev_addr
, addr
->sa_data
, ETH_ALEN
);
5713 if (!netif_running(dev
))
5716 spin_lock_irqsave(&np
->lock
, flags
);
5717 niu_enable_rx_mac(np
, 0);
5718 niu_set_primary_mac(np
, dev
->dev_addr
);
5719 niu_enable_rx_mac(np
, 1);
5720 spin_unlock_irqrestore(&np
->lock
, flags
);
5725 static int niu_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
5730 static void niu_netif_stop(struct niu
*np
)
5732 np
->dev
->trans_start
= jiffies
; /* prevent tx timeout */
5734 niu_disable_napi(np
);
5736 netif_tx_disable(np
->dev
);
5739 static void niu_netif_start(struct niu
*np
)
5741 /* NOTE: unconditional netif_wake_queue is only appropriate
5742 * so long as all callers are assured to have free tx slots
5743 * (such as after niu_init_hw).
5745 netif_wake_queue(np
->dev
);
5747 niu_enable_napi(np
);
5749 niu_enable_interrupts(np
, 1);
5752 static void niu_reset_task(struct work_struct
*work
)
5754 struct niu
*np
= container_of(work
, struct niu
, reset_task
);
5755 unsigned long flags
;
5758 spin_lock_irqsave(&np
->lock
, flags
);
5759 if (!netif_running(np
->dev
)) {
5760 spin_unlock_irqrestore(&np
->lock
, flags
);
5764 spin_unlock_irqrestore(&np
->lock
, flags
);
5766 del_timer_sync(&np
->timer
);
5770 spin_lock_irqsave(&np
->lock
, flags
);
5774 err
= niu_init_hw(np
);
5776 np
->timer
.expires
= jiffies
+ HZ
;
5777 add_timer(&np
->timer
);
5778 niu_netif_start(np
);
5781 spin_unlock_irqrestore(&np
->lock
, flags
);
5784 static void niu_tx_timeout(struct net_device
*dev
)
5786 struct niu
*np
= netdev_priv(dev
);
5788 dev_err(np
->device
, PFX
"%s: Transmit timed out, resetting\n",
5791 schedule_work(&np
->reset_task
);
5794 static void niu_set_txd(struct tx_ring_info
*rp
, int index
,
5795 u64 mapping
, u64 len
, u64 mark
,
5798 __le64
*desc
= &rp
->descr
[index
];
5800 *desc
= cpu_to_le64(mark
|
5801 (n_frags
<< TX_DESC_NUM_PTR_SHIFT
) |
5802 (len
<< TX_DESC_TR_LEN_SHIFT
) |
5803 (mapping
& TX_DESC_SAD
));
5806 static u64
niu_compute_tx_flags(struct sk_buff
*skb
, struct ethhdr
*ehdr
,
5807 u64 pad_bytes
, u64 len
)
5809 u16 eth_proto
, eth_proto_inner
;
5810 u64 csum_bits
, l3off
, ihl
, ret
;
5814 eth_proto
= be16_to_cpu(ehdr
->h_proto
);
5815 eth_proto_inner
= eth_proto
;
5816 if (eth_proto
== ETH_P_8021Q
) {
5817 struct vlan_ethhdr
*vp
= (struct vlan_ethhdr
*) ehdr
;
5818 __be16 val
= vp
->h_vlan_encapsulated_proto
;
5820 eth_proto_inner
= be16_to_cpu(val
);
5824 switch (skb
->protocol
) {
5825 case __constant_htons(ETH_P_IP
):
5826 ip_proto
= ip_hdr(skb
)->protocol
;
5827 ihl
= ip_hdr(skb
)->ihl
;
5829 case __constant_htons(ETH_P_IPV6
):
5830 ip_proto
= ipv6_hdr(skb
)->nexthdr
;
5839 csum_bits
= TXHDR_CSUM_NONE
;
5840 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
5843 csum_bits
= (ip_proto
== IPPROTO_TCP
?
5845 (ip_proto
== IPPROTO_UDP
?
5846 TXHDR_CSUM_UDP
: TXHDR_CSUM_SCTP
));
5848 start
= skb_transport_offset(skb
) -
5849 (pad_bytes
+ sizeof(struct tx_pkt_hdr
));
5850 stuff
= start
+ skb
->csum_offset
;
5852 csum_bits
|= (start
/ 2) << TXHDR_L4START_SHIFT
;
5853 csum_bits
|= (stuff
/ 2) << TXHDR_L4STUFF_SHIFT
;
5856 l3off
= skb_network_offset(skb
) -
5857 (pad_bytes
+ sizeof(struct tx_pkt_hdr
));
5859 ret
= (((pad_bytes
/ 2) << TXHDR_PAD_SHIFT
) |
5860 (len
<< TXHDR_LEN_SHIFT
) |
5861 ((l3off
/ 2) << TXHDR_L3START_SHIFT
) |
5862 (ihl
<< TXHDR_IHL_SHIFT
) |
5863 ((eth_proto_inner
< 1536) ? TXHDR_LLC
: 0) |
5864 ((eth_proto
== ETH_P_8021Q
) ? TXHDR_VLAN
: 0) |
5865 (ipv6
? TXHDR_IP_VER
: 0) |
5871 static struct tx_ring_info
*tx_ring_select(struct niu
*np
, struct sk_buff
*skb
)
5873 return &np
->tx_rings
[0];
5876 static int niu_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
5878 struct niu
*np
= netdev_priv(dev
);
5879 unsigned long align
, headroom
;
5880 struct tx_ring_info
*rp
;
5881 struct tx_pkt_hdr
*tp
;
5882 unsigned int len
, nfg
;
5883 struct ethhdr
*ehdr
;
5887 rp
= tx_ring_select(np
, skb
);
5889 if (niu_tx_avail(rp
) <= (skb_shinfo(skb
)->nr_frags
+ 1)) {
5890 netif_stop_queue(dev
);
5891 dev_err(np
->device
, PFX
"%s: BUG! Tx ring full when "
5892 "queue awake!\n", dev
->name
);
5894 return NETDEV_TX_BUSY
;
5897 if (skb
->len
< ETH_ZLEN
) {
5898 unsigned int pad_bytes
= ETH_ZLEN
- skb
->len
;
5900 if (skb_pad(skb
, pad_bytes
))
5902 skb_put(skb
, pad_bytes
);
5905 len
= sizeof(struct tx_pkt_hdr
) + 15;
5906 if (skb_headroom(skb
) < len
) {
5907 struct sk_buff
*skb_new
;
5909 skb_new
= skb_realloc_headroom(skb
, len
);
5919 align
= ((unsigned long) skb
->data
& (16 - 1));
5920 headroom
= align
+ sizeof(struct tx_pkt_hdr
);
5922 ehdr
= (struct ethhdr
*) skb
->data
;
5923 tp
= (struct tx_pkt_hdr
*) skb_push(skb
, headroom
);
5925 len
= skb
->len
- sizeof(struct tx_pkt_hdr
);
5926 tp
->flags
= cpu_to_le64(niu_compute_tx_flags(skb
, ehdr
, align
, len
));
5929 len
= skb_headlen(skb
);
5930 mapping
= np
->ops
->map_single(np
->device
, skb
->data
,
5931 len
, DMA_TO_DEVICE
);
5935 rp
->tx_buffs
[prod
].skb
= skb
;
5936 rp
->tx_buffs
[prod
].mapping
= mapping
;
5939 if (++rp
->mark_counter
== rp
->mark_freq
) {
5940 rp
->mark_counter
= 0;
5941 mrk
|= TX_DESC_MARK
;
5946 nfg
= skb_shinfo(skb
)->nr_frags
;
5948 tlen
-= MAX_TX_DESC_LEN
;
5953 unsigned int this_len
= len
;
5955 if (this_len
> MAX_TX_DESC_LEN
)
5956 this_len
= MAX_TX_DESC_LEN
;
5958 niu_set_txd(rp
, prod
, mapping
, this_len
, mrk
, nfg
);
5961 prod
= NEXT_TX(rp
, prod
);
5962 mapping
+= this_len
;
5966 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
5967 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
5970 mapping
= np
->ops
->map_page(np
->device
, frag
->page
,
5971 frag
->page_offset
, len
,
5974 rp
->tx_buffs
[prod
].skb
= NULL
;
5975 rp
->tx_buffs
[prod
].mapping
= mapping
;
5977 niu_set_txd(rp
, prod
, mapping
, len
, 0, 0);
5979 prod
= NEXT_TX(rp
, prod
);
5982 if (prod
< rp
->prod
)
5983 rp
->wrap_bit
^= TX_RING_KICK_WRAP
;
5986 nw64(TX_RING_KICK(rp
->tx_channel
), rp
->wrap_bit
| (prod
<< 3));
5988 if (unlikely(niu_tx_avail(rp
) <= (MAX_SKB_FRAGS
+ 1))) {
5989 netif_stop_queue(dev
);
5990 if (niu_tx_avail(rp
) > NIU_TX_WAKEUP_THRESH(rp
))
5991 netif_wake_queue(dev
);
5994 dev
->trans_start
= jiffies
;
5997 return NETDEV_TX_OK
;
6005 static int niu_change_mtu(struct net_device
*dev
, int new_mtu
)
6007 struct niu
*np
= netdev_priv(dev
);
6008 int err
, orig_jumbo
, new_jumbo
;
6010 if (new_mtu
< 68 || new_mtu
> NIU_MAX_MTU
)
6013 orig_jumbo
= (dev
->mtu
> ETH_DATA_LEN
);
6014 new_jumbo
= (new_mtu
> ETH_DATA_LEN
);
6018 if (!netif_running(dev
) ||
6019 (orig_jumbo
== new_jumbo
))
6022 niu_full_shutdown(np
, dev
);
6024 niu_free_channels(np
);
6026 niu_enable_napi(np
);
6028 err
= niu_alloc_channels(np
);
6032 spin_lock_irq(&np
->lock
);
6034 err
= niu_init_hw(np
);
6036 init_timer(&np
->timer
);
6037 np
->timer
.expires
= jiffies
+ HZ
;
6038 np
->timer
.data
= (unsigned long) np
;
6039 np
->timer
.function
= niu_timer
;
6041 err
= niu_enable_interrupts(np
, 1);
6046 spin_unlock_irq(&np
->lock
);
6049 netif_start_queue(dev
);
6050 if (np
->link_config
.loopback_mode
!= LOOPBACK_DISABLED
)
6051 netif_carrier_on(dev
);
6053 add_timer(&np
->timer
);
6059 static void niu_get_drvinfo(struct net_device
*dev
,
6060 struct ethtool_drvinfo
*info
)
6062 struct niu
*np
= netdev_priv(dev
);
6063 struct niu_vpd
*vpd
= &np
->vpd
;
6065 strcpy(info
->driver
, DRV_MODULE_NAME
);
6066 strcpy(info
->version
, DRV_MODULE_VERSION
);
6067 sprintf(info
->fw_version
, "%d.%d",
6068 vpd
->fcode_major
, vpd
->fcode_minor
);
6069 if (np
->parent
->plat_type
!= PLAT_TYPE_NIU
)
6070 strcpy(info
->bus_info
, pci_name(np
->pdev
));
6073 static int niu_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
6075 struct niu
*np
= netdev_priv(dev
);
6076 struct niu_link_config
*lp
;
6078 lp
= &np
->link_config
;
6080 memset(cmd
, 0, sizeof(*cmd
));
6081 cmd
->phy_address
= np
->phy_addr
;
6082 cmd
->supported
= lp
->supported
;
6083 cmd
->advertising
= lp
->advertising
;
6084 cmd
->autoneg
= lp
->autoneg
;
6085 cmd
->speed
= lp
->active_speed
;
6086 cmd
->duplex
= lp
->active_duplex
;
6091 static int niu_set_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
6096 static u32
niu_get_msglevel(struct net_device
*dev
)
6098 struct niu
*np
= netdev_priv(dev
);
6099 return np
->msg_enable
;
6102 static void niu_set_msglevel(struct net_device
*dev
, u32 value
)
6104 struct niu
*np
= netdev_priv(dev
);
6105 np
->msg_enable
= value
;
6108 static int niu_get_eeprom_len(struct net_device
*dev
)
6110 struct niu
*np
= netdev_priv(dev
);
6112 return np
->eeprom_len
;
6115 static int niu_get_eeprom(struct net_device
*dev
,
6116 struct ethtool_eeprom
*eeprom
, u8
*data
)
6118 struct niu
*np
= netdev_priv(dev
);
6119 u32 offset
, len
, val
;
6121 offset
= eeprom
->offset
;
6124 if (offset
+ len
< offset
)
6126 if (offset
>= np
->eeprom_len
)
6128 if (offset
+ len
> np
->eeprom_len
)
6129 len
= eeprom
->len
= np
->eeprom_len
- offset
;
6132 u32 b_offset
, b_count
;
6134 b_offset
= offset
& 3;
6135 b_count
= 4 - b_offset
;
6139 val
= nr64(ESPC_NCR((offset
- b_offset
) / 4));
6140 memcpy(data
, ((char *)&val
) + b_offset
, b_count
);
6146 val
= nr64(ESPC_NCR(offset
/ 4));
6147 memcpy(data
, &val
, 4);
6153 val
= nr64(ESPC_NCR(offset
/ 4));
6154 memcpy(data
, &val
, len
);
6159 static const struct {
6160 const char string
[ETH_GSTRING_LEN
];
6161 } niu_xmac_stat_keys
[] = {
6164 { "tx_fifo_errors" },
6165 { "tx_overflow_errors" },
6166 { "tx_max_pkt_size_errors" },
6167 { "tx_underflow_errors" },
6168 { "rx_local_faults" },
6169 { "rx_remote_faults" },
6170 { "rx_link_faults" },
6171 { "rx_align_errors" },
6183 { "rx_code_violations" },
6184 { "rx_len_errors" },
6185 { "rx_crc_errors" },
6186 { "rx_underflows" },
6188 { "pause_off_state" },
6189 { "pause_on_state" },
6190 { "pause_received" },
6193 #define NUM_XMAC_STAT_KEYS ARRAY_SIZE(niu_xmac_stat_keys)
6195 static const struct {
6196 const char string
[ETH_GSTRING_LEN
];
6197 } niu_bmac_stat_keys
[] = {
6198 { "tx_underflow_errors" },
6199 { "tx_max_pkt_size_errors" },
6204 { "rx_align_errors" },
6205 { "rx_crc_errors" },
6206 { "rx_len_errors" },
6207 { "pause_off_state" },
6208 { "pause_on_state" },
6209 { "pause_received" },
6212 #define NUM_BMAC_STAT_KEYS ARRAY_SIZE(niu_bmac_stat_keys)
6214 static const struct {
6215 const char string
[ETH_GSTRING_LEN
];
6216 } niu_rxchan_stat_keys
[] = {
6224 #define NUM_RXCHAN_STAT_KEYS ARRAY_SIZE(niu_rxchan_stat_keys)
6226 static const struct {
6227 const char string
[ETH_GSTRING_LEN
];
6228 } niu_txchan_stat_keys
[] = {
6235 #define NUM_TXCHAN_STAT_KEYS ARRAY_SIZE(niu_txchan_stat_keys)
6237 static void niu_get_strings(struct net_device
*dev
, u32 stringset
, u8
*data
)
6239 struct niu
*np
= netdev_priv(dev
);
6242 if (stringset
!= ETH_SS_STATS
)
6245 if (np
->flags
& NIU_FLAGS_XMAC
) {
6246 memcpy(data
, niu_xmac_stat_keys
,
6247 sizeof(niu_xmac_stat_keys
));
6248 data
+= sizeof(niu_xmac_stat_keys
);
6250 memcpy(data
, niu_bmac_stat_keys
,
6251 sizeof(niu_bmac_stat_keys
));
6252 data
+= sizeof(niu_bmac_stat_keys
);
6254 for (i
= 0; i
< np
->num_rx_rings
; i
++) {
6255 memcpy(data
, niu_rxchan_stat_keys
,
6256 sizeof(niu_rxchan_stat_keys
));
6257 data
+= sizeof(niu_rxchan_stat_keys
);
6259 for (i
= 0; i
< np
->num_tx_rings
; i
++) {
6260 memcpy(data
, niu_txchan_stat_keys
,
6261 sizeof(niu_txchan_stat_keys
));
6262 data
+= sizeof(niu_txchan_stat_keys
);
6266 static int niu_get_stats_count(struct net_device
*dev
)
6268 struct niu
*np
= netdev_priv(dev
);
6270 return ((np
->flags
& NIU_FLAGS_XMAC
?
6271 NUM_XMAC_STAT_KEYS
:
6272 NUM_BMAC_STAT_KEYS
) +
6273 (np
->num_rx_rings
* NUM_RXCHAN_STAT_KEYS
) +
6274 (np
->num_tx_rings
* NUM_TXCHAN_STAT_KEYS
));
6277 static void niu_get_ethtool_stats(struct net_device
*dev
,
6278 struct ethtool_stats
*stats
, u64
*data
)
6280 struct niu
*np
= netdev_priv(dev
);
6283 niu_sync_mac_stats(np
);
6284 if (np
->flags
& NIU_FLAGS_XMAC
) {
6285 memcpy(data
, &np
->mac_stats
.xmac
,
6286 sizeof(struct niu_xmac_stats
));
6287 data
+= (sizeof(struct niu_xmac_stats
) / sizeof(u64
));
6289 memcpy(data
, &np
->mac_stats
.bmac
,
6290 sizeof(struct niu_bmac_stats
));
6291 data
+= (sizeof(struct niu_bmac_stats
) / sizeof(u64
));
6293 for (i
= 0; i
< np
->num_rx_rings
; i
++) {
6294 struct rx_ring_info
*rp
= &np
->rx_rings
[i
];
6296 data
[0] = rp
->rx_channel
;
6297 data
[1] = rp
->rx_packets
;
6298 data
[2] = rp
->rx_bytes
;
6299 data
[3] = rp
->rx_dropped
;
6300 data
[4] = rp
->rx_errors
;
6303 for (i
= 0; i
< np
->num_tx_rings
; i
++) {
6304 struct tx_ring_info
*rp
= &np
->tx_rings
[i
];
6306 data
[0] = rp
->tx_channel
;
6307 data
[1] = rp
->tx_packets
;
6308 data
[2] = rp
->tx_bytes
;
6309 data
[3] = rp
->tx_errors
;
6314 static u64
niu_led_state_save(struct niu
*np
)
6316 if (np
->flags
& NIU_FLAGS_XMAC
)
6317 return nr64_mac(XMAC_CONFIG
);
6319 return nr64_mac(BMAC_XIF_CONFIG
);
6322 static void niu_led_state_restore(struct niu
*np
, u64 val
)
6324 if (np
->flags
& NIU_FLAGS_XMAC
)
6325 nw64_mac(XMAC_CONFIG
, val
);
6327 nw64_mac(BMAC_XIF_CONFIG
, val
);
6330 static void niu_force_led(struct niu
*np
, int on
)
6334 if (np
->flags
& NIU_FLAGS_XMAC
) {
6336 bit
= XMAC_CONFIG_FORCE_LED_ON
;
6338 reg
= BMAC_XIF_CONFIG
;
6339 bit
= BMAC_XIF_CONFIG_LINK_LED
;
6342 val
= nr64_mac(reg
);
6350 static int niu_phys_id(struct net_device
*dev
, u32 data
)
6352 struct niu
*np
= netdev_priv(dev
);
6356 if (!netif_running(dev
))
6362 orig_led_state
= niu_led_state_save(np
);
6363 for (i
= 0; i
< (data
* 2); i
++) {
6364 int on
= ((i
% 2) == 0);
6366 niu_force_led(np
, on
);
6368 if (msleep_interruptible(500))
6371 niu_led_state_restore(np
, orig_led_state
);
6376 static const struct ethtool_ops niu_ethtool_ops
= {
6377 .get_drvinfo
= niu_get_drvinfo
,
6378 .get_link
= ethtool_op_get_link
,
6379 .get_msglevel
= niu_get_msglevel
,
6380 .set_msglevel
= niu_set_msglevel
,
6381 .get_eeprom_len
= niu_get_eeprom_len
,
6382 .get_eeprom
= niu_get_eeprom
,
6383 .get_settings
= niu_get_settings
,
6384 .set_settings
= niu_set_settings
,
6385 .get_strings
= niu_get_strings
,
6386 .get_stats_count
= niu_get_stats_count
,
6387 .get_ethtool_stats
= niu_get_ethtool_stats
,
6388 .phys_id
= niu_phys_id
,
6391 static int niu_ldg_assign_ldn(struct niu
*np
, struct niu_parent
*parent
,
6394 if (ldg
< NIU_LDG_MIN
|| ldg
> NIU_LDG_MAX
)
6396 if (ldn
< 0 || ldn
> LDN_MAX
)
6399 parent
->ldg_map
[ldn
] = ldg
;
6401 if (np
->parent
->plat_type
== PLAT_TYPE_NIU
) {
6402 /* On N2 NIU, the ldn-->ldg assignments are setup and fixed by
6403 * the firmware, and we're not supposed to change them.
6404 * Validate the mapping, because if it's wrong we probably
6405 * won't get any interrupts and that's painful to debug.
6407 if (nr64(LDG_NUM(ldn
)) != ldg
) {
6408 dev_err(np
->device
, PFX
"Port %u, mis-matched "
6410 "for ldn %d, should be %d is %llu\n",
6412 (unsigned long long) nr64(LDG_NUM(ldn
)));
6416 nw64(LDG_NUM(ldn
), ldg
);
6421 static int niu_set_ldg_timer_res(struct niu
*np
, int res
)
6423 if (res
< 0 || res
> LDG_TIMER_RES_VAL
)
6427 nw64(LDG_TIMER_RES
, res
);
6432 static int niu_set_ldg_sid(struct niu
*np
, int ldg
, int func
, int vector
)
6434 if ((ldg
< NIU_LDG_MIN
|| ldg
> NIU_LDG_MAX
) ||
6435 (func
< 0 || func
> 3) ||
6436 (vector
< 0 || vector
> 0x1f))
6439 nw64(SID(ldg
), (func
<< SID_FUNC_SHIFT
) | vector
);
6444 static int __devinit
niu_pci_eeprom_read(struct niu
*np
, u32 addr
)
6446 u64 frame
, frame_base
= (ESPC_PIO_STAT_READ_START
|
6447 (addr
<< ESPC_PIO_STAT_ADDR_SHIFT
));
6450 if (addr
> (ESPC_PIO_STAT_ADDR
>> ESPC_PIO_STAT_ADDR_SHIFT
))
6454 nw64(ESPC_PIO_STAT
, frame
);
6458 frame
= nr64(ESPC_PIO_STAT
);
6459 if (frame
& ESPC_PIO_STAT_READ_END
)
6462 if (!(frame
& ESPC_PIO_STAT_READ_END
)) {
6463 dev_err(np
->device
, PFX
"EEPROM read timeout frame[%llx]\n",
6464 (unsigned long long) frame
);
6469 nw64(ESPC_PIO_STAT
, frame
);
6473 frame
= nr64(ESPC_PIO_STAT
);
6474 if (frame
& ESPC_PIO_STAT_READ_END
)
6477 if (!(frame
& ESPC_PIO_STAT_READ_END
)) {
6478 dev_err(np
->device
, PFX
"EEPROM read timeout frame[%llx]\n",
6479 (unsigned long long) frame
);
6483 frame
= nr64(ESPC_PIO_STAT
);
6484 return (frame
& ESPC_PIO_STAT_DATA
) >> ESPC_PIO_STAT_DATA_SHIFT
;
6487 static int __devinit
niu_pci_eeprom_read16(struct niu
*np
, u32 off
)
6489 int err
= niu_pci_eeprom_read(np
, off
);
6495 err
= niu_pci_eeprom_read(np
, off
+ 1);
6498 val
|= (err
& 0xff);
6503 static int __devinit
niu_pci_eeprom_read16_swp(struct niu
*np
, u32 off
)
6505 int err
= niu_pci_eeprom_read(np
, off
);
6512 err
= niu_pci_eeprom_read(np
, off
+ 1);
6516 val
|= (err
& 0xff) << 8;
6521 static int __devinit
niu_pci_vpd_get_propname(struct niu
*np
,
6528 for (i
= 0; i
< namebuf_len
; i
++) {
6529 int err
= niu_pci_eeprom_read(np
, off
+ i
);
6536 if (i
>= namebuf_len
)
6542 static void __devinit
niu_vpd_parse_version(struct niu
*np
)
6544 struct niu_vpd
*vpd
= &np
->vpd
;
6545 int len
= strlen(vpd
->version
) + 1;
6546 const char *s
= vpd
->version
;
6549 for (i
= 0; i
< len
- 5; i
++) {
6550 if (!strncmp(s
+ i
, "FCode ", 5))
6557 sscanf(s
, "%d.%d", &vpd
->fcode_major
, &vpd
->fcode_minor
);
6559 niudbg(PROBE
, "VPD_SCAN: FCODE major(%d) minor(%d)\n",
6560 vpd
->fcode_major
, vpd
->fcode_minor
);
6561 if (vpd
->fcode_major
> NIU_VPD_MIN_MAJOR
||
6562 (vpd
->fcode_major
== NIU_VPD_MIN_MAJOR
&&
6563 vpd
->fcode_minor
>= NIU_VPD_MIN_MINOR
))
6564 np
->flags
|= NIU_FLAGS_VPD_VALID
;
6567 /* ESPC_PIO_EN_ENABLE must be set */
6568 static int __devinit
niu_pci_vpd_scan_props(struct niu
*np
,
6571 unsigned int found_mask
= 0;
6572 #define FOUND_MASK_MODEL 0x00000001
6573 #define FOUND_MASK_BMODEL 0x00000002
6574 #define FOUND_MASK_VERS 0x00000004
6575 #define FOUND_MASK_MAC 0x00000008
6576 #define FOUND_MASK_NMAC 0x00000010
6577 #define FOUND_MASK_PHY 0x00000020
6578 #define FOUND_MASK_ALL 0x0000003f
6580 niudbg(PROBE
, "VPD_SCAN: start[%x] end[%x]\n",
6582 while (start
< end
) {
6583 int len
, err
, instance
, type
, prop_len
;
6588 if (found_mask
== FOUND_MASK_ALL
) {
6589 niu_vpd_parse_version(np
);
6593 err
= niu_pci_eeprom_read(np
, start
+ 2);
6599 instance
= niu_pci_eeprom_read(np
, start
);
6600 type
= niu_pci_eeprom_read(np
, start
+ 3);
6601 prop_len
= niu_pci_eeprom_read(np
, start
+ 4);
6602 err
= niu_pci_vpd_get_propname(np
, start
+ 5, namebuf
, 64);
6608 if (!strcmp(namebuf
, "model")) {
6609 prop_buf
= np
->vpd
.model
;
6610 max_len
= NIU_VPD_MODEL_MAX
;
6611 found_mask
|= FOUND_MASK_MODEL
;
6612 } else if (!strcmp(namebuf
, "board-model")) {
6613 prop_buf
= np
->vpd
.board_model
;
6614 max_len
= NIU_VPD_BD_MODEL_MAX
;
6615 found_mask
|= FOUND_MASK_BMODEL
;
6616 } else if (!strcmp(namebuf
, "version")) {
6617 prop_buf
= np
->vpd
.version
;
6618 max_len
= NIU_VPD_VERSION_MAX
;
6619 found_mask
|= FOUND_MASK_VERS
;
6620 } else if (!strcmp(namebuf
, "local-mac-address")) {
6621 prop_buf
= np
->vpd
.local_mac
;
6623 found_mask
|= FOUND_MASK_MAC
;
6624 } else if (!strcmp(namebuf
, "num-mac-addresses")) {
6625 prop_buf
= &np
->vpd
.mac_num
;
6627 found_mask
|= FOUND_MASK_NMAC
;
6628 } else if (!strcmp(namebuf
, "phy-type")) {
6629 prop_buf
= np
->vpd
.phy_type
;
6630 max_len
= NIU_VPD_PHY_TYPE_MAX
;
6631 found_mask
|= FOUND_MASK_PHY
;
6634 if (max_len
&& prop_len
> max_len
) {
6635 dev_err(np
->device
, PFX
"Property '%s' length (%d) is "
6636 "too long.\n", namebuf
, prop_len
);
6641 u32 off
= start
+ 5 + err
;
6644 niudbg(PROBE
, "VPD_SCAN: Reading in property [%s] "
6645 "len[%d]\n", namebuf
, prop_len
);
6646 for (i
= 0; i
< prop_len
; i
++)
6647 *prop_buf
++ = niu_pci_eeprom_read(np
, off
+ i
);
6656 /* ESPC_PIO_EN_ENABLE must be set */
6657 static void __devinit
niu_pci_vpd_fetch(struct niu
*np
, u32 start
)
6662 err
= niu_pci_eeprom_read16_swp(np
, start
+ 1);
6668 while (start
+ offset
< ESPC_EEPROM_SIZE
) {
6669 u32 here
= start
+ offset
;
6672 err
= niu_pci_eeprom_read(np
, here
);
6676 err
= niu_pci_eeprom_read16_swp(np
, here
+ 1);
6680 here
= start
+ offset
+ 3;
6681 end
= start
+ offset
+ err
;
6685 err
= niu_pci_vpd_scan_props(np
, here
, end
);
6686 if (err
< 0 || err
== 1)
6691 /* ESPC_PIO_EN_ENABLE must be set */
6692 static u32 __devinit
niu_pci_vpd_offset(struct niu
*np
)
6694 u32 start
= 0, end
= ESPC_EEPROM_SIZE
, ret
;
6697 while (start
< end
) {
6700 /* ROM header signature? */
6701 err
= niu_pci_eeprom_read16(np
, start
+ 0);
6705 /* Apply offset to PCI data structure. */
6706 err
= niu_pci_eeprom_read16(np
, start
+ 23);
6711 /* Check for "PCIR" signature. */
6712 err
= niu_pci_eeprom_read16(np
, start
+ 0);
6715 err
= niu_pci_eeprom_read16(np
, start
+ 2);
6719 /* Check for OBP image type. */
6720 err
= niu_pci_eeprom_read(np
, start
+ 20);
6724 err
= niu_pci_eeprom_read(np
, ret
+ 2);
6728 start
= ret
+ (err
* 512);
6732 err
= niu_pci_eeprom_read16_swp(np
, start
+ 8);
6737 err
= niu_pci_eeprom_read(np
, ret
+ 0);
6747 static int __devinit
niu_phy_type_prop_decode(struct niu
*np
,
6748 const char *phy_prop
)
6750 if (!strcmp(phy_prop
, "mif")) {
6751 /* 1G copper, MII */
6752 np
->flags
&= ~(NIU_FLAGS_FIBER
|
6754 np
->mac_xcvr
= MAC_XCVR_MII
;
6755 } else if (!strcmp(phy_prop
, "xgf")) {
6756 /* 10G fiber, XPCS */
6757 np
->flags
|= (NIU_FLAGS_10G
|
6759 np
->mac_xcvr
= MAC_XCVR_XPCS
;
6760 } else if (!strcmp(phy_prop
, "pcs")) {
6762 np
->flags
&= ~NIU_FLAGS_10G
;
6763 np
->flags
|= NIU_FLAGS_FIBER
;
6764 np
->mac_xcvr
= MAC_XCVR_PCS
;
6765 } else if (!strcmp(phy_prop
, "xgc")) {
6766 /* 10G copper, XPCS */
6767 np
->flags
|= NIU_FLAGS_10G
;
6768 np
->flags
&= ~NIU_FLAGS_FIBER
;
6769 np
->mac_xcvr
= MAC_XCVR_XPCS
;
6776 static void __devinit
niu_pci_vpd_validate(struct niu
*np
)
6778 struct net_device
*dev
= np
->dev
;
6779 struct niu_vpd
*vpd
= &np
->vpd
;
6782 if (!is_valid_ether_addr(&vpd
->local_mac
[0])) {
6783 dev_err(np
->device
, PFX
"VPD MAC invalid, "
6784 "falling back to SPROM.\n");
6786 np
->flags
&= ~NIU_FLAGS_VPD_VALID
;
6790 if (!strcmp(np
->vpd
.model
, "SUNW,CP3220") ||
6791 !strcmp(np
->vpd
.model
, "SUNW,CP3260")) {
6792 np
->flags
|= NIU_FLAGS_10G
;
6793 np
->flags
&= ~NIU_FLAGS_FIBER
;
6794 np
->flags
|= NIU_FLAGS_XCVR_SERDES
;
6795 np
->mac_xcvr
= MAC_XCVR_PCS
;
6797 np
->flags
|= NIU_FLAGS_FIBER
;
6798 np
->flags
&= ~NIU_FLAGS_10G
;
6800 if (np
->flags
& NIU_FLAGS_10G
)
6801 np
->mac_xcvr
= MAC_XCVR_XPCS
;
6802 } else if (niu_phy_type_prop_decode(np
, np
->vpd
.phy_type
)) {
6803 dev_err(np
->device
, PFX
"Illegal phy string [%s].\n",
6805 dev_err(np
->device
, PFX
"Falling back to SPROM.\n");
6806 np
->flags
&= ~NIU_FLAGS_VPD_VALID
;
6810 memcpy(dev
->perm_addr
, vpd
->local_mac
, ETH_ALEN
);
6812 val8
= dev
->perm_addr
[5];
6813 dev
->perm_addr
[5] += np
->port
;
6814 if (dev
->perm_addr
[5] < val8
)
6815 dev
->perm_addr
[4]++;
6817 memcpy(dev
->dev_addr
, dev
->perm_addr
, dev
->addr_len
);
6820 static int __devinit
niu_pci_probe_sprom(struct niu
*np
)
6822 struct net_device
*dev
= np
->dev
;
6827 val
= (nr64(ESPC_VER_IMGSZ
) & ESPC_VER_IMGSZ_IMGSZ
);
6828 val
>>= ESPC_VER_IMGSZ_IMGSZ_SHIFT
;
6831 np
->eeprom_len
= len
;
6833 niudbg(PROBE
, "SPROM: Image size %llu\n", (unsigned long long) val
);
6836 for (i
= 0; i
< len
; i
++) {
6837 val
= nr64(ESPC_NCR(i
));
6838 sum
+= (val
>> 0) & 0xff;
6839 sum
+= (val
>> 8) & 0xff;
6840 sum
+= (val
>> 16) & 0xff;
6841 sum
+= (val
>> 24) & 0xff;
6843 niudbg(PROBE
, "SPROM: Checksum %x\n", (int)(sum
& 0xff));
6844 if ((sum
& 0xff) != 0xab) {
6845 dev_err(np
->device
, PFX
"Bad SPROM checksum "
6846 "(%x, should be 0xab)\n", (int) (sum
& 0xff));
6850 val
= nr64(ESPC_PHY_TYPE
);
6853 val8
= (val
& ESPC_PHY_TYPE_PORT0
) >>
6854 ESPC_PHY_TYPE_PORT0_SHIFT
;
6857 val8
= (val
& ESPC_PHY_TYPE_PORT1
) >>
6858 ESPC_PHY_TYPE_PORT1_SHIFT
;
6861 val8
= (val
& ESPC_PHY_TYPE_PORT2
) >>
6862 ESPC_PHY_TYPE_PORT2_SHIFT
;
6865 val8
= (val
& ESPC_PHY_TYPE_PORT3
) >>
6866 ESPC_PHY_TYPE_PORT3_SHIFT
;
6869 dev_err(np
->device
, PFX
"Bogus port number %u\n",
6873 niudbg(PROBE
, "SPROM: PHY type %x\n", val8
);
6876 case ESPC_PHY_TYPE_1G_COPPER
:
6877 /* 1G copper, MII */
6878 np
->flags
&= ~(NIU_FLAGS_FIBER
|
6880 np
->mac_xcvr
= MAC_XCVR_MII
;
6883 case ESPC_PHY_TYPE_1G_FIBER
:
6885 np
->flags
&= ~NIU_FLAGS_10G
;
6886 np
->flags
|= NIU_FLAGS_FIBER
;
6887 np
->mac_xcvr
= MAC_XCVR_PCS
;
6890 case ESPC_PHY_TYPE_10G_COPPER
:
6891 /* 10G copper, XPCS */
6892 np
->flags
|= NIU_FLAGS_10G
;
6893 np
->flags
&= ~NIU_FLAGS_FIBER
;
6894 np
->mac_xcvr
= MAC_XCVR_XPCS
;
6897 case ESPC_PHY_TYPE_10G_FIBER
:
6898 /* 10G fiber, XPCS */
6899 np
->flags
|= (NIU_FLAGS_10G
|
6901 np
->mac_xcvr
= MAC_XCVR_XPCS
;
6905 dev_err(np
->device
, PFX
"Bogus SPROM phy type %u\n", val8
);
6909 val
= nr64(ESPC_MAC_ADDR0
);
6910 niudbg(PROBE
, "SPROM: MAC_ADDR0[%08llx]\n",
6911 (unsigned long long) val
);
6912 dev
->perm_addr
[0] = (val
>> 0) & 0xff;
6913 dev
->perm_addr
[1] = (val
>> 8) & 0xff;
6914 dev
->perm_addr
[2] = (val
>> 16) & 0xff;
6915 dev
->perm_addr
[3] = (val
>> 24) & 0xff;
6917 val
= nr64(ESPC_MAC_ADDR1
);
6918 niudbg(PROBE
, "SPROM: MAC_ADDR1[%08llx]\n",
6919 (unsigned long long) val
);
6920 dev
->perm_addr
[4] = (val
>> 0) & 0xff;
6921 dev
->perm_addr
[5] = (val
>> 8) & 0xff;
6923 if (!is_valid_ether_addr(&dev
->perm_addr
[0])) {
6924 dev_err(np
->device
, PFX
"SPROM MAC address invalid\n");
6925 dev_err(np
->device
, PFX
"[ \n");
6926 for (i
= 0; i
< 6; i
++)
6927 printk("%02x ", dev
->perm_addr
[i
]);
6932 val8
= dev
->perm_addr
[5];
6933 dev
->perm_addr
[5] += np
->port
;
6934 if (dev
->perm_addr
[5] < val8
)
6935 dev
->perm_addr
[4]++;
6937 memcpy(dev
->dev_addr
, dev
->perm_addr
, dev
->addr_len
);
6939 val
= nr64(ESPC_MOD_STR_LEN
);
6940 niudbg(PROBE
, "SPROM: MOD_STR_LEN[%llu]\n",
6941 (unsigned long long) val
);
6945 for (i
= 0; i
< val
; i
+= 4) {
6946 u64 tmp
= nr64(ESPC_NCR(5 + (i
/ 4)));
6948 np
->vpd
.model
[i
+ 3] = (tmp
>> 0) & 0xff;
6949 np
->vpd
.model
[i
+ 2] = (tmp
>> 8) & 0xff;
6950 np
->vpd
.model
[i
+ 1] = (tmp
>> 16) & 0xff;
6951 np
->vpd
.model
[i
+ 0] = (tmp
>> 24) & 0xff;
6953 np
->vpd
.model
[val
] = '\0';
6955 val
= nr64(ESPC_BD_MOD_STR_LEN
);
6956 niudbg(PROBE
, "SPROM: BD_MOD_STR_LEN[%llu]\n",
6957 (unsigned long long) val
);
6961 for (i
= 0; i
< val
; i
+= 4) {
6962 u64 tmp
= nr64(ESPC_NCR(14 + (i
/ 4)));
6964 np
->vpd
.board_model
[i
+ 3] = (tmp
>> 0) & 0xff;
6965 np
->vpd
.board_model
[i
+ 2] = (tmp
>> 8) & 0xff;
6966 np
->vpd
.board_model
[i
+ 1] = (tmp
>> 16) & 0xff;
6967 np
->vpd
.board_model
[i
+ 0] = (tmp
>> 24) & 0xff;
6969 np
->vpd
.board_model
[val
] = '\0';
6972 nr64(ESPC_NUM_PORTS_MACS
) & ESPC_NUM_PORTS_MACS_VAL
;
6973 niudbg(PROBE
, "SPROM: NUM_PORTS_MACS[%d]\n",
6979 static int __devinit
niu_get_and_validate_port(struct niu
*np
)
6981 struct niu_parent
*parent
= np
->parent
;
6984 np
->flags
|= NIU_FLAGS_XMAC
;
6986 if (!parent
->num_ports
) {
6987 if (parent
->plat_type
== PLAT_TYPE_NIU
) {
6988 parent
->num_ports
= 2;
6990 parent
->num_ports
= nr64(ESPC_NUM_PORTS_MACS
) &
6991 ESPC_NUM_PORTS_MACS_VAL
;
6993 if (!parent
->num_ports
)
6994 parent
->num_ports
= 4;
6998 niudbg(PROBE
, "niu_get_and_validate_port: port[%d] num_ports[%d]\n",
6999 np
->port
, parent
->num_ports
);
7000 if (np
->port
>= parent
->num_ports
)
7006 static int __devinit
phy_record(struct niu_parent
*parent
,
7007 struct phy_probe_info
*p
,
7008 int dev_id_1
, int dev_id_2
, u8 phy_port
,
7011 u32 id
= (dev_id_1
<< 16) | dev_id_2
;
7014 if (dev_id_1
< 0 || dev_id_2
< 0)
7016 if (type
== PHY_TYPE_PMA_PMD
|| type
== PHY_TYPE_PCS
) {
7017 if (((id
& NIU_PHY_ID_MASK
) != NIU_PHY_ID_BCM8704
) &&
7018 ((id
& NIU_PHY_ID_MASK
) != NIU_PHY_ID_MRVL88X2011
))
7021 if ((id
& NIU_PHY_ID_MASK
) != NIU_PHY_ID_BCM5464R
)
7025 pr_info("niu%d: Found PHY %08x type %s at phy_port %u\n",
7027 (type
== PHY_TYPE_PMA_PMD
?
7029 (type
== PHY_TYPE_PCS
?
7033 if (p
->cur
[type
] >= NIU_MAX_PORTS
) {
7034 printk(KERN_ERR PFX
"Too many PHY ports.\n");
7038 p
->phy_id
[type
][idx
] = id
;
7039 p
->phy_port
[type
][idx
] = phy_port
;
7040 p
->cur
[type
] = idx
+ 1;
7044 static int __devinit
port_has_10g(struct phy_probe_info
*p
, int port
)
7048 for (i
= 0; i
< p
->cur
[PHY_TYPE_PMA_PMD
]; i
++) {
7049 if (p
->phy_port
[PHY_TYPE_PMA_PMD
][i
] == port
)
7052 for (i
= 0; i
< p
->cur
[PHY_TYPE_PCS
]; i
++) {
7053 if (p
->phy_port
[PHY_TYPE_PCS
][i
] == port
)
7060 static int __devinit
count_10g_ports(struct phy_probe_info
*p
, int *lowest
)
7066 for (port
= 8; port
< 32; port
++) {
7067 if (port_has_10g(p
, port
)) {
7077 static int __devinit
count_1g_ports(struct phy_probe_info
*p
, int *lowest
)
7080 if (p
->cur
[PHY_TYPE_MII
])
7081 *lowest
= p
->phy_port
[PHY_TYPE_MII
][0];
7083 return p
->cur
[PHY_TYPE_MII
];
7086 static void __devinit
niu_n2_divide_channels(struct niu_parent
*parent
)
7088 int num_ports
= parent
->num_ports
;
7091 for (i
= 0; i
< num_ports
; i
++) {
7092 parent
->rxchan_per_port
[i
] = (16 / num_ports
);
7093 parent
->txchan_per_port
[i
] = (16 / num_ports
);
7095 pr_info(PFX
"niu%d: Port %u [%u RX chans] "
7098 parent
->rxchan_per_port
[i
],
7099 parent
->txchan_per_port
[i
]);
7103 static void __devinit
niu_divide_channels(struct niu_parent
*parent
,
7104 int num_10g
, int num_1g
)
7106 int num_ports
= parent
->num_ports
;
7107 int rx_chans_per_10g
, rx_chans_per_1g
;
7108 int tx_chans_per_10g
, tx_chans_per_1g
;
7109 int i
, tot_rx
, tot_tx
;
7111 if (!num_10g
|| !num_1g
) {
7112 rx_chans_per_10g
= rx_chans_per_1g
=
7113 (NIU_NUM_RXCHAN
/ num_ports
);
7114 tx_chans_per_10g
= tx_chans_per_1g
=
7115 (NIU_NUM_TXCHAN
/ num_ports
);
7117 rx_chans_per_1g
= NIU_NUM_RXCHAN
/ 8;
7118 rx_chans_per_10g
= (NIU_NUM_RXCHAN
-
7119 (rx_chans_per_1g
* num_1g
)) /
7122 tx_chans_per_1g
= NIU_NUM_TXCHAN
/ 6;
7123 tx_chans_per_10g
= (NIU_NUM_TXCHAN
-
7124 (tx_chans_per_1g
* num_1g
)) /
7128 tot_rx
= tot_tx
= 0;
7129 for (i
= 0; i
< num_ports
; i
++) {
7130 int type
= phy_decode(parent
->port_phy
, i
);
7132 if (type
== PORT_TYPE_10G
) {
7133 parent
->rxchan_per_port
[i
] = rx_chans_per_10g
;
7134 parent
->txchan_per_port
[i
] = tx_chans_per_10g
;
7136 parent
->rxchan_per_port
[i
] = rx_chans_per_1g
;
7137 parent
->txchan_per_port
[i
] = tx_chans_per_1g
;
7139 pr_info(PFX
"niu%d: Port %u [%u RX chans] "
7142 parent
->rxchan_per_port
[i
],
7143 parent
->txchan_per_port
[i
]);
7144 tot_rx
+= parent
->rxchan_per_port
[i
];
7145 tot_tx
+= parent
->txchan_per_port
[i
];
7148 if (tot_rx
> NIU_NUM_RXCHAN
) {
7149 printk(KERN_ERR PFX
"niu%d: Too many RX channels (%d), "
7150 "resetting to one per port.\n",
7151 parent
->index
, tot_rx
);
7152 for (i
= 0; i
< num_ports
; i
++)
7153 parent
->rxchan_per_port
[i
] = 1;
7155 if (tot_tx
> NIU_NUM_TXCHAN
) {
7156 printk(KERN_ERR PFX
"niu%d: Too many TX channels (%d), "
7157 "resetting to one per port.\n",
7158 parent
->index
, tot_tx
);
7159 for (i
= 0; i
< num_ports
; i
++)
7160 parent
->txchan_per_port
[i
] = 1;
7162 if (tot_rx
< NIU_NUM_RXCHAN
|| tot_tx
< NIU_NUM_TXCHAN
) {
7163 printk(KERN_WARNING PFX
"niu%d: Driver bug, wasted channels, "
7165 parent
->index
, tot_rx
, tot_tx
);
7169 static void __devinit
niu_divide_rdc_groups(struct niu_parent
*parent
,
7170 int num_10g
, int num_1g
)
7172 int i
, num_ports
= parent
->num_ports
;
7173 int rdc_group
, rdc_groups_per_port
;
7174 int rdc_channel_base
;
7177 rdc_groups_per_port
= NIU_NUM_RDC_TABLES
/ num_ports
;
7179 rdc_channel_base
= 0;
7181 for (i
= 0; i
< num_ports
; i
++) {
7182 struct niu_rdc_tables
*tp
= &parent
->rdc_group_cfg
[i
];
7183 int grp
, num_channels
= parent
->rxchan_per_port
[i
];
7184 int this_channel_offset
;
7186 tp
->first_table_num
= rdc_group
;
7187 tp
->num_tables
= rdc_groups_per_port
;
7188 this_channel_offset
= 0;
7189 for (grp
= 0; grp
< tp
->num_tables
; grp
++) {
7190 struct rdc_table
*rt
= &tp
->tables
[grp
];
7193 pr_info(PFX
"niu%d: Port %d RDC tbl(%d) [ ",
7194 parent
->index
, i
, tp
->first_table_num
+ grp
);
7195 for (slot
= 0; slot
< NIU_RDC_TABLE_SLOTS
; slot
++) {
7196 rt
->rxdma_channel
[slot
] =
7197 rdc_channel_base
+ this_channel_offset
;
7199 printk("%d ", rt
->rxdma_channel
[slot
]);
7201 if (++this_channel_offset
== num_channels
)
7202 this_channel_offset
= 0;
7207 parent
->rdc_default
[i
] = rdc_channel_base
;
7209 rdc_channel_base
+= num_channels
;
7210 rdc_group
+= rdc_groups_per_port
;
7214 static int __devinit
fill_phy_probe_info(struct niu
*np
,
7215 struct niu_parent
*parent
,
7216 struct phy_probe_info
*info
)
7218 unsigned long flags
;
7221 memset(info
, 0, sizeof(*info
));
7223 /* Port 0 to 7 are reserved for onboard Serdes, probe the rest. */
7224 niu_lock_parent(np
, flags
);
7226 for (port
= 8; port
< 32; port
++) {
7227 int dev_id_1
, dev_id_2
;
7229 dev_id_1
= mdio_read(np
, port
,
7230 NIU_PMA_PMD_DEV_ADDR
, MII_PHYSID1
);
7231 dev_id_2
= mdio_read(np
, port
,
7232 NIU_PMA_PMD_DEV_ADDR
, MII_PHYSID2
);
7233 err
= phy_record(parent
, info
, dev_id_1
, dev_id_2
, port
,
7237 dev_id_1
= mdio_read(np
, port
,
7238 NIU_PCS_DEV_ADDR
, MII_PHYSID1
);
7239 dev_id_2
= mdio_read(np
, port
,
7240 NIU_PCS_DEV_ADDR
, MII_PHYSID2
);
7241 err
= phy_record(parent
, info
, dev_id_1
, dev_id_2
, port
,
7245 dev_id_1
= mii_read(np
, port
, MII_PHYSID1
);
7246 dev_id_2
= mii_read(np
, port
, MII_PHYSID2
);
7247 err
= phy_record(parent
, info
, dev_id_1
, dev_id_2
, port
,
7252 niu_unlock_parent(np
, flags
);
7257 static int __devinit
walk_phys(struct niu
*np
, struct niu_parent
*parent
)
7259 struct phy_probe_info
*info
= &parent
->phy_probe_info
;
7260 int lowest_10g
, lowest_1g
;
7261 int num_10g
, num_1g
;
7266 if (!strcmp(np
->vpd
.model
, "SUNW,CP3220") ||
7267 !strcmp(np
->vpd
.model
, "SUNW,CP3260")) {
7270 parent
->plat_type
= PLAT_TYPE_ATCA_CP3220
;
7271 parent
->num_ports
= 4;
7272 val
= (phy_encode(PORT_TYPE_1G
, 0) |
7273 phy_encode(PORT_TYPE_1G
, 1) |
7274 phy_encode(PORT_TYPE_1G
, 2) |
7275 phy_encode(PORT_TYPE_1G
, 3));
7277 err
= fill_phy_probe_info(np
, parent
, info
);
7281 num_10g
= count_10g_ports(info
, &lowest_10g
);
7282 num_1g
= count_1g_ports(info
, &lowest_1g
);
7284 switch ((num_10g
<< 4) | num_1g
) {
7286 if (lowest_1g
== 10)
7287 parent
->plat_type
= PLAT_TYPE_VF_P0
;
7288 else if (lowest_1g
== 26)
7289 parent
->plat_type
= PLAT_TYPE_VF_P1
;
7291 goto unknown_vg_1g_port
;
7295 val
= (phy_encode(PORT_TYPE_10G
, 0) |
7296 phy_encode(PORT_TYPE_10G
, 1) |
7297 phy_encode(PORT_TYPE_1G
, 2) |
7298 phy_encode(PORT_TYPE_1G
, 3));
7302 val
= (phy_encode(PORT_TYPE_10G
, 0) |
7303 phy_encode(PORT_TYPE_10G
, 1));
7307 val
= phy_encode(PORT_TYPE_10G
, np
->port
);
7311 if (lowest_1g
== 10)
7312 parent
->plat_type
= PLAT_TYPE_VF_P0
;
7313 else if (lowest_1g
== 26)
7314 parent
->plat_type
= PLAT_TYPE_VF_P1
;
7316 goto unknown_vg_1g_port
;
7320 if ((lowest_10g
& 0x7) == 0)
7321 val
= (phy_encode(PORT_TYPE_10G
, 0) |
7322 phy_encode(PORT_TYPE_1G
, 1) |
7323 phy_encode(PORT_TYPE_1G
, 2) |
7324 phy_encode(PORT_TYPE_1G
, 3));
7326 val
= (phy_encode(PORT_TYPE_1G
, 0) |
7327 phy_encode(PORT_TYPE_10G
, 1) |
7328 phy_encode(PORT_TYPE_1G
, 2) |
7329 phy_encode(PORT_TYPE_1G
, 3));
7333 if (lowest_1g
== 10)
7334 parent
->plat_type
= PLAT_TYPE_VF_P0
;
7335 else if (lowest_1g
== 26)
7336 parent
->plat_type
= PLAT_TYPE_VF_P1
;
7338 goto unknown_vg_1g_port
;
7340 val
= (phy_encode(PORT_TYPE_1G
, 0) |
7341 phy_encode(PORT_TYPE_1G
, 1) |
7342 phy_encode(PORT_TYPE_1G
, 2) |
7343 phy_encode(PORT_TYPE_1G
, 3));
7347 printk(KERN_ERR PFX
"Unsupported port config "
7354 parent
->port_phy
= val
;
7356 if (parent
->plat_type
== PLAT_TYPE_NIU
)
7357 niu_n2_divide_channels(parent
);
7359 niu_divide_channels(parent
, num_10g
, num_1g
);
7361 niu_divide_rdc_groups(parent
, num_10g
, num_1g
);
7366 printk(KERN_ERR PFX
"Cannot identify platform type, 1gport=%d\n",
7371 static int __devinit
niu_probe_ports(struct niu
*np
)
7373 struct niu_parent
*parent
= np
->parent
;
7376 niudbg(PROBE
, "niu_probe_ports(): port_phy[%08x]\n",
7379 if (parent
->port_phy
== PORT_PHY_UNKNOWN
) {
7380 err
= walk_phys(np
, parent
);
7384 niu_set_ldg_timer_res(np
, 2);
7385 for (i
= 0; i
<= LDN_MAX
; i
++)
7386 niu_ldn_irq_enable(np
, i
, 0);
7389 if (parent
->port_phy
== PORT_PHY_INVALID
)
7395 static int __devinit
niu_classifier_swstate_init(struct niu
*np
)
7397 struct niu_classifier
*cp
= &np
->clas
;
7399 niudbg(PROBE
, "niu_classifier_swstate_init: num_tcam(%d)\n",
7400 np
->parent
->tcam_num_entries
);
7402 cp
->tcam_index
= (u16
) np
->port
;
7403 cp
->h1_init
= 0xffffffff;
7404 cp
->h2_init
= 0xffff;
7406 return fflp_early_init(np
);
7409 static void __devinit
niu_link_config_init(struct niu
*np
)
7411 struct niu_link_config
*lp
= &np
->link_config
;
7413 lp
->advertising
= (ADVERTISED_10baseT_Half
|
7414 ADVERTISED_10baseT_Full
|
7415 ADVERTISED_100baseT_Half
|
7416 ADVERTISED_100baseT_Full
|
7417 ADVERTISED_1000baseT_Half
|
7418 ADVERTISED_1000baseT_Full
|
7419 ADVERTISED_10000baseT_Full
|
7420 ADVERTISED_Autoneg
);
7421 lp
->speed
= lp
->active_speed
= SPEED_INVALID
;
7422 lp
->duplex
= lp
->active_duplex
= DUPLEX_INVALID
;
7424 lp
->loopback_mode
= LOOPBACK_MAC
;
7425 lp
->active_speed
= SPEED_10000
;
7426 lp
->active_duplex
= DUPLEX_FULL
;
7428 lp
->loopback_mode
= LOOPBACK_DISABLED
;
7432 static int __devinit
niu_init_mac_ipp_pcs_base(struct niu
*np
)
7436 np
->mac_regs
= np
->regs
+ XMAC_PORT0_OFF
;
7437 np
->ipp_off
= 0x00000;
7438 np
->pcs_off
= 0x04000;
7439 np
->xpcs_off
= 0x02000;
7443 np
->mac_regs
= np
->regs
+ XMAC_PORT1_OFF
;
7444 np
->ipp_off
= 0x08000;
7445 np
->pcs_off
= 0x0a000;
7446 np
->xpcs_off
= 0x08000;
7450 np
->mac_regs
= np
->regs
+ BMAC_PORT2_OFF
;
7451 np
->ipp_off
= 0x04000;
7452 np
->pcs_off
= 0x0e000;
7453 np
->xpcs_off
= ~0UL;
7457 np
->mac_regs
= np
->regs
+ BMAC_PORT3_OFF
;
7458 np
->ipp_off
= 0x0c000;
7459 np
->pcs_off
= 0x12000;
7460 np
->xpcs_off
= ~0UL;
7464 dev_err(np
->device
, PFX
"Port %u is invalid, cannot "
7465 "compute MAC block offset.\n", np
->port
);
7472 static void __devinit
niu_try_msix(struct niu
*np
, u8
*ldg_num_map
)
7474 struct msix_entry msi_vec
[NIU_NUM_LDG
];
7475 struct niu_parent
*parent
= np
->parent
;
7476 struct pci_dev
*pdev
= np
->pdev
;
7477 int i
, num_irqs
, err
;
7480 first_ldg
= (NIU_NUM_LDG
/ parent
->num_ports
) * np
->port
;
7481 for (i
= 0; i
< (NIU_NUM_LDG
/ parent
->num_ports
); i
++)
7482 ldg_num_map
[i
] = first_ldg
+ i
;
7484 num_irqs
= (parent
->rxchan_per_port
[np
->port
] +
7485 parent
->txchan_per_port
[np
->port
] +
7486 (np
->port
== 0 ? 3 : 1));
7487 BUG_ON(num_irqs
> (NIU_NUM_LDG
/ parent
->num_ports
));
7490 for (i
= 0; i
< num_irqs
; i
++) {
7491 msi_vec
[i
].vector
= 0;
7492 msi_vec
[i
].entry
= i
;
7495 err
= pci_enable_msix(pdev
, msi_vec
, num_irqs
);
7497 np
->flags
&= ~NIU_FLAGS_MSIX
;
7505 np
->flags
|= NIU_FLAGS_MSIX
;
7506 for (i
= 0; i
< num_irqs
; i
++)
7507 np
->ldg
[i
].irq
= msi_vec
[i
].vector
;
7508 np
->num_ldg
= num_irqs
;
7511 static int __devinit
niu_n2_irq_init(struct niu
*np
, u8
*ldg_num_map
)
7513 #ifdef CONFIG_SPARC64
7514 struct of_device
*op
= np
->op
;
7515 const u32
*int_prop
;
7518 int_prop
= of_get_property(op
->node
, "interrupts", NULL
);
7522 for (i
= 0; i
< op
->num_irqs
; i
++) {
7523 ldg_num_map
[i
] = int_prop
[i
];
7524 np
->ldg
[i
].irq
= op
->irqs
[i
];
7527 np
->num_ldg
= op
->num_irqs
;
7535 static int __devinit
niu_ldg_init(struct niu
*np
)
7537 struct niu_parent
*parent
= np
->parent
;
7538 u8 ldg_num_map
[NIU_NUM_LDG
];
7539 int first_chan
, num_chan
;
7540 int i
, err
, ldg_rotor
;
7544 np
->ldg
[0].irq
= np
->dev
->irq
;
7545 if (parent
->plat_type
== PLAT_TYPE_NIU
) {
7546 err
= niu_n2_irq_init(np
, ldg_num_map
);
7550 niu_try_msix(np
, ldg_num_map
);
7553 for (i
= 0; i
< np
->num_ldg
; i
++) {
7554 struct niu_ldg
*lp
= &np
->ldg
[i
];
7556 netif_napi_add(np
->dev
, &lp
->napi
, niu_poll
, 64);
7559 lp
->ldg_num
= ldg_num_map
[i
];
7560 lp
->timer
= 2; /* XXX */
7562 /* On N2 NIU the firmware has setup the SID mappings so they go
7563 * to the correct values that will route the LDG to the proper
7564 * interrupt in the NCU interrupt table.
7566 if (np
->parent
->plat_type
!= PLAT_TYPE_NIU
) {
7567 err
= niu_set_ldg_sid(np
, lp
->ldg_num
, port
, i
);
7573 /* We adopt the LDG assignment ordering used by the N2 NIU
7574 * 'interrupt' properties because that simplifies a lot of
7575 * things. This ordering is:
7578 * MIF (if port zero)
7579 * SYSERR (if port zero)
7586 err
= niu_ldg_assign_ldn(np
, parent
, ldg_num_map
[ldg_rotor
],
7592 if (ldg_rotor
== np
->num_ldg
)
7596 err
= niu_ldg_assign_ldn(np
, parent
,
7597 ldg_num_map
[ldg_rotor
],
7603 if (ldg_rotor
== np
->num_ldg
)
7606 err
= niu_ldg_assign_ldn(np
, parent
,
7607 ldg_num_map
[ldg_rotor
],
7613 if (ldg_rotor
== np
->num_ldg
)
7619 for (i
= 0; i
< port
; i
++)
7620 first_chan
+= parent
->rxchan_per_port
[port
];
7621 num_chan
= parent
->rxchan_per_port
[port
];
7623 for (i
= first_chan
; i
< (first_chan
+ num_chan
); i
++) {
7624 err
= niu_ldg_assign_ldn(np
, parent
,
7625 ldg_num_map
[ldg_rotor
],
7630 if (ldg_rotor
== np
->num_ldg
)
7635 for (i
= 0; i
< port
; i
++)
7636 first_chan
+= parent
->txchan_per_port
[port
];
7637 num_chan
= parent
->txchan_per_port
[port
];
7638 for (i
= first_chan
; i
< (first_chan
+ num_chan
); i
++) {
7639 err
= niu_ldg_assign_ldn(np
, parent
,
7640 ldg_num_map
[ldg_rotor
],
7645 if (ldg_rotor
== np
->num_ldg
)
7652 static void __devexit
niu_ldg_free(struct niu
*np
)
7654 if (np
->flags
& NIU_FLAGS_MSIX
)
7655 pci_disable_msix(np
->pdev
);
7658 static int __devinit
niu_get_of_props(struct niu
*np
)
7660 #ifdef CONFIG_SPARC64
7661 struct net_device
*dev
= np
->dev
;
7662 struct device_node
*dp
;
7663 const char *phy_type
;
7667 if (np
->parent
->plat_type
== PLAT_TYPE_NIU
)
7670 dp
= pci_device_to_OF_node(np
->pdev
);
7672 phy_type
= of_get_property(dp
, "phy-type", &prop_len
);
7674 dev_err(np
->device
, PFX
"%s: OF node lacks "
7675 "phy-type property\n",
7680 if (!strcmp(phy_type
, "none"))
7683 strcpy(np
->vpd
.phy_type
, phy_type
);
7685 if (niu_phy_type_prop_decode(np
, np
->vpd
.phy_type
)) {
7686 dev_err(np
->device
, PFX
"%s: Illegal phy string [%s].\n",
7687 dp
->full_name
, np
->vpd
.phy_type
);
7691 mac_addr
= of_get_property(dp
, "local-mac-address", &prop_len
);
7693 dev_err(np
->device
, PFX
"%s: OF node lacks "
7694 "local-mac-address property\n",
7698 if (prop_len
!= dev
->addr_len
) {
7699 dev_err(np
->device
, PFX
"%s: OF MAC address prop len (%d) "
7701 dp
->full_name
, prop_len
);
7703 memcpy(dev
->perm_addr
, mac_addr
, dev
->addr_len
);
7704 if (!is_valid_ether_addr(&dev
->perm_addr
[0])) {
7707 dev_err(np
->device
, PFX
"%s: OF MAC address is invalid\n",
7709 dev_err(np
->device
, PFX
"%s: [ \n",
7711 for (i
= 0; i
< 6; i
++)
7712 printk("%02x ", dev
->perm_addr
[i
]);
7717 memcpy(dev
->dev_addr
, dev
->perm_addr
, dev
->addr_len
);
7725 static int __devinit
niu_get_invariants(struct niu
*np
)
7727 int err
, have_props
;
7730 err
= niu_get_of_props(np
);
7736 err
= niu_get_and_validate_port(np
);
7740 err
= niu_init_mac_ipp_pcs_base(np
);
7745 if (np
->parent
->plat_type
== PLAT_TYPE_NIU
)
7748 nw64(ESPC_PIO_EN
, ESPC_PIO_EN_ENABLE
);
7749 offset
= niu_pci_vpd_offset(np
);
7750 niudbg(PROBE
, "niu_get_invariants: VPD offset [%08x]\n",
7753 niu_pci_vpd_fetch(np
, offset
);
7754 nw64(ESPC_PIO_EN
, 0);
7756 if (np
->flags
& NIU_FLAGS_VPD_VALID
)
7757 niu_pci_vpd_validate(np
);
7759 if (!(np
->flags
& NIU_FLAGS_VPD_VALID
)) {
7760 err
= niu_pci_probe_sprom(np
);
7766 err
= niu_probe_ports(np
);
7772 niu_classifier_swstate_init(np
);
7773 niu_link_config_init(np
);
7775 err
= niu_determine_phy_disposition(np
);
7777 err
= niu_init_link(np
);
7782 static LIST_HEAD(niu_parent_list
);
7783 static DEFINE_MUTEX(niu_parent_lock
);
7784 static int niu_parent_index
;
7786 static ssize_t
show_port_phy(struct device
*dev
,
7787 struct device_attribute
*attr
, char *buf
)
7789 struct platform_device
*plat_dev
= to_platform_device(dev
);
7790 struct niu_parent
*p
= plat_dev
->dev
.platform_data
;
7791 u32 port_phy
= p
->port_phy
;
7792 char *orig_buf
= buf
;
7795 if (port_phy
== PORT_PHY_UNKNOWN
||
7796 port_phy
== PORT_PHY_INVALID
)
7799 for (i
= 0; i
< p
->num_ports
; i
++) {
7800 const char *type_str
;
7803 type
= phy_decode(port_phy
, i
);
7804 if (type
== PORT_TYPE_10G
)
7809 (i
== 0) ? "%s" : " %s",
7812 buf
+= sprintf(buf
, "\n");
7813 return buf
- orig_buf
;
7816 static ssize_t
show_plat_type(struct device
*dev
,
7817 struct device_attribute
*attr
, char *buf
)
7819 struct platform_device
*plat_dev
= to_platform_device(dev
);
7820 struct niu_parent
*p
= plat_dev
->dev
.platform_data
;
7821 const char *type_str
;
7823 switch (p
->plat_type
) {
7824 case PLAT_TYPE_ATLAS
:
7830 case PLAT_TYPE_VF_P0
:
7833 case PLAT_TYPE_VF_P1
:
7837 type_str
= "unknown";
7841 return sprintf(buf
, "%s\n", type_str
);
7844 static ssize_t
__show_chan_per_port(struct device
*dev
,
7845 struct device_attribute
*attr
, char *buf
,
7848 struct platform_device
*plat_dev
= to_platform_device(dev
);
7849 struct niu_parent
*p
= plat_dev
->dev
.platform_data
;
7850 char *orig_buf
= buf
;
7854 arr
= (rx
? p
->rxchan_per_port
: p
->txchan_per_port
);
7856 for (i
= 0; i
< p
->num_ports
; i
++) {
7858 (i
== 0) ? "%d" : " %d",
7861 buf
+= sprintf(buf
, "\n");
7863 return buf
- orig_buf
;
7866 static ssize_t
show_rxchan_per_port(struct device
*dev
,
7867 struct device_attribute
*attr
, char *buf
)
7869 return __show_chan_per_port(dev
, attr
, buf
, 1);
7872 static ssize_t
show_txchan_per_port(struct device
*dev
,
7873 struct device_attribute
*attr
, char *buf
)
7875 return __show_chan_per_port(dev
, attr
, buf
, 1);
7878 static ssize_t
show_num_ports(struct device
*dev
,
7879 struct device_attribute
*attr
, char *buf
)
7881 struct platform_device
*plat_dev
= to_platform_device(dev
);
7882 struct niu_parent
*p
= plat_dev
->dev
.platform_data
;
7884 return sprintf(buf
, "%d\n", p
->num_ports
);
7887 static struct device_attribute niu_parent_attributes
[] = {
7888 __ATTR(port_phy
, S_IRUGO
, show_port_phy
, NULL
),
7889 __ATTR(plat_type
, S_IRUGO
, show_plat_type
, NULL
),
7890 __ATTR(rxchan_per_port
, S_IRUGO
, show_rxchan_per_port
, NULL
),
7891 __ATTR(txchan_per_port
, S_IRUGO
, show_txchan_per_port
, NULL
),
7892 __ATTR(num_ports
, S_IRUGO
, show_num_ports
, NULL
),
7896 static struct niu_parent
* __devinit
niu_new_parent(struct niu
*np
,
7897 union niu_parent_id
*id
,
7900 struct platform_device
*plat_dev
;
7901 struct niu_parent
*p
;
7904 niudbg(PROBE
, "niu_new_parent: Creating new parent.\n");
7906 plat_dev
= platform_device_register_simple("niu", niu_parent_index
,
7911 for (i
= 0; attr_name(niu_parent_attributes
[i
]); i
++) {
7912 int err
= device_create_file(&plat_dev
->dev
,
7913 &niu_parent_attributes
[i
]);
7915 goto fail_unregister
;
7918 p
= kzalloc(sizeof(*p
), GFP_KERNEL
);
7920 goto fail_unregister
;
7922 p
->index
= niu_parent_index
++;
7924 plat_dev
->dev
.platform_data
= p
;
7925 p
->plat_dev
= plat_dev
;
7927 memcpy(&p
->id
, id
, sizeof(*id
));
7928 p
->plat_type
= ptype
;
7929 INIT_LIST_HEAD(&p
->list
);
7930 atomic_set(&p
->refcnt
, 0);
7931 list_add(&p
->list
, &niu_parent_list
);
7932 spin_lock_init(&p
->lock
);
7934 p
->rxdma_clock_divider
= 7500;
7936 p
->tcam_num_entries
= NIU_PCI_TCAM_ENTRIES
;
7937 if (p
->plat_type
== PLAT_TYPE_NIU
)
7938 p
->tcam_num_entries
= NIU_NONPCI_TCAM_ENTRIES
;
7940 for (i
= CLASS_CODE_USER_PROG1
; i
<= CLASS_CODE_SCTP_IPV6
; i
++) {
7941 int index
= i
- CLASS_CODE_USER_PROG1
;
7943 p
->tcam_key
[index
] = TCAM_KEY_TSEL
;
7944 p
->flow_key
[index
] = (FLOW_KEY_IPSA
|
7947 (FLOW_KEY_L4_BYTE12
<<
7948 FLOW_KEY_L4_0_SHIFT
) |
7949 (FLOW_KEY_L4_BYTE12
<<
7950 FLOW_KEY_L4_1_SHIFT
));
7953 for (i
= 0; i
< LDN_MAX
+ 1; i
++)
7954 p
->ldg_map
[i
] = LDG_INVALID
;
7959 platform_device_unregister(plat_dev
);
7963 static struct niu_parent
* __devinit
niu_get_parent(struct niu
*np
,
7964 union niu_parent_id
*id
,
7967 struct niu_parent
*p
, *tmp
;
7968 int port
= np
->port
;
7970 niudbg(PROBE
, "niu_get_parent: platform_type[%u] port[%u]\n",
7973 mutex_lock(&niu_parent_lock
);
7975 list_for_each_entry(tmp
, &niu_parent_list
, list
) {
7976 if (!memcmp(id
, &tmp
->id
, sizeof(*id
))) {
7982 p
= niu_new_parent(np
, id
, ptype
);
7988 sprintf(port_name
, "port%d", port
);
7989 err
= sysfs_create_link(&p
->plat_dev
->dev
.kobj
,
7993 p
->ports
[port
] = np
;
7994 atomic_inc(&p
->refcnt
);
7997 mutex_unlock(&niu_parent_lock
);
8002 static void niu_put_parent(struct niu
*np
)
8004 struct niu_parent
*p
= np
->parent
;
8008 BUG_ON(!p
|| p
->ports
[port
] != np
);
8010 niudbg(PROBE
, "niu_put_parent: port[%u]\n", port
);
8012 sprintf(port_name
, "port%d", port
);
8014 mutex_lock(&niu_parent_lock
);
8016 sysfs_remove_link(&p
->plat_dev
->dev
.kobj
, port_name
);
8018 p
->ports
[port
] = NULL
;
8021 if (atomic_dec_and_test(&p
->refcnt
)) {
8023 platform_device_unregister(p
->plat_dev
);
8026 mutex_unlock(&niu_parent_lock
);
8029 static void *niu_pci_alloc_coherent(struct device
*dev
, size_t size
,
8030 u64
*handle
, gfp_t flag
)
8035 ret
= dma_alloc_coherent(dev
, size
, &dh
, flag
);
8041 static void niu_pci_free_coherent(struct device
*dev
, size_t size
,
8042 void *cpu_addr
, u64 handle
)
8044 dma_free_coherent(dev
, size
, cpu_addr
, handle
);
8047 static u64
niu_pci_map_page(struct device
*dev
, struct page
*page
,
8048 unsigned long offset
, size_t size
,
8049 enum dma_data_direction direction
)
8051 return dma_map_page(dev
, page
, offset
, size
, direction
);
8054 static void niu_pci_unmap_page(struct device
*dev
, u64 dma_address
,
8055 size_t size
, enum dma_data_direction direction
)
8057 return dma_unmap_page(dev
, dma_address
, size
, direction
);
8060 static u64
niu_pci_map_single(struct device
*dev
, void *cpu_addr
,
8062 enum dma_data_direction direction
)
8064 return dma_map_single(dev
, cpu_addr
, size
, direction
);
8067 static void niu_pci_unmap_single(struct device
*dev
, u64 dma_address
,
8069 enum dma_data_direction direction
)
8071 dma_unmap_single(dev
, dma_address
, size
, direction
);
8074 static const struct niu_ops niu_pci_ops
= {
8075 .alloc_coherent
= niu_pci_alloc_coherent
,
8076 .free_coherent
= niu_pci_free_coherent
,
8077 .map_page
= niu_pci_map_page
,
8078 .unmap_page
= niu_pci_unmap_page
,
8079 .map_single
= niu_pci_map_single
,
8080 .unmap_single
= niu_pci_unmap_single
,
8083 static void __devinit
niu_driver_version(void)
8085 static int niu_version_printed
;
8087 if (niu_version_printed
++ == 0)
8088 pr_info("%s", version
);
8091 static struct net_device
* __devinit
niu_alloc_and_init(
8092 struct device
*gen_dev
, struct pci_dev
*pdev
,
8093 struct of_device
*op
, const struct niu_ops
*ops
,
8096 struct net_device
*dev
= alloc_etherdev(sizeof(struct niu
));
8100 dev_err(gen_dev
, PFX
"Etherdev alloc failed, aborting.\n");
8104 SET_NETDEV_DEV(dev
, gen_dev
);
8106 np
= netdev_priv(dev
);
8110 np
->device
= gen_dev
;
8113 np
->msg_enable
= niu_debug
;
8115 spin_lock_init(&np
->lock
);
8116 INIT_WORK(&np
->reset_task
, niu_reset_task
);
8123 static void __devinit
niu_assign_netdev_ops(struct net_device
*dev
)
8125 dev
->open
= niu_open
;
8126 dev
->stop
= niu_close
;
8127 dev
->get_stats
= niu_get_stats
;
8128 dev
->set_multicast_list
= niu_set_rx_mode
;
8129 dev
->set_mac_address
= niu_set_mac_addr
;
8130 dev
->do_ioctl
= niu_ioctl
;
8131 dev
->tx_timeout
= niu_tx_timeout
;
8132 dev
->hard_start_xmit
= niu_start_xmit
;
8133 dev
->ethtool_ops
= &niu_ethtool_ops
;
8134 dev
->watchdog_timeo
= NIU_TX_TIMEOUT
;
8135 dev
->change_mtu
= niu_change_mtu
;
8138 static void __devinit
niu_device_announce(struct niu
*np
)
8140 struct net_device
*dev
= np
->dev
;
8141 DECLARE_MAC_BUF(mac
);
8143 pr_info("%s: NIU Ethernet %s\n",
8144 dev
->name
, print_mac(mac
, dev
->dev_addr
));
8146 if (np
->parent
->plat_type
== PLAT_TYPE_ATCA_CP3220
) {
8147 pr_info("%s: Port type[%s] mode[%s:%s] XCVR[%s] phy[%s]\n",
8149 (np
->flags
& NIU_FLAGS_XMAC
? "XMAC" : "BMAC"),
8150 (np
->flags
& NIU_FLAGS_10G
? "10G" : "1G"),
8151 (np
->flags
& NIU_FLAGS_FIBER
? "RGMII FIBER" : "SERDES"),
8152 (np
->mac_xcvr
== MAC_XCVR_MII
? "MII" :
8153 (np
->mac_xcvr
== MAC_XCVR_PCS
? "PCS" : "XPCS")),
8156 pr_info("%s: Port type[%s] mode[%s:%s] XCVR[%s] phy[%s]\n",
8158 (np
->flags
& NIU_FLAGS_XMAC
? "XMAC" : "BMAC"),
8159 (np
->flags
& NIU_FLAGS_10G
? "10G" : "1G"),
8160 (np
->flags
& NIU_FLAGS_FIBER
? "FIBER" : "COPPER"),
8161 (np
->mac_xcvr
== MAC_XCVR_MII
? "MII" :
8162 (np
->mac_xcvr
== MAC_XCVR_PCS
? "PCS" : "XPCS")),
8167 static int __devinit
niu_pci_init_one(struct pci_dev
*pdev
,
8168 const struct pci_device_id
*ent
)
8170 unsigned long niureg_base
, niureg_len
;
8171 union niu_parent_id parent_id
;
8172 struct net_device
*dev
;
8178 niu_driver_version();
8180 err
= pci_enable_device(pdev
);
8182 dev_err(&pdev
->dev
, PFX
"Cannot enable PCI device, "
8187 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
) ||
8188 !(pci_resource_flags(pdev
, 2) & IORESOURCE_MEM
)) {
8189 dev_err(&pdev
->dev
, PFX
"Cannot find proper PCI device "
8190 "base addresses, aborting.\n");
8192 goto err_out_disable_pdev
;
8195 err
= pci_request_regions(pdev
, DRV_MODULE_NAME
);
8197 dev_err(&pdev
->dev
, PFX
"Cannot obtain PCI resources, "
8199 goto err_out_disable_pdev
;
8202 pos
= pci_find_capability(pdev
, PCI_CAP_ID_EXP
);
8204 dev_err(&pdev
->dev
, PFX
"Cannot find PCI Express capability, "
8206 goto err_out_free_res
;
8209 dev
= niu_alloc_and_init(&pdev
->dev
, pdev
, NULL
,
8210 &niu_pci_ops
, PCI_FUNC(pdev
->devfn
));
8213 goto err_out_free_res
;
8215 np
= netdev_priv(dev
);
8217 memset(&parent_id
, 0, sizeof(parent_id
));
8218 parent_id
.pci
.domain
= pci_domain_nr(pdev
->bus
);
8219 parent_id
.pci
.bus
= pdev
->bus
->number
;
8220 parent_id
.pci
.device
= PCI_SLOT(pdev
->devfn
);
8222 np
->parent
= niu_get_parent(np
, &parent_id
,
8226 goto err_out_free_dev
;
8229 pci_read_config_word(pdev
, pos
+ PCI_EXP_DEVCTL
, &val16
);
8230 val16
&= ~PCI_EXP_DEVCTL_NOSNOOP_EN
;
8231 val16
|= (PCI_EXP_DEVCTL_CERE
|
8232 PCI_EXP_DEVCTL_NFERE
|
8233 PCI_EXP_DEVCTL_FERE
|
8234 PCI_EXP_DEVCTL_URRE
|
8235 PCI_EXP_DEVCTL_RELAX_EN
);
8236 pci_write_config_word(pdev
, pos
+ PCI_EXP_DEVCTL
, val16
);
8238 dma_mask
= DMA_44BIT_MASK
;
8239 err
= pci_set_dma_mask(pdev
, dma_mask
);
8241 dev
->features
|= NETIF_F_HIGHDMA
;
8242 err
= pci_set_consistent_dma_mask(pdev
, dma_mask
);
8244 dev_err(&pdev
->dev
, PFX
"Unable to obtain 44 bit "
8245 "DMA for consistent allocations, "
8247 goto err_out_release_parent
;
8250 if (err
|| dma_mask
== DMA_32BIT_MASK
) {
8251 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
8253 dev_err(&pdev
->dev
, PFX
"No usable DMA configuration, "
8255 goto err_out_release_parent
;
8259 dev
->features
|= (NETIF_F_SG
| NETIF_F_HW_CSUM
);
8261 niureg_base
= pci_resource_start(pdev
, 0);
8262 niureg_len
= pci_resource_len(pdev
, 0);
8264 np
->regs
= ioremap_nocache(niureg_base
, niureg_len
);
8266 dev_err(&pdev
->dev
, PFX
"Cannot map device registers, "
8269 goto err_out_release_parent
;
8272 pci_set_master(pdev
);
8273 pci_save_state(pdev
);
8275 dev
->irq
= pdev
->irq
;
8277 niu_assign_netdev_ops(dev
);
8279 err
= niu_get_invariants(np
);
8282 dev_err(&pdev
->dev
, PFX
"Problem fetching invariants "
8283 "of chip, aborting.\n");
8284 goto err_out_iounmap
;
8287 err
= register_netdev(dev
);
8289 dev_err(&pdev
->dev
, PFX
"Cannot register net device, "
8291 goto err_out_iounmap
;
8294 pci_set_drvdata(pdev
, dev
);
8296 niu_device_announce(np
);
8306 err_out_release_parent
:
8313 pci_release_regions(pdev
);
8315 err_out_disable_pdev
:
8316 pci_disable_device(pdev
);
8317 pci_set_drvdata(pdev
, NULL
);
8322 static void __devexit
niu_pci_remove_one(struct pci_dev
*pdev
)
8324 struct net_device
*dev
= pci_get_drvdata(pdev
);
8327 struct niu
*np
= netdev_priv(dev
);
8329 unregister_netdev(dev
);
8340 pci_release_regions(pdev
);
8341 pci_disable_device(pdev
);
8342 pci_set_drvdata(pdev
, NULL
);
8346 static int niu_suspend(struct pci_dev
*pdev
, pm_message_t state
)
8348 struct net_device
*dev
= pci_get_drvdata(pdev
);
8349 struct niu
*np
= netdev_priv(dev
);
8350 unsigned long flags
;
8352 if (!netif_running(dev
))
8355 flush_scheduled_work();
8358 del_timer_sync(&np
->timer
);
8360 spin_lock_irqsave(&np
->lock
, flags
);
8361 niu_enable_interrupts(np
, 0);
8362 spin_unlock_irqrestore(&np
->lock
, flags
);
8364 netif_device_detach(dev
);
8366 spin_lock_irqsave(&np
->lock
, flags
);
8368 spin_unlock_irqrestore(&np
->lock
, flags
);
8370 pci_save_state(pdev
);
8375 static int niu_resume(struct pci_dev
*pdev
)
8377 struct net_device
*dev
= pci_get_drvdata(pdev
);
8378 struct niu
*np
= netdev_priv(dev
);
8379 unsigned long flags
;
8382 if (!netif_running(dev
))
8385 pci_restore_state(pdev
);
8387 netif_device_attach(dev
);
8389 spin_lock_irqsave(&np
->lock
, flags
);
8391 err
= niu_init_hw(np
);
8393 np
->timer
.expires
= jiffies
+ HZ
;
8394 add_timer(&np
->timer
);
8395 niu_netif_start(np
);
8398 spin_unlock_irqrestore(&np
->lock
, flags
);
8403 static struct pci_driver niu_pci_driver
= {
8404 .name
= DRV_MODULE_NAME
,
8405 .id_table
= niu_pci_tbl
,
8406 .probe
= niu_pci_init_one
,
8407 .remove
= __devexit_p(niu_pci_remove_one
),
8408 .suspend
= niu_suspend
,
8409 .resume
= niu_resume
,
8412 #ifdef CONFIG_SPARC64
8413 static void *niu_phys_alloc_coherent(struct device
*dev
, size_t size
,
8414 u64
*dma_addr
, gfp_t flag
)
8416 unsigned long order
= get_order(size
);
8417 unsigned long page
= __get_free_pages(flag
, order
);
8421 memset((char *)page
, 0, PAGE_SIZE
<< order
);
8422 *dma_addr
= __pa(page
);
8424 return (void *) page
;
8427 static void niu_phys_free_coherent(struct device
*dev
, size_t size
,
8428 void *cpu_addr
, u64 handle
)
8430 unsigned long order
= get_order(size
);
8432 free_pages((unsigned long) cpu_addr
, order
);
8435 static u64
niu_phys_map_page(struct device
*dev
, struct page
*page
,
8436 unsigned long offset
, size_t size
,
8437 enum dma_data_direction direction
)
8439 return page_to_phys(page
) + offset
;
8442 static void niu_phys_unmap_page(struct device
*dev
, u64 dma_address
,
8443 size_t size
, enum dma_data_direction direction
)
8445 /* Nothing to do. */
8448 static u64
niu_phys_map_single(struct device
*dev
, void *cpu_addr
,
8450 enum dma_data_direction direction
)
8452 return __pa(cpu_addr
);
8455 static void niu_phys_unmap_single(struct device
*dev
, u64 dma_address
,
8457 enum dma_data_direction direction
)
8459 /* Nothing to do. */
8462 static const struct niu_ops niu_phys_ops
= {
8463 .alloc_coherent
= niu_phys_alloc_coherent
,
8464 .free_coherent
= niu_phys_free_coherent
,
8465 .map_page
= niu_phys_map_page
,
8466 .unmap_page
= niu_phys_unmap_page
,
8467 .map_single
= niu_phys_map_single
,
8468 .unmap_single
= niu_phys_unmap_single
,
8471 static unsigned long res_size(struct resource
*r
)
8473 return r
->end
- r
->start
+ 1UL;
8476 static int __devinit
niu_of_probe(struct of_device
*op
,
8477 const struct of_device_id
*match
)
8479 union niu_parent_id parent_id
;
8480 struct net_device
*dev
;
8485 niu_driver_version();
8487 reg
= of_get_property(op
->node
, "reg", NULL
);
8489 dev_err(&op
->dev
, PFX
"%s: No 'reg' property, aborting.\n",
8490 op
->node
->full_name
);
8494 dev
= niu_alloc_and_init(&op
->dev
, NULL
, op
,
8495 &niu_phys_ops
, reg
[0] & 0x1);
8500 np
= netdev_priv(dev
);
8502 memset(&parent_id
, 0, sizeof(parent_id
));
8503 parent_id
.of
= of_get_parent(op
->node
);
8505 np
->parent
= niu_get_parent(np
, &parent_id
,
8509 goto err_out_free_dev
;
8512 dev
->features
|= (NETIF_F_SG
| NETIF_F_HW_CSUM
);
8514 np
->regs
= of_ioremap(&op
->resource
[1], 0,
8515 res_size(&op
->resource
[1]),
8518 dev_err(&op
->dev
, PFX
"Cannot map device registers, "
8521 goto err_out_release_parent
;
8524 np
->vir_regs_1
= of_ioremap(&op
->resource
[2], 0,
8525 res_size(&op
->resource
[2]),
8527 if (!np
->vir_regs_1
) {
8528 dev_err(&op
->dev
, PFX
"Cannot map device vir registers 1, "
8531 goto err_out_iounmap
;
8534 np
->vir_regs_2
= of_ioremap(&op
->resource
[3], 0,
8535 res_size(&op
->resource
[3]),
8537 if (!np
->vir_regs_2
) {
8538 dev_err(&op
->dev
, PFX
"Cannot map device vir registers 2, "
8541 goto err_out_iounmap
;
8544 niu_assign_netdev_ops(dev
);
8546 err
= niu_get_invariants(np
);
8549 dev_err(&op
->dev
, PFX
"Problem fetching invariants "
8550 "of chip, aborting.\n");
8551 goto err_out_iounmap
;
8554 err
= register_netdev(dev
);
8556 dev_err(&op
->dev
, PFX
"Cannot register net device, "
8558 goto err_out_iounmap
;
8561 dev_set_drvdata(&op
->dev
, dev
);
8563 niu_device_announce(np
);
8568 if (np
->vir_regs_1
) {
8569 of_iounmap(&op
->resource
[2], np
->vir_regs_1
,
8570 res_size(&op
->resource
[2]));
8571 np
->vir_regs_1
= NULL
;
8574 if (np
->vir_regs_2
) {
8575 of_iounmap(&op
->resource
[3], np
->vir_regs_2
,
8576 res_size(&op
->resource
[3]));
8577 np
->vir_regs_2
= NULL
;
8581 of_iounmap(&op
->resource
[1], np
->regs
,
8582 res_size(&op
->resource
[1]));
8586 err_out_release_parent
:
8596 static int __devexit
niu_of_remove(struct of_device
*op
)
8598 struct net_device
*dev
= dev_get_drvdata(&op
->dev
);
8601 struct niu
*np
= netdev_priv(dev
);
8603 unregister_netdev(dev
);
8605 if (np
->vir_regs_1
) {
8606 of_iounmap(&op
->resource
[2], np
->vir_regs_1
,
8607 res_size(&op
->resource
[2]));
8608 np
->vir_regs_1
= NULL
;
8611 if (np
->vir_regs_2
) {
8612 of_iounmap(&op
->resource
[3], np
->vir_regs_2
,
8613 res_size(&op
->resource
[3]));
8614 np
->vir_regs_2
= NULL
;
8618 of_iounmap(&op
->resource
[1], np
->regs
,
8619 res_size(&op
->resource
[1]));
8628 dev_set_drvdata(&op
->dev
, NULL
);
8633 static struct of_device_id niu_match
[] = {
8636 .compatible
= "SUNW,niusl",
8640 MODULE_DEVICE_TABLE(of
, niu_match
);
8642 static struct of_platform_driver niu_of_driver
= {
8644 .match_table
= niu_match
,
8645 .probe
= niu_of_probe
,
8646 .remove
= __devexit_p(niu_of_remove
),
8649 #endif /* CONFIG_SPARC64 */
8651 static int __init
niu_init(void)
8655 BUILD_BUG_ON(PAGE_SIZE
< 4 * 1024);
8657 niu_debug
= netif_msg_init(debug
, NIU_MSG_DEFAULT
);
8659 #ifdef CONFIG_SPARC64
8660 err
= of_register_driver(&niu_of_driver
, &of_bus_type
);
8664 err
= pci_register_driver(&niu_pci_driver
);
8665 #ifdef CONFIG_SPARC64
8667 of_unregister_driver(&niu_of_driver
);
8674 static void __exit
niu_exit(void)
8676 pci_unregister_driver(&niu_pci_driver
);
8677 #ifdef CONFIG_SPARC64
8678 of_unregister_driver(&niu_of_driver
);
8682 module_init(niu_init
);
8683 module_exit(niu_exit
);