aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2014-03-11 16:15:29 -0400
committerDavid S. Miller <davem@davemloft.net>2014-03-11 16:15:29 -0400
commit9d79b3c7aae582df9eebcea8797c41cd5d5fc39c (patch)
treee9fb63376f0a9993728f1e38b9fd7a9dc7a9faa8
parentd25f06ea466ea521b563b76661180b4e44714ae6 (diff)
parentc5e9103dc397114523c65bd24ff0548bcdca54b4 (diff)
Merge branch 'stmmac'
Giuseppe Cavallaro says: ==================== stmmac fixes: EEE and chained mode These patches are to fix some new problems in the STMMAC driver. Mandatory changes are for EEE that needs to be disabled if not supported and for the chain mode that is broken and the kernel panics if this mode is enabled. v3: removed a patch from my previous set that touched the stmmac_tx path that has not to be applied. Other patches for cleaning-up will be sent on top of net-next git repo. v4: do not surround the defaul buffer selection using Koption and adopt a default to 1536bytes. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/chain_mode.c2
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/common.h20
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/ring_mode.c9
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_main.c91
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c2
5 files changed, 60 insertions, 64 deletions
diff --git a/drivers/net/ethernet/stmicro/stmmac/chain_mode.c b/drivers/net/ethernet/stmicro/stmmac/chain_mode.c
index 72d282bf33a5..c553f6b5a913 100644
--- a/drivers/net/ethernet/stmicro/stmmac/chain_mode.c
+++ b/drivers/net/ethernet/stmicro/stmmac/chain_mode.c
@@ -151,7 +151,7 @@ static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p)
151 sizeof(struct dma_desc))); 151 sizeof(struct dma_desc)));
152} 152}
153 153
154const struct stmmac_chain_mode_ops chain_mode_ops = { 154const struct stmmac_mode_ops chain_mode_ops = {
155 .init = stmmac_init_dma_chain, 155 .init = stmmac_init_dma_chain,
156 .is_jumbo_frm = stmmac_is_jumbo_frm, 156 .is_jumbo_frm = stmmac_is_jumbo_frm,
157 .jumbo_frm = stmmac_jumbo_frm, 157 .jumbo_frm = stmmac_jumbo_frm,
diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h
index 7834a3993946..74610f3aca9e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -419,20 +419,13 @@ struct mii_regs {
419 unsigned int data; /* MII Data */ 419 unsigned int data; /* MII Data */
420}; 420};
421 421
422struct stmmac_ring_mode_ops { 422struct stmmac_mode_ops {
423 unsigned int (*is_jumbo_frm) (int len, int ehn_desc);
424 unsigned int (*jumbo_frm) (void *priv, struct sk_buff *skb, int csum);
425 void (*refill_desc3) (void *priv, struct dma_desc *p);
426 void (*init_desc3) (struct dma_desc *p);
427 void (*clean_desc3) (void *priv, struct dma_desc *p);
428 int (*set_16kib_bfsize) (int mtu);
429};
430
431struct stmmac_chain_mode_ops {
432 void (*init) (void *des, dma_addr_t phy_addr, unsigned int size, 423 void (*init) (void *des, dma_addr_t phy_addr, unsigned int size,
433 unsigned int extend_desc); 424 unsigned int extend_desc);
434 unsigned int (*is_jumbo_frm) (int len, int ehn_desc); 425 unsigned int (*is_jumbo_frm) (int len, int ehn_desc);
435 unsigned int (*jumbo_frm) (void *priv, struct sk_buff *skb, int csum); 426 unsigned int (*jumbo_frm) (void *priv, struct sk_buff *skb, int csum);
427 int (*set_16kib_bfsize)(int mtu);
428 void (*init_desc3)(struct dma_desc *p);
436 void (*refill_desc3) (void *priv, struct dma_desc *p); 429 void (*refill_desc3) (void *priv, struct dma_desc *p);
437 void (*clean_desc3) (void *priv, struct dma_desc *p); 430 void (*clean_desc3) (void *priv, struct dma_desc *p);
438}; 431};
@@ -441,8 +434,7 @@ struct mac_device_info {
441 const struct stmmac_ops *mac; 434 const struct stmmac_ops *mac;
442 const struct stmmac_desc_ops *desc; 435 const struct stmmac_desc_ops *desc;
443 const struct stmmac_dma_ops *dma; 436 const struct stmmac_dma_ops *dma;
444 const struct stmmac_ring_mode_ops *ring; 437 const struct stmmac_mode_ops *mode;
445 const struct stmmac_chain_mode_ops *chain;
446 const struct stmmac_hwtimestamp *ptp; 438 const struct stmmac_hwtimestamp *ptp;
447 struct mii_regs mii; /* MII register Addresses */ 439 struct mii_regs mii; /* MII register Addresses */
448 struct mac_link link; 440 struct mac_link link;
@@ -460,7 +452,7 @@ void stmmac_get_mac_addr(void __iomem *ioaddr, unsigned char *addr,
460void stmmac_set_mac(void __iomem *ioaddr, bool enable); 452void stmmac_set_mac(void __iomem *ioaddr, bool enable);
461 453
462void dwmac_dma_flush_tx_fifo(void __iomem *ioaddr); 454void dwmac_dma_flush_tx_fifo(void __iomem *ioaddr);
463extern const struct stmmac_ring_mode_ops ring_mode_ops; 455extern const struct stmmac_mode_ops ring_mode_ops;
464extern const struct stmmac_chain_mode_ops chain_mode_ops; 456extern const struct stmmac_mode_ops chain_mode_ops;
465 457
466#endif /* __COMMON_H__ */ 458#endif /* __COMMON_H__ */
diff --git a/drivers/net/ethernet/stmicro/stmmac/ring_mode.c b/drivers/net/ethernet/stmicro/stmmac/ring_mode.c
index a96c7c2f5f3f..650a4be6bce5 100644
--- a/drivers/net/ethernet/stmicro/stmmac/ring_mode.c
+++ b/drivers/net/ethernet/stmicro/stmmac/ring_mode.c
@@ -100,10 +100,9 @@ static void stmmac_refill_desc3(void *priv_ptr, struct dma_desc *p)
100{ 100{
101 struct stmmac_priv *priv = (struct stmmac_priv *)priv_ptr; 101 struct stmmac_priv *priv = (struct stmmac_priv *)priv_ptr;
102 102
103 if (unlikely(priv->plat->has_gmac)) 103 /* Fill DES3 in case of RING mode */
104 /* Fill DES3 in case of RING mode */ 104 if (priv->dma_buf_sz >= BUF_SIZE_8KiB)
105 if (priv->dma_buf_sz >= BUF_SIZE_8KiB) 105 p->des3 = p->des2 + BUF_SIZE_8KiB;
106 p->des3 = p->des2 + BUF_SIZE_8KiB;
107} 106}
108 107
109/* In ring mode we need to fill the desc3 because it is used as buffer */ 108/* In ring mode we need to fill the desc3 because it is used as buffer */
@@ -126,7 +125,7 @@ static int stmmac_set_16kib_bfsize(int mtu)
126 return ret; 125 return ret;
127} 126}
128 127
129const struct stmmac_ring_mode_ops ring_mode_ops = { 128const struct stmmac_mode_ops ring_mode_ops = {
130 .is_jumbo_frm = stmmac_is_jumbo_frm, 129 .is_jumbo_frm = stmmac_is_jumbo_frm,
131 .jumbo_frm = stmmac_jumbo_frm, 130 .jumbo_frm = stmmac_jumbo_frm,
132 .refill_desc3 = stmmac_refill_desc3, 131 .refill_desc3 = stmmac_refill_desc3,
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 078ad0ec8593..8543e1cfd55e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -92,8 +92,8 @@ static int tc = TC_DEFAULT;
92module_param(tc, int, S_IRUGO | S_IWUSR); 92module_param(tc, int, S_IRUGO | S_IWUSR);
93MODULE_PARM_DESC(tc, "DMA threshold control value"); 93MODULE_PARM_DESC(tc, "DMA threshold control value");
94 94
95#define DMA_BUFFER_SIZE BUF_SIZE_4KiB 95#define DEFAULT_BUFSIZE 1536
96static int buf_sz = DMA_BUFFER_SIZE; 96static int buf_sz = DEFAULT_BUFSIZE;
97module_param(buf_sz, int, S_IRUGO | S_IWUSR); 97module_param(buf_sz, int, S_IRUGO | S_IWUSR);
98MODULE_PARM_DESC(buf_sz, "DMA buffer size"); 98MODULE_PARM_DESC(buf_sz, "DMA buffer size");
99 99
@@ -136,8 +136,8 @@ static void stmmac_verify_args(void)
136 dma_rxsize = DMA_RX_SIZE; 136 dma_rxsize = DMA_RX_SIZE;
137 if (unlikely(dma_txsize < 0)) 137 if (unlikely(dma_txsize < 0))
138 dma_txsize = DMA_TX_SIZE; 138 dma_txsize = DMA_TX_SIZE;
139 if (unlikely((buf_sz < DMA_BUFFER_SIZE) || (buf_sz > BUF_SIZE_16KiB))) 139 if (unlikely((buf_sz < DEFAULT_BUFSIZE) || (buf_sz > BUF_SIZE_16KiB)))
140 buf_sz = DMA_BUFFER_SIZE; 140 buf_sz = DEFAULT_BUFSIZE;
141 if (unlikely(flow_ctrl > 1)) 141 if (unlikely(flow_ctrl > 1))
142 flow_ctrl = FLOW_AUTO; 142 flow_ctrl = FLOW_AUTO;
143 else if (likely(flow_ctrl < 0)) 143 else if (likely(flow_ctrl < 0))
@@ -286,10 +286,25 @@ bool stmmac_eee_init(struct stmmac_priv *priv)
286 286
287 /* MAC core supports the EEE feature. */ 287 /* MAC core supports the EEE feature. */
288 if (priv->dma_cap.eee) { 288 if (priv->dma_cap.eee) {
289 int tx_lpi_timer = priv->tx_lpi_timer;
290
289 /* Check if the PHY supports EEE */ 291 /* Check if the PHY supports EEE */
290 if (phy_init_eee(priv->phydev, 1)) 292 if (phy_init_eee(priv->phydev, 1)) {
293 /* To manage at run-time if the EEE cannot be supported
294 * anymore (for example because the lp caps have been
295 * changed).
296 * In that case the driver disable own timers.
297 */
298 if (priv->eee_active) {
299 pr_debug("stmmac: disable EEE\n");
300 del_timer_sync(&priv->eee_ctrl_timer);
301 priv->hw->mac->set_eee_timer(priv->ioaddr, 0,
302 tx_lpi_timer);
303 }
304 priv->eee_active = 0;
291 goto out; 305 goto out;
292 306 }
307 /* Activate the EEE and start timers */
293 if (!priv->eee_active) { 308 if (!priv->eee_active) {
294 priv->eee_active = 1; 309 priv->eee_active = 1;
295 init_timer(&priv->eee_ctrl_timer); 310 init_timer(&priv->eee_ctrl_timer);
@@ -300,13 +315,13 @@ bool stmmac_eee_init(struct stmmac_priv *priv)
300 315
301 priv->hw->mac->set_eee_timer(priv->ioaddr, 316 priv->hw->mac->set_eee_timer(priv->ioaddr,
302 STMMAC_DEFAULT_LIT_LS, 317 STMMAC_DEFAULT_LIT_LS,
303 priv->tx_lpi_timer); 318 tx_lpi_timer);
304 } else 319 } else
305 /* Set HW EEE according to the speed */ 320 /* Set HW EEE according to the speed */
306 priv->hw->mac->set_eee_pls(priv->ioaddr, 321 priv->hw->mac->set_eee_pls(priv->ioaddr,
307 priv->phydev->link); 322 priv->phydev->link);
308 323
309 pr_info("stmmac: Energy-Efficient Ethernet initialized\n"); 324 pr_debug("stmmac: Energy-Efficient Ethernet initialized\n");
310 325
311 ret = true; 326 ret = true;
312 } 327 }
@@ -886,10 +901,10 @@ static int stmmac_set_bfsize(int mtu, int bufsize)
886 ret = BUF_SIZE_8KiB; 901 ret = BUF_SIZE_8KiB;
887 else if (mtu >= BUF_SIZE_2KiB) 902 else if (mtu >= BUF_SIZE_2KiB)
888 ret = BUF_SIZE_4KiB; 903 ret = BUF_SIZE_4KiB;
889 else if (mtu >= DMA_BUFFER_SIZE) 904 else if (mtu > DEFAULT_BUFSIZE)
890 ret = BUF_SIZE_2KiB; 905 ret = BUF_SIZE_2KiB;
891 else 906 else
892 ret = DMA_BUFFER_SIZE; 907 ret = DEFAULT_BUFSIZE;
893 908
894 return ret; 909 return ret;
895} 910}
@@ -951,9 +966,9 @@ static int stmmac_init_rx_buffers(struct stmmac_priv *priv, struct dma_desc *p,
951 966
952 p->des2 = priv->rx_skbuff_dma[i]; 967 p->des2 = priv->rx_skbuff_dma[i];
953 968
954 if ((priv->mode == STMMAC_RING_MODE) && 969 if ((priv->hw->mode->init_desc3) &&
955 (priv->dma_buf_sz == BUF_SIZE_16KiB)) 970 (priv->dma_buf_sz == BUF_SIZE_16KiB))
956 priv->hw->ring->init_desc3(p); 971 priv->hw->mode->init_desc3(p);
957 972
958 return 0; 973 return 0;
959} 974}
@@ -984,11 +999,8 @@ static int init_dma_desc_rings(struct net_device *dev)
984 unsigned int bfsize = 0; 999 unsigned int bfsize = 0;
985 int ret = -ENOMEM; 1000 int ret = -ENOMEM;
986 1001
987 /* Set the max buffer size according to the DESC mode 1002 if (priv->hw->mode->set_16kib_bfsize)
988 * and the MTU. Note that RING mode allows 16KiB bsize. 1003 bfsize = priv->hw->mode->set_16kib_bfsize(dev->mtu);
989 */
990 if (priv->mode == STMMAC_RING_MODE)
991 bfsize = priv->hw->ring->set_16kib_bfsize(dev->mtu);
992 1004
993 if (bfsize < BUF_SIZE_16KiB) 1005 if (bfsize < BUF_SIZE_16KiB)
994 bfsize = stmmac_set_bfsize(dev->mtu, priv->dma_buf_sz); 1006 bfsize = stmmac_set_bfsize(dev->mtu, priv->dma_buf_sz);
@@ -1029,15 +1041,15 @@ static int init_dma_desc_rings(struct net_device *dev)
1029 /* Setup the chained descriptor addresses */ 1041 /* Setup the chained descriptor addresses */
1030 if (priv->mode == STMMAC_CHAIN_MODE) { 1042 if (priv->mode == STMMAC_CHAIN_MODE) {
1031 if (priv->extend_desc) { 1043 if (priv->extend_desc) {
1032 priv->hw->chain->init(priv->dma_erx, priv->dma_rx_phy, 1044 priv->hw->mode->init(priv->dma_erx, priv->dma_rx_phy,
1033 rxsize, 1); 1045 rxsize, 1);
1034 priv->hw->chain->init(priv->dma_etx, priv->dma_tx_phy, 1046 priv->hw->mode->init(priv->dma_etx, priv->dma_tx_phy,
1035 txsize, 1); 1047 txsize, 1);
1036 } else { 1048 } else {
1037 priv->hw->chain->init(priv->dma_rx, priv->dma_rx_phy, 1049 priv->hw->mode->init(priv->dma_rx, priv->dma_rx_phy,
1038 rxsize, 0); 1050 rxsize, 0);
1039 priv->hw->chain->init(priv->dma_tx, priv->dma_tx_phy, 1051 priv->hw->mode->init(priv->dma_tx, priv->dma_tx_phy,
1040 txsize, 0); 1052 txsize, 0);
1041 } 1053 }
1042 } 1054 }
1043 1055
@@ -1288,7 +1300,7 @@ static void stmmac_tx_clean(struct stmmac_priv *priv)
1288 DMA_TO_DEVICE); 1300 DMA_TO_DEVICE);
1289 priv->tx_skbuff_dma[entry] = 0; 1301 priv->tx_skbuff_dma[entry] = 0;
1290 } 1302 }
1291 priv->hw->ring->clean_desc3(priv, p); 1303 priv->hw->mode->clean_desc3(priv, p);
1292 1304
1293 if (likely(skb != NULL)) { 1305 if (likely(skb != NULL)) {
1294 dev_kfree_skb(skb); 1306 dev_kfree_skb(skb);
@@ -1844,6 +1856,7 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
1844 int nfrags = skb_shinfo(skb)->nr_frags; 1856 int nfrags = skb_shinfo(skb)->nr_frags;
1845 struct dma_desc *desc, *first; 1857 struct dma_desc *desc, *first;
1846 unsigned int nopaged_len = skb_headlen(skb); 1858 unsigned int nopaged_len = skb_headlen(skb);
1859 unsigned int enh_desc = priv->plat->enh_desc;
1847 1860
1848 if (unlikely(stmmac_tx_avail(priv) < nfrags + 1)) { 1861 if (unlikely(stmmac_tx_avail(priv) < nfrags + 1)) {
1849 if (!netif_queue_stopped(dev)) { 1862 if (!netif_queue_stopped(dev)) {
@@ -1871,27 +1884,19 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
1871 first = desc; 1884 first = desc;
1872 1885
1873 /* To program the descriptors according to the size of the frame */ 1886 /* To program the descriptors according to the size of the frame */
1874 if (priv->mode == STMMAC_RING_MODE) { 1887 if (enh_desc)
1875 is_jumbo = priv->hw->ring->is_jumbo_frm(skb->len, 1888 is_jumbo = priv->hw->mode->is_jumbo_frm(skb->len, enh_desc);
1876 priv->plat->enh_desc); 1889
1877 if (unlikely(is_jumbo))
1878 entry = priv->hw->ring->jumbo_frm(priv, skb,
1879 csum_insertion);
1880 } else {
1881 is_jumbo = priv->hw->chain->is_jumbo_frm(skb->len,
1882 priv->plat->enh_desc);
1883 if (unlikely(is_jumbo))
1884 entry = priv->hw->chain->jumbo_frm(priv, skb,
1885 csum_insertion);
1886 }
1887 if (likely(!is_jumbo)) { 1890 if (likely(!is_jumbo)) {
1888 desc->des2 = dma_map_single(priv->device, skb->data, 1891 desc->des2 = dma_map_single(priv->device, skb->data,
1889 nopaged_len, DMA_TO_DEVICE); 1892 nopaged_len, DMA_TO_DEVICE);
1890 priv->tx_skbuff_dma[entry] = desc->des2; 1893 priv->tx_skbuff_dma[entry] = desc->des2;
1891 priv->hw->desc->prepare_tx_desc(desc, 1, nopaged_len, 1894 priv->hw->desc->prepare_tx_desc(desc, 1, nopaged_len,
1892 csum_insertion, priv->mode); 1895 csum_insertion, priv->mode);
1893 } else 1896 } else {
1894 desc = first; 1897 desc = first;
1898 entry = priv->hw->mode->jumbo_frm(priv, skb, csum_insertion);
1899 }
1895 1900
1896 for (i = 0; i < nfrags; i++) { 1901 for (i = 0; i < nfrags; i++) {
1897 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; 1902 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
@@ -2029,7 +2034,7 @@ static inline void stmmac_rx_refill(struct stmmac_priv *priv)
2029 2034
2030 p->des2 = priv->rx_skbuff_dma[entry]; 2035 p->des2 = priv->rx_skbuff_dma[entry];
2031 2036
2032 priv->hw->ring->refill_desc3(priv, p); 2037 priv->hw->mode->refill_desc3(priv, p);
2033 2038
2034 if (netif_msg_rx_status(priv)) 2039 if (netif_msg_rx_status(priv))
2035 pr_debug("\trefill entry #%d\n", entry); 2040 pr_debug("\trefill entry #%d\n", entry);
@@ -2633,11 +2638,11 @@ static int stmmac_hw_init(struct stmmac_priv *priv)
2633 2638
2634 /* To use the chained or ring mode */ 2639 /* To use the chained or ring mode */
2635 if (chain_mode) { 2640 if (chain_mode) {
2636 priv->hw->chain = &chain_mode_ops; 2641 priv->hw->mode = &chain_mode_ops;
2637 pr_info(" Chain mode enabled\n"); 2642 pr_info(" Chain mode enabled\n");
2638 priv->mode = STMMAC_CHAIN_MODE; 2643 priv->mode = STMMAC_CHAIN_MODE;
2639 } else { 2644 } else {
2640 priv->hw->ring = &ring_mode_ops; 2645 priv->hw->mode = &ring_mode_ops;
2641 pr_info(" Ring mode enabled\n"); 2646 pr_info(" Ring mode enabled\n");
2642 priv->mode = STMMAC_RING_MODE; 2647 priv->mode = STMMAC_RING_MODE;
2643 } 2648 }
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index c61bc72b8e90..8fb32a80f1c1 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -36,7 +36,7 @@ static const struct of_device_id stmmac_dt_ids[] = {
36#ifdef CONFIG_DWMAC_STI 36#ifdef CONFIG_DWMAC_STI
37 { .compatible = "st,stih415-dwmac", .data = &sti_gmac_data}, 37 { .compatible = "st,stih415-dwmac", .data = &sti_gmac_data},
38 { .compatible = "st,stih416-dwmac", .data = &sti_gmac_data}, 38 { .compatible = "st,stih416-dwmac", .data = &sti_gmac_data},
39 { .compatible = "st,stih127-dwmac", .data = &sti_gmac_data}, 39 { .compatible = "st,stid127-dwmac", .data = &sti_gmac_data},
40#endif 40#endif
41 /* SoC specific glue layers should come before generic bindings */ 41 /* SoC specific glue layers should come before generic bindings */
42 { .compatible = "st,spear600-gmac"}, 42 { .compatible = "st,spear600-gmac"},