Linux Audio

Check our new training course

Loading...
v6.8
  1/* SPDX-License-Identifier: GPL-2.0-only */
  2/*******************************************************************************
  3  Header File to describe Normal/enhanced descriptor functions used for RING
  4  and CHAINED modes.
  5
  6  Copyright(C) 2011  STMicroelectronics Ltd
  7
  8  It defines all the functions used to handle the normal/enhanced
  9  descriptors in case of the DMA is configured to work in chained or
 10  in ring mode.
 11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 12
 13  Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
 14*******************************************************************************/
 15
 16#ifndef __DESC_COM_H__
 17#define __DESC_COM_H__
 18
 19/* Specific functions used for Ring mode */
 20
 21/* Enhanced descriptors */
 22static inline void ehn_desc_rx_set_on_ring(struct dma_desc *p, int end,
 23					   int bfsize)
 24{
 25	if (bfsize == BUF_SIZE_16KiB)
 26		p->des1 |= cpu_to_le32((BUF_SIZE_8KiB
 27				<< ERDES1_BUFFER2_SIZE_SHIFT)
 28			   & ERDES1_BUFFER2_SIZE_MASK);
 29
 30	if (end)
 31		p->des1 |= cpu_to_le32(ERDES1_END_RING);
 32}
 33
 34static inline void enh_desc_end_tx_desc_on_ring(struct dma_desc *p, int end)
 35{
 36	if (end)
 37		p->des0 |= cpu_to_le32(ETDES0_END_RING);
 38	else
 39		p->des0 &= cpu_to_le32(~ETDES0_END_RING);
 40}
 41
 42static inline void enh_set_tx_desc_len_on_ring(struct dma_desc *p, int len)
 
 
 
 
 
 43{
 44	if (unlikely(len > BUF_SIZE_4KiB)) {
 45		p->des1 |= cpu_to_le32((((len - BUF_SIZE_4KiB)
 46					<< ETDES1_BUFFER2_SIZE_SHIFT)
 47			    & ETDES1_BUFFER2_SIZE_MASK) | (BUF_SIZE_4KiB
 48			    & ETDES1_BUFFER1_SIZE_MASK));
 49	} else
 50		p->des1 |= cpu_to_le32((len & ETDES1_BUFFER1_SIZE_MASK));
 51}
 52
 53/* Normal descriptors */
 54static inline void ndesc_rx_set_on_ring(struct dma_desc *p, int end, int bfsize)
 55{
 56	if (bfsize >= BUF_SIZE_2KiB) {
 57		int bfsize2;
 58
 59		bfsize2 = min(bfsize - BUF_SIZE_2KiB + 1, BUF_SIZE_2KiB - 1);
 60		p->des1 |= cpu_to_le32((bfsize2 << RDES1_BUFFER2_SIZE_SHIFT)
 61			    & RDES1_BUFFER2_SIZE_MASK);
 62	}
 63
 64	if (end)
 65		p->des1 |= cpu_to_le32(RDES1_END_RING);
 66}
 67
 68static inline void ndesc_end_tx_desc_on_ring(struct dma_desc *p, int end)
 69{
 70	if (end)
 71		p->des1 |= cpu_to_le32(TDES1_END_RING);
 72	else
 73		p->des1 &= cpu_to_le32(~TDES1_END_RING);
 74}
 75
 76static inline void norm_set_tx_desc_len_on_ring(struct dma_desc *p, int len)
 
 
 
 
 
 77{
 78	if (unlikely(len > BUF_SIZE_2KiB)) {
 79		unsigned int buffer1 = (BUF_SIZE_2KiB - 1)
 80					& TDES1_BUFFER1_SIZE_MASK;
 81		p->des1 |= cpu_to_le32((((len - buffer1)
 82					<< TDES1_BUFFER2_SIZE_SHIFT)
 83				& TDES1_BUFFER2_SIZE_MASK) | buffer1);
 84	} else
 85		p->des1 |= cpu_to_le32((len & TDES1_BUFFER1_SIZE_MASK));
 86}
 87
 88/* Specific functions used for Chain mode */
 
 
 
 
 
 
 
 
 
 
 89
 90/* Enhanced descriptors */
 91static inline void ehn_desc_rx_set_on_chain(struct dma_desc *p)
 92{
 93	p->des1 |= cpu_to_le32(ERDES1_SECOND_ADDRESS_CHAINED);
 94}
 95
 96static inline void enh_desc_end_tx_desc_on_chain(struct dma_desc *p)
 97{
 98	p->des0 |= cpu_to_le32(ETDES0_SECOND_ADDRESS_CHAINED);
 99}
