Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*******************************************************************************
0003   Header File to describe Normal/enhanced descriptor functions used for RING
0004   and CHAINED modes.
0005 
0006   Copyright(C) 2011  STMicroelectronics Ltd
0007 
0008   It defines all the functions used to handle the normal/enhanced
0009   descriptors in case of the DMA is configured to work in chained or
0010   in ring mode.
0011 
0012 
0013   Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
0014 *******************************************************************************/
0015 
0016 #ifndef __DESC_COM_H__
0017 #define __DESC_COM_H__
0018 
0019 /* Specific functions used for Ring mode */
0020 
0021 /* Enhanced descriptors */
0022 static inline void ehn_desc_rx_set_on_ring(struct dma_desc *p, int end,
0023                        int bfsize)
0024 {
0025     if (bfsize == BUF_SIZE_16KiB)
0026         p->des1 |= cpu_to_le32((BUF_SIZE_8KiB
0027                 << ERDES1_BUFFER2_SIZE_SHIFT)
0028                & ERDES1_BUFFER2_SIZE_MASK);
0029 
0030     if (end)
0031         p->des1 |= cpu_to_le32(ERDES1_END_RING);
0032 }
0033 
0034 static inline void enh_desc_end_tx_desc_on_ring(struct dma_desc *p, int end)
0035 {
0036     if (end)
0037         p->des0 |= cpu_to_le32(ETDES0_END_RING);
0038     else
0039         p->des0 &= cpu_to_le32(~ETDES0_END_RING);
0040 }
0041 
0042 static inline void enh_set_tx_desc_len_on_ring(struct dma_desc *p, int len)
0043 {
0044     if (unlikely(len > BUF_SIZE_4KiB)) {
0045         p->des1 |= cpu_to_le32((((len - BUF_SIZE_4KiB)
0046                     << ETDES1_BUFFER2_SIZE_SHIFT)
0047                 & ETDES1_BUFFER2_SIZE_MASK) | (BUF_SIZE_4KiB
0048                 & ETDES1_BUFFER1_SIZE_MASK));
0049     } else
0050         p->des1 |= cpu_to_le32((len & ETDES1_BUFFER1_SIZE_MASK));
0051 }
0052 
0053 /* Normal descriptors */
0054 static inline void ndesc_rx_set_on_ring(struct dma_desc *p, int end, int bfsize)
0055 {
0056     if (bfsize >= BUF_SIZE_2KiB) {
0057         int bfsize2;
0058 
0059         bfsize2 = min(bfsize - BUF_SIZE_2KiB + 1, BUF_SIZE_2KiB - 1);
0060         p->des1 |= cpu_to_le32((bfsize2 << RDES1_BUFFER2_SIZE_SHIFT)
0061                 & RDES1_BUFFER2_SIZE_MASK);
0062     }
0063 
0064     if (end)
0065         p->des1 |= cpu_to_le32(RDES1_END_RING);
0066 }
0067 
0068 static inline void ndesc_end_tx_desc_on_ring(struct dma_desc *p, int end)
0069 {
0070     if (end)
0071         p->des1 |= cpu_to_le32(TDES1_END_RING);
0072     else
0073         p->des1 &= cpu_to_le32(~TDES1_END_RING);
0074 }
0075 
0076 static inline void norm_set_tx_desc_len_on_ring(struct dma_desc *p, int len)
0077 {
0078     if (unlikely(len > BUF_SIZE_2KiB)) {
0079         unsigned int buffer1 = (BUF_SIZE_2KiB - 1)
0080                     & TDES1_BUFFER1_SIZE_MASK;
0081         p->des1 |= cpu_to_le32((((len - buffer1)
0082                     << TDES1_BUFFER2_SIZE_SHIFT)
0083                 & TDES1_BUFFER2_SIZE_MASK) | buffer1);
0084     } else
0085         p->des1 |= cpu_to_le32((len & TDES1_BUFFER1_SIZE_MASK));
0086 }
0087 
0088 /* Specific functions used for Chain mode */
0089 
0090 /* Enhanced descriptors */
0091 static inline void ehn_desc_rx_set_on_chain(struct dma_desc *p)
0092 {
0093     p->des1 |= cpu_to_le32(ERDES1_SECOND_ADDRESS_CHAINED);
0094 }
0095 
0096 static inline void enh_desc_end_tx_desc_on_chain(struct dma_desc *p)
0097 {
0098     p->des0 |= cpu_to_le32(ETDES0_SECOND_ADDRESS_CHAINED);
0099 }
0100 
0101 static inline void enh_set_tx_desc_len_on_chain(struct dma_desc *p, int len)
0102 {
0103     p->des1 |= cpu_to_le32(len & ETDES1_BUFFER1_SIZE_MASK);
0104 }
0105 
0106 /* Normal descriptors */
0107 static inline void ndesc_rx_set_on_chain(struct dma_desc *p, int end)
0108 {
0109     p->des1 |= cpu_to_le32(RDES1_SECOND_ADDRESS_CHAINED);
0110 }
0111 
0112 static inline void ndesc_tx_set_on_chain(struct dma_desc *p)
0113 {
0114     p->des1 |= cpu_to_le32(TDES1_SECOND_ADDRESS_CHAINED);
0115 }
0116 
0117 static inline void norm_set_tx_desc_len_on_chain(struct dma_desc *p, int len)
0118 {
0119     p->des1 |= cpu_to_le32(len & TDES1_BUFFER1_SIZE_MASK);
0120 }
0121 #endif /* __DESC_COM_H__ */