blob: 9ecd6cf9815a209700ef19b1c0d267faac2072a4 [file] [log] [blame]
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001/*******************************************************************************
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
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +00005 Copyright(C) 2007-2011 STMicroelectronics Ltd
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07006
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
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -070031#include <linux/kernel.h>
32#include <linux/interrupt.h>
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -070033#include <linux/ip.h>
34#include <linux/tcp.h>
35#include <linux/skbuff.h>
36#include <linux/ethtool.h>
37#include <linux/if_ether.h>
38#include <linux/crc32.h>
39#include <linux/mii.h>
Jiri Pirko01789342011-08-16 06:29:00 +000040#include <linux/if.h>
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -070041#include <linux/if_vlan.h>
42#include <linux/dma-mapping.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090043#include <linux/slab.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040044#include <linux/prefetch.h>
Giuseppe CAVALLARO7ac29052011-09-01 21:51:39 +000045#ifdef CONFIG_STMMAC_DEBUG_FS
46#include <linux/debugfs.h>
47#include <linux/seq_file.h>
48#endif
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +000049#include "stmmac.h"
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -070050
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -070051#undef STMMAC_DEBUG
52/*#define STMMAC_DEBUG*/
53#ifdef STMMAC_DEBUG
54#define DBG(nlevel, klevel, fmt, args...) \
55 ((void)(netif_msg_##nlevel(priv) && \
56 printk(KERN_##klevel fmt, ## args)))
57#else
58#define DBG(nlevel, klevel, fmt, args...) do { } while (0)
59#endif
60
61#undef STMMAC_RX_DEBUG
62/*#define STMMAC_RX_DEBUG*/
63#ifdef STMMAC_RX_DEBUG
64#define RX_DBG(fmt, args...) printk(fmt, ## args)
65#else
66#define RX_DBG(fmt, args...) do { } while (0)
67#endif
68
69#undef STMMAC_XMIT_DEBUG
70/*#define STMMAC_XMIT_DEBUG*/
71#ifdef STMMAC_TX_DEBUG
72#define TX_DBG(fmt, args...) printk(fmt, ## args)
73#else
74#define TX_DBG(fmt, args...) do { } while (0)
75#endif
76
77#define STMMAC_ALIGN(x) L1_CACHE_ALIGN(x)
78#define JUMBO_LEN 9000
79
80/* Module parameters */
81#define TX_TIMEO 5000 /* default 5 seconds */
82static int watchdog = TX_TIMEO;
83module_param(watchdog, int, S_IRUGO | S_IWUSR);
84MODULE_PARM_DESC(watchdog, "Transmit timeout in milliseconds");
85
86static int debug = -1; /* -1: default, 0: no output, 16: all */
87module_param(debug, int, S_IRUGO | S_IWUSR);
88MODULE_PARM_DESC(debug, "Message Level (0: no output, 16: all)");
89
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000090int phyaddr = -1;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -070091module_param(phyaddr, int, S_IRUGO);
92MODULE_PARM_DESC(phyaddr, "Physical device address");
93
94#define DMA_TX_SIZE 256
95static int dma_txsize = DMA_TX_SIZE;
96module_param(dma_txsize, int, S_IRUGO | S_IWUSR);
97MODULE_PARM_DESC(dma_txsize, "Number of descriptors in the TX list");
98
99#define DMA_RX_SIZE 256
100static int dma_rxsize = DMA_RX_SIZE;
101module_param(dma_rxsize, int, S_IRUGO | S_IWUSR);
102MODULE_PARM_DESC(dma_rxsize, "Number of descriptors in the RX list");
103
104static int flow_ctrl = FLOW_OFF;
105module_param(flow_ctrl, int, S_IRUGO | S_IWUSR);
106MODULE_PARM_DESC(flow_ctrl, "Flow control ability [on/off]");
107
108static int pause = PAUSE_TIME;
109module_param(pause, int, S_IRUGO | S_IWUSR);
110MODULE_PARM_DESC(pause, "Flow Control Pause Time");
111
112#define TC_DEFAULT 64
113static int tc = TC_DEFAULT;
114module_param(tc, int, S_IRUGO | S_IWUSR);
115MODULE_PARM_DESC(tc, "DMA threshold control value");
116
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700117/* Pay attention to tune this parameter; take care of both
118 * hardware capability and network stabitily/performance impact.
119 * Many tests showed that ~4ms latency seems to be good enough. */
120#ifdef CONFIG_STMMAC_TIMER
121#define DEFAULT_PERIODIC_RATE 256
122static int tmrate = DEFAULT_PERIODIC_RATE;
123module_param(tmrate, int, S_IRUGO | S_IWUSR);
124MODULE_PARM_DESC(tmrate, "External timer freq. (default: 256Hz)");
125#endif
126
127#define DMA_BUFFER_SIZE BUF_SIZE_2KiB
128static int buf_sz = DMA_BUFFER_SIZE;
129module_param(buf_sz, int, S_IRUGO | S_IWUSR);
130MODULE_PARM_DESC(buf_sz, "DMA buffer size");
131
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700132static const u32 default_msg_level = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
133 NETIF_MSG_LINK | NETIF_MSG_IFUP |
134 NETIF_MSG_IFDOWN | NETIF_MSG_TIMER);
135
136static irqreturn_t stmmac_interrupt(int irq, void *dev_id);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700137
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000138#ifdef CONFIG_STMMAC_DEBUG_FS
139static int stmmac_init_fs(struct net_device *dev);
140static void stmmac_exit_fs(void);
141#endif
142
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700143/**
144 * stmmac_verify_args - verify the driver parameters.
145 * Description: it verifies if some wrong parameter is passed to the driver.
146 * Note that wrong parameters are replaced with the default values.
147 */
148static void stmmac_verify_args(void)
149{
150 if (unlikely(watchdog < 0))
151 watchdog = TX_TIMEO;
152 if (unlikely(dma_rxsize < 0))
153 dma_rxsize = DMA_RX_SIZE;
154 if (unlikely(dma_txsize < 0))
155 dma_txsize = DMA_TX_SIZE;
156 if (unlikely((buf_sz < DMA_BUFFER_SIZE) || (buf_sz > BUF_SIZE_16KiB)))
157 buf_sz = DMA_BUFFER_SIZE;
158 if (unlikely(flow_ctrl > 1))
159 flow_ctrl = FLOW_AUTO;
160 else if (likely(flow_ctrl < 0))
161 flow_ctrl = FLOW_OFF;
162 if (unlikely((pause < 0) || (pause > 0xffff)))
163 pause = PAUSE_TIME;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700164}
165
Giuseppe CAVALLAROcd7201f2012-04-04 04:33:27 +0000166static void stmmac_clk_csr_set(struct stmmac_priv *priv)
167{
168#ifdef CONFIG_HAVE_CLK
169 u32 clk_rate;
170
171 clk_rate = clk_get_rate(priv->stmmac_clk);
172
173 /* Platform provided default clk_csr would be assumed valid
174 * for all other cases except for the below mentioned ones. */
175 if (!(priv->clk_csr & MAC_CSR_H_FRQ_MASK)) {
176 if (clk_rate < CSR_F_35M)
177 priv->clk_csr = STMMAC_CSR_20_35M;
178 else if ((clk_rate >= CSR_F_35M) && (clk_rate < CSR_F_60M))
179 priv->clk_csr = STMMAC_CSR_35_60M;
180 else if ((clk_rate >= CSR_F_60M) && (clk_rate < CSR_F_100M))
181 priv->clk_csr = STMMAC_CSR_60_100M;
182 else if ((clk_rate >= CSR_F_100M) && (clk_rate < CSR_F_150M))
183 priv->clk_csr = STMMAC_CSR_100_150M;
184 else if ((clk_rate >= CSR_F_150M) && (clk_rate < CSR_F_250M))
185 priv->clk_csr = STMMAC_CSR_150_250M;
186 else if ((clk_rate >= CSR_F_250M) && (clk_rate < CSR_F_300M))
187 priv->clk_csr = STMMAC_CSR_250_300M;
188 } /* For values higher than the IEEE 802.3 specified frequency
189 * we can not estimate the proper divider as it is not known
190 * the frequency of clk_csr_i. So we do not change the default
191 * divider. */
192#endif
193}
194
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700195#if defined(STMMAC_XMIT_DEBUG) || defined(STMMAC_RX_DEBUG)
196static void print_pkt(unsigned char *buf, int len)
197{
198 int j;
199 pr_info("len = %d byte, buf addr: 0x%p", len, buf);
200 for (j = 0; j < len; j++) {
201 if ((j % 16) == 0)
202 pr_info("\n %03x:", j);
203 pr_info(" %02x", buf[j]);
204 }
205 pr_info("\n");
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700206}
207#endif
208
209/* minimum number of free TX descriptors required to wake up TX process */
210#define STMMAC_TX_THRESH(x) (x->dma_tx_size/4)
211
212static inline u32 stmmac_tx_avail(struct stmmac_priv *priv)
213{
214 return priv->dirty_tx + priv->dma_tx_size - priv->cur_tx - 1;
215}
216
Giuseppe CAVALLARO9dfeb4d2010-11-24 02:37:58 +0000217/* On some ST platforms, some HW system configuraton registers have to be
218 * set according to the link speed negotiated.
219 */
220static inline void stmmac_hw_fix_mac_speed(struct stmmac_priv *priv)
221{
222 struct phy_device *phydev = priv->phydev;
223
224 if (likely(priv->plat->fix_mac_speed))
225 priv->plat->fix_mac_speed(priv->plat->bsp_priv,
226 phydev->speed);
227}
228
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700229/**
230 * stmmac_adjust_link
231 * @dev: net device structure
232 * Description: it adjusts the link parameters.
233 */
234static void stmmac_adjust_link(struct net_device *dev)
235{
236 struct stmmac_priv *priv = netdev_priv(dev);
237 struct phy_device *phydev = priv->phydev;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700238 unsigned long flags;
239 int new_state = 0;
240 unsigned int fc = priv->flow_ctrl, pause_time = priv->pause;
241
242 if (phydev == NULL)
243 return;
244
245 DBG(probe, DEBUG, "stmmac_adjust_link: called. address %d link %d\n",
246 phydev->addr, phydev->link);
247
248 spin_lock_irqsave(&priv->lock, flags);
249 if (phydev->link) {
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +0000250 u32 ctrl = readl(priv->ioaddr + MAC_CTRL_REG);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700251
252 /* Now we make sure that we can be in full duplex mode.
253 * If not, we operate in half-duplex mode. */
254 if (phydev->duplex != priv->oldduplex) {
255 new_state = 1;
256 if (!(phydev->duplex))
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +0000257 ctrl &= ~priv->hw->link.duplex;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700258 else
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +0000259 ctrl |= priv->hw->link.duplex;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700260 priv->oldduplex = phydev->duplex;
261 }
262 /* Flow Control operation */
263 if (phydev->pause)
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +0000264 priv->hw->mac->flow_ctrl(priv->ioaddr, phydev->duplex,
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +0000265 fc, pause_time);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700266
267 if (phydev->speed != priv->speed) {
268 new_state = 1;
269 switch (phydev->speed) {
270 case 1000:
Giuseppe CAVALLARO9dfeb4d2010-11-24 02:37:58 +0000271 if (likely(priv->plat->has_gmac))
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +0000272 ctrl &= ~priv->hw->link.port;
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +0000273 stmmac_hw_fix_mac_speed(priv);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700274 break;
275 case 100:
276 case 10:
Giuseppe CAVALLARO9dfeb4d2010-11-24 02:37:58 +0000277 if (priv->plat->has_gmac) {
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +0000278 ctrl |= priv->hw->link.port;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700279 if (phydev->speed == SPEED_100) {
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +0000280 ctrl |= priv->hw->link.speed;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700281 } else {
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +0000282 ctrl &= ~(priv->hw->link.speed);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700283 }
284 } else {
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +0000285 ctrl &= ~priv->hw->link.port;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700286 }
Giuseppe CAVALLARO9dfeb4d2010-11-24 02:37:58 +0000287 stmmac_hw_fix_mac_speed(priv);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700288 break;
289 default:
290 if (netif_msg_link(priv))
291 pr_warning("%s: Speed (%d) is not 10"
292 " or 100!\n", dev->name, phydev->speed);
293 break;
294 }
295
296 priv->speed = phydev->speed;
297 }
298
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +0000299 writel(ctrl, priv->ioaddr + MAC_CTRL_REG);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700300
301 if (!priv->oldlink) {
302 new_state = 1;
303 priv->oldlink = 1;
304 }
305 } else if (priv->oldlink) {
306 new_state = 1;
307 priv->oldlink = 0;
308 priv->speed = 0;
309 priv->oldduplex = -1;
310 }
311
312 if (new_state && netif_msg_link(priv))
313 phy_print_status(phydev);
314
315 spin_unlock_irqrestore(&priv->lock, flags);
316
317 DBG(probe, DEBUG, "stmmac_adjust_link: exiting\n");
318}
319
320/**
321 * stmmac_init_phy - PHY initialization
322 * @dev: net device structure
323 * Description: it initializes the driver's PHY state, and attaches the PHY
324 * to the mac driver.
325 * Return value:
326 * 0 on success
327 */
328static int stmmac_init_phy(struct net_device *dev)
329{
330 struct stmmac_priv *priv = netdev_priv(dev);
331 struct phy_device *phydev;
Giuseppe CAVALLARO109cdd62010-01-06 23:07:11 +0000332 char phy_id[MII_BUS_ID_SIZE + 3];
333 char bus_id[MII_BUS_ID_SIZE];
Srinivas Kandagatla79ee1dc2011-10-18 00:01:18 +0000334 int interface = priv->plat->interface;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700335 priv->oldlink = 0;
336 priv->speed = 0;
337 priv->oldduplex = -1;
338
Srinivas Kandagatlaf142af22012-04-04 04:33:19 +0000339 if (priv->plat->phy_bus_name)
340 snprintf(bus_id, MII_BUS_ID_SIZE, "%s-%x",
341 priv->plat->phy_bus_name, priv->plat->bus_id);
342 else
343 snprintf(bus_id, MII_BUS_ID_SIZE, "stmmac-%x",
344 priv->plat->bus_id);
345
Giuseppe CAVALLARO109cdd62010-01-06 23:07:11 +0000346 snprintf(phy_id, MII_BUS_ID_SIZE + 3, PHY_ID_FMT, bus_id,
Giuseppe CAVALLARO36bcfe72011-07-20 00:05:23 +0000347 priv->plat->phy_addr);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700348 pr_debug("stmmac_init_phy: trying to attach to %s\n", phy_id);
349
Srinivas Kandagatla79ee1dc2011-10-18 00:01:18 +0000350 phydev = phy_connect(dev, phy_id, &stmmac_adjust_link, 0, interface);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700351
352 if (IS_ERR(phydev)) {
353 pr_err("%s: Could not attach to PHY\n", dev->name);
354 return PTR_ERR(phydev);
355 }
356
Srinivas Kandagatla79ee1dc2011-10-18 00:01:18 +0000357 /* Stop Advertising 1000BASE Capability if interface is not GMII */
Srinivas Kandagatlac5b9b4e2011-11-16 21:57:59 +0000358 if ((interface == PHY_INTERFACE_MODE_MII) ||
359 (interface == PHY_INTERFACE_MODE_RMII))
360 phydev->advertising &= ~(SUPPORTED_1000baseT_Half |
361 SUPPORTED_1000baseT_Full);
Srinivas Kandagatla79ee1dc2011-10-18 00:01:18 +0000362
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700363 /*
364 * Broken HW is sometimes missing the pull-up resistor on the
365 * MDIO line, which results in reads to non-existent devices returning
366 * 0 rather than 0xffff. Catch this here and treat 0 as a non-existent
367 * device as well.
368 * Note: phydev->phy_id is the result of reading the UID PHY registers.
369 */
370 if (phydev->phy_id == 0) {
371 phy_disconnect(phydev);
372 return -ENODEV;
373 }
374 pr_debug("stmmac_init_phy: %s: attached to PHY (UID 0x%x)"
Giuseppe CAVALLARO36bcfe72011-07-20 00:05:23 +0000375 " Link = %d\n", dev->name, phydev->phy_id, phydev->link);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700376
377 priv->phydev = phydev;
378
379 return 0;
380}
381
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700382/**
383 * display_ring
384 * @p: pointer to the ring.
385 * @size: size of the ring.
386 * Description: display all the descriptors within the ring.
387 */
388static void display_ring(struct dma_desc *p, int size)
389{
390 struct tmp_s {
391 u64 a;
392 unsigned int b;
393 unsigned int c;
394 };
395 int i;
396 for (i = 0; i < size; i++) {
397 struct tmp_s *x = (struct tmp_s *)(p + i);
398 pr_info("\t%d [0x%x]: DES0=0x%x DES1=0x%x BUF1=0x%x BUF2=0x%x",
399 i, (unsigned int)virt_to_phys(&p[i]),
400 (unsigned int)(x->a), (unsigned int)((x->a) >> 32),
401 x->b, x->c);
402 pr_info("\n");
403 }
404}
405
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +0000406static int stmmac_set_bfsize(int mtu, int bufsize)
407{
408 int ret = bufsize;
409
410 if (mtu >= BUF_SIZE_4KiB)
411 ret = BUF_SIZE_8KiB;
412 else if (mtu >= BUF_SIZE_2KiB)
413 ret = BUF_SIZE_4KiB;
414 else if (mtu >= DMA_BUFFER_SIZE)
415 ret = BUF_SIZE_2KiB;
416 else
417 ret = DMA_BUFFER_SIZE;
418
419 return ret;
420}
421
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700422/**
423 * init_dma_desc_rings - init the RX/TX descriptor rings
424 * @dev: net device structure
425 * Description: this function initializes the DMA RX/TX descriptors
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +0000426 * and allocates the socket buffers. It suppors the chained and ring
427 * modes.
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700428 */
429static void init_dma_desc_rings(struct net_device *dev)
430{
431 int i;
432 struct stmmac_priv *priv = netdev_priv(dev);
433 struct sk_buff *skb;
434 unsigned int txsize = priv->dma_tx_size;
435 unsigned int rxsize = priv->dma_rx_size;
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +0000436 unsigned int bfsize;
437 int dis_ic = 0;
438 int des3_as_data_buf = 0;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700439
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +0000440 /* Set the max buffer size according to the DESC mode
441 * and the MTU. Note that RING mode allows 16KiB bsize. */
442 bfsize = priv->hw->ring->set_16kib_bfsize(dev->mtu);
443
444 if (bfsize == BUF_SIZE_16KiB)
445 des3_as_data_buf = 1;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700446 else
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +0000447 bfsize = stmmac_set_bfsize(dev->mtu, priv->dma_buf_sz);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700448
Giuseppe CAVALLARO73cfe262009-11-22 22:59:56 +0000449#ifdef CONFIG_STMMAC_TIMER
450 /* Disable interrupts on completion for the reception if timer is on */
451 if (likely(priv->tm->enable))
452 dis_ic = 1;
453#endif
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700454
455 DBG(probe, INFO, "stmmac: txsize %d, rxsize %d, bfsize %d\n",
456 txsize, rxsize, bfsize);
457
458 priv->rx_skbuff_dma = kmalloc(rxsize * sizeof(dma_addr_t), GFP_KERNEL);
459 priv->rx_skbuff =
460 kmalloc(sizeof(struct sk_buff *) * rxsize, GFP_KERNEL);
461 priv->dma_rx =
462 (struct dma_desc *)dma_alloc_coherent(priv->device,
463 rxsize *
464 sizeof(struct dma_desc),
465 &priv->dma_rx_phy,
466 GFP_KERNEL);
467 priv->tx_skbuff = kmalloc(sizeof(struct sk_buff *) * txsize,
468 GFP_KERNEL);
469 priv->dma_tx =
470 (struct dma_desc *)dma_alloc_coherent(priv->device,
471 txsize *
472 sizeof(struct dma_desc),
473 &priv->dma_tx_phy,
474 GFP_KERNEL);
475
476 if ((priv->dma_rx == NULL) || (priv->dma_tx == NULL)) {
477 pr_err("%s:ERROR allocating the DMA Tx/Rx desc\n", __func__);
478 return;
479 }
480
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +0000481 DBG(probe, INFO, "stmmac (%s) DMA desc: virt addr (Rx %p, "
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700482 "Tx %p)\n\tDMA phy addr (Rx 0x%08x, Tx 0x%08x)\n",
483 dev->name, priv->dma_rx, priv->dma_tx,
484 (unsigned int)priv->dma_rx_phy, (unsigned int)priv->dma_tx_phy);
485
486 /* RX INITIALIZATION */
487 DBG(probe, INFO, "stmmac: SKB addresses:\n"
488 "skb\t\tskb data\tdma data\n");
489
490 for (i = 0; i < rxsize; i++) {
491 struct dma_desc *p = priv->dma_rx + i;
492
Giuseppe CAVALLARO45db81e2011-10-18 01:39:55 +0000493 skb = __netdev_alloc_skb(dev, bfsize + NET_IP_ALIGN,
494 GFP_KERNEL);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700495 if (unlikely(skb == NULL)) {
496 pr_err("%s: Rx init fails; skb is NULL\n", __func__);
497 break;
498 }
Giuseppe CAVALLARO45db81e2011-10-18 01:39:55 +0000499 skb_reserve(skb, NET_IP_ALIGN);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700500 priv->rx_skbuff[i] = skb;
501 priv->rx_skbuff_dma[i] = dma_map_single(priv->device, skb->data,
502 bfsize, DMA_FROM_DEVICE);
503
504 p->des2 = priv->rx_skbuff_dma[i];
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +0000505
506 priv->hw->ring->init_desc3(des3_as_data_buf, p);
507
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700508 DBG(probe, INFO, "[%p]\t[%p]\t[%x]\n", priv->rx_skbuff[i],
509 priv->rx_skbuff[i]->data, priv->rx_skbuff_dma[i]);
510 }
511 priv->cur_rx = 0;
512 priv->dirty_rx = (unsigned int)(i - rxsize);
513 priv->dma_buf_sz = bfsize;
514 buf_sz = bfsize;
515
516 /* TX INITIALIZATION */
517 for (i = 0; i < txsize; i++) {
518 priv->tx_skbuff[i] = NULL;
519 priv->dma_tx[i].des2 = 0;
520 }
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +0000521
522 /* In case of Chained mode this sets the des3 to the next
523 * element in the chain */
524 priv->hw->ring->init_dma_chain(priv->dma_rx, priv->dma_rx_phy, rxsize);
525 priv->hw->ring->init_dma_chain(priv->dma_tx, priv->dma_tx_phy, txsize);
526
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700527 priv->dirty_tx = 0;
528 priv->cur_tx = 0;
529
530 /* Clear the Rx/Tx descriptors */
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +0000531 priv->hw->desc->init_rx_desc(priv->dma_rx, rxsize, dis_ic);
532 priv->hw->desc->init_tx_desc(priv->dma_tx, txsize);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700533
534 if (netif_msg_hw(priv)) {
535 pr_info("RX descriptor ring:\n");
536 display_ring(priv->dma_rx, rxsize);
537 pr_info("TX descriptor ring:\n");
538 display_ring(priv->dma_tx, txsize);
539 }
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700540}
541
542static void dma_free_rx_skbufs(struct stmmac_priv *priv)
543{
544 int i;
545
546 for (i = 0; i < priv->dma_rx_size; i++) {
547 if (priv->rx_skbuff[i]) {
548 dma_unmap_single(priv->device, priv->rx_skbuff_dma[i],
549 priv->dma_buf_sz, DMA_FROM_DEVICE);
550 dev_kfree_skb_any(priv->rx_skbuff[i]);
551 }
552 priv->rx_skbuff[i] = NULL;
553 }
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700554}
555
556static void dma_free_tx_skbufs(struct stmmac_priv *priv)
557{
558 int i;
559
560 for (i = 0; i < priv->dma_tx_size; i++) {
561 if (priv->tx_skbuff[i] != NULL) {
562 struct dma_desc *p = priv->dma_tx + i;
563 if (p->des2)
564 dma_unmap_single(priv->device, p->des2,
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +0000565 priv->hw->desc->get_tx_len(p),
566 DMA_TO_DEVICE);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700567 dev_kfree_skb_any(priv->tx_skbuff[i]);
568 priv->tx_skbuff[i] = NULL;
569 }
570 }
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700571}
572
573static void free_dma_desc_resources(struct stmmac_priv *priv)
574{
575 /* Release the DMA TX/RX socket buffers */
576 dma_free_rx_skbufs(priv);
577 dma_free_tx_skbufs(priv);
578
579 /* Free the region of consistent memory previously allocated for
580 * the DMA */
581 dma_free_coherent(priv->device,
582 priv->dma_tx_size * sizeof(struct dma_desc),
583 priv->dma_tx, priv->dma_tx_phy);
584 dma_free_coherent(priv->device,
585 priv->dma_rx_size * sizeof(struct dma_desc),
586 priv->dma_rx, priv->dma_rx_phy);
587 kfree(priv->rx_skbuff_dma);
588 kfree(priv->rx_skbuff);
589 kfree(priv->tx_skbuff);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700590}
591
592/**
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700593 * stmmac_dma_operation_mode - HW DMA operation mode
594 * @priv : pointer to the private device structure.
595 * Description: it sets the DMA operation mode: tx/rx DMA thresholds
Giuseppe CAVALLAROebbb2932010-09-17 03:23:40 +0000596 * or Store-And-Forward capability.
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700597 */
598static void stmmac_dma_operation_mode(struct stmmac_priv *priv)
599{
Srinivas Kandagatla61b80132011-07-17 20:54:09 +0000600 if (likely(priv->plat->force_sf_dma_mode ||
601 ((priv->plat->tx_coe) && (!priv->no_csum_insertion)))) {
602 /*
603 * In case of GMAC, SF mode can be enabled
604 * to perform the TX COE in HW. This depends on:
Giuseppe CAVALLAROebbb2932010-09-17 03:23:40 +0000605 * 1) TX COE if actually supported
606 * 2) There is no bugged Jumbo frame support
607 * that needs to not insert csum in the TDES.
608 */
609 priv->hw->dma->dma_mode(priv->ioaddr,
610 SF_DMA_MODE, SF_DMA_MODE);
611 tc = SF_DMA_MODE;
612 } else
613 priv->hw->dma->dma_mode(priv->ioaddr, tc, SF_DMA_MODE);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700614}
615
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700616/**
617 * stmmac_tx:
618 * @priv: private driver structure
619 * Description: it reclaims resources after transmission completes.
620 */
621static void stmmac_tx(struct stmmac_priv *priv)
622{
623 unsigned int txsize = priv->dma_tx_size;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700624
Giuseppe CAVALLAROa9097a92011-10-18 00:01:19 +0000625 spin_lock(&priv->tx_lock);
626
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700627 while (priv->dirty_tx != priv->cur_tx) {
628 int last;
629 unsigned int entry = priv->dirty_tx % txsize;
630 struct sk_buff *skb = priv->tx_skbuff[entry];
631 struct dma_desc *p = priv->dma_tx + entry;
632
633 /* Check if the descriptor is owned by the DMA. */
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +0000634 if (priv->hw->desc->get_tx_owner(p))
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700635 break;
636
637 /* Verify tx error by looking at the last segment */
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +0000638 last = priv->hw->desc->get_tx_ls(p);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700639 if (likely(last)) {
640 int tx_error =
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +0000641 priv->hw->desc->tx_status(&priv->dev->stats,
642 &priv->xstats, p,
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +0000643 priv->ioaddr);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700644 if (likely(tx_error == 0)) {
645 priv->dev->stats.tx_packets++;
646 priv->xstats.tx_pkt_n++;
647 } else
648 priv->dev->stats.tx_errors++;
649 }
650 TX_DBG("%s: curr %d, dirty %d\n", __func__,
651 priv->cur_tx, priv->dirty_tx);
652
653 if (likely(p->des2))
654 dma_unmap_single(priv->device, p->des2,
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +0000655 priv->hw->desc->get_tx_len(p),
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700656 DMA_TO_DEVICE);
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +0000657 priv->hw->ring->clean_desc3(p);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700658
659 if (likely(skb != NULL)) {
660 /*
661 * If there's room in the queue (limit it to size)
662 * we add this skb back into the pool,
663 * if it's the right size.
664 */
665 if ((skb_queue_len(&priv->rx_recycle) <
666 priv->dma_rx_size) &&
667 skb_recycle_check(skb, priv->dma_buf_sz))
668 __skb_queue_head(&priv->rx_recycle, skb);
669 else
670 dev_kfree_skb(skb);
671
672 priv->tx_skbuff[entry] = NULL;
673 }
674
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +0000675 priv->hw->desc->release_tx_desc(p);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700676
677 entry = (++priv->dirty_tx) % txsize;
678 }
679 if (unlikely(netif_queue_stopped(priv->dev) &&
680 stmmac_tx_avail(priv) > STMMAC_TX_THRESH(priv))) {
681 netif_tx_lock(priv->dev);
682 if (netif_queue_stopped(priv->dev) &&
683 stmmac_tx_avail(priv) > STMMAC_TX_THRESH(priv)) {
684 TX_DBG("%s: restart transmit\n", __func__);
685 netif_wake_queue(priv->dev);
686 }
687 netif_tx_unlock(priv->dev);
688 }
Giuseppe CAVALLAROa9097a92011-10-18 00:01:19 +0000689 spin_unlock(&priv->tx_lock);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700690}
691
692static inline void stmmac_enable_irq(struct stmmac_priv *priv)
693{
Giuseppe CAVALLARO73cfe262009-11-22 22:59:56 +0000694#ifdef CONFIG_STMMAC_TIMER
695 if (likely(priv->tm->enable))
696 priv->tm->timer_start(tmrate);
697 else
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700698#endif
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +0000699 priv->hw->dma->enable_dma_irq(priv->ioaddr);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700700}
701
702static inline void stmmac_disable_irq(struct stmmac_priv *priv)
703{
Giuseppe CAVALLARO73cfe262009-11-22 22:59:56 +0000704#ifdef CONFIG_STMMAC_TIMER
705 if (likely(priv->tm->enable))
706 priv->tm->timer_stop();
707 else
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700708#endif
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +0000709 priv->hw->dma->disable_dma_irq(priv->ioaddr);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700710}
711
712static int stmmac_has_work(struct stmmac_priv *priv)
713{
714 unsigned int has_work = 0;
715 int rxret, tx_work = 0;
716
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +0000717 rxret = priv->hw->desc->get_rx_owner(priv->dma_rx +
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700718 (priv->cur_rx % priv->dma_rx_size));
719
720 if (priv->dirty_tx != priv->cur_tx)
721 tx_work = 1;
722
723 if (likely(!rxret || tx_work))
724 has_work = 1;
725
726 return has_work;
727}
728
729static inline void _stmmac_schedule(struct stmmac_priv *priv)
730{
731 if (likely(stmmac_has_work(priv))) {
732 stmmac_disable_irq(priv);
733 napi_schedule(&priv->napi);
734 }
735}
736
737#ifdef CONFIG_STMMAC_TIMER
738void stmmac_schedule(struct net_device *dev)
739{
740 struct stmmac_priv *priv = netdev_priv(dev);
741
742 priv->xstats.sched_timer_n++;
743
744 _stmmac_schedule(priv);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700745}
746
747static void stmmac_no_timer_started(unsigned int x)
748{;
749};
750
751static void stmmac_no_timer_stopped(void)
752{;
753};
754#endif
755
756/**
757 * stmmac_tx_err:
758 * @priv: pointer to the private device structure
759 * Description: it cleans the descriptors and restarts the transmission
760 * in case of errors.
761 */
762static void stmmac_tx_err(struct stmmac_priv *priv)
763{
764 netif_stop_queue(priv->dev);
765
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +0000766 priv->hw->dma->stop_tx(priv->ioaddr);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700767 dma_free_tx_skbufs(priv);
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +0000768 priv->hw->desc->init_tx_desc(priv->dma_tx, priv->dma_tx_size);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700769 priv->dirty_tx = 0;
770 priv->cur_tx = 0;
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +0000771 priv->hw->dma->start_tx(priv->ioaddr);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700772
773 priv->dev->stats.tx_errors++;
774 netif_wake_queue(priv->dev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700775}
776
Giuseppe CAVALLAROaec7ff22010-01-06 23:07:18 +0000777
778static void stmmac_dma_interrupt(struct stmmac_priv *priv)
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700779{
Giuseppe CAVALLAROaec7ff22010-01-06 23:07:18 +0000780 int status;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700781
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +0000782 status = priv->hw->dma->dma_interrupt(priv->ioaddr, &priv->xstats);
Giuseppe CAVALLAROaec7ff22010-01-06 23:07:18 +0000783 if (likely(status == handle_tx_rx))
784 _stmmac_schedule(priv);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700785
Giuseppe CAVALLAROaec7ff22010-01-06 23:07:18 +0000786 else if (unlikely(status == tx_hard_error_bump_tc)) {
787 /* Try to bump up the dma threshold on this failure */
788 if (unlikely(tc != SF_DMA_MODE) && (tc <= 256)) {
789 tc += 64;
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +0000790 priv->hw->dma->dma_mode(priv->ioaddr, tc, SF_DMA_MODE);
Giuseppe CAVALLAROaec7ff22010-01-06 23:07:18 +0000791 priv->xstats.threshold = tc;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700792 }
Giuseppe CAVALLAROaec7ff22010-01-06 23:07:18 +0000793 } else if (unlikely(status == tx_hard_error))
794 stmmac_tx_err(priv);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700795}
796
Giuseppe CAVALLARO1c901a42011-09-01 21:51:38 +0000797static void stmmac_mmc_setup(struct stmmac_priv *priv)
798{
799 unsigned int mode = MMC_CNTRL_RESET_ON_READ | MMC_CNTRL_COUNTER_RESET |
800 MMC_CNTRL_PRESET | MMC_CNTRL_FULL_HALF_PRESET;
801
Giuseppe CAVALLARO4f795b22011-11-18 05:00:20 +0000802 /* Mask MMC irq, counters are managed in SW and registers
803 * are cleared on each READ eventually. */
Giuseppe CAVALLARO1c901a42011-09-01 21:51:38 +0000804 dwmac_mmc_intr_all_mask(priv->ioaddr);
Giuseppe CAVALLARO4f795b22011-11-18 05:00:20 +0000805
806 if (priv->dma_cap.rmon) {
807 dwmac_mmc_ctrl(priv->ioaddr, mode);
808 memset(&priv->mmc, 0, sizeof(struct stmmac_counters));
809 } else
Stefan Roeseaae54cf2012-01-10 01:47:51 +0000810 pr_info(" No MAC Management Counters available\n");
Giuseppe CAVALLARO1c901a42011-09-01 21:51:38 +0000811}
812
Giuseppe CAVALLAROf0b9d782011-09-01 21:51:40 +0000813static u32 stmmac_get_synopsys_id(struct stmmac_priv *priv)
814{
815 u32 hwid = priv->hw->synopsys_uid;
816
817 /* Only check valid Synopsys Id because old MAC chips
818 * have no HW registers where get the ID */
819 if (likely(hwid)) {
820 u32 uid = ((hwid & 0x0000ff00) >> 8);
821 u32 synid = (hwid & 0x000000ff);
822
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +0000823 pr_info("stmmac - user ID: 0x%x, Synopsys ID: 0x%x\n",
Giuseppe CAVALLAROf0b9d782011-09-01 21:51:40 +0000824 uid, synid);
825
826 return synid;
827 }
828 return 0;
829}
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +0000830
Giuseppe CAVALLARO19e30c12011-11-16 21:58:00 +0000831/**
832 * stmmac_selec_desc_mode
833 * @dev : device pointer
834 * Description: select the Enhanced/Alternate or Normal descriptors */
835static void stmmac_selec_desc_mode(struct stmmac_priv *priv)
836{
837 if (priv->plat->enh_desc) {
838 pr_info(" Enhanced/Alternate descriptors\n");
839 priv->hw->desc = &enh_desc_ops;
840 } else {
841 pr_info(" Normal descriptors\n");
842 priv->hw->desc = &ndesc_ops;
843 }
844}
845
846/**
847 * stmmac_get_hw_features
848 * @priv : private device pointer
849 * Description:
850 * new GMAC chip generations have a new register to indicate the
851 * presence of the optional feature/functions.
852 * This can be also used to override the value passed through the
853 * platform and necessary for old MAC10/100 and GMAC chips.
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +0000854 */
855static int stmmac_get_hw_features(struct stmmac_priv *priv)
856{
Giuseppe CAVALLARO5e6efe82011-10-26 19:43:07 +0000857 u32 hw_cap = 0;
Giuseppe CAVALLARO3c20f722011-10-26 19:43:09 +0000858
Giuseppe CAVALLARO5e6efe82011-10-26 19:43:07 +0000859 if (priv->hw->dma->get_hw_feature) {
860 hw_cap = priv->hw->dma->get_hw_feature(priv->ioaddr);
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +0000861
Rayagond Kokatanur1db123f2011-10-18 00:01:22 +0000862 priv->dma_cap.mbps_10_100 = (hw_cap & DMA_HW_FEAT_MIISEL);
863 priv->dma_cap.mbps_1000 = (hw_cap & DMA_HW_FEAT_GMIISEL) >> 1;
864 priv->dma_cap.half_duplex = (hw_cap & DMA_HW_FEAT_HDSEL) >> 2;
865 priv->dma_cap.hash_filter = (hw_cap & DMA_HW_FEAT_HASHSEL) >> 4;
866 priv->dma_cap.multi_addr =
867 (hw_cap & DMA_HW_FEAT_ADDMACADRSEL) >> 5;
868 priv->dma_cap.pcs = (hw_cap & DMA_HW_FEAT_PCSSEL) >> 6;
869 priv->dma_cap.sma_mdio = (hw_cap & DMA_HW_FEAT_SMASEL) >> 8;
870 priv->dma_cap.pmt_remote_wake_up =
871 (hw_cap & DMA_HW_FEAT_RWKSEL) >> 9;
872 priv->dma_cap.pmt_magic_frame =
873 (hw_cap & DMA_HW_FEAT_MGKSEL) >> 10;
Giuseppe CAVALLARO19e30c12011-11-16 21:58:00 +0000874 /* MMC */
Rayagond Kokatanur1db123f2011-10-18 00:01:22 +0000875 priv->dma_cap.rmon = (hw_cap & DMA_HW_FEAT_MMCSEL) >> 11;
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +0000876 /* IEEE 1588-2002*/
Rayagond Kokatanur1db123f2011-10-18 00:01:22 +0000877 priv->dma_cap.time_stamp =
878 (hw_cap & DMA_HW_FEAT_TSVER1SEL) >> 12;
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +0000879 /* IEEE 1588-2008*/
Rayagond Kokatanur1db123f2011-10-18 00:01:22 +0000880 priv->dma_cap.atime_stamp =
881 (hw_cap & DMA_HW_FEAT_TSVER2SEL) >> 13;
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +0000882 /* 802.3az - Energy-Efficient Ethernet (EEE) */
Rayagond Kokatanur1db123f2011-10-18 00:01:22 +0000883 priv->dma_cap.eee = (hw_cap & DMA_HW_FEAT_EEESEL) >> 14;
884 priv->dma_cap.av = (hw_cap & DMA_HW_FEAT_AVSEL) >> 15;
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +0000885 /* TX and RX csum */
Rayagond Kokatanur1db123f2011-10-18 00:01:22 +0000886 priv->dma_cap.tx_coe = (hw_cap & DMA_HW_FEAT_TXCOESEL) >> 16;
887 priv->dma_cap.rx_coe_type1 =
888 (hw_cap & DMA_HW_FEAT_RXTYP1COE) >> 17;
889 priv->dma_cap.rx_coe_type2 =
890 (hw_cap & DMA_HW_FEAT_RXTYP2COE) >> 18;
891 priv->dma_cap.rxfifo_over_2048 =
892 (hw_cap & DMA_HW_FEAT_RXFIFOSIZE) >> 19;
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +0000893 /* TX and RX number of channels */
Rayagond Kokatanur1db123f2011-10-18 00:01:22 +0000894 priv->dma_cap.number_rx_channel =
895 (hw_cap & DMA_HW_FEAT_RXCHCNT) >> 20;
896 priv->dma_cap.number_tx_channel =
897 (hw_cap & DMA_HW_FEAT_TXCHCNT) >> 22;
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +0000898 /* Alternate (enhanced) DESC mode*/
Rayagond Kokatanur1db123f2011-10-18 00:01:22 +0000899 priv->dma_cap.enh_desc =
900 (hw_cap & DMA_HW_FEAT_ENHDESSEL) >> 24;
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +0000901
Giuseppe CAVALLARO19e30c12011-11-16 21:58:00 +0000902 }
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +0000903
904 return hw_cap;
905}
906
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000907static void stmmac_check_ether_addr(struct stmmac_priv *priv)
908{
909 /* verify if the MAC address is valid, in case of failures it
910 * generates a random MAC address */
911 if (!is_valid_ether_addr(priv->dev->dev_addr)) {
912 priv->hw->mac->get_umac_addr((void __iomem *)
913 priv->dev->base_addr,
914 priv->dev->dev_addr, 0);
915 if (!is_valid_ether_addr(priv->dev->dev_addr))
Danny Kukawkaf2cedb62012-02-15 06:45:39 +0000916 eth_hw_addr_random(priv->dev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000917 }
918 pr_warning("%s: device MAC address %pM\n", priv->dev->name,
919 priv->dev->dev_addr);
920}
921
922/**
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700923 * stmmac_open - open entry point of the driver
924 * @dev : pointer to the device structure.
925 * Description:
926 * This function is the open entry point of the driver.
927 * Return value:
928 * 0 on success and an appropriate (-)ve integer as defined in errno.h
929 * file on failure.
930 */
931static int stmmac_open(struct net_device *dev)
932{
933 struct stmmac_priv *priv = netdev_priv(dev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700934 int ret;
935
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700936#ifdef CONFIG_STMMAC_TIMER
Giuseppe CAVALLARO73cfe262009-11-22 22:59:56 +0000937 priv->tm = kzalloc(sizeof(struct stmmac_timer *), GFP_KERNEL);
Francesco Virlinzi4bfcbd72012-04-18 19:48:20 +0000938 if (unlikely(priv->tm == NULL))
939 return -ENOMEM;
Joe Perchese404dec2012-01-29 12:56:23 +0000940
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700941 priv->tm->freq = tmrate;
942
Giuseppe CAVALLARO73cfe262009-11-22 22:59:56 +0000943 /* Test if the external timer can be actually used.
944 * In case of failure continue without timer. */
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700945 if (unlikely((stmmac_open_ext_timer(dev, priv->tm)) < 0)) {
Giuseppe CAVALLARO73cfe262009-11-22 22:59:56 +0000946 pr_warning("stmmaceth: cannot attach the external timer.\n");
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700947 priv->tm->freq = 0;
948 priv->tm->timer_start = stmmac_no_timer_started;
949 priv->tm->timer_stop = stmmac_no_timer_stopped;
Giuseppe CAVALLARO73cfe262009-11-22 22:59:56 +0000950 } else
951 priv->tm->enable = 1;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700952#endif
Francesco Virlinzi4bfcbd72012-04-18 19:48:20 +0000953 stmmac_clk_enable(priv);
954
955 stmmac_check_ether_addr(priv);
956
Giuseppe CAVALLAROf66ffe22011-04-10 23:16:45 +0000957 ret = stmmac_init_phy(dev);
958 if (unlikely(ret)) {
959 pr_err("%s: Cannot attach to PHY (error: %d)\n", __func__, ret);
960 goto open_error;
961 }
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700962
963 /* Create and initialize the TX/RX descriptors chains. */
964 priv->dma_tx_size = STMMAC_ALIGN(dma_txsize);
965 priv->dma_rx_size = STMMAC_ALIGN(dma_rxsize);
966 priv->dma_buf_sz = STMMAC_ALIGN(buf_sz);
967 init_dma_desc_rings(dev);
968
969 /* DMA initialization and SW reset */
Deepak SIKRI8327eb62012-04-04 04:33:23 +0000970 ret = priv->hw->dma->init(priv->ioaddr, priv->plat->dma_cfg->pbl,
971 priv->plat->dma_cfg->fixed_burst,
972 priv->plat->dma_cfg->burst_len,
Giuseppe CAVALLAROf66ffe22011-04-10 23:16:45 +0000973 priv->dma_tx_phy, priv->dma_rx_phy);
974 if (ret < 0) {
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700975 pr_err("%s: DMA initialization failed\n", __func__);
Giuseppe CAVALLAROf66ffe22011-04-10 23:16:45 +0000976 goto open_error;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700977 }
978
979 /* Copy the MAC addr into the HW */
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +0000980 priv->hw->mac->set_umac_addr(priv->ioaddr, dev->dev_addr, 0);
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +0000981
Giuseppe CAVALLAROca5f12c2010-01-06 23:07:15 +0000982 /* If required, perform hw setup of the bus. */
Giuseppe CAVALLARO9dfeb4d2010-11-24 02:37:58 +0000983 if (priv->plat->bus_setup)
984 priv->plat->bus_setup(priv->ioaddr);
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +0000985
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700986 /* Initialize the MAC Core */
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +0000987 priv->hw->mac->core_init(priv->ioaddr);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700988
Giuseppe CAVALLAROf66ffe22011-04-10 23:16:45 +0000989 /* Request the IRQ lines */
990 ret = request_irq(dev->irq, stmmac_interrupt,
991 IRQF_SHARED, dev->name, dev);
992 if (unlikely(ret < 0)) {
993 pr_err("%s: ERROR: allocating the IRQ %d (error: %d)\n",
994 __func__, dev->irq, ret);
995 goto open_error;
996 }
997
Francesco Virlinzi7a13f8f2012-02-15 00:10:38 +0000998 /* Request the Wake IRQ in case of another line is used for WoL */
999 if (priv->wol_irq != dev->irq) {
1000 ret = request_irq(priv->wol_irq, stmmac_interrupt,
1001 IRQF_SHARED, dev->name, dev);
1002 if (unlikely(ret < 0)) {
1003 pr_err("%s: ERROR: allocating the ext WoL IRQ %d "
1004 "(error: %d)\n", __func__, priv->wol_irq, ret);
1005 goto open_error_wolirq;
1006 }
1007 }
1008
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001009 /* Enable the MAC Rx/Tx */
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001010 stmmac_set_mac(priv->ioaddr, true);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001011
1012 /* Set the HW DMA mode and the COE */
1013 stmmac_dma_operation_mode(priv);
1014
1015 /* Extra statistics */
1016 memset(&priv->xstats, 0, sizeof(struct stmmac_extra_stats));
1017 priv->xstats.threshold = tc;
1018
Giuseppe CAVALLARO4f795b22011-11-18 05:00:20 +00001019 stmmac_mmc_setup(priv);
Giuseppe CAVALLARO1c901a42011-09-01 21:51:38 +00001020
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001021#ifdef CONFIG_STMMAC_DEBUG_FS
1022 ret = stmmac_init_fs(dev);
1023 if (ret < 0)
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00001024 pr_warning("%s: failed debugFS registration\n", __func__);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001025#endif
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001026 /* Start the ball rolling... */
1027 DBG(probe, DEBUG, "%s: DMA RX/TX processes started...\n", dev->name);
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +00001028 priv->hw->dma->start_tx(priv->ioaddr);
1029 priv->hw->dma->start_rx(priv->ioaddr);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001030
1031#ifdef CONFIG_STMMAC_TIMER
1032 priv->tm->timer_start(tmrate);
1033#endif
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00001034
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001035 /* Dump DMA/MAC registers */
1036 if (netif_msg_hw(priv)) {
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +00001037 priv->hw->mac->dump_regs(priv->ioaddr);
1038 priv->hw->dma->dump_regs(priv->ioaddr);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001039 }
1040
1041 if (priv->phydev)
1042 phy_start(priv->phydev);
1043
1044 napi_enable(&priv->napi);
1045 skb_queue_head_init(&priv->rx_recycle);
1046 netif_start_queue(dev);
Giuseppe CAVALLAROf66ffe22011-04-10 23:16:45 +00001047
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001048 return 0;
Giuseppe CAVALLAROf66ffe22011-04-10 23:16:45 +00001049
Francesco Virlinzi7a13f8f2012-02-15 00:10:38 +00001050open_error_wolirq:
1051 free_irq(dev->irq, dev);
1052
Giuseppe CAVALLAROf66ffe22011-04-10 23:16:45 +00001053open_error:
1054#ifdef CONFIG_STMMAC_TIMER
1055 kfree(priv->tm);
1056#endif
1057 if (priv->phydev)
1058 phy_disconnect(priv->phydev);
1059
Giuseppe CAVALLAROba1377ff2012-04-04 04:33:25 +00001060 stmmac_clk_disable(priv);
Francesco Virlinzi4bfcbd72012-04-18 19:48:20 +00001061
Giuseppe CAVALLAROf66ffe22011-04-10 23:16:45 +00001062 return ret;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001063}
1064
1065/**
1066 * stmmac_release - close entry point of the driver
1067 * @dev : device pointer.
1068 * Description:
1069 * This is the stop entry point of the driver.
1070 */
1071static int stmmac_release(struct net_device *dev)
1072{
1073 struct stmmac_priv *priv = netdev_priv(dev);
1074
1075 /* Stop and disconnect the PHY */
1076 if (priv->phydev) {
1077 phy_stop(priv->phydev);
1078 phy_disconnect(priv->phydev);
1079 priv->phydev = NULL;
1080 }
1081
1082 netif_stop_queue(dev);
1083
1084#ifdef CONFIG_STMMAC_TIMER
1085 /* Stop and release the timer */
1086 stmmac_close_ext_timer();
1087 if (priv->tm != NULL)
1088 kfree(priv->tm);
1089#endif
1090 napi_disable(&priv->napi);
1091 skb_queue_purge(&priv->rx_recycle);
1092
1093 /* Free the IRQ lines */
1094 free_irq(dev->irq, dev);
Francesco Virlinzi7a13f8f2012-02-15 00:10:38 +00001095 if (priv->wol_irq != dev->irq)
1096 free_irq(priv->wol_irq, dev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001097
1098 /* Stop TX/RX DMA and clear the descriptors */
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +00001099 priv->hw->dma->stop_tx(priv->ioaddr);
1100 priv->hw->dma->stop_rx(priv->ioaddr);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001101
1102 /* Release and free the Rx/Tx resources */
1103 free_dma_desc_resources(priv);
1104
avisconti19449bf2010-10-25 18:58:14 +00001105 /* Disable the MAC Rx/Tx */
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001106 stmmac_set_mac(priv->ioaddr, false);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001107
1108 netif_carrier_off(dev);
1109
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001110#ifdef CONFIG_STMMAC_DEBUG_FS
1111 stmmac_exit_fs();
1112#endif
Giuseppe CAVALLAROba1377ff2012-04-04 04:33:25 +00001113 stmmac_clk_disable(priv);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001114
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001115 return 0;
1116}
1117
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001118/**
1119 * stmmac_xmit:
1120 * @skb : the socket buffer
1121 * @dev : device pointer
1122 * Description : Tx entry point of the driver.
1123 */
1124static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
1125{
1126 struct stmmac_priv *priv = netdev_priv(dev);
1127 unsigned int txsize = priv->dma_tx_size;
1128 unsigned int entry;
1129 int i, csum_insertion = 0;
1130 int nfrags = skb_shinfo(skb)->nr_frags;
1131 struct dma_desc *desc, *first;
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +00001132 unsigned int nopaged_len = skb_headlen(skb);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001133
1134 if (unlikely(stmmac_tx_avail(priv) < nfrags + 1)) {
1135 if (!netif_queue_stopped(dev)) {
1136 netif_stop_queue(dev);
1137 /* This is a hard error, log it. */
1138 pr_err("%s: BUG! Tx Ring full when queue awake\n",
1139 __func__);
1140 }
1141 return NETDEV_TX_BUSY;
1142 }
1143
Giuseppe CAVALLAROa9097a92011-10-18 00:01:19 +00001144 spin_lock(&priv->tx_lock);
1145
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001146 entry = priv->cur_tx % txsize;
1147
1148#ifdef STMMAC_XMIT_DEBUG
1149 if ((skb->len > ETH_FRAME_LEN) || nfrags)
1150 pr_info("stmmac xmit:\n"
1151 "\tskb addr %p - len: %d - nopaged_len: %d\n"
1152 "\tn_frags: %d - ip_summed: %d - %s gso\n",
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +00001153 skb, skb->len, nopaged_len, nfrags, skb->ip_summed,
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001154 !skb_is_gso(skb) ? "isn't" : "is");
1155#endif
1156
Michał Mirosław5e982f32011-04-09 02:46:55 +00001157 csum_insertion = (skb->ip_summed == CHECKSUM_PARTIAL);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001158
1159 desc = priv->dma_tx + entry;
1160 first = desc;
1161
1162#ifdef STMMAC_XMIT_DEBUG
1163 if ((nfrags > 0) || (skb->len > ETH_FRAME_LEN))
1164 pr_debug("stmmac xmit: skb len: %d, nopaged_len: %d,\n"
1165 "\t\tn_frags: %d, ip_summed: %d\n",
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +00001166 skb->len, nopaged_len, nfrags, skb->ip_summed);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001167#endif
1168 priv->tx_skbuff[entry] = skb;
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +00001169
1170 if (priv->hw->ring->is_jumbo_frm(skb->len, priv->plat->enh_desc)) {
1171 entry = priv->hw->ring->jumbo_frm(priv, skb, csum_insertion);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001172 desc = priv->dma_tx + entry;
1173 } else {
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001174 desc->des2 = dma_map_single(priv->device, skb->data,
1175 nopaged_len, DMA_TO_DEVICE);
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +00001176 priv->hw->desc->prepare_tx_desc(desc, 1, nopaged_len,
1177 csum_insertion);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001178 }
1179
1180 for (i = 0; i < nfrags; i++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00001181 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1182 int len = skb_frag_size(frag);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001183
1184 entry = (++priv->cur_tx) % txsize;
1185 desc = priv->dma_tx + entry;
1186
1187 TX_DBG("\t[entry %d] segment len: %d\n", entry, len);
Ian Campbellf7223802011-09-21 21:53:20 +00001188 desc->des2 = skb_frag_dma_map(priv->device, frag, 0, len,
1189 DMA_TO_DEVICE);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001190 priv->tx_skbuff[entry] = NULL;
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +00001191 priv->hw->desc->prepare_tx_desc(desc, 0, len, csum_insertion);
Shiraz Hashimeb0dc4b2011-07-17 20:54:08 +00001192 wmb();
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +00001193 priv->hw->desc->set_tx_owner(desc);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001194 }
1195
1196 /* Interrupt on completition only for the latest segment */
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +00001197 priv->hw->desc->close_tx_desc(desc);
Giuseppe CAVALLARO73cfe262009-11-22 22:59:56 +00001198
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001199#ifdef CONFIG_STMMAC_TIMER
Giuseppe CAVALLARO73cfe262009-11-22 22:59:56 +00001200 /* Clean IC while using timer */
1201 if (likely(priv->tm->enable))
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +00001202 priv->hw->desc->clear_tx_ic(desc);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001203#endif
Shiraz Hashimeb0dc4b2011-07-17 20:54:08 +00001204
1205 wmb();
1206
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001207 /* To avoid raise condition */
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +00001208 priv->hw->desc->set_tx_owner(first);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001209
1210 priv->cur_tx++;
1211
1212#ifdef STMMAC_XMIT_DEBUG
1213 if (netif_msg_pktdata(priv)) {
1214 pr_info("stmmac xmit: current=%d, dirty=%d, entry=%d, "
1215 "first=%p, nfrags=%d\n",
1216 (priv->cur_tx % txsize), (priv->dirty_tx % txsize),
1217 entry, first, nfrags);
1218 display_ring(priv->dma_tx, txsize);
1219 pr_info(">>> frame to be transmitted: ");
1220 print_pkt(skb->data, skb->len);
1221 }
1222#endif
1223 if (unlikely(stmmac_tx_avail(priv) <= (MAX_SKB_FRAGS + 1))) {
1224 TX_DBG("%s: stop transmitted packets\n", __func__);
1225 netif_stop_queue(dev);
1226 }
1227
1228 dev->stats.tx_bytes += skb->len;
1229
Richard Cochran3e82ce12011-06-12 02:19:06 +00001230 skb_tx_timestamp(skb);
1231
Richard Cochran52f64fa2011-06-19 03:31:43 +00001232 priv->hw->dma->enable_dma_transmission(priv->ioaddr);
1233
Giuseppe CAVALLAROa9097a92011-10-18 00:01:19 +00001234 spin_unlock(&priv->tx_lock);
1235
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001236 return NETDEV_TX_OK;
1237}
1238
1239static inline void stmmac_rx_refill(struct stmmac_priv *priv)
1240{
1241 unsigned int rxsize = priv->dma_rx_size;
1242 int bfsize = priv->dma_buf_sz;
1243 struct dma_desc *p = priv->dma_rx;
1244
1245 for (; priv->cur_rx - priv->dirty_rx > 0; priv->dirty_rx++) {
1246 unsigned int entry = priv->dirty_rx % rxsize;
1247 if (likely(priv->rx_skbuff[entry] == NULL)) {
1248 struct sk_buff *skb;
1249
1250 skb = __skb_dequeue(&priv->rx_recycle);
1251 if (skb == NULL)
1252 skb = netdev_alloc_skb_ip_align(priv->dev,
1253 bfsize);
1254
1255 if (unlikely(skb == NULL))
1256 break;
1257
1258 priv->rx_skbuff[entry] = skb;
1259 priv->rx_skbuff_dma[entry] =
1260 dma_map_single(priv->device, skb->data, bfsize,
1261 DMA_FROM_DEVICE);
1262
1263 (p + entry)->des2 = priv->rx_skbuff_dma[entry];
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +00001264
1265 if (unlikely(priv->plat->has_gmac))
1266 priv->hw->ring->refill_desc3(bfsize, p + entry);
1267
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001268 RX_DBG(KERN_INFO "\trefill entry #%d\n", entry);
1269 }
Shiraz Hashimeb0dc4b2011-07-17 20:54:08 +00001270 wmb();
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +00001271 priv->hw->desc->set_rx_owner(p + entry);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001272 }
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001273}
1274
1275static int stmmac_rx(struct stmmac_priv *priv, int limit)
1276{
1277 unsigned int rxsize = priv->dma_rx_size;
1278 unsigned int entry = priv->cur_rx % rxsize;
1279 unsigned int next_entry;
1280 unsigned int count = 0;
1281 struct dma_desc *p = priv->dma_rx + entry;
1282 struct dma_desc *p_next;
1283
1284#ifdef STMMAC_RX_DEBUG
1285 if (netif_msg_hw(priv)) {
1286 pr_debug(">>> stmmac_rx: descriptor ring:\n");
1287 display_ring(priv->dma_rx, rxsize);
1288 }
1289#endif
1290 count = 0;
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +00001291 while (!priv->hw->desc->get_rx_owner(p)) {
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001292 int status;
1293
1294 if (count >= limit)
1295 break;
1296
1297 count++;
1298
1299 next_entry = (++priv->cur_rx) % rxsize;
1300 p_next = priv->dma_rx + next_entry;
1301 prefetch(p_next);
1302
1303 /* read the status of the incoming frame */
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +00001304 status = (priv->hw->desc->rx_status(&priv->dev->stats,
1305 &priv->xstats, p));
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001306 if (unlikely(status == discard_frame))
1307 priv->dev->stats.rx_errors++;
1308 else {
1309 struct sk_buff *skb;
Giuseppe CAVALLARO3eeb2992010-07-27 00:09:47 +00001310 int frame_len;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001311
Deepak SIKRI38912bd2012-04-04 04:33:21 +00001312 frame_len = priv->hw->desc->get_rx_frame_len(p,
1313 priv->plat->rx_coe);
Giuseppe CAVALLARO3eeb2992010-07-27 00:09:47 +00001314 /* ACS is set; GMAC core strips PAD/FCS for IEEE 802.3
1315 * Type frames (LLC/LLC-SNAP) */
1316 if (unlikely(status != llc_snap))
1317 frame_len -= ETH_FCS_LEN;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001318#ifdef STMMAC_RX_DEBUG
1319 if (frame_len > ETH_FRAME_LEN)
1320 pr_debug("\tRX frame size %d, COE status: %d\n",
1321 frame_len, status);
1322
1323 if (netif_msg_hw(priv))
1324 pr_debug("\tdesc: %p [entry %d] buff=0x%x\n",
1325 p, entry, p->des2);
1326#endif
1327 skb = priv->rx_skbuff[entry];
1328 if (unlikely(!skb)) {
1329 pr_err("%s: Inconsistent Rx descriptor chain\n",
1330 priv->dev->name);
1331 priv->dev->stats.rx_dropped++;
1332 break;
1333 }
1334 prefetch(skb->data - NET_IP_ALIGN);
1335 priv->rx_skbuff[entry] = NULL;
1336
1337 skb_put(skb, frame_len);
1338 dma_unmap_single(priv->device,
1339 priv->rx_skbuff_dma[entry],
1340 priv->dma_buf_sz, DMA_FROM_DEVICE);
1341#ifdef STMMAC_RX_DEBUG
1342 if (netif_msg_pktdata(priv)) {
1343 pr_info(" frame received (%dbytes)", frame_len);
1344 print_pkt(skb->data, frame_len);
1345 }
1346#endif
1347 skb->protocol = eth_type_trans(skb, priv->dev);
1348
Deepak SIKRI38912bd2012-04-04 04:33:21 +00001349 if (unlikely(!priv->plat->rx_coe)) {
Giuseppe CAVALLARO3c20f722011-10-26 19:43:09 +00001350 /* No RX COE for old mac10/100 devices */
Eric Dumazetbc8acf22010-09-02 13:07:41 -07001351 skb_checksum_none_assert(skb);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001352 netif_receive_skb(skb);
1353 } else {
1354 skb->ip_summed = CHECKSUM_UNNECESSARY;
1355 napi_gro_receive(&priv->napi, skb);
1356 }
1357
1358 priv->dev->stats.rx_packets++;
1359 priv->dev->stats.rx_bytes += frame_len;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001360 }
1361 entry = next_entry;
1362 p = p_next; /* use prefetched values */
1363 }
1364
1365 stmmac_rx_refill(priv);
1366
1367 priv->xstats.rx_pkt_n += count;
1368
1369 return count;
1370}
1371
1372/**
1373 * stmmac_poll - stmmac poll method (NAPI)
1374 * @napi : pointer to the napi structure.
1375 * @budget : maximum number of packets that the current CPU can receive from
1376 * all interfaces.
1377 * Description :
1378 * This function implements the the reception process.
1379 * Also it runs the TX completion thread
1380 */
1381static int stmmac_poll(struct napi_struct *napi, int budget)
1382{
1383 struct stmmac_priv *priv = container_of(napi, struct stmmac_priv, napi);
1384 int work_done = 0;
1385
1386 priv->xstats.poll_n++;
1387 stmmac_tx(priv);
1388 work_done = stmmac_rx(priv, budget);
1389
1390 if (work_done < budget) {
1391 napi_complete(napi);
1392 stmmac_enable_irq(priv);
1393 }
1394 return work_done;
1395}
1396
1397/**
1398 * stmmac_tx_timeout
1399 * @dev : Pointer to net device structure
1400 * Description: this function is called when a packet transmission fails to
1401 * complete within a reasonable tmrate. The driver will mark the error in the
1402 * netdev structure and arrange for the device to be reset to a sane state
1403 * in order to transmit a new packet.
1404 */
1405static void stmmac_tx_timeout(struct net_device *dev)
1406{
1407 struct stmmac_priv *priv = netdev_priv(dev);
1408
1409 /* Clear Tx resources and restart transmitting again */
1410 stmmac_tx_err(priv);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001411}
1412
1413/* Configuration changes (passed on by ifconfig) */
1414static int stmmac_config(struct net_device *dev, struct ifmap *map)
1415{
1416 if (dev->flags & IFF_UP) /* can't act on a running interface */
1417 return -EBUSY;
1418
1419 /* Don't allow changing the I/O address */
1420 if (map->base_addr != dev->base_addr) {
1421 pr_warning("%s: can't change I/O address\n", dev->name);
1422 return -EOPNOTSUPP;
1423 }
1424
1425 /* Don't allow changing the IRQ */
1426 if (map->irq != dev->irq) {
1427 pr_warning("%s: can't change IRQ number %d\n",
1428 dev->name, dev->irq);
1429 return -EOPNOTSUPP;
1430 }
1431
1432 /* ignore other fields */
1433 return 0;
1434}
1435
1436/**
Jiri Pirko01789342011-08-16 06:29:00 +00001437 * stmmac_set_rx_mode - entry point for multicast addressing
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001438 * @dev : pointer to the device structure
1439 * Description:
1440 * This function is a driver entry point which gets called by the kernel
1441 * whenever multicast addresses must be enabled/disabled.
1442 * Return value:
1443 * void.
1444 */
Jiri Pirko01789342011-08-16 06:29:00 +00001445static void stmmac_set_rx_mode(struct net_device *dev)
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001446{
1447 struct stmmac_priv *priv = netdev_priv(dev);
1448
1449 spin_lock(&priv->lock);
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +00001450 priv->hw->mac->set_filter(dev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001451 spin_unlock(&priv->lock);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001452}
1453
1454/**
1455 * stmmac_change_mtu - entry point to change MTU size for the device.
1456 * @dev : device pointer.
1457 * @new_mtu : the new MTU size for the device.
1458 * Description: the Maximum Transfer Unit (MTU) is used by the network layer
1459 * to drive packet transmission. Ethernet has an MTU of 1500 octets
1460 * (ETH_DATA_LEN). This value can be changed with ifconfig.
1461 * Return value:
1462 * 0 on success and an appropriate (-)ve integer as defined in errno.h
1463 * file on failure.
1464 */
1465static int stmmac_change_mtu(struct net_device *dev, int new_mtu)
1466{
1467 struct stmmac_priv *priv = netdev_priv(dev);
1468 int max_mtu;
1469
1470 if (netif_running(dev)) {
1471 pr_err("%s: must be stopped to change its MTU\n", dev->name);
1472 return -EBUSY;
1473 }
1474
Giuseppe CAVALLARO48febf72011-10-18 00:01:21 +00001475 if (priv->plat->enh_desc)
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001476 max_mtu = JUMBO_LEN;
1477 else
Giuseppe CAVALLARO45db81e2011-10-18 01:39:55 +00001478 max_mtu = SKB_MAX_HEAD(NET_SKB_PAD + NET_IP_ALIGN);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001479
1480 if ((new_mtu < 46) || (new_mtu > max_mtu)) {
1481 pr_err("%s: invalid MTU, max MTU is: %d\n", dev->name, max_mtu);
1482 return -EINVAL;
1483 }
1484
Michał Mirosław5e982f32011-04-09 02:46:55 +00001485 dev->mtu = new_mtu;
1486 netdev_update_features(dev);
1487
1488 return 0;
1489}
1490
Michał Mirosławc8f44af2011-11-15 15:29:55 +00001491static netdev_features_t stmmac_fix_features(struct net_device *dev,
1492 netdev_features_t features)
Michał Mirosław5e982f32011-04-09 02:46:55 +00001493{
1494 struct stmmac_priv *priv = netdev_priv(dev);
1495
Deepak SIKRI38912bd2012-04-04 04:33:21 +00001496 if (priv->plat->rx_coe == STMMAC_RX_COE_NONE)
Michał Mirosław5e982f32011-04-09 02:46:55 +00001497 features &= ~NETIF_F_RXCSUM;
Deepak SIKRI38912bd2012-04-04 04:33:21 +00001498 else if (priv->plat->rx_coe == STMMAC_RX_COE_TYPE1)
1499 features &= ~NETIF_F_IPV6_CSUM;
Michał Mirosław5e982f32011-04-09 02:46:55 +00001500 if (!priv->plat->tx_coe)
1501 features &= ~NETIF_F_ALL_CSUM;
1502
Giuseppe CAVALLAROebbb2932010-09-17 03:23:40 +00001503 /* Some GMAC devices have a bugged Jumbo frame support that
1504 * needs to have the Tx COE disabled for oversized frames
1505 * (due to limited buffer sizes). In this case we disable
1506 * the TX csum insertionin the TDES and not use SF. */
Michał Mirosław5e982f32011-04-09 02:46:55 +00001507 if (priv->plat->bugged_jumbo && (dev->mtu > ETH_DATA_LEN))
1508 features &= ~NETIF_F_ALL_CSUM;
Giuseppe CAVALLAROebbb2932010-09-17 03:23:40 +00001509
Michał Mirosław5e982f32011-04-09 02:46:55 +00001510 return features;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001511}
1512
1513static irqreturn_t stmmac_interrupt(int irq, void *dev_id)
1514{
1515 struct net_device *dev = (struct net_device *)dev_id;
1516 struct stmmac_priv *priv = netdev_priv(dev);
1517
1518 if (unlikely(!dev)) {
1519 pr_err("%s: invalid dev pointer\n", __func__);
1520 return IRQ_NONE;
1521 }
1522
Giuseppe CAVALLARO9dfeb4d2010-11-24 02:37:58 +00001523 if (priv->plat->has_gmac)
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001524 /* To handle GMAC own interrupts */
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +00001525 priv->hw->mac->host_irq_status((void __iomem *) dev->base_addr);
Giuseppe CAVALLAROaec7ff22010-01-06 23:07:18 +00001526
1527 stmmac_dma_interrupt(priv);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001528
1529 return IRQ_HANDLED;
1530}
1531
1532#ifdef CONFIG_NET_POLL_CONTROLLER
1533/* Polling receive - used by NETCONSOLE and other diagnostic tools
1534 * to allow network I/O with interrupts disabled. */
1535static void stmmac_poll_controller(struct net_device *dev)
1536{
1537 disable_irq(dev->irq);
1538 stmmac_interrupt(dev->irq, dev);
1539 enable_irq(dev->irq);
1540}
1541#endif
1542
1543/**
1544 * stmmac_ioctl - Entry point for the Ioctl
1545 * @dev: Device pointer.
1546 * @rq: An IOCTL specefic structure, that can contain a pointer to
1547 * a proprietary structure used to pass information to the driver.
1548 * @cmd: IOCTL command
1549 * Description:
1550 * Currently there are no special functionality supported in IOCTL, just the
1551 * phy_mii_ioctl(...) can be invoked.
1552 */
1553static int stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1554{
1555 struct stmmac_priv *priv = netdev_priv(dev);
Richard Cochran28b04112010-07-17 08:48:55 +00001556 int ret;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001557
1558 if (!netif_running(dev))
1559 return -EINVAL;
1560
Richard Cochran28b04112010-07-17 08:48:55 +00001561 if (!priv->phydev)
1562 return -EINVAL;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001563
Richard Cochran28b04112010-07-17 08:48:55 +00001564 ret = phy_mii_ioctl(priv->phydev, rq, cmd);
Richard Cochran28b04112010-07-17 08:48:55 +00001565
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001566 return ret;
1567}
1568
Giuseppe CAVALLARO7ac29052011-09-01 21:51:39 +00001569#ifdef CONFIG_STMMAC_DEBUG_FS
1570static struct dentry *stmmac_fs_dir;
1571static struct dentry *stmmac_rings_status;
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +00001572static struct dentry *stmmac_dma_cap;
Giuseppe CAVALLARO7ac29052011-09-01 21:51:39 +00001573
1574static int stmmac_sysfs_ring_read(struct seq_file *seq, void *v)
1575{
1576 struct tmp_s {
1577 u64 a;
1578 unsigned int b;
1579 unsigned int c;
1580 };
1581 int i;
1582 struct net_device *dev = seq->private;
1583 struct stmmac_priv *priv = netdev_priv(dev);
1584
1585 seq_printf(seq, "=======================\n");
1586 seq_printf(seq, " RX descriptor ring\n");
1587 seq_printf(seq, "=======================\n");
1588
1589 for (i = 0; i < priv->dma_rx_size; i++) {
1590 struct tmp_s *x = (struct tmp_s *)(priv->dma_rx + i);
1591 seq_printf(seq, "[%d] DES0=0x%x DES1=0x%x BUF1=0x%x BUF2=0x%x",
1592 i, (unsigned int)(x->a),
1593 (unsigned int)((x->a) >> 32), x->b, x->c);
1594 seq_printf(seq, "\n");
1595 }
1596
1597 seq_printf(seq, "\n");
1598 seq_printf(seq, "=======================\n");
1599 seq_printf(seq, " TX descriptor ring\n");
1600 seq_printf(seq, "=======================\n");
1601
1602 for (i = 0; i < priv->dma_tx_size; i++) {
1603 struct tmp_s *x = (struct tmp_s *)(priv->dma_tx + i);
1604 seq_printf(seq, "[%d] DES0=0x%x DES1=0x%x BUF1=0x%x BUF2=0x%x",
1605 i, (unsigned int)(x->a),
1606 (unsigned int)((x->a) >> 32), x->b, x->c);
1607 seq_printf(seq, "\n");
1608 }
1609
1610 return 0;
1611}
1612
1613static int stmmac_sysfs_ring_open(struct inode *inode, struct file *file)
1614{
1615 return single_open(file, stmmac_sysfs_ring_read, inode->i_private);
1616}
1617
1618static const struct file_operations stmmac_rings_status_fops = {
1619 .owner = THIS_MODULE,
1620 .open = stmmac_sysfs_ring_open,
1621 .read = seq_read,
1622 .llseek = seq_lseek,
1623 .release = seq_release,
1624};
1625
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +00001626static int stmmac_sysfs_dma_cap_read(struct seq_file *seq, void *v)
1627{
1628 struct net_device *dev = seq->private;
1629 struct stmmac_priv *priv = netdev_priv(dev);
1630
Giuseppe CAVALLARO19e30c12011-11-16 21:58:00 +00001631 if (!priv->hw_cap_support) {
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +00001632 seq_printf(seq, "DMA HW features not supported\n");
1633 return 0;
1634 }
1635
1636 seq_printf(seq, "==============================\n");
1637 seq_printf(seq, "\tDMA HW features\n");
1638 seq_printf(seq, "==============================\n");
1639
1640 seq_printf(seq, "\t10/100 Mbps %s\n",
1641 (priv->dma_cap.mbps_10_100) ? "Y" : "N");
1642 seq_printf(seq, "\t1000 Mbps %s\n",
1643 (priv->dma_cap.mbps_1000) ? "Y" : "N");
1644 seq_printf(seq, "\tHalf duple %s\n",
1645 (priv->dma_cap.half_duplex) ? "Y" : "N");
1646 seq_printf(seq, "\tHash Filter: %s\n",
1647 (priv->dma_cap.hash_filter) ? "Y" : "N");
1648 seq_printf(seq, "\tMultiple MAC address registers: %s\n",
1649 (priv->dma_cap.multi_addr) ? "Y" : "N");
1650 seq_printf(seq, "\tPCS (TBI/SGMII/RTBI PHY interfatces): %s\n",
1651 (priv->dma_cap.pcs) ? "Y" : "N");
1652 seq_printf(seq, "\tSMA (MDIO) Interface: %s\n",
1653 (priv->dma_cap.sma_mdio) ? "Y" : "N");
1654 seq_printf(seq, "\tPMT Remote wake up: %s\n",
1655 (priv->dma_cap.pmt_remote_wake_up) ? "Y" : "N");
1656 seq_printf(seq, "\tPMT Magic Frame: %s\n",
1657 (priv->dma_cap.pmt_magic_frame) ? "Y" : "N");
1658 seq_printf(seq, "\tRMON module: %s\n",
1659 (priv->dma_cap.rmon) ? "Y" : "N");
1660 seq_printf(seq, "\tIEEE 1588-2002 Time Stamp: %s\n",
1661 (priv->dma_cap.time_stamp) ? "Y" : "N");
1662 seq_printf(seq, "\tIEEE 1588-2008 Advanced Time Stamp:%s\n",
1663 (priv->dma_cap.atime_stamp) ? "Y" : "N");
1664 seq_printf(seq, "\t802.3az - Energy-Efficient Ethernet (EEE) %s\n",
1665 (priv->dma_cap.eee) ? "Y" : "N");
1666 seq_printf(seq, "\tAV features: %s\n", (priv->dma_cap.av) ? "Y" : "N");
1667 seq_printf(seq, "\tChecksum Offload in TX: %s\n",
1668 (priv->dma_cap.tx_coe) ? "Y" : "N");
1669 seq_printf(seq, "\tIP Checksum Offload (type1) in RX: %s\n",
1670 (priv->dma_cap.rx_coe_type1) ? "Y" : "N");
1671 seq_printf(seq, "\tIP Checksum Offload (type2) in RX: %s\n",
1672 (priv->dma_cap.rx_coe_type2) ? "Y" : "N");
1673 seq_printf(seq, "\tRXFIFO > 2048bytes: %s\n",
1674 (priv->dma_cap.rxfifo_over_2048) ? "Y" : "N");
1675 seq_printf(seq, "\tNumber of Additional RX channel: %d\n",
1676 priv->dma_cap.number_rx_channel);
1677 seq_printf(seq, "\tNumber of Additional TX channel: %d\n",
1678 priv->dma_cap.number_tx_channel);
1679 seq_printf(seq, "\tEnhanced descriptors: %s\n",
1680 (priv->dma_cap.enh_desc) ? "Y" : "N");
1681
1682 return 0;
1683}
1684
1685static int stmmac_sysfs_dma_cap_open(struct inode *inode, struct file *file)
1686{
1687 return single_open(file, stmmac_sysfs_dma_cap_read, inode->i_private);
1688}
1689
1690static const struct file_operations stmmac_dma_cap_fops = {
1691 .owner = THIS_MODULE,
1692 .open = stmmac_sysfs_dma_cap_open,
1693 .read = seq_read,
1694 .llseek = seq_lseek,
1695 .release = seq_release,
1696};
1697
Giuseppe CAVALLARO7ac29052011-09-01 21:51:39 +00001698static int stmmac_init_fs(struct net_device *dev)
1699{
1700 /* Create debugfs entries */
1701 stmmac_fs_dir = debugfs_create_dir(STMMAC_RESOURCE_NAME, NULL);
1702
1703 if (!stmmac_fs_dir || IS_ERR(stmmac_fs_dir)) {
1704 pr_err("ERROR %s, debugfs create directory failed\n",
1705 STMMAC_RESOURCE_NAME);
1706
1707 return -ENOMEM;
1708 }
1709
1710 /* Entry to report DMA RX/TX rings */
1711 stmmac_rings_status = debugfs_create_file("descriptors_status",
1712 S_IRUGO, stmmac_fs_dir, dev,
1713 &stmmac_rings_status_fops);
1714
1715 if (!stmmac_rings_status || IS_ERR(stmmac_rings_status)) {
1716 pr_info("ERROR creating stmmac ring debugfs file\n");
1717 debugfs_remove(stmmac_fs_dir);
1718
1719 return -ENOMEM;
1720 }
1721
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +00001722 /* Entry to report the DMA HW features */
1723 stmmac_dma_cap = debugfs_create_file("dma_cap", S_IRUGO, stmmac_fs_dir,
1724 dev, &stmmac_dma_cap_fops);
1725
1726 if (!stmmac_dma_cap || IS_ERR(stmmac_dma_cap)) {
1727 pr_info("ERROR creating stmmac MMC debugfs file\n");
1728 debugfs_remove(stmmac_rings_status);
1729 debugfs_remove(stmmac_fs_dir);
1730
1731 return -ENOMEM;
1732 }
1733
Giuseppe CAVALLARO7ac29052011-09-01 21:51:39 +00001734 return 0;
1735}
1736
1737static void stmmac_exit_fs(void)
1738{
1739 debugfs_remove(stmmac_rings_status);
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +00001740 debugfs_remove(stmmac_dma_cap);
Giuseppe CAVALLARO7ac29052011-09-01 21:51:39 +00001741 debugfs_remove(stmmac_fs_dir);
1742}
1743#endif /* CONFIG_STMMAC_DEBUG_FS */
1744
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001745static const struct net_device_ops stmmac_netdev_ops = {
1746 .ndo_open = stmmac_open,
1747 .ndo_start_xmit = stmmac_xmit,
1748 .ndo_stop = stmmac_release,
1749 .ndo_change_mtu = stmmac_change_mtu,
Michał Mirosław5e982f32011-04-09 02:46:55 +00001750 .ndo_fix_features = stmmac_fix_features,
Jiri Pirko01789342011-08-16 06:29:00 +00001751 .ndo_set_rx_mode = stmmac_set_rx_mode,
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001752 .ndo_tx_timeout = stmmac_tx_timeout,
1753 .ndo_do_ioctl = stmmac_ioctl,
1754 .ndo_set_config = stmmac_config,
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001755#ifdef CONFIG_NET_POLL_CONTROLLER
1756 .ndo_poll_controller = stmmac_poll_controller,
1757#endif
1758 .ndo_set_mac_address = eth_mac_addr,
1759};
1760
1761/**
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00001762 * stmmac_hw_init - Init the MAC device
1763 * @priv : pointer to the private device structure.
1764 * Description: this function detects which MAC device
1765 * (GMAC/MAC10-100) has to attached, checks the HW capability
1766 * (if supported) and sets the driver's features (for example
1767 * to use the ring or chaine mode or support the normal/enh
1768 * descriptor structure).
1769 */
1770static int stmmac_hw_init(struct stmmac_priv *priv)
1771{
1772 int ret = 0;
1773 struct mac_device_info *mac;
1774
1775 /* Identify the MAC HW device */
Marc Kleine-Budde03f2eec2012-04-03 22:13:01 +00001776 if (priv->plat->has_gmac) {
1777 priv->dev->priv_flags |= IFF_UNICAST_FLT;
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00001778 mac = dwmac1000_setup(priv->ioaddr);
Marc Kleine-Budde03f2eec2012-04-03 22:13:01 +00001779 } else {
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00001780 mac = dwmac100_setup(priv->ioaddr);
Marc Kleine-Budde03f2eec2012-04-03 22:13:01 +00001781 }
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00001782 if (!mac)
1783 return -ENOMEM;
1784
1785 priv->hw = mac;
1786
1787 /* To use the chained or ring mode */
1788 priv->hw->ring = &ring_mode_ops;
1789
1790 /* Get and dump the chip ID */
1791 stmmac_get_synopsys_id(priv);
1792
1793 /* Get the HW capability (new GMAC newer than 3.50a) */
1794 priv->hw_cap_support = stmmac_get_hw_features(priv);
1795 if (priv->hw_cap_support) {
1796 pr_info(" DMA HW capability register supported");
1797
1798 /* We can override some gmac/dma configuration fields: e.g.
1799 * enh_desc, tx_coe (e.g. that are passed through the
1800 * platform) with the values from the HW capability
1801 * register (if supported).
1802 */
1803 priv->plat->enh_desc = priv->dma_cap.enh_desc;
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00001804 priv->plat->pmt = priv->dma_cap.pmt_remote_wake_up;
Deepak SIKRI38912bd2012-04-04 04:33:21 +00001805
1806 priv->plat->tx_coe = priv->dma_cap.tx_coe;
1807
1808 if (priv->dma_cap.rx_coe_type2)
1809 priv->plat->rx_coe = STMMAC_RX_COE_TYPE2;
1810 else if (priv->dma_cap.rx_coe_type1)
1811 priv->plat->rx_coe = STMMAC_RX_COE_TYPE1;
1812
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00001813 } else
1814 pr_info(" No HW DMA feature register supported");
1815
1816 /* Select the enhnaced/normal descriptor structures */
1817 stmmac_selec_desc_mode(priv);
1818
Deepak SIKRI38912bd2012-04-04 04:33:21 +00001819 /* Enable the IPC (Checksum Offload) and check if the feature has been
1820 * enabled during the core configuration. */
1821 ret = priv->hw->mac->rx_ipc(priv->ioaddr);
1822 if (!ret) {
1823 pr_warning(" RX IPC Checksum Offload not configured.\n");
1824 priv->plat->rx_coe = STMMAC_RX_COE_NONE;
1825 }
1826
1827 if (priv->plat->rx_coe)
1828 pr_info(" RX Checksum Offload Engine supported (type %d)\n",
1829 priv->plat->rx_coe);
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00001830 if (priv->plat->tx_coe)
1831 pr_info(" TX Checksum insertion supported\n");
1832
1833 if (priv->plat->pmt) {
1834 pr_info(" Wake-Up On Lan supported\n");
1835 device_set_wakeup_capable(priv->device, 1);
1836 }
1837
1838 return ret;
1839}
1840
1841/**
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001842 * stmmac_dvr_probe
1843 * @device: device pointer
1844 * Description: this is the main probe function used to
1845 * call the alloc_etherdev, allocate the priv structure.
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001846 */
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001847struct stmmac_priv *stmmac_dvr_probe(struct device *device,
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00001848 struct plat_stmmacenet_data *plat_dat,
1849 void __iomem *addr)
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001850{
1851 int ret = 0;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001852 struct net_device *ndev = NULL;
1853 struct stmmac_priv *priv;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001854
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001855 ndev = alloc_etherdev(sizeof(struct stmmac_priv));
Joe Perches41de8d42012-01-29 13:47:52 +00001856 if (!ndev)
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001857 return NULL;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001858
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001859 SET_NETDEV_DEV(ndev, device);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001860
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001861 priv = netdev_priv(ndev);
1862 priv->device = device;
1863 priv->dev = ndev;
1864
1865 ether_setup(ndev);
1866
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001867 stmmac_set_ethtool_ops(ndev);
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00001868 priv->pause = pause;
1869 priv->plat = plat_dat;
1870 priv->ioaddr = addr;
1871 priv->dev->base_addr = (unsigned long)addr;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001872
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00001873 /* Verify driver arguments */
1874 stmmac_verify_args();
1875
1876 /* Override with kernel parameters if supplied XXX CRS XXX
1877 * this needs to have multiple instances */
1878 if ((phyaddr >= 0) && (phyaddr <= 31))
1879 priv->plat->phy_addr = phyaddr;
1880
1881 /* Init MAC and get the capabilities */
1882 stmmac_hw_init(priv);
1883
1884 ndev->netdev_ops = &stmmac_netdev_ops;
1885
1886 ndev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
1887 NETIF_F_RXCSUM;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001888 ndev->features |= ndev->hw_features | NETIF_F_HIGHDMA;
1889 ndev->watchdog_timeo = msecs_to_jiffies(watchdog);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001890#ifdef STMMAC_VLAN_TAG_USED
1891 /* Both mac100 and gmac support receive VLAN tag detection */
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001892 ndev->features |= NETIF_F_HW_VLAN_RX;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001893#endif
1894 priv->msg_enable = netif_msg_init(debug, default_msg_level);
1895
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001896 if (flow_ctrl)
1897 priv->flow_ctrl = FLOW_AUTO; /* RX/TX pause on */
1898
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001899 netif_napi_add(ndev, &priv->napi, stmmac_poll, 64);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001900
Vlad Lunguf8e96162010-11-29 22:52:52 +00001901 spin_lock_init(&priv->lock);
Giuseppe CAVALLAROa9097a92011-10-18 00:01:19 +00001902 spin_lock_init(&priv->tx_lock);
Vlad Lunguf8e96162010-11-29 22:52:52 +00001903
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001904 ret = register_netdev(ndev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001905 if (ret) {
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00001906 pr_err("%s: ERROR %i registering the device\n", __func__, ret);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001907 goto error;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001908 }
1909
Giuseppe CAVALLAROba1377ff2012-04-04 04:33:25 +00001910 if (stmmac_clk_get(priv))
1911 goto error;
1912
Giuseppe CAVALLAROcd7201f2012-04-04 04:33:27 +00001913 /* If a specific clk_csr value is passed from the platform
1914 * this means that the CSR Clock Range selection cannot be
1915 * changed at run-time and it is fixed. Viceversa the driver'll try to
1916 * set the MDC clock dynamically according to the csr actual
1917 * clock input.
1918 */
1919 if (!priv->plat->clk_csr)
1920 stmmac_clk_csr_set(priv);
1921 else
1922 priv->clk_csr = priv->plat->clk_csr;
1923
Francesco Virlinzi4bfcbd72012-04-18 19:48:20 +00001924 /* MDIO bus Registration */
1925 ret = stmmac_mdio_register(ndev);
1926 if (ret < 0) {
1927 pr_debug("%s: MDIO bus (id: %d) registration failed",
1928 __func__, priv->plat->bus_id);
1929 goto error;
1930 }
1931
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001932 return priv;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001933
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001934error:
1935 netif_napi_del(&priv->napi);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001936
Dan Carpenter34a52f32010-12-20 21:34:56 +00001937 unregister_netdev(ndev);
Dan Carpenter34a52f32010-12-20 21:34:56 +00001938 free_netdev(ndev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001939
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001940 return NULL;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001941}
1942
1943/**
1944 * stmmac_dvr_remove
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001945 * @ndev: net device pointer
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001946 * Description: this function resets the TX/RX processes, disables the MAC RX/TX
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001947 * changes the link status, releases the DMA descriptor rings.
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001948 */
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001949int stmmac_dvr_remove(struct net_device *ndev)
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001950{
Giuseppe CAVALLAROaec7ff22010-01-06 23:07:18 +00001951 struct stmmac_priv *priv = netdev_priv(ndev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001952
1953 pr_info("%s:\n\tremoving driver", __func__);
1954
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +00001955 priv->hw->dma->stop_rx(priv->ioaddr);
1956 priv->hw->dma->stop_tx(priv->ioaddr);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001957
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001958 stmmac_set_mac(priv->ioaddr, false);
Francesco Virlinzi4bfcbd72012-04-18 19:48:20 +00001959 stmmac_mdio_unregister(ndev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001960 netif_carrier_off(ndev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001961 unregister_netdev(ndev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001962 free_netdev(ndev);
1963
1964 return 0;
1965}
1966
1967#ifdef CONFIG_PM
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001968int stmmac_suspend(struct net_device *ndev)
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001969{
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00001970 struct stmmac_priv *priv = netdev_priv(ndev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001971 int dis_ic = 0;
1972
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00001973 if (!ndev || !netif_running(ndev))
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001974 return 0;
1975
Francesco Virlinzi102463b2011-11-16 21:58:02 +00001976 if (priv->phydev)
1977 phy_stop(priv->phydev);
1978
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001979 spin_lock(&priv->lock);
1980
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00001981 netif_device_detach(ndev);
1982 netif_stop_queue(ndev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001983
1984#ifdef CONFIG_STMMAC_TIMER
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00001985 priv->tm->timer_stop();
1986 if (likely(priv->tm->enable))
1987 dis_ic = 1;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001988#endif
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00001989 napi_disable(&priv->napi);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001990
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00001991 /* Stop TX/RX DMA */
1992 priv->hw->dma->stop_tx(priv->ioaddr);
1993 priv->hw->dma->stop_rx(priv->ioaddr);
1994 /* Clear the Rx/Tx descriptors */
1995 priv->hw->desc->init_rx_desc(priv->dma_rx, priv->dma_rx_size,
1996 dis_ic);
1997 priv->hw->desc->init_tx_desc(priv->dma_tx, priv->dma_tx_size);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001998
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00001999 /* Enable Power down mode by programming the PMT regs */
2000 if (device_may_wakeup(priv->device))
2001 priv->hw->mac->pmt(priv->ioaddr, priv->wolopts);
Giuseppe CAVALLAROba1377ff2012-04-04 04:33:25 +00002002 else {
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002003 stmmac_set_mac(priv->ioaddr, false);
Giuseppe CAVALLAROba1377ff2012-04-04 04:33:25 +00002004 /* Disable clock in case of PWM is off */
2005 stmmac_clk_disable(priv);
2006 }
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002007 spin_unlock(&priv->lock);
2008 return 0;
2009}
2010
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002011int stmmac_resume(struct net_device *ndev)
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002012{
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002013 struct stmmac_priv *priv = netdev_priv(ndev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002014
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002015 if (!netif_running(ndev))
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002016 return 0;
2017
Giuseppe Cavallaroc4433be2010-09-06 05:02:11 +02002018 spin_lock(&priv->lock);
2019
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002020 /* Power Down bit, into the PM register, is cleared
2021 * automatically as soon as a magic packet or a Wake-up frame
2022 * is received. Anyway, it's better to manually clear
2023 * this bit because it can generate problems while resuming
2024 * from another devices (e.g. serial console). */
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002025 if (device_may_wakeup(priv->device))
Giuseppe Cavallaro543876c2010-09-24 21:27:41 -07002026 priv->hw->mac->pmt(priv->ioaddr, 0);
Giuseppe CAVALLAROba1377ff2012-04-04 04:33:25 +00002027 else
2028 /* enable the clk prevously disabled */
2029 stmmac_clk_enable(priv);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002030
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002031 netif_device_attach(ndev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002032
2033 /* Enable the MAC and DMA */
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002034 stmmac_set_mac(priv->ioaddr, true);
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +00002035 priv->hw->dma->start_tx(priv->ioaddr);
2036 priv->hw->dma->start_rx(priv->ioaddr);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002037
2038#ifdef CONFIG_STMMAC_TIMER
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002039 if (likely(priv->tm->enable))
2040 priv->tm->timer_start(tmrate);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002041#endif
2042 napi_enable(&priv->napi);
2043
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002044 netif_start_queue(ndev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002045
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002046 spin_unlock(&priv->lock);
Francesco Virlinzi102463b2011-11-16 21:58:02 +00002047
2048 if (priv->phydev)
2049 phy_start(priv->phydev);
2050
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002051 return 0;
2052}
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002053
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002054int stmmac_freeze(struct net_device *ndev)
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002055{
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002056 if (!ndev || !netif_running(ndev))
2057 return 0;
2058
2059 return stmmac_release(ndev);
2060}
2061
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002062int stmmac_restore(struct net_device *ndev)
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002063{
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002064 if (!ndev || !netif_running(ndev))
2065 return 0;
2066
2067 return stmmac_open(ndev);
2068}
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002069#endif /* CONFIG_PM */
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002070
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002071#ifndef MODULE
2072static int __init stmmac_cmdline_opt(char *str)
2073{
2074 char *opt;
2075
2076 if (!str || !*str)
2077 return -EINVAL;
2078 while ((opt = strsep(&str, ",")) != NULL) {
Giuseppe CAVALLAROf3240e22011-07-20 00:05:22 +00002079 if (!strncmp(opt, "debug:", 6)) {
2080 if (strict_strtoul(opt + 6, 0, (unsigned long *)&debug))
2081 goto err;
2082 } else if (!strncmp(opt, "phyaddr:", 8)) {
2083 if (strict_strtoul(opt + 8, 0,
2084 (unsigned long *)&phyaddr))
2085 goto err;
2086 } else if (!strncmp(opt, "dma_txsize:", 11)) {
2087 if (strict_strtoul(opt + 11, 0,
2088 (unsigned long *)&dma_txsize))
2089 goto err;
2090 } else if (!strncmp(opt, "dma_rxsize:", 11)) {
2091 if (strict_strtoul(opt + 11, 0,
2092 (unsigned long *)&dma_rxsize))
2093 goto err;
2094 } else if (!strncmp(opt, "buf_sz:", 7)) {
2095 if (strict_strtoul(opt + 7, 0,
2096 (unsigned long *)&buf_sz))
2097 goto err;
2098 } else if (!strncmp(opt, "tc:", 3)) {
2099 if (strict_strtoul(opt + 3, 0, (unsigned long *)&tc))
2100 goto err;
2101 } else if (!strncmp(opt, "watchdog:", 9)) {
2102 if (strict_strtoul(opt + 9, 0,
2103 (unsigned long *)&watchdog))
2104 goto err;
2105 } else if (!strncmp(opt, "flow_ctrl:", 10)) {
2106 if (strict_strtoul(opt + 10, 0,
2107 (unsigned long *)&flow_ctrl))
2108 goto err;
2109 } else if (!strncmp(opt, "pause:", 6)) {
2110 if (strict_strtoul(opt + 6, 0, (unsigned long *)&pause))
2111 goto err;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002112#ifdef CONFIG_STMMAC_TIMER
Giuseppe CAVALLAROf3240e22011-07-20 00:05:22 +00002113 } else if (!strncmp(opt, "tmrate:", 7)) {
2114 if (strict_strtoul(opt + 7, 0,
2115 (unsigned long *)&tmrate))
2116 goto err;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002117#endif
Giuseppe CAVALLAROf3240e22011-07-20 00:05:22 +00002118 }
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002119 }
2120 return 0;
Giuseppe CAVALLAROf3240e22011-07-20 00:05:22 +00002121
2122err:
2123 pr_err("%s: ERROR broken module parameter conversion", __func__);
2124 return -EINVAL;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002125}
2126
2127__setup("stmmaceth=", stmmac_cmdline_opt);
2128#endif
Giuseppe Cavallaro6fc0d0f2011-12-23 14:21:20 -05002129
2130MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet device driver");
2131MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
2132MODULE_LICENSE("GPL");