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 | |
| 16 | You should have received a copy of the GNU General Public License along with |
| 17 | this program; if not, write to the Free Software Foundation, Inc., |
| 18 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | |
| 20 | The full GNU General Public License is included in this distribution in |
| 21 | the file called "COPYING". |
| 22 | |
| 23 | Author: Giuseppe Cavallaro <peppe.cavallaro@st.com> |
| 24 | |
| 25 | Documentation available at: |
| 26 | http://www.stlinux.com |
| 27 | Support available at: |
| 28 | https://bugzilla.stlinux.com/ |
| 29 | *******************************************************************************/ |
| 30 | |
Viresh Kumar | 6a81c26 | 2012-07-30 14:39:41 -0700 | [diff] [blame] | 31 | #include <linux/clk.h> |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 32 | #include <linux/kernel.h> |
| 33 | #include <linux/interrupt.h> |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 34 | #include <linux/ip.h> |
| 35 | #include <linux/tcp.h> |
| 36 | #include <linux/skbuff.h> |
| 37 | #include <linux/ethtool.h> |
| 38 | #include <linux/if_ether.h> |
| 39 | #include <linux/crc32.h> |
| 40 | #include <linux/mii.h> |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 41 | #include <linux/if.h> |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 42 | #include <linux/if_vlan.h> |
| 43 | #include <linux/dma-mapping.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 45 | #include <linux/prefetch.h> |
Srinivas Kandagatla | db88f10 | 2014-01-16 10:52:52 +0000 | [diff] [blame] | 46 | #include <linux/pinctrl/consumer.h> |
Giuseppe CAVALLARO | 50fb4f74 | 2014-11-04 15:49:33 +0100 | [diff] [blame] | 47 | #ifdef CONFIG_DEBUG_FS |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 48 | #include <linux/debugfs.h> |
| 49 | #include <linux/seq_file.h> |
Giuseppe CAVALLARO | 50fb4f74 | 2014-11-04 15:49:33 +0100 | [diff] [blame] | 50 | #endif /* CONFIG_DEBUG_FS */ |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 51 | #include <linux/net_tstamp.h> |
| 52 | #include "stmmac_ptp.h" |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 53 | #include "stmmac.h" |
Chen-Yu Tsai | c5e4ddb | 2014-01-17 21:24:41 +0800 | [diff] [blame] | 54 | #include <linux/reset.h> |
Mathieu Olivari | 5790cf3 | 2015-05-27 11:02:47 -0700 | [diff] [blame] | 55 | #include <linux/of_mdio.h> |
Phil Reid | 19d857c | 2015-12-14 11:32:01 +0800 | [diff] [blame] | 56 | #include "dwmac1000.h" |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 57 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 58 | #define STMMAC_ALIGN(x) L1_CACHE_ALIGN(x) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 59 | |
| 60 | /* Module parameters */ |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 61 | #define TX_TIMEO 5000 |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 62 | static int watchdog = TX_TIMEO; |
| 63 | module_param(watchdog, int, S_IRUGO | S_IWUSR); |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 64 | MODULE_PARM_DESC(watchdog, "Transmit timeout in milliseconds (default 5s)"); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 65 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 66 | static int debug = -1; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 67 | module_param(debug, int, S_IRUGO | S_IWUSR); |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 68 | 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] | 69 | |
stephen hemminger | 47d1f71 | 2013-12-30 10:38:57 -0800 | [diff] [blame] | 70 | static int phyaddr = -1; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 71 | module_param(phyaddr, int, S_IRUGO); |
| 72 | MODULE_PARM_DESC(phyaddr, "Physical device address"); |
| 73 | |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 74 | #define STMMAC_TX_THRESH (DMA_TX_SIZE / 4) |
Giuseppe Cavallaro | 120e87f | 2016-02-29 14:27:42 +0100 | [diff] [blame] | 75 | #define STMMAC_RX_THRESH (DMA_RX_SIZE / 4) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 76 | |
| 77 | static int flow_ctrl = FLOW_OFF; |
| 78 | module_param(flow_ctrl, int, S_IRUGO | S_IWUSR); |
| 79 | MODULE_PARM_DESC(flow_ctrl, "Flow control ability [on/off]"); |
| 80 | |
| 81 | static int pause = PAUSE_TIME; |
| 82 | module_param(pause, int, S_IRUGO | S_IWUSR); |
| 83 | MODULE_PARM_DESC(pause, "Flow Control Pause Time"); |
| 84 | |
| 85 | #define TC_DEFAULT 64 |
| 86 | static int tc = TC_DEFAULT; |
| 87 | module_param(tc, int, S_IRUGO | S_IWUSR); |
| 88 | MODULE_PARM_DESC(tc, "DMA threshold control value"); |
| 89 | |
Giuseppe CAVALLARO | d916701 | 2014-03-10 13:40:32 +0100 | [diff] [blame] | 90 | #define DEFAULT_BUFSIZE 1536 |
| 91 | static int buf_sz = DEFAULT_BUFSIZE; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 92 | module_param(buf_sz, int, S_IRUGO | S_IWUSR); |
| 93 | MODULE_PARM_DESC(buf_sz, "DMA buffer size"); |
| 94 | |
Giuseppe Cavallaro | 22ad383 | 2016-02-29 14:27:41 +0100 | [diff] [blame] | 95 | #define STMMAC_RX_COPYBREAK 256 |
| 96 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 97 | static const u32 default_msg_level = (NETIF_MSG_DRV | NETIF_MSG_PROBE | |
| 98 | NETIF_MSG_LINK | NETIF_MSG_IFUP | |
| 99 | NETIF_MSG_IFDOWN | NETIF_MSG_TIMER); |
| 100 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 101 | #define STMMAC_DEFAULT_LPI_TIMER 1000 |
| 102 | static int eee_timer = STMMAC_DEFAULT_LPI_TIMER; |
| 103 | module_param(eee_timer, int, S_IRUGO | S_IWUSR); |
| 104 | MODULE_PARM_DESC(eee_timer, "LPI tx expiration time in msec"); |
Giuseppe CAVALLARO | f5351ef | 2013-06-18 07:03:23 +0200 | [diff] [blame] | 105 | #define STMMAC_LPI_T(x) (jiffies + msecs_to_jiffies(x)) |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 106 | |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 107 | /* By default the driver will use the ring mode to manage tx and rx descriptors |
| 108 | * but passing this value so user can force to use the chain instead of the ring |
| 109 | */ |
| 110 | static unsigned int chain_mode; |
| 111 | module_param(chain_mode, int, S_IRUGO); |
| 112 | MODULE_PARM_DESC(chain_mode, "To use chain instead of ring mode"); |
| 113 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 114 | static irqreturn_t stmmac_interrupt(int irq, void *dev_id); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 115 | |
Giuseppe CAVALLARO | 50fb4f74 | 2014-11-04 15:49:33 +0100 | [diff] [blame] | 116 | #ifdef CONFIG_DEBUG_FS |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 117 | static int stmmac_init_fs(struct net_device *dev); |
Mathieu Olivari | 466c5ac | 2015-05-22 19:03:29 -0700 | [diff] [blame] | 118 | static void stmmac_exit_fs(struct net_device *dev); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 119 | #endif |
| 120 | |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 121 | #define STMMAC_COAL_TIMER(x) (jiffies + usecs_to_jiffies(x)) |
| 122 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 123 | /** |
| 124 | * stmmac_verify_args - verify the driver parameters. |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 125 | * Description: it checks the driver parameters and set a default in case of |
| 126 | * errors. |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 127 | */ |
| 128 | static void stmmac_verify_args(void) |
| 129 | { |
| 130 | if (unlikely(watchdog < 0)) |
| 131 | watchdog = TX_TIMEO; |
Giuseppe CAVALLARO | d916701 | 2014-03-10 13:40:32 +0100 | [diff] [blame] | 132 | if (unlikely((buf_sz < DEFAULT_BUFSIZE) || (buf_sz > BUF_SIZE_16KiB))) |
| 133 | buf_sz = DEFAULT_BUFSIZE; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 134 | if (unlikely(flow_ctrl > 1)) |
| 135 | flow_ctrl = FLOW_AUTO; |
| 136 | else if (likely(flow_ctrl < 0)) |
| 137 | flow_ctrl = FLOW_OFF; |
| 138 | if (unlikely((pause < 0) || (pause > 0xffff))) |
| 139 | pause = PAUSE_TIME; |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 140 | if (eee_timer < 0) |
| 141 | eee_timer = STMMAC_DEFAULT_LPI_TIMER; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 144 | /** |
| 145 | * stmmac_clk_csr_set - dynamically set the MDC clock |
| 146 | * @priv: driver private structure |
| 147 | * Description: this is to dynamically set the MDC clock according to the csr |
| 148 | * clock input. |
| 149 | * Note: |
| 150 | * If a specific clk_csr value is passed from the platform |
| 151 | * this means that the CSR Clock Range selection cannot be |
| 152 | * changed at run-time and it is fixed (as reported in the driver |
| 153 | * documentation). Viceversa the driver will try to set the MDC |
| 154 | * clock dynamically according to the actual clock input. |
| 155 | */ |
Giuseppe CAVALLARO | cd7201f | 2012-04-04 04:33:27 +0000 | [diff] [blame] | 156 | static void stmmac_clk_csr_set(struct stmmac_priv *priv) |
| 157 | { |
Giuseppe CAVALLARO | cd7201f | 2012-04-04 04:33:27 +0000 | [diff] [blame] | 158 | u32 clk_rate; |
| 159 | |
| 160 | clk_rate = clk_get_rate(priv->stmmac_clk); |
| 161 | |
| 162 | /* Platform provided default clk_csr would be assumed valid |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 163 | * for all other cases except for the below mentioned ones. |
| 164 | * For values higher than the IEEE 802.3 specified frequency |
| 165 | * we can not estimate the proper divider as it is not known |
| 166 | * the frequency of clk_csr_i. So we do not change the default |
| 167 | * divider. |
| 168 | */ |
Giuseppe CAVALLARO | cd7201f | 2012-04-04 04:33:27 +0000 | [diff] [blame] | 169 | if (!(priv->clk_csr & MAC_CSR_H_FRQ_MASK)) { |
| 170 | if (clk_rate < CSR_F_35M) |
| 171 | priv->clk_csr = STMMAC_CSR_20_35M; |
| 172 | else if ((clk_rate >= CSR_F_35M) && (clk_rate < CSR_F_60M)) |
| 173 | priv->clk_csr = STMMAC_CSR_35_60M; |
| 174 | else if ((clk_rate >= CSR_F_60M) && (clk_rate < CSR_F_100M)) |
| 175 | priv->clk_csr = STMMAC_CSR_60_100M; |
| 176 | else if ((clk_rate >= CSR_F_100M) && (clk_rate < CSR_F_150M)) |
| 177 | priv->clk_csr = STMMAC_CSR_100_150M; |
| 178 | else if ((clk_rate >= CSR_F_150M) && (clk_rate < CSR_F_250M)) |
| 179 | priv->clk_csr = STMMAC_CSR_150_250M; |
Phil Reid | 19d857c | 2015-12-14 11:32:01 +0800 | [diff] [blame] | 180 | else if ((clk_rate >= CSR_F_250M) && (clk_rate < CSR_F_300M)) |
Giuseppe CAVALLARO | cd7201f | 2012-04-04 04:33:27 +0000 | [diff] [blame] | 181 | priv->clk_csr = STMMAC_CSR_250_300M; |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 182 | } |
Giuseppe CAVALLARO | cd7201f | 2012-04-04 04:33:27 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 185 | static void print_pkt(unsigned char *buf, int len) |
| 186 | { |
Andy Shevchenko | 424c4f7 | 2014-11-07 16:53:12 +0200 | [diff] [blame] | 187 | pr_debug("len = %d byte, buf addr: 0x%p\n", len, buf); |
| 188 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, buf, len); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 189 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 190 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 191 | static inline u32 stmmac_tx_avail(struct stmmac_priv *priv) |
| 192 | { |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 193 | unsigned avail; |
| 194 | |
| 195 | if (priv->dirty_tx > priv->cur_tx) |
| 196 | avail = priv->dirty_tx - priv->cur_tx - 1; |
| 197 | else |
| 198 | avail = DMA_TX_SIZE - priv->cur_tx + priv->dirty_tx - 1; |
| 199 | |
| 200 | return avail; |
| 201 | } |
| 202 | |
| 203 | static inline u32 stmmac_rx_dirty(struct stmmac_priv *priv) |
| 204 | { |
| 205 | unsigned dirty; |
| 206 | |
| 207 | if (priv->dirty_rx <= priv->cur_rx) |
| 208 | dirty = priv->cur_rx - priv->dirty_rx; |
| 209 | else |
| 210 | dirty = DMA_RX_SIZE - priv->dirty_rx + priv->cur_rx; |
| 211 | |
| 212 | return dirty; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 215 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 216 | * stmmac_hw_fix_mac_speed - callback for speed selection |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 217 | * @priv: driver private structure |
| 218 | * Description: on some platforms (e.g. ST), some HW system configuraton |
| 219 | * registers have to be set according to the link speed negotiated. |
Giuseppe CAVALLARO | 9dfeb4d | 2010-11-24 02:37:58 +0000 | [diff] [blame] | 220 | */ |
| 221 | static inline void stmmac_hw_fix_mac_speed(struct stmmac_priv *priv) |
| 222 | { |
| 223 | struct phy_device *phydev = priv->phydev; |
| 224 | |
| 225 | if (likely(priv->plat->fix_mac_speed)) |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 226 | priv->plat->fix_mac_speed(priv->plat->bsp_priv, phydev->speed); |
Giuseppe CAVALLARO | 9dfeb4d | 2010-11-24 02:37:58 +0000 | [diff] [blame] | 227 | } |
| 228 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 229 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 230 | * stmmac_enable_eee_mode - check and enter in LPI mode |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 231 | * @priv: driver private structure |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 232 | * Description: this function is to verify and enter in LPI mode in case of |
| 233 | * EEE. |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 234 | */ |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 235 | static void stmmac_enable_eee_mode(struct stmmac_priv *priv) |
| 236 | { |
| 237 | /* Check and enter in LPI mode */ |
| 238 | if ((priv->dirty_tx == priv->cur_tx) && |
| 239 | (priv->tx_path_in_lpi_mode == false)) |
Vince Bridgers | 7ed24bb | 2014-07-31 15:49:13 -0500 | [diff] [blame] | 240 | priv->hw->mac->set_eee_mode(priv->hw); |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 241 | } |
| 242 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 243 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 244 | * stmmac_disable_eee_mode - disable and exit from LPI mode |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 245 | * @priv: driver private structure |
| 246 | * Description: this function is to exit and disable EEE in case of |
| 247 | * LPI state is true. This is called by the xmit. |
| 248 | */ |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 249 | void stmmac_disable_eee_mode(struct stmmac_priv *priv) |
| 250 | { |
Vince Bridgers | 7ed24bb | 2014-07-31 15:49:13 -0500 | [diff] [blame] | 251 | priv->hw->mac->reset_eee_mode(priv->hw); |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 252 | del_timer_sync(&priv->eee_ctrl_timer); |
| 253 | priv->tx_path_in_lpi_mode = false; |
| 254 | } |
| 255 | |
| 256 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 257 | * stmmac_eee_ctrl_timer - EEE TX SW timer. |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 258 | * @arg : data hook |
| 259 | * Description: |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 260 | * 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] | 261 | * then MAC Transmitter can be moved to LPI state. |
| 262 | */ |
| 263 | static void stmmac_eee_ctrl_timer(unsigned long arg) |
| 264 | { |
| 265 | struct stmmac_priv *priv = (struct stmmac_priv *)arg; |
| 266 | |
| 267 | stmmac_enable_eee_mode(priv); |
Giuseppe CAVALLARO | f5351ef | 2013-06-18 07:03:23 +0200 | [diff] [blame] | 268 | mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_T(eee_timer)); |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 272 | * stmmac_eee_init - init EEE |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 273 | * @priv: driver private structure |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 274 | * Description: |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 275 | * if the GMAC supports the EEE (from the HW cap reg) and the phy device |
| 276 | * can also manage EEE, this function enable the LPI state and start related |
| 277 | * timer. |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 278 | */ |
| 279 | bool stmmac_eee_init(struct stmmac_priv *priv) |
| 280 | { |
Giuseppe CAVALLARO | 4741cf9 | 2014-11-04 17:08:08 +0100 | [diff] [blame] | 281 | unsigned long flags; |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 282 | bool ret = false; |
| 283 | |
Giuseppe CAVALLARO | f5351ef | 2013-06-18 07:03:23 +0200 | [diff] [blame] | 284 | /* Using PCS we cannot dial with the phy registers at this stage |
| 285 | * so we do not support extra feature like EEE. |
| 286 | */ |
| 287 | if ((priv->pcs == STMMAC_PCS_RGMII) || (priv->pcs == STMMAC_PCS_TBI) || |
| 288 | (priv->pcs == STMMAC_PCS_RTBI)) |
| 289 | goto out; |
| 290 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 291 | /* MAC core supports the EEE feature. */ |
| 292 | if (priv->dma_cap.eee) { |
Giuseppe CAVALLARO | 83bf79b | 2014-03-10 13:40:31 +0100 | [diff] [blame] | 293 | int tx_lpi_timer = priv->tx_lpi_timer; |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 294 | |
Giuseppe CAVALLARO | 83bf79b | 2014-03-10 13:40:31 +0100 | [diff] [blame] | 295 | /* Check if the PHY supports EEE */ |
| 296 | if (phy_init_eee(priv->phydev, 1)) { |
| 297 | /* To manage at run-time if the EEE cannot be supported |
| 298 | * anymore (for example because the lp caps have been |
| 299 | * changed). |
| 300 | * In that case the driver disable own timers. |
| 301 | */ |
Giuseppe CAVALLARO | 4741cf9 | 2014-11-04 17:08:08 +0100 | [diff] [blame] | 302 | spin_lock_irqsave(&priv->lock, flags); |
Giuseppe CAVALLARO | 83bf79b | 2014-03-10 13:40:31 +0100 | [diff] [blame] | 303 | if (priv->eee_active) { |
| 304 | pr_debug("stmmac: disable EEE\n"); |
| 305 | del_timer_sync(&priv->eee_ctrl_timer); |
Vince Bridgers | 7ed24bb | 2014-07-31 15:49:13 -0500 | [diff] [blame] | 306 | priv->hw->mac->set_eee_timer(priv->hw, 0, |
Giuseppe CAVALLARO | 83bf79b | 2014-03-10 13:40:31 +0100 | [diff] [blame] | 307 | tx_lpi_timer); |
| 308 | } |
| 309 | priv->eee_active = 0; |
Giuseppe CAVALLARO | 4741cf9 | 2014-11-04 17:08:08 +0100 | [diff] [blame] | 310 | spin_unlock_irqrestore(&priv->lock, flags); |
Giuseppe CAVALLARO | 83bf79b | 2014-03-10 13:40:31 +0100 | [diff] [blame] | 311 | goto out; |
| 312 | } |
| 313 | /* Activate the EEE and start timers */ |
Giuseppe CAVALLARO | 4741cf9 | 2014-11-04 17:08:08 +0100 | [diff] [blame] | 314 | spin_lock_irqsave(&priv->lock, flags); |
Giuseppe CAVALLARO | f5351ef | 2013-06-18 07:03:23 +0200 | [diff] [blame] | 315 | if (!priv->eee_active) { |
| 316 | priv->eee_active = 1; |
Vaishali Thakkar | ccb36da | 2015-02-28 00:12:34 +0530 | [diff] [blame] | 317 | setup_timer(&priv->eee_ctrl_timer, |
| 318 | stmmac_eee_ctrl_timer, |
| 319 | (unsigned long)priv); |
| 320 | mod_timer(&priv->eee_ctrl_timer, |
| 321 | STMMAC_LPI_T(eee_timer)); |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 322 | |
Vince Bridgers | 7ed24bb | 2014-07-31 15:49:13 -0500 | [diff] [blame] | 323 | priv->hw->mac->set_eee_timer(priv->hw, |
Giuseppe CAVALLARO | f5351ef | 2013-06-18 07:03:23 +0200 | [diff] [blame] | 324 | STMMAC_DEFAULT_LIT_LS, |
Giuseppe CAVALLARO | 83bf79b | 2014-03-10 13:40:31 +0100 | [diff] [blame] | 325 | tx_lpi_timer); |
Giuseppe CAVALLARO | 7196535 | 2014-08-28 08:11:44 +0200 | [diff] [blame] | 326 | } |
| 327 | /* Set HW EEE according to the speed */ |
| 328 | priv->hw->mac->set_eee_pls(priv->hw, priv->phydev->link); |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 329 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 330 | ret = true; |
Giuseppe CAVALLARO | 4741cf9 | 2014-11-04 17:08:08 +0100 | [diff] [blame] | 331 | spin_unlock_irqrestore(&priv->lock, flags); |
| 332 | |
| 333 | pr_debug("stmmac: Energy-Efficient Ethernet initialized\n"); |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 334 | } |
| 335 | out: |
| 336 | return ret; |
| 337 | } |
| 338 | |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 339 | /* stmmac_get_tx_hwtstamp - get HW TX timestamps |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 340 | * @priv: driver private structure |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 341 | * @entry : descriptor index to be used. |
| 342 | * @skb : the socket buffer |
| 343 | * Description : |
| 344 | * This function will read timestamp from the descriptor & pass it to stack. |
| 345 | * and also perform some sanity checks. |
| 346 | */ |
| 347 | static void stmmac_get_tx_hwtstamp(struct stmmac_priv *priv, |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 348 | unsigned int entry, struct sk_buff *skb) |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 349 | { |
| 350 | struct skb_shared_hwtstamps shhwtstamp; |
| 351 | u64 ns; |
| 352 | void *desc = NULL; |
| 353 | |
| 354 | if (!priv->hwts_tx_en) |
| 355 | return; |
| 356 | |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 357 | /* exit if skb doesn't support hw tstamp */ |
damuzi000 | 75e4364 | 2014-01-17 23:47:59 +0800 | [diff] [blame] | 358 | if (likely(!skb || !(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS))) |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 359 | return; |
| 360 | |
| 361 | if (priv->adv_ts) |
| 362 | desc = (priv->dma_etx + entry); |
| 363 | else |
| 364 | desc = (priv->dma_tx + entry); |
| 365 | |
| 366 | /* check tx tstamp status */ |
| 367 | if (!priv->hw->desc->get_tx_timestamp_status((struct dma_desc *)desc)) |
| 368 | return; |
| 369 | |
| 370 | /* get the valid tstamp */ |
| 371 | ns = priv->hw->desc->get_timestamp(desc, priv->adv_ts); |
| 372 | |
| 373 | memset(&shhwtstamp, 0, sizeof(struct skb_shared_hwtstamps)); |
| 374 | shhwtstamp.hwtstamp = ns_to_ktime(ns); |
| 375 | /* pass tstamp to stack */ |
| 376 | skb_tstamp_tx(skb, &shhwtstamp); |
| 377 | |
| 378 | return; |
| 379 | } |
| 380 | |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 381 | /* stmmac_get_rx_hwtstamp - get HW RX timestamps |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 382 | * @priv: driver private structure |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 383 | * @entry : descriptor index to be used. |
| 384 | * @skb : the socket buffer |
| 385 | * Description : |
| 386 | * This function will read received packet's timestamp from the descriptor |
| 387 | * and pass it to stack. It also perform some sanity checks. |
| 388 | */ |
| 389 | static void stmmac_get_rx_hwtstamp(struct stmmac_priv *priv, |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 390 | unsigned int entry, struct sk_buff *skb) |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 391 | { |
| 392 | struct skb_shared_hwtstamps *shhwtstamp = NULL; |
| 393 | u64 ns; |
| 394 | void *desc = NULL; |
| 395 | |
| 396 | if (!priv->hwts_rx_en) |
| 397 | return; |
| 398 | |
| 399 | if (priv->adv_ts) |
| 400 | desc = (priv->dma_erx + entry); |
| 401 | else |
| 402 | desc = (priv->dma_rx + entry); |
| 403 | |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 404 | /* exit if rx tstamp is not valid */ |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 405 | if (!priv->hw->desc->get_rx_timestamp_status(desc, priv->adv_ts)) |
| 406 | return; |
| 407 | |
| 408 | /* get valid tstamp */ |
| 409 | ns = priv->hw->desc->get_timestamp(desc, priv->adv_ts); |
| 410 | shhwtstamp = skb_hwtstamps(skb); |
| 411 | memset(shhwtstamp, 0, sizeof(struct skb_shared_hwtstamps)); |
| 412 | shhwtstamp->hwtstamp = ns_to_ktime(ns); |
| 413 | } |
| 414 | |
| 415 | /** |
| 416 | * stmmac_hwtstamp_ioctl - control hardware timestamping. |
| 417 | * @dev: device pointer. |
| 418 | * @ifr: An IOCTL specefic structure, that can contain a pointer to |
| 419 | * a proprietary structure used to pass information to the driver. |
| 420 | * Description: |
| 421 | * This function configures the MAC to enable/disable both outgoing(TX) |
| 422 | * and incoming(RX) packets time stamping based on user input. |
| 423 | * Return Value: |
| 424 | * 0 on success and an appropriate -ve integer on failure. |
| 425 | */ |
| 426 | static int stmmac_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr) |
| 427 | { |
| 428 | struct stmmac_priv *priv = netdev_priv(dev); |
| 429 | struct hwtstamp_config config; |
Arnd Bergmann | 0a62415 | 2015-09-30 13:26:32 +0200 | [diff] [blame] | 430 | struct timespec64 now; |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 431 | u64 temp = 0; |
| 432 | u32 ptp_v2 = 0; |
| 433 | u32 tstamp_all = 0; |
| 434 | u32 ptp_over_ipv4_udp = 0; |
| 435 | u32 ptp_over_ipv6_udp = 0; |
| 436 | u32 ptp_over_ethernet = 0; |
| 437 | u32 snap_type_sel = 0; |
| 438 | u32 ts_master_en = 0; |
| 439 | u32 ts_event_en = 0; |
| 440 | u32 value = 0; |
Phil Reid | 19d857c | 2015-12-14 11:32:01 +0800 | [diff] [blame] | 441 | u32 sec_inc; |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 442 | |
| 443 | if (!(priv->dma_cap.time_stamp || priv->adv_ts)) { |
| 444 | netdev_alert(priv->dev, "No support for HW time stamping\n"); |
| 445 | priv->hwts_tx_en = 0; |
| 446 | priv->hwts_rx_en = 0; |
| 447 | |
| 448 | return -EOPNOTSUPP; |
| 449 | } |
| 450 | |
| 451 | if (copy_from_user(&config, ifr->ifr_data, |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 452 | sizeof(struct hwtstamp_config))) |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 453 | return -EFAULT; |
| 454 | |
| 455 | pr_debug("%s config flags:0x%x, tx_type:0x%x, rx_filter:0x%x\n", |
| 456 | __func__, config.flags, config.tx_type, config.rx_filter); |
| 457 | |
| 458 | /* reserved for future extensions */ |
| 459 | if (config.flags) |
| 460 | return -EINVAL; |
| 461 | |
Ben Hutchings | 5f3da32 | 2013-11-14 00:43:41 +0000 | [diff] [blame] | 462 | if (config.tx_type != HWTSTAMP_TX_OFF && |
| 463 | config.tx_type != HWTSTAMP_TX_ON) |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 464 | return -ERANGE; |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 465 | |
| 466 | if (priv->adv_ts) { |
| 467 | switch (config.rx_filter) { |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 468 | case HWTSTAMP_FILTER_NONE: |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 469 | /* time stamp no incoming packet at all */ |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 470 | config.rx_filter = HWTSTAMP_FILTER_NONE; |
| 471 | break; |
| 472 | |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 473 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 474 | /* PTP v1, UDP, any kind of event packet */ |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 475 | config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT; |
| 476 | /* take time stamp for all event messages */ |
| 477 | snap_type_sel = PTP_TCR_SNAPTYPSEL_1; |
| 478 | |
| 479 | ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA; |
| 480 | ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA; |
| 481 | break; |
| 482 | |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 483 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 484 | /* PTP v1, UDP, Sync packet */ |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 485 | config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_SYNC; |
| 486 | /* take time stamp for SYNC messages only */ |
| 487 | ts_event_en = PTP_TCR_TSEVNTENA; |
| 488 | |
| 489 | ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA; |
| 490 | ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA; |
| 491 | break; |
| 492 | |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 493 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 494 | /* PTP v1, UDP, Delay_req packet */ |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 495 | config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ; |
| 496 | /* take time stamp for Delay_Req messages only */ |
| 497 | ts_master_en = PTP_TCR_TSMSTRENA; |
| 498 | ts_event_en = PTP_TCR_TSEVNTENA; |
| 499 | |
| 500 | ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA; |
| 501 | ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA; |
| 502 | break; |
| 503 | |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 504 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 505 | /* PTP v2, UDP, any kind of event packet */ |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 506 | config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT; |
| 507 | ptp_v2 = PTP_TCR_TSVER2ENA; |
| 508 | /* take time stamp for all event messages */ |
| 509 | snap_type_sel = PTP_TCR_SNAPTYPSEL_1; |
| 510 | |
| 511 | ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA; |
| 512 | ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA; |
| 513 | break; |
| 514 | |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 515 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 516 | /* PTP v2, UDP, Sync packet */ |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 517 | config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_SYNC; |
| 518 | ptp_v2 = PTP_TCR_TSVER2ENA; |
| 519 | /* take time stamp for SYNC messages only */ |
| 520 | ts_event_en = PTP_TCR_TSEVNTENA; |
| 521 | |
| 522 | ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA; |
| 523 | ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA; |
| 524 | break; |
| 525 | |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 526 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 527 | /* PTP v2, UDP, Delay_req packet */ |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 528 | config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ; |
| 529 | ptp_v2 = PTP_TCR_TSVER2ENA; |
| 530 | /* take time stamp for Delay_Req messages only */ |
| 531 | ts_master_en = PTP_TCR_TSMSTRENA; |
| 532 | ts_event_en = PTP_TCR_TSEVNTENA; |
| 533 | |
| 534 | ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA; |
| 535 | ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA; |
| 536 | break; |
| 537 | |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 538 | case HWTSTAMP_FILTER_PTP_V2_EVENT: |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 539 | /* PTP v2/802.AS1 any layer, any kind of event packet */ |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 540 | config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; |
| 541 | ptp_v2 = PTP_TCR_TSVER2ENA; |
| 542 | /* take time stamp for all event messages */ |
| 543 | snap_type_sel = PTP_TCR_SNAPTYPSEL_1; |
| 544 | |
| 545 | ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA; |
| 546 | ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA; |
| 547 | ptp_over_ethernet = PTP_TCR_TSIPENA; |
| 548 | break; |
| 549 | |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 550 | case HWTSTAMP_FILTER_PTP_V2_SYNC: |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 551 | /* PTP v2/802.AS1, any layer, Sync packet */ |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 552 | config.rx_filter = HWTSTAMP_FILTER_PTP_V2_SYNC; |
| 553 | ptp_v2 = PTP_TCR_TSVER2ENA; |
| 554 | /* take time stamp for SYNC messages only */ |
| 555 | ts_event_en = PTP_TCR_TSEVNTENA; |
| 556 | |
| 557 | ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA; |
| 558 | ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA; |
| 559 | ptp_over_ethernet = PTP_TCR_TSIPENA; |
| 560 | break; |
| 561 | |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 562 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 563 | /* PTP v2/802.AS1, any layer, Delay_req packet */ |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 564 | config.rx_filter = HWTSTAMP_FILTER_PTP_V2_DELAY_REQ; |
| 565 | ptp_v2 = PTP_TCR_TSVER2ENA; |
| 566 | /* take time stamp for Delay_Req messages only */ |
| 567 | ts_master_en = PTP_TCR_TSMSTRENA; |
| 568 | ts_event_en = PTP_TCR_TSEVNTENA; |
| 569 | |
| 570 | ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA; |
| 571 | ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA; |
| 572 | ptp_over_ethernet = PTP_TCR_TSIPENA; |
| 573 | break; |
| 574 | |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 575 | case HWTSTAMP_FILTER_ALL: |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 576 | /* time stamp any incoming packet */ |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 577 | config.rx_filter = HWTSTAMP_FILTER_ALL; |
| 578 | tstamp_all = PTP_TCR_TSENALL; |
| 579 | break; |
| 580 | |
| 581 | default: |
| 582 | return -ERANGE; |
| 583 | } |
| 584 | } else { |
| 585 | switch (config.rx_filter) { |
| 586 | case HWTSTAMP_FILTER_NONE: |
| 587 | config.rx_filter = HWTSTAMP_FILTER_NONE; |
| 588 | break; |
| 589 | default: |
| 590 | /* PTP v1, UDP, any kind of event packet */ |
| 591 | config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT; |
| 592 | break; |
| 593 | } |
| 594 | } |
| 595 | priv->hwts_rx_en = ((config.rx_filter == HWTSTAMP_FILTER_NONE) ? 0 : 1); |
Ben Hutchings | 5f3da32 | 2013-11-14 00:43:41 +0000 | [diff] [blame] | 596 | priv->hwts_tx_en = config.tx_type == HWTSTAMP_TX_ON; |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 597 | |
| 598 | if (!priv->hwts_tx_en && !priv->hwts_rx_en) |
| 599 | priv->hw->ptp->config_hw_tstamping(priv->ioaddr, 0); |
| 600 | else { |
| 601 | value = (PTP_TCR_TSENA | PTP_TCR_TSCFUPDT | PTP_TCR_TSCTRLSSR | |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 602 | tstamp_all | ptp_v2 | ptp_over_ethernet | |
| 603 | ptp_over_ipv6_udp | ptp_over_ipv4_udp | ts_event_en | |
| 604 | ts_master_en | snap_type_sel); |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 605 | priv->hw->ptp->config_hw_tstamping(priv->ioaddr, value); |
| 606 | |
| 607 | /* program Sub Second Increment reg */ |
Phil Reid | 19d857c | 2015-12-14 11:32:01 +0800 | [diff] [blame] | 608 | sec_inc = priv->hw->ptp->config_sub_second_increment( |
| 609 | priv->ioaddr, priv->clk_ptp_rate); |
| 610 | temp = div_u64(1000000000ULL, sec_inc); |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 611 | |
| 612 | /* calculate default added value: |
| 613 | * formula is : |
| 614 | * addend = (2^32)/freq_div_ratio; |
Phil Reid | 19d857c | 2015-12-14 11:32:01 +0800 | [diff] [blame] | 615 | * where, freq_div_ratio = 1e9ns/sec_inc |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 616 | */ |
Phil Reid | 19d857c | 2015-12-14 11:32:01 +0800 | [diff] [blame] | 617 | temp = (u64)(temp << 32); |
Giuseppe CAVALLARO | 5566401 | 2014-08-27 10:37:49 +0200 | [diff] [blame] | 618 | priv->default_addend = div_u64(temp, priv->clk_ptp_rate); |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 619 | priv->hw->ptp->config_addend(priv->ioaddr, |
| 620 | priv->default_addend); |
| 621 | |
| 622 | /* initialize system time */ |
Arnd Bergmann | 0a62415 | 2015-09-30 13:26:32 +0200 | [diff] [blame] | 623 | ktime_get_real_ts64(&now); |
| 624 | |
| 625 | /* lower 32 bits of tv_sec are safe until y2106 */ |
| 626 | priv->hw->ptp->init_systime(priv->ioaddr, (u32)now.tv_sec, |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 627 | now.tv_nsec); |
| 628 | } |
| 629 | |
| 630 | return copy_to_user(ifr->ifr_data, &config, |
| 631 | sizeof(struct hwtstamp_config)) ? -EFAULT : 0; |
| 632 | } |
| 633 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 634 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 635 | * stmmac_init_ptp - init PTP |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 636 | * @priv: driver private structure |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 637 | * 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] | 638 | * This is done by looking at the HW cap. register. |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 639 | * This function also registers the ptp driver. |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 640 | */ |
Rayagond Kokatanur | 92ba688 | 2013-03-26 04:43:11 +0000 | [diff] [blame] | 641 | static int stmmac_init_ptp(struct stmmac_priv *priv) |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 642 | { |
Rayagond Kokatanur | 92ba688 | 2013-03-26 04:43:11 +0000 | [diff] [blame] | 643 | if (!(priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp)) |
| 644 | return -EOPNOTSUPP; |
| 645 | |
Giuseppe CAVALLARO | 5566401 | 2014-08-27 10:37:49 +0200 | [diff] [blame] | 646 | /* Fall-back to main clock in case of no PTP ref is passed */ |
| 647 | priv->clk_ptp_ref = devm_clk_get(priv->device, "clk_ptp_ref"); |
| 648 | if (IS_ERR(priv->clk_ptp_ref)) { |
| 649 | priv->clk_ptp_rate = clk_get_rate(priv->stmmac_clk); |
| 650 | priv->clk_ptp_ref = NULL; |
| 651 | } else { |
| 652 | clk_prepare_enable(priv->clk_ptp_ref); |
| 653 | priv->clk_ptp_rate = clk_get_rate(priv->clk_ptp_ref); |
| 654 | } |
| 655 | |
Vince Bridgers | 7cd0139 | 2013-12-20 11:19:34 -0600 | [diff] [blame] | 656 | priv->adv_ts = 0; |
| 657 | if (priv->dma_cap.atime_stamp && priv->extend_desc) |
| 658 | priv->adv_ts = 1; |
| 659 | |
| 660 | if (netif_msg_hw(priv) && priv->dma_cap.time_stamp) |
| 661 | pr_debug("IEEE 1588-2002 Time Stamp supported\n"); |
| 662 | |
| 663 | if (netif_msg_hw(priv) && priv->adv_ts) |
| 664 | pr_debug("IEEE 1588-2008 Advanced Time Stamp supported\n"); |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 665 | |
| 666 | priv->hw->ptp = &stmmac_ptp; |
| 667 | priv->hwts_tx_en = 0; |
| 668 | priv->hwts_rx_en = 0; |
Rayagond Kokatanur | 92ba688 | 2013-03-26 04:43:11 +0000 | [diff] [blame] | 669 | |
| 670 | return stmmac_ptp_register(priv); |
| 671 | } |
| 672 | |
| 673 | static void stmmac_release_ptp(struct stmmac_priv *priv) |
| 674 | { |
Giuseppe CAVALLARO | 5566401 | 2014-08-27 10:37:49 +0200 | [diff] [blame] | 675 | if (priv->clk_ptp_ref) |
| 676 | clk_disable_unprepare(priv->clk_ptp_ref); |
Rayagond Kokatanur | 92ba688 | 2013-03-26 04:43:11 +0000 | [diff] [blame] | 677 | stmmac_ptp_unregister(priv); |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 678 | } |
| 679 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 680 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 681 | * stmmac_adjust_link - adjusts the link parameters |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 682 | * @dev: net device structure |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 683 | * Description: this is the helper called by the physical abstraction layer |
| 684 | * drivers to communicate the phy link status. According the speed and duplex |
| 685 | * this driver can invoke registered glue-logic as well. |
| 686 | * It also invoke the eee initialization because it could happen when switch |
| 687 | * on different networks (that are eee capable). |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 688 | */ |
| 689 | static void stmmac_adjust_link(struct net_device *dev) |
| 690 | { |
| 691 | struct stmmac_priv *priv = netdev_priv(dev); |
| 692 | struct phy_device *phydev = priv->phydev; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 693 | unsigned long flags; |
| 694 | int new_state = 0; |
| 695 | unsigned int fc = priv->flow_ctrl, pause_time = priv->pause; |
| 696 | |
| 697 | if (phydev == NULL) |
| 698 | return; |
| 699 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 700 | spin_lock_irqsave(&priv->lock, flags); |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 701 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 702 | if (phydev->link) { |
Giuseppe CAVALLARO | ad01b7d | 2010-08-23 20:40:42 +0000 | [diff] [blame] | 703 | u32 ctrl = readl(priv->ioaddr + MAC_CTRL_REG); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 704 | |
| 705 | /* Now we make sure that we can be in full duplex mode. |
| 706 | * If not, we operate in half-duplex mode. */ |
| 707 | if (phydev->duplex != priv->oldduplex) { |
| 708 | new_state = 1; |
| 709 | if (!(phydev->duplex)) |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 710 | ctrl &= ~priv->hw->link.duplex; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 711 | else |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 712 | ctrl |= priv->hw->link.duplex; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 713 | priv->oldduplex = phydev->duplex; |
| 714 | } |
| 715 | /* Flow Control operation */ |
| 716 | if (phydev->pause) |
Vince Bridgers | 7ed24bb | 2014-07-31 15:49:13 -0500 | [diff] [blame] | 717 | priv->hw->mac->flow_ctrl(priv->hw, phydev->duplex, |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 718 | fc, pause_time); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 719 | |
| 720 | if (phydev->speed != priv->speed) { |
| 721 | new_state = 1; |
| 722 | switch (phydev->speed) { |
| 723 | case 1000: |
Giuseppe CAVALLARO | 9dfeb4d | 2010-11-24 02:37:58 +0000 | [diff] [blame] | 724 | if (likely(priv->plat->has_gmac)) |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 725 | ctrl &= ~priv->hw->link.port; |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 726 | stmmac_hw_fix_mac_speed(priv); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 727 | break; |
| 728 | case 100: |
| 729 | case 10: |
Giuseppe CAVALLARO | 9dfeb4d | 2010-11-24 02:37:58 +0000 | [diff] [blame] | 730 | if (priv->plat->has_gmac) { |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 731 | ctrl |= priv->hw->link.port; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 732 | if (phydev->speed == SPEED_100) { |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 733 | ctrl |= priv->hw->link.speed; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 734 | } else { |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 735 | ctrl &= ~(priv->hw->link.speed); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 736 | } |
| 737 | } else { |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 738 | ctrl &= ~priv->hw->link.port; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 739 | } |
Giuseppe CAVALLARO | 9dfeb4d | 2010-11-24 02:37:58 +0000 | [diff] [blame] | 740 | stmmac_hw_fix_mac_speed(priv); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 741 | break; |
| 742 | default: |
| 743 | if (netif_msg_link(priv)) |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 744 | pr_warn("%s: Speed (%d) not 10/100\n", |
| 745 | dev->name, phydev->speed); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 746 | break; |
| 747 | } |
| 748 | |
| 749 | priv->speed = phydev->speed; |
| 750 | } |
| 751 | |
Giuseppe CAVALLARO | ad01b7d | 2010-08-23 20:40:42 +0000 | [diff] [blame] | 752 | writel(ctrl, priv->ioaddr + MAC_CTRL_REG); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 753 | |
| 754 | if (!priv->oldlink) { |
| 755 | new_state = 1; |
| 756 | priv->oldlink = 1; |
| 757 | } |
| 758 | } else if (priv->oldlink) { |
| 759 | new_state = 1; |
| 760 | priv->oldlink = 0; |
| 761 | priv->speed = 0; |
| 762 | priv->oldduplex = -1; |
| 763 | } |
| 764 | |
| 765 | if (new_state && netif_msg_link(priv)) |
| 766 | phy_print_status(phydev); |
| 767 | |
Giuseppe CAVALLARO | 4741cf9 | 2014-11-04 17:08:08 +0100 | [diff] [blame] | 768 | spin_unlock_irqrestore(&priv->lock, flags); |
| 769 | |
Giuseppe CAVALLARO | 52f95bb | 2016-04-05 08:46:57 +0200 | [diff] [blame] | 770 | if (phydev->is_pseudo_fixed_link) |
| 771 | /* Stop PHY layer to call the hook to adjust the link in case |
| 772 | * of a switch is attached to the stmmac driver. |
| 773 | */ |
| 774 | phydev->irq = PHY_IGNORE_INTERRUPT; |
| 775 | else |
| 776 | /* At this stage, init the EEE if supported. |
| 777 | * Never called in case of fixed_link. |
| 778 | */ |
| 779 | priv->eee_enabled = stmmac_eee_init(priv); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 780 | } |
| 781 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 782 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 783 | * stmmac_check_pcs_mode - verify if RGMII/SGMII is supported |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 784 | * @priv: driver private structure |
| 785 | * Description: this is to verify if the HW supports the PCS. |
| 786 | * Physical Coding Sublayer (PCS) interface that can be used when the MAC is |
| 787 | * configured for the TBI, RTBI, or SGMII PHY interface. |
| 788 | */ |
Giuseppe CAVALLARO | e58bb43 | 2013-03-26 04:43:08 +0000 | [diff] [blame] | 789 | static void stmmac_check_pcs_mode(struct stmmac_priv *priv) |
| 790 | { |
| 791 | int interface = priv->plat->interface; |
| 792 | |
| 793 | if (priv->dma_cap.pcs) { |
Byungho An | 0d909dc | 2013-06-28 16:35:31 +0900 | [diff] [blame] | 794 | if ((interface == PHY_INTERFACE_MODE_RGMII) || |
| 795 | (interface == PHY_INTERFACE_MODE_RGMII_ID) || |
| 796 | (interface == PHY_INTERFACE_MODE_RGMII_RXID) || |
| 797 | (interface == PHY_INTERFACE_MODE_RGMII_TXID)) { |
Giuseppe CAVALLARO | e58bb43 | 2013-03-26 04:43:08 +0000 | [diff] [blame] | 798 | pr_debug("STMMAC: PCS RGMII support enable\n"); |
| 799 | priv->pcs = STMMAC_PCS_RGMII; |
Byungho An | 0d909dc | 2013-06-28 16:35:31 +0900 | [diff] [blame] | 800 | } else if (interface == PHY_INTERFACE_MODE_SGMII) { |
Giuseppe CAVALLARO | e58bb43 | 2013-03-26 04:43:08 +0000 | [diff] [blame] | 801 | pr_debug("STMMAC: PCS SGMII support enable\n"); |
| 802 | priv->pcs = STMMAC_PCS_SGMII; |
| 803 | } |
| 804 | } |
| 805 | } |
| 806 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 807 | /** |
| 808 | * stmmac_init_phy - PHY initialization |
| 809 | * @dev: net device structure |
| 810 | * Description: it initializes the driver's PHY state, and attaches the PHY |
| 811 | * to the mac driver. |
| 812 | * Return value: |
| 813 | * 0 on success |
| 814 | */ |
| 815 | static int stmmac_init_phy(struct net_device *dev) |
| 816 | { |
| 817 | struct stmmac_priv *priv = netdev_priv(dev); |
| 818 | struct phy_device *phydev; |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 819 | char phy_id_fmt[MII_BUS_ID_SIZE + 3]; |
Giuseppe CAVALLARO | 109cdd6 | 2010-01-06 23:07:11 +0000 | [diff] [blame] | 820 | char bus_id[MII_BUS_ID_SIZE]; |
Srinivas Kandagatla | 79ee1dc | 2011-10-18 00:01:18 +0000 | [diff] [blame] | 821 | int interface = priv->plat->interface; |
Srinivas Kandagatla | 9cbadf0 | 2014-01-16 10:51:43 +0000 | [diff] [blame] | 822 | int max_speed = priv->plat->max_speed; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 823 | priv->oldlink = 0; |
| 824 | priv->speed = 0; |
| 825 | priv->oldduplex = -1; |
| 826 | |
Mathieu Olivari | 5790cf3 | 2015-05-27 11:02:47 -0700 | [diff] [blame] | 827 | if (priv->plat->phy_node) { |
| 828 | phydev = of_phy_connect(dev, priv->plat->phy_node, |
| 829 | &stmmac_adjust_link, 0, interface); |
| 830 | } else { |
Giuseppe CAVALLARO | a7657f1 | 2016-04-01 09:07:16 +0200 | [diff] [blame] | 831 | snprintf(bus_id, MII_BUS_ID_SIZE, "stmmac-%x", |
| 832 | priv->plat->bus_id); |
Srinivas Kandagatla | f142af2 | 2012-04-04 04:33:19 +0000 | [diff] [blame] | 833 | |
Mathieu Olivari | 5790cf3 | 2015-05-27 11:02:47 -0700 | [diff] [blame] | 834 | snprintf(phy_id_fmt, MII_BUS_ID_SIZE + 3, PHY_ID_FMT, bus_id, |
| 835 | priv->plat->phy_addr); |
| 836 | pr_debug("stmmac_init_phy: trying to attach to %s\n", |
| 837 | phy_id_fmt); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 838 | |
Mathieu Olivari | 5790cf3 | 2015-05-27 11:02:47 -0700 | [diff] [blame] | 839 | phydev = phy_connect(dev, phy_id_fmt, &stmmac_adjust_link, |
| 840 | interface); |
| 841 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 842 | |
Alexey Brodkin | dfc50fc | 2015-09-09 18:01:08 +0300 | [diff] [blame] | 843 | if (IS_ERR_OR_NULL(phydev)) { |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 844 | pr_err("%s: Could not attach to PHY\n", dev->name); |
Alexey Brodkin | dfc50fc | 2015-09-09 18:01:08 +0300 | [diff] [blame] | 845 | if (!phydev) |
| 846 | return -ENODEV; |
| 847 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 848 | return PTR_ERR(phydev); |
| 849 | } |
| 850 | |
Srinivas Kandagatla | 79ee1dc | 2011-10-18 00:01:18 +0000 | [diff] [blame] | 851 | /* Stop Advertising 1000BASE Capability if interface is not GMII */ |
Srinivas Kandagatla | c5b9b4e | 2011-11-16 21:57:59 +0000 | [diff] [blame] | 852 | if ((interface == PHY_INTERFACE_MODE_MII) || |
Srinivas Kandagatla | 9cbadf0 | 2014-01-16 10:51:43 +0000 | [diff] [blame] | 853 | (interface == PHY_INTERFACE_MODE_RMII) || |
Pavel Machek | a77e4ac | 2014-08-25 13:31:16 +0200 | [diff] [blame] | 854 | (max_speed < 1000 && max_speed > 0)) |
Srinivas Kandagatla | c5b9b4e | 2011-11-16 21:57:59 +0000 | [diff] [blame] | 855 | phydev->advertising &= ~(SUPPORTED_1000baseT_Half | |
| 856 | SUPPORTED_1000baseT_Full); |
Srinivas Kandagatla | 79ee1dc | 2011-10-18 00:01:18 +0000 | [diff] [blame] | 857 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 858 | /* |
| 859 | * Broken HW is sometimes missing the pull-up resistor on the |
| 860 | * MDIO line, which results in reads to non-existent devices returning |
| 861 | * 0 rather than 0xffff. Catch this here and treat 0 as a non-existent |
| 862 | * device as well. |
| 863 | * Note: phydev->phy_id is the result of reading the UID PHY registers. |
| 864 | */ |
Mathieu Olivari | 2773238 | 2015-05-27 11:02:48 -0700 | [diff] [blame] | 865 | if (!priv->plat->phy_node && phydev->phy_id == 0) { |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 866 | phy_disconnect(phydev); |
| 867 | return -ENODEV; |
| 868 | } |
Giuseppe Cavallaro | 8e99fc5 | 2016-02-29 14:27:39 +0100 | [diff] [blame] | 869 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 870 | pr_debug("stmmac_init_phy: %s: attached to PHY (UID 0x%x)" |
Giuseppe CAVALLARO | 36bcfe7 | 2011-07-20 00:05:23 +0000 | [diff] [blame] | 871 | " Link = %d\n", dev->name, phydev->phy_id, phydev->link); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 872 | |
| 873 | priv->phydev = phydev; |
| 874 | |
| 875 | return 0; |
| 876 | } |
| 877 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 878 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 879 | * stmmac_display_ring - display ring |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 880 | * @head: pointer to the head of the ring passed. |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 881 | * @size: size of the ring. |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 882 | * @extend_desc: to verify if extended descriptors are used. |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 883 | * Description: display the control/status and buffer descriptors. |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 884 | */ |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 885 | static void stmmac_display_ring(void *head, int size, int extend_desc) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 886 | { |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 887 | int i; |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 888 | struct dma_extended_desc *ep = (struct dma_extended_desc *)head; |
| 889 | struct dma_desc *p = (struct dma_desc *)head; |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 890 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 891 | for (i = 0; i < size; i++) { |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 892 | u64 x; |
| 893 | if (extend_desc) { |
| 894 | x = *(u64 *) ep; |
| 895 | pr_info("%d [0x%x]: 0x%x 0x%x 0x%x 0x%x\n", |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 896 | i, (unsigned int)virt_to_phys(ep), |
| 897 | (unsigned int)x, (unsigned int)(x >> 32), |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 898 | ep->basic.des2, ep->basic.des3); |
| 899 | ep++; |
| 900 | } else { |
| 901 | x = *(u64 *) p; |
| 902 | pr_info("%d [0x%x]: 0x%x 0x%x 0x%x 0x%x", |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 903 | i, (unsigned int)virt_to_phys(p), |
| 904 | (unsigned int)x, (unsigned int)(x >> 32), |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 905 | p->des2, p->des3); |
| 906 | p++; |
| 907 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 908 | pr_info("\n"); |
| 909 | } |
| 910 | } |
| 911 | |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 912 | static void stmmac_display_rings(struct stmmac_priv *priv) |
| 913 | { |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 914 | if (priv->extend_desc) { |
| 915 | pr_info("Extended RX descriptor ring:\n"); |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 916 | stmmac_display_ring((void *)priv->dma_erx, DMA_RX_SIZE, 1); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 917 | pr_info("Extended TX descriptor ring:\n"); |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 918 | stmmac_display_ring((void *)priv->dma_etx, DMA_TX_SIZE, 1); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 919 | } else { |
| 920 | pr_info("RX descriptor ring:\n"); |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 921 | stmmac_display_ring((void *)priv->dma_rx, DMA_RX_SIZE, 0); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 922 | pr_info("TX descriptor ring:\n"); |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 923 | stmmac_display_ring((void *)priv->dma_tx, DMA_TX_SIZE, 0); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 924 | } |
| 925 | } |
| 926 | |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 927 | static int stmmac_set_bfsize(int mtu, int bufsize) |
| 928 | { |
| 929 | int ret = bufsize; |
| 930 | |
| 931 | if (mtu >= BUF_SIZE_4KiB) |
| 932 | ret = BUF_SIZE_8KiB; |
| 933 | else if (mtu >= BUF_SIZE_2KiB) |
| 934 | ret = BUF_SIZE_4KiB; |
Giuseppe CAVALLARO | d916701 | 2014-03-10 13:40:32 +0100 | [diff] [blame] | 935 | else if (mtu > DEFAULT_BUFSIZE) |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 936 | ret = BUF_SIZE_2KiB; |
| 937 | else |
Giuseppe CAVALLARO | d916701 | 2014-03-10 13:40:32 +0100 | [diff] [blame] | 938 | ret = DEFAULT_BUFSIZE; |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 939 | |
| 940 | return ret; |
| 941 | } |
| 942 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 943 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 944 | * stmmac_clear_descriptors - clear descriptors |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 945 | * @priv: driver private structure |
| 946 | * Description: this function is called to clear the tx and rx descriptors |
| 947 | * in case of both basic and extended descriptors are used. |
| 948 | */ |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 949 | static void stmmac_clear_descriptors(struct stmmac_priv *priv) |
| 950 | { |
| 951 | int i; |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 952 | |
| 953 | /* Clear the Rx/Tx descriptors */ |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 954 | for (i = 0; i < DMA_RX_SIZE; i++) |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 955 | if (priv->extend_desc) |
| 956 | priv->hw->desc->init_rx_desc(&priv->dma_erx[i].basic, |
| 957 | priv->use_riwt, priv->mode, |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 958 | (i == DMA_RX_SIZE - 1)); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 959 | else |
| 960 | priv->hw->desc->init_rx_desc(&priv->dma_rx[i], |
| 961 | priv->use_riwt, priv->mode, |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 962 | (i == DMA_RX_SIZE - 1)); |
| 963 | for (i = 0; i < DMA_TX_SIZE; i++) |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 964 | if (priv->extend_desc) |
| 965 | priv->hw->desc->init_tx_desc(&priv->dma_etx[i].basic, |
| 966 | priv->mode, |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 967 | (i == DMA_TX_SIZE - 1)); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 968 | else |
| 969 | priv->hw->desc->init_tx_desc(&priv->dma_tx[i], |
| 970 | priv->mode, |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 971 | (i == DMA_TX_SIZE - 1)); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 972 | } |
| 973 | |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 974 | /** |
| 975 | * stmmac_init_rx_buffers - init the RX descriptor buffer. |
| 976 | * @priv: driver private structure |
| 977 | * @p: descriptor pointer |
| 978 | * @i: descriptor index |
| 979 | * @flags: gfp flag. |
| 980 | * Description: this function is called to allocate a receive buffer, perform |
| 981 | * the DMA mapping and init the descriptor. |
| 982 | */ |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 983 | static int stmmac_init_rx_buffers(struct stmmac_priv *priv, struct dma_desc *p, |
Giuseppe CAVALLARO | 777da23 | 2014-11-04 17:08:09 +0100 | [diff] [blame] | 984 | int i, gfp_t flags) |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 985 | { |
| 986 | struct sk_buff *skb; |
| 987 | |
Vineet Gupta | 4ec49a3 | 2015-05-20 12:04:40 +0530 | [diff] [blame] | 988 | 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] | 989 | if (!skb) { |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 990 | pr_err("%s: Rx init fails; skb is NULL\n", __func__); |
Bartlomiej Zolnierkiewicz | 5632913 | 2013-08-09 14:02:08 +0200 | [diff] [blame] | 991 | return -ENOMEM; |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 992 | } |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 993 | priv->rx_skbuff[i] = skb; |
| 994 | priv->rx_skbuff_dma[i] = dma_map_single(priv->device, skb->data, |
| 995 | priv->dma_buf_sz, |
| 996 | DMA_FROM_DEVICE); |
Bartlomiej Zolnierkiewicz | 5632913 | 2013-08-09 14:02:08 +0200 | [diff] [blame] | 997 | if (dma_mapping_error(priv->device, priv->rx_skbuff_dma[i])) { |
| 998 | pr_err("%s: DMA mapping error\n", __func__); |
| 999 | dev_kfree_skb_any(skb); |
| 1000 | return -EINVAL; |
| 1001 | } |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1002 | |
| 1003 | p->des2 = priv->rx_skbuff_dma[i]; |
| 1004 | |
Giuseppe CAVALLARO | 29896a6 | 2014-03-10 13:40:33 +0100 | [diff] [blame] | 1005 | if ((priv->hw->mode->init_desc3) && |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1006 | (priv->dma_buf_sz == BUF_SIZE_16KiB)) |
Giuseppe CAVALLARO | 29896a6 | 2014-03-10 13:40:33 +0100 | [diff] [blame] | 1007 | priv->hw->mode->init_desc3(p); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1008 | |
| 1009 | return 0; |
| 1010 | } |
| 1011 | |
Bartlomiej Zolnierkiewicz | 5632913 | 2013-08-09 14:02:08 +0200 | [diff] [blame] | 1012 | static void stmmac_free_rx_buffers(struct stmmac_priv *priv, int i) |
| 1013 | { |
| 1014 | if (priv->rx_skbuff[i]) { |
| 1015 | dma_unmap_single(priv->device, priv->rx_skbuff_dma[i], |
| 1016 | priv->dma_buf_sz, DMA_FROM_DEVICE); |
| 1017 | dev_kfree_skb_any(priv->rx_skbuff[i]); |
| 1018 | } |
| 1019 | priv->rx_skbuff[i] = NULL; |
| 1020 | } |
| 1021 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1022 | /** |
| 1023 | * init_dma_desc_rings - init the RX/TX descriptor rings |
| 1024 | * @dev: net device structure |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1025 | * @flags: gfp flag. |
| 1026 | * Description: this function initializes the DMA RX/TX descriptors |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 1027 | * and allocates the socket buffers. It suppors the chained and ring |
| 1028 | * modes. |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1029 | */ |
Giuseppe CAVALLARO | 777da23 | 2014-11-04 17:08:09 +0100 | [diff] [blame] | 1030 | static int init_dma_desc_rings(struct net_device *dev, gfp_t flags) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1031 | { |
| 1032 | int i; |
| 1033 | struct stmmac_priv *priv = netdev_priv(dev); |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 1034 | unsigned int bfsize = 0; |
Bartlomiej Zolnierkiewicz | 5632913 | 2013-08-09 14:02:08 +0200 | [diff] [blame] | 1035 | int ret = -ENOMEM; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1036 | |
Giuseppe CAVALLARO | 29896a6 | 2014-03-10 13:40:33 +0100 | [diff] [blame] | 1037 | if (priv->hw->mode->set_16kib_bfsize) |
| 1038 | bfsize = priv->hw->mode->set_16kib_bfsize(dev->mtu); |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 1039 | |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 1040 | if (bfsize < BUF_SIZE_16KiB) |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 1041 | bfsize = stmmac_set_bfsize(dev->mtu, priv->dma_buf_sz); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1042 | |
Vince Bridgers | 2618abb | 2014-01-20 05:39:01 -0600 | [diff] [blame] | 1043 | priv->dma_buf_sz = bfsize; |
| 1044 | |
Giuseppe CAVALLARO | 83d7af6 | 2013-07-02 14:12:36 +0200 | [diff] [blame] | 1045 | if (netif_msg_probe(priv)) { |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1046 | pr_debug("(%s) dma_rx_phy=0x%08x dma_tx_phy=0x%08x\n", __func__, |
| 1047 | (u32) priv->dma_rx_phy, (u32) priv->dma_tx_phy); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1048 | |
Giuseppe CAVALLARO | 83d7af6 | 2013-07-02 14:12:36 +0200 | [diff] [blame] | 1049 | /* RX INITIALIZATION */ |
| 1050 | pr_debug("\tSKB addresses:\nskb\t\tskb data\tdma data\n"); |
| 1051 | } |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1052 | for (i = 0; i < DMA_RX_SIZE; i++) { |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1053 | struct dma_desc *p; |
| 1054 | if (priv->extend_desc) |
| 1055 | p = &((priv->dma_erx + i)->basic); |
| 1056 | else |
| 1057 | p = priv->dma_rx + i; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1058 | |
Giuseppe CAVALLARO | 777da23 | 2014-11-04 17:08:09 +0100 | [diff] [blame] | 1059 | ret = stmmac_init_rx_buffers(priv, p, i, flags); |
Bartlomiej Zolnierkiewicz | 5632913 | 2013-08-09 14:02:08 +0200 | [diff] [blame] | 1060 | if (ret) |
| 1061 | goto err_init_rx_buffers; |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 1062 | |
Giuseppe CAVALLARO | 83d7af6 | 2013-07-02 14:12:36 +0200 | [diff] [blame] | 1063 | if (netif_msg_probe(priv)) |
| 1064 | pr_debug("[%p]\t[%p]\t[%x]\n", priv->rx_skbuff[i], |
| 1065 | priv->rx_skbuff[i]->data, |
| 1066 | (unsigned int)priv->rx_skbuff_dma[i]); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1067 | } |
| 1068 | priv->cur_rx = 0; |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1069 | priv->dirty_rx = (unsigned int)(i - DMA_RX_SIZE); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1070 | buf_sz = bfsize; |
| 1071 | |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1072 | /* Setup the chained descriptor addresses */ |
| 1073 | if (priv->mode == STMMAC_CHAIN_MODE) { |
| 1074 | if (priv->extend_desc) { |
Giuseppe CAVALLARO | 29896a6 | 2014-03-10 13:40:33 +0100 | [diff] [blame] | 1075 | priv->hw->mode->init(priv->dma_erx, priv->dma_rx_phy, |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1076 | DMA_RX_SIZE, 1); |
Giuseppe CAVALLARO | 29896a6 | 2014-03-10 13:40:33 +0100 | [diff] [blame] | 1077 | priv->hw->mode->init(priv->dma_etx, priv->dma_tx_phy, |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1078 | DMA_TX_SIZE, 1); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1079 | } else { |
Giuseppe CAVALLARO | 29896a6 | 2014-03-10 13:40:33 +0100 | [diff] [blame] | 1080 | priv->hw->mode->init(priv->dma_rx, priv->dma_rx_phy, |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1081 | DMA_RX_SIZE, 0); |
Giuseppe CAVALLARO | 29896a6 | 2014-03-10 13:40:33 +0100 | [diff] [blame] | 1082 | priv->hw->mode->init(priv->dma_tx, priv->dma_tx_phy, |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1083 | DMA_TX_SIZE, 0); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1084 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1085 | } |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 1086 | |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1087 | /* TX INITIALIZATION */ |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1088 | for (i = 0; i < DMA_TX_SIZE; i++) { |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1089 | struct dma_desc *p; |
| 1090 | if (priv->extend_desc) |
| 1091 | p = &((priv->dma_etx + i)->basic); |
| 1092 | else |
| 1093 | p = priv->dma_tx + i; |
| 1094 | p->des2 = 0; |
Giuseppe CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 1095 | priv->tx_skbuff_dma[i].buf = 0; |
| 1096 | priv->tx_skbuff_dma[i].map_as_page = false; |
Giuseppe Cavallaro | 553e2ab | 2016-02-29 14:27:31 +0100 | [diff] [blame] | 1097 | priv->tx_skbuff_dma[i].len = 0; |
Giuseppe Cavallaro | 2a6d8e1 | 2016-02-29 14:27:32 +0100 | [diff] [blame] | 1098 | priv->tx_skbuff_dma[i].last_segment = false; |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1099 | priv->tx_skbuff[i] = NULL; |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 1100 | } |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1101 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1102 | priv->dirty_tx = 0; |
| 1103 | priv->cur_tx = 0; |
Beniamino Galvani | 3897957 | 2015-01-21 19:07:27 +0100 | [diff] [blame] | 1104 | netdev_reset_queue(priv->dev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1105 | |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1106 | stmmac_clear_descriptors(priv); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1107 | |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1108 | if (netif_msg_hw(priv)) |
| 1109 | stmmac_display_rings(priv); |
Bartlomiej Zolnierkiewicz | 5632913 | 2013-08-09 14:02:08 +0200 | [diff] [blame] | 1110 | |
| 1111 | return 0; |
| 1112 | err_init_rx_buffers: |
| 1113 | while (--i >= 0) |
| 1114 | stmmac_free_rx_buffers(priv, i); |
Bartlomiej Zolnierkiewicz | 5632913 | 2013-08-09 14:02:08 +0200 | [diff] [blame] | 1115 | return ret; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | static void dma_free_rx_skbufs(struct stmmac_priv *priv) |
| 1119 | { |
| 1120 | int i; |
| 1121 | |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1122 | for (i = 0; i < DMA_RX_SIZE; i++) |
Bartlomiej Zolnierkiewicz | 5632913 | 2013-08-09 14:02:08 +0200 | [diff] [blame] | 1123 | stmmac_free_rx_buffers(priv, i); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | static void dma_free_tx_skbufs(struct stmmac_priv *priv) |
| 1127 | { |
| 1128 | int i; |
| 1129 | |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1130 | for (i = 0; i < DMA_TX_SIZE; i++) { |
damuzi000 | 75e4364 | 2014-01-17 23:47:59 +0800 | [diff] [blame] | 1131 | struct dma_desc *p; |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1132 | |
damuzi000 | 75e4364 | 2014-01-17 23:47:59 +0800 | [diff] [blame] | 1133 | if (priv->extend_desc) |
| 1134 | p = &((priv->dma_etx + i)->basic); |
| 1135 | else |
| 1136 | p = priv->dma_tx + i; |
| 1137 | |
Giuseppe CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 1138 | if (priv->tx_skbuff_dma[i].buf) { |
| 1139 | if (priv->tx_skbuff_dma[i].map_as_page) |
| 1140 | dma_unmap_page(priv->device, |
| 1141 | priv->tx_skbuff_dma[i].buf, |
Giuseppe Cavallaro | 553e2ab | 2016-02-29 14:27:31 +0100 | [diff] [blame] | 1142 | priv->tx_skbuff_dma[i].len, |
Giuseppe CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 1143 | DMA_TO_DEVICE); |
| 1144 | else |
| 1145 | dma_unmap_single(priv->device, |
| 1146 | priv->tx_skbuff_dma[i].buf, |
Giuseppe Cavallaro | 553e2ab | 2016-02-29 14:27:31 +0100 | [diff] [blame] | 1147 | priv->tx_skbuff_dma[i].len, |
Giuseppe CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 1148 | DMA_TO_DEVICE); |
damuzi000 | 75e4364 | 2014-01-17 23:47:59 +0800 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | if (priv->tx_skbuff[i] != NULL) { |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1152 | dev_kfree_skb_any(priv->tx_skbuff[i]); |
| 1153 | priv->tx_skbuff[i] = NULL; |
Giuseppe CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 1154 | priv->tx_skbuff_dma[i].buf = 0; |
| 1155 | priv->tx_skbuff_dma[i].map_as_page = false; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1156 | } |
| 1157 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1158 | } |
| 1159 | |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1160 | /** |
| 1161 | * alloc_dma_desc_resources - alloc TX/RX resources. |
| 1162 | * @priv: private structure |
| 1163 | * Description: according to which descriptor can be used (extend or basic) |
| 1164 | * this function allocates the resources for TX and RX paths. In case of |
| 1165 | * reception, for example, it pre-allocated the RX socket buffer in order to |
| 1166 | * allow zero-copy mechanism. |
| 1167 | */ |
Srinivas Kandagatla | 09f8d69 | 2014-01-16 10:52:06 +0000 | [diff] [blame] | 1168 | static int alloc_dma_desc_resources(struct stmmac_priv *priv) |
| 1169 | { |
Srinivas Kandagatla | 09f8d69 | 2014-01-16 10:52:06 +0000 | [diff] [blame] | 1170 | int ret = -ENOMEM; |
| 1171 | |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1172 | priv->rx_skbuff_dma = kmalloc_array(DMA_RX_SIZE, sizeof(dma_addr_t), |
Srinivas Kandagatla | 09f8d69 | 2014-01-16 10:52:06 +0000 | [diff] [blame] | 1173 | GFP_KERNEL); |
| 1174 | if (!priv->rx_skbuff_dma) |
| 1175 | return -ENOMEM; |
| 1176 | |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1177 | priv->rx_skbuff = kmalloc_array(DMA_RX_SIZE, sizeof(struct sk_buff *), |
Srinivas Kandagatla | 09f8d69 | 2014-01-16 10:52:06 +0000 | [diff] [blame] | 1178 | GFP_KERNEL); |
| 1179 | if (!priv->rx_skbuff) |
| 1180 | goto err_rx_skbuff; |
| 1181 | |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1182 | priv->tx_skbuff_dma = kmalloc_array(DMA_TX_SIZE, |
Giuseppe CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 1183 | sizeof(*priv->tx_skbuff_dma), |
Srinivas Kandagatla | 09f8d69 | 2014-01-16 10:52:06 +0000 | [diff] [blame] | 1184 | GFP_KERNEL); |
| 1185 | if (!priv->tx_skbuff_dma) |
| 1186 | goto err_tx_skbuff_dma; |
| 1187 | |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1188 | priv->tx_skbuff = kmalloc_array(DMA_TX_SIZE, sizeof(struct sk_buff *), |
Srinivas Kandagatla | 09f8d69 | 2014-01-16 10:52:06 +0000 | [diff] [blame] | 1189 | GFP_KERNEL); |
| 1190 | if (!priv->tx_skbuff) |
| 1191 | goto err_tx_skbuff; |
| 1192 | |
| 1193 | if (priv->extend_desc) { |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1194 | priv->dma_erx = dma_zalloc_coherent(priv->device, DMA_RX_SIZE * |
Alexey Brodkin | f159067 | 2015-06-24 11:47:41 +0300 | [diff] [blame] | 1195 | sizeof(struct |
| 1196 | dma_extended_desc), |
| 1197 | &priv->dma_rx_phy, |
| 1198 | GFP_KERNEL); |
Srinivas Kandagatla | 09f8d69 | 2014-01-16 10:52:06 +0000 | [diff] [blame] | 1199 | if (!priv->dma_erx) |
| 1200 | goto err_dma; |
| 1201 | |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1202 | priv->dma_etx = dma_zalloc_coherent(priv->device, DMA_TX_SIZE * |
Alexey Brodkin | f159067 | 2015-06-24 11:47:41 +0300 | [diff] [blame] | 1203 | sizeof(struct |
| 1204 | dma_extended_desc), |
| 1205 | &priv->dma_tx_phy, |
| 1206 | GFP_KERNEL); |
Srinivas Kandagatla | 09f8d69 | 2014-01-16 10:52:06 +0000 | [diff] [blame] | 1207 | if (!priv->dma_etx) { |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1208 | dma_free_coherent(priv->device, DMA_RX_SIZE * |
Alexey Brodkin | f159067 | 2015-06-24 11:47:41 +0300 | [diff] [blame] | 1209 | sizeof(struct dma_extended_desc), |
| 1210 | priv->dma_erx, priv->dma_rx_phy); |
Srinivas Kandagatla | 09f8d69 | 2014-01-16 10:52:06 +0000 | [diff] [blame] | 1211 | goto err_dma; |
| 1212 | } |
| 1213 | } else { |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1214 | priv->dma_rx = dma_zalloc_coherent(priv->device, DMA_RX_SIZE * |
Alexey Brodkin | f159067 | 2015-06-24 11:47:41 +0300 | [diff] [blame] | 1215 | sizeof(struct dma_desc), |
| 1216 | &priv->dma_rx_phy, |
| 1217 | GFP_KERNEL); |
Srinivas Kandagatla | 09f8d69 | 2014-01-16 10:52:06 +0000 | [diff] [blame] | 1218 | if (!priv->dma_rx) |
| 1219 | goto err_dma; |
| 1220 | |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1221 | priv->dma_tx = dma_zalloc_coherent(priv->device, DMA_TX_SIZE * |
Alexey Brodkin | f159067 | 2015-06-24 11:47:41 +0300 | [diff] [blame] | 1222 | sizeof(struct dma_desc), |
| 1223 | &priv->dma_tx_phy, |
| 1224 | GFP_KERNEL); |
Srinivas Kandagatla | 09f8d69 | 2014-01-16 10:52:06 +0000 | [diff] [blame] | 1225 | if (!priv->dma_tx) { |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1226 | dma_free_coherent(priv->device, DMA_RX_SIZE * |
Alexey Brodkin | f159067 | 2015-06-24 11:47:41 +0300 | [diff] [blame] | 1227 | sizeof(struct dma_desc), |
| 1228 | priv->dma_rx, priv->dma_rx_phy); |
Srinivas Kandagatla | 09f8d69 | 2014-01-16 10:52:06 +0000 | [diff] [blame] | 1229 | goto err_dma; |
| 1230 | } |
| 1231 | } |
| 1232 | |
| 1233 | return 0; |
| 1234 | |
| 1235 | err_dma: |
| 1236 | kfree(priv->tx_skbuff); |
| 1237 | err_tx_skbuff: |
| 1238 | kfree(priv->tx_skbuff_dma); |
| 1239 | err_tx_skbuff_dma: |
| 1240 | kfree(priv->rx_skbuff); |
| 1241 | err_rx_skbuff: |
| 1242 | kfree(priv->rx_skbuff_dma); |
| 1243 | return ret; |
| 1244 | } |
| 1245 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1246 | static void free_dma_desc_resources(struct stmmac_priv *priv) |
| 1247 | { |
| 1248 | /* Release the DMA TX/RX socket buffers */ |
| 1249 | dma_free_rx_skbufs(priv); |
| 1250 | dma_free_tx_skbufs(priv); |
| 1251 | |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 1252 | /* Free DMA regions of consistent memory previously allocated */ |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1253 | if (!priv->extend_desc) { |
| 1254 | dma_free_coherent(priv->device, |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1255 | DMA_TX_SIZE * sizeof(struct dma_desc), |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1256 | priv->dma_tx, priv->dma_tx_phy); |
| 1257 | dma_free_coherent(priv->device, |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1258 | DMA_RX_SIZE * sizeof(struct dma_desc), |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1259 | priv->dma_rx, priv->dma_rx_phy); |
| 1260 | } else { |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1261 | dma_free_coherent(priv->device, DMA_TX_SIZE * |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1262 | sizeof(struct dma_extended_desc), |
| 1263 | priv->dma_etx, priv->dma_tx_phy); |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1264 | dma_free_coherent(priv->device, DMA_RX_SIZE * |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1265 | sizeof(struct dma_extended_desc), |
| 1266 | priv->dma_erx, priv->dma_rx_phy); |
| 1267 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1268 | kfree(priv->rx_skbuff_dma); |
| 1269 | kfree(priv->rx_skbuff); |
Rayagond Kokatanur | cf32dee | 2013-03-26 04:43:09 +0000 | [diff] [blame] | 1270 | kfree(priv->tx_skbuff_dma); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1271 | kfree(priv->tx_skbuff); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | /** |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1275 | * stmmac_dma_operation_mode - HW DMA operation mode |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 1276 | * @priv: driver private structure |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1277 | * Description: it is used for configuring the DMA operation mode register in |
| 1278 | * 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] | 1279 | */ |
| 1280 | static void stmmac_dma_operation_mode(struct stmmac_priv *priv) |
| 1281 | { |
Vince Bridgers | f88203a | 2015-04-15 11:17:42 -0500 | [diff] [blame] | 1282 | int rxfifosz = priv->plat->rx_fifo_size; |
| 1283 | |
Sonic Zhang | e2a240c | 2013-08-28 18:55:39 +0800 | [diff] [blame] | 1284 | if (priv->plat->force_thresh_dma_mode) |
Vince Bridgers | f88203a | 2015-04-15 11:17:42 -0500 | [diff] [blame] | 1285 | priv->hw->dma->dma_mode(priv->ioaddr, tc, tc, rxfifosz); |
Sonic Zhang | e2a240c | 2013-08-28 18:55:39 +0800 | [diff] [blame] | 1286 | else if (priv->plat->force_sf_dma_mode || priv->plat->tx_coe) { |
Srinivas Kandagatla | 61b8013 | 2011-07-17 20:54:09 +0000 | [diff] [blame] | 1287 | /* |
| 1288 | * In case of GMAC, SF mode can be enabled |
| 1289 | * to perform the TX COE in HW. This depends on: |
Giuseppe CAVALLARO | ebbb293 | 2010-09-17 03:23:40 +0000 | [diff] [blame] | 1290 | * 1) TX COE if actually supported |
| 1291 | * 2) There is no bugged Jumbo frame support |
| 1292 | * that needs to not insert csum in the TDES. |
| 1293 | */ |
Vince Bridgers | f88203a | 2015-04-15 11:17:42 -0500 | [diff] [blame] | 1294 | priv->hw->dma->dma_mode(priv->ioaddr, SF_DMA_MODE, SF_DMA_MODE, |
| 1295 | rxfifosz); |
Sonic Zhang | b2dec11 | 2015-01-30 13:49:32 +0800 | [diff] [blame] | 1296 | priv->xstats.threshold = SF_DMA_MODE; |
Giuseppe CAVALLARO | ebbb293 | 2010-09-17 03:23:40 +0000 | [diff] [blame] | 1297 | } else |
Vince Bridgers | f88203a | 2015-04-15 11:17:42 -0500 | [diff] [blame] | 1298 | priv->hw->dma->dma_mode(priv->ioaddr, tc, SF_DMA_MODE, |
| 1299 | rxfifosz); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1300 | } |
| 1301 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1302 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1303 | * stmmac_tx_clean - to manage the transmission completion |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 1304 | * @priv: driver private structure |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1305 | * Description: it reclaims the transmit resources after transmission completes. |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1306 | */ |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 1307 | static void stmmac_tx_clean(struct stmmac_priv *priv) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1308 | { |
Beniamino Galvani | 3897957 | 2015-01-21 19:07:27 +0100 | [diff] [blame] | 1309 | unsigned int bytes_compl = 0, pkts_compl = 0; |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1310 | unsigned int entry = priv->dirty_tx; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1311 | |
Giuseppe CAVALLARO | a9097a9 | 2011-10-18 00:01:19 +0000 | [diff] [blame] | 1312 | spin_lock(&priv->tx_lock); |
| 1313 | |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 1314 | priv->xstats.tx_clean++; |
| 1315 | |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1316 | while (entry != priv->cur_tx) { |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1317 | struct sk_buff *skb = priv->tx_skbuff[entry]; |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1318 | struct dma_desc *p; |
Fabrice Gasnier | c363b65 | 2016-02-29 14:27:36 +0100 | [diff] [blame] | 1319 | int status; |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1320 | |
| 1321 | if (priv->extend_desc) |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 1322 | p = (struct dma_desc *)(priv->dma_etx + entry); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1323 | else |
| 1324 | p = priv->dma_tx + entry; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1325 | |
Fabrice Gasnier | c363b65 | 2016-02-29 14:27:36 +0100 | [diff] [blame] | 1326 | status = priv->hw->desc->tx_status(&priv->dev->stats, |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 1327 | &priv->xstats, p, |
| 1328 | priv->ioaddr); |
Fabrice Gasnier | c363b65 | 2016-02-29 14:27:36 +0100 | [diff] [blame] | 1329 | /* Check if the descriptor is owned by the DMA */ |
| 1330 | if (unlikely(status & tx_dma_own)) |
| 1331 | break; |
| 1332 | |
| 1333 | /* Just consider the last segment and ...*/ |
| 1334 | if (likely(!(status & tx_not_ls))) { |
| 1335 | /* ... verify the status error condition */ |
| 1336 | if (unlikely(status & tx_err)) { |
| 1337 | priv->dev->stats.tx_errors++; |
| 1338 | } else { |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1339 | priv->dev->stats.tx_packets++; |
| 1340 | priv->xstats.tx_pkt_n++; |
Fabrice Gasnier | c363b65 | 2016-02-29 14:27:36 +0100 | [diff] [blame] | 1341 | } |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 1342 | stmmac_get_tx_hwtstamp(priv, entry, skb); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1343 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1344 | |
Giuseppe CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 1345 | if (likely(priv->tx_skbuff_dma[entry].buf)) { |
| 1346 | if (priv->tx_skbuff_dma[entry].map_as_page) |
| 1347 | dma_unmap_page(priv->device, |
| 1348 | priv->tx_skbuff_dma[entry].buf, |
Giuseppe Cavallaro | 553e2ab | 2016-02-29 14:27:31 +0100 | [diff] [blame] | 1349 | priv->tx_skbuff_dma[entry].len, |
Giuseppe CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 1350 | DMA_TO_DEVICE); |
| 1351 | else |
| 1352 | dma_unmap_single(priv->device, |
| 1353 | priv->tx_skbuff_dma[entry].buf, |
Giuseppe Cavallaro | 553e2ab | 2016-02-29 14:27:31 +0100 | [diff] [blame] | 1354 | priv->tx_skbuff_dma[entry].len, |
Giuseppe CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 1355 | DMA_TO_DEVICE); |
| 1356 | priv->tx_skbuff_dma[entry].buf = 0; |
| 1357 | priv->tx_skbuff_dma[entry].map_as_page = false; |
Rayagond Kokatanur | cf32dee | 2013-03-26 04:43:09 +0000 | [diff] [blame] | 1358 | } |
Giuseppe CAVALLARO | 29896a6 | 2014-03-10 13:40:33 +0100 | [diff] [blame] | 1359 | priv->hw->mode->clean_desc3(priv, p); |
Giuseppe Cavallaro | 2a6d8e1 | 2016-02-29 14:27:32 +0100 | [diff] [blame] | 1360 | priv->tx_skbuff_dma[entry].last_segment = false; |
Giuseppe Cavallaro | 9695136 | 2016-02-29 14:27:33 +0100 | [diff] [blame] | 1361 | priv->tx_skbuff_dma[entry].is_jumbo = false; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1362 | |
| 1363 | if (likely(skb != NULL)) { |
Beniamino Galvani | 3897957 | 2015-01-21 19:07:27 +0100 | [diff] [blame] | 1364 | pkts_compl++; |
| 1365 | bytes_compl += skb->len; |
Eric W. Biederman | 7c565c3 | 2014-03-15 18:11:09 -0700 | [diff] [blame] | 1366 | dev_consume_skb_any(skb); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1367 | priv->tx_skbuff[entry] = NULL; |
| 1368 | } |
| 1369 | |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 1370 | priv->hw->desc->release_tx_desc(p, priv->mode); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1371 | |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1372 | entry = STMMAC_GET_ENTRY(entry, DMA_TX_SIZE); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1373 | } |
Giuseppe Cavallaro | fbc8082 | 2016-02-29 14:27:37 +0100 | [diff] [blame] | 1374 | priv->dirty_tx = entry; |
Beniamino Galvani | 3897957 | 2015-01-21 19:07:27 +0100 | [diff] [blame] | 1375 | |
| 1376 | netdev_completed_queue(priv->dev, pkts_compl, bytes_compl); |
| 1377 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1378 | if (unlikely(netif_queue_stopped(priv->dev) && |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1379 | stmmac_tx_avail(priv) > STMMAC_TX_THRESH)) { |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1380 | netif_tx_lock(priv->dev); |
| 1381 | if (netif_queue_stopped(priv->dev) && |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1382 | stmmac_tx_avail(priv) > STMMAC_TX_THRESH) { |
Giuseppe CAVALLARO | 83d7af6 | 2013-07-02 14:12:36 +0200 | [diff] [blame] | 1383 | if (netif_msg_tx_done(priv)) |
| 1384 | pr_debug("%s: restart transmit\n", __func__); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1385 | netif_wake_queue(priv->dev); |
| 1386 | } |
| 1387 | netif_tx_unlock(priv->dev); |
| 1388 | } |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 1389 | |
| 1390 | if ((priv->eee_enabled) && (!priv->tx_path_in_lpi_mode)) { |
| 1391 | stmmac_enable_eee_mode(priv); |
Giuseppe CAVALLARO | f5351ef | 2013-06-18 07:03:23 +0200 | [diff] [blame] | 1392 | mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_T(eee_timer)); |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 1393 | } |
Giuseppe CAVALLARO | a9097a9 | 2011-10-18 00:01:19 +0000 | [diff] [blame] | 1394 | spin_unlock(&priv->tx_lock); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1395 | } |
| 1396 | |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 1397 | static inline void stmmac_enable_dma_irq(struct stmmac_priv *priv) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1398 | { |
Giuseppe CAVALLARO | 7284a3f | 2012-11-25 23:10:41 +0000 | [diff] [blame] | 1399 | priv->hw->dma->enable_dma_irq(priv->ioaddr); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1400 | } |
| 1401 | |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 1402 | static inline void stmmac_disable_dma_irq(struct stmmac_priv *priv) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1403 | { |
Giuseppe CAVALLARO | 7284a3f | 2012-11-25 23:10:41 +0000 | [diff] [blame] | 1404 | priv->hw->dma->disable_dma_irq(priv->ioaddr); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1405 | } |
| 1406 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1407 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1408 | * stmmac_tx_err - to manage the tx error |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 1409 | * @priv: driver private structure |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1410 | * Description: it cleans the descriptors and restarts the transmission |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1411 | * in case of transmission errors. |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1412 | */ |
| 1413 | static void stmmac_tx_err(struct stmmac_priv *priv) |
| 1414 | { |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1415 | int i; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1416 | netif_stop_queue(priv->dev); |
| 1417 | |
Giuseppe CAVALLARO | ad01b7d | 2010-08-23 20:40:42 +0000 | [diff] [blame] | 1418 | priv->hw->dma->stop_tx(priv->ioaddr); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1419 | dma_free_tx_skbufs(priv); |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1420 | for (i = 0; i < DMA_TX_SIZE; i++) |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1421 | if (priv->extend_desc) |
| 1422 | priv->hw->desc->init_tx_desc(&priv->dma_etx[i].basic, |
| 1423 | priv->mode, |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1424 | (i == DMA_TX_SIZE - 1)); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1425 | else |
| 1426 | priv->hw->desc->init_tx_desc(&priv->dma_tx[i], |
| 1427 | priv->mode, |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1428 | (i == DMA_TX_SIZE - 1)); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1429 | priv->dirty_tx = 0; |
| 1430 | priv->cur_tx = 0; |
Beniamino Galvani | 3897957 | 2015-01-21 19:07:27 +0100 | [diff] [blame] | 1431 | netdev_reset_queue(priv->dev); |
Giuseppe CAVALLARO | ad01b7d | 2010-08-23 20:40:42 +0000 | [diff] [blame] | 1432 | priv->hw->dma->start_tx(priv->ioaddr); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1433 | |
| 1434 | priv->dev->stats.tx_errors++; |
| 1435 | netif_wake_queue(priv->dev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1436 | } |
| 1437 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 1438 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1439 | * stmmac_dma_interrupt - DMA ISR |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 1440 | * @priv: driver private structure |
| 1441 | * 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] | 1442 | * It calls the dwmac dma routine and schedule poll method in case of some |
| 1443 | * work can be done. |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 1444 | */ |
Giuseppe CAVALLARO | aec7ff2 | 2010-01-06 23:07:18 +0000 | [diff] [blame] | 1445 | static void stmmac_dma_interrupt(struct stmmac_priv *priv) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1446 | { |
Giuseppe CAVALLARO | aec7ff2 | 2010-01-06 23:07:18 +0000 | [diff] [blame] | 1447 | int status; |
Vince Bridgers | f88203a | 2015-04-15 11:17:42 -0500 | [diff] [blame] | 1448 | int rxfifosz = priv->plat->rx_fifo_size; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1449 | |
Giuseppe CAVALLARO | ad01b7d | 2010-08-23 20:40:42 +0000 | [diff] [blame] | 1450 | status = priv->hw->dma->dma_interrupt(priv->ioaddr, &priv->xstats); |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 1451 | if (likely((status & handle_rx)) || (status & handle_tx)) { |
| 1452 | if (likely(napi_schedule_prep(&priv->napi))) { |
| 1453 | stmmac_disable_dma_irq(priv); |
| 1454 | __napi_schedule(&priv->napi); |
| 1455 | } |
| 1456 | } |
| 1457 | if (unlikely(status & tx_hard_error_bump_tc)) { |
Giuseppe CAVALLARO | aec7ff2 | 2010-01-06 23:07:18 +0000 | [diff] [blame] | 1458 | /* Try to bump up the dma threshold on this failure */ |
Sonic Zhang | b2dec11 | 2015-01-30 13:49:32 +0800 | [diff] [blame] | 1459 | if (unlikely(priv->xstats.threshold != SF_DMA_MODE) && |
| 1460 | (tc <= 256)) { |
Giuseppe CAVALLARO | aec7ff2 | 2010-01-06 23:07:18 +0000 | [diff] [blame] | 1461 | tc += 64; |
Sonic Zhang | c405abe | 2015-01-22 14:55:56 +0800 | [diff] [blame] | 1462 | if (priv->plat->force_thresh_dma_mode) |
Vince Bridgers | f88203a | 2015-04-15 11:17:42 -0500 | [diff] [blame] | 1463 | priv->hw->dma->dma_mode(priv->ioaddr, tc, tc, |
| 1464 | rxfifosz); |
Sonic Zhang | c405abe | 2015-01-22 14:55:56 +0800 | [diff] [blame] | 1465 | else |
| 1466 | priv->hw->dma->dma_mode(priv->ioaddr, tc, |
Vince Bridgers | f88203a | 2015-04-15 11:17:42 -0500 | [diff] [blame] | 1467 | SF_DMA_MODE, rxfifosz); |
Giuseppe CAVALLARO | aec7ff2 | 2010-01-06 23:07:18 +0000 | [diff] [blame] | 1468 | priv->xstats.threshold = tc; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1469 | } |
Giuseppe CAVALLARO | aec7ff2 | 2010-01-06 23:07:18 +0000 | [diff] [blame] | 1470 | } else if (unlikely(status == tx_hard_error)) |
| 1471 | stmmac_tx_err(priv); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1472 | } |
| 1473 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 1474 | /** |
| 1475 | * stmmac_mmc_setup: setup the Mac Management Counters (MMC) |
| 1476 | * @priv: driver private structure |
| 1477 | * Description: this masks the MMC irq, in fact, the counters are managed in SW. |
| 1478 | */ |
Giuseppe CAVALLARO | 1c901a4 | 2011-09-01 21:51:38 +0000 | [diff] [blame] | 1479 | static void stmmac_mmc_setup(struct stmmac_priv *priv) |
| 1480 | { |
| 1481 | unsigned int mode = MMC_CNTRL_RESET_ON_READ | MMC_CNTRL_COUNTER_RESET | |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 1482 | MMC_CNTRL_PRESET | MMC_CNTRL_FULL_HALF_PRESET; |
Giuseppe CAVALLARO | 1c901a4 | 2011-09-01 21:51:38 +0000 | [diff] [blame] | 1483 | |
Giuseppe CAVALLARO | 1c901a4 | 2011-09-01 21:51:38 +0000 | [diff] [blame] | 1484 | dwmac_mmc_intr_all_mask(priv->ioaddr); |
Giuseppe CAVALLARO | 4f795b2 | 2011-11-18 05:00:20 +0000 | [diff] [blame] | 1485 | |
| 1486 | if (priv->dma_cap.rmon) { |
| 1487 | dwmac_mmc_ctrl(priv->ioaddr, mode); |
| 1488 | memset(&priv->mmc, 0, sizeof(struct stmmac_counters)); |
| 1489 | } else |
Stefan Roese | aae54cf | 2012-01-10 01:47:51 +0000 | [diff] [blame] | 1490 | pr_info(" No MAC Management Counters available\n"); |
Giuseppe CAVALLARO | 1c901a4 | 2011-09-01 21:51:38 +0000 | [diff] [blame] | 1491 | } |
| 1492 | |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1493 | /** |
| 1494 | * stmmac_get_synopsys_id - return the SYINID. |
| 1495 | * @priv: driver private structure |
| 1496 | * Description: this simple function is to decode and return the SYINID |
| 1497 | * starting from the HW core register. |
| 1498 | */ |
Giuseppe CAVALLARO | f0b9d78 | 2011-09-01 21:51:40 +0000 | [diff] [blame] | 1499 | static u32 stmmac_get_synopsys_id(struct stmmac_priv *priv) |
| 1500 | { |
| 1501 | u32 hwid = priv->hw->synopsys_uid; |
| 1502 | |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 1503 | /* Check Synopsys Id (not available on old chips) */ |
Giuseppe CAVALLARO | f0b9d78 | 2011-09-01 21:51:40 +0000 | [diff] [blame] | 1504 | if (likely(hwid)) { |
| 1505 | u32 uid = ((hwid & 0x0000ff00) >> 8); |
| 1506 | u32 synid = (hwid & 0x000000ff); |
| 1507 | |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 1508 | pr_info("stmmac - user ID: 0x%x, Synopsys ID: 0x%x\n", |
Giuseppe CAVALLARO | f0b9d78 | 2011-09-01 21:51:40 +0000 | [diff] [blame] | 1509 | uid, synid); |
| 1510 | |
| 1511 | return synid; |
| 1512 | } |
| 1513 | return 0; |
| 1514 | } |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 1515 | |
Giuseppe CAVALLARO | 19e30c1 | 2011-11-16 21:58:00 +0000 | [diff] [blame] | 1516 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1517 | * stmmac_selec_desc_mode - to select among: normal/alternate/extend descriptors |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 1518 | * @priv: driver private structure |
| 1519 | * Description: select the Enhanced/Alternate or Normal descriptors. |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1520 | * In case of Enhanced/Alternate, it checks if the extended descriptors are |
| 1521 | * supported by the HW capability register. |
Giuseppe CAVALLARO | ff3dd78 | 2012-06-04 19:22:55 +0000 | [diff] [blame] | 1522 | */ |
Giuseppe CAVALLARO | 19e30c1 | 2011-11-16 21:58:00 +0000 | [diff] [blame] | 1523 | static void stmmac_selec_desc_mode(struct stmmac_priv *priv) |
| 1524 | { |
| 1525 | if (priv->plat->enh_desc) { |
| 1526 | pr_info(" Enhanced/Alternate descriptors\n"); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1527 | |
| 1528 | /* GMAC older than 3.50 has no extended descriptors */ |
| 1529 | if (priv->synopsys_id >= DWMAC_CORE_3_50) { |
| 1530 | pr_info("\tEnabled extended descriptors\n"); |
| 1531 | priv->extend_desc = 1; |
| 1532 | } else |
| 1533 | pr_warn("Extended descriptors not supported\n"); |
| 1534 | |
Giuseppe CAVALLARO | 19e30c1 | 2011-11-16 21:58:00 +0000 | [diff] [blame] | 1535 | priv->hw->desc = &enh_desc_ops; |
| 1536 | } else { |
| 1537 | pr_info(" Normal descriptors\n"); |
| 1538 | priv->hw->desc = &ndesc_ops; |
| 1539 | } |
| 1540 | } |
| 1541 | |
| 1542 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1543 | * stmmac_get_hw_features - get MAC capabilities from the HW cap. register. |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 1544 | * @priv: driver private structure |
Giuseppe CAVALLARO | 19e30c1 | 2011-11-16 21:58:00 +0000 | [diff] [blame] | 1545 | * Description: |
| 1546 | * new GMAC chip generations have a new register to indicate the |
| 1547 | * presence of the optional feature/functions. |
| 1548 | * This can be also used to override the value passed through the |
| 1549 | * platform and necessary for old MAC10/100 and GMAC chips. |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 1550 | */ |
| 1551 | static int stmmac_get_hw_features(struct stmmac_priv *priv) |
| 1552 | { |
Giuseppe CAVALLARO | 5e6efe8 | 2011-10-26 19:43:07 +0000 | [diff] [blame] | 1553 | u32 hw_cap = 0; |
Giuseppe CAVALLARO | 3c20f72 | 2011-10-26 19:43:09 +0000 | [diff] [blame] | 1554 | |
Giuseppe CAVALLARO | 5e6efe8 | 2011-10-26 19:43:07 +0000 | [diff] [blame] | 1555 | if (priv->hw->dma->get_hw_feature) { |
| 1556 | hw_cap = priv->hw->dma->get_hw_feature(priv->ioaddr); |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 1557 | |
Rayagond Kokatanur | 1db123f | 2011-10-18 00:01:22 +0000 | [diff] [blame] | 1558 | priv->dma_cap.mbps_10_100 = (hw_cap & DMA_HW_FEAT_MIISEL); |
| 1559 | priv->dma_cap.mbps_1000 = (hw_cap & DMA_HW_FEAT_GMIISEL) >> 1; |
| 1560 | priv->dma_cap.half_duplex = (hw_cap & DMA_HW_FEAT_HDSEL) >> 2; |
| 1561 | priv->dma_cap.hash_filter = (hw_cap & DMA_HW_FEAT_HASHSEL) >> 4; |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 1562 | priv->dma_cap.multi_addr = (hw_cap & DMA_HW_FEAT_ADDMAC) >> 5; |
Rayagond Kokatanur | 1db123f | 2011-10-18 00:01:22 +0000 | [diff] [blame] | 1563 | priv->dma_cap.pcs = (hw_cap & DMA_HW_FEAT_PCSSEL) >> 6; |
| 1564 | priv->dma_cap.sma_mdio = (hw_cap & DMA_HW_FEAT_SMASEL) >> 8; |
| 1565 | priv->dma_cap.pmt_remote_wake_up = |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 1566 | (hw_cap & DMA_HW_FEAT_RWKSEL) >> 9; |
Rayagond Kokatanur | 1db123f | 2011-10-18 00:01:22 +0000 | [diff] [blame] | 1567 | priv->dma_cap.pmt_magic_frame = |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 1568 | (hw_cap & DMA_HW_FEAT_MGKSEL) >> 10; |
Giuseppe CAVALLARO | 19e30c1 | 2011-11-16 21:58:00 +0000 | [diff] [blame] | 1569 | /* MMC */ |
Rayagond Kokatanur | 1db123f | 2011-10-18 00:01:22 +0000 | [diff] [blame] | 1570 | priv->dma_cap.rmon = (hw_cap & DMA_HW_FEAT_MMCSEL) >> 11; |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 1571 | /* IEEE 1588-2002 */ |
Rayagond Kokatanur | 1db123f | 2011-10-18 00:01:22 +0000 | [diff] [blame] | 1572 | priv->dma_cap.time_stamp = |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 1573 | (hw_cap & DMA_HW_FEAT_TSVER1SEL) >> 12; |
| 1574 | /* IEEE 1588-2008 */ |
Rayagond Kokatanur | 1db123f | 2011-10-18 00:01:22 +0000 | [diff] [blame] | 1575 | priv->dma_cap.atime_stamp = |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 1576 | (hw_cap & DMA_HW_FEAT_TSVER2SEL) >> 13; |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 1577 | /* 802.3az - Energy-Efficient Ethernet (EEE) */ |
Rayagond Kokatanur | 1db123f | 2011-10-18 00:01:22 +0000 | [diff] [blame] | 1578 | priv->dma_cap.eee = (hw_cap & DMA_HW_FEAT_EEESEL) >> 14; |
| 1579 | priv->dma_cap.av = (hw_cap & DMA_HW_FEAT_AVSEL) >> 15; |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 1580 | /* TX and RX csum */ |
Rayagond Kokatanur | 1db123f | 2011-10-18 00:01:22 +0000 | [diff] [blame] | 1581 | priv->dma_cap.tx_coe = (hw_cap & DMA_HW_FEAT_TXCOESEL) >> 16; |
| 1582 | priv->dma_cap.rx_coe_type1 = |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 1583 | (hw_cap & DMA_HW_FEAT_RXTYP1COE) >> 17; |
Rayagond Kokatanur | 1db123f | 2011-10-18 00:01:22 +0000 | [diff] [blame] | 1584 | priv->dma_cap.rx_coe_type2 = |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 1585 | (hw_cap & DMA_HW_FEAT_RXTYP2COE) >> 18; |
Rayagond Kokatanur | 1db123f | 2011-10-18 00:01:22 +0000 | [diff] [blame] | 1586 | priv->dma_cap.rxfifo_over_2048 = |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 1587 | (hw_cap & DMA_HW_FEAT_RXFIFOSIZE) >> 19; |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 1588 | /* TX and RX number of channels */ |
Rayagond Kokatanur | 1db123f | 2011-10-18 00:01:22 +0000 | [diff] [blame] | 1589 | priv->dma_cap.number_rx_channel = |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 1590 | (hw_cap & DMA_HW_FEAT_RXCHCNT) >> 20; |
Rayagond Kokatanur | 1db123f | 2011-10-18 00:01:22 +0000 | [diff] [blame] | 1591 | priv->dma_cap.number_tx_channel = |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 1592 | (hw_cap & DMA_HW_FEAT_TXCHCNT) >> 22; |
| 1593 | /* Alternate (enhanced) DESC mode */ |
| 1594 | priv->dma_cap.enh_desc = (hw_cap & DMA_HW_FEAT_ENHDESSEL) >> 24; |
Giuseppe CAVALLARO | 19e30c1 | 2011-11-16 21:58:00 +0000 | [diff] [blame] | 1595 | } |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 1596 | |
| 1597 | return hw_cap; |
| 1598 | } |
| 1599 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 1600 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1601 | * stmmac_check_ether_addr - check if the MAC addr is valid |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 1602 | * @priv: driver private structure |
| 1603 | * Description: |
| 1604 | * it is to verify if the MAC address is valid, in case of failures it |
| 1605 | * generates a random MAC address |
| 1606 | */ |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1607 | static void stmmac_check_ether_addr(struct stmmac_priv *priv) |
| 1608 | { |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1609 | if (!is_valid_ether_addr(priv->dev->dev_addr)) { |
Vince Bridgers | 7ed24bb | 2014-07-31 15:49:13 -0500 | [diff] [blame] | 1610 | priv->hw->mac->get_umac_addr(priv->hw, |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1611 | priv->dev->dev_addr, 0); |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 1612 | if (!is_valid_ether_addr(priv->dev->dev_addr)) |
Danny Kukawka | f2cedb6 | 2012-02-15 06:45:39 +0000 | [diff] [blame] | 1613 | eth_hw_addr_random(priv->dev); |
Hans de Goede | c88460b | 2014-01-26 15:50:44 +0100 | [diff] [blame] | 1614 | pr_info("%s: device MAC address %pM\n", priv->dev->name, |
| 1615 | priv->dev->dev_addr); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1616 | } |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1617 | } |
| 1618 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 1619 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1620 | * stmmac_init_dma_engine - DMA init. |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 1621 | * @priv: driver private structure |
| 1622 | * Description: |
| 1623 | * It inits the DMA invoking the specific MAC/GMAC callback. |
| 1624 | * Some DMA parameters can be passed from the platform; |
| 1625 | * in case of these are not passed a default is kept for the MAC or GMAC. |
| 1626 | */ |
Giuseppe CAVALLARO | 0f1f88a | 2012-04-18 19:48:21 +0000 | [diff] [blame] | 1627 | static int stmmac_init_dma_engine(struct stmmac_priv *priv) |
| 1628 | { |
Giuseppe Cavallaro | afea036 | 2016-02-29 14:27:28 +0100 | [diff] [blame] | 1629 | int pbl = DEFAULT_DMA_PBL, fixed_burst = 0, aal = 0; |
Giuseppe CAVALLARO | b9cde0a | 2012-05-13 22:18:42 +0000 | [diff] [blame] | 1630 | int mixed_burst = 0; |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1631 | int atds = 0; |
Giuseppe Cavallaro | 495db27 | 2016-02-29 14:27:27 +0100 | [diff] [blame] | 1632 | int ret = 0; |
Giuseppe CAVALLARO | 0f1f88a | 2012-04-18 19:48:21 +0000 | [diff] [blame] | 1633 | |
Giuseppe CAVALLARO | 0f1f88a | 2012-04-18 19:48:21 +0000 | [diff] [blame] | 1634 | if (priv->plat->dma_cfg) { |
| 1635 | pbl = priv->plat->dma_cfg->pbl; |
| 1636 | fixed_burst = priv->plat->dma_cfg->fixed_burst; |
Giuseppe CAVALLARO | b9cde0a | 2012-05-13 22:18:42 +0000 | [diff] [blame] | 1637 | mixed_burst = priv->plat->dma_cfg->mixed_burst; |
Giuseppe Cavallaro | afea036 | 2016-02-29 14:27:28 +0100 | [diff] [blame] | 1638 | aal = priv->plat->dma_cfg->aal; |
Giuseppe CAVALLARO | 0f1f88a | 2012-04-18 19:48:21 +0000 | [diff] [blame] | 1639 | } |
| 1640 | |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1641 | if (priv->extend_desc && (priv->mode == STMMAC_RING_MODE)) |
| 1642 | atds = 1; |
| 1643 | |
Giuseppe Cavallaro | 495db27 | 2016-02-29 14:27:27 +0100 | [diff] [blame] | 1644 | ret = priv->hw->dma->reset(priv->ioaddr); |
| 1645 | if (ret) { |
| 1646 | dev_err(priv->device, "Failed to reset the dma\n"); |
| 1647 | return ret; |
| 1648 | } |
| 1649 | |
| 1650 | priv->hw->dma->init(priv->ioaddr, pbl, fixed_burst, mixed_burst, |
Giuseppe Cavallaro | afea036 | 2016-02-29 14:27:28 +0100 | [diff] [blame] | 1651 | aal, priv->dma_tx_phy, priv->dma_rx_phy, atds); |
| 1652 | |
| 1653 | if ((priv->synopsys_id >= DWMAC_CORE_3_50) && |
| 1654 | (priv->plat->axi && priv->hw->dma->axi)) |
| 1655 | priv->hw->dma->axi(priv->ioaddr, priv->plat->axi); |
| 1656 | |
Giuseppe Cavallaro | 495db27 | 2016-02-29 14:27:27 +0100 | [diff] [blame] | 1657 | return ret; |
Giuseppe CAVALLARO | 0f1f88a | 2012-04-18 19:48:21 +0000 | [diff] [blame] | 1658 | } |
| 1659 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1660 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1661 | * stmmac_tx_timer - mitigation sw timer for tx. |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 1662 | * @data: data pointer |
| 1663 | * Description: |
| 1664 | * This is the timer handler to directly invoke the stmmac_tx_clean. |
| 1665 | */ |
| 1666 | static void stmmac_tx_timer(unsigned long data) |
| 1667 | { |
| 1668 | struct stmmac_priv *priv = (struct stmmac_priv *)data; |
| 1669 | |
| 1670 | stmmac_tx_clean(priv); |
| 1671 | } |
| 1672 | |
| 1673 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1674 | * stmmac_init_tx_coalesce - init tx mitigation options. |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 1675 | * @priv: driver private structure |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 1676 | * Description: |
| 1677 | * This inits the transmit coalesce parameters: i.e. timer rate, |
| 1678 | * timer handler and default threshold used for enabling the |
| 1679 | * interrupt on completion bit. |
| 1680 | */ |
| 1681 | static void stmmac_init_tx_coalesce(struct stmmac_priv *priv) |
| 1682 | { |
| 1683 | priv->tx_coal_frames = STMMAC_TX_FRAMES; |
| 1684 | priv->tx_coal_timer = STMMAC_COAL_TX_TIMER; |
| 1685 | init_timer(&priv->txtimer); |
| 1686 | priv->txtimer.expires = STMMAC_COAL_TIMER(priv->tx_coal_timer); |
| 1687 | priv->txtimer.data = (unsigned long)priv; |
| 1688 | priv->txtimer.function = stmmac_tx_timer; |
| 1689 | add_timer(&priv->txtimer); |
| 1690 | } |
| 1691 | |
| 1692 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1693 | * stmmac_hw_setup - setup mac in a usable state. |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 1694 | * @dev : pointer to the device structure. |
| 1695 | * Description: |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1696 | * this is the main function to setup the HW in a usable state because the |
| 1697 | * dma engine is reset, the core registers are configured (e.g. AXI, |
| 1698 | * Checksum features, timers). The DMA is ready to start receiving and |
| 1699 | * transmitting. |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 1700 | * Return value: |
| 1701 | * 0 on success and an appropriate (-)ve integer as defined in errno.h |
| 1702 | * file on failure. |
| 1703 | */ |
Huacai Chen | fe131929 | 2014-12-19 22:38:18 +0800 | [diff] [blame] | 1704 | static int stmmac_hw_setup(struct net_device *dev, bool init_ptp) |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 1705 | { |
| 1706 | struct stmmac_priv *priv = netdev_priv(dev); |
| 1707 | int ret; |
| 1708 | |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 1709 | /* DMA initialization and SW reset */ |
| 1710 | ret = stmmac_init_dma_engine(priv); |
| 1711 | if (ret < 0) { |
| 1712 | pr_err("%s: DMA engine initialization failed\n", __func__); |
| 1713 | return ret; |
| 1714 | } |
| 1715 | |
| 1716 | /* Copy the MAC addr into the HW */ |
Vince Bridgers | 7ed24bb | 2014-07-31 15:49:13 -0500 | [diff] [blame] | 1717 | priv->hw->mac->set_umac_addr(priv->hw, dev->dev_addr, 0); |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 1718 | |
| 1719 | /* If required, perform hw setup of the bus. */ |
| 1720 | if (priv->plat->bus_setup) |
| 1721 | priv->plat->bus_setup(priv->ioaddr); |
| 1722 | |
| 1723 | /* Initialize the MAC Core */ |
Vince Bridgers | 7ed24bb | 2014-07-31 15:49:13 -0500 | [diff] [blame] | 1724 | priv->hw->mac->core_init(priv->hw, dev->mtu); |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 1725 | |
Giuseppe CAVALLARO | 978aded | 2014-08-25 14:56:18 +0200 | [diff] [blame] | 1726 | ret = priv->hw->mac->rx_ipc(priv->hw); |
| 1727 | if (!ret) { |
| 1728 | pr_warn(" RX IPC Checksum Offload disabled\n"); |
| 1729 | priv->plat->rx_coe = STMMAC_RX_COE_NONE; |
Giuseppe CAVALLARO | d2afb5b | 2014-09-01 09:17:52 +0200 | [diff] [blame] | 1730 | priv->hw->rx_csum = 0; |
Giuseppe CAVALLARO | 978aded | 2014-08-25 14:56:18 +0200 | [diff] [blame] | 1731 | } |
| 1732 | |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 1733 | /* Enable the MAC Rx/Tx */ |
| 1734 | stmmac_set_mac(priv->ioaddr, true); |
| 1735 | |
| 1736 | /* Set the HW DMA mode and the COE */ |
| 1737 | stmmac_dma_operation_mode(priv); |
| 1738 | |
| 1739 | stmmac_mmc_setup(priv); |
| 1740 | |
Huacai Chen | fe131929 | 2014-12-19 22:38:18 +0800 | [diff] [blame] | 1741 | if (init_ptp) { |
| 1742 | ret = stmmac_init_ptp(priv); |
| 1743 | if (ret && ret != -EOPNOTSUPP) |
| 1744 | pr_warn("%s: failed PTP initialisation\n", __func__); |
| 1745 | } |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 1746 | |
Giuseppe CAVALLARO | 50fb4f74 | 2014-11-04 15:49:33 +0100 | [diff] [blame] | 1747 | #ifdef CONFIG_DEBUG_FS |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 1748 | ret = stmmac_init_fs(dev); |
| 1749 | if (ret < 0) |
| 1750 | pr_warn("%s: failed debugFS registration\n", __func__); |
| 1751 | #endif |
| 1752 | /* Start the ball rolling... */ |
| 1753 | pr_debug("%s: DMA RX/TX processes started...\n", dev->name); |
| 1754 | priv->hw->dma->start_tx(priv->ioaddr); |
| 1755 | priv->hw->dma->start_rx(priv->ioaddr); |
| 1756 | |
| 1757 | /* Dump DMA/MAC registers */ |
| 1758 | if (netif_msg_hw(priv)) { |
Vince Bridgers | 7ed24bb | 2014-07-31 15:49:13 -0500 | [diff] [blame] | 1759 | priv->hw->mac->dump_regs(priv->hw); |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 1760 | priv->hw->dma->dump_regs(priv->ioaddr); |
| 1761 | } |
| 1762 | priv->tx_lpi_timer = STMMAC_DEFAULT_TWT_LS; |
| 1763 | |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 1764 | if ((priv->use_riwt) && (priv->hw->dma->rx_watchdog)) { |
| 1765 | priv->rx_riwt = MAX_DMA_RIWT; |
| 1766 | priv->hw->dma->rx_watchdog(priv->ioaddr, MAX_DMA_RIWT); |
| 1767 | } |
| 1768 | |
| 1769 | if (priv->pcs && priv->hw->mac->ctrl_ane) |
Vince Bridgers | 7ed24bb | 2014-07-31 15:49:13 -0500 | [diff] [blame] | 1770 | priv->hw->mac->ctrl_ane(priv->hw, 0); |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 1771 | |
| 1772 | return 0; |
| 1773 | } |
| 1774 | |
| 1775 | /** |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1776 | * stmmac_open - open entry point of the driver |
| 1777 | * @dev : pointer to the device structure. |
| 1778 | * Description: |
| 1779 | * This function is the open entry point of the driver. |
| 1780 | * Return value: |
| 1781 | * 0 on success and an appropriate (-)ve integer as defined in errno.h |
| 1782 | * file on failure. |
| 1783 | */ |
| 1784 | static int stmmac_open(struct net_device *dev) |
| 1785 | { |
| 1786 | struct stmmac_priv *priv = netdev_priv(dev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1787 | int ret; |
| 1788 | |
Francesco Virlinzi | 4bfcbd7 | 2012-04-18 19:48:20 +0000 | [diff] [blame] | 1789 | stmmac_check_ether_addr(priv); |
| 1790 | |
Byungho An | 4d8f082 | 2013-04-07 17:56:16 +0000 | [diff] [blame] | 1791 | if (priv->pcs != STMMAC_PCS_RGMII && priv->pcs != STMMAC_PCS_TBI && |
| 1792 | priv->pcs != STMMAC_PCS_RTBI) { |
Giuseppe CAVALLARO | e58bb43 | 2013-03-26 04:43:08 +0000 | [diff] [blame] | 1793 | ret = stmmac_init_phy(dev); |
| 1794 | if (ret) { |
| 1795 | pr_err("%s: Cannot attach to PHY (error: %d)\n", |
| 1796 | __func__, ret); |
Hans de Goede | 89df20d | 2014-05-20 11:38:18 +0200 | [diff] [blame] | 1797 | return ret; |
Giuseppe CAVALLARO | e58bb43 | 2013-03-26 04:43:08 +0000 | [diff] [blame] | 1798 | } |
Giuseppe CAVALLARO | f66ffe2 | 2011-04-10 23:16:45 +0000 | [diff] [blame] | 1799 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1800 | |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 1801 | /* Extra statistics */ |
| 1802 | memset(&priv->xstats, 0, sizeof(struct stmmac_extra_stats)); |
| 1803 | priv->xstats.threshold = tc; |
| 1804 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1805 | priv->dma_buf_sz = STMMAC_ALIGN(buf_sz); |
Giuseppe Cavallaro | 22ad383 | 2016-02-29 14:27:41 +0100 | [diff] [blame] | 1806 | priv->rx_copybreak = STMMAC_RX_COPYBREAK; |
Bartlomiej Zolnierkiewicz | 5632913 | 2013-08-09 14:02:08 +0200 | [diff] [blame] | 1807 | |
Tobias Klauser | 7262b7b | 2014-02-22 13:09:03 +0100 | [diff] [blame] | 1808 | ret = alloc_dma_desc_resources(priv); |
Srinivas Kandagatla | 09f8d69 | 2014-01-16 10:52:06 +0000 | [diff] [blame] | 1809 | if (ret < 0) { |
| 1810 | pr_err("%s: DMA descriptors allocation failed\n", __func__); |
| 1811 | goto dma_desc_error; |
| 1812 | } |
| 1813 | |
Giuseppe CAVALLARO | 777da23 | 2014-11-04 17:08:09 +0100 | [diff] [blame] | 1814 | ret = init_dma_desc_rings(dev, GFP_KERNEL); |
| 1815 | if (ret < 0) { |
| 1816 | pr_err("%s: DMA descriptors initialization failed\n", __func__); |
| 1817 | goto init_error; |
| 1818 | } |
| 1819 | |
Huacai Chen | fe131929 | 2014-12-19 22:38:18 +0800 | [diff] [blame] | 1820 | ret = stmmac_hw_setup(dev, true); |
Bartlomiej Zolnierkiewicz | 5632913 | 2013-08-09 14:02:08 +0200 | [diff] [blame] | 1821 | if (ret < 0) { |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 1822 | pr_err("%s: Hw setup failed\n", __func__); |
Giuseppe CAVALLARO | c9324d1 | 2013-07-04 06:18:07 +0200 | [diff] [blame] | 1823 | goto init_error; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1824 | } |
| 1825 | |
Giuseppe CAVALLARO | 777da23 | 2014-11-04 17:08:09 +0100 | [diff] [blame] | 1826 | stmmac_init_tx_coalesce(priv); |
| 1827 | |
Srinivas Kandagatla | 523f11b | 2014-01-16 10:52:14 +0000 | [diff] [blame] | 1828 | if (priv->phydev) |
| 1829 | phy_start(priv->phydev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1830 | |
Giuseppe CAVALLARO | f66ffe2 | 2011-04-10 23:16:45 +0000 | [diff] [blame] | 1831 | /* Request the IRQ lines */ |
| 1832 | ret = request_irq(dev->irq, stmmac_interrupt, |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 1833 | IRQF_SHARED, dev->name, dev); |
Giuseppe CAVALLARO | f66ffe2 | 2011-04-10 23:16:45 +0000 | [diff] [blame] | 1834 | if (unlikely(ret < 0)) { |
| 1835 | pr_err("%s: ERROR: allocating the IRQ %d (error: %d)\n", |
| 1836 | __func__, dev->irq, ret); |
Giuseppe CAVALLARO | c9324d1 | 2013-07-04 06:18:07 +0200 | [diff] [blame] | 1837 | goto init_error; |
Giuseppe CAVALLARO | f66ffe2 | 2011-04-10 23:16:45 +0000 | [diff] [blame] | 1838 | } |
| 1839 | |
Francesco Virlinzi | 7a13f8f | 2012-02-15 00:10:38 +0000 | [diff] [blame] | 1840 | /* Request the Wake IRQ in case of another line is used for WoL */ |
| 1841 | if (priv->wol_irq != dev->irq) { |
| 1842 | ret = request_irq(priv->wol_irq, stmmac_interrupt, |
| 1843 | IRQF_SHARED, dev->name, dev); |
| 1844 | if (unlikely(ret < 0)) { |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 1845 | pr_err("%s: ERROR: allocating the WoL IRQ %d (%d)\n", |
| 1846 | __func__, priv->wol_irq, ret); |
Giuseppe CAVALLARO | c9324d1 | 2013-07-04 06:18:07 +0200 | [diff] [blame] | 1847 | goto wolirq_error; |
Francesco Virlinzi | 7a13f8f | 2012-02-15 00:10:38 +0000 | [diff] [blame] | 1848 | } |
| 1849 | } |
| 1850 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 1851 | /* Request the IRQ lines */ |
Chen-Yu Tsai | d7ec858 | 2014-05-29 22:31:40 +0800 | [diff] [blame] | 1852 | if (priv->lpi_irq > 0) { |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 1853 | ret = request_irq(priv->lpi_irq, stmmac_interrupt, IRQF_SHARED, |
| 1854 | dev->name, dev); |
| 1855 | if (unlikely(ret < 0)) { |
| 1856 | pr_err("%s: ERROR: allocating the LPI IRQ %d (%d)\n", |
| 1857 | __func__, priv->lpi_irq, ret); |
Giuseppe CAVALLARO | c9324d1 | 2013-07-04 06:18:07 +0200 | [diff] [blame] | 1858 | goto lpiirq_error; |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 1859 | } |
| 1860 | } |
| 1861 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1862 | napi_enable(&priv->napi); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1863 | netif_start_queue(dev); |
Giuseppe CAVALLARO | f66ffe2 | 2011-04-10 23:16:45 +0000 | [diff] [blame] | 1864 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1865 | return 0; |
Giuseppe CAVALLARO | f66ffe2 | 2011-04-10 23:16:45 +0000 | [diff] [blame] | 1866 | |
Giuseppe CAVALLARO | c9324d1 | 2013-07-04 06:18:07 +0200 | [diff] [blame] | 1867 | lpiirq_error: |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 1868 | if (priv->wol_irq != dev->irq) |
| 1869 | free_irq(priv->wol_irq, dev); |
Giuseppe CAVALLARO | c9324d1 | 2013-07-04 06:18:07 +0200 | [diff] [blame] | 1870 | wolirq_error: |
Francesco Virlinzi | 7a13f8f | 2012-02-15 00:10:38 +0000 | [diff] [blame] | 1871 | free_irq(dev->irq, dev); |
| 1872 | |
Giuseppe CAVALLARO | c9324d1 | 2013-07-04 06:18:07 +0200 | [diff] [blame] | 1873 | init_error: |
| 1874 | free_dma_desc_resources(priv); |
Bartlomiej Zolnierkiewicz | 5632913 | 2013-08-09 14:02:08 +0200 | [diff] [blame] | 1875 | dma_desc_error: |
Giuseppe CAVALLARO | f66ffe2 | 2011-04-10 23:16:45 +0000 | [diff] [blame] | 1876 | if (priv->phydev) |
| 1877 | phy_disconnect(priv->phydev); |
Francesco Virlinzi | 4bfcbd7 | 2012-04-18 19:48:20 +0000 | [diff] [blame] | 1878 | |
Giuseppe CAVALLARO | f66ffe2 | 2011-04-10 23:16:45 +0000 | [diff] [blame] | 1879 | return ret; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1880 | } |
| 1881 | |
| 1882 | /** |
| 1883 | * stmmac_release - close entry point of the driver |
| 1884 | * @dev : device pointer. |
| 1885 | * Description: |
| 1886 | * This is the stop entry point of the driver. |
| 1887 | */ |
| 1888 | static int stmmac_release(struct net_device *dev) |
| 1889 | { |
| 1890 | struct stmmac_priv *priv = netdev_priv(dev); |
| 1891 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 1892 | if (priv->eee_enabled) |
| 1893 | del_timer_sync(&priv->eee_ctrl_timer); |
| 1894 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1895 | /* Stop and disconnect the PHY */ |
| 1896 | if (priv->phydev) { |
| 1897 | phy_stop(priv->phydev); |
| 1898 | phy_disconnect(priv->phydev); |
| 1899 | priv->phydev = NULL; |
| 1900 | } |
| 1901 | |
| 1902 | netif_stop_queue(dev); |
| 1903 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1904 | napi_disable(&priv->napi); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1905 | |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 1906 | del_timer_sync(&priv->txtimer); |
| 1907 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1908 | /* Free the IRQ lines */ |
| 1909 | free_irq(dev->irq, dev); |
Francesco Virlinzi | 7a13f8f | 2012-02-15 00:10:38 +0000 | [diff] [blame] | 1910 | if (priv->wol_irq != dev->irq) |
| 1911 | free_irq(priv->wol_irq, dev); |
Chen-Yu Tsai | d7ec858 | 2014-05-29 22:31:40 +0800 | [diff] [blame] | 1912 | if (priv->lpi_irq > 0) |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 1913 | free_irq(priv->lpi_irq, dev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1914 | |
| 1915 | /* Stop TX/RX DMA and clear the descriptors */ |
Giuseppe CAVALLARO | ad01b7d | 2010-08-23 20:40:42 +0000 | [diff] [blame] | 1916 | priv->hw->dma->stop_tx(priv->ioaddr); |
| 1917 | priv->hw->dma->stop_rx(priv->ioaddr); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1918 | |
| 1919 | /* Release and free the Rx/Tx resources */ |
| 1920 | free_dma_desc_resources(priv); |
| 1921 | |
avisconti | 19449bf | 2010-10-25 18:58:14 +0000 | [diff] [blame] | 1922 | /* Disable the MAC Rx/Tx */ |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1923 | stmmac_set_mac(priv->ioaddr, false); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1924 | |
| 1925 | netif_carrier_off(dev); |
| 1926 | |
Giuseppe CAVALLARO | 50fb4f74 | 2014-11-04 15:49:33 +0100 | [diff] [blame] | 1927 | #ifdef CONFIG_DEBUG_FS |
Mathieu Olivari | 466c5ac | 2015-05-22 19:03:29 -0700 | [diff] [blame] | 1928 | stmmac_exit_fs(dev); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1929 | #endif |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1930 | |
Rayagond Kokatanur | 92ba688 | 2013-03-26 04:43:11 +0000 | [diff] [blame] | 1931 | stmmac_release_ptp(priv); |
| 1932 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1933 | return 0; |
| 1934 | } |
| 1935 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1936 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 1937 | * stmmac_xmit - Tx entry point of the driver |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1938 | * @skb : the socket buffer |
| 1939 | * @dev : device pointer |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 1940 | * Description : this is the tx entry point of the driver. |
| 1941 | * It programs the chain or the ring and supports oversized frames |
| 1942 | * and SG feature. |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1943 | */ |
| 1944 | static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev) |
| 1945 | { |
| 1946 | struct stmmac_priv *priv = netdev_priv(dev); |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 1947 | unsigned int nopaged_len = skb_headlen(skb); |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 1948 | int i, csum_insertion = 0, is_jumbo = 0; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1949 | int nfrags = skb_shinfo(skb)->nr_frags; |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 1950 | unsigned int entry, first_entry; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1951 | struct dma_desc *desc, *first; |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 1952 | unsigned int enh_desc; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1953 | |
Fabrice Gasnier | 16ee817 | 2014-11-04 17:08:05 +0100 | [diff] [blame] | 1954 | spin_lock(&priv->tx_lock); |
| 1955 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1956 | if (unlikely(stmmac_tx_avail(priv) < nfrags + 1)) { |
Fabrice Gasnier | 16ee817 | 2014-11-04 17:08:05 +0100 | [diff] [blame] | 1957 | spin_unlock(&priv->tx_lock); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1958 | if (!netif_queue_stopped(dev)) { |
| 1959 | netif_stop_queue(dev); |
| 1960 | /* This is a hard error, log it. */ |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 1961 | pr_err("%s: Tx Ring full when queue awake\n", __func__); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1962 | } |
| 1963 | return NETDEV_TX_BUSY; |
| 1964 | } |
| 1965 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 1966 | if (priv->tx_path_in_lpi_mode) |
| 1967 | stmmac_disable_eee_mode(priv); |
| 1968 | |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1969 | entry = priv->cur_tx; |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 1970 | first_entry = entry; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1971 | |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 1972 | csum_insertion = (skb->ip_summed == CHECKSUM_PARTIAL); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1973 | |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 1974 | if (likely(priv->extend_desc)) |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 1975 | desc = (struct dma_desc *)(priv->dma_etx + entry); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 1976 | else |
| 1977 | desc = priv->dma_tx + entry; |
| 1978 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1979 | first = desc; |
| 1980 | |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 1981 | priv->tx_skbuff[first_entry] = skb; |
| 1982 | |
| 1983 | enh_desc = priv->plat->enh_desc; |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 1984 | /* To program the descriptors according to the size of the frame */ |
Giuseppe CAVALLARO | 29896a6 | 2014-03-10 13:40:33 +0100 | [diff] [blame] | 1985 | if (enh_desc) |
| 1986 | is_jumbo = priv->hw->mode->is_jumbo_frm(skb->len, enh_desc); |
| 1987 | |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 1988 | if (unlikely(is_jumbo)) { |
Giuseppe CAVALLARO | 29896a6 | 2014-03-10 13:40:33 +0100 | [diff] [blame] | 1989 | entry = priv->hw->mode->jumbo_frm(priv, skb, csum_insertion); |
Giuseppe CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 1990 | if (unlikely(entry < 0)) |
| 1991 | goto dma_map_err; |
Giuseppe CAVALLARO | 29896a6 | 2014-03-10 13:40:33 +0100 | [diff] [blame] | 1992 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1993 | |
| 1994 | for (i = 0; i < nfrags; i++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 1995 | const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 1996 | int len = skb_frag_size(frag); |
Giuseppe Cavallaro | be434d5 | 2016-02-29 14:27:35 +0100 | [diff] [blame] | 1997 | bool last_segment = (i == (nfrags - 1)); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1998 | |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 1999 | entry = STMMAC_GET_ENTRY(entry, DMA_TX_SIZE); |
| 2000 | |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 2001 | if (likely(priv->extend_desc)) |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 2002 | desc = (struct dma_desc *)(priv->dma_etx + entry); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2003 | else |
| 2004 | desc = priv->dma_tx + entry; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2005 | |
Ian Campbell | f722380 | 2011-09-21 21:53:20 +0000 | [diff] [blame] | 2006 | desc->des2 = skb_frag_dma_map(priv->device, frag, 0, len, |
| 2007 | DMA_TO_DEVICE); |
Giuseppe CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 2008 | if (dma_mapping_error(priv->device, desc->des2)) |
| 2009 | goto dma_map_err; /* should reuse desc w/o issues */ |
| 2010 | |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 2011 | priv->tx_skbuff[entry] = NULL; |
Giuseppe CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 2012 | priv->tx_skbuff_dma[entry].buf = desc->des2; |
| 2013 | priv->tx_skbuff_dma[entry].map_as_page = true; |
Giuseppe Cavallaro | 553e2ab | 2016-02-29 14:27:31 +0100 | [diff] [blame] | 2014 | priv->tx_skbuff_dma[entry].len = len; |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 2015 | priv->tx_skbuff_dma[entry].last_segment = last_segment; |
| 2016 | |
| 2017 | /* Prepare the descriptor and set the own bit too */ |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 2018 | priv->hw->desc->prepare_tx_desc(desc, 0, len, csum_insertion, |
Giuseppe Cavallaro | be434d5 | 2016-02-29 14:27:35 +0100 | [diff] [blame] | 2019 | priv->mode, 1, last_segment); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2020 | } |
| 2021 | |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 2022 | entry = STMMAC_GET_ENTRY(entry, DMA_TX_SIZE); |
| 2023 | |
| 2024 | priv->cur_tx = entry; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2025 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2026 | if (netif_msg_pktdata(priv)) { |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 2027 | pr_debug("%s: curr=%d dirty=%d f=%d, e=%d, first=%p, nfrags=%d", |
| 2028 | __func__, priv->cur_tx, priv->dirty_tx, first_entry, |
| 2029 | entry, first, nfrags); |
Giuseppe CAVALLARO | 83d7af6 | 2013-07-02 14:12:36 +0200 | [diff] [blame] | 2030 | |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2031 | if (priv->extend_desc) |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 2032 | stmmac_display_ring((void *)priv->dma_etx, |
| 2033 | DMA_TX_SIZE, 1); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2034 | else |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 2035 | stmmac_display_ring((void *)priv->dma_tx, |
| 2036 | DMA_TX_SIZE, 0); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2037 | |
Giuseppe CAVALLARO | 83d7af6 | 2013-07-02 14:12:36 +0200 | [diff] [blame] | 2038 | pr_debug(">>> frame to be transmitted: "); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2039 | print_pkt(skb->data, skb->len); |
| 2040 | } |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 2041 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2042 | if (unlikely(stmmac_tx_avail(priv) <= (MAX_SKB_FRAGS + 1))) { |
Giuseppe CAVALLARO | 83d7af6 | 2013-07-02 14:12:36 +0200 | [diff] [blame] | 2043 | if (netif_msg_hw(priv)) |
| 2044 | pr_debug("%s: stop transmitted packets\n", __func__); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2045 | netif_stop_queue(dev); |
| 2046 | } |
| 2047 | |
| 2048 | dev->stats.tx_bytes += skb->len; |
| 2049 | |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 2050 | /* According to the coalesce parameter the IC bit for the latest |
| 2051 | * segment is reset and the timer re-started to clean the tx status. |
| 2052 | * This approach takes care about the fragments: desc is the first |
| 2053 | * element in case of no SG. |
| 2054 | */ |
| 2055 | priv->tx_count_frames += nfrags + 1; |
| 2056 | if (likely(priv->tx_coal_frames > priv->tx_count_frames)) { |
| 2057 | mod_timer(&priv->txtimer, |
| 2058 | STMMAC_COAL_TIMER(priv->tx_coal_timer)); |
| 2059 | } else { |
| 2060 | priv->tx_count_frames = 0; |
| 2061 | priv->hw->desc->set_tx_ic(desc); |
| 2062 | priv->xstats.tx_set_ic_bit++; |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 2063 | } |
| 2064 | |
| 2065 | if (!priv->hwts_tx_en) |
| 2066 | skb_tx_timestamp(skb); |
Richard Cochran | 3e82ce1 | 2011-06-12 02:19:06 +0000 | [diff] [blame] | 2067 | |
Giuseppe Cavallaro | 0e80bdc | 2016-02-29 14:27:38 +0100 | [diff] [blame] | 2068 | /* Ready to fill the first descriptor and set the OWN bit w/o any |
| 2069 | * problems because all the descriptors are actually ready to be |
| 2070 | * passed to the DMA engine. |
| 2071 | */ |
| 2072 | if (likely(!is_jumbo)) { |
| 2073 | bool last_segment = (nfrags == 0); |
| 2074 | |
| 2075 | first->des2 = dma_map_single(priv->device, skb->data, |
| 2076 | nopaged_len, DMA_TO_DEVICE); |
| 2077 | if (dma_mapping_error(priv->device, first->des2)) |
| 2078 | goto dma_map_err; |
| 2079 | |
| 2080 | priv->tx_skbuff_dma[first_entry].buf = first->des2; |
| 2081 | priv->tx_skbuff_dma[first_entry].len = nopaged_len; |
| 2082 | priv->tx_skbuff_dma[first_entry].last_segment = last_segment; |
| 2083 | |
| 2084 | if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && |
| 2085 | priv->hwts_tx_en)) { |
| 2086 | /* declare that device is doing timestamping */ |
| 2087 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 2088 | priv->hw->desc->enable_tx_timestamp(first); |
| 2089 | } |
| 2090 | |
| 2091 | /* Prepare the first descriptor setting the OWN bit too */ |
| 2092 | priv->hw->desc->prepare_tx_desc(first, 1, nopaged_len, |
| 2093 | csum_insertion, priv->mode, 1, |
| 2094 | last_segment); |
| 2095 | |
| 2096 | /* The own bit must be the latest setting done when prepare the |
| 2097 | * descriptor and then barrier is needed to make sure that |
| 2098 | * all is coherent before granting the DMA engine. |
| 2099 | */ |
| 2100 | smp_wmb(); |
| 2101 | } |
| 2102 | |
Beniamino Galvani | 3897957 | 2015-01-21 19:07:27 +0100 | [diff] [blame] | 2103 | netdev_sent_queue(dev, skb->len); |
Richard Cochran | 52f64fa | 2011-06-19 03:31:43 +0000 | [diff] [blame] | 2104 | priv->hw->dma->enable_dma_transmission(priv->ioaddr); |
| 2105 | |
Giuseppe CAVALLARO | a9097a9 | 2011-10-18 00:01:19 +0000 | [diff] [blame] | 2106 | spin_unlock(&priv->tx_lock); |
Giuseppe CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 2107 | return NETDEV_TX_OK; |
Giuseppe CAVALLARO | a9097a9 | 2011-10-18 00:01:19 +0000 | [diff] [blame] | 2108 | |
Giuseppe CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 2109 | dma_map_err: |
Fabrice Gasnier | 758a0ab | 2014-11-04 17:08:06 +0100 | [diff] [blame] | 2110 | spin_unlock(&priv->tx_lock); |
Giuseppe CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 2111 | dev_err(priv->device, "Tx dma map failed\n"); |
| 2112 | dev_kfree_skb(skb); |
| 2113 | priv->dev->stats.tx_dropped++; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2114 | return NETDEV_TX_OK; |
| 2115 | } |
| 2116 | |
Vince Bridgers | b938198 | 2014-01-14 13:42:05 -0600 | [diff] [blame] | 2117 | static void stmmac_rx_vlan(struct net_device *dev, struct sk_buff *skb) |
| 2118 | { |
| 2119 | struct ethhdr *ehdr; |
| 2120 | u16 vlanid; |
| 2121 | |
| 2122 | if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) == |
| 2123 | NETIF_F_HW_VLAN_CTAG_RX && |
| 2124 | !__vlan_get_tag(skb, &vlanid)) { |
| 2125 | /* pop the vlan tag */ |
| 2126 | ehdr = (struct ethhdr *)skb->data; |
| 2127 | memmove(skb->data + VLAN_HLEN, ehdr, ETH_ALEN * 2); |
| 2128 | skb_pull(skb, VLAN_HLEN); |
| 2129 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlanid); |
| 2130 | } |
| 2131 | } |
| 2132 | |
| 2133 | |
Giuseppe Cavallaro | 120e87f | 2016-02-29 14:27:42 +0100 | [diff] [blame] | 2134 | static inline int stmmac_rx_threshold_count(struct stmmac_priv *priv) |
| 2135 | { |
| 2136 | if (priv->rx_zeroc_thresh < STMMAC_RX_THRESH) |
| 2137 | return 0; |
| 2138 | |
| 2139 | return 1; |
| 2140 | } |
| 2141 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 2142 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 2143 | * stmmac_rx_refill - refill used skb preallocated buffers |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 2144 | * @priv: driver private structure |
| 2145 | * Description : this is to reallocate the skb for the reception process |
| 2146 | * that is based on zero-copy. |
| 2147 | */ |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2148 | static inline void stmmac_rx_refill(struct stmmac_priv *priv) |
| 2149 | { |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2150 | int bfsize = priv->dma_buf_sz; |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 2151 | unsigned int entry = priv->dirty_rx; |
| 2152 | int dirty = stmmac_rx_dirty(priv); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2153 | |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 2154 | while (dirty-- > 0) { |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2155 | struct dma_desc *p; |
| 2156 | |
| 2157 | if (priv->extend_desc) |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 2158 | p = (struct dma_desc *)(priv->dma_erx + entry); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2159 | else |
| 2160 | p = priv->dma_rx + entry; |
| 2161 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2162 | if (likely(priv->rx_skbuff[entry] == NULL)) { |
| 2163 | struct sk_buff *skb; |
| 2164 | |
Eric Dumazet | acb600d | 2012-10-05 06:23:55 +0000 | [diff] [blame] | 2165 | skb = netdev_alloc_skb_ip_align(priv->dev, bfsize); |
Giuseppe Cavallaro | 120e87f | 2016-02-29 14:27:42 +0100 | [diff] [blame] | 2166 | if (unlikely(!skb)) { |
| 2167 | /* so for a while no zero-copy! */ |
| 2168 | priv->rx_zeroc_thresh = STMMAC_RX_THRESH; |
| 2169 | if (unlikely(net_ratelimit())) |
| 2170 | dev_err(priv->device, |
| 2171 | "fail to alloc skb entry %d\n", |
| 2172 | entry); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2173 | break; |
Giuseppe Cavallaro | 120e87f | 2016-02-29 14:27:42 +0100 | [diff] [blame] | 2174 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2175 | |
| 2176 | priv->rx_skbuff[entry] = skb; |
| 2177 | priv->rx_skbuff_dma[entry] = |
| 2178 | dma_map_single(priv->device, skb->data, bfsize, |
| 2179 | DMA_FROM_DEVICE); |
Giuseppe CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 2180 | if (dma_mapping_error(priv->device, |
| 2181 | priv->rx_skbuff_dma[entry])) { |
| 2182 | dev_err(priv->device, "Rx dma map failed\n"); |
| 2183 | dev_kfree_skb(skb); |
| 2184 | break; |
| 2185 | } |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2186 | p->des2 = priv->rx_skbuff_dma[entry]; |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 2187 | |
Giuseppe CAVALLARO | 29896a6 | 2014-03-10 13:40:33 +0100 | [diff] [blame] | 2188 | priv->hw->mode->refill_desc3(priv, p); |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 2189 | |
Giuseppe Cavallaro | 120e87f | 2016-02-29 14:27:42 +0100 | [diff] [blame] | 2190 | if (priv->rx_zeroc_thresh > 0) |
| 2191 | priv->rx_zeroc_thresh--; |
| 2192 | |
Giuseppe CAVALLARO | 83d7af6 | 2013-07-02 14:12:36 +0200 | [diff] [blame] | 2193 | if (netif_msg_rx_status(priv)) |
| 2194 | pr_debug("\trefill entry #%d\n", entry); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2195 | } |
Giuseppe Cavallaro | 120e87f | 2016-02-29 14:27:42 +0100 | [diff] [blame] | 2196 | |
Shiraz Hashim | eb0dc4b | 2011-07-17 20:54:08 +0000 | [diff] [blame] | 2197 | wmb(); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2198 | priv->hw->desc->set_rx_owner(p); |
Deepak Sikri | 8e83989 | 2012-07-08 21:14:45 +0000 | [diff] [blame] | 2199 | wmb(); |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 2200 | |
| 2201 | entry = STMMAC_GET_ENTRY(entry, DMA_RX_SIZE); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2202 | } |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 2203 | priv->dirty_rx = entry; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2204 | } |
| 2205 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 2206 | /** |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 2207 | * stmmac_rx - manage the receive process |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 2208 | * @priv: driver private structure |
| 2209 | * @limit: napi bugget. |
| 2210 | * Description : this the function called by the napi poll method. |
| 2211 | * It gets all the frames inside the ring. |
| 2212 | */ |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2213 | static int stmmac_rx(struct stmmac_priv *priv, int limit) |
| 2214 | { |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 2215 | unsigned int entry = priv->cur_rx; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2216 | unsigned int next_entry; |
| 2217 | unsigned int count = 0; |
Giuseppe CAVALLARO | d2afb5b | 2014-09-01 09:17:52 +0200 | [diff] [blame] | 2218 | int coe = priv->hw->rx_csum; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2219 | |
Giuseppe CAVALLARO | 83d7af6 | 2013-07-02 14:12:36 +0200 | [diff] [blame] | 2220 | if (netif_msg_rx_status(priv)) { |
| 2221 | pr_debug("%s: descriptor ring:\n", __func__); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2222 | if (priv->extend_desc) |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 2223 | stmmac_display_ring((void *)priv->dma_erx, |
| 2224 | DMA_RX_SIZE, 1); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2225 | else |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 2226 | stmmac_display_ring((void *)priv->dma_rx, |
| 2227 | DMA_RX_SIZE, 0); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2228 | } |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2229 | while (count < limit) { |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2230 | int status; |
Giuseppe CAVALLARO | 9401bb5 | 2013-04-08 02:10:03 +0000 | [diff] [blame] | 2231 | struct dma_desc *p; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2232 | |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2233 | if (priv->extend_desc) |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 2234 | p = (struct dma_desc *)(priv->dma_erx + entry); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2235 | else |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 2236 | p = priv->dma_rx + entry; |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2237 | |
Fabrice Gasnier | c1fa321 | 2016-02-29 14:27:34 +0100 | [diff] [blame] | 2238 | /* read the status of the incoming frame */ |
| 2239 | status = priv->hw->desc->rx_status(&priv->dev->stats, |
| 2240 | &priv->xstats, p); |
| 2241 | /* check if managed by the DMA otherwise go ahead */ |
| 2242 | if (unlikely(status & dma_own)) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2243 | break; |
| 2244 | |
| 2245 | count++; |
| 2246 | |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 2247 | priv->cur_rx = STMMAC_GET_ENTRY(priv->cur_rx, DMA_RX_SIZE); |
| 2248 | next_entry = priv->cur_rx; |
| 2249 | |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2250 | if (priv->extend_desc) |
Giuseppe CAVALLARO | 9401bb5 | 2013-04-08 02:10:03 +0000 | [diff] [blame] | 2251 | prefetch(priv->dma_erx + next_entry); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2252 | else |
Giuseppe CAVALLARO | 9401bb5 | 2013-04-08 02:10:03 +0000 | [diff] [blame] | 2253 | prefetch(priv->dma_rx + next_entry); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2254 | |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2255 | if ((priv->extend_desc) && (priv->hw->desc->rx_extended_status)) |
| 2256 | priv->hw->desc->rx_extended_status(&priv->dev->stats, |
| 2257 | &priv->xstats, |
| 2258 | priv->dma_erx + |
| 2259 | entry); |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 2260 | if (unlikely(status == discard_frame)) { |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2261 | priv->dev->stats.rx_errors++; |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 2262 | if (priv->hwts_rx_en && !priv->extend_desc) { |
| 2263 | /* DESC2 & DESC3 will be overwitten by device |
| 2264 | * with timestamp value, hence reinitialize |
| 2265 | * them in stmmac_rx_refill() function so that |
| 2266 | * device can reuse it. |
| 2267 | */ |
| 2268 | priv->rx_skbuff[entry] = NULL; |
| 2269 | dma_unmap_single(priv->device, |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 2270 | priv->rx_skbuff_dma[entry], |
| 2271 | priv->dma_buf_sz, |
| 2272 | DMA_FROM_DEVICE); |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 2273 | } |
| 2274 | } else { |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2275 | struct sk_buff *skb; |
Giuseppe CAVALLARO | 3eeb299 | 2010-07-27 00:09:47 +0000 | [diff] [blame] | 2276 | int frame_len; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2277 | |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 2278 | frame_len = priv->hw->desc->get_rx_frame_len(p, coe); |
| 2279 | |
Giuseppe CAVALLARO | e527c4a | 2015-11-26 08:35:45 +0100 | [diff] [blame] | 2280 | /* check if frame_len fits the preallocated memory */ |
| 2281 | if (frame_len > priv->dma_buf_sz) { |
| 2282 | priv->dev->stats.rx_length_errors++; |
| 2283 | break; |
| 2284 | } |
| 2285 | |
Giuseppe CAVALLARO | 3eeb299 | 2010-07-27 00:09:47 +0000 | [diff] [blame] | 2286 | /* ACS is set; GMAC core strips PAD/FCS for IEEE 802.3 |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 2287 | * Type frames (LLC/LLC-SNAP) |
| 2288 | */ |
Giuseppe CAVALLARO | 3eeb299 | 2010-07-27 00:09:47 +0000 | [diff] [blame] | 2289 | if (unlikely(status != llc_snap)) |
| 2290 | frame_len -= ETH_FCS_LEN; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2291 | |
Giuseppe CAVALLARO | 83d7af6 | 2013-07-02 14:12:36 +0200 | [diff] [blame] | 2292 | if (netif_msg_rx_status(priv)) { |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2293 | pr_debug("\tdesc: %p [entry %d] buff=0x%x\n", |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 2294 | p, entry, p->des2); |
Giuseppe CAVALLARO | 83d7af6 | 2013-07-02 14:12:36 +0200 | [diff] [blame] | 2295 | if (frame_len > ETH_FRAME_LEN) |
| 2296 | pr_debug("\tframe size %d, COE: %d\n", |
| 2297 | frame_len, status); |
| 2298 | } |
Giuseppe Cavallaro | 22ad383 | 2016-02-29 14:27:41 +0100 | [diff] [blame] | 2299 | |
Giuseppe Cavallaro | 120e87f | 2016-02-29 14:27:42 +0100 | [diff] [blame] | 2300 | if (unlikely((frame_len < priv->rx_copybreak) || |
| 2301 | stmmac_rx_threshold_count(priv))) { |
Giuseppe Cavallaro | 22ad383 | 2016-02-29 14:27:41 +0100 | [diff] [blame] | 2302 | skb = netdev_alloc_skb_ip_align(priv->dev, |
| 2303 | frame_len); |
| 2304 | if (unlikely(!skb)) { |
| 2305 | if (net_ratelimit()) |
| 2306 | dev_warn(priv->device, |
| 2307 | "packet dropped\n"); |
| 2308 | priv->dev->stats.rx_dropped++; |
| 2309 | break; |
| 2310 | } |
| 2311 | |
| 2312 | dma_sync_single_for_cpu(priv->device, |
| 2313 | priv->rx_skbuff_dma |
| 2314 | [entry], frame_len, |
| 2315 | DMA_FROM_DEVICE); |
| 2316 | skb_copy_to_linear_data(skb, |
| 2317 | priv-> |
| 2318 | rx_skbuff[entry]->data, |
| 2319 | frame_len); |
| 2320 | |
| 2321 | skb_put(skb, frame_len); |
| 2322 | dma_sync_single_for_device(priv->device, |
| 2323 | priv->rx_skbuff_dma |
| 2324 | [entry], frame_len, |
| 2325 | DMA_FROM_DEVICE); |
| 2326 | } else { |
| 2327 | skb = priv->rx_skbuff[entry]; |
| 2328 | if (unlikely(!skb)) { |
| 2329 | pr_err("%s: Inconsistent Rx chain\n", |
| 2330 | priv->dev->name); |
| 2331 | priv->dev->stats.rx_dropped++; |
| 2332 | break; |
| 2333 | } |
| 2334 | prefetch(skb->data - NET_IP_ALIGN); |
| 2335 | priv->rx_skbuff[entry] = NULL; |
Giuseppe Cavallaro | 120e87f | 2016-02-29 14:27:42 +0100 | [diff] [blame] | 2336 | priv->rx_zeroc_thresh++; |
Giuseppe Cavallaro | 22ad383 | 2016-02-29 14:27:41 +0100 | [diff] [blame] | 2337 | |
| 2338 | skb_put(skb, frame_len); |
| 2339 | dma_unmap_single(priv->device, |
| 2340 | priv->rx_skbuff_dma[entry], |
| 2341 | priv->dma_buf_sz, |
| 2342 | DMA_FROM_DEVICE); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2343 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2344 | |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 2345 | stmmac_get_rx_hwtstamp(priv, entry, skb); |
| 2346 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2347 | if (netif_msg_pktdata(priv)) { |
Giuseppe CAVALLARO | 83d7af6 | 2013-07-02 14:12:36 +0200 | [diff] [blame] | 2348 | pr_debug("frame received (%dbytes)", frame_len); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2349 | print_pkt(skb->data, frame_len); |
| 2350 | } |
Giuseppe CAVALLARO | 83d7af6 | 2013-07-02 14:12:36 +0200 | [diff] [blame] | 2351 | |
Vince Bridgers | b938198 | 2014-01-14 13:42:05 -0600 | [diff] [blame] | 2352 | stmmac_rx_vlan(priv->dev, skb); |
| 2353 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2354 | skb->protocol = eth_type_trans(skb, priv->dev); |
| 2355 | |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 2356 | if (unlikely(!coe)) |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 2357 | skb_checksum_none_assert(skb); |
Giuseppe CAVALLARO | 62a2ab9 | 2012-11-25 23:10:43 +0000 | [diff] [blame] | 2358 | else |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2359 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Giuseppe CAVALLARO | 62a2ab9 | 2012-11-25 23:10:43 +0000 | [diff] [blame] | 2360 | |
| 2361 | napi_gro_receive(&priv->napi, skb); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2362 | |
| 2363 | priv->dev->stats.rx_packets++; |
| 2364 | priv->dev->stats.rx_bytes += frame_len; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2365 | } |
| 2366 | entry = next_entry; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2367 | } |
| 2368 | |
| 2369 | stmmac_rx_refill(priv); |
| 2370 | |
| 2371 | priv->xstats.rx_pkt_n += count; |
| 2372 | |
| 2373 | return count; |
| 2374 | } |
| 2375 | |
| 2376 | /** |
| 2377 | * stmmac_poll - stmmac poll method (NAPI) |
| 2378 | * @napi : pointer to the napi structure. |
| 2379 | * @budget : maximum number of packets that the current CPU can receive from |
| 2380 | * all interfaces. |
| 2381 | * Description : |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 2382 | * To look at the incoming frames and clear the tx resources. |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2383 | */ |
| 2384 | static int stmmac_poll(struct napi_struct *napi, int budget) |
| 2385 | { |
| 2386 | struct stmmac_priv *priv = container_of(napi, struct stmmac_priv, napi); |
| 2387 | int work_done = 0; |
| 2388 | |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 2389 | priv->xstats.napi_poll++; |
| 2390 | stmmac_tx_clean(priv); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2391 | |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 2392 | work_done = stmmac_rx(priv, budget); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2393 | if (work_done < budget) { |
| 2394 | napi_complete(napi); |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 2395 | stmmac_enable_dma_irq(priv); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2396 | } |
| 2397 | return work_done; |
| 2398 | } |
| 2399 | |
| 2400 | /** |
| 2401 | * stmmac_tx_timeout |
| 2402 | * @dev : Pointer to net device structure |
| 2403 | * Description: this function is called when a packet transmission fails to |
Giuseppe CAVALLARO | 7284a3f | 2012-11-25 23:10:41 +0000 | [diff] [blame] | 2404 | * 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] | 2405 | * netdev structure and arrange for the device to be reset to a sane state |
| 2406 | * in order to transmit a new packet. |
| 2407 | */ |
| 2408 | static void stmmac_tx_timeout(struct net_device *dev) |
| 2409 | { |
| 2410 | struct stmmac_priv *priv = netdev_priv(dev); |
| 2411 | |
| 2412 | /* Clear Tx resources and restart transmitting again */ |
| 2413 | stmmac_tx_err(priv); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2414 | } |
| 2415 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2416 | /** |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 2417 | * stmmac_set_rx_mode - entry point for multicast addressing |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2418 | * @dev : pointer to the device structure |
| 2419 | * Description: |
| 2420 | * This function is a driver entry point which gets called by the kernel |
| 2421 | * whenever multicast addresses must be enabled/disabled. |
| 2422 | * Return value: |
| 2423 | * void. |
| 2424 | */ |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 2425 | static void stmmac_set_rx_mode(struct net_device *dev) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2426 | { |
| 2427 | struct stmmac_priv *priv = netdev_priv(dev); |
| 2428 | |
Vince Bridgers | 3b57de9 | 2014-07-31 15:49:17 -0500 | [diff] [blame] | 2429 | priv->hw->mac->set_filter(priv->hw, dev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2430 | } |
| 2431 | |
| 2432 | /** |
| 2433 | * stmmac_change_mtu - entry point to change MTU size for the device. |
| 2434 | * @dev : device pointer. |
| 2435 | * @new_mtu : the new MTU size for the device. |
| 2436 | * Description: the Maximum Transfer Unit (MTU) is used by the network layer |
| 2437 | * to drive packet transmission. Ethernet has an MTU of 1500 octets |
| 2438 | * (ETH_DATA_LEN). This value can be changed with ifconfig. |
| 2439 | * Return value: |
| 2440 | * 0 on success and an appropriate (-)ve integer as defined in errno.h |
| 2441 | * file on failure. |
| 2442 | */ |
| 2443 | static int stmmac_change_mtu(struct net_device *dev, int new_mtu) |
| 2444 | { |
| 2445 | struct stmmac_priv *priv = netdev_priv(dev); |
| 2446 | int max_mtu; |
| 2447 | |
| 2448 | if (netif_running(dev)) { |
| 2449 | pr_err("%s: must be stopped to change its MTU\n", dev->name); |
| 2450 | return -EBUSY; |
| 2451 | } |
| 2452 | |
Giuseppe CAVALLARO | 48febf7 | 2011-10-18 00:01:21 +0000 | [diff] [blame] | 2453 | if (priv->plat->enh_desc) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2454 | max_mtu = JUMBO_LEN; |
| 2455 | else |
Giuseppe CAVALLARO | 45db81e | 2011-10-18 01:39:55 +0000 | [diff] [blame] | 2456 | max_mtu = SKB_MAX_HEAD(NET_SKB_PAD + NET_IP_ALIGN); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2457 | |
Vince Bridgers | 2618abb | 2014-01-20 05:39:01 -0600 | [diff] [blame] | 2458 | if (priv->plat->maxmtu < max_mtu) |
| 2459 | max_mtu = priv->plat->maxmtu; |
| 2460 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2461 | if ((new_mtu < 46) || (new_mtu > max_mtu)) { |
| 2462 | pr_err("%s: invalid MTU, max MTU is: %d\n", dev->name, max_mtu); |
| 2463 | return -EINVAL; |
| 2464 | } |
| 2465 | |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 2466 | dev->mtu = new_mtu; |
| 2467 | netdev_update_features(dev); |
| 2468 | |
| 2469 | return 0; |
| 2470 | } |
| 2471 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 2472 | static netdev_features_t stmmac_fix_features(struct net_device *dev, |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 2473 | netdev_features_t features) |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 2474 | { |
| 2475 | struct stmmac_priv *priv = netdev_priv(dev); |
| 2476 | |
Deepak SIKRI | 38912bd | 2012-04-04 04:33:21 +0000 | [diff] [blame] | 2477 | if (priv->plat->rx_coe == STMMAC_RX_COE_NONE) |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 2478 | features &= ~NETIF_F_RXCSUM; |
Giuseppe CAVALLARO | d2afb5b | 2014-09-01 09:17:52 +0200 | [diff] [blame] | 2479 | |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 2480 | if (!priv->plat->tx_coe) |
Tom Herbert | a188222 | 2015-12-14 11:19:43 -0800 | [diff] [blame] | 2481 | features &= ~NETIF_F_CSUM_MASK; |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 2482 | |
Giuseppe CAVALLARO | ebbb293 | 2010-09-17 03:23:40 +0000 | [diff] [blame] | 2483 | /* Some GMAC devices have a bugged Jumbo frame support that |
| 2484 | * needs to have the Tx COE disabled for oversized frames |
| 2485 | * (due to limited buffer sizes). In this case we disable |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 2486 | * the TX csum insertionin the TDES and not use SF. |
| 2487 | */ |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 2488 | if (priv->plat->bugged_jumbo && (dev->mtu > ETH_DATA_LEN)) |
Tom Herbert | a188222 | 2015-12-14 11:19:43 -0800 | [diff] [blame] | 2489 | features &= ~NETIF_F_CSUM_MASK; |
Giuseppe CAVALLARO | ebbb293 | 2010-09-17 03:23:40 +0000 | [diff] [blame] | 2490 | |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 2491 | return features; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2492 | } |
| 2493 | |
Giuseppe CAVALLARO | d2afb5b | 2014-09-01 09:17:52 +0200 | [diff] [blame] | 2494 | static int stmmac_set_features(struct net_device *netdev, |
| 2495 | netdev_features_t features) |
| 2496 | { |
| 2497 | struct stmmac_priv *priv = netdev_priv(netdev); |
| 2498 | |
| 2499 | /* Keep the COE Type in case of csum is supporting */ |
| 2500 | if (features & NETIF_F_RXCSUM) |
| 2501 | priv->hw->rx_csum = priv->plat->rx_coe; |
| 2502 | else |
| 2503 | priv->hw->rx_csum = 0; |
| 2504 | /* No check needed because rx_coe has been set before and it will be |
| 2505 | * fixed in case of issue. |
| 2506 | */ |
| 2507 | priv->hw->mac->rx_ipc(priv->hw); |
| 2508 | |
| 2509 | return 0; |
| 2510 | } |
| 2511 | |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 2512 | /** |
| 2513 | * stmmac_interrupt - main ISR |
| 2514 | * @irq: interrupt number. |
| 2515 | * @dev_id: to pass the net device pointer. |
| 2516 | * Description: this is the main driver interrupt service routine. |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 2517 | * It can call: |
| 2518 | * o DMA service routine (to manage incoming frame reception and transmission |
| 2519 | * status) |
| 2520 | * o Core interrupts to manage: remote wake-up, management counter, LPI |
| 2521 | * interrupts. |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 2522 | */ |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2523 | static irqreturn_t stmmac_interrupt(int irq, void *dev_id) |
| 2524 | { |
| 2525 | struct net_device *dev = (struct net_device *)dev_id; |
| 2526 | struct stmmac_priv *priv = netdev_priv(dev); |
| 2527 | |
Srinivas Kandagatla | 89f7f2c | 2014-01-16 10:53:00 +0000 | [diff] [blame] | 2528 | if (priv->irq_wake) |
| 2529 | pm_wakeup_event(priv->device, 0); |
| 2530 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2531 | if (unlikely(!dev)) { |
| 2532 | pr_err("%s: invalid dev pointer\n", __func__); |
| 2533 | return IRQ_NONE; |
| 2534 | } |
| 2535 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 2536 | /* To handle GMAC own interrupts */ |
| 2537 | if (priv->plat->has_gmac) { |
Vince Bridgers | 7ed24bb | 2014-07-31 15:49:13 -0500 | [diff] [blame] | 2538 | int status = priv->hw->mac->host_irq_status(priv->hw, |
Giuseppe CAVALLARO | 0982a0f | 2013-03-26 04:43:07 +0000 | [diff] [blame] | 2539 | &priv->xstats); |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 2540 | if (unlikely(status)) { |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 2541 | /* For LPI we need to save the tx status */ |
Giuseppe CAVALLARO | 0982a0f | 2013-03-26 04:43:07 +0000 | [diff] [blame] | 2542 | if (status & CORE_IRQ_TX_PATH_IN_LPI_MODE) |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 2543 | priv->tx_path_in_lpi_mode = true; |
Giuseppe CAVALLARO | 0982a0f | 2013-03-26 04:43:07 +0000 | [diff] [blame] | 2544 | if (status & CORE_IRQ_TX_PATH_EXIT_LPI_MODE) |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 2545 | priv->tx_path_in_lpi_mode = false; |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 2546 | } |
| 2547 | } |
| 2548 | |
| 2549 | /* To handle DMA interrupts */ |
Giuseppe CAVALLARO | aec7ff2 | 2010-01-06 23:07:18 +0000 | [diff] [blame] | 2550 | stmmac_dma_interrupt(priv); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2551 | |
| 2552 | return IRQ_HANDLED; |
| 2553 | } |
| 2554 | |
| 2555 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2556 | /* Polling receive - used by NETCONSOLE and other diagnostic tools |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 2557 | * to allow network I/O with interrupts disabled. |
| 2558 | */ |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2559 | static void stmmac_poll_controller(struct net_device *dev) |
| 2560 | { |
| 2561 | disable_irq(dev->irq); |
| 2562 | stmmac_interrupt(dev->irq, dev); |
| 2563 | enable_irq(dev->irq); |
| 2564 | } |
| 2565 | #endif |
| 2566 | |
| 2567 | /** |
| 2568 | * stmmac_ioctl - Entry point for the Ioctl |
| 2569 | * @dev: Device pointer. |
| 2570 | * @rq: An IOCTL specefic structure, that can contain a pointer to |
| 2571 | * a proprietary structure used to pass information to the driver. |
| 2572 | * @cmd: IOCTL command |
| 2573 | * Description: |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 2574 | * Currently it supports the phy_mii_ioctl(...) and HW time stamping. |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2575 | */ |
| 2576 | static int stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 2577 | { |
| 2578 | struct stmmac_priv *priv = netdev_priv(dev); |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 2579 | int ret = -EOPNOTSUPP; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2580 | |
| 2581 | if (!netif_running(dev)) |
| 2582 | return -EINVAL; |
| 2583 | |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 2584 | switch (cmd) { |
| 2585 | case SIOCGMIIPHY: |
| 2586 | case SIOCGMIIREG: |
| 2587 | case SIOCSMIIREG: |
| 2588 | if (!priv->phydev) |
| 2589 | return -EINVAL; |
| 2590 | ret = phy_mii_ioctl(priv->phydev, rq, cmd); |
| 2591 | break; |
| 2592 | case SIOCSHWTSTAMP: |
| 2593 | ret = stmmac_hwtstamp_ioctl(dev, rq); |
| 2594 | break; |
| 2595 | default: |
| 2596 | break; |
| 2597 | } |
Richard Cochran | 28b0411 | 2010-07-17 08:48:55 +0000 | [diff] [blame] | 2598 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2599 | return ret; |
| 2600 | } |
| 2601 | |
Giuseppe CAVALLARO | 50fb4f74 | 2014-11-04 15:49:33 +0100 | [diff] [blame] | 2602 | #ifdef CONFIG_DEBUG_FS |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 2603 | static struct dentry *stmmac_fs_dir; |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 2604 | |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2605 | static void sysfs_display_ring(void *head, int size, int extend_desc, |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 2606 | struct seq_file *seq) |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 2607 | { |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 2608 | int i; |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 2609 | struct dma_extended_desc *ep = (struct dma_extended_desc *)head; |
| 2610 | struct dma_desc *p = (struct dma_desc *)head; |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 2611 | |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2612 | for (i = 0; i < size; i++) { |
| 2613 | u64 x; |
| 2614 | if (extend_desc) { |
| 2615 | x = *(u64 *) ep; |
| 2616 | 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] | 2617 | i, (unsigned int)virt_to_phys(ep), |
| 2618 | (unsigned int)x, (unsigned int)(x >> 32), |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2619 | ep->basic.des2, ep->basic.des3); |
| 2620 | ep++; |
| 2621 | } else { |
| 2622 | x = *(u64 *) p; |
| 2623 | 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] | 2624 | i, (unsigned int)virt_to_phys(ep), |
| 2625 | (unsigned int)x, (unsigned int)(x >> 32), |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2626 | p->des2, p->des3); |
| 2627 | p++; |
| 2628 | } |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 2629 | seq_printf(seq, "\n"); |
| 2630 | } |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2631 | } |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 2632 | |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2633 | static int stmmac_sysfs_ring_read(struct seq_file *seq, void *v) |
| 2634 | { |
| 2635 | struct net_device *dev = seq->private; |
| 2636 | struct stmmac_priv *priv = netdev_priv(dev); |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 2637 | |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2638 | if (priv->extend_desc) { |
| 2639 | seq_printf(seq, "Extended RX descriptor ring:\n"); |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 2640 | sysfs_display_ring((void *)priv->dma_erx, DMA_RX_SIZE, 1, seq); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2641 | seq_printf(seq, "Extended TX descriptor ring:\n"); |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 2642 | sysfs_display_ring((void *)priv->dma_etx, DMA_TX_SIZE, 1, seq); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2643 | } else { |
| 2644 | seq_printf(seq, "RX descriptor ring:\n"); |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 2645 | sysfs_display_ring((void *)priv->dma_rx, DMA_RX_SIZE, 0, seq); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2646 | seq_printf(seq, "TX descriptor ring:\n"); |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 2647 | sysfs_display_ring((void *)priv->dma_tx, DMA_TX_SIZE, 0, seq); |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 2648 | } |
| 2649 | |
| 2650 | return 0; |
| 2651 | } |
| 2652 | |
| 2653 | static int stmmac_sysfs_ring_open(struct inode *inode, struct file *file) |
| 2654 | { |
| 2655 | return single_open(file, stmmac_sysfs_ring_read, inode->i_private); |
| 2656 | } |
| 2657 | |
| 2658 | static const struct file_operations stmmac_rings_status_fops = { |
| 2659 | .owner = THIS_MODULE, |
| 2660 | .open = stmmac_sysfs_ring_open, |
| 2661 | .read = seq_read, |
| 2662 | .llseek = seq_lseek, |
Djalal Harouni | 7486394 | 2012-05-20 13:55:30 +0000 | [diff] [blame] | 2663 | .release = single_release, |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 2664 | }; |
| 2665 | |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 2666 | static int stmmac_sysfs_dma_cap_read(struct seq_file *seq, void *v) |
| 2667 | { |
| 2668 | struct net_device *dev = seq->private; |
| 2669 | struct stmmac_priv *priv = netdev_priv(dev); |
| 2670 | |
Giuseppe CAVALLARO | 19e30c1 | 2011-11-16 21:58:00 +0000 | [diff] [blame] | 2671 | if (!priv->hw_cap_support) { |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 2672 | seq_printf(seq, "DMA HW features not supported\n"); |
| 2673 | return 0; |
| 2674 | } |
| 2675 | |
| 2676 | seq_printf(seq, "==============================\n"); |
| 2677 | seq_printf(seq, "\tDMA HW features\n"); |
| 2678 | seq_printf(seq, "==============================\n"); |
| 2679 | |
| 2680 | seq_printf(seq, "\t10/100 Mbps %s\n", |
| 2681 | (priv->dma_cap.mbps_10_100) ? "Y" : "N"); |
| 2682 | seq_printf(seq, "\t1000 Mbps %s\n", |
| 2683 | (priv->dma_cap.mbps_1000) ? "Y" : "N"); |
| 2684 | seq_printf(seq, "\tHalf duple %s\n", |
| 2685 | (priv->dma_cap.half_duplex) ? "Y" : "N"); |
| 2686 | seq_printf(seq, "\tHash Filter: %s\n", |
| 2687 | (priv->dma_cap.hash_filter) ? "Y" : "N"); |
| 2688 | seq_printf(seq, "\tMultiple MAC address registers: %s\n", |
| 2689 | (priv->dma_cap.multi_addr) ? "Y" : "N"); |
| 2690 | seq_printf(seq, "\tPCS (TBI/SGMII/RTBI PHY interfatces): %s\n", |
| 2691 | (priv->dma_cap.pcs) ? "Y" : "N"); |
| 2692 | seq_printf(seq, "\tSMA (MDIO) Interface: %s\n", |
| 2693 | (priv->dma_cap.sma_mdio) ? "Y" : "N"); |
| 2694 | seq_printf(seq, "\tPMT Remote wake up: %s\n", |
| 2695 | (priv->dma_cap.pmt_remote_wake_up) ? "Y" : "N"); |
| 2696 | seq_printf(seq, "\tPMT Magic Frame: %s\n", |
| 2697 | (priv->dma_cap.pmt_magic_frame) ? "Y" : "N"); |
| 2698 | seq_printf(seq, "\tRMON module: %s\n", |
| 2699 | (priv->dma_cap.rmon) ? "Y" : "N"); |
| 2700 | seq_printf(seq, "\tIEEE 1588-2002 Time Stamp: %s\n", |
| 2701 | (priv->dma_cap.time_stamp) ? "Y" : "N"); |
| 2702 | seq_printf(seq, "\tIEEE 1588-2008 Advanced Time Stamp:%s\n", |
| 2703 | (priv->dma_cap.atime_stamp) ? "Y" : "N"); |
| 2704 | seq_printf(seq, "\t802.3az - Energy-Efficient Ethernet (EEE) %s\n", |
| 2705 | (priv->dma_cap.eee) ? "Y" : "N"); |
| 2706 | seq_printf(seq, "\tAV features: %s\n", (priv->dma_cap.av) ? "Y" : "N"); |
| 2707 | seq_printf(seq, "\tChecksum Offload in TX: %s\n", |
| 2708 | (priv->dma_cap.tx_coe) ? "Y" : "N"); |
| 2709 | seq_printf(seq, "\tIP Checksum Offload (type1) in RX: %s\n", |
| 2710 | (priv->dma_cap.rx_coe_type1) ? "Y" : "N"); |
| 2711 | seq_printf(seq, "\tIP Checksum Offload (type2) in RX: %s\n", |
| 2712 | (priv->dma_cap.rx_coe_type2) ? "Y" : "N"); |
| 2713 | seq_printf(seq, "\tRXFIFO > 2048bytes: %s\n", |
| 2714 | (priv->dma_cap.rxfifo_over_2048) ? "Y" : "N"); |
| 2715 | seq_printf(seq, "\tNumber of Additional RX channel: %d\n", |
| 2716 | priv->dma_cap.number_rx_channel); |
| 2717 | seq_printf(seq, "\tNumber of Additional TX channel: %d\n", |
| 2718 | priv->dma_cap.number_tx_channel); |
| 2719 | seq_printf(seq, "\tEnhanced descriptors: %s\n", |
| 2720 | (priv->dma_cap.enh_desc) ? "Y" : "N"); |
| 2721 | |
| 2722 | return 0; |
| 2723 | } |
| 2724 | |
| 2725 | static int stmmac_sysfs_dma_cap_open(struct inode *inode, struct file *file) |
| 2726 | { |
| 2727 | return single_open(file, stmmac_sysfs_dma_cap_read, inode->i_private); |
| 2728 | } |
| 2729 | |
| 2730 | static const struct file_operations stmmac_dma_cap_fops = { |
| 2731 | .owner = THIS_MODULE, |
| 2732 | .open = stmmac_sysfs_dma_cap_open, |
| 2733 | .read = seq_read, |
| 2734 | .llseek = seq_lseek, |
Djalal Harouni | 7486394 | 2012-05-20 13:55:30 +0000 | [diff] [blame] | 2735 | .release = single_release, |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 2736 | }; |
| 2737 | |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 2738 | static int stmmac_init_fs(struct net_device *dev) |
| 2739 | { |
Mathieu Olivari | 466c5ac | 2015-05-22 19:03:29 -0700 | [diff] [blame] | 2740 | struct stmmac_priv *priv = netdev_priv(dev); |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 2741 | |
Mathieu Olivari | 466c5ac | 2015-05-22 19:03:29 -0700 | [diff] [blame] | 2742 | /* Create per netdev entries */ |
| 2743 | priv->dbgfs_dir = debugfs_create_dir(dev->name, stmmac_fs_dir); |
| 2744 | |
| 2745 | if (!priv->dbgfs_dir || IS_ERR(priv->dbgfs_dir)) { |
| 2746 | pr_err("ERROR %s/%s, debugfs create directory failed\n", |
| 2747 | STMMAC_RESOURCE_NAME, dev->name); |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 2748 | |
| 2749 | return -ENOMEM; |
| 2750 | } |
| 2751 | |
| 2752 | /* Entry to report DMA RX/TX rings */ |
Mathieu Olivari | 466c5ac | 2015-05-22 19:03:29 -0700 | [diff] [blame] | 2753 | priv->dbgfs_rings_status = |
| 2754 | debugfs_create_file("descriptors_status", S_IRUGO, |
| 2755 | priv->dbgfs_dir, dev, |
| 2756 | &stmmac_rings_status_fops); |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 2757 | |
Mathieu Olivari | 466c5ac | 2015-05-22 19:03:29 -0700 | [diff] [blame] | 2758 | if (!priv->dbgfs_rings_status || IS_ERR(priv->dbgfs_rings_status)) { |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 2759 | pr_info("ERROR creating stmmac ring debugfs file\n"); |
Mathieu Olivari | 466c5ac | 2015-05-22 19:03:29 -0700 | [diff] [blame] | 2760 | debugfs_remove_recursive(priv->dbgfs_dir); |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 2761 | |
| 2762 | return -ENOMEM; |
| 2763 | } |
| 2764 | |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 2765 | /* Entry to report the DMA HW features */ |
Mathieu Olivari | 466c5ac | 2015-05-22 19:03:29 -0700 | [diff] [blame] | 2766 | priv->dbgfs_dma_cap = debugfs_create_file("dma_cap", S_IRUGO, |
| 2767 | priv->dbgfs_dir, |
| 2768 | dev, &stmmac_dma_cap_fops); |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 2769 | |
Mathieu Olivari | 466c5ac | 2015-05-22 19:03:29 -0700 | [diff] [blame] | 2770 | if (!priv->dbgfs_dma_cap || IS_ERR(priv->dbgfs_dma_cap)) { |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 2771 | pr_info("ERROR creating stmmac MMC debugfs file\n"); |
Mathieu Olivari | 466c5ac | 2015-05-22 19:03:29 -0700 | [diff] [blame] | 2772 | debugfs_remove_recursive(priv->dbgfs_dir); |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 2773 | |
| 2774 | return -ENOMEM; |
| 2775 | } |
| 2776 | |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 2777 | return 0; |
| 2778 | } |
| 2779 | |
Mathieu Olivari | 466c5ac | 2015-05-22 19:03:29 -0700 | [diff] [blame] | 2780 | static void stmmac_exit_fs(struct net_device *dev) |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 2781 | { |
Mathieu Olivari | 466c5ac | 2015-05-22 19:03:29 -0700 | [diff] [blame] | 2782 | struct stmmac_priv *priv = netdev_priv(dev); |
| 2783 | |
| 2784 | debugfs_remove_recursive(priv->dbgfs_dir); |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 2785 | } |
Giuseppe CAVALLARO | 50fb4f74 | 2014-11-04 15:49:33 +0100 | [diff] [blame] | 2786 | #endif /* CONFIG_DEBUG_FS */ |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 2787 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2788 | static const struct net_device_ops stmmac_netdev_ops = { |
| 2789 | .ndo_open = stmmac_open, |
| 2790 | .ndo_start_xmit = stmmac_xmit, |
| 2791 | .ndo_stop = stmmac_release, |
| 2792 | .ndo_change_mtu = stmmac_change_mtu, |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 2793 | .ndo_fix_features = stmmac_fix_features, |
Giuseppe CAVALLARO | d2afb5b | 2014-09-01 09:17:52 +0200 | [diff] [blame] | 2794 | .ndo_set_features = stmmac_set_features, |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 2795 | .ndo_set_rx_mode = stmmac_set_rx_mode, |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2796 | .ndo_tx_timeout = stmmac_tx_timeout, |
| 2797 | .ndo_do_ioctl = stmmac_ioctl, |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2798 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2799 | .ndo_poll_controller = stmmac_poll_controller, |
| 2800 | #endif |
| 2801 | .ndo_set_mac_address = eth_mac_addr, |
| 2802 | }; |
| 2803 | |
| 2804 | /** |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 2805 | * stmmac_hw_init - Init the MAC device |
Giuseppe CAVALLARO | 32ceabc | 2013-04-08 02:10:00 +0000 | [diff] [blame] | 2806 | * @priv: driver private structure |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 2807 | * Description: this function is to configure the MAC device according to |
| 2808 | * some platform parameters or the HW capability register. It prepares the |
| 2809 | * driver to use either ring or chain modes and to setup either enhanced or |
| 2810 | * normal descriptors. |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 2811 | */ |
| 2812 | static int stmmac_hw_init(struct stmmac_priv *priv) |
| 2813 | { |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 2814 | struct mac_device_info *mac; |
| 2815 | |
| 2816 | /* Identify the MAC HW device */ |
Marc Kleine-Budde | 03f2eec | 2012-04-03 22:13:01 +0000 | [diff] [blame] | 2817 | if (priv->plat->has_gmac) { |
| 2818 | priv->dev->priv_flags |= IFF_UNICAST_FLT; |
Vince Bridgers | 3b57de9 | 2014-07-31 15:49:17 -0500 | [diff] [blame] | 2819 | mac = dwmac1000_setup(priv->ioaddr, |
| 2820 | priv->plat->multicast_filter_bins, |
| 2821 | priv->plat->unicast_filter_entries); |
Marc Kleine-Budde | 03f2eec | 2012-04-03 22:13:01 +0000 | [diff] [blame] | 2822 | } else { |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 2823 | mac = dwmac100_setup(priv->ioaddr); |
Marc Kleine-Budde | 03f2eec | 2012-04-03 22:13:01 +0000 | [diff] [blame] | 2824 | } |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 2825 | if (!mac) |
| 2826 | return -ENOMEM; |
| 2827 | |
| 2828 | priv->hw = mac; |
| 2829 | |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 2830 | /* Get and dump the chip ID */ |
Giuseppe CAVALLARO | cffb13f | 2012-05-13 22:18:41 +0000 | [diff] [blame] | 2831 | priv->synopsys_id = stmmac_get_synopsys_id(priv); |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 2832 | |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 2833 | /* To use the chained or ring mode */ |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 2834 | if (chain_mode) { |
Giuseppe CAVALLARO | 29896a6 | 2014-03-10 13:40:33 +0100 | [diff] [blame] | 2835 | priv->hw->mode = &chain_mode_ops; |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 2836 | pr_info(" Chain mode enabled\n"); |
| 2837 | priv->mode = STMMAC_CHAIN_MODE; |
| 2838 | } else { |
Giuseppe CAVALLARO | 29896a6 | 2014-03-10 13:40:33 +0100 | [diff] [blame] | 2839 | priv->hw->mode = &ring_mode_ops; |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 2840 | pr_info(" Ring mode enabled\n"); |
| 2841 | priv->mode = STMMAC_RING_MODE; |
| 2842 | } |
| 2843 | |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 2844 | /* Get the HW capability (new GMAC newer than 3.50a) */ |
| 2845 | priv->hw_cap_support = stmmac_get_hw_features(priv); |
| 2846 | if (priv->hw_cap_support) { |
| 2847 | pr_info(" DMA HW capability register supported"); |
| 2848 | |
| 2849 | /* We can override some gmac/dma configuration fields: e.g. |
| 2850 | * enh_desc, tx_coe (e.g. that are passed through the |
| 2851 | * platform) with the values from the HW capability |
| 2852 | * register (if supported). |
| 2853 | */ |
| 2854 | priv->plat->enh_desc = priv->dma_cap.enh_desc; |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 2855 | priv->plat->pmt = priv->dma_cap.pmt_remote_wake_up; |
Deepak SIKRI | 38912bd | 2012-04-04 04:33:21 +0000 | [diff] [blame] | 2856 | |
Sonic Zhang | dec2165 | 2015-01-22 14:55:57 +0800 | [diff] [blame] | 2857 | /* TXCOE doesn't work in thresh DMA mode */ |
| 2858 | if (priv->plat->force_thresh_dma_mode) |
| 2859 | priv->plat->tx_coe = 0; |
| 2860 | else |
| 2861 | priv->plat->tx_coe = priv->dma_cap.tx_coe; |
Deepak SIKRI | 38912bd | 2012-04-04 04:33:21 +0000 | [diff] [blame] | 2862 | |
| 2863 | if (priv->dma_cap.rx_coe_type2) |
| 2864 | priv->plat->rx_coe = STMMAC_RX_COE_TYPE2; |
| 2865 | else if (priv->dma_cap.rx_coe_type1) |
| 2866 | priv->plat->rx_coe = STMMAC_RX_COE_TYPE1; |
| 2867 | |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 2868 | } else |
| 2869 | pr_info(" No HW DMA feature register supported"); |
| 2870 | |
Byungho An | 61369d0 | 2013-06-28 16:35:32 +0900 | [diff] [blame] | 2871 | /* To use alternate (extended) or normal descriptor structures */ |
| 2872 | stmmac_selec_desc_mode(priv); |
| 2873 | |
Giuseppe CAVALLARO | d2afb5b | 2014-09-01 09:17:52 +0200 | [diff] [blame] | 2874 | if (priv->plat->rx_coe) { |
| 2875 | priv->hw->rx_csum = priv->plat->rx_coe; |
Deepak SIKRI | 38912bd | 2012-04-04 04:33:21 +0000 | [diff] [blame] | 2876 | pr_info(" RX Checksum Offload Engine supported (type %d)\n", |
| 2877 | priv->plat->rx_coe); |
Giuseppe CAVALLARO | d2afb5b | 2014-09-01 09:17:52 +0200 | [diff] [blame] | 2878 | } |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 2879 | if (priv->plat->tx_coe) |
| 2880 | pr_info(" TX Checksum insertion supported\n"); |
| 2881 | |
| 2882 | if (priv->plat->pmt) { |
| 2883 | pr_info(" Wake-Up On Lan supported\n"); |
| 2884 | device_set_wakeup_capable(priv->device, 1); |
| 2885 | } |
| 2886 | |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2887 | return 0; |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 2888 | } |
| 2889 | |
| 2890 | /** |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2891 | * stmmac_dvr_probe |
| 2892 | * @device: device pointer |
Giuseppe CAVALLARO | ff3dd78 | 2012-06-04 19:22:55 +0000 | [diff] [blame] | 2893 | * @plat_dat: platform data pointer |
Joachim Eastwood | e56788c | 2015-05-20 20:03:07 +0200 | [diff] [blame] | 2894 | * @res: stmmac resource pointer |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2895 | * Description: this is the main probe function used to |
| 2896 | * call the alloc_etherdev, allocate the priv structure. |
Andy Shevchenko | 9afec6e | 2015-01-27 18:38:03 +0200 | [diff] [blame] | 2897 | * Return: |
Joachim Eastwood | 15ffac7 | 2015-05-20 20:03:08 +0200 | [diff] [blame] | 2898 | * returns 0 on success, otherwise errno. |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2899 | */ |
Joachim Eastwood | 15ffac7 | 2015-05-20 20:03:08 +0200 | [diff] [blame] | 2900 | int stmmac_dvr_probe(struct device *device, |
| 2901 | struct plat_stmmacenet_data *plat_dat, |
| 2902 | struct stmmac_resources *res) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2903 | { |
| 2904 | int ret = 0; |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2905 | struct net_device *ndev = NULL; |
| 2906 | struct stmmac_priv *priv; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2907 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2908 | ndev = alloc_etherdev(sizeof(struct stmmac_priv)); |
Joe Perches | 41de8d4 | 2012-01-29 13:47:52 +0000 | [diff] [blame] | 2909 | if (!ndev) |
Joachim Eastwood | 15ffac7 | 2015-05-20 20:03:08 +0200 | [diff] [blame] | 2910 | return -ENOMEM; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2911 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2912 | SET_NETDEV_DEV(ndev, device); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2913 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2914 | priv = netdev_priv(ndev); |
| 2915 | priv->device = device; |
| 2916 | priv->dev = ndev; |
| 2917 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2918 | stmmac_set_ethtool_ops(ndev); |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 2919 | priv->pause = pause; |
| 2920 | priv->plat = plat_dat; |
Joachim Eastwood | e56788c | 2015-05-20 20:03:07 +0200 | [diff] [blame] | 2921 | priv->ioaddr = res->addr; |
| 2922 | priv->dev->base_addr = (unsigned long)res->addr; |
| 2923 | |
| 2924 | priv->dev->irq = res->irq; |
| 2925 | priv->wol_irq = res->wol_irq; |
| 2926 | priv->lpi_irq = res->lpi_irq; |
| 2927 | |
| 2928 | if (res->mac) |
| 2929 | memcpy(priv->dev->dev_addr, res->mac, ETH_ALEN); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2930 | |
Joachim Eastwood | a7a6268 | 2015-07-17 23:48:17 +0200 | [diff] [blame] | 2931 | dev_set_drvdata(device, priv->dev); |
Joachim Eastwood | 803f8fc | 2015-05-20 20:03:06 +0200 | [diff] [blame] | 2932 | |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 2933 | /* Verify driver arguments */ |
| 2934 | stmmac_verify_args(); |
| 2935 | |
| 2936 | /* Override with kernel parameters if supplied XXX CRS XXX |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 2937 | * this needs to have multiple instances |
| 2938 | */ |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 2939 | if ((phyaddr >= 0) && (phyaddr <= 31)) |
| 2940 | priv->plat->phy_addr = phyaddr; |
| 2941 | |
Chen-Yu Tsai | 62866e9 | 2014-01-17 21:24:40 +0800 | [diff] [blame] | 2942 | priv->stmmac_clk = devm_clk_get(priv->device, STMMAC_RESOURCE_NAME); |
| 2943 | if (IS_ERR(priv->stmmac_clk)) { |
| 2944 | dev_warn(priv->device, "%s: warning: cannot get CSR clock\n", |
| 2945 | __func__); |
Kweh, Hock Leong | c5bb86c | 2014-09-26 21:42:55 +0800 | [diff] [blame] | 2946 | /* If failed to obtain stmmac_clk and specific clk_csr value |
| 2947 | * is NOT passed from the platform, probe fail. |
| 2948 | */ |
| 2949 | if (!priv->plat->clk_csr) { |
| 2950 | ret = PTR_ERR(priv->stmmac_clk); |
| 2951 | goto error_clk_get; |
| 2952 | } else { |
| 2953 | priv->stmmac_clk = NULL; |
| 2954 | } |
Chen-Yu Tsai | 62866e9 | 2014-01-17 21:24:40 +0800 | [diff] [blame] | 2955 | } |
| 2956 | clk_prepare_enable(priv->stmmac_clk); |
| 2957 | |
Andrew Bresticker | 5f9755d | 2015-04-07 13:38:45 -0700 | [diff] [blame] | 2958 | priv->pclk = devm_clk_get(priv->device, "pclk"); |
| 2959 | if (IS_ERR(priv->pclk)) { |
| 2960 | if (PTR_ERR(priv->pclk) == -EPROBE_DEFER) { |
| 2961 | ret = -EPROBE_DEFER; |
| 2962 | goto error_pclk_get; |
| 2963 | } |
| 2964 | priv->pclk = NULL; |
| 2965 | } |
| 2966 | clk_prepare_enable(priv->pclk); |
| 2967 | |
Chen-Yu Tsai | c5e4ddb | 2014-01-17 21:24:41 +0800 | [diff] [blame] | 2968 | priv->stmmac_rst = devm_reset_control_get(priv->device, |
| 2969 | STMMAC_RESOURCE_NAME); |
| 2970 | if (IS_ERR(priv->stmmac_rst)) { |
| 2971 | if (PTR_ERR(priv->stmmac_rst) == -EPROBE_DEFER) { |
| 2972 | ret = -EPROBE_DEFER; |
| 2973 | goto error_hw_init; |
| 2974 | } |
| 2975 | dev_info(priv->device, "no reset control found\n"); |
| 2976 | priv->stmmac_rst = NULL; |
| 2977 | } |
| 2978 | if (priv->stmmac_rst) |
| 2979 | reset_control_deassert(priv->stmmac_rst); |
| 2980 | |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 2981 | /* Init MAC and get the capabilities */ |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 2982 | ret = stmmac_hw_init(priv); |
| 2983 | if (ret) |
Chen-Yu Tsai | 62866e9 | 2014-01-17 21:24:40 +0800 | [diff] [blame] | 2984 | goto error_hw_init; |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 2985 | |
| 2986 | ndev->netdev_ops = &stmmac_netdev_ops; |
| 2987 | |
| 2988 | ndev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | |
| 2989 | NETIF_F_RXCSUM; |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2990 | ndev->features |= ndev->hw_features | NETIF_F_HIGHDMA; |
| 2991 | ndev->watchdog_timeo = msecs_to_jiffies(watchdog); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2992 | #ifdef STMMAC_VLAN_TAG_USED |
| 2993 | /* Both mac100 and gmac support receive VLAN tag detection */ |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 2994 | ndev->features |= NETIF_F_HW_VLAN_CTAG_RX; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2995 | #endif |
| 2996 | priv->msg_enable = netif_msg_init(debug, default_msg_level); |
| 2997 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2998 | if (flow_ctrl) |
| 2999 | priv->flow_ctrl = FLOW_AUTO; /* RX/TX pause on */ |
| 3000 | |
Giuseppe CAVALLARO | 62a2ab9 | 2012-11-25 23:10:43 +0000 | [diff] [blame] | 3001 | /* Rx Watchdog is available in the COREs newer than the 3.40. |
| 3002 | * In some case, for example on bugged HW this feature |
| 3003 | * has to be disable and this can be done by passing the |
| 3004 | * riwt_off field from the platform. |
| 3005 | */ |
| 3006 | if ((priv->synopsys_id >= DWMAC_CORE_3_50) && (!priv->plat->riwt_off)) { |
| 3007 | priv->use_riwt = 1; |
| 3008 | pr_info(" Enable RX Mitigation via HW Watchdog Timer\n"); |
| 3009 | } |
| 3010 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 3011 | netif_napi_add(ndev, &priv->napi, stmmac_poll, 64); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3012 | |
Vlad Lungu | f8e9616 | 2010-11-29 22:52:52 +0000 | [diff] [blame] | 3013 | spin_lock_init(&priv->lock); |
Giuseppe CAVALLARO | a9097a9 | 2011-10-18 00:01:19 +0000 | [diff] [blame] | 3014 | spin_lock_init(&priv->tx_lock); |
Vlad Lungu | f8e9616 | 2010-11-29 22:52:52 +0000 | [diff] [blame] | 3015 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 3016 | ret = register_netdev(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3017 | if (ret) { |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 3018 | pr_err("%s: ERROR %i registering the device\n", __func__, ret); |
Viresh Kumar | 6a81c26 | 2012-07-30 14:39:41 -0700 | [diff] [blame] | 3019 | goto error_netdev_register; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3020 | } |
| 3021 | |
Giuseppe CAVALLARO | cd7201f | 2012-04-04 04:33:27 +0000 | [diff] [blame] | 3022 | /* If a specific clk_csr value is passed from the platform |
| 3023 | * this means that the CSR Clock Range selection cannot be |
| 3024 | * changed at run-time and it is fixed. Viceversa the driver'll try to |
| 3025 | * set the MDC clock dynamically according to the csr actual |
| 3026 | * clock input. |
| 3027 | */ |
| 3028 | if (!priv->plat->clk_csr) |
| 3029 | stmmac_clk_csr_set(priv); |
| 3030 | else |
| 3031 | priv->clk_csr = priv->plat->clk_csr; |
| 3032 | |
Giuseppe CAVALLARO | e58bb43 | 2013-03-26 04:43:08 +0000 | [diff] [blame] | 3033 | stmmac_check_pcs_mode(priv); |
| 3034 | |
Byungho An | 4d8f082 | 2013-04-07 17:56:16 +0000 | [diff] [blame] | 3035 | if (priv->pcs != STMMAC_PCS_RGMII && priv->pcs != STMMAC_PCS_TBI && |
| 3036 | priv->pcs != STMMAC_PCS_RTBI) { |
Giuseppe CAVALLARO | e58bb43 | 2013-03-26 04:43:08 +0000 | [diff] [blame] | 3037 | /* MDIO bus Registration */ |
| 3038 | ret = stmmac_mdio_register(ndev); |
| 3039 | if (ret < 0) { |
| 3040 | pr_debug("%s: MDIO bus (id: %d) registration failed", |
| 3041 | __func__, priv->plat->bus_id); |
| 3042 | goto error_mdio_register; |
| 3043 | } |
Francesco Virlinzi | 4bfcbd7 | 2012-04-18 19:48:20 +0000 | [diff] [blame] | 3044 | } |
| 3045 | |
Joachim Eastwood | 15ffac7 | 2015-05-20 20:03:08 +0200 | [diff] [blame] | 3046 | return 0; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3047 | |
Viresh Kumar | 6a81c26 | 2012-07-30 14:39:41 -0700 | [diff] [blame] | 3048 | error_mdio_register: |
Dan Carpenter | 34a52f3 | 2010-12-20 21:34:56 +0000 | [diff] [blame] | 3049 | unregister_netdev(ndev); |
Viresh Kumar | 6a81c26 | 2012-07-30 14:39:41 -0700 | [diff] [blame] | 3050 | error_netdev_register: |
| 3051 | netif_napi_del(&priv->napi); |
Chen-Yu Tsai | 62866e9 | 2014-01-17 21:24:40 +0800 | [diff] [blame] | 3052 | error_hw_init: |
Andrew Bresticker | 5f9755d | 2015-04-07 13:38:45 -0700 | [diff] [blame] | 3053 | clk_disable_unprepare(priv->pclk); |
| 3054 | error_pclk_get: |
Chen-Yu Tsai | 62866e9 | 2014-01-17 21:24:40 +0800 | [diff] [blame] | 3055 | clk_disable_unprepare(priv->stmmac_clk); |
| 3056 | error_clk_get: |
Dan Carpenter | 34a52f3 | 2010-12-20 21:34:56 +0000 | [diff] [blame] | 3057 | free_netdev(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3058 | |
Joachim Eastwood | 15ffac7 | 2015-05-20 20:03:08 +0200 | [diff] [blame] | 3059 | return ret; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3060 | } |
Andy Shevchenko | b2e2f0c | 2014-11-10 12:38:59 +0200 | [diff] [blame] | 3061 | EXPORT_SYMBOL_GPL(stmmac_dvr_probe); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3062 | |
| 3063 | /** |
| 3064 | * stmmac_dvr_remove |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 3065 | * @ndev: net device pointer |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3066 | * 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] | 3067 | * changes the link status, releases the DMA descriptor rings. |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3068 | */ |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 3069 | int stmmac_dvr_remove(struct net_device *ndev) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3070 | { |
Giuseppe CAVALLARO | aec7ff2 | 2010-01-06 23:07:18 +0000 | [diff] [blame] | 3071 | struct stmmac_priv *priv = netdev_priv(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3072 | |
| 3073 | pr_info("%s:\n\tremoving driver", __func__); |
| 3074 | |
Giuseppe CAVALLARO | ad01b7d | 2010-08-23 20:40:42 +0000 | [diff] [blame] | 3075 | priv->hw->dma->stop_rx(priv->ioaddr); |
| 3076 | priv->hw->dma->stop_tx(priv->ioaddr); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3077 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 3078 | stmmac_set_mac(priv->ioaddr, false); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3079 | netif_carrier_off(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3080 | unregister_netdev(ndev); |
Chen-Yu Tsai | c5e4ddb | 2014-01-17 21:24:41 +0800 | [diff] [blame] | 3081 | if (priv->stmmac_rst) |
| 3082 | reset_control_assert(priv->stmmac_rst); |
Andrew Bresticker | 5f9755d | 2015-04-07 13:38:45 -0700 | [diff] [blame] | 3083 | clk_disable_unprepare(priv->pclk); |
Chen-Yu Tsai | 62866e9 | 2014-01-17 21:24:40 +0800 | [diff] [blame] | 3084 | clk_disable_unprepare(priv->stmmac_clk); |
Bryan O'Donoghue | e743471 | 2015-04-16 17:56:03 +0100 | [diff] [blame] | 3085 | if (priv->pcs != STMMAC_PCS_RGMII && priv->pcs != STMMAC_PCS_TBI && |
| 3086 | priv->pcs != STMMAC_PCS_RTBI) |
| 3087 | stmmac_mdio_unregister(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3088 | free_netdev(ndev); |
| 3089 | |
| 3090 | return 0; |
| 3091 | } |
Andy Shevchenko | b2e2f0c | 2014-11-10 12:38:59 +0200 | [diff] [blame] | 3092 | EXPORT_SYMBOL_GPL(stmmac_dvr_remove); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3093 | |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 3094 | /** |
| 3095 | * stmmac_suspend - suspend callback |
| 3096 | * @ndev: net device pointer |
| 3097 | * Description: this is the function to suspend the device and it is called |
| 3098 | * by the platform driver to stop the network queue, release the resources, |
| 3099 | * program the PMT register (for WoL), clean and release driver resources. |
| 3100 | */ |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 3101 | int stmmac_suspend(struct net_device *ndev) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3102 | { |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 3103 | struct stmmac_priv *priv = netdev_priv(ndev); |
Giuseppe CAVALLARO | f8c5a87 | 2012-05-13 22:18:43 +0000 | [diff] [blame] | 3104 | unsigned long flags; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3105 | |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 3106 | if (!ndev || !netif_running(ndev)) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3107 | return 0; |
| 3108 | |
Francesco Virlinzi | 102463b | 2011-11-16 21:58:02 +0000 | [diff] [blame] | 3109 | if (priv->phydev) |
| 3110 | phy_stop(priv->phydev); |
| 3111 | |
Giuseppe CAVALLARO | f8c5a87 | 2012-05-13 22:18:43 +0000 | [diff] [blame] | 3112 | spin_lock_irqsave(&priv->lock, flags); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3113 | |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 3114 | netif_device_detach(ndev); |
| 3115 | netif_stop_queue(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3116 | |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 3117 | napi_disable(&priv->napi); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3118 | |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 3119 | /* Stop TX/RX DMA */ |
| 3120 | priv->hw->dma->stop_tx(priv->ioaddr); |
| 3121 | priv->hw->dma->stop_rx(priv->ioaddr); |
Giuseppe CAVALLARO | c24602e | 2013-03-26 04:43:06 +0000 | [diff] [blame] | 3122 | |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 3123 | /* Enable Power down mode by programming the PMT regs */ |
Srinivas Kandagatla | 89f7f2c | 2014-01-16 10:53:00 +0000 | [diff] [blame] | 3124 | if (device_may_wakeup(priv->device)) { |
Vince Bridgers | 7ed24bb | 2014-07-31 15:49:13 -0500 | [diff] [blame] | 3125 | priv->hw->mac->pmt(priv->hw, priv->wolopts); |
Srinivas Kandagatla | 89f7f2c | 2014-01-16 10:53:00 +0000 | [diff] [blame] | 3126 | priv->irq_wake = 1; |
| 3127 | } else { |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 3128 | stmmac_set_mac(priv->ioaddr, false); |
Srinivas Kandagatla | db88f10 | 2014-01-16 10:52:52 +0000 | [diff] [blame] | 3129 | pinctrl_pm_select_sleep_state(priv->device); |
Giuseppe CAVALLARO | ba1377ff | 2012-04-04 04:33:25 +0000 | [diff] [blame] | 3130 | /* Disable clock in case of PWM is off */ |
Andrew Bresticker | 5f9755d | 2015-04-07 13:38:45 -0700 | [diff] [blame] | 3131 | clk_disable(priv->pclk); |
Giuseppe CAVALLARO | 777da23 | 2014-11-04 17:08:09 +0100 | [diff] [blame] | 3132 | clk_disable(priv->stmmac_clk); |
Giuseppe CAVALLARO | ba1377ff | 2012-04-04 04:33:25 +0000 | [diff] [blame] | 3133 | } |
Giuseppe CAVALLARO | f8c5a87 | 2012-05-13 22:18:43 +0000 | [diff] [blame] | 3134 | spin_unlock_irqrestore(&priv->lock, flags); |
Vince Bridgers | 2d871aa | 2014-07-28 14:07:58 -0500 | [diff] [blame] | 3135 | |
| 3136 | priv->oldlink = 0; |
| 3137 | priv->speed = 0; |
| 3138 | priv->oldduplex = -1; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3139 | return 0; |
| 3140 | } |
Andy Shevchenko | b2e2f0c | 2014-11-10 12:38:59 +0200 | [diff] [blame] | 3141 | EXPORT_SYMBOL_GPL(stmmac_suspend); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3142 | |
Giuseppe CAVALLARO | 732fdf0 | 2014-11-18 09:47:01 +0100 | [diff] [blame] | 3143 | /** |
| 3144 | * stmmac_resume - resume callback |
| 3145 | * @ndev: net device pointer |
| 3146 | * Description: when resume this function is invoked to setup the DMA and CORE |
| 3147 | * in a usable state. |
| 3148 | */ |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 3149 | int stmmac_resume(struct net_device *ndev) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3150 | { |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 3151 | struct stmmac_priv *priv = netdev_priv(ndev); |
Giuseppe CAVALLARO | f8c5a87 | 2012-05-13 22:18:43 +0000 | [diff] [blame] | 3152 | unsigned long flags; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3153 | |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 3154 | if (!netif_running(ndev)) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3155 | return 0; |
| 3156 | |
Giuseppe CAVALLARO | f8c5a87 | 2012-05-13 22:18:43 +0000 | [diff] [blame] | 3157 | spin_lock_irqsave(&priv->lock, flags); |
Giuseppe Cavallaro | c4433be | 2010-09-06 05:02:11 +0200 | [diff] [blame] | 3158 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3159 | /* Power Down bit, into the PM register, is cleared |
| 3160 | * automatically as soon as a magic packet or a Wake-up frame |
| 3161 | * is received. Anyway, it's better to manually clear |
| 3162 | * this bit because it can generate problems while resuming |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 3163 | * from another devices (e.g. serial console). |
| 3164 | */ |
Srinivas Kandagatla | 623997f | 2014-01-16 10:52:35 +0000 | [diff] [blame] | 3165 | if (device_may_wakeup(priv->device)) { |
Vince Bridgers | 7ed24bb | 2014-07-31 15:49:13 -0500 | [diff] [blame] | 3166 | priv->hw->mac->pmt(priv->hw, 0); |
Srinivas Kandagatla | 89f7f2c | 2014-01-16 10:53:00 +0000 | [diff] [blame] | 3167 | priv->irq_wake = 0; |
Srinivas Kandagatla | 623997f | 2014-01-16 10:52:35 +0000 | [diff] [blame] | 3168 | } else { |
Srinivas Kandagatla | db88f10 | 2014-01-16 10:52:52 +0000 | [diff] [blame] | 3169 | pinctrl_pm_select_default_state(priv->device); |
Giuseppe CAVALLARO | ba1377ff | 2012-04-04 04:33:25 +0000 | [diff] [blame] | 3170 | /* enable the clk prevously disabled */ |
Giuseppe CAVALLARO | 777da23 | 2014-11-04 17:08:09 +0100 | [diff] [blame] | 3171 | clk_enable(priv->stmmac_clk); |
Andrew Bresticker | 5f9755d | 2015-04-07 13:38:45 -0700 | [diff] [blame] | 3172 | clk_enable(priv->pclk); |
Srinivas Kandagatla | 623997f | 2014-01-16 10:52:35 +0000 | [diff] [blame] | 3173 | /* reset the phy so that it's ready */ |
| 3174 | if (priv->mii) |
| 3175 | stmmac_mdio_reset(priv->mii); |
| 3176 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3177 | |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 3178 | netif_device_attach(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3179 | |
Giuseppe CAVALLARO | ae79a63 | 2015-12-04 07:21:06 +0100 | [diff] [blame] | 3180 | priv->cur_rx = 0; |
| 3181 | priv->dirty_rx = 0; |
| 3182 | priv->dirty_tx = 0; |
| 3183 | priv->cur_tx = 0; |
| 3184 | stmmac_clear_descriptors(priv); |
| 3185 | |
Huacai Chen | fe131929 | 2014-12-19 22:38:18 +0800 | [diff] [blame] | 3186 | stmmac_hw_setup(ndev, false); |
Giuseppe CAVALLARO | 777da23 | 2014-11-04 17:08:09 +0100 | [diff] [blame] | 3187 | stmmac_init_tx_coalesce(priv); |
Giuseppe CAVALLARO | ac316c7 | 2015-11-26 08:35:41 +0100 | [diff] [blame] | 3188 | stmmac_set_rx_mode(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3189 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3190 | napi_enable(&priv->napi); |
| 3191 | |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 3192 | netif_start_queue(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3193 | |
Giuseppe CAVALLARO | f8c5a87 | 2012-05-13 22:18:43 +0000 | [diff] [blame] | 3194 | spin_unlock_irqrestore(&priv->lock, flags); |
Francesco Virlinzi | 102463b | 2011-11-16 21:58:02 +0000 | [diff] [blame] | 3195 | |
| 3196 | if (priv->phydev) |
| 3197 | phy_start(priv->phydev); |
| 3198 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3199 | return 0; |
| 3200 | } |
Andy Shevchenko | b2e2f0c | 2014-11-10 12:38:59 +0200 | [diff] [blame] | 3201 | EXPORT_SYMBOL_GPL(stmmac_resume); |
Giuseppe CAVALLARO | ba27ec6 | 2012-06-04 19:22:57 +0000 | [diff] [blame] | 3202 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3203 | #ifndef MODULE |
| 3204 | static int __init stmmac_cmdline_opt(char *str) |
| 3205 | { |
| 3206 | char *opt; |
| 3207 | |
| 3208 | if (!str || !*str) |
| 3209 | return -EINVAL; |
| 3210 | while ((opt = strsep(&str, ",")) != NULL) { |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 3211 | if (!strncmp(opt, "debug:", 6)) { |
Giuseppe CAVALLARO | ea2ab87 | 2012-06-27 21:14:35 +0000 | [diff] [blame] | 3212 | if (kstrtoint(opt + 6, 0, &debug)) |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 3213 | goto err; |
| 3214 | } else if (!strncmp(opt, "phyaddr:", 8)) { |
Giuseppe CAVALLARO | ea2ab87 | 2012-06-27 21:14:35 +0000 | [diff] [blame] | 3215 | if (kstrtoint(opt + 8, 0, &phyaddr)) |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 3216 | goto err; |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 3217 | } else if (!strncmp(opt, "buf_sz:", 7)) { |
Giuseppe CAVALLARO | ea2ab87 | 2012-06-27 21:14:35 +0000 | [diff] [blame] | 3218 | if (kstrtoint(opt + 7, 0, &buf_sz)) |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 3219 | goto err; |
| 3220 | } else if (!strncmp(opt, "tc:", 3)) { |
Giuseppe CAVALLARO | ea2ab87 | 2012-06-27 21:14:35 +0000 | [diff] [blame] | 3221 | if (kstrtoint(opt + 3, 0, &tc)) |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 3222 | goto err; |
| 3223 | } else if (!strncmp(opt, "watchdog:", 9)) { |
Giuseppe CAVALLARO | ea2ab87 | 2012-06-27 21:14:35 +0000 | [diff] [blame] | 3224 | if (kstrtoint(opt + 9, 0, &watchdog)) |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 3225 | goto err; |
| 3226 | } else if (!strncmp(opt, "flow_ctrl:", 10)) { |
Giuseppe CAVALLARO | ea2ab87 | 2012-06-27 21:14:35 +0000 | [diff] [blame] | 3227 | if (kstrtoint(opt + 10, 0, &flow_ctrl)) |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 3228 | goto err; |
| 3229 | } else if (!strncmp(opt, "pause:", 6)) { |
Giuseppe CAVALLARO | ea2ab87 | 2012-06-27 21:14:35 +0000 | [diff] [blame] | 3230 | if (kstrtoint(opt + 6, 0, &pause)) |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 3231 | goto err; |
Giuseppe CAVALLARO | 506f669 | 2013-02-14 23:00:13 +0000 | [diff] [blame] | 3232 | } else if (!strncmp(opt, "eee_timer:", 10)) { |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 3233 | if (kstrtoint(opt + 10, 0, &eee_timer)) |
| 3234 | goto err; |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 3235 | } else if (!strncmp(opt, "chain_mode:", 11)) { |
| 3236 | if (kstrtoint(opt + 11, 0, &chain_mode)) |
| 3237 | goto err; |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 3238 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3239 | } |
| 3240 | return 0; |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 3241 | |
| 3242 | err: |
| 3243 | pr_err("%s: ERROR broken module parameter conversion", __func__); |
| 3244 | return -EINVAL; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 3245 | } |
| 3246 | |
| 3247 | __setup("stmmaceth=", stmmac_cmdline_opt); |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 3248 | #endif /* MODULE */ |
Giuseppe Cavallaro | 6fc0d0f | 2011-12-23 14:21:20 -0500 | [diff] [blame] | 3249 | |
Mathieu Olivari | 466c5ac | 2015-05-22 19:03:29 -0700 | [diff] [blame] | 3250 | static int __init stmmac_init(void) |
| 3251 | { |
| 3252 | #ifdef CONFIG_DEBUG_FS |
| 3253 | /* Create debugfs main directory if it doesn't exist yet */ |
| 3254 | if (!stmmac_fs_dir) { |
| 3255 | stmmac_fs_dir = debugfs_create_dir(STMMAC_RESOURCE_NAME, NULL); |
| 3256 | |
| 3257 | if (!stmmac_fs_dir || IS_ERR(stmmac_fs_dir)) { |
| 3258 | pr_err("ERROR %s, debugfs create directory failed\n", |
| 3259 | STMMAC_RESOURCE_NAME); |
| 3260 | |
| 3261 | return -ENOMEM; |
| 3262 | } |
| 3263 | } |
| 3264 | #endif |
| 3265 | |
| 3266 | return 0; |
| 3267 | } |
| 3268 | |
| 3269 | static void __exit stmmac_exit(void) |
| 3270 | { |
| 3271 | #ifdef CONFIG_DEBUG_FS |
| 3272 | debugfs_remove_recursive(stmmac_fs_dir); |
| 3273 | #endif |
| 3274 | } |
| 3275 | |
| 3276 | module_init(stmmac_init) |
| 3277 | module_exit(stmmac_exit) |
| 3278 | |
Giuseppe Cavallaro | 6fc0d0f | 2011-12-23 14:21:20 -0500 | [diff] [blame] | 3279 | MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet device driver"); |
| 3280 | MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>"); |
| 3281 | MODULE_LICENSE("GPL"); |