blob: 452f256ff03f04bb6ee846966eb8961ebbc40c05 [file] [log] [blame]
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +00001/*******************************************************************************
2 Specialised functions for managing Ring mode
3
4 Copyright(C) 2011 STMicroelectronics Ltd
5
6 It defines all the functions used to handle the normal/enhanced
7 descriptors in case of the DMA is configured to work in chained or
8 in ring mode.
9
10 This program is free software; you can redistribute it and/or modify it
11 under the terms and conditions of the GNU General Public License,
12 version 2, as published by the Free Software Foundation.
13
14 This program is distributed in the hope it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 more details.
18
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +000019 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
23*******************************************************************************/
24
25#include "stmmac.h"
26
Giuseppe CAVALLARO362b37b2014-08-27 11:27:00 +020027static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +000028{
Giuseppe CAVALLAROceb694992013-04-08 02:10:01 +000029 struct stmmac_priv *priv = (struct stmmac_priv *)p;
Giuseppe Cavallaroe3ad57c2016-02-29 14:27:30 +010030 unsigned int entry = priv->cur_tx;
Byungho An21ff0192013-08-08 15:30:26 +090031 struct dma_desc *desc;
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +000032 unsigned int nopaged_len = skb_headlen(skb);
Michael Weiserf8be0d72016-11-14 18:58:05 +010033 unsigned int bmax, len, des2;
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +000034
Byungho An21ff0192013-08-08 15:30:26 +090035 if (priv->extend_desc)
36 desc = (struct dma_desc *)(priv->dma_etx + entry);
37 else
38 desc = priv->dma_tx + entry;
39
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +000040 if (priv->plat->enh_desc)
41 bmax = BUF_SIZE_8KiB;
42 else
43 bmax = BUF_SIZE_2KiB;
44
45 len = nopaged_len - bmax;
46
47 if (nopaged_len > BUF_SIZE_8KiB) {
48
Michael Weiserf8be0d72016-11-14 18:58:05 +010049 des2 = dma_map_single(priv->device, skb->data, bmax,
50 DMA_TO_DEVICE);
51 desc->des2 = cpu_to_le32(des2);
52 if (dma_mapping_error(priv->device, des2))
Giuseppe CAVALLARO362b37b2014-08-27 11:27:00 +020053 return -1;
54
Michael Weiserf8be0d72016-11-14 18:58:05 +010055 priv->tx_skbuff_dma[entry].buf = des2;
Giuseppe Cavallaro553e2ab2016-02-29 14:27:31 +010056 priv->tx_skbuff_dma[entry].len = bmax;
Giuseppe Cavallaro96951362016-02-29 14:27:33 +010057 priv->tx_skbuff_dma[entry].is_jumbo = true;
Giuseppe Cavallaro553e2ab2016-02-29 14:27:31 +010058
Michael Weiserf8be0d72016-11-14 18:58:05 +010059 desc->des3 = cpu_to_le32(des2 + BUF_SIZE_4KiB);
Giuseppe CAVALLARO4a7d6662013-03-26 04:43:05 +000060 priv->hw->desc->prepare_tx_desc(desc, 1, bmax, csum,
Giuseppe Cavallarobe434d52016-02-29 14:27:35 +010061 STMMAC_RING_MODE, 0, false);
damuzi00075e43642014-01-17 23:47:59 +080062 priv->tx_skbuff[entry] = NULL;
Giuseppe Cavallaroe3ad57c2016-02-29 14:27:30 +010063 entry = STMMAC_GET_ENTRY(entry, DMA_TX_SIZE);
Byungho An21ff0192013-08-08 15:30:26 +090064
65 if (priv->extend_desc)
66 desc = (struct dma_desc *)(priv->dma_etx + entry);
67 else
68 desc = priv->dma_tx + entry;
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +000069
Michael Weiserf8be0d72016-11-14 18:58:05 +010070 des2 = dma_map_single(priv->device, skb->data + bmax, len,
71 DMA_TO_DEVICE);
72 desc->des2 = cpu_to_le32(des2);
73 if (dma_mapping_error(priv->device, des2))
Giuseppe CAVALLARO362b37b2014-08-27 11:27:00 +020074 return -1;
Michael Weiserf8be0d72016-11-14 18:58:05 +010075 priv->tx_skbuff_dma[entry].buf = des2;
Giuseppe Cavallaro553e2ab2016-02-29 14:27:31 +010076 priv->tx_skbuff_dma[entry].len = len;
Giuseppe Cavallaro96951362016-02-29 14:27:33 +010077 priv->tx_skbuff_dma[entry].is_jumbo = true;
Giuseppe Cavallaro553e2ab2016-02-29 14:27:31 +010078
Michael Weiserf8be0d72016-11-14 18:58:05 +010079 desc->des3 = cpu_to_le32(des2 + BUF_SIZE_4KiB);
Giuseppe CAVALLARO4a7d6662013-03-26 04:43:05 +000080 priv->hw->desc->prepare_tx_desc(desc, 0, len, csum,
Giuseppe Cavallarobe434d52016-02-29 14:27:35 +010081 STMMAC_RING_MODE, 1, true);
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +000082 } else {
Michael Weiserf8be0d72016-11-14 18:58:05 +010083 des2 = dma_map_single(priv->device, skb->data,
84 nopaged_len, DMA_TO_DEVICE);
85 desc->des2 = cpu_to_le32(des2);
86 if (dma_mapping_error(priv->device, des2))
Giuseppe CAVALLARO362b37b2014-08-27 11:27:00 +020087 return -1;
Michael Weiserf8be0d72016-11-14 18:58:05 +010088 priv->tx_skbuff_dma[entry].buf = des2;
Giuseppe Cavallaro553e2ab2016-02-29 14:27:31 +010089 priv->tx_skbuff_dma[entry].len = nopaged_len;
Giuseppe Cavallaro96951362016-02-29 14:27:33 +010090 priv->tx_skbuff_dma[entry].is_jumbo = true;
Michael Weiserf8be0d72016-11-14 18:58:05 +010091 desc->des3 = cpu_to_le32(des2 + BUF_SIZE_4KiB);
Giuseppe CAVALLARO4a7d6662013-03-26 04:43:05 +000092 priv->hw->desc->prepare_tx_desc(desc, 1, nopaged_len, csum,
Giuseppe Cavallarobe434d52016-02-29 14:27:35 +010093 STMMAC_RING_MODE, 0, true);
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +000094 }
95
Giuseppe Cavallaroe3ad57c2016-02-29 14:27:30 +010096 priv->cur_tx = entry;
97
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +000098 return entry;
99}
100
101static unsigned int stmmac_is_jumbo_frm(int len, int enh_desc)
102{
103 unsigned int ret = 0;
104
105 if (len >= BUF_SIZE_4KiB)
106 ret = 1;
107
108 return ret;
109}
110
Rayagond Kokatanur891434b2013-03-26 04:43:10 +0000111static void stmmac_refill_desc3(void *priv_ptr, struct dma_desc *p)
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +0000112{
Rayagond Kokatanur891434b2013-03-26 04:43:10 +0000113 struct stmmac_priv *priv = (struct stmmac_priv *)priv_ptr;
114
Giuseppe CAVALLARO29896a62014-03-10 13:40:33 +0100115 /* Fill DES3 in case of RING mode */
116 if (priv->dma_buf_sz >= BUF_SIZE_8KiB)
Michael Weiserf8be0d72016-11-14 18:58:05 +0100117 p->des3 = cpu_to_le32(le32_to_cpu(p->des2) + BUF_SIZE_8KiB);
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +0000118}
119
Giuseppe CAVALLARO4a7d6662013-03-26 04:43:05 +0000120/* In ring mode we need to fill the desc3 because it is used as buffer */
121static void stmmac_init_desc3(struct dma_desc *p)
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +0000122{
Michael Weiserf8be0d72016-11-14 18:58:05 +0100123 p->des3 = cpu_to_le32(le32_to_cpu(p->des2) + BUF_SIZE_8KiB);
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +0000124}
125
Rayagond Kokatanur891434b2013-03-26 04:43:10 +0000126static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p)
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +0000127{
Giuseppe Cavallaro96951362016-02-29 14:27:33 +0100128 struct stmmac_priv *priv = (struct stmmac_priv *)priv_ptr;
129 unsigned int entry = priv->dirty_tx;
130
131 /* des3 is only used for jumbo frames tx or time stamping */
132 if (unlikely(priv->tx_skbuff_dma[entry].is_jumbo ||
133 (priv->tx_skbuff_dma[entry].last_segment &&
134 !priv->extend_desc && priv->hwts_tx_en)))
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +0000135 p->des3 = 0;
136}
137
138static int stmmac_set_16kib_bfsize(int mtu)
139{
140 int ret = 0;
141 if (unlikely(mtu >= BUF_SIZE_8KiB))
142 ret = BUF_SIZE_16KiB;
143 return ret;
144}
145
Giuseppe CAVALLARO29896a62014-03-10 13:40:33 +0100146const struct stmmac_mode_ops ring_mode_ops = {
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +0000147 .is_jumbo_frm = stmmac_is_jumbo_frm,
148 .jumbo_frm = stmmac_jumbo_frm,
149 .refill_desc3 = stmmac_refill_desc3,
150 .init_desc3 = stmmac_init_desc3,
Giuseppe CAVALLARO286a8372011-10-18 00:01:24 +0000151 .clean_desc3 = stmmac_clean_desc3,
152 .set_16kib_bfsize = stmmac_set_16kib_bfsize,
153};