Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 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 CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 19 | 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 CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 27 | static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum) |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 28 | { |
Giuseppe CAVALLARO | ceb69499 | 2013-04-08 02:10:01 +0000 | [diff] [blame] | 29 | struct stmmac_priv *priv = (struct stmmac_priv *)p; |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 30 | unsigned int entry = priv->cur_tx; |
Byungho An | 21ff019 | 2013-08-08 15:30:26 +0900 | [diff] [blame] | 31 | struct dma_desc *desc; |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 32 | unsigned int nopaged_len = skb_headlen(skb); |
Michael Weiser | f8be0d7 | 2016-11-14 18:58:05 +0100 | [diff] [blame] | 33 | unsigned int bmax, len, des2; |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 34 | |
Byungho An | 21ff019 | 2013-08-08 15:30:26 +0900 | [diff] [blame] | 35 | if (priv->extend_desc) |
| 36 | desc = (struct dma_desc *)(priv->dma_etx + entry); |
| 37 | else |
| 38 | desc = priv->dma_tx + entry; |
| 39 | |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 40 | 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 Weiser | f8be0d7 | 2016-11-14 18:58:05 +0100 | [diff] [blame] | 49 | 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 CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 53 | return -1; |
| 54 | |
Michael Weiser | f8be0d7 | 2016-11-14 18:58:05 +0100 | [diff] [blame] | 55 | priv->tx_skbuff_dma[entry].buf = des2; |
Giuseppe Cavallaro | 553e2ab | 2016-02-29 14:27:31 +0100 | [diff] [blame] | 56 | priv->tx_skbuff_dma[entry].len = bmax; |
Giuseppe Cavallaro | 9695136 | 2016-02-29 14:27:33 +0100 | [diff] [blame] | 57 | priv->tx_skbuff_dma[entry].is_jumbo = true; |
Giuseppe Cavallaro | 553e2ab | 2016-02-29 14:27:31 +0100 | [diff] [blame] | 58 | |
Michael Weiser | f8be0d7 | 2016-11-14 18:58:05 +0100 | [diff] [blame] | 59 | desc->des3 = cpu_to_le32(des2 + BUF_SIZE_4KiB); |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 60 | priv->hw->desc->prepare_tx_desc(desc, 1, bmax, csum, |
Giuseppe Cavallaro | be434d5 | 2016-02-29 14:27:35 +0100 | [diff] [blame] | 61 | STMMAC_RING_MODE, 0, false); |
damuzi000 | 75e4364 | 2014-01-17 23:47:59 +0800 | [diff] [blame] | 62 | priv->tx_skbuff[entry] = NULL; |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 63 | entry = STMMAC_GET_ENTRY(entry, DMA_TX_SIZE); |
Byungho An | 21ff019 | 2013-08-08 15:30:26 +0900 | [diff] [blame] | 64 | |
| 65 | if (priv->extend_desc) |
| 66 | desc = (struct dma_desc *)(priv->dma_etx + entry); |
| 67 | else |
| 68 | desc = priv->dma_tx + entry; |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 69 | |
Michael Weiser | f8be0d7 | 2016-11-14 18:58:05 +0100 | [diff] [blame] | 70 | 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 CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 74 | return -1; |
Michael Weiser | f8be0d7 | 2016-11-14 18:58:05 +0100 | [diff] [blame] | 75 | priv->tx_skbuff_dma[entry].buf = des2; |
Giuseppe Cavallaro | 553e2ab | 2016-02-29 14:27:31 +0100 | [diff] [blame] | 76 | priv->tx_skbuff_dma[entry].len = len; |
Giuseppe Cavallaro | 9695136 | 2016-02-29 14:27:33 +0100 | [diff] [blame] | 77 | priv->tx_skbuff_dma[entry].is_jumbo = true; |
Giuseppe Cavallaro | 553e2ab | 2016-02-29 14:27:31 +0100 | [diff] [blame] | 78 | |
Michael Weiser | f8be0d7 | 2016-11-14 18:58:05 +0100 | [diff] [blame] | 79 | desc->des3 = cpu_to_le32(des2 + BUF_SIZE_4KiB); |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 80 | priv->hw->desc->prepare_tx_desc(desc, 0, len, csum, |
Giuseppe Cavallaro | be434d5 | 2016-02-29 14:27:35 +0100 | [diff] [blame] | 81 | STMMAC_RING_MODE, 1, true); |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 82 | } else { |
Michael Weiser | f8be0d7 | 2016-11-14 18:58:05 +0100 | [diff] [blame] | 83 | 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 CAVALLARO | 362b37b | 2014-08-27 11:27:00 +0200 | [diff] [blame] | 87 | return -1; |
Michael Weiser | f8be0d7 | 2016-11-14 18:58:05 +0100 | [diff] [blame] | 88 | priv->tx_skbuff_dma[entry].buf = des2; |
Giuseppe Cavallaro | 553e2ab | 2016-02-29 14:27:31 +0100 | [diff] [blame] | 89 | priv->tx_skbuff_dma[entry].len = nopaged_len; |
Giuseppe Cavallaro | 9695136 | 2016-02-29 14:27:33 +0100 | [diff] [blame] | 90 | priv->tx_skbuff_dma[entry].is_jumbo = true; |
Michael Weiser | f8be0d7 | 2016-11-14 18:58:05 +0100 | [diff] [blame] | 91 | desc->des3 = cpu_to_le32(des2 + BUF_SIZE_4KiB); |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 92 | priv->hw->desc->prepare_tx_desc(desc, 1, nopaged_len, csum, |
Giuseppe Cavallaro | be434d5 | 2016-02-29 14:27:35 +0100 | [diff] [blame] | 93 | STMMAC_RING_MODE, 0, true); |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Giuseppe Cavallaro | e3ad57c | 2016-02-29 14:27:30 +0100 | [diff] [blame] | 96 | priv->cur_tx = entry; |
| 97 | |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 98 | return entry; |
| 99 | } |
| 100 | |
| 101 | static 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 Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 111 | static void stmmac_refill_desc3(void *priv_ptr, struct dma_desc *p) |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 112 | { |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 113 | struct stmmac_priv *priv = (struct stmmac_priv *)priv_ptr; |
| 114 | |
Giuseppe CAVALLARO | 29896a6 | 2014-03-10 13:40:33 +0100 | [diff] [blame] | 115 | /* Fill DES3 in case of RING mode */ |
| 116 | if (priv->dma_buf_sz >= BUF_SIZE_8KiB) |
Michael Weiser | f8be0d7 | 2016-11-14 18:58:05 +0100 | [diff] [blame] | 117 | p->des3 = cpu_to_le32(le32_to_cpu(p->des2) + BUF_SIZE_8KiB); |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Giuseppe CAVALLARO | 4a7d666 | 2013-03-26 04:43:05 +0000 | [diff] [blame] | 120 | /* In ring mode we need to fill the desc3 because it is used as buffer */ |
| 121 | static void stmmac_init_desc3(struct dma_desc *p) |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 122 | { |
Michael Weiser | f8be0d7 | 2016-11-14 18:58:05 +0100 | [diff] [blame] | 123 | p->des3 = cpu_to_le32(le32_to_cpu(p->des2) + BUF_SIZE_8KiB); |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 124 | } |
| 125 | |
Rayagond Kokatanur | 891434b | 2013-03-26 04:43:10 +0000 | [diff] [blame] | 126 | static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p) |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 127 | { |
Giuseppe Cavallaro | 9695136 | 2016-02-29 14:27:33 +0100 | [diff] [blame] | 128 | 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 CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 135 | p->des3 = 0; |
| 136 | } |
| 137 | |
| 138 | static 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 CAVALLARO | 29896a6 | 2014-03-10 13:40:33 +0100 | [diff] [blame] | 146 | const struct stmmac_mode_ops ring_mode_ops = { |
Giuseppe CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 147 | .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 CAVALLARO | 286a837 | 2011-10-18 00:01:24 +0000 | [diff] [blame] | 151 | .clean_desc3 = stmmac_clean_desc3, |
| 152 | .set_16kib_bfsize = stmmac_set_16kib_bfsize, |
| 153 | }; |