aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ipa/ipa_mem.c
diff options
context:
space:
mode:
authorAlex Elder <elder@linaro.org>2021-06-10 14:23:08 -0500
committerDavid S. Miller <davem@davemloft.net>2021-06-10 14:50:08 -0700
commitc61cfb941dcd8c0529a0c0be31bb1722feaa6082 (patch)
treea2c1ba1603548024f248273b416e001b3975d3c8 /drivers/net/ipa/ipa_mem.c
parentnet: ipa: introduce ipa_mem_find() (diff)
downloadlinux-dev-c61cfb941dcd8c0529a0c0be31bb1722feaa6082.tar.xz
linux-dev-c61cfb941dcd8c0529a0c0be31bb1722feaa6082.zip
net: ipa: don't index mem data array by ID
Finally the code handles the IPA memory region array in the configuration data without assuming it is indexed by region ID. Get rid of the array index designators where these arrays are initialized. As a result, there's no more need to define an explicitly undefined memory region ID, so get rid of that. Change ipa_mem_find() so it no longer assumes the ipa->mem[] array is indexed by memory region ID. Instead, have it search the array for the entry having the requested memory ID, and return the address of the descriptor if found. Otherwise return NULL. Stop allowing memory regions to be defined with zero size and zero canary value. Check for this condition in ipa_mem_valid_one(). As a result, it is not necessary to check for this case in ipa_mem_config(). Finally, there is no need for IPA_MEM_UNDEFINED to be defined any more, so get rid of it. Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ipa/ipa_mem.c')
-rw-r--r--drivers/net/ipa/ipa_mem.c38
1 files changed, 16 insertions, 22 deletions
diff --git a/drivers/net/ipa/ipa_mem.c b/drivers/net/ipa/ipa_mem.c
index 633895fc67b6..4337b0920d3d 100644
--- a/drivers/net/ipa/ipa_mem.c
+++ b/drivers/net/ipa/ipa_mem.c
@@ -28,8 +28,14 @@
const struct ipa_mem *ipa_mem_find(struct ipa *ipa, enum ipa_mem_id mem_id)
{
- if (mem_id < IPA_MEM_COUNT)
- return &ipa->mem[mem_id];
+ u32 i;
+
+ for (i = 0; i < ipa->mem_count; i++) {
+ const struct ipa_mem *mem = &ipa->mem[i];
+
+ if (mem->id == mem_id)
+ return mem;
+ }
return NULL;
}
@@ -209,6 +215,11 @@ static bool ipa_mem_valid_one(struct ipa *ipa, const struct ipa_mem *mem)
return false;
}
+ if (!mem->size && !mem->canary_count) {
+ dev_err(dev, "empty memory region %u\n", mem_id);
+ return false;
+ }
+
/* Other than modem memory, sizes must be a multiple of 8 */
size_multiple = mem_id == IPA_MEM_MODEM ? 4 : 8;
if (mem->size % size_multiple)
@@ -244,25 +255,14 @@ static bool ipa_mem_valid(struct ipa *ipa, const struct ipa_mem_data *mem_data)
for (i = 0; i < mem_data->local_count; i++) {
const struct ipa_mem *mem = &mem_data->local[i];
- if (mem->id == IPA_MEM_UNDEFINED)
- continue;
-
if (__test_and_set_bit(mem->id, regions)) {
dev_err(dev, "duplicate memory region %u\n", mem->id);
return false;
}
/* Defined regions have non-zero size and/or canary count */
- if (mem->size || mem->canary_count) {
- if (ipa_mem_valid_one(ipa, mem))
- continue;
+ if (!ipa_mem_valid_one(ipa, mem))
return false;
- }
-
- /* It's harmless, but warn if an offset is provided */
- if (mem->offset)
- dev_warn(dev, "empty region %u has non-zero offset\n",
- mem->id);
}
/* Now see if any required regions are not defined */
@@ -349,20 +349,14 @@ int ipa_mem_config(struct ipa *ipa)
* space prior to the region's base address if indicated.
*/
for (i = 0; i < ipa->mem_count; i++) {
- u16 canary_count;
+ u16 canary_count = ipa->mem[i].canary_count;
__le32 *canary;
- /* Skip over undefined regions */
- mem = &ipa->mem[i];
- if (!mem->offset && !mem->size)
- continue;
-
- canary_count = mem->canary_count;
if (!canary_count)
continue;
/* Write canary values in the space before the region */
- canary = ipa->mem_virt + ipa->mem_offset + mem->offset;
+ canary = ipa->mem_virt + ipa->mem_offset + ipa->mem[i].offset;
do
*--canary = IPA_MEM_CANARY_VAL;
while (--canary_count);