]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
stmmac: remove dead code for STMMAC_TIMER support
[mirror_ubuntu-bionic-kernel.git] / drivers / net / ethernet / stmicro / stmmac / stmmac_main.c
CommitLineData
47dd7a54
GC
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.
4
286a8372 5 Copyright(C) 2007-2011 STMicroelectronics Ltd
47dd7a54
GC
6
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.
10
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
14 more details.
15
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.
19
20 The full GNU General Public License is included in this distribution in
21 the file called "COPYING".
22
23 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
24
25 Documentation available at:
26 http://www.stlinux.com
27 Support available at:
28 https://bugzilla.stlinux.com/
29*******************************************************************************/
30
6a81c26f 31#include <linux/clk.h>
47dd7a54
GC
32#include <linux/kernel.h>
33#include <linux/interrupt.h>
47dd7a54
GC
34#include <linux/ip.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>
01789349 41#include <linux/if.h>
47dd7a54
GC
42#include <linux/if_vlan.h>
43#include <linux/dma-mapping.h>
5a0e3ad6 44#include <linux/slab.h>
70c71606 45#include <linux/prefetch.h>
7ac29055
GC
46#ifdef CONFIG_STMMAC_DEBUG_FS
47#include <linux/debugfs.h>
48#include <linux/seq_file.h>
49#endif
286a8372 50#include "stmmac.h"
47dd7a54 51
47dd7a54
GC
52#undef STMMAC_DEBUG
53/*#define STMMAC_DEBUG*/
54#ifdef STMMAC_DEBUG
55#define DBG(nlevel, klevel, fmt, args...) \
56 ((void)(netif_msg_##nlevel(priv) && \
57 printk(KERN_##klevel fmt, ## args)))
58#else
59#define DBG(nlevel, klevel, fmt, args...) do { } while (0)
60#endif
61
62#undef STMMAC_RX_DEBUG
63/*#define STMMAC_RX_DEBUG*/
64#ifdef STMMAC_RX_DEBUG
65#define RX_DBG(fmt, args...) printk(fmt, ## args)
66#else
67#define RX_DBG(fmt, args...) do { } while (0)
68#endif
69
70#undef STMMAC_XMIT_DEBUG
71/*#define STMMAC_XMIT_DEBUG*/
72#ifdef STMMAC_TX_DEBUG
73#define TX_DBG(fmt, args...) printk(fmt, ## args)
74#else
75#define TX_DBG(fmt, args...) do { } while (0)
76#endif
77
78#define STMMAC_ALIGN(x) L1_CACHE_ALIGN(x)
79#define JUMBO_LEN 9000
80
81/* Module parameters */
82#define TX_TIMEO 5000 /* default 5 seconds */
83static int watchdog = TX_TIMEO;
84module_param(watchdog, int, S_IRUGO | S_IWUSR);
85MODULE_PARM_DESC(watchdog, "Transmit timeout in milliseconds");
86
87static int debug = -1; /* -1: default, 0: no output, 16: all */
88module_param(debug, int, S_IRUGO | S_IWUSR);
89MODULE_PARM_DESC(debug, "Message Level (0: no output, 16: all)");
90
bfab27a1 91int phyaddr = -1;
47dd7a54
GC
92module_param(phyaddr, int, S_IRUGO);
93MODULE_PARM_DESC(phyaddr, "Physical device address");
94
95#define DMA_TX_SIZE 256
96static int dma_txsize = DMA_TX_SIZE;
97module_param(dma_txsize, int, S_IRUGO | S_IWUSR);
98MODULE_PARM_DESC(dma_txsize, "Number of descriptors in the TX list");
99
100#define DMA_RX_SIZE 256
101static int dma_rxsize = DMA_RX_SIZE;
102module_param(dma_rxsize, int, S_IRUGO | S_IWUSR);
103MODULE_PARM_DESC(dma_rxsize, "Number of descriptors in the RX list");
104
105static int flow_ctrl = FLOW_OFF;
106module_param(flow_ctrl, int, S_IRUGO | S_IWUSR);
107MODULE_PARM_DESC(flow_ctrl, "Flow control ability [on/off]");
108
109static int pause = PAUSE_TIME;
110module_param(pause, int, S_IRUGO | S_IWUSR);
111MODULE_PARM_DESC(pause, "Flow Control Pause Time");
112
113#define TC_DEFAULT 64
114static int tc = TC_DEFAULT;
115module_param(tc, int, S_IRUGO | S_IWUSR);
116MODULE_PARM_DESC(tc, "DMA threshold control value");
117
47dd7a54
GC
118#define DMA_BUFFER_SIZE BUF_SIZE_2KiB
119static int buf_sz = DMA_BUFFER_SIZE;
120module_param(buf_sz, int, S_IRUGO | S_IWUSR);
121MODULE_PARM_DESC(buf_sz, "DMA buffer size");
122
47dd7a54
GC
123static const u32 default_msg_level = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
124 NETIF_MSG_LINK | NETIF_MSG_IFUP |
125 NETIF_MSG_IFDOWN | NETIF_MSG_TIMER);
126
d765955d
GC
127#define STMMAC_DEFAULT_LPI_TIMER 1000
128static int eee_timer = STMMAC_DEFAULT_LPI_TIMER;
129module_param(eee_timer, int, S_IRUGO | S_IWUSR);
130MODULE_PARM_DESC(eee_timer, "LPI tx expiration time in msec");
131#define STMMAC_LPI_TIMER(x) (jiffies + msecs_to_jiffies(x))
132
47dd7a54 133static irqreturn_t stmmac_interrupt(int irq, void *dev_id);
47dd7a54 134
bfab27a1
GC
135#ifdef CONFIG_STMMAC_DEBUG_FS
136static int stmmac_init_fs(struct net_device *dev);
137static void stmmac_exit_fs(void);
138#endif
139
47dd7a54
GC
140/**
141 * stmmac_verify_args - verify the driver parameters.
142 * Description: it verifies if some wrong parameter is passed to the driver.
143 * Note that wrong parameters are replaced with the default values.
144 */
145static void stmmac_verify_args(void)
146{
147 if (unlikely(watchdog < 0))
148 watchdog = TX_TIMEO;
149 if (unlikely(dma_rxsize < 0))
150 dma_rxsize = DMA_RX_SIZE;
151 if (unlikely(dma_txsize < 0))
152 dma_txsize = DMA_TX_SIZE;
153 if (unlikely((buf_sz < DMA_BUFFER_SIZE) || (buf_sz > BUF_SIZE_16KiB)))
154 buf_sz = DMA_BUFFER_SIZE;
155 if (unlikely(flow_ctrl > 1))
156 flow_ctrl = FLOW_AUTO;
157 else if (likely(flow_ctrl < 0))
158 flow_ctrl = FLOW_OFF;
159 if (unlikely((pause < 0) || (pause > 0xffff)))
160 pause = PAUSE_TIME;
d765955d
GC
161 if (eee_timer < 0)
162 eee_timer = STMMAC_DEFAULT_LPI_TIMER;
47dd7a54
GC
163}
164
cd7201f4
GC
165static void stmmac_clk_csr_set(struct stmmac_priv *priv)
166{
cd7201f4
GC
167 u32 clk_rate;
168
169 clk_rate = clk_get_rate(priv->stmmac_clk);
170
171 /* Platform provided default clk_csr would be assumed valid
172 * for all other cases except for the below mentioned ones. */
173 if (!(priv->clk_csr & MAC_CSR_H_FRQ_MASK)) {
174 if (clk_rate < CSR_F_35M)
175 priv->clk_csr = STMMAC_CSR_20_35M;
176 else if ((clk_rate >= CSR_F_35M) && (clk_rate < CSR_F_60M))
177 priv->clk_csr = STMMAC_CSR_35_60M;
178 else if ((clk_rate >= CSR_F_60M) && (clk_rate < CSR_F_100M))
179 priv->clk_csr = STMMAC_CSR_60_100M;
180 else if ((clk_rate >= CSR_F_100M) && (clk_rate < CSR_F_150M))
181 priv->clk_csr = STMMAC_CSR_100_150M;
182 else if ((clk_rate >= CSR_F_150M) && (clk_rate < CSR_F_250M))
183 priv->clk_csr = STMMAC_CSR_150_250M;
184 else if ((clk_rate >= CSR_F_250M) && (clk_rate < CSR_F_300M))
185 priv->clk_csr = STMMAC_CSR_250_300M;
186 } /* For values higher than the IEEE 802.3 specified frequency
187 * we can not estimate the proper divider as it is not known
188 * the frequency of clk_csr_i. So we do not change the default
189 * divider. */
cd7201f4
GC
190}
191
47dd7a54
GC
192#if defined(STMMAC_XMIT_DEBUG) || defined(STMMAC_RX_DEBUG)
193static void print_pkt(unsigned char *buf, int len)
194{
195 int j;
196 pr_info("len = %d byte, buf addr: 0x%p", len, buf);
197 for (j = 0; j < len; j++) {
198 if ((j % 16) == 0)
199 pr_info("\n %03x:", j);
200 pr_info(" %02x", buf[j]);
201 }
202 pr_info("\n");
47dd7a54
GC
203}
204#endif
205
206/* minimum number of free TX descriptors required to wake up TX process */
207#define STMMAC_TX_THRESH(x) (x->dma_tx_size/4)
208
209static inline u32 stmmac_tx_avail(struct stmmac_priv *priv)
210{
211 return priv->dirty_tx + priv->dma_tx_size - priv->cur_tx - 1;
212}
213
9dfeb4d9
GC
214/* On some ST platforms, some HW system configuraton registers have to be
215 * set according to the link speed negotiated.
216 */
217static inline void stmmac_hw_fix_mac_speed(struct stmmac_priv *priv)
218{
219 struct phy_device *phydev = priv->phydev;
220
221 if (likely(priv->plat->fix_mac_speed))
222 priv->plat->fix_mac_speed(priv->plat->bsp_priv,
223 phydev->speed);
224}
225
d765955d
GC
226static void stmmac_enable_eee_mode(struct stmmac_priv *priv)
227{
228 /* Check and enter in LPI mode */
229 if ((priv->dirty_tx == priv->cur_tx) &&
230 (priv->tx_path_in_lpi_mode == false))
231 priv->hw->mac->set_eee_mode(priv->ioaddr);
232}
233
234void stmmac_disable_eee_mode(struct stmmac_priv *priv)
235{
236 /* Exit and disable EEE in case of we are are in LPI state. */
237 priv->hw->mac->reset_eee_mode(priv->ioaddr);
238 del_timer_sync(&priv->eee_ctrl_timer);
239 priv->tx_path_in_lpi_mode = false;
240}
241
242/**
243 * stmmac_eee_ctrl_timer
244 * @arg : data hook
245 * Description:
246 * If there is no data transfer and if we are not in LPI state,
247 * then MAC Transmitter can be moved to LPI state.
248 */
249static void stmmac_eee_ctrl_timer(unsigned long arg)
250{
251 struct stmmac_priv *priv = (struct stmmac_priv *)arg;
252
253 stmmac_enable_eee_mode(priv);
254 mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_TIMER(eee_timer));
255}
256
257/**
258 * stmmac_eee_init
259 * @priv: private device pointer
260 * Description:
261 * If the EEE support has been enabled while configuring the driver,
262 * if the GMAC actually supports the EEE (from the HW cap reg) and the
263 * phy can also manage EEE, so enable the LPI state and start the timer
264 * to verify if the tx path can enter in LPI state.
265 */
266bool stmmac_eee_init(struct stmmac_priv *priv)
267{
268 bool ret = false;
269
270 /* MAC core supports the EEE feature. */
271 if (priv->dma_cap.eee) {
272 /* Check if the PHY supports EEE */
273 if (phy_init_eee(priv->phydev, 1))
274 goto out;
275
276 priv->eee_active = 1;
277 init_timer(&priv->eee_ctrl_timer);
278 priv->eee_ctrl_timer.function = stmmac_eee_ctrl_timer;
279 priv->eee_ctrl_timer.data = (unsigned long)priv;
280 priv->eee_ctrl_timer.expires = STMMAC_LPI_TIMER(eee_timer);
281 add_timer(&priv->eee_ctrl_timer);
282
283 priv->hw->mac->set_eee_timer(priv->ioaddr,
284 STMMAC_DEFAULT_LIT_LS_TIMER,
285 priv->tx_lpi_timer);
286
287 pr_info("stmmac: Energy-Efficient Ethernet initialized\n");
288
289 ret = true;
290 }
291out:
292 return ret;
293}
294
295static void stmmac_eee_adjust(struct stmmac_priv *priv)
296{
297 /* When the EEE has been already initialised we have to
298 * modify the PLS bit in the LPI ctrl & status reg according
299 * to the PHY link status. For this reason.
300 */
301 if (priv->eee_enabled)
302 priv->hw->mac->set_eee_pls(priv->ioaddr, priv->phydev->link);
303}
304
47dd7a54
GC
305/**
306 * stmmac_adjust_link
307 * @dev: net device structure
308 * Description: it adjusts the link parameters.
309 */
310static void stmmac_adjust_link(struct net_device *dev)
311{
312 struct stmmac_priv *priv = netdev_priv(dev);
313 struct phy_device *phydev = priv->phydev;
47dd7a54
GC
314 unsigned long flags;
315 int new_state = 0;
316 unsigned int fc = priv->flow_ctrl, pause_time = priv->pause;
317
318 if (phydev == NULL)
319 return;
320
321 DBG(probe, DEBUG, "stmmac_adjust_link: called. address %d link %d\n",
322 phydev->addr, phydev->link);
323
324 spin_lock_irqsave(&priv->lock, flags);
d765955d 325
47dd7a54 326 if (phydev->link) {
ad01b7d4 327 u32 ctrl = readl(priv->ioaddr + MAC_CTRL_REG);
47dd7a54
GC
328
329 /* Now we make sure that we can be in full duplex mode.
330 * If not, we operate in half-duplex mode. */
331 if (phydev->duplex != priv->oldduplex) {
332 new_state = 1;
333 if (!(phydev->duplex))
db98a0b0 334 ctrl &= ~priv->hw->link.duplex;
47dd7a54 335 else
db98a0b0 336 ctrl |= priv->hw->link.duplex;
47dd7a54
GC
337 priv->oldduplex = phydev->duplex;
338 }
339 /* Flow Control operation */
340 if (phydev->pause)
ad01b7d4 341 priv->hw->mac->flow_ctrl(priv->ioaddr, phydev->duplex,
db98a0b0 342 fc, pause_time);
47dd7a54
GC
343
344 if (phydev->speed != priv->speed) {
345 new_state = 1;
346 switch (phydev->speed) {
347 case 1000:
9dfeb4d9 348 if (likely(priv->plat->has_gmac))
db98a0b0 349 ctrl &= ~priv->hw->link.port;
cf3f047b 350 stmmac_hw_fix_mac_speed(priv);
47dd7a54
GC
351 break;
352 case 100:
353 case 10:
9dfeb4d9 354 if (priv->plat->has_gmac) {
db98a0b0 355 ctrl |= priv->hw->link.port;
47dd7a54 356 if (phydev->speed == SPEED_100) {
db98a0b0 357 ctrl |= priv->hw->link.speed;
47dd7a54 358 } else {
db98a0b0 359 ctrl &= ~(priv->hw->link.speed);
47dd7a54
GC
360 }
361 } else {
db98a0b0 362 ctrl &= ~priv->hw->link.port;
47dd7a54 363 }
9dfeb4d9 364 stmmac_hw_fix_mac_speed(priv);
47dd7a54
GC
365 break;
366 default:
367 if (netif_msg_link(priv))
368 pr_warning("%s: Speed (%d) is not 10"
369 " or 100!\n", dev->name, phydev->speed);
370 break;
371 }
372
373 priv->speed = phydev->speed;
374 }
375
ad01b7d4 376 writel(ctrl, priv->ioaddr + MAC_CTRL_REG);
47dd7a54
GC
377
378 if (!priv->oldlink) {
379 new_state = 1;
380 priv->oldlink = 1;
381 }
382 } else if (priv->oldlink) {
383 new_state = 1;
384 priv->oldlink = 0;
385 priv->speed = 0;
386 priv->oldduplex = -1;
387 }
388
389 if (new_state && netif_msg_link(priv))
390 phy_print_status(phydev);
391
d765955d
GC
392 stmmac_eee_adjust(priv);
393
47dd7a54
GC
394 spin_unlock_irqrestore(&priv->lock, flags);
395
396 DBG(probe, DEBUG, "stmmac_adjust_link: exiting\n");
397}
398
399/**
400 * stmmac_init_phy - PHY initialization
401 * @dev: net device structure
402 * Description: it initializes the driver's PHY state, and attaches the PHY
403 * to the mac driver.
404 * Return value:
405 * 0 on success
406 */
407static int stmmac_init_phy(struct net_device *dev)
408{
409 struct stmmac_priv *priv = netdev_priv(dev);
410 struct phy_device *phydev;
d765955d 411 char phy_id_fmt[MII_BUS_ID_SIZE + 3];
109cdd66 412 char bus_id[MII_BUS_ID_SIZE];
79ee1dc3 413 int interface = priv->plat->interface;
47dd7a54
GC
414 priv->oldlink = 0;
415 priv->speed = 0;
416 priv->oldduplex = -1;
417
f142af2e
SK
418 if (priv->plat->phy_bus_name)
419 snprintf(bus_id, MII_BUS_ID_SIZE, "%s-%x",
420 priv->plat->phy_bus_name, priv->plat->bus_id);
421 else
422 snprintf(bus_id, MII_BUS_ID_SIZE, "stmmac-%x",
423 priv->plat->bus_id);
424
d765955d 425 snprintf(phy_id_fmt, MII_BUS_ID_SIZE + 3, PHY_ID_FMT, bus_id,
36bcfe7d 426 priv->plat->phy_addr);
d765955d 427 pr_debug("stmmac_init_phy: trying to attach to %s\n", phy_id_fmt);
47dd7a54 428
d765955d
GC
429 phydev = phy_connect(dev, phy_id_fmt, &stmmac_adjust_link, 0,
430 interface);
47dd7a54
GC
431
432 if (IS_ERR(phydev)) {
433 pr_err("%s: Could not attach to PHY\n", dev->name);
434 return PTR_ERR(phydev);
435 }
436
79ee1dc3 437 /* Stop Advertising 1000BASE Capability if interface is not GMII */
c5b9b4e4
SK
438 if ((interface == PHY_INTERFACE_MODE_MII) ||
439 (interface == PHY_INTERFACE_MODE_RMII))
440 phydev->advertising &= ~(SUPPORTED_1000baseT_Half |
441 SUPPORTED_1000baseT_Full);
79ee1dc3 442
47dd7a54
GC
443 /*
444 * Broken HW is sometimes missing the pull-up resistor on the
445 * MDIO line, which results in reads to non-existent devices returning
446 * 0 rather than 0xffff. Catch this here and treat 0 as a non-existent
447 * device as well.
448 * Note: phydev->phy_id is the result of reading the UID PHY registers.
449 */
450 if (phydev->phy_id == 0) {
451 phy_disconnect(phydev);
452 return -ENODEV;
453 }
454 pr_debug("stmmac_init_phy: %s: attached to PHY (UID 0x%x)"
36bcfe7d 455 " Link = %d\n", dev->name, phydev->phy_id, phydev->link);
47dd7a54
GC
456
457 priv->phydev = phydev;
458
459 return 0;
460}
461
47dd7a54
GC
462/**
463 * display_ring
464 * @p: pointer to the ring.
465 * @size: size of the ring.
466 * Description: display all the descriptors within the ring.
467 */
468static void display_ring(struct dma_desc *p, int size)
469{
470 struct tmp_s {
471 u64 a;
472 unsigned int b;
473 unsigned int c;
474 };
475 int i;
476 for (i = 0; i < size; i++) {
477 struct tmp_s *x = (struct tmp_s *)(p + i);
478 pr_info("\t%d [0x%x]: DES0=0x%x DES1=0x%x BUF1=0x%x BUF2=0x%x",
479 i, (unsigned int)virt_to_phys(&p[i]),
480 (unsigned int)(x->a), (unsigned int)((x->a) >> 32),
481 x->b, x->c);
482 pr_info("\n");
483 }
484}
485
286a8372
GC
486static int stmmac_set_bfsize(int mtu, int bufsize)
487{
488 int ret = bufsize;
489
490 if (mtu >= BUF_SIZE_4KiB)
491 ret = BUF_SIZE_8KiB;
492 else if (mtu >= BUF_SIZE_2KiB)
493 ret = BUF_SIZE_4KiB;
494 else if (mtu >= DMA_BUFFER_SIZE)
495 ret = BUF_SIZE_2KiB;
496 else
497 ret = DMA_BUFFER_SIZE;
498
499 return ret;
500}
501
47dd7a54
GC
502/**
503 * init_dma_desc_rings - init the RX/TX descriptor rings
504 * @dev: net device structure
505 * Description: this function initializes the DMA RX/TX descriptors
286a8372
GC
506 * and allocates the socket buffers. It suppors the chained and ring
507 * modes.
47dd7a54
GC
508 */
509static void init_dma_desc_rings(struct net_device *dev)
510{
511 int i;
512 struct stmmac_priv *priv = netdev_priv(dev);
513 struct sk_buff *skb;
514 unsigned int txsize = priv->dma_tx_size;
515 unsigned int rxsize = priv->dma_rx_size;
286a8372
GC
516 unsigned int bfsize;
517 int dis_ic = 0;
518 int des3_as_data_buf = 0;
47dd7a54 519
286a8372
GC
520 /* Set the max buffer size according to the DESC mode
521 * and the MTU. Note that RING mode allows 16KiB bsize. */
522 bfsize = priv->hw->ring->set_16kib_bfsize(dev->mtu);
523
524 if (bfsize == BUF_SIZE_16KiB)
525 des3_as_data_buf = 1;
47dd7a54 526 else
286a8372 527 bfsize = stmmac_set_bfsize(dev->mtu, priv->dma_buf_sz);
47dd7a54 528
47dd7a54
GC
529 DBG(probe, INFO, "stmmac: txsize %d, rxsize %d, bfsize %d\n",
530 txsize, rxsize, bfsize);
531
532 priv->rx_skbuff_dma = kmalloc(rxsize * sizeof(dma_addr_t), GFP_KERNEL);
533 priv->rx_skbuff =
534 kmalloc(sizeof(struct sk_buff *) * rxsize, GFP_KERNEL);
535 priv->dma_rx =
536 (struct dma_desc *)dma_alloc_coherent(priv->device,
537 rxsize *
538 sizeof(struct dma_desc),
539 &priv->dma_rx_phy,
540 GFP_KERNEL);
541 priv->tx_skbuff = kmalloc(sizeof(struct sk_buff *) * txsize,
542 GFP_KERNEL);
543 priv->dma_tx =
544 (struct dma_desc *)dma_alloc_coherent(priv->device,
545 txsize *
546 sizeof(struct dma_desc),
547 &priv->dma_tx_phy,
548 GFP_KERNEL);
549
550 if ((priv->dma_rx == NULL) || (priv->dma_tx == NULL)) {
551 pr_err("%s:ERROR allocating the DMA Tx/Rx desc\n", __func__);
552 return;
553 }
554
286a8372 555 DBG(probe, INFO, "stmmac (%s) DMA desc: virt addr (Rx %p, "
47dd7a54
GC
556 "Tx %p)\n\tDMA phy addr (Rx 0x%08x, Tx 0x%08x)\n",
557 dev->name, priv->dma_rx, priv->dma_tx,
558 (unsigned int)priv->dma_rx_phy, (unsigned int)priv->dma_tx_phy);
559
560 /* RX INITIALIZATION */
561 DBG(probe, INFO, "stmmac: SKB addresses:\n"
562 "skb\t\tskb data\tdma data\n");
563
564 for (i = 0; i < rxsize; i++) {
565 struct dma_desc *p = priv->dma_rx + i;
566
45db81e1
GC
567 skb = __netdev_alloc_skb(dev, bfsize + NET_IP_ALIGN,
568 GFP_KERNEL);
47dd7a54
GC
569 if (unlikely(skb == NULL)) {
570 pr_err("%s: Rx init fails; skb is NULL\n", __func__);
571 break;
572 }
45db81e1 573 skb_reserve(skb, NET_IP_ALIGN);
47dd7a54
GC
574 priv->rx_skbuff[i] = skb;
575 priv->rx_skbuff_dma[i] = dma_map_single(priv->device, skb->data,
576 bfsize, DMA_FROM_DEVICE);
577
578 p->des2 = priv->rx_skbuff_dma[i];
286a8372
GC
579
580 priv->hw->ring->init_desc3(des3_as_data_buf, p);
581
47dd7a54
GC
582 DBG(probe, INFO, "[%p]\t[%p]\t[%x]\n", priv->rx_skbuff[i],
583 priv->rx_skbuff[i]->data, priv->rx_skbuff_dma[i]);
584 }
585 priv->cur_rx = 0;
586 priv->dirty_rx = (unsigned int)(i - rxsize);
587 priv->dma_buf_sz = bfsize;
588 buf_sz = bfsize;
589
590 /* TX INITIALIZATION */
591 for (i = 0; i < txsize; i++) {
592 priv->tx_skbuff[i] = NULL;
593 priv->dma_tx[i].des2 = 0;
594 }
286a8372
GC
595
596 /* In case of Chained mode this sets the des3 to the next
597 * element in the chain */
598 priv->hw->ring->init_dma_chain(priv->dma_rx, priv->dma_rx_phy, rxsize);
599 priv->hw->ring->init_dma_chain(priv->dma_tx, priv->dma_tx_phy, txsize);
600
47dd7a54
GC
601 priv->dirty_tx = 0;
602 priv->cur_tx = 0;
603
604 /* Clear the Rx/Tx descriptors */
db98a0b0
GC
605 priv->hw->desc->init_rx_desc(priv->dma_rx, rxsize, dis_ic);
606 priv->hw->desc->init_tx_desc(priv->dma_tx, txsize);
47dd7a54
GC
607
608 if (netif_msg_hw(priv)) {
609 pr_info("RX descriptor ring:\n");
610 display_ring(priv->dma_rx, rxsize);
611 pr_info("TX descriptor ring:\n");
612 display_ring(priv->dma_tx, txsize);
613 }
47dd7a54
GC
614}
615
616static void dma_free_rx_skbufs(struct stmmac_priv *priv)
617{
618 int i;
619
620 for (i = 0; i < priv->dma_rx_size; i++) {
621 if (priv->rx_skbuff[i]) {
622 dma_unmap_single(priv->device, priv->rx_skbuff_dma[i],
623 priv->dma_buf_sz, DMA_FROM_DEVICE);
624 dev_kfree_skb_any(priv->rx_skbuff[i]);
625 }
626 priv->rx_skbuff[i] = NULL;
627 }
47dd7a54
GC
628}
629
630static void dma_free_tx_skbufs(struct stmmac_priv *priv)
631{
632 int i;
633
634 for (i = 0; i < priv->dma_tx_size; i++) {
635 if (priv->tx_skbuff[i] != NULL) {
636 struct dma_desc *p = priv->dma_tx + i;
637 if (p->des2)
638 dma_unmap_single(priv->device, p->des2,
db98a0b0
GC
639 priv->hw->desc->get_tx_len(p),
640 DMA_TO_DEVICE);
47dd7a54
GC
641 dev_kfree_skb_any(priv->tx_skbuff[i]);
642 priv->tx_skbuff[i] = NULL;
643 }
644 }
47dd7a54
GC
645}
646
647static void free_dma_desc_resources(struct stmmac_priv *priv)
648{
649 /* Release the DMA TX/RX socket buffers */
650 dma_free_rx_skbufs(priv);
651 dma_free_tx_skbufs(priv);
652
653 /* Free the region of consistent memory previously allocated for
654 * the DMA */
655 dma_free_coherent(priv->device,
656 priv->dma_tx_size * sizeof(struct dma_desc),
657 priv->dma_tx, priv->dma_tx_phy);
658 dma_free_coherent(priv->device,
659 priv->dma_rx_size * sizeof(struct dma_desc),
660 priv->dma_rx, priv->dma_rx_phy);
661 kfree(priv->rx_skbuff_dma);
662 kfree(priv->rx_skbuff);
663 kfree(priv->tx_skbuff);
47dd7a54
GC
664}
665
47dd7a54
GC
666/**
667 * stmmac_dma_operation_mode - HW DMA operation mode
668 * @priv : pointer to the private device structure.
669 * Description: it sets the DMA operation mode: tx/rx DMA thresholds
ebbb293f 670 * or Store-And-Forward capability.
47dd7a54
GC
671 */
672static void stmmac_dma_operation_mode(struct stmmac_priv *priv)
673{
61b8013a
SK
674 if (likely(priv->plat->force_sf_dma_mode ||
675 ((priv->plat->tx_coe) && (!priv->no_csum_insertion)))) {
676 /*
677 * In case of GMAC, SF mode can be enabled
678 * to perform the TX COE in HW. This depends on:
ebbb293f
GC
679 * 1) TX COE if actually supported
680 * 2) There is no bugged Jumbo frame support
681 * that needs to not insert csum in the TDES.
682 */
683 priv->hw->dma->dma_mode(priv->ioaddr,
684 SF_DMA_MODE, SF_DMA_MODE);
685 tc = SF_DMA_MODE;
686 } else
687 priv->hw->dma->dma_mode(priv->ioaddr, tc, SF_DMA_MODE);
47dd7a54
GC
688}
689
47dd7a54
GC
690/**
691 * stmmac_tx:
692 * @priv: private driver structure
693 * Description: it reclaims resources after transmission completes.
694 */
695static void stmmac_tx(struct stmmac_priv *priv)
696{
697 unsigned int txsize = priv->dma_tx_size;
47dd7a54 698
a9097a96
GC
699 spin_lock(&priv->tx_lock);
700
47dd7a54
GC
701 while (priv->dirty_tx != priv->cur_tx) {
702 int last;
703 unsigned int entry = priv->dirty_tx % txsize;
704 struct sk_buff *skb = priv->tx_skbuff[entry];
705 struct dma_desc *p = priv->dma_tx + entry;
706
707 /* Check if the descriptor is owned by the DMA. */
db98a0b0 708 if (priv->hw->desc->get_tx_owner(p))
47dd7a54
GC
709 break;
710
711 /* Verify tx error by looking at the last segment */
db98a0b0 712 last = priv->hw->desc->get_tx_ls(p);
47dd7a54
GC
713 if (likely(last)) {
714 int tx_error =
db98a0b0
GC
715 priv->hw->desc->tx_status(&priv->dev->stats,
716 &priv->xstats, p,
ad01b7d4 717 priv->ioaddr);
47dd7a54
GC
718 if (likely(tx_error == 0)) {
719 priv->dev->stats.tx_packets++;
720 priv->xstats.tx_pkt_n++;
721 } else
722 priv->dev->stats.tx_errors++;
723 }
724 TX_DBG("%s: curr %d, dirty %d\n", __func__,
725 priv->cur_tx, priv->dirty_tx);
726
727 if (likely(p->des2))
728 dma_unmap_single(priv->device, p->des2,
db98a0b0 729 priv->hw->desc->get_tx_len(p),
47dd7a54 730 DMA_TO_DEVICE);
286a8372 731 priv->hw->ring->clean_desc3(p);
47dd7a54
GC
732
733 if (likely(skb != NULL)) {
acb600de 734 dev_kfree_skb(skb);
47dd7a54
GC
735 priv->tx_skbuff[entry] = NULL;
736 }
737
db98a0b0 738 priv->hw->desc->release_tx_desc(p);
47dd7a54 739
13497f58 740 priv->dirty_tx++;
47dd7a54
GC
741 }
742 if (unlikely(netif_queue_stopped(priv->dev) &&
743 stmmac_tx_avail(priv) > STMMAC_TX_THRESH(priv))) {
744 netif_tx_lock(priv->dev);
745 if (netif_queue_stopped(priv->dev) &&
746 stmmac_tx_avail(priv) > STMMAC_TX_THRESH(priv)) {
747 TX_DBG("%s: restart transmit\n", __func__);
748 netif_wake_queue(priv->dev);
749 }
750 netif_tx_unlock(priv->dev);
751 }
d765955d
GC
752
753 if ((priv->eee_enabled) && (!priv->tx_path_in_lpi_mode)) {
754 stmmac_enable_eee_mode(priv);
755 mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_TIMER(eee_timer));
756 }
a9097a96 757 spin_unlock(&priv->tx_lock);
47dd7a54
GC
758}
759
760static inline void stmmac_enable_irq(struct stmmac_priv *priv)
761{
7284a3f1 762 priv->hw->dma->enable_dma_irq(priv->ioaddr);
47dd7a54
GC
763}
764
765static inline void stmmac_disable_irq(struct stmmac_priv *priv)
766{
7284a3f1 767 priv->hw->dma->disable_dma_irq(priv->ioaddr);
47dd7a54
GC
768}
769
770static int stmmac_has_work(struct stmmac_priv *priv)
771{
772 unsigned int has_work = 0;
773 int rxret, tx_work = 0;
774
db98a0b0 775 rxret = priv->hw->desc->get_rx_owner(priv->dma_rx +
47dd7a54
GC
776 (priv->cur_rx % priv->dma_rx_size));
777
778 if (priv->dirty_tx != priv->cur_tx)
779 tx_work = 1;
780
781 if (likely(!rxret || tx_work))
782 has_work = 1;
783
784 return has_work;
785}
786
787static inline void _stmmac_schedule(struct stmmac_priv *priv)
788{
789 if (likely(stmmac_has_work(priv))) {
790 stmmac_disable_irq(priv);
791 napi_schedule(&priv->napi);
792 }
793}
794
47dd7a54
GC
795/**
796 * stmmac_tx_err:
797 * @priv: pointer to the private device structure
798 * Description: it cleans the descriptors and restarts the transmission
799 * in case of errors.
800 */
801static void stmmac_tx_err(struct stmmac_priv *priv)
802{
803 netif_stop_queue(priv->dev);
804
ad01b7d4 805 priv->hw->dma->stop_tx(priv->ioaddr);
47dd7a54 806 dma_free_tx_skbufs(priv);
db98a0b0 807 priv->hw->desc->init_tx_desc(priv->dma_tx, priv->dma_tx_size);
47dd7a54
GC
808 priv->dirty_tx = 0;
809 priv->cur_tx = 0;
ad01b7d4 810 priv->hw->dma->start_tx(priv->ioaddr);
47dd7a54
GC
811
812 priv->dev->stats.tx_errors++;
813 netif_wake_queue(priv->dev);
47dd7a54
GC
814}
815
47dd7a54 816
aec7ff27
GC
817static void stmmac_dma_interrupt(struct stmmac_priv *priv)
818{
aec7ff27
GC
819 int status;
820
ad01b7d4 821 status = priv->hw->dma->dma_interrupt(priv->ioaddr, &priv->xstats);
aec7ff27
GC
822 if (likely(status == handle_tx_rx))
823 _stmmac_schedule(priv);
824
825 else if (unlikely(status == tx_hard_error_bump_tc)) {
826 /* Try to bump up the dma threshold on this failure */
827 if (unlikely(tc != SF_DMA_MODE) && (tc <= 256)) {
828 tc += 64;
ad01b7d4 829 priv->hw->dma->dma_mode(priv->ioaddr, tc, SF_DMA_MODE);
aec7ff27 830 priv->xstats.threshold = tc;
47dd7a54 831 }
aec7ff27
GC
832 } else if (unlikely(status == tx_hard_error))
833 stmmac_tx_err(priv);
47dd7a54
GC
834}
835
1c901a46
GC
836static void stmmac_mmc_setup(struct stmmac_priv *priv)
837{
838 unsigned int mode = MMC_CNTRL_RESET_ON_READ | MMC_CNTRL_COUNTER_RESET |
839 MMC_CNTRL_PRESET | MMC_CNTRL_FULL_HALF_PRESET;
840
4f795b25
GC
841 /* Mask MMC irq, counters are managed in SW and registers
842 * are cleared on each READ eventually. */
1c901a46 843 dwmac_mmc_intr_all_mask(priv->ioaddr);
4f795b25
GC
844
845 if (priv->dma_cap.rmon) {
846 dwmac_mmc_ctrl(priv->ioaddr, mode);
847 memset(&priv->mmc, 0, sizeof(struct stmmac_counters));
848 } else
aae54cff 849 pr_info(" No MAC Management Counters available\n");
1c901a46
GC
850}
851
f0b9d786
GC
852static u32 stmmac_get_synopsys_id(struct stmmac_priv *priv)
853{
854 u32 hwid = priv->hw->synopsys_uid;
855
856 /* Only check valid Synopsys Id because old MAC chips
857 * have no HW registers where get the ID */
858 if (likely(hwid)) {
859 u32 uid = ((hwid & 0x0000ff00) >> 8);
860 u32 synid = (hwid & 0x000000ff);
861
cf3f047b 862 pr_info("stmmac - user ID: 0x%x, Synopsys ID: 0x%x\n",
f0b9d786
GC
863 uid, synid);
864
865 return synid;
866 }
867 return 0;
868}
e7434821 869
19e30c14
GC
870/**
871 * stmmac_selec_desc_mode
ff3dd78c
GC
872 * @priv : private structure
873 * Description: select the Enhanced/Alternate or Normal descriptors
874 */
19e30c14
GC
875static void stmmac_selec_desc_mode(struct stmmac_priv *priv)
876{
877 if (priv->plat->enh_desc) {
878 pr_info(" Enhanced/Alternate descriptors\n");
879 priv->hw->desc = &enh_desc_ops;
880 } else {
881 pr_info(" Normal descriptors\n");
882 priv->hw->desc = &ndesc_ops;
883 }
884}
885
886/**
887 * stmmac_get_hw_features
888 * @priv : private device pointer
889 * Description:
890 * new GMAC chip generations have a new register to indicate the
891 * presence of the optional feature/functions.
892 * This can be also used to override the value passed through the
893 * platform and necessary for old MAC10/100 and GMAC chips.
e7434821
GC
894 */
895static int stmmac_get_hw_features(struct stmmac_priv *priv)
896{
5e6efe88 897 u32 hw_cap = 0;
3c20f72f 898
5e6efe88
GC
899 if (priv->hw->dma->get_hw_feature) {
900 hw_cap = priv->hw->dma->get_hw_feature(priv->ioaddr);
e7434821 901
1db123fb
RK
902 priv->dma_cap.mbps_10_100 = (hw_cap & DMA_HW_FEAT_MIISEL);
903 priv->dma_cap.mbps_1000 = (hw_cap & DMA_HW_FEAT_GMIISEL) >> 1;
904 priv->dma_cap.half_duplex = (hw_cap & DMA_HW_FEAT_HDSEL) >> 2;
905 priv->dma_cap.hash_filter = (hw_cap & DMA_HW_FEAT_HASHSEL) >> 4;
906 priv->dma_cap.multi_addr =
907 (hw_cap & DMA_HW_FEAT_ADDMACADRSEL) >> 5;
908 priv->dma_cap.pcs = (hw_cap & DMA_HW_FEAT_PCSSEL) >> 6;
909 priv->dma_cap.sma_mdio = (hw_cap & DMA_HW_FEAT_SMASEL) >> 8;
910 priv->dma_cap.pmt_remote_wake_up =
911 (hw_cap & DMA_HW_FEAT_RWKSEL) >> 9;
912 priv->dma_cap.pmt_magic_frame =
913 (hw_cap & DMA_HW_FEAT_MGKSEL) >> 10;
19e30c14 914 /* MMC */
1db123fb 915 priv->dma_cap.rmon = (hw_cap & DMA_HW_FEAT_MMCSEL) >> 11;
e7434821 916 /* IEEE 1588-2002*/
1db123fb
RK
917 priv->dma_cap.time_stamp =
918 (hw_cap & DMA_HW_FEAT_TSVER1SEL) >> 12;
e7434821 919 /* IEEE 1588-2008*/
1db123fb
RK
920 priv->dma_cap.atime_stamp =
921 (hw_cap & DMA_HW_FEAT_TSVER2SEL) >> 13;
e7434821 922 /* 802.3az - Energy-Efficient Ethernet (EEE) */
1db123fb
RK
923 priv->dma_cap.eee = (hw_cap & DMA_HW_FEAT_EEESEL) >> 14;
924 priv->dma_cap.av = (hw_cap & DMA_HW_FEAT_AVSEL) >> 15;
e7434821 925 /* TX and RX csum */
1db123fb
RK
926 priv->dma_cap.tx_coe = (hw_cap & DMA_HW_FEAT_TXCOESEL) >> 16;
927 priv->dma_cap.rx_coe_type1 =
928 (hw_cap & DMA_HW_FEAT_RXTYP1COE) >> 17;
929 priv->dma_cap.rx_coe_type2 =
930 (hw_cap & DMA_HW_FEAT_RXTYP2COE) >> 18;
931 priv->dma_cap.rxfifo_over_2048 =
932 (hw_cap & DMA_HW_FEAT_RXFIFOSIZE) >> 19;
e7434821 933 /* TX and RX number of channels */
1db123fb
RK
934 priv->dma_cap.number_rx_channel =
935 (hw_cap & DMA_HW_FEAT_RXCHCNT) >> 20;
936 priv->dma_cap.number_tx_channel =
937 (hw_cap & DMA_HW_FEAT_TXCHCNT) >> 22;
e7434821 938 /* Alternate (enhanced) DESC mode*/
1db123fb
RK
939 priv->dma_cap.enh_desc =
940 (hw_cap & DMA_HW_FEAT_ENHDESSEL) >> 24;
e7434821 941
19e30c14 942 }
e7434821
GC
943
944 return hw_cap;
945}
946
bfab27a1
GC
947static void stmmac_check_ether_addr(struct stmmac_priv *priv)
948{
949 /* verify if the MAC address is valid, in case of failures it
950 * generates a random MAC address */
951 if (!is_valid_ether_addr(priv->dev->dev_addr)) {
952 priv->hw->mac->get_umac_addr((void __iomem *)
953 priv->dev->base_addr,
954 priv->dev->dev_addr, 0);
955 if (!is_valid_ether_addr(priv->dev->dev_addr))
f2cedb63 956 eth_hw_addr_random(priv->dev);
bfab27a1
GC
957 }
958 pr_warning("%s: device MAC address %pM\n", priv->dev->name,
959 priv->dev->dev_addr);
960}
961
0f1f88a8
GC
962static int stmmac_init_dma_engine(struct stmmac_priv *priv)
963{
964 int pbl = DEFAULT_DMA_PBL, fixed_burst = 0, burst_len = 0;
b9cde0a8 965 int mixed_burst = 0;
0f1f88a8
GC
966
967 /* Some DMA parameters can be passed from the platform;
968 * in case of these are not passed we keep a default
969 * (good for all the chips) and init the DMA! */
970 if (priv->plat->dma_cfg) {
971 pbl = priv->plat->dma_cfg->pbl;
972 fixed_burst = priv->plat->dma_cfg->fixed_burst;
b9cde0a8 973 mixed_burst = priv->plat->dma_cfg->mixed_burst;
0f1f88a8
GC
974 burst_len = priv->plat->dma_cfg->burst_len;
975 }
976
b9cde0a8 977 return priv->hw->dma->init(priv->ioaddr, pbl, fixed_burst, mixed_burst,
0f1f88a8
GC
978 burst_len, priv->dma_tx_phy,
979 priv->dma_rx_phy);
980}
981
47dd7a54
GC
982/**
983 * stmmac_open - open entry point of the driver
984 * @dev : pointer to the device structure.
985 * Description:
986 * This function is the open entry point of the driver.
987 * Return value:
988 * 0 on success and an appropriate (-)ve integer as defined in errno.h
989 * file on failure.
990 */
991static int stmmac_open(struct net_device *dev)
992{
993 struct stmmac_priv *priv = netdev_priv(dev);
47dd7a54
GC
994 int ret;
995
a630844d 996 clk_prepare_enable(priv->stmmac_clk);
4bfcbd7a
FV
997
998 stmmac_check_ether_addr(priv);
999
f66ffe28
GC
1000 ret = stmmac_init_phy(dev);
1001 if (unlikely(ret)) {
1002 pr_err("%s: Cannot attach to PHY (error: %d)\n", __func__, ret);
1003 goto open_error;
1004 }
47dd7a54
GC
1005
1006 /* Create and initialize the TX/RX descriptors chains. */
1007 priv->dma_tx_size = STMMAC_ALIGN(dma_txsize);
1008 priv->dma_rx_size = STMMAC_ALIGN(dma_rxsize);
1009 priv->dma_buf_sz = STMMAC_ALIGN(buf_sz);
1010 init_dma_desc_rings(dev);
1011
1012 /* DMA initialization and SW reset */
0f1f88a8 1013 ret = stmmac_init_dma_engine(priv);
f66ffe28 1014 if (ret < 0) {
47dd7a54 1015 pr_err("%s: DMA initialization failed\n", __func__);
f66ffe28 1016 goto open_error;
47dd7a54
GC
1017 }
1018
1019 /* Copy the MAC addr into the HW */
ad01b7d4 1020 priv->hw->mac->set_umac_addr(priv->ioaddr, dev->dev_addr, 0);
cf3f047b 1021
ca5f12c1 1022 /* If required, perform hw setup of the bus. */
9dfeb4d9
GC
1023 if (priv->plat->bus_setup)
1024 priv->plat->bus_setup(priv->ioaddr);
cf3f047b 1025
47dd7a54 1026 /* Initialize the MAC Core */
ad01b7d4 1027 priv->hw->mac->core_init(priv->ioaddr);
47dd7a54 1028
f66ffe28
GC
1029 /* Request the IRQ lines */
1030 ret = request_irq(dev->irq, stmmac_interrupt,
1031 IRQF_SHARED, dev->name, dev);
1032 if (unlikely(ret < 0)) {
1033 pr_err("%s: ERROR: allocating the IRQ %d (error: %d)\n",
1034 __func__, dev->irq, ret);
1035 goto open_error;
1036 }
1037
7a13f8f5
FV
1038 /* Request the Wake IRQ in case of another line is used for WoL */
1039 if (priv->wol_irq != dev->irq) {
1040 ret = request_irq(priv->wol_irq, stmmac_interrupt,
1041 IRQF_SHARED, dev->name, dev);
1042 if (unlikely(ret < 0)) {
1043 pr_err("%s: ERROR: allocating the ext WoL IRQ %d "
1044 "(error: %d)\n", __func__, priv->wol_irq, ret);
1045 goto open_error_wolirq;
1046 }
1047 }
1048
d765955d
GC
1049 /* Request the IRQ lines */
1050 if (priv->lpi_irq != -ENXIO) {
1051 ret = request_irq(priv->lpi_irq, stmmac_interrupt, IRQF_SHARED,
1052 dev->name, dev);
1053 if (unlikely(ret < 0)) {
1054 pr_err("%s: ERROR: allocating the LPI IRQ %d (%d)\n",
1055 __func__, priv->lpi_irq, ret);
1056 goto open_error_lpiirq;
1057 }
1058 }
1059
47dd7a54 1060 /* Enable the MAC Rx/Tx */
bfab27a1 1061 stmmac_set_mac(priv->ioaddr, true);
47dd7a54
GC
1062
1063 /* Set the HW DMA mode and the COE */
1064 stmmac_dma_operation_mode(priv);
1065
1066 /* Extra statistics */
1067 memset(&priv->xstats, 0, sizeof(struct stmmac_extra_stats));
1068 priv->xstats.threshold = tc;
1069
4f795b25 1070 stmmac_mmc_setup(priv);
1c901a46 1071
bfab27a1
GC
1072#ifdef CONFIG_STMMAC_DEBUG_FS
1073 ret = stmmac_init_fs(dev);
1074 if (ret < 0)
cf3f047b 1075 pr_warning("%s: failed debugFS registration\n", __func__);
bfab27a1 1076#endif
47dd7a54
GC
1077 /* Start the ball rolling... */
1078 DBG(probe, DEBUG, "%s: DMA RX/TX processes started...\n", dev->name);
ad01b7d4
GC
1079 priv->hw->dma->start_tx(priv->ioaddr);
1080 priv->hw->dma->start_rx(priv->ioaddr);
47dd7a54 1081
47dd7a54
GC
1082 /* Dump DMA/MAC registers */
1083 if (netif_msg_hw(priv)) {
ad01b7d4
GC
1084 priv->hw->mac->dump_regs(priv->ioaddr);
1085 priv->hw->dma->dump_regs(priv->ioaddr);
47dd7a54
GC
1086 }
1087
1088 if (priv->phydev)
1089 phy_start(priv->phydev);
1090
d765955d
GC
1091 priv->tx_lpi_timer = STMMAC_DEFAULT_TWT_LS_TIMER;
1092 priv->eee_enabled = stmmac_eee_init(priv);
1093
47dd7a54 1094 napi_enable(&priv->napi);
47dd7a54 1095 netif_start_queue(dev);
f66ffe28 1096
47dd7a54 1097 return 0;
f66ffe28 1098
d765955d
GC
1099open_error_lpiirq:
1100 if (priv->wol_irq != dev->irq)
1101 free_irq(priv->wol_irq, dev);
1102
7a13f8f5
FV
1103open_error_wolirq:
1104 free_irq(dev->irq, dev);
1105
f66ffe28 1106open_error:
f66ffe28
GC
1107 if (priv->phydev)
1108 phy_disconnect(priv->phydev);
1109
a630844d 1110 clk_disable_unprepare(priv->stmmac_clk);
4bfcbd7a 1111
f66ffe28 1112 return ret;
47dd7a54
GC
1113}
1114
1115/**
1116 * stmmac_release - close entry point of the driver
1117 * @dev : device pointer.
1118 * Description:
1119 * This is the stop entry point of the driver.
1120 */
1121static int stmmac_release(struct net_device *dev)
1122{
1123 struct stmmac_priv *priv = netdev_priv(dev);
1124
d765955d
GC
1125 if (priv->eee_enabled)
1126 del_timer_sync(&priv->eee_ctrl_timer);
1127
47dd7a54
GC
1128 /* Stop and disconnect the PHY */
1129 if (priv->phydev) {
1130 phy_stop(priv->phydev);
1131 phy_disconnect(priv->phydev);
1132 priv->phydev = NULL;
1133 }
1134
1135 netif_stop_queue(dev);
1136
47dd7a54 1137 napi_disable(&priv->napi);
47dd7a54
GC
1138
1139 /* Free the IRQ lines */
1140 free_irq(dev->irq, dev);
7a13f8f5
FV
1141 if (priv->wol_irq != dev->irq)
1142 free_irq(priv->wol_irq, dev);
d765955d
GC
1143 if (priv->lpi_irq != -ENXIO)
1144 free_irq(priv->lpi_irq, dev);
47dd7a54
GC
1145
1146 /* Stop TX/RX DMA and clear the descriptors */
ad01b7d4
GC
1147 priv->hw->dma->stop_tx(priv->ioaddr);
1148 priv->hw->dma->stop_rx(priv->ioaddr);
47dd7a54
GC
1149
1150 /* Release and free the Rx/Tx resources */
1151 free_dma_desc_resources(priv);
1152
19449bfc 1153 /* Disable the MAC Rx/Tx */
bfab27a1 1154 stmmac_set_mac(priv->ioaddr, false);
47dd7a54
GC
1155
1156 netif_carrier_off(dev);
1157
bfab27a1
GC
1158#ifdef CONFIG_STMMAC_DEBUG_FS
1159 stmmac_exit_fs();
1160#endif
a630844d 1161 clk_disable_unprepare(priv->stmmac_clk);
bfab27a1 1162
47dd7a54
GC
1163 return 0;
1164}
1165
47dd7a54
GC
1166/**
1167 * stmmac_xmit:
1168 * @skb : the socket buffer
1169 * @dev : device pointer
1170 * Description : Tx entry point of the driver.
1171 */
1172static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
1173{
1174 struct stmmac_priv *priv = netdev_priv(dev);
1175 unsigned int txsize = priv->dma_tx_size;
1176 unsigned int entry;
1177 int i, csum_insertion = 0;
1178 int nfrags = skb_shinfo(skb)->nr_frags;
1179 struct dma_desc *desc, *first;
286a8372 1180 unsigned int nopaged_len = skb_headlen(skb);
47dd7a54
GC
1181
1182 if (unlikely(stmmac_tx_avail(priv) < nfrags + 1)) {
1183 if (!netif_queue_stopped(dev)) {
1184 netif_stop_queue(dev);
1185 /* This is a hard error, log it. */
1186 pr_err("%s: BUG! Tx Ring full when queue awake\n",
1187 __func__);
1188 }
1189 return NETDEV_TX_BUSY;
1190 }
1191
a9097a96
GC
1192 spin_lock(&priv->tx_lock);
1193
d765955d
GC
1194 if (priv->tx_path_in_lpi_mode)
1195 stmmac_disable_eee_mode(priv);
1196
47dd7a54
GC
1197 entry = priv->cur_tx % txsize;
1198
1199#ifdef STMMAC_XMIT_DEBUG
1200 if ((skb->len > ETH_FRAME_LEN) || nfrags)
1201 pr_info("stmmac xmit:\n"
1202 "\tskb addr %p - len: %d - nopaged_len: %d\n"
1203 "\tn_frags: %d - ip_summed: %d - %s gso\n",
286a8372 1204 skb, skb->len, nopaged_len, nfrags, skb->ip_summed,
47dd7a54
GC
1205 !skb_is_gso(skb) ? "isn't" : "is");
1206#endif
1207
5e982f3b 1208 csum_insertion = (skb->ip_summed == CHECKSUM_PARTIAL);
47dd7a54
GC
1209
1210 desc = priv->dma_tx + entry;
1211 first = desc;
1212
1213#ifdef STMMAC_XMIT_DEBUG
1214 if ((nfrags > 0) || (skb->len > ETH_FRAME_LEN))
1215 pr_debug("stmmac xmit: skb len: %d, nopaged_len: %d,\n"
1216 "\t\tn_frags: %d, ip_summed: %d\n",
286a8372 1217 skb->len, nopaged_len, nfrags, skb->ip_summed);
47dd7a54
GC
1218#endif
1219 priv->tx_skbuff[entry] = skb;
286a8372
GC
1220
1221 if (priv->hw->ring->is_jumbo_frm(skb->len, priv->plat->enh_desc)) {
1222 entry = priv->hw->ring->jumbo_frm(priv, skb, csum_insertion);
47dd7a54
GC
1223 desc = priv->dma_tx + entry;
1224 } else {
47dd7a54
GC
1225 desc->des2 = dma_map_single(priv->device, skb->data,
1226 nopaged_len, DMA_TO_DEVICE);
db98a0b0
GC
1227 priv->hw->desc->prepare_tx_desc(desc, 1, nopaged_len,
1228 csum_insertion);
47dd7a54
GC
1229 }
1230
1231 for (i = 0; i < nfrags; i++) {
9e903e08
ED
1232 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1233 int len = skb_frag_size(frag);
47dd7a54
GC
1234
1235 entry = (++priv->cur_tx) % txsize;
1236 desc = priv->dma_tx + entry;
1237
1238 TX_DBG("\t[entry %d] segment len: %d\n", entry, len);
f722380d
IC
1239 desc->des2 = skb_frag_dma_map(priv->device, frag, 0, len,
1240 DMA_TO_DEVICE);
47dd7a54 1241 priv->tx_skbuff[entry] = NULL;
db98a0b0 1242 priv->hw->desc->prepare_tx_desc(desc, 0, len, csum_insertion);
eb0dc4bb 1243 wmb();
db98a0b0 1244 priv->hw->desc->set_tx_owner(desc);
8e839891 1245 wmb();
47dd7a54
GC
1246 }
1247
1248 /* Interrupt on completition only for the latest segment */
db98a0b0 1249 priv->hw->desc->close_tx_desc(desc);
73cfe264 1250
eb0dc4bb
SH
1251 wmb();
1252
47dd7a54 1253 /* To avoid raise condition */
db98a0b0 1254 priv->hw->desc->set_tx_owner(first);
8e839891 1255 wmb();
47dd7a54
GC
1256
1257 priv->cur_tx++;
1258
1259#ifdef STMMAC_XMIT_DEBUG
1260 if (netif_msg_pktdata(priv)) {
1261 pr_info("stmmac xmit: current=%d, dirty=%d, entry=%d, "
1262 "first=%p, nfrags=%d\n",
1263 (priv->cur_tx % txsize), (priv->dirty_tx % txsize),
1264 entry, first, nfrags);
1265 display_ring(priv->dma_tx, txsize);
1266 pr_info(">>> frame to be transmitted: ");
1267 print_pkt(skb->data, skb->len);
1268 }
1269#endif
1270 if (unlikely(stmmac_tx_avail(priv) <= (MAX_SKB_FRAGS + 1))) {
1271 TX_DBG("%s: stop transmitted packets\n", __func__);
1272 netif_stop_queue(dev);
1273 }
1274
1275 dev->stats.tx_bytes += skb->len;
1276
3e82ce12
RC
1277 skb_tx_timestamp(skb);
1278
52f64fae
RC
1279 priv->hw->dma->enable_dma_transmission(priv->ioaddr);
1280
a9097a96
GC
1281 spin_unlock(&priv->tx_lock);
1282
47dd7a54
GC
1283 return NETDEV_TX_OK;
1284}
1285
1286static inline void stmmac_rx_refill(struct stmmac_priv *priv)
1287{
1288 unsigned int rxsize = priv->dma_rx_size;
1289 int bfsize = priv->dma_buf_sz;
1290 struct dma_desc *p = priv->dma_rx;
1291
1292 for (; priv->cur_rx - priv->dirty_rx > 0; priv->dirty_rx++) {
1293 unsigned int entry = priv->dirty_rx % rxsize;
1294 if (likely(priv->rx_skbuff[entry] == NULL)) {
1295 struct sk_buff *skb;
1296
acb600de 1297 skb = netdev_alloc_skb_ip_align(priv->dev, bfsize);
47dd7a54
GC
1298
1299 if (unlikely(skb == NULL))
1300 break;
1301
1302 priv->rx_skbuff[entry] = skb;
1303 priv->rx_skbuff_dma[entry] =
1304 dma_map_single(priv->device, skb->data, bfsize,
1305 DMA_FROM_DEVICE);
1306
1307 (p + entry)->des2 = priv->rx_skbuff_dma[entry];
286a8372
GC
1308
1309 if (unlikely(priv->plat->has_gmac))
1310 priv->hw->ring->refill_desc3(bfsize, p + entry);
1311
47dd7a54
GC
1312 RX_DBG(KERN_INFO "\trefill entry #%d\n", entry);
1313 }
eb0dc4bb 1314 wmb();
db98a0b0 1315 priv->hw->desc->set_rx_owner(p + entry);
8e839891 1316 wmb();
47dd7a54 1317 }
47dd7a54
GC
1318}
1319
1320static int stmmac_rx(struct stmmac_priv *priv, int limit)
1321{
1322 unsigned int rxsize = priv->dma_rx_size;
1323 unsigned int entry = priv->cur_rx % rxsize;
1324 unsigned int next_entry;
1325 unsigned int count = 0;
1326 struct dma_desc *p = priv->dma_rx + entry;
1327 struct dma_desc *p_next;
1328
1329#ifdef STMMAC_RX_DEBUG
1330 if (netif_msg_hw(priv)) {
1331 pr_debug(">>> stmmac_rx: descriptor ring:\n");
1332 display_ring(priv->dma_rx, rxsize);
1333 }
1334#endif
db98a0b0 1335 while (!priv->hw->desc->get_rx_owner(p)) {
47dd7a54
GC
1336 int status;
1337
1338 if (count >= limit)
1339 break;
1340
1341 count++;
1342
1343 next_entry = (++priv->cur_rx) % rxsize;
1344 p_next = priv->dma_rx + next_entry;
1345 prefetch(p_next);
1346
1347 /* read the status of the incoming frame */
db98a0b0
GC
1348 status = (priv->hw->desc->rx_status(&priv->dev->stats,
1349 &priv->xstats, p));
47dd7a54
GC
1350 if (unlikely(status == discard_frame))
1351 priv->dev->stats.rx_errors++;
1352 else {
1353 struct sk_buff *skb;
3eeb2997 1354 int frame_len;
47dd7a54 1355
38912bdb
DS
1356 frame_len = priv->hw->desc->get_rx_frame_len(p,
1357 priv->plat->rx_coe);
3eeb2997
GC
1358 /* ACS is set; GMAC core strips PAD/FCS for IEEE 802.3
1359 * Type frames (LLC/LLC-SNAP) */
1360 if (unlikely(status != llc_snap))
1361 frame_len -= ETH_FCS_LEN;
47dd7a54
GC
1362#ifdef STMMAC_RX_DEBUG
1363 if (frame_len > ETH_FRAME_LEN)
1364 pr_debug("\tRX frame size %d, COE status: %d\n",
1365 frame_len, status);
1366
1367 if (netif_msg_hw(priv))
1368 pr_debug("\tdesc: %p [entry %d] buff=0x%x\n",
1369 p, entry, p->des2);
1370#endif
1371 skb = priv->rx_skbuff[entry];
1372 if (unlikely(!skb)) {
1373 pr_err("%s: Inconsistent Rx descriptor chain\n",
1374 priv->dev->name);
1375 priv->dev->stats.rx_dropped++;
1376 break;
1377 }
1378 prefetch(skb->data - NET_IP_ALIGN);
1379 priv->rx_skbuff[entry] = NULL;
1380
1381 skb_put(skb, frame_len);
1382 dma_unmap_single(priv->device,
1383 priv->rx_skbuff_dma[entry],
1384 priv->dma_buf_sz, DMA_FROM_DEVICE);
1385#ifdef STMMAC_RX_DEBUG
1386 if (netif_msg_pktdata(priv)) {
1387 pr_info(" frame received (%dbytes)", frame_len);
1388 print_pkt(skb->data, frame_len);
1389 }
1390#endif
1391 skb->protocol = eth_type_trans(skb, priv->dev);
1392
38912bdb 1393 if (unlikely(!priv->plat->rx_coe)) {
3c20f72f 1394 /* No RX COE for old mac10/100 devices */
bc8acf2c 1395 skb_checksum_none_assert(skb);
47dd7a54
GC
1396 netif_receive_skb(skb);
1397 } else {
1398 skb->ip_summed = CHECKSUM_UNNECESSARY;
1399 napi_gro_receive(&priv->napi, skb);
1400 }
1401
1402 priv->dev->stats.rx_packets++;
1403 priv->dev->stats.rx_bytes += frame_len;
47dd7a54
GC
1404 }
1405 entry = next_entry;
1406 p = p_next; /* use prefetched values */
1407 }
1408
1409 stmmac_rx_refill(priv);
1410
1411 priv->xstats.rx_pkt_n += count;
1412
1413 return count;
1414}
1415
1416/**
1417 * stmmac_poll - stmmac poll method (NAPI)
1418 * @napi : pointer to the napi structure.
1419 * @budget : maximum number of packets that the current CPU can receive from
1420 * all interfaces.
1421 * Description :
1422 * This function implements the the reception process.
1423 * Also it runs the TX completion thread
1424 */
1425static int stmmac_poll(struct napi_struct *napi, int budget)
1426{
1427 struct stmmac_priv *priv = container_of(napi, struct stmmac_priv, napi);
1428 int work_done = 0;
1429
1430 priv->xstats.poll_n++;
1431 stmmac_tx(priv);
1432 work_done = stmmac_rx(priv, budget);
1433
1434 if (work_done < budget) {
1435 napi_complete(napi);
1436 stmmac_enable_irq(priv);
1437 }
1438 return work_done;
1439}
1440
1441/**
1442 * stmmac_tx_timeout
1443 * @dev : Pointer to net device structure
1444 * Description: this function is called when a packet transmission fails to
7284a3f1 1445 * complete within a reasonable time. The driver will mark the error in the
47dd7a54
GC
1446 * netdev structure and arrange for the device to be reset to a sane state
1447 * in order to transmit a new packet.
1448 */
1449static void stmmac_tx_timeout(struct net_device *dev)
1450{
1451 struct stmmac_priv *priv = netdev_priv(dev);
1452
1453 /* Clear Tx resources and restart transmitting again */
1454 stmmac_tx_err(priv);
47dd7a54
GC
1455}
1456
1457/* Configuration changes (passed on by ifconfig) */
1458static int stmmac_config(struct net_device *dev, struct ifmap *map)
1459{
1460 if (dev->flags & IFF_UP) /* can't act on a running interface */
1461 return -EBUSY;
1462
1463 /* Don't allow changing the I/O address */
1464 if (map->base_addr != dev->base_addr) {
1465 pr_warning("%s: can't change I/O address\n", dev->name);
1466 return -EOPNOTSUPP;
1467 }
1468
1469 /* Don't allow changing the IRQ */
1470 if (map->irq != dev->irq) {
1471 pr_warning("%s: can't change IRQ number %d\n",
1472 dev->name, dev->irq);
1473 return -EOPNOTSUPP;
1474 }
1475
1476 /* ignore other fields */
1477 return 0;
1478}
1479
1480/**
01789349 1481 * stmmac_set_rx_mode - entry point for multicast addressing
47dd7a54
GC
1482 * @dev : pointer to the device structure
1483 * Description:
1484 * This function is a driver entry point which gets called by the kernel
1485 * whenever multicast addresses must be enabled/disabled.
1486 * Return value:
1487 * void.
1488 */
01789349 1489static void stmmac_set_rx_mode(struct net_device *dev)
47dd7a54
GC
1490{
1491 struct stmmac_priv *priv = netdev_priv(dev);
1492
1493 spin_lock(&priv->lock);
cffb13f4 1494 priv->hw->mac->set_filter(dev, priv->synopsys_id);
47dd7a54 1495 spin_unlock(&priv->lock);
47dd7a54
GC
1496}
1497
1498/**
1499 * stmmac_change_mtu - entry point to change MTU size for the device.
1500 * @dev : device pointer.
1501 * @new_mtu : the new MTU size for the device.
1502 * Description: the Maximum Transfer Unit (MTU) is used by the network layer
1503 * to drive packet transmission. Ethernet has an MTU of 1500 octets
1504 * (ETH_DATA_LEN). This value can be changed with ifconfig.
1505 * Return value:
1506 * 0 on success and an appropriate (-)ve integer as defined in errno.h
1507 * file on failure.
1508 */
1509static int stmmac_change_mtu(struct net_device *dev, int new_mtu)
1510{
1511 struct stmmac_priv *priv = netdev_priv(dev);
1512 int max_mtu;
1513
1514 if (netif_running(dev)) {
1515 pr_err("%s: must be stopped to change its MTU\n", dev->name);
1516 return -EBUSY;
1517 }
1518
48febf7e 1519 if (priv->plat->enh_desc)
47dd7a54
GC
1520 max_mtu = JUMBO_LEN;
1521 else
45db81e1 1522 max_mtu = SKB_MAX_HEAD(NET_SKB_PAD + NET_IP_ALIGN);
47dd7a54
GC
1523
1524 if ((new_mtu < 46) || (new_mtu > max_mtu)) {
1525 pr_err("%s: invalid MTU, max MTU is: %d\n", dev->name, max_mtu);
1526 return -EINVAL;
1527 }
1528
5e982f3b
MM
1529 dev->mtu = new_mtu;
1530 netdev_update_features(dev);
1531
1532 return 0;
1533}
1534
c8f44aff
MM
1535static netdev_features_t stmmac_fix_features(struct net_device *dev,
1536 netdev_features_t features)
5e982f3b
MM
1537{
1538 struct stmmac_priv *priv = netdev_priv(dev);
1539
38912bdb 1540 if (priv->plat->rx_coe == STMMAC_RX_COE_NONE)
5e982f3b 1541 features &= ~NETIF_F_RXCSUM;
38912bdb
DS
1542 else if (priv->plat->rx_coe == STMMAC_RX_COE_TYPE1)
1543 features &= ~NETIF_F_IPV6_CSUM;
5e982f3b
MM
1544 if (!priv->plat->tx_coe)
1545 features &= ~NETIF_F_ALL_CSUM;
1546
ebbb293f
GC
1547 /* Some GMAC devices have a bugged Jumbo frame support that
1548 * needs to have the Tx COE disabled for oversized frames
1549 * (due to limited buffer sizes). In this case we disable
1550 * the TX csum insertionin the TDES and not use SF. */
5e982f3b
MM
1551 if (priv->plat->bugged_jumbo && (dev->mtu > ETH_DATA_LEN))
1552 features &= ~NETIF_F_ALL_CSUM;
ebbb293f 1553
5e982f3b 1554 return features;
47dd7a54
GC
1555}
1556
1557static irqreturn_t stmmac_interrupt(int irq, void *dev_id)
1558{
1559 struct net_device *dev = (struct net_device *)dev_id;
1560 struct stmmac_priv *priv = netdev_priv(dev);
1561
1562 if (unlikely(!dev)) {
1563 pr_err("%s: invalid dev pointer\n", __func__);
1564 return IRQ_NONE;
1565 }
1566
d765955d
GC
1567 /* To handle GMAC own interrupts */
1568 if (priv->plat->has_gmac) {
1569 int status = priv->hw->mac->host_irq_status((void __iomem *)
1570 dev->base_addr);
1571 if (unlikely(status)) {
1572 if (status & core_mmc_tx_irq)
1573 priv->xstats.mmc_tx_irq_n++;
1574 if (status & core_mmc_rx_irq)
1575 priv->xstats.mmc_rx_irq_n++;
1576 if (status & core_mmc_rx_csum_offload_irq)
1577 priv->xstats.mmc_rx_csum_offload_irq_n++;
1578 if (status & core_irq_receive_pmt_irq)
1579 priv->xstats.irq_receive_pmt_irq_n++;
1580
1581 /* For LPI we need to save the tx status */
1582 if (status & core_irq_tx_path_in_lpi_mode) {
1583 priv->xstats.irq_tx_path_in_lpi_mode_n++;
1584 priv->tx_path_in_lpi_mode = true;
1585 }
1586 if (status & core_irq_tx_path_exit_lpi_mode) {
1587 priv->xstats.irq_tx_path_exit_lpi_mode_n++;
1588 priv->tx_path_in_lpi_mode = false;
1589 }
1590 if (status & core_irq_rx_path_in_lpi_mode)
1591 priv->xstats.irq_rx_path_in_lpi_mode_n++;
1592 if (status & core_irq_rx_path_exit_lpi_mode)
1593 priv->xstats.irq_rx_path_exit_lpi_mode_n++;
1594 }
1595 }
aec7ff27 1596
d765955d 1597 /* To handle DMA interrupts */
aec7ff27 1598 stmmac_dma_interrupt(priv);
47dd7a54
GC
1599
1600 return IRQ_HANDLED;
1601}
1602
1603#ifdef CONFIG_NET_POLL_CONTROLLER
1604/* Polling receive - used by NETCONSOLE and other diagnostic tools
1605 * to allow network I/O with interrupts disabled. */
1606static void stmmac_poll_controller(struct net_device *dev)
1607{
1608 disable_irq(dev->irq);
1609 stmmac_interrupt(dev->irq, dev);
1610 enable_irq(dev->irq);
1611}
1612#endif
1613
1614/**
1615 * stmmac_ioctl - Entry point for the Ioctl
1616 * @dev: Device pointer.
1617 * @rq: An IOCTL specefic structure, that can contain a pointer to
1618 * a proprietary structure used to pass information to the driver.
1619 * @cmd: IOCTL command
1620 * Description:
1621 * Currently there are no special functionality supported in IOCTL, just the
1622 * phy_mii_ioctl(...) can be invoked.
1623 */
1624static int stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1625{
1626 struct stmmac_priv *priv = netdev_priv(dev);
28b04113 1627 int ret;
47dd7a54
GC
1628
1629 if (!netif_running(dev))
1630 return -EINVAL;
1631
28b04113
RC
1632 if (!priv->phydev)
1633 return -EINVAL;
1634
28b04113 1635 ret = phy_mii_ioctl(priv->phydev, rq, cmd);
28b04113 1636
47dd7a54
GC
1637 return ret;
1638}
1639
7ac29055
GC
1640#ifdef CONFIG_STMMAC_DEBUG_FS
1641static struct dentry *stmmac_fs_dir;
1642static struct dentry *stmmac_rings_status;
e7434821 1643static struct dentry *stmmac_dma_cap;
7ac29055
GC
1644
1645static int stmmac_sysfs_ring_read(struct seq_file *seq, void *v)
1646{
1647 struct tmp_s {
1648 u64 a;
1649 unsigned int b;
1650 unsigned int c;
1651 };
1652 int i;
1653 struct net_device *dev = seq->private;
1654 struct stmmac_priv *priv = netdev_priv(dev);
1655
1656 seq_printf(seq, "=======================\n");
1657 seq_printf(seq, " RX descriptor ring\n");
1658 seq_printf(seq, "=======================\n");
1659
1660 for (i = 0; i < priv->dma_rx_size; i++) {
1661 struct tmp_s *x = (struct tmp_s *)(priv->dma_rx + i);
1662 seq_printf(seq, "[%d] DES0=0x%x DES1=0x%x BUF1=0x%x BUF2=0x%x",
1663 i, (unsigned int)(x->a),
1664 (unsigned int)((x->a) >> 32), x->b, x->c);
1665 seq_printf(seq, "\n");
1666 }
1667
1668 seq_printf(seq, "\n");
1669 seq_printf(seq, "=======================\n");
1670 seq_printf(seq, " TX descriptor ring\n");
1671 seq_printf(seq, "=======================\n");
1672
1673 for (i = 0; i < priv->dma_tx_size; i++) {
1674 struct tmp_s *x = (struct tmp_s *)(priv->dma_tx + i);
1675 seq_printf(seq, "[%d] DES0=0x%x DES1=0x%x BUF1=0x%x BUF2=0x%x",
1676 i, (unsigned int)(x->a),
1677 (unsigned int)((x->a) >> 32), x->b, x->c);
1678 seq_printf(seq, "\n");
1679 }
1680
1681 return 0;
1682}
1683
1684static int stmmac_sysfs_ring_open(struct inode *inode, struct file *file)
1685{
1686 return single_open(file, stmmac_sysfs_ring_read, inode->i_private);
1687}
1688
1689static const struct file_operations stmmac_rings_status_fops = {
1690 .owner = THIS_MODULE,
1691 .open = stmmac_sysfs_ring_open,
1692 .read = seq_read,
1693 .llseek = seq_lseek,
74863948 1694 .release = single_release,
7ac29055
GC
1695};
1696
e7434821
GC
1697static int stmmac_sysfs_dma_cap_read(struct seq_file *seq, void *v)
1698{
1699 struct net_device *dev = seq->private;
1700 struct stmmac_priv *priv = netdev_priv(dev);
1701
19e30c14 1702 if (!priv->hw_cap_support) {
e7434821
GC
1703 seq_printf(seq, "DMA HW features not supported\n");
1704 return 0;
1705 }
1706
1707 seq_printf(seq, "==============================\n");
1708 seq_printf(seq, "\tDMA HW features\n");
1709 seq_printf(seq, "==============================\n");
1710
1711 seq_printf(seq, "\t10/100 Mbps %s\n",
1712 (priv->dma_cap.mbps_10_100) ? "Y" : "N");
1713 seq_printf(seq, "\t1000 Mbps %s\n",
1714 (priv->dma_cap.mbps_1000) ? "Y" : "N");
1715 seq_printf(seq, "\tHalf duple %s\n",
1716 (priv->dma_cap.half_duplex) ? "Y" : "N");
1717 seq_printf(seq, "\tHash Filter: %s\n",
1718 (priv->dma_cap.hash_filter) ? "Y" : "N");
1719 seq_printf(seq, "\tMultiple MAC address registers: %s\n",
1720 (priv->dma_cap.multi_addr) ? "Y" : "N");
1721 seq_printf(seq, "\tPCS (TBI/SGMII/RTBI PHY interfatces): %s\n",
1722 (priv->dma_cap.pcs) ? "Y" : "N");
1723 seq_printf(seq, "\tSMA (MDIO) Interface: %s\n",
1724 (priv->dma_cap.sma_mdio) ? "Y" : "N");
1725 seq_printf(seq, "\tPMT Remote wake up: %s\n",
1726 (priv->dma_cap.pmt_remote_wake_up) ? "Y" : "N");
1727 seq_printf(seq, "\tPMT Magic Frame: %s\n",
1728 (priv->dma_cap.pmt_magic_frame) ? "Y" : "N");
1729 seq_printf(seq, "\tRMON module: %s\n",
1730 (priv->dma_cap.rmon) ? "Y" : "N");
1731 seq_printf(seq, "\tIEEE 1588-2002 Time Stamp: %s\n",
1732 (priv->dma_cap.time_stamp) ? "Y" : "N");
1733 seq_printf(seq, "\tIEEE 1588-2008 Advanced Time Stamp:%s\n",
1734 (priv->dma_cap.atime_stamp) ? "Y" : "N");
1735 seq_printf(seq, "\t802.3az - Energy-Efficient Ethernet (EEE) %s\n",
1736 (priv->dma_cap.eee) ? "Y" : "N");
1737 seq_printf(seq, "\tAV features: %s\n", (priv->dma_cap.av) ? "Y" : "N");
1738 seq_printf(seq, "\tChecksum Offload in TX: %s\n",
1739 (priv->dma_cap.tx_coe) ? "Y" : "N");
1740 seq_printf(seq, "\tIP Checksum Offload (type1) in RX: %s\n",
1741 (priv->dma_cap.rx_coe_type1) ? "Y" : "N");
1742 seq_printf(seq, "\tIP Checksum Offload (type2) in RX: %s\n",
1743 (priv->dma_cap.rx_coe_type2) ? "Y" : "N");
1744 seq_printf(seq, "\tRXFIFO > 2048bytes: %s\n",
1745 (priv->dma_cap.rxfifo_over_2048) ? "Y" : "N");
1746 seq_printf(seq, "\tNumber of Additional RX channel: %d\n",
1747 priv->dma_cap.number_rx_channel);
1748 seq_printf(seq, "\tNumber of Additional TX channel: %d\n",
1749 priv->dma_cap.number_tx_channel);
1750 seq_printf(seq, "\tEnhanced descriptors: %s\n",
1751 (priv->dma_cap.enh_desc) ? "Y" : "N");
1752
1753 return 0;
1754}
1755
1756static int stmmac_sysfs_dma_cap_open(struct inode *inode, struct file *file)
1757{
1758 return single_open(file, stmmac_sysfs_dma_cap_read, inode->i_private);
1759}
1760
1761static const struct file_operations stmmac_dma_cap_fops = {
1762 .owner = THIS_MODULE,
1763 .open = stmmac_sysfs_dma_cap_open,
1764 .read = seq_read,
1765 .llseek = seq_lseek,
74863948 1766 .release = single_release,
e7434821
GC
1767};
1768
7ac29055
GC
1769static int stmmac_init_fs(struct net_device *dev)
1770{
1771 /* Create debugfs entries */
1772 stmmac_fs_dir = debugfs_create_dir(STMMAC_RESOURCE_NAME, NULL);
1773
1774 if (!stmmac_fs_dir || IS_ERR(stmmac_fs_dir)) {
1775 pr_err("ERROR %s, debugfs create directory failed\n",
1776 STMMAC_RESOURCE_NAME);
1777
1778 return -ENOMEM;
1779 }
1780
1781 /* Entry to report DMA RX/TX rings */
1782 stmmac_rings_status = debugfs_create_file("descriptors_status",
1783 S_IRUGO, stmmac_fs_dir, dev,
1784 &stmmac_rings_status_fops);
1785
1786 if (!stmmac_rings_status || IS_ERR(stmmac_rings_status)) {
1787 pr_info("ERROR creating stmmac ring debugfs file\n");
1788 debugfs_remove(stmmac_fs_dir);
1789
1790 return -ENOMEM;
1791 }
1792
e7434821
GC
1793 /* Entry to report the DMA HW features */
1794 stmmac_dma_cap = debugfs_create_file("dma_cap", S_IRUGO, stmmac_fs_dir,
1795 dev, &stmmac_dma_cap_fops);
1796
1797 if (!stmmac_dma_cap || IS_ERR(stmmac_dma_cap)) {
1798 pr_info("ERROR creating stmmac MMC debugfs file\n");
1799 debugfs_remove(stmmac_rings_status);
1800 debugfs_remove(stmmac_fs_dir);
1801
1802 return -ENOMEM;
1803 }
1804
7ac29055
GC
1805 return 0;
1806}
1807
1808static void stmmac_exit_fs(void)
1809{
1810 debugfs_remove(stmmac_rings_status);
e7434821 1811 debugfs_remove(stmmac_dma_cap);
7ac29055
GC
1812 debugfs_remove(stmmac_fs_dir);
1813}
1814#endif /* CONFIG_STMMAC_DEBUG_FS */
1815
47dd7a54
GC
1816static const struct net_device_ops stmmac_netdev_ops = {
1817 .ndo_open = stmmac_open,
1818 .ndo_start_xmit = stmmac_xmit,
1819 .ndo_stop = stmmac_release,
1820 .ndo_change_mtu = stmmac_change_mtu,
5e982f3b 1821 .ndo_fix_features = stmmac_fix_features,
01789349 1822 .ndo_set_rx_mode = stmmac_set_rx_mode,
47dd7a54
GC
1823 .ndo_tx_timeout = stmmac_tx_timeout,
1824 .ndo_do_ioctl = stmmac_ioctl,
1825 .ndo_set_config = stmmac_config,
47dd7a54
GC
1826#ifdef CONFIG_NET_POLL_CONTROLLER
1827 .ndo_poll_controller = stmmac_poll_controller,
1828#endif
1829 .ndo_set_mac_address = eth_mac_addr,
1830};
1831
cf3f047b
GC
1832/**
1833 * stmmac_hw_init - Init the MAC device
1834 * @priv : pointer to the private device structure.
1835 * Description: this function detects which MAC device
1836 * (GMAC/MAC10-100) has to attached, checks the HW capability
1837 * (if supported) and sets the driver's features (for example
1838 * to use the ring or chaine mode or support the normal/enh
1839 * descriptor structure).
1840 */
1841static int stmmac_hw_init(struct stmmac_priv *priv)
1842{
1843 int ret = 0;
1844 struct mac_device_info *mac;
1845
1846 /* Identify the MAC HW device */
03f2eecd
MKB
1847 if (priv->plat->has_gmac) {
1848 priv->dev->priv_flags |= IFF_UNICAST_FLT;
cf3f047b 1849 mac = dwmac1000_setup(priv->ioaddr);
03f2eecd 1850 } else {
cf3f047b 1851 mac = dwmac100_setup(priv->ioaddr);
03f2eecd 1852 }
cf3f047b
GC
1853 if (!mac)
1854 return -ENOMEM;
1855
1856 priv->hw = mac;
1857
1858 /* To use the chained or ring mode */
1859 priv->hw->ring = &ring_mode_ops;
1860
1861 /* Get and dump the chip ID */
cffb13f4 1862 priv->synopsys_id = stmmac_get_synopsys_id(priv);
cf3f047b
GC
1863
1864 /* Get the HW capability (new GMAC newer than 3.50a) */
1865 priv->hw_cap_support = stmmac_get_hw_features(priv);
1866 if (priv->hw_cap_support) {
1867 pr_info(" DMA HW capability register supported");
1868
1869 /* We can override some gmac/dma configuration fields: e.g.
1870 * enh_desc, tx_coe (e.g. that are passed through the
1871 * platform) with the values from the HW capability
1872 * register (if supported).
1873 */
1874 priv->plat->enh_desc = priv->dma_cap.enh_desc;
cf3f047b 1875 priv->plat->pmt = priv->dma_cap.pmt_remote_wake_up;
38912bdb
DS
1876
1877 priv->plat->tx_coe = priv->dma_cap.tx_coe;
1878
1879 if (priv->dma_cap.rx_coe_type2)
1880 priv->plat->rx_coe = STMMAC_RX_COE_TYPE2;
1881 else if (priv->dma_cap.rx_coe_type1)
1882 priv->plat->rx_coe = STMMAC_RX_COE_TYPE1;
1883
cf3f047b
GC
1884 } else
1885 pr_info(" No HW DMA feature register supported");
1886
1887 /* Select the enhnaced/normal descriptor structures */
1888 stmmac_selec_desc_mode(priv);
1889
38912bdb
DS
1890 /* Enable the IPC (Checksum Offload) and check if the feature has been
1891 * enabled during the core configuration. */
1892 ret = priv->hw->mac->rx_ipc(priv->ioaddr);
1893 if (!ret) {
1894 pr_warning(" RX IPC Checksum Offload not configured.\n");
1895 priv->plat->rx_coe = STMMAC_RX_COE_NONE;
1896 }
1897
1898 if (priv->plat->rx_coe)
1899 pr_info(" RX Checksum Offload Engine supported (type %d)\n",
1900 priv->plat->rx_coe);
cf3f047b
GC
1901 if (priv->plat->tx_coe)
1902 pr_info(" TX Checksum insertion supported\n");
1903
1904 if (priv->plat->pmt) {
1905 pr_info(" Wake-Up On Lan supported\n");
1906 device_set_wakeup_capable(priv->device, 1);
1907 }
1908
1909 return ret;
1910}
1911
47dd7a54 1912/**
bfab27a1
GC
1913 * stmmac_dvr_probe
1914 * @device: device pointer
ff3dd78c
GC
1915 * @plat_dat: platform data pointer
1916 * @addr: iobase memory address
bfab27a1
GC
1917 * Description: this is the main probe function used to
1918 * call the alloc_etherdev, allocate the priv structure.
47dd7a54 1919 */
bfab27a1 1920struct stmmac_priv *stmmac_dvr_probe(struct device *device,
cf3f047b
GC
1921 struct plat_stmmacenet_data *plat_dat,
1922 void __iomem *addr)
47dd7a54
GC
1923{
1924 int ret = 0;
bfab27a1
GC
1925 struct net_device *ndev = NULL;
1926 struct stmmac_priv *priv;
47dd7a54 1927
bfab27a1 1928 ndev = alloc_etherdev(sizeof(struct stmmac_priv));
41de8d4c 1929 if (!ndev)
bfab27a1 1930 return NULL;
bfab27a1
GC
1931
1932 SET_NETDEV_DEV(ndev, device);
1933
1934 priv = netdev_priv(ndev);
1935 priv->device = device;
1936 priv->dev = ndev;
47dd7a54 1937
bfab27a1 1938 ether_setup(ndev);
47dd7a54 1939
bfab27a1 1940 stmmac_set_ethtool_ops(ndev);
cf3f047b
GC
1941 priv->pause = pause;
1942 priv->plat = plat_dat;
1943 priv->ioaddr = addr;
1944 priv->dev->base_addr = (unsigned long)addr;
1945
1946 /* Verify driver arguments */
1947 stmmac_verify_args();
bfab27a1 1948
cf3f047b
GC
1949 /* Override with kernel parameters if supplied XXX CRS XXX
1950 * this needs to have multiple instances */
1951 if ((phyaddr >= 0) && (phyaddr <= 31))
1952 priv->plat->phy_addr = phyaddr;
1953
1954 /* Init MAC and get the capabilities */
1955 stmmac_hw_init(priv);
1956
1957 ndev->netdev_ops = &stmmac_netdev_ops;
bfab27a1 1958
cf3f047b
GC
1959 ndev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
1960 NETIF_F_RXCSUM;
bfab27a1
GC
1961 ndev->features |= ndev->hw_features | NETIF_F_HIGHDMA;
1962 ndev->watchdog_timeo = msecs_to_jiffies(watchdog);
47dd7a54
GC
1963#ifdef STMMAC_VLAN_TAG_USED
1964 /* Both mac100 and gmac support receive VLAN tag detection */
bfab27a1 1965 ndev->features |= NETIF_F_HW_VLAN_RX;
47dd7a54
GC
1966#endif
1967 priv->msg_enable = netif_msg_init(debug, default_msg_level);
1968
47dd7a54
GC
1969 if (flow_ctrl)
1970 priv->flow_ctrl = FLOW_AUTO; /* RX/TX pause on */
1971
bfab27a1 1972 netif_napi_add(ndev, &priv->napi, stmmac_poll, 64);
47dd7a54 1973
f8e96161 1974 spin_lock_init(&priv->lock);
a9097a96 1975 spin_lock_init(&priv->tx_lock);
f8e96161 1976
bfab27a1 1977 ret = register_netdev(ndev);
47dd7a54 1978 if (ret) {
cf3f047b 1979 pr_err("%s: ERROR %i registering the device\n", __func__, ret);
6a81c26f 1980 goto error_netdev_register;
47dd7a54
GC
1981 }
1982
ae4d8cf2 1983 priv->stmmac_clk = clk_get(priv->device, STMMAC_RESOURCE_NAME);
6a81c26f 1984 if (IS_ERR(priv->stmmac_clk)) {
31ea38ee 1985 pr_warning("%s: warning: cannot get CSR clock\n", __func__);
6a81c26f
VK
1986 goto error_clk_get;
1987 }
ba1377ff 1988
cd7201f4
GC
1989 /* If a specific clk_csr value is passed from the platform
1990 * this means that the CSR Clock Range selection cannot be
1991 * changed at run-time and it is fixed. Viceversa the driver'll try to
1992 * set the MDC clock dynamically according to the csr actual
1993 * clock input.
1994 */
1995 if (!priv->plat->clk_csr)
1996 stmmac_clk_csr_set(priv);
1997 else
1998 priv->clk_csr = priv->plat->clk_csr;
1999
4bfcbd7a
FV
2000 /* MDIO bus Registration */
2001 ret = stmmac_mdio_register(ndev);
2002 if (ret < 0) {
2003 pr_debug("%s: MDIO bus (id: %d) registration failed",
2004 __func__, priv->plat->bus_id);
6a81c26f 2005 goto error_mdio_register;
4bfcbd7a
FV
2006 }
2007
bfab27a1 2008 return priv;
47dd7a54 2009
6a81c26f
VK
2010error_mdio_register:
2011 clk_put(priv->stmmac_clk);
2012error_clk_get:
34a52f36 2013 unregister_netdev(ndev);
6a81c26f
VK
2014error_netdev_register:
2015 netif_napi_del(&priv->napi);
34a52f36 2016 free_netdev(ndev);
47dd7a54 2017
bfab27a1 2018 return NULL;
47dd7a54
GC
2019}
2020
2021/**
2022 * stmmac_dvr_remove
bfab27a1 2023 * @ndev: net device pointer
47dd7a54 2024 * Description: this function resets the TX/RX processes, disables the MAC RX/TX
bfab27a1 2025 * changes the link status, releases the DMA descriptor rings.
47dd7a54 2026 */
bfab27a1 2027int stmmac_dvr_remove(struct net_device *ndev)
47dd7a54 2028{
aec7ff27 2029 struct stmmac_priv *priv = netdev_priv(ndev);
47dd7a54
GC
2030
2031 pr_info("%s:\n\tremoving driver", __func__);
2032
ad01b7d4
GC
2033 priv->hw->dma->stop_rx(priv->ioaddr);
2034 priv->hw->dma->stop_tx(priv->ioaddr);
47dd7a54 2035
bfab27a1 2036 stmmac_set_mac(priv->ioaddr, false);
4bfcbd7a 2037 stmmac_mdio_unregister(ndev);
47dd7a54 2038 netif_carrier_off(ndev);
47dd7a54 2039 unregister_netdev(ndev);
47dd7a54
GC
2040 free_netdev(ndev);
2041
2042 return 0;
2043}
2044
2045#ifdef CONFIG_PM
bfab27a1 2046int stmmac_suspend(struct net_device *ndev)
47dd7a54 2047{
874bd42d 2048 struct stmmac_priv *priv = netdev_priv(ndev);
47dd7a54 2049 int dis_ic = 0;
f8c5a875 2050 unsigned long flags;
47dd7a54 2051
874bd42d 2052 if (!ndev || !netif_running(ndev))
47dd7a54
GC
2053 return 0;
2054
102463b1
FV
2055 if (priv->phydev)
2056 phy_stop(priv->phydev);
2057
f8c5a875 2058 spin_lock_irqsave(&priv->lock, flags);
47dd7a54 2059
874bd42d
GC
2060 netif_device_detach(ndev);
2061 netif_stop_queue(ndev);
47dd7a54 2062
874bd42d
GC
2063 napi_disable(&priv->napi);
2064
2065 /* Stop TX/RX DMA */
2066 priv->hw->dma->stop_tx(priv->ioaddr);
2067 priv->hw->dma->stop_rx(priv->ioaddr);
2068 /* Clear the Rx/Tx descriptors */
2069 priv->hw->desc->init_rx_desc(priv->dma_rx, priv->dma_rx_size,
2070 dis_ic);
2071 priv->hw->desc->init_tx_desc(priv->dma_tx, priv->dma_tx_size);
2072
2073 /* Enable Power down mode by programming the PMT regs */
2074 if (device_may_wakeup(priv->device))
2075 priv->hw->mac->pmt(priv->ioaddr, priv->wolopts);
ba1377ff 2076 else {
bfab27a1 2077 stmmac_set_mac(priv->ioaddr, false);
ba1377ff 2078 /* Disable clock in case of PWM is off */
a630844d 2079 clk_disable_unprepare(priv->stmmac_clk);
ba1377ff 2080 }
f8c5a875 2081 spin_unlock_irqrestore(&priv->lock, flags);
47dd7a54
GC
2082 return 0;
2083}
2084
bfab27a1 2085int stmmac_resume(struct net_device *ndev)
47dd7a54 2086{
874bd42d 2087 struct stmmac_priv *priv = netdev_priv(ndev);
f8c5a875 2088 unsigned long flags;
47dd7a54 2089
874bd42d 2090 if (!netif_running(ndev))
47dd7a54
GC
2091 return 0;
2092
f8c5a875 2093 spin_lock_irqsave(&priv->lock, flags);
c4433be6 2094
47dd7a54
GC
2095 /* Power Down bit, into the PM register, is cleared
2096 * automatically as soon as a magic packet or a Wake-up frame
2097 * is received. Anyway, it's better to manually clear
2098 * this bit because it can generate problems while resuming
2099 * from another devices (e.g. serial console). */
874bd42d 2100 if (device_may_wakeup(priv->device))
543876c9 2101 priv->hw->mac->pmt(priv->ioaddr, 0);
ba1377ff
GC
2102 else
2103 /* enable the clk prevously disabled */
a630844d 2104 clk_prepare_enable(priv->stmmac_clk);
47dd7a54 2105
874bd42d 2106 netif_device_attach(ndev);
47dd7a54
GC
2107
2108 /* Enable the MAC and DMA */
bfab27a1 2109 stmmac_set_mac(priv->ioaddr, true);
ad01b7d4
GC
2110 priv->hw->dma->start_tx(priv->ioaddr);
2111 priv->hw->dma->start_rx(priv->ioaddr);
47dd7a54 2112
47dd7a54
GC
2113 napi_enable(&priv->napi);
2114
874bd42d 2115 netif_start_queue(ndev);
47dd7a54 2116
f8c5a875 2117 spin_unlock_irqrestore(&priv->lock, flags);
102463b1
FV
2118
2119 if (priv->phydev)
2120 phy_start(priv->phydev);
2121
47dd7a54
GC
2122 return 0;
2123}
47dd7a54 2124
bfab27a1 2125int stmmac_freeze(struct net_device *ndev)
874bd42d 2126{
874bd42d
GC
2127 if (!ndev || !netif_running(ndev))
2128 return 0;
2129
2130 return stmmac_release(ndev);
2131}
2132
bfab27a1 2133int stmmac_restore(struct net_device *ndev)
874bd42d 2134{
874bd42d
GC
2135 if (!ndev || !netif_running(ndev))
2136 return 0;
2137
2138 return stmmac_open(ndev);
2139}
874bd42d 2140#endif /* CONFIG_PM */
47dd7a54 2141
33d5e332
GC
2142/* Driver can be configured w/ and w/ both PCI and Platf drivers
2143 * depending on the configuration selected.
2144 */
ba27ec66
GC
2145static int __init stmmac_init(void)
2146{
33d5e332
GC
2147 int err_plt = 0;
2148 int err_pci = 0;
ba27ec66 2149
33d5e332
GC
2150 err_plt = stmmac_register_platform();
2151 err_pci = stmmac_register_pci();
ba27ec66 2152
33d5e332
GC
2153 if ((err_pci) && (err_plt)) {
2154 pr_err("stmmac: driver registration failed\n");
2155 return -EINVAL;
ba27ec66
GC
2156 }
2157
33d5e332 2158 return 0;
ba27ec66
GC
2159}
2160
2161static void __exit stmmac_exit(void)
2162{
33d5e332
GC
2163 stmmac_unregister_platform();
2164 stmmac_unregister_pci();
ba27ec66
GC
2165}
2166
2167module_init(stmmac_init);
2168module_exit(stmmac_exit);
2169
47dd7a54
GC
2170#ifndef MODULE
2171static int __init stmmac_cmdline_opt(char *str)
2172{
2173 char *opt;
2174
2175 if (!str || !*str)
2176 return -EINVAL;
2177 while ((opt = strsep(&str, ",")) != NULL) {
f3240e28 2178 if (!strncmp(opt, "debug:", 6)) {
ea2ab871 2179 if (kstrtoint(opt + 6, 0, &debug))
f3240e28
GC
2180 goto err;
2181 } else if (!strncmp(opt, "phyaddr:", 8)) {
ea2ab871 2182 if (kstrtoint(opt + 8, 0, &phyaddr))
f3240e28
GC
2183 goto err;
2184 } else if (!strncmp(opt, "dma_txsize:", 11)) {
ea2ab871 2185 if (kstrtoint(opt + 11, 0, &dma_txsize))
f3240e28
GC
2186 goto err;
2187 } else if (!strncmp(opt, "dma_rxsize:", 11)) {
ea2ab871 2188 if (kstrtoint(opt + 11, 0, &dma_rxsize))
f3240e28
GC
2189 goto err;
2190 } else if (!strncmp(opt, "buf_sz:", 7)) {
ea2ab871 2191 if (kstrtoint(opt + 7, 0, &buf_sz))
f3240e28
GC
2192 goto err;
2193 } else if (!strncmp(opt, "tc:", 3)) {
ea2ab871 2194 if (kstrtoint(opt + 3, 0, &tc))
f3240e28
GC
2195 goto err;
2196 } else if (!strncmp(opt, "watchdog:", 9)) {
ea2ab871 2197 if (kstrtoint(opt + 9, 0, &watchdog))
f3240e28
GC
2198 goto err;
2199 } else if (!strncmp(opt, "flow_ctrl:", 10)) {
ea2ab871 2200 if (kstrtoint(opt + 10, 0, &flow_ctrl))
f3240e28
GC
2201 goto err;
2202 } else if (!strncmp(opt, "pause:", 6)) {
ea2ab871 2203 if (kstrtoint(opt + 6, 0, &pause))
f3240e28 2204 goto err;
d765955d
GC
2205 } else if (!strncmp(opt, "eee_timer:", 6)) {
2206 if (kstrtoint(opt + 10, 0, &eee_timer))
2207 goto err;
f3240e28 2208 }
47dd7a54
GC
2209 }
2210 return 0;
f3240e28
GC
2211
2212err:
2213 pr_err("%s: ERROR broken module parameter conversion", __func__);
2214 return -EINVAL;
47dd7a54
GC
2215}
2216
2217__setup("stmmaceth=", stmmac_cmdline_opt);
2218#endif
6fc0d0f2
GC
2219
2220MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet device driver");
2221MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
2222MODULE_LICENSE("GPL");