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-2011 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/clk.h>
32 #include <linux/kernel.h>
33 #include <linux/interrupt.h>
35 #include <linux/tcp.h>
36 #include <linux/skbuff.h>
37 #include <linux/ethtool.h>
38 #include <linux/if_ether.h>
39 #include <linux/crc32.h>
40 #include <linux/mii.h>
42 #include <linux/if_vlan.h>
43 #include <linux/dma-mapping.h>
44 #include <linux/slab.h>
45 #include <linux/prefetch.h>
46 #ifdef CONFIG_STMMAC_DEBUG_FS
47 #include <linux/debugfs.h>
48 #include <linux/seq_file.h>
50 #include <linux/net_tstamp.h>
51 #include "stmmac_ptp.h"
55 /*#define STMMAC_DEBUG*/
57 #define DBG(nlevel, klevel, fmt, args...) \
58 ((void)(netif_msg_##nlevel(priv) && \
59 printk(KERN_##klevel fmt, ## args)))
61 #define DBG(nlevel, klevel, fmt, args...) do { } while (0)
64 #undef STMMAC_RX_DEBUG
65 /*#define STMMAC_RX_DEBUG*/
66 #ifdef STMMAC_RX_DEBUG
67 #define RX_DBG(fmt, args...) printk(fmt, ## args)
69 #define RX_DBG(fmt, args...) do { } while (0)
72 #undef STMMAC_XMIT_DEBUG
73 /*#define STMMAC_XMIT_DEBUG*/
74 #ifdef STMMAC_XMIT_DEBUG
75 #define TX_DBG(fmt, args...) printk(fmt, ## args)
77 #define TX_DBG(fmt, args...) do { } while (0)
80 #define STMMAC_ALIGN(x) L1_CACHE_ALIGN(x)
81 #define JUMBO_LEN 9000
83 /* Module parameters */
84 #define TX_TIMEO 5000 /* default 5 seconds */
85 static int watchdog = TX_TIMEO;
86 module_param(watchdog, int, S_IRUGO | S_IWUSR);
87 MODULE_PARM_DESC(watchdog, "Transmit timeout in milliseconds");
89 static int debug = -1; /* -1: default, 0: no output, 16: all */
90 module_param(debug, int, S_IRUGO | S_IWUSR);
91 MODULE_PARM_DESC(debug, "Message Level (0: no output, 16: all)");
94 module_param(phyaddr, int, S_IRUGO);
95 MODULE_PARM_DESC(phyaddr, "Physical device address");
97 #define DMA_TX_SIZE 256
98 static int dma_txsize = DMA_TX_SIZE;
99 module_param(dma_txsize, int, S_IRUGO | S_IWUSR);
100 MODULE_PARM_DESC(dma_txsize, "Number of descriptors in the TX list");
102 #define DMA_RX_SIZE 256
103 static int dma_rxsize = DMA_RX_SIZE;
104 module_param(dma_rxsize, int, S_IRUGO | S_IWUSR);
105 MODULE_PARM_DESC(dma_rxsize, "Number of descriptors in the RX list");
107 static int flow_ctrl = FLOW_OFF;
108 module_param(flow_ctrl, int, S_IRUGO | S_IWUSR);
109 MODULE_PARM_DESC(flow_ctrl, "Flow control ability [on/off]");
111 static int pause = PAUSE_TIME;
112 module_param(pause, int, S_IRUGO | S_IWUSR);
113 MODULE_PARM_DESC(pause, "Flow Control Pause Time");
115 #define TC_DEFAULT 64
116 static int tc = TC_DEFAULT;
117 module_param(tc, int, S_IRUGO | S_IWUSR);
118 MODULE_PARM_DESC(tc, "DMA threshold control value");
120 #define DMA_BUFFER_SIZE BUF_SIZE_2KiB
121 static int buf_sz = DMA_BUFFER_SIZE;
122 module_param(buf_sz, int, S_IRUGO | S_IWUSR);
123 MODULE_PARM_DESC(buf_sz, "DMA buffer size");
125 static const u32 default_msg_level = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
126 NETIF_MSG_LINK | NETIF_MSG_IFUP |
127 NETIF_MSG_IFDOWN | NETIF_MSG_TIMER);
129 #define STMMAC_DEFAULT_LPI_TIMER 1000
130 static int eee_timer = STMMAC_DEFAULT_LPI_TIMER;
131 module_param(eee_timer, int, S_IRUGO | S_IWUSR);
132 MODULE_PARM_DESC(eee_timer, "LPI tx expiration time in msec");
133 #define STMMAC_LPI_TIMER(x) (jiffies + msecs_to_jiffies(x))
135 /* By default the driver will use the ring mode to manage tx and rx descriptors
136 * but passing this value so user can force to use the chain instead of the ring
138 static unsigned int chain_mode;
139 module_param(chain_mode, int, S_IRUGO);
140 MODULE_PARM_DESC(chain_mode, "To use chain instead of ring mode");
142 static irqreturn_t stmmac_interrupt(int irq, void *dev_id);
144 #ifdef CONFIG_STMMAC_DEBUG_FS
145 static int stmmac_init_fs(struct net_device *dev);
146 static void stmmac_exit_fs(void);
149 #define STMMAC_COAL_TIMER(x) (jiffies + usecs_to_jiffies(x))
152 * stmmac_verify_args - verify the driver parameters.
153 * Description: it verifies if some wrong parameter is passed to the driver.
154 * Note that wrong parameters are replaced with the default values.
156 static void stmmac_verify_args(void)
158 if (unlikely(watchdog < 0))
160 if (unlikely(dma_rxsize < 0))
161 dma_rxsize = DMA_RX_SIZE;
162 if (unlikely(dma_txsize < 0))
163 dma_txsize = DMA_TX_SIZE;
164 if (unlikely((buf_sz < DMA_BUFFER_SIZE) || (buf_sz > BUF_SIZE_16KiB)))
165 buf_sz = DMA_BUFFER_SIZE;
166 if (unlikely(flow_ctrl > 1))
167 flow_ctrl = FLOW_AUTO;
168 else if (likely(flow_ctrl < 0))
169 flow_ctrl = FLOW_OFF;
170 if (unlikely((pause < 0) || (pause > 0xffff)))
173 eee_timer = STMMAC_DEFAULT_LPI_TIMER;
176 static void stmmac_clk_csr_set(struct stmmac_priv *priv)
180 clk_rate = clk_get_rate(priv->stmmac_clk);
182 /* Platform provided default clk_csr would be assumed valid
183 * for all other cases except for the below mentioned ones. */
184 if (!(priv->clk_csr & MAC_CSR_H_FRQ_MASK)) {
185 if (clk_rate < CSR_F_35M)
186 priv->clk_csr = STMMAC_CSR_20_35M;
187 else if ((clk_rate >= CSR_F_35M) && (clk_rate < CSR_F_60M))
188 priv->clk_csr = STMMAC_CSR_35_60M;
189 else if ((clk_rate >= CSR_F_60M) && (clk_rate < CSR_F_100M))
190 priv->clk_csr = STMMAC_CSR_60_100M;
191 else if ((clk_rate >= CSR_F_100M) && (clk_rate < CSR_F_150M))
192 priv->clk_csr = STMMAC_CSR_100_150M;
193 else if ((clk_rate >= CSR_F_150M) && (clk_rate < CSR_F_250M))
194 priv->clk_csr = STMMAC_CSR_150_250M;
195 else if ((clk_rate >= CSR_F_250M) && (clk_rate < CSR_F_300M))
196 priv->clk_csr = STMMAC_CSR_250_300M;
197 } /* For values higher than the IEEE 802.3 specified frequency
198 * we can not estimate the proper divider as it is not known
199 * the frequency of clk_csr_i. So we do not change the default
203 #if defined(STMMAC_XMIT_DEBUG) || defined(STMMAC_RX_DEBUG)
204 static void print_pkt(unsigned char *buf, int len)
207 pr_info("len = %d byte, buf addr: 0x%p", len, buf);
208 for (j = 0; j < len; j++) {
210 pr_info("\n %03x:", j);
211 pr_info(" %02x", buf[j]);
217 /* minimum number of free TX descriptors required to wake up TX process */
218 #define STMMAC_TX_THRESH(x) (x->dma_tx_size/4)
220 static inline u32 stmmac_tx_avail(struct stmmac_priv *priv)
222 return priv->dirty_tx + priv->dma_tx_size - priv->cur_tx - 1;
225 /* On some ST platforms, some HW system configuraton registers have to be
226 * set according to the link speed negotiated.
228 static inline void stmmac_hw_fix_mac_speed(struct stmmac_priv *priv)
230 struct phy_device *phydev = priv->phydev;
232 if (likely(priv->plat->fix_mac_speed))
233 priv->plat->fix_mac_speed(priv->plat->bsp_priv,
237 static void stmmac_enable_eee_mode(struct stmmac_priv *priv)
239 /* Check and enter in LPI mode */
240 if ((priv->dirty_tx == priv->cur_tx) &&
241 (priv->tx_path_in_lpi_mode == false))
242 priv->hw->mac->set_eee_mode(priv->ioaddr);
245 void stmmac_disable_eee_mode(struct stmmac_priv *priv)
247 /* Exit and disable EEE in case of we are are in LPI state. */
248 priv->hw->mac->reset_eee_mode(priv->ioaddr);
249 del_timer_sync(&priv->eee_ctrl_timer);
250 priv->tx_path_in_lpi_mode = false;
254 * stmmac_eee_ctrl_timer
257 * If there is no data transfer and if we are not in LPI state,
258 * then MAC Transmitter can be moved to LPI state.
260 static void stmmac_eee_ctrl_timer(unsigned long arg)
262 struct stmmac_priv *priv = (struct stmmac_priv *)arg;
264 stmmac_enable_eee_mode(priv);
265 mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_TIMER(eee_timer));
270 * @priv: private device pointer
272 * If the EEE support has been enabled while configuring the driver,
273 * if the GMAC actually supports the EEE (from the HW cap reg) and the
274 * phy can also manage EEE, so enable the LPI state and start the timer
275 * to verify if the tx path can enter in LPI state.
277 bool stmmac_eee_init(struct stmmac_priv *priv)
281 /* MAC core supports the EEE feature. */
282 if (priv->dma_cap.eee) {
283 /* Check if the PHY supports EEE */
284 if (phy_init_eee(priv->phydev, 1))
287 priv->eee_active = 1;
288 init_timer(&priv->eee_ctrl_timer);
289 priv->eee_ctrl_timer.function = stmmac_eee_ctrl_timer;
290 priv->eee_ctrl_timer.data = (unsigned long)priv;
291 priv->eee_ctrl_timer.expires = STMMAC_LPI_TIMER(eee_timer);
292 add_timer(&priv->eee_ctrl_timer);
294 priv->hw->mac->set_eee_timer(priv->ioaddr,
295 STMMAC_DEFAULT_LIT_LS_TIMER,
298 pr_info("stmmac: Energy-Efficient Ethernet initialized\n");
306 static void stmmac_eee_adjust(struct stmmac_priv *priv)
308 /* When the EEE has been already initialised we have to
309 * modify the PLS bit in the LPI ctrl & status reg according
310 * to the PHY link status. For this reason.
312 if (priv->eee_enabled)
313 priv->hw->mac->set_eee_pls(priv->ioaddr, priv->phydev->link);
316 /* stmmac_get_tx_hwtstamp:
317 * @priv : pointer to private device structure.
318 * @entry : descriptor index to be used.
319 * @skb : the socket buffer
321 * This function will read timestamp from the descriptor & pass it to stack.
322 * and also perform some sanity checks.
324 static void stmmac_get_tx_hwtstamp(struct stmmac_priv *priv,
328 struct skb_shared_hwtstamps shhwtstamp;
332 if (!priv->hwts_tx_en)
335 /* if skb doesn't support hw tstamp */
336 if (likely(!(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)))
340 desc = (priv->dma_etx + entry);
342 desc = (priv->dma_tx + entry);
344 /* check tx tstamp status */
345 if (!priv->hw->desc->get_tx_timestamp_status((struct dma_desc *)desc))
348 /* get the valid tstamp */
349 ns = priv->hw->desc->get_timestamp(desc, priv->adv_ts);
351 memset(&shhwtstamp, 0, sizeof(struct skb_shared_hwtstamps));
352 shhwtstamp.hwtstamp = ns_to_ktime(ns);
353 /* pass tstamp to stack */
354 skb_tstamp_tx(skb, &shhwtstamp);
359 /* stmmac_get_rx_hwtstamp:
360 * @priv : pointer to private device structure.
361 * @entry : descriptor index to be used.
362 * @skb : the socket buffer
364 * This function will read received packet's timestamp from the descriptor
365 * and pass it to stack. It also perform some sanity checks.
367 static void stmmac_get_rx_hwtstamp(struct stmmac_priv *priv,
371 struct skb_shared_hwtstamps *shhwtstamp = NULL;
375 if (!priv->hwts_rx_en)
379 desc = (priv->dma_erx + entry);
381 desc = (priv->dma_rx + entry);
383 /* if rx tstamp is not valid */
384 if (!priv->hw->desc->get_rx_timestamp_status(desc, priv->adv_ts))
387 /* get valid tstamp */
388 ns = priv->hw->desc->get_timestamp(desc, priv->adv_ts);
389 shhwtstamp = skb_hwtstamps(skb);
390 memset(shhwtstamp, 0, sizeof(struct skb_shared_hwtstamps));
391 shhwtstamp->hwtstamp = ns_to_ktime(ns);
395 * stmmac_hwtstamp_ioctl - control hardware timestamping.
396 * @dev: device pointer.
397 * @ifr: An IOCTL specefic structure, that can contain a pointer to
398 * a proprietary structure used to pass information to the driver.
400 * This function configures the MAC to enable/disable both outgoing(TX)
401 * and incoming(RX) packets time stamping based on user input.
403 * 0 on success and an appropriate -ve integer on failure.
405 static int stmmac_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
407 struct stmmac_priv *priv = netdev_priv(dev);
408 struct hwtstamp_config config;
413 u32 ptp_over_ipv4_udp = 0;
414 u32 ptp_over_ipv6_udp = 0;
415 u32 ptp_over_ethernet = 0;
416 u32 snap_type_sel = 0;
417 u32 ts_master_en = 0;
421 if (!(priv->dma_cap.time_stamp || priv->adv_ts)) {
422 netdev_alert(priv->dev, "No support for HW time stamping\n");
423 priv->hwts_tx_en = 0;
424 priv->hwts_rx_en = 0;
429 if (copy_from_user(&config, ifr->ifr_data,
430 sizeof(struct hwtstamp_config)))
433 pr_debug("%s config flags:0x%x, tx_type:0x%x, rx_filter:0x%x\n",
434 __func__, config.flags, config.tx_type, config.rx_filter);
436 /* reserved for future extensions */
440 switch (config.tx_type) {
441 case HWTSTAMP_TX_OFF:
442 priv->hwts_tx_en = 0;
445 priv->hwts_tx_en = 1;
452 switch (config.rx_filter) {
453 /* time stamp no incoming packet at all */
454 case HWTSTAMP_FILTER_NONE:
455 config.rx_filter = HWTSTAMP_FILTER_NONE;
458 /* PTP v1, UDP, any kind of event packet */
459 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
460 config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
461 /* take time stamp for all event messages */
462 snap_type_sel = PTP_TCR_SNAPTYPSEL_1;
464 ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
465 ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
468 /* PTP v1, UDP, Sync packet */
469 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
470 config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_SYNC;
471 /* take time stamp for SYNC messages only */
472 ts_event_en = PTP_TCR_TSEVNTENA;
474 ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
475 ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
478 /* PTP v1, UDP, Delay_req packet */
479 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
480 config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ;
481 /* take time stamp for Delay_Req messages only */
482 ts_master_en = PTP_TCR_TSMSTRENA;
483 ts_event_en = PTP_TCR_TSEVNTENA;
485 ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
486 ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
489 /* PTP v2, UDP, any kind of event packet */
490 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
491 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT;
492 ptp_v2 = PTP_TCR_TSVER2ENA;
493 /* take time stamp for all event messages */
494 snap_type_sel = PTP_TCR_SNAPTYPSEL_1;
496 ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
497 ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
500 /* PTP v2, UDP, Sync packet */
501 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
502 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_SYNC;
503 ptp_v2 = PTP_TCR_TSVER2ENA;
504 /* take time stamp for SYNC messages only */
505 ts_event_en = PTP_TCR_TSEVNTENA;
507 ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
508 ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
511 /* PTP v2, UDP, Delay_req packet */
512 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
513 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ;
514 ptp_v2 = PTP_TCR_TSVER2ENA;
515 /* take time stamp for Delay_Req messages only */
516 ts_master_en = PTP_TCR_TSMSTRENA;
517 ts_event_en = PTP_TCR_TSEVNTENA;
519 ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
520 ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
523 /* PTP v2/802.AS1, any layer, any kind of event packet */
524 case HWTSTAMP_FILTER_PTP_V2_EVENT:
525 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
526 ptp_v2 = PTP_TCR_TSVER2ENA;
527 /* take time stamp for all event messages */
528 snap_type_sel = PTP_TCR_SNAPTYPSEL_1;
530 ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
531 ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
532 ptp_over_ethernet = PTP_TCR_TSIPENA;
535 /* PTP v2/802.AS1, any layer, Sync packet */
536 case HWTSTAMP_FILTER_PTP_V2_SYNC:
537 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_SYNC;
538 ptp_v2 = PTP_TCR_TSVER2ENA;
539 /* take time stamp for SYNC messages only */
540 ts_event_en = PTP_TCR_TSEVNTENA;
542 ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
543 ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
544 ptp_over_ethernet = PTP_TCR_TSIPENA;
547 /* PTP v2/802.AS1, any layer, Delay_req packet */
548 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
549 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_DELAY_REQ;
550 ptp_v2 = PTP_TCR_TSVER2ENA;
551 /* take time stamp for Delay_Req messages only */
552 ts_master_en = PTP_TCR_TSMSTRENA;
553 ts_event_en = PTP_TCR_TSEVNTENA;
555 ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
556 ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
557 ptp_over_ethernet = PTP_TCR_TSIPENA;
560 /* time stamp any incoming packet */
561 case HWTSTAMP_FILTER_ALL:
562 config.rx_filter = HWTSTAMP_FILTER_ALL;
563 tstamp_all = PTP_TCR_TSENALL;
570 switch (config.rx_filter) {
571 case HWTSTAMP_FILTER_NONE:
572 config.rx_filter = HWTSTAMP_FILTER_NONE;
575 /* PTP v1, UDP, any kind of event packet */
576 config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
580 priv->hwts_rx_en = ((config.rx_filter == HWTSTAMP_FILTER_NONE) ? 0 : 1);
582 if (!priv->hwts_tx_en && !priv->hwts_rx_en)
583 priv->hw->ptp->config_hw_tstamping(priv->ioaddr, 0);
585 value = (PTP_TCR_TSENA | PTP_TCR_TSCFUPDT | PTP_TCR_TSCTRLSSR |
586 tstamp_all | ptp_v2 | ptp_over_ethernet |
587 ptp_over_ipv6_udp | ptp_over_ipv4_udp | ts_event_en |
588 ts_master_en | snap_type_sel);
590 priv->hw->ptp->config_hw_tstamping(priv->ioaddr, value);
592 /* program Sub Second Increment reg */
593 priv->hw->ptp->config_sub_second_increment(priv->ioaddr);
595 /* calculate default added value:
597 * addend = (2^32)/freq_div_ratio;
598 * where, freq_div_ratio = STMMAC_SYSCLOCK/50MHz
599 * hence, addend = ((2^32) * 50MHz)/STMMAC_SYSCLOCK;
600 * NOTE: STMMAC_SYSCLOCK should be >= 50MHz to
601 * achive 20ns accuracy.
603 * 2^x * y == (y << x), hence
604 * 2^32 * 50000000 ==> (50000000 << 32)
606 temp = (u64)(50000000ULL << 32);
607 priv->default_addend = div_u64(temp, STMMAC_SYSCLOCK);
608 priv->hw->ptp->config_addend(priv->ioaddr,
609 priv->default_addend);
611 /* initialize system time */
612 getnstimeofday(&now);
613 priv->hw->ptp->init_systime(priv->ioaddr, now.tv_sec,
617 return copy_to_user(ifr->ifr_data, &config,
618 sizeof(struct hwtstamp_config)) ? -EFAULT : 0;
621 static void stmmac_init_ptp(struct stmmac_priv *priv)
623 if (priv->dma_cap.time_stamp) {
624 pr_debug("IEEE 1588-2002 Time Stamp supported\n");
627 if (priv->dma_cap.atime_stamp && priv->extend_desc) {
628 pr_debug("IEEE 1588-2008 Advanced Time Stamp supported\n");
632 priv->hw->ptp = &stmmac_ptp;
633 priv->hwts_tx_en = 0;
634 priv->hwts_rx_en = 0;
639 * @dev: net device structure
640 * Description: it adjusts the link parameters.
642 static void stmmac_adjust_link(struct net_device *dev)
644 struct stmmac_priv *priv = netdev_priv(dev);
645 struct phy_device *phydev = priv->phydev;
648 unsigned int fc = priv->flow_ctrl, pause_time = priv->pause;
653 DBG(probe, DEBUG, "stmmac_adjust_link: called. address %d link %d\n",
654 phydev->addr, phydev->link);
656 spin_lock_irqsave(&priv->lock, flags);
659 u32 ctrl = readl(priv->ioaddr + MAC_CTRL_REG);
661 /* Now we make sure that we can be in full duplex mode.
662 * If not, we operate in half-duplex mode. */
663 if (phydev->duplex != priv->oldduplex) {
665 if (!(phydev->duplex))
666 ctrl &= ~priv->hw->link.duplex;
668 ctrl |= priv->hw->link.duplex;
669 priv->oldduplex = phydev->duplex;
671 /* Flow Control operation */
673 priv->hw->mac->flow_ctrl(priv->ioaddr, phydev->duplex,
676 if (phydev->speed != priv->speed) {
678 switch (phydev->speed) {
680 if (likely(priv->plat->has_gmac))
681 ctrl &= ~priv->hw->link.port;
682 stmmac_hw_fix_mac_speed(priv);
686 if (priv->plat->has_gmac) {
687 ctrl |= priv->hw->link.port;
688 if (phydev->speed == SPEED_100) {
689 ctrl |= priv->hw->link.speed;
691 ctrl &= ~(priv->hw->link.speed);
694 ctrl &= ~priv->hw->link.port;
696 stmmac_hw_fix_mac_speed(priv);
699 if (netif_msg_link(priv))
700 pr_warning("%s: Speed (%d) is not 10"
701 " or 100!\n", dev->name, phydev->speed);
705 priv->speed = phydev->speed;
708 writel(ctrl, priv->ioaddr + MAC_CTRL_REG);
710 if (!priv->oldlink) {
714 } else if (priv->oldlink) {
718 priv->oldduplex = -1;
721 if (new_state && netif_msg_link(priv))
722 phy_print_status(phydev);
724 stmmac_eee_adjust(priv);
726 spin_unlock_irqrestore(&priv->lock, flags);
728 DBG(probe, DEBUG, "stmmac_adjust_link: exiting\n");
731 static void stmmac_check_pcs_mode(struct stmmac_priv *priv)
733 int interface = priv->plat->interface;
735 if (priv->dma_cap.pcs) {
736 if ((interface & PHY_INTERFACE_MODE_RGMII) ||
737 (interface & PHY_INTERFACE_MODE_RGMII_ID) ||
738 (interface & PHY_INTERFACE_MODE_RGMII_RXID) ||
739 (interface & PHY_INTERFACE_MODE_RGMII_TXID)) {
740 pr_debug("STMMAC: PCS RGMII support enable\n");
741 priv->pcs = STMMAC_PCS_RGMII;
742 } else if (interface & PHY_INTERFACE_MODE_SGMII) {
743 pr_debug("STMMAC: PCS SGMII support enable\n");
744 priv->pcs = STMMAC_PCS_SGMII;
750 * stmmac_init_phy - PHY initialization
751 * @dev: net device structure
752 * Description: it initializes the driver's PHY state, and attaches the PHY
757 static int stmmac_init_phy(struct net_device *dev)
759 struct stmmac_priv *priv = netdev_priv(dev);
760 struct phy_device *phydev;
761 char phy_id_fmt[MII_BUS_ID_SIZE + 3];
762 char bus_id[MII_BUS_ID_SIZE];
763 int interface = priv->plat->interface;
766 priv->oldduplex = -1;
768 if (priv->plat->phy_bus_name)
769 snprintf(bus_id, MII_BUS_ID_SIZE, "%s-%x",
770 priv->plat->phy_bus_name, priv->plat->bus_id);
772 snprintf(bus_id, MII_BUS_ID_SIZE, "stmmac-%x",
775 snprintf(phy_id_fmt, MII_BUS_ID_SIZE + 3, PHY_ID_FMT, bus_id,
776 priv->plat->phy_addr);
777 pr_debug("stmmac_init_phy: trying to attach to %s\n", phy_id_fmt);
779 phydev = phy_connect(dev, phy_id_fmt, &stmmac_adjust_link, interface);
781 if (IS_ERR(phydev)) {
782 pr_err("%s: Could not attach to PHY\n", dev->name);
783 return PTR_ERR(phydev);
786 /* Stop Advertising 1000BASE Capability if interface is not GMII */
787 if ((interface == PHY_INTERFACE_MODE_MII) ||
788 (interface == PHY_INTERFACE_MODE_RMII))
789 phydev->advertising &= ~(SUPPORTED_1000baseT_Half |
790 SUPPORTED_1000baseT_Full);
793 * Broken HW is sometimes missing the pull-up resistor on the
794 * MDIO line, which results in reads to non-existent devices returning
795 * 0 rather than 0xffff. Catch this here and treat 0 as a non-existent
797 * Note: phydev->phy_id is the result of reading the UID PHY registers.
799 if (phydev->phy_id == 0) {
800 phy_disconnect(phydev);
803 pr_debug("stmmac_init_phy: %s: attached to PHY (UID 0x%x)"
804 " Link = %d\n", dev->name, phydev->phy_id, phydev->link);
806 priv->phydev = phydev;
812 * stmmac_display_ring
813 * @p: pointer to the ring.
814 * @size: size of the ring.
815 * Description: display the control/status and buffer descriptors.
817 static void stmmac_display_ring(void *head, int size, int extend_desc)
820 struct dma_extended_desc *ep = (struct dma_extended_desc *) head;
821 struct dma_desc *p = (struct dma_desc *) head;
823 for (i = 0; i < size; i++) {
827 pr_info("%d [0x%x]: 0x%x 0x%x 0x%x 0x%x\n",
828 i, (unsigned int) virt_to_phys(ep),
829 (unsigned int) x, (unsigned int) (x >> 32),
830 ep->basic.des2, ep->basic.des3);
834 pr_info("%d [0x%x]: 0x%x 0x%x 0x%x 0x%x",
835 i, (unsigned int) virt_to_phys(p),
836 (unsigned int) x, (unsigned int) (x >> 32),
844 static void stmmac_display_rings(struct stmmac_priv *priv)
846 unsigned int txsize = priv->dma_tx_size;
847 unsigned int rxsize = priv->dma_rx_size;
849 if (priv->extend_desc) {
850 pr_info("Extended RX descriptor ring:\n");
851 stmmac_display_ring((void *) priv->dma_erx, rxsize, 1);
852 pr_info("Extended TX descriptor ring:\n");
853 stmmac_display_ring((void *) priv->dma_etx, txsize, 1);
855 pr_info("RX descriptor ring:\n");
856 stmmac_display_ring((void *)priv->dma_rx, rxsize, 0);
857 pr_info("TX descriptor ring:\n");
858 stmmac_display_ring((void *)priv->dma_tx, txsize, 0);
862 static int stmmac_set_bfsize(int mtu, int bufsize)
866 if (mtu >= BUF_SIZE_4KiB)
868 else if (mtu >= BUF_SIZE_2KiB)
870 else if (mtu >= DMA_BUFFER_SIZE)
873 ret = DMA_BUFFER_SIZE;
878 static void stmmac_clear_descriptors(struct stmmac_priv *priv)
881 unsigned int txsize = priv->dma_tx_size;
882 unsigned int rxsize = priv->dma_rx_size;
884 /* Clear the Rx/Tx descriptors */
885 for (i = 0; i < rxsize; i++)
886 if (priv->extend_desc)
887 priv->hw->desc->init_rx_desc(&priv->dma_erx[i].basic,
888 priv->use_riwt, priv->mode,
891 priv->hw->desc->init_rx_desc(&priv->dma_rx[i],
892 priv->use_riwt, priv->mode,
894 for (i = 0; i < txsize; i++)
895 if (priv->extend_desc)
896 priv->hw->desc->init_tx_desc(&priv->dma_etx[i].basic,
900 priv->hw->desc->init_tx_desc(&priv->dma_tx[i],
905 static int stmmac_init_rx_buffers(struct stmmac_priv *priv, struct dma_desc *p,
910 skb = __netdev_alloc_skb(priv->dev, priv->dma_buf_sz + NET_IP_ALIGN,
912 if (unlikely(skb == NULL)) {
913 pr_err("%s: Rx init fails; skb is NULL\n", __func__);
916 skb_reserve(skb, NET_IP_ALIGN);
917 priv->rx_skbuff[i] = skb;
918 priv->rx_skbuff_dma[i] = dma_map_single(priv->device, skb->data,
922 p->des2 = priv->rx_skbuff_dma[i];
924 if ((priv->mode == STMMAC_RING_MODE) &&
925 (priv->dma_buf_sz == BUF_SIZE_16KiB))
926 priv->hw->ring->init_desc3(p);
932 * init_dma_desc_rings - init the RX/TX descriptor rings
933 * @dev: net device structure
934 * Description: this function initializes the DMA RX/TX descriptors
935 * and allocates the socket buffers. It suppors the chained and ring
938 static void init_dma_desc_rings(struct net_device *dev)
941 struct stmmac_priv *priv = netdev_priv(dev);
942 unsigned int txsize = priv->dma_tx_size;
943 unsigned int rxsize = priv->dma_rx_size;
944 unsigned int bfsize = 0;
946 /* Set the max buffer size according to the DESC mode
947 * and the MTU. Note that RING mode allows 16KiB bsize. */
948 if (priv->mode == STMMAC_RING_MODE)
949 bfsize = priv->hw->ring->set_16kib_bfsize(dev->mtu);
951 if (bfsize < BUF_SIZE_16KiB)
952 bfsize = stmmac_set_bfsize(dev->mtu, priv->dma_buf_sz);
954 DBG(probe, INFO, "stmmac: txsize %d, rxsize %d, bfsize %d\n",
955 txsize, rxsize, bfsize);
957 if (priv->extend_desc) {
958 priv->dma_erx = dma_alloc_coherent(priv->device, rxsize *
963 priv->dma_etx = dma_alloc_coherent(priv->device, txsize *
968 if ((!priv->dma_erx) || (!priv->dma_etx))
971 priv->dma_rx = dma_alloc_coherent(priv->device, rxsize *
972 sizeof(struct dma_desc),
975 priv->dma_tx = dma_alloc_coherent(priv->device, txsize *
976 sizeof(struct dma_desc),
979 if ((!priv->dma_rx) || (!priv->dma_tx))
983 priv->rx_skbuff_dma = kmalloc_array(rxsize, sizeof(dma_addr_t),
985 priv->rx_skbuff = kmalloc_array(rxsize, sizeof(struct sk_buff *),
987 priv->tx_skbuff_dma = kmalloc_array(txsize, sizeof(dma_addr_t),
989 priv->tx_skbuff = kmalloc_array(txsize, sizeof(struct sk_buff *),
991 if (netif_msg_drv(priv))
992 pr_debug("(%s) dma_rx_phy=0x%08x dma_tx_phy=0x%08x\n", __func__,
993 (u32) priv->dma_rx_phy, (u32) priv->dma_tx_phy);
995 /* RX INITIALIZATION */
996 DBG(probe, INFO, "stmmac: SKB addresses:\nskb\t\tskb data\tdma data\n");
997 for (i = 0; i < rxsize; i++) {
999 if (priv->extend_desc)
1000 p = &((priv->dma_erx + i)->basic);
1002 p = priv->dma_rx + i;
1004 if (stmmac_init_rx_buffers(priv, p, i))
1007 DBG(probe, INFO, "[%p]\t[%p]\t[%x]\n", priv->rx_skbuff[i],
1008 priv->rx_skbuff[i]->data, priv->rx_skbuff_dma[i]);
1011 priv->dirty_rx = (unsigned int)(i - rxsize);
1012 priv->dma_buf_sz = bfsize;
1015 /* Setup the chained descriptor addresses */
1016 if (priv->mode == STMMAC_CHAIN_MODE) {
1017 if (priv->extend_desc) {
1018 priv->hw->chain->init(priv->dma_erx, priv->dma_rx_phy,
1020 priv->hw->chain->init(priv->dma_etx, priv->dma_tx_phy,
1023 priv->hw->chain->init(priv->dma_rx, priv->dma_rx_phy,
1025 priv->hw->chain->init(priv->dma_tx, priv->dma_tx_phy,
1030 /* TX INITIALIZATION */
1031 for (i = 0; i < txsize; i++) {
1033 if (priv->extend_desc)
1034 p = &((priv->dma_etx + i)->basic);
1036 p = priv->dma_tx + i;
1038 priv->tx_skbuff_dma[i] = 0;
1039 priv->tx_skbuff[i] = NULL;
1045 stmmac_clear_descriptors(priv);
1047 if (netif_msg_hw(priv))
1048 stmmac_display_rings(priv);
1051 static void dma_free_rx_skbufs(struct stmmac_priv *priv)
1055 for (i = 0; i < priv->dma_rx_size; i++) {
1056 if (priv->rx_skbuff[i]) {
1057 dma_unmap_single(priv->device, priv->rx_skbuff_dma[i],
1058 priv->dma_buf_sz, DMA_FROM_DEVICE);
1059 dev_kfree_skb_any(priv->rx_skbuff[i]);
1061 priv->rx_skbuff[i] = NULL;
1065 static void dma_free_tx_skbufs(struct stmmac_priv *priv)
1069 for (i = 0; i < priv->dma_tx_size; i++) {
1070 if (priv->tx_skbuff[i] != NULL) {
1072 if (priv->extend_desc)
1073 p = &((priv->dma_etx + i)->basic);
1075 p = priv->dma_tx + i;
1077 if (priv->tx_skbuff_dma[i])
1078 dma_unmap_single(priv->device,
1079 priv->tx_skbuff_dma[i],
1080 priv->hw->desc->get_tx_len(p),
1082 dev_kfree_skb_any(priv->tx_skbuff[i]);
1083 priv->tx_skbuff[i] = NULL;
1084 priv->tx_skbuff_dma[i] = 0;
1089 static void free_dma_desc_resources(struct stmmac_priv *priv)
1091 /* Release the DMA TX/RX socket buffers */
1092 dma_free_rx_skbufs(priv);
1093 dma_free_tx_skbufs(priv);
1095 /* Free the region of consistent memory previously allocated for
1097 if (!priv->extend_desc) {
1098 dma_free_coherent(priv->device,
1099 priv->dma_tx_size * sizeof(struct dma_desc),
1100 priv->dma_tx, priv->dma_tx_phy);
1101 dma_free_coherent(priv->device,
1102 priv->dma_rx_size * sizeof(struct dma_desc),
1103 priv->dma_rx, priv->dma_rx_phy);
1105 dma_free_coherent(priv->device, priv->dma_tx_size *
1106 sizeof(struct dma_extended_desc),
1107 priv->dma_etx, priv->dma_tx_phy);
1108 dma_free_coherent(priv->device, priv->dma_rx_size *
1109 sizeof(struct dma_extended_desc),
1110 priv->dma_erx, priv->dma_rx_phy);
1112 kfree(priv->rx_skbuff_dma);
1113 kfree(priv->rx_skbuff);
1114 kfree(priv->tx_skbuff_dma);
1115 kfree(priv->tx_skbuff);
1119 * stmmac_dma_operation_mode - HW DMA operation mode
1120 * @priv : pointer to the private device structure.
1121 * Description: it sets the DMA operation mode: tx/rx DMA thresholds
1122 * or Store-And-Forward capability.
1124 static void stmmac_dma_operation_mode(struct stmmac_priv *priv)
1126 if (likely(priv->plat->force_sf_dma_mode ||
1127 ((priv->plat->tx_coe) && (!priv->no_csum_insertion)))) {
1129 * In case of GMAC, SF mode can be enabled
1130 * to perform the TX COE in HW. This depends on:
1131 * 1) TX COE if actually supported
1132 * 2) There is no bugged Jumbo frame support
1133 * that needs to not insert csum in the TDES.
1135 priv->hw->dma->dma_mode(priv->ioaddr,
1136 SF_DMA_MODE, SF_DMA_MODE);
1139 priv->hw->dma->dma_mode(priv->ioaddr, tc, SF_DMA_MODE);
1144 * @priv: private data pointer
1145 * Description: it reclaims resources after transmission completes.
1147 static void stmmac_tx_clean(struct stmmac_priv *priv)
1149 unsigned int txsize = priv->dma_tx_size;
1151 spin_lock(&priv->tx_lock);
1153 priv->xstats.tx_clean++;
1155 while (priv->dirty_tx != priv->cur_tx) {
1157 unsigned int entry = priv->dirty_tx % txsize;
1158 struct sk_buff *skb = priv->tx_skbuff[entry];
1161 if (priv->extend_desc)
1162 p = (struct dma_desc *) (priv->dma_etx + entry);
1164 p = priv->dma_tx + entry;
1166 /* Check if the descriptor is owned by the DMA. */
1167 if (priv->hw->desc->get_tx_owner(p))
1170 /* Verify tx error by looking at the last segment. */
1171 last = priv->hw->desc->get_tx_ls(p);
1174 priv->hw->desc->tx_status(&priv->dev->stats,
1177 if (likely(tx_error == 0)) {
1178 priv->dev->stats.tx_packets++;
1179 priv->xstats.tx_pkt_n++;
1181 priv->dev->stats.tx_errors++;
1183 stmmac_get_tx_hwtstamp(priv, entry, skb);
1185 TX_DBG("%s: curr %d, dirty %d\n", __func__,
1186 priv->cur_tx, priv->dirty_tx);
1188 if (likely(priv->tx_skbuff_dma[entry])) {
1189 dma_unmap_single(priv->device,
1190 priv->tx_skbuff_dma[entry],
1191 priv->hw->desc->get_tx_len(p),
1193 priv->tx_skbuff_dma[entry] = 0;
1195 priv->hw->ring->clean_desc3(priv, p);
1197 if (likely(skb != NULL)) {
1199 priv->tx_skbuff[entry] = NULL;
1202 priv->hw->desc->release_tx_desc(p, priv->mode);
1206 if (unlikely(netif_queue_stopped(priv->dev) &&
1207 stmmac_tx_avail(priv) > STMMAC_TX_THRESH(priv))) {
1208 netif_tx_lock(priv->dev);
1209 if (netif_queue_stopped(priv->dev) &&
1210 stmmac_tx_avail(priv) > STMMAC_TX_THRESH(priv)) {
1211 TX_DBG("%s: restart transmit\n", __func__);
1212 netif_wake_queue(priv->dev);
1214 netif_tx_unlock(priv->dev);
1217 if ((priv->eee_enabled) && (!priv->tx_path_in_lpi_mode)) {
1218 stmmac_enable_eee_mode(priv);
1219 mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_TIMER(eee_timer));
1221 spin_unlock(&priv->tx_lock);
1224 static inline void stmmac_enable_dma_irq(struct stmmac_priv *priv)
1226 priv->hw->dma->enable_dma_irq(priv->ioaddr);
1229 static inline void stmmac_disable_dma_irq(struct stmmac_priv *priv)
1231 priv->hw->dma->disable_dma_irq(priv->ioaddr);
1237 * @priv: pointer to the private device structure
1238 * Description: it cleans the descriptors and restarts the transmission
1239 * in case of errors.
1241 static void stmmac_tx_err(struct stmmac_priv *priv)
1244 int txsize = priv->dma_tx_size;
1245 netif_stop_queue(priv->dev);
1247 priv->hw->dma->stop_tx(priv->ioaddr);
1248 dma_free_tx_skbufs(priv);
1249 for (i = 0; i < txsize; i++)
1250 if (priv->extend_desc)
1251 priv->hw->desc->init_tx_desc(&priv->dma_etx[i].basic,
1255 priv->hw->desc->init_tx_desc(&priv->dma_tx[i],
1260 priv->hw->dma->start_tx(priv->ioaddr);
1262 priv->dev->stats.tx_errors++;
1263 netif_wake_queue(priv->dev);
1266 static void stmmac_dma_interrupt(struct stmmac_priv *priv)
1270 status = priv->hw->dma->dma_interrupt(priv->ioaddr, &priv->xstats);
1271 if (likely((status & handle_rx)) || (status & handle_tx)) {
1272 if (likely(napi_schedule_prep(&priv->napi))) {
1273 stmmac_disable_dma_irq(priv);
1274 __napi_schedule(&priv->napi);
1277 if (unlikely(status & tx_hard_error_bump_tc)) {
1278 /* Try to bump up the dma threshold on this failure */
1279 if (unlikely(tc != SF_DMA_MODE) && (tc <= 256)) {
1281 priv->hw->dma->dma_mode(priv->ioaddr, tc, SF_DMA_MODE);
1282 priv->xstats.threshold = tc;
1284 } else if (unlikely(status == tx_hard_error))
1285 stmmac_tx_err(priv);
1288 static void stmmac_mmc_setup(struct stmmac_priv *priv)
1290 unsigned int mode = MMC_CNTRL_RESET_ON_READ | MMC_CNTRL_COUNTER_RESET |
1291 MMC_CNTRL_PRESET | MMC_CNTRL_FULL_HALF_PRESET;
1293 /* Mask MMC irq, counters are managed in SW and registers
1294 * are cleared on each READ eventually. */
1295 dwmac_mmc_intr_all_mask(priv->ioaddr);
1297 if (priv->dma_cap.rmon) {
1298 dwmac_mmc_ctrl(priv->ioaddr, mode);
1299 memset(&priv->mmc, 0, sizeof(struct stmmac_counters));
1301 pr_info(" No MAC Management Counters available\n");
1304 static u32 stmmac_get_synopsys_id(struct stmmac_priv *priv)
1306 u32 hwid = priv->hw->synopsys_uid;
1308 /* Only check valid Synopsys Id because old MAC chips
1309 * have no HW registers where get the ID */
1311 u32 uid = ((hwid & 0x0000ff00) >> 8);
1312 u32 synid = (hwid & 0x000000ff);
1314 pr_info("stmmac - user ID: 0x%x, Synopsys ID: 0x%x\n",
1323 * stmmac_selec_desc_mode
1324 * @priv : private structure
1325 * Description: select the Enhanced/Alternate or Normal descriptors
1327 static void stmmac_selec_desc_mode(struct stmmac_priv *priv)
1329 if (priv->plat->enh_desc) {
1330 pr_info(" Enhanced/Alternate descriptors\n");
1332 /* GMAC older than 3.50 has no extended descriptors */
1333 if (priv->synopsys_id >= DWMAC_CORE_3_50) {
1334 pr_info("\tEnabled extended descriptors\n");
1335 priv->extend_desc = 1;
1337 pr_warn("Extended descriptors not supported\n");
1339 priv->hw->desc = &enh_desc_ops;
1341 pr_info(" Normal descriptors\n");
1342 priv->hw->desc = &ndesc_ops;
1347 * stmmac_get_hw_features
1348 * @priv : private device pointer
1350 * new GMAC chip generations have a new register to indicate the
1351 * presence of the optional feature/functions.
1352 * This can be also used to override the value passed through the
1353 * platform and necessary for old MAC10/100 and GMAC chips.
1355 static int stmmac_get_hw_features(struct stmmac_priv *priv)
1359 if (priv->hw->dma->get_hw_feature) {
1360 hw_cap = priv->hw->dma->get_hw_feature(priv->ioaddr);
1362 priv->dma_cap.mbps_10_100 = (hw_cap & DMA_HW_FEAT_MIISEL);
1363 priv->dma_cap.mbps_1000 = (hw_cap & DMA_HW_FEAT_GMIISEL) >> 1;
1364 priv->dma_cap.half_duplex = (hw_cap & DMA_HW_FEAT_HDSEL) >> 2;
1365 priv->dma_cap.hash_filter = (hw_cap & DMA_HW_FEAT_HASHSEL) >> 4;
1366 priv->dma_cap.multi_addr =
1367 (hw_cap & DMA_HW_FEAT_ADDMACADRSEL) >> 5;
1368 priv->dma_cap.pcs = (hw_cap & DMA_HW_FEAT_PCSSEL) >> 6;
1369 priv->dma_cap.sma_mdio = (hw_cap & DMA_HW_FEAT_SMASEL) >> 8;
1370 priv->dma_cap.pmt_remote_wake_up =
1371 (hw_cap & DMA_HW_FEAT_RWKSEL) >> 9;
1372 priv->dma_cap.pmt_magic_frame =
1373 (hw_cap & DMA_HW_FEAT_MGKSEL) >> 10;
1375 priv->dma_cap.rmon = (hw_cap & DMA_HW_FEAT_MMCSEL) >> 11;
1377 priv->dma_cap.time_stamp =
1378 (hw_cap & DMA_HW_FEAT_TSVER1SEL) >> 12;
1380 priv->dma_cap.atime_stamp =
1381 (hw_cap & DMA_HW_FEAT_TSVER2SEL) >> 13;
1382 /* 802.3az - Energy-Efficient Ethernet (EEE) */
1383 priv->dma_cap.eee = (hw_cap & DMA_HW_FEAT_EEESEL) >> 14;
1384 priv->dma_cap.av = (hw_cap & DMA_HW_FEAT_AVSEL) >> 15;
1385 /* TX and RX csum */
1386 priv->dma_cap.tx_coe = (hw_cap & DMA_HW_FEAT_TXCOESEL) >> 16;
1387 priv->dma_cap.rx_coe_type1 =
1388 (hw_cap & DMA_HW_FEAT_RXTYP1COE) >> 17;
1389 priv->dma_cap.rx_coe_type2 =
1390 (hw_cap & DMA_HW_FEAT_RXTYP2COE) >> 18;
1391 priv->dma_cap.rxfifo_over_2048 =
1392 (hw_cap & DMA_HW_FEAT_RXFIFOSIZE) >> 19;
1393 /* TX and RX number of channels */
1394 priv->dma_cap.number_rx_channel =
1395 (hw_cap & DMA_HW_FEAT_RXCHCNT) >> 20;
1396 priv->dma_cap.number_tx_channel =
1397 (hw_cap & DMA_HW_FEAT_TXCHCNT) >> 22;
1398 /* Alternate (enhanced) DESC mode*/
1399 priv->dma_cap.enh_desc =
1400 (hw_cap & DMA_HW_FEAT_ENHDESSEL) >> 24;
1406 static void stmmac_check_ether_addr(struct stmmac_priv *priv)
1408 /* verify if the MAC address is valid, in case of failures it
1409 * generates a random MAC address */
1410 if (!is_valid_ether_addr(priv->dev->dev_addr)) {
1411 priv->hw->mac->get_umac_addr((void __iomem *)
1412 priv->dev->base_addr,
1413 priv->dev->dev_addr, 0);
1414 if (!is_valid_ether_addr(priv->dev->dev_addr))
1415 eth_hw_addr_random(priv->dev);
1417 pr_warning("%s: device MAC address %pM\n", priv->dev->name,
1418 priv->dev->dev_addr);
1421 static int stmmac_init_dma_engine(struct stmmac_priv *priv)
1423 int pbl = DEFAULT_DMA_PBL, fixed_burst = 0, burst_len = 0;
1424 int mixed_burst = 0;
1427 /* Some DMA parameters can be passed from the platform;
1428 * in case of these are not passed we keep a default
1429 * (good for all the chips) and init the DMA! */
1430 if (priv->plat->dma_cfg) {
1431 pbl = priv->plat->dma_cfg->pbl;
1432 fixed_burst = priv->plat->dma_cfg->fixed_burst;
1433 mixed_burst = priv->plat->dma_cfg->mixed_burst;
1434 burst_len = priv->plat->dma_cfg->burst_len;
1437 if (priv->extend_desc && (priv->mode == STMMAC_RING_MODE))
1440 return priv->hw->dma->init(priv->ioaddr, pbl, fixed_burst, mixed_burst,
1441 burst_len, priv->dma_tx_phy,
1442 priv->dma_rx_phy, atds);
1447 * @data: data pointer
1449 * This is the timer handler to directly invoke the stmmac_tx_clean.
1451 static void stmmac_tx_timer(unsigned long data)
1453 struct stmmac_priv *priv = (struct stmmac_priv *)data;
1455 stmmac_tx_clean(priv);
1460 * @priv: private data structure
1462 * This inits the transmit coalesce parameters: i.e. timer rate,
1463 * timer handler and default threshold used for enabling the
1464 * interrupt on completion bit.
1466 static void stmmac_init_tx_coalesce(struct stmmac_priv *priv)
1468 priv->tx_coal_frames = STMMAC_TX_FRAMES;
1469 priv->tx_coal_timer = STMMAC_COAL_TX_TIMER;
1470 init_timer(&priv->txtimer);
1471 priv->txtimer.expires = STMMAC_COAL_TIMER(priv->tx_coal_timer);
1472 priv->txtimer.data = (unsigned long)priv;
1473 priv->txtimer.function = stmmac_tx_timer;
1474 add_timer(&priv->txtimer);
1478 * stmmac_open - open entry point of the driver
1479 * @dev : pointer to the device structure.
1481 * This function is the open entry point of the driver.
1483 * 0 on success and an appropriate (-)ve integer as defined in errno.h
1486 static int stmmac_open(struct net_device *dev)
1488 struct stmmac_priv *priv = netdev_priv(dev);
1491 clk_prepare_enable(priv->stmmac_clk);
1493 stmmac_check_ether_addr(priv);
1496 ret = stmmac_init_phy(dev);
1498 pr_err("%s: Cannot attach to PHY (error: %d)\n",
1504 /* Create and initialize the TX/RX descriptors chains. */
1505 priv->dma_tx_size = STMMAC_ALIGN(dma_txsize);
1506 priv->dma_rx_size = STMMAC_ALIGN(dma_rxsize);
1507 priv->dma_buf_sz = STMMAC_ALIGN(buf_sz);
1508 init_dma_desc_rings(dev);
1510 /* DMA initialization and SW reset */
1511 ret = stmmac_init_dma_engine(priv);
1513 pr_err("%s: DMA initialization failed\n", __func__);
1517 /* Copy the MAC addr into the HW */
1518 priv->hw->mac->set_umac_addr(priv->ioaddr, dev->dev_addr, 0);
1520 /* If required, perform hw setup of the bus. */
1521 if (priv->plat->bus_setup)
1522 priv->plat->bus_setup(priv->ioaddr);
1524 /* Initialize the MAC Core */
1525 priv->hw->mac->core_init(priv->ioaddr);
1527 /* Request the IRQ lines */
1528 ret = request_irq(dev->irq, stmmac_interrupt,
1529 IRQF_SHARED, dev->name, dev);
1530 if (unlikely(ret < 0)) {
1531 pr_err("%s: ERROR: allocating the IRQ %d (error: %d)\n",
1532 __func__, dev->irq, ret);
1536 /* Request the Wake IRQ in case of another line is used for WoL */
1537 if (priv->wol_irq != dev->irq) {
1538 ret = request_irq(priv->wol_irq, stmmac_interrupt,
1539 IRQF_SHARED, dev->name, dev);
1540 if (unlikely(ret < 0)) {
1541 pr_err("%s: ERROR: allocating the ext WoL IRQ %d "
1542 "(error: %d)\n", __func__, priv->wol_irq, ret);
1543 goto open_error_wolirq;
1547 /* Request the IRQ lines */
1548 if (priv->lpi_irq != -ENXIO) {
1549 ret = request_irq(priv->lpi_irq, stmmac_interrupt, IRQF_SHARED,
1551 if (unlikely(ret < 0)) {
1552 pr_err("%s: ERROR: allocating the LPI IRQ %d (%d)\n",
1553 __func__, priv->lpi_irq, ret);
1554 goto open_error_lpiirq;
1558 /* Enable the MAC Rx/Tx */
1559 stmmac_set_mac(priv->ioaddr, true);
1561 /* Set the HW DMA mode and the COE */
1562 stmmac_dma_operation_mode(priv);
1564 /* Extra statistics */
1565 memset(&priv->xstats, 0, sizeof(struct stmmac_extra_stats));
1566 priv->xstats.threshold = tc;
1568 stmmac_mmc_setup(priv);
1570 stmmac_init_ptp(priv);
1572 #ifdef CONFIG_STMMAC_DEBUG_FS
1573 ret = stmmac_init_fs(dev);
1575 pr_warning("%s: failed debugFS registration\n", __func__);
1577 /* Start the ball rolling... */
1578 DBG(probe, DEBUG, "%s: DMA RX/TX processes started...\n", dev->name);
1579 priv->hw->dma->start_tx(priv->ioaddr);
1580 priv->hw->dma->start_rx(priv->ioaddr);
1582 /* Dump DMA/MAC registers */
1583 if (netif_msg_hw(priv)) {
1584 priv->hw->mac->dump_regs(priv->ioaddr);
1585 priv->hw->dma->dump_regs(priv->ioaddr);
1589 phy_start(priv->phydev);
1591 priv->tx_lpi_timer = STMMAC_DEFAULT_TWT_LS_TIMER;
1593 /* Using PCS we cannot dial with the phy registers at this stage
1594 * so we do not support extra feature like EEE.
1597 priv->eee_enabled = stmmac_eee_init(priv);
1599 stmmac_init_tx_coalesce(priv);
1601 if ((priv->use_riwt) && (priv->hw->dma->rx_watchdog)) {
1602 priv->rx_riwt = MAX_DMA_RIWT;
1603 priv->hw->dma->rx_watchdog(priv->ioaddr, MAX_DMA_RIWT);
1606 if (priv->pcs && priv->hw->mac->ctrl_ane)
1607 priv->hw->mac->ctrl_ane(priv->ioaddr, 0);
1609 napi_enable(&priv->napi);
1610 netif_start_queue(dev);
1615 if (priv->wol_irq != dev->irq)
1616 free_irq(priv->wol_irq, dev);
1619 free_irq(dev->irq, dev);
1623 phy_disconnect(priv->phydev);
1625 clk_disable_unprepare(priv->stmmac_clk);
1631 * stmmac_release - close entry point of the driver
1632 * @dev : device pointer.
1634 * This is the stop entry point of the driver.
1636 static int stmmac_release(struct net_device *dev)
1638 struct stmmac_priv *priv = netdev_priv(dev);
1640 if (priv->eee_enabled)
1641 del_timer_sync(&priv->eee_ctrl_timer);
1643 /* Stop and disconnect the PHY */
1645 phy_stop(priv->phydev);
1646 phy_disconnect(priv->phydev);
1647 priv->phydev = NULL;
1650 netif_stop_queue(dev);
1652 napi_disable(&priv->napi);
1654 del_timer_sync(&priv->txtimer);
1656 /* Free the IRQ lines */
1657 free_irq(dev->irq, dev);
1658 if (priv->wol_irq != dev->irq)
1659 free_irq(priv->wol_irq, dev);
1660 if (priv->lpi_irq != -ENXIO)
1661 free_irq(priv->lpi_irq, dev);
1663 /* Stop TX/RX DMA and clear the descriptors */
1664 priv->hw->dma->stop_tx(priv->ioaddr);
1665 priv->hw->dma->stop_rx(priv->ioaddr);
1667 /* Release and free the Rx/Tx resources */
1668 free_dma_desc_resources(priv);
1670 /* Disable the MAC Rx/Tx */
1671 stmmac_set_mac(priv->ioaddr, false);
1673 netif_carrier_off(dev);
1675 #ifdef CONFIG_STMMAC_DEBUG_FS
1678 clk_disable_unprepare(priv->stmmac_clk);
1685 * @skb : the socket buffer
1686 * @dev : device pointer
1687 * Description : Tx entry point of the driver.
1689 static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
1691 struct stmmac_priv *priv = netdev_priv(dev);
1692 unsigned int txsize = priv->dma_tx_size;
1694 int i, csum_insertion = 0, is_jumbo = 0;
1695 int nfrags = skb_shinfo(skb)->nr_frags;
1696 struct dma_desc *desc, *first;
1697 unsigned int nopaged_len = skb_headlen(skb);
1699 if (unlikely(stmmac_tx_avail(priv) < nfrags + 1)) {
1700 if (!netif_queue_stopped(dev)) {
1701 netif_stop_queue(dev);
1702 /* This is a hard error, log it. */
1703 pr_err("%s: BUG! Tx Ring full when queue awake\n",
1706 return NETDEV_TX_BUSY;
1709 spin_lock(&priv->tx_lock);
1711 if (priv->tx_path_in_lpi_mode)
1712 stmmac_disable_eee_mode(priv);
1714 entry = priv->cur_tx % txsize;
1716 #ifdef STMMAC_XMIT_DEBUG
1717 if ((skb->len > ETH_FRAME_LEN) || nfrags)
1718 pr_debug("stmmac xmit: [entry %d]\n"
1719 "\tskb addr %p - len: %d - nopaged_len: %d\n"
1720 "\tn_frags: %d - ip_summed: %d - %s gso\n"
1721 "\ttx_count_frames %d\n", entry,
1722 skb, skb->len, nopaged_len, nfrags, skb->ip_summed,
1723 !skb_is_gso(skb) ? "isn't" : "is",
1724 priv->tx_count_frames);
1727 csum_insertion = (skb->ip_summed == CHECKSUM_PARTIAL);
1729 if (priv->extend_desc)
1730 desc = (struct dma_desc *) (priv->dma_etx + entry);
1732 desc = priv->dma_tx + entry;
1736 #ifdef STMMAC_XMIT_DEBUG
1737 if ((nfrags > 0) || (skb->len > ETH_FRAME_LEN))
1738 pr_debug("\tskb len: %d, nopaged_len: %d,\n"
1739 "\t\tn_frags: %d, ip_summed: %d\n",
1740 skb->len, nopaged_len, nfrags, skb->ip_summed);
1742 priv->tx_skbuff[entry] = skb;
1744 /* To program the descriptors according to the size of the frame */
1745 if (priv->mode == STMMAC_RING_MODE) {
1746 is_jumbo = priv->hw->ring->is_jumbo_frm(skb->len,
1747 priv->plat->enh_desc);
1748 if (unlikely(is_jumbo))
1749 entry = priv->hw->ring->jumbo_frm(priv, skb,
1752 is_jumbo = priv->hw->chain->is_jumbo_frm(skb->len,
1753 priv->plat->enh_desc);
1754 if (unlikely(is_jumbo))
1755 entry = priv->hw->chain->jumbo_frm(priv, skb,
1758 if (likely(!is_jumbo)) {
1759 desc->des2 = dma_map_single(priv->device, skb->data,
1760 nopaged_len, DMA_TO_DEVICE);
1761 priv->tx_skbuff_dma[entry] = desc->des2;
1762 priv->hw->desc->prepare_tx_desc(desc, 1, nopaged_len,
1763 csum_insertion, priv->mode);
1767 for (i = 0; i < nfrags; i++) {
1768 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1769 int len = skb_frag_size(frag);
1771 entry = (++priv->cur_tx) % txsize;
1772 if (priv->extend_desc)
1773 desc = (struct dma_desc *) (priv->dma_etx + entry);
1775 desc = priv->dma_tx + entry;
1777 TX_DBG("\t[entry %d] segment len: %d\n", entry, len);
1778 desc->des2 = skb_frag_dma_map(priv->device, frag, 0, len,
1780 priv->tx_skbuff_dma[entry] = desc->des2;
1781 priv->tx_skbuff[entry] = NULL;
1782 priv->hw->desc->prepare_tx_desc(desc, 0, len, csum_insertion,
1785 priv->hw->desc->set_tx_owner(desc);
1789 /* Finalize the latest segment. */
1790 priv->hw->desc->close_tx_desc(desc);
1793 /* According to the coalesce parameter the IC bit for the latest
1794 * segment could be reset and the timer re-started to invoke the
1795 * stmmac_tx function. This approach takes care about the fragments.
1797 priv->tx_count_frames += nfrags + 1;
1798 if (priv->tx_coal_frames > priv->tx_count_frames) {
1799 priv->hw->desc->clear_tx_ic(desc);
1800 priv->xstats.tx_reset_ic_bit++;
1801 TX_DBG("\t[entry %d]: tx_count_frames %d\n", entry,
1802 priv->tx_count_frames);
1803 mod_timer(&priv->txtimer,
1804 STMMAC_COAL_TIMER(priv->tx_coal_timer));
1806 priv->tx_count_frames = 0;
1808 /* To avoid raise condition */
1809 priv->hw->desc->set_tx_owner(first);
1814 #ifdef STMMAC_XMIT_DEBUG
1815 if (netif_msg_pktdata(priv)) {
1816 pr_info("stmmac xmit: current=%d, dirty=%d, entry=%d, "
1817 "first=%p, nfrags=%d\n",
1818 (priv->cur_tx % txsize), (priv->dirty_tx % txsize),
1819 entry, first, nfrags);
1820 if (priv->extend_desc)
1821 stmmac_display_ring((void *)priv->dma_etx, txsize, 1);
1823 stmmac_display_ring((void *)priv->dma_tx, txsize, 0);
1825 pr_info(">>> frame to be transmitted: ");
1826 print_pkt(skb->data, skb->len);
1829 if (unlikely(stmmac_tx_avail(priv) <= (MAX_SKB_FRAGS + 1))) {
1830 TX_DBG("%s: stop transmitted packets\n", __func__);
1831 netif_stop_queue(dev);
1834 dev->stats.tx_bytes += skb->len;
1836 if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
1837 priv->hwts_tx_en)) {
1838 /* declare that device is doing timestamping */
1839 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
1840 priv->hw->desc->enable_tx_timestamp(first);
1843 if (!priv->hwts_tx_en)
1844 skb_tx_timestamp(skb);
1846 priv->hw->dma->enable_dma_transmission(priv->ioaddr);
1848 spin_unlock(&priv->tx_lock);
1850 return NETDEV_TX_OK;
1853 static inline void stmmac_rx_refill(struct stmmac_priv *priv)
1855 unsigned int rxsize = priv->dma_rx_size;
1856 int bfsize = priv->dma_buf_sz;
1858 for (; priv->cur_rx - priv->dirty_rx > 0; priv->dirty_rx++) {
1859 unsigned int entry = priv->dirty_rx % rxsize;
1862 if (priv->extend_desc)
1863 p = (struct dma_desc *) (priv->dma_erx + entry);
1865 p = priv->dma_rx + entry;
1867 if (likely(priv->rx_skbuff[entry] == NULL)) {
1868 struct sk_buff *skb;
1870 skb = netdev_alloc_skb_ip_align(priv->dev, bfsize);
1872 if (unlikely(skb == NULL))
1875 priv->rx_skbuff[entry] = skb;
1876 priv->rx_skbuff_dma[entry] =
1877 dma_map_single(priv->device, skb->data, bfsize,
1880 p->des2 = priv->rx_skbuff_dma[entry];
1882 priv->hw->ring->refill_desc3(priv, p);
1884 RX_DBG(KERN_INFO "\trefill entry #%d\n", entry);
1887 priv->hw->desc->set_rx_owner(p);
1892 static int stmmac_rx(struct stmmac_priv *priv, int limit)
1894 unsigned int rxsize = priv->dma_rx_size;
1895 unsigned int entry = priv->cur_rx % rxsize;
1896 unsigned int next_entry;
1897 unsigned int count = 0;
1899 #ifdef STMMAC_RX_DEBUG
1900 if (netif_msg_hw(priv)) {
1901 pr_debug(">>> stmmac_rx: descriptor ring:\n");
1902 if (priv->extend_desc)
1903 stmmac_display_ring((void *) priv->dma_erx, rxsize, 1);
1905 stmmac_display_ring((void *)priv->dma_rx, rxsize, 0);
1908 while (count < limit) {
1910 struct dma_desc *p, *p_next;
1912 if (priv->extend_desc)
1913 p = (struct dma_desc *) (priv->dma_erx + entry);
1915 p = priv->dma_rx + entry ;
1917 if (priv->hw->desc->get_rx_owner(p))
1922 next_entry = (++priv->cur_rx) % rxsize;
1923 if (priv->extend_desc)
1924 p_next = (struct dma_desc *) (priv->dma_erx +
1927 p_next = priv->dma_rx + next_entry;
1931 /* read the status of the incoming frame */
1932 status = priv->hw->desc->rx_status(&priv->dev->stats,
1934 if ((priv->extend_desc) && (priv->hw->desc->rx_extended_status))
1935 priv->hw->desc->rx_extended_status(&priv->dev->stats,
1939 if (unlikely(status == discard_frame)) {
1940 priv->dev->stats.rx_errors++;
1941 if (priv->hwts_rx_en && !priv->extend_desc) {
1942 /* DESC2 & DESC3 will be overwitten by device
1943 * with timestamp value, hence reinitialize
1944 * them in stmmac_rx_refill() function so that
1945 * device can reuse it.
1947 priv->rx_skbuff[entry] = NULL;
1948 dma_unmap_single(priv->device,
1949 priv->rx_skbuff_dma[entry],
1950 priv->dma_buf_sz, DMA_FROM_DEVICE);
1953 struct sk_buff *skb;
1956 frame_len = priv->hw->desc->get_rx_frame_len(p,
1957 priv->plat->rx_coe);
1958 /* ACS is set; GMAC core strips PAD/FCS for IEEE 802.3
1959 * Type frames (LLC/LLC-SNAP) */
1960 if (unlikely(status != llc_snap))
1961 frame_len -= ETH_FCS_LEN;
1962 #ifdef STMMAC_RX_DEBUG
1963 if (frame_len > ETH_FRAME_LEN)
1964 pr_debug("\tRX frame size %d, COE status: %d\n",
1967 if (netif_msg_hw(priv))
1968 pr_debug("\tdesc: %p [entry %d] buff=0x%x\n",
1971 skb = priv->rx_skbuff[entry];
1972 if (unlikely(!skb)) {
1973 pr_err("%s: Inconsistent Rx descriptor chain\n",
1975 priv->dev->stats.rx_dropped++;
1978 prefetch(skb->data - NET_IP_ALIGN);
1979 priv->rx_skbuff[entry] = NULL;
1981 stmmac_get_rx_hwtstamp(priv, entry, skb);
1983 skb_put(skb, frame_len);
1984 dma_unmap_single(priv->device,
1985 priv->rx_skbuff_dma[entry],
1986 priv->dma_buf_sz, DMA_FROM_DEVICE);
1987 #ifdef STMMAC_RX_DEBUG
1988 if (netif_msg_pktdata(priv)) {
1989 pr_info(" frame received (%dbytes)", frame_len);
1990 print_pkt(skb->data, frame_len);
1993 skb->protocol = eth_type_trans(skb, priv->dev);
1995 if (unlikely(!priv->plat->rx_coe))
1996 skb_checksum_none_assert(skb);
1998 skb->ip_summed = CHECKSUM_UNNECESSARY;
2000 napi_gro_receive(&priv->napi, skb);
2002 priv->dev->stats.rx_packets++;
2003 priv->dev->stats.rx_bytes += frame_len;
2008 stmmac_rx_refill(priv);
2010 priv->xstats.rx_pkt_n += count;
2016 * stmmac_poll - stmmac poll method (NAPI)
2017 * @napi : pointer to the napi structure.
2018 * @budget : maximum number of packets that the current CPU can receive from
2021 * To look at the incoming frames and clear the tx resources.
2023 static int stmmac_poll(struct napi_struct *napi, int budget)
2025 struct stmmac_priv *priv = container_of(napi, struct stmmac_priv, napi);
2028 priv->xstats.napi_poll++;
2029 stmmac_tx_clean(priv);
2031 work_done = stmmac_rx(priv, budget);
2032 if (work_done < budget) {
2033 napi_complete(napi);
2034 stmmac_enable_dma_irq(priv);
2041 * @dev : Pointer to net device structure
2042 * Description: this function is called when a packet transmission fails to
2043 * complete within a reasonable time. The driver will mark the error in the
2044 * netdev structure and arrange for the device to be reset to a sane state
2045 * in order to transmit a new packet.
2047 static void stmmac_tx_timeout(struct net_device *dev)
2049 struct stmmac_priv *priv = netdev_priv(dev);
2051 /* Clear Tx resources and restart transmitting again */
2052 stmmac_tx_err(priv);
2055 /* Configuration changes (passed on by ifconfig) */
2056 static int stmmac_config(struct net_device *dev, struct ifmap *map)
2058 if (dev->flags & IFF_UP) /* can't act on a running interface */
2061 /* Don't allow changing the I/O address */
2062 if (map->base_addr != dev->base_addr) {
2063 pr_warning("%s: can't change I/O address\n", dev->name);
2067 /* Don't allow changing the IRQ */
2068 if (map->irq != dev->irq) {
2069 pr_warning("%s: can't change IRQ number %d\n",
2070 dev->name, dev->irq);
2074 /* ignore other fields */
2079 * stmmac_set_rx_mode - entry point for multicast addressing
2080 * @dev : pointer to the device structure
2082 * This function is a driver entry point which gets called by the kernel
2083 * whenever multicast addresses must be enabled/disabled.
2087 static void stmmac_set_rx_mode(struct net_device *dev)
2089 struct stmmac_priv *priv = netdev_priv(dev);
2091 spin_lock(&priv->lock);
2092 priv->hw->mac->set_filter(dev, priv->synopsys_id);
2093 spin_unlock(&priv->lock);
2097 * stmmac_change_mtu - entry point to change MTU size for the device.
2098 * @dev : device pointer.
2099 * @new_mtu : the new MTU size for the device.
2100 * Description: the Maximum Transfer Unit (MTU) is used by the network layer
2101 * to drive packet transmission. Ethernet has an MTU of 1500 octets
2102 * (ETH_DATA_LEN). This value can be changed with ifconfig.
2104 * 0 on success and an appropriate (-)ve integer as defined in errno.h
2107 static int stmmac_change_mtu(struct net_device *dev, int new_mtu)
2109 struct stmmac_priv *priv = netdev_priv(dev);
2112 if (netif_running(dev)) {
2113 pr_err("%s: must be stopped to change its MTU\n", dev->name);
2117 if (priv->plat->enh_desc)
2118 max_mtu = JUMBO_LEN;
2120 max_mtu = SKB_MAX_HEAD(NET_SKB_PAD + NET_IP_ALIGN);
2122 if ((new_mtu < 46) || (new_mtu > max_mtu)) {
2123 pr_err("%s: invalid MTU, max MTU is: %d\n", dev->name, max_mtu);
2128 netdev_update_features(dev);
2133 static netdev_features_t stmmac_fix_features(struct net_device *dev,
2134 netdev_features_t features)
2136 struct stmmac_priv *priv = netdev_priv(dev);
2138 if (priv->plat->rx_coe == STMMAC_RX_COE_NONE)
2139 features &= ~NETIF_F_RXCSUM;
2140 else if (priv->plat->rx_coe == STMMAC_RX_COE_TYPE1)
2141 features &= ~NETIF_F_IPV6_CSUM;
2142 if (!priv->plat->tx_coe)
2143 features &= ~NETIF_F_ALL_CSUM;
2145 /* Some GMAC devices have a bugged Jumbo frame support that
2146 * needs to have the Tx COE disabled for oversized frames
2147 * (due to limited buffer sizes). In this case we disable
2148 * the TX csum insertionin the TDES and not use SF. */
2149 if (priv->plat->bugged_jumbo && (dev->mtu > ETH_DATA_LEN))
2150 features &= ~NETIF_F_ALL_CSUM;
2155 static irqreturn_t stmmac_interrupt(int irq, void *dev_id)
2157 struct net_device *dev = (struct net_device *)dev_id;
2158 struct stmmac_priv *priv = netdev_priv(dev);
2160 if (unlikely(!dev)) {
2161 pr_err("%s: invalid dev pointer\n", __func__);
2165 /* To handle GMAC own interrupts */
2166 if (priv->plat->has_gmac) {
2167 int status = priv->hw->mac->host_irq_status((void __iomem *)
2170 if (unlikely(status)) {
2171 /* For LPI we need to save the tx status */
2172 if (status & CORE_IRQ_TX_PATH_IN_LPI_MODE)
2173 priv->tx_path_in_lpi_mode = true;
2174 if (status & CORE_IRQ_TX_PATH_EXIT_LPI_MODE)
2175 priv->tx_path_in_lpi_mode = false;
2179 /* To handle DMA interrupts */
2180 stmmac_dma_interrupt(priv);
2185 #ifdef CONFIG_NET_POLL_CONTROLLER
2186 /* Polling receive - used by NETCONSOLE and other diagnostic tools
2187 * to allow network I/O with interrupts disabled. */
2188 static void stmmac_poll_controller(struct net_device *dev)
2190 disable_irq(dev->irq);
2191 stmmac_interrupt(dev->irq, dev);
2192 enable_irq(dev->irq);
2197 * stmmac_ioctl - Entry point for the Ioctl
2198 * @dev: Device pointer.
2199 * @rq: An IOCTL specefic structure, that can contain a pointer to
2200 * a proprietary structure used to pass information to the driver.
2201 * @cmd: IOCTL command
2203 * Currently it supports just the phy_mii_ioctl(...) and HW time stamping.
2205 static int stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2207 struct stmmac_priv *priv = netdev_priv(dev);
2208 int ret = -EOPNOTSUPP;
2210 if (!netif_running(dev))
2219 ret = phy_mii_ioctl(priv->phydev, rq, cmd);
2222 ret = stmmac_hwtstamp_ioctl(dev, rq);
2231 #ifdef CONFIG_STMMAC_DEBUG_FS
2232 static struct dentry *stmmac_fs_dir;
2233 static struct dentry *stmmac_rings_status;
2234 static struct dentry *stmmac_dma_cap;
2236 static void sysfs_display_ring(void *head, int size, int extend_desc,
2237 struct seq_file *seq)
2240 struct dma_extended_desc *ep = (struct dma_extended_desc *) head;
2241 struct dma_desc *p = (struct dma_desc *) head;
2243 for (i = 0; i < size; i++) {
2247 seq_printf(seq, "%d [0x%x]: 0x%x 0x%x 0x%x 0x%x\n",
2248 i, (unsigned int) virt_to_phys(ep),
2249 (unsigned int) x, (unsigned int) (x >> 32),
2250 ep->basic.des2, ep->basic.des3);
2254 seq_printf(seq, "%d [0x%x]: 0x%x 0x%x 0x%x 0x%x\n",
2255 i, (unsigned int) virt_to_phys(ep),
2256 (unsigned int) x, (unsigned int) (x >> 32),
2260 seq_printf(seq, "\n");
2264 static int stmmac_sysfs_ring_read(struct seq_file *seq, void *v)
2266 struct net_device *dev = seq->private;
2267 struct stmmac_priv *priv = netdev_priv(dev);
2268 unsigned int txsize = priv->dma_tx_size;
2269 unsigned int rxsize = priv->dma_rx_size;
2271 if (priv->extend_desc) {
2272 seq_printf(seq, "Extended RX descriptor ring:\n");
2273 sysfs_display_ring((void *) priv->dma_erx, rxsize, 1, seq);
2274 seq_printf(seq, "Extended TX descriptor ring:\n");
2275 sysfs_display_ring((void *) priv->dma_etx, txsize, 1, seq);
2277 seq_printf(seq, "RX descriptor ring:\n");
2278 sysfs_display_ring((void *)priv->dma_rx, rxsize, 0, seq);
2279 seq_printf(seq, "TX descriptor ring:\n");
2280 sysfs_display_ring((void *)priv->dma_tx, txsize, 0, seq);
2286 static int stmmac_sysfs_ring_open(struct inode *inode, struct file *file)
2288 return single_open(file, stmmac_sysfs_ring_read, inode->i_private);
2291 static const struct file_operations stmmac_rings_status_fops = {
2292 .owner = THIS_MODULE,
2293 .open = stmmac_sysfs_ring_open,
2295 .llseek = seq_lseek,
2296 .release = single_release,
2299 static int stmmac_sysfs_dma_cap_read(struct seq_file *seq, void *v)
2301 struct net_device *dev = seq->private;
2302 struct stmmac_priv *priv = netdev_priv(dev);
2304 if (!priv->hw_cap_support) {
2305 seq_printf(seq, "DMA HW features not supported\n");
2309 seq_printf(seq, "==============================\n");
2310 seq_printf(seq, "\tDMA HW features\n");
2311 seq_printf(seq, "==============================\n");
2313 seq_printf(seq, "\t10/100 Mbps %s\n",
2314 (priv->dma_cap.mbps_10_100) ? "Y" : "N");
2315 seq_printf(seq, "\t1000 Mbps %s\n",
2316 (priv->dma_cap.mbps_1000) ? "Y" : "N");
2317 seq_printf(seq, "\tHalf duple %s\n",
2318 (priv->dma_cap.half_duplex) ? "Y" : "N");
2319 seq_printf(seq, "\tHash Filter: %s\n",
2320 (priv->dma_cap.hash_filter) ? "Y" : "N");
2321 seq_printf(seq, "\tMultiple MAC address registers: %s\n",
2322 (priv->dma_cap.multi_addr) ? "Y" : "N");
2323 seq_printf(seq, "\tPCS (TBI/SGMII/RTBI PHY interfatces): %s\n",
2324 (priv->dma_cap.pcs) ? "Y" : "N");
2325 seq_printf(seq, "\tSMA (MDIO) Interface: %s\n",
2326 (priv->dma_cap.sma_mdio) ? "Y" : "N");
2327 seq_printf(seq, "\tPMT Remote wake up: %s\n",
2328 (priv->dma_cap.pmt_remote_wake_up) ? "Y" : "N");
2329 seq_printf(seq, "\tPMT Magic Frame: %s\n",
2330 (priv->dma_cap.pmt_magic_frame) ? "Y" : "N");
2331 seq_printf(seq, "\tRMON module: %s\n",
2332 (priv->dma_cap.rmon) ? "Y" : "N");
2333 seq_printf(seq, "\tIEEE 1588-2002 Time Stamp: %s\n",
2334 (priv->dma_cap.time_stamp) ? "Y" : "N");
2335 seq_printf(seq, "\tIEEE 1588-2008 Advanced Time Stamp:%s\n",
2336 (priv->dma_cap.atime_stamp) ? "Y" : "N");
2337 seq_printf(seq, "\t802.3az - Energy-Efficient Ethernet (EEE) %s\n",
2338 (priv->dma_cap.eee) ? "Y" : "N");
2339 seq_printf(seq, "\tAV features: %s\n", (priv->dma_cap.av) ? "Y" : "N");
2340 seq_printf(seq, "\tChecksum Offload in TX: %s\n",
2341 (priv->dma_cap.tx_coe) ? "Y" : "N");
2342 seq_printf(seq, "\tIP Checksum Offload (type1) in RX: %s\n",
2343 (priv->dma_cap.rx_coe_type1) ? "Y" : "N");
2344 seq_printf(seq, "\tIP Checksum Offload (type2) in RX: %s\n",
2345 (priv->dma_cap.rx_coe_type2) ? "Y" : "N");
2346 seq_printf(seq, "\tRXFIFO > 2048bytes: %s\n",
2347 (priv->dma_cap.rxfifo_over_2048) ? "Y" : "N");
2348 seq_printf(seq, "\tNumber of Additional RX channel: %d\n",
2349 priv->dma_cap.number_rx_channel);
2350 seq_printf(seq, "\tNumber of Additional TX channel: %d\n",
2351 priv->dma_cap.number_tx_channel);
2352 seq_printf(seq, "\tEnhanced descriptors: %s\n",
2353 (priv->dma_cap.enh_desc) ? "Y" : "N");
2358 static int stmmac_sysfs_dma_cap_open(struct inode *inode, struct file *file)
2360 return single_open(file, stmmac_sysfs_dma_cap_read, inode->i_private);
2363 static const struct file_operations stmmac_dma_cap_fops = {
2364 .owner = THIS_MODULE,
2365 .open = stmmac_sysfs_dma_cap_open,
2367 .llseek = seq_lseek,
2368 .release = single_release,
2371 static int stmmac_init_fs(struct net_device *dev)
2373 /* Create debugfs entries */
2374 stmmac_fs_dir = debugfs_create_dir(STMMAC_RESOURCE_NAME, NULL);
2376 if (!stmmac_fs_dir || IS_ERR(stmmac_fs_dir)) {
2377 pr_err("ERROR %s, debugfs create directory failed\n",
2378 STMMAC_RESOURCE_NAME);
2383 /* Entry to report DMA RX/TX rings */
2384 stmmac_rings_status = debugfs_create_file("descriptors_status",
2385 S_IRUGO, stmmac_fs_dir, dev,
2386 &stmmac_rings_status_fops);
2388 if (!stmmac_rings_status || IS_ERR(stmmac_rings_status)) {
2389 pr_info("ERROR creating stmmac ring debugfs file\n");
2390 debugfs_remove(stmmac_fs_dir);
2395 /* Entry to report the DMA HW features */
2396 stmmac_dma_cap = debugfs_create_file("dma_cap", S_IRUGO, stmmac_fs_dir,
2397 dev, &stmmac_dma_cap_fops);
2399 if (!stmmac_dma_cap || IS_ERR(stmmac_dma_cap)) {
2400 pr_info("ERROR creating stmmac MMC debugfs file\n");
2401 debugfs_remove(stmmac_rings_status);
2402 debugfs_remove(stmmac_fs_dir);
2410 static void stmmac_exit_fs(void)
2412 debugfs_remove(stmmac_rings_status);
2413 debugfs_remove(stmmac_dma_cap);
2414 debugfs_remove(stmmac_fs_dir);
2416 #endif /* CONFIG_STMMAC_DEBUG_FS */
2418 static const struct net_device_ops stmmac_netdev_ops = {
2419 .ndo_open = stmmac_open,
2420 .ndo_start_xmit = stmmac_xmit,
2421 .ndo_stop = stmmac_release,
2422 .ndo_change_mtu = stmmac_change_mtu,
2423 .ndo_fix_features = stmmac_fix_features,
2424 .ndo_set_rx_mode = stmmac_set_rx_mode,
2425 .ndo_tx_timeout = stmmac_tx_timeout,
2426 .ndo_do_ioctl = stmmac_ioctl,
2427 .ndo_set_config = stmmac_config,
2428 #ifdef CONFIG_NET_POLL_CONTROLLER
2429 .ndo_poll_controller = stmmac_poll_controller,
2431 .ndo_set_mac_address = eth_mac_addr,
2435 * stmmac_hw_init - Init the MAC device
2436 * @priv : pointer to the private device structure.
2437 * Description: this function detects which MAC device
2438 * (GMAC/MAC10-100) has to attached, checks the HW capability
2439 * (if supported) and sets the driver's features (for example
2440 * to use the ring or chaine mode or support the normal/enh
2441 * descriptor structure).
2443 static int stmmac_hw_init(struct stmmac_priv *priv)
2446 struct mac_device_info *mac;
2448 /* Identify the MAC HW device */
2449 if (priv->plat->has_gmac) {
2450 priv->dev->priv_flags |= IFF_UNICAST_FLT;
2451 mac = dwmac1000_setup(priv->ioaddr);
2453 mac = dwmac100_setup(priv->ioaddr);
2460 /* Get and dump the chip ID */
2461 priv->synopsys_id = stmmac_get_synopsys_id(priv);
2463 /* To use alternate (extended) or normal descriptor structures */
2464 stmmac_selec_desc_mode(priv);
2466 /* To use the chained or ring mode */
2468 priv->hw->chain = &chain_mode_ops;
2469 pr_info(" Chain mode enabled\n");
2470 priv->mode = STMMAC_CHAIN_MODE;
2472 priv->hw->ring = &ring_mode_ops;
2473 pr_info(" Ring mode enabled\n");
2474 priv->mode = STMMAC_RING_MODE;
2477 /* Get the HW capability (new GMAC newer than 3.50a) */
2478 priv->hw_cap_support = stmmac_get_hw_features(priv);
2479 if (priv->hw_cap_support) {
2480 pr_info(" DMA HW capability register supported");
2482 /* We can override some gmac/dma configuration fields: e.g.
2483 * enh_desc, tx_coe (e.g. that are passed through the
2484 * platform) with the values from the HW capability
2485 * register (if supported).
2487 priv->plat->enh_desc = priv->dma_cap.enh_desc;
2488 priv->plat->pmt = priv->dma_cap.pmt_remote_wake_up;
2490 priv->plat->tx_coe = priv->dma_cap.tx_coe;
2492 if (priv->dma_cap.rx_coe_type2)
2493 priv->plat->rx_coe = STMMAC_RX_COE_TYPE2;
2494 else if (priv->dma_cap.rx_coe_type1)
2495 priv->plat->rx_coe = STMMAC_RX_COE_TYPE1;
2498 pr_info(" No HW DMA feature register supported");
2500 /* Enable the IPC (Checksum Offload) and check if the feature has been
2501 * enabled during the core configuration. */
2502 ret = priv->hw->mac->rx_ipc(priv->ioaddr);
2504 pr_warning(" RX IPC Checksum Offload not configured.\n");
2505 priv->plat->rx_coe = STMMAC_RX_COE_NONE;
2508 if (priv->plat->rx_coe)
2509 pr_info(" RX Checksum Offload Engine supported (type %d)\n",
2510 priv->plat->rx_coe);
2511 if (priv->plat->tx_coe)
2512 pr_info(" TX Checksum insertion supported\n");
2514 if (priv->plat->pmt) {
2515 pr_info(" Wake-Up On Lan supported\n");
2516 device_set_wakeup_capable(priv->device, 1);
2524 * @device: device pointer
2525 * @plat_dat: platform data pointer
2526 * @addr: iobase memory address
2527 * Description: this is the main probe function used to
2528 * call the alloc_etherdev, allocate the priv structure.
2530 struct stmmac_priv *stmmac_dvr_probe(struct device *device,
2531 struct plat_stmmacenet_data *plat_dat,
2535 struct net_device *ndev = NULL;
2536 struct stmmac_priv *priv;
2538 ndev = alloc_etherdev(sizeof(struct stmmac_priv));
2542 SET_NETDEV_DEV(ndev, device);
2544 priv = netdev_priv(ndev);
2545 priv->device = device;
2550 stmmac_set_ethtool_ops(ndev);
2551 priv->pause = pause;
2552 priv->plat = plat_dat;
2553 priv->ioaddr = addr;
2554 priv->dev->base_addr = (unsigned long)addr;
2556 /* Verify driver arguments */
2557 stmmac_verify_args();
2559 /* Override with kernel parameters if supplied XXX CRS XXX
2560 * this needs to have multiple instances */
2561 if ((phyaddr >= 0) && (phyaddr <= 31))
2562 priv->plat->phy_addr = phyaddr;
2564 /* Init MAC and get the capabilities */
2565 ret = stmmac_hw_init(priv);
2567 goto error_free_netdev;
2569 ndev->netdev_ops = &stmmac_netdev_ops;
2571 ndev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
2573 ndev->features |= ndev->hw_features | NETIF_F_HIGHDMA;
2574 ndev->watchdog_timeo = msecs_to_jiffies(watchdog);
2575 #ifdef STMMAC_VLAN_TAG_USED
2576 /* Both mac100 and gmac support receive VLAN tag detection */
2577 ndev->features |= NETIF_F_HW_VLAN_RX;
2579 priv->msg_enable = netif_msg_init(debug, default_msg_level);
2582 priv->flow_ctrl = FLOW_AUTO; /* RX/TX pause on */
2584 /* Rx Watchdog is available in the COREs newer than the 3.40.
2585 * In some case, for example on bugged HW this feature
2586 * has to be disable and this can be done by passing the
2587 * riwt_off field from the platform.
2589 if ((priv->synopsys_id >= DWMAC_CORE_3_50) && (!priv->plat->riwt_off)) {
2591 pr_info(" Enable RX Mitigation via HW Watchdog Timer\n");
2594 netif_napi_add(ndev, &priv->napi, stmmac_poll, 64);
2596 spin_lock_init(&priv->lock);
2597 spin_lock_init(&priv->tx_lock);
2599 ret = register_netdev(ndev);
2601 pr_err("%s: ERROR %i registering the device\n", __func__, ret);
2602 goto error_netdev_register;
2605 priv->stmmac_clk = clk_get(priv->device, STMMAC_RESOURCE_NAME);
2606 if (IS_ERR(priv->stmmac_clk)) {
2607 pr_warning("%s: warning: cannot get CSR clock\n", __func__);
2611 /* If a specific clk_csr value is passed from the platform
2612 * this means that the CSR Clock Range selection cannot be
2613 * changed at run-time and it is fixed. Viceversa the driver'll try to
2614 * set the MDC clock dynamically according to the csr actual
2617 if (!priv->plat->clk_csr)
2618 stmmac_clk_csr_set(priv);
2620 priv->clk_csr = priv->plat->clk_csr;
2622 stmmac_check_pcs_mode(priv);
2625 /* MDIO bus Registration */
2626 ret = stmmac_mdio_register(ndev);
2628 pr_debug("%s: MDIO bus (id: %d) registration failed",
2629 __func__, priv->plat->bus_id);
2630 goto error_mdio_register;
2636 error_mdio_register:
2637 clk_put(priv->stmmac_clk);
2639 unregister_netdev(ndev);
2640 error_netdev_register:
2641 netif_napi_del(&priv->napi);
2650 * @ndev: net device pointer
2651 * Description: this function resets the TX/RX processes, disables the MAC RX/TX
2652 * changes the link status, releases the DMA descriptor rings.
2654 int stmmac_dvr_remove(struct net_device *ndev)
2656 struct stmmac_priv *priv = netdev_priv(ndev);
2658 pr_info("%s:\n\tremoving driver", __func__);
2660 priv->hw->dma->stop_rx(priv->ioaddr);
2661 priv->hw->dma->stop_tx(priv->ioaddr);
2663 stmmac_set_mac(priv->ioaddr, false);
2665 stmmac_mdio_unregister(ndev);
2666 netif_carrier_off(ndev);
2667 unregister_netdev(ndev);
2674 int stmmac_suspend(struct net_device *ndev)
2676 struct stmmac_priv *priv = netdev_priv(ndev);
2677 unsigned long flags;
2679 if (!ndev || !netif_running(ndev))
2683 phy_stop(priv->phydev);
2685 spin_lock_irqsave(&priv->lock, flags);
2687 netif_device_detach(ndev);
2688 netif_stop_queue(ndev);
2690 napi_disable(&priv->napi);
2692 /* Stop TX/RX DMA */
2693 priv->hw->dma->stop_tx(priv->ioaddr);
2694 priv->hw->dma->stop_rx(priv->ioaddr);
2696 stmmac_clear_descriptors(priv);
2698 /* Enable Power down mode by programming the PMT regs */
2699 if (device_may_wakeup(priv->device))
2700 priv->hw->mac->pmt(priv->ioaddr, priv->wolopts);
2702 stmmac_set_mac(priv->ioaddr, false);
2703 /* Disable clock in case of PWM is off */
2704 clk_disable_unprepare(priv->stmmac_clk);
2706 spin_unlock_irqrestore(&priv->lock, flags);
2710 int stmmac_resume(struct net_device *ndev)
2712 struct stmmac_priv *priv = netdev_priv(ndev);
2713 unsigned long flags;
2715 if (!netif_running(ndev))
2718 spin_lock_irqsave(&priv->lock, flags);
2720 /* Power Down bit, into the PM register, is cleared
2721 * automatically as soon as a magic packet or a Wake-up frame
2722 * is received. Anyway, it's better to manually clear
2723 * this bit because it can generate problems while resuming
2724 * from another devices (e.g. serial console). */
2725 if (device_may_wakeup(priv->device))
2726 priv->hw->mac->pmt(priv->ioaddr, 0);
2728 /* enable the clk prevously disabled */
2729 clk_prepare_enable(priv->stmmac_clk);
2731 netif_device_attach(ndev);
2733 /* Enable the MAC and DMA */
2734 stmmac_set_mac(priv->ioaddr, true);
2735 priv->hw->dma->start_tx(priv->ioaddr);
2736 priv->hw->dma->start_rx(priv->ioaddr);
2738 napi_enable(&priv->napi);
2740 netif_start_queue(ndev);
2742 spin_unlock_irqrestore(&priv->lock, flags);
2745 phy_start(priv->phydev);
2750 int stmmac_freeze(struct net_device *ndev)
2752 if (!ndev || !netif_running(ndev))
2755 return stmmac_release(ndev);
2758 int stmmac_restore(struct net_device *ndev)
2760 if (!ndev || !netif_running(ndev))
2763 return stmmac_open(ndev);
2765 #endif /* CONFIG_PM */
2767 /* Driver can be configured w/ and w/ both PCI and Platf drivers
2768 * depending on the configuration selected.
2770 static int __init stmmac_init(void)
2774 ret = stmmac_register_platform();
2777 ret = stmmac_register_pci();
2782 stmmac_unregister_platform();
2784 pr_err("stmmac: driver registration failed\n");
2788 static void __exit stmmac_exit(void)
2790 stmmac_unregister_platform();
2791 stmmac_unregister_pci();
2794 module_init(stmmac_init);
2795 module_exit(stmmac_exit);
2798 static int __init stmmac_cmdline_opt(char *str)
2804 while ((opt = strsep(&str, ",")) != NULL) {
2805 if (!strncmp(opt, "debug:", 6)) {
2806 if (kstrtoint(opt + 6, 0, &debug))
2808 } else if (!strncmp(opt, "phyaddr:", 8)) {
2809 if (kstrtoint(opt + 8, 0, &phyaddr))
2811 } else if (!strncmp(opt, "dma_txsize:", 11)) {
2812 if (kstrtoint(opt + 11, 0, &dma_txsize))
2814 } else if (!strncmp(opt, "dma_rxsize:", 11)) {
2815 if (kstrtoint(opt + 11, 0, &dma_rxsize))
2817 } else if (!strncmp(opt, "buf_sz:", 7)) {
2818 if (kstrtoint(opt + 7, 0, &buf_sz))
2820 } else if (!strncmp(opt, "tc:", 3)) {
2821 if (kstrtoint(opt + 3, 0, &tc))
2823 } else if (!strncmp(opt, "watchdog:", 9)) {
2824 if (kstrtoint(opt + 9, 0, &watchdog))
2826 } else if (!strncmp(opt, "flow_ctrl:", 10)) {
2827 if (kstrtoint(opt + 10, 0, &flow_ctrl))
2829 } else if (!strncmp(opt, "pause:", 6)) {
2830 if (kstrtoint(opt + 6, 0, &pause))
2832 } else if (!strncmp(opt, "eee_timer:", 10)) {
2833 if (kstrtoint(opt + 10, 0, &eee_timer))
2835 } else if (!strncmp(opt, "chain_mode:", 11)) {
2836 if (kstrtoint(opt + 11, 0, &chain_mode))
2843 pr_err("%s: ERROR broken module parameter conversion", __func__);
2847 __setup("stmmaceth=", stmmac_cmdline_opt);
2850 MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet device driver");
2851 MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
2852 MODULE_LICENSE("GPL");