aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/stmicro
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2014-09-08 00:41:53 -0400
committerDavid S. Miller <davem@davemloft.net>2014-09-08 00:41:53 -0400
commiteb84d6b60491a3ca3d90d62ee5346b007770d40d (patch)
tree22aadf9ada15e1ae5ba4c400aafab6f2541996e6 /drivers/net/ethernet/stmicro
parent97a13e5289baa96eaddd06e61d277457d837af3a (diff)
parentd030671f3f261e528dc6e396a13f10859a74ae7c (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
Diffstat (limited to 'drivers/net/ethernet/stmicro')
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/chain_mode.c14
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/common.h13
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/dwmac1000.h2
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c6
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/mmc.h2
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/mmc_core.c2
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/ring_mode.c15
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac.h9
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c2
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_main.c142
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c1
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h2
12 files changed, 152 insertions, 58 deletions
diff --git a/drivers/net/ethernet/stmicro/stmmac/chain_mode.c b/drivers/net/ethernet/stmicro/stmmac/chain_mode.c
index c553f6b5a913..cf28daba4346 100644
--- a/drivers/net/ethernet/stmicro/stmmac/chain_mode.c
+++ b/drivers/net/ethernet/stmicro/stmmac/chain_mode.c
@@ -28,7 +28,7 @@
28 28
29#include "stmmac.h" 29#include "stmmac.h"
30 30
31static unsigned int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum) 31static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
32{ 32{
33 struct stmmac_priv *priv = (struct stmmac_priv *)p; 33 struct stmmac_priv *priv = (struct stmmac_priv *)p;
34 unsigned int txsize = priv->dma_tx_size; 34 unsigned int txsize = priv->dma_tx_size;
@@ -47,7 +47,9 @@ static unsigned int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
47 47
48 desc->des2 = dma_map_single(priv->device, skb->data, 48 desc->des2 = dma_map_single(priv->device, skb->data,
49 bmax, DMA_TO_DEVICE); 49 bmax, DMA_TO_DEVICE);
50 priv->tx_skbuff_dma[entry] = desc->des2; 50 if (dma_mapping_error(priv->device, desc->des2))
51 return -1;
52 priv->tx_skbuff_dma[entry].buf = desc->des2;
51 priv->hw->desc->prepare_tx_desc(desc, 1, bmax, csum, STMMAC_CHAIN_MODE); 53 priv->hw->desc->prepare_tx_desc(desc, 1, bmax, csum, STMMAC_CHAIN_MODE);
52 54
53 while (len != 0) { 55 while (len != 0) {
@@ -59,7 +61,9 @@ static unsigned int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
59 desc->des2 = dma_map_single(priv->device, 61 desc->des2 = dma_map_single(priv->device,
60 (skb->data + bmax * i), 62 (skb->data + bmax * i),
61 bmax, DMA_TO_DEVICE); 63 bmax, DMA_TO_DEVICE);
62 priv->tx_skbuff_dma[entry] = desc->des2; 64 if (dma_mapping_error(priv->device, desc->des2))
65 return -1;
66 priv->tx_skbuff_dma[entry].buf = desc->des2;
63 priv->hw->desc->prepare_tx_desc(desc, 0, bmax, csum, 67 priv->hw->desc->prepare_tx_desc(desc, 0, bmax, csum,
64 STMMAC_CHAIN_MODE); 68 STMMAC_CHAIN_MODE);
65 priv->hw->desc->set_tx_owner(desc); 69 priv->hw->desc->set_tx_owner(desc);
@@ -69,7 +73,9 @@ static unsigned int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
69 desc->des2 = dma_map_single(priv->device, 73 desc->des2 = dma_map_single(priv->device,
70 (skb->data + bmax * i), len, 74 (skb->data + bmax * i), len,
71 DMA_TO_DEVICE); 75 DMA_TO_DEVICE);
72 priv->tx_skbuff_dma[entry] = desc->des2; 76 if (dma_mapping_error(priv->device, desc->des2))
77 return -1;
78 priv->tx_skbuff_dma[entry].buf = desc->des2;
73 priv->hw->desc->prepare_tx_desc(desc, 0, len, csum, 79 priv->hw->desc->prepare_tx_desc(desc, 0, len, csum,
74 STMMAC_CHAIN_MODE); 80 STMMAC_CHAIN_MODE);
75 priv->hw->desc->set_tx_owner(desc); 81 priv->hw->desc->set_tx_owner(desc);
diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h
index de507c32036c..593e6c4144a7 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -220,10 +220,10 @@ enum dma_irq_status {
220 handle_tx = 0x8, 220 handle_tx = 0x8,
221}; 221};
222 222
223#define CORE_IRQ_TX_PATH_IN_LPI_MODE (1 << 1) 223#define CORE_IRQ_TX_PATH_IN_LPI_MODE (1 << 0)
224#define CORE_IRQ_TX_PATH_EXIT_LPI_MODE (1 << 2) 224#define CORE_IRQ_TX_PATH_EXIT_LPI_MODE (1 << 1)
225#define CORE_IRQ_RX_PATH_IN_LPI_MODE (1 << 3) 225#define CORE_IRQ_RX_PATH_IN_LPI_MODE (1 << 2)
226#define CORE_IRQ_RX_PATH_EXIT_LPI_MODE (1 << 4) 226#define CORE_IRQ_RX_PATH_EXIT_LPI_MODE (1 << 3)
227 227
228#define CORE_PCS_ANE_COMPLETE (1 << 5) 228#define CORE_PCS_ANE_COMPLETE (1 << 5)
229#define CORE_PCS_LINK_STATUS (1 << 6) 229#define CORE_PCS_LINK_STATUS (1 << 6)
@@ -287,7 +287,7 @@ struct dma_features {
287 287
288/* Default LPI timers */ 288/* Default LPI timers */
289#define STMMAC_DEFAULT_LIT_LS 0x3E8 289#define STMMAC_DEFAULT_LIT_LS 0x3E8
290#define STMMAC_DEFAULT_TWT_LS 0x0 290#define STMMAC_DEFAULT_TWT_LS 0x1E
291 291
292#define STMMAC_CHAIN_MODE 0x1 292#define STMMAC_CHAIN_MODE 0x1
293#define STMMAC_RING_MODE 0x2 293#define STMMAC_RING_MODE 0x2
@@ -425,7 +425,7 @@ struct stmmac_mode_ops {
425 void (*init) (void *des, dma_addr_t phy_addr, unsigned int size, 425 void (*init) (void *des, dma_addr_t phy_addr, unsigned int size,
426 unsigned int extend_desc); 426 unsigned int extend_desc);
427 unsigned int (*is_jumbo_frm) (int len, int ehn_desc); 427 unsigned int (*is_jumbo_frm) (int len, int ehn_desc);
428 unsigned int (*jumbo_frm) (void *priv, struct sk_buff *skb, int csum); 428 int (*jumbo_frm)(void *priv, struct sk_buff *skb, int csum);
429 int (*set_16kib_bfsize)(int mtu); 429 int (*set_16kib_bfsize)(int mtu);
430 void (*init_desc3)(struct dma_desc *p); 430 void (*init_desc3)(struct dma_desc *p);
431 void (*refill_desc3) (void *priv, struct dma_desc *p); 431 void (*refill_desc3) (void *priv, struct dma_desc *p);
@@ -445,6 +445,7 @@ struct mac_device_info {
445 int multicast_filter_bins; 445 int multicast_filter_bins;
446 int unicast_filter_entries; 446 int unicast_filter_entries;
447 int mcast_bits_log2; 447 int mcast_bits_log2;
448 unsigned int rx_csum;
448}; 449};
449 450
450struct mac_device_info *dwmac1000_setup(void __iomem *ioaddr, int mcbins, 451struct mac_device_info *dwmac1000_setup(void __iomem *ioaddr, int mcbins,
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h b/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h
index 71b5419256c1..64d8f56a9c17 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h
@@ -153,7 +153,7 @@ enum inter_frame_gap {
153#define GMAC_CONTROL_RE 0x00000004 /* Receiver Enable */ 153#define GMAC_CONTROL_RE 0x00000004 /* Receiver Enable */
154 154
155#define GMAC_CORE_INIT (GMAC_CONTROL_JD | GMAC_CONTROL_PS | GMAC_CONTROL_ACS | \ 155#define GMAC_CORE_INIT (GMAC_CONTROL_JD | GMAC_CONTROL_PS | GMAC_CONTROL_ACS | \
156 GMAC_CONTROL_BE) 156 GMAC_CONTROL_BE | GMAC_CONTROL_DCRS)
157 157
158/* GMAC Frame Filter defines */ 158/* GMAC Frame Filter defines */
159#define GMAC_FRAME_FILTER_PR 0x00000001 /* Promiscuous Mode */ 159#define GMAC_FRAME_FILTER_PR 0x00000001 /* Promiscuous Mode */
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
index d8ef18786a1c..5efe60ea6526 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
@@ -58,7 +58,11 @@ static int dwmac1000_rx_ipc_enable(struct mac_device_info *hw)
58 void __iomem *ioaddr = hw->pcsr; 58 void __iomem *ioaddr = hw->pcsr;
59 u32 value = readl(ioaddr + GMAC_CONTROL); 59 u32 value = readl(ioaddr + GMAC_CONTROL);
60 60
61 value |= GMAC_CONTROL_IPC; 61 if (hw->rx_csum)
62 value |= GMAC_CONTROL_IPC;
63 else
64 value &= ~GMAC_CONTROL_IPC;
65
62 writel(value, ioaddr + GMAC_CONTROL); 66 writel(value, ioaddr + GMAC_CONTROL);
63 67
64 value = readl(ioaddr + GMAC_CONTROL); 68 value = readl(ioaddr + GMAC_CONTROL);
diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc.h b/drivers/net/ethernet/stmicro/stmmac/mmc.h
index 8607488cbcfc..192c2491330b 100644
--- a/drivers/net/ethernet/stmicro/stmmac/mmc.h
+++ b/drivers/net/ethernet/stmicro/stmmac/mmc.h
@@ -68,7 +68,7 @@ struct stmmac_counters {
68 unsigned int mmc_rx_octetcount_g; 68 unsigned int mmc_rx_octetcount_g;
69 unsigned int mmc_rx_broadcastframe_g; 69 unsigned int mmc_rx_broadcastframe_g;
70 unsigned int mmc_rx_multicastframe_g; 70 unsigned int mmc_rx_multicastframe_g;
71 unsigned int mmc_rx_crc_errror; 71 unsigned int mmc_rx_crc_error;
72 unsigned int mmc_rx_align_error; 72 unsigned int mmc_rx_align_error;
73 unsigned int mmc_rx_run_error; 73 unsigned int mmc_rx_run_error;
74 unsigned int mmc_rx_jabber_error; 74 unsigned int mmc_rx_jabber_error;
diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
index 50617c5a0bdb..08c483bd2ec7 100644
--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
@@ -196,7 +196,7 @@ void dwmac_mmc_read(void __iomem *ioaddr, struct stmmac_counters *mmc)
196 mmc->mmc_rx_octetcount_g += readl(ioaddr + MMC_RX_OCTETCOUNT_G); 196 mmc->mmc_rx_octetcount_g += readl(ioaddr + MMC_RX_OCTETCOUNT_G);
197 mmc->mmc_rx_broadcastframe_g += readl(ioaddr + MMC_RX_BROADCASTFRAME_G); 197 mmc->mmc_rx_broadcastframe_g += readl(ioaddr + MMC_RX_BROADCASTFRAME_G);
198 mmc->mmc_rx_multicastframe_g += readl(ioaddr + MMC_RX_MULTICASTFRAME_G); 198 mmc->mmc_rx_multicastframe_g += readl(ioaddr + MMC_RX_MULTICASTFRAME_G);
199 mmc->mmc_rx_crc_errror += readl(ioaddr + MMC_RX_CRC_ERRROR); 199 mmc->mmc_rx_crc_error += readl(ioaddr + MMC_RX_CRC_ERRROR);
200 mmc->mmc_rx_align_error += readl(ioaddr + MMC_RX_ALIGN_ERROR); 200 mmc->mmc_rx_align_error += readl(ioaddr + MMC_RX_ALIGN_ERROR);
201 mmc->mmc_rx_run_error += readl(ioaddr + MMC_RX_RUN_ERROR); 201 mmc->mmc_rx_run_error += readl(ioaddr + MMC_RX_RUN_ERROR);
202 mmc->mmc_rx_jabber_error += readl(ioaddr + MMC_RX_JABBER_ERROR); 202 mmc->mmc_rx_jabber_error += readl(ioaddr + MMC_RX_JABBER_ERROR);
diff --git a/drivers/net/ethernet/stmicro/stmmac/ring_mode.c b/drivers/net/ethernet/stmicro/stmmac/ring_mode.c
index 650a4be6bce5..5dd50c6cda5b 100644
--- a/drivers/net/ethernet/stmicro/stmmac/ring_mode.c
+++ b/drivers/net/ethernet/stmicro/stmmac/ring_mode.c
@@ -28,7 +28,7 @@
28 28
29#include "stmmac.h" 29#include "stmmac.h"
30 30
31static unsigned int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum) 31static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
32{ 32{
33 struct stmmac_priv *priv = (struct stmmac_priv *)p; 33 struct stmmac_priv *priv = (struct stmmac_priv *)p;
34 unsigned int txsize = priv->dma_tx_size; 34 unsigned int txsize = priv->dma_tx_size;
@@ -53,7 +53,10 @@ static unsigned int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
53 53
54 desc->des2 = dma_map_single(priv->device, skb->data, 54 desc->des2 = dma_map_single(priv->device, skb->data,
55 bmax, DMA_TO_DEVICE); 55 bmax, DMA_TO_DEVICE);
56 priv->tx_skbuff_dma[entry] = desc->des2; 56 if (dma_mapping_error(priv->device, desc->des2))
57 return -1;
58
59 priv->tx_skbuff_dma[entry].buf = desc->des2;
57 desc->des3 = desc->des2 + BUF_SIZE_4KiB; 60 desc->des3 = desc->des2 + BUF_SIZE_4KiB;
58 priv->hw->desc->prepare_tx_desc(desc, 1, bmax, csum, 61 priv->hw->desc->prepare_tx_desc(desc, 1, bmax, csum,
59 STMMAC_RING_MODE); 62 STMMAC_RING_MODE);
@@ -68,7 +71,9 @@ static unsigned int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
68 71
69 desc->des2 = dma_map_single(priv->device, skb->data + bmax, 72 desc->des2 = dma_map_single(priv->device, skb->data + bmax,
70 len, DMA_TO_DEVICE); 73 len, DMA_TO_DEVICE);
71 priv->tx_skbuff_dma[entry] = desc->des2; 74 if (dma_mapping_error(priv->device, desc->des2))
75 return -1;
76 priv->tx_skbuff_dma[entry].buf = desc->des2;
72 desc->des3 = desc->des2 + BUF_SIZE_4KiB; 77 desc->des3 = desc->des2 + BUF_SIZE_4KiB;
73 priv->hw->desc->prepare_tx_desc(desc, 0, len, csum, 78 priv->hw->desc->prepare_tx_desc(desc, 0, len, csum,
74 STMMAC_RING_MODE); 79 STMMAC_RING_MODE);
@@ -77,7 +82,9 @@ static unsigned int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
77 } else { 82 } else {
78 desc->des2 = dma_map_single(priv->device, skb->data, 83 desc->des2 = dma_map_single(priv->device, skb->data,
79 nopaged_len, DMA_TO_DEVICE); 84 nopaged_len, DMA_TO_DEVICE);
80 priv->tx_skbuff_dma[entry] = desc->des2; 85 if (dma_mapping_error(priv->device, desc->des2))
86 return -1;
87 priv->tx_skbuff_dma[entry].buf = desc->des2;
81 desc->des3 = desc->des2 + BUF_SIZE_4KiB; 88 desc->des3 = desc->des2 + BUF_SIZE_4KiB;
82 priv->hw->desc->prepare_tx_desc(desc, 1, nopaged_len, csum, 89 priv->hw->desc->prepare_tx_desc(desc, 1, nopaged_len, csum,
83 STMMAC_RING_MODE); 90 STMMAC_RING_MODE);
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
index ca01035634a7..58097c0e2ad5 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
@@ -34,6 +34,11 @@
34#include <linux/ptp_clock_kernel.h> 34#include <linux/ptp_clock_kernel.h>
35#include <linux/reset.h> 35#include <linux/reset.h>
36 36
37struct stmmac_tx_info {
38 dma_addr_t buf;
39 bool map_as_page;
40};
41
37struct stmmac_priv { 42struct stmmac_priv {
38 /* Frequently used values are kept adjacent for cache effect */ 43 /* Frequently used values are kept adjacent for cache effect */
39 struct dma_extended_desc *dma_etx ____cacheline_aligned_in_smp; 44 struct dma_extended_desc *dma_etx ____cacheline_aligned_in_smp;
@@ -45,7 +50,7 @@ struct stmmac_priv {
45 u32 tx_count_frames; 50 u32 tx_count_frames;
46 u32 tx_coal_frames; 51 u32 tx_coal_frames;
47 u32 tx_coal_timer; 52 u32 tx_coal_timer;
48 dma_addr_t *tx_skbuff_dma; 53 struct stmmac_tx_info *tx_skbuff_dma;
49 dma_addr_t dma_tx_phy; 54 dma_addr_t dma_tx_phy;
50 int tx_coalesce; 55 int tx_coalesce;
51 int hwts_tx_en; 56 int hwts_tx_en;
@@ -105,6 +110,8 @@ struct stmmac_priv {
105 struct ptp_clock *ptp_clock; 110 struct ptp_clock *ptp_clock;
106 struct ptp_clock_info ptp_clock_ops; 111 struct ptp_clock_info ptp_clock_ops;
107 unsigned int default_addend; 112 unsigned int default_addend;
113 struct clk *clk_ptp_ref;
114 unsigned int clk_ptp_rate;
108 u32 adv_ts; 115 u32 adv_ts;
109 int use_riwt; 116 int use_riwt;
110 int irq_wake; 117 int irq_wake;
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
index 493fe693e675..3a08a1f78c73 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
@@ -175,7 +175,7 @@ static const struct stmmac_stats stmmac_mmc[] = {
175 STMMAC_MMC_STAT(mmc_rx_octetcount_g), 175 STMMAC_MMC_STAT(mmc_rx_octetcount_g),
176 STMMAC_MMC_STAT(mmc_rx_broadcastframe_g), 176 STMMAC_MMC_STAT(mmc_rx_broadcastframe_g),
177 STMMAC_MMC_STAT(mmc_rx_multicastframe_g), 177 STMMAC_MMC_STAT(mmc_rx_multicastframe_g),
178 STMMAC_MMC_STAT(mmc_rx_crc_errror), 178 STMMAC_MMC_STAT(mmc_rx_crc_error),
179 STMMAC_MMC_STAT(mmc_rx_align_error), 179 STMMAC_MMC_STAT(mmc_rx_align_error),
180 STMMAC_MMC_STAT(mmc_rx_run_error), 180 STMMAC_MMC_STAT(mmc_rx_run_error),
181 STMMAC_MMC_STAT(mmc_rx_jabber_error), 181 STMMAC_MMC_STAT(mmc_rx_jabber_error),
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 8fcc64c37ff1..9dbb02d9d9c2 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -275,6 +275,7 @@ static void stmmac_eee_ctrl_timer(unsigned long arg)
275 */ 275 */
276bool stmmac_eee_init(struct stmmac_priv *priv) 276bool stmmac_eee_init(struct stmmac_priv *priv)
277{ 277{
278 char *phy_bus_name = priv->plat->phy_bus_name;
278 bool ret = false; 279 bool ret = false;
279 280
280 /* Using PCS we cannot dial with the phy registers at this stage 281 /* Using PCS we cannot dial with the phy registers at this stage
@@ -284,6 +285,10 @@ bool stmmac_eee_init(struct stmmac_priv *priv)
284 (priv->pcs == STMMAC_PCS_RTBI)) 285 (priv->pcs == STMMAC_PCS_RTBI))
285 goto out; 286 goto out;
286 287
288 /* Never init EEE in case of a switch is attached */
289 if (phy_bus_name && (!strcmp(phy_bus_name, "fixed")))
290 goto out;
291
287 /* MAC core supports the EEE feature. */ 292 /* MAC core supports the EEE feature. */
288 if (priv->dma_cap.eee) { 293 if (priv->dma_cap.eee) {
289 int tx_lpi_timer = priv->tx_lpi_timer; 294 int tx_lpi_timer = priv->tx_lpi_timer;
@@ -316,10 +321,9 @@ bool stmmac_eee_init(struct stmmac_priv *priv)
316 priv->hw->mac->set_eee_timer(priv->hw, 321 priv->hw->mac->set_eee_timer(priv->hw,
317 STMMAC_DEFAULT_LIT_LS, 322 STMMAC_DEFAULT_LIT_LS,
318 tx_lpi_timer); 323 tx_lpi_timer);
319 } else 324 }
320 /* Set HW EEE according to the speed */ 325 /* Set HW EEE according to the speed */
321 priv->hw->mac->set_eee_pls(priv->hw, 326 priv->hw->mac->set_eee_pls(priv->hw, priv->phydev->link);
322 priv->phydev->link);
323 327
324 pr_debug("stmmac: Energy-Efficient Ethernet initialized\n"); 328 pr_debug("stmmac: Energy-Efficient Ethernet initialized\n");
325 329
@@ -603,16 +607,16 @@ static int stmmac_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
603 /* calculate default added value: 607 /* calculate default added value:
604 * formula is : 608 * formula is :
605 * addend = (2^32)/freq_div_ratio; 609 * addend = (2^32)/freq_div_ratio;
606 * where, freq_div_ratio = STMMAC_SYSCLOCK/50MHz 610 * where, freq_div_ratio = clk_ptp_ref_i/50MHz
607 * hence, addend = ((2^32) * 50MHz)/STMMAC_SYSCLOCK; 611 * hence, addend = ((2^32) * 50MHz)/clk_ptp_ref_i;
608 * NOTE: STMMAC_SYSCLOCK should be >= 50MHz to 612 * NOTE: clk_ptp_ref_i should be >= 50MHz to
609 * achive 20ns accuracy. 613 * achive 20ns accuracy.
610 * 614 *
611 * 2^x * y == (y << x), hence 615 * 2^x * y == (y << x), hence
612 * 2^32 * 50000000 ==> (50000000 << 32) 616 * 2^32 * 50000000 ==> (50000000 << 32)
613 */ 617 */
614 temp = (u64) (50000000ULL << 32); 618 temp = (u64) (50000000ULL << 32);
615 priv->default_addend = div_u64(temp, STMMAC_SYSCLOCK); 619 priv->default_addend = div_u64(temp, priv->clk_ptp_rate);
616 priv->hw->ptp->config_addend(priv->ioaddr, 620 priv->hw->ptp->config_addend(priv->ioaddr,
617 priv->default_addend); 621 priv->default_addend);
618 622
@@ -638,6 +642,16 @@ static int stmmac_init_ptp(struct stmmac_priv *priv)
638 if (!(priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp)) 642 if (!(priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp))
639 return -EOPNOTSUPP; 643 return -EOPNOTSUPP;
640 644
645 /* Fall-back to main clock in case of no PTP ref is passed */
646 priv->clk_ptp_ref = devm_clk_get(priv->device, "clk_ptp_ref");
647 if (IS_ERR(priv->clk_ptp_ref)) {
648 priv->clk_ptp_rate = clk_get_rate(priv->stmmac_clk);
649 priv->clk_ptp_ref = NULL;
650 } else {
651 clk_prepare_enable(priv->clk_ptp_ref);
652 priv->clk_ptp_rate = clk_get_rate(priv->clk_ptp_ref);
653 }
654
641 priv->adv_ts = 0; 655 priv->adv_ts = 0;
642 if (priv->dma_cap.atime_stamp && priv->extend_desc) 656 if (priv->dma_cap.atime_stamp && priv->extend_desc)
643 priv->adv_ts = 1; 657 priv->adv_ts = 1;
@@ -657,6 +671,8 @@ static int stmmac_init_ptp(struct stmmac_priv *priv)
657 671
658static void stmmac_release_ptp(struct stmmac_priv *priv) 672static void stmmac_release_ptp(struct stmmac_priv *priv)
659{ 673{
674 if (priv->clk_ptp_ref)
675 clk_disable_unprepare(priv->clk_ptp_ref);
660 stmmac_ptp_unregister(priv); 676 stmmac_ptp_unregister(priv);
661} 677}
662 678
@@ -1061,7 +1077,8 @@ static int init_dma_desc_rings(struct net_device *dev)
1061 else 1077 else
1062 p = priv->dma_tx + i; 1078 p = priv->dma_tx + i;
1063 p->des2 = 0; 1079 p->des2 = 0;
1064 priv->tx_skbuff_dma[i] = 0; 1080 priv->tx_skbuff_dma[i].buf = 0;
1081 priv->tx_skbuff_dma[i].map_as_page = false;
1065 priv->tx_skbuff[i] = NULL; 1082 priv->tx_skbuff[i] = NULL;
1066 } 1083 }
1067 1084
@@ -1100,17 +1117,24 @@ static void dma_free_tx_skbufs(struct stmmac_priv *priv)
1100 else 1117 else
1101 p = priv->dma_tx + i; 1118 p = priv->dma_tx + i;
1102 1119
1103 if (priv->tx_skbuff_dma[i]) { 1120 if (priv->tx_skbuff_dma[i].buf) {
1104 dma_unmap_single(priv->device, 1121 if (priv->tx_skbuff_dma[i].map_as_page)
1105 priv->tx_skbuff_dma[i], 1122 dma_unmap_page(priv->device,
1106 priv->hw->desc->get_tx_len(p), 1123 priv->tx_skbuff_dma[i].buf,
1107 DMA_TO_DEVICE); 1124 priv->hw->desc->get_tx_len(p),
1108 priv->tx_skbuff_dma[i] = 0; 1125 DMA_TO_DEVICE);
1126 else
1127 dma_unmap_single(priv->device,
1128 priv->tx_skbuff_dma[i].buf,
1129 priv->hw->desc->get_tx_len(p),
1130 DMA_TO_DEVICE);
1109 } 1131 }
1110 1132
1111 if (priv->tx_skbuff[i] != NULL) { 1133 if (priv->tx_skbuff[i] != NULL) {
1112 dev_kfree_skb_any(priv->tx_skbuff[i]); 1134 dev_kfree_skb_any(priv->tx_skbuff[i]);
1113 priv->tx_skbuff[i] = NULL; 1135 priv->tx_skbuff[i] = NULL;
1136 priv->tx_skbuff_dma[i].buf = 0;
1137 priv->tx_skbuff_dma[i].map_as_page = false;
1114 } 1138 }
1115 } 1139 }
1116} 1140}
@@ -1131,7 +1155,8 @@ static int alloc_dma_desc_resources(struct stmmac_priv *priv)
1131 if (!priv->rx_skbuff) 1155 if (!priv->rx_skbuff)
1132 goto err_rx_skbuff; 1156 goto err_rx_skbuff;
1133 1157
1134 priv->tx_skbuff_dma = kmalloc_array(txsize, sizeof(dma_addr_t), 1158 priv->tx_skbuff_dma = kmalloc_array(txsize,
1159 sizeof(*priv->tx_skbuff_dma),
1135 GFP_KERNEL); 1160 GFP_KERNEL);
1136 if (!priv->tx_skbuff_dma) 1161 if (!priv->tx_skbuff_dma)
1137 goto err_tx_skbuff_dma; 1162 goto err_tx_skbuff_dma;
@@ -1293,12 +1318,19 @@ static void stmmac_tx_clean(struct stmmac_priv *priv)
1293 pr_debug("%s: curr %d, dirty %d\n", __func__, 1318 pr_debug("%s: curr %d, dirty %d\n", __func__,
1294 priv->cur_tx, priv->dirty_tx); 1319 priv->cur_tx, priv->dirty_tx);
1295 1320
1296 if (likely(priv->tx_skbuff_dma[entry])) { 1321 if (likely(priv->tx_skbuff_dma[entry].buf)) {
1297 dma_unmap_single(priv->device, 1322 if (priv->tx_skbuff_dma[entry].map_as_page)
1298 priv->tx_skbuff_dma[entry], 1323 dma_unmap_page(priv->device,
1299 priv->hw->desc->get_tx_len(p), 1324 priv->tx_skbuff_dma[entry].buf,
1300 DMA_TO_DEVICE); 1325 priv->hw->desc->get_tx_len(p),
1301 priv->tx_skbuff_dma[entry] = 0; 1326 DMA_TO_DEVICE);
1327 else
1328 dma_unmap_single(priv->device,
1329 priv->tx_skbuff_dma[entry].buf,
1330 priv->hw->desc->get_tx_len(p),
1331 DMA_TO_DEVICE);
1332 priv->tx_skbuff_dma[entry].buf = 0;
1333 priv->tx_skbuff_dma[entry].map_as_page = false;
1302 } 1334 }
1303 priv->hw->mode->clean_desc3(priv, p); 1335 priv->hw->mode->clean_desc3(priv, p);
1304 1336
@@ -1637,6 +1669,13 @@ static int stmmac_hw_setup(struct net_device *dev)
1637 /* Initialize the MAC Core */ 1669 /* Initialize the MAC Core */
1638 priv->hw->mac->core_init(priv->hw, dev->mtu); 1670 priv->hw->mac->core_init(priv->hw, dev->mtu);
1639 1671
1672 ret = priv->hw->mac->rx_ipc(priv->hw);
1673 if (!ret) {
1674 pr_warn(" RX IPC Checksum Offload disabled\n");
1675 priv->plat->rx_coe = STMMAC_RX_COE_NONE;
1676 priv->hw->rx_csum = 0;
1677 }
1678
1640 /* Enable the MAC Rx/Tx */ 1679 /* Enable the MAC Rx/Tx */
1641 stmmac_set_mac(priv->ioaddr, true); 1680 stmmac_set_mac(priv->ioaddr, true);
1642 1681
@@ -1887,12 +1926,16 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
1887 if (likely(!is_jumbo)) { 1926 if (likely(!is_jumbo)) {
1888 desc->des2 = dma_map_single(priv->device, skb->data, 1927 desc->des2 = dma_map_single(priv->device, skb->data,
1889 nopaged_len, DMA_TO_DEVICE); 1928 nopaged_len, DMA_TO_DEVICE);
1890 priv->tx_skbuff_dma[entry] = desc->des2; 1929 if (dma_mapping_error(priv->device, desc->des2))
1930 goto dma_map_err;
1931 priv->tx_skbuff_dma[entry].buf = desc->des2;
1891 priv->hw->desc->prepare_tx_desc(desc, 1, nopaged_len, 1932 priv->hw->desc->prepare_tx_desc(desc, 1, nopaged_len,
1892 csum_insertion, priv->mode); 1933 csum_insertion, priv->mode);
1893 } else { 1934 } else {
1894 desc = first; 1935 desc = first;
1895 entry = priv->hw->mode->jumbo_frm(priv, skb, csum_insertion); 1936 entry = priv->hw->mode->jumbo_frm(priv, skb, csum_insertion);
1937 if (unlikely(entry < 0))
1938 goto dma_map_err;
1896 } 1939 }
1897 1940
1898 for (i = 0; i < nfrags; i++) { 1941 for (i = 0; i < nfrags; i++) {
@@ -1908,7 +1951,11 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
1908 1951
1909 desc->des2 = skb_frag_dma_map(priv->device, frag, 0, len, 1952 desc->des2 = skb_frag_dma_map(priv->device, frag, 0, len,
1910 DMA_TO_DEVICE); 1953 DMA_TO_DEVICE);
1911 priv->tx_skbuff_dma[entry] = desc->des2; 1954 if (dma_mapping_error(priv->device, desc->des2))
1955 goto dma_map_err; /* should reuse desc w/o issues */
1956
1957 priv->tx_skbuff_dma[entry].buf = desc->des2;
1958 priv->tx_skbuff_dma[entry].map_as_page = true;
1912 priv->hw->desc->prepare_tx_desc(desc, 0, len, csum_insertion, 1959 priv->hw->desc->prepare_tx_desc(desc, 0, len, csum_insertion,
1913 priv->mode); 1960 priv->mode);
1914 wmb(); 1961 wmb();
@@ -1975,7 +2022,12 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
1975 priv->hw->dma->enable_dma_transmission(priv->ioaddr); 2022 priv->hw->dma->enable_dma_transmission(priv->ioaddr);
1976 2023
1977 spin_unlock(&priv->tx_lock); 2024 spin_unlock(&priv->tx_lock);
2025 return NETDEV_TX_OK;
1978 2026
2027dma_map_err:
2028 dev_err(priv->device, "Tx dma map failed\n");
2029 dev_kfree_skb(skb);
2030 priv->dev->stats.tx_dropped++;
1979 return NETDEV_TX_OK; 2031 return NETDEV_TX_OK;
1980} 2032}
1981 2033
@@ -2028,7 +2080,12 @@ static inline void stmmac_rx_refill(struct stmmac_priv *priv)
2028 priv->rx_skbuff_dma[entry] = 2080 priv->rx_skbuff_dma[entry] =
2029 dma_map_single(priv->device, skb->data, bfsize, 2081 dma_map_single(priv->device, skb->data, bfsize,
2030 DMA_FROM_DEVICE); 2082 DMA_FROM_DEVICE);
2031 2083 if (dma_mapping_error(priv->device,
2084 priv->rx_skbuff_dma[entry])) {
2085 dev_err(priv->device, "Rx dma map failed\n");
2086 dev_kfree_skb(skb);
2087 break;
2088 }
2032 p->des2 = priv->rx_skbuff_dma[entry]; 2089 p->des2 = priv->rx_skbuff_dma[entry];
2033 2090
2034 priv->hw->mode->refill_desc3(priv, p); 2091 priv->hw->mode->refill_desc3(priv, p);
@@ -2055,7 +2112,7 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit)
2055 unsigned int entry = priv->cur_rx % rxsize; 2112 unsigned int entry = priv->cur_rx % rxsize;
2056 unsigned int next_entry; 2113 unsigned int next_entry;
2057 unsigned int count = 0; 2114 unsigned int count = 0;
2058 int coe = priv->plat->rx_coe; 2115 int coe = priv->hw->rx_csum;
2059 2116
2060 if (netif_msg_rx_status(priv)) { 2117 if (netif_msg_rx_status(priv)) {
2061 pr_debug("%s: descriptor ring:\n", __func__); 2118 pr_debug("%s: descriptor ring:\n", __func__);
@@ -2276,8 +2333,7 @@ static netdev_features_t stmmac_fix_features(struct net_device *dev,
2276 2333
2277 if (priv->plat->rx_coe == STMMAC_RX_COE_NONE) 2334 if (priv->plat->rx_coe == STMMAC_RX_COE_NONE)
2278 features &= ~NETIF_F_RXCSUM; 2335 features &= ~NETIF_F_RXCSUM;
2279 else if (priv->plat->rx_coe == STMMAC_RX_COE_TYPE1) 2336
2280 features &= ~NETIF_F_IPV6_CSUM;
2281 if (!priv->plat->tx_coe) 2337 if (!priv->plat->tx_coe)
2282 features &= ~NETIF_F_ALL_CSUM; 2338 features &= ~NETIF_F_ALL_CSUM;
2283 2339
@@ -2292,6 +2348,24 @@ static netdev_features_t stmmac_fix_features(struct net_device *dev,
2292 return features; 2348 return features;
2293} 2349}
2294 2350
2351static int stmmac_set_features(struct net_device *netdev,
2352 netdev_features_t features)
2353{
2354 struct stmmac_priv *priv = netdev_priv(netdev);
2355
2356 /* Keep the COE Type in case of csum is supporting */
2357 if (features & NETIF_F_RXCSUM)
2358 priv->hw->rx_csum = priv->plat->rx_coe;
2359 else
2360 priv->hw->rx_csum = 0;
2361 /* No check needed because rx_coe has been set before and it will be
2362 * fixed in case of issue.
2363 */
2364 priv->hw->mac->rx_ipc(priv->hw);
2365
2366 return 0;
2367}
2368
2295/** 2369/**
2296 * stmmac_interrupt - main ISR 2370 * stmmac_interrupt - main ISR
2297 * @irq: interrupt number. 2371 * @irq: interrupt number.
@@ -2572,6 +2646,7 @@ static const struct net_device_ops stmmac_netdev_ops = {
2572 .ndo_stop = stmmac_release, 2646 .ndo_stop = stmmac_release,
2573 .ndo_change_mtu = stmmac_change_mtu, 2647 .ndo_change_mtu = stmmac_change_mtu,
2574 .ndo_fix_features = stmmac_fix_features, 2648 .ndo_fix_features = stmmac_fix_features,
2649 .ndo_set_features = stmmac_set_features,
2575 .ndo_set_rx_mode = stmmac_set_rx_mode, 2650 .ndo_set_rx_mode = stmmac_set_rx_mode,
2576 .ndo_tx_timeout = stmmac_tx_timeout, 2651 .ndo_tx_timeout = stmmac_tx_timeout,
2577 .ndo_do_ioctl = stmmac_ioctl, 2652 .ndo_do_ioctl = stmmac_ioctl,
@@ -2592,7 +2667,6 @@ static const struct net_device_ops stmmac_netdev_ops = {
2592 */ 2667 */
2593static int stmmac_hw_init(struct stmmac_priv *priv) 2668static int stmmac_hw_init(struct stmmac_priv *priv)
2594{ 2669{
2595 int ret;
2596 struct mac_device_info *mac; 2670 struct mac_device_info *mac;
2597 2671
2598 /* Identify the MAC HW device */ 2672 /* Identify the MAC HW device */
@@ -2649,15 +2723,11 @@ static int stmmac_hw_init(struct stmmac_priv *priv)
2649 /* To use alternate (extended) or normal descriptor structures */ 2723 /* To use alternate (extended) or normal descriptor structures */
2650 stmmac_selec_desc_mode(priv); 2724 stmmac_selec_desc_mode(priv);
2651 2725
2652 ret = priv->hw->mac->rx_ipc(priv->hw); 2726 if (priv->plat->rx_coe) {
2653 if (!ret) { 2727 priv->hw->rx_csum = priv->plat->rx_coe;
2654 pr_warn(" RX IPC Checksum Offload not configured.\n");
2655 priv->plat->rx_coe = STMMAC_RX_COE_NONE;
2656 }
2657
2658 if (priv->plat->rx_coe)
2659 pr_info(" RX Checksum Offload Engine supported (type %d)\n", 2728 pr_info(" RX Checksum Offload Engine supported (type %d)\n",
2660 priv->plat->rx_coe); 2729 priv->plat->rx_coe);
2730 }
2661 if (priv->plat->tx_coe) 2731 if (priv->plat->tx_coe)
2662 pr_info(" TX Checksum insertion supported\n"); 2732 pr_info(" TX Checksum insertion supported\n");
2663 2733
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
index b7ad3565566c..c5ee79d8a8c5 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
@@ -206,6 +206,7 @@ void stmmac_ptp_unregister(struct stmmac_priv *priv)
206{ 206{
207 if (priv->ptp_clock) { 207 if (priv->ptp_clock) {
208 ptp_clock_unregister(priv->ptp_clock); 208 ptp_clock_unregister(priv->ptp_clock);
209 priv->ptp_clock = NULL;
209 pr_debug("Removed PTP HW clock successfully on %s\n", 210 pr_debug("Removed PTP HW clock successfully on %s\n",
210 priv->dev->name); 211 priv->dev->name);
211 } 212 }
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
index 3dbc047622fa..4535df37c227 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
@@ -25,8 +25,6 @@
25#ifndef __STMMAC_PTP_H__ 25#ifndef __STMMAC_PTP_H__
26#define __STMMAC_PTP_H__ 26#define __STMMAC_PTP_H__
27 27
28#define STMMAC_SYSCLOCK 62500000
29
30/* IEEE 1588 PTP register offsets */ 28/* IEEE 1588 PTP register offsets */
31#define PTP_TCR 0x0700 /* Timestamp Control Reg */ 29#define PTP_TCR 0x0700 /* Timestamp Control Reg */
32#define PTP_SSIR 0x0704 /* Sub-Second Increment Reg */ 30#define PTP_SSIR 0x0704 /* Sub-Second Increment Reg */