Skip to content

Commit 57937fa

Browse files
Atomar25vinodkoul
authored andcommitted
dmaengine: Actions: get rid of bit fields from dma descriptor
At the moment, Driver uses bit fields to describe registers of the DMA descriptor structure that makes it less portable and maintainable, and Andre suugested(and even sketched important bits for it) to make use of array to describe this DMA descriptors instead. It gives the flexibility while extending support for other platform such as Actions S700. This commit removes the "owl_dma_lli_hw" (that includes bit-fields) and uses array to describe DMA descriptor. Suggested-by: Andre Przywara <[email protected]> Signed-off-by: Amit Singh Tomar <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent bbeeb86 commit 57937fa

File tree

1 file changed

+56
-42
lines changed

1 file changed

+56
-42
lines changed

drivers/dma/owl-dma.c

Lines changed: 56 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -120,30 +120,33 @@
120120
#define BIT_FIELD(val, width, shift, newshift) \
121121
((((val) >> (shift)) & ((BIT(width)) - 1)) << (newshift))
122122

123+
/* Frame count value is fixed as 1 */
124+
#define FCNT_VAL 0x1
125+
123126
/**
124-
* struct owl_dma_lli_hw - Hardware link list for dma transfer
125-
* @next_lli: physical address of the next link list
126-
* @saddr: source physical address
127-
* @daddr: destination physical address
128-
* @flen: frame length
129-
* @fcnt: frame count
130-
* @src_stride: source stride
131-
* @dst_stride: destination stride
132-
* @ctrla: dma_mode and linklist ctrl config
133-
* @ctrlb: interrupt config
134-
* @const_num: data for constant fill
127+
* owl_dmadesc_offsets - Describe DMA descriptor, hardware link
128+
* list for dma transfer
129+
* @OWL_DMADESC_NEXT_LLI: physical address of the next link list
130+
* @OWL_DMADESC_SADDR: source physical address
131+
* @OWL_DMADESC_DADDR: destination physical address
132+
* @OWL_DMADESC_FLEN: frame length
133+
* @OWL_DMADESC_SRC_STRIDE: source stride
134+
* @OWL_DMADESC_DST_STRIDE: destination stride
135+
* @OWL_DMADESC_CTRLA: dma_mode and linklist ctrl config
136+
* @OWL_DMADESC_CTRLB: interrupt config
137+
* @OWL_DMADESC_CONST_NUM: data for constant fill
135138
*/
136-
struct owl_dma_lli_hw {
137-
u32 next_lli;
138-
u32 saddr;
139-
u32 daddr;
140-
u32 flen:20;
141-
u32 fcnt:12;
142-
u32 src_stride;
143-
u32 dst_stride;
144-
u32 ctrla;
145-
u32 ctrlb;
146-
u32 const_num;
139+
enum owl_dmadesc_offsets {
140+
OWL_DMADESC_NEXT_LLI = 0,
141+
OWL_DMADESC_SADDR,
142+
OWL_DMADESC_DADDR,
143+
OWL_DMADESC_FLEN,
144+
OWL_DMADESC_SRC_STRIDE,
145+
OWL_DMADESC_DST_STRIDE,
146+
OWL_DMADESC_CTRLA,
147+
OWL_DMADESC_CTRLB,
148+
OWL_DMADESC_CONST_NUM,
149+
OWL_DMADESC_SIZE
147150
};
148151

149152
/**
@@ -153,7 +156,7 @@ struct owl_dma_lli_hw {
153156
* @node: node for txd's lli_list
154157
*/
155158
struct owl_dma_lli {
156-
struct owl_dma_lli_hw hw;
159+
u32 hw[OWL_DMADESC_SIZE];
157160
dma_addr_t phys;
158161
struct list_head node;
159162
};
@@ -318,6 +321,11 @@ static inline u32 llc_hw_ctrlb(u32 int_ctl)
318321
return ctl;
319322
}
320323

