Lines Matching +full:non +full:- +full:zero

1 // SPDX-License-Identifier: GPL-2.0
3 /* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
4 * Copyright (C) 2018-2023 Linaro Ltd.
15 #include <linux/dma-mapping.h>
30 * The IPA has tables defined in its local (IPA-resident) memory that define
32 * endian 64-bit "slot" that holds the address of a rule definition. (The
41 * an object (such as a route or filter table) in IPA-resident memory must
42 * 128-byte aligned. An object in system memory (such as a route or filter
43 * rule) must be at an 8-byte aligned address. We currently only place
46 * A rule consists of a contiguous block of 32-bit values terminated with
47 * 32 zero bits. A special "zero entry" rule consisting of 64 zero bits
52 * not all TX endpoints support filtering. The first 64-bit slot in a
56 * v5.0, the low-order bit (bit 0) in this bitmap represents a special
62 * position defines the endpoint ID--i.e. if bit 1 is set in the endpoint
73 * The AP initializes all entries in a filter table to refer to a "zero"
82 * ----------------------
84 * |--------------------|
86 * |--------------------|
88 * |--------------------|
90 * |--------------------|
92 * |--------------------|
94 * ----------------------
98 * a "zero entry". Once initialized, the modem and AP are responsible for
103 * ----------------------
105 * |--------------------|
107 * |--------------------|
109 * |--------------------|
111 * |--------------------|
113 * |--------------------|
115 * |--------------------|
117 * |--------------------|
119 * ----------------------
122 /* Filter or route rules consist of a set of 32-bit values followed by a
123 * 32-bit all-zero rule list terminator. The "zero rule" is simply an
124 * all-zero rule followed by the list terminator.
140 /* A "zero rule" is used to represent no filtering or no routing. in ipa_table_validate_build()
141 * It is a 64-bit block of zeroed memory. Code in ipa_table_init() in ipa_table_validate_build()
166 struct device *dev = &ipa->pdev->dev; in ipa_filtered_valid()
176 if (count > ipa->filter_count) { in ipa_filtered_valid()
178 count, ipa->filter_count); in ipa_filtered_valid()
186 /* Zero entry count means no table, so just return a 0 address */
194 WARN_ON(count > max_t(u32, ipa->filter_count, ipa->route_count)); in ipa_table_addr()
196 /* Skip over the zero rule and possibly the filter mask */ in ipa_table_addr()
199 return ipa->table_addr + skip * sizeof(*ipa->table_virt); in ipa_table_addr()
205 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_table_reset_add()
213 if (!mem || !mem->size) in ipa_table_reset_add()
219 offset = mem->offset + first * sizeof(__le64); in ipa_table_reset_add()
227 * modem to refer to the zero entry. The memory region supplied will be
228 * for the IPv4 and IPv6 non-hashed and hashed filter tables.
233 u64 ep_mask = ipa->filtered; in ipa_filter_reset_table()
239 dev_err(&ipa->pdev->dev, in ipa_filter_reset_table()
242 return -EBUSY; in ipa_filter_reset_table()
252 endpoint = &ipa->endpoint[endpoint_id]; in ipa_filter_reset_table()
253 if (endpoint->ee_id != ee_id) in ipa_filter_reset_table()
289 * won't exceed the per-transaction command limit.
294 u32 modem_route_count = ipa->modem_route_count; in ipa_route_reset()
301 dev_err(&ipa->pdev->dev, in ipa_route_reset()
304 return -EBUSY; in ipa_route_reset()
312 count = ipa->route_count - modem_route_count; in ipa_route_reset()
330 struct device *dev = &ipa->pdev->dev; in ipa_table_reset()
359 dev_err(&ipa->pdev->dev, "no transaction for hash flush\n"); in ipa_table_hash_flush()
360 return -EBUSY; in ipa_table_hash_flush()
363 if (ipa->version < IPA_VERSION_5_0) { in ipa_table_hash_flush()
387 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_table_init_add()
406 /* The non-hashed region will exist (see ipa_table_mem_valid()) */ in ipa_table_init_add()
409 hash_offset = hash_mem ? hash_mem->offset : 0; in ipa_table_init_add()
416 * table is either the same as the non-hashed one, or zero. in ipa_table_init_add()
418 count = 1 + hweight64(ipa->filtered); in ipa_table_init_add()
419 hash_count = hash_mem && hash_mem->size ? count : 0; in ipa_table_init_add()
424 count = mem->size / sizeof(__le64); in ipa_table_init_add()
425 hash_count = hash_mem ? hash_mem->size / sizeof(__le64) : 0; in ipa_table_init_add()
433 ipa_cmd_table_init_add(trans, opcode, size, mem->offset, addr, in ipa_table_init_add()
438 /* Zero the unused space in the filter table */ in ipa_table_init_add()
439 zero_offset = mem->offset + size; in ipa_table_init_add()
440 zero_size = mem->size - size; in ipa_table_init_add()
442 ipa->zero_addr, true); in ipa_table_init_add()
446 /* Zero the unused space in the hashed filter table */ in ipa_table_init_add()
448 zero_size = hash_mem->size - hash_size; in ipa_table_init_add()
450 ipa->zero_addr, true); in ipa_table_init_add()
458 * - IPv4: in ipa_table_setup()
459 * - One for route table initialization (non-hashed and hashed) in ipa_table_setup()
460 * - One for filter table initialization (non-hashed and hashed) in ipa_table_setup()
461 * - One to zero unused entries in the non-hashed filter table in ipa_table_setup()
462 * - One to zero unused entries in the hashed filter table in ipa_table_setup()
463 * - IPv6: in ipa_table_setup()
464 * - One for route table initialization (non-hashed and hashed) in ipa_table_setup()
465 * - One for filter table initialization (non-hashed and hashed) in ipa_table_setup()
466 * - One to zero unused entries in the non-hashed filter table in ipa_table_setup()
467 * - One to zero unused entries in the hashed filter table in ipa_table_setup()
472 dev_err(&ipa->pdev->dev, "no transaction for table setup\n"); in ipa_table_setup()
473 return -EBUSY; in ipa_table_setup()
487 * ipa_filter_tuple_zero() - Zero an endpoint's hashed filter tuple
495 u32 endpoint_id = endpoint->endpoint_id; in ipa_filter_tuple_zero()
496 struct ipa *ipa = endpoint->ipa; in ipa_filter_tuple_zero()
501 if (ipa->version < IPA_VERSION_5_0) { in ipa_filter_tuple_zero()
505 val = ioread32(endpoint->ipa->reg_virt + offset); in ipa_filter_tuple_zero()
507 /* Zero all filter-related fields, preserving the rest */ in ipa_filter_tuple_zero()
514 /* Zero all filter-related fields */ in ipa_filter_tuple_zero()
518 iowrite32(val, endpoint->ipa->reg_virt + offset); in ipa_filter_tuple_zero()
525 u64 ep_mask = ipa->filtered; in ipa_filter_config()
536 endpoint = &ipa->endpoint[endpoint_id]; in ipa_filter_config()
537 if (endpoint->ee_id == ee_id) in ipa_filter_config()
544 return route_id < ipa->modem_route_count; in ipa_route_id_modem()
548 * ipa_route_tuple_zero() - Zero a hashed route table entry tuple
560 if (ipa->version < IPA_VERSION_5_0) { in ipa_route_tuple_zero()
564 val = ioread32(ipa->reg_virt + offset); in ipa_route_tuple_zero()
566 /* Zero all route-related fields, preserving the rest */ in ipa_route_tuple_zero()
573 /* Zero all route-related fields */ in ipa_route_tuple_zero()
577 iowrite32(val, ipa->reg_virt + offset); in ipa_route_tuple_zero()
588 for (route_id = 0; route_id < ipa->route_count; route_id++) in ipa_route_config()
613 /* IPv4 and IPv6 non-hashed tables are expected to be defined and in ipa_table_mem_valid()
625 if (mem_ipv4->size != mem_ipv6->size) in ipa_table_mem_valid()
629 count = mem_ipv4->size / sizeof(__le64); in ipa_table_mem_valid()
633 ipa->filter_count = count - 1; /* Filter map in first entry */ in ipa_table_mem_valid()
635 ipa->route_count = count; in ipa_table_mem_valid()
646 if (count < 1 + hweight64(ipa->filtered)) in ipa_table_mem_valid()
652 if (count < ipa->modem_route_count + 1) in ipa_table_mem_valid()
657 * and have the same size as non-hashed tables. If hashing is not in ipa_table_mem_valid()
658 * supported, hashed tables are expected to have zero size (or not in ipa_table_mem_valid()
663 if (!mem_hashed || mem_hashed->size != mem_ipv4->size) in ipa_table_mem_valid()
666 if (mem_hashed && mem_hashed->size) in ipa_table_mem_valid()
673 if (!mem_hashed || mem_hashed->size != mem_ipv6->size) in ipa_table_mem_valid()
676 if (mem_hashed && mem_hashed->size) in ipa_table_mem_valid()
691 * address of a filter rule. A "zero rule" indicates no filtering, and
693 * reset) its entries are made to refer to the zero rule.
696 * routing there is also a 64-bit "zero rule" that means no routing, and
698 * to the zero rule. The zero rule is shared for route and filter tables.
700 * +-------------------+
701 * --> | zero rule |
702 * / |-------------------|
704 * |\ |-------------------|
705 * | ---- zero rule address | \
706 * |\ |-------------------| |
707 * | ---- zero rule address | | Max IPA filter count
708 * | |-------------------| > or IPA route count,
710 * \ |-------------------| |
711 * ---- zero rule address | /
712 * +-------------------+
716 struct device *dev = &ipa->pdev->dev; in ipa_table_init()
725 count = max_t(u32, ipa->filter_count, ipa->route_count); in ipa_table_init()
728 * aligned on a 128-byte boundary. We put the "zero rule" at the in ipa_table_init()
730 * by dma_alloc_coherent() is guaranteed to be a power-of-2 number in ipa_table_init()
736 return -ENOMEM; in ipa_table_init()
738 ipa->table_virt = virt; in ipa_table_init()
739 ipa->table_addr = addr; in ipa_table_init()
741 /* First slot is the zero rule */ in ipa_table_init()
750 if (ipa->version < IPA_VERSION_5_0) in ipa_table_init()
751 *virt++ = cpu_to_le64(ipa->filtered << 1); in ipa_table_init()
753 *virt++ = cpu_to_le64(ipa->filtered); in ipa_table_init()
755 /* All the rest contain the DMA address of the zero rule */ in ipa_table_init()
757 while (count--) in ipa_table_init()
765 u32 count = max_t(u32, 1 + ipa->filter_count, ipa->route_count); in ipa_table_exit()
766 struct device *dev = &ipa->pdev->dev; in ipa_table_exit()
771 dma_free_coherent(dev, size, ipa->table_virt, ipa->table_addr); in ipa_table_exit()
772 ipa->table_addr = 0; in ipa_table_exit()
773 ipa->table_virt = NULL; in ipa_table_exit()