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