2020-03-05 22:28:25 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
|
|
|
/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
|
2022-09-30 17:45:49 -05:00
|
|
|
* Copyright (C) 2018-2022 Linaro Ltd.
|
2020-03-05 22:28:25 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/bits.h>
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/bitfield.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/build_bug.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
|
|
|
|
#include "ipa.h"
|
|
|
|
#include "ipa_version.h"
|
|
|
|
#include "ipa_endpoint.h"
|
|
|
|
#include "ipa_table.h"
|
|
|
|
#include "ipa_reg.h"
|
|
|
|
#include "ipa_mem.h"
|
|
|
|
#include "ipa_cmd.h"
|
|
|
|
#include "gsi.h"
|
|
|
|
#include "gsi_trans.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DOC: IPA Filter and Route Tables
|
|
|
|
*
|
2021-03-28 12:31:11 -05:00
|
|
|
* The IPA has tables defined in its local (IPA-resident) memory that define
|
|
|
|
* filter and routing rules. An entry in either of these tables is a little
|
|
|
|
* endian 64-bit "slot" that holds the address of a rule definition. (The
|
|
|
|
* size of these slots is 64 bits regardless of the host DMA address size.)
|
|
|
|
*
|
|
|
|
* Separate tables (both filter and route) used for IPv4 and IPv6. There
|
|
|
|
* are normally another set of "hashed" filter and route tables, which are
|
|
|
|
* used with a hash of message metadata. Hashed operation is not supported
|
|
|
|
* by all IPA hardware (IPA v4.2 doesn't support hashed tables).
|
|
|
|
*
|
|
|
|
* Rules can be in local memory or in DRAM (system memory). The offset of
|
|
|
|
* an object (such as a route or filter table) in IPA-resident memory must
|
|
|
|
* 128-byte aligned. An object in system memory (such as a route or filter
|
|
|
|
* rule) must be at an 8-byte aligned address. We currently only place
|
|
|
|
* route or filter rules in system memory.
|
|
|
|
*
|
2020-03-05 22:28:25 -06:00
|
|
|
* A rule consists of a contiguous block of 32-bit values terminated with
|
|
|
|
* 32 zero bits. A special "zero entry" rule consisting of 64 zero bits
|
|
|
|
* represents "no filtering" or "no routing," and is the reset value for
|
2021-03-28 12:31:11 -05:00
|
|
|
* filter or route table rules.
|
2020-03-05 22:28:25 -06:00
|
|
|
*
|
|
|
|
* Each filter rule is associated with an AP or modem TX endpoint, though
|
2021-03-28 12:31:11 -05:00
|
|
|
* not all TX endpoints support filtering. The first 64-bit slot in a
|
2020-03-05 22:28:25 -06:00
|
|
|
* filter table is a bitmap indicating which endpoints have entries in
|
|
|
|
* the table. The low-order bit (bit 0) in this bitmap represents a
|
|
|
|
* special global filter, which applies to all traffic. This is not
|
|
|
|
* used in the current code. Bit 1, if set, indicates that there is an
|
2021-03-28 12:31:11 -05:00
|
|
|
* entry (i.e. slot containing a system address referring to a rule) for
|
|
|
|
* endpoint 0 in the table. Bit 3, if set, indicates there is an entry
|
|
|
|
* for endpoint 2, and so on. Space is set aside in IPA local memory to
|
|
|
|
* hold as many filter table entries as might be required, but typically
|
|
|
|
* they are not all used.
|
2020-03-05 22:28:25 -06:00
|
|
|
*
|
|
|
|
* The AP initializes all entries in a filter table to refer to a "zero"
|
|
|
|
* entry. Once initialized the modem and AP update the entries for
|
|
|
|
* endpoints they "own" directly. Currently the AP does not use the
|
|
|
|
* IPA filtering functionality.
|
|
|
|
*
|
|
|
|
* IPA Filter Table
|
|
|
|
* ----------------------
|
|
|
|
* endpoint bitmap | 0x0000000000000048 | Bits 3 and 6 set (endpoints 2 and 5)
|
|
|
|
* |--------------------|
|
|
|
|
* 1st endpoint | 0x000123456789abc0 | DMA address for modem endpoint 2 rule
|
|
|
|
* |--------------------|
|
|
|
|
* 2nd endpoint | 0x000123456789abf0 | DMA address for AP endpoint 5 rule
|
|
|
|
* |--------------------|
|
|
|
|
* (unused) | | (Unused space in filter table)
|
|
|
|
* |--------------------|
|
|
|
|
* . . .
|
|
|
|
* |--------------------|
|
|
|
|
* (unused) | | (Unused space in filter table)
|
|
|
|
* ----------------------
|
|
|
|
*
|
|
|
|
* The set of available route rules is divided about equally between the AP
|
|
|
|
* and modem. The AP initializes all entries in a route table to refer to
|
|
|
|
* a "zero entry". Once initialized, the modem and AP are responsible for
|
|
|
|
* updating their own entries. All entries in a route table are usable,
|
|
|
|
* though the AP currently does not use the IPA routing functionality.
|
|
|
|
*
|
|
|
|
* IPA Route Table
|
|
|
|
* ----------------------
|
|
|
|
* 1st modem route | 0x0001234500001100 | DMA address for first route rule
|
|
|
|
* |--------------------|
|
|
|
|
* 2nd modem route | 0x0001234500001140 | DMA address for second route rule
|
|
|
|
* |--------------------|
|
|
|
|
* . . .
|
|
|
|
* |--------------------|
|
|
|
|
* Last modem route| 0x0001234500002280 | DMA address for Nth route rule
|
|
|
|
* |--------------------|
|
|
|
|
* 1st AP route | 0x0001234500001100 | DMA address for route rule (N+1)
|
|
|
|
* |--------------------|
|
|
|
|
* 2nd AP route | 0x0001234500001140 | DMA address for next route rule
|
|
|
|
* |--------------------|
|
|
|
|
* . . .
|
|
|
|
* |--------------------|
|
|
|
|
* Last AP route | 0x0001234500002280 | DMA address for last route rule
|
|
|
|
* ----------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Filter or route rules consist of a set of 32-bit values followed by a
|
|
|
|
* 32-bit all-zero rule list terminator. The "zero rule" is simply an
|
|
|
|
* all-zero rule followed by the list terminator.
|
|
|
|
*/
|
|
|
|
#define IPA_ZERO_RULE_SIZE (2 * sizeof(__le32))
|
|
|
|
|
|
|
|
/* Check things that can be validated at build time. */
|
|
|
|
static void ipa_table_validate_build(void)
|
|
|
|
{
|
2021-03-18 13:59:27 -05:00
|
|
|
/* Filter and route tables contain DMA addresses that refer
|
|
|
|
* to filter or route rules. But the size of a table entry
|
|
|
|
* is 64 bits regardless of what the size of an AP DMA address
|
|
|
|
* is. A fixed constant defines the size of an entry, and
|
|
|
|
* code in ipa_table_init() uses a pointer to __le64 to
|
|
|
|
* initialize tables.
|
2020-03-05 22:28:25 -06:00
|
|
|
*/
|
2021-03-28 12:31:11 -05:00
|
|
|
BUILD_BUG_ON(sizeof(dma_addr_t) > sizeof(__le64));
|
2020-03-05 22:28:25 -06:00
|
|
|
|
|
|
|
/* A "zero rule" is used to represent no filtering or no routing.
|
|
|
|
* It is a 64-bit block of zeroed memory. Code in ipa_table_init()
|
|
|
|
* assumes that it can be written using a pointer to __le64.
|
|
|
|
*/
|
|
|
|
BUILD_BUG_ON(IPA_ZERO_RULE_SIZE != sizeof(__le64));
|
|
|
|
|
|
|
|
/* Impose a practical limit on the number of routes */
|
|
|
|
BUILD_BUG_ON(IPA_ROUTE_COUNT_MAX > 32);
|
|
|
|
/* The modem must be allotted at least one route table entry */
|
|
|
|
BUILD_BUG_ON(!IPA_ROUTE_MODEM_COUNT);
|
2022-10-21 14:13:36 -05:00
|
|
|
/* AP must too, but we can't use more than what is available */
|
|
|
|
BUILD_BUG_ON(IPA_ROUTE_MODEM_COUNT >= IPA_ROUTE_COUNT_MAX);
|
|
|
|
}
|
2020-03-05 22:28:25 -06:00
|
|
|
|
2022-10-21 14:13:36 -05:00
|
|
|
static const struct ipa_mem *
|
|
|
|
ipa_table_mem(struct ipa *ipa, bool filter, bool hashed, bool ipv6)
|
|
|
|
{
|
|
|
|
enum ipa_mem_id mem_id;
|
|
|
|
|
|
|
|
mem_id = filter ? hashed ? ipv6 ? IPA_MEM_V6_FILTER_HASHED
|
|
|
|
: IPA_MEM_V4_FILTER_HASHED
|
|
|
|
: ipv6 ? IPA_MEM_V6_FILTER
|
|
|
|
: IPA_MEM_V4_FILTER
|
|
|
|
: hashed ? ipv6 ? IPA_MEM_V6_ROUTE_HASHED
|
|
|
|
: IPA_MEM_V4_ROUTE_HASHED
|
|
|
|
: ipv6 ? IPA_MEM_V6_ROUTE
|
|
|
|
: IPA_MEM_V4_ROUTE;
|
|
|
|
|
|
|
|
return ipa_mem_find(ipa, mem_id);
|
2020-03-05 22:28:25 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ipa_filter_map_valid(struct ipa *ipa, u32 filter_map)
|
|
|
|
{
|
|
|
|
struct device *dev = &ipa->pdev->dev;
|
|
|
|
u32 count;
|
|
|
|
|
|
|
|
if (!filter_map) {
|
|
|
|
dev_err(dev, "at least one filtering endpoint is required\n");
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
count = hweight32(filter_map);
|
|
|
|
if (count > IPA_FILTER_COUNT_MAX) {
|
|
|
|
dev_err(dev, "too many filtering endpoints (%u, max %u)\n",
|
|
|
|
count, IPA_FILTER_COUNT_MAX);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Zero entry count means no table, so just return a 0 address */
|
|
|
|
static dma_addr_t ipa_table_addr(struct ipa *ipa, bool filter_mask, u16 count)
|
|
|
|
{
|
|
|
|
u32 skip;
|
|
|
|
|
|
|
|
if (!count)
|
|
|
|
return 0;
|
|
|
|
|
2022-10-25 14:51:40 -05:00
|
|
|
WARN_ON(count > max_t(u32, IPA_FILTER_COUNT_MAX, ipa->route_count));
|
2020-03-05 22:28:25 -06:00
|
|
|
|
|
|
|
/* Skip over the zero rule and possibly the filter mask */
|
|
|
|
skip = filter_mask ? 1 : 2;
|
|
|
|
|
|
|
|
return ipa->table_addr + skip * sizeof(*ipa->table_virt);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ipa_table_reset_add(struct gsi_trans *trans, bool filter,
|
2021-06-10 14:23:05 -05:00
|
|
|
u16 first, u16 count, enum ipa_mem_id mem_id)
|
2020-03-05 22:28:25 -06:00
|
|
|
{
|
|
|
|
struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi);
|
2021-06-10 14:23:07 -05:00
|
|
|
const struct ipa_mem *mem = ipa_mem_find(ipa, mem_id);
|
2020-03-05 22:28:25 -06:00
|
|
|
dma_addr_t addr;
|
|
|
|
u32 offset;
|
|
|
|
u16 size;
|
|
|
|
|
2021-06-10 14:23:05 -05:00
|
|
|
/* Nothing to do if the table memory region is empty */
|
2020-03-05 22:28:25 -06:00
|
|
|
if (!mem->size)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (filter)
|
|
|
|
first++; /* skip over bitmap */
|
|
|
|
|
2021-03-28 12:31:11 -05:00
|
|
|
offset = mem->offset + first * sizeof(__le64);
|
|
|
|
size = count * sizeof(__le64);
|
2020-03-05 22:28:25 -06:00
|
|
|
addr = ipa_table_addr(ipa, false, count);
|
|
|
|
|
|
|
|
ipa_cmd_dma_shared_mem_add(trans, offset, size, addr, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset entries in a single filter table belonging to either the AP or
|
|
|
|
* modem to refer to the zero entry. The memory region supplied will be
|
|
|
|
* for the IPv4 and IPv6 non-hashed and hashed filter tables.
|
|
|
|
*/
|
|
|
|
static int
|
2021-06-10 14:23:03 -05:00
|
|
|
ipa_filter_reset_table(struct ipa *ipa, enum ipa_mem_id mem_id, bool modem)
|
2020-03-05 22:28:25 -06:00
|
|
|
{
|
|
|
|
u32 ep_mask = ipa->filter_map;
|
|
|
|
u32 count = hweight32(ep_mask);
|
|
|
|
struct gsi_trans *trans;
|
|
|
|
enum gsi_ee_id ee_id;
|
|
|
|
|
|
|
|
trans = ipa_cmd_trans_alloc(ipa, count);
|
|
|
|
if (!trans) {
|
|
|
|
dev_err(&ipa->pdev->dev,
|
|
|
|
"no transaction for %s filter reset\n",
|
|
|
|
modem ? "modem" : "AP");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
ee_id = modem ? GSI_EE_MODEM : GSI_EE_AP;
|
|
|
|
while (ep_mask) {
|
|
|
|
u32 endpoint_id = __ffs(ep_mask);
|
|
|
|
struct ipa_endpoint *endpoint;
|
|
|
|
|
|
|
|
ep_mask ^= BIT(endpoint_id);
|
|
|
|
|
|
|
|
endpoint = &ipa->endpoint[endpoint_id];
|
|
|
|
if (endpoint->ee_id != ee_id)
|
|
|
|
continue;
|
|
|
|
|
2021-06-10 14:23:05 -05:00
|
|
|
ipa_table_reset_add(trans, true, endpoint_id, 1, mem_id);
|
2020-03-05 22:28:25 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
gsi_trans_commit_wait(trans);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Theoretically, each filter table could have more filter slots to
|
|
|
|
* update than the maximum number of commands in a transaction. So
|
|
|
|
* we do each table separately.
|
|
|
|
*/
|
|
|
|
static int ipa_filter_reset(struct ipa *ipa, bool modem)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2021-06-10 14:23:03 -05:00
|
|
|
ret = ipa_filter_reset_table(ipa, IPA_MEM_V4_FILTER, modem);
|
2020-03-05 22:28:25 -06:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2021-06-10 14:23:03 -05:00
|
|
|
ret = ipa_filter_reset_table(ipa, IPA_MEM_V4_FILTER_HASHED, modem);
|
2020-03-05 22:28:25 -06:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2021-06-10 14:23:03 -05:00
|
|
|
ret = ipa_filter_reset_table(ipa, IPA_MEM_V6_FILTER, modem);
|
2020-03-05 22:28:25 -06:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2021-06-10 14:23:03 -05:00
|
|
|
ret = ipa_filter_reset_table(ipa, IPA_MEM_V6_FILTER_HASHED, modem);
|
2020-03-05 22:28:25 -06:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The AP routes and modem routes are each contiguous within the
|
|
|
|
* table. We can update each table with a single command, and we
|
|
|
|
* won't exceed the per-transaction command limit.
|
|
|
|
* */
|
|
|
|
static int ipa_route_reset(struct ipa *ipa, bool modem)
|
|
|
|
{
|
|
|
|
struct gsi_trans *trans;
|
|
|
|
u16 first;
|
|
|
|
u16 count;
|
|
|
|
|
|
|
|
trans = ipa_cmd_trans_alloc(ipa, 4);
|
|
|
|
if (!trans) {
|
|
|
|
dev_err(&ipa->pdev->dev,
|
|
|
|
"no transaction for %s route reset\n",
|
|
|
|
modem ? "modem" : "AP");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (modem) {
|
2022-10-21 14:13:34 -05:00
|
|
|
first = 0;
|
2020-03-05 22:28:25 -06:00
|
|
|
count = IPA_ROUTE_MODEM_COUNT;
|
|
|
|
} else {
|
2022-10-21 14:13:34 -05:00
|
|
|
first = IPA_ROUTE_MODEM_COUNT;
|
2022-10-25 14:51:40 -05:00
|
|
|
count = ipa->route_count - IPA_ROUTE_MODEM_COUNT;
|
2020-03-05 22:28:25 -06:00
|
|
|
}
|
|
|
|
|
2021-06-10 14:23:05 -05:00
|
|
|
ipa_table_reset_add(trans, false, first, count, IPA_MEM_V4_ROUTE);
|
2020-03-05 22:28:25 -06:00
|
|
|
ipa_table_reset_add(trans, false, first, count,
|
2021-06-10 14:23:05 -05:00
|
|
|
IPA_MEM_V4_ROUTE_HASHED);
|
2020-03-05 22:28:25 -06:00
|
|
|
|
2021-06-10 14:23:05 -05:00
|
|
|
ipa_table_reset_add(trans, false, first, count, IPA_MEM_V6_ROUTE);
|
2020-03-05 22:28:25 -06:00
|
|
|
ipa_table_reset_add(trans, false, first, count,
|
2021-06-10 14:23:05 -05:00
|
|
|
IPA_MEM_V6_ROUTE_HASHED);
|
2020-03-05 22:28:25 -06:00
|
|
|
|
|
|
|
gsi_trans_commit_wait(trans);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ipa_table_reset(struct ipa *ipa, bool modem)
|
|
|
|
{
|
|
|
|
struct device *dev = &ipa->pdev->dev;
|
|
|
|
const char *ee_name;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ee_name = modem ? "modem" : "AP";
|
|
|
|
|
|
|
|
/* Report errors, but reset filter and route tables */
|
|
|
|
ret = ipa_filter_reset(ipa, modem);
|
|
|
|
if (ret)
|
|
|
|
dev_err(dev, "error %d resetting filter table for %s\n",
|
|
|
|
ret, ee_name);
|
|
|
|
|
|
|
|
ret = ipa_route_reset(ipa, modem);
|
|
|
|
if (ret)
|
|
|
|
dev_err(dev, "error %d resetting route table for %s\n",
|
|
|
|
ret, ee_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ipa_table_hash_flush(struct ipa *ipa)
|
|
|
|
{
|
2022-09-26 17:09:21 -05:00
|
|
|
const struct ipa_reg *reg;
|
2020-03-05 22:28:25 -06:00
|
|
|
struct gsi_trans *trans;
|
2022-09-26 17:09:21 -05:00
|
|
|
u32 offset;
|
2020-03-05 22:28:25 -06:00
|
|
|
u32 val;
|
|
|
|
|
2021-02-12 08:34:01 -06:00
|
|
|
if (!ipa_table_hash_support(ipa))
|
2020-03-05 22:28:25 -06:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
trans = ipa_cmd_trans_alloc(ipa, 1);
|
|
|
|
if (!trans) {
|
|
|
|
dev_err(&ipa->pdev->dev, "no transaction for hash flush\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
2022-09-26 17:09:21 -05:00
|
|
|
reg = ipa_reg(ipa, FILT_ROUT_HASH_FLUSH);
|
|
|
|
offset = ipa_reg_offset(reg);
|
|
|
|
|
2022-09-26 17:09:25 -05:00
|
|
|
val = ipa_reg_bit(reg, IPV6_ROUTER_HASH);
|
|
|
|
val |= ipa_reg_bit(reg, IPV6_FILTER_HASH);
|
|
|
|
val |= ipa_reg_bit(reg, IPV4_ROUTER_HASH);
|
|
|
|
val |= ipa_reg_bit(reg, IPV4_FILTER_HASH);
|
2020-03-05 22:28:25 -06:00
|
|
|
|
|
|
|
ipa_cmd_register_write_add(trans, offset, val, val, false);
|
|
|
|
|
|
|
|
gsi_trans_commit_wait(trans);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ipa_table_init_add(struct gsi_trans *trans, bool filter,
|
|
|
|
enum ipa_cmd_opcode opcode,
|
2021-06-10 14:23:05 -05:00
|
|
|
enum ipa_mem_id mem_id,
|
|
|
|
enum ipa_mem_id hash_mem_id)
|
2020-03-05 22:28:25 -06:00
|
|
|
{
|
|
|
|
struct ipa *ipa = container_of(trans->gsi, struct ipa, gsi);
|
2021-06-10 14:23:07 -05:00
|
|
|
const struct ipa_mem *hash_mem = ipa_mem_find(ipa, hash_mem_id);
|
|
|
|
const struct ipa_mem *mem = ipa_mem_find(ipa, mem_id);
|
2020-03-05 22:28:25 -06:00
|
|
|
dma_addr_t hash_addr;
|
|
|
|
dma_addr_t addr;
|
2021-11-24 14:25:06 -06:00
|
|
|
u32 zero_offset;
|
2020-03-05 22:28:25 -06:00
|
|
|
u16 hash_count;
|
2021-11-24 14:25:06 -06:00
|
|
|
u32 zero_size;
|
2020-03-05 22:28:25 -06:00
|
|
|
u16 hash_size;
|
|
|
|
u16 count;
|
|
|
|
u16 size;
|
|
|
|
|
2021-11-24 14:25:06 -06:00
|
|
|
/* Compute the number of table entries to initialize */
|
2020-03-05 22:28:25 -06:00
|
|
|
if (filter) {
|
2021-11-24 14:25:06 -06:00
|
|
|
/* The number of filtering endpoints determines number of
|
|
|
|
* entries in the filter table; we also add one more "slot"
|
|
|
|
* to hold the bitmap itself. The size of the hashed filter
|
|
|
|
* table is either the same as the non-hashed one, or zero.
|
|
|
|
*/
|
2021-09-07 12:05:54 -05:00
|
|
|
count = 1 + hweight32(ipa->filter_map);
|
2020-03-05 22:28:25 -06:00
|
|
|
hash_count = hash_mem->size ? count : 0;
|
|
|
|
} else {
|
2021-11-24 14:25:06 -06:00
|
|
|
/* The size of a route table region determines the number
|
|
|
|
* of entries it has.
|
|
|
|
*/
|
2021-03-28 12:31:11 -05:00
|
|
|
count = mem->size / sizeof(__le64);
|
|
|
|
hash_count = hash_mem->size / sizeof(__le64);
|
2020-03-05 22:28:25 -06:00
|
|
|
}
|
2021-03-28 12:31:11 -05:00
|
|
|
size = count * sizeof(__le64);
|
|
|
|
hash_size = hash_count * sizeof(__le64);
|
2020-03-05 22:28:25 -06:00
|
|
|
|
|
|
|
addr = ipa_table_addr(ipa, filter, count);
|
|
|
|
hash_addr = ipa_table_addr(ipa, filter, hash_count);
|
|
|
|
|
|
|
|
ipa_cmd_table_init_add(trans, opcode, size, mem->offset, addr,
|
|
|
|
hash_size, hash_mem->offset, hash_addr);
|
2021-11-24 14:25:06 -06:00
|
|
|
if (!filter)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Zero the unused space in the filter table */
|
|
|
|
zero_offset = mem->offset + size;
|
|
|
|
zero_size = mem->size - size;
|
|
|
|
ipa_cmd_dma_shared_mem_add(trans, zero_offset, zero_size,
|
|
|
|
ipa->zero_addr, true);
|
|
|
|
if (!hash_size)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Zero the unused space in the hashed filter table */
|
|
|
|
zero_offset = hash_mem->offset + hash_size;
|
|
|
|
zero_size = hash_mem->size - hash_size;
|
|
|
|
ipa_cmd_dma_shared_mem_add(trans, zero_offset, zero_size,
|
|
|
|
ipa->zero_addr, true);
|
2020-03-05 22:28:25 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
int ipa_table_setup(struct ipa *ipa)
|
|
|
|
{
|
|
|
|
struct gsi_trans *trans;
|
|
|
|
|
2021-11-24 14:25:06 -06:00
|
|
|
/* We will need at most 8 TREs:
|
|
|
|
* - IPv4:
|
|
|
|
* - One for route table initialization (non-hashed and hashed)
|
|
|
|
* - One for filter table initialization (non-hashed and hashed)
|
|
|
|
* - One to zero unused entries in the non-hashed filter table
|
|
|
|
* - One to zero unused entries in the hashed filter table
|
|
|
|
* - IPv6:
|
|
|
|
* - One for route table initialization (non-hashed and hashed)
|
|
|
|
* - One for filter table initialization (non-hashed and hashed)
|
|
|
|
* - One to zero unused entries in the non-hashed filter table
|
|
|
|
* - One to zero unused entries in the hashed filter table
|
|
|
|
* All platforms support at least 8 TREs in a transaction.
|
|
|
|
*/
|
|
|
|
trans = ipa_cmd_trans_alloc(ipa, 8);
|
2020-03-05 22:28:25 -06:00
|
|
|
if (!trans) {
|
|
|
|
dev_err(&ipa->pdev->dev, "no transaction for table setup\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
ipa_table_init_add(trans, false, IPA_CMD_IP_V4_ROUTING_INIT,
|
2021-06-10 14:23:05 -05:00
|
|
|
IPA_MEM_V4_ROUTE, IPA_MEM_V4_ROUTE_HASHED);
|
2020-03-05 22:28:25 -06:00
|
|
|
|
|
|
|
ipa_table_init_add(trans, false, IPA_CMD_IP_V6_ROUTING_INIT,
|
2021-06-10 14:23:05 -05:00
|
|
|
IPA_MEM_V6_ROUTE, IPA_MEM_V6_ROUTE_HASHED);
|
2020-03-05 22:28:25 -06:00
|
|
|
|
|
|
|
ipa_table_init_add(trans, true, IPA_CMD_IP_V4_FILTER_INIT,
|
2021-06-10 14:23:05 -05:00
|
|
|
IPA_MEM_V4_FILTER, IPA_MEM_V4_FILTER_HASHED);
|
2020-03-05 22:28:25 -06:00
|
|
|
|
|
|
|
ipa_table_init_add(trans, true, IPA_CMD_IP_V6_FILTER_INIT,
|
2021-06-10 14:23:05 -05:00
|
|
|
IPA_MEM_V6_FILTER, IPA_MEM_V6_FILTER_HASHED);
|
2020-03-05 22:28:25 -06:00
|
|
|
|
|
|
|
gsi_trans_commit_wait(trans);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ipa_filter_tuple_zero() - Zero an endpoint's hashed filter tuple
|
2020-07-13 07:24:18 -05:00
|
|
|
* @endpoint: Endpoint whose filter hash tuple should be zeroed
|
2020-03-05 22:28:25 -06:00
|
|
|
*
|
|
|
|
* Endpoint must be for the AP (not modem) and support filtering. Updates
|
|
|
|
* the filter hash values without changing route ones.
|
|
|
|
*/
|
|
|
|
static void ipa_filter_tuple_zero(struct ipa_endpoint *endpoint)
|
|
|
|
{
|
|
|
|
u32 endpoint_id = endpoint->endpoint_id;
|
2022-09-26 17:09:18 -05:00
|
|
|
struct ipa *ipa = endpoint->ipa;
|
2022-09-26 17:09:21 -05:00
|
|
|
const struct ipa_reg *reg;
|
2020-03-05 22:28:25 -06:00
|
|
|
u32 offset;
|
|
|
|
u32 val;
|
|
|
|
|
2022-09-26 17:09:21 -05:00
|
|
|
reg = ipa_reg(ipa, ENDP_FILTER_ROUTER_HSH_CFG);
|
2020-03-05 22:28:25 -06:00
|
|
|
|
2022-09-26 17:09:31 -05:00
|
|
|
offset = ipa_reg_n_offset(reg, endpoint_id);
|
2020-03-05 22:28:25 -06:00
|
|
|
val = ioread32(endpoint->ipa->reg_virt + offset);
|
|
|
|
|
|
|
|
/* Zero all filter-related fields, preserving the rest */
|
2022-09-26 17:09:31 -05:00
|
|
|
val &= ~ipa_reg_fmask(reg, FILTER_HASH_MSK_ALL);
|
2020-03-05 22:28:25 -06:00
|
|
|
|
|
|
|
iowrite32(val, endpoint->ipa->reg_virt + offset);
|
|
|
|
}
|
|
|
|
|
2021-04-09 13:07:20 -05:00
|
|
|
/* Configure a hashed filter table; there is no ipa_filter_deconfig() */
|
2020-03-05 22:28:25 -06:00
|
|
|
static void ipa_filter_config(struct ipa *ipa, bool modem)
|
|
|
|
{
|
|
|
|
enum gsi_ee_id ee_id = modem ? GSI_EE_MODEM : GSI_EE_AP;
|
|
|
|
u32 ep_mask = ipa->filter_map;
|
|
|
|
|
2021-02-12 08:34:01 -06:00
|
|
|
if (!ipa_table_hash_support(ipa))
|
2020-03-05 22:28:25 -06:00
|
|
|
return;
|
|
|
|
|
|
|
|
while (ep_mask) {
|
|
|
|
u32 endpoint_id = __ffs(ep_mask);
|
|
|
|
struct ipa_endpoint *endpoint;
|
|
|
|
|
|
|
|
ep_mask ^= BIT(endpoint_id);
|
|
|
|
|
|
|
|
endpoint = &ipa->endpoint[endpoint_id];
|
|
|
|
if (endpoint->ee_id == ee_id)
|
|
|
|
ipa_filter_tuple_zero(endpoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool ipa_route_id_modem(u32 route_id)
|
|
|
|
{
|
2022-10-21 14:13:34 -05:00
|
|
|
return route_id < IPA_ROUTE_MODEM_COUNT;
|
2020-03-05 22:28:25 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ipa_route_tuple_zero() - Zero a hashed route table entry tuple
|
2020-07-13 07:24:18 -05:00
|
|
|
* @ipa: IPA pointer
|
2020-03-05 22:28:25 -06:00
|
|
|
* @route_id: Route table entry whose hash tuple should be zeroed
|
|
|
|
*
|
|
|
|
* Updates the route hash values without changing filter ones.
|
|
|
|
*/
|
|
|
|
static void ipa_route_tuple_zero(struct ipa *ipa, u32 route_id)
|
|
|
|
{
|
2022-09-26 17:09:21 -05:00
|
|
|
const struct ipa_reg *reg;
|
2022-09-26 17:09:18 -05:00
|
|
|
u32 offset;
|
2020-03-05 22:28:25 -06:00
|
|
|
u32 val;
|
|
|
|
|
2022-09-26 17:09:21 -05:00
|
|
|
reg = ipa_reg(ipa, ENDP_FILTER_ROUTER_HSH_CFG);
|
|
|
|
offset = ipa_reg_n_offset(reg, route_id);
|
2022-09-26 17:09:18 -05:00
|
|
|
|
2020-03-05 22:28:25 -06:00
|
|
|
val = ioread32(ipa->reg_virt + offset);
|
|
|
|
|
|
|
|
/* Zero all route-related fields, preserving the rest */
|
2022-09-26 17:09:31 -05:00
|
|
|
val &= ~ipa_reg_fmask(reg, ROUTER_HASH_MSK_ALL);
|
2020-03-05 22:28:25 -06:00
|
|
|
|
|
|
|
iowrite32(val, ipa->reg_virt + offset);
|
|
|
|
}
|
|
|
|
|
2021-04-09 13:07:20 -05:00
|
|
|
/* Configure a hashed route table; there is no ipa_route_deconfig() */
|
2020-03-05 22:28:25 -06:00
|
|
|
static void ipa_route_config(struct ipa *ipa, bool modem)
|
|
|
|
{
|
|
|
|
u32 route_id;
|
|
|
|
|
2021-02-12 08:34:01 -06:00
|
|
|
if (!ipa_table_hash_support(ipa))
|
2020-03-05 22:28:25 -06:00
|
|
|
return;
|
|
|
|
|
2022-10-25 14:51:40 -05:00
|
|
|
for (route_id = 0; route_id < ipa->route_count; route_id++)
|
2020-03-05 22:28:25 -06:00
|
|
|
if (ipa_route_id_modem(route_id) == modem)
|
|
|
|
ipa_route_tuple_zero(ipa, route_id);
|
|
|
|
}
|
|
|
|
|
2021-04-09 13:07:20 -05:00
|
|
|
/* Configure a filter and route tables; there is no ipa_table_deconfig() */
|
2020-03-05 22:28:25 -06:00
|
|
|
void ipa_table_config(struct ipa *ipa)
|
|
|
|
{
|
|
|
|
ipa_filter_config(ipa, false);
|
|
|
|
ipa_filter_config(ipa, true);
|
|
|
|
ipa_route_config(ipa, false);
|
|
|
|
ipa_route_config(ipa, true);
|
|
|
|
}
|
|
|
|
|
2022-10-25 14:51:40 -05:00
|
|
|
/* Verify the sizes of all IPA table filter or routing table memory regions
|
|
|
|
* are valid. If valid, this records the size of the routing table.
|
|
|
|
*/
|
2022-10-21 14:13:40 -05:00
|
|
|
bool ipa_table_mem_valid(struct ipa *ipa, bool modem_route_count)
|
2022-10-21 14:13:36 -05:00
|
|
|
{
|
|
|
|
bool hash_support = ipa_table_hash_support(ipa);
|
|
|
|
bool filter = !modem_route_count;
|
|
|
|
const struct ipa_mem *mem_hashed;
|
|
|
|
const struct ipa_mem *mem_ipv4;
|
|
|
|
const struct ipa_mem *mem_ipv6;
|
|
|
|
u32 count;
|
|
|
|
|
|
|
|
/* IPv4 and IPv6 non-hashed tables are expected to be defined and
|
|
|
|
* have the same size. Both must have at least two entries (and
|
|
|
|
* would normally have more than that).
|
|
|
|
*/
|
|
|
|
mem_ipv4 = ipa_table_mem(ipa, filter, false, false);
|
|
|
|
if (!mem_ipv4)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
mem_ipv6 = ipa_table_mem(ipa, filter, false, true);
|
|
|
|
if (!mem_ipv6)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (mem_ipv4->size != mem_ipv6->size)
|
|
|
|
return false;
|
|
|
|
|
2022-10-25 14:51:40 -05:00
|
|
|
/* Record the number of routing table entries */
|
|
|
|
if (!filter)
|
|
|
|
ipa->route_count = IPA_ROUTE_COUNT_MAX;
|
|
|
|
|
2022-10-21 14:13:37 -05:00
|
|
|
/* Table offset and size must fit in TABLE_INIT command fields */
|
|
|
|
if (!ipa_cmd_table_init_valid(ipa, mem_ipv4, !filter))
|
|
|
|
return false;
|
|
|
|
|
2022-10-21 14:13:36 -05:00
|
|
|
/* Make sure the regions are big enough */
|
|
|
|
count = mem_ipv4->size / sizeof(__le64);
|
|
|
|
if (count < 2)
|
|
|
|
return false;
|
|
|
|
if (filter) {
|
|
|
|
/* Filter tables must able to hold the endpoint bitmap plus
|
|
|
|
* an entry for each endpoint that supports filtering
|
|
|
|
*/
|
|
|
|
if (count < 1 + hweight32(ipa->filter_map))
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
/* Routing tables must be able to hold all modem entries,
|
|
|
|
* plus at least one entry for the AP.
|
|
|
|
*/
|
|
|
|
if (count < modem_route_count + 1)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If hashing is supported, hashed tables are expected to be defined,
|
|
|
|
* and have the same size as non-hashed tables. If hashing is not
|
|
|
|
* supported, hashed tables are expected to have zero size (or not
|
|
|
|
* be defined).
|
|
|
|
*/
|
|
|
|
mem_hashed = ipa_table_mem(ipa, filter, true, false);
|
|
|
|
if (hash_support) {
|
|
|
|
if (!mem_hashed || mem_hashed->size != mem_ipv4->size)
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
if (mem_hashed && mem_hashed->size)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Same check for IPv6 tables */
|
|
|
|
mem_hashed = ipa_table_mem(ipa, filter, true, true);
|
|
|
|
if (hash_support) {
|
|
|
|
if (!mem_hashed || mem_hashed->size != mem_ipv6->size)
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
if (mem_hashed && mem_hashed->size)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize a coherent DMA allocation containing initialized filter and
|
2020-03-05 22:28:25 -06:00
|
|
|
* route table data. This is used when initializing or resetting the IPA
|
|
|
|
* filter or route table.
|
|
|
|
*
|
|
|
|
* The first entry in a filter table contains a bitmap indicating which
|
|
|
|
* endpoints contain entries in the table. In addition to that first entry,
|
|
|
|
* there are at most IPA_FILTER_COUNT_MAX entries that follow. Filter table
|
|
|
|
* entries are 64 bits wide, and (other than the bitmap) contain the DMA
|
|
|
|
* address of a filter rule. A "zero rule" indicates no filtering, and
|
|
|
|
* consists of 64 bits of zeroes. When a filter table is initialized (or
|
|
|
|
* reset) its entries are made to refer to the zero rule.
|
|
|
|
*
|
|
|
|
* Each entry in a route table is the DMA address of a routing rule. For
|
|
|
|
* routing there is also a 64-bit "zero rule" that means no routing, and
|
|
|
|
* when a route table is initialized or reset, its entries are made to refer
|
|
|
|
* to the zero rule. The zero rule is shared for route and filter tables.
|
|
|
|
*
|
|
|
|
* Note that the IPA hardware requires a filter or route rule address to be
|
|
|
|
* aligned on a 128 byte boundary. The coherent DMA buffer we allocate here
|
|
|
|
* has a minimum alignment, and we place the zero rule at the base of that
|
|
|
|
* allocated space. In ipa_table_init() we verify the minimum DMA allocation
|
|
|
|
* meets our requirement.
|
|
|
|
*
|
|
|
|
* +-------------------+
|
|
|
|
* --> | zero rule |
|
|
|
|
* / |-------------------|
|
|
|
|
* | | filter mask |
|
|
|
|
* |\ |-------------------|
|
|
|
|
* | ---- zero rule address | \
|
|
|
|
* |\ |-------------------| |
|
|
|
|
* | ---- zero rule address | | IPA_FILTER_COUNT_MAX
|
2022-10-25 14:51:40 -05:00
|
|
|
* | |-------------------| > or IPA route count,
|
2020-03-05 22:28:25 -06:00
|
|
|
* | ... | whichever is greater
|
|
|
|
* \ |-------------------| |
|
|
|
|
* ---- zero rule address | /
|
|
|
|
* +-------------------+
|
|
|
|
*/
|
|
|
|
int ipa_table_init(struct ipa *ipa)
|
|
|
|
{
|
|
|
|
struct device *dev = &ipa->pdev->dev;
|
|
|
|
dma_addr_t addr;
|
|
|
|
__le64 le_addr;
|
|
|
|
__le64 *virt;
|
|
|
|
size_t size;
|
2022-10-25 14:51:40 -05:00
|
|
|
u32 count;
|
2020-03-05 22:28:25 -06:00
|
|
|
|
|
|
|
ipa_table_validate_build();
|
|
|
|
|
2022-10-25 14:51:40 -05:00
|
|
|
count = max_t(u32, IPA_FILTER_COUNT_MAX, ipa->route_count);
|
|
|
|
|
2021-03-28 12:31:10 -05:00
|
|
|
/* The IPA hardware requires route and filter table rules to be
|
|
|
|
* aligned on a 128-byte boundary. We put the "zero rule" at the
|
|
|
|
* base of the table area allocated here. The DMA address returned
|
|
|
|
* by dma_alloc_coherent() is guaranteed to be a power-of-2 number
|
|
|
|
* of pages, which satisfies the rule alignment requirement.
|
|
|
|
*/
|
2021-03-28 12:31:11 -05:00
|
|
|
size = IPA_ZERO_RULE_SIZE + (1 + count) * sizeof(__le64);
|
2020-03-05 22:28:25 -06:00
|
|
|
virt = dma_alloc_coherent(dev, size, &addr, GFP_KERNEL);
|
|
|
|
if (!virt)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ipa->table_virt = virt;
|
|
|
|
ipa->table_addr = addr;
|
|
|
|
|
|
|
|
/* First slot is the zero rule */
|
|
|
|
*virt++ = 0;
|
|
|
|
|
|
|
|
/* Next is the filter table bitmap. The "soft" bitmap value
|
|
|
|
* must be converted to the hardware representation by shifting
|
|
|
|
* it left one position. (Bit 0 repesents global filtering,
|
|
|
|
* which is possible but not used.)
|
|
|
|
*/
|
|
|
|
*virt++ = cpu_to_le64((u64)ipa->filter_map << 1);
|
|
|
|
|
|
|
|
/* All the rest contain the DMA address of the zero rule */
|
|
|
|
le_addr = cpu_to_le64(addr);
|
|
|
|
while (count--)
|
|
|
|
*virt++ = le_addr;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ipa_table_exit(struct ipa *ipa)
|
|
|
|
{
|
2022-10-25 14:51:40 -05:00
|
|
|
u32 count = max_t(u32, 1 + IPA_FILTER_COUNT_MAX, ipa->route_count);
|
2020-03-05 22:28:25 -06:00
|
|
|
struct device *dev = &ipa->pdev->dev;
|
|
|
|
size_t size;
|
|
|
|
|
2021-03-28 12:31:11 -05:00
|
|
|
size = IPA_ZERO_RULE_SIZE + (1 + count) * sizeof(__le64);
|
2020-03-05 22:28:25 -06:00
|
|
|
|
|
|
|
dma_free_coherent(dev, size, ipa->table_virt, ipa->table_addr);
|
|
|
|
ipa->table_addr = 0;
|
|
|
|
ipa->table_virt = NULL;
|
|
|
|
}
|