diff options
| -rw-r--r-- | drivers/net/ipa/gsi.c | 55 | ||||
| -rw-r--r-- | drivers/net/ipa/gsi_private.h | 14 | ||||
| -rw-r--r-- | drivers/net/ipa/gsi_trans.c | 68 |
3 files changed, 79 insertions, 58 deletions
diff --git a/drivers/net/ipa/gsi.c b/drivers/net/ipa/gsi.c index 9e307eebd33f..16df699009a8 100644 --- a/drivers/net/ipa/gsi.c +++ b/drivers/net/ipa/gsi.c @@ -710,43 +710,32 @@ static void gsi_evt_ring_program(struct gsi *gsi, u32 evt_ring_id) static struct gsi_trans *gsi_channel_trans_last(struct gsi_channel *channel) { struct gsi_trans_info *trans_info = &channel->trans_info; - const struct list_head *list; + u32 pending_id = trans_info->pending_id; struct gsi_trans *trans; - - spin_lock_bh(&trans_info->spinlock); - - /* There is a small chance a TX transaction got allocated just - * before we disabled transmits, so check for that. - */ - if (channel->toward_ipa) { - list = &trans_info->alloc; - if (!list_empty(list)) - goto done; - list = &trans_info->committed; - if (!list_empty(list)) - goto done; - list = &trans_info->pending; - if (!list_empty(list)) - goto done; + u16 trans_id; + + if (channel->toward_ipa && pending_id != trans_info->free_id) { + /* There is a small chance a TX transaction got allocated + * just before we disabled transmits, so check for that. + * The last allocated, committed, or pending transaction + * precedes the first free transaction. + */ + trans_id = trans_info->free_id - 1; + } else if (trans_info->polled_id != pending_id) { + /* Otherwise (TX or RX) we want to wait for anything that + * has completed, or has been polled but not released yet. + * + * The last completed or polled transaction precedes the + * first pending transaction. + */ + trans_id = pending_id - 1; + } else { + return NULL; } - /* Otherwise (TX or RX) we want to wait for anything that - * has completed, or has been polled but not released yet. - */ - list = &trans_info->complete; - if (!list_empty(list)) - goto done; - list = &trans_info->polled; - if (list_empty(list)) - list = NULL; -done: - trans = list ? list_last_entry(list, struct gsi_trans, links) : NULL; - /* Caller will wait for this, so take a reference */ - if (trans) - refcount_inc(&trans->refcount); - - spin_unlock_bh(&trans_info->spinlock); + trans = &trans_info->trans[trans_id % channel->tre_count]; + refcount_inc(&trans->refcount); return trans; } diff --git a/drivers/net/ipa/gsi_private.h b/drivers/net/ipa/gsi_private.h index 0b2516fa21b5..51bbc7a40dc2 100644 --- a/drivers/net/ipa/gsi_private.h +++ b/drivers/net/ipa/gsi_private.h @@ -17,6 +17,20 @@ struct gsi_channel; #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 * @trans: Transaction to commit */ diff --git a/drivers/net/ipa/gsi_trans.c b/drivers/net/ipa/gsi_trans.c index 4eef1480c200..05ab4d052c68 100644 --- a/drivers/net/ipa/gsi_trans.c +++ b/drivers/net/ipa/gsi_trans.c @@ -237,8 +237,24 @@ gsi_channel_trans_mapped(struct gsi_channel *channel, u32 index) /* Return the oldest completed transaction for a channel (or null) */ struct gsi_trans *gsi_channel_trans_complete(struct gsi_channel *channel) { - return list_first_entry_or_null(&channel->trans_info.complete, - struct gsi_trans, links); + struct gsi_trans_info *trans_info = &channel->trans_info; + 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)) { + trans_id %= channel->tre_count; + WARN_ON(trans != &trans_info->trans[trans_id]); + } + + return trans; } /* Move a transaction from the allocated list to the committed list */ @@ -309,23 +325,15 @@ void gsi_trans_move_polled(struct gsi_trans *trans) { struct gsi_channel *channel = &trans->gsi->channel[trans->channel_id]; struct gsi_trans_info *trans_info = &channel->trans_info; - u16 trans_index; spin_lock_bh(&trans_info->spinlock); list_move_tail(&trans->links, &trans_info->polled); - trans = list_first_entry(&trans_info->polled, - struct gsi_trans, links); - spin_unlock_bh(&trans_info->spinlock); /* This completed transaction is now polled */ trans_info->completed_id++; - - WARN_ON(trans_info->polled_id == trans_info->completed_id); - trans_index = trans_info->polled_id % channel->tre_count; - WARN_ON(trans != &trans_info->trans[trans_index]); } /* Reserve some number of TREs on a channel. Returns true if successful */ @@ -413,11 +421,8 @@ struct gsi_trans *gsi_channel_trans_alloc(struct gsi *gsi, u32 channel_id, /* Free a previously-allocated transaction */ void gsi_trans_free(struct gsi_trans *trans) { - struct gsi_channel *channel = &trans->gsi->channel[trans->channel_id]; refcount_t *refcount = &trans->refcount; struct gsi_trans_info *trans_info; - struct gsi_trans *polled; - u16 trans_index; bool last; /* We must hold the lock to release the last reference */ @@ -433,9 +438,6 @@ void gsi_trans_free(struct gsi_trans *trans) if (last) list_del(&trans->links); - polled = list_first_entry_or_null(&trans_info->polled, - struct gsi_trans, links); - spin_unlock_bh(&trans_info->spinlock); if (!last) @@ -456,14 +458,6 @@ void gsi_trans_free(struct gsi_trans *trans) /* This transaction is now free */ trans_info->polled_id++; - if (polled) { - trans_index = trans_info->polled_id % channel->tre_count; - WARN_ON(polled != &trans_info->trans[trans_index]); - } else { - WARN_ON(trans_info->polled_id != - trans_info->completed_id); - } - /* Releasing the reserved TREs implicitly frees the sgl[] and * (if present) info[] arrays, plus the transaction itself. */ @@ -712,6 +706,8 @@ void gsi_channel_trans_cancel_pending(struct gsi_channel *channel) { struct gsi_trans_info *trans_info = &channel->trans_info; struct gsi_trans *trans; + struct gsi_trans *first; + struct gsi_trans *last; bool cancelled; /* channel->gsi->mutex is held by caller */ @@ -723,11 +719,33 @@ void gsi_channel_trans_cancel_pending(struct gsi_channel *channel) list_splice_tail_init(&trans_info->pending, &trans_info->complete); + first = list_first_entry_or_null(&trans_info->complete, + struct gsi_trans, links); + last = list_last_entry_or_null(&trans_info->complete, + struct gsi_trans, links); + spin_unlock_bh(&trans_info->spinlock); + /* 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; + /* Schedule NAPI polling to complete the cancelled transactions */ - if (cancelled) + if (cancelled) { + 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 */ |
