Commit 5fb859f7 authored by Alex Elder's avatar Alex Elder Committed by David S. Miller

net: ipa: initialize ring indexes to 0

When a GSI channel is initially allocated, and after it has been
reset, the hardware assumes its ring index is 0.  And although we
do initialize channels this way, the comments in the IPA code don't
really explain this.  For event rings, it doesn't matter what value
we use initially, so using 0 is just fine.

Add some information about the assumptions made by hardware above
the definition of the gsi_ring structure in "gsi.h".

Zero the index field for all rings (channel and event) when the ring
is allocated.  As a result, that function initializes all fields in
the structure.

Stop zeroing the index the top of gsi_channel_program().  Initially
we'll use the index value set when the channel ring was allocated.
And we'll explicitly zero the index value in gsi_channel_reset()
before programming the hardware, adding a comment explaining why
it's required.

For event rings, use the index initialized by gsi_ring_alloc()
rather than 0 when ringing the doorbell in gsi_evt_ring_program().
(It'll still be zero, but we won't assume that to be the case.)

Use a local variable in gsi_evt_ring_program() that represents the
address of the event ring's ring structure.
Signed-off-by: default avatarAlex Elder <elder@linaro.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 52323ef7
...@@ -665,7 +665,8 @@ static void gsi_evt_ring_doorbell(struct gsi *gsi, u32 evt_ring_id, u32 index) ...@@ -665,7 +665,8 @@ static void gsi_evt_ring_doorbell(struct gsi *gsi, u32 evt_ring_id, u32 index)
static void gsi_evt_ring_program(struct gsi *gsi, u32 evt_ring_id) static void gsi_evt_ring_program(struct gsi *gsi, u32 evt_ring_id)
{ {
struct gsi_evt_ring *evt_ring = &gsi->evt_ring[evt_ring_id]; struct gsi_evt_ring *evt_ring = &gsi->evt_ring[evt_ring_id];
size_t size = evt_ring->ring.count * GSI_RING_ELEMENT_SIZE; struct gsi_ring *ring = &evt_ring->ring;
size_t size;
u32 val; u32 val;
/* We program all event rings as GPI type/protocol */ /* We program all event rings as GPI type/protocol */
...@@ -674,6 +675,7 @@ static void gsi_evt_ring_program(struct gsi *gsi, u32 evt_ring_id) ...@@ -674,6 +675,7 @@ static void gsi_evt_ring_program(struct gsi *gsi, u32 evt_ring_id)
val |= u32_encode_bits(GSI_RING_ELEMENT_SIZE, EV_ELEMENT_SIZE_FMASK); val |= u32_encode_bits(GSI_RING_ELEMENT_SIZE, EV_ELEMENT_SIZE_FMASK);
iowrite32(val, gsi->virt + GSI_EV_CH_E_CNTXT_0_OFFSET(evt_ring_id)); iowrite32(val, gsi->virt + GSI_EV_CH_E_CNTXT_0_OFFSET(evt_ring_id));
size = ring->count * GSI_RING_ELEMENT_SIZE;
val = ev_r_length_encoded(gsi->version, size); val = ev_r_length_encoded(gsi->version, size);
iowrite32(val, gsi->virt + GSI_EV_CH_E_CNTXT_1_OFFSET(evt_ring_id)); iowrite32(val, gsi->virt + GSI_EV_CH_E_CNTXT_1_OFFSET(evt_ring_id));
...@@ -681,9 +683,9 @@ static void gsi_evt_ring_program(struct gsi *gsi, u32 evt_ring_id) ...@@ -681,9 +683,9 @@ static void gsi_evt_ring_program(struct gsi *gsi, u32 evt_ring_id)
* high-order 32 bits of the address of the event ring, * high-order 32 bits of the address of the event ring,
* respectively. * respectively.
*/ */
val = lower_32_bits(evt_ring->ring.addr); val = lower_32_bits(ring->addr);
iowrite32(val, gsi->virt + GSI_EV_CH_E_CNTXT_2_OFFSET(evt_ring_id)); iowrite32(val, gsi->virt + GSI_EV_CH_E_CNTXT_2_OFFSET(evt_ring_id));
val = upper_32_bits(evt_ring->ring.addr); val = upper_32_bits(ring->addr);
iowrite32(val, gsi->virt + GSI_EV_CH_E_CNTXT_3_OFFSET(evt_ring_id)); iowrite32(val, gsi->virt + GSI_EV_CH_E_CNTXT_3_OFFSET(evt_ring_id));
/* Enable interrupt moderation by setting the moderation delay */ /* Enable interrupt moderation by setting the moderation delay */
...@@ -700,8 +702,8 @@ static void gsi_evt_ring_program(struct gsi *gsi, u32 evt_ring_id) ...@@ -700,8 +702,8 @@ static void gsi_evt_ring_program(struct gsi *gsi, u32 evt_ring_id)
iowrite32(0, gsi->virt + GSI_EV_CH_E_CNTXT_12_OFFSET(evt_ring_id)); iowrite32(0, gsi->virt + GSI_EV_CH_E_CNTXT_12_OFFSET(evt_ring_id));
iowrite32(0, gsi->virt + GSI_EV_CH_E_CNTXT_13_OFFSET(evt_ring_id)); iowrite32(0, gsi->virt + GSI_EV_CH_E_CNTXT_13_OFFSET(evt_ring_id));
/* Finally, tell the hardware we've completed event 0 (arbitrary) */ /* Finally, tell the hardware our "last processed" event (arbitrary) */
gsi_evt_ring_doorbell(gsi, evt_ring_id, 0); gsi_evt_ring_doorbell(gsi, evt_ring_id, ring->index);
} }
/* Find the transaction whose completion indicates a channel is quiesced */ /* Find the transaction whose completion indicates a channel is quiesced */
...@@ -770,9 +772,6 @@ static void gsi_channel_program(struct gsi_channel *channel, bool doorbell) ...@@ -770,9 +772,6 @@ static void gsi_channel_program(struct gsi_channel *channel, bool doorbell)
u32 wrr_weight = 0; u32 wrr_weight = 0;
u32 val; u32 val;
/* Arbitrarily pick TRE 0 as the first channel element to use */
channel->tre_ring.index = 0;
/* We program all channels as GPI type/protocol */ /* We program all channels as GPI type/protocol */
val = chtype_protocol_encoded(gsi->version, GSI_CHANNEL_TYPE_GPI); val = chtype_protocol_encoded(gsi->version, GSI_CHANNEL_TYPE_GPI);
if (channel->toward_ipa) if (channel->toward_ipa)
...@@ -949,6 +948,8 @@ void gsi_channel_reset(struct gsi *gsi, u32 channel_id, bool doorbell) ...@@ -949,6 +948,8 @@ void gsi_channel_reset(struct gsi *gsi, u32 channel_id, bool doorbell)
if (gsi->version < IPA_VERSION_4_0 && !channel->toward_ipa) if (gsi->version < IPA_VERSION_4_0 && !channel->toward_ipa)
gsi_channel_reset_command(channel); gsi_channel_reset_command(channel);
/* Hardware assumes this is 0 following reset */
channel->tre_ring.index = 0;
gsi_channel_program(channel, doorbell); gsi_channel_program(channel, doorbell);
gsi_channel_trans_cancel_pending(channel); gsi_channel_trans_cancel_pending(channel);
...@@ -1433,6 +1434,7 @@ static int gsi_ring_alloc(struct gsi *gsi, struct gsi_ring *ring, u32 count) ...@@ -1433,6 +1434,7 @@ static int gsi_ring_alloc(struct gsi *gsi, struct gsi_ring *ring, u32 count)
ring->addr = addr; ring->addr = addr;
ring->count = count; ring->count = count;
ring->index = 0;
return 0; return 0;
} }
......
...@@ -48,12 +48,13 @@ struct gsi_ring { ...@@ -48,12 +48,13 @@ struct gsi_ring {
* *
* A channel ring consists of TRE entries filled by the AP and passed * A channel ring consists of TRE entries filled by the AP and passed
* to the hardware for processing. For a channel ring, the ring index * to the hardware for processing. For a channel ring, the ring index
* identifies the next unused entry to be filled by the AP. * identifies the next unused entry to be filled by the AP. In this
* case the initial value is assumed by hardware to be 0.
* *
* An event ring consists of event structures filled by the hardware * An event ring consists of event structures filled by the hardware
* and passed to the AP. For event rings, the ring index identifies * and passed to the AP. For event rings, the ring index identifies
* the next ring entry that is not known to have been filled by the * the next ring entry that is not known to have been filled by the
* hardware. * hardware. The initial value used is arbitrary (so we use 0).
*/ */
u32 index; u32 index;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment