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