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