1 /*******************************************************************************
2 This is the driver for the ST MAC 10/100/1000 on-chip Ethernet controllers.
3 ST Ethernet IPs are built around a Synopsys IP Core.
5 Copyright (C) 2007-2009 STMicroelectronics Ltd
7 This program is free software; you can redistribute it and/or modify it
8 under the terms and conditions of the GNU General Public License,
9 version 2, as published by the Free Software Foundation.
11 This program is distributed in the hope it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
20 The full GNU General Public License is included in this distribution in
21 the file called "COPYING".
23 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
25 Documentation available at:
26 http://www.stlinux.com
28 https://bugzilla.stlinux.com/
29 *******************************************************************************/
31 #include <linux/module.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/interrupt.h>
35 #include <linux/etherdevice.h>
36 #include <linux/platform_device.h>
38 #include <linux/tcp.h>
39 #include <linux/skbuff.h>
40 #include <linux/ethtool.h>
41 #include <linux/if_ether.h>
42 #include <linux/crc32.h>
43 #include <linux/mii.h>
44 #include <linux/phy.h>
46 #include <linux/if_vlan.h>
47 #include <linux/dma-mapping.h>
48 #include <linux/slab.h>
49 #include <linux/prefetch.h>
51 #ifdef CONFIG_STMMAC_DEBUG_FS
52 #include <linux/debugfs.h>
53 #include <linux/seq_file.h>
56 #define STMMAC_RESOURCE_NAME "stmmaceth"
59 /*#define STMMAC_DEBUG*/
61 #define DBG(nlevel, klevel, fmt, args...) \
62 ((void)(netif_msg_##nlevel(priv) && \
63 printk(KERN_##klevel fmt, ## args)))
65 #define DBG(nlevel, klevel, fmt, args...) do { } while (0)
68 #undef STMMAC_RX_DEBUG
69 /*#define STMMAC_RX_DEBUG*/
70 #ifdef STMMAC_RX_DEBUG
71 #define RX_DBG(fmt, args...) printk(fmt, ## args)
73 #define RX_DBG(fmt, args...) do { } while (0)
76 #undef STMMAC_XMIT_DEBUG
77 /*#define STMMAC_XMIT_DEBUG*/
78 #ifdef STMMAC_TX_DEBUG
79 #define TX_DBG(fmt, args...) printk(fmt, ## args)
81 #define TX_DBG(fmt, args...) do { } while (0)
84 #define STMMAC_ALIGN(x) L1_CACHE_ALIGN(x)
85 #define JUMBO_LEN 9000
87 /* Module parameters */
88 #define TX_TIMEO 5000 /* default 5 seconds */
89 static int watchdog
= TX_TIMEO
;
90 module_param(watchdog
, int, S_IRUGO
| S_IWUSR
);
91 MODULE_PARM_DESC(watchdog
, "Transmit timeout in milliseconds");
93 static int debug
= -1; /* -1: default, 0: no output, 16: all */
94 module_param(debug
, int, S_IRUGO
| S_IWUSR
);
95 MODULE_PARM_DESC(debug
, "Message Level (0: no output, 16: all)");
97 static int phyaddr
= -1;
98 module_param(phyaddr
, int, S_IRUGO
);
99 MODULE_PARM_DESC(phyaddr
, "Physical device address");
101 #define DMA_TX_SIZE 256
102 static int dma_txsize
= DMA_TX_SIZE
;
103 module_param(dma_txsize
, int, S_IRUGO
| S_IWUSR
);
104 MODULE_PARM_DESC(dma_txsize
, "Number of descriptors in the TX list");
106 #define DMA_RX_SIZE 256
107 static int dma_rxsize
= DMA_RX_SIZE
;
108 module_param(dma_rxsize
, int, S_IRUGO
| S_IWUSR
);
109 MODULE_PARM_DESC(dma_rxsize
, "Number of descriptors in the RX list");
111 static int flow_ctrl
= FLOW_OFF
;
112 module_param(flow_ctrl
, int, S_IRUGO
| S_IWUSR
);
113 MODULE_PARM_DESC(flow_ctrl
, "Flow control ability [on/off]");
115 static int pause
= PAUSE_TIME
;
116 module_param(pause
, int, S_IRUGO
| S_IWUSR
);
117 MODULE_PARM_DESC(pause
, "Flow Control Pause Time");
119 #define TC_DEFAULT 64
120 static int tc
= TC_DEFAULT
;
121 module_param(tc
, int, S_IRUGO
| S_IWUSR
);
122 MODULE_PARM_DESC(tc
, "DMA threshold control value");
124 /* Pay attention to tune this parameter; take care of both
125 * hardware capability and network stabitily/performance impact.
126 * Many tests showed that ~4ms latency seems to be good enough. */
127 #ifdef CONFIG_STMMAC_TIMER
128 #define DEFAULT_PERIODIC_RATE 256
129 static int tmrate
= DEFAULT_PERIODIC_RATE
;
130 module_param(tmrate
, int, S_IRUGO
| S_IWUSR
);
131 MODULE_PARM_DESC(tmrate
, "External timer freq. (default: 256Hz)");
134 #define DMA_BUFFER_SIZE BUF_SIZE_2KiB
135 static int buf_sz
= DMA_BUFFER_SIZE
;
136 module_param(buf_sz
, int, S_IRUGO
| S_IWUSR
);
137 MODULE_PARM_DESC(buf_sz
, "DMA buffer size");
139 static const u32 default_msg_level
= (NETIF_MSG_DRV
| NETIF_MSG_PROBE
|
140 NETIF_MSG_LINK
| NETIF_MSG_IFUP
|
141 NETIF_MSG_IFDOWN
| NETIF_MSG_TIMER
);
143 static irqreturn_t
stmmac_interrupt(int irq
, void *dev_id
);
146 * stmmac_verify_args - verify the driver parameters.
147 * Description: it verifies if some wrong parameter is passed to the driver.
148 * Note that wrong parameters are replaced with the default values.
150 static void stmmac_verify_args(void)
152 if (unlikely(watchdog
< 0))
154 if (unlikely(dma_rxsize
< 0))
155 dma_rxsize
= DMA_RX_SIZE
;
156 if (unlikely(dma_txsize
< 0))
157 dma_txsize
= DMA_TX_SIZE
;
158 if (unlikely((buf_sz
< DMA_BUFFER_SIZE
) || (buf_sz
> BUF_SIZE_16KiB
)))
159 buf_sz
= DMA_BUFFER_SIZE
;
160 if (unlikely(flow_ctrl
> 1))
161 flow_ctrl
= FLOW_AUTO
;
162 else if (likely(flow_ctrl
< 0))
163 flow_ctrl
= FLOW_OFF
;
164 if (unlikely((pause
< 0) || (pause
> 0xffff)))
168 #if defined(STMMAC_XMIT_DEBUG) || defined(STMMAC_RX_DEBUG)
169 static void print_pkt(unsigned char *buf
, int len
)
172 pr_info("len = %d byte, buf addr: 0x%p", len
, buf
);
173 for (j
= 0; j
< len
; j
++) {
175 pr_info("\n %03x:", j
);
176 pr_info(" %02x", buf
[j
]);
182 /* minimum number of free TX descriptors required to wake up TX process */
183 #define STMMAC_TX_THRESH(x) (x->dma_tx_size/4)
185 static inline u32
stmmac_tx_avail(struct stmmac_priv
*priv
)
187 return priv
->dirty_tx
+ priv
->dma_tx_size
- priv
->cur_tx
- 1;
190 /* On some ST platforms, some HW system configuraton registers have to be
191 * set according to the link speed negotiated.
193 static inline void stmmac_hw_fix_mac_speed(struct stmmac_priv
*priv
)
195 struct phy_device
*phydev
= priv
->phydev
;
197 if (likely(priv
->plat
->fix_mac_speed
))
198 priv
->plat
->fix_mac_speed(priv
->plat
->bsp_priv
,
204 * @dev: net device structure
205 * Description: it adjusts the link parameters.
207 static void stmmac_adjust_link(struct net_device
*dev
)
209 struct stmmac_priv
*priv
= netdev_priv(dev
);
210 struct phy_device
*phydev
= priv
->phydev
;
213 unsigned int fc
= priv
->flow_ctrl
, pause_time
= priv
->pause
;
218 DBG(probe
, DEBUG
, "stmmac_adjust_link: called. address %d link %d\n",
219 phydev
->addr
, phydev
->link
);
221 spin_lock_irqsave(&priv
->lock
, flags
);
223 u32 ctrl
= readl(priv
->ioaddr
+ MAC_CTRL_REG
);
225 /* Now we make sure that we can be in full duplex mode.
226 * If not, we operate in half-duplex mode. */
227 if (phydev
->duplex
!= priv
->oldduplex
) {
229 if (!(phydev
->duplex
))
230 ctrl
&= ~priv
->hw
->link
.duplex
;
232 ctrl
|= priv
->hw
->link
.duplex
;
233 priv
->oldduplex
= phydev
->duplex
;
235 /* Flow Control operation */
237 priv
->hw
->mac
->flow_ctrl(priv
->ioaddr
, phydev
->duplex
,
240 if (phydev
->speed
!= priv
->speed
) {
242 switch (phydev
->speed
) {
244 if (likely(priv
->plat
->has_gmac
))
245 ctrl
&= ~priv
->hw
->link
.port
;
246 stmmac_hw_fix_mac_speed(priv
);
250 if (priv
->plat
->has_gmac
) {
251 ctrl
|= priv
->hw
->link
.port
;
252 if (phydev
->speed
== SPEED_100
) {
253 ctrl
|= priv
->hw
->link
.speed
;
255 ctrl
&= ~(priv
->hw
->link
.speed
);
258 ctrl
&= ~priv
->hw
->link
.port
;
260 stmmac_hw_fix_mac_speed(priv
);
263 if (netif_msg_link(priv
))
264 pr_warning("%s: Speed (%d) is not 10"
265 " or 100!\n", dev
->name
, phydev
->speed
);
269 priv
->speed
= phydev
->speed
;
272 writel(ctrl
, priv
->ioaddr
+ MAC_CTRL_REG
);
274 if (!priv
->oldlink
) {
278 } else if (priv
->oldlink
) {
282 priv
->oldduplex
= -1;
285 if (new_state
&& netif_msg_link(priv
))
286 phy_print_status(phydev
);
288 spin_unlock_irqrestore(&priv
->lock
, flags
);
290 DBG(probe
, DEBUG
, "stmmac_adjust_link: exiting\n");
294 * stmmac_init_phy - PHY initialization
295 * @dev: net device structure
296 * Description: it initializes the driver's PHY state, and attaches the PHY
301 static int stmmac_init_phy(struct net_device
*dev
)
303 struct stmmac_priv
*priv
= netdev_priv(dev
);
304 struct phy_device
*phydev
;
305 char phy_id
[MII_BUS_ID_SIZE
+ 3];
306 char bus_id
[MII_BUS_ID_SIZE
];
310 priv
->oldduplex
= -1;
312 snprintf(bus_id
, MII_BUS_ID_SIZE
, "%x", priv
->plat
->bus_id
);
313 snprintf(phy_id
, MII_BUS_ID_SIZE
+ 3, PHY_ID_FMT
, bus_id
,
314 priv
->plat
->phy_addr
);
315 pr_debug("stmmac_init_phy: trying to attach to %s\n", phy_id
);
317 phydev
= phy_connect(dev
, phy_id
, &stmmac_adjust_link
, 0,
318 priv
->plat
->interface
);
320 if (IS_ERR(phydev
)) {
321 pr_err("%s: Could not attach to PHY\n", dev
->name
);
322 return PTR_ERR(phydev
);
326 * Broken HW is sometimes missing the pull-up resistor on the
327 * MDIO line, which results in reads to non-existent devices returning
328 * 0 rather than 0xffff. Catch this here and treat 0 as a non-existent
330 * Note: phydev->phy_id is the result of reading the UID PHY registers.
332 if (phydev
->phy_id
== 0) {
333 phy_disconnect(phydev
);
336 pr_debug("stmmac_init_phy: %s: attached to PHY (UID 0x%x)"
337 " Link = %d\n", dev
->name
, phydev
->phy_id
, phydev
->link
);
339 priv
->phydev
= phydev
;
344 static inline void stmmac_enable_mac(void __iomem
*ioaddr
)
346 u32 value
= readl(ioaddr
+ MAC_CTRL_REG
);
348 value
|= MAC_RNABLE_RX
| MAC_ENABLE_TX
;
349 writel(value
, ioaddr
+ MAC_CTRL_REG
);
352 static inline void stmmac_disable_mac(void __iomem
*ioaddr
)
354 u32 value
= readl(ioaddr
+ MAC_CTRL_REG
);
356 value
&= ~(MAC_ENABLE_TX
| MAC_RNABLE_RX
);
357 writel(value
, ioaddr
+ MAC_CTRL_REG
);
362 * @p: pointer to the ring.
363 * @size: size of the ring.
364 * Description: display all the descriptors within the ring.
366 static void display_ring(struct dma_desc
*p
, int size
)
374 for (i
= 0; i
< size
; i
++) {
375 struct tmp_s
*x
= (struct tmp_s
*)(p
+ i
);
376 pr_info("\t%d [0x%x]: DES0=0x%x DES1=0x%x BUF1=0x%x BUF2=0x%x",
377 i
, (unsigned int)virt_to_phys(&p
[i
]),
378 (unsigned int)(x
->a
), (unsigned int)((x
->a
) >> 32),
385 * init_dma_desc_rings - init the RX/TX descriptor rings
386 * @dev: net device structure
387 * Description: this function initializes the DMA RX/TX descriptors
388 * and allocates the socket buffers.
390 static void init_dma_desc_rings(struct net_device
*dev
)
393 struct stmmac_priv
*priv
= netdev_priv(dev
);
395 unsigned int txsize
= priv
->dma_tx_size
;
396 unsigned int rxsize
= priv
->dma_rx_size
;
397 unsigned int bfsize
= priv
->dma_buf_sz
;
398 int buff2_needed
= 0, dis_ic
= 0;
400 /* Set the Buffer size according to the MTU;
401 * indeed, in case of jumbo we need to bump-up the buffer sizes.
403 if (unlikely(dev
->mtu
>= BUF_SIZE_8KiB
))
404 bfsize
= BUF_SIZE_16KiB
;
405 else if (unlikely(dev
->mtu
>= BUF_SIZE_4KiB
))
406 bfsize
= BUF_SIZE_8KiB
;
407 else if (unlikely(dev
->mtu
>= BUF_SIZE_2KiB
))
408 bfsize
= BUF_SIZE_4KiB
;
409 else if (unlikely(dev
->mtu
>= DMA_BUFFER_SIZE
))
410 bfsize
= BUF_SIZE_2KiB
;
412 bfsize
= DMA_BUFFER_SIZE
;
414 #ifdef CONFIG_STMMAC_TIMER
415 /* Disable interrupts on completion for the reception if timer is on */
416 if (likely(priv
->tm
->enable
))
419 /* If the MTU exceeds 8k so use the second buffer in the chain */
420 if (bfsize
>= BUF_SIZE_8KiB
)
423 DBG(probe
, INFO
, "stmmac: txsize %d, rxsize %d, bfsize %d\n",
424 txsize
, rxsize
, bfsize
);
426 priv
->rx_skbuff_dma
= kmalloc(rxsize
* sizeof(dma_addr_t
), GFP_KERNEL
);
428 kmalloc(sizeof(struct sk_buff
*) * rxsize
, GFP_KERNEL
);
430 (struct dma_desc
*)dma_alloc_coherent(priv
->device
,
432 sizeof(struct dma_desc
),
435 priv
->tx_skbuff
= kmalloc(sizeof(struct sk_buff
*) * txsize
,
438 (struct dma_desc
*)dma_alloc_coherent(priv
->device
,
440 sizeof(struct dma_desc
),
444 if ((priv
->dma_rx
== NULL
) || (priv
->dma_tx
== NULL
)) {
445 pr_err("%s:ERROR allocating the DMA Tx/Rx desc\n", __func__
);
449 DBG(probe
, INFO
, "stmmac (%s) DMA desc rings: virt addr (Rx %p, "
450 "Tx %p)\n\tDMA phy addr (Rx 0x%08x, Tx 0x%08x)\n",
451 dev
->name
, priv
->dma_rx
, priv
->dma_tx
,
452 (unsigned int)priv
->dma_rx_phy
, (unsigned int)priv
->dma_tx_phy
);
454 /* RX INITIALIZATION */
455 DBG(probe
, INFO
, "stmmac: SKB addresses:\n"
456 "skb\t\tskb data\tdma data\n");
458 for (i
= 0; i
< rxsize
; i
++) {
459 struct dma_desc
*p
= priv
->dma_rx
+ i
;
461 skb
= netdev_alloc_skb_ip_align(dev
, bfsize
);
462 if (unlikely(skb
== NULL
)) {
463 pr_err("%s: Rx init fails; skb is NULL\n", __func__
);
466 priv
->rx_skbuff
[i
] = skb
;
467 priv
->rx_skbuff_dma
[i
] = dma_map_single(priv
->device
, skb
->data
,
468 bfsize
, DMA_FROM_DEVICE
);
470 p
->des2
= priv
->rx_skbuff_dma
[i
];
471 if (unlikely(buff2_needed
))
472 p
->des3
= p
->des2
+ BUF_SIZE_8KiB
;
473 DBG(probe
, INFO
, "[%p]\t[%p]\t[%x]\n", priv
->rx_skbuff
[i
],
474 priv
->rx_skbuff
[i
]->data
, priv
->rx_skbuff_dma
[i
]);
477 priv
->dirty_rx
= (unsigned int)(i
- rxsize
);
478 priv
->dma_buf_sz
= bfsize
;
481 /* TX INITIALIZATION */
482 for (i
= 0; i
< txsize
; i
++) {
483 priv
->tx_skbuff
[i
] = NULL
;
484 priv
->dma_tx
[i
].des2
= 0;
489 /* Clear the Rx/Tx descriptors */
490 priv
->hw
->desc
->init_rx_desc(priv
->dma_rx
, rxsize
, dis_ic
);
491 priv
->hw
->desc
->init_tx_desc(priv
->dma_tx
, txsize
);
493 if (netif_msg_hw(priv
)) {
494 pr_info("RX descriptor ring:\n");
495 display_ring(priv
->dma_rx
, rxsize
);
496 pr_info("TX descriptor ring:\n");
497 display_ring(priv
->dma_tx
, txsize
);
501 static void dma_free_rx_skbufs(struct stmmac_priv
*priv
)
505 for (i
= 0; i
< priv
->dma_rx_size
; i
++) {
506 if (priv
->rx_skbuff
[i
]) {
507 dma_unmap_single(priv
->device
, priv
->rx_skbuff_dma
[i
],
508 priv
->dma_buf_sz
, DMA_FROM_DEVICE
);
509 dev_kfree_skb_any(priv
->rx_skbuff
[i
]);
511 priv
->rx_skbuff
[i
] = NULL
;
515 static void dma_free_tx_skbufs(struct stmmac_priv
*priv
)
519 for (i
= 0; i
< priv
->dma_tx_size
; i
++) {
520 if (priv
->tx_skbuff
[i
] != NULL
) {
521 struct dma_desc
*p
= priv
->dma_tx
+ i
;
523 dma_unmap_single(priv
->device
, p
->des2
,
524 priv
->hw
->desc
->get_tx_len(p
),
526 dev_kfree_skb_any(priv
->tx_skbuff
[i
]);
527 priv
->tx_skbuff
[i
] = NULL
;
532 static void free_dma_desc_resources(struct stmmac_priv
*priv
)
534 /* Release the DMA TX/RX socket buffers */
535 dma_free_rx_skbufs(priv
);
536 dma_free_tx_skbufs(priv
);
538 /* Free the region of consistent memory previously allocated for
540 dma_free_coherent(priv
->device
,
541 priv
->dma_tx_size
* sizeof(struct dma_desc
),
542 priv
->dma_tx
, priv
->dma_tx_phy
);
543 dma_free_coherent(priv
->device
,
544 priv
->dma_rx_size
* sizeof(struct dma_desc
),
545 priv
->dma_rx
, priv
->dma_rx_phy
);
546 kfree(priv
->rx_skbuff_dma
);
547 kfree(priv
->rx_skbuff
);
548 kfree(priv
->tx_skbuff
);
552 * stmmac_dma_operation_mode - HW DMA operation mode
553 * @priv : pointer to the private device structure.
554 * Description: it sets the DMA operation mode: tx/rx DMA thresholds
555 * or Store-And-Forward capability.
557 static void stmmac_dma_operation_mode(struct stmmac_priv
*priv
)
559 if (likely(priv
->plat
->force_sf_dma_mode
||
560 ((priv
->plat
->tx_coe
) && (!priv
->no_csum_insertion
)))) {
562 * In case of GMAC, SF mode can be enabled
563 * to perform the TX COE in HW. This depends on:
564 * 1) TX COE if actually supported
565 * 2) There is no bugged Jumbo frame support
566 * that needs to not insert csum in the TDES.
568 priv
->hw
->dma
->dma_mode(priv
->ioaddr
,
569 SF_DMA_MODE
, SF_DMA_MODE
);
572 priv
->hw
->dma
->dma_mode(priv
->ioaddr
, tc
, SF_DMA_MODE
);
577 * @priv: private driver structure
578 * Description: it reclaims resources after transmission completes.
580 static void stmmac_tx(struct stmmac_priv
*priv
)
582 unsigned int txsize
= priv
->dma_tx_size
;
584 while (priv
->dirty_tx
!= priv
->cur_tx
) {
586 unsigned int entry
= priv
->dirty_tx
% txsize
;
587 struct sk_buff
*skb
= priv
->tx_skbuff
[entry
];
588 struct dma_desc
*p
= priv
->dma_tx
+ entry
;
590 /* Check if the descriptor is owned by the DMA. */
591 if (priv
->hw
->desc
->get_tx_owner(p
))
594 /* Verify tx error by looking at the last segment */
595 last
= priv
->hw
->desc
->get_tx_ls(p
);
598 priv
->hw
->desc
->tx_status(&priv
->dev
->stats
,
601 if (likely(tx_error
== 0)) {
602 priv
->dev
->stats
.tx_packets
++;
603 priv
->xstats
.tx_pkt_n
++;
605 priv
->dev
->stats
.tx_errors
++;
607 TX_DBG("%s: curr %d, dirty %d\n", __func__
,
608 priv
->cur_tx
, priv
->dirty_tx
);
611 dma_unmap_single(priv
->device
, p
->des2
,
612 priv
->hw
->desc
->get_tx_len(p
),
614 if (unlikely(p
->des3
))
617 if (likely(skb
!= NULL
)) {
619 * If there's room in the queue (limit it to size)
620 * we add this skb back into the pool,
621 * if it's the right size.
623 if ((skb_queue_len(&priv
->rx_recycle
) <
624 priv
->dma_rx_size
) &&
625 skb_recycle_check(skb
, priv
->dma_buf_sz
))
626 __skb_queue_head(&priv
->rx_recycle
, skb
);
630 priv
->tx_skbuff
[entry
] = NULL
;
633 priv
->hw
->desc
->release_tx_desc(p
);
635 entry
= (++priv
->dirty_tx
) % txsize
;
637 if (unlikely(netif_queue_stopped(priv
->dev
) &&
638 stmmac_tx_avail(priv
) > STMMAC_TX_THRESH(priv
))) {
639 netif_tx_lock(priv
->dev
);
640 if (netif_queue_stopped(priv
->dev
) &&
641 stmmac_tx_avail(priv
) > STMMAC_TX_THRESH(priv
)) {
642 TX_DBG("%s: restart transmit\n", __func__
);
643 netif_wake_queue(priv
->dev
);
645 netif_tx_unlock(priv
->dev
);
649 static inline void stmmac_enable_irq(struct stmmac_priv
*priv
)
651 #ifdef CONFIG_STMMAC_TIMER
652 if (likely(priv
->tm
->enable
))
653 priv
->tm
->timer_start(tmrate
);
656 priv
->hw
->dma
->enable_dma_irq(priv
->ioaddr
);
659 static inline void stmmac_disable_irq(struct stmmac_priv
*priv
)
661 #ifdef CONFIG_STMMAC_TIMER
662 if (likely(priv
->tm
->enable
))
663 priv
->tm
->timer_stop();
666 priv
->hw
->dma
->disable_dma_irq(priv
->ioaddr
);
669 static int stmmac_has_work(struct stmmac_priv
*priv
)
671 unsigned int has_work
= 0;
672 int rxret
, tx_work
= 0;
674 rxret
= priv
->hw
->desc
->get_rx_owner(priv
->dma_rx
+
675 (priv
->cur_rx
% priv
->dma_rx_size
));
677 if (priv
->dirty_tx
!= priv
->cur_tx
)
680 if (likely(!rxret
|| tx_work
))
686 static inline void _stmmac_schedule(struct stmmac_priv
*priv
)
688 if (likely(stmmac_has_work(priv
))) {
689 stmmac_disable_irq(priv
);
690 napi_schedule(&priv
->napi
);
694 #ifdef CONFIG_STMMAC_TIMER
695 void stmmac_schedule(struct net_device
*dev
)
697 struct stmmac_priv
*priv
= netdev_priv(dev
);
699 priv
->xstats
.sched_timer_n
++;
701 _stmmac_schedule(priv
);
704 static void stmmac_no_timer_started(unsigned int x
)
708 static void stmmac_no_timer_stopped(void)
715 * @priv: pointer to the private device structure
716 * Description: it cleans the descriptors and restarts the transmission
719 static void stmmac_tx_err(struct stmmac_priv
*priv
)
722 netif_stop_queue(priv
->dev
);
724 priv
->hw
->dma
->stop_tx(priv
->ioaddr
);
725 dma_free_tx_skbufs(priv
);
726 priv
->hw
->desc
->init_tx_desc(priv
->dma_tx
, priv
->dma_tx_size
);
729 priv
->hw
->dma
->start_tx(priv
->ioaddr
);
731 priv
->dev
->stats
.tx_errors
++;
732 netif_wake_queue(priv
->dev
);
736 static void stmmac_dma_interrupt(struct stmmac_priv
*priv
)
740 status
= priv
->hw
->dma
->dma_interrupt(priv
->ioaddr
, &priv
->xstats
);
741 if (likely(status
== handle_tx_rx
))
742 _stmmac_schedule(priv
);
744 else if (unlikely(status
== tx_hard_error_bump_tc
)) {
745 /* Try to bump up the dma threshold on this failure */
746 if (unlikely(tc
!= SF_DMA_MODE
) && (tc
<= 256)) {
748 priv
->hw
->dma
->dma_mode(priv
->ioaddr
, tc
, SF_DMA_MODE
);
749 priv
->xstats
.threshold
= tc
;
751 } else if (unlikely(status
== tx_hard_error
))
755 static void stmmac_mmc_setup(struct stmmac_priv
*priv
)
757 unsigned int mode
= MMC_CNTRL_RESET_ON_READ
| MMC_CNTRL_COUNTER_RESET
|
758 MMC_CNTRL_PRESET
| MMC_CNTRL_FULL_HALF_PRESET
;
760 /* Do not manage MMC IRQ (FIXME) */
761 dwmac_mmc_intr_all_mask(priv
->ioaddr
);
762 dwmac_mmc_ctrl(priv
->ioaddr
, mode
);
763 memset(&priv
->mmc
, 0, sizeof(struct stmmac_counters
));
766 static u32
stmmac_get_synopsys_id(struct stmmac_priv
*priv
)
768 u32 hwid
= priv
->hw
->synopsys_uid
;
770 /* Only check valid Synopsys Id because old MAC chips
771 * have no HW registers where get the ID */
773 u32 uid
= ((hwid
& 0x0000ff00) >> 8);
774 u32 synid
= (hwid
& 0x000000ff);
776 pr_info("STMMAC - user ID: 0x%x, Synopsys ID: 0x%x\n",
784 /* New GMAC chips support a new register to indicate the
785 * presence of the optional feature/functions.
787 static int stmmac_get_hw_features(struct stmmac_priv
*priv
)
789 u32 hw_cap
= priv
->hw
->dma
->get_hw_feature(priv
->ioaddr
);
791 if (likely(hw_cap
)) {
792 priv
->dma_cap
.mbps_10_100
= (hw_cap
& 0x1);
793 priv
->dma_cap
.mbps_1000
= (hw_cap
& 0x2) >> 1;
794 priv
->dma_cap
.half_duplex
= (hw_cap
& 0x4) >> 2;
795 priv
->dma_cap
.hash_filter
= (hw_cap
& 0x10) >> 4;
796 priv
->dma_cap
.multi_addr
= (hw_cap
& 0x20) >> 5;
797 priv
->dma_cap
.pcs
= (hw_cap
& 0x40) >> 6;
798 priv
->dma_cap
.sma_mdio
= (hw_cap
& 0x100) >> 8;
799 priv
->dma_cap
.pmt_remote_wake_up
= (hw_cap
& 0x200) >> 9;
800 priv
->dma_cap
.pmt_magic_frame
= (hw_cap
& 0x400) >> 10;
801 priv
->dma_cap
.rmon
= (hw_cap
& 0x800) >> 11; /* MMC */
803 priv
->dma_cap
.time_stamp
= (hw_cap
& 0x1000) >> 12;
805 priv
->dma_cap
.atime_stamp
= (hw_cap
& 0x2000) >> 13;
806 /* 802.3az - Energy-Efficient Ethernet (EEE) */
807 priv
->dma_cap
.eee
= (hw_cap
& 0x4000) >> 14;
808 priv
->dma_cap
.av
= (hw_cap
& 0x8000) >> 15;
810 priv
->dma_cap
.tx_coe
= (hw_cap
& 0x10000) >> 16;
811 priv
->dma_cap
.rx_coe_type1
= (hw_cap
& 0x20000) >> 17;
812 priv
->dma_cap
.rx_coe_type2
= (hw_cap
& 0x40000) >> 18;
813 priv
->dma_cap
.rxfifo_over_2048
= (hw_cap
& 0x80000) >> 19;
814 /* TX and RX number of channels */
815 priv
->dma_cap
.number_rx_channel
= (hw_cap
& 0x300000) >> 20;
816 priv
->dma_cap
.number_tx_channel
= (hw_cap
& 0xc00000) >> 22;
817 /* Alternate (enhanced) DESC mode*/
818 priv
->dma_cap
.enh_desc
= (hw_cap
& 0x1000000) >> 24;
821 pr_debug("\tNo HW DMA feature register supported");
827 * stmmac_open - open entry point of the driver
828 * @dev : pointer to the device structure.
830 * This function is the open entry point of the driver.
832 * 0 on success and an appropriate (-)ve integer as defined in errno.h
835 static int stmmac_open(struct net_device
*dev
)
837 struct stmmac_priv
*priv
= netdev_priv(dev
);
840 /* Check that the MAC address is valid. If its not, refuse
841 * to bring the device up. The user must specify an
842 * address using the following linux command:
843 * ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx */
844 if (!is_valid_ether_addr(dev
->dev_addr
)) {
845 random_ether_addr(dev
->dev_addr
);
846 pr_warning("%s: generated random MAC address %pM\n", dev
->name
,
850 stmmac_verify_args();
852 #ifdef CONFIG_STMMAC_TIMER
853 priv
->tm
= kzalloc(sizeof(struct stmmac_timer
*), GFP_KERNEL
);
854 if (unlikely(priv
->tm
== NULL
)) {
855 pr_err("%s: ERROR: timer memory alloc failed\n", __func__
);
858 priv
->tm
->freq
= tmrate
;
860 /* Test if the external timer can be actually used.
861 * In case of failure continue without timer. */
862 if (unlikely((stmmac_open_ext_timer(dev
, priv
->tm
)) < 0)) {
863 pr_warning("stmmaceth: cannot attach the external timer.\n");
865 priv
->tm
->timer_start
= stmmac_no_timer_started
;
866 priv
->tm
->timer_stop
= stmmac_no_timer_stopped
;
868 priv
->tm
->enable
= 1;
870 ret
= stmmac_init_phy(dev
);
872 pr_err("%s: Cannot attach to PHY (error: %d)\n", __func__
, ret
);
876 /* Create and initialize the TX/RX descriptors chains. */
877 priv
->dma_tx_size
= STMMAC_ALIGN(dma_txsize
);
878 priv
->dma_rx_size
= STMMAC_ALIGN(dma_rxsize
);
879 priv
->dma_buf_sz
= STMMAC_ALIGN(buf_sz
);
880 init_dma_desc_rings(dev
);
882 /* DMA initialization and SW reset */
883 ret
= priv
->hw
->dma
->init(priv
->ioaddr
, priv
->plat
->pbl
,
884 priv
->dma_tx_phy
, priv
->dma_rx_phy
);
886 pr_err("%s: DMA initialization failed\n", __func__
);
890 /* Copy the MAC addr into the HW */
891 priv
->hw
->mac
->set_umac_addr(priv
->ioaddr
, dev
->dev_addr
, 0);
892 /* If required, perform hw setup of the bus. */
893 if (priv
->plat
->bus_setup
)
894 priv
->plat
->bus_setup(priv
->ioaddr
);
895 /* Initialize the MAC Core */
896 priv
->hw
->mac
->core_init(priv
->ioaddr
);
898 stmmac_get_synopsys_id(priv
);
900 stmmac_get_hw_features(priv
);
903 pr_info("stmmac: Rx Checksum Offload Engine supported\n");
904 if (priv
->plat
->tx_coe
)
905 pr_info("\tTX Checksum insertion supported\n");
906 netdev_update_features(dev
);
908 /* Request the IRQ lines */
909 ret
= request_irq(dev
->irq
, stmmac_interrupt
,
910 IRQF_SHARED
, dev
->name
, dev
);
911 if (unlikely(ret
< 0)) {
912 pr_err("%s: ERROR: allocating the IRQ %d (error: %d)\n",
913 __func__
, dev
->irq
, ret
);
917 /* Enable the MAC Rx/Tx */
918 stmmac_enable_mac(priv
->ioaddr
);
920 /* Set the HW DMA mode and the COE */
921 stmmac_dma_operation_mode(priv
);
923 /* Extra statistics */
924 memset(&priv
->xstats
, 0, sizeof(struct stmmac_extra_stats
));
925 priv
->xstats
.threshold
= tc
;
927 stmmac_mmc_setup(priv
);
929 /* Start the ball rolling... */
930 DBG(probe
, DEBUG
, "%s: DMA RX/TX processes started...\n", dev
->name
);
931 priv
->hw
->dma
->start_tx(priv
->ioaddr
);
932 priv
->hw
->dma
->start_rx(priv
->ioaddr
);
934 #ifdef CONFIG_STMMAC_TIMER
935 priv
->tm
->timer_start(tmrate
);
937 /* Dump DMA/MAC registers */
938 if (netif_msg_hw(priv
)) {
939 priv
->hw
->mac
->dump_regs(priv
->ioaddr
);
940 priv
->hw
->dma
->dump_regs(priv
->ioaddr
);
944 phy_start(priv
->phydev
);
946 napi_enable(&priv
->napi
);
947 skb_queue_head_init(&priv
->rx_recycle
);
948 netif_start_queue(dev
);
953 #ifdef CONFIG_STMMAC_TIMER
957 phy_disconnect(priv
->phydev
);
963 * stmmac_release - close entry point of the driver
964 * @dev : device pointer.
966 * This is the stop entry point of the driver.
968 static int stmmac_release(struct net_device
*dev
)
970 struct stmmac_priv
*priv
= netdev_priv(dev
);
972 /* Stop and disconnect the PHY */
974 phy_stop(priv
->phydev
);
975 phy_disconnect(priv
->phydev
);
979 netif_stop_queue(dev
);
981 #ifdef CONFIG_STMMAC_TIMER
982 /* Stop and release the timer */
983 stmmac_close_ext_timer();
984 if (priv
->tm
!= NULL
)
987 napi_disable(&priv
->napi
);
988 skb_queue_purge(&priv
->rx_recycle
);
990 /* Free the IRQ lines */
991 free_irq(dev
->irq
, dev
);
993 /* Stop TX/RX DMA and clear the descriptors */
994 priv
->hw
->dma
->stop_tx(priv
->ioaddr
);
995 priv
->hw
->dma
->stop_rx(priv
->ioaddr
);
997 /* Release and free the Rx/Tx resources */
998 free_dma_desc_resources(priv
);
1000 /* Disable the MAC Rx/Tx */
1001 stmmac_disable_mac(priv
->ioaddr
);
1003 netif_carrier_off(dev
);
1008 static unsigned int stmmac_handle_jumbo_frames(struct sk_buff
*skb
,
1009 struct net_device
*dev
,
1012 struct stmmac_priv
*priv
= netdev_priv(dev
);
1013 unsigned int nopaged_len
= skb_headlen(skb
);
1014 unsigned int txsize
= priv
->dma_tx_size
;
1015 unsigned int entry
= priv
->cur_tx
% txsize
;
1016 struct dma_desc
*desc
= priv
->dma_tx
+ entry
;
1018 if (nopaged_len
> BUF_SIZE_8KiB
) {
1020 int buf2_size
= nopaged_len
- BUF_SIZE_8KiB
;
1022 desc
->des2
= dma_map_single(priv
->device
, skb
->data
,
1023 BUF_SIZE_8KiB
, DMA_TO_DEVICE
);
1024 desc
->des3
= desc
->des2
+ BUF_SIZE_4KiB
;
1025 priv
->hw
->desc
->prepare_tx_desc(desc
, 1, BUF_SIZE_8KiB
,
1028 entry
= (++priv
->cur_tx
) % txsize
;
1029 desc
= priv
->dma_tx
+ entry
;
1031 desc
->des2
= dma_map_single(priv
->device
,
1032 skb
->data
+ BUF_SIZE_8KiB
,
1033 buf2_size
, DMA_TO_DEVICE
);
1034 desc
->des3
= desc
->des2
+ BUF_SIZE_4KiB
;
1035 priv
->hw
->desc
->prepare_tx_desc(desc
, 0, buf2_size
,
1037 priv
->hw
->desc
->set_tx_owner(desc
);
1038 priv
->tx_skbuff
[entry
] = NULL
;
1040 desc
->des2
= dma_map_single(priv
->device
, skb
->data
,
1041 nopaged_len
, DMA_TO_DEVICE
);
1042 desc
->des3
= desc
->des2
+ BUF_SIZE_4KiB
;
1043 priv
->hw
->desc
->prepare_tx_desc(desc
, 1, nopaged_len
,
1051 * @skb : the socket buffer
1052 * @dev : device pointer
1053 * Description : Tx entry point of the driver.
1055 static netdev_tx_t
stmmac_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1057 struct stmmac_priv
*priv
= netdev_priv(dev
);
1058 unsigned int txsize
= priv
->dma_tx_size
;
1060 int i
, csum_insertion
= 0;
1061 int nfrags
= skb_shinfo(skb
)->nr_frags
;
1062 struct dma_desc
*desc
, *first
;
1064 if (unlikely(stmmac_tx_avail(priv
) < nfrags
+ 1)) {
1065 if (!netif_queue_stopped(dev
)) {
1066 netif_stop_queue(dev
);
1067 /* This is a hard error, log it. */
1068 pr_err("%s: BUG! Tx Ring full when queue awake\n",
1071 return NETDEV_TX_BUSY
;
1074 entry
= priv
->cur_tx
% txsize
;
1076 #ifdef STMMAC_XMIT_DEBUG
1077 if ((skb
->len
> ETH_FRAME_LEN
) || nfrags
)
1078 pr_info("stmmac xmit:\n"
1079 "\tskb addr %p - len: %d - nopaged_len: %d\n"
1080 "\tn_frags: %d - ip_summed: %d - %s gso\n",
1081 skb
, skb
->len
, skb_headlen(skb
), nfrags
, skb
->ip_summed
,
1082 !skb_is_gso(skb
) ? "isn't" : "is");
1085 csum_insertion
= (skb
->ip_summed
== CHECKSUM_PARTIAL
);
1087 desc
= priv
->dma_tx
+ entry
;
1090 #ifdef STMMAC_XMIT_DEBUG
1091 if ((nfrags
> 0) || (skb
->len
> ETH_FRAME_LEN
))
1092 pr_debug("stmmac xmit: skb len: %d, nopaged_len: %d,\n"
1093 "\t\tn_frags: %d, ip_summed: %d\n",
1094 skb
->len
, skb_headlen(skb
), nfrags
, skb
->ip_summed
);
1096 priv
->tx_skbuff
[entry
] = skb
;
1097 if (unlikely(skb
->len
>= BUF_SIZE_4KiB
)) {
1098 entry
= stmmac_handle_jumbo_frames(skb
, dev
, csum_insertion
);
1099 desc
= priv
->dma_tx
+ entry
;
1101 unsigned int nopaged_len
= skb_headlen(skb
);
1102 desc
->des2
= dma_map_single(priv
->device
, skb
->data
,
1103 nopaged_len
, DMA_TO_DEVICE
);
1104 priv
->hw
->desc
->prepare_tx_desc(desc
, 1, nopaged_len
,
1108 for (i
= 0; i
< nfrags
; i
++) {
1109 const skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
1110 int len
= skb_frag_size(frag
);
1112 entry
= (++priv
->cur_tx
) % txsize
;
1113 desc
= priv
->dma_tx
+ entry
;
1115 TX_DBG("\t[entry %d] segment len: %d\n", entry
, len
);
1116 desc
->des2
= skb_frag_dma_map(priv
->device
, frag
, 0, len
,
1118 priv
->tx_skbuff
[entry
] = NULL
;
1119 priv
->hw
->desc
->prepare_tx_desc(desc
, 0, len
, csum_insertion
);
1121 priv
->hw
->desc
->set_tx_owner(desc
);
1124 /* Interrupt on completition only for the latest segment */
1125 priv
->hw
->desc
->close_tx_desc(desc
);
1127 #ifdef CONFIG_STMMAC_TIMER
1128 /* Clean IC while using timer */
1129 if (likely(priv
->tm
->enable
))
1130 priv
->hw
->desc
->clear_tx_ic(desc
);
1135 /* To avoid raise condition */
1136 priv
->hw
->desc
->set_tx_owner(first
);
1140 #ifdef STMMAC_XMIT_DEBUG
1141 if (netif_msg_pktdata(priv
)) {
1142 pr_info("stmmac xmit: current=%d, dirty=%d, entry=%d, "
1143 "first=%p, nfrags=%d\n",
1144 (priv
->cur_tx
% txsize
), (priv
->dirty_tx
% txsize
),
1145 entry
, first
, nfrags
);
1146 display_ring(priv
->dma_tx
, txsize
);
1147 pr_info(">>> frame to be transmitted: ");
1148 print_pkt(skb
->data
, skb
->len
);
1151 if (unlikely(stmmac_tx_avail(priv
) <= (MAX_SKB_FRAGS
+ 1))) {
1152 TX_DBG("%s: stop transmitted packets\n", __func__
);
1153 netif_stop_queue(dev
);
1156 dev
->stats
.tx_bytes
+= skb
->len
;
1158 skb_tx_timestamp(skb
);
1160 priv
->hw
->dma
->enable_dma_transmission(priv
->ioaddr
);
1162 return NETDEV_TX_OK
;
1165 static inline void stmmac_rx_refill(struct stmmac_priv
*priv
)
1167 unsigned int rxsize
= priv
->dma_rx_size
;
1168 int bfsize
= priv
->dma_buf_sz
;
1169 struct dma_desc
*p
= priv
->dma_rx
;
1171 for (; priv
->cur_rx
- priv
->dirty_rx
> 0; priv
->dirty_rx
++) {
1172 unsigned int entry
= priv
->dirty_rx
% rxsize
;
1173 if (likely(priv
->rx_skbuff
[entry
] == NULL
)) {
1174 struct sk_buff
*skb
;
1176 skb
= __skb_dequeue(&priv
->rx_recycle
);
1178 skb
= netdev_alloc_skb_ip_align(priv
->dev
,
1181 if (unlikely(skb
== NULL
))
1184 priv
->rx_skbuff
[entry
] = skb
;
1185 priv
->rx_skbuff_dma
[entry
] =
1186 dma_map_single(priv
->device
, skb
->data
, bfsize
,
1189 (p
+ entry
)->des2
= priv
->rx_skbuff_dma
[entry
];
1190 if (unlikely(priv
->plat
->has_gmac
)) {
1191 if (bfsize
>= BUF_SIZE_8KiB
)
1193 (p
+ entry
)->des2
+ BUF_SIZE_8KiB
;
1195 RX_DBG(KERN_INFO
"\trefill entry #%d\n", entry
);
1198 priv
->hw
->desc
->set_rx_owner(p
+ entry
);
1202 static int stmmac_rx(struct stmmac_priv
*priv
, int limit
)
1204 unsigned int rxsize
= priv
->dma_rx_size
;
1205 unsigned int entry
= priv
->cur_rx
% rxsize
;
1206 unsigned int next_entry
;
1207 unsigned int count
= 0;
1208 struct dma_desc
*p
= priv
->dma_rx
+ entry
;
1209 struct dma_desc
*p_next
;
1211 #ifdef STMMAC_RX_DEBUG
1212 if (netif_msg_hw(priv
)) {
1213 pr_debug(">>> stmmac_rx: descriptor ring:\n");
1214 display_ring(priv
->dma_rx
, rxsize
);
1218 while (!priv
->hw
->desc
->get_rx_owner(p
)) {
1226 next_entry
= (++priv
->cur_rx
) % rxsize
;
1227 p_next
= priv
->dma_rx
+ next_entry
;
1230 /* read the status of the incoming frame */
1231 status
= (priv
->hw
->desc
->rx_status(&priv
->dev
->stats
,
1233 if (unlikely(status
== discard_frame
))
1234 priv
->dev
->stats
.rx_errors
++;
1236 struct sk_buff
*skb
;
1239 frame_len
= priv
->hw
->desc
->get_rx_frame_len(p
);
1240 /* ACS is set; GMAC core strips PAD/FCS for IEEE 802.3
1241 * Type frames (LLC/LLC-SNAP) */
1242 if (unlikely(status
!= llc_snap
))
1243 frame_len
-= ETH_FCS_LEN
;
1244 #ifdef STMMAC_RX_DEBUG
1245 if (frame_len
> ETH_FRAME_LEN
)
1246 pr_debug("\tRX frame size %d, COE status: %d\n",
1249 if (netif_msg_hw(priv
))
1250 pr_debug("\tdesc: %p [entry %d] buff=0x%x\n",
1253 skb
= priv
->rx_skbuff
[entry
];
1254 if (unlikely(!skb
)) {
1255 pr_err("%s: Inconsistent Rx descriptor chain\n",
1257 priv
->dev
->stats
.rx_dropped
++;
1260 prefetch(skb
->data
- NET_IP_ALIGN
);
1261 priv
->rx_skbuff
[entry
] = NULL
;
1263 skb_put(skb
, frame_len
);
1264 dma_unmap_single(priv
->device
,
1265 priv
->rx_skbuff_dma
[entry
],
1266 priv
->dma_buf_sz
, DMA_FROM_DEVICE
);
1267 #ifdef STMMAC_RX_DEBUG
1268 if (netif_msg_pktdata(priv
)) {
1269 pr_info(" frame received (%dbytes)", frame_len
);
1270 print_pkt(skb
->data
, frame_len
);
1273 skb
->protocol
= eth_type_trans(skb
, priv
->dev
);
1275 if (unlikely(status
== csum_none
)) {
1276 /* always for the old mac 10/100 */
1277 skb_checksum_none_assert(skb
);
1278 netif_receive_skb(skb
);
1280 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1281 napi_gro_receive(&priv
->napi
, skb
);
1284 priv
->dev
->stats
.rx_packets
++;
1285 priv
->dev
->stats
.rx_bytes
+= frame_len
;
1288 p
= p_next
; /* use prefetched values */
1291 stmmac_rx_refill(priv
);
1293 priv
->xstats
.rx_pkt_n
+= count
;
1299 * stmmac_poll - stmmac poll method (NAPI)
1300 * @napi : pointer to the napi structure.
1301 * @budget : maximum number of packets that the current CPU can receive from
1304 * This function implements the the reception process.
1305 * Also it runs the TX completion thread
1307 static int stmmac_poll(struct napi_struct
*napi
, int budget
)
1309 struct stmmac_priv
*priv
= container_of(napi
, struct stmmac_priv
, napi
);
1312 priv
->xstats
.poll_n
++;
1314 work_done
= stmmac_rx(priv
, budget
);
1316 if (work_done
< budget
) {
1317 napi_complete(napi
);
1318 stmmac_enable_irq(priv
);
1325 * @dev : Pointer to net device structure
1326 * Description: this function is called when a packet transmission fails to
1327 * complete within a reasonable tmrate. The driver will mark the error in the
1328 * netdev structure and arrange for the device to be reset to a sane state
1329 * in order to transmit a new packet.
1331 static void stmmac_tx_timeout(struct net_device
*dev
)
1333 struct stmmac_priv
*priv
= netdev_priv(dev
);
1335 /* Clear Tx resources and restart transmitting again */
1336 stmmac_tx_err(priv
);
1339 /* Configuration changes (passed on by ifconfig) */
1340 static int stmmac_config(struct net_device
*dev
, struct ifmap
*map
)
1342 if (dev
->flags
& IFF_UP
) /* can't act on a running interface */
1345 /* Don't allow changing the I/O address */
1346 if (map
->base_addr
!= dev
->base_addr
) {
1347 pr_warning("%s: can't change I/O address\n", dev
->name
);
1351 /* Don't allow changing the IRQ */
1352 if (map
->irq
!= dev
->irq
) {
1353 pr_warning("%s: can't change IRQ number %d\n",
1354 dev
->name
, dev
->irq
);
1358 /* ignore other fields */
1363 * stmmac_set_rx_mode - entry point for multicast addressing
1364 * @dev : pointer to the device structure
1366 * This function is a driver entry point which gets called by the kernel
1367 * whenever multicast addresses must be enabled/disabled.
1371 static void stmmac_set_rx_mode(struct net_device
*dev
)
1373 struct stmmac_priv
*priv
= netdev_priv(dev
);
1375 spin_lock(&priv
->lock
);
1376 priv
->hw
->mac
->set_filter(dev
);
1377 spin_unlock(&priv
->lock
);
1381 * stmmac_change_mtu - entry point to change MTU size for the device.
1382 * @dev : device pointer.
1383 * @new_mtu : the new MTU size for the device.
1384 * Description: the Maximum Transfer Unit (MTU) is used by the network layer
1385 * to drive packet transmission. Ethernet has an MTU of 1500 octets
1386 * (ETH_DATA_LEN). This value can be changed with ifconfig.
1388 * 0 on success and an appropriate (-)ve integer as defined in errno.h
1391 static int stmmac_change_mtu(struct net_device
*dev
, int new_mtu
)
1393 struct stmmac_priv
*priv
= netdev_priv(dev
);
1396 if (netif_running(dev
)) {
1397 pr_err("%s: must be stopped to change its MTU\n", dev
->name
);
1401 if (priv
->plat
->has_gmac
)
1402 max_mtu
= JUMBO_LEN
;
1404 max_mtu
= ETH_DATA_LEN
;
1406 if ((new_mtu
< 46) || (new_mtu
> max_mtu
)) {
1407 pr_err("%s: invalid MTU, max MTU is: %d\n", dev
->name
, max_mtu
);
1412 netdev_update_features(dev
);
1417 static u32
stmmac_fix_features(struct net_device
*dev
, u32 features
)
1419 struct stmmac_priv
*priv
= netdev_priv(dev
);
1422 features
&= ~NETIF_F_RXCSUM
;
1423 if (!priv
->plat
->tx_coe
)
1424 features
&= ~NETIF_F_ALL_CSUM
;
1426 /* Some GMAC devices have a bugged Jumbo frame support that
1427 * needs to have the Tx COE disabled for oversized frames
1428 * (due to limited buffer sizes). In this case we disable
1429 * the TX csum insertionin the TDES and not use SF. */
1430 if (priv
->plat
->bugged_jumbo
&& (dev
->mtu
> ETH_DATA_LEN
))
1431 features
&= ~NETIF_F_ALL_CSUM
;
1436 static irqreturn_t
stmmac_interrupt(int irq
, void *dev_id
)
1438 struct net_device
*dev
= (struct net_device
*)dev_id
;
1439 struct stmmac_priv
*priv
= netdev_priv(dev
);
1441 if (unlikely(!dev
)) {
1442 pr_err("%s: invalid dev pointer\n", __func__
);
1446 if (priv
->plat
->has_gmac
)
1447 /* To handle GMAC own interrupts */
1448 priv
->hw
->mac
->host_irq_status((void __iomem
*) dev
->base_addr
);
1450 stmmac_dma_interrupt(priv
);
1455 #ifdef CONFIG_NET_POLL_CONTROLLER
1456 /* Polling receive - used by NETCONSOLE and other diagnostic tools
1457 * to allow network I/O with interrupts disabled. */
1458 static void stmmac_poll_controller(struct net_device
*dev
)
1460 disable_irq(dev
->irq
);
1461 stmmac_interrupt(dev
->irq
, dev
);
1462 enable_irq(dev
->irq
);
1467 * stmmac_ioctl - Entry point for the Ioctl
1468 * @dev: Device pointer.
1469 * @rq: An IOCTL specefic structure, that can contain a pointer to
1470 * a proprietary structure used to pass information to the driver.
1471 * @cmd: IOCTL command
1473 * Currently there are no special functionality supported in IOCTL, just the
1474 * phy_mii_ioctl(...) can be invoked.
1476 static int stmmac_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
1478 struct stmmac_priv
*priv
= netdev_priv(dev
);
1481 if (!netif_running(dev
))
1487 spin_lock(&priv
->lock
);
1488 ret
= phy_mii_ioctl(priv
->phydev
, rq
, cmd
);
1489 spin_unlock(&priv
->lock
);
1494 #ifdef CONFIG_STMMAC_DEBUG_FS
1495 static struct dentry
*stmmac_fs_dir
;
1496 static struct dentry
*stmmac_rings_status
;
1497 static struct dentry
*stmmac_dma_cap
;
1499 static int stmmac_sysfs_ring_read(struct seq_file
*seq
, void *v
)
1507 struct net_device
*dev
= seq
->private;
1508 struct stmmac_priv
*priv
= netdev_priv(dev
);
1510 seq_printf(seq
, "=======================\n");
1511 seq_printf(seq
, " RX descriptor ring\n");
1512 seq_printf(seq
, "=======================\n");
1514 for (i
= 0; i
< priv
->dma_rx_size
; i
++) {
1515 struct tmp_s
*x
= (struct tmp_s
*)(priv
->dma_rx
+ i
);
1516 seq_printf(seq
, "[%d] DES0=0x%x DES1=0x%x BUF1=0x%x BUF2=0x%x",
1517 i
, (unsigned int)(x
->a
),
1518 (unsigned int)((x
->a
) >> 32), x
->b
, x
->c
);
1519 seq_printf(seq
, "\n");
1522 seq_printf(seq
, "\n");
1523 seq_printf(seq
, "=======================\n");
1524 seq_printf(seq
, " TX descriptor ring\n");
1525 seq_printf(seq
, "=======================\n");
1527 for (i
= 0; i
< priv
->dma_tx_size
; i
++) {
1528 struct tmp_s
*x
= (struct tmp_s
*)(priv
->dma_tx
+ i
);
1529 seq_printf(seq
, "[%d] DES0=0x%x DES1=0x%x BUF1=0x%x BUF2=0x%x",
1530 i
, (unsigned int)(x
->a
),
1531 (unsigned int)((x
->a
) >> 32), x
->b
, x
->c
);
1532 seq_printf(seq
, "\n");
1538 static int stmmac_sysfs_ring_open(struct inode
*inode
, struct file
*file
)
1540 return single_open(file
, stmmac_sysfs_ring_read
, inode
->i_private
);
1543 static const struct file_operations stmmac_rings_status_fops
= {
1544 .owner
= THIS_MODULE
,
1545 .open
= stmmac_sysfs_ring_open
,
1547 .llseek
= seq_lseek
,
1548 .release
= seq_release
,
1551 static int stmmac_sysfs_dma_cap_read(struct seq_file
*seq
, void *v
)
1553 struct net_device
*dev
= seq
->private;
1554 struct stmmac_priv
*priv
= netdev_priv(dev
);
1556 if (!stmmac_get_hw_features(priv
)) {
1557 seq_printf(seq
, "DMA HW features not supported\n");
1561 seq_printf(seq
, "==============================\n");
1562 seq_printf(seq
, "\tDMA HW features\n");
1563 seq_printf(seq
, "==============================\n");
1565 seq_printf(seq
, "\t10/100 Mbps %s\n",
1566 (priv
->dma_cap
.mbps_10_100
) ? "Y" : "N");
1567 seq_printf(seq
, "\t1000 Mbps %s\n",
1568 (priv
->dma_cap
.mbps_1000
) ? "Y" : "N");
1569 seq_printf(seq
, "\tHalf duple %s\n",
1570 (priv
->dma_cap
.half_duplex
) ? "Y" : "N");
1571 seq_printf(seq
, "\tHash Filter: %s\n",
1572 (priv
->dma_cap
.hash_filter
) ? "Y" : "N");
1573 seq_printf(seq
, "\tMultiple MAC address registers: %s\n",
1574 (priv
->dma_cap
.multi_addr
) ? "Y" : "N");
1575 seq_printf(seq
, "\tPCS (TBI/SGMII/RTBI PHY interfatces): %s\n",
1576 (priv
->dma_cap
.pcs
) ? "Y" : "N");
1577 seq_printf(seq
, "\tSMA (MDIO) Interface: %s\n",
1578 (priv
->dma_cap
.sma_mdio
) ? "Y" : "N");
1579 seq_printf(seq
, "\tPMT Remote wake up: %s\n",
1580 (priv
->dma_cap
.pmt_remote_wake_up
) ? "Y" : "N");
1581 seq_printf(seq
, "\tPMT Magic Frame: %s\n",
1582 (priv
->dma_cap
.pmt_magic_frame
) ? "Y" : "N");
1583 seq_printf(seq
, "\tRMON module: %s\n",
1584 (priv
->dma_cap
.rmon
) ? "Y" : "N");
1585 seq_printf(seq
, "\tIEEE 1588-2002 Time Stamp: %s\n",
1586 (priv
->dma_cap
.time_stamp
) ? "Y" : "N");
1587 seq_printf(seq
, "\tIEEE 1588-2008 Advanced Time Stamp:%s\n",
1588 (priv
->dma_cap
.atime_stamp
) ? "Y" : "N");
1589 seq_printf(seq
, "\t802.3az - Energy-Efficient Ethernet (EEE) %s\n",
1590 (priv
->dma_cap
.eee
) ? "Y" : "N");
1591 seq_printf(seq
, "\tAV features: %s\n", (priv
->dma_cap
.av
) ? "Y" : "N");
1592 seq_printf(seq
, "\tChecksum Offload in TX: %s\n",
1593 (priv
->dma_cap
.tx_coe
) ? "Y" : "N");
1594 seq_printf(seq
, "\tIP Checksum Offload (type1) in RX: %s\n",
1595 (priv
->dma_cap
.rx_coe_type1
) ? "Y" : "N");
1596 seq_printf(seq
, "\tIP Checksum Offload (type2) in RX: %s\n",
1597 (priv
->dma_cap
.rx_coe_type2
) ? "Y" : "N");
1598 seq_printf(seq
, "\tRXFIFO > 2048bytes: %s\n",
1599 (priv
->dma_cap
.rxfifo_over_2048
) ? "Y" : "N");
1600 seq_printf(seq
, "\tNumber of Additional RX channel: %d\n",
1601 priv
->dma_cap
.number_rx_channel
);
1602 seq_printf(seq
, "\tNumber of Additional TX channel: %d\n",
1603 priv
->dma_cap
.number_tx_channel
);
1604 seq_printf(seq
, "\tEnhanced descriptors: %s\n",
1605 (priv
->dma_cap
.enh_desc
) ? "Y" : "N");
1610 static int stmmac_sysfs_dma_cap_open(struct inode
*inode
, struct file
*file
)
1612 return single_open(file
, stmmac_sysfs_dma_cap_read
, inode
->i_private
);
1615 static const struct file_operations stmmac_dma_cap_fops
= {
1616 .owner
= THIS_MODULE
,
1617 .open
= stmmac_sysfs_dma_cap_open
,
1619 .llseek
= seq_lseek
,
1620 .release
= seq_release
,
1623 static int stmmac_init_fs(struct net_device
*dev
)
1625 /* Create debugfs entries */
1626 stmmac_fs_dir
= debugfs_create_dir(STMMAC_RESOURCE_NAME
, NULL
);
1628 if (!stmmac_fs_dir
|| IS_ERR(stmmac_fs_dir
)) {
1629 pr_err("ERROR %s, debugfs create directory failed\n",
1630 STMMAC_RESOURCE_NAME
);
1635 /* Entry to report DMA RX/TX rings */
1636 stmmac_rings_status
= debugfs_create_file("descriptors_status",
1637 S_IRUGO
, stmmac_fs_dir
, dev
,
1638 &stmmac_rings_status_fops
);
1640 if (!stmmac_rings_status
|| IS_ERR(stmmac_rings_status
)) {
1641 pr_info("ERROR creating stmmac ring debugfs file\n");
1642 debugfs_remove(stmmac_fs_dir
);
1647 /* Entry to report the DMA HW features */
1648 stmmac_dma_cap
= debugfs_create_file("dma_cap", S_IRUGO
, stmmac_fs_dir
,
1649 dev
, &stmmac_dma_cap_fops
);
1651 if (!stmmac_dma_cap
|| IS_ERR(stmmac_dma_cap
)) {
1652 pr_info("ERROR creating stmmac MMC debugfs file\n");
1653 debugfs_remove(stmmac_rings_status
);
1654 debugfs_remove(stmmac_fs_dir
);
1662 static void stmmac_exit_fs(void)
1664 debugfs_remove(stmmac_rings_status
);
1665 debugfs_remove(stmmac_dma_cap
);
1666 debugfs_remove(stmmac_fs_dir
);
1668 #endif /* CONFIG_STMMAC_DEBUG_FS */
1670 static const struct net_device_ops stmmac_netdev_ops
= {
1671 .ndo_open
= stmmac_open
,
1672 .ndo_start_xmit
= stmmac_xmit
,
1673 .ndo_stop
= stmmac_release
,
1674 .ndo_change_mtu
= stmmac_change_mtu
,
1675 .ndo_fix_features
= stmmac_fix_features
,
1676 .ndo_set_rx_mode
= stmmac_set_rx_mode
,
1677 .ndo_tx_timeout
= stmmac_tx_timeout
,
1678 .ndo_do_ioctl
= stmmac_ioctl
,
1679 .ndo_set_config
= stmmac_config
,
1680 #ifdef CONFIG_NET_POLL_CONTROLLER
1681 .ndo_poll_controller
= stmmac_poll_controller
,
1683 .ndo_set_mac_address
= eth_mac_addr
,
1687 * stmmac_probe - Initialization of the adapter .
1688 * @dev : device pointer
1689 * Description: The function initializes the network device structure for
1690 * the STMMAC driver. It also calls the low level routines
1691 * in order to init the HW (i.e. the DMA engine)
1693 static int stmmac_probe(struct net_device
*dev
)
1696 struct stmmac_priv
*priv
= netdev_priv(dev
);
1700 dev
->netdev_ops
= &stmmac_netdev_ops
;
1701 stmmac_set_ethtool_ops(dev
);
1703 dev
->hw_features
= NETIF_F_SG
| NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
;
1704 dev
->features
|= dev
->hw_features
| NETIF_F_HIGHDMA
;
1705 dev
->watchdog_timeo
= msecs_to_jiffies(watchdog
);
1706 #ifdef STMMAC_VLAN_TAG_USED
1707 /* Both mac100 and gmac support receive VLAN tag detection */
1708 dev
->features
|= NETIF_F_HW_VLAN_RX
;
1710 priv
->msg_enable
= netif_msg_init(debug
, default_msg_level
);
1713 priv
->flow_ctrl
= FLOW_AUTO
; /* RX/TX pause on */
1715 priv
->pause
= pause
;
1716 netif_napi_add(dev
, &priv
->napi
, stmmac_poll
, 64);
1718 /* Get the MAC address */
1719 priv
->hw
->mac
->get_umac_addr((void __iomem
*) dev
->base_addr
,
1722 if (!is_valid_ether_addr(dev
->dev_addr
))
1723 pr_warning("\tno valid MAC address;"
1724 "please, use ifconfig or nwhwconfig!\n");
1726 spin_lock_init(&priv
->lock
);
1728 ret
= register_netdev(dev
);
1730 pr_err("%s: ERROR %i registering the device\n",
1735 DBG(probe
, DEBUG
, "%s: Scatter/Gather: %s - HW checksums: %s\n",
1736 dev
->name
, (dev
->features
& NETIF_F_SG
) ? "on" : "off",
1737 (dev
->features
& NETIF_F_IP_CSUM
) ? "on" : "off");
1743 * stmmac_mac_device_setup
1744 * @dev : device pointer
1745 * Description: select and initialise the mac device (mac100 or Gmac).
1747 static int stmmac_mac_device_setup(struct net_device
*dev
)
1749 struct stmmac_priv
*priv
= netdev_priv(dev
);
1751 struct mac_device_info
*device
;
1753 if (priv
->plat
->has_gmac
) {
1754 dev
->priv_flags
|= IFF_UNICAST_FLT
;
1755 device
= dwmac1000_setup(priv
->ioaddr
);
1757 device
= dwmac100_setup(priv
->ioaddr
);
1763 if (priv
->plat
->enh_desc
) {
1764 device
->desc
= &enh_desc_ops
;
1765 pr_info("\tEnhanced descriptor structure\n");
1767 device
->desc
= &ndesc_ops
;
1771 if (device_can_wakeup(priv
->device
)) {
1772 priv
->wolopts
= WAKE_MAGIC
; /* Magic Frame as default */
1773 enable_irq_wake(priv
->wol_irq
);
1781 * @pdev: platform device pointer
1782 * Description: the driver is initialized through platform_device.
1784 static int stmmac_dvr_probe(struct platform_device
*pdev
)
1787 struct resource
*res
;
1788 void __iomem
*addr
= NULL
;
1789 struct net_device
*ndev
= NULL
;
1790 struct stmmac_priv
*priv
= NULL
;
1791 struct plat_stmmacenet_data
*plat_dat
;
1793 pr_info("STMMAC driver:\n\tplatform registration... ");
1794 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1797 pr_info("\tdone!\n");
1799 if (!request_mem_region(res
->start
, resource_size(res
),
1801 pr_err("%s: ERROR: memory allocation failed"
1802 "cannot get the I/O addr 0x%x\n",
1803 __func__
, (unsigned int)res
->start
);
1807 addr
= ioremap(res
->start
, resource_size(res
));
1809 pr_err("%s: ERROR: memory mapping failed\n", __func__
);
1811 goto out_release_region
;
1814 ndev
= alloc_etherdev(sizeof(struct stmmac_priv
));
1816 pr_err("%s: ERROR: allocating the device\n", __func__
);
1821 SET_NETDEV_DEV(ndev
, &pdev
->dev
);
1823 /* Get the MAC information */
1824 ndev
->irq
= platform_get_irq_byname(pdev
, "macirq");
1825 if (ndev
->irq
== -ENXIO
) {
1826 pr_err("%s: ERROR: MAC IRQ configuration "
1827 "information not found\n", __func__
);
1832 priv
= netdev_priv(ndev
);
1833 priv
->device
= &(pdev
->dev
);
1835 plat_dat
= pdev
->dev
.platform_data
;
1837 priv
->plat
= plat_dat
;
1839 priv
->ioaddr
= addr
;
1841 /* PMT module is not integrated in all the MAC devices. */
1842 if (plat_dat
->pmt
) {
1843 pr_info("\tPMT module supported\n");
1844 device_set_wakeup_capable(&pdev
->dev
, 1);
1847 * On some platforms e.g. SPEAr the wake up irq differs from the mac irq
1848 * The external wake up irq can be passed through the platform code
1849 * named as "eth_wake_irq"
1851 * In case the wake up interrupt is not passed from the platform
1852 * so the driver will continue to use the mac irq (ndev->irq)
1854 priv
->wol_irq
= platform_get_irq_byname(pdev
, "eth_wake_irq");
1855 if (priv
->wol_irq
== -ENXIO
)
1856 priv
->wol_irq
= ndev
->irq
;
1859 platform_set_drvdata(pdev
, ndev
);
1861 /* Set the I/O base addr */
1862 ndev
->base_addr
= (unsigned long)addr
;
1864 /* Custom initialisation */
1865 if (priv
->plat
->init
) {
1866 ret
= priv
->plat
->init(pdev
);
1871 /* MAC HW revice detection */
1872 ret
= stmmac_mac_device_setup(ndev
);
1876 /* Network Device Registration */
1877 ret
= stmmac_probe(ndev
);
1881 /* Override with kernel parameters if supplied XXX CRS XXX
1882 * this needs to have multiple instances */
1883 if ((phyaddr
>= 0) && (phyaddr
<= 31))
1884 priv
->plat
->phy_addr
= phyaddr
;
1886 pr_info("\t%s - (dev. name: %s - id: %d, IRQ #%d\n"
1887 "\tIO base addr: 0x%p)\n", ndev
->name
, pdev
->name
,
1888 pdev
->id
, ndev
->irq
, addr
);
1890 /* MDIO bus Registration */
1891 pr_debug("\tMDIO bus (id: %d)...", priv
->plat
->bus_id
);
1892 ret
= stmmac_mdio_register(ndev
);
1894 goto out_unregister
;
1895 pr_debug("registered!\n");
1897 #ifdef CONFIG_STMMAC_DEBUG_FS
1898 ret
= stmmac_init_fs(ndev
);
1900 pr_warning("\tFailed debugFS registration");
1906 unregister_netdev(ndev
);
1908 if (priv
->plat
->exit
)
1909 priv
->plat
->exit(pdev
);
1912 platform_set_drvdata(pdev
, NULL
);
1916 release_mem_region(res
->start
, resource_size(res
));
1923 * @pdev: platform device pointer
1924 * Description: this function resets the TX/RX processes, disables the MAC RX/TX
1925 * changes the link status, releases the DMA descriptor rings,
1926 * unregisters the MDIO bus and unmaps the allocated memory.
1928 static int stmmac_dvr_remove(struct platform_device
*pdev
)
1930 struct net_device
*ndev
= platform_get_drvdata(pdev
);
1931 struct stmmac_priv
*priv
= netdev_priv(ndev
);
1932 struct resource
*res
;
1934 pr_info("%s:\n\tremoving driver", __func__
);
1936 priv
->hw
->dma
->stop_rx(priv
->ioaddr
);
1937 priv
->hw
->dma
->stop_tx(priv
->ioaddr
);
1939 stmmac_disable_mac(priv
->ioaddr
);
1941 netif_carrier_off(ndev
);
1943 stmmac_mdio_unregister(ndev
);
1945 if (priv
->plat
->exit
)
1946 priv
->plat
->exit(pdev
);
1948 platform_set_drvdata(pdev
, NULL
);
1949 unregister_netdev(ndev
);
1951 iounmap((void *)priv
->ioaddr
);
1952 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1953 release_mem_region(res
->start
, resource_size(res
));
1955 #ifdef CONFIG_STMMAC_DEBUG_FS
1965 static int stmmac_suspend(struct device
*dev
)
1967 struct net_device
*ndev
= dev_get_drvdata(dev
);
1968 struct stmmac_priv
*priv
= netdev_priv(ndev
);
1971 if (!ndev
|| !netif_running(ndev
))
1974 spin_lock(&priv
->lock
);
1976 netif_device_detach(ndev
);
1977 netif_stop_queue(ndev
);
1979 phy_stop(priv
->phydev
);
1981 #ifdef CONFIG_STMMAC_TIMER
1982 priv
->tm
->timer_stop();
1983 if (likely(priv
->tm
->enable
))
1986 napi_disable(&priv
->napi
);
1988 /* Stop TX/RX DMA */
1989 priv
->hw
->dma
->stop_tx(priv
->ioaddr
);
1990 priv
->hw
->dma
->stop_rx(priv
->ioaddr
);
1991 /* Clear the Rx/Tx descriptors */
1992 priv
->hw
->desc
->init_rx_desc(priv
->dma_rx
, priv
->dma_rx_size
,
1994 priv
->hw
->desc
->init_tx_desc(priv
->dma_tx
, priv
->dma_tx_size
);
1996 /* Enable Power down mode by programming the PMT regs */
1997 if (device_may_wakeup(priv
->device
))
1998 priv
->hw
->mac
->pmt(priv
->ioaddr
, priv
->wolopts
);
2000 stmmac_disable_mac(priv
->ioaddr
);
2002 spin_unlock(&priv
->lock
);
2006 static int stmmac_resume(struct device
*dev
)
2008 struct net_device
*ndev
= dev_get_drvdata(dev
);
2009 struct stmmac_priv
*priv
= netdev_priv(ndev
);
2011 if (!netif_running(ndev
))
2014 spin_lock(&priv
->lock
);
2016 /* Power Down bit, into the PM register, is cleared
2017 * automatically as soon as a magic packet or a Wake-up frame
2018 * is received. Anyway, it's better to manually clear
2019 * this bit because it can generate problems while resuming
2020 * from another devices (e.g. serial console). */
2021 if (device_may_wakeup(priv
->device
))
2022 priv
->hw
->mac
->pmt(priv
->ioaddr
, 0);
2024 netif_device_attach(ndev
);
2026 /* Enable the MAC and DMA */
2027 stmmac_enable_mac(priv
->ioaddr
);
2028 priv
->hw
->dma
->start_tx(priv
->ioaddr
);
2029 priv
->hw
->dma
->start_rx(priv
->ioaddr
);
2031 #ifdef CONFIG_STMMAC_TIMER
2032 if (likely(priv
->tm
->enable
))
2033 priv
->tm
->timer_start(tmrate
);
2035 napi_enable(&priv
->napi
);
2038 phy_start(priv
->phydev
);
2040 netif_start_queue(ndev
);
2042 spin_unlock(&priv
->lock
);
2046 static int stmmac_freeze(struct device
*dev
)
2048 struct net_device
*ndev
= dev_get_drvdata(dev
);
2050 if (!ndev
|| !netif_running(ndev
))
2053 return stmmac_release(ndev
);
2056 static int stmmac_restore(struct device
*dev
)
2058 struct net_device
*ndev
= dev_get_drvdata(dev
);
2060 if (!ndev
|| !netif_running(ndev
))
2063 return stmmac_open(ndev
);
2066 static const struct dev_pm_ops stmmac_pm_ops
= {
2067 .suspend
= stmmac_suspend
,
2068 .resume
= stmmac_resume
,
2069 .freeze
= stmmac_freeze
,
2070 .thaw
= stmmac_restore
,
2071 .restore
= stmmac_restore
,
2074 static const struct dev_pm_ops stmmac_pm_ops
;
2075 #endif /* CONFIG_PM */
2077 static struct platform_driver stmmac_driver
= {
2078 .probe
= stmmac_dvr_probe
,
2079 .remove
= stmmac_dvr_remove
,
2081 .name
= STMMAC_RESOURCE_NAME
,
2082 .owner
= THIS_MODULE
,
2083 .pm
= &stmmac_pm_ops
,
2088 * stmmac_init_module - Entry point for the driver
2089 * Description: This function is the entry point for the driver.
2091 static int __init
stmmac_init_module(void)
2095 ret
= platform_driver_register(&stmmac_driver
);
2100 * stmmac_cleanup_module - Cleanup routine for the driver
2101 * Description: This function is the cleanup routine for the driver.
2103 static void __exit
stmmac_cleanup_module(void)
2105 platform_driver_unregister(&stmmac_driver
);
2109 static int __init
stmmac_cmdline_opt(char *str
)
2115 while ((opt
= strsep(&str
, ",")) != NULL
) {
2116 if (!strncmp(opt
, "debug:", 6)) {
2117 if (strict_strtoul(opt
+ 6, 0, (unsigned long *)&debug
))
2119 } else if (!strncmp(opt
, "phyaddr:", 8)) {
2120 if (strict_strtoul(opt
+ 8, 0,
2121 (unsigned long *)&phyaddr
))
2123 } else if (!strncmp(opt
, "dma_txsize:", 11)) {
2124 if (strict_strtoul(opt
+ 11, 0,
2125 (unsigned long *)&dma_txsize
))
2127 } else if (!strncmp(opt
, "dma_rxsize:", 11)) {
2128 if (strict_strtoul(opt
+ 11, 0,
2129 (unsigned long *)&dma_rxsize
))
2131 } else if (!strncmp(opt
, "buf_sz:", 7)) {
2132 if (strict_strtoul(opt
+ 7, 0,
2133 (unsigned long *)&buf_sz
))
2135 } else if (!strncmp(opt
, "tc:", 3)) {
2136 if (strict_strtoul(opt
+ 3, 0, (unsigned long *)&tc
))
2138 } else if (!strncmp(opt
, "watchdog:", 9)) {
2139 if (strict_strtoul(opt
+ 9, 0,
2140 (unsigned long *)&watchdog
))
2142 } else if (!strncmp(opt
, "flow_ctrl:", 10)) {
2143 if (strict_strtoul(opt
+ 10, 0,
2144 (unsigned long *)&flow_ctrl
))
2146 } else if (!strncmp(opt
, "pause:", 6)) {
2147 if (strict_strtoul(opt
+ 6, 0, (unsigned long *)&pause
))
2149 #ifdef CONFIG_STMMAC_TIMER
2150 } else if (!strncmp(opt
, "tmrate:", 7)) {
2151 if (strict_strtoul(opt
+ 7, 0,
2152 (unsigned long *)&tmrate
))
2160 pr_err("%s: ERROR broken module parameter conversion", __func__
);
2164 __setup("stmmaceth=", stmmac_cmdline_opt
);
2167 module_init(stmmac_init_module
);
2168 module_exit(stmmac_cleanup_module
);
2170 MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet driver");
2171 MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
2172 MODULE_LICENSE("GPL");