]> git.itanic.dy.fi Git - linux-stable/commitdiff
net: ipa: reduce arguments to ipa_table_init_add()
authorAlex Elder <elder@linaro.org>
Wed, 2 Nov 2022 22:11:31 +0000 (17:11 -0500)
committerDavid S. Miller <davem@davemloft.net>
Fri, 4 Nov 2022 10:16:53 +0000 (10:16 +0000)
Recently ipa_table_mem() was added as a way to look up one of 8
possible memory regions by indicating whether it was a filter or
route table, hashed or not, and IPv6 or not.

We can simplify the interface to ipa_table_init_add() by passing two
flags to it instead of the opcode and both hashed and non-hashed
memory region IDs.  The "filter" and "ipv6" flags are sufficient to
determine the opcode to use, and with ipa_table_mem() can look up
the correct memory region as well.

It's possible to not have hashed tables, but we already verify the
number of entries in a filter or routing table is nonzero.  Stop
assuming a hashed table entry exists in ipa_table_init_add().

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

index cf3a3de239dc3f72cc7cf3828e10e59eaecdb74b..94bb7611e574ba4b3d8f9317213788ec943da73e 100644 (file)
@@ -376,14 +376,12 @@ int ipa_table_hash_flush(struct ipa *ipa)
        return 0;
 }
 
-static void ipa_table_init_add(struct gsi_trans *trans, bool filter,
-                              enum ipa_cmd_opcode opcode,
-                              enum ipa_mem_id mem_id,
-                              enum ipa_mem_id hash_mem_id)
+static void ipa_table_init_add(struct gsi_trans *trans, bool filter, bool ipv6)
 {
        struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi);
-       const struct ipa_mem *hash_mem = ipa_mem_find(ipa, hash_mem_id);
-       const struct ipa_mem *mem = ipa_mem_find(ipa, mem_id);
+       const struct ipa_mem *hash_mem;
+       enum ipa_cmd_opcode opcode;
+       const struct ipa_mem *mem;
        dma_addr_t hash_addr;
        dma_addr_t addr;
        u32 zero_offset;
@@ -393,6 +391,14 @@ static void ipa_table_init_add(struct gsi_trans *trans, bool filter,
        u16 count;
        u16 size;
 
+       opcode = filter ? ipv6 ? IPA_CMD_IP_V6_FILTER_INIT
+                              : IPA_CMD_IP_V4_FILTER_INIT
+                       : ipv6 ? IPA_CMD_IP_V6_ROUTING_INIT
+                              : IPA_CMD_IP_V4_ROUTING_INIT;
+
+       mem = ipa_table_mem(ipa, filter, false, ipv6);
+       hash_mem = ipa_table_mem(ipa, filter, true, ipv6);
+
        /* Compute the number of table entries to initialize */
        if (filter) {
                /* The number of filtering endpoints determines number of
@@ -401,13 +407,13 @@ static void ipa_table_init_add(struct gsi_trans *trans, bool filter,
                 * table is either the same as the non-hashed one, or zero.
                 */
                count = 1 + hweight32(ipa->filter_map);
-               hash_count = hash_mem->size ? count : 0;
+               hash_count = hash_mem && hash_mem->size ? count : 0;
        } else {
                /* The size of a route table region determines the number
                 * of entries it has.
                 */
                count = mem->size / sizeof(__le64);
-               hash_count = hash_mem->size / sizeof(__le64);
+               hash_count = hash_mem && hash_mem->size / sizeof(__le64);
        }
        size = count * sizeof(__le64);
        hash_size = hash_count * sizeof(__le64);
@@ -458,17 +464,10 @@ int ipa_table_setup(struct ipa *ipa)
                return -EBUSY;
        }
 
-       ipa_table_init_add(trans, false, IPA_CMD_IP_V4_ROUTING_INIT,
-                          IPA_MEM_V4_ROUTE, IPA_MEM_V4_ROUTE_HASHED);
-
-       ipa_table_init_add(trans, false, IPA_CMD_IP_V6_ROUTING_INIT,
-                          IPA_MEM_V6_ROUTE, IPA_MEM_V6_ROUTE_HASHED);
-
-       ipa_table_init_add(trans, true, IPA_CMD_IP_V4_FILTER_INIT,
-                          IPA_MEM_V4_FILTER, IPA_MEM_V4_FILTER_HASHED);
-
-       ipa_table_init_add(trans, true, IPA_CMD_IP_V6_FILTER_INIT,
-                          IPA_MEM_V6_FILTER, IPA_MEM_V6_FILTER_HASHED);
+       ipa_table_init_add(trans, false, false);
+       ipa_table_init_add(trans, false, true);
+       ipa_table_init_add(trans, true, false);
+       ipa_table_init_add(trans, true, true);
 
        gsi_trans_commit_wait(trans);