Skip to content

Commit

Permalink
can: mcp251xfd: struct mcp251xfd_priv::tef to array of length 1
Browse files Browse the repository at this point in the history
This patch converts the struct mcp251xfd_tef_ring member within the struct
mcp251xfd_priv into an array of length one. This way all rings (tef, tx and rx)
can be accessed in the same way.

Link: https://lore.kernel.org/r/20201126132144.351154-4-mkl@pengutronix.de
Tested-by: Thomas Kopp <thomas.kopp@microchip.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
  • Loading branch information
Marc Kleine-Budde committed Nov 29, 2020
1 parent 1f652bb commit dada6a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
18 changes: 10 additions & 8 deletions drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ mcp251xfd_tx_ring_init_tx_obj(const struct mcp251xfd_priv *priv,

static void mcp251xfd_ring_init(struct mcp251xfd_priv *priv)
{
struct mcp251xfd_tef_ring *tef_ring;
struct mcp251xfd_tx_ring *tx_ring;
struct mcp251xfd_rx_ring *rx_ring, *prev_rx_ring = NULL;
struct mcp251xfd_tx_obj *tx_obj;
Expand All @@ -335,8 +336,9 @@ static void mcp251xfd_ring_init(struct mcp251xfd_priv *priv)
int i, j;

/* TEF */
priv->tef.head = 0;
priv->tef.tail = 0;
tef_ring = priv->tef;
tef_ring->head = 0;
tef_ring->tail = 0;

/* TX */
tx_ring = priv->tx;
Expand Down Expand Up @@ -1219,7 +1221,7 @@ mcp251xfd_handle_tefif_recover(const struct mcp251xfd_priv *priv, const u32 seq)
tef_sta & MCP251XFD_REG_TEFSTA_TEFFIF ?
"full" : tef_sta & MCP251XFD_REG_TEFSTA_TEFNEIF ?
"not empty" : "empty",
seq, priv->tef.tail, priv->tef.head, tx_ring->head);
seq, priv->tef->tail, priv->tef->head, tx_ring->head);

/* The Sequence Number in the TEF doesn't match our tef_tail. */
return -EAGAIN;
Expand All @@ -1243,7 +1245,7 @@ mcp251xfd_handle_tefif_one(struct mcp251xfd_priv *priv,
*/
seq_masked = seq &
field_mask(MCP251XFD_OBJ_FLAGS_SEQ_MCP2517FD_MASK);
tef_tail_masked = priv->tef.tail &
tef_tail_masked = priv->tef->tail &
field_mask(MCP251XFD_OBJ_FLAGS_SEQ_MCP2517FD_MASK);
if (seq_masked != tef_tail_masked)
return mcp251xfd_handle_tefif_recover(priv, seq);
Expand All @@ -1261,7 +1263,7 @@ mcp251xfd_handle_tefif_one(struct mcp251xfd_priv *priv,
if (err)
return err;

priv->tef.tail++;
priv->tef->tail++;
tx_ring->tail++;

return mcp251xfd_check_tef_tail(priv);
Expand All @@ -1281,12 +1283,12 @@ static int mcp251xfd_tef_ring_update(struct mcp251xfd_priv *priv)
/* chip_tx_tail, is the next TX-Object send by the HW.
* The new TEF head must be >= the old head, ...
*/
new_head = round_down(priv->tef.head, tx_ring->obj_num) + chip_tx_tail;
if (new_head <= priv->tef.head)
new_head = round_down(priv->tef->head, tx_ring->obj_num) + chip_tx_tail;
if (new_head <= priv->tef->head)
new_head += tx_ring->obj_num;

/* ... but it cannot exceed the TX head. */
priv->tef.head = min(new_head, tx_ring->head);
priv->tef->head = min(new_head, tx_ring->head);

return mcp251xfd_check_tef_tail(priv);
}
Expand Down
8 changes: 4 additions & 4 deletions drivers/net/can/spi/mcp251xfd/mcp251xfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ struct mcp251xfd_priv {
struct spi_device *spi;
u32 spi_max_speed_hz_orig;

struct mcp251xfd_tef_ring tef;
struct mcp251xfd_tef_ring tef[1];
struct mcp251xfd_tx_ring tx[1];
struct mcp251xfd_rx_ring *rx[1];

Expand Down Expand Up @@ -744,17 +744,17 @@ mcp251xfd_get_rx_obj_addr(const struct mcp251xfd_rx_ring *ring, u8 n)

static inline u8 mcp251xfd_get_tef_head(const struct mcp251xfd_priv *priv)
{
return priv->tef.head & (priv->tx->obj_num - 1);
return priv->tef->head & (priv->tx->obj_num - 1);
}

static inline u8 mcp251xfd_get_tef_tail(const struct mcp251xfd_priv *priv)
{
return priv->tef.tail & (priv->tx->obj_num - 1);
return priv->tef->tail & (priv->tx->obj_num - 1);
}

static inline u8 mcp251xfd_get_tef_len(const struct mcp251xfd_priv *priv)
{
return priv->tef.head - priv->tef.tail;
return priv->tef->head - priv->tef->tail;
}

static inline u8 mcp251xfd_get_tef_linear_len(const struct mcp251xfd_priv *priv)
Expand Down

0 comments on commit dada6a6

Please sign in to comment.