net: ipa: start generalizing "ipa_reg"
IPA register definitions have evolved with each new version. The
changes required to support more than 32 endpoints in IPA v5.0 made
it best to define a unified mechanism for defining registers and
their fields.
GSI register definitions, meanwhile, have remained fairly stable.
And even as the total number of IPA endpoints goes beyond 32, the
number of GSI channels on a given EE that underly endpoints still
remains 32 or less.
Despite that, GSI v3.0 (which is used with IPA v5.0) extends the
number of channels (and events) it supports to be about 256, and as
a result, many GSI register definitions must change significantly.
To address this, we'll use the same "ipa_reg" mechanism to define
the GSI registers.
As a first step in generalizing the "ipa_reg" to also support GSI
registers, isolate the definitions of the "ipa_reg" and "ipa_regs"
structure types (and some supporting macros) into a new header file,
and remove the "ipa_" and "IPA_" from symbol names.
Separate the IPA register ID validity checking from the generic
check that a register ID is in range. Aside from that, this is
intended to have no functional effect on the code.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-02-08 20:56:51 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
|
net: ipa: include some standard header files
Some IPA header files use types defined in <linux/types.h>, but do
not include that file:
- In "ipa_mem.h", the ipa_mem structure has u16 and u32 fields
- In "ipa_power.h", ipa_power_retention() takes a bool argument,
and ipa_core_clock_rate() returns u32
- In "ipa_version.h", ipa_version_supported() returns bool
Include it in these files to satisfy their dependencies.
The ipa_qmi structure (defined in "ipa_qmi.h") contains a work
structure, so include <linux/workqueue.h> in there.
All of the data and register definition files, as well as "reg.h",
use the ARRAY_SIZE() macro. Include <linux/array_size.h> everywhere
it's used.
Similarly, all register definition files (and a few others) use the
GENMASK() macro, so include <linux/bits.h> to ensure it's defined
where used. BIT() becomes available by including this file also.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2024-04-16 23:10:12 +00:00
|
|
|
/* Copyright (C) 2022-2024 Linaro Ltd. */
|
net: ipa: start generalizing "ipa_reg"
IPA register definitions have evolved with each new version. The
changes required to support more than 32 endpoints in IPA v5.0 made
it best to define a unified mechanism for defining registers and
their fields.
GSI register definitions, meanwhile, have remained fairly stable.
And even as the total number of IPA endpoints goes beyond 32, the
number of GSI channels on a given EE that underly endpoints still
remains 32 or less.
Despite that, GSI v3.0 (which is used with IPA v5.0) extends the
number of channels (and events) it supports to be about 256, and as
a result, many GSI register definitions must change significantly.
To address this, we'll use the same "ipa_reg" mechanism to define
the GSI registers.
As a first step in generalizing the "ipa_reg" to also support GSI
registers, isolate the definitions of the "ipa_reg" and "ipa_regs"
structure types (and some supporting macros) into a new header file,
and remove the "ipa_" and "IPA_" from symbol names.
Separate the IPA register ID validity checking from the generic
check that a register ID is in range. Aside from that, this is
intended to have no functional effect on the code.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-02-08 20:56:51 +00:00
|
|
|
|
|
|
|
#ifndef _REG_H_
|
|
|
|
#define _REG_H_
|
|
|
|
|
net: ipa: include some standard header files
Some IPA header files use types defined in <linux/types.h>, but do
not include that file:
- In "ipa_mem.h", the ipa_mem structure has u16 and u32 fields
- In "ipa_power.h", ipa_power_retention() takes a bool argument,
and ipa_core_clock_rate() returns u32
- In "ipa_version.h", ipa_version_supported() returns bool
Include it in these files to satisfy their dependencies.
The ipa_qmi structure (defined in "ipa_qmi.h") contains a work
structure, so include <linux/workqueue.h> in there.
All of the data and register definition files, as well as "reg.h",
use the ARRAY_SIZE() macro. Include <linux/array_size.h> everywhere
it's used.
Similarly, all register definition files (and a few others) use the
GENMASK() macro, so include <linux/bits.h> to ensure it's defined
where used. BIT() becomes available by including this file also.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2024-04-16 23:10:12 +00:00
|
|
|
#include <linux/array_size.h>
|
|
|
|
#include <linux/bits.h>
|
2023-03-16 14:51:33 +00:00
|
|
|
#include <linux/bug.h>
|
2024-04-16 23:10:18 +00:00
|
|
|
#include <linux/log2.h>
|
|
|
|
#include <linux/types.h>
|
net: ipa: start generalizing "ipa_reg"
IPA register definitions have evolved with each new version. The
changes required to support more than 32 endpoints in IPA v5.0 made
it best to define a unified mechanism for defining registers and
their fields.
GSI register definitions, meanwhile, have remained fairly stable.
And even as the total number of IPA endpoints goes beyond 32, the
number of GSI channels on a given EE that underly endpoints still
remains 32 or less.
Despite that, GSI v3.0 (which is used with IPA v5.0) extends the
number of channels (and events) it supports to be about 256, and as
a result, many GSI register definitions must change significantly.
To address this, we'll use the same "ipa_reg" mechanism to define
the GSI registers.
As a first step in generalizing the "ipa_reg" to also support GSI
registers, isolate the definitions of the "ipa_reg" and "ipa_regs"
structure types (and some supporting macros) into a new header file,
and remove the "ipa_" and "IPA_" from symbol names.
Separate the IPA register ID validity checking from the generic
check that a register ID is in range. Aside from that, this is
intended to have no functional effect on the code.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-02-08 20:56:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* struct reg - A register descriptor
|
|
|
|
* @offset: Register offset relative to base of register memory
|
|
|
|
* @stride: Distance between two instances, if parameterized
|
|
|
|
* @fcount: Number of entries in the @fmask array
|
|
|
|
* @fmask: Array of mask values defining position and width of fields
|
|
|
|
* @name: Upper-case name of the register
|
|
|
|
*/
|
|
|
|
struct reg {
|
|
|
|
u32 offset;
|
|
|
|
u32 stride;
|
|
|
|
u32 fcount;
|
|
|
|
const u32 *fmask; /* BIT(nr) or GENMASK(h, l) */
|
|
|
|
const char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Helper macro for defining "simple" (non-parameterized) registers */
|
|
|
|
#define REG(__NAME, __reg_id, __offset) \
|
|
|
|
REG_STRIDE(__NAME, __reg_id, __offset, 0)
|
|
|
|
|
|
|
|
/* Helper macro for defining parameterized registers, specifying stride */
|
|
|
|
#define REG_STRIDE(__NAME, __reg_id, __offset, __stride) \
|
|
|
|
static const struct reg reg_ ## __reg_id = { \
|
|
|
|
.name = #__NAME, \
|
|
|
|
.offset = __offset, \
|
|
|
|
.stride = __stride, \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define REG_FIELDS(__NAME, __name, __offset) \
|
|
|
|
REG_STRIDE_FIELDS(__NAME, __name, __offset, 0)
|
|
|
|
|
|
|
|
#define REG_STRIDE_FIELDS(__NAME, __name, __offset, __stride) \
|
|
|
|
static const struct reg reg_ ## __name = { \
|
|
|
|
.name = #__NAME, \
|
|
|
|
.offset = __offset, \
|
|
|
|
.stride = __stride, \
|
|
|
|
.fcount = ARRAY_SIZE(reg_ ## __name ## _fmask), \
|
|
|
|
.fmask = reg_ ## __name ## _fmask, \
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct regs - Description of registers supported by hardware
|
|
|
|
* @reg_count: Number of registers in the @reg[] array
|
|
|
|
* @reg: Array of register descriptors
|
|
|
|
*/
|
|
|
|
struct regs {
|
|
|
|
u32 reg_count;
|
|
|
|
const struct reg **reg;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline const struct reg *reg(const struct regs *regs, u32 reg_id)
|
|
|
|
{
|
|
|
|
if (WARN(reg_id >= regs->reg_count,
|
|
|
|
"reg out of range (%u > %u)\n", reg_id, regs->reg_count - 1))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return regs->reg[reg_id];
|
|
|
|
}
|
|
|
|
|
2023-02-08 20:56:53 +00:00
|
|
|
/* Return the field mask for a field in a register, or 0 on error */
|
|
|
|
static inline u32 reg_fmask(const struct reg *reg, u32 field_id)
|
|
|
|
{
|
|
|
|
if (!reg || WARN_ON(field_id >= reg->fcount))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return reg->fmask[field_id];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the mask for a single-bit field in a register, or 0 on error */
|
|
|
|
static inline u32 reg_bit(const struct reg *reg, u32 field_id)
|
|
|
|
{
|
|
|
|
u32 fmask = reg_fmask(reg, field_id);
|
|
|
|
|
|
|
|
if (WARN_ON(!is_power_of_2(fmask)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return fmask;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the maximum value representable by the given field; always 2^n - 1 */
|
|
|
|
static inline u32 reg_field_max(const struct reg *reg, u32 field_id)
|
|
|
|
{
|
|
|
|
u32 fmask = reg_fmask(reg, field_id);
|
|
|
|
|
|
|
|
return fmask ? fmask >> __ffs(fmask) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Encode a value into the given field of a register */
|
|
|
|
static inline u32 reg_encode(const struct reg *reg, u32 field_id, u32 val)
|
|
|
|
{
|
|
|
|
u32 fmask = reg_fmask(reg, field_id);
|
|
|
|
|
|
|
|
if (!fmask)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
val <<= __ffs(fmask);
|
|
|
|
if (WARN_ON(val & ~fmask))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Given a register value, decode (extract) the value in the given field */
|
|
|
|
static inline u32 reg_decode(const struct reg *reg, u32 field_id, u32 val)
|
|
|
|
{
|
|
|
|
u32 fmask = reg_fmask(reg, field_id);
|
|
|
|
|
|
|
|
return fmask ? (val & fmask) >> __ffs(fmask) : 0;
|
|
|
|
}
|
|
|
|
|
2023-02-08 20:56:52 +00:00
|
|
|
/* Returns 0 for NULL reg; warning should have already been issued */
|
|
|
|
static inline u32 reg_offset(const struct reg *reg)
|
|
|
|
{
|
|
|
|
return reg ? reg->offset : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns 0 for NULL reg; warning should have already been issued */
|
|
|
|
static inline u32 reg_n_offset(const struct reg *reg, u32 n)
|
|
|
|
{
|
|
|
|
return reg ? reg->offset + n * reg->stride : 0;
|
|
|
|
}
|
|
|
|
|
net: ipa: start generalizing "ipa_reg"
IPA register definitions have evolved with each new version. The
changes required to support more than 32 endpoints in IPA v5.0 made
it best to define a unified mechanism for defining registers and
their fields.
GSI register definitions, meanwhile, have remained fairly stable.
And even as the total number of IPA endpoints goes beyond 32, the
number of GSI channels on a given EE that underly endpoints still
remains 32 or less.
Despite that, GSI v3.0 (which is used with IPA v5.0) extends the
number of channels (and events) it supports to be about 256, and as
a result, many GSI register definitions must change significantly.
To address this, we'll use the same "ipa_reg" mechanism to define
the GSI registers.
As a first step in generalizing the "ipa_reg" to also support GSI
registers, isolate the definitions of the "ipa_reg" and "ipa_regs"
structure types (and some supporting macros) into a new header file,
and remove the "ipa_" and "IPA_" from symbol names.
Separate the IPA register ID validity checking from the generic
check that a register ID is in range. Aside from that, this is
intended to have no functional effect on the code.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-02-08 20:56:51 +00:00
|
|
|
#endif /* _REG_H_ */
|