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