324+
static u32 llc_hw_flen(struct owl_dma_lli *lli)
325+
{
326+
return lli->hw[OWL_DMADESC_FLEN] & GENMASK(19, 0);
327+
}
328+
321329
static void owl_dma_free_lli(struct owl_dma *od,
322330
struct owl_dma_lli *lli)
323331
{
@@ -349,8 +357,9 @@ static struct owl_dma_lli *owl_dma_add_lli(struct owl_dma_txd *txd,
349357
list_add_tail(&next->node, &txd->lli_list);
350358

351359
if (prev) {
352-
prev->hw.next_lli = next->phys;
353-
prev->hw.ctrla |= llc_hw_ctrla(OWL_DMA_MODE_LME, 0);
360+
prev->hw[OWL_DMADESC_NEXT_LLI] = next->phys;
361+
prev->hw[OWL_DMADESC_CTRLA] |=
362+
llc_hw_ctrla(OWL_DMA_MODE_LME, 0);
354363
}
355364

356365
return next;
@@ -363,8 +372,7 @@ static inline int owl_dma_cfg_lli(struct owl_dma_vchan *vchan,
363372
struct dma_slave_config *sconfig,
364373
bool is_cyclic)
365374
{
366-
struct owl_dma_lli_hw *hw = &lli->hw;
367-
u32 mode;
375+
u32 mode, ctrlb;
368376

369377
mode = OWL_DMA_MODE_PW(0);
370378

@@ -405,22 +413,28 @@ static inline int owl_dma_cfg_lli(struct owl_dma_vchan *vchan,
405413
return -EINVAL;
406414
}
407415

408-
hw->next_lli = 0; /* One link list by default */
409-
hw->saddr = src;
410-
hw->daddr = dst;
411-
412-
hw->fcnt = 1; /* Frame count fixed as 1 */
413-
hw->flen = len; /* Max frame length is 1MB */
414-
hw->src_stride = 0;
415-
hw->dst_stride = 0;
416-
hw->ctrla = llc_hw_ctrla(mode,
417-
OWL_DMA_LLC_SAV_LOAD_NEXT |
418-
OWL_DMA_LLC_DAV_LOAD_NEXT);
416+
lli->hw[OWL_DMADESC_CTRLA] = llc_hw_ctrla(mode,
417+
OWL_DMA_LLC_SAV_LOAD_NEXT |
418+
OWL_DMA_LLC_DAV_LOAD_NEXT);
419419

420420
if (is_cyclic)
421-
hw->ctrlb = llc_hw_ctrlb(OWL_DMA_INTCTL_BLOCK);
421+
ctrlb = llc_hw_ctrlb(OWL_DMA_INTCTL_BLOCK);
422422
else
423-
hw->ctrlb = llc_hw_ctrlb(OWL_DMA_INTCTL_SUPER_BLOCK);
423+
ctrlb = llc_hw_ctrlb(OWL_DMA_INTCTL_SUPER_BLOCK);
424+
425+
lli->hw[OWL_DMADESC_NEXT_LLI] = 0; /* One link list by default */
426+
lli->hw[OWL_DMADESC_SADDR] = src;
427+
lli->hw[OWL_DMADESC_DADDR] = dst;
428+
lli->hw[OWL_DMADESC_SRC_STRIDE] = 0;
429+
lli->hw[OWL_DMADESC_DST_STRIDE] = 0;
430+
/*
431+
* Word starts from offset 0xC is shared between frame length
432+
* (max frame length is 1MB) and frame count, where first 20
433+
* bits are for frame length and rest of 12 bits are for frame
434+
* count.
435+
*/
436+
lli->hw[OWL_DMADESC_FLEN] = len | FCNT_VAL << 20;
437+
lli->hw[OWL_DMADESC_CTRLB] = ctrlb;
424438

425439
return 0;
426440
}
@@ -752,7 +766,7 @@ static u32 owl_dma_getbytes_chan(struct owl_dma_vchan *vchan)
752766
/* Start from the next active node */
753767
if (lli->phys == next_lli_phy) {
754768
list_for_each_entry(lli, &txd->lli_list, node)
755-
bytes += lli->hw.flen;
769+
bytes += llc_hw_flen(lli);
756770
break;
757771
}
758772
}
@@ -783,7 +797,7 @@ static enum dma_status owl_dma_tx_status(struct dma_chan *chan,
783797
if (vd) {
784798
txd = to_owl_txd(&vd->tx);
785799
list_for_each_entry(lli, &txd->lli_list, node)
786-
bytes += lli->hw.flen;
800+
bytes += llc_hw_flen(lli);
787801
} else {
788802
bytes = owl_dma_getbytes_chan(vchan);
789803
}

0 commit comments

Comments
 (0)