Lines Matching +full:dma +full:- +full:mem
1 // SPDX-License-Identifier: GPL-2.0
3 /* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
4 * Copyright (C) 2018-2020 Linaro Ltd.
15 #include <linux/dma-mapping.h>
31 * and routing rules. Each entry in these tables contains a 64-bit DMA
33 * A rule consists of a contiguous block of 32-bit values terminated with
42 * not all TX endpoints support filtering. The first 64-bit entry in a
44 * the table. The low-order bit (bit 0) in this bitmap represents a
47 * entry (i.e. a DMA address referring to a rule) for endpoint 0 in the
59 * ----------------------
61 * |--------------------|
62 * 1st endpoint | 0x000123456789abc0 | DMA address for modem endpoint 2 rule
63 * |--------------------|
64 * 2nd endpoint | 0x000123456789abf0 | DMA address for AP endpoint 5 rule
65 * |--------------------|
67 * |--------------------|
69 * |--------------------|
71 * ----------------------
80 * ----------------------
81 * 1st modem route | 0x0001234500001100 | DMA address for first route rule
82 * |--------------------|
83 * 2nd modem route | 0x0001234500001140 | DMA address for second route rule
84 * |--------------------|
86 * |--------------------|
87 * Last modem route| 0x0001234500002280 | DMA address for Nth route rule
88 * |--------------------|
89 * 1st AP route | 0x0001234500001100 | DMA address for route rule (N+1)
90 * |--------------------|
91 * 2nd AP route | 0x0001234500001140 | DMA address for next route rule
92 * |--------------------|
94 * |--------------------|
95 * Last AP route | 0x0001234500002280 | DMA address for last route rule
96 * ----------------------
108 (IPA_ROUTE_COUNT_MAX - IPA_ROUTE_MODEM_COUNT)
110 /* Filter or route rules consist of a set of 32-bit values followed by a
111 * 32-bit all-zero rule list terminator. The "zero rule" is simply an
112 * all-zero rule followed by the list terminator.
123 * aligned on 128-byte byte boundaries. The only rule address in ipa_table_validate_build()
125 * of a coherent DMA allocation. in ipa_table_validate_build()
129 /* Filter and route tables contain DMA addresses that refer to 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()
155 struct device *dev = &ipa->pdev->dev; in ipa_table_valid_one()
156 const struct ipa_mem *mem; in ipa_table_valid_one() local
161 mem = hashed ? &ipa->mem[IPA_MEM_V6_ROUTE_HASHED] in ipa_table_valid_one()
162 : &ipa->mem[IPA_MEM_V6_ROUTE]; in ipa_table_valid_one()
164 mem = hashed ? &ipa->mem[IPA_MEM_V4_ROUTE_HASHED] in ipa_table_valid_one()
165 : &ipa->mem[IPA_MEM_V4_ROUTE]; in ipa_table_valid_one()
169 mem = hashed ? &ipa->mem[IPA_MEM_V6_FILTER_HASHED] in ipa_table_valid_one()
170 : &ipa->mem[IPA_MEM_V6_FILTER]; in ipa_table_valid_one()
172 mem = hashed ? &ipa->mem[IPA_MEM_V4_FILTER_HASHED] in ipa_table_valid_one()
173 : &ipa->mem[IPA_MEM_V4_FILTER]; in ipa_table_valid_one()
177 if (!ipa_cmd_table_valid(ipa, mem, route, ipv6, hashed)) in ipa_table_valid_one()
180 /* mem->size >= size is sufficient, but we'll demand more */ in ipa_table_valid_one()
181 if (mem->size == size) in ipa_table_valid_one()
185 if (hashed && !mem->size) in ipa_table_valid_one()
190 route ? "route" : "filter", mem->size, size); in ipa_table_valid_one()
214 struct device *dev = &ipa->pdev->dev; in ipa_filter_map_valid()
255 return ipa->table_addr + skip * sizeof(*ipa->table_virt); in ipa_table_addr()
259 u16 first, u16 count, const struct ipa_mem *mem) in ipa_table_reset_add() argument
261 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_table_reset_add()
267 if (!mem->size) in ipa_table_reset_add()
273 offset = mem->offset + first * IPA_TABLE_ENTRY_SIZE; in ipa_table_reset_add()
282 * for the IPv4 and IPv6 non-hashed and hashed filter tables.
285 ipa_filter_reset_table(struct ipa *ipa, const struct ipa_mem *mem, bool modem) in ipa_filter_reset_table() argument
287 u32 ep_mask = ipa->filter_map; in ipa_filter_reset_table()
292 if (!mem->size) in ipa_filter_reset_table()
297 dev_err(&ipa->pdev->dev, in ipa_filter_reset_table()
300 return -EBUSY; in ipa_filter_reset_table()
310 endpoint = &ipa->endpoint[endpoint_id]; in ipa_filter_reset_table()
311 if (endpoint->ee_id != ee_id) in ipa_filter_reset_table()
314 ipa_table_reset_add(trans, true, endpoint_id, 1, mem); in ipa_filter_reset_table()
330 ret = ipa_filter_reset_table(ipa, &ipa->mem[IPA_MEM_V4_FILTER], modem); in ipa_filter_reset()
334 ret = ipa_filter_reset_table(ipa, &ipa->mem[IPA_MEM_V4_FILTER_HASHED], in ipa_filter_reset()
339 ret = ipa_filter_reset_table(ipa, &ipa->mem[IPA_MEM_V6_FILTER], modem); in ipa_filter_reset()
342 ret = ipa_filter_reset_table(ipa, &ipa->mem[IPA_MEM_V6_FILTER_HASHED], in ipa_filter_reset()
350 * won't exceed the per-transaction command limit.
360 dev_err(&ipa->pdev->dev, in ipa_route_reset()
363 return -EBUSY; in ipa_route_reset()
375 &ipa->mem[IPA_MEM_V4_ROUTE]); in ipa_route_reset()
377 &ipa->mem[IPA_MEM_V4_ROUTE_HASHED]); in ipa_route_reset()
380 &ipa->mem[IPA_MEM_V6_ROUTE]); in ipa_route_reset()
382 &ipa->mem[IPA_MEM_V6_ROUTE_HASHED]); in ipa_route_reset()
391 struct device *dev = &ipa->pdev->dev; in ipa_table_reset()
411 u32 offset = ipa_reg_filt_rout_hash_flush_offset(ipa->version); in ipa_table_hash_flush()
416 if (ipa->version == IPA_VERSION_4_2) in ipa_table_hash_flush()
421 dev_err(&ipa->pdev->dev, "no transaction for hash flush\n"); in ipa_table_hash_flush()
422 return -EBUSY; in ipa_table_hash_flush()
437 const struct ipa_mem *mem, in ipa_table_init_add() argument
440 struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi); in ipa_table_init_add()
449 * in the filter table. The hashed and non-hashed filter table in ipa_table_init_add()
454 count = hweight32(ipa->filter_map); in ipa_table_init_add()
455 hash_count = hash_mem->size ? count : 0; in ipa_table_init_add()
457 count = mem->size / IPA_TABLE_ENTRY_SIZE; in ipa_table_init_add()
458 hash_count = hash_mem->size / IPA_TABLE_ENTRY_SIZE; in ipa_table_init_add()
466 ipa_cmd_table_init_add(trans, opcode, size, mem->offset, addr, in ipa_table_init_add()
467 hash_size, hash_mem->offset, hash_addr); in ipa_table_init_add()
476 dev_err(&ipa->pdev->dev, "no transaction for table setup\n"); in ipa_table_setup()
477 return -EBUSY; in ipa_table_setup()
481 &ipa->mem[IPA_MEM_V4_ROUTE], in ipa_table_setup()
482 &ipa->mem[IPA_MEM_V4_ROUTE_HASHED]); in ipa_table_setup()
485 &ipa->mem[IPA_MEM_V6_ROUTE], in ipa_table_setup()
486 &ipa->mem[IPA_MEM_V6_ROUTE_HASHED]); in ipa_table_setup()
489 &ipa->mem[IPA_MEM_V4_FILTER], in ipa_table_setup()
490 &ipa->mem[IPA_MEM_V4_FILTER_HASHED]); in ipa_table_setup()
493 &ipa->mem[IPA_MEM_V6_FILTER], in ipa_table_setup()
494 &ipa->mem[IPA_MEM_V6_FILTER_HASHED]); in ipa_table_setup()
507 * ipa_filter_tuple_zero() - Zero an endpoint's hashed filter tuple
515 u32 endpoint_id = endpoint->endpoint_id; in ipa_filter_tuple_zero()
521 val = ioread32(endpoint->ipa->reg_virt + offset); in ipa_filter_tuple_zero()
523 /* Zero all filter-related fields, preserving the rest */ in ipa_filter_tuple_zero()
526 iowrite32(val, endpoint->ipa->reg_virt + offset); in ipa_filter_tuple_zero()
532 u32 ep_mask = ipa->filter_map; in ipa_filter_config()
535 if (ipa->version == IPA_VERSION_4_2) in ipa_filter_config()
544 endpoint = &ipa->endpoint[endpoint_id]; in ipa_filter_config()
545 if (endpoint->ee_id == ee_id) in ipa_filter_config()
558 route_id <= IPA_ROUTE_MODEM_MIN + IPA_ROUTE_MODEM_COUNT - 1; in ipa_route_id_modem()
562 * ipa_route_tuple_zero() - Zero a hashed route table entry tuple
573 val = ioread32(ipa->reg_virt + offset); in ipa_route_tuple_zero()
575 /* Zero all route-related fields, preserving the rest */ in ipa_route_tuple_zero()
578 iowrite32(val, ipa->reg_virt + offset); in ipa_route_tuple_zero()
586 if (ipa->version == IPA_VERSION_4_2) in ipa_route_config()
616 * Initialize a coherent DMA allocation containing initialized filter and
623 * entries are 64 bits wide, and (other than the bitmap) contain the DMA
628 * Each entry in a route table is the DMA address of a routing rule. For
629 * routing there is also a 64-bit "zero rule" that means no routing, and
634 * aligned on a 128 byte boundary. The coherent DMA buffer we allocate here
636 * allocated space. In ipa_table_init() we verify the minimum DMA allocation
639 * +-------------------+
640 * --> | zero rule |
641 * / |-------------------|
643 * |\ |-------------------|
644 * | ---- zero rule address | \
645 * |\ |-------------------| |
646 * | ---- zero rule address | | IPA_FILTER_COUNT_MAX
647 * | |-------------------| > or IPA_ROUTE_COUNT_MAX,
649 * \ |-------------------| |
650 * ---- zero rule address | /
651 * +-------------------+
656 struct device *dev = &ipa->pdev->dev; in ipa_table_init()
667 return -ENOMEM; in ipa_table_init()
669 ipa->table_virt = virt; in ipa_table_init()
670 ipa->table_addr = addr; in ipa_table_init()
680 *virt++ = cpu_to_le64((u64)ipa->filter_map << 1); in ipa_table_init()
682 /* All the rest contain the DMA address of the zero rule */ in ipa_table_init()
684 while (count--) in ipa_table_init()
693 struct device *dev = &ipa->pdev->dev; in ipa_table_exit()
698 dma_free_coherent(dev, size, ipa->table_virt, ipa->table_addr); in ipa_table_exit()
699 ipa->table_addr = 0; in ipa_table_exit()
700 ipa->table_virt = NULL; in ipa_table_exit()