2 * Broadcom BCM7xxx System Port Ethernet MAC driver
4 * Copyright (C) 2014 Broadcom Corporation
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13 #include <linux/init.h>
14 #include <linux/interrupt.h>
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/netdevice.h>
18 #include <linux/etherdevice.h>
19 #include <linux/platform_device.h>
21 #include <linux/of_net.h>
22 #include <linux/of_mdio.h>
23 #include <linux/phy.h>
24 #include <linux/phy_fixed.h>
28 #include "bcmsysport.h"
30 /* I/O accessors register helpers */
31 #define BCM_SYSPORT_IO_MACRO(name, offset) \
32 static inline u32 name##_readl(struct bcm_sysport_priv *priv, u32 off) \
34 u32 reg = __raw_readl(priv->base + offset + off); \
37 static inline void name##_writel(struct bcm_sysport_priv *priv, \
40 __raw_writel(val, priv->base + offset + off); \
43 BCM_SYSPORT_IO_MACRO(intrl2_0, SYS_PORT_INTRL2_0_OFFSET);
44 BCM_SYSPORT_IO_MACRO(intrl2_1
, SYS_PORT_INTRL2_1_OFFSET
);
45 BCM_SYSPORT_IO_MACRO(umac
, SYS_PORT_UMAC_OFFSET
);
46 BCM_SYSPORT_IO_MACRO(tdma
, SYS_PORT_TDMA_OFFSET
);
47 BCM_SYSPORT_IO_MACRO(rdma
, SYS_PORT_RDMA_OFFSET
);
48 BCM_SYSPORT_IO_MACRO(rxchk
, SYS_PORT_RXCHK_OFFSET
);
49 BCM_SYSPORT_IO_MACRO(txchk
, SYS_PORT_TXCHK_OFFSET
);
50 BCM_SYSPORT_IO_MACRO(rbuf
, SYS_PORT_RBUF_OFFSET
);
51 BCM_SYSPORT_IO_MACRO(tbuf
, SYS_PORT_TBUF_OFFSET
);
52 BCM_SYSPORT_IO_MACRO(topctrl
, SYS_PORT_TOPCTRL_OFFSET
);
54 /* L2-interrupt masking/unmasking helpers, does automatic saving of the applied
55 * mask in a software copy to avoid CPU_MASK_STATUS reads in hot-paths.
57 #define BCM_SYSPORT_INTR_L2(which) \
58 static inline void intrl2_##which##_mask_clear(struct bcm_sysport_priv *priv, \
61 intrl2_##which##_writel(priv, mask, INTRL2_CPU_MASK_CLEAR); \
62 priv->irq##which##_mask &= ~(mask); \
64 static inline void intrl2_##which##_mask_set(struct bcm_sysport_priv *priv, \
67 intrl2_## which##_writel(priv, mask, INTRL2_CPU_MASK_SET); \
68 priv->irq##which##_mask |= (mask); \
71 BCM_SYSPORT_INTR_L2(0)
72 BCM_SYSPORT_INTR_L2(1)
74 /* Register accesses to GISB/RBUS registers are expensive (few hundred
75 * nanoseconds), so keep the check for 64-bits explicit here to save
76 * one register write per-packet on 32-bits platforms.
78 static inline void dma_desc_set_addr(struct bcm_sysport_priv
*priv
,
82 #ifdef CONFIG_PHYS_ADDR_T_64BIT
83 __raw_writel(upper_32_bits(addr
) & DESC_ADDR_HI_MASK
,
84 d
+ DESC_ADDR_HI_STATUS_LEN
);
86 __raw_writel(lower_32_bits(addr
), d
+ DESC_ADDR_LO
);
89 static inline void tdma_port_write_desc_addr(struct bcm_sysport_priv
*priv
,
90 struct dma_desc
*desc
,
93 /* Ports are latched, so write upper address first */
94 tdma_writel(priv
, desc
->addr_status_len
, TDMA_WRITE_PORT_HI(port
));
95 tdma_writel(priv
, desc
->addr_lo
, TDMA_WRITE_PORT_LO(port
));
98 /* Ethtool operations */
99 static int bcm_sysport_set_settings(struct net_device
*dev
,
100 struct ethtool_cmd
*cmd
)
102 struct bcm_sysport_priv
*priv
= netdev_priv(dev
);
104 if (!netif_running(dev
))
107 return phy_ethtool_sset(priv
->phydev
, cmd
);
110 static int bcm_sysport_get_settings(struct net_device
*dev
,
111 struct ethtool_cmd
*cmd
)
113 struct bcm_sysport_priv
*priv
= netdev_priv(dev
);
115 if (!netif_running(dev
))
118 return phy_ethtool_gset(priv
->phydev
, cmd
);
121 static int bcm_sysport_set_rx_csum(struct net_device
*dev
,
122 netdev_features_t wanted
)
124 struct bcm_sysport_priv
*priv
= netdev_priv(dev
);
127 priv
->rx_chk_en
= !!(wanted
& NETIF_F_RXCSUM
);
128 reg
= rxchk_readl(priv
, RXCHK_CONTROL
);
134 /* If UniMAC forwards CRC, we need to skip over it to get
135 * a valid CHK bit to be set in the per-packet status word
137 if (priv
->rx_chk_en
&& priv
->crc_fwd
)
138 reg
|= RXCHK_SKIP_FCS
;
140 reg
&= ~RXCHK_SKIP_FCS
;
142 /* If Broadcom tags are enabled (e.g: using a switch), make
143 * sure we tell the RXCHK hardware to expect a 4-bytes Broadcom
144 * tag after the Ethernet MAC Source Address.
146 if (netdev_uses_dsa(dev
))
147 reg
|= RXCHK_BRCM_TAG_EN
;
149 reg
&= ~RXCHK_BRCM_TAG_EN
;
151 rxchk_writel(priv
, reg
, RXCHK_CONTROL
);
156 static int bcm_sysport_set_tx_csum(struct net_device
*dev
,
157 netdev_features_t wanted
)
159 struct bcm_sysport_priv
*priv
= netdev_priv(dev
);
162 /* Hardware transmit checksum requires us to enable the Transmit status
163 * block prepended to the packet contents
165 priv
->tsb_en
= !!(wanted
& (NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
));
166 reg
= tdma_readl(priv
, TDMA_CONTROL
);
171 tdma_writel(priv
, reg
, TDMA_CONTROL
);
176 static int bcm_sysport_set_features(struct net_device
*dev
,
177 netdev_features_t features
)
179 netdev_features_t changed
= features
^ dev
->features
;
180 netdev_features_t wanted
= dev
->wanted_features
;
183 if (changed
& NETIF_F_RXCSUM
)
184 ret
= bcm_sysport_set_rx_csum(dev
, wanted
);
185 if (changed
& (NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
))
186 ret
= bcm_sysport_set_tx_csum(dev
, wanted
);
191 /* Hardware counters must be kept in sync because the order/offset
192 * is important here (order in structure declaration = order in hardware)
194 static const struct bcm_sysport_stats bcm_sysport_gstrings_stats
[] = {
196 STAT_NETDEV(rx_packets
),
197 STAT_NETDEV(tx_packets
),
198 STAT_NETDEV(rx_bytes
),
199 STAT_NETDEV(tx_bytes
),
200 STAT_NETDEV(rx_errors
),
201 STAT_NETDEV(tx_errors
),
202 STAT_NETDEV(rx_dropped
),
203 STAT_NETDEV(tx_dropped
),
204 STAT_NETDEV(multicast
),
205 /* UniMAC RSV counters */
206 STAT_MIB_RX("rx_64_octets", mib
.rx
.pkt_cnt
.cnt_64
),
207 STAT_MIB_RX("rx_65_127_oct", mib
.rx
.pkt_cnt
.cnt_127
),
208 STAT_MIB_RX("rx_128_255_oct", mib
.rx
.pkt_cnt
.cnt_255
),
209 STAT_MIB_RX("rx_256_511_oct", mib
.rx
.pkt_cnt
.cnt_511
),
210 STAT_MIB_RX("rx_512_1023_oct", mib
.rx
.pkt_cnt
.cnt_1023
),
211 STAT_MIB_RX("rx_1024_1518_oct", mib
.rx
.pkt_cnt
.cnt_1518
),
212 STAT_MIB_RX("rx_vlan_1519_1522_oct", mib
.rx
.pkt_cnt
.cnt_mgv
),
213 STAT_MIB_RX("rx_1522_2047_oct", mib
.rx
.pkt_cnt
.cnt_2047
),
214 STAT_MIB_RX("rx_2048_4095_oct", mib
.rx
.pkt_cnt
.cnt_4095
),
215 STAT_MIB_RX("rx_4096_9216_oct", mib
.rx
.pkt_cnt
.cnt_9216
),
216 STAT_MIB_RX("rx_pkts", mib
.rx
.pkt
),
217 STAT_MIB_RX("rx_bytes", mib
.rx
.bytes
),
218 STAT_MIB_RX("rx_multicast", mib
.rx
.mca
),
219 STAT_MIB_RX("rx_broadcast", mib
.rx
.bca
),
220 STAT_MIB_RX("rx_fcs", mib
.rx
.fcs
),
221 STAT_MIB_RX("rx_control", mib
.rx
.cf
),
222 STAT_MIB_RX("rx_pause", mib
.rx
.pf
),
223 STAT_MIB_RX("rx_unknown", mib
.rx
.uo
),
224 STAT_MIB_RX("rx_align", mib
.rx
.aln
),
225 STAT_MIB_RX("rx_outrange", mib
.rx
.flr
),
226 STAT_MIB_RX("rx_code", mib
.rx
.cde
),
227 STAT_MIB_RX("rx_carrier", mib
.rx
.fcr
),
228 STAT_MIB_RX("rx_oversize", mib
.rx
.ovr
),
229 STAT_MIB_RX("rx_jabber", mib
.rx
.jbr
),
230 STAT_MIB_RX("rx_mtu_err", mib
.rx
.mtue
),
231 STAT_MIB_RX("rx_good_pkts", mib
.rx
.pok
),
232 STAT_MIB_RX("rx_unicast", mib
.rx
.uc
),
233 STAT_MIB_RX("rx_ppp", mib
.rx
.ppp
),
234 STAT_MIB_RX("rx_crc", mib
.rx
.rcrc
),
235 /* UniMAC TSV counters */
236 STAT_MIB_TX("tx_64_octets", mib
.tx
.pkt_cnt
.cnt_64
),
237 STAT_MIB_TX("tx_65_127_oct", mib
.tx
.pkt_cnt
.cnt_127
),
238 STAT_MIB_TX("tx_128_255_oct", mib
.tx
.pkt_cnt
.cnt_255
),
239 STAT_MIB_TX("tx_256_511_oct", mib
.tx
.pkt_cnt
.cnt_511
),
240 STAT_MIB_TX("tx_512_1023_oct", mib
.tx
.pkt_cnt
.cnt_1023
),
241 STAT_MIB_TX("tx_1024_1518_oct", mib
.tx
.pkt_cnt
.cnt_1518
),
242 STAT_MIB_TX("tx_vlan_1519_1522_oct", mib
.tx
.pkt_cnt
.cnt_mgv
),
243 STAT_MIB_TX("tx_1522_2047_oct", mib
.tx
.pkt_cnt
.cnt_2047
),
244 STAT_MIB_TX("tx_2048_4095_oct", mib
.tx
.pkt_cnt
.cnt_4095
),
245 STAT_MIB_TX("tx_4096_9216_oct", mib
.tx
.pkt_cnt
.cnt_9216
),
246 STAT_MIB_TX("tx_pkts", mib
.tx
.pkts
),
247 STAT_MIB_TX("tx_multicast", mib
.tx
.mca
),
248 STAT_MIB_TX("tx_broadcast", mib
.tx
.bca
),
249 STAT_MIB_TX("tx_pause", mib
.tx
.pf
),
250 STAT_MIB_TX("tx_control", mib
.tx
.cf
),
251 STAT_MIB_TX("tx_fcs_err", mib
.tx
.fcs
),
252 STAT_MIB_TX("tx_oversize", mib
.tx
.ovr
),
253 STAT_MIB_TX("tx_defer", mib
.tx
.drf
),
254 STAT_MIB_TX("tx_excess_defer", mib
.tx
.edf
),
255 STAT_MIB_TX("tx_single_col", mib
.tx
.scl
),
256 STAT_MIB_TX("tx_multi_col", mib
.tx
.mcl
),
257 STAT_MIB_TX("tx_late_col", mib
.tx
.lcl
),
258 STAT_MIB_TX("tx_excess_col", mib
.tx
.ecl
),
259 STAT_MIB_TX("tx_frags", mib
.tx
.frg
),
260 STAT_MIB_TX("tx_total_col", mib
.tx
.ncl
),
261 STAT_MIB_TX("tx_jabber", mib
.tx
.jbr
),
262 STAT_MIB_TX("tx_bytes", mib
.tx
.bytes
),
263 STAT_MIB_TX("tx_good_pkts", mib
.tx
.pok
),
264 STAT_MIB_TX("tx_unicast", mib
.tx
.uc
),
265 /* UniMAC RUNT counters */
266 STAT_RUNT("rx_runt_pkts", mib
.rx_runt_cnt
),
267 STAT_RUNT("rx_runt_valid_fcs", mib
.rx_runt_fcs
),
268 STAT_RUNT("rx_runt_inval_fcs_align", mib
.rx_runt_fcs_align
),
269 STAT_RUNT("rx_runt_bytes", mib
.rx_runt_bytes
),
270 /* RXCHK misc statistics */
271 STAT_RXCHK("rxchk_bad_csum", mib
.rxchk_bad_csum
, RXCHK_BAD_CSUM_CNTR
),
272 STAT_RXCHK("rxchk_other_pkt_disc", mib
.rxchk_other_pkt_disc
,
273 RXCHK_OTHER_DISC_CNTR
),
274 /* RBUF misc statistics */
275 STAT_RBUF("rbuf_ovflow_cnt", mib
.rbuf_ovflow_cnt
, RBUF_OVFL_DISC_CNTR
),
276 STAT_RBUF("rbuf_err_cnt", mib
.rbuf_err_cnt
, RBUF_ERR_PKT_CNTR
),
277 STAT_MIB_SOFT("alloc_rx_buff_failed", mib
.alloc_rx_buff_failed
),
278 STAT_MIB_SOFT("rx_dma_failed", mib
.rx_dma_failed
),
279 STAT_MIB_SOFT("tx_dma_failed", mib
.tx_dma_failed
),
282 #define BCM_SYSPORT_STATS_LEN ARRAY_SIZE(bcm_sysport_gstrings_stats)
284 static void bcm_sysport_get_drvinfo(struct net_device
*dev
,
285 struct ethtool_drvinfo
*info
)
287 strlcpy(info
->driver
, KBUILD_MODNAME
, sizeof(info
->driver
));
288 strlcpy(info
->version
, "0.1", sizeof(info
->version
));
289 strlcpy(info
->bus_info
, "platform", sizeof(info
->bus_info
));
290 info
->n_stats
= BCM_SYSPORT_STATS_LEN
;
293 static u32
bcm_sysport_get_msglvl(struct net_device
*dev
)
295 struct bcm_sysport_priv
*priv
= netdev_priv(dev
);
297 return priv
->msg_enable
;
300 static void bcm_sysport_set_msglvl(struct net_device
*dev
, u32 enable
)
302 struct bcm_sysport_priv
*priv
= netdev_priv(dev
);
304 priv
->msg_enable
= enable
;
307 static int bcm_sysport_get_sset_count(struct net_device
*dev
, int string_set
)
309 switch (string_set
) {
311 return BCM_SYSPORT_STATS_LEN
;
317 static void bcm_sysport_get_strings(struct net_device
*dev
,
318 u32 stringset
, u8
*data
)
324 for (i
= 0; i
< BCM_SYSPORT_STATS_LEN
; i
++) {
325 memcpy(data
+ i
* ETH_GSTRING_LEN
,
326 bcm_sysport_gstrings_stats
[i
].stat_string
,
335 static void bcm_sysport_update_mib_counters(struct bcm_sysport_priv
*priv
)
339 for (i
= 0; i
< BCM_SYSPORT_STATS_LEN
; i
++) {
340 const struct bcm_sysport_stats
*s
;
345 s
= &bcm_sysport_gstrings_stats
[i
];
347 case BCM_SYSPORT_STAT_NETDEV
:
348 case BCM_SYSPORT_STAT_SOFT
:
350 case BCM_SYSPORT_STAT_MIB_RX
:
351 case BCM_SYSPORT_STAT_MIB_TX
:
352 case BCM_SYSPORT_STAT_RUNT
:
353 if (s
->type
!= BCM_SYSPORT_STAT_MIB_RX
)
354 offset
= UMAC_MIB_STAT_OFFSET
;
355 val
= umac_readl(priv
, UMAC_MIB_START
+ j
+ offset
);
357 case BCM_SYSPORT_STAT_RXCHK
:
358 val
= rxchk_readl(priv
, s
->reg_offset
);
360 rxchk_writel(priv
, 0, s
->reg_offset
);
362 case BCM_SYSPORT_STAT_RBUF
:
363 val
= rbuf_readl(priv
, s
->reg_offset
);
365 rbuf_writel(priv
, 0, s
->reg_offset
);
370 p
= (char *)priv
+ s
->stat_offset
;
374 netif_dbg(priv
, hw
, priv
->netdev
, "updated MIB counters\n");
377 static void bcm_sysport_get_stats(struct net_device
*dev
,
378 struct ethtool_stats
*stats
, u64
*data
)
380 struct bcm_sysport_priv
*priv
= netdev_priv(dev
);
383 if (netif_running(dev
))
384 bcm_sysport_update_mib_counters(priv
);
386 for (i
= 0; i
< BCM_SYSPORT_STATS_LEN
; i
++) {
387 const struct bcm_sysport_stats
*s
;
390 s
= &bcm_sysport_gstrings_stats
[i
];
391 if (s
->type
== BCM_SYSPORT_STAT_NETDEV
)
392 p
= (char *)&dev
->stats
;
400 static void bcm_sysport_get_wol(struct net_device
*dev
,
401 struct ethtool_wolinfo
*wol
)
403 struct bcm_sysport_priv
*priv
= netdev_priv(dev
);
406 wol
->supported
= WAKE_MAGIC
| WAKE_MAGICSECURE
;
407 wol
->wolopts
= priv
->wolopts
;
409 if (!(priv
->wolopts
& WAKE_MAGICSECURE
))
412 /* Return the programmed SecureOn password */
413 reg
= umac_readl(priv
, UMAC_PSW_MS
);
414 put_unaligned_be16(reg
, &wol
->sopass
[0]);
415 reg
= umac_readl(priv
, UMAC_PSW_LS
);
416 put_unaligned_be32(reg
, &wol
->sopass
[2]);
419 static int bcm_sysport_set_wol(struct net_device
*dev
,
420 struct ethtool_wolinfo
*wol
)
422 struct bcm_sysport_priv
*priv
= netdev_priv(dev
);
423 struct device
*kdev
= &priv
->pdev
->dev
;
424 u32 supported
= WAKE_MAGIC
| WAKE_MAGICSECURE
;
426 if (!device_can_wakeup(kdev
))
429 if (wol
->wolopts
& ~supported
)
432 /* Program the SecureOn password */
433 if (wol
->wolopts
& WAKE_MAGICSECURE
) {
434 umac_writel(priv
, get_unaligned_be16(&wol
->sopass
[0]),
436 umac_writel(priv
, get_unaligned_be32(&wol
->sopass
[2]),
440 /* Flag the device and relevant IRQ as wakeup capable */
442 device_set_wakeup_enable(kdev
, 1);
443 if (priv
->wol_irq_disabled
)
444 enable_irq_wake(priv
->wol_irq
);
445 priv
->wol_irq_disabled
= 0;
447 device_set_wakeup_enable(kdev
, 0);
448 /* Avoid unbalanced disable_irq_wake calls */
449 if (!priv
->wol_irq_disabled
)
450 disable_irq_wake(priv
->wol_irq
);
451 priv
->wol_irq_disabled
= 1;
454 priv
->wolopts
= wol
->wolopts
;
459 static int bcm_sysport_get_coalesce(struct net_device
*dev
,
460 struct ethtool_coalesce
*ec
)
462 struct bcm_sysport_priv
*priv
= netdev_priv(dev
);
465 reg
= tdma_readl(priv
, TDMA_DESC_RING_INTR_CONTROL(0));
467 ec
->tx_coalesce_usecs
= (reg
>> RING_TIMEOUT_SHIFT
) * 8192 / 1000;
468 ec
->tx_max_coalesced_frames
= reg
& RING_INTR_THRESH_MASK
;
470 reg
= rdma_readl(priv
, RDMA_MBDONE_INTR
);
472 ec
->rx_coalesce_usecs
= (reg
>> RDMA_TIMEOUT_SHIFT
) * 8192 / 1000;
473 ec
->rx_max_coalesced_frames
= reg
& RDMA_INTR_THRESH_MASK
;
478 static int bcm_sysport_set_coalesce(struct net_device
*dev
,
479 struct ethtool_coalesce
*ec
)
481 struct bcm_sysport_priv
*priv
= netdev_priv(dev
);
485 /* Base system clock is 125Mhz, DMA timeout is this reference clock
486 * divided by 1024, which yield roughly 8.192 us, our maximum value has
487 * to fit in the RING_TIMEOUT_MASK (16 bits).
489 if (ec
->tx_max_coalesced_frames
> RING_INTR_THRESH_MASK
||
490 ec
->tx_coalesce_usecs
> (RING_TIMEOUT_MASK
* 8) + 1 ||
491 ec
->rx_max_coalesced_frames
> RDMA_INTR_THRESH_MASK
||
492 ec
->rx_coalesce_usecs
> (RDMA_TIMEOUT_MASK
* 8) + 1)
495 if ((ec
->tx_coalesce_usecs
== 0 && ec
->tx_max_coalesced_frames
== 0) ||
496 (ec
->rx_coalesce_usecs
== 0 && ec
->rx_max_coalesced_frames
== 0))
499 for (i
= 0; i
< dev
->num_tx_queues
; i
++) {
500 reg
= tdma_readl(priv
, TDMA_DESC_RING_INTR_CONTROL(i
));
501 reg
&= ~(RING_INTR_THRESH_MASK
|
502 RING_TIMEOUT_MASK
<< RING_TIMEOUT_SHIFT
);
503 reg
|= ec
->tx_max_coalesced_frames
;
504 reg
|= DIV_ROUND_UP(ec
->tx_coalesce_usecs
* 1000, 8192) <<
506 tdma_writel(priv
, reg
, TDMA_DESC_RING_INTR_CONTROL(i
));
509 reg
= rdma_readl(priv
, RDMA_MBDONE_INTR
);
510 reg
&= ~(RDMA_INTR_THRESH_MASK
|
511 RDMA_TIMEOUT_MASK
<< RDMA_TIMEOUT_SHIFT
);
512 reg
|= ec
->rx_max_coalesced_frames
;
513 reg
|= DIV_ROUND_UP(ec
->rx_coalesce_usecs
* 1000, 8192) <<
515 rdma_writel(priv
, reg
, RDMA_MBDONE_INTR
);
520 static void bcm_sysport_free_cb(struct bcm_sysport_cb
*cb
)
522 dev_kfree_skb_any(cb
->skb
);
524 dma_unmap_addr_set(cb
, dma_addr
, 0);
527 static struct sk_buff
*bcm_sysport_rx_refill(struct bcm_sysport_priv
*priv
,
528 struct bcm_sysport_cb
*cb
)
530 struct device
*kdev
= &priv
->pdev
->dev
;
531 struct net_device
*ndev
= priv
->netdev
;
532 struct sk_buff
*skb
, *rx_skb
;
535 /* Allocate a new SKB for a new packet */
536 skb
= netdev_alloc_skb(priv
->netdev
, RX_BUF_LENGTH
);
538 priv
->mib
.alloc_rx_buff_failed
++;
539 netif_err(priv
, rx_err
, ndev
, "SKB alloc failed\n");
543 mapping
= dma_map_single(kdev
, skb
->data
,
544 RX_BUF_LENGTH
, DMA_FROM_DEVICE
);
545 if (dma_mapping_error(kdev
, mapping
)) {
546 priv
->mib
.rx_dma_failed
++;
547 dev_kfree_skb_any(skb
);
548 netif_err(priv
, rx_err
, ndev
, "DMA mapping failure\n");
552 /* Grab the current SKB on the ring */
555 dma_unmap_single(kdev
, dma_unmap_addr(cb
, dma_addr
),
556 RX_BUF_LENGTH
, DMA_FROM_DEVICE
);
558 /* Put the new SKB on the ring */
560 dma_unmap_addr_set(cb
, dma_addr
, mapping
);
561 dma_desc_set_addr(priv
, cb
->bd_addr
, mapping
);
563 netif_dbg(priv
, rx_status
, ndev
, "RX refill\n");
565 /* Return the current SKB to the caller */
569 static int bcm_sysport_alloc_rx_bufs(struct bcm_sysport_priv
*priv
)
571 struct bcm_sysport_cb
*cb
;
575 for (i
= 0; i
< priv
->num_rx_bds
; i
++) {
576 cb
= &priv
->rx_cbs
[i
];
577 skb
= bcm_sysport_rx_refill(priv
, cb
);
587 /* Poll the hardware for up to budget packets to process */
588 static unsigned int bcm_sysport_desc_rx(struct bcm_sysport_priv
*priv
,
591 struct net_device
*ndev
= priv
->netdev
;
592 unsigned int processed
= 0, to_process
;
593 struct bcm_sysport_cb
*cb
;
595 unsigned int p_index
;
599 /* Determine how much we should process since last call */
600 p_index
= rdma_readl(priv
, RDMA_PROD_INDEX
);
601 p_index
&= RDMA_PROD_INDEX_MASK
;
603 if (p_index
< priv
->rx_c_index
)
604 to_process
= (RDMA_CONS_INDEX_MASK
+ 1) -
605 priv
->rx_c_index
+ p_index
;
607 to_process
= p_index
- priv
->rx_c_index
;
609 netif_dbg(priv
, rx_status
, ndev
,
610 "p_index=%d rx_c_index=%d to_process=%d\n",
611 p_index
, priv
->rx_c_index
, to_process
);
613 while ((processed
< to_process
) && (processed
< budget
)) {
614 cb
= &priv
->rx_cbs
[priv
->rx_read_ptr
];
615 skb
= bcm_sysport_rx_refill(priv
, cb
);
618 /* We do not have a backing SKB, so we do not a corresponding
619 * DMA mapping for this incoming packet since
620 * bcm_sysport_rx_refill always either has both skb and mapping
623 if (unlikely(!skb
)) {
624 netif_err(priv
, rx_err
, ndev
, "out of memory!\n");
625 ndev
->stats
.rx_dropped
++;
626 ndev
->stats
.rx_errors
++;
630 /* Extract the Receive Status Block prepended */
631 rsb
= (struct bcm_rsb
*)skb
->data
;
632 len
= (rsb
->rx_status_len
>> DESC_LEN_SHIFT
) & DESC_LEN_MASK
;
633 status
= (rsb
->rx_status_len
>> DESC_STATUS_SHIFT
) &
636 netif_dbg(priv
, rx_status
, ndev
,
637 "p=%d, c=%d, rd_ptr=%d, len=%d, flag=0x%04x\n",
638 p_index
, priv
->rx_c_index
, priv
->rx_read_ptr
,
641 if (unlikely(len
> RX_BUF_LENGTH
)) {
642 netif_err(priv
, rx_status
, ndev
, "oversized packet\n");
643 ndev
->stats
.rx_length_errors
++;
644 ndev
->stats
.rx_errors
++;
645 dev_kfree_skb_any(skb
);
649 if (unlikely(!(status
& DESC_EOP
) || !(status
& DESC_SOP
))) {
650 netif_err(priv
, rx_status
, ndev
, "fragmented packet!\n");
651 ndev
->stats
.rx_dropped
++;
652 ndev
->stats
.rx_errors
++;
653 dev_kfree_skb_any(skb
);
657 if (unlikely(status
& (RX_STATUS_ERR
| RX_STATUS_OVFLOW
))) {
658 netif_err(priv
, rx_err
, ndev
, "error packet\n");
659 if (status
& RX_STATUS_OVFLOW
)
660 ndev
->stats
.rx_over_errors
++;
661 ndev
->stats
.rx_dropped
++;
662 ndev
->stats
.rx_errors
++;
663 dev_kfree_skb_any(skb
);
669 /* Hardware validated our checksum */
670 if (likely(status
& DESC_L4_CSUM
))
671 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
673 /* Hardware pre-pends packets with 2bytes before Ethernet
674 * header plus we have the Receive Status Block, strip off all
675 * of this from the SKB.
677 skb_pull(skb
, sizeof(*rsb
) + 2);
678 len
-= (sizeof(*rsb
) + 2);
680 /* UniMAC may forward CRC */
682 skb_trim(skb
, len
- ETH_FCS_LEN
);
686 skb
->protocol
= eth_type_trans(skb
, ndev
);
687 ndev
->stats
.rx_packets
++;
688 ndev
->stats
.rx_bytes
+= len
;
690 napi_gro_receive(&priv
->napi
, skb
);
695 if (priv
->rx_read_ptr
== priv
->num_rx_bds
)
696 priv
->rx_read_ptr
= 0;
702 static void bcm_sysport_tx_reclaim_one(struct bcm_sysport_priv
*priv
,
703 struct bcm_sysport_cb
*cb
,
704 unsigned int *bytes_compl
,
705 unsigned int *pkts_compl
)
707 struct device
*kdev
= &priv
->pdev
->dev
;
708 struct net_device
*ndev
= priv
->netdev
;
711 ndev
->stats
.tx_bytes
+= cb
->skb
->len
;
712 *bytes_compl
+= cb
->skb
->len
;
713 dma_unmap_single(kdev
, dma_unmap_addr(cb
, dma_addr
),
714 dma_unmap_len(cb
, dma_len
),
716 ndev
->stats
.tx_packets
++;
718 bcm_sysport_free_cb(cb
);
720 } else if (dma_unmap_addr(cb
, dma_addr
)) {
721 ndev
->stats
.tx_bytes
+= dma_unmap_len(cb
, dma_len
);
722 dma_unmap_page(kdev
, dma_unmap_addr(cb
, dma_addr
),
723 dma_unmap_len(cb
, dma_len
), DMA_TO_DEVICE
);
724 dma_unmap_addr_set(cb
, dma_addr
, 0);
728 /* Reclaim queued SKBs for transmission completion, lockless version */
729 static unsigned int __bcm_sysport_tx_reclaim(struct bcm_sysport_priv
*priv
,
730 struct bcm_sysport_tx_ring
*ring
)
732 struct net_device
*ndev
= priv
->netdev
;
733 unsigned int c_index
, last_c_index
, last_tx_cn
, num_tx_cbs
;
734 unsigned int pkts_compl
= 0, bytes_compl
= 0;
735 struct bcm_sysport_cb
*cb
;
736 struct netdev_queue
*txq
;
739 txq
= netdev_get_tx_queue(ndev
, ring
->index
);
741 /* Compute how many descriptors have been processed since last call */
742 hw_ind
= tdma_readl(priv
, TDMA_DESC_RING_PROD_CONS_INDEX(ring
->index
));
743 c_index
= (hw_ind
>> RING_CONS_INDEX_SHIFT
) & RING_CONS_INDEX_MASK
;
744 ring
->p_index
= (hw_ind
& RING_PROD_INDEX_MASK
);
746 last_c_index
= ring
->c_index
;
747 num_tx_cbs
= ring
->size
;
749 c_index
&= (num_tx_cbs
- 1);
751 if (c_index
>= last_c_index
)
752 last_tx_cn
= c_index
- last_c_index
;
754 last_tx_cn
= num_tx_cbs
- last_c_index
+ c_index
;
756 netif_dbg(priv
, tx_done
, ndev
,
757 "ring=%d c_index=%d last_tx_cn=%d last_c_index=%d\n",
758 ring
->index
, c_index
, last_tx_cn
, last_c_index
);
760 while (last_tx_cn
-- > 0) {
761 cb
= ring
->cbs
+ last_c_index
;
762 bcm_sysport_tx_reclaim_one(priv
, cb
, &bytes_compl
, &pkts_compl
);
766 last_c_index
&= (num_tx_cbs
- 1);
769 ring
->c_index
= c_index
;
771 if (netif_tx_queue_stopped(txq
) && pkts_compl
)
772 netif_tx_wake_queue(txq
);
774 netif_dbg(priv
, tx_done
, ndev
,
775 "ring=%d c_index=%d pkts_compl=%d, bytes_compl=%d\n",
776 ring
->index
, ring
->c_index
, pkts_compl
, bytes_compl
);
781 /* Locked version of the per-ring TX reclaim routine */
782 static unsigned int bcm_sysport_tx_reclaim(struct bcm_sysport_priv
*priv
,
783 struct bcm_sysport_tx_ring
*ring
)
785 unsigned int released
;
788 spin_lock_irqsave(&ring
->lock
, flags
);
789 released
= __bcm_sysport_tx_reclaim(priv
, ring
);
790 spin_unlock_irqrestore(&ring
->lock
, flags
);
795 static int bcm_sysport_tx_poll(struct napi_struct
*napi
, int budget
)
797 struct bcm_sysport_tx_ring
*ring
=
798 container_of(napi
, struct bcm_sysport_tx_ring
, napi
);
799 unsigned int work_done
= 0;
801 work_done
= bcm_sysport_tx_reclaim(ring
->priv
, ring
);
803 if (work_done
== 0) {
805 /* re-enable TX interrupt */
806 intrl2_1_mask_clear(ring
->priv
, BIT(ring
->index
));
814 static void bcm_sysport_tx_reclaim_all(struct bcm_sysport_priv
*priv
)
818 for (q
= 0; q
< priv
->netdev
->num_tx_queues
; q
++)
819 bcm_sysport_tx_reclaim(priv
, &priv
->tx_rings
[q
]);
822 static int bcm_sysport_poll(struct napi_struct
*napi
, int budget
)
824 struct bcm_sysport_priv
*priv
=
825 container_of(napi
, struct bcm_sysport_priv
, napi
);
826 unsigned int work_done
= 0;
828 work_done
= bcm_sysport_desc_rx(priv
, budget
);
830 priv
->rx_c_index
+= work_done
;
831 priv
->rx_c_index
&= RDMA_CONS_INDEX_MASK
;
832 rdma_writel(priv
, priv
->rx_c_index
, RDMA_CONS_INDEX
);
834 if (work_done
< budget
) {
836 /* re-enable RX interrupts */
837 intrl2_0_mask_clear(priv
, INTRL2_0_RDMA_MBDONE
);
843 static void bcm_sysport_resume_from_wol(struct bcm_sysport_priv
*priv
)
847 /* Stop monitoring MPD interrupt */
848 intrl2_0_mask_set(priv
, INTRL2_0_MPD
);
850 /* Clear the MagicPacket detection logic */
851 reg
= umac_readl(priv
, UMAC_MPD_CTRL
);
853 umac_writel(priv
, reg
, UMAC_MPD_CTRL
);
855 netif_dbg(priv
, wol
, priv
->netdev
, "resumed from WOL\n");
858 /* RX and misc interrupt routine */
859 static irqreturn_t
bcm_sysport_rx_isr(int irq
, void *dev_id
)
861 struct net_device
*dev
= dev_id
;
862 struct bcm_sysport_priv
*priv
= netdev_priv(dev
);
864 priv
->irq0_stat
= intrl2_0_readl(priv
, INTRL2_CPU_STATUS
) &
865 ~intrl2_0_readl(priv
, INTRL2_CPU_MASK_STATUS
);
866 intrl2_0_writel(priv
, priv
->irq0_stat
, INTRL2_CPU_CLEAR
);
868 if (unlikely(priv
->irq0_stat
== 0)) {
869 netdev_warn(priv
->netdev
, "spurious RX interrupt\n");
873 if (priv
->irq0_stat
& INTRL2_0_RDMA_MBDONE
) {
874 if (likely(napi_schedule_prep(&priv
->napi
))) {
875 /* disable RX interrupts */
876 intrl2_0_mask_set(priv
, INTRL2_0_RDMA_MBDONE
);
877 __napi_schedule(&priv
->napi
);
881 /* TX ring is full, perform a full reclaim since we do not know
882 * which one would trigger this interrupt
884 if (priv
->irq0_stat
& INTRL2_0_TX_RING_FULL
)
885 bcm_sysport_tx_reclaim_all(priv
);
887 if (priv
->irq0_stat
& INTRL2_0_MPD
) {
888 netdev_info(priv
->netdev
, "Wake-on-LAN interrupt!\n");
889 bcm_sysport_resume_from_wol(priv
);
895 /* TX interrupt service routine */
896 static irqreturn_t
bcm_sysport_tx_isr(int irq
, void *dev_id
)
898 struct net_device
*dev
= dev_id
;
899 struct bcm_sysport_priv
*priv
= netdev_priv(dev
);
900 struct bcm_sysport_tx_ring
*txr
;
903 priv
->irq1_stat
= intrl2_1_readl(priv
, INTRL2_CPU_STATUS
) &
904 ~intrl2_1_readl(priv
, INTRL2_CPU_MASK_STATUS
);
905 intrl2_1_writel(priv
, 0xffffffff, INTRL2_CPU_CLEAR
);
907 if (unlikely(priv
->irq1_stat
== 0)) {
908 netdev_warn(priv
->netdev
, "spurious TX interrupt\n");
912 for (ring
= 0; ring
< dev
->num_tx_queues
; ring
++) {
913 if (!(priv
->irq1_stat
& BIT(ring
)))
916 txr
= &priv
->tx_rings
[ring
];
918 if (likely(napi_schedule_prep(&txr
->napi
))) {
919 intrl2_1_mask_set(priv
, BIT(ring
));
920 __napi_schedule(&txr
->napi
);
927 static irqreturn_t
bcm_sysport_wol_isr(int irq
, void *dev_id
)
929 struct bcm_sysport_priv
*priv
= dev_id
;
931 pm_wakeup_event(&priv
->pdev
->dev
, 0);
936 static struct sk_buff
*bcm_sysport_insert_tsb(struct sk_buff
*skb
,
937 struct net_device
*dev
)
939 struct sk_buff
*nskb
;
946 /* Re-allocate SKB if needed */
947 if (unlikely(skb_headroom(skb
) < sizeof(*tsb
))) {
948 nskb
= skb_realloc_headroom(skb
, sizeof(*tsb
));
951 dev
->stats
.tx_errors
++;
952 dev
->stats
.tx_dropped
++;
958 tsb
= (struct bcm_tsb
*)skb_push(skb
, sizeof(*tsb
));
959 /* Zero-out TSB by default */
960 memset(tsb
, 0, sizeof(*tsb
));
962 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
963 ip_ver
= htons(skb
->protocol
);
966 ip_proto
= ip_hdr(skb
)->protocol
;
969 ip_proto
= ipv6_hdr(skb
)->nexthdr
;
975 /* Get the checksum offset and the L4 (transport) offset */
976 csum_start
= skb_checksum_start_offset(skb
) - sizeof(*tsb
);
977 csum_info
= (csum_start
+ skb
->csum_offset
) & L4_CSUM_PTR_MASK
;
978 csum_info
|= (csum_start
<< L4_PTR_SHIFT
);
980 if (ip_proto
== IPPROTO_TCP
|| ip_proto
== IPPROTO_UDP
) {
981 csum_info
|= L4_LENGTH_VALID
;
982 if (ip_proto
== IPPROTO_UDP
&& ip_ver
== ETH_P_IP
)
988 tsb
->l4_ptr_dest_map
= csum_info
;
994 static netdev_tx_t
bcm_sysport_xmit(struct sk_buff
*skb
,
995 struct net_device
*dev
)
997 struct bcm_sysport_priv
*priv
= netdev_priv(dev
);
998 struct device
*kdev
= &priv
->pdev
->dev
;
999 struct bcm_sysport_tx_ring
*ring
;
1000 struct bcm_sysport_cb
*cb
;
1001 struct netdev_queue
*txq
;
1002 struct dma_desc
*desc
;
1003 unsigned int skb_len
;
1004 unsigned long flags
;
1010 queue
= skb_get_queue_mapping(skb
);
1011 txq
= netdev_get_tx_queue(dev
, queue
);
1012 ring
= &priv
->tx_rings
[queue
];
1014 /* lock against tx reclaim in BH context and TX ring full interrupt */
1015 spin_lock_irqsave(&ring
->lock
, flags
);
1016 if (unlikely(ring
->desc_count
== 0)) {
1017 netif_tx_stop_queue(txq
);
1018 netdev_err(dev
, "queue %d awake and ring full!\n", queue
);
1019 ret
= NETDEV_TX_BUSY
;
1023 /* Insert TSB and checksum infos */
1025 skb
= bcm_sysport_insert_tsb(skb
, dev
);
1032 /* The Ethernet switch we are interfaced with needs packets to be at
1033 * least 64 bytes (including FCS) otherwise they will be discarded when
1034 * they enter the switch port logic. When Broadcom tags are enabled, we
1035 * need to make sure that packets are at least 68 bytes
1036 * (including FCS and tag) because the length verification is done after
1037 * the Broadcom tag is stripped off the ingress packet.
1039 if (skb_padto(skb
, ETH_ZLEN
+ ENET_BRCM_TAG_LEN
)) {
1044 skb_len
= skb
->len
< ETH_ZLEN
+ ENET_BRCM_TAG_LEN
?
1045 ETH_ZLEN
+ ENET_BRCM_TAG_LEN
: skb
->len
;
1047 mapping
= dma_map_single(kdev
, skb
->data
, skb_len
, DMA_TO_DEVICE
);
1048 if (dma_mapping_error(kdev
, mapping
)) {
1049 priv
->mib
.tx_dma_failed
++;
1050 netif_err(priv
, tx_err
, dev
, "DMA map failed at %p (len=%d)\n",
1051 skb
->data
, skb_len
);
1056 /* Remember the SKB for future freeing */
1057 cb
= &ring
->cbs
[ring
->curr_desc
];
1059 dma_unmap_addr_set(cb
, dma_addr
, mapping
);
1060 dma_unmap_len_set(cb
, dma_len
, skb_len
);
1062 /* Fetch a descriptor entry from our pool */
1063 desc
= ring
->desc_cpu
;
1065 desc
->addr_lo
= lower_32_bits(mapping
);
1066 len_status
= upper_32_bits(mapping
) & DESC_ADDR_HI_MASK
;
1067 len_status
|= (skb_len
<< DESC_LEN_SHIFT
);
1068 len_status
|= (DESC_SOP
| DESC_EOP
| TX_STATUS_APP_CRC
) <<
1070 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
1071 len_status
|= (DESC_L4_CSUM
<< DESC_STATUS_SHIFT
);
1074 if (ring
->curr_desc
== ring
->size
)
1075 ring
->curr_desc
= 0;
1078 /* Ensure write completion of the descriptor status/length
1079 * in DRAM before the System Port WRITE_PORT register latches
1083 desc
->addr_status_len
= len_status
;
1086 /* Write this descriptor address to the RING write port */
1087 tdma_port_write_desc_addr(priv
, desc
, ring
->index
);
1089 /* Check ring space and update SW control flow */
1090 if (ring
->desc_count
== 0)
1091 netif_tx_stop_queue(txq
);
1093 netif_dbg(priv
, tx_queued
, dev
, "ring=%d desc_count=%d, curr_desc=%d\n",
1094 ring
->index
, ring
->desc_count
, ring
->curr_desc
);
1098 spin_unlock_irqrestore(&ring
->lock
, flags
);
1102 static void bcm_sysport_tx_timeout(struct net_device
*dev
)
1104 netdev_warn(dev
, "transmit timeout!\n");
1106 dev
->trans_start
= jiffies
;
1107 dev
->stats
.tx_errors
++;
1109 netif_tx_wake_all_queues(dev
);
1112 /* phylib adjust link callback */
1113 static void bcm_sysport_adj_link(struct net_device
*dev
)
1115 struct bcm_sysport_priv
*priv
= netdev_priv(dev
);
1116 struct phy_device
*phydev
= priv
->phydev
;
1117 unsigned int changed
= 0;
1118 u32 cmd_bits
= 0, reg
;
1120 if (priv
->old_link
!= phydev
->link
) {
1122 priv
->old_link
= phydev
->link
;
1125 if (priv
->old_duplex
!= phydev
->duplex
) {
1127 priv
->old_duplex
= phydev
->duplex
;
1130 switch (phydev
->speed
) {
1132 cmd_bits
= CMD_SPEED_2500
;
1135 cmd_bits
= CMD_SPEED_1000
;
1138 cmd_bits
= CMD_SPEED_100
;
1141 cmd_bits
= CMD_SPEED_10
;
1146 cmd_bits
<<= CMD_SPEED_SHIFT
;
1148 if (phydev
->duplex
== DUPLEX_HALF
)
1149 cmd_bits
|= CMD_HD_EN
;
1151 if (priv
->old_pause
!= phydev
->pause
) {
1153 priv
->old_pause
= phydev
->pause
;
1157 cmd_bits
|= CMD_RX_PAUSE_IGNORE
| CMD_TX_PAUSE_IGNORE
;
1163 reg
= umac_readl(priv
, UMAC_CMD
);
1164 reg
&= ~((CMD_SPEED_MASK
<< CMD_SPEED_SHIFT
) |
1165 CMD_HD_EN
| CMD_RX_PAUSE_IGNORE
|
1166 CMD_TX_PAUSE_IGNORE
);
1168 umac_writel(priv
, reg
, UMAC_CMD
);
1171 phy_print_status(priv
->phydev
);
1174 static int bcm_sysport_init_tx_ring(struct bcm_sysport_priv
*priv
,
1177 struct bcm_sysport_tx_ring
*ring
= &priv
->tx_rings
[index
];
1178 struct device
*kdev
= &priv
->pdev
->dev
;
1183 /* Simple descriptors partitioning for now */
1186 /* We just need one DMA descriptor which is DMA-able, since writing to
1187 * the port will allocate a new descriptor in its internal linked-list
1189 p
= dma_zalloc_coherent(kdev
, sizeof(struct dma_desc
), &ring
->desc_dma
,
1192 netif_err(priv
, hw
, priv
->netdev
, "DMA alloc failed\n");
1196 ring
->cbs
= kcalloc(size
, sizeof(struct bcm_sysport_cb
), GFP_KERNEL
);
1198 netif_err(priv
, hw
, priv
->netdev
, "CB allocation failed\n");
1202 /* Initialize SW view of the ring */
1203 spin_lock_init(&ring
->lock
);
1205 netif_napi_add(priv
->netdev
, &ring
->napi
, bcm_sysport_tx_poll
, 64);
1206 ring
->index
= index
;
1208 ring
->alloc_size
= ring
->size
;
1210 ring
->desc_count
= ring
->size
;
1211 ring
->curr_desc
= 0;
1213 /* Initialize HW ring */
1214 tdma_writel(priv
, RING_EN
, TDMA_DESC_RING_HEAD_TAIL_PTR(index
));
1215 tdma_writel(priv
, 0, TDMA_DESC_RING_COUNT(index
));
1216 tdma_writel(priv
, 1, TDMA_DESC_RING_INTR_CONTROL(index
));
1217 tdma_writel(priv
, 0, TDMA_DESC_RING_PROD_CONS_INDEX(index
));
1218 tdma_writel(priv
, RING_IGNORE_STATUS
, TDMA_DESC_RING_MAPPING(index
));
1219 tdma_writel(priv
, 0, TDMA_DESC_RING_PCP_DEI_VID(index
));
1221 /* Program the number of descriptors as MAX_THRESHOLD and half of
1222 * its size for the hysteresis trigger
1224 tdma_writel(priv
, ring
->size
|
1225 1 << RING_HYST_THRESH_SHIFT
,
1226 TDMA_DESC_RING_MAX_HYST(index
));
1228 /* Enable the ring queue in the arbiter */
1229 reg
= tdma_readl(priv
, TDMA_TIER1_ARB_0_QUEUE_EN
);
1230 reg
|= (1 << index
);
1231 tdma_writel(priv
, reg
, TDMA_TIER1_ARB_0_QUEUE_EN
);
1233 napi_enable(&ring
->napi
);
1235 netif_dbg(priv
, hw
, priv
->netdev
,
1236 "TDMA cfg, size=%d, desc_cpu=%p\n",
1237 ring
->size
, ring
->desc_cpu
);
1242 static void bcm_sysport_fini_tx_ring(struct bcm_sysport_priv
*priv
,
1245 struct bcm_sysport_tx_ring
*ring
= &priv
->tx_rings
[index
];
1246 struct device
*kdev
= &priv
->pdev
->dev
;
1249 /* Caller should stop the TDMA engine */
1250 reg
= tdma_readl(priv
, TDMA_STATUS
);
1251 if (!(reg
& TDMA_DISABLED
))
1252 netdev_warn(priv
->netdev
, "TDMA not stopped!\n");
1254 /* ring->cbs is the last part in bcm_sysport_init_tx_ring which could
1255 * fail, so by checking this pointer we know whether the TX ring was
1256 * fully initialized or not.
1261 napi_disable(&ring
->napi
);
1262 netif_napi_del(&ring
->napi
);
1264 bcm_sysport_tx_reclaim(priv
, ring
);
1269 if (ring
->desc_dma
) {
1270 dma_free_coherent(kdev
, sizeof(struct dma_desc
),
1271 ring
->desc_cpu
, ring
->desc_dma
);
1275 ring
->alloc_size
= 0;
1277 netif_dbg(priv
, hw
, priv
->netdev
, "TDMA fini done\n");
1281 static inline int rdma_enable_set(struct bcm_sysport_priv
*priv
,
1282 unsigned int enable
)
1284 unsigned int timeout
= 1000;
1287 reg
= rdma_readl(priv
, RDMA_CONTROL
);
1292 rdma_writel(priv
, reg
, RDMA_CONTROL
);
1294 /* Poll for RMDA disabling completion */
1296 reg
= rdma_readl(priv
, RDMA_STATUS
);
1297 if (!!(reg
& RDMA_DISABLED
) == !enable
)
1299 usleep_range(1000, 2000);
1300 } while (timeout
-- > 0);
1302 netdev_err(priv
->netdev
, "timeout waiting for RDMA to finish\n");
1308 static inline int tdma_enable_set(struct bcm_sysport_priv
*priv
,
1309 unsigned int enable
)
1311 unsigned int timeout
= 1000;
1314 reg
= tdma_readl(priv
, TDMA_CONTROL
);
1319 tdma_writel(priv
, reg
, TDMA_CONTROL
);
1321 /* Poll for TMDA disabling completion */
1323 reg
= tdma_readl(priv
, TDMA_STATUS
);
1324 if (!!(reg
& TDMA_DISABLED
) == !enable
)
1327 usleep_range(1000, 2000);
1328 } while (timeout
-- > 0);
1330 netdev_err(priv
->netdev
, "timeout waiting for TDMA to finish\n");
1335 static int bcm_sysport_init_rx_ring(struct bcm_sysport_priv
*priv
)
1337 struct bcm_sysport_cb
*cb
;
1342 /* Initialize SW view of the RX ring */
1343 priv
->num_rx_bds
= NUM_RX_DESC
;
1344 priv
->rx_bds
= priv
->base
+ SYS_PORT_RDMA_OFFSET
;
1345 priv
->rx_c_index
= 0;
1346 priv
->rx_read_ptr
= 0;
1347 priv
->rx_cbs
= kcalloc(priv
->num_rx_bds
, sizeof(struct bcm_sysport_cb
),
1349 if (!priv
->rx_cbs
) {
1350 netif_err(priv
, hw
, priv
->netdev
, "CB allocation failed\n");
1354 for (i
= 0; i
< priv
->num_rx_bds
; i
++) {
1355 cb
= priv
->rx_cbs
+ i
;
1356 cb
->bd_addr
= priv
->rx_bds
+ i
* DESC_SIZE
;
1359 ret
= bcm_sysport_alloc_rx_bufs(priv
);
1361 netif_err(priv
, hw
, priv
->netdev
, "SKB allocation failed\n");
1365 /* Initialize HW, ensure RDMA is disabled */
1366 reg
= rdma_readl(priv
, RDMA_STATUS
);
1367 if (!(reg
& RDMA_DISABLED
))
1368 rdma_enable_set(priv
, 0);
1370 rdma_writel(priv
, 0, RDMA_WRITE_PTR_LO
);
1371 rdma_writel(priv
, 0, RDMA_WRITE_PTR_HI
);
1372 rdma_writel(priv
, 0, RDMA_PROD_INDEX
);
1373 rdma_writel(priv
, 0, RDMA_CONS_INDEX
);
1374 rdma_writel(priv
, priv
->num_rx_bds
<< RDMA_RING_SIZE_SHIFT
|
1375 RX_BUF_LENGTH
, RDMA_RING_BUF_SIZE
);
1376 /* Operate the queue in ring mode */
1377 rdma_writel(priv
, 0, RDMA_START_ADDR_HI
);
1378 rdma_writel(priv
, 0, RDMA_START_ADDR_LO
);
1379 rdma_writel(priv
, 0, RDMA_END_ADDR_HI
);
1380 rdma_writel(priv
, NUM_HW_RX_DESC_WORDS
- 1, RDMA_END_ADDR_LO
);
1382 rdma_writel(priv
, 1, RDMA_MBDONE_INTR
);
1384 netif_dbg(priv
, hw
, priv
->netdev
,
1385 "RDMA cfg, num_rx_bds=%d, rx_bds=%p\n",
1386 priv
->num_rx_bds
, priv
->rx_bds
);
1391 static void bcm_sysport_fini_rx_ring(struct bcm_sysport_priv
*priv
)
1393 struct bcm_sysport_cb
*cb
;
1397 /* Caller should ensure RDMA is disabled */
1398 reg
= rdma_readl(priv
, RDMA_STATUS
);
1399 if (!(reg
& RDMA_DISABLED
))
1400 netdev_warn(priv
->netdev
, "RDMA not stopped!\n");
1402 for (i
= 0; i
< priv
->num_rx_bds
; i
++) {
1403 cb
= &priv
->rx_cbs
[i
];
1404 if (dma_unmap_addr(cb
, dma_addr
))
1405 dma_unmap_single(&priv
->pdev
->dev
,
1406 dma_unmap_addr(cb
, dma_addr
),
1407 RX_BUF_LENGTH
, DMA_FROM_DEVICE
);
1408 bcm_sysport_free_cb(cb
);
1411 kfree(priv
->rx_cbs
);
1412 priv
->rx_cbs
= NULL
;
1414 netif_dbg(priv
, hw
, priv
->netdev
, "RDMA fini done\n");
1417 static void bcm_sysport_set_rx_mode(struct net_device
*dev
)
1419 struct bcm_sysport_priv
*priv
= netdev_priv(dev
);
1422 reg
= umac_readl(priv
, UMAC_CMD
);
1423 if (dev
->flags
& IFF_PROMISC
)
1426 reg
&= ~CMD_PROMISC
;
1427 umac_writel(priv
, reg
, UMAC_CMD
);
1429 /* No support for ALLMULTI */
1430 if (dev
->flags
& IFF_ALLMULTI
)
1434 static inline void umac_enable_set(struct bcm_sysport_priv
*priv
,
1435 u32 mask
, unsigned int enable
)
1439 reg
= umac_readl(priv
, UMAC_CMD
);
1444 umac_writel(priv
, reg
, UMAC_CMD
);
1446 /* UniMAC stops on a packet boundary, wait for a full-sized packet
1447 * to be processed (1 msec).
1450 usleep_range(1000, 2000);
1453 static inline void umac_reset(struct bcm_sysport_priv
*priv
)
1457 reg
= umac_readl(priv
, UMAC_CMD
);
1458 reg
|= CMD_SW_RESET
;
1459 umac_writel(priv
, reg
, UMAC_CMD
);
1461 reg
= umac_readl(priv
, UMAC_CMD
);
1462 reg
&= ~CMD_SW_RESET
;
1463 umac_writel(priv
, reg
, UMAC_CMD
);
1466 static void umac_set_hw_addr(struct bcm_sysport_priv
*priv
,
1467 unsigned char *addr
)
1469 umac_writel(priv
, (addr
[0] << 24) | (addr
[1] << 16) |
1470 (addr
[2] << 8) | addr
[3], UMAC_MAC0
);
1471 umac_writel(priv
, (addr
[4] << 8) | addr
[5], UMAC_MAC1
);
1474 static void topctrl_flush(struct bcm_sysport_priv
*priv
)
1476 topctrl_writel(priv
, RX_FLUSH
, RX_FLUSH_CNTL
);
1477 topctrl_writel(priv
, TX_FLUSH
, TX_FLUSH_CNTL
);
1479 topctrl_writel(priv
, 0, RX_FLUSH_CNTL
);
1480 topctrl_writel(priv
, 0, TX_FLUSH_CNTL
);
1483 static int bcm_sysport_change_mac(struct net_device
*dev
, void *p
)
1485 struct bcm_sysport_priv
*priv
= netdev_priv(dev
);
1486 struct sockaddr
*addr
= p
;
1488 if (!is_valid_ether_addr(addr
->sa_data
))
1491 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
1493 /* interface is disabled, changes to MAC will be reflected on next
1496 if (!netif_running(dev
))
1499 umac_set_hw_addr(priv
, dev
->dev_addr
);
1504 static void bcm_sysport_netif_start(struct net_device
*dev
)
1506 struct bcm_sysport_priv
*priv
= netdev_priv(dev
);
1509 napi_enable(&priv
->napi
);
1511 /* Enable RX interrupt and TX ring full interrupt */
1512 intrl2_0_mask_clear(priv
, INTRL2_0_RDMA_MBDONE
| INTRL2_0_TX_RING_FULL
);
1514 phy_start(priv
->phydev
);
1516 /* Enable TX interrupts for the 32 TXQs */
1517 intrl2_1_mask_clear(priv
, 0xffffffff);
1519 /* Last call before we start the real business */
1520 netif_tx_start_all_queues(dev
);
1523 static void rbuf_init(struct bcm_sysport_priv
*priv
)
1527 reg
= rbuf_readl(priv
, RBUF_CONTROL
);
1528 reg
|= RBUF_4B_ALGN
| RBUF_RSB_EN
;
1529 rbuf_writel(priv
, reg
, RBUF_CONTROL
);
1532 static int bcm_sysport_open(struct net_device
*dev
)
1534 struct bcm_sysport_priv
*priv
= netdev_priv(dev
);
1541 /* Flush TX and RX FIFOs at TOPCTRL level */
1542 topctrl_flush(priv
);
1544 /* Disable the UniMAC RX/TX */
1545 umac_enable_set(priv
, CMD_RX_EN
| CMD_TX_EN
, 0);
1547 /* Enable RBUF 2bytes alignment and Receive Status Block */
1550 /* Set maximum frame length */
1551 umac_writel(priv
, UMAC_MAX_MTU_SIZE
, UMAC_MAX_FRAME_LEN
);
1553 /* Set MAC address */
1554 umac_set_hw_addr(priv
, dev
->dev_addr
);
1556 /* Read CRC forward */
1557 priv
->crc_fwd
= !!(umac_readl(priv
, UMAC_CMD
) & CMD_CRC_FWD
);
1559 priv
->phydev
= of_phy_connect(dev
, priv
->phy_dn
, bcm_sysport_adj_link
,
1560 0, priv
->phy_interface
);
1561 if (!priv
->phydev
) {
1562 netdev_err(dev
, "could not attach to PHY\n");
1566 /* Reset house keeping link status */
1567 priv
->old_duplex
= -1;
1568 priv
->old_link
= -1;
1569 priv
->old_pause
= -1;
1571 /* mask all interrupts and request them */
1572 intrl2_0_writel(priv
, 0xffffffff, INTRL2_CPU_MASK_SET
);
1573 intrl2_0_writel(priv
, 0xffffffff, INTRL2_CPU_CLEAR
);
1574 intrl2_0_writel(priv
, 0, INTRL2_CPU_MASK_CLEAR
);
1575 intrl2_1_writel(priv
, 0xffffffff, INTRL2_CPU_MASK_SET
);
1576 intrl2_1_writel(priv
, 0xffffffff, INTRL2_CPU_CLEAR
);
1577 intrl2_1_writel(priv
, 0, INTRL2_CPU_MASK_CLEAR
);
1579 ret
= request_irq(priv
->irq0
, bcm_sysport_rx_isr
, 0, dev
->name
, dev
);
1581 netdev_err(dev
, "failed to request RX interrupt\n");
1582 goto out_phy_disconnect
;
1585 ret
= request_irq(priv
->irq1
, bcm_sysport_tx_isr
, 0, dev
->name
, dev
);
1587 netdev_err(dev
, "failed to request TX interrupt\n");
1591 /* Initialize both hardware and software ring */
1592 for (i
= 0; i
< dev
->num_tx_queues
; i
++) {
1593 ret
= bcm_sysport_init_tx_ring(priv
, i
);
1595 netdev_err(dev
, "failed to initialize TX ring %d\n",
1597 goto out_free_tx_ring
;
1601 /* Initialize linked-list */
1602 tdma_writel(priv
, TDMA_LL_RAM_INIT_BUSY
, TDMA_STATUS
);
1604 /* Initialize RX ring */
1605 ret
= bcm_sysport_init_rx_ring(priv
);
1607 netdev_err(dev
, "failed to initialize RX ring\n");
1608 goto out_free_rx_ring
;
1612 ret
= rdma_enable_set(priv
, 1);
1614 goto out_free_rx_ring
;
1617 ret
= tdma_enable_set(priv
, 1);
1619 goto out_clear_rx_int
;
1621 /* Turn on UniMAC TX/RX */
1622 umac_enable_set(priv
, CMD_RX_EN
| CMD_TX_EN
, 1);
1624 bcm_sysport_netif_start(dev
);
1629 intrl2_0_mask_set(priv
, INTRL2_0_RDMA_MBDONE
| INTRL2_0_TX_RING_FULL
);
1631 bcm_sysport_fini_rx_ring(priv
);
1633 for (i
= 0; i
< dev
->num_tx_queues
; i
++)
1634 bcm_sysport_fini_tx_ring(priv
, i
);
1635 free_irq(priv
->irq1
, dev
);
1637 free_irq(priv
->irq0
, dev
);
1639 phy_disconnect(priv
->phydev
);
1643 static void bcm_sysport_netif_stop(struct net_device
*dev
)
1645 struct bcm_sysport_priv
*priv
= netdev_priv(dev
);
1647 /* stop all software from updating hardware */
1648 netif_tx_stop_all_queues(dev
);
1649 napi_disable(&priv
->napi
);
1650 phy_stop(priv
->phydev
);
1652 /* mask all interrupts */
1653 intrl2_0_mask_set(priv
, 0xffffffff);
1654 intrl2_0_writel(priv
, 0xffffffff, INTRL2_CPU_CLEAR
);
1655 intrl2_1_mask_set(priv
, 0xffffffff);
1656 intrl2_1_writel(priv
, 0xffffffff, INTRL2_CPU_CLEAR
);
1659 static int bcm_sysport_stop(struct net_device
*dev
)
1661 struct bcm_sysport_priv
*priv
= netdev_priv(dev
);
1665 bcm_sysport_netif_stop(dev
);
1667 /* Disable UniMAC RX */
1668 umac_enable_set(priv
, CMD_RX_EN
, 0);
1670 ret
= tdma_enable_set(priv
, 0);
1672 netdev_err(dev
, "timeout disabling RDMA\n");
1676 /* Wait for a maximum packet size to be drained */
1677 usleep_range(2000, 3000);
1679 ret
= rdma_enable_set(priv
, 0);
1681 netdev_err(dev
, "timeout disabling TDMA\n");
1685 /* Disable UniMAC TX */
1686 umac_enable_set(priv
, CMD_TX_EN
, 0);
1688 /* Free RX/TX rings SW structures */
1689 for (i
= 0; i
< dev
->num_tx_queues
; i
++)
1690 bcm_sysport_fini_tx_ring(priv
, i
);
1691 bcm_sysport_fini_rx_ring(priv
);
1693 free_irq(priv
->irq0
, dev
);
1694 free_irq(priv
->irq1
, dev
);
1696 /* Disconnect from PHY */
1697 phy_disconnect(priv
->phydev
);
1702 static struct ethtool_ops bcm_sysport_ethtool_ops
= {
1703 .get_settings
= bcm_sysport_get_settings
,
1704 .set_settings
= bcm_sysport_set_settings
,
1705 .get_drvinfo
= bcm_sysport_get_drvinfo
,
1706 .get_msglevel
= bcm_sysport_get_msglvl
,
1707 .set_msglevel
= bcm_sysport_set_msglvl
,
1708 .get_link
= ethtool_op_get_link
,
1709 .get_strings
= bcm_sysport_get_strings
,
1710 .get_ethtool_stats
= bcm_sysport_get_stats
,
1711 .get_sset_count
= bcm_sysport_get_sset_count
,
1712 .get_wol
= bcm_sysport_get_wol
,
1713 .set_wol
= bcm_sysport_set_wol
,
1714 .get_coalesce
= bcm_sysport_get_coalesce
,
1715 .set_coalesce
= bcm_sysport_set_coalesce
,
1718 static const struct net_device_ops bcm_sysport_netdev_ops
= {
1719 .ndo_start_xmit
= bcm_sysport_xmit
,
1720 .ndo_tx_timeout
= bcm_sysport_tx_timeout
,
1721 .ndo_open
= bcm_sysport_open
,
1722 .ndo_stop
= bcm_sysport_stop
,
1723 .ndo_set_features
= bcm_sysport_set_features
,
1724 .ndo_set_rx_mode
= bcm_sysport_set_rx_mode
,
1725 .ndo_set_mac_address
= bcm_sysport_change_mac
,
1728 #define REV_FMT "v%2x.%02x"
1730 static int bcm_sysport_probe(struct platform_device
*pdev
)
1732 struct bcm_sysport_priv
*priv
;
1733 struct device_node
*dn
;
1734 struct net_device
*dev
;
1735 const void *macaddr
;
1740 dn
= pdev
->dev
.of_node
;
1741 r
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1743 /* Read the Transmit/Receive Queue properties */
1744 if (of_property_read_u32(dn
, "systemport,num-txq", &txq
))
1745 txq
= TDMA_NUM_RINGS
;
1746 if (of_property_read_u32(dn
, "systemport,num-rxq", &rxq
))
1749 dev
= alloc_etherdev_mqs(sizeof(*priv
), txq
, rxq
);
1753 /* Initialize private members */
1754 priv
= netdev_priv(dev
);
1756 priv
->irq0
= platform_get_irq(pdev
, 0);
1757 priv
->irq1
= platform_get_irq(pdev
, 1);
1758 priv
->wol_irq
= platform_get_irq(pdev
, 2);
1759 if (priv
->irq0
<= 0 || priv
->irq1
<= 0) {
1760 dev_err(&pdev
->dev
, "invalid interrupts\n");
1765 priv
->base
= devm_ioremap_resource(&pdev
->dev
, r
);
1766 if (IS_ERR(priv
->base
)) {
1767 ret
= PTR_ERR(priv
->base
);
1774 priv
->phy_interface
= of_get_phy_mode(dn
);
1775 /* Default to GMII interface mode */
1776 if (priv
->phy_interface
< 0)
1777 priv
->phy_interface
= PHY_INTERFACE_MODE_GMII
;
1779 /* In the case of a fixed PHY, the DT node associated
1780 * to the PHY is the Ethernet MAC DT node.
1782 if (of_phy_is_fixed_link(dn
)) {
1783 ret
= of_phy_register_fixed_link(dn
);
1785 dev_err(&pdev
->dev
, "failed to register fixed PHY\n");
1792 /* Initialize netdevice members */
1793 macaddr
= of_get_mac_address(dn
);
1794 if (!macaddr
|| !is_valid_ether_addr(macaddr
)) {
1795 dev_warn(&pdev
->dev
, "using random Ethernet MAC\n");
1796 random_ether_addr(dev
->dev_addr
);
1798 ether_addr_copy(dev
->dev_addr
, macaddr
);
1801 SET_NETDEV_DEV(dev
, &pdev
->dev
);
1802 dev_set_drvdata(&pdev
->dev
, dev
);
1803 dev
->ethtool_ops
= &bcm_sysport_ethtool_ops
;
1804 dev
->netdev_ops
= &bcm_sysport_netdev_ops
;
1805 netif_napi_add(dev
, &priv
->napi
, bcm_sysport_poll
, 64);
1807 /* HW supported features, none enabled by default */
1808 dev
->hw_features
|= NETIF_F_RXCSUM
| NETIF_F_HIGHDMA
|
1809 NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
;
1811 /* Request the WOL interrupt and advertise suspend if available */
1812 priv
->wol_irq_disabled
= 1;
1813 ret
= devm_request_irq(&pdev
->dev
, priv
->wol_irq
,
1814 bcm_sysport_wol_isr
, 0, dev
->name
, priv
);
1816 device_set_wakeup_capable(&pdev
->dev
, 1);
1818 /* Set the needed headroom once and for all */
1819 BUILD_BUG_ON(sizeof(struct bcm_tsb
) != 8);
1820 dev
->needed_headroom
+= sizeof(struct bcm_tsb
);
1822 /* libphy will adjust the link state accordingly */
1823 netif_carrier_off(dev
);
1825 ret
= register_netdev(dev
);
1827 dev_err(&pdev
->dev
, "failed to register net_device\n");
1831 priv
->rev
= topctrl_readl(priv
, REV_CNTL
) & REV_MASK
;
1832 dev_info(&pdev
->dev
,
1833 "Broadcom SYSTEMPORT" REV_FMT
1834 " at 0x%p (irqs: %d, %d, TXQs: %d, RXQs: %d)\n",
1835 (priv
->rev
>> 8) & 0xff, priv
->rev
& 0xff,
1836 priv
->base
, priv
->irq0
, priv
->irq1
, txq
, rxq
);
1844 static int bcm_sysport_remove(struct platform_device
*pdev
)
1846 struct net_device
*dev
= dev_get_drvdata(&pdev
->dev
);
1848 /* Not much to do, ndo_close has been called
1849 * and we use managed allocations
1851 unregister_netdev(dev
);
1853 dev_set_drvdata(&pdev
->dev
, NULL
);
1858 #ifdef CONFIG_PM_SLEEP
1859 static int bcm_sysport_suspend_to_wol(struct bcm_sysport_priv
*priv
)
1861 struct net_device
*ndev
= priv
->netdev
;
1862 unsigned int timeout
= 1000;
1865 /* Password has already been programmed */
1866 reg
= umac_readl(priv
, UMAC_MPD_CTRL
);
1869 if (priv
->wolopts
& WAKE_MAGICSECURE
)
1871 umac_writel(priv
, reg
, UMAC_MPD_CTRL
);
1873 /* Make sure RBUF entered WoL mode as result */
1875 reg
= rbuf_readl(priv
, RBUF_STATUS
);
1876 if (reg
& RBUF_WOL_MODE
)
1880 } while (timeout
-- > 0);
1882 /* Do not leave the UniMAC RBUF matching only MPD packets */
1884 reg
= umac_readl(priv
, UMAC_MPD_CTRL
);
1886 umac_writel(priv
, reg
, UMAC_MPD_CTRL
);
1887 netif_err(priv
, wol
, ndev
, "failed to enter WOL mode\n");
1891 /* UniMAC receive needs to be turned on */
1892 umac_enable_set(priv
, CMD_RX_EN
, 1);
1894 /* Enable the interrupt wake-up source */
1895 intrl2_0_mask_clear(priv
, INTRL2_0_MPD
);
1897 netif_dbg(priv
, wol
, ndev
, "entered WOL mode\n");
1902 static int bcm_sysport_suspend(struct device
*d
)
1904 struct net_device
*dev
= dev_get_drvdata(d
);
1905 struct bcm_sysport_priv
*priv
= netdev_priv(dev
);
1910 if (!netif_running(dev
))
1913 bcm_sysport_netif_stop(dev
);
1915 phy_suspend(priv
->phydev
);
1917 netif_device_detach(dev
);
1919 /* Disable UniMAC RX */
1920 umac_enable_set(priv
, CMD_RX_EN
, 0);
1922 ret
= rdma_enable_set(priv
, 0);
1924 netdev_err(dev
, "RDMA timeout!\n");
1928 /* Disable RXCHK if enabled */
1929 if (priv
->rx_chk_en
) {
1930 reg
= rxchk_readl(priv
, RXCHK_CONTROL
);
1932 rxchk_writel(priv
, reg
, RXCHK_CONTROL
);
1937 topctrl_writel(priv
, RX_FLUSH
, RX_FLUSH_CNTL
);
1939 ret
= tdma_enable_set(priv
, 0);
1941 netdev_err(dev
, "TDMA timeout!\n");
1945 /* Wait for a packet boundary */
1946 usleep_range(2000, 3000);
1948 umac_enable_set(priv
, CMD_TX_EN
, 0);
1950 topctrl_writel(priv
, TX_FLUSH
, TX_FLUSH_CNTL
);
1952 /* Free RX/TX rings SW structures */
1953 for (i
= 0; i
< dev
->num_tx_queues
; i
++)
1954 bcm_sysport_fini_tx_ring(priv
, i
);
1955 bcm_sysport_fini_rx_ring(priv
);
1957 /* Get prepared for Wake-on-LAN */
1958 if (device_may_wakeup(d
) && priv
->wolopts
)
1959 ret
= bcm_sysport_suspend_to_wol(priv
);
1964 static int bcm_sysport_resume(struct device
*d
)
1966 struct net_device
*dev
= dev_get_drvdata(d
);
1967 struct bcm_sysport_priv
*priv
= netdev_priv(dev
);
1972 if (!netif_running(dev
))
1977 /* We may have been suspended and never received a WOL event that
1978 * would turn off MPD detection, take care of that now
1980 bcm_sysport_resume_from_wol(priv
);
1982 /* Initialize both hardware and software ring */
1983 for (i
= 0; i
< dev
->num_tx_queues
; i
++) {
1984 ret
= bcm_sysport_init_tx_ring(priv
, i
);
1986 netdev_err(dev
, "failed to initialize TX ring %d\n",
1988 goto out_free_tx_rings
;
1992 /* Initialize linked-list */
1993 tdma_writel(priv
, TDMA_LL_RAM_INIT_BUSY
, TDMA_STATUS
);
1995 /* Initialize RX ring */
1996 ret
= bcm_sysport_init_rx_ring(priv
);
1998 netdev_err(dev
, "failed to initialize RX ring\n");
1999 goto out_free_rx_ring
;
2002 netif_device_attach(dev
);
2004 /* RX pipe enable */
2005 topctrl_writel(priv
, 0, RX_FLUSH_CNTL
);
2007 ret
= rdma_enable_set(priv
, 1);
2009 netdev_err(dev
, "failed to enable RDMA\n");
2010 goto out_free_rx_ring
;
2014 if (priv
->rx_chk_en
) {
2015 reg
= rxchk_readl(priv
, RXCHK_CONTROL
);
2017 rxchk_writel(priv
, reg
, RXCHK_CONTROL
);
2022 /* Set maximum frame length */
2023 umac_writel(priv
, UMAC_MAX_MTU_SIZE
, UMAC_MAX_FRAME_LEN
);
2025 /* Set MAC address */
2026 umac_set_hw_addr(priv
, dev
->dev_addr
);
2028 umac_enable_set(priv
, CMD_RX_EN
, 1);
2030 /* TX pipe enable */
2031 topctrl_writel(priv
, 0, TX_FLUSH_CNTL
);
2033 umac_enable_set(priv
, CMD_TX_EN
, 1);
2035 ret
= tdma_enable_set(priv
, 1);
2037 netdev_err(dev
, "TDMA timeout!\n");
2038 goto out_free_rx_ring
;
2041 phy_resume(priv
->phydev
);
2043 bcm_sysport_netif_start(dev
);
2048 bcm_sysport_fini_rx_ring(priv
);
2050 for (i
= 0; i
< dev
->num_tx_queues
; i
++)
2051 bcm_sysport_fini_tx_ring(priv
, i
);
2056 static SIMPLE_DEV_PM_OPS(bcm_sysport_pm_ops
,
2057 bcm_sysport_suspend
, bcm_sysport_resume
);
2059 static const struct of_device_id bcm_sysport_of_match
[] = {
2060 { .compatible
= "brcm,systemport-v1.00" },
2061 { .compatible
= "brcm,systemport" },
2065 static struct platform_driver bcm_sysport_driver
= {
2066 .probe
= bcm_sysport_probe
,
2067 .remove
= bcm_sysport_remove
,
2069 .name
= "brcm-systemport",
2070 .of_match_table
= bcm_sysport_of_match
,
2071 .pm
= &bcm_sysport_pm_ops
,
2074 module_platform_driver(bcm_sysport_driver
);
2076 MODULE_AUTHOR("Broadcom Corporation");
2077 MODULE_DESCRIPTION("Broadcom System Port Ethernet MAC driver");
2078 MODULE_ALIAS("platform:brcm-systemport");
2079 MODULE_LICENSE("GPL");