Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (C) 2014 Texas Instruments Incorporated
0004  * Authors: Sandeep Nair <sandeep_n@ti.com
0005  *      Cyril Chemparathy <cyril@ti.com
0006         Santosh Shilimkar <santosh.shilimkar@ti.com>
0007  */
0008 
0009 #ifndef __SOC_TI_KEYSTONE_NAVIGATOR_DMA_H__
0010 #define __SOC_TI_KEYSTONE_NAVIGATOR_DMA_H__
0011 
0012 #include <linux/dmaengine.h>
0013 
0014 /*
0015  * PKTDMA descriptor manipulation macros for host packet descriptor
0016  */
0017 #define MASK(x)                 (BIT(x) - 1)
0018 #define KNAV_DMA_DESC_PKT_LEN_MASK      MASK(22)
0019 #define KNAV_DMA_DESC_PKT_LEN_SHIFT     0
0020 #define KNAV_DMA_DESC_PS_INFO_IN_SOP        BIT(22)
0021 #define KNAV_DMA_DESC_PS_INFO_IN_DESC       0
0022 #define KNAV_DMA_DESC_TAG_MASK          MASK(8)
0023 #define KNAV_DMA_DESC_SAG_HI_SHIFT      24
0024 #define KNAV_DMA_DESC_STAG_LO_SHIFT     16
0025 #define KNAV_DMA_DESC_DTAG_HI_SHIFT     8
0026 #define KNAV_DMA_DESC_DTAG_LO_SHIFT     0
0027 #define KNAV_DMA_DESC_HAS_EPIB          BIT(31)
0028 #define KNAV_DMA_DESC_NO_EPIB           0
0029 #define KNAV_DMA_DESC_PSLEN_SHIFT       24
0030 #define KNAV_DMA_DESC_PSLEN_MASK        MASK(6)
0031 #define KNAV_DMA_DESC_ERR_FLAG_SHIFT        20
0032 #define KNAV_DMA_DESC_ERR_FLAG_MASK     MASK(4)
0033 #define KNAV_DMA_DESC_PSFLAG_SHIFT      16
0034 #define KNAV_DMA_DESC_PSFLAG_MASK       MASK(4)
0035 #define KNAV_DMA_DESC_RETQ_SHIFT        0
0036 #define KNAV_DMA_DESC_RETQ_MASK         MASK(14)
0037 #define KNAV_DMA_DESC_BUF_LEN_MASK      MASK(22)
0038 #define KNAV_DMA_DESC_EFLAGS_MASK       MASK(4)
0039 #define KNAV_DMA_DESC_EFLAGS_SHIFT      20
0040 
0041 #define KNAV_DMA_NUM_EPIB_WORDS         4
0042 #define KNAV_DMA_NUM_PS_WORDS           16
0043 #define KNAV_DMA_NUM_SW_DATA_WORDS      4
0044 #define KNAV_DMA_FDQ_PER_CHAN           4
0045 
0046 /* Tx channel scheduling priority */
0047 enum knav_dma_tx_priority {
0048     DMA_PRIO_HIGH   = 0,
0049     DMA_PRIO_MED_H,
0050     DMA_PRIO_MED_L,
0051     DMA_PRIO_LOW
0052 };
0053 
0054 /* Rx channel error handling mode during buffer starvation */
0055 enum knav_dma_rx_err_mode {
0056     DMA_DROP = 0,
0057     DMA_RETRY
0058 };
0059 
0060 /* Rx flow size threshold configuration */
0061 enum knav_dma_rx_thresholds {
0062     DMA_THRESH_NONE     = 0,
0063     DMA_THRESH_0        = 1,
0064     DMA_THRESH_0_1      = 3,
0065     DMA_THRESH_0_1_2    = 7
0066 };
0067 
0068 /* Descriptor type */
0069 enum knav_dma_desc_type {
0070     DMA_DESC_HOST = 0,
0071     DMA_DESC_MONOLITHIC = 2
0072 };
0073 
0074 /**
0075  * struct knav_dma_tx_cfg:  Tx channel configuration
0076  * @filt_einfo:         Filter extended packet info
0077  * @filt_pswords:       Filter PS words present
0078  * @knav_dma_tx_priority:   Tx channel scheduling priority
0079  */
0080 struct knav_dma_tx_cfg {
0081     bool                filt_einfo;
0082     bool                filt_pswords;
0083     enum knav_dma_tx_priority   priority;
0084 };
0085 
0086 /**
0087  * struct knav_dma_rx_cfg:  Rx flow configuration
0088  * @einfo_present:      Extended packet info present
0089  * @psinfo_present:     PS words present
0090  * @knav_dma_rx_err_mode:   Error during buffer starvation
0091  * @knav_dma_desc_type: Host or Monolithic desc
0092  * @psinfo_at_sop:      PS word located at start of packet
0093  * @sop_offset:         Start of packet offset
0094  * @dst_q:          Destination queue for a given flow
0095  * @thresh:         Rx flow size threshold
0096  * @fdq[]:          Free desc Queue array
0097  * @sz_thresh0:         RX packet size threshold 0
0098  * @sz_thresh1:         RX packet size threshold 1
0099  * @sz_thresh2:         RX packet size threshold 2
0100  */
0101 struct knav_dma_rx_cfg {
0102     bool                einfo_present;
0103     bool                psinfo_present;
0104     enum knav_dma_rx_err_mode   err_mode;
0105     enum knav_dma_desc_type     desc_type;
0106     bool                psinfo_at_sop;
0107     unsigned int            sop_offset;
0108     unsigned int            dst_q;
0109     enum knav_dma_rx_thresholds thresh;
0110     unsigned int            fdq[KNAV_DMA_FDQ_PER_CHAN];
0111     unsigned int            sz_thresh0;
0112     unsigned int            sz_thresh1;
0113     unsigned int            sz_thresh2;
0114 };
0115 
0116 /**
0117  * struct knav_dma_cfg: Pktdma channel configuration
0118  * @sl_cfg:         Slave configuration
0119  * @tx:             Tx channel configuration
0120  * @rx:             Rx flow configuration
0121  */
0122 struct knav_dma_cfg {
0123     enum dma_transfer_direction direction;
0124     union {
0125         struct knav_dma_tx_cfg  tx;
0126         struct knav_dma_rx_cfg  rx;
0127     } u;
0128 };
0129 
0130 /**
0131  * struct knav_dma_desc:    Host packet descriptor layout
0132  * @desc_info:          Descriptor information like id, type, length
0133  * @tag_info:           Flow tag info written in during RX
0134  * @packet_info:        Queue Manager, policy, flags etc
0135  * @buff_len:           Buffer length in bytes
0136  * @buff:           Buffer pointer
0137  * @next_desc:          For chaining the descriptors
0138  * @orig_len:           length since 'buff_len' can be overwritten
0139  * @orig_buff:          buff pointer since 'buff' can be overwritten
0140  * @epib:           Extended packet info block
0141  * @psdata:         Protocol specific
0142  * @sw_data:            Software private data not touched by h/w
0143  */
0144 struct knav_dma_desc {
0145     __le32  desc_info;
0146     __le32  tag_info;
0147     __le32  packet_info;
0148     __le32  buff_len;
0149     __le32  buff;
0150     __le32  next_desc;
0151     __le32  orig_len;
0152     __le32  orig_buff;
0153     __le32  epib[KNAV_DMA_NUM_EPIB_WORDS];
0154     __le32  psdata[KNAV_DMA_NUM_PS_WORDS];
0155     u32 sw_data[KNAV_DMA_NUM_SW_DATA_WORDS];
0156 } ____cacheline_aligned;
0157 
0158 #if IS_ENABLED(CONFIG_KEYSTONE_NAVIGATOR_DMA)
0159 void *knav_dma_open_channel(struct device *dev, const char *name,
0160                 struct knav_dma_cfg *config);
0161 void knav_dma_close_channel(void *channel);
0162 int knav_dma_get_flow(void *channel);
0163 bool knav_dma_device_ready(void);
0164 #else
0165 static inline void *knav_dma_open_channel(struct device *dev, const char *name,
0166                 struct knav_dma_cfg *config)
0167 {
0168     return (void *) NULL;
0169 }
0170 static inline void knav_dma_close_channel(void *channel)
0171 {}
0172 
0173 static inline int knav_dma_get_flow(void *channel)
0174 {
0175     return -EINVAL;
0176 }
0177 
0178 static inline bool knav_dma_device_ready(void)
0179 {
0180     return false;
0181 }
0182 
0183 #endif
0184 
0185 #endif /* __SOC_TI_KEYSTONE_NAVIGATOR_DMA_H__ */