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#ifndef __DESC_COM_H__ 31#define __DESC_COM_H__ 32 33/* Specific functions used for Ring mode */ 34 35/* Enhanced descriptors */ 36static inline void ehn_desc_rx_set_on_ring(struct dma_desc *p, int end) 37{ 38 p->des01.erx.buffer2_size = BUF_SIZE_8KiB - 1; 39 if (end) 40 p->des01.erx.end_ring = 1; 41} 42 43static inline void ehn_desc_tx_set_on_ring(struct dma_desc *p, int end) 44{ 45 if (end) 46 p->des01.etx.end_ring = 1; 47} 48 49static inline void enh_desc_end_tx_desc_on_ring(struct dma_desc *p, int ter) 50{ 51 p->des01.etx.end_ring = ter; 52} 53 54static inline void enh_set_tx_desc_len_on_ring(struct dma_desc *p, int len) 55{ 56 if (unlikely(len > BUF_SIZE_4KiB)) { 57 p->des01.etx.buffer1_size = BUF_SIZE_4KiB; 58 p->des01.etx.buffer2_size = len - BUF_SIZE_4KiB; 59 } else 60 p->des01.etx.buffer1_size = len; 61} 62 63/* Normal descriptors */ 64static inline void ndesc_rx_set_on_ring(struct dma_desc *p, int end) 65{ 66 p->des01.rx.buffer2_size = BUF_SIZE_2KiB - 1; 67 if (end) 68 p->des01.rx.end_ring = 1; 69} 70 71static inline void ndesc_tx_set_on_ring(struct dma_desc *p, int end) 72{ 73 if (end) 74 p->des01.tx.end_ring = 1; 75} 76 77static inline void ndesc_end_tx_desc_on_ring(struct dma_desc *p, int ter) 78{ 79 p->des01.tx.end_ring = ter; 80} 81 82static inline void norm_set_tx_desc_len_on_ring(struct dma_desc *p, int len) 83{ 84 if (unlikely(len > BUF_SIZE_2KiB)) { 85 p->des01.etx.buffer1_size = BUF_SIZE_2KiB - 1; 86 p->des01.etx.buffer2_size = len - p->des01.etx.buffer1_size; 87 } else 88 p->des01.tx.buffer1_size = len; 89} 90 91/* Specific functions used for Chain mode */ 92 93/* Enhanced descriptors */ 94static inline void ehn_desc_rx_set_on_chain(struct dma_desc *p, int end) 95{ 96 p->des01.erx.second_address_chained = 1; 97} 98 99static inline void ehn_desc_tx_set_on_chain(struct dma_desc *p, int end) 100{ 101 p->des01.etx.second_address_chained = 1; 102} 103 104static inline void enh_desc_end_tx_desc_on_chain(struct dma_desc *p, int ter) 105{ 106 p->des01.etx.second_address_chained = 1; 107} 108 109static inline void enh_set_tx_desc_len_on_chain(struct dma_desc *p, int len) 110{ 111 p->des01.etx.buffer1_size = len; 112} 113 114/* Normal descriptors */ 115static inline void ndesc_rx_set_on_chain(struct dma_desc *p, int end) 116{ 117 p->des01.rx.second_address_chained = 1; 118} 119 120static inline void ndesc_tx_set_on_chain(struct dma_desc *p, int ring_size) 121{ 122 p->des01.tx.second_address_chained = 1; 123} 124 125static inline void ndesc_end_tx_desc_on_chain(struct dma_desc *p, int ter) 126{ 127 p->des01.tx.second_address_chained = 1; 128} 129 130static inline void norm_set_tx_desc_len_on_chain(struct dma_desc *p, int len) 131{ 132 p->des01.tx.buffer1_size = len; 133} 134#endif /* __DESC_COM_H__ */ 135