Lines Matching +full:ipa +full:- +full:ap +full:- +full:to +full:- +full:modem

1 // SPDX-License-Identifier: GPL-2.0
3 /* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
4 * Copyright (C) 2018-2024 Linaro Ltd.
10 #include <linux/dma-mapping.h>
16 #include "ipa.h"
25 * DOC: IPA Filter and Route Tables
27 * The IPA has tables defined in its local (IPA-resident) memory that define
29 * endian 64-bit "slot" that holds the address of a rule definition. (The
35 * by all IPA hardware (IPA v4.2 doesn't support hashed tables).
38 * an object (such as a route or filter table) in IPA-resident memory must
39 * 128-byte aligned. An object in system memory (such as a route or filter
40 * rule) must be at an 8-byte aligned address. We currently only place
43 * A rule consists of a contiguous block of 32-bit values terminated with
48 * Each filter rule is associated with an AP or modem TX endpoint, though
49 * not all TX endpoints support filtering. The first 64-bit slot in a
52 * address of a filter rule in the memory following the bitmap. Until IPA
53 * v5.0, the low-order bit (bit 0) in this bitmap represents a special
54 * global filter, which applies to all traffic. Otherwise the position of
58 * removed starting at IPA v5.0. For IPA v5.0+, the endpoint bitmap
59 * position defines the endpoint ID--i.e. if bit 1 is set in the endpoint
60 * bitmap, endpoint 1 has a filter rule. Older versions of IPA represent
70 * The AP initializes all entries in a filter table to refer to a "zero"
71 * rule. Once initialized, the modem and AP update the entries for
72 * endpoints they "own" directly. Currently the AP does not use the IPA
76 * bitmap as defined prior to IPA v5.0.
78 * IPA Filter Table
79 * ----------------------
81 * |--------------------|
82 * 1st endpoint | 0x000123456789abc0 | DMA address for modem endpoint 2 rule
83 * |--------------------|
84 * 2nd endpoint | 0x000123456789abf0 | DMA address for AP endpoint 5 rule
85 * |--------------------|
87 * |--------------------|
89 * |--------------------|
91 * ----------------------
93 * The set of available route rules is divided about equally between the AP
94 * and modem. The AP initializes all entries in a route table to refer to
95 * a "zero entry". Once initialized, the modem and AP are responsible for
97 * though the AP currently does not use the IPA routing functionality.
99 * IPA Route Table
100 * ----------------------
101 * 1st modem route | 0x0001234500001100 | DMA address for first route rule
102 * |--------------------|
103 * 2nd modem route | 0x0001234500001140 | DMA address for second route rule
104 * |--------------------|
106 * |--------------------|
107 * Last modem route| 0x0001234500002280 | DMA address for Nth route rule
108 * |--------------------|
109 * 1st AP route | 0x0001234500001100 | DMA address for route rule (N+1)
110 * |--------------------|
111 * 2nd AP route | 0x0001234500001140 | DMA address for next route rule
112 * |--------------------|
114 * |--------------------|
115 * Last AP route | 0x0001234500002280 | DMA address for last route rule
116 * ----------------------
119 /* Filter or route rules consist of a set of 32-bit values followed by a
120 * 32-bit all-zero rule list terminator. The "zero rule" is simply an
121 * all-zero rule followed by the list terminator.
129 * to filter or route rules. But the size of a table entry in ipa_table_validate_build()
130 * is 64 bits regardless of what the size of an AP DMA address in ipa_table_validate_build()
132 * code in ipa_table_init() uses a pointer to __le64 to in ipa_table_validate_build()
137 /* A "zero rule" is used to represent no filtering or no routing. in ipa_table_validate_build()
138 * It is a 64-bit block of zeroed memory. Code in ipa_table_init() in ipa_table_validate_build()
139 * assumes that it can be written using a pointer to __le64. in ipa_table_validate_build()
145 ipa_table_mem(struct ipa *ipa, bool filter, bool hashed, bool ipv6) in ipa_table_mem() argument
158 return ipa_mem_find(ipa, mem_id); in ipa_table_mem()
162 bool ipa_table_hash_support(struct ipa *ipa) in ipa_table_hash_support() argument
164 return ipa->version != IPA_VERSION_4_2; in ipa_table_hash_support()
167 bool ipa_filtered_valid(struct ipa *ipa, u64 filtered) in ipa_filtered_valid() argument
169 struct device *dev = ipa->dev; in ipa_filtered_valid()
179 if (count > ipa->filter_count) { in ipa_filtered_valid()
181 count, ipa->filter_count); in ipa_filtered_valid()
190 static dma_addr_t ipa_table_addr(struct ipa *ipa, bool filter_mask, u16 count) in ipa_table_addr() argument
197 WARN_ON(count > max_t(u32, ipa->filter_count, ipa->route_count)); in ipa_table_addr()
202 return ipa->table_addr + skip * sizeof(*ipa->table_virt); in ipa_table_addr()
208 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_table_reset_add() local
214 /* Nothing to do if the memory region is doesn't exist or is empty */ in ipa_table_reset_add()
215 mem = ipa_table_mem(ipa, filter, hashed, ipv6); in ipa_table_reset_add()
216 if (!mem || !mem->size) in ipa_table_reset_add()
222 offset = mem->offset + first * sizeof(__le64); in ipa_table_reset_add()
224 addr = ipa_table_addr(ipa, false, count); in ipa_table_reset_add()
229 /* Reset entries in a single filter table belonging to either the AP or
230 * modem to refer to the zero entry. The memory region supplied will be
231 * for the IPv4 and IPv6 non-hashed and hashed filter tables.
234 ipa_filter_reset_table(struct ipa *ipa, bool hashed, bool ipv6, bool modem) in ipa_filter_reset_table() argument
236 u64 ep_mask = ipa->filtered; in ipa_filter_reset_table()
240 trans = ipa_cmd_trans_alloc(ipa, hweight64(ep_mask)); in ipa_filter_reset_table()
242 dev_err(ipa->dev, "no transaction for %s filter reset\n", in ipa_filter_reset_table()
243 modem ? "modem" : "AP"); in ipa_filter_reset_table()
244 return -EBUSY; in ipa_filter_reset_table()
247 ee_id = modem ? GSI_EE_MODEM : GSI_EE_AP; in ipa_filter_reset_table()
254 endpoint = &ipa->endpoint[endpoint_id]; in ipa_filter_reset_table()
255 if (endpoint->ee_id != ee_id) in ipa_filter_reset_table()
266 /* Theoretically, each filter table could have more filter slots to
270 static int ipa_filter_reset(struct ipa *ipa, bool modem) in ipa_filter_reset() argument
274 ret = ipa_filter_reset_table(ipa, false, false, modem); in ipa_filter_reset()
278 ret = ipa_filter_reset_table(ipa, false, true, modem); in ipa_filter_reset()
279 if (ret || !ipa_table_hash_support(ipa)) in ipa_filter_reset()
282 ret = ipa_filter_reset_table(ipa, true, false, modem); in ipa_filter_reset()
286 return ipa_filter_reset_table(ipa, true, true, modem); in ipa_filter_reset()
289 /* The AP routes and modem routes are each contiguous within the
291 * won't exceed the per-transaction command limit.
293 static int ipa_route_reset(struct ipa *ipa, bool modem) in ipa_route_reset() argument
295 bool hash_support = ipa_table_hash_support(ipa); in ipa_route_reset()
296 u32 modem_route_count = ipa->modem_route_count; in ipa_route_reset()
301 trans = ipa_cmd_trans_alloc(ipa, hash_support ? 4 : 2); in ipa_route_reset()
303 dev_err(ipa->dev, "no transaction for %s route reset\n", in ipa_route_reset()
304 modem ? "modem" : "AP"); in ipa_route_reset()
305 return -EBUSY; in ipa_route_reset()
308 if (modem) { in ipa_route_reset()
313 count = ipa->route_count - modem_route_count; in ipa_route_reset()
329 void ipa_table_reset(struct ipa *ipa, bool modem) in ipa_table_reset() argument
331 struct device *dev = ipa->dev; in ipa_table_reset()
335 ee_name = modem ? "modem" : "AP"; in ipa_table_reset()
338 ret = ipa_filter_reset(ipa, modem); in ipa_table_reset()
343 ret = ipa_route_reset(ipa, modem); in ipa_table_reset()
349 int ipa_table_hash_flush(struct ipa *ipa) in ipa_table_hash_flush() argument
355 if (!ipa_table_hash_support(ipa)) in ipa_table_hash_flush()
358 trans = ipa_cmd_trans_alloc(ipa, 1); in ipa_table_hash_flush()
360 dev_err(ipa->dev, "no transaction for hash flush\n"); in ipa_table_hash_flush()
361 return -EBUSY; in ipa_table_hash_flush()
364 if (ipa->version < IPA_VERSION_5_0) { in ipa_table_hash_flush()
365 reg = ipa_reg(ipa, FILT_ROUT_HASH_FLUSH); in ipa_table_hash_flush()
372 reg = ipa_reg(ipa, FILT_ROUT_CACHE_FLUSH); in ipa_table_hash_flush()
374 /* IPA v5.0+ uses a unified cache (both IPv4 and IPv6) */ in ipa_table_hash_flush()
388 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_table_init_add() local
407 /* The non-hashed region will exist (see ipa_table_mem_valid()) */ in ipa_table_init_add()
408 mem = ipa_table_mem(ipa, filter, false, ipv6); in ipa_table_init_add()
409 hash_mem = ipa_table_mem(ipa, filter, true, ipv6); in ipa_table_init_add()
410 hash_offset = hash_mem ? hash_mem->offset : 0; in ipa_table_init_add()
412 /* Compute the number of table entries to initialize */ in ipa_table_init_add()
416 * to hold the bitmap itself. The size of the hashed filter in ipa_table_init_add()
417 * table is either the same as the non-hashed one, or zero. in ipa_table_init_add()
419 count = 1 + hweight64(ipa->filtered); in ipa_table_init_add()
420 hash_count = hash_mem && hash_mem->size ? count : 0; in ipa_table_init_add()
425 count = mem->size / sizeof(__le64); in ipa_table_init_add()
426 hash_count = hash_mem ? hash_mem->size / sizeof(__le64) : 0; in ipa_table_init_add()
431 addr = ipa_table_addr(ipa, filter, count); in ipa_table_init_add()
432 hash_addr = ipa_table_addr(ipa, filter, hash_count); in ipa_table_init_add()
434 ipa_cmd_table_init_add(trans, opcode, size, mem->offset, addr, in ipa_table_init_add()
440 zero_offset = mem->offset + size; in ipa_table_init_add()
441 zero_size = mem->size - size; in ipa_table_init_add()
443 ipa->zero_addr, true); in ipa_table_init_add()
449 zero_size = hash_mem->size - hash_size; in ipa_table_init_add()
451 ipa->zero_addr, true); in ipa_table_init_add()
454 int ipa_table_setup(struct ipa *ipa) in ipa_table_setup() argument
459 * - IPv4: in ipa_table_setup()
460 * - One for route table initialization (non-hashed and hashed) in ipa_table_setup()
461 * - One for filter table initialization (non-hashed and hashed) in ipa_table_setup()
462 * - One to zero unused entries in the non-hashed filter table in ipa_table_setup()
463 * - One to zero unused entries in the hashed filter table in ipa_table_setup()
464 * - IPv6: in ipa_table_setup()
465 * - One for route table initialization (non-hashed and hashed) in ipa_table_setup()
466 * - One for filter table initialization (non-hashed and hashed) in ipa_table_setup()
467 * - One to zero unused entries in the non-hashed filter table in ipa_table_setup()
468 * - One to zero unused entries in the hashed filter table in ipa_table_setup()
471 trans = ipa_cmd_trans_alloc(ipa, 8); in ipa_table_setup()
473 dev_err(ipa->dev, "no transaction for table setup\n"); in ipa_table_setup()
474 return -EBUSY; in ipa_table_setup()
488 * ipa_filter_tuple_zero() - Zero an endpoint's hashed filter tuple
491 * Endpoint must be for the AP (not modem) and support filtering. Updates
496 u32 endpoint_id = endpoint->endpoint_id; in ipa_filter_tuple_zero()
497 struct ipa *ipa = endpoint->ipa; in ipa_filter_tuple_zero() local
502 if (ipa->version < IPA_VERSION_5_0) { in ipa_filter_tuple_zero()
503 reg = ipa_reg(ipa, ENDP_FILTER_ROUTER_HSH_CFG); in ipa_filter_tuple_zero()
506 val = ioread32(endpoint->ipa->reg_virt + offset); in ipa_filter_tuple_zero()
508 /* Zero all filter-related fields, preserving the rest */ in ipa_filter_tuple_zero()
511 /* IPA v5.0 separates filter and router cache configuration */ in ipa_filter_tuple_zero()
512 reg = ipa_reg(ipa, ENDP_FILTER_CACHE_CFG); in ipa_filter_tuple_zero()
515 /* Zero all filter-related fields */ in ipa_filter_tuple_zero()
519 iowrite32(val, endpoint->ipa->reg_virt + offset); in ipa_filter_tuple_zero()
523 static void ipa_filter_config(struct ipa *ipa, bool modem) in ipa_filter_config() argument
525 enum gsi_ee_id ee_id = modem ? GSI_EE_MODEM : GSI_EE_AP; in ipa_filter_config()
526 u64 ep_mask = ipa->filtered; in ipa_filter_config()
528 if (!ipa_table_hash_support(ipa)) in ipa_filter_config()
537 endpoint = &ipa->endpoint[endpoint_id]; in ipa_filter_config()
538 if (endpoint->ee_id == ee_id) in ipa_filter_config()
543 static bool ipa_route_id_modem(struct ipa *ipa, u32 route_id) in ipa_route_id_modem() argument
545 return route_id < ipa->modem_route_count; in ipa_route_id_modem()
549 * ipa_route_tuple_zero() - Zero a hashed route table entry tuple
550 * @ipa: IPA pointer
555 static void ipa_route_tuple_zero(struct ipa *ipa, u32 route_id) in ipa_route_tuple_zero() argument
561 if (ipa->version < IPA_VERSION_5_0) { in ipa_route_tuple_zero()
562 reg = ipa_reg(ipa, ENDP_FILTER_ROUTER_HSH_CFG); in ipa_route_tuple_zero()
565 val = ioread32(ipa->reg_virt + offset); in ipa_route_tuple_zero()
567 /* Zero all route-related fields, preserving the rest */ in ipa_route_tuple_zero()
570 /* IPA v5.0 separates filter and router cache configuration */ in ipa_route_tuple_zero()
571 reg = ipa_reg(ipa, ENDP_ROUTER_CACHE_CFG); in ipa_route_tuple_zero()
574 /* Zero all route-related fields */ in ipa_route_tuple_zero()
578 iowrite32(val, ipa->reg_virt + offset); in ipa_route_tuple_zero()
582 static void ipa_route_config(struct ipa *ipa, bool modem) in ipa_route_config() argument
586 if (!ipa_table_hash_support(ipa)) in ipa_route_config()
589 for (route_id = 0; route_id < ipa->route_count; route_id++) in ipa_route_config()
590 if (ipa_route_id_modem(ipa, route_id) == modem) in ipa_route_config()
591 ipa_route_tuple_zero(ipa, route_id); in ipa_route_config()
595 void ipa_table_config(struct ipa *ipa) in ipa_table_config() argument
597 ipa_filter_config(ipa, false); in ipa_table_config()
598 ipa_filter_config(ipa, true); in ipa_table_config()
599 ipa_route_config(ipa, false); in ipa_table_config()
600 ipa_route_config(ipa, true); in ipa_table_config()
603 /* Verify the sizes of all IPA table filter or routing table memory regions
606 bool ipa_table_mem_valid(struct ipa *ipa, bool filter) in ipa_table_mem_valid() argument
608 bool hash_support = ipa_table_hash_support(ipa); in ipa_table_mem_valid()
614 /* IPv4 and IPv6 non-hashed tables are expected to be defined and in ipa_table_mem_valid()
618 mem_ipv4 = ipa_table_mem(ipa, filter, false, false); in ipa_table_mem_valid()
622 mem_ipv6 = ipa_table_mem(ipa, filter, false, true); in ipa_table_mem_valid()
626 if (mem_ipv4->size != mem_ipv6->size) in ipa_table_mem_valid()
630 count = mem_ipv4->size / sizeof(__le64); in ipa_table_mem_valid()
634 ipa->filter_count = count - 1; /* Filter map in first entry */ in ipa_table_mem_valid()
636 ipa->route_count = count; in ipa_table_mem_valid()
639 if (!ipa_cmd_table_init_valid(ipa, mem_ipv4, !filter)) in ipa_table_mem_valid()
644 /* Filter tables must able to hold the endpoint bitmap plus in ipa_table_mem_valid()
647 if (count < 1 + hweight64(ipa->filtered)) in ipa_table_mem_valid()
650 /* Routing tables must be able to hold all modem entries, in ipa_table_mem_valid()
651 * plus at least one entry for the AP. in ipa_table_mem_valid()
653 if (count < ipa->modem_route_count + 1) in ipa_table_mem_valid()
657 /* If hashing is supported, hashed tables are expected to be defined, in ipa_table_mem_valid()
658 * and have the same size as non-hashed tables. If hashing is not in ipa_table_mem_valid()
659 * supported, hashed tables are expected to have zero size (or not in ipa_table_mem_valid()
662 mem_hashed = ipa_table_mem(ipa, filter, true, false); in ipa_table_mem_valid()
664 if (!mem_hashed || mem_hashed->size != mem_ipv4->size) in ipa_table_mem_valid()
667 if (mem_hashed && mem_hashed->size) in ipa_table_mem_valid()
672 mem_hashed = ipa_table_mem(ipa, filter, true, true); in ipa_table_mem_valid()
674 if (!mem_hashed || mem_hashed->size != mem_ipv6->size) in ipa_table_mem_valid()
677 if (mem_hashed && mem_hashed->size) in ipa_table_mem_valid()
685 * route table data. This is used when initializing or resetting the IPA
689 * endpoints contain entries in the table. In addition to that first entry,
694 * reset) its entries are made to refer to the zero rule.
697 * routing there is also a 64-bit "zero rule" that means no routing, and
698 * when a route table is initialized or reset, its entries are made to refer
699 * to the zero rule. The zero rule is shared for route and filter tables.
701 * +-------------------+
702 * --> | zero rule |
703 * / |-------------------|
705 * |\ |-------------------|
706 * | ---- zero rule address | \
707 * |\ |-------------------| |
708 * | ---- zero rule address | | Max IPA filter count
709 * | |-------------------| > or IPA route count,
711 * \ |-------------------| |
712 * ---- zero rule address | /
713 * +-------------------+
715 int ipa_table_init(struct ipa *ipa) in ipa_table_init() argument
717 struct device *dev = ipa->dev; in ipa_table_init()
726 count = max_t(u32, ipa->filter_count, ipa->route_count); in ipa_table_init()
728 /* The IPA hardware requires route and filter table rules to be in ipa_table_init()
729 * aligned on a 128-byte boundary. We put the "zero rule" at the in ipa_table_init()
731 * by dma_alloc_coherent() is guaranteed to be a power-of-2 number in ipa_table_init()
737 return -ENOMEM; in ipa_table_init()
739 ipa->table_virt = virt; in ipa_table_init()
740 ipa->table_addr = addr; in ipa_table_init()
746 * need to be converted to the hardware representation by shifting in ipa_table_init()
747 * it left one position. Prior to IPA v5.0, bit 0 repesents global in ipa_table_init()
748 * filtering, which is possible but not used. IPA v5.0+ eliminated in ipa_table_init()
751 if (ipa->version < IPA_VERSION_5_0) in ipa_table_init()
752 *virt++ = cpu_to_le64(ipa->filtered << 1); in ipa_table_init()
754 *virt++ = cpu_to_le64(ipa->filtered); in ipa_table_init()
758 while (count--) in ipa_table_init()
764 void ipa_table_exit(struct ipa *ipa) in ipa_table_exit() argument
766 u32 count = max_t(u32, 1 + ipa->filter_count, ipa->route_count); in ipa_table_exit()
767 struct device *dev = ipa->dev; in ipa_table_exit()
772 dma_free_coherent(dev, size, ipa->table_virt, ipa->table_addr); in ipa_table_exit()
773 ipa->table_addr = 0; in ipa_table_exit()
774 ipa->table_virt = NULL; in ipa_table_exit()