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> |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 46 | #ifdef CONFIG_STMMAC_DEBUG_FS |
| 47 | #include <linux/debugfs.h> |
| 48 | #include <linux/seq_file.h> |
| 49 | #endif |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 50 | #include "stmmac.h" |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 51 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 52 | #undef STMMAC_DEBUG |
| 53 | /*#define STMMAC_DEBUG*/ |
| 54 | #ifdef STMMAC_DEBUG |
| 55 | #define DBG(nlevel, klevel, fmt, args...) \ |
| 56 | ((void)(netif_msg_##nlevel(priv) && \ |
| 57 | printk(KERN_##klevel fmt, ## args))) |
| 58 | #else |
| 59 | #define DBG(nlevel, klevel, fmt, args...) do { } while (0) |
| 60 | #endif |
| 61 | |
| 62 | #undef STMMAC_RX_DEBUG |
| 63 | /*#define STMMAC_RX_DEBUG*/ |
| 64 | #ifdef STMMAC_RX_DEBUG |
| 65 | #define RX_DBG(fmt, args...) printk(fmt, ## args) |
| 66 | #else |
| 67 | #define RX_DBG(fmt, args...) do { } while (0) |
| 68 | #endif |
| 69 | |
| 70 | #undef STMMAC_XMIT_DEBUG |
| 71 | /*#define STMMAC_XMIT_DEBUG*/ |
Giuseppe CAVALLARO | de53d55 | 2013-02-06 20:47:51 +0000 | [diff] [blame] | 72 | #ifdef STMMAC_XMIT_DEBUG |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 73 | #define TX_DBG(fmt, args...) printk(fmt, ## args) |
| 74 | #else |
| 75 | #define TX_DBG(fmt, args...) do { } while (0) |
| 76 | #endif |
| 77 | |
| 78 | #define STMMAC_ALIGN(x) L1_CACHE_ALIGN(x) |
| 79 | #define JUMBO_LEN 9000 |
| 80 | |
| 81 | /* Module parameters */ |
| 82 | #define TX_TIMEO 5000 /* default 5 seconds */ |
| 83 | static int watchdog = TX_TIMEO; |
| 84 | module_param(watchdog, int, S_IRUGO | S_IWUSR); |
| 85 | MODULE_PARM_DESC(watchdog, "Transmit timeout in milliseconds"); |
| 86 | |
| 87 | static int debug = -1; /* -1: default, 0: no output, 16: all */ |
| 88 | module_param(debug, int, S_IRUGO | S_IWUSR); |
| 89 | MODULE_PARM_DESC(debug, "Message Level (0: no output, 16: all)"); |
| 90 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 91 | int phyaddr = -1; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 92 | module_param(phyaddr, int, S_IRUGO); |
| 93 | MODULE_PARM_DESC(phyaddr, "Physical device address"); |
| 94 | |
| 95 | #define DMA_TX_SIZE 256 |
| 96 | static int dma_txsize = DMA_TX_SIZE; |
| 97 | module_param(dma_txsize, int, S_IRUGO | S_IWUSR); |
| 98 | MODULE_PARM_DESC(dma_txsize, "Number of descriptors in the TX list"); |
| 99 | |
| 100 | #define DMA_RX_SIZE 256 |
| 101 | static int dma_rxsize = DMA_RX_SIZE; |
| 102 | module_param(dma_rxsize, int, S_IRUGO | S_IWUSR); |
| 103 | MODULE_PARM_DESC(dma_rxsize, "Number of descriptors in the RX list"); |
| 104 | |
| 105 | static int flow_ctrl = FLOW_OFF; |
| 106 | module_param(flow_ctrl, int, S_IRUGO | S_IWUSR); |
| 107 | MODULE_PARM_DESC(flow_ctrl, "Flow control ability [on/off]"); |
| 108 | |
| 109 | static int pause = PAUSE_TIME; |
| 110 | module_param(pause, int, S_IRUGO | S_IWUSR); |
| 111 | MODULE_PARM_DESC(pause, "Flow Control Pause Time"); |
| 112 | |
| 113 | #define TC_DEFAULT 64 |
| 114 | static int tc = TC_DEFAULT; |
| 115 | module_param(tc, int, S_IRUGO | S_IWUSR); |
| 116 | MODULE_PARM_DESC(tc, "DMA threshold control value"); |
| 117 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 118 | #define DMA_BUFFER_SIZE BUF_SIZE_2KiB |
| 119 | static int buf_sz = DMA_BUFFER_SIZE; |
| 120 | module_param(buf_sz, int, S_IRUGO | S_IWUSR); |
| 121 | MODULE_PARM_DESC(buf_sz, "DMA buffer size"); |
| 122 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 123 | static const u32 default_msg_level = (NETIF_MSG_DRV | NETIF_MSG_PROBE | |
| 124 | NETIF_MSG_LINK | NETIF_MSG_IFUP | |
| 125 | NETIF_MSG_IFDOWN | NETIF_MSG_TIMER); |
| 126 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 127 | #define STMMAC_DEFAULT_LPI_TIMER 1000 |
| 128 | static int eee_timer = STMMAC_DEFAULT_LPI_TIMER; |
| 129 | module_param(eee_timer, int, S_IRUGO | S_IWUSR); |
| 130 | MODULE_PARM_DESC(eee_timer, "LPI tx expiration time in msec"); |
| 131 | #define STMMAC_LPI_TIMER(x) (jiffies + msecs_to_jiffies(x)) |
| 132 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 133 | static irqreturn_t stmmac_interrupt(int irq, void *dev_id); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 134 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 135 | #ifdef CONFIG_STMMAC_DEBUG_FS |
| 136 | static int stmmac_init_fs(struct net_device *dev); |
| 137 | static void stmmac_exit_fs(void); |
| 138 | #endif |
| 139 | |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 140 | #define STMMAC_COAL_TIMER(x) (jiffies + usecs_to_jiffies(x)) |
| 141 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 142 | /** |
| 143 | * stmmac_verify_args - verify the driver parameters. |
| 144 | * Description: it verifies if some wrong parameter is passed to the driver. |
| 145 | * Note that wrong parameters are replaced with the default values. |
| 146 | */ |
| 147 | static void stmmac_verify_args(void) |
| 148 | { |
| 149 | if (unlikely(watchdog < 0)) |
| 150 | watchdog = TX_TIMEO; |
| 151 | if (unlikely(dma_rxsize < 0)) |
| 152 | dma_rxsize = DMA_RX_SIZE; |
| 153 | if (unlikely(dma_txsize < 0)) |
| 154 | dma_txsize = DMA_TX_SIZE; |
| 155 | if (unlikely((buf_sz < DMA_BUFFER_SIZE) || (buf_sz > BUF_SIZE_16KiB))) |
| 156 | buf_sz = DMA_BUFFER_SIZE; |
| 157 | if (unlikely(flow_ctrl > 1)) |
| 158 | flow_ctrl = FLOW_AUTO; |
| 159 | else if (likely(flow_ctrl < 0)) |
| 160 | flow_ctrl = FLOW_OFF; |
| 161 | if (unlikely((pause < 0) || (pause > 0xffff))) |
| 162 | pause = PAUSE_TIME; |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 163 | if (eee_timer < 0) |
| 164 | eee_timer = STMMAC_DEFAULT_LPI_TIMER; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Giuseppe CAVALLARO | cd7201f | 2012-04-04 04:33:27 +0000 | [diff] [blame] | 167 | static void stmmac_clk_csr_set(struct stmmac_priv *priv) |
| 168 | { |
Giuseppe CAVALLARO | cd7201f | 2012-04-04 04:33:27 +0000 | [diff] [blame] | 169 | u32 clk_rate; |
| 170 | |
| 171 | clk_rate = clk_get_rate(priv->stmmac_clk); |
| 172 | |
| 173 | /* Platform provided default clk_csr would be assumed valid |
| 174 | * for all other cases except for the below mentioned ones. */ |
| 175 | if (!(priv->clk_csr & MAC_CSR_H_FRQ_MASK)) { |
| 176 | if (clk_rate < CSR_F_35M) |
| 177 | priv->clk_csr = STMMAC_CSR_20_35M; |
| 178 | else if ((clk_rate >= CSR_F_35M) && (clk_rate < CSR_F_60M)) |
| 179 | priv->clk_csr = STMMAC_CSR_35_60M; |
| 180 | else if ((clk_rate >= CSR_F_60M) && (clk_rate < CSR_F_100M)) |
| 181 | priv->clk_csr = STMMAC_CSR_60_100M; |
| 182 | else if ((clk_rate >= CSR_F_100M) && (clk_rate < CSR_F_150M)) |
| 183 | priv->clk_csr = STMMAC_CSR_100_150M; |
| 184 | else if ((clk_rate >= CSR_F_150M) && (clk_rate < CSR_F_250M)) |
| 185 | priv->clk_csr = STMMAC_CSR_150_250M; |
| 186 | else if ((clk_rate >= CSR_F_250M) && (clk_rate < CSR_F_300M)) |
| 187 | priv->clk_csr = STMMAC_CSR_250_300M; |
| 188 | } /* For values higher than the IEEE 802.3 specified frequency |
| 189 | * we can not estimate the proper divider as it is not known |
| 190 | * the frequency of clk_csr_i. So we do not change the default |
| 191 | * divider. */ |
Giuseppe CAVALLARO | cd7201f | 2012-04-04 04:33:27 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 194 | #if defined(STMMAC_XMIT_DEBUG) || defined(STMMAC_RX_DEBUG) |
| 195 | static void print_pkt(unsigned char *buf, int len) |
| 196 | { |
| 197 | int j; |
| 198 | pr_info("len = %d byte, buf addr: 0x%p", len, buf); |
| 199 | for (j = 0; j < len; j++) { |
| 200 | if ((j % 16) == 0) |
| 201 | pr_info("\n %03x:", j); |
| 202 | pr_info(" %02x", buf[j]); |
| 203 | } |
| 204 | pr_info("\n"); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 205 | } |
| 206 | #endif |
| 207 | |
| 208 | /* minimum number of free TX descriptors required to wake up TX process */ |
| 209 | #define STMMAC_TX_THRESH(x) (x->dma_tx_size/4) |
| 210 | |
| 211 | static inline u32 stmmac_tx_avail(struct stmmac_priv *priv) |
| 212 | { |
| 213 | return priv->dirty_tx + priv->dma_tx_size - priv->cur_tx - 1; |
| 214 | } |
| 215 | |
Giuseppe CAVALLARO | 9dfeb4d | 2010-11-24 02:37:58 +0000 | [diff] [blame] | 216 | /* On some ST platforms, some HW system configuraton registers have to be |
| 217 | * set according to the link speed negotiated. |
| 218 | */ |
| 219 | static inline void stmmac_hw_fix_mac_speed(struct stmmac_priv *priv) |
| 220 | { |
| 221 | struct phy_device *phydev = priv->phydev; |
| 222 | |
| 223 | if (likely(priv->plat->fix_mac_speed)) |
| 224 | priv->plat->fix_mac_speed(priv->plat->bsp_priv, |
| 225 | phydev->speed); |
| 226 | } |
| 227 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 228 | static void stmmac_enable_eee_mode(struct stmmac_priv *priv) |
| 229 | { |
| 230 | /* Check and enter in LPI mode */ |
| 231 | if ((priv->dirty_tx == priv->cur_tx) && |
| 232 | (priv->tx_path_in_lpi_mode == false)) |
| 233 | priv->hw->mac->set_eee_mode(priv->ioaddr); |
| 234 | } |
| 235 | |
| 236 | void stmmac_disable_eee_mode(struct stmmac_priv *priv) |
| 237 | { |
| 238 | /* Exit and disable EEE in case of we are are in LPI state. */ |
| 239 | priv->hw->mac->reset_eee_mode(priv->ioaddr); |
| 240 | del_timer_sync(&priv->eee_ctrl_timer); |
| 241 | priv->tx_path_in_lpi_mode = false; |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * stmmac_eee_ctrl_timer |
| 246 | * @arg : data hook |
| 247 | * Description: |
| 248 | * If there is no data transfer and if we are not in LPI state, |
| 249 | * then MAC Transmitter can be moved to LPI state. |
| 250 | */ |
| 251 | static void stmmac_eee_ctrl_timer(unsigned long arg) |
| 252 | { |
| 253 | struct stmmac_priv *priv = (struct stmmac_priv *)arg; |
| 254 | |
| 255 | stmmac_enable_eee_mode(priv); |
| 256 | mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_TIMER(eee_timer)); |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * stmmac_eee_init |
| 261 | * @priv: private device pointer |
| 262 | * Description: |
| 263 | * If the EEE support has been enabled while configuring the driver, |
| 264 | * if the GMAC actually supports the EEE (from the HW cap reg) and the |
| 265 | * phy can also manage EEE, so enable the LPI state and start the timer |
| 266 | * to verify if the tx path can enter in LPI state. |
| 267 | */ |
| 268 | bool stmmac_eee_init(struct stmmac_priv *priv) |
| 269 | { |
| 270 | bool ret = false; |
| 271 | |
| 272 | /* MAC core supports the EEE feature. */ |
| 273 | if (priv->dma_cap.eee) { |
| 274 | /* Check if the PHY supports EEE */ |
| 275 | if (phy_init_eee(priv->phydev, 1)) |
| 276 | goto out; |
| 277 | |
| 278 | priv->eee_active = 1; |
| 279 | init_timer(&priv->eee_ctrl_timer); |
| 280 | priv->eee_ctrl_timer.function = stmmac_eee_ctrl_timer; |
| 281 | priv->eee_ctrl_timer.data = (unsigned long)priv; |
| 282 | priv->eee_ctrl_timer.expires = STMMAC_LPI_TIMER(eee_timer); |
| 283 | add_timer(&priv->eee_ctrl_timer); |
| 284 | |
| 285 | priv->hw->mac->set_eee_timer(priv->ioaddr, |
| 286 | STMMAC_DEFAULT_LIT_LS_TIMER, |
| 287 | priv->tx_lpi_timer); |
| 288 | |
| 289 | pr_info("stmmac: Energy-Efficient Ethernet initialized\n"); |
| 290 | |
| 291 | ret = true; |
| 292 | } |
| 293 | out: |
| 294 | return ret; |
| 295 | } |
| 296 | |
| 297 | static void stmmac_eee_adjust(struct stmmac_priv *priv) |
| 298 | { |
| 299 | /* When the EEE has been already initialised we have to |
| 300 | * modify the PLS bit in the LPI ctrl & status reg according |
| 301 | * to the PHY link status. For this reason. |
| 302 | */ |
| 303 | if (priv->eee_enabled) |
| 304 | priv->hw->mac->set_eee_pls(priv->ioaddr, priv->phydev->link); |
| 305 | } |
| 306 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 307 | /** |
| 308 | * stmmac_adjust_link |
| 309 | * @dev: net device structure |
| 310 | * Description: it adjusts the link parameters. |
| 311 | */ |
| 312 | static void stmmac_adjust_link(struct net_device *dev) |
| 313 | { |
| 314 | struct stmmac_priv *priv = netdev_priv(dev); |
| 315 | struct phy_device *phydev = priv->phydev; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 316 | unsigned long flags; |
| 317 | int new_state = 0; |
| 318 | unsigned int fc = priv->flow_ctrl, pause_time = priv->pause; |
| 319 | |
| 320 | if (phydev == NULL) |
| 321 | return; |
| 322 | |
| 323 | DBG(probe, DEBUG, "stmmac_adjust_link: called. address %d link %d\n", |
| 324 | phydev->addr, phydev->link); |
| 325 | |
| 326 | spin_lock_irqsave(&priv->lock, flags); |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 327 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 328 | if (phydev->link) { |
Giuseppe CAVALLARO | ad01b7d | 2010-08-23 20:40:42 +0000 | [diff] [blame] | 329 | u32 ctrl = readl(priv->ioaddr + MAC_CTRL_REG); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 330 | |
| 331 | /* Now we make sure that we can be in full duplex mode. |
| 332 | * If not, we operate in half-duplex mode. */ |
| 333 | if (phydev->duplex != priv->oldduplex) { |
| 334 | new_state = 1; |
| 335 | if (!(phydev->duplex)) |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 336 | ctrl &= ~priv->hw->link.duplex; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 337 | else |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 338 | ctrl |= priv->hw->link.duplex; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 339 | priv->oldduplex = phydev->duplex; |
| 340 | } |
| 341 | /* Flow Control operation */ |
| 342 | if (phydev->pause) |
Giuseppe CAVALLARO | ad01b7d | 2010-08-23 20:40:42 +0000 | [diff] [blame] | 343 | priv->hw->mac->flow_ctrl(priv->ioaddr, phydev->duplex, |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 344 | fc, pause_time); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 345 | |
| 346 | if (phydev->speed != priv->speed) { |
| 347 | new_state = 1; |
| 348 | switch (phydev->speed) { |
| 349 | case 1000: |
Giuseppe CAVALLARO | 9dfeb4d | 2010-11-24 02:37:58 +0000 | [diff] [blame] | 350 | if (likely(priv->plat->has_gmac)) |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 351 | ctrl &= ~priv->hw->link.port; |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 352 | stmmac_hw_fix_mac_speed(priv); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 353 | break; |
| 354 | case 100: |
| 355 | case 10: |
Giuseppe CAVALLARO | 9dfeb4d | 2010-11-24 02:37:58 +0000 | [diff] [blame] | 356 | if (priv->plat->has_gmac) { |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 357 | ctrl |= priv->hw->link.port; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 358 | if (phydev->speed == SPEED_100) { |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 359 | ctrl |= priv->hw->link.speed; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 360 | } else { |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 361 | ctrl &= ~(priv->hw->link.speed); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 362 | } |
| 363 | } else { |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 364 | ctrl &= ~priv->hw->link.port; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 365 | } |
Giuseppe CAVALLARO | 9dfeb4d | 2010-11-24 02:37:58 +0000 | [diff] [blame] | 366 | stmmac_hw_fix_mac_speed(priv); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 367 | break; |
| 368 | default: |
| 369 | if (netif_msg_link(priv)) |
| 370 | pr_warning("%s: Speed (%d) is not 10" |
| 371 | " or 100!\n", dev->name, phydev->speed); |
| 372 | break; |
| 373 | } |
| 374 | |
| 375 | priv->speed = phydev->speed; |
| 376 | } |
| 377 | |
Giuseppe CAVALLARO | ad01b7d | 2010-08-23 20:40:42 +0000 | [diff] [blame] | 378 | writel(ctrl, priv->ioaddr + MAC_CTRL_REG); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 379 | |
| 380 | if (!priv->oldlink) { |
| 381 | new_state = 1; |
| 382 | priv->oldlink = 1; |
| 383 | } |
| 384 | } else if (priv->oldlink) { |
| 385 | new_state = 1; |
| 386 | priv->oldlink = 0; |
| 387 | priv->speed = 0; |
| 388 | priv->oldduplex = -1; |
| 389 | } |
| 390 | |
| 391 | if (new_state && netif_msg_link(priv)) |
| 392 | phy_print_status(phydev); |
| 393 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 394 | stmmac_eee_adjust(priv); |
| 395 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 396 | spin_unlock_irqrestore(&priv->lock, flags); |
| 397 | |
| 398 | DBG(probe, DEBUG, "stmmac_adjust_link: exiting\n"); |
| 399 | } |
| 400 | |
| 401 | /** |
| 402 | * stmmac_init_phy - PHY initialization |
| 403 | * @dev: net device structure |
| 404 | * Description: it initializes the driver's PHY state, and attaches the PHY |
| 405 | * to the mac driver. |
| 406 | * Return value: |
| 407 | * 0 on success |
| 408 | */ |
| 409 | static int stmmac_init_phy(struct net_device *dev) |
| 410 | { |
| 411 | struct stmmac_priv *priv = netdev_priv(dev); |
| 412 | struct phy_device *phydev; |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 413 | char phy_id_fmt[MII_BUS_ID_SIZE + 3]; |
Giuseppe CAVALLARO | 109cdd6 | 2010-01-06 23:07:11 +0000 | [diff] [blame] | 414 | char bus_id[MII_BUS_ID_SIZE]; |
Srinivas Kandagatla | 79ee1dc | 2011-10-18 00:01:18 +0000 | [diff] [blame] | 415 | int interface = priv->plat->interface; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 416 | priv->oldlink = 0; |
| 417 | priv->speed = 0; |
| 418 | priv->oldduplex = -1; |
| 419 | |
Srinivas Kandagatla | f142af2 | 2012-04-04 04:33:19 +0000 | [diff] [blame] | 420 | if (priv->plat->phy_bus_name) |
| 421 | snprintf(bus_id, MII_BUS_ID_SIZE, "%s-%x", |
| 422 | priv->plat->phy_bus_name, priv->plat->bus_id); |
| 423 | else |
| 424 | snprintf(bus_id, MII_BUS_ID_SIZE, "stmmac-%x", |
| 425 | priv->plat->bus_id); |
| 426 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 427 | snprintf(phy_id_fmt, MII_BUS_ID_SIZE + 3, PHY_ID_FMT, bus_id, |
Giuseppe CAVALLARO | 36bcfe7 | 2011-07-20 00:05:23 +0000 | [diff] [blame] | 428 | priv->plat->phy_addr); |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 429 | pr_debug("stmmac_init_phy: trying to attach to %s\n", phy_id_fmt); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 430 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 431 | phydev = phy_connect(dev, phy_id_fmt, &stmmac_adjust_link, 0, |
| 432 | interface); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 433 | |
| 434 | if (IS_ERR(phydev)) { |
| 435 | pr_err("%s: Could not attach to PHY\n", dev->name); |
| 436 | return PTR_ERR(phydev); |
| 437 | } |
| 438 | |
Srinivas Kandagatla | 79ee1dc | 2011-10-18 00:01:18 +0000 | [diff] [blame] | 439 | /* Stop Advertising 1000BASE Capability if interface is not GMII */ |
Srinivas Kandagatla | c5b9b4e | 2011-11-16 21:57:59 +0000 | [diff] [blame] | 440 | if ((interface == PHY_INTERFACE_MODE_MII) || |
| 441 | (interface == PHY_INTERFACE_MODE_RMII)) |
| 442 | phydev->advertising &= ~(SUPPORTED_1000baseT_Half | |
| 443 | SUPPORTED_1000baseT_Full); |
Srinivas Kandagatla | 79ee1dc | 2011-10-18 00:01:18 +0000 | [diff] [blame] | 444 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 445 | /* |
| 446 | * Broken HW is sometimes missing the pull-up resistor on the |
| 447 | * MDIO line, which results in reads to non-existent devices returning |
| 448 | * 0 rather than 0xffff. Catch this here and treat 0 as a non-existent |
| 449 | * device as well. |
| 450 | * Note: phydev->phy_id is the result of reading the UID PHY registers. |
| 451 | */ |
| 452 | if (phydev->phy_id == 0) { |
| 453 | phy_disconnect(phydev); |
| 454 | return -ENODEV; |
| 455 | } |
| 456 | pr_debug("stmmac_init_phy: %s: attached to PHY (UID 0x%x)" |
Giuseppe CAVALLARO | 36bcfe7 | 2011-07-20 00:05:23 +0000 | [diff] [blame] | 457 | " Link = %d\n", dev->name, phydev->phy_id, phydev->link); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 458 | |
| 459 | priv->phydev = phydev; |
| 460 | |
| 461 | return 0; |
| 462 | } |
| 463 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 464 | /** |
| 465 | * display_ring |
| 466 | * @p: pointer to the ring. |
| 467 | * @size: size of the ring. |
| 468 | * Description: display all the descriptors within the ring. |
| 469 | */ |
| 470 | static void display_ring(struct dma_desc *p, int size) |
| 471 | { |
| 472 | struct tmp_s { |
| 473 | u64 a; |
| 474 | unsigned int b; |
| 475 | unsigned int c; |
| 476 | }; |
| 477 | int i; |
| 478 | for (i = 0; i < size; i++) { |
| 479 | struct tmp_s *x = (struct tmp_s *)(p + i); |
| 480 | pr_info("\t%d [0x%x]: DES0=0x%x DES1=0x%x BUF1=0x%x BUF2=0x%x", |
| 481 | i, (unsigned int)virt_to_phys(&p[i]), |
| 482 | (unsigned int)(x->a), (unsigned int)((x->a) >> 32), |
| 483 | x->b, x->c); |
| 484 | pr_info("\n"); |
| 485 | } |
| 486 | } |
| 487 | |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 488 | static int stmmac_set_bfsize(int mtu, int bufsize) |
| 489 | { |
| 490 | int ret = bufsize; |
| 491 | |
| 492 | if (mtu >= BUF_SIZE_4KiB) |
| 493 | ret = BUF_SIZE_8KiB; |
| 494 | else if (mtu >= BUF_SIZE_2KiB) |
| 495 | ret = BUF_SIZE_4KiB; |
| 496 | else if (mtu >= DMA_BUFFER_SIZE) |
| 497 | ret = BUF_SIZE_2KiB; |
| 498 | else |
| 499 | ret = DMA_BUFFER_SIZE; |
| 500 | |
| 501 | return ret; |
| 502 | } |
| 503 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 504 | /** |
| 505 | * init_dma_desc_rings - init the RX/TX descriptor rings |
| 506 | * @dev: net device structure |
| 507 | * Description: this function initializes the DMA RX/TX descriptors |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 508 | * and allocates the socket buffers. It suppors the chained and ring |
| 509 | * modes. |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 510 | */ |
| 511 | static void init_dma_desc_rings(struct net_device *dev) |
| 512 | { |
| 513 | int i; |
| 514 | struct stmmac_priv *priv = netdev_priv(dev); |
| 515 | struct sk_buff *skb; |
| 516 | unsigned int txsize = priv->dma_tx_size; |
| 517 | unsigned int rxsize = priv->dma_rx_size; |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 518 | unsigned int bfsize; |
| 519 | int dis_ic = 0; |
| 520 | int des3_as_data_buf = 0; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 521 | |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 522 | /* Set the max buffer size according to the DESC mode |
| 523 | * and the MTU. Note that RING mode allows 16KiB bsize. */ |
| 524 | bfsize = priv->hw->ring->set_16kib_bfsize(dev->mtu); |
| 525 | |
| 526 | if (bfsize == BUF_SIZE_16KiB) |
| 527 | des3_as_data_buf = 1; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 528 | else |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 529 | bfsize = stmmac_set_bfsize(dev->mtu, priv->dma_buf_sz); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 530 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 531 | DBG(probe, INFO, "stmmac: txsize %d, rxsize %d, bfsize %d\n", |
| 532 | txsize, rxsize, bfsize); |
| 533 | |
| 534 | priv->rx_skbuff_dma = kmalloc(rxsize * sizeof(dma_addr_t), GFP_KERNEL); |
| 535 | priv->rx_skbuff = |
| 536 | kmalloc(sizeof(struct sk_buff *) * rxsize, GFP_KERNEL); |
| 537 | priv->dma_rx = |
| 538 | (struct dma_desc *)dma_alloc_coherent(priv->device, |
| 539 | rxsize * |
| 540 | sizeof(struct dma_desc), |
| 541 | &priv->dma_rx_phy, |
| 542 | GFP_KERNEL); |
| 543 | priv->tx_skbuff = kmalloc(sizeof(struct sk_buff *) * txsize, |
| 544 | GFP_KERNEL); |
| 545 | priv->dma_tx = |
| 546 | (struct dma_desc *)dma_alloc_coherent(priv->device, |
| 547 | txsize * |
| 548 | sizeof(struct dma_desc), |
| 549 | &priv->dma_tx_phy, |
| 550 | GFP_KERNEL); |
| 551 | |
| 552 | if ((priv->dma_rx == NULL) || (priv->dma_tx == NULL)) { |
| 553 | pr_err("%s:ERROR allocating the DMA Tx/Rx desc\n", __func__); |
| 554 | return; |
| 555 | } |
| 556 | |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 557 | DBG(probe, INFO, "stmmac (%s) DMA desc: virt addr (Rx %p, " |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 558 | "Tx %p)\n\tDMA phy addr (Rx 0x%08x, Tx 0x%08x)\n", |
| 559 | dev->name, priv->dma_rx, priv->dma_tx, |
| 560 | (unsigned int)priv->dma_rx_phy, (unsigned int)priv->dma_tx_phy); |
| 561 | |
| 562 | /* RX INITIALIZATION */ |
| 563 | DBG(probe, INFO, "stmmac: SKB addresses:\n" |
| 564 | "skb\t\tskb data\tdma data\n"); |
| 565 | |
| 566 | for (i = 0; i < rxsize; i++) { |
| 567 | struct dma_desc *p = priv->dma_rx + i; |
| 568 | |
Giuseppe CAVALLARO | 45db81e | 2011-10-18 01:39:55 +0000 | [diff] [blame] | 569 | skb = __netdev_alloc_skb(dev, bfsize + NET_IP_ALIGN, |
| 570 | GFP_KERNEL); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 571 | if (unlikely(skb == NULL)) { |
| 572 | pr_err("%s: Rx init fails; skb is NULL\n", __func__); |
| 573 | break; |
| 574 | } |
Giuseppe CAVALLARO | 45db81e | 2011-10-18 01:39:55 +0000 | [diff] [blame] | 575 | skb_reserve(skb, NET_IP_ALIGN); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 576 | priv->rx_skbuff[i] = skb; |
| 577 | priv->rx_skbuff_dma[i] = dma_map_single(priv->device, skb->data, |
| 578 | bfsize, DMA_FROM_DEVICE); |
| 579 | |
| 580 | p->des2 = priv->rx_skbuff_dma[i]; |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 581 | |
| 582 | priv->hw->ring->init_desc3(des3_as_data_buf, p); |
| 583 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 584 | DBG(probe, INFO, "[%p]\t[%p]\t[%x]\n", priv->rx_skbuff[i], |
| 585 | priv->rx_skbuff[i]->data, priv->rx_skbuff_dma[i]); |
| 586 | } |
| 587 | priv->cur_rx = 0; |
| 588 | priv->dirty_rx = (unsigned int)(i - rxsize); |
| 589 | priv->dma_buf_sz = bfsize; |
| 590 | buf_sz = bfsize; |
| 591 | |
| 592 | /* TX INITIALIZATION */ |
| 593 | for (i = 0; i < txsize; i++) { |
| 594 | priv->tx_skbuff[i] = NULL; |
| 595 | priv->dma_tx[i].des2 = 0; |
| 596 | } |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 597 | |
| 598 | /* In case of Chained mode this sets the des3 to the next |
| 599 | * element in the chain */ |
| 600 | priv->hw->ring->init_dma_chain(priv->dma_rx, priv->dma_rx_phy, rxsize); |
| 601 | priv->hw->ring->init_dma_chain(priv->dma_tx, priv->dma_tx_phy, txsize); |
| 602 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 603 | priv->dirty_tx = 0; |
| 604 | priv->cur_tx = 0; |
| 605 | |
Giuseppe CAVALLARO | 62a2ab9 | 2012-11-25 23:10:43 +0000 | [diff] [blame] | 606 | if (priv->use_riwt) |
| 607 | dis_ic = 1; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 608 | /* Clear the Rx/Tx descriptors */ |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 609 | priv->hw->desc->init_rx_desc(priv->dma_rx, rxsize, dis_ic); |
| 610 | priv->hw->desc->init_tx_desc(priv->dma_tx, txsize); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 611 | |
| 612 | if (netif_msg_hw(priv)) { |
| 613 | pr_info("RX descriptor ring:\n"); |
| 614 | display_ring(priv->dma_rx, rxsize); |
| 615 | pr_info("TX descriptor ring:\n"); |
| 616 | display_ring(priv->dma_tx, txsize); |
| 617 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | static void dma_free_rx_skbufs(struct stmmac_priv *priv) |
| 621 | { |
| 622 | int i; |
| 623 | |
| 624 | for (i = 0; i < priv->dma_rx_size; i++) { |
| 625 | if (priv->rx_skbuff[i]) { |
| 626 | dma_unmap_single(priv->device, priv->rx_skbuff_dma[i], |
| 627 | priv->dma_buf_sz, DMA_FROM_DEVICE); |
| 628 | dev_kfree_skb_any(priv->rx_skbuff[i]); |
| 629 | } |
| 630 | priv->rx_skbuff[i] = NULL; |
| 631 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | static void dma_free_tx_skbufs(struct stmmac_priv *priv) |
| 635 | { |
| 636 | int i; |
| 637 | |
| 638 | for (i = 0; i < priv->dma_tx_size; i++) { |
| 639 | if (priv->tx_skbuff[i] != NULL) { |
| 640 | struct dma_desc *p = priv->dma_tx + i; |
| 641 | if (p->des2) |
| 642 | dma_unmap_single(priv->device, p->des2, |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 643 | priv->hw->desc->get_tx_len(p), |
| 644 | DMA_TO_DEVICE); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 645 | dev_kfree_skb_any(priv->tx_skbuff[i]); |
| 646 | priv->tx_skbuff[i] = NULL; |
| 647 | } |
| 648 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | static void free_dma_desc_resources(struct stmmac_priv *priv) |
| 652 | { |
| 653 | /* Release the DMA TX/RX socket buffers */ |
| 654 | dma_free_rx_skbufs(priv); |
| 655 | dma_free_tx_skbufs(priv); |
| 656 | |
| 657 | /* Free the region of consistent memory previously allocated for |
| 658 | * the DMA */ |
| 659 | dma_free_coherent(priv->device, |
| 660 | priv->dma_tx_size * sizeof(struct dma_desc), |
| 661 | priv->dma_tx, priv->dma_tx_phy); |
| 662 | dma_free_coherent(priv->device, |
| 663 | priv->dma_rx_size * sizeof(struct dma_desc), |
| 664 | priv->dma_rx, priv->dma_rx_phy); |
| 665 | kfree(priv->rx_skbuff_dma); |
| 666 | kfree(priv->rx_skbuff); |
| 667 | kfree(priv->tx_skbuff); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | /** |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 671 | * stmmac_dma_operation_mode - HW DMA operation mode |
| 672 | * @priv : pointer to the private device structure. |
| 673 | * Description: it sets the DMA operation mode: tx/rx DMA thresholds |
Giuseppe CAVALLARO | ebbb293 | 2010-09-17 03:23:40 +0000 | [diff] [blame] | 674 | * or Store-And-Forward capability. |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 675 | */ |
| 676 | static void stmmac_dma_operation_mode(struct stmmac_priv *priv) |
| 677 | { |
Srinivas Kandagatla | 61b8013 | 2011-07-17 20:54:09 +0000 | [diff] [blame] | 678 | if (likely(priv->plat->force_sf_dma_mode || |
| 679 | ((priv->plat->tx_coe) && (!priv->no_csum_insertion)))) { |
| 680 | /* |
| 681 | * In case of GMAC, SF mode can be enabled |
| 682 | * to perform the TX COE in HW. This depends on: |
Giuseppe CAVALLARO | ebbb293 | 2010-09-17 03:23:40 +0000 | [diff] [blame] | 683 | * 1) TX COE if actually supported |
| 684 | * 2) There is no bugged Jumbo frame support |
| 685 | * that needs to not insert csum in the TDES. |
| 686 | */ |
| 687 | priv->hw->dma->dma_mode(priv->ioaddr, |
| 688 | SF_DMA_MODE, SF_DMA_MODE); |
| 689 | tc = SF_DMA_MODE; |
| 690 | } else |
| 691 | priv->hw->dma->dma_mode(priv->ioaddr, tc, SF_DMA_MODE); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 692 | } |
| 693 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 694 | /** |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 695 | * stmmac_tx_clean: |
| 696 | * @priv: private data pointer |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 697 | * Description: it reclaims resources after transmission completes. |
| 698 | */ |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 699 | static void stmmac_tx_clean(struct stmmac_priv *priv) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 700 | { |
| 701 | unsigned int txsize = priv->dma_tx_size; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 702 | |
Giuseppe CAVALLARO | a9097a9 | 2011-10-18 00:01:19 +0000 | [diff] [blame] | 703 | spin_lock(&priv->tx_lock); |
| 704 | |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 705 | priv->xstats.tx_clean++; |
| 706 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 707 | while (priv->dirty_tx != priv->cur_tx) { |
| 708 | int last; |
| 709 | unsigned int entry = priv->dirty_tx % txsize; |
| 710 | struct sk_buff *skb = priv->tx_skbuff[entry]; |
| 711 | struct dma_desc *p = priv->dma_tx + entry; |
| 712 | |
| 713 | /* Check if the descriptor is owned by the DMA. */ |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 714 | if (priv->hw->desc->get_tx_owner(p)) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 715 | break; |
| 716 | |
| 717 | /* Verify tx error by looking at the last segment */ |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 718 | last = priv->hw->desc->get_tx_ls(p); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 719 | if (likely(last)) { |
| 720 | int tx_error = |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 721 | priv->hw->desc->tx_status(&priv->dev->stats, |
| 722 | &priv->xstats, p, |
Giuseppe CAVALLARO | ad01b7d | 2010-08-23 20:40:42 +0000 | [diff] [blame] | 723 | priv->ioaddr); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 724 | if (likely(tx_error == 0)) { |
| 725 | priv->dev->stats.tx_packets++; |
| 726 | priv->xstats.tx_pkt_n++; |
| 727 | } else |
| 728 | priv->dev->stats.tx_errors++; |
| 729 | } |
| 730 | TX_DBG("%s: curr %d, dirty %d\n", __func__, |
| 731 | priv->cur_tx, priv->dirty_tx); |
| 732 | |
| 733 | if (likely(p->des2)) |
| 734 | dma_unmap_single(priv->device, p->des2, |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 735 | priv->hw->desc->get_tx_len(p), |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 736 | DMA_TO_DEVICE); |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 737 | priv->hw->ring->clean_desc3(p); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 738 | |
| 739 | if (likely(skb != NULL)) { |
Eric Dumazet | acb600d | 2012-10-05 06:23:55 +0000 | [diff] [blame] | 740 | dev_kfree_skb(skb); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 741 | priv->tx_skbuff[entry] = NULL; |
| 742 | } |
| 743 | |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 744 | priv->hw->desc->release_tx_desc(p); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 745 | |
Giuseppe CAVALLARO | 13497f5 | 2012-06-04 06:36:22 +0000 | [diff] [blame] | 746 | priv->dirty_tx++; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 747 | } |
| 748 | if (unlikely(netif_queue_stopped(priv->dev) && |
| 749 | stmmac_tx_avail(priv) > STMMAC_TX_THRESH(priv))) { |
| 750 | netif_tx_lock(priv->dev); |
| 751 | if (netif_queue_stopped(priv->dev) && |
| 752 | stmmac_tx_avail(priv) > STMMAC_TX_THRESH(priv)) { |
| 753 | TX_DBG("%s: restart transmit\n", __func__); |
| 754 | netif_wake_queue(priv->dev); |
| 755 | } |
| 756 | netif_tx_unlock(priv->dev); |
| 757 | } |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 758 | |
| 759 | if ((priv->eee_enabled) && (!priv->tx_path_in_lpi_mode)) { |
| 760 | stmmac_enable_eee_mode(priv); |
| 761 | mod_timer(&priv->eee_ctrl_timer, STMMAC_LPI_TIMER(eee_timer)); |
| 762 | } |
Giuseppe CAVALLARO | a9097a9 | 2011-10-18 00:01:19 +0000 | [diff] [blame] | 763 | spin_unlock(&priv->tx_lock); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 764 | } |
| 765 | |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 766 | static inline void stmmac_enable_dma_irq(struct stmmac_priv *priv) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 767 | { |
Giuseppe CAVALLARO | 7284a3f | 2012-11-25 23:10:41 +0000 | [diff] [blame] | 768 | priv->hw->dma->enable_dma_irq(priv->ioaddr); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 769 | } |
| 770 | |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 771 | static inline void stmmac_disable_dma_irq(struct stmmac_priv *priv) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 772 | { |
Giuseppe CAVALLARO | 7284a3f | 2012-11-25 23:10:41 +0000 | [diff] [blame] | 773 | priv->hw->dma->disable_dma_irq(priv->ioaddr); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 774 | } |
| 775 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 776 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 777 | /** |
| 778 | * stmmac_tx_err: |
| 779 | * @priv: pointer to the private device structure |
| 780 | * Description: it cleans the descriptors and restarts the transmission |
| 781 | * in case of errors. |
| 782 | */ |
| 783 | static void stmmac_tx_err(struct stmmac_priv *priv) |
| 784 | { |
| 785 | netif_stop_queue(priv->dev); |
| 786 | |
Giuseppe CAVALLARO | ad01b7d | 2010-08-23 20:40:42 +0000 | [diff] [blame] | 787 | priv->hw->dma->stop_tx(priv->ioaddr); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 788 | dma_free_tx_skbufs(priv); |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 789 | priv->hw->desc->init_tx_desc(priv->dma_tx, priv->dma_tx_size); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 790 | priv->dirty_tx = 0; |
| 791 | priv->cur_tx = 0; |
Giuseppe CAVALLARO | ad01b7d | 2010-08-23 20:40:42 +0000 | [diff] [blame] | 792 | priv->hw->dma->start_tx(priv->ioaddr); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 793 | |
| 794 | priv->dev->stats.tx_errors++; |
| 795 | netif_wake_queue(priv->dev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 796 | } |
| 797 | |
Giuseppe CAVALLARO | aec7ff2 | 2010-01-06 23:07:18 +0000 | [diff] [blame] | 798 | static void stmmac_dma_interrupt(struct stmmac_priv *priv) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 799 | { |
Giuseppe CAVALLARO | aec7ff2 | 2010-01-06 23:07:18 +0000 | [diff] [blame] | 800 | int status; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 801 | |
Giuseppe CAVALLARO | ad01b7d | 2010-08-23 20:40:42 +0000 | [diff] [blame] | 802 | status = priv->hw->dma->dma_interrupt(priv->ioaddr, &priv->xstats); |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 803 | if (likely((status & handle_rx)) || (status & handle_tx)) { |
| 804 | if (likely(napi_schedule_prep(&priv->napi))) { |
| 805 | stmmac_disable_dma_irq(priv); |
| 806 | __napi_schedule(&priv->napi); |
| 807 | } |
| 808 | } |
| 809 | if (unlikely(status & tx_hard_error_bump_tc)) { |
Giuseppe CAVALLARO | aec7ff2 | 2010-01-06 23:07:18 +0000 | [diff] [blame] | 810 | /* Try to bump up the dma threshold on this failure */ |
| 811 | if (unlikely(tc != SF_DMA_MODE) && (tc <= 256)) { |
| 812 | tc += 64; |
Giuseppe CAVALLARO | ad01b7d | 2010-08-23 20:40:42 +0000 | [diff] [blame] | 813 | priv->hw->dma->dma_mode(priv->ioaddr, tc, SF_DMA_MODE); |
Giuseppe CAVALLARO | aec7ff2 | 2010-01-06 23:07:18 +0000 | [diff] [blame] | 814 | priv->xstats.threshold = tc; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 815 | } |
Giuseppe CAVALLARO | aec7ff2 | 2010-01-06 23:07:18 +0000 | [diff] [blame] | 816 | } else if (unlikely(status == tx_hard_error)) |
| 817 | stmmac_tx_err(priv); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 818 | } |
| 819 | |
Giuseppe CAVALLARO | 1c901a4 | 2011-09-01 21:51:38 +0000 | [diff] [blame] | 820 | static void stmmac_mmc_setup(struct stmmac_priv *priv) |
| 821 | { |
| 822 | unsigned int mode = MMC_CNTRL_RESET_ON_READ | MMC_CNTRL_COUNTER_RESET | |
| 823 | MMC_CNTRL_PRESET | MMC_CNTRL_FULL_HALF_PRESET; |
| 824 | |
Giuseppe CAVALLARO | 4f795b2 | 2011-11-18 05:00:20 +0000 | [diff] [blame] | 825 | /* Mask MMC irq, counters are managed in SW and registers |
| 826 | * are cleared on each READ eventually. */ |
Giuseppe CAVALLARO | 1c901a4 | 2011-09-01 21:51:38 +0000 | [diff] [blame] | 827 | dwmac_mmc_intr_all_mask(priv->ioaddr); |
Giuseppe CAVALLARO | 4f795b2 | 2011-11-18 05:00:20 +0000 | [diff] [blame] | 828 | |
| 829 | if (priv->dma_cap.rmon) { |
| 830 | dwmac_mmc_ctrl(priv->ioaddr, mode); |
| 831 | memset(&priv->mmc, 0, sizeof(struct stmmac_counters)); |
| 832 | } else |
Stefan Roese | aae54cf | 2012-01-10 01:47:51 +0000 | [diff] [blame] | 833 | pr_info(" No MAC Management Counters available\n"); |
Giuseppe CAVALLARO | 1c901a4 | 2011-09-01 21:51:38 +0000 | [diff] [blame] | 834 | } |
| 835 | |
Giuseppe CAVALLARO | f0b9d78 | 2011-09-01 21:51:40 +0000 | [diff] [blame] | 836 | static u32 stmmac_get_synopsys_id(struct stmmac_priv *priv) |
| 837 | { |
| 838 | u32 hwid = priv->hw->synopsys_uid; |
| 839 | |
| 840 | /* Only check valid Synopsys Id because old MAC chips |
| 841 | * have no HW registers where get the ID */ |
| 842 | if (likely(hwid)) { |
| 843 | u32 uid = ((hwid & 0x0000ff00) >> 8); |
| 844 | u32 synid = (hwid & 0x000000ff); |
| 845 | |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 846 | pr_info("stmmac - user ID: 0x%x, Synopsys ID: 0x%x\n", |
Giuseppe CAVALLARO | f0b9d78 | 2011-09-01 21:51:40 +0000 | [diff] [blame] | 847 | uid, synid); |
| 848 | |
| 849 | return synid; |
| 850 | } |
| 851 | return 0; |
| 852 | } |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 853 | |
Giuseppe CAVALLARO | 19e30c1 | 2011-11-16 21:58:00 +0000 | [diff] [blame] | 854 | /** |
| 855 | * stmmac_selec_desc_mode |
Giuseppe CAVALLARO | ff3dd78 | 2012-06-04 19:22:55 +0000 | [diff] [blame] | 856 | * @priv : private structure |
| 857 | * Description: select the Enhanced/Alternate or Normal descriptors |
| 858 | */ |
Giuseppe CAVALLARO | 19e30c1 | 2011-11-16 21:58:00 +0000 | [diff] [blame] | 859 | static void stmmac_selec_desc_mode(struct stmmac_priv *priv) |
| 860 | { |
| 861 | if (priv->plat->enh_desc) { |
| 862 | pr_info(" Enhanced/Alternate descriptors\n"); |
| 863 | priv->hw->desc = &enh_desc_ops; |
| 864 | } else { |
| 865 | pr_info(" Normal descriptors\n"); |
| 866 | priv->hw->desc = &ndesc_ops; |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | /** |
| 871 | * stmmac_get_hw_features |
| 872 | * @priv : private device pointer |
| 873 | * Description: |
| 874 | * new GMAC chip generations have a new register to indicate the |
| 875 | * presence of the optional feature/functions. |
| 876 | * This can be also used to override the value passed through the |
| 877 | * platform and necessary for old MAC10/100 and GMAC chips. |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 878 | */ |
| 879 | static int stmmac_get_hw_features(struct stmmac_priv *priv) |
| 880 | { |
Giuseppe CAVALLARO | 5e6efe8 | 2011-10-26 19:43:07 +0000 | [diff] [blame] | 881 | u32 hw_cap = 0; |
Giuseppe CAVALLARO | 3c20f72 | 2011-10-26 19:43:09 +0000 | [diff] [blame] | 882 | |
Giuseppe CAVALLARO | 5e6efe8 | 2011-10-26 19:43:07 +0000 | [diff] [blame] | 883 | if (priv->hw->dma->get_hw_feature) { |
| 884 | hw_cap = priv->hw->dma->get_hw_feature(priv->ioaddr); |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 885 | |
Rayagond Kokatanur | 1db123f | 2011-10-18 00:01:22 +0000 | [diff] [blame] | 886 | priv->dma_cap.mbps_10_100 = (hw_cap & DMA_HW_FEAT_MIISEL); |
| 887 | priv->dma_cap.mbps_1000 = (hw_cap & DMA_HW_FEAT_GMIISEL) >> 1; |
| 888 | priv->dma_cap.half_duplex = (hw_cap & DMA_HW_FEAT_HDSEL) >> 2; |
| 889 | priv->dma_cap.hash_filter = (hw_cap & DMA_HW_FEAT_HASHSEL) >> 4; |
| 890 | priv->dma_cap.multi_addr = |
| 891 | (hw_cap & DMA_HW_FEAT_ADDMACADRSEL) >> 5; |
| 892 | priv->dma_cap.pcs = (hw_cap & DMA_HW_FEAT_PCSSEL) >> 6; |
| 893 | priv->dma_cap.sma_mdio = (hw_cap & DMA_HW_FEAT_SMASEL) >> 8; |
| 894 | priv->dma_cap.pmt_remote_wake_up = |
| 895 | (hw_cap & DMA_HW_FEAT_RWKSEL) >> 9; |
| 896 | priv->dma_cap.pmt_magic_frame = |
| 897 | (hw_cap & DMA_HW_FEAT_MGKSEL) >> 10; |
Giuseppe CAVALLARO | 19e30c1 | 2011-11-16 21:58:00 +0000 | [diff] [blame] | 898 | /* MMC */ |
Rayagond Kokatanur | 1db123f | 2011-10-18 00:01:22 +0000 | [diff] [blame] | 899 | priv->dma_cap.rmon = (hw_cap & DMA_HW_FEAT_MMCSEL) >> 11; |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 900 | /* IEEE 1588-2002*/ |
Rayagond Kokatanur | 1db123f | 2011-10-18 00:01:22 +0000 | [diff] [blame] | 901 | priv->dma_cap.time_stamp = |
| 902 | (hw_cap & DMA_HW_FEAT_TSVER1SEL) >> 12; |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 903 | /* IEEE 1588-2008*/ |
Rayagond Kokatanur | 1db123f | 2011-10-18 00:01:22 +0000 | [diff] [blame] | 904 | priv->dma_cap.atime_stamp = |
| 905 | (hw_cap & DMA_HW_FEAT_TSVER2SEL) >> 13; |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 906 | /* 802.3az - Energy-Efficient Ethernet (EEE) */ |
Rayagond Kokatanur | 1db123f | 2011-10-18 00:01:22 +0000 | [diff] [blame] | 907 | priv->dma_cap.eee = (hw_cap & DMA_HW_FEAT_EEESEL) >> 14; |
| 908 | priv->dma_cap.av = (hw_cap & DMA_HW_FEAT_AVSEL) >> 15; |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 909 | /* TX and RX csum */ |
Rayagond Kokatanur | 1db123f | 2011-10-18 00:01:22 +0000 | [diff] [blame] | 910 | priv->dma_cap.tx_coe = (hw_cap & DMA_HW_FEAT_TXCOESEL) >> 16; |
| 911 | priv->dma_cap.rx_coe_type1 = |
| 912 | (hw_cap & DMA_HW_FEAT_RXTYP1COE) >> 17; |
| 913 | priv->dma_cap.rx_coe_type2 = |
| 914 | (hw_cap & DMA_HW_FEAT_RXTYP2COE) >> 18; |
| 915 | priv->dma_cap.rxfifo_over_2048 = |
| 916 | (hw_cap & DMA_HW_FEAT_RXFIFOSIZE) >> 19; |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 917 | /* TX and RX number of channels */ |
Rayagond Kokatanur | 1db123f | 2011-10-18 00:01:22 +0000 | [diff] [blame] | 918 | priv->dma_cap.number_rx_channel = |
| 919 | (hw_cap & DMA_HW_FEAT_RXCHCNT) >> 20; |
| 920 | priv->dma_cap.number_tx_channel = |
| 921 | (hw_cap & DMA_HW_FEAT_TXCHCNT) >> 22; |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 922 | /* Alternate (enhanced) DESC mode*/ |
Rayagond Kokatanur | 1db123f | 2011-10-18 00:01:22 +0000 | [diff] [blame] | 923 | priv->dma_cap.enh_desc = |
| 924 | (hw_cap & DMA_HW_FEAT_ENHDESSEL) >> 24; |
Giuseppe CAVALLARO | 19e30c1 | 2011-11-16 21:58:00 +0000 | [diff] [blame] | 925 | } |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 926 | |
| 927 | return hw_cap; |
| 928 | } |
| 929 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 930 | static void stmmac_check_ether_addr(struct stmmac_priv *priv) |
| 931 | { |
| 932 | /* verify if the MAC address is valid, in case of failures it |
| 933 | * generates a random MAC address */ |
| 934 | if (!is_valid_ether_addr(priv->dev->dev_addr)) { |
| 935 | priv->hw->mac->get_umac_addr((void __iomem *) |
| 936 | priv->dev->base_addr, |
| 937 | priv->dev->dev_addr, 0); |
| 938 | if (!is_valid_ether_addr(priv->dev->dev_addr)) |
Danny Kukawka | f2cedb6 | 2012-02-15 06:45:39 +0000 | [diff] [blame] | 939 | eth_hw_addr_random(priv->dev); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 940 | } |
| 941 | pr_warning("%s: device MAC address %pM\n", priv->dev->name, |
| 942 | priv->dev->dev_addr); |
| 943 | } |
| 944 | |
Giuseppe CAVALLARO | 0f1f88a | 2012-04-18 19:48:21 +0000 | [diff] [blame] | 945 | static int stmmac_init_dma_engine(struct stmmac_priv *priv) |
| 946 | { |
| 947 | int pbl = DEFAULT_DMA_PBL, fixed_burst = 0, burst_len = 0; |
Giuseppe CAVALLARO | b9cde0a | 2012-05-13 22:18:42 +0000 | [diff] [blame] | 948 | int mixed_burst = 0; |
Giuseppe CAVALLARO | 0f1f88a | 2012-04-18 19:48:21 +0000 | [diff] [blame] | 949 | |
| 950 | /* Some DMA parameters can be passed from the platform; |
| 951 | * in case of these are not passed we keep a default |
| 952 | * (good for all the chips) and init the DMA! */ |
| 953 | if (priv->plat->dma_cfg) { |
| 954 | pbl = priv->plat->dma_cfg->pbl; |
| 955 | fixed_burst = priv->plat->dma_cfg->fixed_burst; |
Giuseppe CAVALLARO | b9cde0a | 2012-05-13 22:18:42 +0000 | [diff] [blame] | 956 | mixed_burst = priv->plat->dma_cfg->mixed_burst; |
Giuseppe CAVALLARO | 0f1f88a | 2012-04-18 19:48:21 +0000 | [diff] [blame] | 957 | burst_len = priv->plat->dma_cfg->burst_len; |
| 958 | } |
| 959 | |
Giuseppe CAVALLARO | b9cde0a | 2012-05-13 22:18:42 +0000 | [diff] [blame] | 960 | return priv->hw->dma->init(priv->ioaddr, pbl, fixed_burst, mixed_burst, |
Giuseppe CAVALLARO | 0f1f88a | 2012-04-18 19:48:21 +0000 | [diff] [blame] | 961 | burst_len, priv->dma_tx_phy, |
| 962 | priv->dma_rx_phy); |
| 963 | } |
| 964 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 965 | /** |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 966 | * stmmac_tx_timer: |
| 967 | * @data: data pointer |
| 968 | * Description: |
| 969 | * This is the timer handler to directly invoke the stmmac_tx_clean. |
| 970 | */ |
| 971 | static void stmmac_tx_timer(unsigned long data) |
| 972 | { |
| 973 | struct stmmac_priv *priv = (struct stmmac_priv *)data; |
| 974 | |
| 975 | stmmac_tx_clean(priv); |
| 976 | } |
| 977 | |
| 978 | /** |
| 979 | * stmmac_tx_timer: |
| 980 | * @priv: private data structure |
| 981 | * Description: |
| 982 | * This inits the transmit coalesce parameters: i.e. timer rate, |
| 983 | * timer handler and default threshold used for enabling the |
| 984 | * interrupt on completion bit. |
| 985 | */ |
| 986 | static void stmmac_init_tx_coalesce(struct stmmac_priv *priv) |
| 987 | { |
| 988 | priv->tx_coal_frames = STMMAC_TX_FRAMES; |
| 989 | priv->tx_coal_timer = STMMAC_COAL_TX_TIMER; |
| 990 | init_timer(&priv->txtimer); |
| 991 | priv->txtimer.expires = STMMAC_COAL_TIMER(priv->tx_coal_timer); |
| 992 | priv->txtimer.data = (unsigned long)priv; |
| 993 | priv->txtimer.function = stmmac_tx_timer; |
| 994 | add_timer(&priv->txtimer); |
| 995 | } |
| 996 | |
| 997 | /** |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 998 | * stmmac_open - open entry point of the driver |
| 999 | * @dev : pointer to the device structure. |
| 1000 | * Description: |
| 1001 | * This function is the open entry point of the driver. |
| 1002 | * Return value: |
| 1003 | * 0 on success and an appropriate (-)ve integer as defined in errno.h |
| 1004 | * file on failure. |
| 1005 | */ |
| 1006 | static int stmmac_open(struct net_device *dev) |
| 1007 | { |
| 1008 | struct stmmac_priv *priv = netdev_priv(dev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1009 | int ret; |
| 1010 | |
Stefan Roese | a630844 | 2012-09-21 01:06:29 +0000 | [diff] [blame] | 1011 | clk_prepare_enable(priv->stmmac_clk); |
Francesco Virlinzi | 4bfcbd7 | 2012-04-18 19:48:20 +0000 | [diff] [blame] | 1012 | |
| 1013 | stmmac_check_ether_addr(priv); |
| 1014 | |
Giuseppe CAVALLARO | f66ffe2 | 2011-04-10 23:16:45 +0000 | [diff] [blame] | 1015 | ret = stmmac_init_phy(dev); |
| 1016 | if (unlikely(ret)) { |
| 1017 | pr_err("%s: Cannot attach to PHY (error: %d)\n", __func__, ret); |
| 1018 | goto open_error; |
| 1019 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1020 | |
| 1021 | /* Create and initialize the TX/RX descriptors chains. */ |
| 1022 | priv->dma_tx_size = STMMAC_ALIGN(dma_txsize); |
| 1023 | priv->dma_rx_size = STMMAC_ALIGN(dma_rxsize); |
| 1024 | priv->dma_buf_sz = STMMAC_ALIGN(buf_sz); |
| 1025 | init_dma_desc_rings(dev); |
| 1026 | |
| 1027 | /* DMA initialization and SW reset */ |
Giuseppe CAVALLARO | 0f1f88a | 2012-04-18 19:48:21 +0000 | [diff] [blame] | 1028 | ret = stmmac_init_dma_engine(priv); |
Giuseppe CAVALLARO | f66ffe2 | 2011-04-10 23:16:45 +0000 | [diff] [blame] | 1029 | if (ret < 0) { |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1030 | pr_err("%s: DMA initialization failed\n", __func__); |
Giuseppe CAVALLARO | f66ffe2 | 2011-04-10 23:16:45 +0000 | [diff] [blame] | 1031 | goto open_error; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | /* Copy the MAC addr into the HW */ |
Giuseppe CAVALLARO | ad01b7d | 2010-08-23 20:40:42 +0000 | [diff] [blame] | 1035 | priv->hw->mac->set_umac_addr(priv->ioaddr, dev->dev_addr, 0); |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 1036 | |
Giuseppe CAVALLARO | ca5f12c | 2010-01-06 23:07:15 +0000 | [diff] [blame] | 1037 | /* If required, perform hw setup of the bus. */ |
Giuseppe CAVALLARO | 9dfeb4d | 2010-11-24 02:37:58 +0000 | [diff] [blame] | 1038 | if (priv->plat->bus_setup) |
| 1039 | priv->plat->bus_setup(priv->ioaddr); |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 1040 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1041 | /* Initialize the MAC Core */ |
Giuseppe CAVALLARO | ad01b7d | 2010-08-23 20:40:42 +0000 | [diff] [blame] | 1042 | priv->hw->mac->core_init(priv->ioaddr); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1043 | |
Giuseppe CAVALLARO | f66ffe2 | 2011-04-10 23:16:45 +0000 | [diff] [blame] | 1044 | /* Request the IRQ lines */ |
| 1045 | ret = request_irq(dev->irq, stmmac_interrupt, |
| 1046 | IRQF_SHARED, dev->name, dev); |
| 1047 | if (unlikely(ret < 0)) { |
| 1048 | pr_err("%s: ERROR: allocating the IRQ %d (error: %d)\n", |
| 1049 | __func__, dev->irq, ret); |
| 1050 | goto open_error; |
| 1051 | } |
| 1052 | |
Francesco Virlinzi | 7a13f8f | 2012-02-15 00:10:38 +0000 | [diff] [blame] | 1053 | /* Request the Wake IRQ in case of another line is used for WoL */ |
| 1054 | if (priv->wol_irq != dev->irq) { |
| 1055 | ret = request_irq(priv->wol_irq, stmmac_interrupt, |
| 1056 | IRQF_SHARED, dev->name, dev); |
| 1057 | if (unlikely(ret < 0)) { |
| 1058 | pr_err("%s: ERROR: allocating the ext WoL IRQ %d " |
| 1059 | "(error: %d)\n", __func__, priv->wol_irq, ret); |
| 1060 | goto open_error_wolirq; |
| 1061 | } |
| 1062 | } |
| 1063 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 1064 | /* Request the IRQ lines */ |
| 1065 | if (priv->lpi_irq != -ENXIO) { |
| 1066 | ret = request_irq(priv->lpi_irq, stmmac_interrupt, IRQF_SHARED, |
| 1067 | dev->name, dev); |
| 1068 | if (unlikely(ret < 0)) { |
| 1069 | pr_err("%s: ERROR: allocating the LPI IRQ %d (%d)\n", |
| 1070 | __func__, priv->lpi_irq, ret); |
| 1071 | goto open_error_lpiirq; |
| 1072 | } |
| 1073 | } |
| 1074 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1075 | /* Enable the MAC Rx/Tx */ |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1076 | stmmac_set_mac(priv->ioaddr, true); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1077 | |
| 1078 | /* Set the HW DMA mode and the COE */ |
| 1079 | stmmac_dma_operation_mode(priv); |
| 1080 | |
| 1081 | /* Extra statistics */ |
| 1082 | memset(&priv->xstats, 0, sizeof(struct stmmac_extra_stats)); |
| 1083 | priv->xstats.threshold = tc; |
| 1084 | |
Giuseppe CAVALLARO | 4f795b2 | 2011-11-18 05:00:20 +0000 | [diff] [blame] | 1085 | stmmac_mmc_setup(priv); |
Giuseppe CAVALLARO | 1c901a4 | 2011-09-01 21:51:38 +0000 | [diff] [blame] | 1086 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1087 | #ifdef CONFIG_STMMAC_DEBUG_FS |
| 1088 | ret = stmmac_init_fs(dev); |
| 1089 | if (ret < 0) |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 1090 | pr_warning("%s: failed debugFS registration\n", __func__); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1091 | #endif |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1092 | /* Start the ball rolling... */ |
| 1093 | DBG(probe, DEBUG, "%s: DMA RX/TX processes started...\n", dev->name); |
Giuseppe CAVALLARO | ad01b7d | 2010-08-23 20:40:42 +0000 | [diff] [blame] | 1094 | priv->hw->dma->start_tx(priv->ioaddr); |
| 1095 | priv->hw->dma->start_rx(priv->ioaddr); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1096 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1097 | /* Dump DMA/MAC registers */ |
| 1098 | if (netif_msg_hw(priv)) { |
Giuseppe CAVALLARO | ad01b7d | 2010-08-23 20:40:42 +0000 | [diff] [blame] | 1099 | priv->hw->mac->dump_regs(priv->ioaddr); |
| 1100 | priv->hw->dma->dump_regs(priv->ioaddr); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | if (priv->phydev) |
| 1104 | phy_start(priv->phydev); |
| 1105 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 1106 | priv->tx_lpi_timer = STMMAC_DEFAULT_TWT_LS_TIMER; |
| 1107 | priv->eee_enabled = stmmac_eee_init(priv); |
| 1108 | |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 1109 | stmmac_init_tx_coalesce(priv); |
| 1110 | |
Giuseppe CAVALLARO | 62a2ab9 | 2012-11-25 23:10:43 +0000 | [diff] [blame] | 1111 | if ((priv->use_riwt) && (priv->hw->dma->rx_watchdog)) { |
| 1112 | priv->rx_riwt = MAX_DMA_RIWT; |
| 1113 | priv->hw->dma->rx_watchdog(priv->ioaddr, MAX_DMA_RIWT); |
| 1114 | } |
| 1115 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1116 | napi_enable(&priv->napi); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1117 | netif_start_queue(dev); |
Giuseppe CAVALLARO | f66ffe2 | 2011-04-10 23:16:45 +0000 | [diff] [blame] | 1118 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1119 | return 0; |
Giuseppe CAVALLARO | f66ffe2 | 2011-04-10 23:16:45 +0000 | [diff] [blame] | 1120 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 1121 | open_error_lpiirq: |
| 1122 | if (priv->wol_irq != dev->irq) |
| 1123 | free_irq(priv->wol_irq, dev); |
| 1124 | |
Francesco Virlinzi | 7a13f8f | 2012-02-15 00:10:38 +0000 | [diff] [blame] | 1125 | open_error_wolirq: |
| 1126 | free_irq(dev->irq, dev); |
| 1127 | |
Giuseppe CAVALLARO | f66ffe2 | 2011-04-10 23:16:45 +0000 | [diff] [blame] | 1128 | open_error: |
Giuseppe CAVALLARO | f66ffe2 | 2011-04-10 23:16:45 +0000 | [diff] [blame] | 1129 | if (priv->phydev) |
| 1130 | phy_disconnect(priv->phydev); |
| 1131 | |
Stefan Roese | a630844 | 2012-09-21 01:06:29 +0000 | [diff] [blame] | 1132 | clk_disable_unprepare(priv->stmmac_clk); |
Francesco Virlinzi | 4bfcbd7 | 2012-04-18 19:48:20 +0000 | [diff] [blame] | 1133 | |
Giuseppe CAVALLARO | f66ffe2 | 2011-04-10 23:16:45 +0000 | [diff] [blame] | 1134 | return ret; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | /** |
| 1138 | * stmmac_release - close entry point of the driver |
| 1139 | * @dev : device pointer. |
| 1140 | * Description: |
| 1141 | * This is the stop entry point of the driver. |
| 1142 | */ |
| 1143 | static int stmmac_release(struct net_device *dev) |
| 1144 | { |
| 1145 | struct stmmac_priv *priv = netdev_priv(dev); |
| 1146 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 1147 | if (priv->eee_enabled) |
| 1148 | del_timer_sync(&priv->eee_ctrl_timer); |
| 1149 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1150 | /* Stop and disconnect the PHY */ |
| 1151 | if (priv->phydev) { |
| 1152 | phy_stop(priv->phydev); |
| 1153 | phy_disconnect(priv->phydev); |
| 1154 | priv->phydev = NULL; |
| 1155 | } |
| 1156 | |
| 1157 | netif_stop_queue(dev); |
| 1158 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1159 | napi_disable(&priv->napi); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1160 | |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 1161 | del_timer_sync(&priv->txtimer); |
| 1162 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1163 | /* Free the IRQ lines */ |
| 1164 | free_irq(dev->irq, dev); |
Francesco Virlinzi | 7a13f8f | 2012-02-15 00:10:38 +0000 | [diff] [blame] | 1165 | if (priv->wol_irq != dev->irq) |
| 1166 | free_irq(priv->wol_irq, dev); |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 1167 | if (priv->lpi_irq != -ENXIO) |
| 1168 | free_irq(priv->lpi_irq, dev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1169 | |
| 1170 | /* Stop TX/RX DMA and clear the descriptors */ |
Giuseppe CAVALLARO | ad01b7d | 2010-08-23 20:40:42 +0000 | [diff] [blame] | 1171 | priv->hw->dma->stop_tx(priv->ioaddr); |
| 1172 | priv->hw->dma->stop_rx(priv->ioaddr); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1173 | |
| 1174 | /* Release and free the Rx/Tx resources */ |
| 1175 | free_dma_desc_resources(priv); |
| 1176 | |
avisconti | 19449bf | 2010-10-25 18:58:14 +0000 | [diff] [blame] | 1177 | /* Disable the MAC Rx/Tx */ |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1178 | stmmac_set_mac(priv->ioaddr, false); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1179 | |
| 1180 | netif_carrier_off(dev); |
| 1181 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1182 | #ifdef CONFIG_STMMAC_DEBUG_FS |
| 1183 | stmmac_exit_fs(); |
| 1184 | #endif |
Stefan Roese | a630844 | 2012-09-21 01:06:29 +0000 | [diff] [blame] | 1185 | clk_disable_unprepare(priv->stmmac_clk); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1186 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1187 | return 0; |
| 1188 | } |
| 1189 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1190 | /** |
| 1191 | * stmmac_xmit: |
| 1192 | * @skb : the socket buffer |
| 1193 | * @dev : device pointer |
| 1194 | * Description : Tx entry point of the driver. |
| 1195 | */ |
| 1196 | static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev) |
| 1197 | { |
| 1198 | struct stmmac_priv *priv = netdev_priv(dev); |
| 1199 | unsigned int txsize = priv->dma_tx_size; |
| 1200 | unsigned int entry; |
| 1201 | int i, csum_insertion = 0; |
| 1202 | int nfrags = skb_shinfo(skb)->nr_frags; |
| 1203 | struct dma_desc *desc, *first; |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 1204 | unsigned int nopaged_len = skb_headlen(skb); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1205 | |
| 1206 | if (unlikely(stmmac_tx_avail(priv) < nfrags + 1)) { |
| 1207 | if (!netif_queue_stopped(dev)) { |
| 1208 | netif_stop_queue(dev); |
| 1209 | /* This is a hard error, log it. */ |
| 1210 | pr_err("%s: BUG! Tx Ring full when queue awake\n", |
| 1211 | __func__); |
| 1212 | } |
| 1213 | return NETDEV_TX_BUSY; |
| 1214 | } |
| 1215 | |
Giuseppe CAVALLARO | a9097a9 | 2011-10-18 00:01:19 +0000 | [diff] [blame] | 1216 | spin_lock(&priv->tx_lock); |
| 1217 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 1218 | if (priv->tx_path_in_lpi_mode) |
| 1219 | stmmac_disable_eee_mode(priv); |
| 1220 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1221 | entry = priv->cur_tx % txsize; |
| 1222 | |
| 1223 | #ifdef STMMAC_XMIT_DEBUG |
| 1224 | if ((skb->len > ETH_FRAME_LEN) || nfrags) |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 1225 | pr_debug("stmmac xmit: [entry %d]\n" |
| 1226 | "\tskb addr %p - len: %d - nopaged_len: %d\n" |
| 1227 | "\tn_frags: %d - ip_summed: %d - %s gso\n" |
| 1228 | "\ttx_count_frames %d\n", entry, |
| 1229 | skb, skb->len, nopaged_len, nfrags, skb->ip_summed, |
| 1230 | !skb_is_gso(skb) ? "isn't" : "is", |
| 1231 | priv->tx_count_frames); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1232 | #endif |
| 1233 | |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 1234 | csum_insertion = (skb->ip_summed == CHECKSUM_PARTIAL); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1235 | |
| 1236 | desc = priv->dma_tx + entry; |
| 1237 | first = desc; |
| 1238 | |
| 1239 | #ifdef STMMAC_XMIT_DEBUG |
| 1240 | if ((nfrags > 0) || (skb->len > ETH_FRAME_LEN)) |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 1241 | pr_debug("\tskb len: %d, nopaged_len: %d,\n" |
| 1242 | "\t\tn_frags: %d, ip_summed: %d\n", |
| 1243 | skb->len, nopaged_len, nfrags, skb->ip_summed); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1244 | #endif |
| 1245 | priv->tx_skbuff[entry] = skb; |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 1246 | |
| 1247 | if (priv->hw->ring->is_jumbo_frm(skb->len, priv->plat->enh_desc)) { |
| 1248 | entry = priv->hw->ring->jumbo_frm(priv, skb, csum_insertion); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1249 | desc = priv->dma_tx + entry; |
| 1250 | } else { |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1251 | desc->des2 = dma_map_single(priv->device, skb->data, |
| 1252 | nopaged_len, DMA_TO_DEVICE); |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 1253 | priv->hw->desc->prepare_tx_desc(desc, 1, nopaged_len, |
| 1254 | csum_insertion); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | for (i = 0; i < nfrags; i++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 1258 | const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 1259 | int len = skb_frag_size(frag); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1260 | |
| 1261 | entry = (++priv->cur_tx) % txsize; |
| 1262 | desc = priv->dma_tx + entry; |
| 1263 | |
| 1264 | TX_DBG("\t[entry %d] segment len: %d\n", entry, len); |
Ian Campbell | f722380 | 2011-09-21 21:53:20 +0000 | [diff] [blame] | 1265 | desc->des2 = skb_frag_dma_map(priv->device, frag, 0, len, |
| 1266 | DMA_TO_DEVICE); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1267 | priv->tx_skbuff[entry] = NULL; |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 1268 | priv->hw->desc->prepare_tx_desc(desc, 0, len, csum_insertion); |
Shiraz Hashim | eb0dc4b | 2011-07-17 20:54:08 +0000 | [diff] [blame] | 1269 | wmb(); |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 1270 | priv->hw->desc->set_tx_owner(desc); |
Deepak Sikri | 8e83989 | 2012-07-08 21:14:45 +0000 | [diff] [blame] | 1271 | wmb(); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1272 | } |
| 1273 | |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 1274 | /* Finalize the latest segment. */ |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 1275 | priv->hw->desc->close_tx_desc(desc); |
Giuseppe CAVALLARO | 73cfe26 | 2009-11-22 22:59:56 +0000 | [diff] [blame] | 1276 | |
Shiraz Hashim | eb0dc4b | 2011-07-17 20:54:08 +0000 | [diff] [blame] | 1277 | wmb(); |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 1278 | /* According to the coalesce parameter the IC bit for the latest |
| 1279 | * segment could be reset and the timer re-started to invoke the |
| 1280 | * stmmac_tx function. This approach takes care about the fragments. |
| 1281 | */ |
| 1282 | priv->tx_count_frames += nfrags + 1; |
| 1283 | if (priv->tx_coal_frames > priv->tx_count_frames) { |
| 1284 | priv->hw->desc->clear_tx_ic(desc); |
| 1285 | priv->xstats.tx_reset_ic_bit++; |
| 1286 | TX_DBG("\t[entry %d]: tx_count_frames %d\n", entry, |
| 1287 | priv->tx_count_frames); |
| 1288 | mod_timer(&priv->txtimer, |
| 1289 | STMMAC_COAL_TIMER(priv->tx_coal_timer)); |
| 1290 | } else |
| 1291 | priv->tx_count_frames = 0; |
Shiraz Hashim | eb0dc4b | 2011-07-17 20:54:08 +0000 | [diff] [blame] | 1292 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1293 | /* To avoid raise condition */ |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 1294 | priv->hw->desc->set_tx_owner(first); |
Deepak Sikri | 8e83989 | 2012-07-08 21:14:45 +0000 | [diff] [blame] | 1295 | wmb(); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1296 | |
| 1297 | priv->cur_tx++; |
| 1298 | |
| 1299 | #ifdef STMMAC_XMIT_DEBUG |
| 1300 | if (netif_msg_pktdata(priv)) { |
| 1301 | pr_info("stmmac xmit: current=%d, dirty=%d, entry=%d, " |
| 1302 | "first=%p, nfrags=%d\n", |
| 1303 | (priv->cur_tx % txsize), (priv->dirty_tx % txsize), |
| 1304 | entry, first, nfrags); |
| 1305 | display_ring(priv->dma_tx, txsize); |
| 1306 | pr_info(">>> frame to be transmitted: "); |
| 1307 | print_pkt(skb->data, skb->len); |
| 1308 | } |
| 1309 | #endif |
| 1310 | if (unlikely(stmmac_tx_avail(priv) <= (MAX_SKB_FRAGS + 1))) { |
| 1311 | TX_DBG("%s: stop transmitted packets\n", __func__); |
| 1312 | netif_stop_queue(dev); |
| 1313 | } |
| 1314 | |
| 1315 | dev->stats.tx_bytes += skb->len; |
| 1316 | |
Richard Cochran | 3e82ce1 | 2011-06-12 02:19:06 +0000 | [diff] [blame] | 1317 | skb_tx_timestamp(skb); |
| 1318 | |
Richard Cochran | 52f64fa | 2011-06-19 03:31:43 +0000 | [diff] [blame] | 1319 | priv->hw->dma->enable_dma_transmission(priv->ioaddr); |
| 1320 | |
Giuseppe CAVALLARO | a9097a9 | 2011-10-18 00:01:19 +0000 | [diff] [blame] | 1321 | spin_unlock(&priv->tx_lock); |
| 1322 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1323 | return NETDEV_TX_OK; |
| 1324 | } |
| 1325 | |
| 1326 | static inline void stmmac_rx_refill(struct stmmac_priv *priv) |
| 1327 | { |
| 1328 | unsigned int rxsize = priv->dma_rx_size; |
| 1329 | int bfsize = priv->dma_buf_sz; |
| 1330 | struct dma_desc *p = priv->dma_rx; |
| 1331 | |
| 1332 | for (; priv->cur_rx - priv->dirty_rx > 0; priv->dirty_rx++) { |
| 1333 | unsigned int entry = priv->dirty_rx % rxsize; |
| 1334 | if (likely(priv->rx_skbuff[entry] == NULL)) { |
| 1335 | struct sk_buff *skb; |
| 1336 | |
Eric Dumazet | acb600d | 2012-10-05 06:23:55 +0000 | [diff] [blame] | 1337 | skb = netdev_alloc_skb_ip_align(priv->dev, bfsize); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1338 | |
| 1339 | if (unlikely(skb == NULL)) |
| 1340 | break; |
| 1341 | |
| 1342 | priv->rx_skbuff[entry] = skb; |
| 1343 | priv->rx_skbuff_dma[entry] = |
| 1344 | dma_map_single(priv->device, skb->data, bfsize, |
| 1345 | DMA_FROM_DEVICE); |
| 1346 | |
| 1347 | (p + entry)->des2 = priv->rx_skbuff_dma[entry]; |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 1348 | |
| 1349 | if (unlikely(priv->plat->has_gmac)) |
| 1350 | priv->hw->ring->refill_desc3(bfsize, p + entry); |
| 1351 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1352 | RX_DBG(KERN_INFO "\trefill entry #%d\n", entry); |
| 1353 | } |
Shiraz Hashim | eb0dc4b | 2011-07-17 20:54:08 +0000 | [diff] [blame] | 1354 | wmb(); |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 1355 | priv->hw->desc->set_rx_owner(p + entry); |
Deepak Sikri | 8e83989 | 2012-07-08 21:14:45 +0000 | [diff] [blame] | 1356 | wmb(); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1357 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1358 | } |
| 1359 | |
| 1360 | static int stmmac_rx(struct stmmac_priv *priv, int limit) |
| 1361 | { |
| 1362 | unsigned int rxsize = priv->dma_rx_size; |
| 1363 | unsigned int entry = priv->cur_rx % rxsize; |
| 1364 | unsigned int next_entry; |
| 1365 | unsigned int count = 0; |
| 1366 | struct dma_desc *p = priv->dma_rx + entry; |
| 1367 | struct dma_desc *p_next; |
| 1368 | |
| 1369 | #ifdef STMMAC_RX_DEBUG |
| 1370 | if (netif_msg_hw(priv)) { |
| 1371 | pr_debug(">>> stmmac_rx: descriptor ring:\n"); |
| 1372 | display_ring(priv->dma_rx, rxsize); |
| 1373 | } |
| 1374 | #endif |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 1375 | while (!priv->hw->desc->get_rx_owner(p)) { |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1376 | int status; |
| 1377 | |
| 1378 | if (count >= limit) |
| 1379 | break; |
| 1380 | |
| 1381 | count++; |
| 1382 | |
| 1383 | next_entry = (++priv->cur_rx) % rxsize; |
| 1384 | p_next = priv->dma_rx + next_entry; |
| 1385 | prefetch(p_next); |
| 1386 | |
| 1387 | /* read the status of the incoming frame */ |
Giuseppe CAVALLARO | db98a0b | 2010-01-06 23:07:17 +0000 | [diff] [blame] | 1388 | status = (priv->hw->desc->rx_status(&priv->dev->stats, |
| 1389 | &priv->xstats, p)); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1390 | if (unlikely(status == discard_frame)) |
| 1391 | priv->dev->stats.rx_errors++; |
| 1392 | else { |
| 1393 | struct sk_buff *skb; |
Giuseppe CAVALLARO | 3eeb299 | 2010-07-27 00:09:47 +0000 | [diff] [blame] | 1394 | int frame_len; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1395 | |
Deepak SIKRI | 38912bd | 2012-04-04 04:33:21 +0000 | [diff] [blame] | 1396 | frame_len = priv->hw->desc->get_rx_frame_len(p, |
| 1397 | priv->plat->rx_coe); |
Giuseppe CAVALLARO | 3eeb299 | 2010-07-27 00:09:47 +0000 | [diff] [blame] | 1398 | /* ACS is set; GMAC core strips PAD/FCS for IEEE 802.3 |
| 1399 | * Type frames (LLC/LLC-SNAP) */ |
| 1400 | if (unlikely(status != llc_snap)) |
| 1401 | frame_len -= ETH_FCS_LEN; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1402 | #ifdef STMMAC_RX_DEBUG |
| 1403 | if (frame_len > ETH_FRAME_LEN) |
| 1404 | pr_debug("\tRX frame size %d, COE status: %d\n", |
| 1405 | frame_len, status); |
| 1406 | |
| 1407 | if (netif_msg_hw(priv)) |
| 1408 | pr_debug("\tdesc: %p [entry %d] buff=0x%x\n", |
| 1409 | p, entry, p->des2); |
| 1410 | #endif |
| 1411 | skb = priv->rx_skbuff[entry]; |
| 1412 | if (unlikely(!skb)) { |
| 1413 | pr_err("%s: Inconsistent Rx descriptor chain\n", |
| 1414 | priv->dev->name); |
| 1415 | priv->dev->stats.rx_dropped++; |
| 1416 | break; |
| 1417 | } |
| 1418 | prefetch(skb->data - NET_IP_ALIGN); |
| 1419 | priv->rx_skbuff[entry] = NULL; |
| 1420 | |
| 1421 | skb_put(skb, frame_len); |
| 1422 | dma_unmap_single(priv->device, |
| 1423 | priv->rx_skbuff_dma[entry], |
| 1424 | priv->dma_buf_sz, DMA_FROM_DEVICE); |
| 1425 | #ifdef STMMAC_RX_DEBUG |
| 1426 | if (netif_msg_pktdata(priv)) { |
| 1427 | pr_info(" frame received (%dbytes)", frame_len); |
| 1428 | print_pkt(skb->data, frame_len); |
| 1429 | } |
| 1430 | #endif |
| 1431 | skb->protocol = eth_type_trans(skb, priv->dev); |
| 1432 | |
Giuseppe CAVALLARO | 62a2ab9 | 2012-11-25 23:10:43 +0000 | [diff] [blame] | 1433 | if (unlikely(!priv->plat->rx_coe)) |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 1434 | skb_checksum_none_assert(skb); |
Giuseppe CAVALLARO | 62a2ab9 | 2012-11-25 23:10:43 +0000 | [diff] [blame] | 1435 | else |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1436 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Giuseppe CAVALLARO | 62a2ab9 | 2012-11-25 23:10:43 +0000 | [diff] [blame] | 1437 | |
| 1438 | napi_gro_receive(&priv->napi, skb); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1439 | |
| 1440 | priv->dev->stats.rx_packets++; |
| 1441 | priv->dev->stats.rx_bytes += frame_len; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1442 | } |
| 1443 | entry = next_entry; |
| 1444 | p = p_next; /* use prefetched values */ |
| 1445 | } |
| 1446 | |
| 1447 | stmmac_rx_refill(priv); |
| 1448 | |
| 1449 | priv->xstats.rx_pkt_n += count; |
| 1450 | |
| 1451 | return count; |
| 1452 | } |
| 1453 | |
| 1454 | /** |
| 1455 | * stmmac_poll - stmmac poll method (NAPI) |
| 1456 | * @napi : pointer to the napi structure. |
| 1457 | * @budget : maximum number of packets that the current CPU can receive from |
| 1458 | * all interfaces. |
| 1459 | * Description : |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 1460 | * To look at the incoming frames and clear the tx resources. |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1461 | */ |
| 1462 | static int stmmac_poll(struct napi_struct *napi, int budget) |
| 1463 | { |
| 1464 | struct stmmac_priv *priv = container_of(napi, struct stmmac_priv, napi); |
| 1465 | int work_done = 0; |
| 1466 | |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 1467 | priv->xstats.napi_poll++; |
| 1468 | stmmac_tx_clean(priv); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1469 | |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 1470 | work_done = stmmac_rx(priv, budget); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1471 | if (work_done < budget) { |
| 1472 | napi_complete(napi); |
Giuseppe CAVALLARO | 9125cdd | 2012-11-25 23:10:42 +0000 | [diff] [blame] | 1473 | stmmac_enable_dma_irq(priv); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1474 | } |
| 1475 | return work_done; |
| 1476 | } |
| 1477 | |
| 1478 | /** |
| 1479 | * stmmac_tx_timeout |
| 1480 | * @dev : Pointer to net device structure |
| 1481 | * Description: this function is called when a packet transmission fails to |
Giuseppe CAVALLARO | 7284a3f | 2012-11-25 23:10:41 +0000 | [diff] [blame] | 1482 | * 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] | 1483 | * netdev structure and arrange for the device to be reset to a sane state |
| 1484 | * in order to transmit a new packet. |
| 1485 | */ |
| 1486 | static void stmmac_tx_timeout(struct net_device *dev) |
| 1487 | { |
| 1488 | struct stmmac_priv *priv = netdev_priv(dev); |
| 1489 | |
| 1490 | /* Clear Tx resources and restart transmitting again */ |
| 1491 | stmmac_tx_err(priv); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | /* Configuration changes (passed on by ifconfig) */ |
| 1495 | static int stmmac_config(struct net_device *dev, struct ifmap *map) |
| 1496 | { |
| 1497 | if (dev->flags & IFF_UP) /* can't act on a running interface */ |
| 1498 | return -EBUSY; |
| 1499 | |
| 1500 | /* Don't allow changing the I/O address */ |
| 1501 | if (map->base_addr != dev->base_addr) { |
| 1502 | pr_warning("%s: can't change I/O address\n", dev->name); |
| 1503 | return -EOPNOTSUPP; |
| 1504 | } |
| 1505 | |
| 1506 | /* Don't allow changing the IRQ */ |
| 1507 | if (map->irq != dev->irq) { |
| 1508 | pr_warning("%s: can't change IRQ number %d\n", |
| 1509 | dev->name, dev->irq); |
| 1510 | return -EOPNOTSUPP; |
| 1511 | } |
| 1512 | |
| 1513 | /* ignore other fields */ |
| 1514 | return 0; |
| 1515 | } |
| 1516 | |
| 1517 | /** |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 1518 | * stmmac_set_rx_mode - entry point for multicast addressing |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1519 | * @dev : pointer to the device structure |
| 1520 | * Description: |
| 1521 | * This function is a driver entry point which gets called by the kernel |
| 1522 | * whenever multicast addresses must be enabled/disabled. |
| 1523 | * Return value: |
| 1524 | * void. |
| 1525 | */ |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 1526 | static void stmmac_set_rx_mode(struct net_device *dev) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1527 | { |
| 1528 | struct stmmac_priv *priv = netdev_priv(dev); |
| 1529 | |
| 1530 | spin_lock(&priv->lock); |
Giuseppe CAVALLARO | cffb13f | 2012-05-13 22:18:41 +0000 | [diff] [blame] | 1531 | priv->hw->mac->set_filter(dev, priv->synopsys_id); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1532 | spin_unlock(&priv->lock); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1533 | } |
| 1534 | |
| 1535 | /** |
| 1536 | * stmmac_change_mtu - entry point to change MTU size for the device. |
| 1537 | * @dev : device pointer. |
| 1538 | * @new_mtu : the new MTU size for the device. |
| 1539 | * Description: the Maximum Transfer Unit (MTU) is used by the network layer |
| 1540 | * to drive packet transmission. Ethernet has an MTU of 1500 octets |
| 1541 | * (ETH_DATA_LEN). This value can be changed with ifconfig. |
| 1542 | * Return value: |
| 1543 | * 0 on success and an appropriate (-)ve integer as defined in errno.h |
| 1544 | * file on failure. |
| 1545 | */ |
| 1546 | static int stmmac_change_mtu(struct net_device *dev, int new_mtu) |
| 1547 | { |
| 1548 | struct stmmac_priv *priv = netdev_priv(dev); |
| 1549 | int max_mtu; |
| 1550 | |
| 1551 | if (netif_running(dev)) { |
| 1552 | pr_err("%s: must be stopped to change its MTU\n", dev->name); |
| 1553 | return -EBUSY; |
| 1554 | } |
| 1555 | |
Giuseppe CAVALLARO | 48febf7 | 2011-10-18 00:01:21 +0000 | [diff] [blame] | 1556 | if (priv->plat->enh_desc) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1557 | max_mtu = JUMBO_LEN; |
| 1558 | else |
Giuseppe CAVALLARO | 45db81e | 2011-10-18 01:39:55 +0000 | [diff] [blame] | 1559 | max_mtu = SKB_MAX_HEAD(NET_SKB_PAD + NET_IP_ALIGN); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1560 | |
| 1561 | if ((new_mtu < 46) || (new_mtu > max_mtu)) { |
| 1562 | pr_err("%s: invalid MTU, max MTU is: %d\n", dev->name, max_mtu); |
| 1563 | return -EINVAL; |
| 1564 | } |
| 1565 | |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 1566 | dev->mtu = new_mtu; |
| 1567 | netdev_update_features(dev); |
| 1568 | |
| 1569 | return 0; |
| 1570 | } |
| 1571 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 1572 | static netdev_features_t stmmac_fix_features(struct net_device *dev, |
| 1573 | netdev_features_t features) |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 1574 | { |
| 1575 | struct stmmac_priv *priv = netdev_priv(dev); |
| 1576 | |
Deepak SIKRI | 38912bd | 2012-04-04 04:33:21 +0000 | [diff] [blame] | 1577 | if (priv->plat->rx_coe == STMMAC_RX_COE_NONE) |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 1578 | features &= ~NETIF_F_RXCSUM; |
Deepak SIKRI | 38912bd | 2012-04-04 04:33:21 +0000 | [diff] [blame] | 1579 | else if (priv->plat->rx_coe == STMMAC_RX_COE_TYPE1) |
| 1580 | features &= ~NETIF_F_IPV6_CSUM; |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 1581 | if (!priv->plat->tx_coe) |
| 1582 | features &= ~NETIF_F_ALL_CSUM; |
| 1583 | |
Giuseppe CAVALLARO | ebbb293 | 2010-09-17 03:23:40 +0000 | [diff] [blame] | 1584 | /* Some GMAC devices have a bugged Jumbo frame support that |
| 1585 | * needs to have the Tx COE disabled for oversized frames |
| 1586 | * (due to limited buffer sizes). In this case we disable |
| 1587 | * the TX csum insertionin the TDES and not use SF. */ |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 1588 | if (priv->plat->bugged_jumbo && (dev->mtu > ETH_DATA_LEN)) |
| 1589 | features &= ~NETIF_F_ALL_CSUM; |
Giuseppe CAVALLARO | ebbb293 | 2010-09-17 03:23:40 +0000 | [diff] [blame] | 1590 | |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 1591 | return features; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1592 | } |
| 1593 | |
| 1594 | static irqreturn_t stmmac_interrupt(int irq, void *dev_id) |
| 1595 | { |
| 1596 | struct net_device *dev = (struct net_device *)dev_id; |
| 1597 | struct stmmac_priv *priv = netdev_priv(dev); |
| 1598 | |
| 1599 | if (unlikely(!dev)) { |
| 1600 | pr_err("%s: invalid dev pointer\n", __func__); |
| 1601 | return IRQ_NONE; |
| 1602 | } |
| 1603 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 1604 | /* To handle GMAC own interrupts */ |
| 1605 | if (priv->plat->has_gmac) { |
| 1606 | int status = priv->hw->mac->host_irq_status((void __iomem *) |
| 1607 | dev->base_addr); |
| 1608 | if (unlikely(status)) { |
| 1609 | if (status & core_mmc_tx_irq) |
| 1610 | priv->xstats.mmc_tx_irq_n++; |
| 1611 | if (status & core_mmc_rx_irq) |
| 1612 | priv->xstats.mmc_rx_irq_n++; |
| 1613 | if (status & core_mmc_rx_csum_offload_irq) |
| 1614 | priv->xstats.mmc_rx_csum_offload_irq_n++; |
| 1615 | if (status & core_irq_receive_pmt_irq) |
| 1616 | priv->xstats.irq_receive_pmt_irq_n++; |
Giuseppe CAVALLARO | aec7ff2 | 2010-01-06 23:07:18 +0000 | [diff] [blame] | 1617 | |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 1618 | /* For LPI we need to save the tx status */ |
| 1619 | if (status & core_irq_tx_path_in_lpi_mode) { |
| 1620 | priv->xstats.irq_tx_path_in_lpi_mode_n++; |
| 1621 | priv->tx_path_in_lpi_mode = true; |
| 1622 | } |
| 1623 | if (status & core_irq_tx_path_exit_lpi_mode) { |
| 1624 | priv->xstats.irq_tx_path_exit_lpi_mode_n++; |
| 1625 | priv->tx_path_in_lpi_mode = false; |
| 1626 | } |
| 1627 | if (status & core_irq_rx_path_in_lpi_mode) |
| 1628 | priv->xstats.irq_rx_path_in_lpi_mode_n++; |
| 1629 | if (status & core_irq_rx_path_exit_lpi_mode) |
| 1630 | priv->xstats.irq_rx_path_exit_lpi_mode_n++; |
| 1631 | } |
| 1632 | } |
| 1633 | |
| 1634 | /* To handle DMA interrupts */ |
Giuseppe CAVALLARO | aec7ff2 | 2010-01-06 23:07:18 +0000 | [diff] [blame] | 1635 | stmmac_dma_interrupt(priv); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1636 | |
| 1637 | return IRQ_HANDLED; |
| 1638 | } |
| 1639 | |
| 1640 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1641 | /* Polling receive - used by NETCONSOLE and other diagnostic tools |
| 1642 | * to allow network I/O with interrupts disabled. */ |
| 1643 | static void stmmac_poll_controller(struct net_device *dev) |
| 1644 | { |
| 1645 | disable_irq(dev->irq); |
| 1646 | stmmac_interrupt(dev->irq, dev); |
| 1647 | enable_irq(dev->irq); |
| 1648 | } |
| 1649 | #endif |
| 1650 | |
| 1651 | /** |
| 1652 | * stmmac_ioctl - Entry point for the Ioctl |
| 1653 | * @dev: Device pointer. |
| 1654 | * @rq: An IOCTL specefic structure, that can contain a pointer to |
| 1655 | * a proprietary structure used to pass information to the driver. |
| 1656 | * @cmd: IOCTL command |
| 1657 | * Description: |
| 1658 | * Currently there are no special functionality supported in IOCTL, just the |
| 1659 | * phy_mii_ioctl(...) can be invoked. |
| 1660 | */ |
| 1661 | static int stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 1662 | { |
| 1663 | struct stmmac_priv *priv = netdev_priv(dev); |
Richard Cochran | 28b0411 | 2010-07-17 08:48:55 +0000 | [diff] [blame] | 1664 | int ret; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1665 | |
| 1666 | if (!netif_running(dev)) |
| 1667 | return -EINVAL; |
| 1668 | |
Richard Cochran | 28b0411 | 2010-07-17 08:48:55 +0000 | [diff] [blame] | 1669 | if (!priv->phydev) |
| 1670 | return -EINVAL; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1671 | |
Richard Cochran | 28b0411 | 2010-07-17 08:48:55 +0000 | [diff] [blame] | 1672 | ret = phy_mii_ioctl(priv->phydev, rq, cmd); |
Richard Cochran | 28b0411 | 2010-07-17 08:48:55 +0000 | [diff] [blame] | 1673 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1674 | return ret; |
| 1675 | } |
| 1676 | |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 1677 | #ifdef CONFIG_STMMAC_DEBUG_FS |
| 1678 | static struct dentry *stmmac_fs_dir; |
| 1679 | static struct dentry *stmmac_rings_status; |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 1680 | static struct dentry *stmmac_dma_cap; |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 1681 | |
| 1682 | static int stmmac_sysfs_ring_read(struct seq_file *seq, void *v) |
| 1683 | { |
| 1684 | struct tmp_s { |
| 1685 | u64 a; |
| 1686 | unsigned int b; |
| 1687 | unsigned int c; |
| 1688 | }; |
| 1689 | int i; |
| 1690 | struct net_device *dev = seq->private; |
| 1691 | struct stmmac_priv *priv = netdev_priv(dev); |
| 1692 | |
| 1693 | seq_printf(seq, "=======================\n"); |
| 1694 | seq_printf(seq, " RX descriptor ring\n"); |
| 1695 | seq_printf(seq, "=======================\n"); |
| 1696 | |
| 1697 | for (i = 0; i < priv->dma_rx_size; i++) { |
| 1698 | struct tmp_s *x = (struct tmp_s *)(priv->dma_rx + i); |
| 1699 | seq_printf(seq, "[%d] DES0=0x%x DES1=0x%x BUF1=0x%x BUF2=0x%x", |
| 1700 | i, (unsigned int)(x->a), |
| 1701 | (unsigned int)((x->a) >> 32), x->b, x->c); |
| 1702 | seq_printf(seq, "\n"); |
| 1703 | } |
| 1704 | |
| 1705 | seq_printf(seq, "\n"); |
| 1706 | seq_printf(seq, "=======================\n"); |
| 1707 | seq_printf(seq, " TX descriptor ring\n"); |
| 1708 | seq_printf(seq, "=======================\n"); |
| 1709 | |
| 1710 | for (i = 0; i < priv->dma_tx_size; i++) { |
| 1711 | struct tmp_s *x = (struct tmp_s *)(priv->dma_tx + i); |
| 1712 | seq_printf(seq, "[%d] DES0=0x%x DES1=0x%x BUF1=0x%x BUF2=0x%x", |
| 1713 | i, (unsigned int)(x->a), |
| 1714 | (unsigned int)((x->a) >> 32), x->b, x->c); |
| 1715 | seq_printf(seq, "\n"); |
| 1716 | } |
| 1717 | |
| 1718 | return 0; |
| 1719 | } |
| 1720 | |
| 1721 | static int stmmac_sysfs_ring_open(struct inode *inode, struct file *file) |
| 1722 | { |
| 1723 | return single_open(file, stmmac_sysfs_ring_read, inode->i_private); |
| 1724 | } |
| 1725 | |
| 1726 | static const struct file_operations stmmac_rings_status_fops = { |
| 1727 | .owner = THIS_MODULE, |
| 1728 | .open = stmmac_sysfs_ring_open, |
| 1729 | .read = seq_read, |
| 1730 | .llseek = seq_lseek, |
Djalal Harouni | 7486394 | 2012-05-20 13:55:30 +0000 | [diff] [blame] | 1731 | .release = single_release, |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 1732 | }; |
| 1733 | |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 1734 | static int stmmac_sysfs_dma_cap_read(struct seq_file *seq, void *v) |
| 1735 | { |
| 1736 | struct net_device *dev = seq->private; |
| 1737 | struct stmmac_priv *priv = netdev_priv(dev); |
| 1738 | |
Giuseppe CAVALLARO | 19e30c1 | 2011-11-16 21:58:00 +0000 | [diff] [blame] | 1739 | if (!priv->hw_cap_support) { |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 1740 | seq_printf(seq, "DMA HW features not supported\n"); |
| 1741 | return 0; |
| 1742 | } |
| 1743 | |
| 1744 | seq_printf(seq, "==============================\n"); |
| 1745 | seq_printf(seq, "\tDMA HW features\n"); |
| 1746 | seq_printf(seq, "==============================\n"); |
| 1747 | |
| 1748 | seq_printf(seq, "\t10/100 Mbps %s\n", |
| 1749 | (priv->dma_cap.mbps_10_100) ? "Y" : "N"); |
| 1750 | seq_printf(seq, "\t1000 Mbps %s\n", |
| 1751 | (priv->dma_cap.mbps_1000) ? "Y" : "N"); |
| 1752 | seq_printf(seq, "\tHalf duple %s\n", |
| 1753 | (priv->dma_cap.half_duplex) ? "Y" : "N"); |
| 1754 | seq_printf(seq, "\tHash Filter: %s\n", |
| 1755 | (priv->dma_cap.hash_filter) ? "Y" : "N"); |
| 1756 | seq_printf(seq, "\tMultiple MAC address registers: %s\n", |
| 1757 | (priv->dma_cap.multi_addr) ? "Y" : "N"); |
| 1758 | seq_printf(seq, "\tPCS (TBI/SGMII/RTBI PHY interfatces): %s\n", |
| 1759 | (priv->dma_cap.pcs) ? "Y" : "N"); |
| 1760 | seq_printf(seq, "\tSMA (MDIO) Interface: %s\n", |
| 1761 | (priv->dma_cap.sma_mdio) ? "Y" : "N"); |
| 1762 | seq_printf(seq, "\tPMT Remote wake up: %s\n", |
| 1763 | (priv->dma_cap.pmt_remote_wake_up) ? "Y" : "N"); |
| 1764 | seq_printf(seq, "\tPMT Magic Frame: %s\n", |
| 1765 | (priv->dma_cap.pmt_magic_frame) ? "Y" : "N"); |
| 1766 | seq_printf(seq, "\tRMON module: %s\n", |
| 1767 | (priv->dma_cap.rmon) ? "Y" : "N"); |
| 1768 | seq_printf(seq, "\tIEEE 1588-2002 Time Stamp: %s\n", |
| 1769 | (priv->dma_cap.time_stamp) ? "Y" : "N"); |
| 1770 | seq_printf(seq, "\tIEEE 1588-2008 Advanced Time Stamp:%s\n", |
| 1771 | (priv->dma_cap.atime_stamp) ? "Y" : "N"); |
| 1772 | seq_printf(seq, "\t802.3az - Energy-Efficient Ethernet (EEE) %s\n", |
| 1773 | (priv->dma_cap.eee) ? "Y" : "N"); |
| 1774 | seq_printf(seq, "\tAV features: %s\n", (priv->dma_cap.av) ? "Y" : "N"); |
| 1775 | seq_printf(seq, "\tChecksum Offload in TX: %s\n", |
| 1776 | (priv->dma_cap.tx_coe) ? "Y" : "N"); |
| 1777 | seq_printf(seq, "\tIP Checksum Offload (type1) in RX: %s\n", |
| 1778 | (priv->dma_cap.rx_coe_type1) ? "Y" : "N"); |
| 1779 | seq_printf(seq, "\tIP Checksum Offload (type2) in RX: %s\n", |
| 1780 | (priv->dma_cap.rx_coe_type2) ? "Y" : "N"); |
| 1781 | seq_printf(seq, "\tRXFIFO > 2048bytes: %s\n", |
| 1782 | (priv->dma_cap.rxfifo_over_2048) ? "Y" : "N"); |
| 1783 | seq_printf(seq, "\tNumber of Additional RX channel: %d\n", |
| 1784 | priv->dma_cap.number_rx_channel); |
| 1785 | seq_printf(seq, "\tNumber of Additional TX channel: %d\n", |
| 1786 | priv->dma_cap.number_tx_channel); |
| 1787 | seq_printf(seq, "\tEnhanced descriptors: %s\n", |
| 1788 | (priv->dma_cap.enh_desc) ? "Y" : "N"); |
| 1789 | |
| 1790 | return 0; |
| 1791 | } |
| 1792 | |
| 1793 | static int stmmac_sysfs_dma_cap_open(struct inode *inode, struct file *file) |
| 1794 | { |
| 1795 | return single_open(file, stmmac_sysfs_dma_cap_read, inode->i_private); |
| 1796 | } |
| 1797 | |
| 1798 | static const struct file_operations stmmac_dma_cap_fops = { |
| 1799 | .owner = THIS_MODULE, |
| 1800 | .open = stmmac_sysfs_dma_cap_open, |
| 1801 | .read = seq_read, |
| 1802 | .llseek = seq_lseek, |
Djalal Harouni | 7486394 | 2012-05-20 13:55:30 +0000 | [diff] [blame] | 1803 | .release = single_release, |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 1804 | }; |
| 1805 | |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 1806 | static int stmmac_init_fs(struct net_device *dev) |
| 1807 | { |
| 1808 | /* Create debugfs entries */ |
| 1809 | stmmac_fs_dir = debugfs_create_dir(STMMAC_RESOURCE_NAME, NULL); |
| 1810 | |
| 1811 | if (!stmmac_fs_dir || IS_ERR(stmmac_fs_dir)) { |
| 1812 | pr_err("ERROR %s, debugfs create directory failed\n", |
| 1813 | STMMAC_RESOURCE_NAME); |
| 1814 | |
| 1815 | return -ENOMEM; |
| 1816 | } |
| 1817 | |
| 1818 | /* Entry to report DMA RX/TX rings */ |
| 1819 | stmmac_rings_status = debugfs_create_file("descriptors_status", |
| 1820 | S_IRUGO, stmmac_fs_dir, dev, |
| 1821 | &stmmac_rings_status_fops); |
| 1822 | |
| 1823 | if (!stmmac_rings_status || IS_ERR(stmmac_rings_status)) { |
| 1824 | pr_info("ERROR creating stmmac ring debugfs file\n"); |
| 1825 | debugfs_remove(stmmac_fs_dir); |
| 1826 | |
| 1827 | return -ENOMEM; |
| 1828 | } |
| 1829 | |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 1830 | /* Entry to report the DMA HW features */ |
| 1831 | stmmac_dma_cap = debugfs_create_file("dma_cap", S_IRUGO, stmmac_fs_dir, |
| 1832 | dev, &stmmac_dma_cap_fops); |
| 1833 | |
| 1834 | if (!stmmac_dma_cap || IS_ERR(stmmac_dma_cap)) { |
| 1835 | pr_info("ERROR creating stmmac MMC debugfs file\n"); |
| 1836 | debugfs_remove(stmmac_rings_status); |
| 1837 | debugfs_remove(stmmac_fs_dir); |
| 1838 | |
| 1839 | return -ENOMEM; |
| 1840 | } |
| 1841 | |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 1842 | return 0; |
| 1843 | } |
| 1844 | |
| 1845 | static void stmmac_exit_fs(void) |
| 1846 | { |
| 1847 | debugfs_remove(stmmac_rings_status); |
Giuseppe CAVALLARO | e743482 | 2011-09-01 21:51:41 +0000 | [diff] [blame] | 1848 | debugfs_remove(stmmac_dma_cap); |
Giuseppe CAVALLARO | 7ac2905 | 2011-09-01 21:51:39 +0000 | [diff] [blame] | 1849 | debugfs_remove(stmmac_fs_dir); |
| 1850 | } |
| 1851 | #endif /* CONFIG_STMMAC_DEBUG_FS */ |
| 1852 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1853 | static const struct net_device_ops stmmac_netdev_ops = { |
| 1854 | .ndo_open = stmmac_open, |
| 1855 | .ndo_start_xmit = stmmac_xmit, |
| 1856 | .ndo_stop = stmmac_release, |
| 1857 | .ndo_change_mtu = stmmac_change_mtu, |
Michał Mirosław | 5e982f3 | 2011-04-09 02:46:55 +0000 | [diff] [blame] | 1858 | .ndo_fix_features = stmmac_fix_features, |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 1859 | .ndo_set_rx_mode = stmmac_set_rx_mode, |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1860 | .ndo_tx_timeout = stmmac_tx_timeout, |
| 1861 | .ndo_do_ioctl = stmmac_ioctl, |
| 1862 | .ndo_set_config = stmmac_config, |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1863 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1864 | .ndo_poll_controller = stmmac_poll_controller, |
| 1865 | #endif |
| 1866 | .ndo_set_mac_address = eth_mac_addr, |
| 1867 | }; |
| 1868 | |
| 1869 | /** |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 1870 | * stmmac_hw_init - Init the MAC device |
| 1871 | * @priv : pointer to the private device structure. |
| 1872 | * Description: this function detects which MAC device |
| 1873 | * (GMAC/MAC10-100) has to attached, checks the HW capability |
| 1874 | * (if supported) and sets the driver's features (for example |
| 1875 | * to use the ring or chaine mode or support the normal/enh |
| 1876 | * descriptor structure). |
| 1877 | */ |
| 1878 | static int stmmac_hw_init(struct stmmac_priv *priv) |
| 1879 | { |
| 1880 | int ret = 0; |
| 1881 | struct mac_device_info *mac; |
| 1882 | |
| 1883 | /* Identify the MAC HW device */ |
Marc Kleine-Budde | 03f2eec | 2012-04-03 22:13:01 +0000 | [diff] [blame] | 1884 | if (priv->plat->has_gmac) { |
| 1885 | priv->dev->priv_flags |= IFF_UNICAST_FLT; |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 1886 | mac = dwmac1000_setup(priv->ioaddr); |
Marc Kleine-Budde | 03f2eec | 2012-04-03 22:13:01 +0000 | [diff] [blame] | 1887 | } else { |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 1888 | mac = dwmac100_setup(priv->ioaddr); |
Marc Kleine-Budde | 03f2eec | 2012-04-03 22:13:01 +0000 | [diff] [blame] | 1889 | } |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 1890 | if (!mac) |
| 1891 | return -ENOMEM; |
| 1892 | |
| 1893 | priv->hw = mac; |
| 1894 | |
| 1895 | /* To use the chained or ring mode */ |
| 1896 | priv->hw->ring = &ring_mode_ops; |
| 1897 | |
| 1898 | /* Get and dump the chip ID */ |
Giuseppe CAVALLARO | cffb13f | 2012-05-13 22:18:41 +0000 | [diff] [blame] | 1899 | priv->synopsys_id = stmmac_get_synopsys_id(priv); |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 1900 | |
| 1901 | /* Get the HW capability (new GMAC newer than 3.50a) */ |
| 1902 | priv->hw_cap_support = stmmac_get_hw_features(priv); |
| 1903 | if (priv->hw_cap_support) { |
| 1904 | pr_info(" DMA HW capability register supported"); |
| 1905 | |
| 1906 | /* We can override some gmac/dma configuration fields: e.g. |
| 1907 | * enh_desc, tx_coe (e.g. that are passed through the |
| 1908 | * platform) with the values from the HW capability |
| 1909 | * register (if supported). |
| 1910 | */ |
| 1911 | priv->plat->enh_desc = priv->dma_cap.enh_desc; |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 1912 | priv->plat->pmt = priv->dma_cap.pmt_remote_wake_up; |
Deepak SIKRI | 38912bd | 2012-04-04 04:33:21 +0000 | [diff] [blame] | 1913 | |
| 1914 | priv->plat->tx_coe = priv->dma_cap.tx_coe; |
| 1915 | |
| 1916 | if (priv->dma_cap.rx_coe_type2) |
| 1917 | priv->plat->rx_coe = STMMAC_RX_COE_TYPE2; |
| 1918 | else if (priv->dma_cap.rx_coe_type1) |
| 1919 | priv->plat->rx_coe = STMMAC_RX_COE_TYPE1; |
| 1920 | |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 1921 | } else |
| 1922 | pr_info(" No HW DMA feature register supported"); |
| 1923 | |
| 1924 | /* Select the enhnaced/normal descriptor structures */ |
| 1925 | stmmac_selec_desc_mode(priv); |
| 1926 | |
Deepak SIKRI | 38912bd | 2012-04-04 04:33:21 +0000 | [diff] [blame] | 1927 | /* Enable the IPC (Checksum Offload) and check if the feature has been |
| 1928 | * enabled during the core configuration. */ |
| 1929 | ret = priv->hw->mac->rx_ipc(priv->ioaddr); |
| 1930 | if (!ret) { |
| 1931 | pr_warning(" RX IPC Checksum Offload not configured.\n"); |
| 1932 | priv->plat->rx_coe = STMMAC_RX_COE_NONE; |
| 1933 | } |
| 1934 | |
| 1935 | if (priv->plat->rx_coe) |
| 1936 | pr_info(" RX Checksum Offload Engine supported (type %d)\n", |
| 1937 | priv->plat->rx_coe); |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 1938 | if (priv->plat->tx_coe) |
| 1939 | pr_info(" TX Checksum insertion supported\n"); |
| 1940 | |
| 1941 | if (priv->plat->pmt) { |
| 1942 | pr_info(" Wake-Up On Lan supported\n"); |
| 1943 | device_set_wakeup_capable(priv->device, 1); |
| 1944 | } |
| 1945 | |
| 1946 | return ret; |
| 1947 | } |
| 1948 | |
| 1949 | /** |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1950 | * stmmac_dvr_probe |
| 1951 | * @device: device pointer |
Giuseppe CAVALLARO | ff3dd78 | 2012-06-04 19:22:55 +0000 | [diff] [blame] | 1952 | * @plat_dat: platform data pointer |
| 1953 | * @addr: iobase memory address |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1954 | * Description: this is the main probe function used to |
| 1955 | * call the alloc_etherdev, allocate the priv structure. |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1956 | */ |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1957 | struct stmmac_priv *stmmac_dvr_probe(struct device *device, |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 1958 | struct plat_stmmacenet_data *plat_dat, |
| 1959 | void __iomem *addr) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1960 | { |
| 1961 | int ret = 0; |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1962 | struct net_device *ndev = NULL; |
| 1963 | struct stmmac_priv *priv; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1964 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1965 | ndev = alloc_etherdev(sizeof(struct stmmac_priv)); |
Joe Perches | 41de8d4 | 2012-01-29 13:47:52 +0000 | [diff] [blame] | 1966 | if (!ndev) |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1967 | return NULL; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1968 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1969 | SET_NETDEV_DEV(ndev, device); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 1970 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1971 | priv = netdev_priv(ndev); |
| 1972 | priv->device = device; |
| 1973 | priv->dev = ndev; |
| 1974 | |
| 1975 | ether_setup(ndev); |
| 1976 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1977 | stmmac_set_ethtool_ops(ndev); |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 1978 | priv->pause = pause; |
| 1979 | priv->plat = plat_dat; |
| 1980 | priv->ioaddr = addr; |
| 1981 | priv->dev->base_addr = (unsigned long)addr; |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1982 | |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 1983 | /* Verify driver arguments */ |
| 1984 | stmmac_verify_args(); |
| 1985 | |
| 1986 | /* Override with kernel parameters if supplied XXX CRS XXX |
| 1987 | * this needs to have multiple instances */ |
| 1988 | if ((phyaddr >= 0) && (phyaddr <= 31)) |
| 1989 | priv->plat->phy_addr = phyaddr; |
| 1990 | |
| 1991 | /* Init MAC and get the capabilities */ |
| 1992 | stmmac_hw_init(priv); |
| 1993 | |
| 1994 | ndev->netdev_ops = &stmmac_netdev_ops; |
| 1995 | |
| 1996 | ndev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | |
| 1997 | NETIF_F_RXCSUM; |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1998 | ndev->features |= ndev->hw_features | NETIF_F_HIGHDMA; |
| 1999 | ndev->watchdog_timeo = msecs_to_jiffies(watchdog); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2000 | #ifdef STMMAC_VLAN_TAG_USED |
| 2001 | /* Both mac100 and gmac support receive VLAN tag detection */ |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2002 | ndev->features |= NETIF_F_HW_VLAN_RX; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2003 | #endif |
| 2004 | priv->msg_enable = netif_msg_init(debug, default_msg_level); |
| 2005 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2006 | if (flow_ctrl) |
| 2007 | priv->flow_ctrl = FLOW_AUTO; /* RX/TX pause on */ |
| 2008 | |
Giuseppe CAVALLARO | 62a2ab9 | 2012-11-25 23:10:43 +0000 | [diff] [blame] | 2009 | /* Rx Watchdog is available in the COREs newer than the 3.40. |
| 2010 | * In some case, for example on bugged HW this feature |
| 2011 | * has to be disable and this can be done by passing the |
| 2012 | * riwt_off field from the platform. |
| 2013 | */ |
| 2014 | if ((priv->synopsys_id >= DWMAC_CORE_3_50) && (!priv->plat->riwt_off)) { |
| 2015 | priv->use_riwt = 1; |
| 2016 | pr_info(" Enable RX Mitigation via HW Watchdog Timer\n"); |
| 2017 | } |
| 2018 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2019 | netif_napi_add(ndev, &priv->napi, stmmac_poll, 64); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2020 | |
Vlad Lungu | f8e9616 | 2010-11-29 22:52:52 +0000 | [diff] [blame] | 2021 | spin_lock_init(&priv->lock); |
Giuseppe CAVALLARO | a9097a9 | 2011-10-18 00:01:19 +0000 | [diff] [blame] | 2022 | spin_lock_init(&priv->tx_lock); |
Vlad Lungu | f8e9616 | 2010-11-29 22:52:52 +0000 | [diff] [blame] | 2023 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2024 | ret = register_netdev(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2025 | if (ret) { |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 2026 | pr_err("%s: ERROR %i registering the device\n", __func__, ret); |
Viresh Kumar | 6a81c26 | 2012-07-30 14:39:41 -0700 | [diff] [blame] | 2027 | goto error_netdev_register; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2028 | } |
| 2029 | |
Kelvin Cheung | ae4d8cf | 2012-08-18 00:16:23 +0000 | [diff] [blame] | 2030 | priv->stmmac_clk = clk_get(priv->device, STMMAC_RESOURCE_NAME); |
Viresh Kumar | 6a81c26 | 2012-07-30 14:39:41 -0700 | [diff] [blame] | 2031 | if (IS_ERR(priv->stmmac_clk)) { |
Giuseppe CAVALLARO | 31ea38e | 2012-04-18 19:48:22 +0000 | [diff] [blame] | 2032 | pr_warning("%s: warning: cannot get CSR clock\n", __func__); |
Viresh Kumar | 6a81c26 | 2012-07-30 14:39:41 -0700 | [diff] [blame] | 2033 | goto error_clk_get; |
| 2034 | } |
Giuseppe CAVALLARO | ba1377ff | 2012-04-04 04:33:25 +0000 | [diff] [blame] | 2035 | |
Giuseppe CAVALLARO | cd7201f | 2012-04-04 04:33:27 +0000 | [diff] [blame] | 2036 | /* If a specific clk_csr value is passed from the platform |
| 2037 | * this means that the CSR Clock Range selection cannot be |
| 2038 | * changed at run-time and it is fixed. Viceversa the driver'll try to |
| 2039 | * set the MDC clock dynamically according to the csr actual |
| 2040 | * clock input. |
| 2041 | */ |
| 2042 | if (!priv->plat->clk_csr) |
| 2043 | stmmac_clk_csr_set(priv); |
| 2044 | else |
| 2045 | priv->clk_csr = priv->plat->clk_csr; |
| 2046 | |
Francesco Virlinzi | 4bfcbd7 | 2012-04-18 19:48:20 +0000 | [diff] [blame] | 2047 | /* MDIO bus Registration */ |
| 2048 | ret = stmmac_mdio_register(ndev); |
| 2049 | if (ret < 0) { |
| 2050 | pr_debug("%s: MDIO bus (id: %d) registration failed", |
| 2051 | __func__, priv->plat->bus_id); |
Viresh Kumar | 6a81c26 | 2012-07-30 14:39:41 -0700 | [diff] [blame] | 2052 | goto error_mdio_register; |
Francesco Virlinzi | 4bfcbd7 | 2012-04-18 19:48:20 +0000 | [diff] [blame] | 2053 | } |
| 2054 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2055 | return priv; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2056 | |
Viresh Kumar | 6a81c26 | 2012-07-30 14:39:41 -0700 | [diff] [blame] | 2057 | error_mdio_register: |
| 2058 | clk_put(priv->stmmac_clk); |
| 2059 | error_clk_get: |
Dan Carpenter | 34a52f3 | 2010-12-20 21:34:56 +0000 | [diff] [blame] | 2060 | unregister_netdev(ndev); |
Viresh Kumar | 6a81c26 | 2012-07-30 14:39:41 -0700 | [diff] [blame] | 2061 | error_netdev_register: |
| 2062 | netif_napi_del(&priv->napi); |
Dan Carpenter | 34a52f3 | 2010-12-20 21:34:56 +0000 | [diff] [blame] | 2063 | free_netdev(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2064 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2065 | return NULL; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | /** |
| 2069 | * stmmac_dvr_remove |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2070 | * @ndev: net device pointer |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2071 | * 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] | 2072 | * changes the link status, releases the DMA descriptor rings. |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2073 | */ |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2074 | int stmmac_dvr_remove(struct net_device *ndev) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2075 | { |
Giuseppe CAVALLARO | aec7ff2 | 2010-01-06 23:07:18 +0000 | [diff] [blame] | 2076 | struct stmmac_priv *priv = netdev_priv(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2077 | |
| 2078 | pr_info("%s:\n\tremoving driver", __func__); |
| 2079 | |
Giuseppe CAVALLARO | ad01b7d | 2010-08-23 20:40:42 +0000 | [diff] [blame] | 2080 | priv->hw->dma->stop_rx(priv->ioaddr); |
| 2081 | priv->hw->dma->stop_tx(priv->ioaddr); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2082 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2083 | stmmac_set_mac(priv->ioaddr, false); |
Francesco Virlinzi | 4bfcbd7 | 2012-04-18 19:48:20 +0000 | [diff] [blame] | 2084 | stmmac_mdio_unregister(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2085 | netif_carrier_off(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2086 | unregister_netdev(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2087 | free_netdev(ndev); |
| 2088 | |
| 2089 | return 0; |
| 2090 | } |
| 2091 | |
| 2092 | #ifdef CONFIG_PM |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2093 | int stmmac_suspend(struct net_device *ndev) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2094 | { |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 2095 | struct stmmac_priv *priv = netdev_priv(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2096 | int dis_ic = 0; |
Giuseppe CAVALLARO | f8c5a87 | 2012-05-13 22:18:43 +0000 | [diff] [blame] | 2097 | unsigned long flags; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2098 | |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 2099 | if (!ndev || !netif_running(ndev)) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2100 | return 0; |
| 2101 | |
Francesco Virlinzi | 102463b | 2011-11-16 21:58:02 +0000 | [diff] [blame] | 2102 | if (priv->phydev) |
| 2103 | phy_stop(priv->phydev); |
| 2104 | |
Giuseppe CAVALLARO | f8c5a87 | 2012-05-13 22:18:43 +0000 | [diff] [blame] | 2105 | spin_lock_irqsave(&priv->lock, flags); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2106 | |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 2107 | netif_device_detach(ndev); |
| 2108 | netif_stop_queue(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2109 | |
Giuseppe CAVALLARO | 62a2ab9 | 2012-11-25 23:10:43 +0000 | [diff] [blame] | 2110 | if (priv->use_riwt) |
| 2111 | dis_ic = 1; |
| 2112 | |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 2113 | napi_disable(&priv->napi); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2114 | |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 2115 | /* Stop TX/RX DMA */ |
| 2116 | priv->hw->dma->stop_tx(priv->ioaddr); |
| 2117 | priv->hw->dma->stop_rx(priv->ioaddr); |
| 2118 | /* Clear the Rx/Tx descriptors */ |
| 2119 | priv->hw->desc->init_rx_desc(priv->dma_rx, priv->dma_rx_size, |
| 2120 | dis_ic); |
| 2121 | priv->hw->desc->init_tx_desc(priv->dma_tx, priv->dma_tx_size); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2122 | |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 2123 | /* Enable Power down mode by programming the PMT regs */ |
| 2124 | if (device_may_wakeup(priv->device)) |
| 2125 | priv->hw->mac->pmt(priv->ioaddr, priv->wolopts); |
Giuseppe CAVALLARO | ba1377ff | 2012-04-04 04:33:25 +0000 | [diff] [blame] | 2126 | else { |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2127 | stmmac_set_mac(priv->ioaddr, false); |
Giuseppe CAVALLARO | ba1377ff | 2012-04-04 04:33:25 +0000 | [diff] [blame] | 2128 | /* Disable clock in case of PWM is off */ |
Stefan Roese | a630844 | 2012-09-21 01:06:29 +0000 | [diff] [blame] | 2129 | clk_disable_unprepare(priv->stmmac_clk); |
Giuseppe CAVALLARO | ba1377ff | 2012-04-04 04:33:25 +0000 | [diff] [blame] | 2130 | } |
Giuseppe CAVALLARO | f8c5a87 | 2012-05-13 22:18:43 +0000 | [diff] [blame] | 2131 | spin_unlock_irqrestore(&priv->lock, flags); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2132 | return 0; |
| 2133 | } |
| 2134 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2135 | int stmmac_resume(struct net_device *ndev) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2136 | { |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 2137 | struct stmmac_priv *priv = netdev_priv(ndev); |
Giuseppe CAVALLARO | f8c5a87 | 2012-05-13 22:18:43 +0000 | [diff] [blame] | 2138 | unsigned long flags; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2139 | |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 2140 | if (!netif_running(ndev)) |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2141 | return 0; |
| 2142 | |
Giuseppe CAVALLARO | f8c5a87 | 2012-05-13 22:18:43 +0000 | [diff] [blame] | 2143 | spin_lock_irqsave(&priv->lock, flags); |
Giuseppe Cavallaro | c4433be | 2010-09-06 05:02:11 +0200 | [diff] [blame] | 2144 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2145 | /* Power Down bit, into the PM register, is cleared |
| 2146 | * automatically as soon as a magic packet or a Wake-up frame |
| 2147 | * is received. Anyway, it's better to manually clear |
| 2148 | * this bit because it can generate problems while resuming |
| 2149 | * from another devices (e.g. serial console). */ |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 2150 | if (device_may_wakeup(priv->device)) |
Giuseppe Cavallaro | 543876c | 2010-09-24 21:27:41 -0700 | [diff] [blame] | 2151 | priv->hw->mac->pmt(priv->ioaddr, 0); |
Giuseppe CAVALLARO | ba1377ff | 2012-04-04 04:33:25 +0000 | [diff] [blame] | 2152 | else |
| 2153 | /* enable the clk prevously disabled */ |
Stefan Roese | a630844 | 2012-09-21 01:06:29 +0000 | [diff] [blame] | 2154 | clk_prepare_enable(priv->stmmac_clk); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2155 | |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 2156 | netif_device_attach(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2157 | |
| 2158 | /* Enable the MAC and DMA */ |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2159 | stmmac_set_mac(priv->ioaddr, true); |
Giuseppe CAVALLARO | ad01b7d | 2010-08-23 20:40:42 +0000 | [diff] [blame] | 2160 | priv->hw->dma->start_tx(priv->ioaddr); |
| 2161 | priv->hw->dma->start_rx(priv->ioaddr); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2162 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2163 | napi_enable(&priv->napi); |
| 2164 | |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 2165 | netif_start_queue(ndev); |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2166 | |
Giuseppe CAVALLARO | f8c5a87 | 2012-05-13 22:18:43 +0000 | [diff] [blame] | 2167 | spin_unlock_irqrestore(&priv->lock, flags); |
Francesco Virlinzi | 102463b | 2011-11-16 21:58:02 +0000 | [diff] [blame] | 2168 | |
| 2169 | if (priv->phydev) |
| 2170 | phy_start(priv->phydev); |
| 2171 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2172 | return 0; |
| 2173 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2174 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2175 | int stmmac_freeze(struct net_device *ndev) |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 2176 | { |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 2177 | if (!ndev || !netif_running(ndev)) |
| 2178 | return 0; |
| 2179 | |
| 2180 | return stmmac_release(ndev); |
| 2181 | } |
| 2182 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 2183 | int stmmac_restore(struct net_device *ndev) |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 2184 | { |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 2185 | if (!ndev || !netif_running(ndev)) |
| 2186 | return 0; |
| 2187 | |
| 2188 | return stmmac_open(ndev); |
| 2189 | } |
Giuseppe CAVALLARO | 874bd42 | 2010-11-24 02:38:11 +0000 | [diff] [blame] | 2190 | #endif /* CONFIG_PM */ |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2191 | |
Giuseppe CAVALLARO | 33d5e33 | 2012-06-07 19:25:07 +0000 | [diff] [blame] | 2192 | /* Driver can be configured w/ and w/ both PCI and Platf drivers |
| 2193 | * depending on the configuration selected. |
| 2194 | */ |
Giuseppe CAVALLARO | ba27ec6 | 2012-06-04 19:22:57 +0000 | [diff] [blame] | 2195 | static int __init stmmac_init(void) |
| 2196 | { |
Konstantin Khlebnikov | 493682b | 2012-12-14 01:02:51 +0000 | [diff] [blame] | 2197 | int ret; |
Giuseppe CAVALLARO | ba27ec6 | 2012-06-04 19:22:57 +0000 | [diff] [blame] | 2198 | |
Konstantin Khlebnikov | 493682b | 2012-12-14 01:02:51 +0000 | [diff] [blame] | 2199 | ret = stmmac_register_platform(); |
| 2200 | if (ret) |
| 2201 | goto err; |
| 2202 | ret = stmmac_register_pci(); |
| 2203 | if (ret) |
| 2204 | goto err_pci; |
Giuseppe CAVALLARO | 33d5e33 | 2012-06-07 19:25:07 +0000 | [diff] [blame] | 2205 | return 0; |
Konstantin Khlebnikov | 493682b | 2012-12-14 01:02:51 +0000 | [diff] [blame] | 2206 | err_pci: |
| 2207 | stmmac_unregister_platform(); |
| 2208 | err: |
| 2209 | pr_err("stmmac: driver registration failed\n"); |
| 2210 | return ret; |
Giuseppe CAVALLARO | ba27ec6 | 2012-06-04 19:22:57 +0000 | [diff] [blame] | 2211 | } |
| 2212 | |
| 2213 | static void __exit stmmac_exit(void) |
| 2214 | { |
Giuseppe CAVALLARO | 33d5e33 | 2012-06-07 19:25:07 +0000 | [diff] [blame] | 2215 | stmmac_unregister_platform(); |
| 2216 | stmmac_unregister_pci(); |
Giuseppe CAVALLARO | ba27ec6 | 2012-06-04 19:22:57 +0000 | [diff] [blame] | 2217 | } |
| 2218 | |
| 2219 | module_init(stmmac_init); |
| 2220 | module_exit(stmmac_exit); |
| 2221 | |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2222 | #ifndef MODULE |
| 2223 | static int __init stmmac_cmdline_opt(char *str) |
| 2224 | { |
| 2225 | char *opt; |
| 2226 | |
| 2227 | if (!str || !*str) |
| 2228 | return -EINVAL; |
| 2229 | while ((opt = strsep(&str, ",")) != NULL) { |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 2230 | if (!strncmp(opt, "debug:", 6)) { |
Giuseppe CAVALLARO | ea2ab87 | 2012-06-27 21:14:35 +0000 | [diff] [blame] | 2231 | if (kstrtoint(opt + 6, 0, &debug)) |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 2232 | goto err; |
| 2233 | } else if (!strncmp(opt, "phyaddr:", 8)) { |
Giuseppe CAVALLARO | ea2ab87 | 2012-06-27 21:14:35 +0000 | [diff] [blame] | 2234 | if (kstrtoint(opt + 8, 0, &phyaddr)) |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 2235 | goto err; |
| 2236 | } else if (!strncmp(opt, "dma_txsize:", 11)) { |
Giuseppe CAVALLARO | ea2ab87 | 2012-06-27 21:14:35 +0000 | [diff] [blame] | 2237 | if (kstrtoint(opt + 11, 0, &dma_txsize)) |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 2238 | goto err; |
| 2239 | } else if (!strncmp(opt, "dma_rxsize:", 11)) { |
Giuseppe CAVALLARO | ea2ab87 | 2012-06-27 21:14:35 +0000 | [diff] [blame] | 2240 | if (kstrtoint(opt + 11, 0, &dma_rxsize)) |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 2241 | goto err; |
| 2242 | } else if (!strncmp(opt, "buf_sz:", 7)) { |
Giuseppe CAVALLARO | ea2ab87 | 2012-06-27 21:14:35 +0000 | [diff] [blame] | 2243 | if (kstrtoint(opt + 7, 0, &buf_sz)) |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 2244 | goto err; |
| 2245 | } else if (!strncmp(opt, "tc:", 3)) { |
Giuseppe CAVALLARO | ea2ab87 | 2012-06-27 21:14:35 +0000 | [diff] [blame] | 2246 | if (kstrtoint(opt + 3, 0, &tc)) |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 2247 | goto err; |
| 2248 | } else if (!strncmp(opt, "watchdog:", 9)) { |
Giuseppe CAVALLARO | ea2ab87 | 2012-06-27 21:14:35 +0000 | [diff] [blame] | 2249 | if (kstrtoint(opt + 9, 0, &watchdog)) |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 2250 | goto err; |
| 2251 | } else if (!strncmp(opt, "flow_ctrl:", 10)) { |
Giuseppe CAVALLARO | ea2ab87 | 2012-06-27 21:14:35 +0000 | [diff] [blame] | 2252 | if (kstrtoint(opt + 10, 0, &flow_ctrl)) |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 2253 | goto err; |
| 2254 | } else if (!strncmp(opt, "pause:", 6)) { |
Giuseppe CAVALLARO | ea2ab87 | 2012-06-27 21:14:35 +0000 | [diff] [blame] | 2255 | if (kstrtoint(opt + 6, 0, &pause)) |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 2256 | goto err; |
Giuseppe CAVALLARO | 506f669 | 2013-02-14 23:00:13 +0000 | [diff] [blame^] | 2257 | } else if (!strncmp(opt, "eee_timer:", 10)) { |
Giuseppe CAVALLARO | d765955 | 2012-06-27 21:14:37 +0000 | [diff] [blame] | 2258 | if (kstrtoint(opt + 10, 0, &eee_timer)) |
| 2259 | goto err; |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 2260 | } |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2261 | } |
| 2262 | return 0; |
Giuseppe CAVALLARO | f3240e2 | 2011-07-20 00:05:22 +0000 | [diff] [blame] | 2263 | |
| 2264 | err: |
| 2265 | pr_err("%s: ERROR broken module parameter conversion", __func__); |
| 2266 | return -EINVAL; |
Giuseppe Cavallaro | 47dd7a5 | 2009-10-14 15:13:45 -0700 | [diff] [blame] | 2267 | } |
| 2268 | |
| 2269 | __setup("stmmaceth=", stmmac_cmdline_opt); |
| 2270 | #endif |
Giuseppe Cavallaro | 6fc0d0f | 2011-12-23 14:21:20 -0500 | [diff] [blame] | 2271 | |
| 2272 | MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet device driver"); |
| 2273 | MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>"); |
| 2274 | MODULE_LICENSE("GPL"); |