blob: 6906772069e33a7aed97b1323861a3c58dec4847 [file] [log] [blame]
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001/*******************************************************************************
2 This is the driver for the ST MAC 10/100/1000 on-chip Ethernet controllers.
3 ST Ethernet IPs are built around a Synopsys IP Core.
4
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +00005 Copyright(C) 2007-2011 STMicroelectronics Ltd
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07006
7 This program is free software; you can redistribute it and/or modify it
8 under the terms and conditions of the GNU General Public License,
9 version 2, as published by the Free Software Foundation.
10
11 This program is distributed in the hope it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details.
15
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19
20 The full GNU General Public License is included in this distribution in
21 the file called "COPYING".
22
23 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
24
25 Documentation available at:
26 http://www.stlinux.com
27 Support available at:
28 https://bugzilla.stlinux.com/
29*******************************************************************************/
30
Viresh Kumar6a81c262012-07-30 14:39:41 -070031#include <linux/clk.h>
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -070032#include <linux/kernel.h>
33#include <linux/interrupt.h>
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -070034#include <linux/ip.h>
35#include <linux/tcp.h>
36#include <linux/skbuff.h>
37#include <linux/ethtool.h>
38#include <linux/if_ether.h>
39#include <linux/crc32.h>
40#include <linux/mii.h>
Jiri Pirko01789342011-08-16 06:29:00 +000041#include <linux/if.h>
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -070042#include <linux/if_vlan.h>
43#include <linux/dma-mapping.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090044#include <linux/slab.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040045#include <linux/prefetch.h>
Giuseppe CAVALLARO7ac29052011-09-01 21:51:39 +000046#ifdef CONFIG_STMMAC_DEBUG_FS
47#include <linux/debugfs.h>
48#include <linux/seq_file.h>
49#endif
Rayagond Kokatanur891434b2013-03-26 04:43:10 +000050#include <linux/net_tstamp.h>
51#include "stmmac_ptp.h"
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +000052#include "stmmac.h"
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -070053
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -070054#undef STMMAC_DEBUG
55/*#define STMMAC_DEBUG*/
56#ifdef STMMAC_DEBUG
57#define DBG(nlevel, klevel, fmt, args...) \
58 ((void)(netif_msg_##nlevel(priv) && \
59 printk(KERN_##klevel fmt, ## args)))
60#else
61#define DBG(nlevel, klevel, fmt, args...) do { } while (0)
62#endif
63
64#undef STMMAC_RX_DEBUG
65/*#define STMMAC_RX_DEBUG*/
66#ifdef STMMAC_RX_DEBUG
67#define RX_DBG(fmt, args...) printk(fmt, ## args)
68#else
69#define RX_DBG(fmt, args...) do { } while (0)
70#endif
71
72#undef STMMAC_XMIT_DEBUG
73/*#define STMMAC_XMIT_DEBUG*/
Giuseppe CAVALLAROde53d552013-02-06 20:47:51 +000074#ifdef STMMAC_XMIT_DEBUG
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -070075#define TX_DBG(fmt, args...) printk(fmt, ## args)
76#else
77#define TX_DBG(fmt, args...) do { } while (0)
78#endif
79
80#define STMMAC_ALIGN(x) L1_CACHE_ALIGN(x)
81#define JUMBO_LEN 9000
82
83/* Module parameters */
84#define TX_TIMEO 5000 /* default 5 seconds */
85static int watchdog = TX_TIMEO;
86module_param(watchdog, int, S_IRUGO | S_IWUSR);
87MODULE_PARM_DESC(watchdog, "Transmit timeout in milliseconds");
88
89static int debug = -1; /* -1: default, 0: no output, 16: all */
90module_param(debug, int, S_IRUGO | S_IWUSR);
91MODULE_PARM_DESC(debug, "Message Level (0: no output, 16: all)");
92
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000093int phyaddr = -1;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -070094module_param(phyaddr, int, S_IRUGO);
95MODULE_PARM_DESC(phyaddr, "Physical device address");
96
97#define DMA_TX_SIZE 256
98static int dma_txsize = DMA_TX_SIZE;
99module_param(dma_txsize, int, S_IRUGO | S_IWUSR);
100MODULE_PARM_DESC(dma_txsize, "Number of descriptors in the TX list");
101
102#define DMA_RX_SIZE 256
103static int dma_rxsize = DMA_RX_SIZE;
104module_param(dma_rxsize, int, S_IRUGO | S_IWUSR);
105MODULE_PARM_DESC(dma_rxsize, "Number of descriptors in the RX list");
106
107static int flow_ctrl = FLOW_OFF;
108module_param(flow_ctrl, int, S_IRUGO | S_IWUSR);
109MODULE_PARM_DESC(flow_ctrl, "Flow control ability [on/off]");
110
111static int pause = PAUSE_TIME;
112module_param(pause, int, S_IRUGO | S_IWUSR);
113MODULE_PARM_DESC(pause, "Flow Control Pause Time");
114
115#define TC_DEFAULT 64
116static int tc = TC_DEFAULT;
117module_param(tc, int, S_IRUGO | S_IWUSR);
118MODULE_PARM_DESC(tc, "DMA threshold control value");
119
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700120#define DMA_BUFFER_SIZE BUF_SIZE_2KiB
121static int buf_sz = DMA_BUFFER_SIZE;
122module_param(buf_sz, int, S_IRUGO | S_IWUSR);
123MODULE_PARM_DESC(buf_sz, "DMA buffer size");
124
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700125static const u32 default_msg_level = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
126 NETIF_MSG_LINK | NETIF_MSG_IFUP |
127 NETIF_MSG_IFDOWN | NETIF_MSG_TIMER);
128
Giuseppe CAVALLAROd7659552012-06-27 21:14:37 +0000129#define STMMAC_DEFAULT_LPI_TIMER 1000
130static int eee_timer = STMMAC_DEFAULT_LPI_TIMER;
131module_param(eee_timer, int, S_IRUGO | S_IWUSR);
132MODULE_PARM_DESC(eee_timer, "LPI tx expiration time in msec");
133#define STMMAC_LPI_TIMER(x) (jiffies + msecs_to_jiffies(x))
134
Giuseppe CAVALLARO4a7d6662013-03-26 04:43:05 +0000135/* By default the driver will use the ring mode to manage tx and rx descriptors
136 * but passing this value so user can force to use the chain instead of the ring
137 */
138static unsigned int chain_mode;
139module_param(chain_mode, int, S_IRUGO);
140MODULE_PARM_DESC(chain_mode, "To use chain instead of ring mode");
141
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700142static irqreturn_t stmmac_interrupt(int irq, void *dev_id);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700143
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000144#ifdef CONFIG_STMMAC_DEBUG_FS
145static int stmmac_init_fs(struct net_device *dev);
146static void stmmac_exit_fs(void);
147#endif
148
Giuseppe CAVALLARO9125cdd2012-11-25 23:10:42 +0000149#define STMMAC_COAL_TIMER(x) (jiffies + usecs_to_jiffies(x))
150
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700151/**
152 * stmmac_verify_args - verify the driver parameters.
153 * Description: it verifies if some wrong parameter is passed to the driver.
154 * Note that wrong parameters are replaced with the default values.
155 */
156static void stmmac_verify_args(void)
157{
158 if (unlikely(watchdog < 0))
159 watchdog = TX_TIMEO;
160 if (unlikely(dma_rxsize < 0))
161 dma_rxsize = DMA_RX_SIZE;
162 if (unlikely(dma_txsize < 0))
163 dma_txsize = DMA_TX_SIZE;
164 if (unlikely((buf_sz < DMA_BUFFER_SIZE) || (buf_sz > BUF_SIZE_16KiB)))
165 buf_sz = DMA_BUFFER_SIZE;
166 if (unlikely(flow_ctrl > 1))
167 flow_ctrl = FLOW_AUTO;
168 else if (likely(flow_ctrl < 0))
169 flow_ctrl = FLOW_OFF;
170 if (unlikely((pause < 0) || (pause > 0xffff)))
171 pause = PAUSE_TIME;
Giuseppe CAVALLAROd7659552012-06-27 21:14:37 +0000172 if (eee_timer < 0)
173 eee_timer = STMMAC_DEFAULT_LPI_TIMER;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700174}
175
Giuseppe CAVALLAROcd7201f2012-04-04 04:33:27 +0000176static void stmmac_clk_csr_set(struct stmmac_priv *priv)
177{
Giuseppe CAVALLAROcd7201f2012-04-04 04:33:27 +0000178 u32 clk_rate;
179
180 clk_rate = clk_get_rate(priv->stmmac_clk);
181
182 /* Platform provided default clk_csr would be assumed valid
183 * for all other cases except for the below mentioned ones. */
184 if (!(priv->clk_csr & MAC_CSR_H_FRQ_MASK)) {
185 if (clk_rate < CSR_F_35M)
186 priv->clk_csr = STMMAC_CSR_20_35M;
187 else if ((clk_rate >= CSR_F_35M) && (clk_rate < CSR_F_60M))
188 priv->clk_csr = STMMAC_CSR_35_60M;
189 else if ((clk_rate >= CSR_F_60M) && (clk_rate < CSR_F_100M))
190 priv->clk_csr = STMMAC_CSR_60_100M;
191 else if ((clk_rate >= CSR_F_100M) && (clk_rate < CSR_F_150M))
192 priv->clk_csr = STMMAC_CSR_100_150M;
193 else if ((clk_rate >= CSR_F_150M) && (clk_rate < CSR_F_250M))
194 priv->clk_csr = STMMAC_CSR_150_250M;
195 else if ((clk_rate >= CSR_F_250M) && (clk_rate < CSR_F_300M))
196 priv->clk_csr = STMMAC_CSR_250_300M;
197 } /* For values higher than the IEEE 802.3 specified frequency
198 * we can not estimate the proper divider as it is not known
199 * the frequency of clk_csr_i. So we do not change the default
200 * divider. */
Giuseppe CAVALLAROcd7201f2012-04-04 04:33:27 +0000201}
202
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700203#if defined(STMMAC_XMIT_DEBUG) || defined(STMMAC_RX_DEBUG)
204static void print_pkt(unsigned char *buf, int len)
205{
206 int j;
207 pr_info("len = %d byte, buf addr: 0x%p", len, buf);
208 for (j = 0; j < len; j++) {
209 if ((j % 16) == 0)
210 pr_info("\n %03x:", j);
211 pr_info(" %02x", buf[j]);
212 }
213 pr_info("\n");
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700214}
215#endif
216
217/* minimum number of free TX descriptors required to wake up TX process */
218#define STMMAC_TX_THRESH(x) (x->dma_tx_size/4)
219
220static inline u32 stmmac_tx_avail(struct stmmac_priv *priv)
221{
222 return priv->dirty_tx + priv->dma_tx_size - priv->cur_tx - 1;
223}
224
Giuseppe CAVALLARO9dfeb4d2010-11-24 02:37:58 +0000225/* On some ST platforms, some HW system configuraton registers have to be
226 * set according to the link speed negotiated.
227 */
228static inline void stmmac_hw_fix_mac_speed(struct stmmac_priv *priv)
229{
230 struct phy_device *phydev = priv->phydev;
231
232 if (likely(priv->plat->fix_mac_speed))
233 priv->plat->fix_mac_speed(priv->plat->bsp_priv,
234 phydev->speed);
235}
236
Giuseppe CAVALLAROd7659552012-06-27 21:14:37 +0000237static void stmmac_enable_eee_mode(struct stmmac_priv *priv)
238{
239 /* Check and enter in LPI mode */
240 if ((priv->dirty_tx == priv->cur_tx) &&
241 (priv->tx_path_in_lpi_mode == false))
242 priv->hw->mac->set_eee_mode(priv->ioaddr);
243}
244
245void stmmac_disable_eee_mode(struct stmmac_priv *priv)
246{
247 /* Exit and disable EEE in case of we are are in LPI state. */
248 priv->hw->mac->reset_eee_mode(priv->ioaddr);
249 del_timer_sync(&priv->eee_ctrl_timer);
250 priv->tx_path_in_lpi_mode = false;
251}
252
253/**
254 * stmmac_eee_ctrl_timer
255 * @arg : data hook
256 * Description:
257 * If there is no data transfer and if we are not in LPI state,
258 * then MAC Transmitter can be moved to LPI state.
259 */
260static void stmmac_eee_ctrl_timer(unsigned long arg)
261{
262 struct stmmac_priv *priv = (struct stmmac_priv *)arg;
263
264 stmmac_enable_eee_mode(priv);
265 mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_TIMER(eee_timer));
266}
267
268/**
269 * stmmac_eee_init
270 * @priv: private device pointer
271 * Description:
272 * If the EEE support has been enabled while configuring the driver,
273 * if the GMAC actually supports the EEE (from the HW cap reg) and the
274 * phy can also manage EEE, so enable the LPI state and start the timer
275 * to verify if the tx path can enter in LPI state.
276 */
277bool stmmac_eee_init(struct stmmac_priv *priv)
278{
279 bool ret = false;
280
281 /* MAC core supports the EEE feature. */
282 if (priv->dma_cap.eee) {
283 /* Check if the PHY supports EEE */
284 if (phy_init_eee(priv->phydev, 1))
285 goto out;
286
287 priv->eee_active = 1;
288 init_timer(&priv->eee_ctrl_timer);
289 priv->eee_ctrl_timer.function = stmmac_eee_ctrl_timer;
290 priv->eee_ctrl_timer.data = (unsigned long)priv;
291 priv->eee_ctrl_timer.expires = STMMAC_LPI_TIMER(eee_timer);
292 add_timer(&priv->eee_ctrl_timer);
293
294 priv->hw->mac->set_eee_timer(priv->ioaddr,
295 STMMAC_DEFAULT_LIT_LS_TIMER,
296 priv->tx_lpi_timer);
297
298 pr_info("stmmac: Energy-Efficient Ethernet initialized\n");
299
300 ret = true;
301 }
302out:
303 return ret;
304}
305
306static void stmmac_eee_adjust(struct stmmac_priv *priv)
307{
308 /* When the EEE has been already initialised we have to
309 * modify the PLS bit in the LPI ctrl & status reg according
310 * to the PHY link status. For this reason.
311 */
312 if (priv->eee_enabled)
313 priv->hw->mac->set_eee_pls(priv->ioaddr, priv->phydev->link);
314}
315
Rayagond Kokatanur891434b2013-03-26 04:43:10 +0000316/* stmmac_get_tx_hwtstamp:
317 * @priv : pointer to private device structure.
318 * @entry : descriptor index to be used.
319 * @skb : the socket buffer
320 * Description :
321 * This function will read timestamp from the descriptor & pass it to stack.
322 * and also perform some sanity checks.
323 */
324static void stmmac_get_tx_hwtstamp(struct stmmac_priv *priv,
325 unsigned int entry,
326 struct sk_buff *skb)
327{
328 struct skb_shared_hwtstamps shhwtstamp;
329 u64 ns;
330 void *desc = NULL;
331
332 if (!priv->hwts_tx_en)
333 return;
334
335 /* if skb doesn't support hw tstamp */
336 if (likely(!(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)))
337 return;
338
339 if (priv->adv_ts)
340 desc = (priv->dma_etx + entry);
341 else
342 desc = (priv->dma_tx + entry);
343
344 /* check tx tstamp status */
345 if (!priv->hw->desc->get_tx_timestamp_status((struct dma_desc *)desc))
346 return;
347
348 /* get the valid tstamp */
349 ns = priv->hw->desc->get_timestamp(desc, priv->adv_ts);
350
351 memset(&shhwtstamp, 0, sizeof(struct skb_shared_hwtstamps));
352 shhwtstamp.hwtstamp = ns_to_ktime(ns);
353 /* pass tstamp to stack */
354 skb_tstamp_tx(skb, &shhwtstamp);
355
356 return;
357}
358
359/* stmmac_get_rx_hwtstamp:
360 * @priv : pointer to private device structure.
361 * @entry : descriptor index to be used.
362 * @skb : the socket buffer
363 * Description :
364 * This function will read received packet's timestamp from the descriptor
365 * and pass it to stack. It also perform some sanity checks.
366 */
367static void stmmac_get_rx_hwtstamp(struct stmmac_priv *priv,
368 unsigned int entry,
369 struct sk_buff *skb)
370{
371 struct skb_shared_hwtstamps *shhwtstamp = NULL;
372 u64 ns;
373 void *desc = NULL;
374
375 if (!priv->hwts_rx_en)
376 return;
377
378 if (priv->adv_ts)
379 desc = (priv->dma_erx + entry);
380 else
381 desc = (priv->dma_rx + entry);
382
383 /* if rx tstamp is not valid */
384 if (!priv->hw->desc->get_rx_timestamp_status(desc, priv->adv_ts))
385 return;
386
387 /* get valid tstamp */
388 ns = priv->hw->desc->get_timestamp(desc, priv->adv_ts);
389 shhwtstamp = skb_hwtstamps(skb);
390 memset(shhwtstamp, 0, sizeof(struct skb_shared_hwtstamps));
391 shhwtstamp->hwtstamp = ns_to_ktime(ns);
392}
393
394/**
395 * stmmac_hwtstamp_ioctl - control hardware timestamping.
396 * @dev: device pointer.
397 * @ifr: An IOCTL specefic structure, that can contain a pointer to
398 * a proprietary structure used to pass information to the driver.
399 * Description:
400 * This function configures the MAC to enable/disable both outgoing(TX)
401 * and incoming(RX) packets time stamping based on user input.
402 * Return Value:
403 * 0 on success and an appropriate -ve integer on failure.
404 */
405static int stmmac_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
406{
407 struct stmmac_priv *priv = netdev_priv(dev);
408 struct hwtstamp_config config;
409 struct timespec now;
410 u64 temp = 0;
411 u32 ptp_v2 = 0;
412 u32 tstamp_all = 0;
413 u32 ptp_over_ipv4_udp = 0;
414 u32 ptp_over_ipv6_udp = 0;
415 u32 ptp_over_ethernet = 0;
416 u32 snap_type_sel = 0;
417 u32 ts_master_en = 0;
418 u32 ts_event_en = 0;
419 u32 value = 0;
420
421 if (!(priv->dma_cap.time_stamp || priv->adv_ts)) {
422 netdev_alert(priv->dev, "No support for HW time stamping\n");
423 priv->hwts_tx_en = 0;
424 priv->hwts_rx_en = 0;
425
426 return -EOPNOTSUPP;
427 }
428
429 if (copy_from_user(&config, ifr->ifr_data,
430 sizeof(struct hwtstamp_config)))
431 return -EFAULT;
432
433 pr_debug("%s config flags:0x%x, tx_type:0x%x, rx_filter:0x%x\n",
434 __func__, config.flags, config.tx_type, config.rx_filter);
435
436 /* reserved for future extensions */
437 if (config.flags)
438 return -EINVAL;
439
440 switch (config.tx_type) {
441 case HWTSTAMP_TX_OFF:
442 priv->hwts_tx_en = 0;
443 break;
444 case HWTSTAMP_TX_ON:
445 priv->hwts_tx_en = 1;
446 break;
447 default:
448 return -ERANGE;
449 }
450
451 if (priv->adv_ts) {
452 switch (config.rx_filter) {
453 /* time stamp no incoming packet at all */
454 case HWTSTAMP_FILTER_NONE:
455 config.rx_filter = HWTSTAMP_FILTER_NONE;
456 break;
457
458 /* PTP v1, UDP, any kind of event packet */
459 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
460 config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
461 /* take time stamp for all event messages */
462 snap_type_sel = PTP_TCR_SNAPTYPSEL_1;
463
464 ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
465 ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
466 break;
467
468 /* PTP v1, UDP, Sync packet */
469 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
470 config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_SYNC;
471 /* take time stamp for SYNC messages only */
472 ts_event_en = PTP_TCR_TSEVNTENA;
473
474 ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
475 ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
476 break;
477
478 /* PTP v1, UDP, Delay_req packet */
479 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
480 config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ;
481 /* take time stamp for Delay_Req messages only */
482 ts_master_en = PTP_TCR_TSMSTRENA;
483 ts_event_en = PTP_TCR_TSEVNTENA;
484
485 ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
486 ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
487 break;
488
489 /* PTP v2, UDP, any kind of event packet */
490 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
491 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT;
492 ptp_v2 = PTP_TCR_TSVER2ENA;
493 /* take time stamp for all event messages */
494 snap_type_sel = PTP_TCR_SNAPTYPSEL_1;
495
496 ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
497 ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
498 break;
499
500 /* PTP v2, UDP, Sync packet */
501 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
502 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_SYNC;
503 ptp_v2 = PTP_TCR_TSVER2ENA;
504 /* take time stamp for SYNC messages only */
505 ts_event_en = PTP_TCR_TSEVNTENA;
506
507 ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
508 ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
509 break;
510
511 /* PTP v2, UDP, Delay_req packet */
512 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
513 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ;
514 ptp_v2 = PTP_TCR_TSVER2ENA;
515 /* take time stamp for Delay_Req messages only */
516 ts_master_en = PTP_TCR_TSMSTRENA;
517 ts_event_en = PTP_TCR_TSEVNTENA;
518
519 ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
520 ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
521 break;
522
523 /* PTP v2/802.AS1, any layer, any kind of event packet */
524 case HWTSTAMP_FILTER_PTP_V2_EVENT:
525 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
526 ptp_v2 = PTP_TCR_TSVER2ENA;
527 /* take time stamp for all event messages */
528 snap_type_sel = PTP_TCR_SNAPTYPSEL_1;
529
530 ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
531 ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
532 ptp_over_ethernet = PTP_TCR_TSIPENA;
533 break;
534
535 /* PTP v2/802.AS1, any layer, Sync packet */
536 case HWTSTAMP_FILTER_PTP_V2_SYNC:
537 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_SYNC;
538 ptp_v2 = PTP_TCR_TSVER2ENA;
539 /* take time stamp for SYNC messages only */
540 ts_event_en = PTP_TCR_TSEVNTENA;
541
542 ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
543 ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
544 ptp_over_ethernet = PTP_TCR_TSIPENA;
545 break;
546
547 /* PTP v2/802.AS1, any layer, Delay_req packet */
548 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
549 config.rx_filter = HWTSTAMP_FILTER_PTP_V2_DELAY_REQ;
550 ptp_v2 = PTP_TCR_TSVER2ENA;
551 /* take time stamp for Delay_Req messages only */
552 ts_master_en = PTP_TCR_TSMSTRENA;
553 ts_event_en = PTP_TCR_TSEVNTENA;
554
555 ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
556 ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
557 ptp_over_ethernet = PTP_TCR_TSIPENA;
558 break;
559
560 /* time stamp any incoming packet */
561 case HWTSTAMP_FILTER_ALL:
562 config.rx_filter = HWTSTAMP_FILTER_ALL;
563 tstamp_all = PTP_TCR_TSENALL;
564 break;
565
566 default:
567 return -ERANGE;
568 }
569 } else {
570 switch (config.rx_filter) {
571 case HWTSTAMP_FILTER_NONE:
572 config.rx_filter = HWTSTAMP_FILTER_NONE;
573 break;
574 default:
575 /* PTP v1, UDP, any kind of event packet */
576 config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
577 break;
578 }
579 }
580 priv->hwts_rx_en = ((config.rx_filter == HWTSTAMP_FILTER_NONE) ? 0 : 1);
581
582 if (!priv->hwts_tx_en && !priv->hwts_rx_en)
583 priv->hw->ptp->config_hw_tstamping(priv->ioaddr, 0);
584 else {
585 value = (PTP_TCR_TSENA | PTP_TCR_TSCFUPDT | PTP_TCR_TSCTRLSSR |
586 tstamp_all | ptp_v2 | ptp_over_ethernet |
587 ptp_over_ipv6_udp | ptp_over_ipv4_udp | ts_event_en |
588 ts_master_en | snap_type_sel);
589
590 priv->hw->ptp->config_hw_tstamping(priv->ioaddr, value);
591
592 /* program Sub Second Increment reg */
593 priv->hw->ptp->config_sub_second_increment(priv->ioaddr);
594
595 /* calculate default added value:
596 * formula is :
597 * addend = (2^32)/freq_div_ratio;
598 * where, freq_div_ratio = STMMAC_SYSCLOCK/50MHz
599 * hence, addend = ((2^32) * 50MHz)/STMMAC_SYSCLOCK;
600 * NOTE: STMMAC_SYSCLOCK should be >= 50MHz to
601 * achive 20ns accuracy.
602 *
603 * 2^x * y == (y << x), hence
604 * 2^32 * 50000000 ==> (50000000 << 32)
605 */
606 temp = (u64)(50000000ULL << 32);
607 priv->default_addend = div_u64(temp, STMMAC_SYSCLOCK);
608 priv->hw->ptp->config_addend(priv->ioaddr,
609 priv->default_addend);
610
611 /* initialize system time */
612 getnstimeofday(&now);
613 priv->hw->ptp->init_systime(priv->ioaddr, now.tv_sec,
614 now.tv_nsec);
615 }
616
617 return copy_to_user(ifr->ifr_data, &config,
618 sizeof(struct hwtstamp_config)) ? -EFAULT : 0;
619}
620
621static void stmmac_init_ptp(struct stmmac_priv *priv)
622{
623 if (priv->dma_cap.time_stamp) {
624 pr_debug("IEEE 1588-2002 Time Stamp supported\n");
625 priv->adv_ts = 0;
626 }
627 if (priv->dma_cap.atime_stamp && priv->extend_desc) {
628 pr_debug("IEEE 1588-2008 Advanced Time Stamp supported\n");
629 priv->adv_ts = 1;
630 }
631
632 priv->hw->ptp = &stmmac_ptp;
633 priv->hwts_tx_en = 0;
634 priv->hwts_rx_en = 0;
635}
636
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700637/**
638 * stmmac_adjust_link
639 * @dev: net device structure
640 * Description: it adjusts the link parameters.
641 */
642static void stmmac_adjust_link(struct net_device *dev)
643{
644 struct stmmac_priv *priv = netdev_priv(dev);
645 struct phy_device *phydev = priv->phydev;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700646 unsigned long flags;
647 int new_state = 0;
648 unsigned int fc = priv->flow_ctrl, pause_time = priv->pause;
649
650 if (phydev == NULL)
651 return;
652
653 DBG(probe, DEBUG, "stmmac_adjust_link: called. address %d link %d\n",
654 phydev->addr, phydev->link);
655
656 spin_lock_irqsave(&priv->lock, flags);
Giuseppe CAVALLAROd7659552012-06-27 21:14:37 +0000657
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700658 if (phydev->link) {
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +0000659 u32 ctrl = readl(priv->ioaddr + MAC_CTRL_REG);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700660
661 /* Now we make sure that we can be in full duplex mode.
662 * If not, we operate in half-duplex mode. */
663 if (phydev->duplex != priv->oldduplex) {
664 new_state = 1;
665 if (!(phydev->duplex))
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +0000666 ctrl &= ~priv->hw->link.duplex;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700667 else
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +0000668 ctrl |= priv->hw->link.duplex;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700669 priv->oldduplex = phydev->duplex;
670 }
671 /* Flow Control operation */
672 if (phydev->pause)
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +0000673 priv->hw->mac->flow_ctrl(priv->ioaddr, phydev->duplex,
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +0000674 fc, pause_time);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700675
676 if (phydev->speed != priv->speed) {
677 new_state = 1;
678 switch (phydev->speed) {
679 case 1000:
Giuseppe CAVALLARO9dfeb4d2010-11-24 02:37:58 +0000680 if (likely(priv->plat->has_gmac))
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +0000681 ctrl &= ~priv->hw->link.port;
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +0000682 stmmac_hw_fix_mac_speed(priv);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700683 break;
684 case 100:
685 case 10:
Giuseppe CAVALLARO9dfeb4d2010-11-24 02:37:58 +0000686 if (priv->plat->has_gmac) {
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +0000687 ctrl |= priv->hw->link.port;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700688 if (phydev->speed == SPEED_100) {
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +0000689 ctrl |= priv->hw->link.speed;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700690 } else {
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +0000691 ctrl &= ~(priv->hw->link.speed);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700692 }
693 } else {
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +0000694 ctrl &= ~priv->hw->link.port;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700695 }
Giuseppe CAVALLARO9dfeb4d2010-11-24 02:37:58 +0000696 stmmac_hw_fix_mac_speed(priv);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700697 break;
698 default:
699 if (netif_msg_link(priv))
700 pr_warning("%s: Speed (%d) is not 10"
701 " or 100!\n", dev->name, phydev->speed);
702 break;
703 }
704
705 priv->speed = phydev->speed;
706 }
707
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +0000708 writel(ctrl, priv->ioaddr + MAC_CTRL_REG);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700709
710 if (!priv->oldlink) {
711 new_state = 1;
712 priv->oldlink = 1;
713 }
714 } else if (priv->oldlink) {
715 new_state = 1;
716 priv->oldlink = 0;
717 priv->speed = 0;
718 priv->oldduplex = -1;
719 }
720
721 if (new_state && netif_msg_link(priv))
722 phy_print_status(phydev);
723
Giuseppe CAVALLAROd7659552012-06-27 21:14:37 +0000724 stmmac_eee_adjust(priv);
725
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700726 spin_unlock_irqrestore(&priv->lock, flags);
727
728 DBG(probe, DEBUG, "stmmac_adjust_link: exiting\n");
729}
730
Giuseppe CAVALLAROe58bb432013-03-26 04:43:08 +0000731static void stmmac_check_pcs_mode(struct stmmac_priv *priv)
732{
733 int interface = priv->plat->interface;
734
735 if (priv->dma_cap.pcs) {
736 if ((interface & PHY_INTERFACE_MODE_RGMII) ||
737 (interface & PHY_INTERFACE_MODE_RGMII_ID) ||
738 (interface & PHY_INTERFACE_MODE_RGMII_RXID) ||
739 (interface & PHY_INTERFACE_MODE_RGMII_TXID)) {
740 pr_debug("STMMAC: PCS RGMII support enable\n");
741 priv->pcs = STMMAC_PCS_RGMII;
742 } else if (interface & PHY_INTERFACE_MODE_SGMII) {
743 pr_debug("STMMAC: PCS SGMII support enable\n");
744 priv->pcs = STMMAC_PCS_SGMII;
745 }
746 }
747}
748
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700749/**
750 * stmmac_init_phy - PHY initialization
751 * @dev: net device structure
752 * Description: it initializes the driver's PHY state, and attaches the PHY
753 * to the mac driver.
754 * Return value:
755 * 0 on success
756 */
757static int stmmac_init_phy(struct net_device *dev)
758{
759 struct stmmac_priv *priv = netdev_priv(dev);
760 struct phy_device *phydev;
Giuseppe CAVALLAROd7659552012-06-27 21:14:37 +0000761 char phy_id_fmt[MII_BUS_ID_SIZE + 3];
Giuseppe CAVALLARO109cdd62010-01-06 23:07:11 +0000762 char bus_id[MII_BUS_ID_SIZE];
Srinivas Kandagatla79ee1dc2011-10-18 00:01:18 +0000763 int interface = priv->plat->interface;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700764 priv->oldlink = 0;
765 priv->speed = 0;
766 priv->oldduplex = -1;
767
Srinivas Kandagatlaf142af22012-04-04 04:33:19 +0000768 if (priv->plat->phy_bus_name)
769 snprintf(bus_id, MII_BUS_ID_SIZE, "%s-%x",
770 priv->plat->phy_bus_name, priv->plat->bus_id);
771 else
772 snprintf(bus_id, MII_BUS_ID_SIZE, "stmmac-%x",
773 priv->plat->bus_id);
774
Giuseppe CAVALLAROd7659552012-06-27 21:14:37 +0000775 snprintf(phy_id_fmt, MII_BUS_ID_SIZE + 3, PHY_ID_FMT, bus_id,
Giuseppe CAVALLARO36bcfe72011-07-20 00:05:23 +0000776 priv->plat->phy_addr);
Giuseppe CAVALLAROd7659552012-06-27 21:14:37 +0000777 pr_debug("stmmac_init_phy: trying to attach to %s\n", phy_id_fmt);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700778
Florian Fainellif9a8f832013-01-14 00:52:52 +0000779 phydev = phy_connect(dev, phy_id_fmt, &stmmac_adjust_link, interface);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700780
781 if (IS_ERR(phydev)) {
782 pr_err("%s: Could not attach to PHY\n", dev->name);
783 return PTR_ERR(phydev);
784 }
785
Srinivas Kandagatla79ee1dc2011-10-18 00:01:18 +0000786 /* Stop Advertising 1000BASE Capability if interface is not GMII */
Srinivas Kandagatlac5b9b4e2011-11-16 21:57:59 +0000787 if ((interface == PHY_INTERFACE_MODE_MII) ||
788 (interface == PHY_INTERFACE_MODE_RMII))
789 phydev->advertising &= ~(SUPPORTED_1000baseT_Half |
790 SUPPORTED_1000baseT_Full);
Srinivas Kandagatla79ee1dc2011-10-18 00:01:18 +0000791
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700792 /*
793 * Broken HW is sometimes missing the pull-up resistor on the
794 * MDIO line, which results in reads to non-existent devices returning
795 * 0 rather than 0xffff. Catch this here and treat 0 as a non-existent
796 * device as well.
797 * Note: phydev->phy_id is the result of reading the UID PHY registers.
798 */
799 if (phydev->phy_id == 0) {
800 phy_disconnect(phydev);
801 return -ENODEV;
802 }
803 pr_debug("stmmac_init_phy: %s: attached to PHY (UID 0x%x)"
Giuseppe CAVALLARO36bcfe72011-07-20 00:05:23 +0000804 " Link = %d\n", dev->name, phydev->phy_id, phydev->link);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700805
806 priv->phydev = phydev;
807
808 return 0;
809}
810
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700811/**
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +0000812 * stmmac_display_ring
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700813 * @p: pointer to the ring.
814 * @size: size of the ring.
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +0000815 * Description: display the control/status and buffer descriptors.
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700816 */
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +0000817static void stmmac_display_ring(void *head, int size, int extend_desc)
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700818{
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700819 int i;
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +0000820 struct dma_extended_desc *ep = (struct dma_extended_desc *) head;
821 struct dma_desc *p = (struct dma_desc *) head;
822
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700823 for (i = 0; i < size; i++) {
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +0000824 u64 x;
825 if (extend_desc) {
826 x = *(u64 *) ep;
827 pr_info("%d [0x%x]: 0x%x 0x%x 0x%x 0x%x\n",
828 i, (unsigned int) virt_to_phys(ep),
829 (unsigned int) x, (unsigned int) (x >> 32),
830 ep->basic.des2, ep->basic.des3);
831 ep++;
832 } else {
833 x = *(u64 *) p;
834 pr_info("%d [0x%x]: 0x%x 0x%x 0x%x 0x%x",
835 i, (unsigned int) virt_to_phys(p),
836 (unsigned int) x, (unsigned int) (x >> 32),
837 p->des2, p->des3);
838 p++;
839 }
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700840 pr_info("\n");
841 }
842}
843
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +0000844static void stmmac_display_rings(struct stmmac_priv *priv)
845{
846 unsigned int txsize = priv->dma_tx_size;
847 unsigned int rxsize = priv->dma_rx_size;
848
849 if (priv->extend_desc) {
850 pr_info("Extended RX descriptor ring:\n");
851 stmmac_display_ring((void *) priv->dma_erx, rxsize, 1);
852 pr_info("Extended TX descriptor ring:\n");
853 stmmac_display_ring((void *) priv->dma_etx, txsize, 1);
854 } else {
855 pr_info("RX descriptor ring:\n");
856 stmmac_display_ring((void *)priv->dma_rx, rxsize, 0);
857 pr_info("TX descriptor ring:\n");
858 stmmac_display_ring((void *)priv->dma_tx, txsize, 0);
859 }
860}
861
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +0000862static int stmmac_set_bfsize(int mtu, int bufsize)
863{
864 int ret = bufsize;
865
866 if (mtu >= BUF_SIZE_4KiB)
867 ret = BUF_SIZE_8KiB;
868 else if (mtu >= BUF_SIZE_2KiB)
869 ret = BUF_SIZE_4KiB;
870 else if (mtu >= DMA_BUFFER_SIZE)
871 ret = BUF_SIZE_2KiB;
872 else
873 ret = DMA_BUFFER_SIZE;
874
875 return ret;
876}
877
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +0000878static void stmmac_clear_descriptors(struct stmmac_priv *priv)
879{
880 int i;
881 unsigned int txsize = priv->dma_tx_size;
882 unsigned int rxsize = priv->dma_rx_size;
883
884 /* Clear the Rx/Tx descriptors */
885 for (i = 0; i < rxsize; i++)
886 if (priv->extend_desc)
887 priv->hw->desc->init_rx_desc(&priv->dma_erx[i].basic,
888 priv->use_riwt, priv->mode,
889 (i == rxsize - 1));
890 else
891 priv->hw->desc->init_rx_desc(&priv->dma_rx[i],
892 priv->use_riwt, priv->mode,
893 (i == rxsize - 1));
894 for (i = 0; i < txsize; i++)
895 if (priv->extend_desc)
896 priv->hw->desc->init_tx_desc(&priv->dma_etx[i].basic,
897 priv->mode,
898 (i == txsize - 1));
899 else
900 priv->hw->desc->init_tx_desc(&priv->dma_tx[i],
901 priv->mode,
902 (i == txsize - 1));
903}
904
905static int stmmac_init_rx_buffers(struct stmmac_priv *priv, struct dma_desc *p,
906 int i)
907{
908 struct sk_buff *skb;
909
910 skb = __netdev_alloc_skb(priv->dev, priv->dma_buf_sz + NET_IP_ALIGN,
911 GFP_KERNEL);
912 if (unlikely(skb == NULL)) {
913 pr_err("%s: Rx init fails; skb is NULL\n", __func__);
914 return 1;
915 }
916 skb_reserve(skb, NET_IP_ALIGN);
917 priv->rx_skbuff[i] = skb;
918 priv->rx_skbuff_dma[i] = dma_map_single(priv->device, skb->data,
919 priv->dma_buf_sz,
920 DMA_FROM_DEVICE);
921
922 p->des2 = priv->rx_skbuff_dma[i];
923
924 if ((priv->mode == STMMAC_RING_MODE) &&
925 (priv->dma_buf_sz == BUF_SIZE_16KiB))
926 priv->hw->ring->init_desc3(p);
927
928 return 0;
929}
930
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700931/**
932 * init_dma_desc_rings - init the RX/TX descriptor rings
933 * @dev: net device structure
934 * Description: this function initializes the DMA RX/TX descriptors
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +0000935 * and allocates the socket buffers. It suppors the chained and ring
936 * modes.
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700937 */
938static void init_dma_desc_rings(struct net_device *dev)
939{
940 int i;
941 struct stmmac_priv *priv = netdev_priv(dev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700942 unsigned int txsize = priv->dma_tx_size;
943 unsigned int rxsize = priv->dma_rx_size;
Giuseppe CAVALLARO4a7d6662013-03-26 04:43:05 +0000944 unsigned int bfsize = 0;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700945
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +0000946 /* Set the max buffer size according to the DESC mode
947 * and the MTU. Note that RING mode allows 16KiB bsize. */
Giuseppe CAVALLARO4a7d6662013-03-26 04:43:05 +0000948 if (priv->mode == STMMAC_RING_MODE)
949 bfsize = priv->hw->ring->set_16kib_bfsize(dev->mtu);
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +0000950
Giuseppe CAVALLARO4a7d6662013-03-26 04:43:05 +0000951 if (bfsize < BUF_SIZE_16KiB)
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +0000952 bfsize = stmmac_set_bfsize(dev->mtu, priv->dma_buf_sz);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700953
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700954 DBG(probe, INFO, "stmmac: txsize %d, rxsize %d, bfsize %d\n",
955 txsize, rxsize, bfsize);
956
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +0000957 if (priv->extend_desc) {
958 priv->dma_erx = dma_alloc_coherent(priv->device, rxsize *
959 sizeof(struct
960 dma_extended_desc),
961 &priv->dma_rx_phy,
962 GFP_KERNEL);
963 priv->dma_etx = dma_alloc_coherent(priv->device, txsize *
964 sizeof(struct
965 dma_extended_desc),
966 &priv->dma_tx_phy,
967 GFP_KERNEL);
968 if ((!priv->dma_erx) || (!priv->dma_etx))
969 return;
970 } else {
971 priv->dma_rx = dma_alloc_coherent(priv->device, rxsize *
972 sizeof(struct dma_desc),
973 &priv->dma_rx_phy,
974 GFP_KERNEL);
975 priv->dma_tx = dma_alloc_coherent(priv->device, txsize *
976 sizeof(struct dma_desc),
977 &priv->dma_tx_phy,
978 GFP_KERNEL);
979 if ((!priv->dma_rx) || (!priv->dma_tx))
980 return;
981 }
982
Joe Perchesb2adaca2013-02-03 17:43:58 +0000983 priv->rx_skbuff_dma = kmalloc_array(rxsize, sizeof(dma_addr_t),
984 GFP_KERNEL);
985 priv->rx_skbuff = kmalloc_array(rxsize, sizeof(struct sk_buff *),
986 GFP_KERNEL);
Rayagond Kokatanurcf32dee2013-03-26 04:43:09 +0000987 priv->tx_skbuff_dma = kmalloc_array(txsize, sizeof(dma_addr_t),
988 GFP_KERNEL);
Joe Perchesb2adaca2013-02-03 17:43:58 +0000989 priv->tx_skbuff = kmalloc_array(txsize, sizeof(struct sk_buff *),
990 GFP_KERNEL);
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +0000991 if (netif_msg_drv(priv))
992 pr_debug("(%s) dma_rx_phy=0x%08x dma_tx_phy=0x%08x\n", __func__,
993 (u32) priv->dma_rx_phy, (u32) priv->dma_tx_phy);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700994
995 /* RX INITIALIZATION */
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +0000996 DBG(probe, INFO, "stmmac: SKB addresses:\nskb\t\tskb data\tdma data\n");
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -0700997 for (i = 0; i < rxsize; i++) {
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +0000998 struct dma_desc *p;
999 if (priv->extend_desc)
1000 p = &((priv->dma_erx + i)->basic);
1001 else
1002 p = priv->dma_rx + i;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001003
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001004 if (stmmac_init_rx_buffers(priv, p, i))
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001005 break;
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +00001006
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001007 DBG(probe, INFO, "[%p]\t[%p]\t[%x]\n", priv->rx_skbuff[i],
1008 priv->rx_skbuff[i]->data, priv->rx_skbuff_dma[i]);
1009 }
1010 priv->cur_rx = 0;
1011 priv->dirty_rx = (unsigned int)(i - rxsize);
1012 priv->dma_buf_sz = bfsize;
1013 buf_sz = bfsize;
1014
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001015 /* Setup the chained descriptor addresses */
1016 if (priv->mode == STMMAC_CHAIN_MODE) {
1017 if (priv->extend_desc) {
1018 priv->hw->chain->init(priv->dma_erx, priv->dma_rx_phy,
1019 rxsize, 1);
1020 priv->hw->chain->init(priv->dma_etx, priv->dma_tx_phy,
1021 txsize, 1);
1022 } else {
1023 priv->hw->chain->init(priv->dma_rx, priv->dma_rx_phy,
1024 rxsize, 0);
1025 priv->hw->chain->init(priv->dma_tx, priv->dma_tx_phy,
1026 txsize, 0);
1027 }
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001028 }
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +00001029
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001030 /* TX INITIALIZATION */
1031 for (i = 0; i < txsize; i++) {
1032 struct dma_desc *p;
1033 if (priv->extend_desc)
1034 p = &((priv->dma_etx + i)->basic);
1035 else
1036 p = priv->dma_tx + i;
1037 p->des2 = 0;
Rayagond Kokatanurcf32dee2013-03-26 04:43:09 +00001038 priv->tx_skbuff_dma[i] = 0;
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001039 priv->tx_skbuff[i] = NULL;
Giuseppe CAVALLARO4a7d6662013-03-26 04:43:05 +00001040 }
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001041
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001042 priv->dirty_tx = 0;
1043 priv->cur_tx = 0;
1044
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001045 stmmac_clear_descriptors(priv);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001046
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001047 if (netif_msg_hw(priv))
1048 stmmac_display_rings(priv);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001049}
1050
1051static void dma_free_rx_skbufs(struct stmmac_priv *priv)
1052{
1053 int i;
1054
1055 for (i = 0; i < priv->dma_rx_size; i++) {
1056 if (priv->rx_skbuff[i]) {
1057 dma_unmap_single(priv->device, priv->rx_skbuff_dma[i],
1058 priv->dma_buf_sz, DMA_FROM_DEVICE);
1059 dev_kfree_skb_any(priv->rx_skbuff[i]);
1060 }
1061 priv->rx_skbuff[i] = NULL;
1062 }
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001063}
1064
1065static void dma_free_tx_skbufs(struct stmmac_priv *priv)
1066{
1067 int i;
1068
1069 for (i = 0; i < priv->dma_tx_size; i++) {
1070 if (priv->tx_skbuff[i] != NULL) {
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001071 struct dma_desc *p;
1072 if (priv->extend_desc)
1073 p = &((priv->dma_etx + i)->basic);
1074 else
1075 p = priv->dma_tx + i;
1076
Rayagond Kokatanurcf32dee2013-03-26 04:43:09 +00001077 if (priv->tx_skbuff_dma[i])
1078 dma_unmap_single(priv->device,
1079 priv->tx_skbuff_dma[i],
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +00001080 priv->hw->desc->get_tx_len(p),
1081 DMA_TO_DEVICE);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001082 dev_kfree_skb_any(priv->tx_skbuff[i]);
1083 priv->tx_skbuff[i] = NULL;
Rayagond Kokatanurcf32dee2013-03-26 04:43:09 +00001084 priv->tx_skbuff_dma[i] = 0;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001085 }
1086 }
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001087}
1088
1089static void free_dma_desc_resources(struct stmmac_priv *priv)
1090{
1091 /* Release the DMA TX/RX socket buffers */
1092 dma_free_rx_skbufs(priv);
1093 dma_free_tx_skbufs(priv);
1094
1095 /* Free the region of consistent memory previously allocated for
1096 * the DMA */
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001097 if (!priv->extend_desc) {
1098 dma_free_coherent(priv->device,
1099 priv->dma_tx_size * sizeof(struct dma_desc),
1100 priv->dma_tx, priv->dma_tx_phy);
1101 dma_free_coherent(priv->device,
1102 priv->dma_rx_size * sizeof(struct dma_desc),
1103 priv->dma_rx, priv->dma_rx_phy);
1104 } else {
1105 dma_free_coherent(priv->device, priv->dma_tx_size *
1106 sizeof(struct dma_extended_desc),
1107 priv->dma_etx, priv->dma_tx_phy);
1108 dma_free_coherent(priv->device, priv->dma_rx_size *
1109 sizeof(struct dma_extended_desc),
1110 priv->dma_erx, priv->dma_rx_phy);
1111 }
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001112 kfree(priv->rx_skbuff_dma);
1113 kfree(priv->rx_skbuff);
Rayagond Kokatanurcf32dee2013-03-26 04:43:09 +00001114 kfree(priv->tx_skbuff_dma);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001115 kfree(priv->tx_skbuff);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001116}
1117
1118/**
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001119 * stmmac_dma_operation_mode - HW DMA operation mode
1120 * @priv : pointer to the private device structure.
1121 * Description: it sets the DMA operation mode: tx/rx DMA thresholds
Giuseppe CAVALLAROebbb2932010-09-17 03:23:40 +00001122 * or Store-And-Forward capability.
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001123 */
1124static void stmmac_dma_operation_mode(struct stmmac_priv *priv)
1125{
Srinivas Kandagatla61b80132011-07-17 20:54:09 +00001126 if (likely(priv->plat->force_sf_dma_mode ||
1127 ((priv->plat->tx_coe) && (!priv->no_csum_insertion)))) {
1128 /*
1129 * In case of GMAC, SF mode can be enabled
1130 * to perform the TX COE in HW. This depends on:
Giuseppe CAVALLAROebbb2932010-09-17 03:23:40 +00001131 * 1) TX COE if actually supported
1132 * 2) There is no bugged Jumbo frame support
1133 * that needs to not insert csum in the TDES.
1134 */
1135 priv->hw->dma->dma_mode(priv->ioaddr,
1136 SF_DMA_MODE, SF_DMA_MODE);
1137 tc = SF_DMA_MODE;
1138 } else
1139 priv->hw->dma->dma_mode(priv->ioaddr, tc, SF_DMA_MODE);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001140}
1141
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001142/**
Giuseppe CAVALLARO9125cdd2012-11-25 23:10:42 +00001143 * stmmac_tx_clean:
1144 * @priv: private data pointer
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001145 * Description: it reclaims resources after transmission completes.
1146 */
Giuseppe CAVALLARO9125cdd2012-11-25 23:10:42 +00001147static void stmmac_tx_clean(struct stmmac_priv *priv)
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001148{
1149 unsigned int txsize = priv->dma_tx_size;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001150
Giuseppe CAVALLAROa9097a92011-10-18 00:01:19 +00001151 spin_lock(&priv->tx_lock);
1152
Giuseppe CAVALLARO9125cdd2012-11-25 23:10:42 +00001153 priv->xstats.tx_clean++;
1154
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001155 while (priv->dirty_tx != priv->cur_tx) {
1156 int last;
1157 unsigned int entry = priv->dirty_tx % txsize;
1158 struct sk_buff *skb = priv->tx_skbuff[entry];
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001159 struct dma_desc *p;
1160
1161 if (priv->extend_desc)
1162 p = (struct dma_desc *) (priv->dma_etx + entry);
1163 else
1164 p = priv->dma_tx + entry;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001165
1166 /* Check if the descriptor is owned by the DMA. */
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +00001167 if (priv->hw->desc->get_tx_owner(p))
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001168 break;
1169
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001170 /* Verify tx error by looking at the last segment. */
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +00001171 last = priv->hw->desc->get_tx_ls(p);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001172 if (likely(last)) {
1173 int tx_error =
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +00001174 priv->hw->desc->tx_status(&priv->dev->stats,
1175 &priv->xstats, p,
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +00001176 priv->ioaddr);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001177 if (likely(tx_error == 0)) {
1178 priv->dev->stats.tx_packets++;
1179 priv->xstats.tx_pkt_n++;
1180 } else
1181 priv->dev->stats.tx_errors++;
Rayagond Kokatanur891434b2013-03-26 04:43:10 +00001182
1183 stmmac_get_tx_hwtstamp(priv, entry, skb);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001184 }
1185 TX_DBG("%s: curr %d, dirty %d\n", __func__,
1186 priv->cur_tx, priv->dirty_tx);
1187
Rayagond Kokatanurcf32dee2013-03-26 04:43:09 +00001188 if (likely(priv->tx_skbuff_dma[entry])) {
1189 dma_unmap_single(priv->device,
1190 priv->tx_skbuff_dma[entry],
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +00001191 priv->hw->desc->get_tx_len(p),
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001192 DMA_TO_DEVICE);
Rayagond Kokatanurcf32dee2013-03-26 04:43:09 +00001193 priv->tx_skbuff_dma[entry] = 0;
1194 }
Rayagond Kokatanur891434b2013-03-26 04:43:10 +00001195 priv->hw->ring->clean_desc3(priv, p);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001196
1197 if (likely(skb != NULL)) {
Eric Dumazetacb600d2012-10-05 06:23:55 +00001198 dev_kfree_skb(skb);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001199 priv->tx_skbuff[entry] = NULL;
1200 }
1201
Giuseppe CAVALLARO4a7d6662013-03-26 04:43:05 +00001202 priv->hw->desc->release_tx_desc(p, priv->mode);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001203
Giuseppe CAVALLARO13497f52012-06-04 06:36:22 +00001204 priv->dirty_tx++;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001205 }
1206 if (unlikely(netif_queue_stopped(priv->dev) &&
1207 stmmac_tx_avail(priv) > STMMAC_TX_THRESH(priv))) {
1208 netif_tx_lock(priv->dev);
1209 if (netif_queue_stopped(priv->dev) &&
1210 stmmac_tx_avail(priv) > STMMAC_TX_THRESH(priv)) {
1211 TX_DBG("%s: restart transmit\n", __func__);
1212 netif_wake_queue(priv->dev);
1213 }
1214 netif_tx_unlock(priv->dev);
1215 }
Giuseppe CAVALLAROd7659552012-06-27 21:14:37 +00001216
1217 if ((priv->eee_enabled) && (!priv->tx_path_in_lpi_mode)) {
1218 stmmac_enable_eee_mode(priv);
1219 mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_TIMER(eee_timer));
1220 }
Giuseppe CAVALLAROa9097a92011-10-18 00:01:19 +00001221 spin_unlock(&priv->tx_lock);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001222}
1223
Giuseppe CAVALLARO9125cdd2012-11-25 23:10:42 +00001224static inline void stmmac_enable_dma_irq(struct stmmac_priv *priv)
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001225{
Giuseppe CAVALLARO7284a3f2012-11-25 23:10:41 +00001226 priv->hw->dma->enable_dma_irq(priv->ioaddr);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001227}
1228
Giuseppe CAVALLARO9125cdd2012-11-25 23:10:42 +00001229static inline void stmmac_disable_dma_irq(struct stmmac_priv *priv)
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001230{
Giuseppe CAVALLARO7284a3f2012-11-25 23:10:41 +00001231 priv->hw->dma->disable_dma_irq(priv->ioaddr);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001232}
1233
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001234
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001235/**
1236 * stmmac_tx_err:
1237 * @priv: pointer to the private device structure
1238 * Description: it cleans the descriptors and restarts the transmission
1239 * in case of errors.
1240 */
1241static void stmmac_tx_err(struct stmmac_priv *priv)
1242{
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001243 int i;
1244 int txsize = priv->dma_tx_size;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001245 netif_stop_queue(priv->dev);
1246
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +00001247 priv->hw->dma->stop_tx(priv->ioaddr);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001248 dma_free_tx_skbufs(priv);
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001249 for (i = 0; i < txsize; i++)
1250 if (priv->extend_desc)
1251 priv->hw->desc->init_tx_desc(&priv->dma_etx[i].basic,
1252 priv->mode,
1253 (i == txsize - 1));
1254 else
1255 priv->hw->desc->init_tx_desc(&priv->dma_tx[i],
1256 priv->mode,
1257 (i == txsize - 1));
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001258 priv->dirty_tx = 0;
1259 priv->cur_tx = 0;
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +00001260 priv->hw->dma->start_tx(priv->ioaddr);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001261
1262 priv->dev->stats.tx_errors++;
1263 netif_wake_queue(priv->dev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001264}
1265
Giuseppe CAVALLAROaec7ff22010-01-06 23:07:18 +00001266static void stmmac_dma_interrupt(struct stmmac_priv *priv)
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001267{
Giuseppe CAVALLAROaec7ff22010-01-06 23:07:18 +00001268 int status;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001269
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +00001270 status = priv->hw->dma->dma_interrupt(priv->ioaddr, &priv->xstats);
Giuseppe CAVALLARO9125cdd2012-11-25 23:10:42 +00001271 if (likely((status & handle_rx)) || (status & handle_tx)) {
1272 if (likely(napi_schedule_prep(&priv->napi))) {
1273 stmmac_disable_dma_irq(priv);
1274 __napi_schedule(&priv->napi);
1275 }
1276 }
1277 if (unlikely(status & tx_hard_error_bump_tc)) {
Giuseppe CAVALLAROaec7ff22010-01-06 23:07:18 +00001278 /* Try to bump up the dma threshold on this failure */
1279 if (unlikely(tc != SF_DMA_MODE) && (tc <= 256)) {
1280 tc += 64;
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +00001281 priv->hw->dma->dma_mode(priv->ioaddr, tc, SF_DMA_MODE);
Giuseppe CAVALLAROaec7ff22010-01-06 23:07:18 +00001282 priv->xstats.threshold = tc;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001283 }
Giuseppe CAVALLAROaec7ff22010-01-06 23:07:18 +00001284 } else if (unlikely(status == tx_hard_error))
1285 stmmac_tx_err(priv);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001286}
1287
Giuseppe CAVALLARO1c901a42011-09-01 21:51:38 +00001288static void stmmac_mmc_setup(struct stmmac_priv *priv)
1289{
1290 unsigned int mode = MMC_CNTRL_RESET_ON_READ | MMC_CNTRL_COUNTER_RESET |
1291 MMC_CNTRL_PRESET | MMC_CNTRL_FULL_HALF_PRESET;
1292
Giuseppe CAVALLARO4f795b22011-11-18 05:00:20 +00001293 /* Mask MMC irq, counters are managed in SW and registers
1294 * are cleared on each READ eventually. */
Giuseppe CAVALLARO1c901a42011-09-01 21:51:38 +00001295 dwmac_mmc_intr_all_mask(priv->ioaddr);
Giuseppe CAVALLARO4f795b22011-11-18 05:00:20 +00001296
1297 if (priv->dma_cap.rmon) {
1298 dwmac_mmc_ctrl(priv->ioaddr, mode);
1299 memset(&priv->mmc, 0, sizeof(struct stmmac_counters));
1300 } else
Stefan Roeseaae54cf2012-01-10 01:47:51 +00001301 pr_info(" No MAC Management Counters available\n");
Giuseppe CAVALLARO1c901a42011-09-01 21:51:38 +00001302}
1303
Giuseppe CAVALLAROf0b9d782011-09-01 21:51:40 +00001304static u32 stmmac_get_synopsys_id(struct stmmac_priv *priv)
1305{
1306 u32 hwid = priv->hw->synopsys_uid;
1307
1308 /* Only check valid Synopsys Id because old MAC chips
1309 * have no HW registers where get the ID */
1310 if (likely(hwid)) {
1311 u32 uid = ((hwid & 0x0000ff00) >> 8);
1312 u32 synid = (hwid & 0x000000ff);
1313
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00001314 pr_info("stmmac - user ID: 0x%x, Synopsys ID: 0x%x\n",
Giuseppe CAVALLAROf0b9d782011-09-01 21:51:40 +00001315 uid, synid);
1316
1317 return synid;
1318 }
1319 return 0;
1320}
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +00001321
Giuseppe CAVALLARO19e30c12011-11-16 21:58:00 +00001322/**
1323 * stmmac_selec_desc_mode
Giuseppe CAVALLAROff3dd782012-06-04 19:22:55 +00001324 * @priv : private structure
1325 * Description: select the Enhanced/Alternate or Normal descriptors
1326 */
Giuseppe CAVALLARO19e30c12011-11-16 21:58:00 +00001327static void stmmac_selec_desc_mode(struct stmmac_priv *priv)
1328{
1329 if (priv->plat->enh_desc) {
1330 pr_info(" Enhanced/Alternate descriptors\n");
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001331
1332 /* GMAC older than 3.50 has no extended descriptors */
1333 if (priv->synopsys_id >= DWMAC_CORE_3_50) {
1334 pr_info("\tEnabled extended descriptors\n");
1335 priv->extend_desc = 1;
1336 } else
1337 pr_warn("Extended descriptors not supported\n");
1338
Giuseppe CAVALLARO19e30c12011-11-16 21:58:00 +00001339 priv->hw->desc = &enh_desc_ops;
1340 } else {
1341 pr_info(" Normal descriptors\n");
1342 priv->hw->desc = &ndesc_ops;
1343 }
1344}
1345
1346/**
1347 * stmmac_get_hw_features
1348 * @priv : private device pointer
1349 * Description:
1350 * new GMAC chip generations have a new register to indicate the
1351 * presence of the optional feature/functions.
1352 * This can be also used to override the value passed through the
1353 * platform and necessary for old MAC10/100 and GMAC chips.
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +00001354 */
1355static int stmmac_get_hw_features(struct stmmac_priv *priv)
1356{
Giuseppe CAVALLARO5e6efe82011-10-26 19:43:07 +00001357 u32 hw_cap = 0;
Giuseppe CAVALLARO3c20f722011-10-26 19:43:09 +00001358
Giuseppe CAVALLARO5e6efe82011-10-26 19:43:07 +00001359 if (priv->hw->dma->get_hw_feature) {
1360 hw_cap = priv->hw->dma->get_hw_feature(priv->ioaddr);
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +00001361
Rayagond Kokatanur1db123f2011-10-18 00:01:22 +00001362 priv->dma_cap.mbps_10_100 = (hw_cap & DMA_HW_FEAT_MIISEL);
1363 priv->dma_cap.mbps_1000 = (hw_cap & DMA_HW_FEAT_GMIISEL) >> 1;
1364 priv->dma_cap.half_duplex = (hw_cap & DMA_HW_FEAT_HDSEL) >> 2;
1365 priv->dma_cap.hash_filter = (hw_cap & DMA_HW_FEAT_HASHSEL) >> 4;
1366 priv->dma_cap.multi_addr =
1367 (hw_cap & DMA_HW_FEAT_ADDMACADRSEL) >> 5;
1368 priv->dma_cap.pcs = (hw_cap & DMA_HW_FEAT_PCSSEL) >> 6;
1369 priv->dma_cap.sma_mdio = (hw_cap & DMA_HW_FEAT_SMASEL) >> 8;
1370 priv->dma_cap.pmt_remote_wake_up =
1371 (hw_cap & DMA_HW_FEAT_RWKSEL) >> 9;
1372 priv->dma_cap.pmt_magic_frame =
1373 (hw_cap & DMA_HW_FEAT_MGKSEL) >> 10;
Giuseppe CAVALLARO19e30c12011-11-16 21:58:00 +00001374 /* MMC */
Rayagond Kokatanur1db123f2011-10-18 00:01:22 +00001375 priv->dma_cap.rmon = (hw_cap & DMA_HW_FEAT_MMCSEL) >> 11;
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +00001376 /* IEEE 1588-2002*/
Rayagond Kokatanur1db123f2011-10-18 00:01:22 +00001377 priv->dma_cap.time_stamp =
1378 (hw_cap & DMA_HW_FEAT_TSVER1SEL) >> 12;
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +00001379 /* IEEE 1588-2008*/
Rayagond Kokatanur1db123f2011-10-18 00:01:22 +00001380 priv->dma_cap.atime_stamp =
1381 (hw_cap & DMA_HW_FEAT_TSVER2SEL) >> 13;
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +00001382 /* 802.3az - Energy-Efficient Ethernet (EEE) */
Rayagond Kokatanur1db123f2011-10-18 00:01:22 +00001383 priv->dma_cap.eee = (hw_cap & DMA_HW_FEAT_EEESEL) >> 14;
1384 priv->dma_cap.av = (hw_cap & DMA_HW_FEAT_AVSEL) >> 15;
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +00001385 /* TX and RX csum */
Rayagond Kokatanur1db123f2011-10-18 00:01:22 +00001386 priv->dma_cap.tx_coe = (hw_cap & DMA_HW_FEAT_TXCOESEL) >> 16;
1387 priv->dma_cap.rx_coe_type1 =
1388 (hw_cap & DMA_HW_FEAT_RXTYP1COE) >> 17;
1389 priv->dma_cap.rx_coe_type2 =
1390 (hw_cap & DMA_HW_FEAT_RXTYP2COE) >> 18;
1391 priv->dma_cap.rxfifo_over_2048 =
1392 (hw_cap & DMA_HW_FEAT_RXFIFOSIZE) >> 19;
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +00001393 /* TX and RX number of channels */
Rayagond Kokatanur1db123f2011-10-18 00:01:22 +00001394 priv->dma_cap.number_rx_channel =
1395 (hw_cap & DMA_HW_FEAT_RXCHCNT) >> 20;
1396 priv->dma_cap.number_tx_channel =
1397 (hw_cap & DMA_HW_FEAT_TXCHCNT) >> 22;
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +00001398 /* Alternate (enhanced) DESC mode*/
Rayagond Kokatanur1db123f2011-10-18 00:01:22 +00001399 priv->dma_cap.enh_desc =
1400 (hw_cap & DMA_HW_FEAT_ENHDESSEL) >> 24;
Giuseppe CAVALLARO19e30c12011-11-16 21:58:00 +00001401 }
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +00001402
1403 return hw_cap;
1404}
1405
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001406static void stmmac_check_ether_addr(struct stmmac_priv *priv)
1407{
1408 /* verify if the MAC address is valid, in case of failures it
1409 * generates a random MAC address */
1410 if (!is_valid_ether_addr(priv->dev->dev_addr)) {
1411 priv->hw->mac->get_umac_addr((void __iomem *)
1412 priv->dev->base_addr,
1413 priv->dev->dev_addr, 0);
1414 if (!is_valid_ether_addr(priv->dev->dev_addr))
Danny Kukawkaf2cedb62012-02-15 06:45:39 +00001415 eth_hw_addr_random(priv->dev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001416 }
1417 pr_warning("%s: device MAC address %pM\n", priv->dev->name,
1418 priv->dev->dev_addr);
1419}
1420
Giuseppe CAVALLARO0f1f88a2012-04-18 19:48:21 +00001421static int stmmac_init_dma_engine(struct stmmac_priv *priv)
1422{
1423 int pbl = DEFAULT_DMA_PBL, fixed_burst = 0, burst_len = 0;
Giuseppe CAVALLAROb9cde0a2012-05-13 22:18:42 +00001424 int mixed_burst = 0;
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001425 int atds = 0;
Giuseppe CAVALLARO0f1f88a2012-04-18 19:48:21 +00001426
1427 /* Some DMA parameters can be passed from the platform;
1428 * in case of these are not passed we keep a default
1429 * (good for all the chips) and init the DMA! */
1430 if (priv->plat->dma_cfg) {
1431 pbl = priv->plat->dma_cfg->pbl;
1432 fixed_burst = priv->plat->dma_cfg->fixed_burst;
Giuseppe CAVALLAROb9cde0a2012-05-13 22:18:42 +00001433 mixed_burst = priv->plat->dma_cfg->mixed_burst;
Giuseppe CAVALLARO0f1f88a2012-04-18 19:48:21 +00001434 burst_len = priv->plat->dma_cfg->burst_len;
1435 }
1436
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001437 if (priv->extend_desc && (priv->mode == STMMAC_RING_MODE))
1438 atds = 1;
1439
Giuseppe CAVALLAROb9cde0a2012-05-13 22:18:42 +00001440 return priv->hw->dma->init(priv->ioaddr, pbl, fixed_burst, mixed_burst,
Giuseppe CAVALLARO0f1f88a2012-04-18 19:48:21 +00001441 burst_len, priv->dma_tx_phy,
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001442 priv->dma_rx_phy, atds);
Giuseppe CAVALLARO0f1f88a2012-04-18 19:48:21 +00001443}
1444
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001445/**
Giuseppe CAVALLARO9125cdd2012-11-25 23:10:42 +00001446 * stmmac_tx_timer:
1447 * @data: data pointer
1448 * Description:
1449 * This is the timer handler to directly invoke the stmmac_tx_clean.
1450 */
1451static void stmmac_tx_timer(unsigned long data)
1452{
1453 struct stmmac_priv *priv = (struct stmmac_priv *)data;
1454
1455 stmmac_tx_clean(priv);
1456}
1457
1458/**
1459 * stmmac_tx_timer:
1460 * @priv: private data structure
1461 * Description:
1462 * This inits the transmit coalesce parameters: i.e. timer rate,
1463 * timer handler and default threshold used for enabling the
1464 * interrupt on completion bit.
1465 */
1466static void stmmac_init_tx_coalesce(struct stmmac_priv *priv)
1467{
1468 priv->tx_coal_frames = STMMAC_TX_FRAMES;
1469 priv->tx_coal_timer = STMMAC_COAL_TX_TIMER;
1470 init_timer(&priv->txtimer);
1471 priv->txtimer.expires = STMMAC_COAL_TIMER(priv->tx_coal_timer);
1472 priv->txtimer.data = (unsigned long)priv;
1473 priv->txtimer.function = stmmac_tx_timer;
1474 add_timer(&priv->txtimer);
1475}
1476
1477/**
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001478 * stmmac_open - open entry point of the driver
1479 * @dev : pointer to the device structure.
1480 * Description:
1481 * This function is the open entry point of the driver.
1482 * Return value:
1483 * 0 on success and an appropriate (-)ve integer as defined in errno.h
1484 * file on failure.
1485 */
1486static int stmmac_open(struct net_device *dev)
1487{
1488 struct stmmac_priv *priv = netdev_priv(dev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001489 int ret;
1490
Stefan Roesea6308442012-09-21 01:06:29 +00001491 clk_prepare_enable(priv->stmmac_clk);
Francesco Virlinzi4bfcbd72012-04-18 19:48:20 +00001492
1493 stmmac_check_ether_addr(priv);
1494
Giuseppe CAVALLAROe58bb432013-03-26 04:43:08 +00001495 if (!priv->pcs) {
1496 ret = stmmac_init_phy(dev);
1497 if (ret) {
1498 pr_err("%s: Cannot attach to PHY (error: %d)\n",
1499 __func__, ret);
1500 goto open_error;
1501 }
Giuseppe CAVALLAROf66ffe22011-04-10 23:16:45 +00001502 }
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001503
1504 /* Create and initialize the TX/RX descriptors chains. */
1505 priv->dma_tx_size = STMMAC_ALIGN(dma_txsize);
1506 priv->dma_rx_size = STMMAC_ALIGN(dma_rxsize);
1507 priv->dma_buf_sz = STMMAC_ALIGN(buf_sz);
1508 init_dma_desc_rings(dev);
1509
1510 /* DMA initialization and SW reset */
Giuseppe CAVALLARO0f1f88a2012-04-18 19:48:21 +00001511 ret = stmmac_init_dma_engine(priv);
Giuseppe CAVALLAROf66ffe22011-04-10 23:16:45 +00001512 if (ret < 0) {
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001513 pr_err("%s: DMA initialization failed\n", __func__);
Giuseppe CAVALLAROf66ffe22011-04-10 23:16:45 +00001514 goto open_error;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001515 }
1516
1517 /* Copy the MAC addr into the HW */
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +00001518 priv->hw->mac->set_umac_addr(priv->ioaddr, dev->dev_addr, 0);
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00001519
Giuseppe CAVALLAROca5f12c2010-01-06 23:07:15 +00001520 /* If required, perform hw setup of the bus. */
Giuseppe CAVALLARO9dfeb4d2010-11-24 02:37:58 +00001521 if (priv->plat->bus_setup)
1522 priv->plat->bus_setup(priv->ioaddr);
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00001523
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001524 /* Initialize the MAC Core */
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +00001525 priv->hw->mac->core_init(priv->ioaddr);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001526
Giuseppe CAVALLAROf66ffe22011-04-10 23:16:45 +00001527 /* Request the IRQ lines */
1528 ret = request_irq(dev->irq, stmmac_interrupt,
1529 IRQF_SHARED, dev->name, dev);
1530 if (unlikely(ret < 0)) {
1531 pr_err("%s: ERROR: allocating the IRQ %d (error: %d)\n",
1532 __func__, dev->irq, ret);
1533 goto open_error;
1534 }
1535
Francesco Virlinzi7a13f8f2012-02-15 00:10:38 +00001536 /* Request the Wake IRQ in case of another line is used for WoL */
1537 if (priv->wol_irq != dev->irq) {
1538 ret = request_irq(priv->wol_irq, stmmac_interrupt,
1539 IRQF_SHARED, dev->name, dev);
1540 if (unlikely(ret < 0)) {
1541 pr_err("%s: ERROR: allocating the ext WoL IRQ %d "
1542 "(error: %d)\n", __func__, priv->wol_irq, ret);
1543 goto open_error_wolirq;
1544 }
1545 }
1546
Giuseppe CAVALLAROd7659552012-06-27 21:14:37 +00001547 /* Request the IRQ lines */
1548 if (priv->lpi_irq != -ENXIO) {
1549 ret = request_irq(priv->lpi_irq, stmmac_interrupt, IRQF_SHARED,
1550 dev->name, dev);
1551 if (unlikely(ret < 0)) {
1552 pr_err("%s: ERROR: allocating the LPI IRQ %d (%d)\n",
1553 __func__, priv->lpi_irq, ret);
1554 goto open_error_lpiirq;
1555 }
1556 }
1557
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001558 /* Enable the MAC Rx/Tx */
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001559 stmmac_set_mac(priv->ioaddr, true);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001560
1561 /* Set the HW DMA mode and the COE */
1562 stmmac_dma_operation_mode(priv);
1563
1564 /* Extra statistics */
1565 memset(&priv->xstats, 0, sizeof(struct stmmac_extra_stats));
1566 priv->xstats.threshold = tc;
1567
Giuseppe CAVALLARO4f795b22011-11-18 05:00:20 +00001568 stmmac_mmc_setup(priv);
Giuseppe CAVALLARO1c901a42011-09-01 21:51:38 +00001569
Rayagond Kokatanur891434b2013-03-26 04:43:10 +00001570 stmmac_init_ptp(priv);
1571
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001572#ifdef CONFIG_STMMAC_DEBUG_FS
1573 ret = stmmac_init_fs(dev);
1574 if (ret < 0)
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00001575 pr_warning("%s: failed debugFS registration\n", __func__);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001576#endif
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001577 /* Start the ball rolling... */
1578 DBG(probe, DEBUG, "%s: DMA RX/TX processes started...\n", dev->name);
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +00001579 priv->hw->dma->start_tx(priv->ioaddr);
1580 priv->hw->dma->start_rx(priv->ioaddr);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001581
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001582 /* Dump DMA/MAC registers */
1583 if (netif_msg_hw(priv)) {
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +00001584 priv->hw->mac->dump_regs(priv->ioaddr);
1585 priv->hw->dma->dump_regs(priv->ioaddr);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001586 }
1587
1588 if (priv->phydev)
1589 phy_start(priv->phydev);
1590
Giuseppe CAVALLAROd7659552012-06-27 21:14:37 +00001591 priv->tx_lpi_timer = STMMAC_DEFAULT_TWT_LS_TIMER;
Giuseppe CAVALLAROe58bb432013-03-26 04:43:08 +00001592
1593 /* Using PCS we cannot dial with the phy registers at this stage
1594 * so we do not support extra feature like EEE.
1595 */
1596 if (!priv->pcs)
1597 priv->eee_enabled = stmmac_eee_init(priv);
Giuseppe CAVALLAROd7659552012-06-27 21:14:37 +00001598
Giuseppe CAVALLARO9125cdd2012-11-25 23:10:42 +00001599 stmmac_init_tx_coalesce(priv);
1600
Giuseppe CAVALLARO62a2ab92012-11-25 23:10:43 +00001601 if ((priv->use_riwt) && (priv->hw->dma->rx_watchdog)) {
1602 priv->rx_riwt = MAX_DMA_RIWT;
1603 priv->hw->dma->rx_watchdog(priv->ioaddr, MAX_DMA_RIWT);
1604 }
1605
Giuseppe CAVALLAROe58bb432013-03-26 04:43:08 +00001606 if (priv->pcs && priv->hw->mac->ctrl_ane)
1607 priv->hw->mac->ctrl_ane(priv->ioaddr, 0);
1608
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001609 napi_enable(&priv->napi);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001610 netif_start_queue(dev);
Giuseppe CAVALLAROf66ffe22011-04-10 23:16:45 +00001611
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001612 return 0;
Giuseppe CAVALLAROf66ffe22011-04-10 23:16:45 +00001613
Giuseppe CAVALLAROd7659552012-06-27 21:14:37 +00001614open_error_lpiirq:
1615 if (priv->wol_irq != dev->irq)
1616 free_irq(priv->wol_irq, dev);
1617
Francesco Virlinzi7a13f8f2012-02-15 00:10:38 +00001618open_error_wolirq:
1619 free_irq(dev->irq, dev);
1620
Giuseppe CAVALLAROf66ffe22011-04-10 23:16:45 +00001621open_error:
Giuseppe CAVALLAROf66ffe22011-04-10 23:16:45 +00001622 if (priv->phydev)
1623 phy_disconnect(priv->phydev);
1624
Stefan Roesea6308442012-09-21 01:06:29 +00001625 clk_disable_unprepare(priv->stmmac_clk);
Francesco Virlinzi4bfcbd72012-04-18 19:48:20 +00001626
Giuseppe CAVALLAROf66ffe22011-04-10 23:16:45 +00001627 return ret;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001628}
1629
1630/**
1631 * stmmac_release - close entry point of the driver
1632 * @dev : device pointer.
1633 * Description:
1634 * This is the stop entry point of the driver.
1635 */
1636static int stmmac_release(struct net_device *dev)
1637{
1638 struct stmmac_priv *priv = netdev_priv(dev);
1639
Giuseppe CAVALLAROd7659552012-06-27 21:14:37 +00001640 if (priv->eee_enabled)
1641 del_timer_sync(&priv->eee_ctrl_timer);
1642
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001643 /* Stop and disconnect the PHY */
1644 if (priv->phydev) {
1645 phy_stop(priv->phydev);
1646 phy_disconnect(priv->phydev);
1647 priv->phydev = NULL;
1648 }
1649
1650 netif_stop_queue(dev);
1651
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001652 napi_disable(&priv->napi);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001653
Giuseppe CAVALLARO9125cdd2012-11-25 23:10:42 +00001654 del_timer_sync(&priv->txtimer);
1655
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001656 /* Free the IRQ lines */
1657 free_irq(dev->irq, dev);
Francesco Virlinzi7a13f8f2012-02-15 00:10:38 +00001658 if (priv->wol_irq != dev->irq)
1659 free_irq(priv->wol_irq, dev);
Giuseppe CAVALLAROd7659552012-06-27 21:14:37 +00001660 if (priv->lpi_irq != -ENXIO)
1661 free_irq(priv->lpi_irq, dev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001662
1663 /* Stop TX/RX DMA and clear the descriptors */
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +00001664 priv->hw->dma->stop_tx(priv->ioaddr);
1665 priv->hw->dma->stop_rx(priv->ioaddr);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001666
1667 /* Release and free the Rx/Tx resources */
1668 free_dma_desc_resources(priv);
1669
avisconti19449bf2010-10-25 18:58:14 +00001670 /* Disable the MAC Rx/Tx */
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001671 stmmac_set_mac(priv->ioaddr, false);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001672
1673 netif_carrier_off(dev);
1674
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001675#ifdef CONFIG_STMMAC_DEBUG_FS
1676 stmmac_exit_fs();
1677#endif
Stefan Roesea6308442012-09-21 01:06:29 +00001678 clk_disable_unprepare(priv->stmmac_clk);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001679
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001680 return 0;
1681}
1682
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001683/**
1684 * stmmac_xmit:
1685 * @skb : the socket buffer
1686 * @dev : device pointer
1687 * Description : Tx entry point of the driver.
1688 */
1689static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
1690{
1691 struct stmmac_priv *priv = netdev_priv(dev);
1692 unsigned int txsize = priv->dma_tx_size;
1693 unsigned int entry;
Giuseppe CAVALLARO4a7d6662013-03-26 04:43:05 +00001694 int i, csum_insertion = 0, is_jumbo = 0;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001695 int nfrags = skb_shinfo(skb)->nr_frags;
1696 struct dma_desc *desc, *first;
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +00001697 unsigned int nopaged_len = skb_headlen(skb);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001698
1699 if (unlikely(stmmac_tx_avail(priv) < nfrags + 1)) {
1700 if (!netif_queue_stopped(dev)) {
1701 netif_stop_queue(dev);
1702 /* This is a hard error, log it. */
1703 pr_err("%s: BUG! Tx Ring full when queue awake\n",
1704 __func__);
1705 }
1706 return NETDEV_TX_BUSY;
1707 }
1708
Giuseppe CAVALLAROa9097a92011-10-18 00:01:19 +00001709 spin_lock(&priv->tx_lock);
1710
Giuseppe CAVALLAROd7659552012-06-27 21:14:37 +00001711 if (priv->tx_path_in_lpi_mode)
1712 stmmac_disable_eee_mode(priv);
1713
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001714 entry = priv->cur_tx % txsize;
1715
1716#ifdef STMMAC_XMIT_DEBUG
1717 if ((skb->len > ETH_FRAME_LEN) || nfrags)
Giuseppe CAVALLARO9125cdd2012-11-25 23:10:42 +00001718 pr_debug("stmmac xmit: [entry %d]\n"
1719 "\tskb addr %p - len: %d - nopaged_len: %d\n"
1720 "\tn_frags: %d - ip_summed: %d - %s gso\n"
1721 "\ttx_count_frames %d\n", entry,
1722 skb, skb->len, nopaged_len, nfrags, skb->ip_summed,
1723 !skb_is_gso(skb) ? "isn't" : "is",
1724 priv->tx_count_frames);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001725#endif
1726
Michał Mirosław5e982f32011-04-09 02:46:55 +00001727 csum_insertion = (skb->ip_summed == CHECKSUM_PARTIAL);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001728
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001729 if (priv->extend_desc)
1730 desc = (struct dma_desc *) (priv->dma_etx + entry);
1731 else
1732 desc = priv->dma_tx + entry;
1733
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001734 first = desc;
1735
1736#ifdef STMMAC_XMIT_DEBUG
1737 if ((nfrags > 0) || (skb->len > ETH_FRAME_LEN))
Giuseppe CAVALLARO9125cdd2012-11-25 23:10:42 +00001738 pr_debug("\tskb len: %d, nopaged_len: %d,\n"
1739 "\t\tn_frags: %d, ip_summed: %d\n",
1740 skb->len, nopaged_len, nfrags, skb->ip_summed);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001741#endif
1742 priv->tx_skbuff[entry] = skb;
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +00001743
Giuseppe CAVALLARO4a7d6662013-03-26 04:43:05 +00001744 /* To program the descriptors according to the size of the frame */
1745 if (priv->mode == STMMAC_RING_MODE) {
1746 is_jumbo = priv->hw->ring->is_jumbo_frm(skb->len,
1747 priv->plat->enh_desc);
1748 if (unlikely(is_jumbo))
1749 entry = priv->hw->ring->jumbo_frm(priv, skb,
1750 csum_insertion);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001751 } else {
Giuseppe CAVALLARO4a7d6662013-03-26 04:43:05 +00001752 is_jumbo = priv->hw->chain->is_jumbo_frm(skb->len,
1753 priv->plat->enh_desc);
1754 if (unlikely(is_jumbo))
1755 entry = priv->hw->chain->jumbo_frm(priv, skb,
1756 csum_insertion);
1757 }
1758 if (likely(!is_jumbo)) {
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001759 desc->des2 = dma_map_single(priv->device, skb->data,
1760 nopaged_len, DMA_TO_DEVICE);
Rayagond Kokatanurcf32dee2013-03-26 04:43:09 +00001761 priv->tx_skbuff_dma[entry] = desc->des2;
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +00001762 priv->hw->desc->prepare_tx_desc(desc, 1, nopaged_len,
Giuseppe CAVALLARO4a7d6662013-03-26 04:43:05 +00001763 csum_insertion, priv->mode);
1764 } else
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001765 desc = first;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001766
1767 for (i = 0; i < nfrags; i++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00001768 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1769 int len = skb_frag_size(frag);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001770
1771 entry = (++priv->cur_tx) % txsize;
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001772 if (priv->extend_desc)
1773 desc = (struct dma_desc *) (priv->dma_etx + entry);
1774 else
1775 desc = priv->dma_tx + entry;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001776
1777 TX_DBG("\t[entry %d] segment len: %d\n", entry, len);
Ian Campbellf7223802011-09-21 21:53:20 +00001778 desc->des2 = skb_frag_dma_map(priv->device, frag, 0, len,
1779 DMA_TO_DEVICE);
Rayagond Kokatanurcf32dee2013-03-26 04:43:09 +00001780 priv->tx_skbuff_dma[entry] = desc->des2;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001781 priv->tx_skbuff[entry] = NULL;
Giuseppe CAVALLARO4a7d6662013-03-26 04:43:05 +00001782 priv->hw->desc->prepare_tx_desc(desc, 0, len, csum_insertion,
1783 priv->mode);
Shiraz Hashimeb0dc4b2011-07-17 20:54:08 +00001784 wmb();
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +00001785 priv->hw->desc->set_tx_owner(desc);
Deepak Sikri8e839892012-07-08 21:14:45 +00001786 wmb();
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001787 }
1788
Giuseppe CAVALLARO9125cdd2012-11-25 23:10:42 +00001789 /* Finalize the latest segment. */
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +00001790 priv->hw->desc->close_tx_desc(desc);
Giuseppe CAVALLARO73cfe262009-11-22 22:59:56 +00001791
Shiraz Hashimeb0dc4b2011-07-17 20:54:08 +00001792 wmb();
Giuseppe CAVALLARO9125cdd2012-11-25 23:10:42 +00001793 /* According to the coalesce parameter the IC bit for the latest
1794 * segment could be reset and the timer re-started to invoke the
1795 * stmmac_tx function. This approach takes care about the fragments.
1796 */
1797 priv->tx_count_frames += nfrags + 1;
1798 if (priv->tx_coal_frames > priv->tx_count_frames) {
1799 priv->hw->desc->clear_tx_ic(desc);
1800 priv->xstats.tx_reset_ic_bit++;
1801 TX_DBG("\t[entry %d]: tx_count_frames %d\n", entry,
1802 priv->tx_count_frames);
1803 mod_timer(&priv->txtimer,
1804 STMMAC_COAL_TIMER(priv->tx_coal_timer));
1805 } else
1806 priv->tx_count_frames = 0;
Shiraz Hashimeb0dc4b2011-07-17 20:54:08 +00001807
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001808 /* To avoid raise condition */
Giuseppe CAVALLAROdb98a0b2010-01-06 23:07:17 +00001809 priv->hw->desc->set_tx_owner(first);
Deepak Sikri8e839892012-07-08 21:14:45 +00001810 wmb();
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001811
1812 priv->cur_tx++;
1813
1814#ifdef STMMAC_XMIT_DEBUG
1815 if (netif_msg_pktdata(priv)) {
1816 pr_info("stmmac xmit: current=%d, dirty=%d, entry=%d, "
1817 "first=%p, nfrags=%d\n",
1818 (priv->cur_tx % txsize), (priv->dirty_tx % txsize),
1819 entry, first, nfrags);
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001820 if (priv->extend_desc)
1821 stmmac_display_ring((void *)priv->dma_etx, txsize, 1);
1822 else
1823 stmmac_display_ring((void *)priv->dma_tx, txsize, 0);
1824
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001825 pr_info(">>> frame to be transmitted: ");
1826 print_pkt(skb->data, skb->len);
1827 }
1828#endif
1829 if (unlikely(stmmac_tx_avail(priv) <= (MAX_SKB_FRAGS + 1))) {
1830 TX_DBG("%s: stop transmitted packets\n", __func__);
1831 netif_stop_queue(dev);
1832 }
1833
1834 dev->stats.tx_bytes += skb->len;
1835
Rayagond Kokatanur891434b2013-03-26 04:43:10 +00001836 if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
1837 priv->hwts_tx_en)) {
1838 /* declare that device is doing timestamping */
1839 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
1840 priv->hw->desc->enable_tx_timestamp(first);
1841 }
1842
1843 if (!priv->hwts_tx_en)
1844 skb_tx_timestamp(skb);
Richard Cochran3e82ce12011-06-12 02:19:06 +00001845
Richard Cochran52f64fa2011-06-19 03:31:43 +00001846 priv->hw->dma->enable_dma_transmission(priv->ioaddr);
1847
Giuseppe CAVALLAROa9097a92011-10-18 00:01:19 +00001848 spin_unlock(&priv->tx_lock);
1849
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001850 return NETDEV_TX_OK;
1851}
1852
1853static inline void stmmac_rx_refill(struct stmmac_priv *priv)
1854{
1855 unsigned int rxsize = priv->dma_rx_size;
1856 int bfsize = priv->dma_buf_sz;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001857
1858 for (; priv->cur_rx - priv->dirty_rx > 0; priv->dirty_rx++) {
1859 unsigned int entry = priv->dirty_rx % rxsize;
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001860 struct dma_desc *p;
1861
1862 if (priv->extend_desc)
1863 p = (struct dma_desc *) (priv->dma_erx + entry);
1864 else
1865 p = priv->dma_rx + entry;
1866
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001867 if (likely(priv->rx_skbuff[entry] == NULL)) {
1868 struct sk_buff *skb;
1869
Eric Dumazetacb600d2012-10-05 06:23:55 +00001870 skb = netdev_alloc_skb_ip_align(priv->dev, bfsize);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001871
1872 if (unlikely(skb == NULL))
1873 break;
1874
1875 priv->rx_skbuff[entry] = skb;
1876 priv->rx_skbuff_dma[entry] =
1877 dma_map_single(priv->device, skb->data, bfsize,
1878 DMA_FROM_DEVICE);
1879
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001880 p->des2 = priv->rx_skbuff_dma[entry];
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +00001881
Rayagond Kokatanur891434b2013-03-26 04:43:10 +00001882 priv->hw->ring->refill_desc3(priv, p);
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +00001883
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001884 RX_DBG(KERN_INFO "\trefill entry #%d\n", entry);
1885 }
Shiraz Hashimeb0dc4b2011-07-17 20:54:08 +00001886 wmb();
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001887 priv->hw->desc->set_rx_owner(p);
Deepak Sikri8e839892012-07-08 21:14:45 +00001888 wmb();
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001889 }
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001890}
1891
1892static int stmmac_rx(struct stmmac_priv *priv, int limit)
1893{
1894 unsigned int rxsize = priv->dma_rx_size;
1895 unsigned int entry = priv->cur_rx % rxsize;
1896 unsigned int next_entry;
1897 unsigned int count = 0;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001898
1899#ifdef STMMAC_RX_DEBUG
1900 if (netif_msg_hw(priv)) {
1901 pr_debug(">>> stmmac_rx: descriptor ring:\n");
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001902 if (priv->extend_desc)
1903 stmmac_display_ring((void *) priv->dma_erx, rxsize, 1);
1904 else
1905 stmmac_display_ring((void *)priv->dma_rx, rxsize, 0);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001906 }
1907#endif
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001908 while (count < limit) {
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001909 int status;
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001910 struct dma_desc *p, *p_next;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001911
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001912 if (priv->extend_desc)
1913 p = (struct dma_desc *) (priv->dma_erx + entry);
1914 else
1915 p = priv->dma_rx + entry ;
1916
1917 if (priv->hw->desc->get_rx_owner(p))
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001918 break;
1919
1920 count++;
1921
1922 next_entry = (++priv->cur_rx) % rxsize;
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001923 if (priv->extend_desc)
1924 p_next = (struct dma_desc *) (priv->dma_erx +
1925 next_entry);
1926 else
1927 p_next = priv->dma_rx + next_entry;
1928
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001929 prefetch(p_next);
1930
1931 /* read the status of the incoming frame */
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00001932 status = priv->hw->desc->rx_status(&priv->dev->stats,
1933 &priv->xstats, p);
1934 if ((priv->extend_desc) && (priv->hw->desc->rx_extended_status))
1935 priv->hw->desc->rx_extended_status(&priv->dev->stats,
1936 &priv->xstats,
1937 priv->dma_erx +
1938 entry);
Rayagond Kokatanur891434b2013-03-26 04:43:10 +00001939 if (unlikely(status == discard_frame)) {
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001940 priv->dev->stats.rx_errors++;
Rayagond Kokatanur891434b2013-03-26 04:43:10 +00001941 if (priv->hwts_rx_en && !priv->extend_desc) {
1942 /* DESC2 & DESC3 will be overwitten by device
1943 * with timestamp value, hence reinitialize
1944 * them in stmmac_rx_refill() function so that
1945 * device can reuse it.
1946 */
1947 priv->rx_skbuff[entry] = NULL;
1948 dma_unmap_single(priv->device,
1949 priv->rx_skbuff_dma[entry],
1950 priv->dma_buf_sz, DMA_FROM_DEVICE);
1951 }
1952 } else {
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001953 struct sk_buff *skb;
Giuseppe CAVALLARO3eeb2992010-07-27 00:09:47 +00001954 int frame_len;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001955
Deepak SIKRI38912bd2012-04-04 04:33:21 +00001956 frame_len = priv->hw->desc->get_rx_frame_len(p,
1957 priv->plat->rx_coe);
Giuseppe CAVALLARO3eeb2992010-07-27 00:09:47 +00001958 /* ACS is set; GMAC core strips PAD/FCS for IEEE 802.3
1959 * Type frames (LLC/LLC-SNAP) */
1960 if (unlikely(status != llc_snap))
1961 frame_len -= ETH_FCS_LEN;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001962#ifdef STMMAC_RX_DEBUG
1963 if (frame_len > ETH_FRAME_LEN)
1964 pr_debug("\tRX frame size %d, COE status: %d\n",
1965 frame_len, status);
1966
1967 if (netif_msg_hw(priv))
1968 pr_debug("\tdesc: %p [entry %d] buff=0x%x\n",
1969 p, entry, p->des2);
1970#endif
1971 skb = priv->rx_skbuff[entry];
1972 if (unlikely(!skb)) {
1973 pr_err("%s: Inconsistent Rx descriptor chain\n",
1974 priv->dev->name);
1975 priv->dev->stats.rx_dropped++;
1976 break;
1977 }
1978 prefetch(skb->data - NET_IP_ALIGN);
1979 priv->rx_skbuff[entry] = NULL;
1980
Rayagond Kokatanur891434b2013-03-26 04:43:10 +00001981 stmmac_get_rx_hwtstamp(priv, entry, skb);
1982
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001983 skb_put(skb, frame_len);
1984 dma_unmap_single(priv->device,
1985 priv->rx_skbuff_dma[entry],
1986 priv->dma_buf_sz, DMA_FROM_DEVICE);
1987#ifdef STMMAC_RX_DEBUG
1988 if (netif_msg_pktdata(priv)) {
1989 pr_info(" frame received (%dbytes)", frame_len);
1990 print_pkt(skb->data, frame_len);
1991 }
1992#endif
1993 skb->protocol = eth_type_trans(skb, priv->dev);
1994
Giuseppe CAVALLARO62a2ab92012-11-25 23:10:43 +00001995 if (unlikely(!priv->plat->rx_coe))
Eric Dumazetbc8acf22010-09-02 13:07:41 -07001996 skb_checksum_none_assert(skb);
Giuseppe CAVALLARO62a2ab92012-11-25 23:10:43 +00001997 else
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07001998 skb->ip_summed = CHECKSUM_UNNECESSARY;
Giuseppe CAVALLARO62a2ab92012-11-25 23:10:43 +00001999
2000 napi_gro_receive(&priv->napi, skb);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002001
2002 priv->dev->stats.rx_packets++;
2003 priv->dev->stats.rx_bytes += frame_len;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002004 }
2005 entry = next_entry;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002006 }
2007
2008 stmmac_rx_refill(priv);
2009
2010 priv->xstats.rx_pkt_n += count;
2011
2012 return count;
2013}
2014
2015/**
2016 * stmmac_poll - stmmac poll method (NAPI)
2017 * @napi : pointer to the napi structure.
2018 * @budget : maximum number of packets that the current CPU can receive from
2019 * all interfaces.
2020 * Description :
Giuseppe CAVALLARO9125cdd2012-11-25 23:10:42 +00002021 * To look at the incoming frames and clear the tx resources.
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002022 */
2023static int stmmac_poll(struct napi_struct *napi, int budget)
2024{
2025 struct stmmac_priv *priv = container_of(napi, struct stmmac_priv, napi);
2026 int work_done = 0;
2027
Giuseppe CAVALLARO9125cdd2012-11-25 23:10:42 +00002028 priv->xstats.napi_poll++;
2029 stmmac_tx_clean(priv);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002030
Giuseppe CAVALLARO9125cdd2012-11-25 23:10:42 +00002031 work_done = stmmac_rx(priv, budget);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002032 if (work_done < budget) {
2033 napi_complete(napi);
Giuseppe CAVALLARO9125cdd2012-11-25 23:10:42 +00002034 stmmac_enable_dma_irq(priv);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002035 }
2036 return work_done;
2037}
2038
2039/**
2040 * stmmac_tx_timeout
2041 * @dev : Pointer to net device structure
2042 * Description: this function is called when a packet transmission fails to
Giuseppe CAVALLARO7284a3f2012-11-25 23:10:41 +00002043 * complete within a reasonable time. The driver will mark the error in the
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002044 * netdev structure and arrange for the device to be reset to a sane state
2045 * in order to transmit a new packet.
2046 */
2047static void stmmac_tx_timeout(struct net_device *dev)
2048{
2049 struct stmmac_priv *priv = netdev_priv(dev);
2050
2051 /* Clear Tx resources and restart transmitting again */
2052 stmmac_tx_err(priv);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002053}
2054
2055/* Configuration changes (passed on by ifconfig) */
2056static int stmmac_config(struct net_device *dev, struct ifmap *map)
2057{
2058 if (dev->flags & IFF_UP) /* can't act on a running interface */
2059 return -EBUSY;
2060
2061 /* Don't allow changing the I/O address */
2062 if (map->base_addr != dev->base_addr) {
2063 pr_warning("%s: can't change I/O address\n", dev->name);
2064 return -EOPNOTSUPP;
2065 }
2066
2067 /* Don't allow changing the IRQ */
2068 if (map->irq != dev->irq) {
2069 pr_warning("%s: can't change IRQ number %d\n",
2070 dev->name, dev->irq);
2071 return -EOPNOTSUPP;
2072 }
2073
2074 /* ignore other fields */
2075 return 0;
2076}
2077
2078/**
Jiri Pirko01789342011-08-16 06:29:00 +00002079 * stmmac_set_rx_mode - entry point for multicast addressing
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002080 * @dev : pointer to the device structure
2081 * Description:
2082 * This function is a driver entry point which gets called by the kernel
2083 * whenever multicast addresses must be enabled/disabled.
2084 * Return value:
2085 * void.
2086 */
Jiri Pirko01789342011-08-16 06:29:00 +00002087static void stmmac_set_rx_mode(struct net_device *dev)
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002088{
2089 struct stmmac_priv *priv = netdev_priv(dev);
2090
2091 spin_lock(&priv->lock);
Giuseppe CAVALLAROcffb13f2012-05-13 22:18:41 +00002092 priv->hw->mac->set_filter(dev, priv->synopsys_id);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002093 spin_unlock(&priv->lock);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002094}
2095
2096/**
2097 * stmmac_change_mtu - entry point to change MTU size for the device.
2098 * @dev : device pointer.
2099 * @new_mtu : the new MTU size for the device.
2100 * Description: the Maximum Transfer Unit (MTU) is used by the network layer
2101 * to drive packet transmission. Ethernet has an MTU of 1500 octets
2102 * (ETH_DATA_LEN). This value can be changed with ifconfig.
2103 * Return value:
2104 * 0 on success and an appropriate (-)ve integer as defined in errno.h
2105 * file on failure.
2106 */
2107static int stmmac_change_mtu(struct net_device *dev, int new_mtu)
2108{
2109 struct stmmac_priv *priv = netdev_priv(dev);
2110 int max_mtu;
2111
2112 if (netif_running(dev)) {
2113 pr_err("%s: must be stopped to change its MTU\n", dev->name);
2114 return -EBUSY;
2115 }
2116
Giuseppe CAVALLARO48febf72011-10-18 00:01:21 +00002117 if (priv->plat->enh_desc)
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002118 max_mtu = JUMBO_LEN;
2119 else
Giuseppe CAVALLARO45db81e2011-10-18 01:39:55 +00002120 max_mtu = SKB_MAX_HEAD(NET_SKB_PAD + NET_IP_ALIGN);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002121
2122 if ((new_mtu < 46) || (new_mtu > max_mtu)) {
2123 pr_err("%s: invalid MTU, max MTU is: %d\n", dev->name, max_mtu);
2124 return -EINVAL;
2125 }
2126
Michał Mirosław5e982f32011-04-09 02:46:55 +00002127 dev->mtu = new_mtu;
2128 netdev_update_features(dev);
2129
2130 return 0;
2131}
2132
Michał Mirosławc8f44af2011-11-15 15:29:55 +00002133static netdev_features_t stmmac_fix_features(struct net_device *dev,
2134 netdev_features_t features)
Michał Mirosław5e982f32011-04-09 02:46:55 +00002135{
2136 struct stmmac_priv *priv = netdev_priv(dev);
2137
Deepak SIKRI38912bd2012-04-04 04:33:21 +00002138 if (priv->plat->rx_coe == STMMAC_RX_COE_NONE)
Michał Mirosław5e982f32011-04-09 02:46:55 +00002139 features &= ~NETIF_F_RXCSUM;
Deepak SIKRI38912bd2012-04-04 04:33:21 +00002140 else if (priv->plat->rx_coe == STMMAC_RX_COE_TYPE1)
2141 features &= ~NETIF_F_IPV6_CSUM;
Michał Mirosław5e982f32011-04-09 02:46:55 +00002142 if (!priv->plat->tx_coe)
2143 features &= ~NETIF_F_ALL_CSUM;
2144
Giuseppe CAVALLAROebbb2932010-09-17 03:23:40 +00002145 /* Some GMAC devices have a bugged Jumbo frame support that
2146 * needs to have the Tx COE disabled for oversized frames
2147 * (due to limited buffer sizes). In this case we disable
2148 * the TX csum insertionin the TDES and not use SF. */
Michał Mirosław5e982f32011-04-09 02:46:55 +00002149 if (priv->plat->bugged_jumbo && (dev->mtu > ETH_DATA_LEN))
2150 features &= ~NETIF_F_ALL_CSUM;
Giuseppe CAVALLAROebbb2932010-09-17 03:23:40 +00002151
Michał Mirosław5e982f32011-04-09 02:46:55 +00002152 return features;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002153}
2154
2155static irqreturn_t stmmac_interrupt(int irq, void *dev_id)
2156{
2157 struct net_device *dev = (struct net_device *)dev_id;
2158 struct stmmac_priv *priv = netdev_priv(dev);
2159
2160 if (unlikely(!dev)) {
2161 pr_err("%s: invalid dev pointer\n", __func__);
2162 return IRQ_NONE;
2163 }
2164
Giuseppe CAVALLAROd7659552012-06-27 21:14:37 +00002165 /* To handle GMAC own interrupts */
2166 if (priv->plat->has_gmac) {
2167 int status = priv->hw->mac->host_irq_status((void __iomem *)
Giuseppe CAVALLARO0982a0f2013-03-26 04:43:07 +00002168 dev->base_addr,
2169 &priv->xstats);
Giuseppe CAVALLAROd7659552012-06-27 21:14:37 +00002170 if (unlikely(status)) {
Giuseppe CAVALLAROd7659552012-06-27 21:14:37 +00002171 /* For LPI we need to save the tx status */
Giuseppe CAVALLARO0982a0f2013-03-26 04:43:07 +00002172 if (status & CORE_IRQ_TX_PATH_IN_LPI_MODE)
Giuseppe CAVALLAROd7659552012-06-27 21:14:37 +00002173 priv->tx_path_in_lpi_mode = true;
Giuseppe CAVALLARO0982a0f2013-03-26 04:43:07 +00002174 if (status & CORE_IRQ_TX_PATH_EXIT_LPI_MODE)
Giuseppe CAVALLAROd7659552012-06-27 21:14:37 +00002175 priv->tx_path_in_lpi_mode = false;
Giuseppe CAVALLAROd7659552012-06-27 21:14:37 +00002176 }
2177 }
2178
2179 /* To handle DMA interrupts */
Giuseppe CAVALLAROaec7ff22010-01-06 23:07:18 +00002180 stmmac_dma_interrupt(priv);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002181
2182 return IRQ_HANDLED;
2183}
2184
2185#ifdef CONFIG_NET_POLL_CONTROLLER
2186/* Polling receive - used by NETCONSOLE and other diagnostic tools
2187 * to allow network I/O with interrupts disabled. */
2188static void stmmac_poll_controller(struct net_device *dev)
2189{
2190 disable_irq(dev->irq);
2191 stmmac_interrupt(dev->irq, dev);
2192 enable_irq(dev->irq);
2193}
2194#endif
2195
2196/**
2197 * stmmac_ioctl - Entry point for the Ioctl
2198 * @dev: Device pointer.
2199 * @rq: An IOCTL specefic structure, that can contain a pointer to
2200 * a proprietary structure used to pass information to the driver.
2201 * @cmd: IOCTL command
2202 * Description:
Rayagond Kokatanur891434b2013-03-26 04:43:10 +00002203 * Currently it supports just the phy_mii_ioctl(...) and HW time stamping.
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002204 */
2205static int stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2206{
2207 struct stmmac_priv *priv = netdev_priv(dev);
Rayagond Kokatanur891434b2013-03-26 04:43:10 +00002208 int ret = -EOPNOTSUPP;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002209
2210 if (!netif_running(dev))
2211 return -EINVAL;
2212
Rayagond Kokatanur891434b2013-03-26 04:43:10 +00002213 switch (cmd) {
2214 case SIOCGMIIPHY:
2215 case SIOCGMIIREG:
2216 case SIOCSMIIREG:
2217 if (!priv->phydev)
2218 return -EINVAL;
2219 ret = phy_mii_ioctl(priv->phydev, rq, cmd);
2220 break;
2221 case SIOCSHWTSTAMP:
2222 ret = stmmac_hwtstamp_ioctl(dev, rq);
2223 break;
2224 default:
2225 break;
2226 }
Richard Cochran28b04112010-07-17 08:48:55 +00002227
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002228 return ret;
2229}
2230
Giuseppe CAVALLARO7ac29052011-09-01 21:51:39 +00002231#ifdef CONFIG_STMMAC_DEBUG_FS
2232static struct dentry *stmmac_fs_dir;
2233static struct dentry *stmmac_rings_status;
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +00002234static struct dentry *stmmac_dma_cap;
Giuseppe CAVALLARO7ac29052011-09-01 21:51:39 +00002235
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00002236static void sysfs_display_ring(void *head, int size, int extend_desc,
2237 struct seq_file *seq)
Giuseppe CAVALLARO7ac29052011-09-01 21:51:39 +00002238{
Giuseppe CAVALLARO7ac29052011-09-01 21:51:39 +00002239 int i;
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00002240 struct dma_extended_desc *ep = (struct dma_extended_desc *) head;
2241 struct dma_desc *p = (struct dma_desc *) head;
Giuseppe CAVALLARO7ac29052011-09-01 21:51:39 +00002242
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00002243 for (i = 0; i < size; i++) {
2244 u64 x;
2245 if (extend_desc) {
2246 x = *(u64 *) ep;
2247 seq_printf(seq, "%d [0x%x]: 0x%x 0x%x 0x%x 0x%x\n",
2248 i, (unsigned int) virt_to_phys(ep),
2249 (unsigned int) x, (unsigned int) (x >> 32),
2250 ep->basic.des2, ep->basic.des3);
2251 ep++;
2252 } else {
2253 x = *(u64 *) p;
2254 seq_printf(seq, "%d [0x%x]: 0x%x 0x%x 0x%x 0x%x\n",
2255 i, (unsigned int) virt_to_phys(ep),
2256 (unsigned int) x, (unsigned int) (x >> 32),
2257 p->des2, p->des3);
2258 p++;
2259 }
Giuseppe CAVALLARO7ac29052011-09-01 21:51:39 +00002260 seq_printf(seq, "\n");
2261 }
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00002262}
Giuseppe CAVALLARO7ac29052011-09-01 21:51:39 +00002263
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00002264static int stmmac_sysfs_ring_read(struct seq_file *seq, void *v)
2265{
2266 struct net_device *dev = seq->private;
2267 struct stmmac_priv *priv = netdev_priv(dev);
2268 unsigned int txsize = priv->dma_tx_size;
2269 unsigned int rxsize = priv->dma_rx_size;
Giuseppe CAVALLARO7ac29052011-09-01 21:51:39 +00002270
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00002271 if (priv->extend_desc) {
2272 seq_printf(seq, "Extended RX descriptor ring:\n");
2273 sysfs_display_ring((void *) priv->dma_erx, rxsize, 1, seq);
2274 seq_printf(seq, "Extended TX descriptor ring:\n");
2275 sysfs_display_ring((void *) priv->dma_etx, txsize, 1, seq);
2276 } else {
2277 seq_printf(seq, "RX descriptor ring:\n");
2278 sysfs_display_ring((void *)priv->dma_rx, rxsize, 0, seq);
2279 seq_printf(seq, "TX descriptor ring:\n");
2280 sysfs_display_ring((void *)priv->dma_tx, txsize, 0, seq);
Giuseppe CAVALLARO7ac29052011-09-01 21:51:39 +00002281 }
2282
2283 return 0;
2284}
2285
2286static int stmmac_sysfs_ring_open(struct inode *inode, struct file *file)
2287{
2288 return single_open(file, stmmac_sysfs_ring_read, inode->i_private);
2289}
2290
2291static const struct file_operations stmmac_rings_status_fops = {
2292 .owner = THIS_MODULE,
2293 .open = stmmac_sysfs_ring_open,
2294 .read = seq_read,
2295 .llseek = seq_lseek,
Djalal Harouni74863942012-05-20 13:55:30 +00002296 .release = single_release,
Giuseppe CAVALLARO7ac29052011-09-01 21:51:39 +00002297};
2298
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +00002299static int stmmac_sysfs_dma_cap_read(struct seq_file *seq, void *v)
2300{
2301 struct net_device *dev = seq->private;
2302 struct stmmac_priv *priv = netdev_priv(dev);
2303
Giuseppe CAVALLARO19e30c12011-11-16 21:58:00 +00002304 if (!priv->hw_cap_support) {
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +00002305 seq_printf(seq, "DMA HW features not supported\n");
2306 return 0;
2307 }
2308
2309 seq_printf(seq, "==============================\n");
2310 seq_printf(seq, "\tDMA HW features\n");
2311 seq_printf(seq, "==============================\n");
2312
2313 seq_printf(seq, "\t10/100 Mbps %s\n",
2314 (priv->dma_cap.mbps_10_100) ? "Y" : "N");
2315 seq_printf(seq, "\t1000 Mbps %s\n",
2316 (priv->dma_cap.mbps_1000) ? "Y" : "N");
2317 seq_printf(seq, "\tHalf duple %s\n",
2318 (priv->dma_cap.half_duplex) ? "Y" : "N");
2319 seq_printf(seq, "\tHash Filter: %s\n",
2320 (priv->dma_cap.hash_filter) ? "Y" : "N");
2321 seq_printf(seq, "\tMultiple MAC address registers: %s\n",
2322 (priv->dma_cap.multi_addr) ? "Y" : "N");
2323 seq_printf(seq, "\tPCS (TBI/SGMII/RTBI PHY interfatces): %s\n",
2324 (priv->dma_cap.pcs) ? "Y" : "N");
2325 seq_printf(seq, "\tSMA (MDIO) Interface: %s\n",
2326 (priv->dma_cap.sma_mdio) ? "Y" : "N");
2327 seq_printf(seq, "\tPMT Remote wake up: %s\n",
2328 (priv->dma_cap.pmt_remote_wake_up) ? "Y" : "N");
2329 seq_printf(seq, "\tPMT Magic Frame: %s\n",
2330 (priv->dma_cap.pmt_magic_frame) ? "Y" : "N");
2331 seq_printf(seq, "\tRMON module: %s\n",
2332 (priv->dma_cap.rmon) ? "Y" : "N");
2333 seq_printf(seq, "\tIEEE 1588-2002 Time Stamp: %s\n",
2334 (priv->dma_cap.time_stamp) ? "Y" : "N");
2335 seq_printf(seq, "\tIEEE 1588-2008 Advanced Time Stamp:%s\n",
2336 (priv->dma_cap.atime_stamp) ? "Y" : "N");
2337 seq_printf(seq, "\t802.3az - Energy-Efficient Ethernet (EEE) %s\n",
2338 (priv->dma_cap.eee) ? "Y" : "N");
2339 seq_printf(seq, "\tAV features: %s\n", (priv->dma_cap.av) ? "Y" : "N");
2340 seq_printf(seq, "\tChecksum Offload in TX: %s\n",
2341 (priv->dma_cap.tx_coe) ? "Y" : "N");
2342 seq_printf(seq, "\tIP Checksum Offload (type1) in RX: %s\n",
2343 (priv->dma_cap.rx_coe_type1) ? "Y" : "N");
2344 seq_printf(seq, "\tIP Checksum Offload (type2) in RX: %s\n",
2345 (priv->dma_cap.rx_coe_type2) ? "Y" : "N");
2346 seq_printf(seq, "\tRXFIFO > 2048bytes: %s\n",
2347 (priv->dma_cap.rxfifo_over_2048) ? "Y" : "N");
2348 seq_printf(seq, "\tNumber of Additional RX channel: %d\n",
2349 priv->dma_cap.number_rx_channel);
2350 seq_printf(seq, "\tNumber of Additional TX channel: %d\n",
2351 priv->dma_cap.number_tx_channel);
2352 seq_printf(seq, "\tEnhanced descriptors: %s\n",
2353 (priv->dma_cap.enh_desc) ? "Y" : "N");
2354
2355 return 0;
2356}
2357
2358static int stmmac_sysfs_dma_cap_open(struct inode *inode, struct file *file)
2359{
2360 return single_open(file, stmmac_sysfs_dma_cap_read, inode->i_private);
2361}
2362
2363static const struct file_operations stmmac_dma_cap_fops = {
2364 .owner = THIS_MODULE,
2365 .open = stmmac_sysfs_dma_cap_open,
2366 .read = seq_read,
2367 .llseek = seq_lseek,
Djalal Harouni74863942012-05-20 13:55:30 +00002368 .release = single_release,
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +00002369};
2370
Giuseppe CAVALLARO7ac29052011-09-01 21:51:39 +00002371static int stmmac_init_fs(struct net_device *dev)
2372{
2373 /* Create debugfs entries */
2374 stmmac_fs_dir = debugfs_create_dir(STMMAC_RESOURCE_NAME, NULL);
2375
2376 if (!stmmac_fs_dir || IS_ERR(stmmac_fs_dir)) {
2377 pr_err("ERROR %s, debugfs create directory failed\n",
2378 STMMAC_RESOURCE_NAME);
2379
2380 return -ENOMEM;
2381 }
2382
2383 /* Entry to report DMA RX/TX rings */
2384 stmmac_rings_status = debugfs_create_file("descriptors_status",
2385 S_IRUGO, stmmac_fs_dir, dev,
2386 &stmmac_rings_status_fops);
2387
2388 if (!stmmac_rings_status || IS_ERR(stmmac_rings_status)) {
2389 pr_info("ERROR creating stmmac ring debugfs file\n");
2390 debugfs_remove(stmmac_fs_dir);
2391
2392 return -ENOMEM;
2393 }
2394
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +00002395 /* Entry to report the DMA HW features */
2396 stmmac_dma_cap = debugfs_create_file("dma_cap", S_IRUGO, stmmac_fs_dir,
2397 dev, &stmmac_dma_cap_fops);
2398
2399 if (!stmmac_dma_cap || IS_ERR(stmmac_dma_cap)) {
2400 pr_info("ERROR creating stmmac MMC debugfs file\n");
2401 debugfs_remove(stmmac_rings_status);
2402 debugfs_remove(stmmac_fs_dir);
2403
2404 return -ENOMEM;
2405 }
2406
Giuseppe CAVALLARO7ac29052011-09-01 21:51:39 +00002407 return 0;
2408}
2409
2410static void stmmac_exit_fs(void)
2411{
2412 debugfs_remove(stmmac_rings_status);
Giuseppe CAVALLAROe7434822011-09-01 21:51:41 +00002413 debugfs_remove(stmmac_dma_cap);
Giuseppe CAVALLARO7ac29052011-09-01 21:51:39 +00002414 debugfs_remove(stmmac_fs_dir);
2415}
2416#endif /* CONFIG_STMMAC_DEBUG_FS */
2417
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002418static const struct net_device_ops stmmac_netdev_ops = {
2419 .ndo_open = stmmac_open,
2420 .ndo_start_xmit = stmmac_xmit,
2421 .ndo_stop = stmmac_release,
2422 .ndo_change_mtu = stmmac_change_mtu,
Michał Mirosław5e982f32011-04-09 02:46:55 +00002423 .ndo_fix_features = stmmac_fix_features,
Jiri Pirko01789342011-08-16 06:29:00 +00002424 .ndo_set_rx_mode = stmmac_set_rx_mode,
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002425 .ndo_tx_timeout = stmmac_tx_timeout,
2426 .ndo_do_ioctl = stmmac_ioctl,
2427 .ndo_set_config = stmmac_config,
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002428#ifdef CONFIG_NET_POLL_CONTROLLER
2429 .ndo_poll_controller = stmmac_poll_controller,
2430#endif
2431 .ndo_set_mac_address = eth_mac_addr,
2432};
2433
2434/**
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00002435 * stmmac_hw_init - Init the MAC device
2436 * @priv : pointer to the private device structure.
2437 * Description: this function detects which MAC device
2438 * (GMAC/MAC10-100) has to attached, checks the HW capability
2439 * (if supported) and sets the driver's features (for example
2440 * to use the ring or chaine mode or support the normal/enh
2441 * descriptor structure).
2442 */
2443static int stmmac_hw_init(struct stmmac_priv *priv)
2444{
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00002445 int ret;
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00002446 struct mac_device_info *mac;
2447
2448 /* Identify the MAC HW device */
Marc Kleine-Budde03f2eec2012-04-03 22:13:01 +00002449 if (priv->plat->has_gmac) {
2450 priv->dev->priv_flags |= IFF_UNICAST_FLT;
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00002451 mac = dwmac1000_setup(priv->ioaddr);
Marc Kleine-Budde03f2eec2012-04-03 22:13:01 +00002452 } else {
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00002453 mac = dwmac100_setup(priv->ioaddr);
Marc Kleine-Budde03f2eec2012-04-03 22:13:01 +00002454 }
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00002455 if (!mac)
2456 return -ENOMEM;
2457
2458 priv->hw = mac;
2459
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00002460 /* Get and dump the chip ID */
Giuseppe CAVALLAROcffb13f2012-05-13 22:18:41 +00002461 priv->synopsys_id = stmmac_get_synopsys_id(priv);
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00002462
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00002463 /* To use alternate (extended) or normal descriptor structures */
2464 stmmac_selec_desc_mode(priv);
2465
Giuseppe CAVALLARO4a7d6662013-03-26 04:43:05 +00002466 /* To use the chained or ring mode */
2467 if (chain_mode) {
2468 priv->hw->chain = &chain_mode_ops;
2469 pr_info(" Chain mode enabled\n");
2470 priv->mode = STMMAC_CHAIN_MODE;
2471 } else {
2472 priv->hw->ring = &ring_mode_ops;
2473 pr_info(" Ring mode enabled\n");
2474 priv->mode = STMMAC_RING_MODE;
2475 }
2476
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00002477 /* Get the HW capability (new GMAC newer than 3.50a) */
2478 priv->hw_cap_support = stmmac_get_hw_features(priv);
2479 if (priv->hw_cap_support) {
2480 pr_info(" DMA HW capability register supported");
2481
2482 /* We can override some gmac/dma configuration fields: e.g.
2483 * enh_desc, tx_coe (e.g. that are passed through the
2484 * platform) with the values from the HW capability
2485 * register (if supported).
2486 */
2487 priv->plat->enh_desc = priv->dma_cap.enh_desc;
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00002488 priv->plat->pmt = priv->dma_cap.pmt_remote_wake_up;
Deepak SIKRI38912bd2012-04-04 04:33:21 +00002489
2490 priv->plat->tx_coe = priv->dma_cap.tx_coe;
2491
2492 if (priv->dma_cap.rx_coe_type2)
2493 priv->plat->rx_coe = STMMAC_RX_COE_TYPE2;
2494 else if (priv->dma_cap.rx_coe_type1)
2495 priv->plat->rx_coe = STMMAC_RX_COE_TYPE1;
2496
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00002497 } else
2498 pr_info(" No HW DMA feature register supported");
2499
Deepak SIKRI38912bd2012-04-04 04:33:21 +00002500 /* Enable the IPC (Checksum Offload) and check if the feature has been
2501 * enabled during the core configuration. */
2502 ret = priv->hw->mac->rx_ipc(priv->ioaddr);
2503 if (!ret) {
2504 pr_warning(" RX IPC Checksum Offload not configured.\n");
2505 priv->plat->rx_coe = STMMAC_RX_COE_NONE;
2506 }
2507
2508 if (priv->plat->rx_coe)
2509 pr_info(" RX Checksum Offload Engine supported (type %d)\n",
2510 priv->plat->rx_coe);
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00002511 if (priv->plat->tx_coe)
2512 pr_info(" TX Checksum insertion supported\n");
2513
2514 if (priv->plat->pmt) {
2515 pr_info(" Wake-Up On Lan supported\n");
2516 device_set_wakeup_capable(priv->device, 1);
2517 }
2518
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00002519 return 0;
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00002520}
2521
2522/**
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002523 * stmmac_dvr_probe
2524 * @device: device pointer
Giuseppe CAVALLAROff3dd782012-06-04 19:22:55 +00002525 * @plat_dat: platform data pointer
2526 * @addr: iobase memory address
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002527 * Description: this is the main probe function used to
2528 * call the alloc_etherdev, allocate the priv structure.
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002529 */
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002530struct stmmac_priv *stmmac_dvr_probe(struct device *device,
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00002531 struct plat_stmmacenet_data *plat_dat,
2532 void __iomem *addr)
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002533{
2534 int ret = 0;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002535 struct net_device *ndev = NULL;
2536 struct stmmac_priv *priv;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002537
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002538 ndev = alloc_etherdev(sizeof(struct stmmac_priv));
Joe Perches41de8d42012-01-29 13:47:52 +00002539 if (!ndev)
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002540 return NULL;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002541
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002542 SET_NETDEV_DEV(ndev, device);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002543
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002544 priv = netdev_priv(ndev);
2545 priv->device = device;
2546 priv->dev = ndev;
2547
2548 ether_setup(ndev);
2549
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002550 stmmac_set_ethtool_ops(ndev);
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00002551 priv->pause = pause;
2552 priv->plat = plat_dat;
2553 priv->ioaddr = addr;
2554 priv->dev->base_addr = (unsigned long)addr;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002555
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00002556 /* Verify driver arguments */
2557 stmmac_verify_args();
2558
2559 /* Override with kernel parameters if supplied XXX CRS XXX
2560 * this needs to have multiple instances */
2561 if ((phyaddr >= 0) && (phyaddr <= 31))
2562 priv->plat->phy_addr = phyaddr;
2563
2564 /* Init MAC and get the capabilities */
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00002565 ret = stmmac_hw_init(priv);
2566 if (ret)
2567 goto error_free_netdev;
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00002568
2569 ndev->netdev_ops = &stmmac_netdev_ops;
2570
2571 ndev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
2572 NETIF_F_RXCSUM;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002573 ndev->features |= ndev->hw_features | NETIF_F_HIGHDMA;
2574 ndev->watchdog_timeo = msecs_to_jiffies(watchdog);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002575#ifdef STMMAC_VLAN_TAG_USED
2576 /* Both mac100 and gmac support receive VLAN tag detection */
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002577 ndev->features |= NETIF_F_HW_VLAN_RX;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002578#endif
2579 priv->msg_enable = netif_msg_init(debug, default_msg_level);
2580
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002581 if (flow_ctrl)
2582 priv->flow_ctrl = FLOW_AUTO; /* RX/TX pause on */
2583
Giuseppe CAVALLARO62a2ab92012-11-25 23:10:43 +00002584 /* Rx Watchdog is available in the COREs newer than the 3.40.
2585 * In some case, for example on bugged HW this feature
2586 * has to be disable and this can be done by passing the
2587 * riwt_off field from the platform.
2588 */
2589 if ((priv->synopsys_id >= DWMAC_CORE_3_50) && (!priv->plat->riwt_off)) {
2590 priv->use_riwt = 1;
2591 pr_info(" Enable RX Mitigation via HW Watchdog Timer\n");
2592 }
2593
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002594 netif_napi_add(ndev, &priv->napi, stmmac_poll, 64);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002595
Vlad Lunguf8e96162010-11-29 22:52:52 +00002596 spin_lock_init(&priv->lock);
Giuseppe CAVALLAROa9097a92011-10-18 00:01:19 +00002597 spin_lock_init(&priv->tx_lock);
Vlad Lunguf8e96162010-11-29 22:52:52 +00002598
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002599 ret = register_netdev(ndev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002600 if (ret) {
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +00002601 pr_err("%s: ERROR %i registering the device\n", __func__, ret);
Viresh Kumar6a81c262012-07-30 14:39:41 -07002602 goto error_netdev_register;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002603 }
2604
Kelvin Cheungae4d8cf2012-08-18 00:16:23 +00002605 priv->stmmac_clk = clk_get(priv->device, STMMAC_RESOURCE_NAME);
Viresh Kumar6a81c262012-07-30 14:39:41 -07002606 if (IS_ERR(priv->stmmac_clk)) {
Giuseppe CAVALLARO31ea38e2012-04-18 19:48:22 +00002607 pr_warning("%s: warning: cannot get CSR clock\n", __func__);
Viresh Kumar6a81c262012-07-30 14:39:41 -07002608 goto error_clk_get;
2609 }
Giuseppe CAVALLAROba1377ff2012-04-04 04:33:25 +00002610
Giuseppe CAVALLAROcd7201f2012-04-04 04:33:27 +00002611 /* If a specific clk_csr value is passed from the platform
2612 * this means that the CSR Clock Range selection cannot be
2613 * changed at run-time and it is fixed. Viceversa the driver'll try to
2614 * set the MDC clock dynamically according to the csr actual
2615 * clock input.
2616 */
2617 if (!priv->plat->clk_csr)
2618 stmmac_clk_csr_set(priv);
2619 else
2620 priv->clk_csr = priv->plat->clk_csr;
2621
Giuseppe CAVALLAROe58bb432013-03-26 04:43:08 +00002622 stmmac_check_pcs_mode(priv);
2623
2624 if (!priv->pcs) {
2625 /* MDIO bus Registration */
2626 ret = stmmac_mdio_register(ndev);
2627 if (ret < 0) {
2628 pr_debug("%s: MDIO bus (id: %d) registration failed",
2629 __func__, priv->plat->bus_id);
2630 goto error_mdio_register;
2631 }
Francesco Virlinzi4bfcbd72012-04-18 19:48:20 +00002632 }
2633
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002634 return priv;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002635
Viresh Kumar6a81c262012-07-30 14:39:41 -07002636error_mdio_register:
2637 clk_put(priv->stmmac_clk);
2638error_clk_get:
Dan Carpenter34a52f32010-12-20 21:34:56 +00002639 unregister_netdev(ndev);
Viresh Kumar6a81c262012-07-30 14:39:41 -07002640error_netdev_register:
2641 netif_napi_del(&priv->napi);
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00002642error_free_netdev:
Dan Carpenter34a52f32010-12-20 21:34:56 +00002643 free_netdev(ndev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002644
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002645 return NULL;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002646}
2647
2648/**
2649 * stmmac_dvr_remove
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002650 * @ndev: net device pointer
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002651 * Description: this function resets the TX/RX processes, disables the MAC RX/TX
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002652 * changes the link status, releases the DMA descriptor rings.
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002653 */
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002654int stmmac_dvr_remove(struct net_device *ndev)
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002655{
Giuseppe CAVALLAROaec7ff22010-01-06 23:07:18 +00002656 struct stmmac_priv *priv = netdev_priv(ndev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002657
2658 pr_info("%s:\n\tremoving driver", __func__);
2659
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +00002660 priv->hw->dma->stop_rx(priv->ioaddr);
2661 priv->hw->dma->stop_tx(priv->ioaddr);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002662
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002663 stmmac_set_mac(priv->ioaddr, false);
Giuseppe CAVALLAROe58bb432013-03-26 04:43:08 +00002664 if (!priv->pcs)
2665 stmmac_mdio_unregister(ndev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002666 netif_carrier_off(ndev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002667 unregister_netdev(ndev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002668 free_netdev(ndev);
2669
2670 return 0;
2671}
2672
2673#ifdef CONFIG_PM
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002674int stmmac_suspend(struct net_device *ndev)
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002675{
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002676 struct stmmac_priv *priv = netdev_priv(ndev);
Giuseppe CAVALLAROf8c5a872012-05-13 22:18:43 +00002677 unsigned long flags;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002678
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002679 if (!ndev || !netif_running(ndev))
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002680 return 0;
2681
Francesco Virlinzi102463b2011-11-16 21:58:02 +00002682 if (priv->phydev)
2683 phy_stop(priv->phydev);
2684
Giuseppe CAVALLAROf8c5a872012-05-13 22:18:43 +00002685 spin_lock_irqsave(&priv->lock, flags);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002686
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002687 netif_device_detach(ndev);
2688 netif_stop_queue(ndev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002689
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002690 napi_disable(&priv->napi);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002691
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002692 /* Stop TX/RX DMA */
2693 priv->hw->dma->stop_tx(priv->ioaddr);
2694 priv->hw->dma->stop_rx(priv->ioaddr);
Giuseppe CAVALLAROc24602e2013-03-26 04:43:06 +00002695
2696 stmmac_clear_descriptors(priv);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002697
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002698 /* Enable Power down mode by programming the PMT regs */
2699 if (device_may_wakeup(priv->device))
2700 priv->hw->mac->pmt(priv->ioaddr, priv->wolopts);
Giuseppe CAVALLAROba1377ff2012-04-04 04:33:25 +00002701 else {
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002702 stmmac_set_mac(priv->ioaddr, false);
Giuseppe CAVALLAROba1377ff2012-04-04 04:33:25 +00002703 /* Disable clock in case of PWM is off */
Stefan Roesea6308442012-09-21 01:06:29 +00002704 clk_disable_unprepare(priv->stmmac_clk);
Giuseppe CAVALLAROba1377ff2012-04-04 04:33:25 +00002705 }
Giuseppe CAVALLAROf8c5a872012-05-13 22:18:43 +00002706 spin_unlock_irqrestore(&priv->lock, flags);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002707 return 0;
2708}
2709
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002710int stmmac_resume(struct net_device *ndev)
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002711{
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002712 struct stmmac_priv *priv = netdev_priv(ndev);
Giuseppe CAVALLAROf8c5a872012-05-13 22:18:43 +00002713 unsigned long flags;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002714
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002715 if (!netif_running(ndev))
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002716 return 0;
2717
Giuseppe CAVALLAROf8c5a872012-05-13 22:18:43 +00002718 spin_lock_irqsave(&priv->lock, flags);
Giuseppe Cavallaroc4433be2010-09-06 05:02:11 +02002719
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002720 /* Power Down bit, into the PM register, is cleared
2721 * automatically as soon as a magic packet or a Wake-up frame
2722 * is received. Anyway, it's better to manually clear
2723 * this bit because it can generate problems while resuming
2724 * from another devices (e.g. serial console). */
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002725 if (device_may_wakeup(priv->device))
Giuseppe Cavallaro543876c2010-09-24 21:27:41 -07002726 priv->hw->mac->pmt(priv->ioaddr, 0);
Giuseppe CAVALLAROba1377ff2012-04-04 04:33:25 +00002727 else
2728 /* enable the clk prevously disabled */
Stefan Roesea6308442012-09-21 01:06:29 +00002729 clk_prepare_enable(priv->stmmac_clk);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002730
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002731 netif_device_attach(ndev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002732
2733 /* Enable the MAC and DMA */
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002734 stmmac_set_mac(priv->ioaddr, true);
Giuseppe CAVALLAROad01b7d2010-08-23 20:40:42 +00002735 priv->hw->dma->start_tx(priv->ioaddr);
2736 priv->hw->dma->start_rx(priv->ioaddr);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002737
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002738 napi_enable(&priv->napi);
2739
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002740 netif_start_queue(ndev);
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002741
Giuseppe CAVALLAROf8c5a872012-05-13 22:18:43 +00002742 spin_unlock_irqrestore(&priv->lock, flags);
Francesco Virlinzi102463b2011-11-16 21:58:02 +00002743
2744 if (priv->phydev)
2745 phy_start(priv->phydev);
2746
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002747 return 0;
2748}
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002749
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002750int stmmac_freeze(struct net_device *ndev)
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002751{
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002752 if (!ndev || !netif_running(ndev))
2753 return 0;
2754
2755 return stmmac_release(ndev);
2756}
2757
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00002758int stmmac_restore(struct net_device *ndev)
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002759{
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002760 if (!ndev || !netif_running(ndev))
2761 return 0;
2762
2763 return stmmac_open(ndev);
2764}
Giuseppe CAVALLARO874bd422010-11-24 02:38:11 +00002765#endif /* CONFIG_PM */
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002766
Giuseppe CAVALLARO33d5e332012-06-07 19:25:07 +00002767/* Driver can be configured w/ and w/ both PCI and Platf drivers
2768 * depending on the configuration selected.
2769 */
Giuseppe CAVALLAROba27ec62012-06-04 19:22:57 +00002770static int __init stmmac_init(void)
2771{
Konstantin Khlebnikov493682b2012-12-14 01:02:51 +00002772 int ret;
Giuseppe CAVALLAROba27ec62012-06-04 19:22:57 +00002773
Konstantin Khlebnikov493682b2012-12-14 01:02:51 +00002774 ret = stmmac_register_platform();
2775 if (ret)
2776 goto err;
2777 ret = stmmac_register_pci();
2778 if (ret)
2779 goto err_pci;
Giuseppe CAVALLARO33d5e332012-06-07 19:25:07 +00002780 return 0;
Konstantin Khlebnikov493682b2012-12-14 01:02:51 +00002781err_pci:
2782 stmmac_unregister_platform();
2783err:
2784 pr_err("stmmac: driver registration failed\n");
2785 return ret;
Giuseppe CAVALLAROba27ec62012-06-04 19:22:57 +00002786}
2787
2788static void __exit stmmac_exit(void)
2789{
Giuseppe CAVALLARO33d5e332012-06-07 19:25:07 +00002790 stmmac_unregister_platform();
2791 stmmac_unregister_pci();
Giuseppe CAVALLAROba27ec62012-06-04 19:22:57 +00002792}
2793
2794module_init(stmmac_init);
2795module_exit(stmmac_exit);
2796
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002797#ifndef MODULE
2798static int __init stmmac_cmdline_opt(char *str)
2799{
2800 char *opt;
2801
2802 if (!str || !*str)
2803 return -EINVAL;
2804 while ((opt = strsep(&str, ",")) != NULL) {
Giuseppe CAVALLAROf3240e22011-07-20 00:05:22 +00002805 if (!strncmp(opt, "debug:", 6)) {
Giuseppe CAVALLAROea2ab872012-06-27 21:14:35 +00002806 if (kstrtoint(opt + 6, 0, &debug))
Giuseppe CAVALLAROf3240e22011-07-20 00:05:22 +00002807 goto err;
2808 } else if (!strncmp(opt, "phyaddr:", 8)) {
Giuseppe CAVALLAROea2ab872012-06-27 21:14:35 +00002809 if (kstrtoint(opt + 8, 0, &phyaddr))
Giuseppe CAVALLAROf3240e22011-07-20 00:05:22 +00002810 goto err;
2811 } else if (!strncmp(opt, "dma_txsize:", 11)) {
Giuseppe CAVALLAROea2ab872012-06-27 21:14:35 +00002812 if (kstrtoint(opt + 11, 0, &dma_txsize))
Giuseppe CAVALLAROf3240e22011-07-20 00:05:22 +00002813 goto err;
2814 } else if (!strncmp(opt, "dma_rxsize:", 11)) {
Giuseppe CAVALLAROea2ab872012-06-27 21:14:35 +00002815 if (kstrtoint(opt + 11, 0, &dma_rxsize))
Giuseppe CAVALLAROf3240e22011-07-20 00:05:22 +00002816 goto err;
2817 } else if (!strncmp(opt, "buf_sz:", 7)) {
Giuseppe CAVALLAROea2ab872012-06-27 21:14:35 +00002818 if (kstrtoint(opt + 7, 0, &buf_sz))
Giuseppe CAVALLAROf3240e22011-07-20 00:05:22 +00002819 goto err;
2820 } else if (!strncmp(opt, "tc:", 3)) {
Giuseppe CAVALLAROea2ab872012-06-27 21:14:35 +00002821 if (kstrtoint(opt + 3, 0, &tc))
Giuseppe CAVALLAROf3240e22011-07-20 00:05:22 +00002822 goto err;
2823 } else if (!strncmp(opt, "watchdog:", 9)) {
Giuseppe CAVALLAROea2ab872012-06-27 21:14:35 +00002824 if (kstrtoint(opt + 9, 0, &watchdog))
Giuseppe CAVALLAROf3240e22011-07-20 00:05:22 +00002825 goto err;
2826 } else if (!strncmp(opt, "flow_ctrl:", 10)) {
Giuseppe CAVALLAROea2ab872012-06-27 21:14:35 +00002827 if (kstrtoint(opt + 10, 0, &flow_ctrl))
Giuseppe CAVALLAROf3240e22011-07-20 00:05:22 +00002828 goto err;
2829 } else if (!strncmp(opt, "pause:", 6)) {
Giuseppe CAVALLAROea2ab872012-06-27 21:14:35 +00002830 if (kstrtoint(opt + 6, 0, &pause))
Giuseppe CAVALLAROf3240e22011-07-20 00:05:22 +00002831 goto err;
Giuseppe CAVALLARO506f6692013-02-14 23:00:13 +00002832 } else if (!strncmp(opt, "eee_timer:", 10)) {
Giuseppe CAVALLAROd7659552012-06-27 21:14:37 +00002833 if (kstrtoint(opt + 10, 0, &eee_timer))
2834 goto err;
Giuseppe CAVALLARO4a7d6662013-03-26 04:43:05 +00002835 } else if (!strncmp(opt, "chain_mode:", 11)) {
2836 if (kstrtoint(opt + 11, 0, &chain_mode))
2837 goto err;
Giuseppe CAVALLAROf3240e22011-07-20 00:05:22 +00002838 }
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002839 }
2840 return 0;
Giuseppe CAVALLAROf3240e22011-07-20 00:05:22 +00002841
2842err:
2843 pr_err("%s: ERROR broken module parameter conversion", __func__);
2844 return -EINVAL;
Giuseppe Cavallaro47dd7a52009-10-14 15:13:45 -07002845}
2846
2847__setup("stmmaceth=", stmmac_cmdline_opt);
2848#endif
Giuseppe Cavallaro6fc0d0f2011-12-23 14:21:20 -05002849
2850MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet device driver");
2851MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
2852MODULE_LICENSE("GPL");