net: ipa: always use transaction IDs instead of lists
authorAlex Elder <elder@linaro.org>
Tue, 6 Sep 2022 17:19:38 +0000 (12:19 -0500)
committerDavid S. Miller <davem@davemloft.net>
Fri, 9 Sep 2022 10:45:25 +0000 (11:45 +0100)
In gsi_channel_trans_complete(), use the completed and pending IDs
to determine whether there are any transactions in completed state.

Similarly, in gsi_channel_trans_cancel_pending(), use the pending
and committed IDs to mark pending transactions cancelled.  Rearrange
the logic a bit there for a simpler result.

This removes the only user of list_last_entry_or_null(), so get rid
of that macro.

Remove the temporary warnings added by the previous commit.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ipa/gsi_private.h
drivers/net/ipa/gsi_trans.c

index 51bbc7a40dc2d462dea1d0e876be7fc18356fe01..0b2516fa21b5deb057a38aee8f16babab66532cd 100644 (file)
@@ -16,20 +16,6 @@ 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
index 05ab4d052c68be982591a201d12d9d799358d270..a131a4fbb53fcae4b189005aba0fcb1c90e18d39 100644 (file)
@@ -239,22 +239,11 @@ struct gsi_trans *gsi_channel_trans_complete(struct gsi_channel *channel)
 {
        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);
+       if (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;
+       return &trans_info->trans[trans_id %= channel->tre_count];
 }
 
 /* Move a transaction from the allocated list to the committed list */
@@ -705,47 +694,32 @@ void gsi_trans_complete(struct gsi_trans *trans)
 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;
+       u16 trans_id = trans_info->pending_id;
 
        /* 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);
 
-       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) {
-               u16 trans_id;
+       /* If there are no pending transactions, we're done */
+       if (trans_id == trans_info->committed_id)
+               return;
 
-               napi_schedule(&channel->napi);
+       /* Mark all pending transactions cancelled */
+       do {
+               struct gsi_trans *trans;
 
-               trans_id = trans_info->completed_id;
                trans = &trans_info->trans[trans_id % channel->tre_count];
-               WARN_ON(trans != first);
+               trans->cancelled = true;
+       } while (++trans_id != trans_info->committed_id);
 
-               trans_id = trans_info->pending_id - 1;
-               trans = &trans_info->trans[trans_id % channel->tre_count];
-               WARN_ON(trans != last);
-       }
+       /* All pending transactions are now completed */
+       trans_info->pending_id = trans_info->committed_id;
+
+       /* Schedule NAPI polling to complete the cancelled transactions */
+       napi_schedule(&channel->napi);
 }
 
 /* Issue a command to read a single byte from a channel */