100
101static inline void enh_set_tx_desc_len_on_chain(struct dma_desc *p, int len)
102{
103	p->des1 |= cpu_to_le32(len & ETDES1_BUFFER1_SIZE_MASK);
104}
105
106/* Normal descriptors */
107static inline void ndesc_rx_set_on_chain(struct dma_desc *p, int end)
108{
109	p->des1 |= cpu_to_le32(RDES1_SECOND_ADDRESS_CHAINED);
110}
111
112static inline void ndesc_tx_set_on_chain(struct dma_desc *p)
113{
114	p->des1 |= cpu_to_le32(TDES1_SECOND_ADDRESS_CHAINED);
115}
116
117static inline void norm_set_tx_desc_len_on_chain(struct dma_desc *p, int len)
118{
119	p->des1 |= cpu_to_le32(len & TDES1_BUFFER1_SIZE_MASK);
120}
121#endif /* __DESC_COM_H__ */
v3.5.6
 
  1/*******************************************************************************
  2  Header File to describe Normal/enhanced descriptor functions used for RING
  3  and CHAINED modes.
  4
  5  Copyright(C) 2011  STMicroelectronics Ltd
  6
  7  It defines all the functions used to handle the normal/enhanced
  8  descriptors in case of the DMA is configured to work in chained or
  9  in ring mode.
 10
 11  This program is free software; you can redistribute it and/or modify it
 12  under the terms and conditions of the GNU General Public License,
 13  version 2, as published by the Free Software Foundation.
 14
 15  This program is distributed in the hope it will be useful, but WITHOUT
 16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 17  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 18  more details.
 19
 20  You should have received a copy of the GNU General Public License along with
 21  this program; if not, write to the Free Software Foundation, Inc.,
 22  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
 23
 24  The full GNU General Public License is included in this distribution in
 25  the file called "COPYING".
 26
 27  Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
 28*******************************************************************************/
 29
 30#if defined(CONFIG_STMMAC_RING)
 31static inline void ehn_desc_rx_set_on_ring_chain(struct dma_desc *p, int end)
 32{
 33	p->des01.erx.buffer2_size = BUF_SIZE_8KiB - 1;
 
 
 
 
 
 
 
 
 
 
 34	if (end)
 35		p->des01.erx.end_ring = 1;
 36}
 37
 38static inline void ehn_desc_tx_set_on_ring_chain(struct dma_desc *p, int end)
 39{
 40	if (end)
 41		p->des01.etx.end_ring = 1;
 
 
 42}
 43
 44static inline void enh_desc_end_tx_desc(struct dma_desc *p, int ter)
 45{
 46	p->des01.etx.end_ring = ter;
 47}
 48
 49static inline void enh_set_tx_desc_len(struct dma_desc *p, int len)
 50{
 51	if (unlikely(len > BUF_SIZE_4KiB)) {
 52		p->des01.etx.buffer1_size = BUF_SIZE_4KiB;
 53		p->des01.etx.buffer2_size = len - BUF_SIZE_4KiB;
 
 
 54	} else
 55		p->des01.etx.buffer1_size = len;
 56}
 57
 58static inline void ndesc_rx_set_on_ring_chain(struct dma_desc *p, int end)
 
 59{
 60	p->des01.rx.buffer2_size = BUF_SIZE_2KiB - 1;
 
 
 
 
 
 
 
 61	if (end)
 62		p->des01.rx.end_ring = 1;
 63}
 64
 65static inline void ndesc_tx_set_on_ring_chain(struct dma_desc *p, int end)
 66{
 67	if (end)
 68		p->des01.tx.end_ring = 1;
 
 
 69}
 70
 71static inline void ndesc_end_tx_desc(struct dma_desc *p, int ter)
 72{
 73	p->des01.tx.end_ring = ter;
 74}
 75
 76static inline void norm_set_tx_desc_len(struct dma_desc *p, int len)
 77{
 78	if (unlikely(len > BUF_SIZE_2KiB)) {
 79		p->des01.etx.buffer1_size = BUF_SIZE_2KiB - 1;
 80		p->des01.etx.buffer2_size = len - p->des01.etx.buffer1_size;
 
 
 
 81	} else
 82		p->des01.tx.buffer1_size = len;
 83}
 84
 85#else
 86
 87static inline void ehn_desc_rx_set_on_ring_chain(struct dma_desc *p, int end)
 88{
 89	p->des01.erx.second_address_chained = 1;
 90}
 91
 92static inline void ehn_desc_tx_set_on_ring_chain(struct dma_desc *p, int end)
 93{
 94	p->des01.etx.second_address_chained = 1;
 95}
 96
 97static inline void enh_desc_end_tx_desc(struct dma_desc *p, int ter)
 
 98{
 99	p->des01.etx.second_address_chained = 1;
100}
101
102static inline void enh_set_tx_desc_len(struct dma_desc *p, int len)
103{
104	p->des01.etx.buffer1_size = len;
105}
106
107static inline void ndesc_rx_set_on_ring_chain(struct dma_desc *p, int end)
108{
109	p->des01.rx.second_address_chained = 1;
110}
111
112static inline void ndesc_tx_set_on_ring_chain(struct dma_desc *p, int ring_size)
 
113{
114	p->des01.tx.second_address_chained = 1;
115}
116
117static inline void ndesc_end_tx_desc(struct dma_desc *p, int ter)
118{
119	p->des01.tx.second_address_chained = 1;
120}
121
122static inline void norm_set_tx_desc_len(struct dma_desc *p, int len)
123{
124	p->des01.tx.buffer1_size = len;
125}
126#endif