]>
Commit | Line | Data |
---|---|---|
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 | ||
5 | Copyright (C) 2007-2009 STMicroelectronics Ltd | |
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 | ||
31 | #include <linux/module.h> | |
32 | #include <linux/init.h> | |
33 | #include <linux/kernel.h> | |
34 | #include <linux/interrupt.h> | |
47dd7a54 GC |
35 | #include <linux/etherdevice.h> |
36 | #include <linux/platform_device.h> | |
37 | #include <linux/ip.h> | |
38 | #include <linux/tcp.h> | |
39 | #include <linux/skbuff.h> | |
40 | #include <linux/ethtool.h> | |
41 | #include <linux/if_ether.h> | |
42 | #include <linux/crc32.h> | |
43 | #include <linux/mii.h> | |
44 | #include <linux/phy.h> | |
45 | #include <linux/if_vlan.h> | |
46 | #include <linux/dma-mapping.h> | |
5a0e3ad6 | 47 | #include <linux/slab.h> |
47dd7a54 GC |
48 | #include "stmmac.h" |
49 | ||
50 | #define STMMAC_RESOURCE_NAME "stmmaceth" | |
51 | #define PHY_RESOURCE_NAME "stmmacphy" | |
52 | ||
53 | #undef STMMAC_DEBUG | |
54 | /*#define STMMAC_DEBUG*/ | |
55 | #ifdef STMMAC_DEBUG | |
56 | #define DBG(nlevel, klevel, fmt, args...) \ | |
57 | ((void)(netif_msg_##nlevel(priv) && \ | |
58 | printk(KERN_##klevel fmt, ## args))) | |
59 | #else | |
60 | #define DBG(nlevel, klevel, fmt, args...) do { } while (0) | |
61 | #endif | |
62 | ||
63 | #undef STMMAC_RX_DEBUG | |
64 | /*#define STMMAC_RX_DEBUG*/ | |
65 | #ifdef STMMAC_RX_DEBUG | |
66 | #define RX_DBG(fmt, args...) printk(fmt, ## args) | |
67 | #else | |
68 | #define RX_DBG(fmt, args...) do { } while (0) | |
69 | #endif | |
70 | ||
71 | #undef STMMAC_XMIT_DEBUG | |
72 | /*#define STMMAC_XMIT_DEBUG*/ | |
73 | #ifdef STMMAC_TX_DEBUG | |
74 | #define TX_DBG(fmt, args...) printk(fmt, ## args) | |
75 | #else | |
76 | #define TX_DBG(fmt, args...) do { } while (0) | |
77 | #endif | |
78 | ||
79 | #define STMMAC_ALIGN(x) L1_CACHE_ALIGN(x) | |
80 | #define JUMBO_LEN 9000 | |
81 | ||
82 | /* Module parameters */ | |
83 | #define TX_TIMEO 5000 /* default 5 seconds */ | |
84 | static int watchdog = TX_TIMEO; | |
85 | module_param(watchdog, int, S_IRUGO | S_IWUSR); | |
86 | MODULE_PARM_DESC(watchdog, "Transmit timeout in milliseconds"); | |
87 | ||
88 | static int debug = -1; /* -1: default, 0: no output, 16: all */ | |
89 | module_param(debug, int, S_IRUGO | S_IWUSR); | |
90 | MODULE_PARM_DESC(debug, "Message Level (0: no output, 16: all)"); | |
91 | ||
92 | static int phyaddr = -1; | |
93 | module_param(phyaddr, int, S_IRUGO); | |
94 | MODULE_PARM_DESC(phyaddr, "Physical device address"); | |
95 | ||
96 | #define DMA_TX_SIZE 256 | |
97 | static int dma_txsize = DMA_TX_SIZE; | |
98 | module_param(dma_txsize, int, S_IRUGO | S_IWUSR); | |
99 | MODULE_PARM_DESC(dma_txsize, "Number of descriptors in the TX list"); | |
100 | ||
101 | #define DMA_RX_SIZE 256 | |
102 | static int dma_rxsize = DMA_RX_SIZE; | |
103 | module_param(dma_rxsize, int, S_IRUGO | S_IWUSR); | |
104 | MODULE_PARM_DESC(dma_rxsize, "Number of descriptors in the RX list"); | |
105 | ||
106 | static int flow_ctrl = FLOW_OFF; | |
107 | module_param(flow_ctrl, int, S_IRUGO | S_IWUSR); | |
108 | MODULE_PARM_DESC(flow_ctrl, "Flow control ability [on/off]"); | |
109 | ||
110 | static int pause = PAUSE_TIME; | |
111 | module_param(pause, int, S_IRUGO | S_IWUSR); | |
112 | MODULE_PARM_DESC(pause, "Flow Control Pause Time"); | |
113 | ||
114 | #define TC_DEFAULT 64 | |
115 | static int tc = TC_DEFAULT; | |
116 | module_param(tc, int, S_IRUGO | S_IWUSR); | |
117 | MODULE_PARM_DESC(tc, "DMA threshold control value"); | |
118 | ||
119 | #define RX_NO_COALESCE 1 /* Always interrupt on completion */ | |
120 | #define TX_NO_COALESCE -1 /* No moderation by default */ | |
121 | ||
122 | /* Pay attention to tune this parameter; take care of both | |
123 | * hardware capability and network stabitily/performance impact. | |
124 | * Many tests showed that ~4ms latency seems to be good enough. */ | |
125 | #ifdef CONFIG_STMMAC_TIMER | |
126 | #define DEFAULT_PERIODIC_RATE 256 | |
127 | static int tmrate = DEFAULT_PERIODIC_RATE; | |
128 | module_param(tmrate, int, S_IRUGO | S_IWUSR); | |
129 | MODULE_PARM_DESC(tmrate, "External timer freq. (default: 256Hz)"); | |
130 | #endif | |
131 | ||
132 | #define DMA_BUFFER_SIZE BUF_SIZE_2KiB | |
133 | static int buf_sz = DMA_BUFFER_SIZE; | |
134 | module_param(buf_sz, int, S_IRUGO | S_IWUSR); | |
135 | MODULE_PARM_DESC(buf_sz, "DMA buffer size"); | |
136 | ||
47dd7a54 GC |
137 | static const u32 default_msg_level = (NETIF_MSG_DRV | NETIF_MSG_PROBE | |
138 | NETIF_MSG_LINK | NETIF_MSG_IFUP | | |
139 | NETIF_MSG_IFDOWN | NETIF_MSG_TIMER); | |
140 | ||
141 | static irqreturn_t stmmac_interrupt(int irq, void *dev_id); | |
142 | static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev); | |
143 | ||
144 | /** | |
145 | * stmmac_verify_args - verify the driver parameters. | |
146 | * Description: it verifies if some wrong parameter is passed to the driver. | |
147 | * Note that wrong parameters are replaced with the default values. | |
148 | */ | |
149 | static void stmmac_verify_args(void) | |
150 | { | |
151 | if (unlikely(watchdog < 0)) | |
152 | watchdog = TX_TIMEO; | |
153 | if (unlikely(dma_rxsize < 0)) | |
154 | dma_rxsize = DMA_RX_SIZE; | |
155 | if (unlikely(dma_txsize < 0)) | |
156 | dma_txsize = DMA_TX_SIZE; | |
157 | if (unlikely((buf_sz < DMA_BUFFER_SIZE) || (buf_sz > BUF_SIZE_16KiB))) | |
158 | buf_sz = DMA_BUFFER_SIZE; | |
159 | if (unlikely(flow_ctrl > 1)) | |
160 | flow_ctrl = FLOW_AUTO; | |
161 | else if (likely(flow_ctrl < 0)) | |
162 | flow_ctrl = FLOW_OFF; | |
163 | if (unlikely((pause < 0) || (pause > 0xffff))) | |
164 | pause = PAUSE_TIME; | |
47dd7a54 GC |
165 | } |
166 | ||
167 | #if defined(STMMAC_XMIT_DEBUG) || defined(STMMAC_RX_DEBUG) | |
168 | static void print_pkt(unsigned char *buf, int len) | |
169 | { | |
170 | int j; | |
171 | pr_info("len = %d byte, buf addr: 0x%p", len, buf); | |
172 | for (j = 0; j < len; j++) { | |
173 | if ((j % 16) == 0) | |
174 | pr_info("\n %03x:", j); | |
175 | pr_info(" %02x", buf[j]); | |
176 | } | |
177 | pr_info("\n"); | |
47dd7a54 GC |
178 | } |
179 | #endif | |
180 | ||
181 | /* minimum number of free TX descriptors required to wake up TX process */ | |
182 | #define STMMAC_TX_THRESH(x) (x->dma_tx_size/4) | |
183 | ||
184 | static inline u32 stmmac_tx_avail(struct stmmac_priv *priv) | |
185 | { | |
186 | return priv->dirty_tx + priv->dma_tx_size - priv->cur_tx - 1; | |
187 | } | |
188 | ||
189 | /** | |
190 | * stmmac_adjust_link | |
191 | * @dev: net device structure | |
192 | * Description: it adjusts the link parameters. | |
193 | */ | |
194 | static void stmmac_adjust_link(struct net_device *dev) | |
195 | { | |
196 | struct stmmac_priv *priv = netdev_priv(dev); | |
197 | struct phy_device *phydev = priv->phydev; | |
47dd7a54 GC |
198 | unsigned long flags; |
199 | int new_state = 0; | |
200 | unsigned int fc = priv->flow_ctrl, pause_time = priv->pause; | |
201 | ||
202 | if (phydev == NULL) | |
203 | return; | |
204 | ||
205 | DBG(probe, DEBUG, "stmmac_adjust_link: called. address %d link %d\n", | |
206 | phydev->addr, phydev->link); | |
207 | ||
208 | spin_lock_irqsave(&priv->lock, flags); | |
209 | if (phydev->link) { | |
ad01b7d4 | 210 | u32 ctrl = readl(priv->ioaddr + MAC_CTRL_REG); |
47dd7a54 GC |
211 | |
212 | /* Now we make sure that we can be in full duplex mode. | |
213 | * If not, we operate in half-duplex mode. */ | |
214 | if (phydev->duplex != priv->oldduplex) { | |
215 | new_state = 1; | |
216 | if (!(phydev->duplex)) | |
db98a0b0 | 217 | ctrl &= ~priv->hw->link.duplex; |
47dd7a54 | 218 | else |
db98a0b0 | 219 | ctrl |= priv->hw->link.duplex; |
47dd7a54 GC |
220 | priv->oldduplex = phydev->duplex; |
221 | } | |
222 | /* Flow Control operation */ | |
223 | if (phydev->pause) | |
ad01b7d4 | 224 | priv->hw->mac->flow_ctrl(priv->ioaddr, phydev->duplex, |
db98a0b0 | 225 | fc, pause_time); |
47dd7a54 GC |
226 | |
227 | if (phydev->speed != priv->speed) { | |
228 | new_state = 1; | |
229 | switch (phydev->speed) { | |
230 | case 1000: | |
231 | if (likely(priv->is_gmac)) | |
db98a0b0 | 232 | ctrl &= ~priv->hw->link.port; |
219dd113 PM |
233 | if (likely(priv->fix_mac_speed)) |
234 | priv->fix_mac_speed(priv->bsp_priv, | |
235 | phydev->speed); | |
47dd7a54 GC |
236 | break; |
237 | case 100: | |
238 | case 10: | |
239 | if (priv->is_gmac) { | |
db98a0b0 | 240 | ctrl |= priv->hw->link.port; |
47dd7a54 | 241 | if (phydev->speed == SPEED_100) { |
db98a0b0 | 242 | ctrl |= priv->hw->link.speed; |
47dd7a54 | 243 | } else { |
db98a0b0 | 244 | ctrl &= ~(priv->hw->link.speed); |
47dd7a54 GC |
245 | } |
246 | } else { | |
db98a0b0 | 247 | ctrl &= ~priv->hw->link.port; |
47dd7a54 | 248 | } |
65818fa7 GC |
249 | if (likely(priv->fix_mac_speed)) |
250 | priv->fix_mac_speed(priv->bsp_priv, | |
251 | phydev->speed); | |
47dd7a54 GC |
252 | break; |
253 | default: | |
254 | if (netif_msg_link(priv)) | |
255 | pr_warning("%s: Speed (%d) is not 10" | |
256 | " or 100!\n", dev->name, phydev->speed); | |
257 | break; | |
258 | } | |
259 | ||
260 | priv->speed = phydev->speed; | |
261 | } | |
262 | ||
ad01b7d4 | 263 | writel(ctrl, priv->ioaddr + MAC_CTRL_REG); |
47dd7a54 GC |
264 | |
265 | if (!priv->oldlink) { | |
266 | new_state = 1; | |
267 | priv->oldlink = 1; | |
268 | } | |
269 | } else if (priv->oldlink) { | |
270 | new_state = 1; | |
271 | priv->oldlink = 0; | |
272 | priv->speed = 0; | |
273 | priv->oldduplex = -1; | |
274 | } | |
275 | ||
276 | if (new_state && netif_msg_link(priv)) | |
277 | phy_print_status(phydev); | |
278 | ||
279 | spin_unlock_irqrestore(&priv->lock, flags); | |
280 | ||
281 | DBG(probe, DEBUG, "stmmac_adjust_link: exiting\n"); | |
282 | } | |
283 | ||
284 | /** | |
285 | * stmmac_init_phy - PHY initialization | |
286 | * @dev: net device structure | |
287 | * Description: it initializes the driver's PHY state, and attaches the PHY | |
288 | * to the mac driver. | |
289 | * Return value: | |
290 | * 0 on success | |
291 | */ | |
292 | static int stmmac_init_phy(struct net_device *dev) | |
293 | { | |
294 | struct stmmac_priv *priv = netdev_priv(dev); | |
295 | struct phy_device *phydev; | |
109cdd66 GC |
296 | char phy_id[MII_BUS_ID_SIZE + 3]; |
297 | char bus_id[MII_BUS_ID_SIZE]; | |
47dd7a54 GC |
298 | |
299 | priv->oldlink = 0; | |
300 | priv->speed = 0; | |
301 | priv->oldduplex = -1; | |
302 | ||
303 | if (priv->phy_addr == -1) { | |
304 | /* We don't have a PHY, so do nothing */ | |
305 | return 0; | |
306 | } | |
307 | ||
308 | snprintf(bus_id, MII_BUS_ID_SIZE, "%x", priv->bus_id); | |
109cdd66 GC |
309 | snprintf(phy_id, MII_BUS_ID_SIZE + 3, PHY_ID_FMT, bus_id, |
310 | priv->phy_addr); | |
47dd7a54 GC |
311 | pr_debug("stmmac_init_phy: trying to attach to %s\n", phy_id); |
312 | ||
313 | phydev = phy_connect(dev, phy_id, &stmmac_adjust_link, 0, | |
314 | priv->phy_interface); | |
315 | ||
316 | if (IS_ERR(phydev)) { | |
317 | pr_err("%s: Could not attach to PHY\n", dev->name); | |
318 | return PTR_ERR(phydev); | |
319 | } | |
320 | ||
321 | /* | |
322 | * Broken HW is sometimes missing the pull-up resistor on the | |
323 | * MDIO line, which results in reads to non-existent devices returning | |
324 | * 0 rather than 0xffff. Catch this here and treat 0 as a non-existent | |
325 | * device as well. | |
326 | * Note: phydev->phy_id is the result of reading the UID PHY registers. | |
327 | */ | |
328 | if (phydev->phy_id == 0) { | |
329 | phy_disconnect(phydev); | |
330 | return -ENODEV; | |
331 | } | |
332 | pr_debug("stmmac_init_phy: %s: attached to PHY (UID 0x%x)" | |
333 | " Link = %d\n", dev->name, phydev->phy_id, phydev->link); | |
334 | ||
335 | priv->phydev = phydev; | |
336 | ||
337 | return 0; | |
338 | } | |
339 | ||
ad01b7d4 | 340 | static inline void stmmac_mac_enable_rx(void __iomem *ioaddr) |
47dd7a54 GC |
341 | { |
342 | u32 value = readl(ioaddr + MAC_CTRL_REG); | |
343 | value |= MAC_RNABLE_RX; | |
344 | /* Set the RE (receive enable bit into the MAC CTRL register). */ | |
345 | writel(value, ioaddr + MAC_CTRL_REG); | |
346 | } | |
347 | ||
ad01b7d4 | 348 | static inline void stmmac_mac_enable_tx(void __iomem *ioaddr) |
47dd7a54 GC |
349 | { |
350 | u32 value = readl(ioaddr + MAC_CTRL_REG); | |
351 | value |= MAC_ENABLE_TX; | |
352 | /* Set the TE (transmit enable bit into the MAC CTRL register). */ | |
353 | writel(value, ioaddr + MAC_CTRL_REG); | |
354 | } | |
355 | ||
ad01b7d4 | 356 | static inline void stmmac_mac_disable_rx(void __iomem *ioaddr) |
47dd7a54 GC |
357 | { |
358 | u32 value = readl(ioaddr + MAC_CTRL_REG); | |
359 | value &= ~MAC_RNABLE_RX; | |
360 | writel(value, ioaddr + MAC_CTRL_REG); | |
361 | } | |
362 | ||
ad01b7d4 | 363 | static inline void stmmac_mac_disable_tx(void __iomem *ioaddr) |
47dd7a54 GC |
364 | { |
365 | u32 value = readl(ioaddr + MAC_CTRL_REG); | |
366 | value &= ~MAC_ENABLE_TX; | |
367 | writel(value, ioaddr + MAC_CTRL_REG); | |
368 | } | |
369 | ||
370 | /** | |
371 | * display_ring | |
372 | * @p: pointer to the ring. | |
373 | * @size: size of the ring. | |
374 | * Description: display all the descriptors within the ring. | |
375 | */ | |
376 | static void display_ring(struct dma_desc *p, int size) | |
377 | { | |
378 | struct tmp_s { | |
379 | u64 a; | |
380 | unsigned int b; | |
381 | unsigned int c; | |
382 | }; | |
383 | int i; | |
384 | for (i = 0; i < size; i++) { | |
385 | struct tmp_s *x = (struct tmp_s *)(p + i); | |
386 | pr_info("\t%d [0x%x]: DES0=0x%x DES1=0x%x BUF1=0x%x BUF2=0x%x", | |
387 | i, (unsigned int)virt_to_phys(&p[i]), | |
388 | (unsigned int)(x->a), (unsigned int)((x->a) >> 32), | |
389 | x->b, x->c); | |
390 | pr_info("\n"); | |
391 | } | |
392 | } | |
393 | ||
394 | /** | |
395 | * init_dma_desc_rings - init the RX/TX descriptor rings | |
396 | * @dev: net device structure | |
397 | * Description: this function initializes the DMA RX/TX descriptors | |
398 | * and allocates the socket buffers. | |
399 | */ | |
400 | static void init_dma_desc_rings(struct net_device *dev) | |
401 | { | |
402 | int i; | |
403 | struct stmmac_priv *priv = netdev_priv(dev); | |
404 | struct sk_buff *skb; | |
405 | unsigned int txsize = priv->dma_tx_size; | |
406 | unsigned int rxsize = priv->dma_rx_size; | |
407 | unsigned int bfsize = priv->dma_buf_sz; | |
73cfe264 | 408 | int buff2_needed = 0, dis_ic = 0; |
47dd7a54 | 409 | |
47dd7a54 GC |
410 | /* Set the Buffer size according to the MTU; |
411 | * indeed, in case of jumbo we need to bump-up the buffer sizes. | |
412 | */ | |
413 | if (unlikely(dev->mtu >= BUF_SIZE_8KiB)) | |
414 | bfsize = BUF_SIZE_16KiB; | |
415 | else if (unlikely(dev->mtu >= BUF_SIZE_4KiB)) | |
416 | bfsize = BUF_SIZE_8KiB; | |
417 | else if (unlikely(dev->mtu >= BUF_SIZE_2KiB)) | |
418 | bfsize = BUF_SIZE_4KiB; | |
419 | else if (unlikely(dev->mtu >= DMA_BUFFER_SIZE)) | |
420 | bfsize = BUF_SIZE_2KiB; | |
421 | else | |
422 | bfsize = DMA_BUFFER_SIZE; | |
423 | ||
73cfe264 GC |
424 | #ifdef CONFIG_STMMAC_TIMER |
425 | /* Disable interrupts on completion for the reception if timer is on */ | |
426 | if (likely(priv->tm->enable)) | |
427 | dis_ic = 1; | |
428 | #endif | |
47dd7a54 GC |
429 | /* If the MTU exceeds 8k so use the second buffer in the chain */ |
430 | if (bfsize >= BUF_SIZE_8KiB) | |
431 | buff2_needed = 1; | |
432 | ||
433 | DBG(probe, INFO, "stmmac: txsize %d, rxsize %d, bfsize %d\n", | |
434 | txsize, rxsize, bfsize); | |
435 | ||
436 | priv->rx_skbuff_dma = kmalloc(rxsize * sizeof(dma_addr_t), GFP_KERNEL); | |
437 | priv->rx_skbuff = | |
438 | kmalloc(sizeof(struct sk_buff *) * rxsize, GFP_KERNEL); | |
439 | priv->dma_rx = | |
440 | (struct dma_desc *)dma_alloc_coherent(priv->device, | |
441 | rxsize * | |
442 | sizeof(struct dma_desc), | |
443 | &priv->dma_rx_phy, | |
444 | GFP_KERNEL); | |
445 | priv->tx_skbuff = kmalloc(sizeof(struct sk_buff *) * txsize, | |
446 | GFP_KERNEL); | |
447 | priv->dma_tx = | |
448 | (struct dma_desc *)dma_alloc_coherent(priv->device, | |
449 | txsize * | |
450 | sizeof(struct dma_desc), | |
451 | &priv->dma_tx_phy, | |
452 | GFP_KERNEL); | |
453 | ||
454 | if ((priv->dma_rx == NULL) || (priv->dma_tx == NULL)) { | |
455 | pr_err("%s:ERROR allocating the DMA Tx/Rx desc\n", __func__); | |
456 | return; | |
457 | } | |
458 | ||
459 | DBG(probe, INFO, "stmmac (%s) DMA desc rings: virt addr (Rx %p, " | |
460 | "Tx %p)\n\tDMA phy addr (Rx 0x%08x, Tx 0x%08x)\n", | |
461 | dev->name, priv->dma_rx, priv->dma_tx, | |
462 | (unsigned int)priv->dma_rx_phy, (unsigned int)priv->dma_tx_phy); | |
463 | ||
464 | /* RX INITIALIZATION */ | |
465 | DBG(probe, INFO, "stmmac: SKB addresses:\n" | |
466 | "skb\t\tskb data\tdma data\n"); | |
467 | ||
468 | for (i = 0; i < rxsize; i++) { | |
469 | struct dma_desc *p = priv->dma_rx + i; | |
470 | ||
471 | skb = netdev_alloc_skb_ip_align(dev, bfsize); | |
472 | if (unlikely(skb == NULL)) { | |
473 | pr_err("%s: Rx init fails; skb is NULL\n", __func__); | |
474 | break; | |
475 | } | |
476 | priv->rx_skbuff[i] = skb; | |
477 | priv->rx_skbuff_dma[i] = dma_map_single(priv->device, skb->data, | |
478 | bfsize, DMA_FROM_DEVICE); | |
479 | ||
480 | p->des2 = priv->rx_skbuff_dma[i]; | |
481 | if (unlikely(buff2_needed)) | |
482 | p->des3 = p->des2 + BUF_SIZE_8KiB; | |
483 | DBG(probe, INFO, "[%p]\t[%p]\t[%x]\n", priv->rx_skbuff[i], | |
484 | priv->rx_skbuff[i]->data, priv->rx_skbuff_dma[i]); | |
485 | } | |
486 | priv->cur_rx = 0; | |
487 | priv->dirty_rx = (unsigned int)(i - rxsize); | |
488 | priv->dma_buf_sz = bfsize; | |
489 | buf_sz = bfsize; | |
490 | ||
491 | /* TX INITIALIZATION */ | |
492 | for (i = 0; i < txsize; i++) { | |
493 | priv->tx_skbuff[i] = NULL; | |
494 | priv->dma_tx[i].des2 = 0; | |
495 | } | |
496 | priv->dirty_tx = 0; | |
497 | priv->cur_tx = 0; | |
498 | ||
499 | /* Clear the Rx/Tx descriptors */ | |
db98a0b0 GC |
500 | priv->hw->desc->init_rx_desc(priv->dma_rx, rxsize, dis_ic); |
501 | priv->hw->desc->init_tx_desc(priv->dma_tx, txsize); | |
47dd7a54 GC |
502 | |
503 | if (netif_msg_hw(priv)) { | |
504 | pr_info("RX descriptor ring:\n"); | |
505 | display_ring(priv->dma_rx, rxsize); | |
506 | pr_info("TX descriptor ring:\n"); | |
507 | display_ring(priv->dma_tx, txsize); | |
508 | } | |
47dd7a54 GC |
509 | } |
510 | ||
511 | static void dma_free_rx_skbufs(struct stmmac_priv *priv) | |
512 | { | |
513 | int i; | |
514 | ||
515 | for (i = 0; i < priv->dma_rx_size; i++) { | |
516 | if (priv->rx_skbuff[i]) { | |
517 | dma_unmap_single(priv->device, priv->rx_skbuff_dma[i], | |
518 | priv->dma_buf_sz, DMA_FROM_DEVICE); | |
519 | dev_kfree_skb_any(priv->rx_skbuff[i]); | |
520 | } | |
521 | priv->rx_skbuff[i] = NULL; | |
522 | } | |
47dd7a54 GC |
523 | } |
524 | ||
525 | static void dma_free_tx_skbufs(struct stmmac_priv *priv) | |
526 | { | |
527 | int i; | |
528 | ||
529 | for (i = 0; i < priv->dma_tx_size; i++) { | |
530 | if (priv->tx_skbuff[i] != NULL) { | |
531 | struct dma_desc *p = priv->dma_tx + i; | |
532 | if (p->des2) | |
533 | dma_unmap_single(priv->device, p->des2, | |
db98a0b0 GC |
534 | priv->hw->desc->get_tx_len(p), |
535 | DMA_TO_DEVICE); | |
47dd7a54 GC |
536 | dev_kfree_skb_any(priv->tx_skbuff[i]); |
537 | priv->tx_skbuff[i] = NULL; | |
538 | } | |
539 | } | |
47dd7a54 GC |
540 | } |
541 | ||
542 | static void free_dma_desc_resources(struct stmmac_priv *priv) | |
543 | { | |
544 | /* Release the DMA TX/RX socket buffers */ | |
545 | dma_free_rx_skbufs(priv); | |
546 | dma_free_tx_skbufs(priv); | |
547 | ||
548 | /* Free the region of consistent memory previously allocated for | |
549 | * the DMA */ | |
550 | dma_free_coherent(priv->device, | |
551 | priv->dma_tx_size * sizeof(struct dma_desc), | |
552 | priv->dma_tx, priv->dma_tx_phy); | |
553 | dma_free_coherent(priv->device, | |
554 | priv->dma_rx_size * sizeof(struct dma_desc), | |
555 | priv->dma_rx, priv->dma_rx_phy); | |
556 | kfree(priv->rx_skbuff_dma); | |
557 | kfree(priv->rx_skbuff); | |
558 | kfree(priv->tx_skbuff); | |
47dd7a54 GC |
559 | } |
560 | ||
47dd7a54 GC |
561 | /** |
562 | * stmmac_dma_operation_mode - HW DMA operation mode | |
563 | * @priv : pointer to the private device structure. | |
564 | * Description: it sets the DMA operation mode: tx/rx DMA thresholds | |
ebbb293f | 565 | * or Store-And-Forward capability. |
47dd7a54 GC |
566 | */ |
567 | static void stmmac_dma_operation_mode(struct stmmac_priv *priv) | |
568 | { | |
ebbb293f GC |
569 | if (likely((priv->tx_coe) && (!priv->no_csum_insertion))) { |
570 | /* In case of GMAC, SF mode has to be enabled | |
571 | * to perform the TX COE. This depends on: | |
572 | * 1) TX COE if actually supported | |
573 | * 2) There is no bugged Jumbo frame support | |
574 | * that needs to not insert csum in the TDES. | |
575 | */ | |
576 | priv->hw->dma->dma_mode(priv->ioaddr, | |
577 | SF_DMA_MODE, SF_DMA_MODE); | |
578 | tc = SF_DMA_MODE; | |
579 | } else | |
580 | priv->hw->dma->dma_mode(priv->ioaddr, tc, SF_DMA_MODE); | |
47dd7a54 GC |
581 | } |
582 | ||
47dd7a54 GC |
583 | /** |
584 | * stmmac_tx: | |
585 | * @priv: private driver structure | |
586 | * Description: it reclaims resources after transmission completes. | |
587 | */ | |
588 | static void stmmac_tx(struct stmmac_priv *priv) | |
589 | { | |
590 | unsigned int txsize = priv->dma_tx_size; | |
47dd7a54 GC |
591 | |
592 | while (priv->dirty_tx != priv->cur_tx) { | |
593 | int last; | |
594 | unsigned int entry = priv->dirty_tx % txsize; | |
595 | struct sk_buff *skb = priv->tx_skbuff[entry]; | |
596 | struct dma_desc *p = priv->dma_tx + entry; | |
597 | ||
598 | /* Check if the descriptor is owned by the DMA. */ | |
db98a0b0 | 599 | if (priv->hw->desc->get_tx_owner(p)) |
47dd7a54 GC |
600 | break; |
601 | ||
602 | /* Verify tx error by looking at the last segment */ | |
db98a0b0 | 603 | last = priv->hw->desc->get_tx_ls(p); |
47dd7a54 GC |
604 | if (likely(last)) { |
605 | int tx_error = | |
db98a0b0 GC |
606 | priv->hw->desc->tx_status(&priv->dev->stats, |
607 | &priv->xstats, p, | |
ad01b7d4 | 608 | priv->ioaddr); |
47dd7a54 GC |
609 | if (likely(tx_error == 0)) { |
610 | priv->dev->stats.tx_packets++; | |
611 | priv->xstats.tx_pkt_n++; | |
612 | } else | |
613 | priv->dev->stats.tx_errors++; | |
614 | } | |
615 | TX_DBG("%s: curr %d, dirty %d\n", __func__, | |
616 | priv->cur_tx, priv->dirty_tx); | |
617 | ||
618 | if (likely(p->des2)) | |
619 | dma_unmap_single(priv->device, p->des2, | |
db98a0b0 | 620 | priv->hw->desc->get_tx_len(p), |
47dd7a54 GC |
621 | DMA_TO_DEVICE); |
622 | if (unlikely(p->des3)) | |
623 | p->des3 = 0; | |
624 | ||
625 | if (likely(skb != NULL)) { | |
626 | /* | |
627 | * If there's room in the queue (limit it to size) | |
628 | * we add this skb back into the pool, | |
629 | * if it's the right size. | |
630 | */ | |
631 | if ((skb_queue_len(&priv->rx_recycle) < | |
632 | priv->dma_rx_size) && | |
633 | skb_recycle_check(skb, priv->dma_buf_sz)) | |
634 | __skb_queue_head(&priv->rx_recycle, skb); | |
635 | else | |
636 | dev_kfree_skb(skb); | |
637 | ||
638 | priv->tx_skbuff[entry] = NULL; | |
639 | } | |
640 | ||
db98a0b0 | 641 | priv->hw->desc->release_tx_desc(p); |
47dd7a54 GC |
642 | |
643 | entry = (++priv->dirty_tx) % txsize; | |
644 | } | |
645 | if (unlikely(netif_queue_stopped(priv->dev) && | |
646 | stmmac_tx_avail(priv) > STMMAC_TX_THRESH(priv))) { | |
647 | netif_tx_lock(priv->dev); | |
648 | if (netif_queue_stopped(priv->dev) && | |
649 | stmmac_tx_avail(priv) > STMMAC_TX_THRESH(priv)) { | |
650 | TX_DBG("%s: restart transmit\n", __func__); | |
651 | netif_wake_queue(priv->dev); | |
652 | } | |
653 | netif_tx_unlock(priv->dev); | |
654 | } | |
47dd7a54 GC |
655 | } |
656 | ||
657 | static inline void stmmac_enable_irq(struct stmmac_priv *priv) | |
658 | { | |
73cfe264 GC |
659 | #ifdef CONFIG_STMMAC_TIMER |
660 | if (likely(priv->tm->enable)) | |
661 | priv->tm->timer_start(tmrate); | |
662 | else | |
47dd7a54 | 663 | #endif |
ad01b7d4 | 664 | priv->hw->dma->enable_dma_irq(priv->ioaddr); |
47dd7a54 GC |
665 | } |
666 | ||
667 | static inline void stmmac_disable_irq(struct stmmac_priv *priv) | |
668 | { | |
73cfe264 GC |
669 | #ifdef CONFIG_STMMAC_TIMER |
670 | if (likely(priv->tm->enable)) | |
671 | priv->tm->timer_stop(); | |
672 | else | |
47dd7a54 | 673 | #endif |
ad01b7d4 | 674 | priv->hw->dma->disable_dma_irq(priv->ioaddr); |
47dd7a54 GC |
675 | } |
676 | ||
677 | static int stmmac_has_work(struct stmmac_priv *priv) | |
678 | { | |
679 | unsigned int has_work = 0; | |
680 | int rxret, tx_work = 0; | |
681 | ||
db98a0b0 | 682 | rxret = priv->hw->desc->get_rx_owner(priv->dma_rx + |
47dd7a54 GC |
683 | (priv->cur_rx % priv->dma_rx_size)); |
684 | ||
685 | if (priv->dirty_tx != priv->cur_tx) | |
686 | tx_work = 1; | |
687 | ||
688 | if (likely(!rxret || tx_work)) | |
689 | has_work = 1; | |
690 | ||
691 | return has_work; | |
692 | } | |
693 | ||
694 | static inline void _stmmac_schedule(struct stmmac_priv *priv) | |
695 | { | |
696 | if (likely(stmmac_has_work(priv))) { | |
697 | stmmac_disable_irq(priv); | |
698 | napi_schedule(&priv->napi); | |
699 | } | |
700 | } | |
701 | ||
702 | #ifdef CONFIG_STMMAC_TIMER | |
703 | void stmmac_schedule(struct net_device *dev) | |
704 | { | |
705 | struct stmmac_priv *priv = netdev_priv(dev); | |
706 | ||
707 | priv->xstats.sched_timer_n++; | |
708 | ||
709 | _stmmac_schedule(priv); | |
47dd7a54 GC |
710 | } |
711 | ||
712 | static void stmmac_no_timer_started(unsigned int x) | |
713 | {; | |
714 | }; | |
715 | ||
716 | static void stmmac_no_timer_stopped(void) | |
717 | {; | |
718 | }; | |
719 | #endif | |
720 | ||
721 | /** | |
722 | * stmmac_tx_err: | |
723 | * @priv: pointer to the private device structure | |
724 | * Description: it cleans the descriptors and restarts the transmission | |
725 | * in case of errors. | |
726 | */ | |
727 | static void stmmac_tx_err(struct stmmac_priv *priv) | |
728 | { | |
ad01b7d4 | 729 | |
47dd7a54 GC |
730 | netif_stop_queue(priv->dev); |
731 | ||
ad01b7d4 | 732 | priv->hw->dma->stop_tx(priv->ioaddr); |
47dd7a54 | 733 | dma_free_tx_skbufs(priv); |
db98a0b0 | 734 | priv->hw->desc->init_tx_desc(priv->dma_tx, priv->dma_tx_size); |
47dd7a54 GC |
735 | priv->dirty_tx = 0; |
736 | priv->cur_tx = 0; | |
ad01b7d4 | 737 | priv->hw->dma->start_tx(priv->ioaddr); |
47dd7a54 GC |
738 | |
739 | priv->dev->stats.tx_errors++; | |
740 | netif_wake_queue(priv->dev); | |
47dd7a54 GC |
741 | } |
742 | ||
47dd7a54 | 743 | |
aec7ff27 GC |
744 | static void stmmac_dma_interrupt(struct stmmac_priv *priv) |
745 | { | |
aec7ff27 GC |
746 | int status; |
747 | ||
ad01b7d4 | 748 | status = priv->hw->dma->dma_interrupt(priv->ioaddr, &priv->xstats); |
aec7ff27 GC |
749 | if (likely(status == handle_tx_rx)) |
750 | _stmmac_schedule(priv); | |
751 | ||
752 | else if (unlikely(status == tx_hard_error_bump_tc)) { | |
753 | /* Try to bump up the dma threshold on this failure */ | |
754 | if (unlikely(tc != SF_DMA_MODE) && (tc <= 256)) { | |
755 | tc += 64; | |
ad01b7d4 | 756 | priv->hw->dma->dma_mode(priv->ioaddr, tc, SF_DMA_MODE); |
aec7ff27 | 757 | priv->xstats.threshold = tc; |
47dd7a54 | 758 | } |
aec7ff27 GC |
759 | stmmac_tx_err(priv); |
760 | } else if (unlikely(status == tx_hard_error)) | |
761 | stmmac_tx_err(priv); | |
47dd7a54 GC |
762 | } |
763 | ||
764 | /** | |
765 | * stmmac_open - open entry point of the driver | |
766 | * @dev : pointer to the device structure. | |
767 | * Description: | |
768 | * This function is the open entry point of the driver. | |
769 | * Return value: | |
770 | * 0 on success and an appropriate (-)ve integer as defined in errno.h | |
771 | * file on failure. | |
772 | */ | |
773 | static int stmmac_open(struct net_device *dev) | |
774 | { | |
775 | struct stmmac_priv *priv = netdev_priv(dev); | |
47dd7a54 GC |
776 | int ret; |
777 | ||
778 | /* Check that the MAC address is valid. If its not, refuse | |
779 | * to bring the device up. The user must specify an | |
780 | * address using the following linux command: | |
781 | * ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx */ | |
782 | if (!is_valid_ether_addr(dev->dev_addr)) { | |
783 | random_ether_addr(dev->dev_addr); | |
784 | pr_warning("%s: generated random MAC address %pM\n", dev->name, | |
785 | dev->dev_addr); | |
786 | } | |
787 | ||
788 | stmmac_verify_args(); | |
789 | ||
790 | ret = stmmac_init_phy(dev); | |
791 | if (unlikely(ret)) { | |
792 | pr_err("%s: Cannot attach to PHY (error: %d)\n", __func__, ret); | |
793 | return ret; | |
794 | } | |
795 | ||
796 | /* Request the IRQ lines */ | |
a0607fd3 | 797 | ret = request_irq(dev->irq, stmmac_interrupt, |
47dd7a54 GC |
798 | IRQF_SHARED, dev->name, dev); |
799 | if (unlikely(ret < 0)) { | |
800 | pr_err("%s: ERROR: allocating the IRQ %d (error: %d)\n", | |
801 | __func__, dev->irq, ret); | |
802 | return ret; | |
803 | } | |
804 | ||
805 | #ifdef CONFIG_STMMAC_TIMER | |
73cfe264 | 806 | priv->tm = kzalloc(sizeof(struct stmmac_timer *), GFP_KERNEL); |
47dd7a54 | 807 | if (unlikely(priv->tm == NULL)) { |
2381a55c | 808 | pr_err("%s: ERROR: timer memory alloc failed\n", __func__); |
47dd7a54 GC |
809 | return -ENOMEM; |
810 | } | |
811 | priv->tm->freq = tmrate; | |
812 | ||
73cfe264 GC |
813 | /* Test if the external timer can be actually used. |
814 | * In case of failure continue without timer. */ | |
47dd7a54 | 815 | if (unlikely((stmmac_open_ext_timer(dev, priv->tm)) < 0)) { |
73cfe264 | 816 | pr_warning("stmmaceth: cannot attach the external timer.\n"); |
47dd7a54 GC |
817 | priv->tm->freq = 0; |
818 | priv->tm->timer_start = stmmac_no_timer_started; | |
819 | priv->tm->timer_stop = stmmac_no_timer_stopped; | |
73cfe264 GC |
820 | } else |
821 | priv->tm->enable = 1; | |
47dd7a54 GC |
822 | #endif |
823 | ||
824 | /* Create and initialize the TX/RX descriptors chains. */ | |
825 | priv->dma_tx_size = STMMAC_ALIGN(dma_txsize); | |
826 | priv->dma_rx_size = STMMAC_ALIGN(dma_rxsize); | |
827 | priv->dma_buf_sz = STMMAC_ALIGN(buf_sz); | |
828 | init_dma_desc_rings(dev); | |
829 | ||
830 | /* DMA initialization and SW reset */ | |
ad01b7d4 GC |
831 | if (unlikely(priv->hw->dma->init(priv->ioaddr, priv->pbl, |
832 | priv->dma_tx_phy, | |
db98a0b0 | 833 | priv->dma_rx_phy) < 0)) { |
47dd7a54 GC |
834 | |
835 | pr_err("%s: DMA initialization failed\n", __func__); | |
836 | return -1; | |
837 | } | |
838 | ||
839 | /* Copy the MAC addr into the HW */ | |
ad01b7d4 | 840 | priv->hw->mac->set_umac_addr(priv->ioaddr, dev->dev_addr, 0); |
ca5f12c1 GC |
841 | /* If required, perform hw setup of the bus. */ |
842 | if (priv->bus_setup) | |
ad01b7d4 | 843 | priv->bus_setup(priv->ioaddr); |
47dd7a54 | 844 | /* Initialize the MAC Core */ |
ad01b7d4 | 845 | priv->hw->mac->core_init(priv->ioaddr); |
47dd7a54 | 846 | |
ebbb293f GC |
847 | priv->rx_coe = priv->hw->mac->rx_coe(priv->ioaddr); |
848 | if (priv->rx_coe) | |
849 | pr_info("stmmac: Rx Checksum Offload Engine supported\n"); | |
850 | if (priv->tx_coe) | |
851 | pr_info("\tTX Checksum insertion supported\n"); | |
852 | ||
47dd7a54 GC |
853 | priv->shutdown = 0; |
854 | ||
855 | /* Initialise the MMC (if present) to disable all interrupts. */ | |
ad01b7d4 GC |
856 | writel(0xffffffff, priv->ioaddr + MMC_HIGH_INTR_MASK); |
857 | writel(0xffffffff, priv->ioaddr + MMC_LOW_INTR_MASK); | |
47dd7a54 GC |
858 | |
859 | /* Enable the MAC Rx/Tx */ | |
ad01b7d4 GC |
860 | stmmac_mac_enable_rx(priv->ioaddr); |
861 | stmmac_mac_enable_tx(priv->ioaddr); | |
47dd7a54 GC |
862 | |
863 | /* Set the HW DMA mode and the COE */ | |
864 | stmmac_dma_operation_mode(priv); | |
865 | ||
866 | /* Extra statistics */ | |
867 | memset(&priv->xstats, 0, sizeof(struct stmmac_extra_stats)); | |
868 | priv->xstats.threshold = tc; | |
869 | ||
870 | /* Start the ball rolling... */ | |
871 | DBG(probe, DEBUG, "%s: DMA RX/TX processes started...\n", dev->name); | |
ad01b7d4 GC |
872 | priv->hw->dma->start_tx(priv->ioaddr); |
873 | priv->hw->dma->start_rx(priv->ioaddr); | |
47dd7a54 GC |
874 | |
875 | #ifdef CONFIG_STMMAC_TIMER | |
876 | priv->tm->timer_start(tmrate); | |
877 | #endif | |
878 | /* Dump DMA/MAC registers */ | |
879 | if (netif_msg_hw(priv)) { | |
ad01b7d4 GC |
880 | priv->hw->mac->dump_regs(priv->ioaddr); |
881 | priv->hw->dma->dump_regs(priv->ioaddr); | |
47dd7a54 GC |
882 | } |
883 | ||
884 | if (priv->phydev) | |
885 | phy_start(priv->phydev); | |
886 | ||
887 | napi_enable(&priv->napi); | |
888 | skb_queue_head_init(&priv->rx_recycle); | |
889 | netif_start_queue(dev); | |
890 | return 0; | |
891 | } | |
892 | ||
893 | /** | |
894 | * stmmac_release - close entry point of the driver | |
895 | * @dev : device pointer. | |
896 | * Description: | |
897 | * This is the stop entry point of the driver. | |
898 | */ | |
899 | static int stmmac_release(struct net_device *dev) | |
900 | { | |
901 | struct stmmac_priv *priv = netdev_priv(dev); | |
902 | ||
903 | /* Stop and disconnect the PHY */ | |
904 | if (priv->phydev) { | |
905 | phy_stop(priv->phydev); | |
906 | phy_disconnect(priv->phydev); | |
907 | priv->phydev = NULL; | |
908 | } | |
909 | ||
910 | netif_stop_queue(dev); | |
911 | ||
912 | #ifdef CONFIG_STMMAC_TIMER | |
913 | /* Stop and release the timer */ | |
914 | stmmac_close_ext_timer(); | |
915 | if (priv->tm != NULL) | |
916 | kfree(priv->tm); | |
917 | #endif | |
918 | napi_disable(&priv->napi); | |
919 | skb_queue_purge(&priv->rx_recycle); | |
920 | ||
921 | /* Free the IRQ lines */ | |
922 | free_irq(dev->irq, dev); | |
923 | ||
924 | /* Stop TX/RX DMA and clear the descriptors */ | |
ad01b7d4 GC |
925 | priv->hw->dma->stop_tx(priv->ioaddr); |
926 | priv->hw->dma->stop_rx(priv->ioaddr); | |
47dd7a54 GC |
927 | |
928 | /* Release and free the Rx/Tx resources */ | |
929 | free_dma_desc_resources(priv); | |
930 | ||
931 | /* Disable the MAC core */ | |
ad01b7d4 GC |
932 | stmmac_mac_disable_tx(priv->ioaddr); |
933 | stmmac_mac_disable_rx(priv->ioaddr); | |
47dd7a54 GC |
934 | |
935 | netif_carrier_off(dev); | |
936 | ||
937 | return 0; | |
938 | } | |
939 | ||
940 | /* | |
941 | * To perform emulated hardware segmentation on skb. | |
942 | */ | |
943 | static int stmmac_sw_tso(struct stmmac_priv *priv, struct sk_buff *skb) | |
944 | { | |
945 | struct sk_buff *segs, *curr_skb; | |
946 | int gso_segs = skb_shinfo(skb)->gso_segs; | |
947 | ||
948 | /* Estimate the number of fragments in the worst case */ | |
949 | if (unlikely(stmmac_tx_avail(priv) < gso_segs)) { | |
950 | netif_stop_queue(priv->dev); | |
951 | TX_DBG(KERN_ERR "%s: TSO BUG! Tx Ring full when queue awake\n", | |
952 | __func__); | |
953 | if (stmmac_tx_avail(priv) < gso_segs) | |
954 | return NETDEV_TX_BUSY; | |
955 | ||
956 | netif_wake_queue(priv->dev); | |
957 | } | |
958 | TX_DBG("\tstmmac_sw_tso: segmenting: skb %p (len %d)\n", | |
959 | skb, skb->len); | |
960 | ||
961 | segs = skb_gso_segment(skb, priv->dev->features & ~NETIF_F_TSO); | |
962 | if (unlikely(IS_ERR(segs))) | |
963 | goto sw_tso_end; | |
964 | ||
965 | do { | |
966 | curr_skb = segs; | |
967 | segs = segs->next; | |
968 | TX_DBG("\t\tcurrent skb->len: %d, *curr %p," | |
969 | "*next %p\n", curr_skb->len, curr_skb, segs); | |
970 | curr_skb->next = NULL; | |
971 | stmmac_xmit(curr_skb, priv->dev); | |
972 | } while (segs); | |
973 | ||
974 | sw_tso_end: | |
975 | dev_kfree_skb(skb); | |
976 | ||
977 | return NETDEV_TX_OK; | |
978 | } | |
979 | ||
980 | static unsigned int stmmac_handle_jumbo_frames(struct sk_buff *skb, | |
981 | struct net_device *dev, | |
982 | int csum_insertion) | |
983 | { | |
984 | struct stmmac_priv *priv = netdev_priv(dev); | |
985 | unsigned int nopaged_len = skb_headlen(skb); | |
986 | unsigned int txsize = priv->dma_tx_size; | |
987 | unsigned int entry = priv->cur_tx % txsize; | |
988 | struct dma_desc *desc = priv->dma_tx + entry; | |
989 | ||
990 | if (nopaged_len > BUF_SIZE_8KiB) { | |
991 | ||
992 | int buf2_size = nopaged_len - BUF_SIZE_8KiB; | |
993 | ||
994 | desc->des2 = dma_map_single(priv->device, skb->data, | |
995 | BUF_SIZE_8KiB, DMA_TO_DEVICE); | |
996 | desc->des3 = desc->des2 + BUF_SIZE_4KiB; | |
db98a0b0 GC |
997 | priv->hw->desc->prepare_tx_desc(desc, 1, BUF_SIZE_8KiB, |
998 | csum_insertion); | |
47dd7a54 GC |
999 | |
1000 | entry = (++priv->cur_tx) % txsize; | |
1001 | desc = priv->dma_tx + entry; | |
1002 | ||
1003 | desc->des2 = dma_map_single(priv->device, | |
1004 | skb->data + BUF_SIZE_8KiB, | |
1005 | buf2_size, DMA_TO_DEVICE); | |
1006 | desc->des3 = desc->des2 + BUF_SIZE_4KiB; | |
db98a0b0 GC |
1007 | priv->hw->desc->prepare_tx_desc(desc, 0, buf2_size, |
1008 | csum_insertion); | |
1009 | priv->hw->desc->set_tx_owner(desc); | |
47dd7a54 GC |
1010 | priv->tx_skbuff[entry] = NULL; |
1011 | } else { | |
1012 | desc->des2 = dma_map_single(priv->device, skb->data, | |
1013 | nopaged_len, DMA_TO_DEVICE); | |
1014 | desc->des3 = desc->des2 + BUF_SIZE_4KiB; | |
db98a0b0 GC |
1015 | priv->hw->desc->prepare_tx_desc(desc, 1, nopaged_len, |
1016 | csum_insertion); | |
47dd7a54 GC |
1017 | } |
1018 | return entry; | |
1019 | } | |
1020 | ||
1021 | /** | |
1022 | * stmmac_xmit: | |
1023 | * @skb : the socket buffer | |
1024 | * @dev : device pointer | |
1025 | * Description : Tx entry point of the driver. | |
1026 | */ | |
1027 | static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev) | |
1028 | { | |
1029 | struct stmmac_priv *priv = netdev_priv(dev); | |
1030 | unsigned int txsize = priv->dma_tx_size; | |
1031 | unsigned int entry; | |
1032 | int i, csum_insertion = 0; | |
1033 | int nfrags = skb_shinfo(skb)->nr_frags; | |
1034 | struct dma_desc *desc, *first; | |
1035 | ||
1036 | if (unlikely(stmmac_tx_avail(priv) < nfrags + 1)) { | |
1037 | if (!netif_queue_stopped(dev)) { | |
1038 | netif_stop_queue(dev); | |
1039 | /* This is a hard error, log it. */ | |
1040 | pr_err("%s: BUG! Tx Ring full when queue awake\n", | |
1041 | __func__); | |
1042 | } | |
1043 | return NETDEV_TX_BUSY; | |
1044 | } | |
1045 | ||
1046 | entry = priv->cur_tx % txsize; | |
1047 | ||
1048 | #ifdef STMMAC_XMIT_DEBUG | |
1049 | if ((skb->len > ETH_FRAME_LEN) || nfrags) | |
1050 | pr_info("stmmac xmit:\n" | |
1051 | "\tskb addr %p - len: %d - nopaged_len: %d\n" | |
1052 | "\tn_frags: %d - ip_summed: %d - %s gso\n", | |
1053 | skb, skb->len, skb_headlen(skb), nfrags, skb->ip_summed, | |
1054 | !skb_is_gso(skb) ? "isn't" : "is"); | |
1055 | #endif | |
1056 | ||
1057 | if (unlikely(skb_is_gso(skb))) | |
1058 | return stmmac_sw_tso(priv, skb); | |
1059 | ||
1060 | if (likely((skb->ip_summed == CHECKSUM_PARTIAL))) { | |
ebbb293f | 1061 | if (unlikely((!priv->tx_coe) || (priv->no_csum_insertion))) |
47dd7a54 GC |
1062 | skb_checksum_help(skb); |
1063 | else | |
1064 | csum_insertion = 1; | |
1065 | } | |
1066 | ||
1067 | desc = priv->dma_tx + entry; | |
1068 | first = desc; | |
1069 | ||
1070 | #ifdef STMMAC_XMIT_DEBUG | |
1071 | if ((nfrags > 0) || (skb->len > ETH_FRAME_LEN)) | |
1072 | pr_debug("stmmac xmit: skb len: %d, nopaged_len: %d,\n" | |
1073 | "\t\tn_frags: %d, ip_summed: %d\n", | |
1074 | skb->len, skb_headlen(skb), nfrags, skb->ip_summed); | |
1075 | #endif | |
1076 | priv->tx_skbuff[entry] = skb; | |
1077 | if (unlikely(skb->len >= BUF_SIZE_4KiB)) { | |
1078 | entry = stmmac_handle_jumbo_frames(skb, dev, csum_insertion); | |
1079 | desc = priv->dma_tx + entry; | |
1080 | } else { | |
1081 | unsigned int nopaged_len = skb_headlen(skb); | |
1082 | desc->des2 = dma_map_single(priv->device, skb->data, | |
1083 | nopaged_len, DMA_TO_DEVICE); | |
db98a0b0 GC |
1084 | priv->hw->desc->prepare_tx_desc(desc, 1, nopaged_len, |
1085 | csum_insertion); | |
47dd7a54 GC |
1086 | } |
1087 | ||
1088 | for (i = 0; i < nfrags; i++) { | |
1089 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; | |
1090 | int len = frag->size; | |
1091 | ||
1092 | entry = (++priv->cur_tx) % txsize; | |
1093 | desc = priv->dma_tx + entry; | |
1094 | ||
1095 | TX_DBG("\t[entry %d] segment len: %d\n", entry, len); | |
1096 | desc->des2 = dma_map_page(priv->device, frag->page, | |
1097 | frag->page_offset, | |
1098 | len, DMA_TO_DEVICE); | |
1099 | priv->tx_skbuff[entry] = NULL; | |
db98a0b0 GC |
1100 | priv->hw->desc->prepare_tx_desc(desc, 0, len, csum_insertion); |
1101 | priv->hw->desc->set_tx_owner(desc); | |
47dd7a54 GC |
1102 | } |
1103 | ||
1104 | /* Interrupt on completition only for the latest segment */ | |
db98a0b0 | 1105 | priv->hw->desc->close_tx_desc(desc); |
73cfe264 | 1106 | |
47dd7a54 | 1107 | #ifdef CONFIG_STMMAC_TIMER |
73cfe264 GC |
1108 | /* Clean IC while using timer */ |
1109 | if (likely(priv->tm->enable)) | |
db98a0b0 | 1110 | priv->hw->desc->clear_tx_ic(desc); |
47dd7a54 GC |
1111 | #endif |
1112 | /* To avoid raise condition */ | |
db98a0b0 | 1113 | priv->hw->desc->set_tx_owner(first); |
47dd7a54 GC |
1114 | |
1115 | priv->cur_tx++; | |
1116 | ||
1117 | #ifdef STMMAC_XMIT_DEBUG | |
1118 | if (netif_msg_pktdata(priv)) { | |
1119 | pr_info("stmmac xmit: current=%d, dirty=%d, entry=%d, " | |
1120 | "first=%p, nfrags=%d\n", | |
1121 | (priv->cur_tx % txsize), (priv->dirty_tx % txsize), | |
1122 | entry, first, nfrags); | |
1123 | display_ring(priv->dma_tx, txsize); | |
1124 | pr_info(">>> frame to be transmitted: "); | |
1125 | print_pkt(skb->data, skb->len); | |
1126 | } | |
1127 | #endif | |
1128 | if (unlikely(stmmac_tx_avail(priv) <= (MAX_SKB_FRAGS + 1))) { | |
1129 | TX_DBG("%s: stop transmitted packets\n", __func__); | |
1130 | netif_stop_queue(dev); | |
1131 | } | |
1132 | ||
1133 | dev->stats.tx_bytes += skb->len; | |
1134 | ||
ad01b7d4 | 1135 | priv->hw->dma->enable_dma_transmission(priv->ioaddr); |
47dd7a54 GC |
1136 | |
1137 | return NETDEV_TX_OK; | |
1138 | } | |
1139 | ||
1140 | static inline void stmmac_rx_refill(struct stmmac_priv *priv) | |
1141 | { | |
1142 | unsigned int rxsize = priv->dma_rx_size; | |
1143 | int bfsize = priv->dma_buf_sz; | |
1144 | struct dma_desc *p = priv->dma_rx; | |
1145 | ||
1146 | for (; priv->cur_rx - priv->dirty_rx > 0; priv->dirty_rx++) { | |
1147 | unsigned int entry = priv->dirty_rx % rxsize; | |
1148 | if (likely(priv->rx_skbuff[entry] == NULL)) { | |
1149 | struct sk_buff *skb; | |
1150 | ||
1151 | skb = __skb_dequeue(&priv->rx_recycle); | |
1152 | if (skb == NULL) | |
1153 | skb = netdev_alloc_skb_ip_align(priv->dev, | |
1154 | bfsize); | |
1155 | ||
1156 | if (unlikely(skb == NULL)) | |
1157 | break; | |
1158 | ||
1159 | priv->rx_skbuff[entry] = skb; | |
1160 | priv->rx_skbuff_dma[entry] = | |
1161 | dma_map_single(priv->device, skb->data, bfsize, | |
1162 | DMA_FROM_DEVICE); | |
1163 | ||
1164 | (p + entry)->des2 = priv->rx_skbuff_dma[entry]; | |
1165 | if (unlikely(priv->is_gmac)) { | |
1166 | if (bfsize >= BUF_SIZE_8KiB) | |
1167 | (p + entry)->des3 = | |
1168 | (p + entry)->des2 + BUF_SIZE_8KiB; | |
1169 | } | |
1170 | RX_DBG(KERN_INFO "\trefill entry #%d\n", entry); | |
1171 | } | |
db98a0b0 | 1172 | priv->hw->desc->set_rx_owner(p + entry); |
47dd7a54 | 1173 | } |
47dd7a54 GC |
1174 | } |
1175 | ||
1176 | static int stmmac_rx(struct stmmac_priv *priv, int limit) | |
1177 | { | |
1178 | unsigned int rxsize = priv->dma_rx_size; | |
1179 | unsigned int entry = priv->cur_rx % rxsize; | |
1180 | unsigned int next_entry; | |
1181 | unsigned int count = 0; | |
1182 | struct dma_desc *p = priv->dma_rx + entry; | |
1183 | struct dma_desc *p_next; | |
1184 | ||
1185 | #ifdef STMMAC_RX_DEBUG | |
1186 | if (netif_msg_hw(priv)) { | |
1187 | pr_debug(">>> stmmac_rx: descriptor ring:\n"); | |
1188 | display_ring(priv->dma_rx, rxsize); | |
1189 | } | |
1190 | #endif | |
1191 | count = 0; | |
db98a0b0 | 1192 | while (!priv->hw->desc->get_rx_owner(p)) { |
47dd7a54 GC |
1193 | int status; |
1194 | ||
1195 | if (count >= limit) | |
1196 | break; | |
1197 | ||
1198 | count++; | |
1199 | ||
1200 | next_entry = (++priv->cur_rx) % rxsize; | |
1201 | p_next = priv->dma_rx + next_entry; | |
1202 | prefetch(p_next); | |
1203 | ||
1204 | /* read the status of the incoming frame */ | |
db98a0b0 GC |
1205 | status = (priv->hw->desc->rx_status(&priv->dev->stats, |
1206 | &priv->xstats, p)); | |
47dd7a54 GC |
1207 | if (unlikely(status == discard_frame)) |
1208 | priv->dev->stats.rx_errors++; | |
1209 | else { | |
1210 | struct sk_buff *skb; | |
3eeb2997 | 1211 | int frame_len; |
47dd7a54 | 1212 | |
3eeb2997 GC |
1213 | frame_len = priv->hw->desc->get_rx_frame_len(p); |
1214 | /* ACS is set; GMAC core strips PAD/FCS for IEEE 802.3 | |
1215 | * Type frames (LLC/LLC-SNAP) */ | |
1216 | if (unlikely(status != llc_snap)) | |
1217 | frame_len -= ETH_FCS_LEN; | |
47dd7a54 GC |
1218 | #ifdef STMMAC_RX_DEBUG |
1219 | if (frame_len > ETH_FRAME_LEN) | |
1220 | pr_debug("\tRX frame size %d, COE status: %d\n", | |
1221 | frame_len, status); | |
1222 | ||
1223 | if (netif_msg_hw(priv)) | |
1224 | pr_debug("\tdesc: %p [entry %d] buff=0x%x\n", | |
1225 | p, entry, p->des2); | |
1226 | #endif | |
1227 | skb = priv->rx_skbuff[entry]; | |
1228 | if (unlikely(!skb)) { | |
1229 | pr_err("%s: Inconsistent Rx descriptor chain\n", | |
1230 | priv->dev->name); | |
1231 | priv->dev->stats.rx_dropped++; | |
1232 | break; | |
1233 | } | |
1234 | prefetch(skb->data - NET_IP_ALIGN); | |
1235 | priv->rx_skbuff[entry] = NULL; | |
1236 | ||
1237 | skb_put(skb, frame_len); | |
1238 | dma_unmap_single(priv->device, | |
1239 | priv->rx_skbuff_dma[entry], | |
1240 | priv->dma_buf_sz, DMA_FROM_DEVICE); | |
1241 | #ifdef STMMAC_RX_DEBUG | |
1242 | if (netif_msg_pktdata(priv)) { | |
1243 | pr_info(" frame received (%dbytes)", frame_len); | |
1244 | print_pkt(skb->data, frame_len); | |
1245 | } | |
1246 | #endif | |
1247 | skb->protocol = eth_type_trans(skb, priv->dev); | |
1248 | ||
1249 | if (unlikely(status == csum_none)) { | |
1250 | /* always for the old mac 10/100 */ | |
bc8acf2c | 1251 | skb_checksum_none_assert(skb); |
47dd7a54 GC |
1252 | netif_receive_skb(skb); |
1253 | } else { | |
1254 | skb->ip_summed = CHECKSUM_UNNECESSARY; | |
1255 | napi_gro_receive(&priv->napi, skb); | |
1256 | } | |
1257 | ||
1258 | priv->dev->stats.rx_packets++; | |
1259 | priv->dev->stats.rx_bytes += frame_len; | |
47dd7a54 GC |
1260 | } |
1261 | entry = next_entry; | |
1262 | p = p_next; /* use prefetched values */ | |
1263 | } | |
1264 | ||
1265 | stmmac_rx_refill(priv); | |
1266 | ||
1267 | priv->xstats.rx_pkt_n += count; | |
1268 | ||
1269 | return count; | |
1270 | } | |
1271 | ||
1272 | /** | |
1273 | * stmmac_poll - stmmac poll method (NAPI) | |
1274 | * @napi : pointer to the napi structure. | |
1275 | * @budget : maximum number of packets that the current CPU can receive from | |
1276 | * all interfaces. | |
1277 | * Description : | |
1278 | * This function implements the the reception process. | |
1279 | * Also it runs the TX completion thread | |
1280 | */ | |
1281 | static int stmmac_poll(struct napi_struct *napi, int budget) | |
1282 | { | |
1283 | struct stmmac_priv *priv = container_of(napi, struct stmmac_priv, napi); | |
1284 | int work_done = 0; | |
1285 | ||
1286 | priv->xstats.poll_n++; | |
1287 | stmmac_tx(priv); | |
1288 | work_done = stmmac_rx(priv, budget); | |
1289 | ||
1290 | if (work_done < budget) { | |
1291 | napi_complete(napi); | |
1292 | stmmac_enable_irq(priv); | |
1293 | } | |
1294 | return work_done; | |
1295 | } | |
1296 | ||
1297 | /** | |
1298 | * stmmac_tx_timeout | |
1299 | * @dev : Pointer to net device structure | |
1300 | * Description: this function is called when a packet transmission fails to | |
1301 | * complete within a reasonable tmrate. The driver will mark the error in the | |
1302 | * netdev structure and arrange for the device to be reset to a sane state | |
1303 | * in order to transmit a new packet. | |
1304 | */ | |
1305 | static void stmmac_tx_timeout(struct net_device *dev) | |
1306 | { | |
1307 | struct stmmac_priv *priv = netdev_priv(dev); | |
1308 | ||
1309 | /* Clear Tx resources and restart transmitting again */ | |
1310 | stmmac_tx_err(priv); | |
47dd7a54 GC |
1311 | } |
1312 | ||
1313 | /* Configuration changes (passed on by ifconfig) */ | |
1314 | static int stmmac_config(struct net_device *dev, struct ifmap *map) | |
1315 | { | |
1316 | if (dev->flags & IFF_UP) /* can't act on a running interface */ | |
1317 | return -EBUSY; | |
1318 | ||
1319 | /* Don't allow changing the I/O address */ | |
1320 | if (map->base_addr != dev->base_addr) { | |
1321 | pr_warning("%s: can't change I/O address\n", dev->name); | |
1322 | return -EOPNOTSUPP; | |
1323 | } | |
1324 | ||
1325 | /* Don't allow changing the IRQ */ | |
1326 | if (map->irq != dev->irq) { | |
1327 | pr_warning("%s: can't change IRQ number %d\n", | |
1328 | dev->name, dev->irq); | |
1329 | return -EOPNOTSUPP; | |
1330 | } | |
1331 | ||
1332 | /* ignore other fields */ | |
1333 | return 0; | |
1334 | } | |
1335 | ||
1336 | /** | |
1337 | * stmmac_multicast_list - entry point for multicast addressing | |
1338 | * @dev : pointer to the device structure | |
1339 | * Description: | |
1340 | * This function is a driver entry point which gets called by the kernel | |
1341 | * whenever multicast addresses must be enabled/disabled. | |
1342 | * Return value: | |
1343 | * void. | |
1344 | */ | |
1345 | static void stmmac_multicast_list(struct net_device *dev) | |
1346 | { | |
1347 | struct stmmac_priv *priv = netdev_priv(dev); | |
1348 | ||
1349 | spin_lock(&priv->lock); | |
db98a0b0 | 1350 | priv->hw->mac->set_filter(dev); |
47dd7a54 | 1351 | spin_unlock(&priv->lock); |
47dd7a54 GC |
1352 | } |
1353 | ||
1354 | /** | |
1355 | * stmmac_change_mtu - entry point to change MTU size for the device. | |
1356 | * @dev : device pointer. | |
1357 | * @new_mtu : the new MTU size for the device. | |
1358 | * Description: the Maximum Transfer Unit (MTU) is used by the network layer | |
1359 | * to drive packet transmission. Ethernet has an MTU of 1500 octets | |
1360 | * (ETH_DATA_LEN). This value can be changed with ifconfig. | |
1361 | * Return value: | |
1362 | * 0 on success and an appropriate (-)ve integer as defined in errno.h | |
1363 | * file on failure. | |
1364 | */ | |
1365 | static int stmmac_change_mtu(struct net_device *dev, int new_mtu) | |
1366 | { | |
1367 | struct stmmac_priv *priv = netdev_priv(dev); | |
1368 | int max_mtu; | |
1369 | ||
1370 | if (netif_running(dev)) { | |
1371 | pr_err("%s: must be stopped to change its MTU\n", dev->name); | |
1372 | return -EBUSY; | |
1373 | } | |
1374 | ||
1375 | if (priv->is_gmac) | |
1376 | max_mtu = JUMBO_LEN; | |
1377 | else | |
1378 | max_mtu = ETH_DATA_LEN; | |
1379 | ||
1380 | if ((new_mtu < 46) || (new_mtu > max_mtu)) { | |
1381 | pr_err("%s: invalid MTU, max MTU is: %d\n", dev->name, max_mtu); | |
1382 | return -EINVAL; | |
1383 | } | |
1384 | ||
ebbb293f GC |
1385 | /* Some GMAC devices have a bugged Jumbo frame support that |
1386 | * needs to have the Tx COE disabled for oversized frames | |
1387 | * (due to limited buffer sizes). In this case we disable | |
1388 | * the TX csum insertionin the TDES and not use SF. */ | |
1389 | if ((priv->bugged_jumbo) && (priv->dev->mtu > ETH_DATA_LEN)) | |
1390 | priv->no_csum_insertion = 1; | |
1391 | else | |
1392 | priv->no_csum_insertion = 0; | |
1393 | ||
47dd7a54 GC |
1394 | dev->mtu = new_mtu; |
1395 | ||
1396 | return 0; | |
1397 | } | |
1398 | ||
1399 | static irqreturn_t stmmac_interrupt(int irq, void *dev_id) | |
1400 | { | |
1401 | struct net_device *dev = (struct net_device *)dev_id; | |
1402 | struct stmmac_priv *priv = netdev_priv(dev); | |
1403 | ||
1404 | if (unlikely(!dev)) { | |
1405 | pr_err("%s: invalid dev pointer\n", __func__); | |
1406 | return IRQ_NONE; | |
1407 | } | |
1408 | ||
ad01b7d4 | 1409 | if (priv->is_gmac) |
47dd7a54 | 1410 | /* To handle GMAC own interrupts */ |
ad01b7d4 | 1411 | priv->hw->mac->host_irq_status((void __iomem *) dev->base_addr); |
aec7ff27 GC |
1412 | |
1413 | stmmac_dma_interrupt(priv); | |
47dd7a54 GC |
1414 | |
1415 | return IRQ_HANDLED; | |
1416 | } | |
1417 | ||
1418 | #ifdef CONFIG_NET_POLL_CONTROLLER | |
1419 | /* Polling receive - used by NETCONSOLE and other diagnostic tools | |
1420 | * to allow network I/O with interrupts disabled. */ | |
1421 | static void stmmac_poll_controller(struct net_device *dev) | |
1422 | { | |
1423 | disable_irq(dev->irq); | |
1424 | stmmac_interrupt(dev->irq, dev); | |
1425 | enable_irq(dev->irq); | |
1426 | } | |
1427 | #endif | |
1428 | ||
1429 | /** | |
1430 | * stmmac_ioctl - Entry point for the Ioctl | |
1431 | * @dev: Device pointer. | |
1432 | * @rq: An IOCTL specefic structure, that can contain a pointer to | |
1433 | * a proprietary structure used to pass information to the driver. | |
1434 | * @cmd: IOCTL command | |
1435 | * Description: | |
1436 | * Currently there are no special functionality supported in IOCTL, just the | |
1437 | * phy_mii_ioctl(...) can be invoked. | |
1438 | */ | |
1439 | static int stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) | |
1440 | { | |
1441 | struct stmmac_priv *priv = netdev_priv(dev); | |
28b04113 | 1442 | int ret; |
47dd7a54 GC |
1443 | |
1444 | if (!netif_running(dev)) | |
1445 | return -EINVAL; | |
1446 | ||
28b04113 RC |
1447 | if (!priv->phydev) |
1448 | return -EINVAL; | |
1449 | ||
1450 | spin_lock(&priv->lock); | |
1451 | ret = phy_mii_ioctl(priv->phydev, rq, cmd); | |
1452 | spin_unlock(&priv->lock); | |
1453 | ||
47dd7a54 GC |
1454 | return ret; |
1455 | } | |
1456 | ||
1457 | #ifdef STMMAC_VLAN_TAG_USED | |
1458 | static void stmmac_vlan_rx_register(struct net_device *dev, | |
1459 | struct vlan_group *grp) | |
1460 | { | |
1461 | struct stmmac_priv *priv = netdev_priv(dev); | |
1462 | ||
1463 | DBG(probe, INFO, "%s: Setting vlgrp to %p\n", dev->name, grp); | |
1464 | ||
1465 | spin_lock(&priv->lock); | |
1466 | priv->vlgrp = grp; | |
1467 | spin_unlock(&priv->lock); | |
47dd7a54 GC |
1468 | } |
1469 | #endif | |
1470 | ||
1471 | static const struct net_device_ops stmmac_netdev_ops = { | |
1472 | .ndo_open = stmmac_open, | |
1473 | .ndo_start_xmit = stmmac_xmit, | |
1474 | .ndo_stop = stmmac_release, | |
1475 | .ndo_change_mtu = stmmac_change_mtu, | |
1476 | .ndo_set_multicast_list = stmmac_multicast_list, | |
1477 | .ndo_tx_timeout = stmmac_tx_timeout, | |
1478 | .ndo_do_ioctl = stmmac_ioctl, | |
1479 | .ndo_set_config = stmmac_config, | |
1480 | #ifdef STMMAC_VLAN_TAG_USED | |
1481 | .ndo_vlan_rx_register = stmmac_vlan_rx_register, | |
1482 | #endif | |
1483 | #ifdef CONFIG_NET_POLL_CONTROLLER | |
1484 | .ndo_poll_controller = stmmac_poll_controller, | |
1485 | #endif | |
1486 | .ndo_set_mac_address = eth_mac_addr, | |
1487 | }; | |
1488 | ||
1489 | /** | |
1490 | * stmmac_probe - Initialization of the adapter . | |
1491 | * @dev : device pointer | |
1492 | * Description: The function initializes the network device structure for | |
1493 | * the STMMAC driver. It also calls the low level routines | |
1494 | * in order to init the HW (i.e. the DMA engine) | |
1495 | */ | |
1496 | static int stmmac_probe(struct net_device *dev) | |
1497 | { | |
1498 | int ret = 0; | |
1499 | struct stmmac_priv *priv = netdev_priv(dev); | |
1500 | ||
1501 | ether_setup(dev); | |
1502 | ||
1503 | dev->netdev_ops = &stmmac_netdev_ops; | |
1504 | stmmac_set_ethtool_ops(dev); | |
1505 | ||
1506 | dev->features |= (NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_HIGHDMA); | |
1507 | dev->watchdog_timeo = msecs_to_jiffies(watchdog); | |
1508 | #ifdef STMMAC_VLAN_TAG_USED | |
1509 | /* Both mac100 and gmac support receive VLAN tag detection */ | |
1510 | dev->features |= NETIF_F_HW_VLAN_RX; | |
1511 | #endif | |
1512 | priv->msg_enable = netif_msg_init(debug, default_msg_level); | |
1513 | ||
47dd7a54 GC |
1514 | if (flow_ctrl) |
1515 | priv->flow_ctrl = FLOW_AUTO; /* RX/TX pause on */ | |
1516 | ||
1517 | priv->pause = pause; | |
1518 | netif_napi_add(dev, &priv->napi, stmmac_poll, 64); | |
1519 | ||
1520 | /* Get the MAC address */ | |
ad01b7d4 GC |
1521 | priv->hw->mac->get_umac_addr((void __iomem *) dev->base_addr, |
1522 | dev->dev_addr, 0); | |
47dd7a54 GC |
1523 | |
1524 | if (!is_valid_ether_addr(dev->dev_addr)) | |
1525 | pr_warning("\tno valid MAC address;" | |
1526 | "please, use ifconfig or nwhwconfig!\n"); | |
1527 | ||
1528 | ret = register_netdev(dev); | |
1529 | if (ret) { | |
1530 | pr_err("%s: ERROR %i registering the device\n", | |
1531 | __func__, ret); | |
1532 | return -ENODEV; | |
1533 | } | |
1534 | ||
1535 | DBG(probe, DEBUG, "%s: Scatter/Gather: %s - HW checksums: %s\n", | |
1536 | dev->name, (dev->features & NETIF_F_SG) ? "on" : "off", | |
1537 | (dev->features & NETIF_F_HW_CSUM) ? "on" : "off"); | |
1538 | ||
1539 | spin_lock_init(&priv->lock); | |
1540 | ||
1541 | return ret; | |
1542 | } | |
1543 | ||
1544 | /** | |
1545 | * stmmac_mac_device_setup | |
1546 | * @dev : device pointer | |
1547 | * Description: select and initialise the mac device (mac100 or Gmac). | |
1548 | */ | |
1549 | static int stmmac_mac_device_setup(struct net_device *dev) | |
1550 | { | |
1551 | struct stmmac_priv *priv = netdev_priv(dev); | |
47dd7a54 GC |
1552 | |
1553 | struct mac_device_info *device; | |
1554 | ||
3d90c508 | 1555 | if (priv->is_gmac) |
ad01b7d4 | 1556 | device = dwmac1000_setup(priv->ioaddr); |
3d90c508 | 1557 | else |
ad01b7d4 | 1558 | device = dwmac100_setup(priv->ioaddr); |
3d90c508 | 1559 | |
1ff21906 DC |
1560 | if (!device) |
1561 | return -ENOMEM; | |
1562 | ||
3d90c508 GC |
1563 | if (priv->enh_desc) { |
1564 | device->desc = &enh_desc_ops; | |
1565 | pr_info("\tEnhanced descriptor structure\n"); | |
1566 | } else | |
56b106ae | 1567 | device->desc = &ndesc_ops; |
47dd7a54 | 1568 | |
db98a0b0 | 1569 | priv->hw = device; |
47dd7a54 | 1570 | |
db98a0b0 | 1571 | priv->wolenabled = priv->hw->pmt; /* PMT supported */ |
47dd7a54 GC |
1572 | if (priv->wolenabled == PMT_SUPPORTED) |
1573 | priv->wolopts = WAKE_MAGIC; /* Magic Frame */ | |
1574 | ||
1575 | return 0; | |
1576 | } | |
1577 | ||
1578 | static int stmmacphy_dvr_probe(struct platform_device *pdev) | |
1579 | { | |
ee7946a7 | 1580 | struct plat_stmmacphy_data *plat_dat = pdev->dev.platform_data; |
47dd7a54 GC |
1581 | |
1582 | pr_debug("stmmacphy_dvr_probe: added phy for bus %d\n", | |
1583 | plat_dat->bus_id); | |
1584 | ||
1585 | return 0; | |
1586 | } | |
1587 | ||
1588 | static int stmmacphy_dvr_remove(struct platform_device *pdev) | |
1589 | { | |
1590 | return 0; | |
1591 | } | |
1592 | ||
1593 | static struct platform_driver stmmacphy_driver = { | |
1594 | .driver = { | |
1595 | .name = PHY_RESOURCE_NAME, | |
1596 | }, | |
1597 | .probe = stmmacphy_dvr_probe, | |
1598 | .remove = stmmacphy_dvr_remove, | |
1599 | }; | |
1600 | ||
1601 | /** | |
1602 | * stmmac_associate_phy | |
1603 | * @dev: pointer to device structure | |
1604 | * @data: points to the private structure. | |
1605 | * Description: Scans through all the PHYs we have registered and checks if | |
1606 | * any are associated with our MAC. If so, then just fill in | |
1607 | * the blanks in our local context structure | |
1608 | */ | |
1609 | static int stmmac_associate_phy(struct device *dev, void *data) | |
1610 | { | |
1611 | struct stmmac_priv *priv = (struct stmmac_priv *)data; | |
ee7946a7 | 1612 | struct plat_stmmacphy_data *plat_dat = dev->platform_data; |
47dd7a54 GC |
1613 | |
1614 | DBG(probe, DEBUG, "%s: checking phy for bus %d\n", __func__, | |
1615 | plat_dat->bus_id); | |
1616 | ||
1617 | /* Check that this phy is for the MAC being initialised */ | |
1618 | if (priv->bus_id != plat_dat->bus_id) | |
1619 | return 0; | |
1620 | ||
1621 | /* OK, this PHY is connected to the MAC. | |
1622 | Go ahead and get the parameters */ | |
1623 | DBG(probe, DEBUG, "%s: OK. Found PHY config\n", __func__); | |
1624 | priv->phy_irq = | |
1625 | platform_get_irq_byname(to_platform_device(dev), "phyirq"); | |
1626 | DBG(probe, DEBUG, "%s: PHY irq on bus %d is %d\n", __func__, | |
1627 | plat_dat->bus_id, priv->phy_irq); | |
1628 | ||
1629 | /* Override with kernel parameters if supplied XXX CRS XXX | |
1630 | * this needs to have multiple instances */ | |
1631 | if ((phyaddr >= 0) && (phyaddr <= 31)) | |
1632 | plat_dat->phy_addr = phyaddr; | |
1633 | ||
1634 | priv->phy_addr = plat_dat->phy_addr; | |
1635 | priv->phy_mask = plat_dat->phy_mask; | |
1636 | priv->phy_interface = plat_dat->interface; | |
1637 | priv->phy_reset = plat_dat->phy_reset; | |
1638 | ||
1639 | DBG(probe, DEBUG, "%s: exiting\n", __func__); | |
1640 | return 1; /* forces exit of driver_for_each_device() */ | |
1641 | } | |
1642 | ||
1643 | /** | |
1644 | * stmmac_dvr_probe | |
1645 | * @pdev: platform device pointer | |
1646 | * Description: the driver is initialized through platform_device. | |
1647 | */ | |
1648 | static int stmmac_dvr_probe(struct platform_device *pdev) | |
1649 | { | |
1650 | int ret = 0; | |
1651 | struct resource *res; | |
ad01b7d4 | 1652 | void __iomem *addr = NULL; |
47dd7a54 GC |
1653 | struct net_device *ndev = NULL; |
1654 | struct stmmac_priv *priv; | |
1655 | struct plat_stmmacenet_data *plat_dat; | |
1656 | ||
1657 | pr_info("STMMAC driver:\n\tplatform registration... "); | |
1658 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | |
1659 | if (!res) { | |
1660 | ret = -ENODEV; | |
1661 | goto out; | |
1662 | } | |
ebbb293f | 1663 | pr_info("\tdone!\n"); |
47dd7a54 | 1664 | |
b6222682 | 1665 | if (!request_mem_region(res->start, resource_size(res), |
47dd7a54 GC |
1666 | pdev->name)) { |
1667 | pr_err("%s: ERROR: memory allocation failed" | |
1668 | "cannot get the I/O addr 0x%x\n", | |
1669 | __func__, (unsigned int)res->start); | |
1670 | ret = -EBUSY; | |
1671 | goto out; | |
1672 | } | |
1673 | ||
7c5365bc | 1674 | addr = ioremap(res->start, resource_size(res)); |
47dd7a54 | 1675 | if (!addr) { |
7c5365bc | 1676 | pr_err("%s: ERROR: memory mapping failed\n", __func__); |
47dd7a54 GC |
1677 | ret = -ENOMEM; |
1678 | goto out; | |
1679 | } | |
1680 | ||
1681 | ndev = alloc_etherdev(sizeof(struct stmmac_priv)); | |
1682 | if (!ndev) { | |
1683 | pr_err("%s: ERROR: allocating the device\n", __func__); | |
1684 | ret = -ENOMEM; | |
1685 | goto out; | |
1686 | } | |
1687 | ||
1688 | SET_NETDEV_DEV(ndev, &pdev->dev); | |
1689 | ||
1690 | /* Get the MAC information */ | |
1691 | ndev->irq = platform_get_irq_byname(pdev, "macirq"); | |
1692 | if (ndev->irq == -ENXIO) { | |
1693 | pr_err("%s: ERROR: MAC IRQ configuration " | |
1694 | "information not found\n", __func__); | |
1695 | ret = -ENODEV; | |
1696 | goto out; | |
1697 | } | |
1698 | ||
1699 | priv = netdev_priv(ndev); | |
1700 | priv->device = &(pdev->dev); | |
1701 | priv->dev = ndev; | |
ee7946a7 | 1702 | plat_dat = pdev->dev.platform_data; |
47dd7a54 GC |
1703 | priv->bus_id = plat_dat->bus_id; |
1704 | priv->pbl = plat_dat->pbl; /* TLI */ | |
dfb8fb96 | 1705 | priv->mii_clk_csr = plat_dat->clk_csr; |
ebbb293f GC |
1706 | priv->tx_coe = plat_dat->tx_coe; |
1707 | priv->bugged_jumbo = plat_dat->bugged_jumbo; | |
47dd7a54 | 1708 | priv->is_gmac = plat_dat->has_gmac; /* GMAC is on board */ |
3d90c508 | 1709 | priv->enh_desc = plat_dat->enh_desc; |
ad01b7d4 | 1710 | priv->ioaddr = addr; |
47dd7a54 GC |
1711 | |
1712 | platform_set_drvdata(pdev, ndev); | |
1713 | ||
1714 | /* Set the I/O base addr */ | |
1715 | ndev->base_addr = (unsigned long)addr; | |
1716 | ||
ee7946a7 GC |
1717 | /* Verify embedded resource for the platform */ |
1718 | ret = stmmac_claim_resource(pdev); | |
1719 | if (ret < 0) | |
1720 | goto out; | |
1721 | ||
47dd7a54 GC |
1722 | /* MAC HW revice detection */ |
1723 | ret = stmmac_mac_device_setup(ndev); | |
1724 | if (ret < 0) | |
1725 | goto out; | |
1726 | ||
1727 | /* Network Device Registration */ | |
1728 | ret = stmmac_probe(ndev); | |
1729 | if (ret < 0) | |
1730 | goto out; | |
1731 | ||
1732 | /* associate a PHY - it is provided by another platform bus */ | |
1733 | if (!driver_for_each_device | |
1734 | (&(stmmacphy_driver.driver), NULL, (void *)priv, | |
1735 | stmmac_associate_phy)) { | |
1736 | pr_err("No PHY device is associated with this MAC!\n"); | |
1737 | ret = -ENODEV; | |
1738 | goto out; | |
1739 | } | |
1740 | ||
1741 | priv->fix_mac_speed = plat_dat->fix_mac_speed; | |
ee7946a7 | 1742 | priv->bus_setup = plat_dat->bus_setup; |
47dd7a54 GC |
1743 | priv->bsp_priv = plat_dat->bsp_priv; |
1744 | ||
1745 | pr_info("\t%s - (dev. name: %s - id: %d, IRQ #%d\n" | |
1f0f6388 DM |
1746 | "\tIO base addr: 0x%p)\n", ndev->name, pdev->name, |
1747 | pdev->id, ndev->irq, addr); | |
47dd7a54 GC |
1748 | |
1749 | /* MDIO bus Registration */ | |
1750 | pr_debug("\tMDIO bus (id: %d)...", priv->bus_id); | |
1751 | ret = stmmac_mdio_register(ndev); | |
1752 | if (ret < 0) | |
1753 | goto out; | |
1754 | pr_debug("registered!\n"); | |
1755 | ||
1756 | out: | |
1757 | if (ret < 0) { | |
1758 | platform_set_drvdata(pdev, NULL); | |
7c5365bc | 1759 | release_mem_region(res->start, resource_size(res)); |
47dd7a54 GC |
1760 | if (addr != NULL) |
1761 | iounmap(addr); | |
1762 | } | |
1763 | ||
1764 | return ret; | |
1765 | } | |
1766 | ||
1767 | /** | |
1768 | * stmmac_dvr_remove | |
1769 | * @pdev: platform device pointer | |
1770 | * Description: this function resets the TX/RX processes, disables the MAC RX/TX | |
1771 | * changes the link status, releases the DMA descriptor rings, | |
1772 | * unregisters the MDIO bus and unmaps the allocated memory. | |
1773 | */ | |
1774 | static int stmmac_dvr_remove(struct platform_device *pdev) | |
1775 | { | |
1776 | struct net_device *ndev = platform_get_drvdata(pdev); | |
aec7ff27 | 1777 | struct stmmac_priv *priv = netdev_priv(ndev); |
47dd7a54 GC |
1778 | struct resource *res; |
1779 | ||
1780 | pr_info("%s:\n\tremoving driver", __func__); | |
1781 | ||
ad01b7d4 GC |
1782 | priv->hw->dma->stop_rx(priv->ioaddr); |
1783 | priv->hw->dma->stop_tx(priv->ioaddr); | |
47dd7a54 | 1784 | |
ad01b7d4 GC |
1785 | stmmac_mac_disable_rx(priv->ioaddr); |
1786 | stmmac_mac_disable_tx(priv->ioaddr); | |
47dd7a54 GC |
1787 | |
1788 | netif_carrier_off(ndev); | |
1789 | ||
1790 | stmmac_mdio_unregister(ndev); | |
1791 | ||
1792 | platform_set_drvdata(pdev, NULL); | |
1793 | unregister_netdev(ndev); | |
1794 | ||
ad01b7d4 | 1795 | iounmap((void *)priv->ioaddr); |
47dd7a54 | 1796 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
7c5365bc | 1797 | release_mem_region(res->start, resource_size(res)); |
47dd7a54 GC |
1798 | |
1799 | free_netdev(ndev); | |
1800 | ||
1801 | return 0; | |
1802 | } | |
1803 | ||
1804 | #ifdef CONFIG_PM | |
1805 | static int stmmac_suspend(struct platform_device *pdev, pm_message_t state) | |
1806 | { | |
1807 | struct net_device *dev = platform_get_drvdata(pdev); | |
1808 | struct stmmac_priv *priv = netdev_priv(dev); | |
1809 | int dis_ic = 0; | |
1810 | ||
1811 | if (!dev || !netif_running(dev)) | |
1812 | return 0; | |
1813 | ||
1814 | spin_lock(&priv->lock); | |
1815 | ||
1816 | if (state.event == PM_EVENT_SUSPEND) { | |
1817 | netif_device_detach(dev); | |
1818 | netif_stop_queue(dev); | |
1819 | if (priv->phydev) | |
1820 | phy_stop(priv->phydev); | |
1821 | ||
1822 | #ifdef CONFIG_STMMAC_TIMER | |
1823 | priv->tm->timer_stop(); | |
73cfe264 GC |
1824 | if (likely(priv->tm->enable)) |
1825 | dis_ic = 1; | |
47dd7a54 GC |
1826 | #endif |
1827 | napi_disable(&priv->napi); | |
1828 | ||
1829 | /* Stop TX/RX DMA */ | |
ad01b7d4 GC |
1830 | priv->hw->dma->stop_tx(priv->ioaddr); |
1831 | priv->hw->dma->stop_rx(priv->ioaddr); | |
47dd7a54 | 1832 | /* Clear the Rx/Tx descriptors */ |
db98a0b0 GC |
1833 | priv->hw->desc->init_rx_desc(priv->dma_rx, priv->dma_rx_size, |
1834 | dis_ic); | |
1835 | priv->hw->desc->init_tx_desc(priv->dma_tx, priv->dma_tx_size); | |
47dd7a54 | 1836 | |
ad01b7d4 | 1837 | stmmac_mac_disable_tx(priv->ioaddr); |
47dd7a54 GC |
1838 | |
1839 | if (device_may_wakeup(&(pdev->dev))) { | |
1840 | /* Enable Power down mode by programming the PMT regs */ | |
1841 | if (priv->wolenabled == PMT_SUPPORTED) | |
ad01b7d4 | 1842 | priv->hw->mac->pmt(priv->ioaddr, priv->wolopts); |
47dd7a54 | 1843 | } else { |
ad01b7d4 | 1844 | stmmac_mac_disable_rx(priv->ioaddr); |
47dd7a54 GC |
1845 | } |
1846 | } else { | |
1847 | priv->shutdown = 1; | |
1848 | /* Although this can appear slightly redundant it actually | |
1849 | * makes fast the standby operation and guarantees the driver | |
1850 | * working if hibernation is on media. */ | |
1851 | stmmac_release(dev); | |
1852 | } | |
1853 | ||
1854 | spin_unlock(&priv->lock); | |
1855 | return 0; | |
1856 | } | |
1857 | ||
1858 | static int stmmac_resume(struct platform_device *pdev) | |
1859 | { | |
1860 | struct net_device *dev = platform_get_drvdata(pdev); | |
1861 | struct stmmac_priv *priv = netdev_priv(dev); | |
47dd7a54 GC |
1862 | |
1863 | if (!netif_running(dev)) | |
1864 | return 0; | |
1865 | ||
47dd7a54 GC |
1866 | if (priv->shutdown) { |
1867 | /* Re-open the interface and re-init the MAC/DMA | |
c4433be6 | 1868 | and the rings (i.e. on hibernation stage) */ |
47dd7a54 | 1869 | stmmac_open(dev); |
c4433be6 | 1870 | return 0; |
47dd7a54 GC |
1871 | } |
1872 | ||
c4433be6 GC |
1873 | spin_lock(&priv->lock); |
1874 | ||
47dd7a54 GC |
1875 | /* Power Down bit, into the PM register, is cleared |
1876 | * automatically as soon as a magic packet or a Wake-up frame | |
1877 | * is received. Anyway, it's better to manually clear | |
1878 | * this bit because it can generate problems while resuming | |
1879 | * from another devices (e.g. serial console). */ | |
1880 | if (device_may_wakeup(&(pdev->dev))) | |
1881 | if (priv->wolenabled == PMT_SUPPORTED) | |
ad01b7d4 | 1882 | priv->hw->mac->pmt(priv->ioaddr, 0); |
47dd7a54 GC |
1883 | |
1884 | netif_device_attach(dev); | |
1885 | ||
1886 | /* Enable the MAC and DMA */ | |
ad01b7d4 GC |
1887 | stmmac_mac_enable_rx(priv->ioaddr); |
1888 | stmmac_mac_enable_tx(priv->ioaddr); | |
1889 | priv->hw->dma->start_tx(priv->ioaddr); | |
1890 | priv->hw->dma->start_rx(priv->ioaddr); | |
47dd7a54 GC |
1891 | |
1892 | #ifdef CONFIG_STMMAC_TIMER | |
1893 | priv->tm->timer_start(tmrate); | |
1894 | #endif | |
1895 | napi_enable(&priv->napi); | |
1896 | ||
1897 | if (priv->phydev) | |
1898 | phy_start(priv->phydev); | |
1899 | ||
1900 | netif_start_queue(dev); | |
1901 | ||
47dd7a54 GC |
1902 | spin_unlock(&priv->lock); |
1903 | return 0; | |
1904 | } | |
1905 | #endif | |
1906 | ||
1907 | static struct platform_driver stmmac_driver = { | |
1908 | .driver = { | |
1909 | .name = STMMAC_RESOURCE_NAME, | |
1910 | }, | |
1911 | .probe = stmmac_dvr_probe, | |
1912 | .remove = stmmac_dvr_remove, | |
1913 | #ifdef CONFIG_PM | |
1914 | .suspend = stmmac_suspend, | |
1915 | .resume = stmmac_resume, | |
1916 | #endif | |
1917 | ||
1918 | }; | |
1919 | ||
1920 | /** | |
1921 | * stmmac_init_module - Entry point for the driver | |
1922 | * Description: This function is the entry point for the driver. | |
1923 | */ | |
1924 | static int __init stmmac_init_module(void) | |
1925 | { | |
1926 | int ret; | |
1927 | ||
1928 | if (platform_driver_register(&stmmacphy_driver)) { | |
1929 | pr_err("No PHY devices registered!\n"); | |
1930 | return -ENODEV; | |
1931 | } | |
1932 | ||
1933 | ret = platform_driver_register(&stmmac_driver); | |
1934 | return ret; | |
1935 | } | |
1936 | ||
1937 | /** | |
1938 | * stmmac_cleanup_module - Cleanup routine for the driver | |
1939 | * Description: This function is the cleanup routine for the driver. | |
1940 | */ | |
1941 | static void __exit stmmac_cleanup_module(void) | |
1942 | { | |
1943 | platform_driver_unregister(&stmmacphy_driver); | |
1944 | platform_driver_unregister(&stmmac_driver); | |
1945 | } | |
1946 | ||
1947 | #ifndef MODULE | |
1948 | static int __init stmmac_cmdline_opt(char *str) | |
1949 | { | |
1950 | char *opt; | |
1951 | ||
1952 | if (!str || !*str) | |
1953 | return -EINVAL; | |
1954 | while ((opt = strsep(&str, ",")) != NULL) { | |
1955 | if (!strncmp(opt, "debug:", 6)) | |
1956 | strict_strtoul(opt + 6, 0, (unsigned long *)&debug); | |
1957 | else if (!strncmp(opt, "phyaddr:", 8)) | |
1958 | strict_strtoul(opt + 8, 0, (unsigned long *)&phyaddr); | |
1959 | else if (!strncmp(opt, "dma_txsize:", 11)) | |
1960 | strict_strtoul(opt + 11, 0, | |
1961 | (unsigned long *)&dma_txsize); | |
1962 | else if (!strncmp(opt, "dma_rxsize:", 11)) | |
1963 | strict_strtoul(opt + 11, 0, | |
1964 | (unsigned long *)&dma_rxsize); | |
1965 | else if (!strncmp(opt, "buf_sz:", 7)) | |
1966 | strict_strtoul(opt + 7, 0, (unsigned long *)&buf_sz); | |
1967 | else if (!strncmp(opt, "tc:", 3)) | |
1968 | strict_strtoul(opt + 3, 0, (unsigned long *)&tc); | |
47dd7a54 GC |
1969 | else if (!strncmp(opt, "watchdog:", 9)) |
1970 | strict_strtoul(opt + 9, 0, (unsigned long *)&watchdog); | |
1971 | else if (!strncmp(opt, "flow_ctrl:", 10)) | |
1972 | strict_strtoul(opt + 10, 0, | |
1973 | (unsigned long *)&flow_ctrl); | |
1974 | else if (!strncmp(opt, "pause:", 6)) | |
1975 | strict_strtoul(opt + 6, 0, (unsigned long *)&pause); | |
1976 | #ifdef CONFIG_STMMAC_TIMER | |
1977 | else if (!strncmp(opt, "tmrate:", 7)) | |
1978 | strict_strtoul(opt + 7, 0, (unsigned long *)&tmrate); | |
1979 | #endif | |
1980 | } | |
1981 | return 0; | |
1982 | } | |
1983 | ||
1984 | __setup("stmmaceth=", stmmac_cmdline_opt); | |
1985 | #endif | |
1986 | ||
1987 | module_init(stmmac_init_module); | |
1988 | module_exit(stmmac_cleanup_module); | |
1989 | ||
1990 | MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet driver"); | |
1991 | MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>"); | |
1992 | MODULE_LICENSE("GPL"); |