Re: [PATCH v2 10/14] dmaengine: ti: New driver for K3 UDMA - split#3: alloc/free chan_resources
From: Peter Ujfalusi
Date: Tue Sep 10 2019 - 03:52:58 EST
On 10/09/2019 10.25, Grygorii Strashko wrote:
>
>
> On 30/07/2019 12:34, Peter Ujfalusi wrote:
>> Split patch for review containing: channel rsource allocation and free
>> functions.
>>
>> DMA driver for
>> Texas Instruments K3 NAVSS Unified DMA â Peripheral Root Complex (UDMA-P)
>>
>> The UDMA-P is intended to perform similar (but significantly upgraded)
>> functions
>> as the packet-oriented DMA used on previous SoC devices. The UDMA-P
>> module
>> supports the transmission and reception of various packet types. The
>> UDMA-P is
>> architected to facilitate the segmentation and reassembly of SoC DMA data
>> structure compliant packets to/from smaller data blocks that are natively
>> compatible with the specific requirements of each connected
>> peripheral. Multiple
>> Tx and Rx channels are provided within the DMA which allow multiple
>> segmentation
>> or reassembly operations to be ongoing. The DMA controller maintains
>> state
>> information for each of the channels which allows packet segmentation and
>> reassembly operations to be time division multiplexed between channels
>> in order
>> to share the underlying DMA hardware. An external DMA scheduler is
>> used to
>> control the ordering and rate at which this multiplexing occurs for
>> Transmit
>> operations. The ordering and rate of Receive operations is indirectly
>> controlled
>> by the order in which blocks are pushed into the DMA on the Rx PSI-L
>> interface.
>>
>> The UDMA-P also supports acting as both a UTC and UDMA-C for its internal
>> channels. Channels in the UDMA-P can be configured to be either
>> Packet-Based or
>> Third-Party channels on a channel by channel basis.
>>
>> The initial driver supports:
>> - MEM_TO_MEM (TR mode)
>> - DEV_TO_MEM (Packet / TR mode)
>> - MEM_TO_DEV (Packet / TR mode)
>> - Cyclic (Packet / TR mode)
>> - Metadata for descriptors
>>
>> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@xxxxxx>
>> ---
>> Â drivers/dma/ti/k3-udma.c | 780 +++++++++++++++++++++++++++++++++++++++
>> Â 1 file changed, 780 insertions(+)
>>
>> diff --git a/drivers/dma/ti/k3-udma.c b/drivers/dma/ti/k3-udma.c
>> index 52ccc6d46de9..0de38db03b8d 100644
>> --- a/drivers/dma/ti/k3-udma.c
>> +++ b/drivers/dma/ti/k3-udma.c
>> @@ -1039,6 +1039,786 @@ static irqreturn_t udma_udma_irq_handler(int
>> irq, void *data)
>> ÂÂÂÂÂ return IRQ_HANDLED;
>> Â }
>> Â +static struct udma_rflow *__udma_reserve_rflow(struct udma_dev *ud,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ enum udma_tp_level tpl, int id)
>> +{
>> +ÂÂÂ DECLARE_BITMAP(tmp, K3_UDMA_MAX_RFLOWS);
>> +
>> +ÂÂÂ if (id >= 0) {
>> +ÂÂÂÂÂÂÂ if (test_bit(id, ud->rflow_map)) {
>> +ÂÂÂÂÂÂÂÂÂÂÂ dev_err(ud->dev, "rflow%d is in use\n", id);
>> +ÂÂÂÂÂÂÂÂÂÂÂ return ERR_PTR(-ENOENT);
>> +ÂÂÂÂÂÂÂ }
>> +ÂÂÂ } else {
>> +ÂÂÂÂÂÂÂ bitmap_or(tmp, ud->rflow_map, ud->rflow_map_reserved,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂ ud->rflow_cnt);
>> +
>> +ÂÂÂÂÂÂÂ id = find_next_zero_bit(tmp, ud->rflow_cnt, ud->rchan_cnt);
>> +ÂÂÂÂÂÂÂ if (id >= ud->rflow_cnt)
>> +ÂÂÂÂÂÂÂÂÂÂÂ return ERR_PTR(-ENOENT);
>> +ÂÂÂ }
>> +
>> +ÂÂÂ set_bit(id, ud->rflow_map);
>> +ÂÂÂ return &ud->rflows[id];
>> +}
>> +
>> +#define UDMA_RESERVE_RESOURCE(res)ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>> +static struct udma_##res *__udma_reserve_##res(struct udma_dev *ud,ÂÂÂ \
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ enum udma_tp_level tpl,ÂÂÂ \
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ int id)ÂÂÂÂÂÂÂÂÂÂÂ \
>> +{ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>> +ÂÂÂ if (id >= 0) {ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>> +ÂÂÂÂÂÂÂ if (test_bit(id, ud->res##_map)) {ÂÂÂÂÂÂÂÂÂÂÂ \
>> +ÂÂÂÂÂÂÂÂÂÂÂ dev_err(ud->dev, "res##%d is in use\n", id);ÂÂÂ \
>> +ÂÂÂÂÂÂÂÂÂÂÂ return ERR_PTR(-ENOENT);ÂÂÂÂÂÂÂÂÂÂÂ \
>> +ÂÂÂÂÂÂÂ }ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>> +ÂÂÂ } else {ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>> +ÂÂÂÂÂÂÂ int start;ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>> +ÂÂÂÂÂÂÂ if (tpl >= ud->match_data->tpl_levels)ÂÂÂÂÂÂÂÂÂÂÂ \
>> +ÂÂÂÂÂÂÂÂÂÂÂ tpl = ud->match_data->tpl_levels - 1;ÂÂÂÂÂÂÂ \
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>> +ÂÂÂÂÂÂÂ start = ud->match_data->level_start_idx[tpl];ÂÂÂÂÂÂÂ \
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>> +ÂÂÂÂÂÂÂ id = find_next_zero_bit(ud->res##_map, ud->res##_cnt,ÂÂÂ \
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ start);ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>> +ÂÂÂÂÂÂÂ if (id == ud->res##_cnt) {ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>> +ÂÂÂÂÂÂÂÂÂÂÂ return ERR_PTR(-ENOENT);ÂÂÂÂÂÂÂÂÂÂÂ \
>> +ÂÂÂÂÂÂÂ }ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>> +ÂÂÂ }ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>> +ÂÂÂ set_bit(id, ud->res##_map);ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>> +ÂÂÂ return &ud->res##s[id];ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ \
>> +}
>> +
>> +UDMA_RESERVE_RESOURCE(tchan);
>> +UDMA_RESERVE_RESOURCE(rchan);
>
> Personally I'm not a fan of such a big macro, wouldn't be static
> functions better.
The other option is to have two identical function with only difference
is s/tchan/rchan.
>
>> +
>> +static int udma_get_tchan(struct udma_chan *uc)
>> +{
>> +ÂÂÂ struct udma_dev *ud = uc->ud;
>> +
>> +ÂÂÂ if (uc->tchan) {
>> +ÂÂÂÂÂÂÂ dev_dbg(ud->dev, "chan%d: already have tchan%d allocated\n",
>> +ÂÂÂÂÂÂÂÂÂÂÂ uc->id, uc->tchan->id);
>> +ÂÂÂÂÂÂÂ return 0;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ uc->tchan = __udma_reserve_tchan(ud, uc->channel_tpl, -1);
>> +ÂÂÂ if (IS_ERR(uc->tchan))
>> +ÂÂÂÂÂÂÂ return PTR_ERR(uc->tchan);
>> +
>> +ÂÂÂ return 0;
>> +}
>> +
>
> [...]
>
>> +
>> +static int udma_tisci_channel_config(struct udma_chan *uc)
>> +{
>> +ÂÂÂ struct udma_dev *ud = uc->ud;
>> +ÂÂÂ struct udma_tisci_rm *tisci_rm = &ud->tisci_rm;
>> +ÂÂÂ const struct ti_sci_rm_udmap_ops *tisci_ops =
>> tisci_rm->tisci_udmap_ops;
>> +ÂÂÂ struct udma_tchan *tchan = uc->tchan;
>> +ÂÂÂ struct udma_rchan *rchan = uc->rchan;
>> +ÂÂÂ int ret = 0;
>> +
>> +ÂÂÂ if (uc->dir == DMA_MEM_TO_MEM) {
>> +ÂÂÂÂÂÂÂ /* Non synchronized - mem to mem type of transfer */
>> +ÂÂÂÂÂÂÂ int tc_ring = k3_ringacc_get_ring_id(tchan->tc_ring);
>> +ÂÂÂÂÂÂÂ struct ti_sci_msg_rm_udmap_tx_ch_cfg req_tx = { 0 };
>> +ÂÂÂÂÂÂÂ struct ti_sci_msg_rm_udmap_rx_ch_cfg req_rx = { 0 };
>> +
>> +ÂÂÂÂÂÂÂ req_tx.valid_params =
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_CH_PAUSE_ON_ERR_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_CH_TX_FILT_EINFO_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_CH_TX_FILT_PSWORDS_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_CH_CHAN_TYPE_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_CH_TX_SUPR_TDPKT_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_CH_FETCH_SIZE_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_CH_CQ_QNUM_VALID;
>> +
>> +ÂÂÂÂÂÂÂ req_tx.nav_id = tisci_rm->tisci_dev_id;
>> +ÂÂÂÂÂÂÂ req_tx.index = tchan->id;
>> +ÂÂÂÂÂÂÂ req_tx.tx_pause_on_err = 0;
>> +ÂÂÂÂÂÂÂ req_tx.tx_filt_einfo = 0;
>> +ÂÂÂÂÂÂÂ req_tx.tx_filt_pswords = 0;
>> +ÂÂÂÂÂÂÂ req_tx.tx_chan_type = TI_SCI_RM_UDMAP_CHAN_TYPE_3RDP_BCOPY_PBRR;
>> +ÂÂÂÂÂÂÂ req_tx.tx_supr_tdpkt = 0;
>> +ÂÂÂÂÂÂÂ req_tx.tx_fetch_size = sizeof(struct cppi5_desc_hdr_t) >> 2;
>> +ÂÂÂÂÂÂÂ req_tx.txcq_qnum = tc_ring;
>> +
>> +ÂÂÂÂÂÂÂ ret = tisci_ops->tx_ch_cfg(tisci_rm->tisci, &req_tx);
>> +ÂÂÂÂÂÂÂ if (ret) {
>> +ÂÂÂÂÂÂÂÂÂÂÂ dev_err(ud->dev, "tchan%d cfg failed %d\n",
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ tchan->id, ret);
>> +ÂÂÂÂÂÂÂÂÂÂÂ return ret;
>> +ÂÂÂÂÂÂÂ }
>> +
>> +ÂÂÂÂÂÂÂ req_rx.valid_params =
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_CH_PAUSE_ON_ERR_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_CH_FETCH_SIZE_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_CH_CQ_QNUM_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_CH_CHAN_TYPE_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_CH_RX_IGNORE_SHORT_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_CH_RX_IGNORE_LONG_VALID;
>> +
>> +ÂÂÂÂÂÂÂ req_rx.nav_id = tisci_rm->tisci_dev_id;
>> +ÂÂÂÂÂÂÂ req_rx.index = rchan->id;
>> +ÂÂÂÂÂÂÂ req_rx.rx_fetch_size = sizeof(struct cppi5_desc_hdr_t) >> 2;
>> +ÂÂÂÂÂÂÂ req_rx.rxcq_qnum = tc_ring;
>> +ÂÂÂÂÂÂÂ req_rx.rx_pause_on_err = 0;
>> +ÂÂÂÂÂÂÂ req_rx.rx_chan_type = TI_SCI_RM_UDMAP_CHAN_TYPE_3RDP_BCOPY_PBRR;
>> +ÂÂÂÂÂÂÂ req_rx.rx_ignore_short = 0;
>> +ÂÂÂÂÂÂÂ req_rx.rx_ignore_long = 0;
>> +
>> +ÂÂÂÂÂÂÂ ret = tisci_ops->rx_ch_cfg(tisci_rm->tisci, &req_rx);
>> +ÂÂÂÂÂÂÂ if (ret) {
>> +ÂÂÂÂÂÂÂÂÂÂÂ dev_err(ud->dev, "rchan%d alloc failed %d\n",
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ rchan->id, ret);
>> +ÂÂÂÂÂÂÂÂÂÂÂ return ret;
>> +ÂÂÂÂÂÂÂ }
>> +ÂÂÂ } else {
>> +ÂÂÂÂÂÂÂ /* Slave transfer */
>> +ÂÂÂÂÂÂÂ u32 mode, fetch_size;
>> +
>> +ÂÂÂÂÂÂÂ if (uc->pkt_mode) {
>> +ÂÂÂÂÂÂÂÂÂÂÂ mode = TI_SCI_RM_UDMAP_CHAN_TYPE_PKT_PBRR;
>> +ÂÂÂÂÂÂÂÂÂÂÂ fetch_size = cppi5_hdesc_calc_size(uc->needs_epib,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ uc->psd_size, 0);
>> +ÂÂÂÂÂÂÂ } else {
>> +ÂÂÂÂÂÂÂÂÂÂÂ mode = TI_SCI_RM_UDMAP_CHAN_TYPE_3RDP_PBRR;
>> +ÂÂÂÂÂÂÂÂÂÂÂ fetch_size = sizeof(struct cppi5_desc_hdr_t);
>> +ÂÂÂÂÂÂÂ }
>> +
>> +ÂÂÂÂÂÂÂ if (uc->dir == DMA_MEM_TO_DEV) {
>> +ÂÂÂÂÂÂÂÂÂÂÂ /* TX */
>> +ÂÂÂÂÂÂÂÂÂÂÂ int tc_ring = k3_ringacc_get_ring_id(tchan->tc_ring);
>> +ÂÂÂÂÂÂÂÂÂÂÂ struct ti_sci_msg_rm_udmap_tx_ch_cfg req_tx = { 0 };
>> +
>> +ÂÂÂÂÂÂÂÂÂÂÂ req_tx.valid_params =
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_CH_PAUSE_ON_ERR_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_CH_TX_FILT_EINFO_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_CH_TX_FILT_PSWORDS_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_CH_CHAN_TYPE_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_CH_TX_SUPR_TDPKT_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_CH_FETCH_SIZE_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_CH_CQ_QNUM_VALID;
>> +
>> +ÂÂÂÂÂÂÂÂÂÂÂ req_tx.nav_id = tisci_rm->tisci_dev_id;
>> +ÂÂÂÂÂÂÂÂÂÂÂ req_tx.index = tchan->id;
>> +ÂÂÂÂÂÂÂÂÂÂÂ req_tx.tx_pause_on_err = 0;
>> +ÂÂÂÂÂÂÂÂÂÂÂ req_tx.tx_filt_einfo = 0;
>> +ÂÂÂÂÂÂÂÂÂÂÂ req_tx.tx_filt_pswords = 0;
>> +ÂÂÂÂÂÂÂÂÂÂÂ req_tx.tx_chan_type = mode;
>> +ÂÂÂÂÂÂÂÂÂÂÂ req_tx.tx_supr_tdpkt = 0;
>> +ÂÂÂÂÂÂÂÂÂÂÂ req_tx.tx_fetch_size = fetch_size >> 2;
>> +ÂÂÂÂÂÂÂÂÂÂÂ req_tx.txcq_qnum = tc_ring;
>> +
>> +ÂÂÂÂÂÂÂÂÂÂÂ ret = tisci_ops->tx_ch_cfg(tisci_rm->tisci, &req_tx);
>> +ÂÂÂÂÂÂÂÂÂÂÂ if (ret) {
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ dev_err(ud->dev, "tchan%d cfg failed %d\n",
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ tchan->id, ret);
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return ret;
>> +ÂÂÂÂÂÂÂÂÂÂÂ }
>> +ÂÂÂÂÂÂÂ } else {
>> +ÂÂÂÂÂÂÂÂÂÂÂ /* RX */
>> +ÂÂÂÂÂÂÂÂÂÂÂ int fd_ring = k3_ringacc_get_ring_id(rchan->fd_ring);
>> +ÂÂÂÂÂÂÂÂÂÂÂ int rx_ring = k3_ringacc_get_ring_id(rchan->r_ring);
>> +ÂÂÂÂÂÂÂÂÂÂÂ struct ti_sci_msg_rm_udmap_rx_ch_cfg req_rx = { 0 };
>> +ÂÂÂÂÂÂÂÂÂÂÂ struct ti_sci_msg_rm_udmap_flow_cfg flow_req = { 0 };
>> +
>> +ÂÂÂÂÂÂÂÂÂÂÂ req_rx.valid_params =
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_CH_PAUSE_ON_ERR_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_CH_FETCH_SIZE_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_CH_CQ_QNUM_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_CH_CHAN_TYPE_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_CH_RX_IGNORE_SHORT_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_CH_RX_IGNORE_LONG_VALID;
>> +
>> +ÂÂÂÂÂÂÂÂÂÂÂ req_rx.nav_id = tisci_rm->tisci_dev_id;
>> +ÂÂÂÂÂÂÂÂÂÂÂ req_rx.index = rchan->id;
>> +ÂÂÂÂÂÂÂÂÂÂÂ req_rx.rx_fetch_size =Â fetch_size >> 2;
>> +ÂÂÂÂÂÂÂÂÂÂÂ req_rx.rxcq_qnum = rx_ring;
>> +ÂÂÂÂÂÂÂÂÂÂÂ req_rx.rx_pause_on_err = 0;
>> +ÂÂÂÂÂÂÂÂÂÂÂ req_rx.rx_chan_type = mode;
>> +ÂÂÂÂÂÂÂÂÂÂÂ req_rx.rx_ignore_short = 0;
>> +ÂÂÂÂÂÂÂÂÂÂÂ req_rx.rx_ignore_long = 0;
>> +
>> +ÂÂÂÂÂÂÂÂÂÂÂ ret = tisci_ops->rx_ch_cfg(tisci_rm->tisci, &req_rx);
>> +ÂÂÂÂÂÂÂÂÂÂÂ if (ret) {
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ dev_err(ud->dev, "rchan%d cfg failed %d\n",
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ rchan->id, ret);
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return ret;
>> +ÂÂÂÂÂÂÂÂÂÂÂ }
>> +
>> +ÂÂÂÂÂÂÂÂÂÂÂ flow_req.valid_params =
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_EINFO_PRESENT_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_PSINFO_PRESENT_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_ERROR_HANDLING_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_DESC_TYPE_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_DEST_QNUM_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_SRC_TAG_HI_SEL_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_SRC_TAG_LO_SEL_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_DEST_TAG_HI_SEL_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_DEST_TAG_LO_SEL_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_FDQ0_SZ0_QNUM_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_FDQ1_QNUM_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_FDQ2_QNUM_VALID |
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_FDQ3_QNUM_VALID;
>> +
>> +ÂÂÂÂÂÂÂÂÂÂÂ flow_req.nav_id = tisci_rm->tisci_dev_id;
>> +ÂÂÂÂÂÂÂÂÂÂÂ flow_req.flow_index = rchan->id;
>> +
>> +ÂÂÂÂÂÂÂÂÂÂÂ if (uc->needs_epib)
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ flow_req.rx_einfo_present = 1;
>> +ÂÂÂÂÂÂÂÂÂÂÂ else
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ flow_req.rx_einfo_present = 0;
>> +ÂÂÂÂÂÂÂÂÂÂÂ if (uc->psd_size)
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ flow_req.rx_psinfo_present = 1;
>> +ÂÂÂÂÂÂÂÂÂÂÂ else
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ flow_req.rx_psinfo_present = 0;
>> +ÂÂÂÂÂÂÂÂÂÂÂ flow_req.rx_error_handling = 1;
>> +ÂÂÂÂÂÂÂÂÂÂÂ flow_req.rx_desc_type = 0;
>> +ÂÂÂÂÂÂÂÂÂÂÂ flow_req.rx_dest_qnum = rx_ring;
>> +ÂÂÂÂÂÂÂÂÂÂÂ flow_req.rx_src_tag_hi_sel = 2;
>> +ÂÂÂÂÂÂÂÂÂÂÂ flow_req.rx_src_tag_lo_sel = 4;
>> +ÂÂÂÂÂÂÂÂÂÂÂ flow_req.rx_dest_tag_hi_sel = 5;
>> +ÂÂÂÂÂÂÂÂÂÂÂ flow_req.rx_dest_tag_lo_sel = 4;
>> +ÂÂÂÂÂÂÂÂÂÂÂ flow_req.rx_fdq0_sz0_qnum = fd_ring;
>> +ÂÂÂÂÂÂÂÂÂÂÂ flow_req.rx_fdq1_qnum = fd_ring;
>> +ÂÂÂÂÂÂÂÂÂÂÂ flow_req.rx_fdq2_qnum = fd_ring;
>> +ÂÂÂÂÂÂÂÂÂÂÂ flow_req.rx_fdq3_qnum = fd_ring;
>> +
>> +ÂÂÂÂÂÂÂÂÂÂÂ ret = tisci_ops->rx_flow_cfg(tisci_rm->tisci,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &flow_req);
>> +
>> +ÂÂÂÂÂÂÂÂÂÂÂ if (ret) {
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ dev_err(ud->dev, "flow%d config failed: %d\n",
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ rchan->id, ret);
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return ret;
>> +ÂÂÂÂÂÂÂÂÂÂÂ }
>> +ÂÂÂÂÂÂÂ }
>> +ÂÂÂ }
>> +
>> +ÂÂÂ return 0;
>> +}
>
> Could you split above big function pls?
I can slit to:
udma_tisci_m2m_channel_config()
udma_tisci_tx_channel_config()
udma_tisci_rx_channel_config()
and call them from the first switch case in udma_alloc_chan_resources()
>
>> +
>> +static int udma_alloc_chan_resources(struct dma_chan *chan)
>> +{
>> +ÂÂÂ struct udma_chan *uc = to_udma_chan(chan);
>> +ÂÂÂ struct udma_dev *ud = to_udma_dev(chan->device);
>> +ÂÂÂ const struct udma_match_data *match_data = ud->match_data;
>> +ÂÂÂ struct k3_ring *irq_ring;
>> +ÂÂÂ u32 irq_udma_idx;
>> +ÂÂÂ int ret;
>> +
>> +ÂÂÂ if (uc->pkt_mode || uc->dir == DMA_MEM_TO_MEM) {
>> +ÂÂÂÂÂÂÂ uc->use_dma_pool = true;
>> +ÂÂÂÂÂÂÂ /* in case of MEM_TO_MEM we have maximum of two TRs */
>> +ÂÂÂÂÂÂÂ if (uc->dir == DMA_MEM_TO_MEM) {
>> +ÂÂÂÂÂÂÂÂÂÂÂ uc->hdesc_size = cppi5_trdesc_calc_size(
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ sizeof(struct cppi5_tr_type15_t), 2);
>> +ÂÂÂÂÂÂÂÂÂÂÂ uc->pkt_mode = false;
>> +ÂÂÂÂÂÂÂ }
>> +ÂÂÂ }
>> +
>> +ÂÂÂ if (uc->use_dma_pool) {
>> +ÂÂÂÂÂÂÂ uc->hdesc_pool = dma_pool_create(uc->name, ud->ddev.dev,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ uc->hdesc_size, ud->desc_align,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ 0);
>> +ÂÂÂÂÂÂÂ if (!uc->hdesc_pool) {
>> +ÂÂÂÂÂÂÂÂÂÂÂ dev_err(ud->ddev.dev,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ "Descriptor pool allocation failed\n");
>> +ÂÂÂÂÂÂÂÂÂÂÂ uc->use_dma_pool = false;
>> +ÂÂÂÂÂÂÂÂÂÂÂ return -ENOMEM;
>> +ÂÂÂÂÂÂÂ }
>> +ÂÂÂ }
>> +
>> +ÂÂÂ pm_runtime_get_sync(ud->ddev.dev);
>> +
>> +ÂÂÂ /*
>> +ÂÂÂÂ * Make sure that the completion is in a known state:
>> +ÂÂÂÂ * No teardown, the channel is idle
>> +ÂÂÂÂ */
>> +ÂÂÂ reinit_completion(&uc->teardown_completed);
>> +ÂÂÂ complete_all(&uc->teardown_completed);
>> +ÂÂÂ uc->state = UDMA_CHAN_IS_IDLE;
>> +
>> +ÂÂÂ switch (uc->dir) {
>> +ÂÂÂ case DMA_MEM_TO_MEM:
>> +ÂÂÂÂÂÂÂ /* Non synchronized - mem to mem type of transfer */
>> +ÂÂÂÂÂÂÂ dev_dbg(uc->ud->dev, "%s: chan%d as MEM-to-MEM\n", __func__,
>> +ÂÂÂÂÂÂÂÂÂÂÂ uc->id);
>> +
>> +ÂÂÂÂÂÂÂ ret = udma_get_chan_pair(uc);
>> +ÂÂÂÂÂÂÂ if (ret)
>> +ÂÂÂÂÂÂÂÂÂÂÂ return ret;
>> +
>> +ÂÂÂÂÂÂÂ ret = udma_alloc_tx_resources(uc);
>> +ÂÂÂÂÂÂÂ if (ret)
>> +ÂÂÂÂÂÂÂÂÂÂÂ return ret;
>> +
>> +ÂÂÂÂÂÂÂ ret = udma_alloc_rx_resources(uc);
>> +ÂÂÂÂÂÂÂ if (ret) {
>> +ÂÂÂÂÂÂÂÂÂÂÂ udma_free_tx_resources(uc);
>> +ÂÂÂÂÂÂÂÂÂÂÂ return ret;
>> +ÂÂÂÂÂÂÂ }
>> +
>> +ÂÂÂÂÂÂÂ uc->src_thread = ud->psil_base + uc->tchan->id;
>> +ÂÂÂÂÂÂÂ uc->dst_thread = (ud->psil_base + uc->rchan->id) |
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ UDMA_PSIL_DST_THREAD_ID_OFFSET;
>> +
>> +ÂÂÂÂÂÂÂ irq_ring = uc->tchan->tc_ring;
>> +ÂÂÂÂÂÂÂ irq_udma_idx = uc->tchan->id;
>> +ÂÂÂÂÂÂÂ break;
>> +ÂÂÂ case DMA_MEM_TO_DEV:
>> +ÂÂÂÂÂÂÂ /* Slave transfer synchronized - mem to dev (TX) trasnfer */
>> +ÂÂÂÂÂÂÂ dev_dbg(uc->ud->dev, "%s: chan%d as MEM-to-DEV\n", __func__,
>> +ÂÂÂÂÂÂÂÂÂÂÂ uc->id);
>> +
>> +ÂÂÂÂÂÂÂ ret = udma_alloc_tx_resources(uc);
>> +ÂÂÂÂÂÂÂ if (ret) {
>> +ÂÂÂÂÂÂÂÂÂÂÂ uc->remote_thread_id = -1;
>> +ÂÂÂÂÂÂÂÂÂÂÂ return ret;
>> +ÂÂÂÂÂÂÂ }
>> +
>> +ÂÂÂÂÂÂÂ uc->src_thread = ud->psil_base + uc->tchan->id;
>> +ÂÂÂÂÂÂÂ uc->dst_thread = uc->remote_thread_id;
>> +ÂÂÂÂÂÂÂ uc->dst_thread |= UDMA_PSIL_DST_THREAD_ID_OFFSET;
>> +
>> +ÂÂÂÂÂÂÂ irq_ring = uc->tchan->tc_ring;
>> +ÂÂÂÂÂÂÂ irq_udma_idx = uc->tchan->id;
>> +ÂÂÂÂÂÂÂ break;
>> +ÂÂÂ case DMA_DEV_TO_MEM:
>> +ÂÂÂÂÂÂÂ /* Slave transfer synchronized - dev to mem (RX) trasnfer */
>> +ÂÂÂÂÂÂÂ dev_dbg(uc->ud->dev, "%s: chan%d as DEV-to-MEM\n", __func__,
>> +ÂÂÂÂÂÂÂÂÂÂÂ uc->id);
>> +
>> +ÂÂÂÂÂÂÂ ret = udma_alloc_rx_resources(uc);
>> +ÂÂÂÂÂÂÂ if (ret) {
>> +ÂÂÂÂÂÂÂÂÂÂÂ uc->remote_thread_id = -1;
>> +ÂÂÂÂÂÂÂÂÂÂÂ return ret;
>> +ÂÂÂÂÂÂÂ }
>> +
>> +ÂÂÂÂÂÂÂ uc->src_thread = uc->remote_thread_id;
>> +ÂÂÂÂÂÂÂ uc->dst_thread = (ud->psil_base + uc->rchan->id) |
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ UDMA_PSIL_DST_THREAD_ID_OFFSET;
>> +
>> +ÂÂÂÂÂÂÂ irq_ring = uc->rchan->r_ring;
>> +ÂÂÂÂÂÂÂ irq_udma_idx = match_data->rchan_oes_offset + uc->rchan->id;
>> +ÂÂÂÂÂÂÂ break;
>> +ÂÂÂ default:
>> +ÂÂÂÂÂÂÂ /* Can not happen */
>> +ÂÂÂÂÂÂÂ dev_err(uc->ud->dev, "%s: chan%d invalid direction (%u)\n",
>> +ÂÂÂÂÂÂÂÂÂÂÂ __func__, uc->id, uc->dir);
>> +ÂÂÂÂÂÂÂ return -EINVAL;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ /* Configure channel(s), rflow via tisci */
>> +ÂÂÂ ret = udma_tisci_channel_config(uc);
>> +ÂÂÂ if (ret)
>> +ÂÂÂÂÂÂÂ goto err_res_free;
>> +
>> +ÂÂÂ if (udma_is_chan_running(uc)) {
>> +ÂÂÂÂÂÂÂ dev_warn(ud->dev, "chan%d: is running!\n", uc->id);
>> +ÂÂÂÂÂÂÂ udma_stop(uc);
>> +ÂÂÂÂÂÂÂ if (udma_is_chan_running(uc)) {
>> +ÂÂÂÂÂÂÂÂÂÂÂ dev_err(ud->dev, "chan%d: won't stop!\n", uc->id);
>> +ÂÂÂÂÂÂÂÂÂÂÂ goto err_res_free;
>> +ÂÂÂÂÂÂÂ }
>> +ÂÂÂ }
>> +
>> +ÂÂÂ /* PSI-L pairing */
>> +ÂÂÂ ret = navss_psil_pair(ud, uc->src_thread, uc->dst_thread);
>> +ÂÂÂ if (ret) {
>> +ÂÂÂÂÂÂÂ dev_err(ud->dev, "PSI-L pairing failed: 0x%04x -> 0x%04x\n",
>> +ÂÂÂÂÂÂÂÂÂÂÂ uc->src_thread, uc->dst_thread);
>> +ÂÂÂÂÂÂÂ goto err_res_free;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ uc->psil_paired = true;
>> +
>> +ÂÂÂ uc->irq_num_ring = k3_ringacc_get_ring_irq_num(irq_ring);
>> +ÂÂÂ if (uc->irq_num_ring <= 0) {
>> +ÂÂÂÂÂÂÂ dev_err(ud->dev, "Failed to get ring irq (index: %u)\n",
>> +ÂÂÂÂÂÂÂÂÂÂÂ k3_ringacc_get_ring_id(irq_ring));
>> +ÂÂÂÂÂÂÂ ret = -EINVAL;
>> +ÂÂÂÂÂÂÂ goto err_psi_free;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ ret = request_irq(uc->irq_num_ring, udma_ring_irq_handler,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂ IRQF_TRIGGER_HIGH, uc->name, uc);
>> +ÂÂÂ if (ret) {
>> +ÂÂÂÂÂÂÂ dev_err(ud->dev, "chan%d: ring irq request failed\n", uc->id);
>> +ÂÂÂÂÂÂÂ goto err_irq_free;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ /* Event from UDMA (TR events) only needed for slave TR mode
>> channels */
>> +ÂÂÂ if (is_slave_direction(uc->dir) && !uc->pkt_mode) {
>> +ÂÂÂÂÂÂÂ uc->irq_num_udma = ti_sci_inta_msi_get_virq(ud->dev,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ irq_udma_idx);
>> +ÂÂÂÂÂÂÂ if (uc->irq_num_udma <= 0) {
>> +ÂÂÂÂÂÂÂÂÂÂÂ dev_err(ud->dev, "Failed to get udma irq (index: %u)\n",
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ irq_udma_idx);
>> +ÂÂÂÂÂÂÂÂÂÂÂ free_irq(uc->irq_num_ring, uc);
>> +ÂÂÂÂÂÂÂÂÂÂÂ ret = -EINVAL;
>> +ÂÂÂÂÂÂÂÂÂÂÂ goto err_irq_free;
>> +ÂÂÂÂÂÂÂ }
>> +
>> +ÂÂÂÂÂÂÂ ret = request_irq(uc->irq_num_udma, udma_udma_irq_handler, 0,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ uc->name, uc);
>> +ÂÂÂÂÂÂÂ if (ret) {
>> +ÂÂÂÂÂÂÂÂÂÂÂ dev_err(ud->dev, "chan%d: UDMA irq request failed\n",
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ uc->id);
>> +ÂÂÂÂÂÂÂÂÂÂÂ free_irq(uc->irq_num_ring, uc);
>> +ÂÂÂÂÂÂÂÂÂÂÂ goto err_irq_free;
>> +ÂÂÂÂÂÂÂ }
>> +ÂÂÂ } else {
>> +ÂÂÂÂÂÂÂ uc->irq_num_udma = 0;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ udma_reset_rings(uc);
>> +
>> +ÂÂÂ return 0;
>> +
>> +err_irq_free:
>> +ÂÂÂ uc->irq_num_ring = 0;
>> +ÂÂÂ uc->irq_num_udma = 0;
>> +err_psi_free:
>> +ÂÂÂ navss_psil_unpair(ud, uc->src_thread, uc->dst_thread);
>> +ÂÂÂ uc->psil_paired = false;
>> +err_res_free:
>> +ÂÂÂ udma_free_tx_resources(uc);
>> +ÂÂÂ udma_free_rx_resources(uc);
>> +
>> +ÂÂÂ uc->remote_thread_id = -1;
>> +ÂÂÂ uc->dir = DMA_MEM_TO_MEM;
>> +ÂÂÂ uc->pkt_mode = false;
>> +ÂÂÂ uc->static_tr_type = 0;
>> +ÂÂÂ uc->enable_acc32 = 0;
>> +ÂÂÂ uc->enable_burst = 0;
>> +ÂÂÂ uc->channel_tpl = 0;
>> +ÂÂÂ uc->psd_size = 0;
>> +ÂÂÂ uc->metadata_size = 0;
>> +ÂÂÂ uc->hdesc_size = 0;
>> +
>> +ÂÂÂ if (uc->use_dma_pool) {
>> +ÂÂÂÂÂÂÂ dma_pool_destroy(uc->hdesc_pool);
>> +ÂÂÂÂÂÂÂ uc->use_dma_pool = false;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ return ret;
>> +}
>> +
>
> [...]
>
- PÃter
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki