Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | This is the driver for the ST MAC 10/100/1000 on-chip Ethernet controllers. |
| 3 | ST Ethernet IPs are built around a Synopsys IP Core. |
| 4 | |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 5 | Copyright(C) 2007-2011 STMicroelectronics Ltd |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 6 | |
| 7 | This program is free software; you can redistribute it and/or modify it |
| 8 | under the terms and conditions of the GNU General Public License, |
| 9 | version 2, as published by the Free Software Foundation. |
| 10 | |
| 11 | This program is distributed in the hope it will be useful, but WITHOUT |
| 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 14 | more details. |
| 15 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 16 | The full GNU General Public License is included in this distribution in |
| 17 | the file called "COPYING". |
| 18 | |
| 19 | Author: Giuseppe Cavallaro <peppe.cavallaro@st.com> |
| 20 | |
| 21 | Documentation available at: |
| 22 | http://www.stlinux.com |
| 23 | Support available at: |
| 24 | https://bugzilla.stlinux.com/ |
| 25 | *******************************************************************************/ |
| 26 | |
Viresh Kumar | 6a81c26 | 2012-07-30 14:39:41 -0700 | [diff] [blame] | 27 | #include <linux/clk.h> |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 28 | #include <linux/kernel.h> |
| 29 | #include <linux/interrupt.h> |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 30 | #include <linux/ip.h> |
| 31 | #include <linux/tcp.h> |
| 32 | #include <linux/skbuff.h> |
| 33 | #include <linux/ethtool.h> |
| 34 | #include <linux/if_ether.h> |
| 35 | #include <linux/crc32.h> |
| 36 | #include <linux/mii.h> |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 37 | #include <linux/if.h> |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 38 | #include <linux/if_vlan.h> |
| 39 | #include <linux/dma-mapping.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 40 | #include <linux/slab.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 41 | #include <linux/prefetch.h> |
Srinivas Kandagatla | db88f10 | 2014-01-16 10:52:52 +0000 | [diff] [blame] | 42 | #include <linux/pinctrl/consumer.h> |
Giuseppe CAVALLARO | 50fb4f74 | 2014-11-04 15:49:33 +0100 | [diff] [blame] | 43 | #ifdef CONFIG_DEBUG_FS |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 44 | #include <linux/debugfs.h> |
| 45 | #include <linux/seq_file.h> |
Giuseppe CAVALLARO | 50fb4f74 | 2014-11-04 15:49:33 +0100 | [diff] [blame] | 46 | #endif /* CONFIG_DEBUG_FS */ |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 47 | #include <linux/net_tstamp.h> |
| 48 | #include "stmmac_ptp.h" |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 49 | #include "stmmac.h" |
Chen-Yu Tsai | c5e4ddb | 2014-01-17 21:24:41 +0800 | [diff] [blame] | 50 | #include <linux/reset.h> |
Mathieu Olivari | 5790cf3 | 2015-05-27 11:02:47 -0700 | [diff] [blame] | 51 | #include <linux/of_mdio.h> |
Phil Reid | 19d857c | 2015-12-14 11:32:01 +0800 | [diff] [blame] | 52 | #include "dwmac1000.h" |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 53 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 54 | #define STMMAC_ALIGN(x) L1_CACHE_ALIGN(x) |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 55 | #define TSO_MAX_BUFF_SIZE (SZ_16K - 1) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 56 | |
| 57 | /* Module parameters */ |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 58 | #define TX_TIMEO 5000 |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 59 | static int watchdog = TX_TIMEO; |
| 60 | module_param(watchdog, int, S_IRUGO | S_IWUSR); |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 61 | MODULE_PARM_DESC(watchdog, "Transmit timeout in milliseconds (default 5s)"); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 62 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 63 | static int debug = -1; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 64 | module_param(debug, int, S_IRUGO | S_IWUSR); |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 65 | MODULE_PARM_DESC(debug, "Message Level (-1: default, 0: no output, 16: all)"); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 66 | |
stephen hemminger | 47d1f71 | 2013-12-30 10:38:57 -0800 | [diff] [blame] | 67 | static int phyaddr = -1; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 68 | module_param(phyaddr, int, S_IRUGO); |
| 69 | MODULE_PARM_DESC(phyaddr, "Physical device address"); |
| 70 | |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 71 | #define STMMAC_TX_THRESH (DMA_TX_SIZE / 4) |
Giuseppe Cavallaro | 120e87f | 2016-02-29 14:27:42 +0100 | [diff] [blame] | 72 | #define STMMAC_RX_THRESH (DMA_RX_SIZE / 4) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 73 | |
| 74 | static int flow_ctrl = FLOW_OFF; |
| 75 | module_param(flow_ctrl, int, S_IRUGO | S_IWUSR); |
| 76 | MODULE_PARM_DESC(flow_ctrl, "Flow control ability [on/off]"); |
| 77 | |
| 78 | static int pause = PAUSE_TIME; |
| 79 | module_param(pause, int, S_IRUGO | S_IWUSR); |
| 80 | MODULE_PARM_DESC(pause, "Flow Control Pause Time"); |
| 81 | |
| 82 | #define TC_DEFAULT 64 |
| 83 | static int tc = TC_DEFAULT; |
| 84 | module_param(tc, int, S_IRUGO | S_IWUSR); |
| 85 | MODULE_PARM_DESC(tc, "DMA threshold control value"); |
| 86 | |
Giuseppe CAVALLARO | d916701 | 2014-03-10 13:40:32 +0100 | [diff] [blame] | 87 | #define DEFAULT_BUFSIZE 1536 |
| 88 | static int buf_sz = DEFAULT_BUFSIZE; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 89 | module_param(buf_sz, int, S_IRUGO | S_IWUSR); |
| 90 | MODULE_PARM_DESC(buf_sz, "DMA buffer size"); |
| 91 | |
Giuseppe Cavallaro | 22ad383 | 2016-02-29 14:27:41 +0100 | [diff] [blame] | 92 | #define STMMAC_RX_COPYBREAK 256 |
| 93 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 94 | static const u32 default_msg_level = (NETIF_MSG_DRV | NETIF_MSG_PROBE | |
| 95 | NETIF_MSG_LINK | NETIF_MSG_IFUP | |
| 96 | NETIF_MSG_IFDOWN | NETIF_MSG_TIMER); |
| 97 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 98 | #define STMMAC_DEFAULT_LPI_TIMER 1000 |
| 99 | static int eee_timer = STMMAC_DEFAULT_LPI_TIMER; |
| 100 | module_param(eee_timer, int, S_IRUGO | S_IWUSR); |
| 101 | MODULE_PARM_DESC(eee_timer, "LPI tx expiration time in msec"); |
Giuseppe CAVALLARO | f5351ef | 2013-06-18 07:03:23 +0200 | [diff] [blame] | 102 | #define STMMAC_LPI_T(x) (jiffies + msecs_to_jiffies(x)) |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 103 | |
Pavel Machek | 22d3efe | 2016-11-28 12:55:59 +0100 | [diff] [blame] | 104 | /* By default the driver will use the ring mode to manage tx and rx descriptors, |
| 105 | * but allow user to force to use the chain instead of the ring |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 106 | */ |
| 107 | static unsigned int chain_mode; |
| 108 | module_param(chain_mode, int, S_IRUGO); |
| 109 | MODULE_PARM_DESC(chain_mode, "To use chain instead of ring mode"); |
| 110 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 111 | static irqreturn_t stmmac_interrupt(int irq, void *dev_id); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 112 | |
Giuseppe CAVALLARO | 50fb4f74 | 2014-11-04 15:49:33 +0100 | [diff] [blame] | 113 | #ifdef CONFIG_DEBUG_FS |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 114 | static int stmmac_init_fs(struct net_device *dev); |
Mathieu Olivari | 466c5ac | 2015-05-22 19:03:29 -0700 | [diff] [blame] | 115 | static void stmmac_exit_fs(struct net_device *dev); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 116 | #endif |
| 117 | |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 118 | #define STMMAC_COAL_TIMER(x) (jiffies + usecs_to_jiffies(x)) |
| 119 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 120 | /** |
| 121 | * stmmac_verify_args - verify the driver parameters. |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 122 | * Description: it checks the driver parameters and set a default in case of |
| 123 | * errors. |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 124 | */ |
| 125 | static void stmmac_verify_args(void) |
| 126 | { |
| 127 | if (unlikely(watchdog < 0)) |
| 128 | watchdog = TX_TIMEO; |
Giuseppe CAVALLARO | d916701 | 2014-03-10 13:40:32 +0100 | [diff] [blame] | 129 | if (unlikely((buf_sz < DEFAULT_BUFSIZE) || (buf_sz > BUF_SIZE_16KiB))) |
| 130 | buf_sz = DEFAULT_BUFSIZE; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 131 | if (unlikely(flow_ctrl > 1)) |
| 132 | flow_ctrl = FLOW_AUTO; |
| 133 | else if (likely(flow_ctrl < 0)) |
| 134 | flow_ctrl = FLOW_OFF; |
| 135 | if (unlikely((pause < 0) || (pause > 0xffff))) |
| 136 | pause = PAUSE_TIME; |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 137 | if (eee_timer < 0) |
| 138 | eee_timer = STMMAC_DEFAULT_LPI_TIMER; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 141 | /** |
| 142 | * stmmac_clk_csr_set - dynamically set the MDC clock |
| 143 | * @priv: driver private structure |
| 144 | * Description: this is to dynamically set the MDC clock according to the csr |
| 145 | * clock input. |
| 146 | * Note: |
| 147 | * If a specific clk_csr value is passed from the platform |
| 148 | * this means that the CSR Clock Range selection cannot be |
| 149 | * changed at run-time and it is fixed (as reported in the driver |
| 150 | * documentation). Viceversa the driver will try to set the MDC |
| 151 | * clock dynamically according to the actual clock input. |
| 152 | */ |
Giuseppe CAVALLARO | cd7201f | 2012-04-04 04:33:27 +0000 | [diff] [blame] | 153 | static void stmmac_clk_csr_set(struct stmmac_priv *priv) |
| 154 | { |
Giuseppe CAVALLARO | cd7201f | 2012-04-04 04:33:27 +0000 | [diff] [blame] | 155 | u32 clk_rate; |
| 156 | |
jpinto | f573c0b | 2017-01-09 12:35:09 +0000 | [diff] [blame] | 157 | clk_rate = clk_get_rate(priv->plat->stmmac_clk); |
Giuseppe CAVALLARO | cd7201f | 2012-04-04 04:33:27 +0000 | [diff] [blame] | 158 | |
| 159 | /* Platform provided default clk_csr would be assumed valid |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 160 | * for all other cases except for the below mentioned ones. |
| 161 | * For values higher than the IEEE 802.3 specified frequency |
| 162 | * we can not estimate the proper divider as it is not known |
| 163 | * the frequency of clk_csr_i. So we do not change the default |
| 164 | * divider. |
| 165 | */ |
Giuseppe CAVALLARO | cd7201f | 2012-04-04 04:33:27 +0000 | [diff] [blame] | 166 | if (!(priv->clk_csr & MAC_CSR_H_FRQ_MASK)) { |
| 167 | if (clk_rate < CSR_F_35M) |
| 168 | priv->clk_csr = STMMAC_CSR_20_35M; |
| 169 | else if ((clk_rate >= CSR_F_35M) && (clk_rate < CSR_F_60M)) |
| 170 | priv->clk_csr = STMMAC_CSR_35_60M; |
| 171 | else if ((clk_rate >= CSR_F_60M) && (clk_rate < CSR_F_100M)) |
| 172 | priv->clk_csr = STMMAC_CSR_60_100M; |
| 173 | else if ((clk_rate >= CSR_F_100M) && (clk_rate < CSR_F_150M)) |
| 174 | priv->clk_csr = STMMAC_CSR_100_150M; |
| 175 | else if ((clk_rate >= CSR_F_150M) && (clk_rate < CSR_F_250M)) |
| 176 | priv->clk_csr = STMMAC_CSR_150_250M; |
Phil Reid | 19d857c | 2015-12-14 11:32:01 +0800 | [diff] [blame] | 177 | else if ((clk_rate >= CSR_F_250M) && (clk_rate < CSR_F_300M)) |
Giuseppe CAVALLARO | cd7201f | 2012-04-04 04:33:27 +0000 | [diff] [blame] | 178 | priv->clk_csr = STMMAC_CSR_250_300M; |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 179 | } |
Giuseppe CAVALLARO | cd7201f | 2012-04-04 04:33:27 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 182 | static void print_pkt(unsigned char *buf, int len) |
| 183 | { |
Andy Shevchenko | 424c4f7 | 2014-11-07 16:53:12 +0200 | [diff] [blame] | 184 | pr_debug("len = %d byte, buf addr: 0x%p\n", len, buf); |
| 185 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, buf, len); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 186 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 187 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 188 | static inline u32 stmmac_tx_avail(struct stmmac_priv *priv, u32 queue) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 189 | { |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 190 | struct stmmac_tx_queue *tx_q = &priv->tx_queue[queue]; |
LABBE Corentin | a6a3e02 | 2017-02-08 09:31:21 +0100 | [diff] [blame] | 191 | u32 avail; |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 192 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 193 | if (tx_q->dirty_tx > tx_q->cur_tx) |
| 194 | avail = tx_q->dirty_tx - tx_q->cur_tx - 1; |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 195 | else |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 196 | avail = DMA_TX_SIZE - tx_q->cur_tx + tx_q->dirty_tx - 1; |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 197 | |
| 198 | return avail; |
| 199 | } |
| 200 | |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 201 | /** |
| 202 | * stmmac_rx_dirty - Get RX queue dirty |
| 203 | * @priv: driver private structure |
| 204 | * @queue: RX queue index |
| 205 | */ |
| 206 | static inline u32 stmmac_rx_dirty(struct stmmac_priv *priv, u32 queue) |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 207 | { |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 208 | struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue]; |
LABBE Corentin | a6a3e02 | 2017-02-08 09:31:21 +0100 | [diff] [blame] | 209 | u32 dirty; |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 210 | |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 211 | if (rx_q->dirty_rx <= rx_q->cur_rx) |
| 212 | dirty = rx_q->cur_rx - rx_q->dirty_rx; |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 213 | else |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 214 | dirty = DMA_RX_SIZE - rx_q->dirty_rx + rx_q->cur_rx; |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 215 | |
| 216 | return dirty; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 219 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 220 | * stmmac_hw_fix_mac_speed - callback for speed selection |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 221 | * @priv: driver private structure |
LABBE Corentin | 8d45e42 | 2017-02-08 09:31:08 +0100 | [diff] [blame] | 222 | * Description: on some platforms (e.g. ST), some HW system configuration |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 223 | * registers have to be set according to the link speed negotiated. |
Giuseppe CAVALLARO | 9dfeb4d | 2010-11-24 02:37:58 +0000 | [diff] [blame] | 224 | */ |
| 225 | static inline void stmmac_hw_fix_mac_speed(struct stmmac_priv *priv) |
| 226 | { |
Philippe Reynes | d6d50c7 | 2016-10-03 08:28:19 +0200 | [diff] [blame] | 227 | struct net_device *ndev = priv->dev; |
| 228 | struct phy_device *phydev = ndev->phydev; |
Giuseppe CAVALLARO | 9dfeb4d | 2010-11-24 02:37:58 +0000 | [diff] [blame] | 229 | |
| 230 | if (likely(priv->plat->fix_mac_speed)) |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 231 | priv->plat->fix_mac_speed(priv->plat->bsp_priv, phydev->speed); |
Giuseppe CAVALLARO | 9dfeb4d | 2010-11-24 02:37:58 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 234 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 235 | * stmmac_enable_eee_mode - check and enter in LPI mode |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 236 | * @priv: driver private structure |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 237 | * Description: this function is to verify and enter in LPI mode in case of |
| 238 | * EEE. |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 239 | */ |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 240 | static void stmmac_enable_eee_mode(struct stmmac_priv *priv) |
| 241 | { |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 242 | u32 tx_cnt = priv->plat->tx_queues_to_use; |
| 243 | u32 queue; |
| 244 | |
| 245 | /* check if all TX queues have the work finished */ |
| 246 | for (queue = 0; queue < tx_cnt; queue++) { |
| 247 | struct stmmac_tx_queue *tx_q = &priv->tx_queue[queue]; |
| 248 | |
| 249 | if (tx_q->dirty_tx != tx_q->cur_tx) |
| 250 | return; /* still unfinished work */ |
| 251 | } |
| 252 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 253 | /* Check and enter in LPI mode */ |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 254 | if (!priv->tx_path_in_lpi_mode) |
jpinto | b4b7b77 | 2017-01-09 12:35:08 +0000 | [diff] [blame] | 255 | priv->hw->mac->set_eee_mode(priv->hw, |
| 256 | priv->plat->en_tx_lpi_clockgating); |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 259 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 260 | * stmmac_disable_eee_mode - disable and exit from LPI mode |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 261 | * @priv: driver private structure |
| 262 | * Description: this function is to exit and disable EEE in case of |
| 263 | * LPI state is true. This is called by the xmit. |
| 264 | */ |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 265 | void stmmac_disable_eee_mode(struct stmmac_priv *priv) |
| 266 | { |
Vince Bridgers | 7ed24bb | 2014-07-31 15:49:13 -0500 | [diff] [blame] | 267 | priv->hw->mac->reset_eee_mode(priv->hw); |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 268 | del_timer_sync(&priv->eee_ctrl_timer); |
| 269 | priv->tx_path_in_lpi_mode = false; |
| 270 | } |
| 271 | |
| 272 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 273 | * stmmac_eee_ctrl_timer - EEE TX SW timer. |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 274 | * @arg : data hook |
| 275 | * Description: |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 276 | * if there is no data transfer and if we are not in LPI state, |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 277 | * then MAC Transmitter can be moved to LPI state. |
| 278 | */ |
| 279 | static void stmmac_eee_ctrl_timer(unsigned long arg) |
| 280 | { |
| 281 | struct stmmac_priv *priv = (struct stmmac_priv *)arg; |
| 282 | |
| 283 | stmmac_enable_eee_mode(priv); |
Giuseppe CAVALLARO | f5351ef | 2013-06-18 07:03:23 +0200 | [diff] [blame] | 284 | mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_T(eee_timer)); |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 288 | * stmmac_eee_init - init EEE |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 289 | * @priv: driver private structure |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 290 | * Description: |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 291 | * if the GMAC supports the EEE (from the HW cap reg) and the phy device |
| 292 | * can also manage EEE, this function enable the LPI state and start related |
| 293 | * timer. |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 294 | */ |
| 295 | bool stmmac_eee_init(struct stmmac_priv *priv) |
| 296 | { |
Philippe Reynes | d6d50c7 | 2016-10-03 08:28:19 +0200 | [diff] [blame] | 297 | struct net_device *ndev = priv->dev; |
Giuseppe CAVALLARO | 4741cf9 | 2014-11-04 17:08:08 +0100 | [diff] [blame] | 298 | unsigned long flags; |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 299 | bool ret = false; |
| 300 | |
Giuseppe CAVALLARO | f5351ef | 2013-06-18 07:03:23 +0200 | [diff] [blame] | 301 | /* Using PCS we cannot dial with the phy registers at this stage |
| 302 | * so we do not support extra feature like EEE. |
| 303 | */ |
Giuseppe CAVALLARO | 3fe5cad | 2016-06-24 15:16:25 +0200 | [diff] [blame] | 304 | if ((priv->hw->pcs == STMMAC_PCS_RGMII) || |
| 305 | (priv->hw->pcs == STMMAC_PCS_TBI) || |
| 306 | (priv->hw->pcs == STMMAC_PCS_RTBI)) |
Giuseppe CAVALLARO | f5351ef | 2013-06-18 07:03:23 +0200 | [diff] [blame] | 307 | goto out; |
| 308 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 309 | /* MAC core supports the EEE feature. */ |
| 310 | if (priv->dma_cap.eee) { |
Giuseppe CAVALLARO | 83bf79b | 2014-03-10 13:40:31 +0100 | [diff] [blame] | 311 | int tx_lpi_timer = priv->tx_lpi_timer; |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 312 | |
Giuseppe CAVALLARO | 83bf79b | 2014-03-10 13:40:31 +0100 | [diff] [blame] | 313 | /* Check if the PHY supports EEE */ |
Philippe Reynes | d6d50c7 | 2016-10-03 08:28:19 +0200 | [diff] [blame] | 314 | if (phy_init_eee(ndev->phydev, 1)) { |
Giuseppe CAVALLARO | 83bf79b | 2014-03-10 13:40:31 +0100 | [diff] [blame] | 315 | /* To manage at run-time if the EEE cannot be supported |
| 316 | * anymore (for example because the lp caps have been |
| 317 | * changed). |
| 318 | * In that case the driver disable own timers. |
| 319 | */ |
Giuseppe CAVALLARO | 4741cf9 | 2014-11-04 17:08:08 +0100 | [diff] [blame] | 320 | spin_lock_irqsave(&priv->lock, flags); |
Giuseppe CAVALLARO | 83bf79b | 2014-03-10 13:40:31 +0100 | [diff] [blame] | 321 | if (priv->eee_active) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 322 | netdev_dbg(priv->dev, "disable EEE\n"); |
Giuseppe CAVALLARO | 83bf79b | 2014-03-10 13:40:31 +0100 | [diff] [blame] | 323 | del_timer_sync(&priv->eee_ctrl_timer); |
Vince Bridgers | 7ed24bb | 2014-07-31 15:49:13 -0500 | [diff] [blame] | 324 | priv->hw->mac->set_eee_timer(priv->hw, 0, |
Giuseppe CAVALLARO | 83bf79b | 2014-03-10 13:40:31 +0100 | [diff] [blame] | 325 | tx_lpi_timer); |
| 326 | } |
| 327 | priv->eee_active = 0; |
Giuseppe CAVALLARO | 4741cf9 | 2014-11-04 17:08:08 +0100 | [diff] [blame] | 328 | spin_unlock_irqrestore(&priv->lock, flags); |
Giuseppe CAVALLARO | 83bf79b | 2014-03-10 13:40:31 +0100 | [diff] [blame] | 329 | goto out; |
| 330 | } |
| 331 | /* Activate the EEE and start timers */ |
Giuseppe CAVALLARO | 4741cf9 | 2014-11-04 17:08:08 +0100 | [diff] [blame] | 332 | spin_lock_irqsave(&priv->lock, flags); |
Giuseppe CAVALLARO | f5351ef | 2013-06-18 07:03:23 +0200 | [diff] [blame] | 333 | if (!priv->eee_active) { |
| 334 | priv->eee_active = 1; |
Vaishali Thakkar | ccb36da | 2015-02-28 00:12:34 +0530 | [diff] [blame] | 335 | setup_timer(&priv->eee_ctrl_timer, |
| 336 | stmmac_eee_ctrl_timer, |
| 337 | (unsigned long)priv); |
| 338 | mod_timer(&priv->eee_ctrl_timer, |
| 339 | STMMAC_LPI_T(eee_timer)); |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 340 | |
Vince Bridgers | 7ed24bb | 2014-07-31 15:49:13 -0500 | [diff] [blame] | 341 | priv->hw->mac->set_eee_timer(priv->hw, |
Giuseppe CAVALLARO | f5351ef | 2013-06-18 07:03:23 +0200 | [diff] [blame] | 342 | STMMAC_DEFAULT_LIT_LS, |
Giuseppe CAVALLARO | 83bf79b | 2014-03-10 13:40:31 +0100 | [diff] [blame] | 343 | tx_lpi_timer); |
Giuseppe CAVALLARO | 7196535 | 2014-08-28 08:11:44 +0200 | [diff] [blame] | 344 | } |
| 345 | /* Set HW EEE according to the speed */ |
Philippe Reynes | d6d50c7 | 2016-10-03 08:28:19 +0200 | [diff] [blame] | 346 | priv->hw->mac->set_eee_pls(priv->hw, ndev->phydev->link); |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 347 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 348 | ret = true; |
Giuseppe CAVALLARO | 4741cf9 | 2014-11-04 17:08:08 +0100 | [diff] [blame] | 349 | spin_unlock_irqrestore(&priv->lock, flags); |
| 350 | |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 351 | netdev_dbg(priv->dev, "Energy-Efficient Ethernet initialized\n"); |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 352 | } |
| 353 | out: |
| 354 | return ret; |
| 355 | } |
| 356 | |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 357 | /* stmmac_get_tx_hwtstamp - get HW TX timestamps |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 358 | * @priv: driver private structure |
Giuseppe CAVALLARO | ba1ffd7 | 2016-11-14 09:27:29 +0100 | [diff] [blame] | 359 | * @p : descriptor pointer |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 360 | * @skb : the socket buffer |
| 361 | * Description : |
| 362 | * This function will read timestamp from the descriptor & pass it to stack. |
| 363 | * and also perform some sanity checks. |
| 364 | */ |
| 365 | static void stmmac_get_tx_hwtstamp(struct stmmac_priv *priv, |
Giuseppe CAVALLARO | ba1ffd7 | 2016-11-14 09:27:29 +0100 | [diff] [blame] | 366 | struct dma_desc *p, struct sk_buff *skb) |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 367 | { |
| 368 | struct skb_shared_hwtstamps shhwtstamp; |
| 369 | u64 ns; |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 370 | |
| 371 | if (!priv->hwts_tx_en) |
| 372 | return; |
| 373 | |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 374 | /* exit if skb doesn't support hw tstamp */ |
damuzi000 | 75e4364 | 2014-01-17 23:47:59 +0800 | [diff] [blame] | 375 | if (likely(!skb || !(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS))) |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 376 | return; |
| 377 | |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 378 | /* check tx tstamp status */ |
Giuseppe CAVALLARO | ba1ffd7 | 2016-11-14 09:27:29 +0100 | [diff] [blame] | 379 | if (!priv->hw->desc->get_tx_timestamp_status(p)) { |
| 380 | /* get the valid tstamp */ |
| 381 | ns = priv->hw->desc->get_timestamp(p, priv->adv_ts); |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 382 | |
Giuseppe CAVALLARO | ba1ffd7 | 2016-11-14 09:27:29 +0100 | [diff] [blame] | 383 | memset(&shhwtstamp, 0, sizeof(struct skb_shared_hwtstamps)); |
| 384 | shhwtstamp.hwtstamp = ns_to_ktime(ns); |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 385 | |
Giuseppe CAVALLARO | ba1ffd7 | 2016-11-14 09:27:29 +0100 | [diff] [blame] | 386 | netdev_info(priv->dev, "get valid TX hw timestamp %llu\n", ns); |
| 387 | /* pass tstamp to stack */ |
| 388 | skb_tstamp_tx(skb, &shhwtstamp); |
| 389 | } |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 390 | |
| 391 | return; |
| 392 | } |
| 393 | |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 394 | /* stmmac_get_rx_hwtstamp - get HW RX timestamps |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 395 | * @priv: driver private structure |
Giuseppe CAVALLARO | ba1ffd7 | 2016-11-14 09:27:29 +0100 | [diff] [blame] | 396 | * @p : descriptor pointer |
| 397 | * @np : next descriptor pointer |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 398 | * @skb : the socket buffer |
| 399 | * Description : |
| 400 | * This function will read received packet's timestamp from the descriptor |
| 401 | * and pass it to stack. It also perform some sanity checks. |
| 402 | */ |
Giuseppe CAVALLARO | ba1ffd7 | 2016-11-14 09:27:29 +0100 | [diff] [blame] | 403 | static void stmmac_get_rx_hwtstamp(struct stmmac_priv *priv, struct dma_desc *p, |
| 404 | struct dma_desc *np, struct sk_buff *skb) |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 405 | { |
| 406 | struct skb_shared_hwtstamps *shhwtstamp = NULL; |
| 407 | u64 ns; |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 408 | |
| 409 | if (!priv->hwts_rx_en) |
| 410 | return; |
| 411 | |
Giuseppe CAVALLARO | ba1ffd7 | 2016-11-14 09:27:29 +0100 | [diff] [blame] | 412 | /* Check if timestamp is available */ |
| 413 | if (!priv->hw->desc->get_rx_timestamp_status(p, priv->adv_ts)) { |
| 414 | /* For GMAC4, the valid timestamp is from CTX next desc. */ |
| 415 | if (priv->plat->has_gmac4) |
| 416 | ns = priv->hw->desc->get_timestamp(np, priv->adv_ts); |
| 417 | else |
| 418 | ns = priv->hw->desc->get_timestamp(p, priv->adv_ts); |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 419 | |
Giuseppe CAVALLARO | ba1ffd7 | 2016-11-14 09:27:29 +0100 | [diff] [blame] | 420 | netdev_info(priv->dev, "get valid RX hw timestamp %llu\n", ns); |
| 421 | shhwtstamp = skb_hwtstamps(skb); |
| 422 | memset(shhwtstamp, 0, sizeof(struct skb_shared_hwtstamps)); |
| 423 | shhwtstamp->hwtstamp = ns_to_ktime(ns); |
| 424 | } else { |
| 425 | netdev_err(priv->dev, "cannot get RX hw timestamp\n"); |
| 426 | } |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | /** |
| 430 | * stmmac_hwtstamp_ioctl - control hardware timestamping. |
| 431 | * @dev: device pointer. |
LABBE Corentin | 8d45e42 | 2017-02-08 09:31:08 +0100 | [diff] [blame] | 432 | * @ifr: An IOCTL specific structure, that can contain a pointer to |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 433 | * a proprietary structure used to pass information to the driver. |
| 434 | * Description: |
| 435 | * This function configures the MAC to enable/disable both outgoing(TX) |
| 436 | * and incoming(RX) packets time stamping based on user input. |
| 437 | * Return Value: |
| 438 | * 0 on success and an appropriate -ve integer on failure. |
| 439 | */ |
| 440 | static int stmmac_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr) |
| 441 | { |
| 442 | struct stmmac_priv *priv = netdev_priv(dev); |
| 443 | struct hwtstamp_config config; |
Arnd Bergmann | 0a62415 | 2015-09-30 13:26:32 +0200 | [diff] [blame] | 444 | struct timespec64 now; |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 445 | u64 temp = 0; |
| 446 | u32 ptp_v2 = 0; |
| 447 | u32 tstamp_all = 0; |
| 448 | u32 ptp_over_ipv4_udp = 0; |
| 449 | u32 ptp_over_ipv6_udp = 0; |
| 450 | u32 ptp_over_ethernet = 0; |
| 451 | u32 snap_type_sel = 0; |
| 452 | u32 ts_master_en = 0; |
| 453 | u32 ts_event_en = 0; |
| 454 | u32 value = 0; |
Phil Reid | 19d857c | 2015-12-14 11:32:01 +0800 | [diff] [blame] | 455 | u32 sec_inc; |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 456 | |
| 457 | if (!(priv->dma_cap.time_stamp || priv->adv_ts)) { |
| 458 | netdev_alert(priv->dev, "No support for HW time stamping\n"); |
| 459 | priv->hwts_tx_en = 0; |
| 460 | priv->hwts_rx_en = 0; |
| 461 | |
| 462 | return -EOPNOTSUPP; |
| 463 | } |
| 464 | |
| 465 | if (copy_from_user(&config, ifr->ifr_data, |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 466 | sizeof(struct hwtstamp_config))) |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 467 | return -EFAULT; |
| 468 | |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 469 | netdev_dbg(priv->dev, "%s config flags:0x%x, tx_type:0x%x, rx_filter:0x%x\n", |
| 470 | __func__, config.flags, config.tx_type, config.rx_filter); |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 471 | |
| 472 | /* reserved for future extensions */ |
| 473 | if (config.flags) |
| 474 | return -EINVAL; |
| 475 | |
Ben Hutchings | 5f3da32 | 2013-11-14 00:43:41 +0000 | [diff] [blame] | 476 | if (config.tx_type != HWTSTAMP_TX_OFF && |
| 477 | config.tx_type != HWTSTAMP_TX_ON) |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 478 | return -ERANGE; |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 479 | |
| 480 | if (priv->adv_ts) { |
| 481 | switch (config.rx_filter) { |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 482 | case HWTSTAMP_FILTER_NONE: |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 483 | /* time stamp no incoming packet at all */ |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 484 | config.rx_filter = HWTSTAMP_FILTER_NONE; |
| 485 | break; |
| 486 | |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 487 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 488 | /* PTP v1, UDP, any kind of event packet */ |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 489 | config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT; |
| 490 | /* take time stamp for all event messages */ |
| 491 | snap_type_sel = PTP_TCR_SNAPTYPSEL_1; |
| 492 | |
| 493 | ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA; |
| 494 | ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA; |
| 495 | break; |
| 496 | |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 497 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 498 | /* PTP v1, UDP, Sync packet */ |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 499 | config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_SYNC; |
| 500 | /* take time stamp for SYNC messages only */ |
| 501 | ts_event_en = PTP_TCR_TSEVNTENA; |
| 502 | |
| 503 | ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA; |
| 504 | ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA; |
| 505 | break; |
| 506 | |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 507 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 508 | /* PTP v1, UDP, Delay_req packet */ |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 509 | config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ; |
| 510 | /* take time stamp for Delay_Req messages only */ |
| 511 | ts_master_en = PTP_TCR_TSMSTRENA; |
| 512 | ts_event_en = PTP_TCR_TSEVNTENA; |
| 513 | |
| 514 | ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA; |
| 515 | ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA; |
| 516 | break; |
| 517 | |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 518 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 519 | /* PTP v2, UDP, any kind of event packet */ |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 520 | config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT; |
| 521 | ptp_v2 = PTP_TCR_TSVER2ENA; |
| 522 | /* take time stamp for all event messages */ |
| 523 | snap_type_sel = PTP_TCR_SNAPTYPSEL_1; |
| 524 | |
| 525 | ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA; |
| 526 | ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA; |
| 527 | break; |
| 528 | |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 529 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 530 | /* PTP v2, UDP, Sync packet */ |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 531 | config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_SYNC; |
| 532 | ptp_v2 = PTP_TCR_TSVER2ENA; |
| 533 | /* take time stamp for SYNC messages only */ |
| 534 | ts_event_en = PTP_TCR_TSEVNTENA; |
| 535 | |
| 536 | ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA; |
| 537 | ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA; |
| 538 | break; |
| 539 | |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 540 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 541 | /* PTP v2, UDP, Delay_req packet */ |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 542 | config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ; |
| 543 | ptp_v2 = PTP_TCR_TSVER2ENA; |
| 544 | /* take time stamp for Delay_Req messages only */ |
| 545 | ts_master_en = PTP_TCR_TSMSTRENA; |
| 546 | ts_event_en = PTP_TCR_TSEVNTENA; |
| 547 | |
| 548 | ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA; |
| 549 | ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA; |
| 550 | break; |
| 551 | |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 552 | case HWTSTAMP_FILTER_PTP_V2_EVENT: |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 553 | /* PTP v2/802.AS1 any layer, any kind of event packet */ |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 554 | config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; |
| 555 | ptp_v2 = PTP_TCR_TSVER2ENA; |
| 556 | /* take time stamp for all event messages */ |
| 557 | snap_type_sel = PTP_TCR_SNAPTYPSEL_1; |
| 558 | |
| 559 | ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA; |
| 560 | ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA; |
| 561 | ptp_over_ethernet = PTP_TCR_TSIPENA; |
| 562 | break; |
| 563 | |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 564 | case HWTSTAMP_FILTER_PTP_V2_SYNC: |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 565 | /* PTP v2/802.AS1, any layer, Sync packet */ |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 566 | config.rx_filter = HWTSTAMP_FILTER_PTP_V2_SYNC; |
| 567 | ptp_v2 = PTP_TCR_TSVER2ENA; |
| 568 | /* take time stamp for SYNC messages only */ |
| 569 | ts_event_en = PTP_TCR_TSEVNTENA; |
| 570 | |
| 571 | ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA; |
| 572 | ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA; |
| 573 | ptp_over_ethernet = PTP_TCR_TSIPENA; |
| 574 | break; |
| 575 | |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 576 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 577 | /* PTP v2/802.AS1, any layer, Delay_req packet */ |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 578 | config.rx_filter = HWTSTAMP_FILTER_PTP_V2_DELAY_REQ; |
| 579 | ptp_v2 = PTP_TCR_TSVER2ENA; |
| 580 | /* take time stamp for Delay_Req messages only */ |
| 581 | ts_master_en = PTP_TCR_TSMSTRENA; |
| 582 | ts_event_en = PTP_TCR_TSEVNTENA; |
| 583 | |
| 584 | ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA; |
| 585 | ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA; |
| 586 | ptp_over_ethernet = PTP_TCR_TSIPENA; |
| 587 | break; |
| 588 | |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 589 | case HWTSTAMP_FILTER_ALL: |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 590 | /* time stamp any incoming packet */ |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 591 | config.rx_filter = HWTSTAMP_FILTER_ALL; |
| 592 | tstamp_all = PTP_TCR_TSENALL; |
| 593 | break; |
| 594 | |
| 595 | default: |
| 596 | return -ERANGE; |
| 597 | } |
| 598 | } else { |
| 599 | switch (config.rx_filter) { |
| 600 | case HWTSTAMP_FILTER_NONE: |
| 601 | config.rx_filter = HWTSTAMP_FILTER_NONE; |
| 602 | break; |
| 603 | default: |
| 604 | /* PTP v1, UDP, any kind of event packet */ |
| 605 | config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT; |
| 606 | break; |
| 607 | } |
| 608 | } |
| 609 | priv->hwts_rx_en = ((config.rx_filter == HWTSTAMP_FILTER_NONE) ? 0 : 1); |
Ben Hutchings | 5f3da32 | 2013-11-14 00:43:41 +0000 | [diff] [blame] | 610 | priv->hwts_tx_en = config.tx_type == HWTSTAMP_TX_ON; |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 611 | |
| 612 | if (!priv->hwts_tx_en && !priv->hwts_rx_en) |
Giuseppe CAVALLARO | ba1ffd7 | 2016-11-14 09:27:29 +0100 | [diff] [blame] | 613 | priv->hw->ptp->config_hw_tstamping(priv->ptpaddr, 0); |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 614 | else { |
| 615 | value = (PTP_TCR_TSENA | PTP_TCR_TSCFUPDT | PTP_TCR_TSCTRLSSR | |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 616 | tstamp_all | ptp_v2 | ptp_over_ethernet | |
| 617 | ptp_over_ipv6_udp | ptp_over_ipv4_udp | ts_event_en | |
| 618 | ts_master_en | snap_type_sel); |
Giuseppe CAVALLARO | ba1ffd7 | 2016-11-14 09:27:29 +0100 | [diff] [blame] | 619 | priv->hw->ptp->config_hw_tstamping(priv->ptpaddr, value); |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 620 | |
| 621 | /* program Sub Second Increment reg */ |
Phil Reid | 19d857c | 2015-12-14 11:32:01 +0800 | [diff] [blame] | 622 | sec_inc = priv->hw->ptp->config_sub_second_increment( |
jpinto | f573c0b | 2017-01-09 12:35:09 +0000 | [diff] [blame] | 623 | priv->ptpaddr, priv->plat->clk_ptp_rate, |
Giuseppe CAVALLARO | ba1ffd7 | 2016-11-14 09:27:29 +0100 | [diff] [blame] | 624 | priv->plat->has_gmac4); |
Phil Reid | 19d857c | 2015-12-14 11:32:01 +0800 | [diff] [blame] | 625 | temp = div_u64(1000000000ULL, sec_inc); |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 626 | |
| 627 | /* calculate default added value: |
| 628 | * formula is : |
| 629 | * addend = (2^32)/freq_div_ratio; |
Phil Reid | 19d857c | 2015-12-14 11:32:01 +0800 | [diff] [blame] | 630 | * where, freq_div_ratio = 1e9ns/sec_inc |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 631 | */ |
Phil Reid | 19d857c | 2015-12-14 11:32:01 +0800 | [diff] [blame] | 632 | temp = (u64)(temp << 32); |
jpinto | f573c0b | 2017-01-09 12:35:09 +0000 | [diff] [blame] | 633 | priv->default_addend = div_u64(temp, priv->plat->clk_ptp_rate); |
Giuseppe CAVALLARO | ba1ffd7 | 2016-11-14 09:27:29 +0100 | [diff] [blame] | 634 | priv->hw->ptp->config_addend(priv->ptpaddr, |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 635 | priv->default_addend); |
| 636 | |
| 637 | /* initialize system time */ |
Arnd Bergmann | 0a62415 | 2015-09-30 13:26:32 +0200 | [diff] [blame] | 638 | ktime_get_real_ts64(&now); |
| 639 | |
| 640 | /* lower 32 bits of tv_sec are safe until y2106 */ |
Giuseppe CAVALLARO | ba1ffd7 | 2016-11-14 09:27:29 +0100 | [diff] [blame] | 641 | priv->hw->ptp->init_systime(priv->ptpaddr, (u32)now.tv_sec, |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 642 | now.tv_nsec); |
| 643 | } |
| 644 | |
| 645 | return copy_to_user(ifr->ifr_data, &config, |
| 646 | sizeof(struct hwtstamp_config)) ? -EFAULT : 0; |
| 647 | } |
| 648 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 649 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 650 | * stmmac_init_ptp - init PTP |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 651 | * @priv: driver private structure |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 652 | * Description: this is to verify if the HW supports the PTPv1 or PTPv2. |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 653 | * This is done by looking at the HW cap. register. |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 654 | * This function also registers the ptp driver. |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 655 | */ |
Rayagond Kokatanur | 92ba688 | 2013-03-26 04:43:11 +0000 | [diff] [blame] | 656 | static int stmmac_init_ptp(struct stmmac_priv *priv) |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 657 | { |
Rayagond Kokatanur | 92ba688 | 2013-03-26 04:43:11 +0000 | [diff] [blame] | 658 | if (!(priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp)) |
| 659 | return -EOPNOTSUPP; |
| 660 | |
Vince Bridgers | 7cd0139 | 2013-12-20 11:19:34 -0600 | [diff] [blame] | 661 | priv->adv_ts = 0; |
Giuseppe CAVALLARO | be9b317 | 2016-10-12 15:42:03 +0200 | [diff] [blame] | 662 | /* Check if adv_ts can be enabled for dwmac 4.x core */ |
| 663 | if (priv->plat->has_gmac4 && priv->dma_cap.atime_stamp) |
| 664 | priv->adv_ts = 1; |
| 665 | /* Dwmac 3.x core with extend_desc can support adv_ts */ |
| 666 | else if (priv->extend_desc && priv->dma_cap.atime_stamp) |
Vince Bridgers | 7cd0139 | 2013-12-20 11:19:34 -0600 | [diff] [blame] | 667 | priv->adv_ts = 1; |
| 668 | |
Giuseppe CAVALLARO | be9b317 | 2016-10-12 15:42:03 +0200 | [diff] [blame] | 669 | if (priv->dma_cap.time_stamp) |
| 670 | netdev_info(priv->dev, "IEEE 1588-2002 Timestamp supported\n"); |
Vince Bridgers | 7cd0139 | 2013-12-20 11:19:34 -0600 | [diff] [blame] | 671 | |
Giuseppe CAVALLARO | be9b317 | 2016-10-12 15:42:03 +0200 | [diff] [blame] | 672 | if (priv->adv_ts) |
| 673 | netdev_info(priv->dev, |
| 674 | "IEEE 1588-2008 Advanced Timestamp supported\n"); |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 675 | |
| 676 | priv->hw->ptp = &stmmac_ptp; |
| 677 | priv->hwts_tx_en = 0; |
| 678 | priv->hwts_rx_en = 0; |
Rayagond Kokatanur | 92ba688 | 2013-03-26 04:43:11 +0000 | [diff] [blame] | 679 | |
Giuseppe CAVALLARO | c30a70d | 2016-10-19 09:06:41 +0200 | [diff] [blame] | 680 | stmmac_ptp_register(priv); |
| 681 | |
| 682 | return 0; |
Rayagond Kokatanur | 92ba688 | 2013-03-26 04:43:11 +0000 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | static void stmmac_release_ptp(struct stmmac_priv *priv) |
| 686 | { |
jpinto | f573c0b | 2017-01-09 12:35:09 +0000 | [diff] [blame] | 687 | if (priv->plat->clk_ptp_ref) |
| 688 | clk_disable_unprepare(priv->plat->clk_ptp_ref); |
Rayagond Kokatanur | 92ba688 | 2013-03-26 04:43:11 +0000 | [diff] [blame] | 689 | stmmac_ptp_unregister(priv); |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 690 | } |
| 691 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 692 | /** |
Joao Pinto | 29feff3 | 2017-03-10 18:24:56 +0000 | [diff] [blame] | 693 | * stmmac_mac_flow_ctrl - Configure flow control in all queues |
| 694 | * @priv: driver private structure |
| 695 | * Description: It is used for configuring the flow control in all queues |
| 696 | */ |
| 697 | static void stmmac_mac_flow_ctrl(struct stmmac_priv *priv, u32 duplex) |
| 698 | { |
| 699 | u32 tx_cnt = priv->plat->tx_queues_to_use; |
| 700 | |
| 701 | priv->hw->mac->flow_ctrl(priv->hw, duplex, priv->flow_ctrl, |
| 702 | priv->pause, tx_cnt); |
| 703 | } |
| 704 | |
| 705 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 706 | * stmmac_adjust_link - adjusts the link parameters |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 707 | * @dev: net device structure |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 708 | * Description: this is the helper called by the physical abstraction layer |
| 709 | * drivers to communicate the phy link status. According the speed and duplex |
| 710 | * this driver can invoke registered glue-logic as well. |
| 711 | * It also invoke the eee initialization because it could happen when switch |
| 712 | * on different networks (that are eee capable). |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 713 | */ |
| 714 | static void stmmac_adjust_link(struct net_device *dev) |
| 715 | { |
| 716 | struct stmmac_priv *priv = netdev_priv(dev); |
Philippe Reynes | d6d50c7 | 2016-10-03 08:28:19 +0200 | [diff] [blame] | 717 | struct phy_device *phydev = dev->phydev; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 718 | unsigned long flags; |
| 719 | int new_state = 0; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 720 | |
LABBE Corentin | 662ec2b | 2017-02-08 09:31:16 +0100 | [diff] [blame] | 721 | if (!phydev) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 722 | return; |
| 723 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 724 | spin_lock_irqsave(&priv->lock, flags); |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 725 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 726 | if (phydev->link) { |
Giuseppe CAVALLARO | ad01b7d | 2010-08-23 20:40:42 +0000 | [diff] [blame] | 727 | u32 ctrl = readl(priv->ioaddr + MAC_CTRL_REG); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 728 | |
| 729 | /* Now we make sure that we can be in full duplex mode. |
| 730 | * If not, we operate in half-duplex mode. */ |
| 731 | if (phydev->duplex != priv->oldduplex) { |
| 732 | new_state = 1; |
| 733 | if (!(phydev->duplex)) |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 734 | ctrl &= ~priv->hw->link.duplex; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 735 | else |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 736 | ctrl |= priv->hw->link.duplex; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 737 | priv->oldduplex = phydev->duplex; |
| 738 | } |
| 739 | /* Flow Control operation */ |
| 740 | if (phydev->pause) |
Joao Pinto | 29feff3 | 2017-03-10 18:24:56 +0000 | [diff] [blame] | 741 | stmmac_mac_flow_ctrl(priv, phydev->duplex); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 742 | |
| 743 | if (phydev->speed != priv->speed) { |
| 744 | new_state = 1; |
| 745 | switch (phydev->speed) { |
| 746 | case 1000: |
LABBE Corentin | 3e12790e | 2017-02-15 10:46:39 +0100 | [diff] [blame] | 747 | if (priv->plat->has_gmac || |
| 748 | priv->plat->has_gmac4) |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 749 | ctrl &= ~priv->hw->link.port; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 750 | break; |
| 751 | case 100: |
LABBE Corentin | 9beae26 | 2017-02-15 10:46:43 +0100 | [diff] [blame] | 752 | if (priv->plat->has_gmac || |
| 753 | priv->plat->has_gmac4) { |
| 754 | ctrl |= priv->hw->link.port; |
| 755 | ctrl |= priv->hw->link.speed; |
| 756 | } else { |
| 757 | ctrl &= ~priv->hw->link.port; |
| 758 | } |
| 759 | break; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 760 | case 10: |
LABBE Corentin | 3e12790e | 2017-02-15 10:46:39 +0100 | [diff] [blame] | 761 | if (priv->plat->has_gmac || |
| 762 | priv->plat->has_gmac4) { |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 763 | ctrl |= priv->hw->link.port; |
LABBE Corentin | 9beae26 | 2017-02-15 10:46:43 +0100 | [diff] [blame] | 764 | ctrl &= ~(priv->hw->link.speed); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 765 | } else { |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 766 | ctrl &= ~priv->hw->link.port; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 767 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 768 | break; |
| 769 | default: |
LABBE Corentin | b3e5106 | 2016-11-16 20:09:41 +0100 | [diff] [blame] | 770 | netif_warn(priv, link, priv->dev, |
LABBE Corentin | cba920a | 2017-02-08 09:31:15 +0100 | [diff] [blame] | 771 | "broken speed: %d\n", phydev->speed); |
LABBE Corentin | 688495b | 2017-02-15 10:46:41 +0100 | [diff] [blame] | 772 | phydev->speed = SPEED_UNKNOWN; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 773 | break; |
| 774 | } |
LABBE Corentin | 5db1355 | 2017-02-15 10:46:42 +0100 | [diff] [blame] | 775 | if (phydev->speed != SPEED_UNKNOWN) |
| 776 | stmmac_hw_fix_mac_speed(priv); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 777 | priv->speed = phydev->speed; |
| 778 | } |
| 779 | |
Giuseppe CAVALLARO | ad01b7d | 2010-08-23 20:40:42 +0000 | [diff] [blame] | 780 | writel(ctrl, priv->ioaddr + MAC_CTRL_REG); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 781 | |
| 782 | if (!priv->oldlink) { |
| 783 | new_state = 1; |
| 784 | priv->oldlink = 1; |
| 785 | } |
| 786 | } else if (priv->oldlink) { |
| 787 | new_state = 1; |
| 788 | priv->oldlink = 0; |
LABBE Corentin | bd00632 | 2017-02-15 10:46:40 +0100 | [diff] [blame] | 789 | priv->speed = SPEED_UNKNOWN; |
| 790 | priv->oldduplex = DUPLEX_UNKNOWN; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | if (new_state && netif_msg_link(priv)) |
| 794 | phy_print_status(phydev); |
| 795 | |
Giuseppe CAVALLARO | 4741cf9 | 2014-11-04 17:08:08 +0100 | [diff] [blame] | 796 | spin_unlock_irqrestore(&priv->lock, flags); |
| 797 | |
Giuseppe CAVALLARO | 52f95bb | 2016-04-05 08:46:57 +0200 | [diff] [blame] | 798 | if (phydev->is_pseudo_fixed_link) |
| 799 | /* Stop PHY layer to call the hook to adjust the link in case |
| 800 | * of a switch is attached to the stmmac driver. |
| 801 | */ |
| 802 | phydev->irq = PHY_IGNORE_INTERRUPT; |
| 803 | else |
| 804 | /* At this stage, init the EEE if supported. |
| 805 | * Never called in case of fixed_link. |
| 806 | */ |
| 807 | priv->eee_enabled = stmmac_eee_init(priv); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 808 | } |
| 809 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 810 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 811 | * stmmac_check_pcs_mode - verify if RGMII/SGMII is supported |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 812 | * @priv: driver private structure |
| 813 | * Description: this is to verify if the HW supports the PCS. |
| 814 | * Physical Coding Sublayer (PCS) interface that can be used when the MAC is |
| 815 | * configured for the TBI, RTBI, or SGMII PHY interface. |
| 816 | */ |
Giuseppe CAVALLARO | e58bb43 | 2013-03-26 04:43:08 +0000 | [diff] [blame] | 817 | static void stmmac_check_pcs_mode(struct stmmac_priv *priv) |
| 818 | { |
| 819 | int interface = priv->plat->interface; |
| 820 | |
| 821 | if (priv->dma_cap.pcs) { |
Byungho An | 0d909dc | 2013-06-28 16:35:31 +0900 | [diff] [blame] | 822 | if ((interface == PHY_INTERFACE_MODE_RGMII) || |
| 823 | (interface == PHY_INTERFACE_MODE_RGMII_ID) || |
| 824 | (interface == PHY_INTERFACE_MODE_RGMII_RXID) || |
| 825 | (interface == PHY_INTERFACE_MODE_RGMII_TXID)) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 826 | netdev_dbg(priv->dev, "PCS RGMII support enabled\n"); |
Giuseppe CAVALLARO | 3fe5cad | 2016-06-24 15:16:25 +0200 | [diff] [blame] | 827 | priv->hw->pcs = STMMAC_PCS_RGMII; |
Byungho An | 0d909dc | 2013-06-28 16:35:31 +0900 | [diff] [blame] | 828 | } else if (interface == PHY_INTERFACE_MODE_SGMII) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 829 | netdev_dbg(priv->dev, "PCS SGMII support enabled\n"); |
Giuseppe CAVALLARO | 3fe5cad | 2016-06-24 15:16:25 +0200 | [diff] [blame] | 830 | priv->hw->pcs = STMMAC_PCS_SGMII; |
Giuseppe CAVALLARO | e58bb43 | 2013-03-26 04:43:08 +0000 | [diff] [blame] | 831 | } |
| 832 | } |
| 833 | } |
| 834 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 835 | /** |
| 836 | * stmmac_init_phy - PHY initialization |
| 837 | * @dev: net device structure |
| 838 | * Description: it initializes the driver's PHY state, and attaches the PHY |
| 839 | * to the mac driver. |
| 840 | * Return value: |
| 841 | * 0 on success |
| 842 | */ |
| 843 | static int stmmac_init_phy(struct net_device *dev) |
| 844 | { |
| 845 | struct stmmac_priv *priv = netdev_priv(dev); |
| 846 | struct phy_device *phydev; |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 847 | char phy_id_fmt[MII_BUS_ID_SIZE + 3]; |
Giuseppe CAVALLARO | 109cdd6 | 2010-01-06 23:07:11 +0000 | [diff] [blame] | 848 | char bus_id[MII_BUS_ID_SIZE]; |
Srinivas Kandagatla | 79ee1dc | 2011-10-18 00:01:18 +0000 | [diff] [blame] | 849 | int interface = priv->plat->interface; |
Srinivas Kandagatla | 9cbadf0 | 2014-01-16 10:51:43 +0000 | [diff] [blame] | 850 | int max_speed = priv->plat->max_speed; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 851 | priv->oldlink = 0; |
LABBE Corentin | bd00632 | 2017-02-15 10:46:40 +0100 | [diff] [blame] | 852 | priv->speed = SPEED_UNKNOWN; |
| 853 | priv->oldduplex = DUPLEX_UNKNOWN; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 854 | |
Mathieu Olivari | 5790cf3 | 2015-05-27 11:02:47 -0700 | [diff] [blame] | 855 | if (priv->plat->phy_node) { |
| 856 | phydev = of_phy_connect(dev, priv->plat->phy_node, |
| 857 | &stmmac_adjust_link, 0, interface); |
| 858 | } else { |
Giuseppe CAVALLARO | a7657f1 | 2016-04-01 09:07:16 +0200 | [diff] [blame] | 859 | snprintf(bus_id, MII_BUS_ID_SIZE, "stmmac-%x", |
| 860 | priv->plat->bus_id); |
Srinivas Kandagatla | f142af2 | 2012-04-04 04:33:19 +0000 | [diff] [blame] | 861 | |
Mathieu Olivari | 5790cf3 | 2015-05-27 11:02:47 -0700 | [diff] [blame] | 862 | snprintf(phy_id_fmt, MII_BUS_ID_SIZE + 3, PHY_ID_FMT, bus_id, |
| 863 | priv->plat->phy_addr); |
LABBE Corentin | de9a216 | 2016-11-16 20:09:40 +0100 | [diff] [blame] | 864 | netdev_dbg(priv->dev, "%s: trying to attach to %s\n", __func__, |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 865 | phy_id_fmt); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 866 | |
Mathieu Olivari | 5790cf3 | 2015-05-27 11:02:47 -0700 | [diff] [blame] | 867 | phydev = phy_connect(dev, phy_id_fmt, &stmmac_adjust_link, |
| 868 | interface); |
| 869 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 870 | |
Alexey Brodkin | dfc50fc | 2015-09-09 18:01:08 +0300 | [diff] [blame] | 871 | if (IS_ERR_OR_NULL(phydev)) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 872 | netdev_err(priv->dev, "Could not attach to PHY\n"); |
Alexey Brodkin | dfc50fc | 2015-09-09 18:01:08 +0300 | [diff] [blame] | 873 | if (!phydev) |
| 874 | return -ENODEV; |
| 875 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 876 | return PTR_ERR(phydev); |
| 877 | } |
| 878 | |
Srinivas Kandagatla | 79ee1dc | 2011-10-18 00:01:18 +0000 | [diff] [blame] | 879 | /* Stop Advertising 1000BASE Capability if interface is not GMII */ |
Srinivas Kandagatla | c5b9b4e | 2011-11-16 21:57:59 +0000 | [diff] [blame] | 880 | if ((interface == PHY_INTERFACE_MODE_MII) || |
Srinivas Kandagatla | 9cbadf0 | 2014-01-16 10:51:43 +0000 | [diff] [blame] | 881 | (interface == PHY_INTERFACE_MODE_RMII) || |
Pavel Machek | a77e4ac | 2014-08-25 13:31:16 +0200 | [diff] [blame] | 882 | (max_speed < 1000 && max_speed > 0)) |
Srinivas Kandagatla | c5b9b4e | 2011-11-16 21:57:59 +0000 | [diff] [blame] | 883 | phydev->advertising &= ~(SUPPORTED_1000baseT_Half | |
| 884 | SUPPORTED_1000baseT_Full); |
Srinivas Kandagatla | 79ee1dc | 2011-10-18 00:01:18 +0000 | [diff] [blame] | 885 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 886 | /* |
| 887 | * Broken HW is sometimes missing the pull-up resistor on the |
| 888 | * MDIO line, which results in reads to non-existent devices returning |
| 889 | * 0 rather than 0xffff. Catch this here and treat 0 as a non-existent |
| 890 | * device as well. |
| 891 | * Note: phydev->phy_id is the result of reading the UID PHY registers. |
| 892 | */ |
Mathieu Olivari | 2773238 | 2015-05-27 11:02:48 -0700 | [diff] [blame] | 893 | if (!priv->plat->phy_node && phydev->phy_id == 0) { |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 894 | phy_disconnect(phydev); |
| 895 | return -ENODEV; |
| 896 | } |
Giuseppe Cavallaro | 8e99fc5 | 2016-02-29 14:27:39 +0100 | [diff] [blame] | 897 | |
Florian Fainelli | c51e424 | 2016-11-13 17:50:35 -0800 | [diff] [blame] | 898 | /* stmmac_adjust_link will change this to PHY_IGNORE_INTERRUPT to avoid |
| 899 | * subsequent PHY polling, make sure we force a link transition if |
| 900 | * we have a UP/DOWN/UP transition |
| 901 | */ |
| 902 | if (phydev->is_pseudo_fixed_link) |
| 903 | phydev->irq = PHY_POLL; |
| 904 | |
LABBE Corentin | b05c76a | 2017-02-08 09:31:18 +0100 | [diff] [blame] | 905 | phy_attached_info(phydev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 906 | return 0; |
| 907 | } |
| 908 | |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 909 | static void stmmac_display_rx_rings(struct stmmac_priv *priv) |
| 910 | { |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 911 | u32 rx_cnt = priv->plat->rx_queues_to_use; |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 912 | void *head_rx; |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 913 | u32 queue; |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 914 | |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 915 | /* Display RX rings */ |
| 916 | for (queue = 0; queue < rx_cnt; queue++) { |
| 917 | struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue]; |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 918 | |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 919 | pr_info("\tRX Queue %u rings\n", queue); |
| 920 | |
| 921 | if (priv->extend_desc) |
| 922 | head_rx = (void *)rx_q->dma_erx; |
| 923 | else |
| 924 | head_rx = (void *)rx_q->dma_rx; |
| 925 | |
| 926 | /* Display RX ring */ |
| 927 | priv->hw->desc->display_ring(head_rx, DMA_RX_SIZE, true); |
| 928 | } |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | static void stmmac_display_tx_rings(struct stmmac_priv *priv) |
| 932 | { |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 933 | u32 tx_cnt = priv->plat->tx_queues_to_use; |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 934 | void *head_tx; |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 935 | u32 queue; |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 936 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 937 | /* Display TX rings */ |
| 938 | for (queue = 0; queue < tx_cnt; queue++) { |
| 939 | struct stmmac_tx_queue *tx_q = &priv->tx_queue[queue]; |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 940 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 941 | pr_info("\tTX Queue %d rings\n", queue); |
| 942 | |
| 943 | if (priv->extend_desc) |
| 944 | head_tx = (void *)tx_q->dma_etx; |
| 945 | else |
| 946 | head_tx = (void *)tx_q->dma_tx; |
| 947 | |
| 948 | priv->hw->desc->display_ring(head_tx, DMA_TX_SIZE, false); |
| 949 | } |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 950 | } |
| 951 | |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 952 | static void stmmac_display_rings(struct stmmac_priv *priv) |
| 953 | { |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 954 | /* Display RX ring */ |
| 955 | stmmac_display_rx_rings(priv); |
Alexandre TORGUE | d0225e7 | 2016-04-01 11:37:26 +0200 | [diff] [blame] | 956 | |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 957 | /* Display TX ring */ |
| 958 | stmmac_display_tx_rings(priv); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 959 | } |
| 960 | |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 961 | static int stmmac_set_bfsize(int mtu, int bufsize) |
| 962 | { |
| 963 | int ret = bufsize; |
| 964 | |
| 965 | if (mtu >= BUF_SIZE_4KiB) |
| 966 | ret = BUF_SIZE_8KiB; |
| 967 | else if (mtu >= BUF_SIZE_2KiB) |
| 968 | ret = BUF_SIZE_4KiB; |
Giuseppe CAVALLARO | d916701 | 2014-03-10 13:40:32 +0100 | [diff] [blame] | 969 | else if (mtu > DEFAULT_BUFSIZE) |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 970 | ret = BUF_SIZE_2KiB; |
| 971 | else |
Giuseppe CAVALLARO | d916701 | 2014-03-10 13:40:32 +0100 | [diff] [blame] | 972 | ret = DEFAULT_BUFSIZE; |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 973 | |
| 974 | return ret; |
| 975 | } |
| 976 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 977 | /** |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 978 | * stmmac_clear_rx_descriptors - clear RX descriptors |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 979 | * @priv: driver private structure |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 980 | * @queue: RX queue index |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 981 | * Description: this function is called to clear the RX descriptors |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 982 | * in case of both basic and extended descriptors are used. |
| 983 | */ |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 984 | static void stmmac_clear_rx_descriptors(struct stmmac_priv *priv, u32 queue) |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 985 | { |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 986 | struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue]; |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 987 | int i; |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 988 | |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 989 | /* Clear the RX descriptors */ |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 990 | for (i = 0; i < DMA_RX_SIZE; i++) |
| 991 | if (priv->extend_desc) |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 992 | priv->hw->desc->init_rx_desc(&rx_q->dma_erx[i].basic, |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 993 | priv->use_riwt, priv->mode, |
| 994 | (i == DMA_RX_SIZE - 1)); |
| 995 | else |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 996 | priv->hw->desc->init_rx_desc(&rx_q->dma_rx[i], |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 997 | priv->use_riwt, priv->mode, |
| 998 | (i == DMA_RX_SIZE - 1)); |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | /** |
| 1002 | * stmmac_clear_tx_descriptors - clear tx descriptors |
| 1003 | * @priv: driver private structure |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1004 | * @queue: TX queue index. |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1005 | * Description: this function is called to clear the TX descriptors |
| 1006 | * in case of both basic and extended descriptors are used. |
| 1007 | */ |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1008 | static void stmmac_clear_tx_descriptors(struct stmmac_priv *priv, u32 queue) |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1009 | { |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1010 | struct stmmac_tx_queue *tx_q = &priv->tx_queue[queue]; |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1011 | int i; |
| 1012 | |
| 1013 | /* Clear the TX descriptors */ |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 1014 | for (i = 0; i < DMA_TX_SIZE; i++) |
| 1015 | if (priv->extend_desc) |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1016 | priv->hw->desc->init_tx_desc(&tx_q->dma_etx[i].basic, |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 1017 | priv->mode, |
| 1018 | (i == DMA_TX_SIZE - 1)); |
| 1019 | else |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1020 | priv->hw->desc->init_tx_desc(&tx_q->dma_tx[i], |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 1021 | priv->mode, |
| 1022 | (i == DMA_TX_SIZE - 1)); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1025 | /** |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1026 | * stmmac_clear_descriptors - clear descriptors |
| 1027 | * @priv: driver private structure |
| 1028 | * Description: this function is called to clear the TX and RX descriptors |
| 1029 | * in case of both basic and extended descriptors are used. |
| 1030 | */ |
| 1031 | static void stmmac_clear_descriptors(struct stmmac_priv *priv) |
| 1032 | { |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1033 | u32 rx_queue_cnt = priv->plat->rx_queues_to_use; |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1034 | u32 tx_queue_cnt = priv->plat->tx_queues_to_use; |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1035 | u32 queue; |
| 1036 | |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1037 | /* Clear the RX descriptors */ |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1038 | for (queue = 0; queue < rx_queue_cnt; queue++) |
| 1039 | stmmac_clear_rx_descriptors(priv, queue); |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1040 | |
| 1041 | /* Clear the TX descriptors */ |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1042 | for (queue = 0; queue < tx_queue_cnt; queue++) |
| 1043 | stmmac_clear_tx_descriptors(priv, queue); |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1047 | * stmmac_init_rx_buffers - init the RX descriptor buffer. |
| 1048 | * @priv: driver private structure |
| 1049 | * @p: descriptor pointer |
| 1050 | * @i: descriptor index |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1051 | * @flags: gfp flag |
| 1052 | * @queue: RX queue index |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1053 | * Description: this function is called to allocate a receive buffer, perform |
| 1054 | * the DMA mapping and init the descriptor. |
| 1055 | */ |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1056 | static int stmmac_init_rx_buffers(struct stmmac_priv *priv, struct dma_desc *p, |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1057 | int i, gfp_t flags, u32 queue) |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1058 | { |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1059 | struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue]; |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1060 | struct sk_buff *skb; |
| 1061 | |
Vineet Gupta | 4ec49a3 | 2015-05-20 12:04:40 +0530 | [diff] [blame] | 1062 | skb = __netdev_alloc_skb_ip_align(priv->dev, priv->dma_buf_sz, flags); |
Bartlomiej Zolnierkiewicz | 5632913 | 2013-08-09 14:02:08 +0200 | [diff] [blame] | 1063 | if (!skb) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 1064 | netdev_err(priv->dev, |
| 1065 | "%s: Rx init fails; skb is NULL\n", __func__); |
Bartlomiej Zolnierkiewicz | 5632913 | 2013-08-09 14:02:08 +0200 | [diff] [blame] | 1066 | return -ENOMEM; |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1067 | } |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1068 | rx_q->rx_skbuff[i] = skb; |
| 1069 | rx_q->rx_skbuff_dma[i] = dma_map_single(priv->device, skb->data, |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1070 | priv->dma_buf_sz, |
| 1071 | DMA_FROM_DEVICE); |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1072 | if (dma_mapping_error(priv->device, rx_q->rx_skbuff_dma[i])) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 1073 | netdev_err(priv->dev, "%s: DMA mapping error\n", __func__); |
Bartlomiej Zolnierkiewicz | 5632913 | 2013-08-09 14:02:08 +0200 | [diff] [blame] | 1074 | dev_kfree_skb_any(skb); |
| 1075 | return -EINVAL; |
| 1076 | } |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1077 | |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 1078 | if (priv->synopsys_id >= DWMAC_CORE_4_00) |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1079 | p->des0 = cpu_to_le32(rx_q->rx_skbuff_dma[i]); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 1080 | else |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1081 | p->des2 = cpu_to_le32(rx_q->rx_skbuff_dma[i]); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1082 | |
Giuseppe CAVALLARO | 29896a6 | 2014-03-10 13:40:33 +0100 | [diff] [blame] | 1083 | if ((priv->hw->mode->init_desc3) && |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1084 | (priv->dma_buf_sz == BUF_SIZE_16KiB)) |
Giuseppe CAVALLARO | 29896a6 | 2014-03-10 13:40:33 +0100 | [diff] [blame] | 1085 | priv->hw->mode->init_desc3(p); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1086 | |
| 1087 | return 0; |
| 1088 | } |
| 1089 | |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1090 | /** |
| 1091 | * stmmac_free_rx_buffer - free RX dma buffers |
| 1092 | * @priv: private structure |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1093 | * @queue: RX queue index |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1094 | * @i: buffer index. |
| 1095 | */ |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1096 | static void stmmac_free_rx_buffer(struct stmmac_priv *priv, u32 queue, int i) |
Bartlomiej Zolnierkiewicz | 5632913 | 2013-08-09 14:02:08 +0200 | [diff] [blame] | 1097 | { |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1098 | struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue]; |
| 1099 | |
| 1100 | if (rx_q->rx_skbuff[i]) { |
| 1101 | dma_unmap_single(priv->device, rx_q->rx_skbuff_dma[i], |
Bartlomiej Zolnierkiewicz | 5632913 | 2013-08-09 14:02:08 +0200 | [diff] [blame] | 1102 | priv->dma_buf_sz, DMA_FROM_DEVICE); |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1103 | dev_kfree_skb_any(rx_q->rx_skbuff[i]); |
Bartlomiej Zolnierkiewicz | 5632913 | 2013-08-09 14:02:08 +0200 | [diff] [blame] | 1104 | } |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1105 | rx_q->rx_skbuff[i] = NULL; |
Bartlomiej Zolnierkiewicz | 5632913 | 2013-08-09 14:02:08 +0200 | [diff] [blame] | 1106 | } |
| 1107 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1108 | /** |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1109 | * stmmac_free_tx_buffer - free RX dma buffers |
| 1110 | * @priv: private structure |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1111 | * @queue: RX queue index |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1112 | * @i: buffer index. |
| 1113 | */ |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1114 | static void stmmac_free_tx_buffer(struct stmmac_priv *priv, u32 queue, int i) |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1115 | { |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1116 | struct stmmac_tx_queue *tx_q = &priv->tx_queue[queue]; |
| 1117 | |
| 1118 | if (tx_q->tx_skbuff_dma[i].buf) { |
| 1119 | if (tx_q->tx_skbuff_dma[i].map_as_page) |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1120 | dma_unmap_page(priv->device, |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1121 | tx_q->tx_skbuff_dma[i].buf, |
| 1122 | tx_q->tx_skbuff_dma[i].len, |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1123 | DMA_TO_DEVICE); |
| 1124 | else |
| 1125 | dma_unmap_single(priv->device, |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1126 | tx_q->tx_skbuff_dma[i].buf, |
| 1127 | tx_q->tx_skbuff_dma[i].len, |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1128 | DMA_TO_DEVICE); |
| 1129 | } |
| 1130 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1131 | if (tx_q->tx_skbuff[i]) { |
| 1132 | dev_kfree_skb_any(tx_q->tx_skbuff[i]); |
| 1133 | tx_q->tx_skbuff[i] = NULL; |
| 1134 | tx_q->tx_skbuff_dma[i].buf = 0; |
| 1135 | tx_q->tx_skbuff_dma[i].map_as_page = false; |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1136 | } |
| 1137 | } |
| 1138 | |
| 1139 | /** |
| 1140 | * init_dma_rx_desc_rings - init the RX descriptor rings |
Joao Pinto | aff3d9e | 2017-03-17 16:11:05 +0000 | [diff] [blame] | 1141 | * @dev: net device structure |
| 1142 | * @flags: gfp flag. |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1143 | * Description: this function initializes the DMA RX descriptors |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 1144 | * and allocates the socket buffers. It supports the chained and ring |
Joao Pinto | aff3d9e | 2017-03-17 16:11:05 +0000 | [diff] [blame] | 1145 | * modes. |
| 1146 | */ |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1147 | static int init_dma_rx_desc_rings(struct net_device *dev, gfp_t flags) |
Joao Pinto | aff3d9e | 2017-03-17 16:11:05 +0000 | [diff] [blame] | 1148 | { |
| 1149 | struct stmmac_priv *priv = netdev_priv(dev); |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1150 | u32 rx_count = priv->plat->rx_queues_to_use; |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 1151 | unsigned int bfsize = 0; |
Bartlomiej Zolnierkiewicz | 5632913 | 2013-08-09 14:02:08 +0200 | [diff] [blame] | 1152 | int ret = -ENOMEM; |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1153 | u32 queue; |
| 1154 | int i; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1155 | |
Giuseppe CAVALLARO | 29896a6 | 2014-03-10 13:40:33 +0100 | [diff] [blame] | 1156 | if (priv->hw->mode->set_16kib_bfsize) |
| 1157 | bfsize = priv->hw->mode->set_16kib_bfsize(dev->mtu); |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 1158 | |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 1159 | if (bfsize < BUF_SIZE_16KiB) |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 1160 | bfsize = stmmac_set_bfsize(dev->mtu, priv->dma_buf_sz); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1161 | |
Vince Bridgers | 2618abb | 2014-01-20 05:39:01 -0600 | [diff] [blame] | 1162 | priv->dma_buf_sz = bfsize; |
| 1163 | |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1164 | /* RX INITIALIZATION */ |
LABBE Corentin | b3e5106 | 2016-11-16 20:09:41 +0100 | [diff] [blame] | 1165 | netif_dbg(priv, probe, priv->dev, |
| 1166 | "SKB addresses:\nskb\t\tskb data\tdma data\n"); |
| 1167 | |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1168 | for (queue = 0; queue < rx_count; queue++) { |
| 1169 | struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue]; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1170 | |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1171 | netif_dbg(priv, probe, priv->dev, |
| 1172 | "(%s) dma_rx_phy=0x%08x\n", __func__, |
| 1173 | (u32)rx_q->dma_rx_phy); |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 1174 | |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1175 | for (i = 0; i < DMA_RX_SIZE; i++) { |
| 1176 | struct dma_desc *p; |
| 1177 | |
| 1178 | if (priv->extend_desc) |
| 1179 | p = &((rx_q->dma_erx + i)->basic); |
| 1180 | else |
| 1181 | p = rx_q->dma_rx + i; |
| 1182 | |
| 1183 | ret = stmmac_init_rx_buffers(priv, p, i, flags, |
| 1184 | queue); |
| 1185 | if (ret) |
| 1186 | goto err_init_rx_buffers; |
| 1187 | |
| 1188 | netif_dbg(priv, probe, priv->dev, "[%p]\t[%p]\t[%x]\n", |
| 1189 | rx_q->rx_skbuff[i], rx_q->rx_skbuff[i]->data, |
| 1190 | (unsigned int)rx_q->rx_skbuff_dma[i]); |
| 1191 | } |
| 1192 | |
| 1193 | rx_q->cur_rx = 0; |
| 1194 | rx_q->dirty_rx = (unsigned int)(i - DMA_RX_SIZE); |
| 1195 | |
| 1196 | stmmac_clear_rx_descriptors(priv, queue); |
| 1197 | |
| 1198 | /* Setup the chained descriptor addresses */ |
| 1199 | if (priv->mode == STMMAC_CHAIN_MODE) { |
| 1200 | if (priv->extend_desc) |
| 1201 | priv->hw->mode->init(rx_q->dma_erx, |
| 1202 | rx_q->dma_rx_phy, |
| 1203 | DMA_RX_SIZE, 1); |
| 1204 | else |
| 1205 | priv->hw->mode->init(rx_q->dma_rx, |
| 1206 | rx_q->dma_rx_phy, |
| 1207 | DMA_RX_SIZE, 0); |
| 1208 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1209 | } |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1210 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1211 | buf_sz = bfsize; |
| 1212 | |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1213 | return 0; |
| 1214 | |
| 1215 | err_init_rx_buffers: |
| 1216 | while (queue >= 0) { |
| 1217 | while (--i >= 0) |
| 1218 | stmmac_free_rx_buffer(priv, queue, i); |
| 1219 | |
| 1220 | if (queue == 0) |
| 1221 | break; |
| 1222 | |
| 1223 | i = DMA_RX_SIZE; |
| 1224 | queue--; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1225 | } |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 1226 | |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1227 | return ret; |
| 1228 | } |
| 1229 | |
| 1230 | /** |
| 1231 | * init_dma_tx_desc_rings - init the TX descriptor rings |
| 1232 | * @dev: net device structure. |
| 1233 | * Description: this function initializes the DMA TX descriptors |
| 1234 | * and allocates the socket buffers. It supports the chained and ring |
| 1235 | * modes. |
| 1236 | */ |
| 1237 | static int init_dma_tx_desc_rings(struct net_device *dev) |
| 1238 | { |
| 1239 | struct stmmac_priv *priv = netdev_priv(dev); |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1240 | u32 tx_queue_cnt = priv->plat->tx_queues_to_use; |
| 1241 | u32 queue; |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1242 | int i; |
| 1243 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1244 | for (queue = 0; queue < tx_queue_cnt; queue++) { |
| 1245 | struct stmmac_tx_queue *tx_q = &priv->tx_queue[queue]; |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1246 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1247 | netif_dbg(priv, probe, priv->dev, |
| 1248 | "(%s) dma_tx_phy=0x%08x\n", __func__, |
| 1249 | (u32)tx_q->dma_tx_phy); |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1250 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1251 | /* Setup the chained descriptor addresses */ |
| 1252 | if (priv->mode == STMMAC_CHAIN_MODE) { |
| 1253 | if (priv->extend_desc) |
| 1254 | priv->hw->mode->init(tx_q->dma_etx, |
| 1255 | tx_q->dma_tx_phy, |
| 1256 | DMA_TX_SIZE, 1); |
| 1257 | else |
| 1258 | priv->hw->mode->init(tx_q->dma_tx, |
| 1259 | tx_q->dma_tx_phy, |
| 1260 | DMA_TX_SIZE, 0); |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 1261 | } |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 1262 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1263 | for (i = 0; i < DMA_TX_SIZE; i++) { |
| 1264 | struct dma_desc *p; |
| 1265 | |
| 1266 | if (priv->extend_desc) |
| 1267 | p = &((tx_q->dma_etx + i)->basic); |
| 1268 | else |
| 1269 | p = tx_q->dma_tx + i; |
| 1270 | |
| 1271 | if (priv->synopsys_id >= DWMAC_CORE_4_00) { |
| 1272 | p->des0 = 0; |
| 1273 | p->des1 = 0; |
| 1274 | p->des2 = 0; |
| 1275 | p->des3 = 0; |
| 1276 | } else { |
| 1277 | p->des2 = 0; |
| 1278 | } |
| 1279 | |
| 1280 | tx_q->tx_skbuff_dma[i].buf = 0; |
| 1281 | tx_q->tx_skbuff_dma[i].map_as_page = false; |
| 1282 | tx_q->tx_skbuff_dma[i].len = 0; |
| 1283 | tx_q->tx_skbuff_dma[i].last_segment = false; |
| 1284 | tx_q->tx_skbuff[i] = NULL; |
| 1285 | } |
| 1286 | |
| 1287 | tx_q->dirty_tx = 0; |
| 1288 | tx_q->cur_tx = 0; |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 1289 | } |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1290 | |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 1291 | netdev_reset_queue(priv->dev); |
| 1292 | |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1293 | return 0; |
| 1294 | } |
| 1295 | |
| 1296 | /** |
| 1297 | * init_dma_desc_rings - init the RX/TX descriptor rings |
| 1298 | * @dev: net device structure |
| 1299 | * @flags: gfp flag. |
| 1300 | * Description: this function initializes the DMA RX/TX descriptors |
| 1301 | * and allocates the socket buffers. It supports the chained and ring |
| 1302 | * modes. |
| 1303 | */ |
| 1304 | static int init_dma_desc_rings(struct net_device *dev, gfp_t flags) |
| 1305 | { |
| 1306 | struct stmmac_priv *priv = netdev_priv(dev); |
| 1307 | int ret; |
| 1308 | |
| 1309 | ret = init_dma_rx_desc_rings(dev, flags); |
| 1310 | if (ret) |
| 1311 | return ret; |
| 1312 | |
| 1313 | ret = init_dma_tx_desc_rings(dev); |
| 1314 | |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 1315 | stmmac_clear_descriptors(priv); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1316 | |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1317 | if (netif_msg_hw(priv)) |
| 1318 | stmmac_display_rings(priv); |
Bartlomiej Zolnierkiewicz | 5632913 | 2013-08-09 14:02:08 +0200 | [diff] [blame] | 1319 | |
Bartlomiej Zolnierkiewicz | 5632913 | 2013-08-09 14:02:08 +0200 | [diff] [blame] | 1320 | return ret; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1321 | } |
| 1322 | |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1323 | /** |
| 1324 | * dma_free_rx_skbufs - free RX dma buffers |
| 1325 | * @priv: private structure |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1326 | * @queue: RX queue index |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1327 | */ |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1328 | static void dma_free_rx_skbufs(struct stmmac_priv *priv, u32 queue) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1329 | { |
| 1330 | int i; |
| 1331 | |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1332 | for (i = 0; i < DMA_RX_SIZE; i++) |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1333 | stmmac_free_rx_buffer(priv, queue, i); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1334 | } |
| 1335 | |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1336 | /** |
| 1337 | * dma_free_tx_skbufs - free TX dma buffers |
| 1338 | * @priv: private structure |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1339 | * @queue: TX queue index |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1340 | */ |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1341 | static void dma_free_tx_skbufs(struct stmmac_priv *priv, u32 queue) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1342 | { |
| 1343 | int i; |
| 1344 | |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1345 | for (i = 0; i < DMA_TX_SIZE; i++) |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1346 | stmmac_free_tx_buffer(priv, queue, i); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1347 | } |
| 1348 | |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1349 | /** |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1350 | * free_dma_rx_desc_resources - free RX dma desc resources |
| 1351 | * @priv: private structure |
| 1352 | */ |
| 1353 | static void free_dma_rx_desc_resources(struct stmmac_priv *priv) |
| 1354 | { |
| 1355 | u32 rx_count = priv->plat->rx_queues_to_use; |
| 1356 | u32 queue; |
| 1357 | |
| 1358 | /* Free RX queue resources */ |
| 1359 | for (queue = 0; queue < rx_count; queue++) { |
| 1360 | struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue]; |
| 1361 | |
| 1362 | /* Release the DMA RX socket buffers */ |
| 1363 | dma_free_rx_skbufs(priv, queue); |
| 1364 | |
| 1365 | /* Free DMA regions of consistent memory previously allocated */ |
| 1366 | if (!priv->extend_desc) |
| 1367 | dma_free_coherent(priv->device, |
| 1368 | DMA_RX_SIZE * sizeof(struct dma_desc), |
| 1369 | rx_q->dma_rx, rx_q->dma_rx_phy); |
| 1370 | else |
| 1371 | dma_free_coherent(priv->device, DMA_RX_SIZE * |
| 1372 | sizeof(struct dma_extended_desc), |
| 1373 | rx_q->dma_erx, rx_q->dma_rx_phy); |
| 1374 | |
| 1375 | kfree(rx_q->rx_skbuff_dma); |
| 1376 | kfree(rx_q->rx_skbuff); |
| 1377 | } |
| 1378 | } |
| 1379 | |
| 1380 | /** |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1381 | * free_dma_tx_desc_resources - free TX dma desc resources |
| 1382 | * @priv: private structure |
| 1383 | */ |
| 1384 | static void free_dma_tx_desc_resources(struct stmmac_priv *priv) |
| 1385 | { |
| 1386 | u32 tx_count = priv->plat->tx_queues_to_use; |
| 1387 | u32 queue = 0; |
| 1388 | |
| 1389 | /* Free TX queue resources */ |
| 1390 | for (queue = 0; queue < tx_count; queue++) { |
| 1391 | struct stmmac_tx_queue *tx_q = &priv->tx_queue[queue]; |
| 1392 | |
| 1393 | /* Release the DMA TX socket buffers */ |
| 1394 | dma_free_tx_skbufs(priv, queue); |
| 1395 | |
| 1396 | /* Free DMA regions of consistent memory previously allocated */ |
| 1397 | if (!priv->extend_desc) |
| 1398 | dma_free_coherent(priv->device, |
| 1399 | DMA_TX_SIZE * sizeof(struct dma_desc), |
| 1400 | tx_q->dma_tx, tx_q->dma_tx_phy); |
| 1401 | else |
| 1402 | dma_free_coherent(priv->device, DMA_TX_SIZE * |
| 1403 | sizeof(struct dma_extended_desc), |
| 1404 | tx_q->dma_etx, tx_q->dma_tx_phy); |
| 1405 | |
| 1406 | kfree(tx_q->tx_skbuff_dma); |
| 1407 | kfree(tx_q->tx_skbuff); |
| 1408 | } |
| 1409 | } |
| 1410 | |
| 1411 | /** |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1412 | * alloc_dma_rx_desc_resources - alloc RX resources. |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1413 | * @priv: private structure |
| 1414 | * Description: according to which descriptor can be used (extend or basic) |
| 1415 | * this function allocates the resources for TX and RX paths. In case of |
| 1416 | * reception, for example, it pre-allocated the RX socket buffer in order to |
| 1417 | * allow zero-copy mechanism. |
| 1418 | */ |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1419 | static int alloc_dma_rx_desc_resources(struct stmmac_priv *priv) |
Srinivas Kandagatla | 09f8d69 | 2014-01-16 10:52:06 +0000 | [diff] [blame] | 1420 | { |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1421 | u32 rx_count = priv->plat->rx_queues_to_use; |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 1422 | int ret = -ENOMEM; |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1423 | u32 queue; |
Srinivas Kandagatla | 09f8d69 | 2014-01-16 10:52:06 +0000 | [diff] [blame] | 1424 | |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1425 | /* RX queues buffers and DMA */ |
| 1426 | for (queue = 0; queue < rx_count; queue++) { |
| 1427 | struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue]; |
Srinivas Kandagatla | 09f8d69 | 2014-01-16 10:52:06 +0000 | [diff] [blame] | 1428 | |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1429 | rx_q->queue_index = queue; |
| 1430 | rx_q->priv_data = priv; |
Srinivas Kandagatla | 09f8d69 | 2014-01-16 10:52:06 +0000 | [diff] [blame] | 1431 | |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1432 | rx_q->rx_skbuff_dma = kmalloc_array(DMA_RX_SIZE, |
| 1433 | sizeof(dma_addr_t), |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 1434 | GFP_KERNEL); |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1435 | if (!rx_q->rx_skbuff_dma) |
| 1436 | return -ENOMEM; |
| 1437 | |
| 1438 | rx_q->rx_skbuff = kmalloc_array(DMA_RX_SIZE, |
| 1439 | sizeof(struct sk_buff *), |
| 1440 | GFP_KERNEL); |
| 1441 | if (!rx_q->rx_skbuff) |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 1442 | goto err_dma; |
| 1443 | |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1444 | if (priv->extend_desc) { |
| 1445 | rx_q->dma_erx = dma_zalloc_coherent(priv->device, |
| 1446 | DMA_RX_SIZE * |
| 1447 | sizeof(struct |
| 1448 | dma_extended_desc), |
| 1449 | &rx_q->dma_rx_phy, |
| 1450 | GFP_KERNEL); |
| 1451 | if (!rx_q->dma_erx) |
| 1452 | goto err_dma; |
| 1453 | |
| 1454 | } else { |
| 1455 | rx_q->dma_rx = dma_zalloc_coherent(priv->device, |
| 1456 | DMA_RX_SIZE * |
| 1457 | sizeof(struct |
| 1458 | dma_desc), |
| 1459 | &rx_q->dma_rx_phy, |
| 1460 | GFP_KERNEL); |
| 1461 | if (!rx_q->dma_rx) |
| 1462 | goto err_dma; |
| 1463 | } |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | return 0; |
| 1467 | |
| 1468 | err_dma: |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1469 | free_dma_rx_desc_resources(priv); |
| 1470 | |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1471 | return ret; |
| 1472 | } |
| 1473 | |
| 1474 | /** |
| 1475 | * alloc_dma_tx_desc_resources - alloc TX resources. |
| 1476 | * @priv: private structure |
| 1477 | * Description: according to which descriptor can be used (extend or basic) |
| 1478 | * this function allocates the resources for TX and RX paths. In case of |
| 1479 | * reception, for example, it pre-allocated the RX socket buffer in order to |
| 1480 | * allow zero-copy mechanism. |
| 1481 | */ |
| 1482 | static int alloc_dma_tx_desc_resources(struct stmmac_priv *priv) |
| 1483 | { |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1484 | u32 tx_count = priv->plat->tx_queues_to_use; |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1485 | int ret = -ENOMEM; |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1486 | u32 queue; |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1487 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1488 | /* TX queues buffers and DMA */ |
| 1489 | for (queue = 0; queue < tx_count; queue++) { |
| 1490 | struct stmmac_tx_queue *tx_q = &priv->tx_queue[queue]; |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1491 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1492 | tx_q->queue_index = queue; |
| 1493 | tx_q->priv_data = priv; |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1494 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1495 | tx_q->tx_skbuff_dma = kmalloc_array(DMA_TX_SIZE, |
| 1496 | sizeof(*tx_q->tx_skbuff_dma), |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 1497 | GFP_KERNEL); |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1498 | if (!tx_q->tx_skbuff_dma) |
| 1499 | return -ENOMEM; |
| 1500 | |
| 1501 | tx_q->tx_skbuff = kmalloc_array(DMA_TX_SIZE, |
| 1502 | sizeof(struct sk_buff *), |
| 1503 | GFP_KERNEL); |
| 1504 | if (!tx_q->tx_skbuff) |
| 1505 | goto err_dma_buffers; |
| 1506 | |
| 1507 | if (priv->extend_desc) { |
| 1508 | tx_q->dma_etx = dma_zalloc_coherent(priv->device, |
| 1509 | DMA_TX_SIZE * |
| 1510 | sizeof(struct |
| 1511 | dma_extended_desc), |
| 1512 | &tx_q->dma_tx_phy, |
| 1513 | GFP_KERNEL); |
| 1514 | if (!tx_q->dma_etx) |
| 1515 | goto err_dma_buffers; |
| 1516 | } else { |
| 1517 | tx_q->dma_tx = dma_zalloc_coherent(priv->device, |
| 1518 | DMA_TX_SIZE * |
| 1519 | sizeof(struct |
| 1520 | dma_desc), |
| 1521 | &tx_q->dma_tx_phy, |
| 1522 | GFP_KERNEL); |
| 1523 | if (!tx_q->dma_tx) |
| 1524 | goto err_dma_buffers; |
| 1525 | } |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | return 0; |
| 1529 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1530 | err_dma_buffers: |
| 1531 | free_dma_tx_desc_resources(priv); |
| 1532 | |
Srinivas Kandagatla | 09f8d69 | 2014-01-16 10:52:06 +0000 | [diff] [blame] | 1533 | return ret; |
| 1534 | } |
| 1535 | |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1536 | /** |
| 1537 | * alloc_dma_desc_resources - alloc TX/RX resources. |
| 1538 | * @priv: private structure |
| 1539 | * Description: according to which descriptor can be used (extend or basic) |
| 1540 | * this function allocates the resources for TX and RX paths. In case of |
| 1541 | * reception, for example, it pre-allocated the RX socket buffer in order to |
| 1542 | * allow zero-copy mechanism. |
| 1543 | */ |
| 1544 | static int alloc_dma_desc_resources(struct stmmac_priv *priv) |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 1545 | { |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 1546 | /* RX Allocation */ |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1547 | int ret = alloc_dma_rx_desc_resources(priv); |
| 1548 | |
| 1549 | if (ret) |
| 1550 | return ret; |
| 1551 | |
| 1552 | ret = alloc_dma_tx_desc_resources(priv); |
| 1553 | |
| 1554 | return ret; |
| 1555 | } |
| 1556 | |
| 1557 | /** |
Joao Pinto | 71fedb0 | 2017-04-06 09:49:08 +0100 | [diff] [blame] | 1558 | * free_dma_desc_resources - free dma desc resources |
| 1559 | * @priv: private structure |
| 1560 | */ |
| 1561 | static void free_dma_desc_resources(struct stmmac_priv *priv) |
| 1562 | { |
| 1563 | /* Release the DMA RX socket buffers */ |
| 1564 | free_dma_rx_desc_resources(priv); |
| 1565 | |
| 1566 | /* Release the DMA TX socket buffers */ |
| 1567 | free_dma_tx_desc_resources(priv); |
| 1568 | } |
| 1569 | |
| 1570 | /** |
jpinto | 9eb1247 | 2016-12-28 12:57:48 +0000 | [diff] [blame] | 1571 | * stmmac_mac_enable_rx_queues - Enable MAC rx queues |
| 1572 | * @priv: driver private structure |
| 1573 | * Description: It is used for enabling the rx queues in the MAC |
| 1574 | */ |
| 1575 | static void stmmac_mac_enable_rx_queues(struct stmmac_priv *priv) |
| 1576 | { |
Joao Pinto | 4f6046f | 2017-03-10 18:24:54 +0000 | [diff] [blame] | 1577 | u32 rx_queues_count = priv->plat->rx_queues_to_use; |
| 1578 | int queue; |
| 1579 | u8 mode; |
jpinto | 9eb1247 | 2016-12-28 12:57:48 +0000 | [diff] [blame] | 1580 | |
Joao Pinto | 4f6046f | 2017-03-10 18:24:54 +0000 | [diff] [blame] | 1581 | for (queue = 0; queue < rx_queues_count; queue++) { |
| 1582 | mode = priv->plat->rx_queues_cfg[queue].mode_to_use; |
| 1583 | priv->hw->mac->rx_queue_enable(priv->hw, mode, queue); |
| 1584 | } |
jpinto | 9eb1247 | 2016-12-28 12:57:48 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | /** |
Joao Pinto | ae4f0d4 | 2017-03-15 11:04:47 +0000 | [diff] [blame] | 1588 | * stmmac_start_rx_dma - start RX DMA channel |
| 1589 | * @priv: driver private structure |
| 1590 | * @chan: RX channel index |
| 1591 | * Description: |
| 1592 | * This starts a RX DMA channel |
| 1593 | */ |
| 1594 | static void stmmac_start_rx_dma(struct stmmac_priv *priv, u32 chan) |
| 1595 | { |
| 1596 | netdev_dbg(priv->dev, "DMA RX processes started in channel %d\n", chan); |
| 1597 | priv->hw->dma->start_rx(priv->ioaddr, chan); |
| 1598 | } |
| 1599 | |
| 1600 | /** |
| 1601 | * stmmac_start_tx_dma - start TX DMA channel |
| 1602 | * @priv: driver private structure |
| 1603 | * @chan: TX channel index |
| 1604 | * Description: |
| 1605 | * This starts a TX DMA channel |
| 1606 | */ |
| 1607 | static void stmmac_start_tx_dma(struct stmmac_priv *priv, u32 chan) |
| 1608 | { |
| 1609 | netdev_dbg(priv->dev, "DMA TX processes started in channel %d\n", chan); |
| 1610 | priv->hw->dma->start_tx(priv->ioaddr, chan); |
| 1611 | } |
| 1612 | |
| 1613 | /** |
| 1614 | * stmmac_stop_rx_dma - stop RX DMA channel |
| 1615 | * @priv: driver private structure |
| 1616 | * @chan: RX channel index |
| 1617 | * Description: |
| 1618 | * This stops a RX DMA channel |
| 1619 | */ |
| 1620 | static void stmmac_stop_rx_dma(struct stmmac_priv *priv, u32 chan) |
| 1621 | { |
| 1622 | netdev_dbg(priv->dev, "DMA RX processes stopped in channel %d\n", chan); |
| 1623 | priv->hw->dma->stop_rx(priv->ioaddr, chan); |
| 1624 | } |
| 1625 | |
| 1626 | /** |
| 1627 | * stmmac_stop_tx_dma - stop TX DMA channel |
| 1628 | * @priv: driver private structure |
| 1629 | * @chan: TX channel index |
| 1630 | * Description: |
| 1631 | * This stops a TX DMA channel |
| 1632 | */ |
| 1633 | static void stmmac_stop_tx_dma(struct stmmac_priv *priv, u32 chan) |
| 1634 | { |
| 1635 | netdev_dbg(priv->dev, "DMA TX processes stopped in channel %d\n", chan); |
| 1636 | priv->hw->dma->stop_tx(priv->ioaddr, chan); |
| 1637 | } |
| 1638 | |
| 1639 | /** |
| 1640 | * stmmac_start_all_dma - start all RX and TX DMA channels |
| 1641 | * @priv: driver private structure |
| 1642 | * Description: |
| 1643 | * This starts all the RX and TX DMA channels |
| 1644 | */ |
| 1645 | static void stmmac_start_all_dma(struct stmmac_priv *priv) |
| 1646 | { |
| 1647 | u32 rx_channels_count = priv->plat->rx_queues_to_use; |
| 1648 | u32 tx_channels_count = priv->plat->tx_queues_to_use; |
| 1649 | u32 chan = 0; |
| 1650 | |
| 1651 | for (chan = 0; chan < rx_channels_count; chan++) |
| 1652 | stmmac_start_rx_dma(priv, chan); |
| 1653 | |
| 1654 | for (chan = 0; chan < tx_channels_count; chan++) |
| 1655 | stmmac_start_tx_dma(priv, chan); |
| 1656 | } |
| 1657 | |
| 1658 | /** |
| 1659 | * stmmac_stop_all_dma - stop all RX and TX DMA channels |
| 1660 | * @priv: driver private structure |
| 1661 | * Description: |
| 1662 | * This stops the RX and TX DMA channels |
| 1663 | */ |
| 1664 | static void stmmac_stop_all_dma(struct stmmac_priv *priv) |
| 1665 | { |
| 1666 | u32 rx_channels_count = priv->plat->rx_queues_to_use; |
| 1667 | u32 tx_channels_count = priv->plat->tx_queues_to_use; |
| 1668 | u32 chan = 0; |
| 1669 | |
| 1670 | for (chan = 0; chan < rx_channels_count; chan++) |
| 1671 | stmmac_stop_rx_dma(priv, chan); |
| 1672 | |
| 1673 | for (chan = 0; chan < tx_channels_count; chan++) |
| 1674 | stmmac_stop_tx_dma(priv, chan); |
| 1675 | } |
| 1676 | |
| 1677 | /** |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1678 | * stmmac_dma_operation_mode - HW DMA operation mode |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 1679 | * @priv: driver private structure |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1680 | * Description: it is used for configuring the DMA operation mode register in |
| 1681 | * order to program the tx/rx DMA thresholds or Store-And-Forward mode. |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1682 | */ |
| 1683 | static void stmmac_dma_operation_mode(struct stmmac_priv *priv) |
| 1684 | { |
Joao Pinto | 6deee22 | 2017-03-15 11:04:45 +0000 | [diff] [blame] | 1685 | u32 rx_channels_count = priv->plat->rx_queues_to_use; |
| 1686 | u32 tx_channels_count = priv->plat->tx_queues_to_use; |
Vince Bridgers | f88203a | 2015-04-15 11:17:42 -0500 | [diff] [blame] | 1687 | int rxfifosz = priv->plat->rx_fifo_size; |
Joao Pinto | 6deee22 | 2017-03-15 11:04:45 +0000 | [diff] [blame] | 1688 | u32 txmode = 0; |
| 1689 | u32 rxmode = 0; |
| 1690 | u32 chan = 0; |
Vince Bridgers | f88203a | 2015-04-15 11:17:42 -0500 | [diff] [blame] | 1691 | |
Thierry Reding | 11fbf81 | 2017-03-10 17:34:58 +0100 | [diff] [blame] | 1692 | if (rxfifosz == 0) |
| 1693 | rxfifosz = priv->dma_cap.rx_fifo_size; |
| 1694 | |
Joao Pinto | 6deee22 | 2017-03-15 11:04:45 +0000 | [diff] [blame] | 1695 | if (priv->plat->force_thresh_dma_mode) { |
| 1696 | txmode = tc; |
| 1697 | rxmode = tc; |
| 1698 | } else if (priv->plat->force_sf_dma_mode || priv->plat->tx_coe) { |
Srinivas Kandagatla | 61b8013 | 2011-07-17 20:54:09 +0000 | [diff] [blame] | 1699 | /* |
| 1700 | * In case of GMAC, SF mode can be enabled |
| 1701 | * to perform the TX COE in HW. This depends on: |
Giuseppe CAVALLARO | ebbb293 | 2010-09-17 03:23:40 +0000 | [diff] [blame] | 1702 | * 1) TX COE if actually supported |
| 1703 | * 2) There is no bugged Jumbo frame support |
| 1704 | * that needs to not insert csum in the TDES. |
| 1705 | */ |
Joao Pinto | 6deee22 | 2017-03-15 11:04:45 +0000 | [diff] [blame] | 1706 | txmode = SF_DMA_MODE; |
| 1707 | rxmode = SF_DMA_MODE; |
Sonic Zhang | b2dec11 | 2015-01-30 13:49:32 +0800 | [diff] [blame] | 1708 | priv->xstats.threshold = SF_DMA_MODE; |
Joao Pinto | 6deee22 | 2017-03-15 11:04:45 +0000 | [diff] [blame] | 1709 | } else { |
| 1710 | txmode = tc; |
| 1711 | rxmode = SF_DMA_MODE; |
| 1712 | } |
| 1713 | |
| 1714 | /* configure all channels */ |
| 1715 | if (priv->synopsys_id >= DWMAC_CORE_4_00) { |
| 1716 | for (chan = 0; chan < rx_channels_count; chan++) |
| 1717 | priv->hw->dma->dma_rx_mode(priv->ioaddr, rxmode, chan, |
| 1718 | rxfifosz); |
| 1719 | |
| 1720 | for (chan = 0; chan < tx_channels_count; chan++) |
| 1721 | priv->hw->dma->dma_tx_mode(priv->ioaddr, txmode, chan); |
| 1722 | } else { |
| 1723 | priv->hw->dma->dma_mode(priv->ioaddr, txmode, rxmode, |
Vince Bridgers | f88203a | 2015-04-15 11:17:42 -0500 | [diff] [blame] | 1724 | rxfifosz); |
Joao Pinto | 6deee22 | 2017-03-15 11:04:45 +0000 | [diff] [blame] | 1725 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1726 | } |
| 1727 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1728 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1729 | * stmmac_tx_clean - to manage the transmission completion |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 1730 | * @priv: driver private structure |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1731 | * @queue: TX queue index |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1732 | * Description: it reclaims the transmit resources after transmission completes. |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1733 | */ |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1734 | static void stmmac_tx_clean(struct stmmac_priv *priv, u32 queue) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1735 | { |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1736 | struct stmmac_tx_queue *tx_q = &priv->tx_queue[queue]; |
Beniamino Galvani | 3897957 | 2015-01-21 19:07:27 +0100 | [diff] [blame] | 1737 | unsigned int bytes_compl = 0, pkts_compl = 0; |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1738 | unsigned int entry = tx_q->dirty_tx; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1739 | |
Lino Sanfilippo | 739c8e1 | 2016-12-09 00:55:43 +0100 | [diff] [blame] | 1740 | netif_tx_lock(priv->dev); |
Giuseppe CAVALLARO | a9097a9 | 2011-10-18 00:01:19 +0000 | [diff] [blame] | 1741 | |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 1742 | priv->xstats.tx_clean++; |
| 1743 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1744 | while (entry != tx_q->cur_tx) { |
| 1745 | struct sk_buff *skb = tx_q->tx_skbuff[entry]; |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1746 | struct dma_desc *p; |
Fabrice Gasnier | c363b65 | 2016-02-29 14:27:36 +0100 | [diff] [blame] | 1747 | int status; |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1748 | |
| 1749 | if (priv->extend_desc) |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1750 | p = (struct dma_desc *)(tx_q->dma_etx + entry); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1751 | else |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1752 | p = tx_q->dma_tx + entry; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1753 | |
Fabrice Gasnier | c363b65 | 2016-02-29 14:27:36 +0100 | [diff] [blame] | 1754 | status = priv->hw->desc->tx_status(&priv->dev->stats, |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 1755 | &priv->xstats, p, |
| 1756 | priv->ioaddr); |
Fabrice Gasnier | c363b65 | 2016-02-29 14:27:36 +0100 | [diff] [blame] | 1757 | /* Check if the descriptor is owned by the DMA */ |
| 1758 | if (unlikely(status & tx_dma_own)) |
| 1759 | break; |
| 1760 | |
| 1761 | /* Just consider the last segment and ...*/ |
| 1762 | if (likely(!(status & tx_not_ls))) { |
| 1763 | /* ... verify the status error condition */ |
| 1764 | if (unlikely(status & tx_err)) { |
| 1765 | priv->dev->stats.tx_errors++; |
| 1766 | } else { |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1767 | priv->dev->stats.tx_packets++; |
| 1768 | priv->xstats.tx_pkt_n++; |
Fabrice Gasnier | c363b65 | 2016-02-29 14:27:36 +0100 | [diff] [blame] | 1769 | } |
Giuseppe CAVALLARO | ba1ffd7 | 2016-11-14 09:27:29 +0100 | [diff] [blame] | 1770 | stmmac_get_tx_hwtstamp(priv, p, skb); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1771 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1772 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1773 | if (likely(tx_q->tx_skbuff_dma[entry].buf)) { |
| 1774 | if (tx_q->tx_skbuff_dma[entry].map_as_page) |
Giuseppe CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 1775 | dma_unmap_page(priv->device, |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1776 | tx_q->tx_skbuff_dma[entry].buf, |
| 1777 | tx_q->tx_skbuff_dma[entry].len, |
Giuseppe CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 1778 | DMA_TO_DEVICE); |
| 1779 | else |
| 1780 | dma_unmap_single(priv->device, |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1781 | tx_q->tx_skbuff_dma[entry].buf, |
| 1782 | tx_q->tx_skbuff_dma[entry].len, |
Giuseppe CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 1783 | DMA_TO_DEVICE); |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1784 | tx_q->tx_skbuff_dma[entry].buf = 0; |
| 1785 | tx_q->tx_skbuff_dma[entry].len = 0; |
| 1786 | tx_q->tx_skbuff_dma[entry].map_as_page = false; |
Rayagond Kokatanur | cf32dee | 2013-03-26 04:43:09 +0000 | [diff] [blame] | 1787 | } |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 1788 | |
| 1789 | if (priv->hw->mode->clean_desc3) |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1790 | priv->hw->mode->clean_desc3(tx_q, p); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 1791 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1792 | tx_q->tx_skbuff_dma[entry].last_segment = false; |
| 1793 | tx_q->tx_skbuff_dma[entry].is_jumbo = false; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1794 | |
| 1795 | if (likely(skb != NULL)) { |
Beniamino Galvani | 3897957 | 2015-01-21 19:07:27 +0100 | [diff] [blame] | 1796 | pkts_compl++; |
| 1797 | bytes_compl += skb->len; |
Eric W. Biederman | 7c565c3 | 2014-03-15 18:11:09 -0700 | [diff] [blame] | 1798 | dev_consume_skb_any(skb); |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1799 | tx_q->tx_skbuff[entry] = NULL; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1800 | } |
| 1801 | |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 1802 | priv->hw->desc->release_tx_desc(p, priv->mode); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1803 | |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1804 | entry = STMMAC_GET_ENTRY(entry, DMA_TX_SIZE); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1805 | } |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1806 | tx_q->dirty_tx = entry; |
Beniamino Galvani | 3897957 | 2015-01-21 19:07:27 +0100 | [diff] [blame] | 1807 | |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 1808 | netdev_completed_queue(priv->dev, pkts_compl, bytes_compl); |
Beniamino Galvani | 3897957 | 2015-01-21 19:07:27 +0100 | [diff] [blame] | 1809 | |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 1810 | if (unlikely(netif_queue_stopped(priv->dev) && |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1811 | stmmac_tx_avail(priv, queue) > STMMAC_TX_THRESH)) { |
Lino Sanfilippo | 739c8e1 | 2016-12-09 00:55:43 +0100 | [diff] [blame] | 1812 | netif_dbg(priv, tx_done, priv->dev, |
| 1813 | "%s: restart transmit\n", __func__); |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 1814 | netif_wake_queue(priv->dev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1815 | } |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 1816 | |
| 1817 | if ((priv->eee_enabled) && (!priv->tx_path_in_lpi_mode)) { |
| 1818 | stmmac_enable_eee_mode(priv); |
Giuseppe CAVALLARO | f5351ef | 2013-06-18 07:03:23 +0200 | [diff] [blame] | 1819 | mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_T(eee_timer)); |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 1820 | } |
Lino Sanfilippo | 739c8e1 | 2016-12-09 00:55:43 +0100 | [diff] [blame] | 1821 | netif_tx_unlock(priv->dev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1822 | } |
| 1823 | |
Joao Pinto | 4f513ec | 2017-03-15 11:04:46 +0000 | [diff] [blame] | 1824 | static inline void stmmac_enable_dma_irq(struct stmmac_priv *priv, u32 chan) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1825 | { |
Joao Pinto | 4f513ec | 2017-03-15 11:04:46 +0000 | [diff] [blame] | 1826 | priv->hw->dma->enable_dma_irq(priv->ioaddr, chan); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1827 | } |
| 1828 | |
Joao Pinto | 4f513ec | 2017-03-15 11:04:46 +0000 | [diff] [blame] | 1829 | static inline void stmmac_disable_dma_irq(struct stmmac_priv *priv, u32 chan) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1830 | { |
Joao Pinto | 4f513ec | 2017-03-15 11:04:46 +0000 | [diff] [blame] | 1831 | priv->hw->dma->disable_dma_irq(priv->ioaddr, chan); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1832 | } |
| 1833 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1834 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1835 | * stmmac_tx_err - to manage the tx error |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 1836 | * @priv: driver private structure |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 1837 | * @chan: channel index |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1838 | * Description: it cleans the descriptors and restarts the transmission |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1839 | * in case of transmission errors. |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1840 | */ |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 1841 | static void stmmac_tx_err(struct stmmac_priv *priv, u32 chan) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1842 | { |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1843 | struct stmmac_tx_queue *tx_q = &priv->tx_queue[chan]; |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1844 | int i; |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1845 | |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 1846 | netif_stop_queue(priv->dev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1847 | |
Joao Pinto | ae4f0d4 | 2017-03-15 11:04:47 +0000 | [diff] [blame] | 1848 | stmmac_stop_tx_dma(priv, chan); |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1849 | dma_free_tx_skbufs(priv, chan); |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1850 | for (i = 0; i < DMA_TX_SIZE; i++) |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1851 | if (priv->extend_desc) |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1852 | priv->hw->desc->init_tx_desc(&tx_q->dma_etx[i].basic, |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1853 | priv->mode, |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1854 | (i == DMA_TX_SIZE - 1)); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1855 | else |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1856 | priv->hw->desc->init_tx_desc(&tx_q->dma_tx[i], |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1857 | priv->mode, |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1858 | (i == DMA_TX_SIZE - 1)); |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 1859 | tx_q->dirty_tx = 0; |
| 1860 | tx_q->cur_tx = 0; |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 1861 | netdev_reset_queue(priv->dev); |
Joao Pinto | ae4f0d4 | 2017-03-15 11:04:47 +0000 | [diff] [blame] | 1862 | stmmac_start_tx_dma(priv, chan); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1863 | |
| 1864 | priv->dev->stats.tx_errors++; |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 1865 | netif_wake_queue(priv->dev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1866 | } |
| 1867 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 1868 | /** |
Joao Pinto | 6deee22 | 2017-03-15 11:04:45 +0000 | [diff] [blame] | 1869 | * stmmac_set_dma_operation_mode - Set DMA operation mode by channel |
| 1870 | * @priv: driver private structure |
| 1871 | * @txmode: TX operating mode |
| 1872 | * @rxmode: RX operating mode |
| 1873 | * @chan: channel index |
| 1874 | * Description: it is used for configuring of the DMA operation mode in |
| 1875 | * runtime in order to program the tx/rx DMA thresholds or Store-And-Forward |
| 1876 | * mode. |
| 1877 | */ |
| 1878 | static void stmmac_set_dma_operation_mode(struct stmmac_priv *priv, u32 txmode, |
| 1879 | u32 rxmode, u32 chan) |
| 1880 | { |
| 1881 | int rxfifosz = priv->plat->rx_fifo_size; |
| 1882 | |
| 1883 | if (rxfifosz == 0) |
| 1884 | rxfifosz = priv->dma_cap.rx_fifo_size; |
| 1885 | |
| 1886 | if (priv->synopsys_id >= DWMAC_CORE_4_00) { |
| 1887 | priv->hw->dma->dma_rx_mode(priv->ioaddr, rxmode, chan, |
| 1888 | rxfifosz); |
| 1889 | priv->hw->dma->dma_tx_mode(priv->ioaddr, txmode, chan); |
| 1890 | } else { |
| 1891 | priv->hw->dma->dma_mode(priv->ioaddr, txmode, rxmode, |
| 1892 | rxfifosz); |
| 1893 | } |
| 1894 | } |
| 1895 | |
| 1896 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1897 | * stmmac_dma_interrupt - DMA ISR |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 1898 | * @priv: driver private structure |
| 1899 | * Description: this is the DMA ISR. It is called by the main ISR. |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1900 | * It calls the dwmac dma routine and schedule poll method in case of some |
| 1901 | * work can be done. |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 1902 | */ |
Giuseppe CAVALLARO | aec7ff2 | 2010-01-06 23:07:18 +0000 | [diff] [blame] | 1903 | static void stmmac_dma_interrupt(struct stmmac_priv *priv) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1904 | { |
Joao Pinto | d62a107 | 2017-03-15 11:04:49 +0000 | [diff] [blame] | 1905 | u32 tx_channel_count = priv->plat->tx_queues_to_use; |
Giuseppe CAVALLARO | aec7ff2 | 2010-01-06 23:07:18 +0000 | [diff] [blame] | 1906 | int status; |
Joao Pinto | d62a107 | 2017-03-15 11:04:49 +0000 | [diff] [blame] | 1907 | u32 chan; |
Joao Pinto | 68e5cfa | 2017-03-13 10:36:29 +0000 | [diff] [blame] | 1908 | |
Joao Pinto | d62a107 | 2017-03-15 11:04:49 +0000 | [diff] [blame] | 1909 | for (chan = 0; chan < tx_channel_count; chan++) { |
| 1910 | status = priv->hw->dma->dma_interrupt(priv->ioaddr, |
| 1911 | &priv->xstats, chan); |
| 1912 | if (likely((status & handle_rx)) || (status & handle_tx)) { |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 1913 | if (likely(napi_schedule_prep(&priv->napi))) { |
Joao Pinto | d62a107 | 2017-03-15 11:04:49 +0000 | [diff] [blame] | 1914 | stmmac_disable_dma_irq(priv, chan); |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 1915 | __napi_schedule(&priv->napi); |
Joao Pinto | d62a107 | 2017-03-15 11:04:49 +0000 | [diff] [blame] | 1916 | } |
| 1917 | } |
| 1918 | |
| 1919 | if (unlikely(status & tx_hard_error_bump_tc)) { |
| 1920 | /* Try to bump up the dma threshold on this failure */ |
| 1921 | if (unlikely(priv->xstats.threshold != SF_DMA_MODE) && |
| 1922 | (tc <= 256)) { |
| 1923 | tc += 64; |
| 1924 | if (priv->plat->force_thresh_dma_mode) |
| 1925 | stmmac_set_dma_operation_mode(priv, |
| 1926 | tc, |
| 1927 | tc, |
| 1928 | chan); |
| 1929 | else |
| 1930 | stmmac_set_dma_operation_mode(priv, |
| 1931 | tc, |
| 1932 | SF_DMA_MODE, |
| 1933 | chan); |
| 1934 | priv->xstats.threshold = tc; |
| 1935 | } |
| 1936 | } else if (unlikely(status == tx_hard_error)) { |
| 1937 | stmmac_tx_err(priv, chan); |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 1938 | } |
| 1939 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1940 | } |
| 1941 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 1942 | /** |
| 1943 | * stmmac_mmc_setup: setup the Mac Management Counters (MMC) |
| 1944 | * @priv: driver private structure |
| 1945 | * Description: this masks the MMC irq, in fact, the counters are managed in SW. |
| 1946 | */ |
Giuseppe CAVALLARO | 1c901a4 | 2011-09-01 21:51:38 +0000 | [diff] [blame] | 1947 | static void stmmac_mmc_setup(struct stmmac_priv *priv) |
| 1948 | { |
| 1949 | unsigned int mode = MMC_CNTRL_RESET_ON_READ | MMC_CNTRL_COUNTER_RESET | |
Alexandre TORGUE | 36ff7c1 | 2016-04-01 11:37:32 +0200 | [diff] [blame] | 1950 | MMC_CNTRL_PRESET | MMC_CNTRL_FULL_HALF_PRESET; |
Giuseppe CAVALLARO | 1c901a4 | 2011-09-01 21:51:38 +0000 | [diff] [blame] | 1951 | |
Giuseppe CAVALLARO | ba1ffd7 | 2016-11-14 09:27:29 +0100 | [diff] [blame] | 1952 | if (priv->synopsys_id >= DWMAC_CORE_4_00) { |
| 1953 | priv->ptpaddr = priv->ioaddr + PTP_GMAC4_OFFSET; |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 1954 | priv->mmcaddr = priv->ioaddr + MMC_GMAC4_OFFSET; |
Giuseppe CAVALLARO | ba1ffd7 | 2016-11-14 09:27:29 +0100 | [diff] [blame] | 1955 | } else { |
| 1956 | priv->ptpaddr = priv->ioaddr + PTP_GMAC3_X_OFFSET; |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 1957 | priv->mmcaddr = priv->ioaddr + MMC_GMAC3_X_OFFSET; |
Giuseppe CAVALLARO | ba1ffd7 | 2016-11-14 09:27:29 +0100 | [diff] [blame] | 1958 | } |
Alexandre TORGUE | 36ff7c1 | 2016-04-01 11:37:32 +0200 | [diff] [blame] | 1959 | |
| 1960 | dwmac_mmc_intr_all_mask(priv->mmcaddr); |
Giuseppe CAVALLARO | 4f795b2 | 2011-11-18 05:00:20 +0000 | [diff] [blame] | 1961 | |
| 1962 | if (priv->dma_cap.rmon) { |
Alexandre TORGUE | 36ff7c1 | 2016-04-01 11:37:32 +0200 | [diff] [blame] | 1963 | dwmac_mmc_ctrl(priv->mmcaddr, mode); |
Giuseppe CAVALLARO | 4f795b2 | 2011-11-18 05:00:20 +0000 | [diff] [blame] | 1964 | memset(&priv->mmc, 0, sizeof(struct stmmac_counters)); |
| 1965 | } else |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 1966 | netdev_info(priv->dev, "No MAC Management Counters available\n"); |
Giuseppe CAVALLARO | 1c901a4 | 2011-09-01 21:51:38 +0000 | [diff] [blame] | 1967 | } |
| 1968 | |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1969 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1970 | * stmmac_selec_desc_mode - to select among: normal/alternate/extend descriptors |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 1971 | * @priv: driver private structure |
| 1972 | * Description: select the Enhanced/Alternate or Normal descriptors. |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1973 | * In case of Enhanced/Alternate, it checks if the extended descriptors are |
| 1974 | * supported by the HW capability register. |
Giuseppe CAVALLARO | ff3dd78 | 2012-06-04 19:22:55 +0000 | [diff] [blame] | 1975 | */ |
Giuseppe CAVALLARO | 19e30c1 | 2011-11-16 21:58:00 +0000 | [diff] [blame] | 1976 | static void stmmac_selec_desc_mode(struct stmmac_priv *priv) |
| 1977 | { |
| 1978 | if (priv->plat->enh_desc) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 1979 | dev_info(priv->device, "Enhanced/Alternate descriptors\n"); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1980 | |
| 1981 | /* GMAC older than 3.50 has no extended descriptors */ |
| 1982 | if (priv->synopsys_id >= DWMAC_CORE_3_50) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 1983 | dev_info(priv->device, "Enabled extended descriptors\n"); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1984 | priv->extend_desc = 1; |
| 1985 | } else |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 1986 | dev_warn(priv->device, "Extended descriptors not supported\n"); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1987 | |
Giuseppe CAVALLARO | 19e30c1 | 2011-11-16 21:58:00 +0000 | [diff] [blame] | 1988 | priv->hw->desc = &enh_desc_ops; |
| 1989 | } else { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 1990 | dev_info(priv->device, "Normal descriptors\n"); |
Giuseppe CAVALLARO | 19e30c1 | 2011-11-16 21:58:00 +0000 | [diff] [blame] | 1991 | priv->hw->desc = &ndesc_ops; |
| 1992 | } |
| 1993 | } |
| 1994 | |
| 1995 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1996 | * stmmac_get_hw_features - get MAC capabilities from the HW cap. register. |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 1997 | * @priv: driver private structure |
Giuseppe CAVALLARO | 19e30c1 | 2011-11-16 21:58:00 +0000 | [diff] [blame] | 1998 | * Description: |
| 1999 | * new GMAC chip generations have a new register to indicate the |
| 2000 | * presence of the optional feature/functions. |
| 2001 | * This can be also used to override the value passed through the |
| 2002 | * platform and necessary for old MAC10/100 and GMAC chips. |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 2003 | */ |
| 2004 | static int stmmac_get_hw_features(struct stmmac_priv *priv) |
| 2005 | { |
Alexandre TORGUE | f10a6a3 | 2016-04-01 11:37:25 +0200 | [diff] [blame] | 2006 | u32 ret = 0; |
Giuseppe CAVALLARO | 3c20f72 | 2011-10-26 19:43:09 +0000 | [diff] [blame] | 2007 | |
Giuseppe CAVALLARO | 5e6efe8 | 2011-10-26 19:43:07 +0000 | [diff] [blame] | 2008 | if (priv->hw->dma->get_hw_feature) { |
Alexandre TORGUE | f10a6a3 | 2016-04-01 11:37:25 +0200 | [diff] [blame] | 2009 | priv->hw->dma->get_hw_feature(priv->ioaddr, |
| 2010 | &priv->dma_cap); |
| 2011 | ret = 1; |
Giuseppe CAVALLARO | 19e30c1 | 2011-11-16 21:58:00 +0000 | [diff] [blame] | 2012 | } |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 2013 | |
Alexandre TORGUE | f10a6a3 | 2016-04-01 11:37:25 +0200 | [diff] [blame] | 2014 | return ret; |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 2015 | } |
| 2016 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 2017 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 2018 | * stmmac_check_ether_addr - check if the MAC addr is valid |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 2019 | * @priv: driver private structure |
| 2020 | * Description: |
| 2021 | * it is to verify if the MAC address is valid, in case of failures it |
| 2022 | * generates a random MAC address |
| 2023 | */ |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2024 | static void stmmac_check_ether_addr(struct stmmac_priv *priv) |
| 2025 | { |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2026 | if (!is_valid_ether_addr(priv->dev->dev_addr)) { |
Vince Bridgers | 7ed24bb | 2014-07-31 15:49:13 -0500 | [diff] [blame] | 2027 | priv->hw->mac->get_umac_addr(priv->hw, |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2028 | priv->dev->dev_addr, 0); |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 2029 | if (!is_valid_ether_addr(priv->dev->dev_addr)) |
Danny Kukawka | f2cedb6 | 2012-02-15 06:45:39 +0000 | [diff] [blame] | 2030 | eth_hw_addr_random(priv->dev); |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 2031 | netdev_info(priv->dev, "device MAC address %pM\n", |
| 2032 | priv->dev->dev_addr); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2033 | } |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2034 | } |
| 2035 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 2036 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 2037 | * stmmac_init_dma_engine - DMA init. |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 2038 | * @priv: driver private structure |
| 2039 | * Description: |
| 2040 | * It inits the DMA invoking the specific MAC/GMAC callback. |
| 2041 | * Some DMA parameters can be passed from the platform; |
| 2042 | * in case of these are not passed a default is kept for the MAC or GMAC. |
| 2043 | */ |
Giuseppe CAVALLARO | 0f1f88a | 2012-04-18 19:48:21 +0000 | [diff] [blame] | 2044 | static int stmmac_init_dma_engine(struct stmmac_priv *priv) |
| 2045 | { |
Joao Pinto | 47f2a9c | 2017-03-15 11:04:53 +0000 | [diff] [blame] | 2046 | u32 rx_channels_count = priv->plat->rx_queues_to_use; |
| 2047 | u32 tx_channels_count = priv->plat->tx_queues_to_use; |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 2048 | struct stmmac_rx_queue *rx_q; |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2049 | struct stmmac_tx_queue *tx_q; |
Joao Pinto | 47f2a9c | 2017-03-15 11:04:53 +0000 | [diff] [blame] | 2050 | u32 dummy_dma_rx_phy = 0; |
| 2051 | u32 dummy_dma_tx_phy = 0; |
| 2052 | u32 chan = 0; |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2053 | int atds = 0; |
Giuseppe Cavallaro | 495db27 | 2016-02-29 14:27:27 +0100 | [diff] [blame] | 2054 | int ret = 0; |
Giuseppe CAVALLARO | 0f1f88a | 2012-04-18 19:48:21 +0000 | [diff] [blame] | 2055 | |
Niklas Cassel | a332e2f | 2016-12-07 15:20:05 +0100 | [diff] [blame] | 2056 | if (!priv->plat->dma_cfg || !priv->plat->dma_cfg->pbl) { |
| 2057 | dev_err(priv->device, "Invalid DMA configuration\n"); |
Niklas Cassel | 89ab75b | 2016-12-07 15:20:03 +0100 | [diff] [blame] | 2058 | return -EINVAL; |
Giuseppe CAVALLARO | 0f1f88a | 2012-04-18 19:48:21 +0000 | [diff] [blame] | 2059 | } |
| 2060 | |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2061 | if (priv->extend_desc && (priv->mode == STMMAC_RING_MODE)) |
| 2062 | atds = 1; |
| 2063 | |
Giuseppe Cavallaro | 495db27 | 2016-02-29 14:27:27 +0100 | [diff] [blame] | 2064 | ret = priv->hw->dma->reset(priv->ioaddr); |
| 2065 | if (ret) { |
| 2066 | dev_err(priv->device, "Failed to reset the dma\n"); |
| 2067 | return ret; |
| 2068 | } |
| 2069 | |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2070 | if (priv->synopsys_id >= DWMAC_CORE_4_00) { |
Joao Pinto | 47f2a9c | 2017-03-15 11:04:53 +0000 | [diff] [blame] | 2071 | /* DMA Configuration */ |
| 2072 | priv->hw->dma->init(priv->ioaddr, priv->plat->dma_cfg, |
| 2073 | dummy_dma_tx_phy, dummy_dma_rx_phy, atds); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2074 | |
Joao Pinto | 47f2a9c | 2017-03-15 11:04:53 +0000 | [diff] [blame] | 2075 | /* DMA RX Channel Configuration */ |
| 2076 | for (chan = 0; chan < rx_channels_count; chan++) { |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 2077 | rx_q = &priv->rx_queue[chan]; |
| 2078 | |
Joao Pinto | 47f2a9c | 2017-03-15 11:04:53 +0000 | [diff] [blame] | 2079 | priv->hw->dma->init_rx_chan(priv->ioaddr, |
| 2080 | priv->plat->dma_cfg, |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 2081 | rx_q->dma_rx_phy, chan); |
Joao Pinto | 47f2a9c | 2017-03-15 11:04:53 +0000 | [diff] [blame] | 2082 | |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 2083 | rx_q->rx_tail_addr = rx_q->dma_rx_phy + |
Joao Pinto | 47f2a9c | 2017-03-15 11:04:53 +0000 | [diff] [blame] | 2084 | (DMA_RX_SIZE * sizeof(struct dma_desc)); |
| 2085 | priv->hw->dma->set_rx_tail_ptr(priv->ioaddr, |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 2086 | rx_q->rx_tail_addr, |
Joao Pinto | 47f2a9c | 2017-03-15 11:04:53 +0000 | [diff] [blame] | 2087 | chan); |
| 2088 | } |
| 2089 | |
| 2090 | /* DMA TX Channel Configuration */ |
| 2091 | for (chan = 0; chan < tx_channels_count; chan++) { |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2092 | tx_q = &priv->tx_queue[chan]; |
| 2093 | |
Joao Pinto | 47f2a9c | 2017-03-15 11:04:53 +0000 | [diff] [blame] | 2094 | priv->hw->dma->init_chan(priv->ioaddr, |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2095 | priv->plat->dma_cfg, |
| 2096 | chan); |
Joao Pinto | 47f2a9c | 2017-03-15 11:04:53 +0000 | [diff] [blame] | 2097 | |
| 2098 | priv->hw->dma->init_tx_chan(priv->ioaddr, |
| 2099 | priv->plat->dma_cfg, |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2100 | tx_q->dma_tx_phy, chan); |
Joao Pinto | 47f2a9c | 2017-03-15 11:04:53 +0000 | [diff] [blame] | 2101 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2102 | tx_q->tx_tail_addr = tx_q->dma_tx_phy + |
Joao Pinto | 47f2a9c | 2017-03-15 11:04:53 +0000 | [diff] [blame] | 2103 | (DMA_TX_SIZE * sizeof(struct dma_desc)); |
| 2104 | priv->hw->dma->set_tx_tail_ptr(priv->ioaddr, |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2105 | tx_q->tx_tail_addr, |
Joao Pinto | 47f2a9c | 2017-03-15 11:04:53 +0000 | [diff] [blame] | 2106 | chan); |
| 2107 | } |
| 2108 | } else { |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 2109 | rx_q = &priv->rx_queue[chan]; |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2110 | tx_q = &priv->tx_queue[chan]; |
Joao Pinto | 47f2a9c | 2017-03-15 11:04:53 +0000 | [diff] [blame] | 2111 | priv->hw->dma->init(priv->ioaddr, priv->plat->dma_cfg, |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2112 | tx_q->dma_tx_phy, rx_q->dma_rx_phy, atds); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | if (priv->plat->axi && priv->hw->dma->axi) |
Giuseppe Cavallaro | afea036 | 2016-02-29 14:27:28 +0100 | [diff] [blame] | 2116 | priv->hw->dma->axi(priv->ioaddr, priv->plat->axi); |
| 2117 | |
Giuseppe Cavallaro | 495db27 | 2016-02-29 14:27:27 +0100 | [diff] [blame] | 2118 | return ret; |
Giuseppe CAVALLARO | 0f1f88a | 2012-04-18 19:48:21 +0000 | [diff] [blame] | 2119 | } |
| 2120 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2121 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 2122 | * stmmac_tx_timer - mitigation sw timer for tx. |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 2123 | * @data: data pointer |
| 2124 | * Description: |
| 2125 | * This is the timer handler to directly invoke the stmmac_tx_clean. |
| 2126 | */ |
| 2127 | static void stmmac_tx_timer(unsigned long data) |
| 2128 | { |
| 2129 | struct stmmac_priv *priv = (struct stmmac_priv *)data; |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2130 | u32 tx_queues_count = priv->plat->tx_queues_to_use; |
| 2131 | u32 queue; |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 2132 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2133 | /* let's scan all the tx queues */ |
| 2134 | for (queue = 0; queue < tx_queues_count; queue++) |
| 2135 | stmmac_tx_clean(priv, queue); |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 2136 | } |
| 2137 | |
| 2138 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 2139 | * stmmac_init_tx_coalesce - init tx mitigation options. |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 2140 | * @priv: driver private structure |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 2141 | * Description: |
| 2142 | * This inits the transmit coalesce parameters: i.e. timer rate, |
| 2143 | * timer handler and default threshold used for enabling the |
| 2144 | * interrupt on completion bit. |
| 2145 | */ |
| 2146 | static void stmmac_init_tx_coalesce(struct stmmac_priv *priv) |
| 2147 | { |
| 2148 | priv->tx_coal_frames = STMMAC_TX_FRAMES; |
| 2149 | priv->tx_coal_timer = STMMAC_COAL_TX_TIMER; |
| 2150 | init_timer(&priv->txtimer); |
| 2151 | priv->txtimer.expires = STMMAC_COAL_TIMER(priv->tx_coal_timer); |
| 2152 | priv->txtimer.data = (unsigned long)priv; |
| 2153 | priv->txtimer.function = stmmac_tx_timer; |
| 2154 | add_timer(&priv->txtimer); |
| 2155 | } |
| 2156 | |
Joao Pinto | 4854ab9 | 2017-03-15 11:04:51 +0000 | [diff] [blame] | 2157 | static void stmmac_set_rings_length(struct stmmac_priv *priv) |
| 2158 | { |
| 2159 | u32 rx_channels_count = priv->plat->rx_queues_to_use; |
| 2160 | u32 tx_channels_count = priv->plat->tx_queues_to_use; |
| 2161 | u32 chan; |
| 2162 | |
| 2163 | /* set TX ring length */ |
| 2164 | if (priv->hw->dma->set_tx_ring_len) { |
| 2165 | for (chan = 0; chan < tx_channels_count; chan++) |
| 2166 | priv->hw->dma->set_tx_ring_len(priv->ioaddr, |
| 2167 | (DMA_TX_SIZE - 1), chan); |
| 2168 | } |
| 2169 | |
| 2170 | /* set RX ring length */ |
| 2171 | if (priv->hw->dma->set_rx_ring_len) { |
| 2172 | for (chan = 0; chan < rx_channels_count; chan++) |
| 2173 | priv->hw->dma->set_rx_ring_len(priv->ioaddr, |
| 2174 | (DMA_RX_SIZE - 1), chan); |
| 2175 | } |
| 2176 | } |
| 2177 | |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 2178 | /** |
Joao Pinto | 6a3a719 | 2017-03-10 18:24:53 +0000 | [diff] [blame] | 2179 | * stmmac_set_tx_queue_weight - Set TX queue weight |
| 2180 | * @priv: driver private structure |
| 2181 | * Description: It is used for setting TX queues weight |
| 2182 | */ |
| 2183 | static void stmmac_set_tx_queue_weight(struct stmmac_priv *priv) |
| 2184 | { |
| 2185 | u32 tx_queues_count = priv->plat->tx_queues_to_use; |
| 2186 | u32 weight; |
| 2187 | u32 queue; |
| 2188 | |
| 2189 | for (queue = 0; queue < tx_queues_count; queue++) { |
| 2190 | weight = priv->plat->tx_queues_cfg[queue].weight; |
| 2191 | priv->hw->mac->set_mtl_tx_queue_weight(priv->hw, weight, queue); |
| 2192 | } |
| 2193 | } |
| 2194 | |
| 2195 | /** |
Joao Pinto | 19d9187 | 2017-03-10 18:24:59 +0000 | [diff] [blame] | 2196 | * stmmac_configure_cbs - Configure CBS in TX queue |
| 2197 | * @priv: driver private structure |
| 2198 | * Description: It is used for configuring CBS in AVB TX queues |
| 2199 | */ |
| 2200 | static void stmmac_configure_cbs(struct stmmac_priv *priv) |
| 2201 | { |
| 2202 | u32 tx_queues_count = priv->plat->tx_queues_to_use; |
| 2203 | u32 mode_to_use; |
| 2204 | u32 queue; |
| 2205 | |
Joao Pinto | 44781fe | 2017-03-31 14:22:02 +0100 | [diff] [blame] | 2206 | /* queue 0 is reserved for legacy traffic */ |
| 2207 | for (queue = 1; queue < tx_queues_count; queue++) { |
Joao Pinto | 19d9187 | 2017-03-10 18:24:59 +0000 | [diff] [blame] | 2208 | mode_to_use = priv->plat->tx_queues_cfg[queue].mode_to_use; |
| 2209 | if (mode_to_use == MTL_QUEUE_DCB) |
| 2210 | continue; |
| 2211 | |
| 2212 | priv->hw->mac->config_cbs(priv->hw, |
| 2213 | priv->plat->tx_queues_cfg[queue].send_slope, |
| 2214 | priv->plat->tx_queues_cfg[queue].idle_slope, |
| 2215 | priv->plat->tx_queues_cfg[queue].high_credit, |
| 2216 | priv->plat->tx_queues_cfg[queue].low_credit, |
| 2217 | queue); |
| 2218 | } |
| 2219 | } |
| 2220 | |
| 2221 | /** |
Joao Pinto | d43042f | 2017-03-10 18:24:55 +0000 | [diff] [blame] | 2222 | * stmmac_rx_queue_dma_chan_map - Map RX queue to RX dma channel |
| 2223 | * @priv: driver private structure |
| 2224 | * Description: It is used for mapping RX queues to RX dma channels |
| 2225 | */ |
| 2226 | static void stmmac_rx_queue_dma_chan_map(struct stmmac_priv *priv) |
| 2227 | { |
| 2228 | u32 rx_queues_count = priv->plat->rx_queues_to_use; |
| 2229 | u32 queue; |
| 2230 | u32 chan; |
| 2231 | |
| 2232 | for (queue = 0; queue < rx_queues_count; queue++) { |
| 2233 | chan = priv->plat->rx_queues_cfg[queue].chan; |
| 2234 | priv->hw->mac->map_mtl_to_dma(priv->hw, queue, chan); |
| 2235 | } |
| 2236 | } |
| 2237 | |
| 2238 | /** |
Joao Pinto | a8f5102 | 2017-03-17 16:11:06 +0000 | [diff] [blame] | 2239 | * stmmac_mac_config_rx_queues_prio - Configure RX Queue priority |
| 2240 | * @priv: driver private structure |
| 2241 | * Description: It is used for configuring the RX Queue Priority |
| 2242 | */ |
| 2243 | static void stmmac_mac_config_rx_queues_prio(struct stmmac_priv *priv) |
| 2244 | { |
| 2245 | u32 rx_queues_count = priv->plat->rx_queues_to_use; |
| 2246 | u32 queue; |
| 2247 | u32 prio; |
| 2248 | |
| 2249 | for (queue = 0; queue < rx_queues_count; queue++) { |
| 2250 | if (!priv->plat->rx_queues_cfg[queue].use_prio) |
| 2251 | continue; |
| 2252 | |
| 2253 | prio = priv->plat->rx_queues_cfg[queue].prio; |
| 2254 | priv->hw->mac->rx_queue_prio(priv->hw, prio, queue); |
| 2255 | } |
| 2256 | } |
| 2257 | |
| 2258 | /** |
| 2259 | * stmmac_mac_config_tx_queues_prio - Configure TX Queue priority |
| 2260 | * @priv: driver private structure |
| 2261 | * Description: It is used for configuring the TX Queue Priority |
| 2262 | */ |
| 2263 | static void stmmac_mac_config_tx_queues_prio(struct stmmac_priv *priv) |
| 2264 | { |
| 2265 | u32 tx_queues_count = priv->plat->tx_queues_to_use; |
| 2266 | u32 queue; |
| 2267 | u32 prio; |
| 2268 | |
| 2269 | for (queue = 0; queue < tx_queues_count; queue++) { |
| 2270 | if (!priv->plat->tx_queues_cfg[queue].use_prio) |
| 2271 | continue; |
| 2272 | |
| 2273 | prio = priv->plat->tx_queues_cfg[queue].prio; |
| 2274 | priv->hw->mac->tx_queue_prio(priv->hw, prio, queue); |
| 2275 | } |
| 2276 | } |
| 2277 | |
| 2278 | /** |
Joao Pinto | abe80fd | 2017-03-17 16:11:07 +0000 | [diff] [blame] | 2279 | * stmmac_mac_config_rx_queues_routing - Configure RX Queue Routing |
| 2280 | * @priv: driver private structure |
| 2281 | * Description: It is used for configuring the RX queue routing |
| 2282 | */ |
| 2283 | static void stmmac_mac_config_rx_queues_routing(struct stmmac_priv *priv) |
| 2284 | { |
| 2285 | u32 rx_queues_count = priv->plat->rx_queues_to_use; |
| 2286 | u32 queue; |
| 2287 | u8 packet; |
| 2288 | |
| 2289 | for (queue = 0; queue < rx_queues_count; queue++) { |
| 2290 | /* no specific packet type routing specified for the queue */ |
| 2291 | if (priv->plat->rx_queues_cfg[queue].pkt_route == 0x0) |
| 2292 | continue; |
| 2293 | |
| 2294 | packet = priv->plat->rx_queues_cfg[queue].pkt_route; |
| 2295 | priv->hw->mac->rx_queue_prio(priv->hw, packet, queue); |
| 2296 | } |
| 2297 | } |
| 2298 | |
| 2299 | /** |
Joao Pinto | d0a9c9f | 2017-03-10 18:24:52 +0000 | [diff] [blame] | 2300 | * stmmac_mtl_configuration - Configure MTL |
| 2301 | * @priv: driver private structure |
| 2302 | * Description: It is used for configurring MTL |
| 2303 | */ |
| 2304 | static void stmmac_mtl_configuration(struct stmmac_priv *priv) |
| 2305 | { |
| 2306 | u32 rx_queues_count = priv->plat->rx_queues_to_use; |
| 2307 | u32 tx_queues_count = priv->plat->tx_queues_to_use; |
| 2308 | |
Joao Pinto | 6a3a719 | 2017-03-10 18:24:53 +0000 | [diff] [blame] | 2309 | if (tx_queues_count > 1 && priv->hw->mac->set_mtl_tx_queue_weight) |
| 2310 | stmmac_set_tx_queue_weight(priv); |
| 2311 | |
Joao Pinto | d0a9c9f | 2017-03-10 18:24:52 +0000 | [diff] [blame] | 2312 | /* Configure MTL RX algorithms */ |
| 2313 | if (rx_queues_count > 1 && priv->hw->mac->prog_mtl_rx_algorithms) |
| 2314 | priv->hw->mac->prog_mtl_rx_algorithms(priv->hw, |
| 2315 | priv->plat->rx_sched_algorithm); |
| 2316 | |
| 2317 | /* Configure MTL TX algorithms */ |
| 2318 | if (tx_queues_count > 1 && priv->hw->mac->prog_mtl_tx_algorithms) |
| 2319 | priv->hw->mac->prog_mtl_tx_algorithms(priv->hw, |
| 2320 | priv->plat->tx_sched_algorithm); |
| 2321 | |
Joao Pinto | 19d9187 | 2017-03-10 18:24:59 +0000 | [diff] [blame] | 2322 | /* Configure CBS in AVB TX queues */ |
| 2323 | if (tx_queues_count > 1 && priv->hw->mac->config_cbs) |
| 2324 | stmmac_configure_cbs(priv); |
| 2325 | |
Joao Pinto | d43042f | 2017-03-10 18:24:55 +0000 | [diff] [blame] | 2326 | /* Map RX MTL to DMA channels */ |
Joao Pinto | 03cf65a | 2017-04-03 16:34:04 +0100 | [diff] [blame] | 2327 | if (priv->hw->mac->map_mtl_to_dma) |
Joao Pinto | d43042f | 2017-03-10 18:24:55 +0000 | [diff] [blame] | 2328 | stmmac_rx_queue_dma_chan_map(priv); |
| 2329 | |
Joao Pinto | d0a9c9f | 2017-03-10 18:24:52 +0000 | [diff] [blame] | 2330 | /* Enable MAC RX Queues */ |
Thierry Reding | f397687 | 2017-03-21 16:12:09 +0100 | [diff] [blame] | 2331 | if (priv->hw->mac->rx_queue_enable) |
Joao Pinto | d0a9c9f | 2017-03-10 18:24:52 +0000 | [diff] [blame] | 2332 | stmmac_mac_enable_rx_queues(priv); |
Joao Pinto | 6deee22 | 2017-03-15 11:04:45 +0000 | [diff] [blame] | 2333 | |
Joao Pinto | a8f5102 | 2017-03-17 16:11:06 +0000 | [diff] [blame] | 2334 | /* Set RX priorities */ |
| 2335 | if (rx_queues_count > 1 && priv->hw->mac->rx_queue_prio) |
| 2336 | stmmac_mac_config_rx_queues_prio(priv); |
| 2337 | |
| 2338 | /* Set TX priorities */ |
| 2339 | if (tx_queues_count > 1 && priv->hw->mac->tx_queue_prio) |
| 2340 | stmmac_mac_config_tx_queues_prio(priv); |
Joao Pinto | abe80fd | 2017-03-17 16:11:07 +0000 | [diff] [blame] | 2341 | |
| 2342 | /* Set RX routing */ |
| 2343 | if (rx_queues_count > 1 && priv->hw->mac->rx_queue_routing) |
| 2344 | stmmac_mac_config_rx_queues_routing(priv); |
Joao Pinto | d0a9c9f | 2017-03-10 18:24:52 +0000 | [diff] [blame] | 2345 | } |
| 2346 | |
| 2347 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 2348 | * stmmac_hw_setup - setup mac in a usable state. |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 2349 | * @dev : pointer to the device structure. |
| 2350 | * Description: |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 2351 | * this is the main function to setup the HW in a usable state because the |
| 2352 | * dma engine is reset, the core registers are configured (e.g. AXI, |
| 2353 | * Checksum features, timers). The DMA is ready to start receiving and |
| 2354 | * transmitting. |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 2355 | * Return value: |
| 2356 | * 0 on success and an appropriate (-)ve integer as defined in errno.h |
| 2357 | * file on failure. |
| 2358 | */ |
Huacai Chen | fe131929 | 2014-12-19 22:38:18 +0800 | [diff] [blame] | 2359 | static int stmmac_hw_setup(struct net_device *dev, bool init_ptp) |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 2360 | { |
| 2361 | struct stmmac_priv *priv = netdev_priv(dev); |
Joao Pinto | 3c55d4d | 2017-03-15 11:04:50 +0000 | [diff] [blame] | 2362 | u32 rx_cnt = priv->plat->rx_queues_to_use; |
Joao Pinto | 146617b | 2017-03-15 11:04:54 +0000 | [diff] [blame] | 2363 | u32 tx_cnt = priv->plat->tx_queues_to_use; |
| 2364 | u32 chan; |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 2365 | int ret; |
| 2366 | |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 2367 | /* DMA initialization and SW reset */ |
| 2368 | ret = stmmac_init_dma_engine(priv); |
| 2369 | if (ret < 0) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 2370 | netdev_err(priv->dev, "%s: DMA engine initialization failed\n", |
| 2371 | __func__); |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 2372 | return ret; |
| 2373 | } |
| 2374 | |
| 2375 | /* Copy the MAC addr into the HW */ |
Vince Bridgers | 7ed24bb | 2014-07-31 15:49:13 -0500 | [diff] [blame] | 2376 | priv->hw->mac->set_umac_addr(priv->hw, dev->dev_addr, 0); |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 2377 | |
Giuseppe CAVALLARO | 02e57b9 | 2016-06-24 15:16:26 +0200 | [diff] [blame] | 2378 | /* PS and related bits will be programmed according to the speed */ |
| 2379 | if (priv->hw->pcs) { |
| 2380 | int speed = priv->plat->mac_port_sel_speed; |
| 2381 | |
| 2382 | if ((speed == SPEED_10) || (speed == SPEED_100) || |
| 2383 | (speed == SPEED_1000)) { |
| 2384 | priv->hw->ps = speed; |
| 2385 | } else { |
| 2386 | dev_warn(priv->device, "invalid port speed\n"); |
| 2387 | priv->hw->ps = 0; |
| 2388 | } |
| 2389 | } |
| 2390 | |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 2391 | /* Initialize the MAC Core */ |
Vince Bridgers | 7ed24bb | 2014-07-31 15:49:13 -0500 | [diff] [blame] | 2392 | priv->hw->mac->core_init(priv->hw, dev->mtu); |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 2393 | |
Joao Pinto | d0a9c9f | 2017-03-10 18:24:52 +0000 | [diff] [blame] | 2394 | /* Initialize MTL*/ |
| 2395 | if (priv->synopsys_id >= DWMAC_CORE_4_00) |
| 2396 | stmmac_mtl_configuration(priv); |
jpinto | 9eb1247 | 2016-12-28 12:57:48 +0000 | [diff] [blame] | 2397 | |
Giuseppe CAVALLARO | 978aded | 2014-08-25 14:56:18 +0200 | [diff] [blame] | 2398 | ret = priv->hw->mac->rx_ipc(priv->hw); |
| 2399 | if (!ret) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 2400 | netdev_warn(priv->dev, "RX IPC Checksum Offload disabled\n"); |
Giuseppe CAVALLARO | 978aded | 2014-08-25 14:56:18 +0200 | [diff] [blame] | 2401 | priv->plat->rx_coe = STMMAC_RX_COE_NONE; |
Giuseppe CAVALLARO | d2afb5b | 2014-09-01 09:17:52 +0200 | [diff] [blame] | 2402 | priv->hw->rx_csum = 0; |
Giuseppe CAVALLARO | 978aded | 2014-08-25 14:56:18 +0200 | [diff] [blame] | 2403 | } |
| 2404 | |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 2405 | /* Enable the MAC Rx/Tx */ |
LABBE Corentin | 270c775 | 2017-03-23 14:40:22 +0100 | [diff] [blame] | 2406 | priv->hw->mac->set_mac(priv->ioaddr, true); |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 2407 | |
Joao Pinto | b4f0a66 | 2017-03-22 11:56:05 +0000 | [diff] [blame] | 2408 | /* Set the HW DMA mode and the COE */ |
| 2409 | stmmac_dma_operation_mode(priv); |
| 2410 | |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 2411 | stmmac_mmc_setup(priv); |
| 2412 | |
Huacai Chen | fe131929 | 2014-12-19 22:38:18 +0800 | [diff] [blame] | 2413 | if (init_ptp) { |
Thierry Reding | 0ad2be7 | 2017-03-10 17:34:56 +0100 | [diff] [blame] | 2414 | ret = clk_prepare_enable(priv->plat->clk_ptp_ref); |
| 2415 | if (ret < 0) |
| 2416 | netdev_warn(priv->dev, "failed to enable PTP reference clock: %d\n", ret); |
| 2417 | |
Huacai Chen | fe131929 | 2014-12-19 22:38:18 +0800 | [diff] [blame] | 2418 | ret = stmmac_init_ptp(priv); |
Heiner Kallweit | 722eef2 | 2017-02-01 22:02:02 +0100 | [diff] [blame] | 2419 | if (ret == -EOPNOTSUPP) |
| 2420 | netdev_warn(priv->dev, "PTP not supported by HW\n"); |
| 2421 | else if (ret) |
| 2422 | netdev_warn(priv->dev, "PTP init failed\n"); |
Huacai Chen | fe131929 | 2014-12-19 22:38:18 +0800 | [diff] [blame] | 2423 | } |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 2424 | |
Giuseppe CAVALLARO | 50fb4f74 | 2014-11-04 15:49:33 +0100 | [diff] [blame] | 2425 | #ifdef CONFIG_DEBUG_FS |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 2426 | ret = stmmac_init_fs(dev); |
| 2427 | if (ret < 0) |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 2428 | netdev_warn(priv->dev, "%s: failed debugFS registration\n", |
| 2429 | __func__); |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 2430 | #endif |
| 2431 | /* Start the ball rolling... */ |
Joao Pinto | ae4f0d4 | 2017-03-15 11:04:47 +0000 | [diff] [blame] | 2432 | stmmac_start_all_dma(priv); |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 2433 | |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 2434 | priv->tx_lpi_timer = STMMAC_DEFAULT_TWT_LS; |
| 2435 | |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 2436 | if ((priv->use_riwt) && (priv->hw->dma->rx_watchdog)) { |
| 2437 | priv->rx_riwt = MAX_DMA_RIWT; |
Joao Pinto | 3c55d4d | 2017-03-15 11:04:50 +0000 | [diff] [blame] | 2438 | priv->hw->dma->rx_watchdog(priv->ioaddr, MAX_DMA_RIWT, rx_cnt); |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 2439 | } |
| 2440 | |
Giuseppe CAVALLARO | 3fe5cad | 2016-06-24 15:16:25 +0200 | [diff] [blame] | 2441 | if (priv->hw->pcs && priv->hw->mac->pcs_ctrl_ane) |
Giuseppe CAVALLARO | 02e57b9 | 2016-06-24 15:16:26 +0200 | [diff] [blame] | 2442 | priv->hw->mac->pcs_ctrl_ane(priv->hw, 1, priv->hw->ps, 0); |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 2443 | |
Joao Pinto | 4854ab9 | 2017-03-15 11:04:51 +0000 | [diff] [blame] | 2444 | /* set TX and RX rings length */ |
| 2445 | stmmac_set_rings_length(priv); |
| 2446 | |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2447 | /* Enable TSO */ |
Joao Pinto | 146617b | 2017-03-15 11:04:54 +0000 | [diff] [blame] | 2448 | if (priv->tso) { |
| 2449 | for (chan = 0; chan < tx_cnt; chan++) |
| 2450 | priv->hw->dma->enable_tso(priv->ioaddr, 1, chan); |
| 2451 | } |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2452 | |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 2453 | return 0; |
| 2454 | } |
| 2455 | |
Thierry Reding | c66f6c3 | 2017-03-10 17:34:55 +0100 | [diff] [blame] | 2456 | static void stmmac_hw_teardown(struct net_device *dev) |
| 2457 | { |
| 2458 | struct stmmac_priv *priv = netdev_priv(dev); |
| 2459 | |
| 2460 | clk_disable_unprepare(priv->plat->clk_ptp_ref); |
| 2461 | } |
| 2462 | |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 2463 | /** |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2464 | * stmmac_open - open entry point of the driver |
| 2465 | * @dev : pointer to the device structure. |
| 2466 | * Description: |
| 2467 | * This function is the open entry point of the driver. |
| 2468 | * Return value: |
| 2469 | * 0 on success and an appropriate (-)ve integer as defined in errno.h |
| 2470 | * file on failure. |
| 2471 | */ |
| 2472 | static int stmmac_open(struct net_device *dev) |
| 2473 | { |
| 2474 | struct stmmac_priv *priv = netdev_priv(dev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2475 | int ret; |
| 2476 | |
Francesco Virlinzi | 4bfcbd7 | 2012-04-18 19:48:20 +0000 | [diff] [blame] | 2477 | stmmac_check_ether_addr(priv); |
| 2478 | |
Giuseppe CAVALLARO | 3fe5cad | 2016-06-24 15:16:25 +0200 | [diff] [blame] | 2479 | if (priv->hw->pcs != STMMAC_PCS_RGMII && |
| 2480 | priv->hw->pcs != STMMAC_PCS_TBI && |
| 2481 | priv->hw->pcs != STMMAC_PCS_RTBI) { |
Giuseppe CAVALLARO | e58bb43 | 2013-03-26 04:43:08 +0000 | [diff] [blame] | 2482 | ret = stmmac_init_phy(dev); |
| 2483 | if (ret) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 2484 | netdev_err(priv->dev, |
| 2485 | "%s: Cannot attach to PHY (error: %d)\n", |
| 2486 | __func__, ret); |
Hans de Goede | 89df20d | 2014-05-20 11:38:18 +0200 | [diff] [blame] | 2487 | return ret; |
Giuseppe CAVALLARO | e58bb43 | 2013-03-26 04:43:08 +0000 | [diff] [blame] | 2488 | } |
Giuseppe CAVALLARO | f66ffe2 | 2011-04-10 23:16:45 +0000 | [diff] [blame] | 2489 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2490 | |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 2491 | /* Extra statistics */ |
| 2492 | memset(&priv->xstats, 0, sizeof(struct stmmac_extra_stats)); |
| 2493 | priv->xstats.threshold = tc; |
| 2494 | |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 2495 | priv->dma_buf_sz = STMMAC_ALIGN(buf_sz); |
Giuseppe Cavallaro | 22ad383 | 2016-02-29 14:27:41 +0100 | [diff] [blame] | 2496 | priv->rx_copybreak = STMMAC_RX_COPYBREAK; |
Bartlomiej Zolnierkiewicz | 5632913 | 2013-08-09 14:02:08 +0200 | [diff] [blame] | 2497 | |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 2498 | ret = alloc_dma_desc_resources(priv); |
| 2499 | if (ret < 0) { |
| 2500 | netdev_err(priv->dev, "%s: DMA descriptors allocation failed\n", |
| 2501 | __func__); |
| 2502 | goto dma_desc_error; |
| 2503 | } |
| 2504 | |
| 2505 | ret = init_dma_desc_rings(dev, GFP_KERNEL); |
| 2506 | if (ret < 0) { |
| 2507 | netdev_err(priv->dev, "%s: DMA descriptors initialization failed\n", |
| 2508 | __func__); |
| 2509 | goto init_error; |
| 2510 | } |
| 2511 | |
Huacai Chen | fe131929 | 2014-12-19 22:38:18 +0800 | [diff] [blame] | 2512 | ret = stmmac_hw_setup(dev, true); |
Bartlomiej Zolnierkiewicz | 5632913 | 2013-08-09 14:02:08 +0200 | [diff] [blame] | 2513 | if (ret < 0) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 2514 | netdev_err(priv->dev, "%s: Hw setup failed\n", __func__); |
Giuseppe CAVALLARO | c9324d1 | 2013-07-04 06:18:07 +0200 | [diff] [blame] | 2515 | goto init_error; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2516 | } |
| 2517 | |
Giuseppe CAVALLARO | 777da230 | 2014-11-04 17:08:09 +0100 | [diff] [blame] | 2518 | stmmac_init_tx_coalesce(priv); |
| 2519 | |
Philippe Reynes | d6d50c7 | 2016-10-03 08:28:19 +0200 | [diff] [blame] | 2520 | if (dev->phydev) |
| 2521 | phy_start(dev->phydev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2522 | |
Giuseppe CAVALLARO | f66ffe2 | 2011-04-10 23:16:45 +0000 | [diff] [blame] | 2523 | /* Request the IRQ lines */ |
| 2524 | ret = request_irq(dev->irq, stmmac_interrupt, |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 2525 | IRQF_SHARED, dev->name, dev); |
Giuseppe CAVALLARO | f66ffe2 | 2011-04-10 23:16:45 +0000 | [diff] [blame] | 2526 | if (unlikely(ret < 0)) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 2527 | netdev_err(priv->dev, |
| 2528 | "%s: ERROR: allocating the IRQ %d (error: %d)\n", |
| 2529 | __func__, dev->irq, ret); |
Thierry Reding | 6c1e5ab | 2017-03-10 17:34:54 +0100 | [diff] [blame] | 2530 | goto irq_error; |
Giuseppe CAVALLARO | f66ffe2 | 2011-04-10 23:16:45 +0000 | [diff] [blame] | 2531 | } |
| 2532 | |
Francesco Virlinzi | 7a13f8f | 2012-02-15 00:10:38 +0000 | [diff] [blame] | 2533 | /* Request the Wake IRQ in case of another line is used for WoL */ |
| 2534 | if (priv->wol_irq != dev->irq) { |
| 2535 | ret = request_irq(priv->wol_irq, stmmac_interrupt, |
| 2536 | IRQF_SHARED, dev->name, dev); |
| 2537 | if (unlikely(ret < 0)) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 2538 | netdev_err(priv->dev, |
| 2539 | "%s: ERROR: allocating the WoL IRQ %d (%d)\n", |
| 2540 | __func__, priv->wol_irq, ret); |
Giuseppe CAVALLARO | c9324d1 | 2013-07-04 06:18:07 +0200 | [diff] [blame] | 2541 | goto wolirq_error; |
Francesco Virlinzi | 7a13f8f | 2012-02-15 00:10:38 +0000 | [diff] [blame] | 2542 | } |
| 2543 | } |
| 2544 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 2545 | /* Request the IRQ lines */ |
Chen-Yu Tsai | d7ec858 | 2014-05-29 22:31:40 +0800 | [diff] [blame] | 2546 | if (priv->lpi_irq > 0) { |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 2547 | ret = request_irq(priv->lpi_irq, stmmac_interrupt, IRQF_SHARED, |
| 2548 | dev->name, dev); |
| 2549 | if (unlikely(ret < 0)) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 2550 | netdev_err(priv->dev, |
| 2551 | "%s: ERROR: allocating the LPI IRQ %d (%d)\n", |
| 2552 | __func__, priv->lpi_irq, ret); |
Giuseppe CAVALLARO | c9324d1 | 2013-07-04 06:18:07 +0200 | [diff] [blame] | 2553 | goto lpiirq_error; |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 2554 | } |
| 2555 | } |
| 2556 | |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 2557 | napi_enable(&priv->napi); |
| 2558 | netif_start_queue(dev); |
Giuseppe CAVALLARO | f66ffe2 | 2011-04-10 23:16:45 +0000 | [diff] [blame] | 2559 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2560 | return 0; |
Giuseppe CAVALLARO | f66ffe2 | 2011-04-10 23:16:45 +0000 | [diff] [blame] | 2561 | |
Giuseppe CAVALLARO | c9324d1 | 2013-07-04 06:18:07 +0200 | [diff] [blame] | 2562 | lpiirq_error: |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 2563 | if (priv->wol_irq != dev->irq) |
| 2564 | free_irq(priv->wol_irq, dev); |
Giuseppe CAVALLARO | c9324d1 | 2013-07-04 06:18:07 +0200 | [diff] [blame] | 2565 | wolirq_error: |
Francesco Virlinzi | 7a13f8f | 2012-02-15 00:10:38 +0000 | [diff] [blame] | 2566 | free_irq(dev->irq, dev); |
Thierry Reding | 6c1e5ab | 2017-03-10 17:34:54 +0100 | [diff] [blame] | 2567 | irq_error: |
| 2568 | if (dev->phydev) |
| 2569 | phy_stop(dev->phydev); |
Francesco Virlinzi | 7a13f8f | 2012-02-15 00:10:38 +0000 | [diff] [blame] | 2570 | |
Thierry Reding | 6c1e5ab | 2017-03-10 17:34:54 +0100 | [diff] [blame] | 2571 | del_timer_sync(&priv->txtimer); |
Thierry Reding | c66f6c3 | 2017-03-10 17:34:55 +0100 | [diff] [blame] | 2572 | stmmac_hw_teardown(dev); |
Giuseppe CAVALLARO | c9324d1 | 2013-07-04 06:18:07 +0200 | [diff] [blame] | 2573 | init_error: |
| 2574 | free_dma_desc_resources(priv); |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 2575 | dma_desc_error: |
Philippe Reynes | d6d50c7 | 2016-10-03 08:28:19 +0200 | [diff] [blame] | 2576 | if (dev->phydev) |
| 2577 | phy_disconnect(dev->phydev); |
Francesco Virlinzi | 4bfcbd7 | 2012-04-18 19:48:20 +0000 | [diff] [blame] | 2578 | |
Giuseppe CAVALLARO | f66ffe2 | 2011-04-10 23:16:45 +0000 | [diff] [blame] | 2579 | return ret; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2580 | } |
| 2581 | |
| 2582 | /** |
| 2583 | * stmmac_release - close entry point of the driver |
| 2584 | * @dev : device pointer. |
| 2585 | * Description: |
| 2586 | * This is the stop entry point of the driver. |
| 2587 | */ |
| 2588 | static int stmmac_release(struct net_device *dev) |
| 2589 | { |
| 2590 | struct stmmac_priv *priv = netdev_priv(dev); |
| 2591 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 2592 | if (priv->eee_enabled) |
| 2593 | del_timer_sync(&priv->eee_ctrl_timer); |
| 2594 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2595 | /* Stop and disconnect the PHY */ |
Philippe Reynes | d6d50c7 | 2016-10-03 08:28:19 +0200 | [diff] [blame] | 2596 | if (dev->phydev) { |
| 2597 | phy_stop(dev->phydev); |
| 2598 | phy_disconnect(dev->phydev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2599 | } |
| 2600 | |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 2601 | netif_stop_queue(dev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2602 | |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 2603 | napi_disable(&priv->napi); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2604 | |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 2605 | del_timer_sync(&priv->txtimer); |
| 2606 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2607 | /* Free the IRQ lines */ |
| 2608 | free_irq(dev->irq, dev); |
Francesco Virlinzi | 7a13f8f | 2012-02-15 00:10:38 +0000 | [diff] [blame] | 2609 | if (priv->wol_irq != dev->irq) |
| 2610 | free_irq(priv->wol_irq, dev); |
Chen-Yu Tsai | d7ec858 | 2014-05-29 22:31:40 +0800 | [diff] [blame] | 2611 | if (priv->lpi_irq > 0) |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 2612 | free_irq(priv->lpi_irq, dev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2613 | |
| 2614 | /* Stop TX/RX DMA and clear the descriptors */ |
Joao Pinto | ae4f0d4 | 2017-03-15 11:04:47 +0000 | [diff] [blame] | 2615 | stmmac_stop_all_dma(priv); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2616 | |
| 2617 | /* Release and free the Rx/Tx resources */ |
| 2618 | free_dma_desc_resources(priv); |
| 2619 | |
avisconti | 19449bf | 2010-10-25 18:58:14 +0000 | [diff] [blame] | 2620 | /* Disable the MAC Rx/Tx */ |
LABBE Corentin | 270c775 | 2017-03-23 14:40:22 +0100 | [diff] [blame] | 2621 | priv->hw->mac->set_mac(priv->ioaddr, false); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2622 | |
| 2623 | netif_carrier_off(dev); |
| 2624 | |
Giuseppe CAVALLARO | 50fb4f74 | 2014-11-04 15:49:33 +0100 | [diff] [blame] | 2625 | #ifdef CONFIG_DEBUG_FS |
Mathieu Olivari | 466c5ac | 2015-05-22 19:03:29 -0700 | [diff] [blame] | 2626 | stmmac_exit_fs(dev); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2627 | #endif |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2628 | |
Rayagond Kokatanur | 92ba688 | 2013-03-26 04:43:11 +0000 | [diff] [blame] | 2629 | stmmac_release_ptp(priv); |
| 2630 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2631 | return 0; |
| 2632 | } |
| 2633 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2634 | /** |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2635 | * stmmac_tso_allocator - close entry point of the driver |
| 2636 | * @priv: driver private structure |
| 2637 | * @des: buffer start address |
| 2638 | * @total_len: total length to fill in descriptors |
| 2639 | * @last_segmant: condition for the last descriptor |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2640 | * @queue: TX queue index |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2641 | * Description: |
| 2642 | * This function fills descriptor and request new descriptors according to |
| 2643 | * buffer length to fill |
| 2644 | */ |
| 2645 | static void stmmac_tso_allocator(struct stmmac_priv *priv, unsigned int des, |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2646 | int total_len, bool last_segment, u32 queue) |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2647 | { |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2648 | struct stmmac_tx_queue *tx_q = &priv->tx_queue[queue]; |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2649 | struct dma_desc *desc; |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 2650 | u32 buff_size; |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2651 | int tmp_len; |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2652 | |
| 2653 | tmp_len = total_len; |
| 2654 | |
| 2655 | while (tmp_len > 0) { |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2656 | tx_q->cur_tx = STMMAC_GET_ENTRY(tx_q->cur_tx, DMA_TX_SIZE); |
| 2657 | desc = tx_q->dma_tx + tx_q->cur_tx; |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2658 | |
Michael Weiser | f8be0d7 | 2016-11-14 18:58:05 +0100 | [diff] [blame] | 2659 | desc->des0 = cpu_to_le32(des + (total_len - tmp_len)); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2660 | buff_size = tmp_len >= TSO_MAX_BUFF_SIZE ? |
| 2661 | TSO_MAX_BUFF_SIZE : tmp_len; |
| 2662 | |
| 2663 | priv->hw->desc->prepare_tso_tx_desc(desc, 0, buff_size, |
| 2664 | 0, 1, |
| 2665 | (last_segment) && (buff_size < TSO_MAX_BUFF_SIZE), |
| 2666 | 0, 0); |
| 2667 | |
| 2668 | tmp_len -= TSO_MAX_BUFF_SIZE; |
| 2669 | } |
| 2670 | } |
| 2671 | |
| 2672 | /** |
| 2673 | * stmmac_tso_xmit - Tx entry point of the driver for oversized frames (TSO) |
| 2674 | * @skb : the socket buffer |
| 2675 | * @dev : device pointer |
| 2676 | * Description: this is the transmit function that is called on TSO frames |
| 2677 | * (support available on GMAC4 and newer chips). |
| 2678 | * Diagram below show the ring programming in case of TSO frames: |
| 2679 | * |
| 2680 | * First Descriptor |
| 2681 | * -------- |
| 2682 | * | DES0 |---> buffer1 = L2/L3/L4 header |
| 2683 | * | DES1 |---> TCP Payload (can continue on next descr...) |
| 2684 | * | DES2 |---> buffer 1 and 2 len |
| 2685 | * | DES3 |---> must set TSE, TCP hdr len-> [22:19]. TCP payload len [17:0] |
| 2686 | * -------- |
| 2687 | * | |
| 2688 | * ... |
| 2689 | * | |
| 2690 | * -------- |
| 2691 | * | DES0 | --| Split TCP Payload on Buffers 1 and 2 |
| 2692 | * | DES1 | --| |
| 2693 | * | DES2 | --> buffer 1 and 2 len |
| 2694 | * | DES3 | |
| 2695 | * -------- |
| 2696 | * |
| 2697 | * mss is fixed when enable tso, so w/o programming the TDES3 ctx field. |
| 2698 | */ |
| 2699 | static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev) |
| 2700 | { |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2701 | struct dma_desc *desc, *first, *mss_desc = NULL; |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2702 | struct stmmac_priv *priv = netdev_priv(dev); |
| 2703 | int nfrags = skb_shinfo(skb)->nr_frags; |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2704 | u32 queue = skb_get_queue_mapping(skb); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2705 | unsigned int first_entry, des; |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2706 | struct stmmac_tx_queue *tx_q; |
| 2707 | int tmp_pay_len = 0; |
| 2708 | u32 pay_len, mss; |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2709 | u8 proto_hdr_len; |
| 2710 | int i; |
| 2711 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2712 | tx_q = &priv->tx_queue[queue]; |
| 2713 | |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2714 | /* Compute header lengths */ |
| 2715 | proto_hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
| 2716 | |
| 2717 | /* Desc availability based on threshold should be enough safe */ |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2718 | if (unlikely(stmmac_tx_avail(priv, queue) < |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2719 | (((skb->len - proto_hdr_len) / TSO_MAX_BUFF_SIZE + 1)))) { |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 2720 | if (!netif_queue_stopped(dev)) { |
| 2721 | netif_stop_queue(dev); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2722 | /* This is a hard error, log it. */ |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 2723 | netdev_err(priv->dev, |
| 2724 | "%s: Tx Ring full when queue awake\n", |
| 2725 | __func__); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2726 | } |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2727 | return NETDEV_TX_BUSY; |
| 2728 | } |
| 2729 | |
| 2730 | pay_len = skb_headlen(skb) - proto_hdr_len; /* no frags */ |
| 2731 | |
| 2732 | mss = skb_shinfo(skb)->gso_size; |
| 2733 | |
| 2734 | /* set new MSS value if needed */ |
| 2735 | if (mss != priv->mss) { |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2736 | mss_desc = tx_q->dma_tx + tx_q->cur_tx; |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2737 | priv->hw->desc->set_mss(mss_desc, mss); |
| 2738 | priv->mss = mss; |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2739 | tx_q->cur_tx = STMMAC_GET_ENTRY(tx_q->cur_tx, DMA_TX_SIZE); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2740 | } |
| 2741 | |
| 2742 | if (netif_msg_tx_queued(priv)) { |
| 2743 | pr_info("%s: tcphdrlen %d, hdr_len %d, pay_len %d, mss %d\n", |
| 2744 | __func__, tcp_hdrlen(skb), proto_hdr_len, pay_len, mss); |
| 2745 | pr_info("\tskb->len %d, skb->data_len %d\n", skb->len, |
| 2746 | skb->data_len); |
| 2747 | } |
| 2748 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2749 | first_entry = tx_q->cur_tx; |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2750 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2751 | desc = tx_q->dma_tx + first_entry; |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2752 | first = desc; |
| 2753 | |
| 2754 | /* first descriptor: fill Headers on Buf1 */ |
| 2755 | des = dma_map_single(priv->device, skb->data, skb_headlen(skb), |
| 2756 | DMA_TO_DEVICE); |
| 2757 | if (dma_mapping_error(priv->device, des)) |
| 2758 | goto dma_map_err; |
| 2759 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2760 | tx_q->tx_skbuff_dma[first_entry].buf = des; |
| 2761 | tx_q->tx_skbuff_dma[first_entry].len = skb_headlen(skb); |
| 2762 | tx_q->tx_skbuff[first_entry] = skb; |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2763 | |
Michael Weiser | f8be0d7 | 2016-11-14 18:58:05 +0100 | [diff] [blame] | 2764 | first->des0 = cpu_to_le32(des); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2765 | |
| 2766 | /* Fill start of payload in buff2 of first descriptor */ |
| 2767 | if (pay_len) |
Michael Weiser | f8be0d7 | 2016-11-14 18:58:05 +0100 | [diff] [blame] | 2768 | first->des1 = cpu_to_le32(des + proto_hdr_len); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2769 | |
| 2770 | /* If needed take extra descriptors to fill the remaining payload */ |
| 2771 | tmp_pay_len = pay_len - TSO_MAX_BUFF_SIZE; |
| 2772 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2773 | stmmac_tso_allocator(priv, des, tmp_pay_len, (nfrags == 0), queue); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2774 | |
| 2775 | /* Prepare fragments */ |
| 2776 | for (i = 0; i < nfrags; i++) { |
| 2777 | const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 2778 | |
| 2779 | des = skb_frag_dma_map(priv->device, frag, 0, |
| 2780 | skb_frag_size(frag), |
| 2781 | DMA_TO_DEVICE); |
Thierry Reding | 937071c | 2017-03-10 17:34:57 +0100 | [diff] [blame] | 2782 | if (dma_mapping_error(priv->device, des)) |
| 2783 | goto dma_map_err; |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2784 | |
| 2785 | stmmac_tso_allocator(priv, des, skb_frag_size(frag), |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2786 | (i == nfrags - 1), queue); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2787 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2788 | tx_q->tx_skbuff_dma[tx_q->cur_tx].buf = des; |
| 2789 | tx_q->tx_skbuff_dma[tx_q->cur_tx].len = skb_frag_size(frag); |
| 2790 | tx_q->tx_skbuff[tx_q->cur_tx] = NULL; |
| 2791 | tx_q->tx_skbuff_dma[tx_q->cur_tx].map_as_page = true; |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2792 | } |
| 2793 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2794 | tx_q->tx_skbuff_dma[tx_q->cur_tx].last_segment = true; |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2795 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2796 | tx_q->cur_tx = STMMAC_GET_ENTRY(tx_q->cur_tx, DMA_TX_SIZE); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2797 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2798 | if (unlikely(stmmac_tx_avail(priv, queue) <= (MAX_SKB_FRAGS + 1))) { |
LABBE Corentin | b3e5106 | 2016-11-16 20:09:41 +0100 | [diff] [blame] | 2799 | netif_dbg(priv, hw, priv->dev, "%s: stop transmitted packets\n", |
| 2800 | __func__); |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 2801 | netif_stop_queue(dev); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2802 | } |
| 2803 | |
| 2804 | dev->stats.tx_bytes += skb->len; |
| 2805 | priv->xstats.tx_tso_frames++; |
| 2806 | priv->xstats.tx_tso_nfrags += nfrags; |
| 2807 | |
| 2808 | /* Manage tx mitigation */ |
| 2809 | priv->tx_count_frames += nfrags + 1; |
| 2810 | if (likely(priv->tx_coal_frames > priv->tx_count_frames)) { |
| 2811 | mod_timer(&priv->txtimer, |
| 2812 | STMMAC_COAL_TIMER(priv->tx_coal_timer)); |
| 2813 | } else { |
| 2814 | priv->tx_count_frames = 0; |
| 2815 | priv->hw->desc->set_tx_ic(desc); |
| 2816 | priv->xstats.tx_set_ic_bit++; |
| 2817 | } |
| 2818 | |
| 2819 | if (!priv->hwts_tx_en) |
| 2820 | skb_tx_timestamp(skb); |
| 2821 | |
| 2822 | if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && |
| 2823 | priv->hwts_tx_en)) { |
| 2824 | /* declare that device is doing timestamping */ |
| 2825 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 2826 | priv->hw->desc->enable_tx_timestamp(first); |
| 2827 | } |
| 2828 | |
| 2829 | /* Complete the first descriptor before granting the DMA */ |
| 2830 | priv->hw->desc->prepare_tso_tx_desc(first, 1, |
| 2831 | proto_hdr_len, |
| 2832 | pay_len, |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2833 | 1, tx_q->tx_skbuff_dma[first_entry].last_segment, |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2834 | tcp_hdrlen(skb) / 4, (skb->len - proto_hdr_len)); |
| 2835 | |
| 2836 | /* If context desc is used to change MSS */ |
| 2837 | if (mss_desc) |
| 2838 | priv->hw->desc->set_tx_owner(mss_desc); |
| 2839 | |
| 2840 | /* The own bit must be the latest setting done when prepare the |
| 2841 | * descriptor and then barrier is needed to make sure that |
| 2842 | * all is coherent before granting the DMA engine. |
| 2843 | */ |
Pavel Machek | ad688cd | 2016-12-18 21:38:12 +0100 | [diff] [blame] | 2844 | dma_wmb(); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2845 | |
| 2846 | if (netif_msg_pktdata(priv)) { |
| 2847 | pr_info("%s: curr=%d dirty=%d f=%d, e=%d, f_p=%p, nfrags %d\n", |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2848 | __func__, tx_q->cur_tx, tx_q->dirty_tx, first_entry, |
| 2849 | tx_q->cur_tx, first, nfrags); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2850 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2851 | priv->hw->desc->display_ring((void *)tx_q->dma_tx, DMA_TX_SIZE, |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2852 | 0); |
| 2853 | |
| 2854 | pr_info(">>> frame to be transmitted: "); |
| 2855 | print_pkt(skb->data, skb_headlen(skb)); |
| 2856 | } |
| 2857 | |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 2858 | netdev_sent_queue(dev, skb->len); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2859 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2860 | priv->hw->dma->set_tx_tail_ptr(priv->ioaddr, tx_q->tx_tail_addr, |
| 2861 | queue); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2862 | |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2863 | return NETDEV_TX_OK; |
| 2864 | |
| 2865 | dma_map_err: |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2866 | dev_err(priv->device, "Tx dma map failed\n"); |
| 2867 | dev_kfree_skb(skb); |
| 2868 | priv->dev->stats.tx_dropped++; |
| 2869 | return NETDEV_TX_OK; |
| 2870 | } |
| 2871 | |
| 2872 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 2873 | * stmmac_xmit - Tx entry point of the driver |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2874 | * @skb : the socket buffer |
| 2875 | * @dev : device pointer |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 2876 | * Description : this is the tx entry point of the driver. |
| 2877 | * It programs the chain or the ring and supports oversized frames |
| 2878 | * and SG feature. |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2879 | */ |
| 2880 | static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev) |
| 2881 | { |
| 2882 | struct stmmac_priv *priv = netdev_priv(dev); |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 2883 | unsigned int nopaged_len = skb_headlen(skb); |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 2884 | int i, csum_insertion = 0, is_jumbo = 0; |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2885 | u32 queue = skb_get_queue_mapping(skb); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2886 | int nfrags = skb_shinfo(skb)->nr_frags; |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 2887 | unsigned int entry, first_entry; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2888 | struct dma_desc *desc, *first; |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2889 | struct stmmac_tx_queue *tx_q; |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 2890 | unsigned int enh_desc; |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2891 | unsigned int des; |
| 2892 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2893 | tx_q = &priv->tx_queue[queue]; |
| 2894 | |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2895 | /* Manage oversized TCP frames for GMAC4 device */ |
| 2896 | if (skb_is_gso(skb) && priv->tso) { |
| 2897 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 2898 | return stmmac_tso_xmit(skb, dev); |
| 2899 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2900 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2901 | if (unlikely(stmmac_tx_avail(priv, queue) < nfrags + 1)) { |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 2902 | if (!netif_queue_stopped(dev)) { |
| 2903 | netif_stop_queue(dev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2904 | /* This is a hard error, log it. */ |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 2905 | netdev_err(priv->dev, |
| 2906 | "%s: Tx Ring full when queue awake\n", |
| 2907 | __func__); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2908 | } |
| 2909 | return NETDEV_TX_BUSY; |
| 2910 | } |
| 2911 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 2912 | if (priv->tx_path_in_lpi_mode) |
| 2913 | stmmac_disable_eee_mode(priv); |
| 2914 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2915 | entry = tx_q->cur_tx; |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 2916 | first_entry = entry; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2917 | |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 2918 | csum_insertion = (skb->ip_summed == CHECKSUM_PARTIAL); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2919 | |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 2920 | if (likely(priv->extend_desc)) |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2921 | desc = (struct dma_desc *)(tx_q->dma_etx + entry); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2922 | else |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2923 | desc = tx_q->dma_tx + entry; |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2924 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2925 | first = desc; |
| 2926 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2927 | tx_q->tx_skbuff[first_entry] = skb; |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 2928 | |
| 2929 | enh_desc = priv->plat->enh_desc; |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 2930 | /* To program the descriptors according to the size of the frame */ |
Giuseppe CAVALLARO | 29896a6 | 2014-03-10 13:40:33 +0100 | [diff] [blame] | 2931 | if (enh_desc) |
| 2932 | is_jumbo = priv->hw->mode->is_jumbo_frm(skb->len, enh_desc); |
| 2933 | |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2934 | if (unlikely(is_jumbo) && likely(priv->synopsys_id < |
| 2935 | DWMAC_CORE_4_00)) { |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2936 | entry = priv->hw->mode->jumbo_frm(tx_q, skb, csum_insertion); |
Giuseppe CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 2937 | if (unlikely(entry < 0)) |
| 2938 | goto dma_map_err; |
Giuseppe CAVALLARO | 29896a6 | 2014-03-10 13:40:33 +0100 | [diff] [blame] | 2939 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2940 | |
| 2941 | for (i = 0; i < nfrags; i++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 2942 | const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 2943 | int len = skb_frag_size(frag); |
Giuseppe Cavallaro | be434d5 | 2016-02-29 14:27:35 +0100 | [diff] [blame] | 2944 | bool last_segment = (i == (nfrags - 1)); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2945 | |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 2946 | entry = STMMAC_GET_ENTRY(entry, DMA_TX_SIZE); |
| 2947 | |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 2948 | if (likely(priv->extend_desc)) |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2949 | desc = (struct dma_desc *)(tx_q->dma_etx + entry); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2950 | else |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2951 | desc = tx_q->dma_tx + entry; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2952 | |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2953 | des = skb_frag_dma_map(priv->device, frag, 0, len, |
| 2954 | DMA_TO_DEVICE); |
| 2955 | if (dma_mapping_error(priv->device, des)) |
Giuseppe CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 2956 | goto dma_map_err; /* should reuse desc w/o issues */ |
| 2957 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2958 | tx_q->tx_skbuff[entry] = NULL; |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2959 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2960 | tx_q->tx_skbuff_dma[entry].buf = des; |
Michael Weiser | f8be0d7 | 2016-11-14 18:58:05 +0100 | [diff] [blame] | 2961 | if (unlikely(priv->synopsys_id >= DWMAC_CORE_4_00)) |
| 2962 | desc->des0 = cpu_to_le32(des); |
| 2963 | else |
| 2964 | desc->des2 = cpu_to_le32(des); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 2965 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2966 | tx_q->tx_skbuff_dma[entry].map_as_page = true; |
| 2967 | tx_q->tx_skbuff_dma[entry].len = len; |
| 2968 | tx_q->tx_skbuff_dma[entry].last_segment = last_segment; |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 2969 | |
| 2970 | /* Prepare the descriptor and set the own bit too */ |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 2971 | priv->hw->desc->prepare_tx_desc(desc, 0, len, csum_insertion, |
Giuseppe Cavallaro | be434d5 | 2016-02-29 14:27:35 +0100 | [diff] [blame] | 2972 | priv->mode, 1, last_segment); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2973 | } |
| 2974 | |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 2975 | entry = STMMAC_GET_ENTRY(entry, DMA_TX_SIZE); |
| 2976 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2977 | tx_q->cur_tx = entry; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2978 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2979 | if (netif_msg_pktdata(priv)) { |
Alexandre TORGUE | d0225e7 | 2016-04-01 11:37:26 +0200 | [diff] [blame] | 2980 | void *tx_head; |
| 2981 | |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 2982 | netdev_dbg(priv->dev, |
| 2983 | "%s: curr=%d dirty=%d f=%d, e=%d, first=%p, nfrags=%d", |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2984 | __func__, tx_q->cur_tx, tx_q->dirty_tx, first_entry, |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 2985 | entry, first, nfrags); |
Giuseppe CAVALLARO | 83d7af6 | 2013-07-02 14:12:36 +0200 | [diff] [blame] | 2986 | |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2987 | if (priv->extend_desc) |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2988 | tx_head = (void *)tx_q->dma_etx; |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2989 | else |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2990 | tx_head = (void *)tx_q->dma_tx; |
Alexandre TORGUE | d0225e7 | 2016-04-01 11:37:26 +0200 | [diff] [blame] | 2991 | |
| 2992 | priv->hw->desc->display_ring(tx_head, DMA_TX_SIZE, false); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2993 | |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 2994 | netdev_dbg(priv->dev, ">>> frame to be transmitted: "); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2995 | print_pkt(skb->data, skb->len); |
| 2996 | } |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 2997 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 2998 | if (unlikely(stmmac_tx_avail(priv, queue) <= (MAX_SKB_FRAGS + 1))) { |
LABBE Corentin | b3e5106 | 2016-11-16 20:09:41 +0100 | [diff] [blame] | 2999 | netif_dbg(priv, hw, priv->dev, "%s: stop transmitted packets\n", |
| 3000 | __func__); |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 3001 | netif_stop_queue(dev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3002 | } |
| 3003 | |
| 3004 | dev->stats.tx_bytes += skb->len; |
| 3005 | |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 3006 | /* According to the coalesce parameter the IC bit for the latest |
| 3007 | * segment is reset and the timer re-started to clean the tx status. |
| 3008 | * This approach takes care about the fragments: desc is the first |
| 3009 | * element in case of no SG. |
| 3010 | */ |
| 3011 | priv->tx_count_frames += nfrags + 1; |
| 3012 | if (likely(priv->tx_coal_frames > priv->tx_count_frames)) { |
| 3013 | mod_timer(&priv->txtimer, |
| 3014 | STMMAC_COAL_TIMER(priv->tx_coal_timer)); |
| 3015 | } else { |
| 3016 | priv->tx_count_frames = 0; |
| 3017 | priv->hw->desc->set_tx_ic(desc); |
| 3018 | priv->xstats.tx_set_ic_bit++; |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 3019 | } |
| 3020 | |
| 3021 | if (!priv->hwts_tx_en) |
| 3022 | skb_tx_timestamp(skb); |
Richard Cochran | 3e82ce1 | 2011-06-12 02:19:06 +0000 | [diff] [blame] | 3023 | |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 3024 | /* Ready to fill the first descriptor and set the OWN bit w/o any |
| 3025 | * problems because all the descriptors are actually ready to be |
| 3026 | * passed to the DMA engine. |
| 3027 | */ |
| 3028 | if (likely(!is_jumbo)) { |
| 3029 | bool last_segment = (nfrags == 0); |
| 3030 | |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 3031 | des = dma_map_single(priv->device, skb->data, |
| 3032 | nopaged_len, DMA_TO_DEVICE); |
| 3033 | if (dma_mapping_error(priv->device, des)) |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 3034 | goto dma_map_err; |
| 3035 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 3036 | tx_q->tx_skbuff_dma[first_entry].buf = des; |
Michael Weiser | f8be0d7 | 2016-11-14 18:58:05 +0100 | [diff] [blame] | 3037 | if (unlikely(priv->synopsys_id >= DWMAC_CORE_4_00)) |
| 3038 | first->des0 = cpu_to_le32(des); |
| 3039 | else |
| 3040 | first->des2 = cpu_to_le32(des); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 3041 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 3042 | tx_q->tx_skbuff_dma[first_entry].len = nopaged_len; |
| 3043 | tx_q->tx_skbuff_dma[first_entry].last_segment = last_segment; |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 3044 | |
| 3045 | if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && |
| 3046 | priv->hwts_tx_en)) { |
| 3047 | /* declare that device is doing timestamping */ |
| 3048 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 3049 | priv->hw->desc->enable_tx_timestamp(first); |
| 3050 | } |
| 3051 | |
| 3052 | /* Prepare the first descriptor setting the OWN bit too */ |
| 3053 | priv->hw->desc->prepare_tx_desc(first, 1, nopaged_len, |
| 3054 | csum_insertion, priv->mode, 1, |
| 3055 | last_segment); |
| 3056 | |
| 3057 | /* The own bit must be the latest setting done when prepare the |
| 3058 | * descriptor and then barrier is needed to make sure that |
| 3059 | * all is coherent before granting the DMA engine. |
| 3060 | */ |
Pavel Machek | ad688cd | 2016-12-18 21:38:12 +0100 | [diff] [blame] | 3061 | dma_wmb(); |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 3062 | } |
| 3063 | |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 3064 | netdev_sent_queue(dev, skb->len); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 3065 | |
| 3066 | if (priv->synopsys_id < DWMAC_CORE_4_00) |
| 3067 | priv->hw->dma->enable_dma_transmission(priv->ioaddr); |
| 3068 | else |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 3069 | priv->hw->dma->set_tx_tail_ptr(priv->ioaddr, tx_q->tx_tail_addr, |
| 3070 | queue); |
Richard Cochran | 52f64fa | 2011-06-19 03:31:43 +0000 | [diff] [blame] | 3071 | |
Giuseppe CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 3072 | return NETDEV_TX_OK; |
Giuseppe CAVALLARO | a9097a9 | 2011-10-18 00:01:19 +0000 | [diff] [blame] | 3073 | |
Giuseppe CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 3074 | dma_map_err: |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 3075 | netdev_err(priv->dev, "Tx DMA map failed\n"); |
Giuseppe CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 3076 | dev_kfree_skb(skb); |
| 3077 | priv->dev->stats.tx_dropped++; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3078 | return NETDEV_TX_OK; |
| 3079 | } |
| 3080 | |
Vince Bridgers | b938198 | 2014-01-14 13:42:05 -0600 | [diff] [blame] | 3081 | static void stmmac_rx_vlan(struct net_device *dev, struct sk_buff *skb) |
| 3082 | { |
| 3083 | struct ethhdr *ehdr; |
| 3084 | u16 vlanid; |
| 3085 | |
| 3086 | if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) == |
| 3087 | NETIF_F_HW_VLAN_CTAG_RX && |
| 3088 | !__vlan_get_tag(skb, &vlanid)) { |
| 3089 | /* pop the vlan tag */ |
| 3090 | ehdr = (struct ethhdr *)skb->data; |
| 3091 | memmove(skb->data + VLAN_HLEN, ehdr, ETH_ALEN * 2); |
| 3092 | skb_pull(skb, VLAN_HLEN); |
| 3093 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlanid); |
| 3094 | } |
| 3095 | } |
| 3096 | |
| 3097 | |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3098 | static inline int stmmac_rx_threshold_count(struct stmmac_rx_queue *rx_q) |
Giuseppe Cavallaro | 120e87f | 2016-02-29 14:27:42 +0100 | [diff] [blame] | 3099 | { |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3100 | if (rx_q->rx_zeroc_thresh < STMMAC_RX_THRESH) |
Giuseppe Cavallaro | 120e87f | 2016-02-29 14:27:42 +0100 | [diff] [blame] | 3101 | return 0; |
| 3102 | |
| 3103 | return 1; |
| 3104 | } |
| 3105 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 3106 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 3107 | * stmmac_rx_refill - refill used skb preallocated buffers |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 3108 | * @priv: driver private structure |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3109 | * @queue: RX queue index |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 3110 | * Description : this is to reallocate the skb for the reception process |
| 3111 | * that is based on zero-copy. |
| 3112 | */ |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3113 | static inline void stmmac_rx_refill(struct stmmac_priv *priv, u32 queue) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3114 | { |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3115 | struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue]; |
| 3116 | int dirty = stmmac_rx_dirty(priv, queue); |
| 3117 | unsigned int entry = rx_q->dirty_rx; |
| 3118 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3119 | int bfsize = priv->dma_buf_sz; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3120 | |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 3121 | while (dirty-- > 0) { |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 3122 | struct dma_desc *p; |
| 3123 | |
| 3124 | if (priv->extend_desc) |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3125 | p = (struct dma_desc *)(rx_q->dma_erx + entry); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 3126 | else |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3127 | p = rx_q->dma_rx + entry; |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 3128 | |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3129 | if (likely(!rx_q->rx_skbuff[entry])) { |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3130 | struct sk_buff *skb; |
| 3131 | |
Eric Dumazet | acb600d | 2012-10-05 06:23:55 +0000 | [diff] [blame] | 3132 | skb = netdev_alloc_skb_ip_align(priv->dev, bfsize); |
Giuseppe Cavallaro | 120e87f | 2016-02-29 14:27:42 +0100 | [diff] [blame] | 3133 | if (unlikely(!skb)) { |
| 3134 | /* so for a while no zero-copy! */ |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3135 | rx_q->rx_zeroc_thresh = STMMAC_RX_THRESH; |
Giuseppe Cavallaro | 120e87f | 2016-02-29 14:27:42 +0100 | [diff] [blame] | 3136 | if (unlikely(net_ratelimit())) |
| 3137 | dev_err(priv->device, |
| 3138 | "fail to alloc skb entry %d\n", |
| 3139 | entry); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3140 | break; |
Giuseppe Cavallaro | 120e87f | 2016-02-29 14:27:42 +0100 | [diff] [blame] | 3141 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3142 | |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3143 | rx_q->rx_skbuff[entry] = skb; |
| 3144 | rx_q->rx_skbuff_dma[entry] = |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3145 | dma_map_single(priv->device, skb->data, bfsize, |
| 3146 | DMA_FROM_DEVICE); |
Giuseppe CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 3147 | if (dma_mapping_error(priv->device, |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3148 | rx_q->rx_skbuff_dma[entry])) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 3149 | netdev_err(priv->dev, "Rx DMA map failed\n"); |
Giuseppe CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 3150 | dev_kfree_skb(skb); |
| 3151 | break; |
| 3152 | } |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 3153 | |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 3154 | if (unlikely(priv->synopsys_id >= DWMAC_CORE_4_00)) { |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3155 | p->des0 = cpu_to_le32(rx_q->rx_skbuff_dma[entry]); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 3156 | p->des1 = 0; |
| 3157 | } else { |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3158 | p->des2 = cpu_to_le32(rx_q->rx_skbuff_dma[entry]); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 3159 | } |
| 3160 | if (priv->hw->mode->refill_desc3) |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3161 | priv->hw->mode->refill_desc3(rx_q, p); |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 3162 | |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3163 | if (rx_q->rx_zeroc_thresh > 0) |
| 3164 | rx_q->rx_zeroc_thresh--; |
Giuseppe Cavallaro | 120e87f | 2016-02-29 14:27:42 +0100 | [diff] [blame] | 3165 | |
LABBE Corentin | b3e5106 | 2016-11-16 20:09:41 +0100 | [diff] [blame] | 3166 | netif_dbg(priv, rx_status, priv->dev, |
| 3167 | "refill entry #%d\n", entry); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3168 | } |
Pavel Machek | ad688cd | 2016-12-18 21:38:12 +0100 | [diff] [blame] | 3169 | dma_wmb(); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 3170 | |
| 3171 | if (unlikely(priv->synopsys_id >= DWMAC_CORE_4_00)) |
| 3172 | priv->hw->desc->init_rx_desc(p, priv->use_riwt, 0, 0); |
| 3173 | else |
| 3174 | priv->hw->desc->set_rx_owner(p); |
| 3175 | |
Pavel Machek | ad688cd | 2016-12-18 21:38:12 +0100 | [diff] [blame] | 3176 | dma_wmb(); |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 3177 | |
| 3178 | entry = STMMAC_GET_ENTRY(entry, DMA_RX_SIZE); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3179 | } |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3180 | rx_q->dirty_rx = entry; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3181 | } |
| 3182 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 3183 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 3184 | * stmmac_rx - manage the receive process |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 3185 | * @priv: driver private structure |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3186 | * @limit: napi bugget |
| 3187 | * @queue: RX queue index. |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 3188 | * Description : this the function called by the napi poll method. |
| 3189 | * It gets all the frames inside the ring. |
| 3190 | */ |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3191 | static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3192 | { |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3193 | struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue]; |
| 3194 | unsigned int entry = rx_q->cur_rx; |
| 3195 | int coe = priv->hw->rx_csum; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3196 | unsigned int next_entry; |
| 3197 | unsigned int count = 0; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3198 | |
Giuseppe CAVALLARO | 83d7af6 | 2013-07-02 14:12:36 +0200 | [diff] [blame] | 3199 | if (netif_msg_rx_status(priv)) { |
Alexandre TORGUE | d0225e7 | 2016-04-01 11:37:26 +0200 | [diff] [blame] | 3200 | void *rx_head; |
| 3201 | |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 3202 | netdev_dbg(priv->dev, "%s: descriptor ring:\n", __func__); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 3203 | if (priv->extend_desc) |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3204 | rx_head = (void *)rx_q->dma_erx; |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 3205 | else |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3206 | rx_head = (void *)rx_q->dma_rx; |
Alexandre TORGUE | d0225e7 | 2016-04-01 11:37:26 +0200 | [diff] [blame] | 3207 | |
| 3208 | priv->hw->desc->display_ring(rx_head, DMA_RX_SIZE, true); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3209 | } |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 3210 | while (count < limit) { |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3211 | int status; |
Giuseppe CAVALLARO | 9401bb5 | 2013-04-08 02:10:03 +0000 | [diff] [blame] | 3212 | struct dma_desc *p; |
Giuseppe CAVALLARO | ba1ffd7 | 2016-11-14 09:27:29 +0100 | [diff] [blame] | 3213 | struct dma_desc *np; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3214 | |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 3215 | if (priv->extend_desc) |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3216 | p = (struct dma_desc *)(rx_q->dma_erx + entry); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 3217 | else |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3218 | p = rx_q->dma_rx + entry; |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 3219 | |
Fabrice Gasnier | c1fa321 | 2016-02-29 14:27:34 +0100 | [diff] [blame] | 3220 | /* read the status of the incoming frame */ |
| 3221 | status = priv->hw->desc->rx_status(&priv->dev->stats, |
| 3222 | &priv->xstats, p); |
| 3223 | /* check if managed by the DMA otherwise go ahead */ |
| 3224 | if (unlikely(status & dma_own)) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3225 | break; |
| 3226 | |
| 3227 | count++; |
| 3228 | |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3229 | rx_q->cur_rx = STMMAC_GET_ENTRY(rx_q->cur_rx, DMA_RX_SIZE); |
| 3230 | next_entry = rx_q->cur_rx; |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 3231 | |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 3232 | if (priv->extend_desc) |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3233 | np = (struct dma_desc *)(rx_q->dma_erx + next_entry); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 3234 | else |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3235 | np = rx_q->dma_rx + next_entry; |
Giuseppe CAVALLARO | ba1ffd7 | 2016-11-14 09:27:29 +0100 | [diff] [blame] | 3236 | |
| 3237 | prefetch(np); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3238 | |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 3239 | if ((priv->extend_desc) && (priv->hw->desc->rx_extended_status)) |
| 3240 | priv->hw->desc->rx_extended_status(&priv->dev->stats, |
| 3241 | &priv->xstats, |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3242 | rx_q->dma_erx + |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 3243 | entry); |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 3244 | if (unlikely(status == discard_frame)) { |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3245 | priv->dev->stats.rx_errors++; |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 3246 | if (priv->hwts_rx_en && !priv->extend_desc) { |
LABBE Corentin | 8d45e42 | 2017-02-08 09:31:08 +0100 | [diff] [blame] | 3247 | /* DESC2 & DESC3 will be overwritten by device |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 3248 | * with timestamp value, hence reinitialize |
| 3249 | * them in stmmac_rx_refill() function so that |
| 3250 | * device can reuse it. |
| 3251 | */ |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3252 | rx_q->rx_skbuff[entry] = NULL; |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 3253 | dma_unmap_single(priv->device, |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3254 | rx_q->rx_skbuff_dma[entry], |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 3255 | priv->dma_buf_sz, |
| 3256 | DMA_FROM_DEVICE); |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 3257 | } |
| 3258 | } else { |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3259 | struct sk_buff *skb; |
Giuseppe CAVALLARO | 3eeb299 | 2010-07-27 00:09:47 +0000 | [diff] [blame] | 3260 | int frame_len; |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 3261 | unsigned int des; |
| 3262 | |
| 3263 | if (unlikely(priv->synopsys_id >= DWMAC_CORE_4_00)) |
Michael Weiser | f8be0d7 | 2016-11-14 18:58:05 +0100 | [diff] [blame] | 3264 | des = le32_to_cpu(p->des0); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 3265 | else |
Michael Weiser | f8be0d7 | 2016-11-14 18:58:05 +0100 | [diff] [blame] | 3266 | des = le32_to_cpu(p->des2); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3267 | |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 3268 | frame_len = priv->hw->desc->get_rx_frame_len(p, coe); |
| 3269 | |
LABBE Corentin | 8d45e42 | 2017-02-08 09:31:08 +0100 | [diff] [blame] | 3270 | /* If frame length is greater than skb buffer size |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 3271 | * (preallocated during init) then the packet is |
| 3272 | * ignored |
| 3273 | */ |
Giuseppe CAVALLARO | e527c4a | 2015-11-26 08:35:45 +0100 | [diff] [blame] | 3274 | if (frame_len > priv->dma_buf_sz) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 3275 | netdev_err(priv->dev, |
| 3276 | "len %d larger than size (%d)\n", |
| 3277 | frame_len, priv->dma_buf_sz); |
Giuseppe CAVALLARO | e527c4a | 2015-11-26 08:35:45 +0100 | [diff] [blame] | 3278 | priv->dev->stats.rx_length_errors++; |
| 3279 | break; |
| 3280 | } |
| 3281 | |
Giuseppe CAVALLARO | 3eeb299 | 2010-07-27 00:09:47 +0000 | [diff] [blame] | 3282 | /* ACS is set; GMAC core strips PAD/FCS for IEEE 802.3 |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 3283 | * Type frames (LLC/LLC-SNAP) |
| 3284 | */ |
Giuseppe CAVALLARO | 3eeb299 | 2010-07-27 00:09:47 +0000 | [diff] [blame] | 3285 | if (unlikely(status != llc_snap)) |
| 3286 | frame_len -= ETH_FCS_LEN; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3287 | |
Giuseppe CAVALLARO | 83d7af6 | 2013-07-02 14:12:36 +0200 | [diff] [blame] | 3288 | if (netif_msg_rx_status(priv)) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 3289 | netdev_dbg(priv->dev, "\tdesc: %p [entry %d] buff=0x%x\n", |
| 3290 | p, entry, des); |
Giuseppe CAVALLARO | 83d7af6 | 2013-07-02 14:12:36 +0200 | [diff] [blame] | 3291 | if (frame_len > ETH_FRAME_LEN) |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 3292 | netdev_dbg(priv->dev, "frame size %d, COE: %d\n", |
| 3293 | frame_len, status); |
Giuseppe CAVALLARO | 83d7af6 | 2013-07-02 14:12:36 +0200 | [diff] [blame] | 3294 | } |
Giuseppe Cavallaro | 22ad383 | 2016-02-29 14:27:41 +0100 | [diff] [blame] | 3295 | |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 3296 | /* The zero-copy is always used for all the sizes |
| 3297 | * in case of GMAC4 because it needs |
| 3298 | * to refill the used descriptors, always. |
| 3299 | */ |
| 3300 | if (unlikely(!priv->plat->has_gmac4 && |
| 3301 | ((frame_len < priv->rx_copybreak) || |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3302 | stmmac_rx_threshold_count(rx_q)))) { |
Giuseppe Cavallaro | 22ad383 | 2016-02-29 14:27:41 +0100 | [diff] [blame] | 3303 | skb = netdev_alloc_skb_ip_align(priv->dev, |
| 3304 | frame_len); |
| 3305 | if (unlikely(!skb)) { |
| 3306 | if (net_ratelimit()) |
| 3307 | dev_warn(priv->device, |
| 3308 | "packet dropped\n"); |
| 3309 | priv->dev->stats.rx_dropped++; |
| 3310 | break; |
| 3311 | } |
| 3312 | |
| 3313 | dma_sync_single_for_cpu(priv->device, |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3314 | rx_q->rx_skbuff_dma |
Giuseppe Cavallaro | 22ad383 | 2016-02-29 14:27:41 +0100 | [diff] [blame] | 3315 | [entry], frame_len, |
| 3316 | DMA_FROM_DEVICE); |
| 3317 | skb_copy_to_linear_data(skb, |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3318 | rx_q-> |
Giuseppe Cavallaro | 22ad383 | 2016-02-29 14:27:41 +0100 | [diff] [blame] | 3319 | rx_skbuff[entry]->data, |
| 3320 | frame_len); |
| 3321 | |
| 3322 | skb_put(skb, frame_len); |
| 3323 | dma_sync_single_for_device(priv->device, |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3324 | rx_q->rx_skbuff_dma |
Giuseppe Cavallaro | 22ad383 | 2016-02-29 14:27:41 +0100 | [diff] [blame] | 3325 | [entry], frame_len, |
| 3326 | DMA_FROM_DEVICE); |
| 3327 | } else { |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3328 | skb = rx_q->rx_skbuff[entry]; |
Giuseppe Cavallaro | 22ad383 | 2016-02-29 14:27:41 +0100 | [diff] [blame] | 3329 | if (unlikely(!skb)) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 3330 | netdev_err(priv->dev, |
| 3331 | "%s: Inconsistent Rx chain\n", |
| 3332 | priv->dev->name); |
Giuseppe Cavallaro | 22ad383 | 2016-02-29 14:27:41 +0100 | [diff] [blame] | 3333 | priv->dev->stats.rx_dropped++; |
| 3334 | break; |
| 3335 | } |
| 3336 | prefetch(skb->data - NET_IP_ALIGN); |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3337 | rx_q->rx_skbuff[entry] = NULL; |
| 3338 | rx_q->rx_zeroc_thresh++; |
Giuseppe Cavallaro | 22ad383 | 2016-02-29 14:27:41 +0100 | [diff] [blame] | 3339 | |
| 3340 | skb_put(skb, frame_len); |
| 3341 | dma_unmap_single(priv->device, |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3342 | rx_q->rx_skbuff_dma[entry], |
Giuseppe Cavallaro | 22ad383 | 2016-02-29 14:27:41 +0100 | [diff] [blame] | 3343 | priv->dma_buf_sz, |
| 3344 | DMA_FROM_DEVICE); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3345 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3346 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3347 | if (netif_msg_pktdata(priv)) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 3348 | netdev_dbg(priv->dev, "frame received (%dbytes)", |
| 3349 | frame_len); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3350 | print_pkt(skb->data, frame_len); |
| 3351 | } |
Giuseppe CAVALLARO | 83d7af6 | 2013-07-02 14:12:36 +0200 | [diff] [blame] | 3352 | |
Giuseppe CAVALLARO | ba1ffd7 | 2016-11-14 09:27:29 +0100 | [diff] [blame] | 3353 | stmmac_get_rx_hwtstamp(priv, p, np, skb); |
| 3354 | |
Vince Bridgers | b938198 | 2014-01-14 13:42:05 -0600 | [diff] [blame] | 3355 | stmmac_rx_vlan(priv->dev, skb); |
| 3356 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3357 | skb->protocol = eth_type_trans(skb, priv->dev); |
| 3358 | |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 3359 | if (unlikely(!coe)) |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 3360 | skb_checksum_none_assert(skb); |
Giuseppe CAVALLARO | 62a2ab9 | 2012-11-25 23:10:43 +0000 | [diff] [blame] | 3361 | else |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3362 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Giuseppe CAVALLARO | 62a2ab9 | 2012-11-25 23:10:43 +0000 | [diff] [blame] | 3363 | |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 3364 | napi_gro_receive(&priv->napi, skb); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3365 | |
| 3366 | priv->dev->stats.rx_packets++; |
| 3367 | priv->dev->stats.rx_bytes += frame_len; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3368 | } |
| 3369 | entry = next_entry; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3370 | } |
| 3371 | |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3372 | stmmac_rx_refill(priv, queue); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3373 | |
| 3374 | priv->xstats.rx_pkt_n += count; |
| 3375 | |
| 3376 | return count; |
| 3377 | } |
| 3378 | |
| 3379 | /** |
| 3380 | * stmmac_poll - stmmac poll method (NAPI) |
| 3381 | * @napi : pointer to the napi structure. |
| 3382 | * @budget : maximum number of packets that the current CPU can receive from |
| 3383 | * all interfaces. |
| 3384 | * Description : |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 3385 | * To look at the incoming frames and clear the tx resources. |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3386 | */ |
| 3387 | static int stmmac_poll(struct napi_struct *napi, int budget) |
| 3388 | { |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 3389 | struct stmmac_priv *priv = container_of(napi, struct stmmac_priv, napi); |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 3390 | u32 tx_count = priv->plat->tx_queues_to_use; |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 3391 | u32 chan = STMMAC_CHAN0; |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3392 | int work_done = 0; |
| 3393 | u32 queue = chan; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3394 | |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 3395 | priv->xstats.napi_poll++; |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 3396 | |
| 3397 | /* check all the queues */ |
| 3398 | for (queue = 0; queue < tx_count; queue++) |
| 3399 | stmmac_tx_clean(priv, queue); |
| 3400 | |
| 3401 | queue = chan; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3402 | |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3403 | work_done = stmmac_rx(priv, budget, queue); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3404 | if (work_done < budget) { |
Eric Dumazet | 6ad2016 | 2017-01-30 08:22:01 -0800 | [diff] [blame] | 3405 | napi_complete_done(napi, work_done); |
Joao Pinto | 4f513ec | 2017-03-15 11:04:46 +0000 | [diff] [blame] | 3406 | stmmac_enable_dma_irq(priv, chan); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3407 | } |
| 3408 | return work_done; |
| 3409 | } |
| 3410 | |
| 3411 | /** |
| 3412 | * stmmac_tx_timeout |
| 3413 | * @dev : Pointer to net device structure |
| 3414 | * Description: this function is called when a packet transmission fails to |
Giuseppe CAVALLARO | 7284a3f | 2012-11-25 23:10:41 +0000 | [diff] [blame] | 3415 | * complete within a reasonable time. The driver will mark the error in the |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3416 | * netdev structure and arrange for the device to be reset to a sane state |
| 3417 | * in order to transmit a new packet. |
| 3418 | */ |
| 3419 | static void stmmac_tx_timeout(struct net_device *dev) |
| 3420 | { |
| 3421 | struct stmmac_priv *priv = netdev_priv(dev); |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 3422 | u32 tx_count = priv->plat->tx_queues_to_use; |
| 3423 | u32 chan; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3424 | |
| 3425 | /* Clear Tx resources and restart transmitting again */ |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 3426 | for (chan = 0; chan < tx_count; chan++) |
| 3427 | stmmac_tx_err(priv, chan); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3428 | } |
| 3429 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3430 | /** |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 3431 | * stmmac_set_rx_mode - entry point for multicast addressing |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3432 | * @dev : pointer to the device structure |
| 3433 | * Description: |
| 3434 | * This function is a driver entry point which gets called by the kernel |
| 3435 | * whenever multicast addresses must be enabled/disabled. |
| 3436 | * Return value: |
| 3437 | * void. |
| 3438 | */ |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 3439 | static void stmmac_set_rx_mode(struct net_device *dev) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3440 | { |
| 3441 | struct stmmac_priv *priv = netdev_priv(dev); |
| 3442 | |
Vince Bridgers | 3b57de9 | 2014-07-31 15:49:17 -0500 | [diff] [blame] | 3443 | priv->hw->mac->set_filter(priv->hw, dev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3444 | } |
| 3445 | |
| 3446 | /** |
| 3447 | * stmmac_change_mtu - entry point to change MTU size for the device. |
| 3448 | * @dev : device pointer. |
| 3449 | * @new_mtu : the new MTU size for the device. |
| 3450 | * Description: the Maximum Transfer Unit (MTU) is used by the network layer |
| 3451 | * to drive packet transmission. Ethernet has an MTU of 1500 octets |
| 3452 | * (ETH_DATA_LEN). This value can be changed with ifconfig. |
| 3453 | * Return value: |
| 3454 | * 0 on success and an appropriate (-)ve integer as defined in errno.h |
| 3455 | * file on failure. |
| 3456 | */ |
| 3457 | static int stmmac_change_mtu(struct net_device *dev, int new_mtu) |
| 3458 | { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 3459 | struct stmmac_priv *priv = netdev_priv(dev); |
| 3460 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3461 | if (netif_running(dev)) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 3462 | netdev_err(priv->dev, "must be stopped to change its MTU\n"); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3463 | return -EBUSY; |
| 3464 | } |
| 3465 | |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 3466 | dev->mtu = new_mtu; |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 3467 | |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 3468 | netdev_update_features(dev); |
| 3469 | |
| 3470 | return 0; |
| 3471 | } |
| 3472 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 3473 | static netdev_features_t stmmac_fix_features(struct net_device *dev, |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 3474 | netdev_features_t features) |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 3475 | { |
| 3476 | struct stmmac_priv *priv = netdev_priv(dev); |
| 3477 | |
Deepak SIKRI | 38912bd | 2012-04-04 04:33:21 +0000 | [diff] [blame] | 3478 | if (priv->plat->rx_coe == STMMAC_RX_COE_NONE) |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 3479 | features &= ~NETIF_F_RXCSUM; |
Giuseppe CAVALLARO | d2afb5b | 2014-09-01 09:17:52 +0200 | [diff] [blame] | 3480 | |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 3481 | if (!priv->plat->tx_coe) |
Tom Herbert | a188222 | 2015-12-14 11:19:43 -0800 | [diff] [blame] | 3482 | features &= ~NETIF_F_CSUM_MASK; |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 3483 | |
Giuseppe CAVALLARO | ebbb293 | 2010-09-17 03:23:40 +0000 | [diff] [blame] | 3484 | /* Some GMAC devices have a bugged Jumbo frame support that |
| 3485 | * needs to have the Tx COE disabled for oversized frames |
| 3486 | * (due to limited buffer sizes). In this case we disable |
LABBE Corentin | 8d45e42 | 2017-02-08 09:31:08 +0100 | [diff] [blame] | 3487 | * the TX csum insertion in the TDES and not use SF. |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 3488 | */ |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 3489 | if (priv->plat->bugged_jumbo && (dev->mtu > ETH_DATA_LEN)) |
Tom Herbert | a188222 | 2015-12-14 11:19:43 -0800 | [diff] [blame] | 3490 | features &= ~NETIF_F_CSUM_MASK; |
Giuseppe CAVALLARO | ebbb293 | 2010-09-17 03:23:40 +0000 | [diff] [blame] | 3491 | |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 3492 | /* Disable tso if asked by ethtool */ |
| 3493 | if ((priv->plat->tso_en) && (priv->dma_cap.tsoen)) { |
| 3494 | if (features & NETIF_F_TSO) |
| 3495 | priv->tso = true; |
| 3496 | else |
| 3497 | priv->tso = false; |
| 3498 | } |
| 3499 | |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 3500 | return features; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3501 | } |
| 3502 | |
Giuseppe CAVALLARO | d2afb5b | 2014-09-01 09:17:52 +0200 | [diff] [blame] | 3503 | static int stmmac_set_features(struct net_device *netdev, |
| 3504 | netdev_features_t features) |
| 3505 | { |
| 3506 | struct stmmac_priv *priv = netdev_priv(netdev); |
| 3507 | |
| 3508 | /* Keep the COE Type in case of csum is supporting */ |
| 3509 | if (features & NETIF_F_RXCSUM) |
| 3510 | priv->hw->rx_csum = priv->plat->rx_coe; |
| 3511 | else |
| 3512 | priv->hw->rx_csum = 0; |
| 3513 | /* No check needed because rx_coe has been set before and it will be |
| 3514 | * fixed in case of issue. |
| 3515 | */ |
| 3516 | priv->hw->mac->rx_ipc(priv->hw); |
| 3517 | |
| 3518 | return 0; |
| 3519 | } |
| 3520 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 3521 | /** |
| 3522 | * stmmac_interrupt - main ISR |
| 3523 | * @irq: interrupt number. |
| 3524 | * @dev_id: to pass the net device pointer. |
| 3525 | * Description: this is the main driver interrupt service routine. |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 3526 | * It can call: |
| 3527 | * o DMA service routine (to manage incoming frame reception and transmission |
| 3528 | * status) |
| 3529 | * o Core interrupts to manage: remote wake-up, management counter, LPI |
| 3530 | * interrupts. |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 3531 | */ |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3532 | static irqreturn_t stmmac_interrupt(int irq, void *dev_id) |
| 3533 | { |
| 3534 | struct net_device *dev = (struct net_device *)dev_id; |
| 3535 | struct stmmac_priv *priv = netdev_priv(dev); |
Joao Pinto | 7bac4e1 | 2017-03-15 11:04:55 +0000 | [diff] [blame] | 3536 | u32 rx_cnt = priv->plat->rx_queues_to_use; |
| 3537 | u32 tx_cnt = priv->plat->tx_queues_to_use; |
| 3538 | u32 queues_count; |
| 3539 | u32 queue; |
| 3540 | |
| 3541 | queues_count = (rx_cnt > tx_cnt) ? rx_cnt : tx_cnt; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3542 | |
Srinivas Kandagatla | 89f7f2c | 2014-01-16 10:53:00 +0000 | [diff] [blame] | 3543 | if (priv->irq_wake) |
| 3544 | pm_wakeup_event(priv->device, 0); |
| 3545 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3546 | if (unlikely(!dev)) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 3547 | netdev_err(priv->dev, "%s: invalid dev pointer\n", __func__); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3548 | return IRQ_NONE; |
| 3549 | } |
| 3550 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 3551 | /* To handle GMAC own interrupts */ |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 3552 | if ((priv->plat->has_gmac) || (priv->plat->has_gmac4)) { |
Vince Bridgers | 7ed24bb | 2014-07-31 15:49:13 -0500 | [diff] [blame] | 3553 | int status = priv->hw->mac->host_irq_status(priv->hw, |
Giuseppe CAVALLARO | 0982a0f | 2013-03-26 04:43:07 +0000 | [diff] [blame] | 3554 | &priv->xstats); |
Joao Pinto | 8f71a88 | 2017-03-10 18:24:57 +0000 | [diff] [blame] | 3555 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 3556 | if (unlikely(status)) { |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 3557 | /* For LPI we need to save the tx status */ |
Giuseppe CAVALLARO | 0982a0f | 2013-03-26 04:43:07 +0000 | [diff] [blame] | 3558 | if (status & CORE_IRQ_TX_PATH_IN_LPI_MODE) |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 3559 | priv->tx_path_in_lpi_mode = true; |
Giuseppe CAVALLARO | 0982a0f | 2013-03-26 04:43:07 +0000 | [diff] [blame] | 3560 | if (status & CORE_IRQ_TX_PATH_EXIT_LPI_MODE) |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 3561 | priv->tx_path_in_lpi_mode = false; |
Joao Pinto | 7bac4e1 | 2017-03-15 11:04:55 +0000 | [diff] [blame] | 3562 | } |
| 3563 | |
| 3564 | if (priv->synopsys_id >= DWMAC_CORE_4_00) { |
| 3565 | for (queue = 0; queue < queues_count; queue++) { |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3566 | struct stmmac_rx_queue *rx_q = |
| 3567 | &priv->rx_queue[queue]; |
| 3568 | |
Joao Pinto | 7bac4e1 | 2017-03-15 11:04:55 +0000 | [diff] [blame] | 3569 | status |= |
| 3570 | priv->hw->mac->host_mtl_irq_status(priv->hw, |
| 3571 | queue); |
| 3572 | |
| 3573 | if (status & CORE_IRQ_MTL_RX_OVERFLOW && |
| 3574 | priv->hw->dma->set_rx_tail_ptr) |
| 3575 | priv->hw->dma->set_rx_tail_ptr(priv->ioaddr, |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3576 | rx_q->rx_tail_addr, |
Joao Pinto | 7bac4e1 | 2017-03-15 11:04:55 +0000 | [diff] [blame] | 3577 | queue); |
| 3578 | } |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 3579 | } |
Giuseppe CAVALLARO | 70523e63 | 2016-06-24 15:16:24 +0200 | [diff] [blame] | 3580 | |
| 3581 | /* PCS link status */ |
Giuseppe CAVALLARO | 3fe5cad | 2016-06-24 15:16:25 +0200 | [diff] [blame] | 3582 | if (priv->hw->pcs) { |
Giuseppe CAVALLARO | 70523e63 | 2016-06-24 15:16:24 +0200 | [diff] [blame] | 3583 | if (priv->xstats.pcs_link) |
| 3584 | netif_carrier_on(dev); |
| 3585 | else |
| 3586 | netif_carrier_off(dev); |
| 3587 | } |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 3588 | } |
| 3589 | |
| 3590 | /* To handle DMA interrupts */ |
Giuseppe CAVALLARO | aec7ff2 | 2010-01-06 23:07:18 +0000 | [diff] [blame] | 3591 | stmmac_dma_interrupt(priv); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3592 | |
| 3593 | return IRQ_HANDLED; |
| 3594 | } |
| 3595 | |
| 3596 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3597 | /* Polling receive - used by NETCONSOLE and other diagnostic tools |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 3598 | * to allow network I/O with interrupts disabled. |
| 3599 | */ |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3600 | static void stmmac_poll_controller(struct net_device *dev) |
| 3601 | { |
| 3602 | disable_irq(dev->irq); |
| 3603 | stmmac_interrupt(dev->irq, dev); |
| 3604 | enable_irq(dev->irq); |
| 3605 | } |
| 3606 | #endif |
| 3607 | |
| 3608 | /** |
| 3609 | * stmmac_ioctl - Entry point for the Ioctl |
| 3610 | * @dev: Device pointer. |
| 3611 | * @rq: An IOCTL specefic structure, that can contain a pointer to |
| 3612 | * a proprietary structure used to pass information to the driver. |
| 3613 | * @cmd: IOCTL command |
| 3614 | * Description: |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 3615 | * Currently it supports the phy_mii_ioctl(...) and HW time stamping. |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3616 | */ |
| 3617 | static int stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 3618 | { |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 3619 | int ret = -EOPNOTSUPP; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3620 | |
| 3621 | if (!netif_running(dev)) |
| 3622 | return -EINVAL; |
| 3623 | |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 3624 | switch (cmd) { |
| 3625 | case SIOCGMIIPHY: |
| 3626 | case SIOCGMIIREG: |
| 3627 | case SIOCSMIIREG: |
Philippe Reynes | d6d50c7 | 2016-10-03 08:28:19 +0200 | [diff] [blame] | 3628 | if (!dev->phydev) |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 3629 | return -EINVAL; |
Philippe Reynes | d6d50c7 | 2016-10-03 08:28:19 +0200 | [diff] [blame] | 3630 | ret = phy_mii_ioctl(dev->phydev, rq, cmd); |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 3631 | break; |
| 3632 | case SIOCSHWTSTAMP: |
| 3633 | ret = stmmac_hwtstamp_ioctl(dev, rq); |
| 3634 | break; |
| 3635 | default: |
| 3636 | break; |
| 3637 | } |
Richard Cochran | 28b0411 | 2010-07-17 08:48:55 +0000 | [diff] [blame] | 3638 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3639 | return ret; |
| 3640 | } |
| 3641 | |
Giuseppe CAVALLARO | 50fb4f74 | 2014-11-04 15:49:33 +0100 | [diff] [blame] | 3642 | #ifdef CONFIG_DEBUG_FS |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 3643 | static struct dentry *stmmac_fs_dir; |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 3644 | |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 3645 | static void sysfs_display_ring(void *head, int size, int extend_desc, |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 3646 | struct seq_file *seq) |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 3647 | { |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 3648 | int i; |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 3649 | struct dma_extended_desc *ep = (struct dma_extended_desc *)head; |
| 3650 | struct dma_desc *p = (struct dma_desc *)head; |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 3651 | |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 3652 | for (i = 0; i < size; i++) { |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 3653 | if (extend_desc) { |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 3654 | seq_printf(seq, "%d [0x%x]: 0x%x 0x%x 0x%x 0x%x\n", |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 3655 | i, (unsigned int)virt_to_phys(ep), |
Michael Weiser | f8be0d7 | 2016-11-14 18:58:05 +0100 | [diff] [blame] | 3656 | le32_to_cpu(ep->basic.des0), |
| 3657 | le32_to_cpu(ep->basic.des1), |
| 3658 | le32_to_cpu(ep->basic.des2), |
| 3659 | le32_to_cpu(ep->basic.des3)); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 3660 | ep++; |
| 3661 | } else { |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 3662 | seq_printf(seq, "%d [0x%x]: 0x%x 0x%x 0x%x 0x%x\n", |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 3663 | i, (unsigned int)virt_to_phys(ep), |
Michael Weiser | f8be0d7 | 2016-11-14 18:58:05 +0100 | [diff] [blame] | 3664 | le32_to_cpu(p->des0), le32_to_cpu(p->des1), |
| 3665 | le32_to_cpu(p->des2), le32_to_cpu(p->des3)); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 3666 | p++; |
| 3667 | } |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 3668 | seq_printf(seq, "\n"); |
| 3669 | } |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 3670 | } |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 3671 | |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 3672 | static int stmmac_sysfs_ring_read(struct seq_file *seq, void *v) |
| 3673 | { |
| 3674 | struct net_device *dev = seq->private; |
| 3675 | struct stmmac_priv *priv = netdev_priv(dev); |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3676 | u32 rx_count = priv->plat->rx_queues_to_use; |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 3677 | u32 tx_count = priv->plat->tx_queues_to_use; |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 3678 | u32 queue; |
| 3679 | |
| 3680 | for (queue = 0; queue < rx_count; queue++) { |
| 3681 | struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue]; |
| 3682 | |
| 3683 | seq_printf(seq, "RX Queue %d:\n", queue); |
| 3684 | |
| 3685 | if (priv->extend_desc) { |
| 3686 | seq_printf(seq, "Extended descriptor ring:\n"); |
| 3687 | sysfs_display_ring((void *)rx_q->dma_erx, |
| 3688 | DMA_RX_SIZE, 1, seq); |
| 3689 | } else { |
| 3690 | seq_printf(seq, "Descriptor ring:\n"); |
| 3691 | sysfs_display_ring((void *)rx_q->dma_rx, |
| 3692 | DMA_RX_SIZE, 0, seq); |
| 3693 | } |
| 3694 | } |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 3695 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 3696 | for (queue = 0; queue < tx_count; queue++) { |
| 3697 | struct stmmac_tx_queue *tx_q = &priv->tx_queue[queue]; |
| 3698 | |
| 3699 | seq_printf(seq, "TX Queue %d:\n", queue); |
| 3700 | |
| 3701 | if (priv->extend_desc) { |
| 3702 | seq_printf(seq, "Extended descriptor ring:\n"); |
| 3703 | sysfs_display_ring((void *)tx_q->dma_etx, |
| 3704 | DMA_TX_SIZE, 1, seq); |
| 3705 | } else { |
| 3706 | seq_printf(seq, "Descriptor ring:\n"); |
| 3707 | sysfs_display_ring((void *)tx_q->dma_tx, |
| 3708 | DMA_TX_SIZE, 0, seq); |
| 3709 | } |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 3710 | } |
| 3711 | |
| 3712 | return 0; |
| 3713 | } |
| 3714 | |
| 3715 | static int stmmac_sysfs_ring_open(struct inode *inode, struct file *file) |
| 3716 | { |
| 3717 | return single_open(file, stmmac_sysfs_ring_read, inode->i_private); |
| 3718 | } |
| 3719 | |
Pavel Machek | 22d3efe | 2016-11-28 12:55:59 +0100 | [diff] [blame] | 3720 | /* Debugfs files, should appear in /sys/kernel/debug/stmmaceth/eth0 */ |
| 3721 | |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 3722 | static const struct file_operations stmmac_rings_status_fops = { |
| 3723 | .owner = THIS_MODULE, |
| 3724 | .open = stmmac_sysfs_ring_open, |
| 3725 | .read = seq_read, |
| 3726 | .llseek = seq_lseek, |
Djalal Harouni | 7486394 | 2012-05-20 13:55:30 +0000 | [diff] [blame] | 3727 | .release = single_release, |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 3728 | }; |
| 3729 | |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 3730 | static int stmmac_sysfs_dma_cap_read(struct seq_file *seq, void *v) |
| 3731 | { |
| 3732 | struct net_device *dev = seq->private; |
| 3733 | struct stmmac_priv *priv = netdev_priv(dev); |
| 3734 | |
Giuseppe CAVALLARO | 19e30c1 | 2011-11-16 21:58:00 +0000 | [diff] [blame] | 3735 | if (!priv->hw_cap_support) { |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 3736 | seq_printf(seq, "DMA HW features not supported\n"); |
| 3737 | return 0; |
| 3738 | } |
| 3739 | |
| 3740 | seq_printf(seq, "==============================\n"); |
| 3741 | seq_printf(seq, "\tDMA HW features\n"); |
| 3742 | seq_printf(seq, "==============================\n"); |
| 3743 | |
Pavel Machek | 22d3efe | 2016-11-28 12:55:59 +0100 | [diff] [blame] | 3744 | seq_printf(seq, "\t10/100 Mbps: %s\n", |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 3745 | (priv->dma_cap.mbps_10_100) ? "Y" : "N"); |
Pavel Machek | 22d3efe | 2016-11-28 12:55:59 +0100 | [diff] [blame] | 3746 | seq_printf(seq, "\t1000 Mbps: %s\n", |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 3747 | (priv->dma_cap.mbps_1000) ? "Y" : "N"); |
Pavel Machek | 22d3efe | 2016-11-28 12:55:59 +0100 | [diff] [blame] | 3748 | seq_printf(seq, "\tHalf duplex: %s\n", |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 3749 | (priv->dma_cap.half_duplex) ? "Y" : "N"); |
| 3750 | seq_printf(seq, "\tHash Filter: %s\n", |
| 3751 | (priv->dma_cap.hash_filter) ? "Y" : "N"); |
| 3752 | seq_printf(seq, "\tMultiple MAC address registers: %s\n", |
| 3753 | (priv->dma_cap.multi_addr) ? "Y" : "N"); |
LABBE Corentin | 8d45e42 | 2017-02-08 09:31:08 +0100 | [diff] [blame] | 3754 | seq_printf(seq, "\tPCS (TBI/SGMII/RTBI PHY interfaces): %s\n", |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 3755 | (priv->dma_cap.pcs) ? "Y" : "N"); |
| 3756 | seq_printf(seq, "\tSMA (MDIO) Interface: %s\n", |
| 3757 | (priv->dma_cap.sma_mdio) ? "Y" : "N"); |
| 3758 | seq_printf(seq, "\tPMT Remote wake up: %s\n", |
| 3759 | (priv->dma_cap.pmt_remote_wake_up) ? "Y" : "N"); |
| 3760 | seq_printf(seq, "\tPMT Magic Frame: %s\n", |
| 3761 | (priv->dma_cap.pmt_magic_frame) ? "Y" : "N"); |
| 3762 | seq_printf(seq, "\tRMON module: %s\n", |
| 3763 | (priv->dma_cap.rmon) ? "Y" : "N"); |
| 3764 | seq_printf(seq, "\tIEEE 1588-2002 Time Stamp: %s\n", |
| 3765 | (priv->dma_cap.time_stamp) ? "Y" : "N"); |
Pavel Machek | 22d3efe | 2016-11-28 12:55:59 +0100 | [diff] [blame] | 3766 | seq_printf(seq, "\tIEEE 1588-2008 Advanced Time Stamp: %s\n", |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 3767 | (priv->dma_cap.atime_stamp) ? "Y" : "N"); |
Pavel Machek | 22d3efe | 2016-11-28 12:55:59 +0100 | [diff] [blame] | 3768 | seq_printf(seq, "\t802.3az - Energy-Efficient Ethernet (EEE): %s\n", |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 3769 | (priv->dma_cap.eee) ? "Y" : "N"); |
| 3770 | seq_printf(seq, "\tAV features: %s\n", (priv->dma_cap.av) ? "Y" : "N"); |
| 3771 | seq_printf(seq, "\tChecksum Offload in TX: %s\n", |
| 3772 | (priv->dma_cap.tx_coe) ? "Y" : "N"); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 3773 | if (priv->synopsys_id >= DWMAC_CORE_4_00) { |
| 3774 | seq_printf(seq, "\tIP Checksum Offload in RX: %s\n", |
| 3775 | (priv->dma_cap.rx_coe) ? "Y" : "N"); |
| 3776 | } else { |
| 3777 | seq_printf(seq, "\tIP Checksum Offload (type1) in RX: %s\n", |
| 3778 | (priv->dma_cap.rx_coe_type1) ? "Y" : "N"); |
| 3779 | seq_printf(seq, "\tIP Checksum Offload (type2) in RX: %s\n", |
| 3780 | (priv->dma_cap.rx_coe_type2) ? "Y" : "N"); |
| 3781 | } |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 3782 | seq_printf(seq, "\tRXFIFO > 2048bytes: %s\n", |
| 3783 | (priv->dma_cap.rxfifo_over_2048) ? "Y" : "N"); |
| 3784 | seq_printf(seq, "\tNumber of Additional RX channel: %d\n", |
| 3785 | priv->dma_cap.number_rx_channel); |
| 3786 | seq_printf(seq, "\tNumber of Additional TX channel: %d\n", |
| 3787 | priv->dma_cap.number_tx_channel); |
| 3788 | seq_printf(seq, "\tEnhanced descriptors: %s\n", |
| 3789 | (priv->dma_cap.enh_desc) ? "Y" : "N"); |
| 3790 | |
| 3791 | return 0; |
| 3792 | } |
| 3793 | |
| 3794 | static int stmmac_sysfs_dma_cap_open(struct inode *inode, struct file *file) |
| 3795 | { |
| 3796 | return single_open(file, stmmac_sysfs_dma_cap_read, inode->i_private); |
| 3797 | } |
| 3798 | |
| 3799 | static const struct file_operations stmmac_dma_cap_fops = { |
| 3800 | .owner = THIS_MODULE, |
| 3801 | .open = stmmac_sysfs_dma_cap_open, |
| 3802 | .read = seq_read, |
| 3803 | .llseek = seq_lseek, |
Djalal Harouni | 7486394 | 2012-05-20 13:55:30 +0000 | [diff] [blame] | 3804 | .release = single_release, |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 3805 | }; |
| 3806 | |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 3807 | static int stmmac_init_fs(struct net_device *dev) |
| 3808 | { |
Mathieu Olivari | 466c5ac | 2015-05-22 19:03:29 -0700 | [diff] [blame] | 3809 | struct stmmac_priv *priv = netdev_priv(dev); |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 3810 | |
Mathieu Olivari | 466c5ac | 2015-05-22 19:03:29 -0700 | [diff] [blame] | 3811 | /* Create per netdev entries */ |
| 3812 | priv->dbgfs_dir = debugfs_create_dir(dev->name, stmmac_fs_dir); |
| 3813 | |
| 3814 | if (!priv->dbgfs_dir || IS_ERR(priv->dbgfs_dir)) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 3815 | netdev_err(priv->dev, "ERROR failed to create debugfs directory\n"); |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 3816 | |
| 3817 | return -ENOMEM; |
| 3818 | } |
| 3819 | |
| 3820 | /* Entry to report DMA RX/TX rings */ |
Mathieu Olivari | 466c5ac | 2015-05-22 19:03:29 -0700 | [diff] [blame] | 3821 | priv->dbgfs_rings_status = |
| 3822 | debugfs_create_file("descriptors_status", S_IRUGO, |
| 3823 | priv->dbgfs_dir, dev, |
| 3824 | &stmmac_rings_status_fops); |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 3825 | |
Mathieu Olivari | 466c5ac | 2015-05-22 19:03:29 -0700 | [diff] [blame] | 3826 | if (!priv->dbgfs_rings_status || IS_ERR(priv->dbgfs_rings_status)) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 3827 | netdev_err(priv->dev, "ERROR creating stmmac ring debugfs file\n"); |
Mathieu Olivari | 466c5ac | 2015-05-22 19:03:29 -0700 | [diff] [blame] | 3828 | debugfs_remove_recursive(priv->dbgfs_dir); |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 3829 | |
| 3830 | return -ENOMEM; |
| 3831 | } |
| 3832 | |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 3833 | /* Entry to report the DMA HW features */ |
Mathieu Olivari | 466c5ac | 2015-05-22 19:03:29 -0700 | [diff] [blame] | 3834 | priv->dbgfs_dma_cap = debugfs_create_file("dma_cap", S_IRUGO, |
| 3835 | priv->dbgfs_dir, |
| 3836 | dev, &stmmac_dma_cap_fops); |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 3837 | |
Mathieu Olivari | 466c5ac | 2015-05-22 19:03:29 -0700 | [diff] [blame] | 3838 | if (!priv->dbgfs_dma_cap || IS_ERR(priv->dbgfs_dma_cap)) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 3839 | netdev_err(priv->dev, "ERROR creating stmmac MMC debugfs file\n"); |
Mathieu Olivari | 466c5ac | 2015-05-22 19:03:29 -0700 | [diff] [blame] | 3840 | debugfs_remove_recursive(priv->dbgfs_dir); |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 3841 | |
| 3842 | return -ENOMEM; |
| 3843 | } |
| 3844 | |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 3845 | return 0; |
| 3846 | } |
| 3847 | |
Mathieu Olivari | 466c5ac | 2015-05-22 19:03:29 -0700 | [diff] [blame] | 3848 | static void stmmac_exit_fs(struct net_device *dev) |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 3849 | { |
Mathieu Olivari | 466c5ac | 2015-05-22 19:03:29 -0700 | [diff] [blame] | 3850 | struct stmmac_priv *priv = netdev_priv(dev); |
| 3851 | |
| 3852 | debugfs_remove_recursive(priv->dbgfs_dir); |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 3853 | } |
Giuseppe CAVALLARO | 50fb4f74 | 2014-11-04 15:49:33 +0100 | [diff] [blame] | 3854 | #endif /* CONFIG_DEBUG_FS */ |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 3855 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3856 | static const struct net_device_ops stmmac_netdev_ops = { |
| 3857 | .ndo_open = stmmac_open, |
| 3858 | .ndo_start_xmit = stmmac_xmit, |
| 3859 | .ndo_stop = stmmac_release, |
| 3860 | .ndo_change_mtu = stmmac_change_mtu, |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 3861 | .ndo_fix_features = stmmac_fix_features, |
Giuseppe CAVALLARO | d2afb5b | 2014-09-01 09:17:52 +0200 | [diff] [blame] | 3862 | .ndo_set_features = stmmac_set_features, |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 3863 | .ndo_set_rx_mode = stmmac_set_rx_mode, |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3864 | .ndo_tx_timeout = stmmac_tx_timeout, |
| 3865 | .ndo_do_ioctl = stmmac_ioctl, |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3866 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3867 | .ndo_poll_controller = stmmac_poll_controller, |
| 3868 | #endif |
| 3869 | .ndo_set_mac_address = eth_mac_addr, |
| 3870 | }; |
| 3871 | |
| 3872 | /** |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 3873 | * stmmac_hw_init - Init the MAC device |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 3874 | * @priv: driver private structure |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 3875 | * Description: this function is to configure the MAC device according to |
| 3876 | * some platform parameters or the HW capability register. It prepares the |
| 3877 | * driver to use either ring or chain modes and to setup either enhanced or |
| 3878 | * normal descriptors. |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 3879 | */ |
| 3880 | static int stmmac_hw_init(struct stmmac_priv *priv) |
| 3881 | { |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 3882 | struct mac_device_info *mac; |
| 3883 | |
| 3884 | /* Identify the MAC HW device */ |
Marc Kleine-Budde | 03f2eec | 2012-04-03 22:13:01 +0000 | [diff] [blame] | 3885 | if (priv->plat->has_gmac) { |
| 3886 | priv->dev->priv_flags |= IFF_UNICAST_FLT; |
Vince Bridgers | 3b57de9 | 2014-07-31 15:49:17 -0500 | [diff] [blame] | 3887 | mac = dwmac1000_setup(priv->ioaddr, |
| 3888 | priv->plat->multicast_filter_bins, |
Alexandre TORGUE | c623d14 | 2016-04-01 11:37:27 +0200 | [diff] [blame] | 3889 | priv->plat->unicast_filter_entries, |
| 3890 | &priv->synopsys_id); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 3891 | } else if (priv->plat->has_gmac4) { |
| 3892 | priv->dev->priv_flags |= IFF_UNICAST_FLT; |
| 3893 | mac = dwmac4_setup(priv->ioaddr, |
| 3894 | priv->plat->multicast_filter_bins, |
| 3895 | priv->plat->unicast_filter_entries, |
| 3896 | &priv->synopsys_id); |
Marc Kleine-Budde | 03f2eec | 2012-04-03 22:13:01 +0000 | [diff] [blame] | 3897 | } else { |
Alexandre TORGUE | c623d14 | 2016-04-01 11:37:27 +0200 | [diff] [blame] | 3898 | mac = dwmac100_setup(priv->ioaddr, &priv->synopsys_id); |
Marc Kleine-Budde | 03f2eec | 2012-04-03 22:13:01 +0000 | [diff] [blame] | 3899 | } |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 3900 | if (!mac) |
| 3901 | return -ENOMEM; |
| 3902 | |
| 3903 | priv->hw = mac; |
| 3904 | |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 3905 | /* To use the chained or ring mode */ |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 3906 | if (priv->synopsys_id >= DWMAC_CORE_4_00) { |
| 3907 | priv->hw->mode = &dwmac4_ring_mode_ops; |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 3908 | } else { |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 3909 | if (chain_mode) { |
| 3910 | priv->hw->mode = &chain_mode_ops; |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 3911 | dev_info(priv->device, "Chain mode enabled\n"); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 3912 | priv->mode = STMMAC_CHAIN_MODE; |
| 3913 | } else { |
| 3914 | priv->hw->mode = &ring_mode_ops; |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 3915 | dev_info(priv->device, "Ring mode enabled\n"); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 3916 | priv->mode = STMMAC_RING_MODE; |
| 3917 | } |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 3918 | } |
| 3919 | |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 3920 | /* Get the HW capability (new GMAC newer than 3.50a) */ |
| 3921 | priv->hw_cap_support = stmmac_get_hw_features(priv); |
| 3922 | if (priv->hw_cap_support) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 3923 | dev_info(priv->device, "DMA HW capability register supported\n"); |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 3924 | |
| 3925 | /* We can override some gmac/dma configuration fields: e.g. |
| 3926 | * enh_desc, tx_coe (e.g. that are passed through the |
| 3927 | * platform) with the values from the HW capability |
| 3928 | * register (if supported). |
| 3929 | */ |
| 3930 | priv->plat->enh_desc = priv->dma_cap.enh_desc; |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 3931 | priv->plat->pmt = priv->dma_cap.pmt_remote_wake_up; |
Giuseppe CAVALLARO | 3fe5cad | 2016-06-24 15:16:25 +0200 | [diff] [blame] | 3932 | priv->hw->pmt = priv->plat->pmt; |
Deepak SIKRI | 38912bd | 2012-04-04 04:33:21 +0000 | [diff] [blame] | 3933 | |
Ezequiel Garcia | a8df35d | 2016-05-16 12:41:07 -0300 | [diff] [blame] | 3934 | /* TXCOE doesn't work in thresh DMA mode */ |
| 3935 | if (priv->plat->force_thresh_dma_mode) |
| 3936 | priv->plat->tx_coe = 0; |
| 3937 | else |
| 3938 | priv->plat->tx_coe = priv->dma_cap.tx_coe; |
| 3939 | |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 3940 | /* In case of GMAC4 rx_coe is from HW cap register. */ |
| 3941 | priv->plat->rx_coe = priv->dma_cap.rx_coe; |
Deepak SIKRI | 38912bd | 2012-04-04 04:33:21 +0000 | [diff] [blame] | 3942 | |
| 3943 | if (priv->dma_cap.rx_coe_type2) |
| 3944 | priv->plat->rx_coe = STMMAC_RX_COE_TYPE2; |
| 3945 | else if (priv->dma_cap.rx_coe_type1) |
| 3946 | priv->plat->rx_coe = STMMAC_RX_COE_TYPE1; |
| 3947 | |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 3948 | } else { |
| 3949 | dev_info(priv->device, "No HW DMA feature register supported\n"); |
| 3950 | } |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 3951 | |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 3952 | /* To use alternate (extended), normal or GMAC4 descriptor structures */ |
| 3953 | if (priv->synopsys_id >= DWMAC_CORE_4_00) |
| 3954 | priv->hw->desc = &dwmac4_desc_ops; |
| 3955 | else |
| 3956 | stmmac_selec_desc_mode(priv); |
Byungho An | 61369d0 | 2013-06-28 16:35:32 +0900 | [diff] [blame] | 3957 | |
Giuseppe CAVALLARO | d2afb5b | 2014-09-01 09:17:52 +0200 | [diff] [blame] | 3958 | if (priv->plat->rx_coe) { |
| 3959 | priv->hw->rx_csum = priv->plat->rx_coe; |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 3960 | dev_info(priv->device, "RX Checksum Offload Engine supported\n"); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 3961 | if (priv->synopsys_id < DWMAC_CORE_4_00) |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 3962 | dev_info(priv->device, "COE Type %d\n", priv->hw->rx_csum); |
Giuseppe CAVALLARO | d2afb5b | 2014-09-01 09:17:52 +0200 | [diff] [blame] | 3963 | } |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 3964 | if (priv->plat->tx_coe) |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 3965 | dev_info(priv->device, "TX Checksum insertion supported\n"); |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 3966 | |
| 3967 | if (priv->plat->pmt) { |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 3968 | dev_info(priv->device, "Wake-Up On Lan supported\n"); |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 3969 | device_set_wakeup_capable(priv->device, 1); |
| 3970 | } |
| 3971 | |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 3972 | if (priv->dma_cap.tsoen) |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 3973 | dev_info(priv->device, "TSO supported\n"); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 3974 | |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 3975 | return 0; |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 3976 | } |
| 3977 | |
| 3978 | /** |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 3979 | * stmmac_dvr_probe |
| 3980 | * @device: device pointer |
Giuseppe CAVALLARO | ff3dd78 | 2012-06-04 19:22:55 +0000 | [diff] [blame] | 3981 | * @plat_dat: platform data pointer |
Joachim Eastwood | e56788c | 2015-05-20 20:03:07 +0200 | [diff] [blame] | 3982 | * @res: stmmac resource pointer |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 3983 | * Description: this is the main probe function used to |
| 3984 | * call the alloc_etherdev, allocate the priv structure. |
Andy Shevchenko | 9afec6e | 2015-01-27 18:38:03 +0200 | [diff] [blame] | 3985 | * Return: |
Joachim Eastwood | 15ffac7 | 2015-05-20 20:03:08 +0200 | [diff] [blame] | 3986 | * returns 0 on success, otherwise errno. |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3987 | */ |
Joachim Eastwood | 15ffac7 | 2015-05-20 20:03:08 +0200 | [diff] [blame] | 3988 | int stmmac_dvr_probe(struct device *device, |
| 3989 | struct plat_stmmacenet_data *plat_dat, |
| 3990 | struct stmmac_resources *res) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3991 | { |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 3992 | int ret = 0; |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 3993 | struct net_device *ndev = NULL; |
| 3994 | struct stmmac_priv *priv; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3995 | |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 3996 | ndev = alloc_etherdev(sizeof(struct stmmac_priv)); |
Joe Perches | 41de8d4 | 2012-01-29 13:47:52 +0000 | [diff] [blame] | 3997 | if (!ndev) |
Joachim Eastwood | 15ffac7 | 2015-05-20 20:03:08 +0200 | [diff] [blame] | 3998 | return -ENOMEM; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3999 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 4000 | SET_NETDEV_DEV(ndev, device); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4001 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 4002 | priv = netdev_priv(ndev); |
| 4003 | priv->device = device; |
| 4004 | priv->dev = ndev; |
| 4005 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 4006 | stmmac_set_ethtool_ops(ndev); |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 4007 | priv->pause = pause; |
| 4008 | priv->plat = plat_dat; |
Joachim Eastwood | e56788c | 2015-05-20 20:03:07 +0200 | [diff] [blame] | 4009 | priv->ioaddr = res->addr; |
| 4010 | priv->dev->base_addr = (unsigned long)res->addr; |
| 4011 | |
| 4012 | priv->dev->irq = res->irq; |
| 4013 | priv->wol_irq = res->wol_irq; |
| 4014 | priv->lpi_irq = res->lpi_irq; |
| 4015 | |
| 4016 | if (res->mac) |
| 4017 | memcpy(priv->dev->dev_addr, res->mac, ETH_ALEN); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 4018 | |
Joachim Eastwood | a7a6268 | 2015-07-17 23:48:17 +0200 | [diff] [blame] | 4019 | dev_set_drvdata(device, priv->dev); |
Joachim Eastwood | 803f8fc | 2015-05-20 20:03:06 +0200 | [diff] [blame] | 4020 | |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 4021 | /* Verify driver arguments */ |
| 4022 | stmmac_verify_args(); |
| 4023 | |
| 4024 | /* Override with kernel parameters if supplied XXX CRS XXX |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 4025 | * this needs to have multiple instances |
| 4026 | */ |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 4027 | if ((phyaddr >= 0) && (phyaddr <= 31)) |
| 4028 | priv->plat->phy_addr = phyaddr; |
| 4029 | |
jpinto | f573c0b | 2017-01-09 12:35:09 +0000 | [diff] [blame] | 4030 | if (priv->plat->stmmac_rst) |
| 4031 | reset_control_deassert(priv->plat->stmmac_rst); |
Chen-Yu Tsai | c5e4ddb | 2014-01-17 21:24:41 +0800 | [diff] [blame] | 4032 | |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 4033 | /* Init MAC and get the capabilities */ |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 4034 | ret = stmmac_hw_init(priv); |
| 4035 | if (ret) |
Chen-Yu Tsai | 62866e9 | 2014-01-17 21:24:40 +0800 | [diff] [blame] | 4036 | goto error_hw_init; |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 4037 | |
| 4038 | ndev->netdev_ops = &stmmac_netdev_ops; |
| 4039 | |
| 4040 | ndev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | |
| 4041 | NETIF_F_RXCSUM; |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 4042 | |
| 4043 | if ((priv->plat->tso_en) && (priv->dma_cap.tsoen)) { |
| 4044 | ndev->hw_features |= NETIF_F_TSO; |
| 4045 | priv->tso = true; |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 4046 | dev_info(priv->device, "TSO feature enabled\n"); |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 4047 | } |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 4048 | ndev->features |= ndev->hw_features | NETIF_F_HIGHDMA; |
| 4049 | ndev->watchdog_timeo = msecs_to_jiffies(watchdog); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4050 | #ifdef STMMAC_VLAN_TAG_USED |
| 4051 | /* Both mac100 and gmac support receive VLAN tag detection */ |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 4052 | ndev->features |= NETIF_F_HW_VLAN_CTAG_RX; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4053 | #endif |
| 4054 | priv->msg_enable = netif_msg_init(debug, default_msg_level); |
| 4055 | |
Jarod Wilson | 44770e1 | 2016-10-17 15:54:17 -0400 | [diff] [blame] | 4056 | /* MTU range: 46 - hw-specific max */ |
| 4057 | ndev->min_mtu = ETH_ZLEN - ETH_HLEN; |
| 4058 | if ((priv->plat->enh_desc) || (priv->synopsys_id >= DWMAC_CORE_4_00)) |
| 4059 | ndev->max_mtu = JUMBO_LEN; |
| 4060 | else |
| 4061 | ndev->max_mtu = SKB_MAX_HEAD(NET_SKB_PAD + NET_IP_ALIGN); |
Kweh, Hock Leong | a2cd64f | 2017-01-07 17:32:03 +0800 | [diff] [blame] | 4062 | /* Will not overwrite ndev->max_mtu if plat->maxmtu > ndev->max_mtu |
| 4063 | * as well as plat->maxmtu < ndev->min_mtu which is a invalid range. |
| 4064 | */ |
| 4065 | if ((priv->plat->maxmtu < ndev->max_mtu) && |
| 4066 | (priv->plat->maxmtu >= ndev->min_mtu)) |
Jarod Wilson | 44770e1 | 2016-10-17 15:54:17 -0400 | [diff] [blame] | 4067 | ndev->max_mtu = priv->plat->maxmtu; |
Kweh, Hock Leong | a2cd64f | 2017-01-07 17:32:03 +0800 | [diff] [blame] | 4068 | else if (priv->plat->maxmtu < ndev->min_mtu) |
Heiner Kallweit | b618ab4 | 2017-01-15 19:19:00 +0100 | [diff] [blame] | 4069 | dev_warn(priv->device, |
| 4070 | "%s: warning: maxmtu having invalid value (%d)\n", |
| 4071 | __func__, priv->plat->maxmtu); |
Jarod Wilson | 44770e1 | 2016-10-17 15:54:17 -0400 | [diff] [blame] | 4072 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4073 | if (flow_ctrl) |
| 4074 | priv->flow_ctrl = FLOW_AUTO; /* RX/TX pause on */ |
| 4075 | |
Giuseppe CAVALLARO | 62a2ab9 | 2012-11-25 23:10:43 +0000 | [diff] [blame] | 4076 | /* Rx Watchdog is available in the COREs newer than the 3.40. |
| 4077 | * In some case, for example on bugged HW this feature |
| 4078 | * has to be disable and this can be done by passing the |
| 4079 | * riwt_off field from the platform. |
| 4080 | */ |
| 4081 | if ((priv->synopsys_id >= DWMAC_CORE_3_50) && (!priv->plat->riwt_off)) { |
| 4082 | priv->use_riwt = 1; |
Heiner Kallweit | b618ab4 | 2017-01-15 19:19:00 +0100 | [diff] [blame] | 4083 | dev_info(priv->device, |
| 4084 | "Enable RX Mitigation via HW Watchdog Timer\n"); |
Giuseppe CAVALLARO | 62a2ab9 | 2012-11-25 23:10:43 +0000 | [diff] [blame] | 4085 | } |
| 4086 | |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 4087 | netif_napi_add(ndev, &priv->napi, stmmac_poll, 64); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4088 | |
Vlad Lungu | f8e9616 | 2010-11-29 22:52:52 +0000 | [diff] [blame] | 4089 | spin_lock_init(&priv->lock); |
| 4090 | |
Giuseppe CAVALLARO | cd7201f | 2012-04-04 04:33:27 +0000 | [diff] [blame] | 4091 | /* If a specific clk_csr value is passed from the platform |
| 4092 | * this means that the CSR Clock Range selection cannot be |
| 4093 | * changed at run-time and it is fixed. Viceversa the driver'll try to |
| 4094 | * set the MDC clock dynamically according to the csr actual |
| 4095 | * clock input. |
| 4096 | */ |
| 4097 | if (!priv->plat->clk_csr) |
| 4098 | stmmac_clk_csr_set(priv); |
| 4099 | else |
| 4100 | priv->clk_csr = priv->plat->clk_csr; |
| 4101 | |
Giuseppe CAVALLARO | e58bb43 | 2013-03-26 04:43:08 +0000 | [diff] [blame] | 4102 | stmmac_check_pcs_mode(priv); |
| 4103 | |
Giuseppe CAVALLARO | 3fe5cad | 2016-06-24 15:16:25 +0200 | [diff] [blame] | 4104 | if (priv->hw->pcs != STMMAC_PCS_RGMII && |
| 4105 | priv->hw->pcs != STMMAC_PCS_TBI && |
| 4106 | priv->hw->pcs != STMMAC_PCS_RTBI) { |
Giuseppe CAVALLARO | e58bb43 | 2013-03-26 04:43:08 +0000 | [diff] [blame] | 4107 | /* MDIO bus Registration */ |
| 4108 | ret = stmmac_mdio_register(ndev); |
| 4109 | if (ret < 0) { |
Heiner Kallweit | b618ab4 | 2017-01-15 19:19:00 +0100 | [diff] [blame] | 4110 | dev_err(priv->device, |
| 4111 | "%s: MDIO bus (id: %d) registration failed", |
| 4112 | __func__, priv->plat->bus_id); |
Giuseppe CAVALLARO | e58bb43 | 2013-03-26 04:43:08 +0000 | [diff] [blame] | 4113 | goto error_mdio_register; |
| 4114 | } |
Francesco Virlinzi | 4bfcbd7 | 2012-04-18 19:48:20 +0000 | [diff] [blame] | 4115 | } |
| 4116 | |
Florian Fainelli | 5701659 | 2016-12-27 18:23:06 -0800 | [diff] [blame] | 4117 | ret = register_netdev(ndev); |
Florian Fainelli | b2eb09a | 2016-12-28 15:44:41 -0800 | [diff] [blame] | 4118 | if (ret) { |
Heiner Kallweit | b618ab4 | 2017-01-15 19:19:00 +0100 | [diff] [blame] | 4119 | dev_err(priv->device, "%s: ERROR %i registering the device\n", |
| 4120 | __func__, ret); |
Florian Fainelli | b2eb09a | 2016-12-28 15:44:41 -0800 | [diff] [blame] | 4121 | goto error_netdev_register; |
| 4122 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4123 | |
Florian Fainelli | 5701659 | 2016-12-27 18:23:06 -0800 | [diff] [blame] | 4124 | return ret; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4125 | |
Viresh Kumar | 6a81c26 | 2012-07-30 14:39:41 -0700 | [diff] [blame] | 4126 | error_netdev_register: |
Florian Fainelli | b2eb09a | 2016-12-28 15:44:41 -0800 | [diff] [blame] | 4127 | if (priv->hw->pcs != STMMAC_PCS_RGMII && |
| 4128 | priv->hw->pcs != STMMAC_PCS_TBI && |
| 4129 | priv->hw->pcs != STMMAC_PCS_RTBI) |
| 4130 | stmmac_mdio_unregister(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4131 | error_mdio_register: |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 4132 | netif_napi_del(&priv->napi); |
Chen-Yu Tsai | 62866e9 | 2014-01-17 21:24:40 +0800 | [diff] [blame] | 4133 | error_hw_init: |
Dan Carpenter | 34a52f3 | 2010-12-20 21:34:56 +0000 | [diff] [blame] | 4134 | free_netdev(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4135 | |
Joachim Eastwood | 15ffac7 | 2015-05-20 20:03:08 +0200 | [diff] [blame] | 4136 | return ret; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4137 | } |
Andy Shevchenko | b2e2f0c | 2014-11-10 12:38:59 +0200 | [diff] [blame] | 4138 | EXPORT_SYMBOL_GPL(stmmac_dvr_probe); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4139 | |
| 4140 | /** |
| 4141 | * stmmac_dvr_remove |
Joachim Eastwood | f4e7bd8 | 2016-05-01 22:58:19 +0200 | [diff] [blame] | 4142 | * @dev: device pointer |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4143 | * Description: this function resets the TX/RX processes, disables the MAC RX/TX |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 4144 | * changes the link status, releases the DMA descriptor rings. |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4145 | */ |
Joachim Eastwood | f4e7bd8 | 2016-05-01 22:58:19 +0200 | [diff] [blame] | 4146 | int stmmac_dvr_remove(struct device *dev) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4147 | { |
Joachim Eastwood | f4e7bd8 | 2016-05-01 22:58:19 +0200 | [diff] [blame] | 4148 | struct net_device *ndev = dev_get_drvdata(dev); |
Giuseppe CAVALLARO | aec7ff2 | 2010-01-06 23:07:18 +0000 | [diff] [blame] | 4149 | struct stmmac_priv *priv = netdev_priv(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4150 | |
LABBE Corentin | 38ddc59 | 2016-11-16 20:09:39 +0100 | [diff] [blame] | 4151 | netdev_info(priv->dev, "%s: removing driver", __func__); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4152 | |
Joao Pinto | ae4f0d4 | 2017-03-15 11:04:47 +0000 | [diff] [blame] | 4153 | stmmac_stop_all_dma(priv); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4154 | |
LABBE Corentin | 270c775 | 2017-03-23 14:40:22 +0100 | [diff] [blame] | 4155 | priv->hw->mac->set_mac(priv->ioaddr, false); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4156 | netif_carrier_off(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4157 | unregister_netdev(ndev); |
jpinto | f573c0b | 2017-01-09 12:35:09 +0000 | [diff] [blame] | 4158 | if (priv->plat->stmmac_rst) |
| 4159 | reset_control_assert(priv->plat->stmmac_rst); |
| 4160 | clk_disable_unprepare(priv->plat->pclk); |
| 4161 | clk_disable_unprepare(priv->plat->stmmac_clk); |
Giuseppe CAVALLARO | 3fe5cad | 2016-06-24 15:16:25 +0200 | [diff] [blame] | 4162 | if (priv->hw->pcs != STMMAC_PCS_RGMII && |
| 4163 | priv->hw->pcs != STMMAC_PCS_TBI && |
| 4164 | priv->hw->pcs != STMMAC_PCS_RTBI) |
Bryan O'Donoghue | e743471 | 2015-04-16 17:56:03 +0100 | [diff] [blame] | 4165 | stmmac_mdio_unregister(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4166 | free_netdev(ndev); |
| 4167 | |
| 4168 | return 0; |
| 4169 | } |
Andy Shevchenko | b2e2f0c | 2014-11-10 12:38:59 +0200 | [diff] [blame] | 4170 | EXPORT_SYMBOL_GPL(stmmac_dvr_remove); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4171 | |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 4172 | /** |
| 4173 | * stmmac_suspend - suspend callback |
Joachim Eastwood | f4e7bd8 | 2016-05-01 22:58:19 +0200 | [diff] [blame] | 4174 | * @dev: device pointer |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 4175 | * Description: this is the function to suspend the device and it is called |
| 4176 | * by the platform driver to stop the network queue, release the resources, |
| 4177 | * program the PMT register (for WoL), clean and release driver resources. |
| 4178 | */ |
Joachim Eastwood | f4e7bd8 | 2016-05-01 22:58:19 +0200 | [diff] [blame] | 4179 | int stmmac_suspend(struct device *dev) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4180 | { |
Joachim Eastwood | f4e7bd8 | 2016-05-01 22:58:19 +0200 | [diff] [blame] | 4181 | struct net_device *ndev = dev_get_drvdata(dev); |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 4182 | struct stmmac_priv *priv = netdev_priv(ndev); |
Giuseppe CAVALLARO | f8c5a87 | 2012-05-13 22:18:43 +0000 | [diff] [blame] | 4183 | unsigned long flags; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4184 | |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 4185 | if (!ndev || !netif_running(ndev)) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4186 | return 0; |
| 4187 | |
Philippe Reynes | d6d50c7 | 2016-10-03 08:28:19 +0200 | [diff] [blame] | 4188 | if (ndev->phydev) |
| 4189 | phy_stop(ndev->phydev); |
Francesco Virlinzi | 102463b | 2011-11-16 21:58:02 +0000 | [diff] [blame] | 4190 | |
Giuseppe CAVALLARO | f8c5a87 | 2012-05-13 22:18:43 +0000 | [diff] [blame] | 4191 | spin_lock_irqsave(&priv->lock, flags); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4192 | |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 4193 | netif_device_detach(ndev); |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 4194 | netif_stop_queue(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4195 | |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 4196 | napi_disable(&priv->napi); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4197 | |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 4198 | /* Stop TX/RX DMA */ |
Joao Pinto | ae4f0d4 | 2017-03-15 11:04:47 +0000 | [diff] [blame] | 4199 | stmmac_stop_all_dma(priv); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 4200 | |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 4201 | /* Enable Power down mode by programming the PMT regs */ |
Srinivas Kandagatla | 89f7f2c | 2014-01-16 10:53:00 +0000 | [diff] [blame] | 4202 | if (device_may_wakeup(priv->device)) { |
Vince Bridgers | 7ed24bb | 2014-07-31 15:49:13 -0500 | [diff] [blame] | 4203 | priv->hw->mac->pmt(priv->hw, priv->wolopts); |
Srinivas Kandagatla | 89f7f2c | 2014-01-16 10:53:00 +0000 | [diff] [blame] | 4204 | priv->irq_wake = 1; |
| 4205 | } else { |
LABBE Corentin | 270c775 | 2017-03-23 14:40:22 +0100 | [diff] [blame] | 4206 | priv->hw->mac->set_mac(priv->ioaddr, false); |
Srinivas Kandagatla | db88f10 | 2014-01-16 10:52:52 +0000 | [diff] [blame] | 4207 | pinctrl_pm_select_sleep_state(priv->device); |
Giuseppe CAVALLARO | ba1377ff | 2012-04-04 04:33:25 +0000 | [diff] [blame] | 4208 | /* Disable clock in case of PWM is off */ |
jpinto | f573c0b | 2017-01-09 12:35:09 +0000 | [diff] [blame] | 4209 | clk_disable(priv->plat->pclk); |
| 4210 | clk_disable(priv->plat->stmmac_clk); |
Giuseppe CAVALLARO | ba1377ff | 2012-04-04 04:33:25 +0000 | [diff] [blame] | 4211 | } |
Giuseppe CAVALLARO | f8c5a87 | 2012-05-13 22:18:43 +0000 | [diff] [blame] | 4212 | spin_unlock_irqrestore(&priv->lock, flags); |
Vince Bridgers | 2d871aa | 2014-07-28 14:07:58 -0500 | [diff] [blame] | 4213 | |
| 4214 | priv->oldlink = 0; |
LABBE Corentin | bd00632 | 2017-02-15 10:46:40 +0100 | [diff] [blame] | 4215 | priv->speed = SPEED_UNKNOWN; |
| 4216 | priv->oldduplex = DUPLEX_UNKNOWN; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4217 | return 0; |
| 4218 | } |
Andy Shevchenko | b2e2f0c | 2014-11-10 12:38:59 +0200 | [diff] [blame] | 4219 | EXPORT_SYMBOL_GPL(stmmac_suspend); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4220 | |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 4221 | /** |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 4222 | * stmmac_reset_queues_param - reset queue parameters |
| 4223 | * @dev: device pointer |
| 4224 | */ |
| 4225 | static void stmmac_reset_queues_param(struct stmmac_priv *priv) |
| 4226 | { |
| 4227 | u32 rx_cnt = priv->plat->rx_queues_to_use; |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 4228 | u32 tx_cnt = priv->plat->tx_queues_to_use; |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 4229 | u32 queue; |
| 4230 | |
| 4231 | for (queue = 0; queue < rx_cnt; queue++) { |
| 4232 | struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue]; |
| 4233 | |
| 4234 | rx_q->cur_rx = 0; |
| 4235 | rx_q->dirty_rx = 0; |
| 4236 | } |
| 4237 | |
Joao Pinto | ce73678 | 2017-04-06 09:49:10 +0100 | [diff] [blame^] | 4238 | for (queue = 0; queue < tx_cnt; queue++) { |
| 4239 | struct stmmac_tx_queue *tx_q = &priv->tx_queue[queue]; |
| 4240 | |
| 4241 | tx_q->cur_tx = 0; |
| 4242 | tx_q->dirty_tx = 0; |
| 4243 | } |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 4244 | } |
| 4245 | |
| 4246 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 4247 | * stmmac_resume - resume callback |
Joachim Eastwood | f4e7bd8 | 2016-05-01 22:58:19 +0200 | [diff] [blame] | 4248 | * @dev: device pointer |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 4249 | * Description: when resume this function is invoked to setup the DMA and CORE |
| 4250 | * in a usable state. |
| 4251 | */ |
Joachim Eastwood | f4e7bd8 | 2016-05-01 22:58:19 +0200 | [diff] [blame] | 4252 | int stmmac_resume(struct device *dev) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4253 | { |
Joachim Eastwood | f4e7bd8 | 2016-05-01 22:58:19 +0200 | [diff] [blame] | 4254 | struct net_device *ndev = dev_get_drvdata(dev); |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 4255 | struct stmmac_priv *priv = netdev_priv(ndev); |
Giuseppe CAVALLARO | f8c5a87 | 2012-05-13 22:18:43 +0000 | [diff] [blame] | 4256 | unsigned long flags; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4257 | |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 4258 | if (!netif_running(ndev)) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4259 | return 0; |
| 4260 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4261 | /* Power Down bit, into the PM register, is cleared |
| 4262 | * automatically as soon as a magic packet or a Wake-up frame |
| 4263 | * is received. Anyway, it's better to manually clear |
| 4264 | * this bit because it can generate problems while resuming |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 4265 | * from another devices (e.g. serial console). |
| 4266 | */ |
Srinivas Kandagatla | 623997f | 2014-01-16 10:52:35 +0000 | [diff] [blame] | 4267 | if (device_may_wakeup(priv->device)) { |
Vincent Palatin | f55d84b | 2016-06-01 08:53:48 -0700 | [diff] [blame] | 4268 | spin_lock_irqsave(&priv->lock, flags); |
Vince Bridgers | 7ed24bb | 2014-07-31 15:49:13 -0500 | [diff] [blame] | 4269 | priv->hw->mac->pmt(priv->hw, 0); |
Vincent Palatin | f55d84b | 2016-06-01 08:53:48 -0700 | [diff] [blame] | 4270 | spin_unlock_irqrestore(&priv->lock, flags); |
Srinivas Kandagatla | 89f7f2c | 2014-01-16 10:53:00 +0000 | [diff] [blame] | 4271 | priv->irq_wake = 0; |
Srinivas Kandagatla | 623997f | 2014-01-16 10:52:35 +0000 | [diff] [blame] | 4272 | } else { |
Srinivas Kandagatla | db88f10 | 2014-01-16 10:52:52 +0000 | [diff] [blame] | 4273 | pinctrl_pm_select_default_state(priv->device); |
LABBE Corentin | 8d45e42 | 2017-02-08 09:31:08 +0100 | [diff] [blame] | 4274 | /* enable the clk previously disabled */ |
jpinto | f573c0b | 2017-01-09 12:35:09 +0000 | [diff] [blame] | 4275 | clk_enable(priv->plat->stmmac_clk); |
| 4276 | clk_enable(priv->plat->pclk); |
Srinivas Kandagatla | 623997f | 2014-01-16 10:52:35 +0000 | [diff] [blame] | 4277 | /* reset the phy so that it's ready */ |
| 4278 | if (priv->mii) |
| 4279 | stmmac_mdio_reset(priv->mii); |
| 4280 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4281 | |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 4282 | netif_device_attach(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4283 | |
Vincent Palatin | f55d84b | 2016-06-01 08:53:48 -0700 | [diff] [blame] | 4284 | spin_lock_irqsave(&priv->lock, flags); |
| 4285 | |
Joao Pinto | 54139cf | 2017-04-06 09:49:09 +0100 | [diff] [blame] | 4286 | stmmac_reset_queues_param(priv); |
| 4287 | |
Alexandre TORGUE | f748be5 | 2016-04-01 11:37:34 +0200 | [diff] [blame] | 4288 | /* reset private mss value to force mss context settings at |
| 4289 | * next tso xmit (only used for gmac4). |
| 4290 | */ |
| 4291 | priv->mss = 0; |
| 4292 | |
Giuseppe CAVALLARO | ae79a63 | 2015-12-04 07:21:06 +0100 | [diff] [blame] | 4293 | stmmac_clear_descriptors(priv); |
| 4294 | |
Huacai Chen | fe131929 | 2014-12-19 22:38:18 +0800 | [diff] [blame] | 4295 | stmmac_hw_setup(ndev, false); |
Giuseppe CAVALLARO | 777da230 | 2014-11-04 17:08:09 +0100 | [diff] [blame] | 4296 | stmmac_init_tx_coalesce(priv); |
Giuseppe CAVALLARO | ac316c7 | 2015-11-26 08:35:41 +0100 | [diff] [blame] | 4297 | stmmac_set_rx_mode(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4298 | |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 4299 | napi_enable(&priv->napi); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4300 | |
LABBE Corentin | 5bacd77 | 2017-03-29 07:05:40 +0200 | [diff] [blame] | 4301 | netif_start_queue(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4302 | |
Giuseppe CAVALLARO | f8c5a87 | 2012-05-13 22:18:43 +0000 | [diff] [blame] | 4303 | spin_unlock_irqrestore(&priv->lock, flags); |
Francesco Virlinzi | 102463b | 2011-11-16 21:58:02 +0000 | [diff] [blame] | 4304 | |
Philippe Reynes | d6d50c7 | 2016-10-03 08:28:19 +0200 | [diff] [blame] | 4305 | if (ndev->phydev) |
| 4306 | phy_start(ndev->phydev); |
Francesco Virlinzi | 102463b | 2011-11-16 21:58:02 +0000 | [diff] [blame] | 4307 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4308 | return 0; |
| 4309 | } |
Andy Shevchenko | b2e2f0c | 2014-11-10 12:38:59 +0200 | [diff] [blame] | 4310 | EXPORT_SYMBOL_GPL(stmmac_resume); |
Giuseppe CAVALLARO | ba27ec6 | 2012-06-04 19:22:57 +0000 | [diff] [blame] | 4311 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4312 | #ifndef MODULE |
| 4313 | static int __init stmmac_cmdline_opt(char *str) |
| 4314 | { |
| 4315 | char *opt; |
| 4316 | |
| 4317 | if (!str || !*str) |
| 4318 | return -EINVAL; |
| 4319 | while ((opt = strsep(&str, ",")) != NULL) { |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 4320 | if (!strncmp(opt, "debug:", 6)) { |
Giuseppe CAVALLARO | ea2ab87 | 2012-06-27 21:14:35 +0000 | [diff] [blame] | 4321 | if (kstrtoint(opt + 6, 0, &debug)) |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 4322 | goto err; |
| 4323 | } else if (!strncmp(opt, "phyaddr:", 8)) { |
Giuseppe CAVALLARO | ea2ab87 | 2012-06-27 21:14:35 +0000 | [diff] [blame] | 4324 | if (kstrtoint(opt + 8, 0, &phyaddr)) |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 4325 | goto err; |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 4326 | } else if (!strncmp(opt, "buf_sz:", 7)) { |
Giuseppe CAVALLARO | ea2ab87 | 2012-06-27 21:14:35 +0000 | [diff] [blame] | 4327 | if (kstrtoint(opt + 7, 0, &buf_sz)) |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 4328 | goto err; |
| 4329 | } else if (!strncmp(opt, "tc:", 3)) { |
Giuseppe CAVALLARO | ea2ab87 | 2012-06-27 21:14:35 +0000 | [diff] [blame] | 4330 | if (kstrtoint(opt + 3, 0, &tc)) |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 4331 | goto err; |
| 4332 | } else if (!strncmp(opt, "watchdog:", 9)) { |
Giuseppe CAVALLARO | ea2ab87 | 2012-06-27 21:14:35 +0000 | [diff] [blame] | 4333 | if (kstrtoint(opt + 9, 0, &watchdog)) |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 4334 | goto err; |
| 4335 | } else if (!strncmp(opt, "flow_ctrl:", 10)) { |
Giuseppe CAVALLARO | ea2ab87 | 2012-06-27 21:14:35 +0000 | [diff] [blame] | 4336 | if (kstrtoint(opt + 10, 0, &flow_ctrl)) |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 4337 | goto err; |
| 4338 | } else if (!strncmp(opt, "pause:", 6)) { |
Giuseppe CAVALLARO | ea2ab87 | 2012-06-27 21:14:35 +0000 | [diff] [blame] | 4339 | if (kstrtoint(opt + 6, 0, &pause)) |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 4340 | goto err; |
Giuseppe CAVALLARO | 506f669 | 2013-02-14 23:00:13 +0000 | [diff] [blame] | 4341 | } else if (!strncmp(opt, "eee_timer:", 10)) { |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 4342 | if (kstrtoint(opt + 10, 0, &eee_timer)) |
| 4343 | goto err; |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 4344 | } else if (!strncmp(opt, "chain_mode:", 11)) { |
| 4345 | if (kstrtoint(opt + 11, 0, &chain_mode)) |
| 4346 | goto err; |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 4347 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4348 | } |
| 4349 | return 0; |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 4350 | |
| 4351 | err: |
| 4352 | pr_err("%s: ERROR broken module parameter conversion", __func__); |
| 4353 | return -EINVAL; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 4354 | } |
| 4355 | |
| 4356 | __setup("stmmaceth=", stmmac_cmdline_opt); |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 4357 | #endif /* MODULE */ |
Giuseppe Cavallaro | 6fc0d0f | 2011-12-23 14:21:20 -0500 | [diff] [blame] | 4358 | |
Mathieu Olivari | 466c5ac | 2015-05-22 19:03:29 -0700 | [diff] [blame] | 4359 | static int __init stmmac_init(void) |
| 4360 | { |
| 4361 | #ifdef CONFIG_DEBUG_FS |
| 4362 | /* Create debugfs main directory if it doesn't exist yet */ |
| 4363 | if (!stmmac_fs_dir) { |
| 4364 | stmmac_fs_dir = debugfs_create_dir(STMMAC_RESOURCE_NAME, NULL); |
| 4365 | |
| 4366 | if (!stmmac_fs_dir || IS_ERR(stmmac_fs_dir)) { |
| 4367 | pr_err("ERROR %s, debugfs create directory failed\n", |
| 4368 | STMMAC_RESOURCE_NAME); |
| 4369 | |
| 4370 | return -ENOMEM; |
| 4371 | } |
| 4372 | } |
| 4373 | #endif |
| 4374 | |
| 4375 | return 0; |
| 4376 | } |
| 4377 | |
| 4378 | static void __exit stmmac_exit(void) |
| 4379 | { |
| 4380 | #ifdef CONFIG_DEBUG_FS |
| 4381 | debugfs_remove_recursive(stmmac_fs_dir); |
| 4382 | #endif |
| 4383 | } |
| 4384 | |
| 4385 | module_init(stmmac_init) |
| 4386 | module_exit(stmmac_exit) |
| 4387 | |
Giuseppe Cavallaro | 6fc0d0f | 2011-12-23 14:21:20 -0500 | [diff] [blame] | 4388 | MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet device driver"); |
| 4389 | MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>"); |
| 4390 | MODULE_LICENSE("GPL"); |