Commit 6988c1d3 authored by David S. Miller's avatar David S. Miller

Merge branch 'net-ipa-next'

Alex Elder says:

====================
net: ipa: don't use lists for transaction state

This is the last series of patches to convert the IPA code so
integer IDs are used rather than lists to track the state of
transactions.

A first series of patches added ID fields to track the state of
transactions:
  https://lore.kernel.org/netdev/20220831224017.377745-1-elder@linaro.org
The second series started transitioning code to use these IDs rather
than lists to manage state:
  https://lore.kernel.org/netdev/20220902210218.745873-1-elder@linaro.org

This final series finishes the transition, to always use IDs instead
of the lists to manage transaction state.  As a result, the list
fields, links, and a spinlock to protect updates are no longer
needed, so they are removed.  This permits a few other improvements
to be implemented.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 6fff9261 019e37ea
...@@ -1475,7 +1475,7 @@ void gsi_channel_doorbell(struct gsi_channel *channel) ...@@ -1475,7 +1475,7 @@ void gsi_channel_doorbell(struct gsi_channel *channel)
} }
/* Consult hardware, move any newly completed transactions to completed list */ /* Consult hardware, move any newly completed transactions to completed list */
static struct gsi_trans *gsi_channel_update(struct gsi_channel *channel) void gsi_channel_update(struct gsi_channel *channel)
{ {
u32 evt_ring_id = channel->evt_ring_id; u32 evt_ring_id = channel->evt_ring_id;
struct gsi *gsi = channel->gsi; struct gsi *gsi = channel->gsi;
...@@ -1494,12 +1494,12 @@ static struct gsi_trans *gsi_channel_update(struct gsi_channel *channel) ...@@ -1494,12 +1494,12 @@ static struct gsi_trans *gsi_channel_update(struct gsi_channel *channel)
offset = GSI_EV_CH_E_CNTXT_4_OFFSET(evt_ring_id); offset = GSI_EV_CH_E_CNTXT_4_OFFSET(evt_ring_id);
index = gsi_ring_index(ring, ioread32(gsi->virt + offset)); index = gsi_ring_index(ring, ioread32(gsi->virt + offset));
if (index == ring->index % ring->count) if (index == ring->index % ring->count)
return NULL; return;
/* Get the transaction for the latest completed event. */ /* Get the transaction for the latest completed event. */
trans = gsi_event_trans(gsi, gsi_ring_virt(ring, index - 1)); trans = gsi_event_trans(gsi, gsi_ring_virt(ring, index - 1));
if (!trans) if (!trans)
return NULL; return;
/* For RX channels, update each completed transaction with the number /* For RX channels, update each completed transaction with the number
* of bytes that were actually received. For TX channels, report * of bytes that were actually received. For TX channels, report
...@@ -1507,8 +1507,6 @@ static struct gsi_trans *gsi_channel_update(struct gsi_channel *channel) ...@@ -1507,8 +1507,6 @@ static struct gsi_trans *gsi_channel_update(struct gsi_channel *channel)
* up the network stack. * up the network stack.
*/ */
gsi_evt_ring_update(gsi, evt_ring_id, index); gsi_evt_ring_update(gsi, evt_ring_id, index);
return gsi_channel_trans_complete(channel);
} }
/** /**
...@@ -1529,9 +1527,6 @@ static struct gsi_trans *gsi_channel_poll_one(struct gsi_channel *channel) ...@@ -1529,9 +1527,6 @@ static struct gsi_trans *gsi_channel_poll_one(struct gsi_channel *channel)
/* Get the first transaction from the completed list */ /* Get the first transaction from the completed list */
trans = gsi_channel_trans_complete(channel); trans = gsi_channel_trans_complete(channel);
if (!trans) /* List is empty; see if there's more to do */
trans = gsi_channel_update(channel);
if (trans) if (trans)
gsi_trans_move_polled(trans); gsi_trans_move_polled(trans);
......
...@@ -94,13 +94,6 @@ struct gsi_trans_info { ...@@ -94,13 +94,6 @@ struct gsi_trans_info {
struct gsi_trans_pool sg_pool; /* scatterlist pool */ struct gsi_trans_pool sg_pool; /* scatterlist pool */
struct gsi_trans_pool cmd_pool; /* command payload DMA pool */ struct gsi_trans_pool cmd_pool; /* command payload DMA pool */
spinlock_t spinlock; /* protects updates to the lists */
struct list_head alloc; /* allocated, not committed */
struct list_head committed; /* committed, awaiting doorbell */
struct list_head pending; /* pending, awaiting completion */
struct list_head complete; /* completed, awaiting poll */
struct list_head polled; /* returned by gsi_channel_poll_one() */
}; };
/* Hardware values signifying the state of a channel */ /* Hardware values signifying the state of a channel */
......
...@@ -16,20 +16,6 @@ struct gsi_channel; ...@@ -16,20 +16,6 @@ struct gsi_channel;
#define GSI_RING_ELEMENT_SIZE 16 /* bytes; must be a power of 2 */ #define GSI_RING_ELEMENT_SIZE 16 /* bytes; must be a power of 2 */
/**
* list_last_entry_or_null - get the last element from a list
* @ptr: the list head to take the element from.
* @type: the type of the struct this is embedded in.
* @member: the name of the list_head within the struct.
*
* Note that if the list is empty, it returns NULL.
*/
#define list_last_entry_or_null(ptr, type, member) ({ \
struct list_head *head__ = (ptr); \
struct list_head *pos__ = READ_ONCE(head__->prev); \
pos__ != head__ ? list_entry(pos__, type, member) : NULL; \
})
/** /**
* gsi_trans_move_complete() - Mark a GSI transaction completed * gsi_trans_move_complete() - Mark a GSI transaction completed
* @trans: Transaction to commit * @trans: Transaction to commit
...@@ -108,6 +94,14 @@ void gsi_channel_trans_exit(struct gsi_channel *channel); ...@@ -108,6 +94,14 @@ void gsi_channel_trans_exit(struct gsi_channel *channel);
*/ */
void gsi_channel_doorbell(struct gsi_channel *channel); void gsi_channel_doorbell(struct gsi_channel *channel);
/* gsi_channel_update() - Update knowledge of channel hardware state
* @channel: Channel to be updated
*
* Consult hardware, move any newly completed transactions to a
* channel's completed list.
*/
void gsi_channel_update(struct gsi_channel *channel);
/** /**
* gsi_ring_virt() - Return virtual address for a ring entry * gsi_ring_virt() - Return virtual address for a ring entry
* @ring: Ring whose address is to be translated * @ring: Ring whose address is to be translated
......
...@@ -239,99 +239,59 @@ struct gsi_trans *gsi_channel_trans_complete(struct gsi_channel *channel) ...@@ -239,99 +239,59 @@ struct gsi_trans *gsi_channel_trans_complete(struct gsi_channel *channel)
{ {
struct gsi_trans_info *trans_info = &channel->trans_info; struct gsi_trans_info *trans_info = &channel->trans_info;
u16 trans_id = trans_info->completed_id; u16 trans_id = trans_info->completed_id;
struct gsi_trans *trans;
trans = list_first_entry_or_null(&trans_info->complete,
struct gsi_trans, links);
if (!trans) {
WARN_ON(trans_id != trans_info->pending_id);
return NULL;
}
if (!WARN_ON(trans_id == trans_info->pending_id)) { if (trans_id == trans_info->pending_id) {
trans_id %= channel->tre_count; gsi_channel_update(channel);
WARN_ON(trans != &trans_info->trans[trans_id]); if (trans_id == trans_info->pending_id)
return NULL;
} }
return trans; return &trans_info->trans[trans_id %= channel->tre_count];
} }
/* Move a transaction from the allocated list to the committed list */ /* Move a transaction from allocated to committed state */
static void gsi_trans_move_committed(struct gsi_trans *trans) static void gsi_trans_move_committed(struct gsi_trans *trans)
{ {
struct gsi_channel *channel = &trans->gsi->channel[trans->channel_id]; struct gsi_channel *channel = &trans->gsi->channel[trans->channel_id];
struct gsi_trans_info *trans_info = &channel->trans_info; struct gsi_trans_info *trans_info = &channel->trans_info;
spin_lock_bh(&trans_info->spinlock);
list_move_tail(&trans->links, &trans_info->committed);
spin_unlock_bh(&trans_info->spinlock);
/* This allocated transaction is now committed */ /* This allocated transaction is now committed */
trans_info->allocated_id++; trans_info->allocated_id++;
} }
/* Move transactions from the committed list to the pending list */ /* Move committed transactions to pending state */
static void gsi_trans_move_pending(struct gsi_trans *trans) static void gsi_trans_move_pending(struct gsi_trans *trans)
{ {
struct gsi_channel *channel = &trans->gsi->channel[trans->channel_id]; struct gsi_channel *channel = &trans->gsi->channel[trans->channel_id];
struct gsi_trans_info *trans_info = &channel->trans_info; struct gsi_trans_info *trans_info = &channel->trans_info;
u16 trans_index = trans - &trans_info->trans[0]; u16 trans_index = trans - &trans_info->trans[0];
struct list_head list;
u16 delta; u16 delta;
spin_lock_bh(&trans_info->spinlock);
/* Move this transaction and all predecessors to the pending list */
list_cut_position(&list, &trans_info->committed, &trans->links);
list_splice_tail(&list, &trans_info->pending);
spin_unlock_bh(&trans_info->spinlock);
/* These committed transactions are now pending */ /* These committed transactions are now pending */
delta = trans_index - trans_info->committed_id + 1; delta = trans_index - trans_info->committed_id + 1;
trans_info->committed_id += delta % channel->tre_count; trans_info->committed_id += delta % channel->tre_count;
} }
/* Move a transaction and all of its predecessors from the pending list /* Move pending transactions to completed state */
* to the completed list.
*/
void gsi_trans_move_complete(struct gsi_trans *trans) void gsi_trans_move_complete(struct gsi_trans *trans)
{ {
struct gsi_channel *channel = &trans->gsi->channel[trans->channel_id]; struct gsi_channel *channel = &trans->gsi->channel[trans->channel_id];
struct gsi_trans_info *trans_info = &channel->trans_info; struct gsi_trans_info *trans_info = &channel->trans_info;
u16 trans_index = trans - trans_info->trans; u16 trans_index = trans - trans_info->trans;
struct list_head list;
u16 delta; u16 delta;
spin_lock_bh(&trans_info->spinlock);
/* Move this transaction and all predecessors to completed list */
list_cut_position(&list, &trans_info->pending, &trans->links);
list_splice_tail(&list, &trans_info->complete);
spin_unlock_bh(&trans_info->spinlock);
/* These pending transactions are now completed */ /* These pending transactions are now completed */
delta = trans_index - trans_info->pending_id + 1; delta = trans_index - trans_info->pending_id + 1;
delta %= channel->tre_count; delta %= channel->tre_count;
trans_info->pending_id += delta; trans_info->pending_id += delta;
} }
/* Move a transaction from the completed list to the polled list */ /* Move a transaction from completed to polled state */
void gsi_trans_move_polled(struct gsi_trans *trans) void gsi_trans_move_polled(struct gsi_trans *trans)
{ {
struct gsi_channel *channel = &trans->gsi->channel[trans->channel_id]; struct gsi_channel *channel = &trans->gsi->channel[trans->channel_id];
struct gsi_trans_info *trans_info = &channel->trans_info; struct gsi_trans_info *trans_info = &channel->trans_info;
spin_lock_bh(&trans_info->spinlock);
list_move_tail(&trans->links, &trans_info->polled);
spin_unlock_bh(&trans_info->spinlock);
/* This completed transaction is now polled */ /* This completed transaction is now polled */
trans_info->completed_id++; trans_info->completed_id++;
} }
...@@ -406,46 +366,24 @@ struct gsi_trans *gsi_channel_trans_alloc(struct gsi *gsi, u32 channel_id, ...@@ -406,46 +366,24 @@ struct gsi_trans *gsi_channel_trans_alloc(struct gsi *gsi, u32 channel_id,
trans->direction = direction; trans->direction = direction;
refcount_set(&trans->refcount, 1); refcount_set(&trans->refcount, 1);
/* This free transaction will now be allocated */ /* This free transaction is now allocated */
trans_info->free_id++; trans_info->free_id++;
spin_lock_bh(&trans_info->spinlock);
list_add_tail(&trans->links, &trans_info->alloc);
spin_unlock_bh(&trans_info->spinlock);
return trans; return trans;
} }
/* Free a previously-allocated transaction */ /* Free a previously-allocated transaction */
void gsi_trans_free(struct gsi_trans *trans) void gsi_trans_free(struct gsi_trans *trans)
{ {
refcount_t *refcount = &trans->refcount;
struct gsi_trans_info *trans_info; struct gsi_trans_info *trans_info;
bool last;
/* We must hold the lock to release the last reference */ if (!refcount_dec_and_test(&trans->refcount))
if (refcount_dec_not_one(refcount))
return;
trans_info = &trans->gsi->channel[trans->channel_id].trans_info;
spin_lock_bh(&trans_info->spinlock);
/* Reference might have been added before we got the lock */
last = refcount_dec_and_test(refcount);
if (last)
list_del(&trans->links);
spin_unlock_bh(&trans_info->spinlock);
if (!last)
return; return;
/* Unused transactions are allocated but never committed, pending, /* Unused transactions are allocated but never committed, pending,
* completed, or polled. * completed, or polled.
*/ */
trans_info = &trans->gsi->channel[trans->channel_id].trans_info;
if (!trans->used_count) { if (!trans->used_count) {
trans_info->allocated_id++; trans_info->allocated_id++;
trans_info->committed_id++; trans_info->committed_id++;
...@@ -705,47 +643,27 @@ void gsi_trans_complete(struct gsi_trans *trans) ...@@ -705,47 +643,27 @@ void gsi_trans_complete(struct gsi_trans *trans)
void gsi_channel_trans_cancel_pending(struct gsi_channel *channel) void gsi_channel_trans_cancel_pending(struct gsi_channel *channel)
{ {
struct gsi_trans_info *trans_info = &channel->trans_info; struct gsi_trans_info *trans_info = &channel->trans_info;
struct gsi_trans *trans; u16 trans_id = trans_info->pending_id;
struct gsi_trans *first;
struct gsi_trans *last;
bool cancelled;
/* channel->gsi->mutex is held by caller */ /* channel->gsi->mutex is held by caller */
spin_lock_bh(&trans_info->spinlock);
cancelled = !list_empty(&trans_info->pending);
list_for_each_entry(trans, &trans_info->pending, links)
trans->cancelled = true;
list_splice_tail_init(&trans_info->pending, &trans_info->complete); /* If there are no pending transactions, we're done */
if (trans_id == trans_info->committed_id)
return;
first = list_first_entry_or_null(&trans_info->complete, /* Mark all pending transactions cancelled */
struct gsi_trans, links); do {
last = list_last_entry_or_null(&trans_info->complete, struct gsi_trans *trans;
struct gsi_trans, links);
spin_unlock_bh(&trans_info->spinlock); trans = &trans_info->trans[trans_id % channel->tre_count];
trans->cancelled = true;
} while (++trans_id != trans_info->committed_id);
/* All pending transactions are now completed */ /* All pending transactions are now completed */
WARN_ON(cancelled != (trans_info->pending_id !=
trans_info->committed_id));
trans_info->pending_id = trans_info->committed_id; trans_info->pending_id = trans_info->committed_id;
/* Schedule NAPI polling to complete the cancelled transactions */ /* Schedule NAPI polling to complete the cancelled transactions */
if (cancelled) { napi_schedule(&channel->napi);
u16 trans_id;
napi_schedule(&channel->napi);
trans_id = trans_info->completed_id;
trans = &trans_info->trans[trans_id % channel->tre_count];
WARN_ON(trans != first);
trans_id = trans_info->pending_id - 1;
trans = &trans_info->trans[trans_id % channel->tre_count];
WARN_ON(trans != last);
}
} }
/* Issue a command to read a single byte from a channel */ /* Issue a command to read a single byte from a channel */
...@@ -846,12 +764,6 @@ int gsi_channel_trans_init(struct gsi *gsi, u32 channel_id) ...@@ -846,12 +764,6 @@ int gsi_channel_trans_init(struct gsi *gsi, u32 channel_id)
if (ret) if (ret)
goto err_map_free; goto err_map_free;
spin_lock_init(&trans_info->spinlock);
INIT_LIST_HEAD(&trans_info->alloc);
INIT_LIST_HEAD(&trans_info->committed);
INIT_LIST_HEAD(&trans_info->pending);
INIT_LIST_HEAD(&trans_info->complete);
INIT_LIST_HEAD(&trans_info->polled);
return 0; return 0;
......
...@@ -29,7 +29,6 @@ struct gsi_trans_pool; ...@@ -29,7 +29,6 @@ struct gsi_trans_pool;
* struct gsi_trans - a GSI transaction * struct gsi_trans - a GSI transaction
* *
* Most fields in this structure for internal use by the transaction core code: * Most fields in this structure for internal use by the transaction core code:
* @links: Links for channel transaction lists by state
* @gsi: GSI pointer * @gsi: GSI pointer
* @channel_id: Channel number transaction is associated with * @channel_id: Channel number transaction is associated with
* @cancelled: If set by the core code, transaction was cancelled * @cancelled: If set by the core code, transaction was cancelled
...@@ -50,8 +49,6 @@ struct gsi_trans_pool; ...@@ -50,8 +49,6 @@ struct gsi_trans_pool;
* received. * received.
*/ */
struct gsi_trans { struct gsi_trans {
struct list_head links; /* gsi_channel lists */
struct gsi *gsi; struct gsi *gsi;
u8 channel_id; u8 channel_id;
......
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