Commit 01a7ee36 authored by David S. Miller's avatar David S. Miller

Merge branch 'net-ipa-GSI'

Alex Elder says:

====================
net: ipa: prepare for GSI register updtaes

An upcoming series (or two) will convert the definitions of GSI
registers used by IPA so they use the "IPA reg" mechanism to specify
register offsets and their fields.  This will simplify implementing
the fairly large number of changes required in GSI registers to
support more than 32 GSI channels (introduced in IPA v5.0).

A few minor problems and inconsistencies were found, and they're
fixed here.  The last three patches in this series change the
"ipa_reg" code to separate the IPA-specific part (the base virtual
address, basically) from the generic register part, and the now-
generic code is renamed to use just "reg_" or "REG_" as a prefix
rather than "ipa_reg" or "IPA_REG_".
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 47400aae f1470fd7
...@@ -182,6 +182,41 @@ static bool gsi_channel_initialized(struct gsi_channel *channel) ...@@ -182,6 +182,41 @@ static bool gsi_channel_initialized(struct gsi_channel *channel)
return !!channel->gsi; return !!channel->gsi;
} }
/* Encode the channel protocol for the CH_C_CNTXT_0 register */
static u32 ch_c_cntxt_0_type_encode(enum ipa_version version,
enum gsi_channel_type type)
{
u32 val;
val = u32_encode_bits(type, CHTYPE_PROTOCOL_FMASK);
if (version < IPA_VERSION_4_5)
return val;
type >>= hweight32(CHTYPE_PROTOCOL_FMASK);
return val | u32_encode_bits(type, CHTYPE_PROTOCOL_MSB_FMASK);
}
/* Encode a channel ring buffer length for the CH_C_CNTXT_1 register */
static u32 ch_c_cntxt_1_length_encode(enum ipa_version version, u32 length)
{
if (version < IPA_VERSION_4_9)
return u32_encode_bits(length, GENMASK(15, 0));
return u32_encode_bits(length, GENMASK(19, 0));
}
/* Encode the length of the event channel ring buffer for the
* EV_CH_E_CNTXT_1 register.
*/
static u32 ev_ch_e_cntxt_1_length_encode(enum ipa_version version, u32 length)
{
if (version < IPA_VERSION_4_9)
return u32_encode_bits(length, GENMASK(15, 0));
return u32_encode_bits(length, GENMASK(19, 0));
}
/* Update the GSI IRQ type register with the cached value */ /* Update the GSI IRQ type register with the cached value */
static void gsi_irq_type_update(struct gsi *gsi, u32 val) static void gsi_irq_type_update(struct gsi *gsi, u32 val)
{ {
...@@ -191,12 +226,12 @@ static void gsi_irq_type_update(struct gsi *gsi, u32 val) ...@@ -191,12 +226,12 @@ static void gsi_irq_type_update(struct gsi *gsi, u32 val)
static void gsi_irq_type_enable(struct gsi *gsi, enum gsi_irq_type_id type_id) static void gsi_irq_type_enable(struct gsi *gsi, enum gsi_irq_type_id type_id)
{ {
gsi_irq_type_update(gsi, gsi->type_enabled_bitmap | BIT(type_id)); gsi_irq_type_update(gsi, gsi->type_enabled_bitmap | type_id);
} }
static void gsi_irq_type_disable(struct gsi *gsi, enum gsi_irq_type_id type_id) static void gsi_irq_type_disable(struct gsi *gsi, enum gsi_irq_type_id type_id)
{ {
gsi_irq_type_update(gsi, gsi->type_enabled_bitmap & ~BIT(type_id)); gsi_irq_type_update(gsi, gsi->type_enabled_bitmap & ~type_id);
} }
/* Event ring commands are performed one at a time. Their completion /* Event ring commands are performed one at a time. Their completion
...@@ -292,19 +327,19 @@ static void gsi_irq_enable(struct gsi *gsi) ...@@ -292,19 +327,19 @@ static void gsi_irq_enable(struct gsi *gsi)
/* Global interrupts include hardware error reports. Enable /* Global interrupts include hardware error reports. Enable
* that so we can at least report the error should it occur. * that so we can at least report the error should it occur.
*/ */
iowrite32(BIT(ERROR_INT), gsi->virt + GSI_CNTXT_GLOB_IRQ_EN_OFFSET); iowrite32(ERROR_INT, gsi->virt + GSI_CNTXT_GLOB_IRQ_EN_OFFSET);
gsi_irq_type_update(gsi, gsi->type_enabled_bitmap | BIT(GSI_GLOB_EE)); gsi_irq_type_update(gsi, gsi->type_enabled_bitmap | GSI_GLOB_EE);
/* General GSI interrupts are reported to all EEs; if they occur /* General GSI interrupts are reported to all EEs; if they occur
* they are unrecoverable (without reset). A breakpoint interrupt * they are unrecoverable (without reset). A breakpoint interrupt
* also exists, but we don't support that. We want to be notified * also exists, but we don't support that. We want to be notified
* of errors so we can report them, even if they can't be handled. * of errors so we can report them, even if they can't be handled.
*/ */
val = BIT(BUS_ERROR); val = BUS_ERROR;
val |= BIT(CMD_FIFO_OVRFLOW); val |= CMD_FIFO_OVRFLOW;
val |= BIT(MCS_STACK_OVRFLOW); val |= MCS_STACK_OVRFLOW;
iowrite32(val, gsi->virt + GSI_CNTXT_GSI_IRQ_EN_OFFSET); iowrite32(val, gsi->virt + GSI_CNTXT_GSI_IRQ_EN_OFFSET);
gsi_irq_type_update(gsi, gsi->type_enabled_bitmap | BIT(GSI_GENERAL)); gsi_irq_type_update(gsi, gsi->type_enabled_bitmap | GSI_GENERAL);
} }
/* Disable all GSI interrupt types */ /* Disable all GSI interrupt types */
...@@ -676,7 +711,7 @@ static void gsi_evt_ring_program(struct gsi *gsi, u32 evt_ring_id) ...@@ -676,7 +711,7 @@ static void gsi_evt_ring_program(struct gsi *gsi, u32 evt_ring_id)
iowrite32(val, gsi->virt + GSI_EV_CH_E_CNTXT_0_OFFSET(evt_ring_id)); iowrite32(val, gsi->virt + GSI_EV_CH_E_CNTXT_0_OFFSET(evt_ring_id));
size = ring->count * GSI_RING_ELEMENT_SIZE; size = ring->count * GSI_RING_ELEMENT_SIZE;
val = ev_r_length_encoded(gsi->version, size); val = ev_ch_e_cntxt_1_length_encode(gsi->version, size);
iowrite32(val, gsi->virt + GSI_EV_CH_E_CNTXT_1_OFFSET(evt_ring_id)); iowrite32(val, gsi->virt + GSI_EV_CH_E_CNTXT_1_OFFSET(evt_ring_id));
/* The context 2 and 3 registers store the low-order and /* The context 2 and 3 registers store the low-order and
...@@ -765,14 +800,14 @@ static void gsi_channel_program(struct gsi_channel *channel, bool doorbell) ...@@ -765,14 +800,14 @@ static void gsi_channel_program(struct gsi_channel *channel, bool doorbell)
u32 val; u32 val;
/* We program all channels as GPI type/protocol */ /* We program all channels as GPI type/protocol */
val = chtype_protocol_encoded(gsi->version, GSI_CHANNEL_TYPE_GPI); val = ch_c_cntxt_0_type_encode(gsi->version, GSI_CHANNEL_TYPE_GPI);
if (channel->toward_ipa) if (channel->toward_ipa)
val |= CHTYPE_DIR_FMASK; val |= CHTYPE_DIR_FMASK;
val |= u32_encode_bits(channel->evt_ring_id, ERINDEX_FMASK); val |= u32_encode_bits(channel->evt_ring_id, ERINDEX_FMASK);
val |= u32_encode_bits(GSI_RING_ELEMENT_SIZE, ELEMENT_SIZE_FMASK); val |= u32_encode_bits(GSI_RING_ELEMENT_SIZE, ELEMENT_SIZE_FMASK);
iowrite32(val, gsi->virt + GSI_CH_C_CNTXT_0_OFFSET(channel_id)); iowrite32(val, gsi->virt + GSI_CH_C_CNTXT_0_OFFSET(channel_id));
val = r_length_encoded(gsi->version, size); val = ch_c_cntxt_1_length_encode(gsi->version, size);
iowrite32(val, gsi->virt + GSI_CH_C_CNTXT_1_OFFSET(channel_id)); iowrite32(val, gsi->virt + GSI_CH_C_CNTXT_1_OFFSET(channel_id));
/* The context 2 and 3 registers store the low-order and /* The context 2 and 3 registers store the low-order and
...@@ -1195,15 +1230,15 @@ static void gsi_isr_glob_ee(struct gsi *gsi) ...@@ -1195,15 +1230,15 @@ static void gsi_isr_glob_ee(struct gsi *gsi)
val = ioread32(gsi->virt + GSI_CNTXT_GLOB_IRQ_STTS_OFFSET); val = ioread32(gsi->virt + GSI_CNTXT_GLOB_IRQ_STTS_OFFSET);
if (val & BIT(ERROR_INT)) if (val & ERROR_INT)
gsi_isr_glob_err(gsi); gsi_isr_glob_err(gsi);
iowrite32(val, gsi->virt + GSI_CNTXT_GLOB_IRQ_CLR_OFFSET); iowrite32(val, gsi->virt + GSI_CNTXT_GLOB_IRQ_CLR_OFFSET);
val &= ~BIT(ERROR_INT); val &= ~ERROR_INT;
if (val & BIT(GP_INT1)) { if (val & GP_INT1) {
val ^= BIT(GP_INT1); val ^= GP_INT1;
gsi_isr_gp_int1(gsi); gsi_isr_gp_int1(gsi);
} }
...@@ -1264,19 +1299,19 @@ static irqreturn_t gsi_isr(int irq, void *dev_id) ...@@ -1264,19 +1299,19 @@ static irqreturn_t gsi_isr(int irq, void *dev_id)
intr_mask ^= gsi_intr; intr_mask ^= gsi_intr;
switch (gsi_intr) { switch (gsi_intr) {
case BIT(GSI_CH_CTRL): case GSI_CH_CTRL:
gsi_isr_chan_ctrl(gsi); gsi_isr_chan_ctrl(gsi);
break; break;
case BIT(GSI_EV_CTRL): case GSI_EV_CTRL:
gsi_isr_evt_ctrl(gsi); gsi_isr_evt_ctrl(gsi);
break; break;
case BIT(GSI_GLOB_EE): case GSI_GLOB_EE:
gsi_isr_glob_ee(gsi); gsi_isr_glob_ee(gsi);
break; break;
case BIT(GSI_IEOB): case GSI_IEOB:
gsi_isr_ieob(gsi); gsi_isr_ieob(gsi);
break; break;
case BIT(GSI_GENERAL): case GSI_GENERAL:
gsi_isr_general(gsi); gsi_isr_general(gsi);
break; break;
default: default:
...@@ -1654,7 +1689,7 @@ static int gsi_generic_command(struct gsi *gsi, u32 channel_id, ...@@ -1654,7 +1689,7 @@ static int gsi_generic_command(struct gsi *gsi, u32 channel_id,
* channel), and only from this function. So we enable the GP_INT1 * channel), and only from this function. So we enable the GP_INT1
* IRQ type here, and disable it again after the command completes. * IRQ type here, and disable it again after the command completes.
*/ */
val = BIT(ERROR_INT) | BIT(GP_INT1); val = ERROR_INT | GP_INT1;
iowrite32(val, gsi->virt + GSI_CNTXT_GLOB_IRQ_EN_OFFSET); iowrite32(val, gsi->virt + GSI_CNTXT_GLOB_IRQ_EN_OFFSET);
/* First zero the result code field */ /* First zero the result code field */
...@@ -1666,12 +1701,13 @@ static int gsi_generic_command(struct gsi *gsi, u32 channel_id, ...@@ -1666,12 +1701,13 @@ static int gsi_generic_command(struct gsi *gsi, u32 channel_id,
val = u32_encode_bits(opcode, GENERIC_OPCODE_FMASK); val = u32_encode_bits(opcode, GENERIC_OPCODE_FMASK);
val |= u32_encode_bits(channel_id, GENERIC_CHID_FMASK); val |= u32_encode_bits(channel_id, GENERIC_CHID_FMASK);
val |= u32_encode_bits(GSI_EE_MODEM, GENERIC_EE_FMASK); val |= u32_encode_bits(GSI_EE_MODEM, GENERIC_EE_FMASK);
val |= u32_encode_bits(params, GENERIC_PARAMS_FMASK); if (gsi->version >= IPA_VERSION_4_11)
val |= u32_encode_bits(params, GENERIC_PARAMS_FMASK);
timeout = !gsi_command(gsi, GSI_GENERIC_CMD_OFFSET, val); timeout = !gsi_command(gsi, GSI_GENERIC_CMD_OFFSET, val);
/* Disable the GP_INT1 IRQ type again */ /* Disable the GP_INT1 IRQ type again */
iowrite32(BIT(ERROR_INT), gsi->virt + GSI_CNTXT_GLOB_IRQ_EN_OFFSET); iowrite32(ERROR_INT, gsi->virt + GSI_CNTXT_GLOB_IRQ_EN_OFFSET);
if (!timeout) if (!timeout)
return gsi->result; return gsi->result;
......
...@@ -62,6 +62,18 @@ ...@@ -62,6 +62,18 @@
/* All other register offsets are relative to gsi->virt */ /* All other register offsets are relative to gsi->virt */
#define GSI_CH_C_CNTXT_0_OFFSET(ch) \
(0x0001c000 + 0x4000 * GSI_EE_AP + 0x80 * (ch))
#define CHTYPE_PROTOCOL_FMASK GENMASK(2, 0)
#define CHTYPE_DIR_FMASK GENMASK(3, 3)
#define EE_FMASK GENMASK(7, 4)
#define CHID_FMASK GENMASK(12, 8)
/* The next field is present for IPA v4.5 and above */
#define CHTYPE_PROTOCOL_MSB_FMASK GENMASK(13, 13)
#define ERINDEX_FMASK GENMASK(18, 14)
#define CHSTATE_FMASK GENMASK(23, 20)
#define ELEMENT_SIZE_FMASK GENMASK(31, 24)
/** enum gsi_channel_type - CHTYPE_PROTOCOL field values in CH_C_CNTXT_0 */ /** enum gsi_channel_type - CHTYPE_PROTOCOL field values in CH_C_CNTXT_0 */
enum gsi_channel_type { enum gsi_channel_type {
GSI_CHANNEL_TYPE_MHI = 0x0, GSI_CHANNEL_TYPE_MHI = 0x0,
...@@ -76,46 +88,9 @@ enum gsi_channel_type { ...@@ -76,46 +88,9 @@ enum gsi_channel_type {
GSI_CHANNEL_TYPE_11AD = 0x9, GSI_CHANNEL_TYPE_11AD = 0x9,
}; };
#define GSI_CH_C_CNTXT_0_OFFSET(ch) \
(0x0001c000 + 0x4000 * GSI_EE_AP + 0x80 * (ch))
#define CHTYPE_PROTOCOL_FMASK GENMASK(2, 0)
#define CHTYPE_DIR_FMASK GENMASK(3, 3)
#define EE_FMASK GENMASK(7, 4)
#define CHID_FMASK GENMASK(12, 8)
/* The next field is present for IPA v4.5 and above */
#define CHTYPE_PROTOCOL_MSB_FMASK GENMASK(13, 13)
#define ERINDEX_FMASK GENMASK(18, 14)
#define CHSTATE_FMASK GENMASK(23, 20)
#define ELEMENT_SIZE_FMASK GENMASK(31, 24)
/* Encoded value for CH_C_CNTXT_0 register channel protocol fields */
static inline u32
chtype_protocol_encoded(enum ipa_version version, enum gsi_channel_type type)
{
u32 val;
val = u32_encode_bits(type, CHTYPE_PROTOCOL_FMASK);
if (version < IPA_VERSION_4_5)
return val;
/* Encode upper bit(s) as well */
type >>= hweight32(CHTYPE_PROTOCOL_FMASK);
val |= u32_encode_bits(type, CHTYPE_PROTOCOL_MSB_FMASK);
return val;
}
#define GSI_CH_C_CNTXT_1_OFFSET(ch) \ #define GSI_CH_C_CNTXT_1_OFFSET(ch) \
(0x0001c004 + 0x4000 * GSI_EE_AP + 0x80 * (ch)) (0x0001c004 + 0x4000 * GSI_EE_AP + 0x80 * (ch))
/* Encoded value for CH_C_CNTXT_1 register R_LENGTH field */
static inline u32 r_length_encoded(enum ipa_version version, u32 length)
{
if (version < IPA_VERSION_4_9)
return u32_encode_bits(length, GENMASK(15, 0));
return u32_encode_bits(length, GENMASK(19, 0));
}
#define GSI_CH_C_CNTXT_2_OFFSET(ch) \ #define GSI_CH_C_CNTXT_2_OFFSET(ch) \
(0x0001c008 + 0x4000 * GSI_EE_AP + 0x80 * (ch)) (0x0001c008 + 0x4000 * GSI_EE_AP + 0x80 * (ch))
...@@ -167,13 +142,6 @@ enum gsi_prefetch_mode { ...@@ -167,13 +142,6 @@ enum gsi_prefetch_mode {
#define GSI_EV_CH_E_CNTXT_1_OFFSET(ev) \ #define GSI_EV_CH_E_CNTXT_1_OFFSET(ev) \
(0x0001d004 + 0x4000 * GSI_EE_AP + 0x80 * (ev)) (0x0001d004 + 0x4000 * GSI_EE_AP + 0x80 * (ev))
/* Encoded value for EV_CH_C_CNTXT_1 register EV_R_LENGTH field */
static inline u32 ev_r_length_encoded(enum ipa_version version, u32 length)
{
if (version < IPA_VERSION_4_9)
return u32_encode_bits(length, GENMASK(15, 0));
return u32_encode_bits(length, GENMASK(19, 0));
}
#define GSI_EV_CH_E_CNTXT_2_OFFSET(ev) \ #define GSI_EV_CH_E_CNTXT_2_OFFSET(ev) \
(0x0001d008 + 0x4000 * GSI_EE_AP + 0x80 * (ev)) (0x0001d008 + 0x4000 * GSI_EE_AP + 0x80 * (ev))
...@@ -299,15 +267,25 @@ enum gsi_iram_size { ...@@ -299,15 +267,25 @@ enum gsi_iram_size {
#define GSI_CNTXT_TYPE_IRQ_MSK_OFFSET \ #define GSI_CNTXT_TYPE_IRQ_MSK_OFFSET \
(0x0001f088 + 0x4000 * GSI_EE_AP) (0x0001f088 + 0x4000 * GSI_EE_AP)
/* Values here are bit positions in the TYPE_IRQ and TYPE_IRQ_MSK registers */ /**
* enum gsi_irq_type_id: GSI IRQ types
* @GSI_CH_CTRL: Channel allocation, deallocation, etc.
* @GSI_EV_CTRL: Event ring allocation, deallocation, etc.
* @GSI_GLOB_EE: Global/general event
* @GSI_IEOB: Transfer (TRE) completion
* @GSI_INTER_EE_CH_CTRL: Remote-issued stop/reset (unused)
* @GSI_INTER_EE_EV_CTRL: Remote-issued event reset (unused)
* @GSI_GENERAL: General hardware event (bus error, etc.)
*/
enum gsi_irq_type_id { enum gsi_irq_type_id {
GSI_CH_CTRL = 0x0, /* channel allocation, etc. */ GSI_CH_CTRL = BIT(0),
GSI_EV_CTRL = 0x1, /* event ring allocation, etc. */ GSI_EV_CTRL = BIT(1),
GSI_GLOB_EE = 0x2, /* global/general event */ GSI_GLOB_EE = BIT(2),
GSI_IEOB = 0x3, /* TRE completion */ GSI_IEOB = BIT(3),
GSI_INTER_EE_CH_CTRL = 0x4, /* remote-issued stop/reset (unused) */ GSI_INTER_EE_CH_CTRL = BIT(4),
GSI_INTER_EE_EV_CTRL = 0x5, /* remote-issued event reset (unused) */ GSI_INTER_EE_EV_CTRL = BIT(5),
GSI_GENERAL = 0x6, /* general-purpose event */ GSI_GENERAL = BIT(6),
/* IRQ types 7-31 (and their bit values) are reserved */
}; };
#define GSI_CNTXT_SRC_CH_IRQ_OFFSET \ #define GSI_CNTXT_SRC_CH_IRQ_OFFSET \
...@@ -343,12 +321,14 @@ enum gsi_irq_type_id { ...@@ -343,12 +321,14 @@ enum gsi_irq_type_id {
(0x0001f108 + 0x4000 * GSI_EE_AP) (0x0001f108 + 0x4000 * GSI_EE_AP)
#define GSI_CNTXT_GLOB_IRQ_CLR_OFFSET \ #define GSI_CNTXT_GLOB_IRQ_CLR_OFFSET \
(0x0001f110 + 0x4000 * GSI_EE_AP) (0x0001f110 + 0x4000 * GSI_EE_AP)
/* Values here are bit positions in the GLOB_IRQ_* registers */
/** enum gsi_global_irq_id: Global GSI interrupt events */
enum gsi_global_irq_id { enum gsi_global_irq_id {
ERROR_INT = 0x0, ERROR_INT = BIT(0),
GP_INT1 = 0x1, GP_INT1 = BIT(1),
GP_INT2 = 0x2, GP_INT2 = BIT(2),
GP_INT3 = 0x3, GP_INT3 = BIT(3),
/* Global IRQ types 4-31 (and their bit values) are reserved */
}; };
#define GSI_CNTXT_GSI_IRQ_STTS_OFFSET \ #define GSI_CNTXT_GSI_IRQ_STTS_OFFSET \
...@@ -357,12 +337,14 @@ enum gsi_global_irq_id { ...@@ -357,12 +337,14 @@ enum gsi_global_irq_id {
(0x0001f120 + 0x4000 * GSI_EE_AP) (0x0001f120 + 0x4000 * GSI_EE_AP)
#define GSI_CNTXT_GSI_IRQ_CLR_OFFSET \ #define GSI_CNTXT_GSI_IRQ_CLR_OFFSET \
(0x0001f128 + 0x4000 * GSI_EE_AP) (0x0001f128 + 0x4000 * GSI_EE_AP)
/* Values here are bit positions in the (general) GSI_IRQ_* registers */
enum gsi_general_id { /** enum gsi_general_irq_id: GSI general IRQ conditions */
BREAK_POINT = 0x0, enum gsi_general_irq_id {
BUS_ERROR = 0x1, BREAK_POINT = BIT(0),
CMD_FIFO_OVRFLOW = 0x2, BUS_ERROR = BIT(1),
MCS_STACK_OVRFLOW = 0x3, CMD_FIFO_OVRFLOW = BIT(2),
MCS_STACK_OVRFLOW = BIT(3),
/* General IRQ types 4-31 (and their bit values) are reserved */
}; };
#define GSI_CNTXT_INTSET_OFFSET \ #define GSI_CNTXT_INTSET_OFFSET \
...@@ -372,7 +354,6 @@ enum gsi_general_id { ...@@ -372,7 +354,6 @@ enum gsi_general_id {
#define GSI_ERROR_LOG_OFFSET \ #define GSI_ERROR_LOG_OFFSET \
(0x0001f200 + 0x4000 * GSI_EE_AP) (0x0001f200 + 0x4000 * GSI_EE_AP)
/* Fields below are present for IPA v3.5.1 and above */
#define ERR_ARG3_FMASK GENMASK(3, 0) #define ERR_ARG3_FMASK GENMASK(3, 0)
#define ERR_ARG2_FMASK GENMASK(7, 4) #define ERR_ARG2_FMASK GENMASK(7, 4)
#define ERR_ARG1_FMASK GENMASK(11, 8) #define ERR_ARG1_FMASK GENMASK(11, 8)
......
...@@ -45,7 +45,6 @@ struct ipa_interrupt; ...@@ -45,7 +45,6 @@ struct ipa_interrupt;
* @interrupt: IPA Interrupt information * @interrupt: IPA Interrupt information
* @uc_powered: true if power is active by proxy for microcontroller * @uc_powered: true if power is active by proxy for microcontroller
* @uc_loaded: true after microcontroller has reported it's ready * @uc_loaded: true after microcontroller has reported it's ready
* @reg_addr: DMA address used for IPA register access
* @reg_virt: Virtual address used for IPA register access * @reg_virt: Virtual address used for IPA register access
* @regs: IPA register definitions * @regs: IPA register definitions
* @mem_addr: DMA address of IPA-local memory space * @mem_addr: DMA address of IPA-local memory space
...@@ -97,9 +96,8 @@ struct ipa { ...@@ -97,9 +96,8 @@ struct ipa {
bool uc_powered; bool uc_powered;
bool uc_loaded; bool uc_loaded;
dma_addr_t reg_addr;
void __iomem *reg_virt; void __iomem *reg_virt;
const struct ipa_regs *regs; const struct regs *regs;
dma_addr_t mem_addr; dma_addr_t mem_addr;
void *mem_virt; void *mem_virt;
......
...@@ -287,7 +287,7 @@ static bool ipa_cmd_register_write_offset_valid(struct ipa *ipa, ...@@ -287,7 +287,7 @@ static bool ipa_cmd_register_write_offset_valid(struct ipa *ipa,
/* Check whether offsets passed to register_write are valid */ /* Check whether offsets passed to register_write are valid */
static bool ipa_cmd_register_write_valid(struct ipa *ipa) static bool ipa_cmd_register_write_valid(struct ipa *ipa)
{ {
const struct ipa_reg *reg; const struct reg *reg;
const char *name; const char *name;
u32 offset; u32 offset;
...@@ -300,7 +300,7 @@ static bool ipa_cmd_register_write_valid(struct ipa *ipa) ...@@ -300,7 +300,7 @@ static bool ipa_cmd_register_write_valid(struct ipa *ipa)
else else
reg = ipa_reg(ipa, FILT_ROUT_CACHE_FLUSH); reg = ipa_reg(ipa, FILT_ROUT_CACHE_FLUSH);
offset = ipa_reg_offset(reg); offset = reg_offset(reg);
name = "filter/route hash flush"; name = "filter/route hash flush";
if (!ipa_cmd_register_write_offset_valid(ipa, name, offset)) if (!ipa_cmd_register_write_offset_valid(ipa, name, offset))
return false; return false;
...@@ -314,7 +314,7 @@ static bool ipa_cmd_register_write_valid(struct ipa *ipa) ...@@ -314,7 +314,7 @@ static bool ipa_cmd_register_write_valid(struct ipa *ipa)
* fits in the register write command field(s) that must hold it. * fits in the register write command field(s) that must hold it.
*/ */
reg = ipa_reg(ipa, ENDP_STATUS); reg = ipa_reg(ipa, ENDP_STATUS);
offset = ipa_reg_n_offset(reg, IPA_ENDPOINT_COUNT - 1); offset = reg_n_offset(reg, IPA_ENDPOINT_COUNT - 1);
name = "maximal endpoint status"; name = "maximal endpoint status";
if (!ipa_cmd_register_write_offset_valid(ipa, name, offset)) if (!ipa_cmd_register_write_offset_valid(ipa, name, offset))
return false; return false;
......
This diff is collapsed.
...@@ -47,12 +47,12 @@ struct ipa_interrupt { ...@@ -47,12 +47,12 @@ struct ipa_interrupt {
static void ipa_interrupt_process(struct ipa_interrupt *interrupt, u32 irq_id) static void ipa_interrupt_process(struct ipa_interrupt *interrupt, u32 irq_id)
{ {
struct ipa *ipa = interrupt->ipa; struct ipa *ipa = interrupt->ipa;
const struct ipa_reg *reg; const struct reg *reg;
u32 mask = BIT(irq_id); u32 mask = BIT(irq_id);
u32 offset; u32 offset;
reg = ipa_reg(ipa, IPA_IRQ_CLR); reg = ipa_reg(ipa, IPA_IRQ_CLR);
offset = ipa_reg_offset(reg); offset = reg_offset(reg);
switch (irq_id) { switch (irq_id) {
case IPA_IRQ_UC_0: case IPA_IRQ_UC_0:
...@@ -85,7 +85,7 @@ static irqreturn_t ipa_isr_thread(int irq, void *dev_id) ...@@ -85,7 +85,7 @@ static irqreturn_t ipa_isr_thread(int irq, void *dev_id)
struct ipa_interrupt *interrupt = dev_id; struct ipa_interrupt *interrupt = dev_id;
struct ipa *ipa = interrupt->ipa; struct ipa *ipa = interrupt->ipa;
u32 enabled = interrupt->enabled; u32 enabled = interrupt->enabled;
const struct ipa_reg *reg; const struct reg *reg;
struct device *dev; struct device *dev;
u32 pending; u32 pending;
u32 offset; u32 offset;
...@@ -102,7 +102,7 @@ static irqreturn_t ipa_isr_thread(int irq, void *dev_id) ...@@ -102,7 +102,7 @@ static irqreturn_t ipa_isr_thread(int irq, void *dev_id)
* only the enabled ones. * only the enabled ones.
*/ */
reg = ipa_reg(ipa, IPA_IRQ_STTS); reg = ipa_reg(ipa, IPA_IRQ_STTS);
offset = ipa_reg_offset(reg); offset = reg_offset(reg);
pending = ioread32(ipa->reg_virt + offset); pending = ioread32(ipa->reg_virt + offset);
while ((mask = pending & enabled)) { while ((mask = pending & enabled)) {
do { do {
...@@ -120,8 +120,7 @@ static irqreturn_t ipa_isr_thread(int irq, void *dev_id) ...@@ -120,8 +120,7 @@ static irqreturn_t ipa_isr_thread(int irq, void *dev_id)
dev_dbg(dev, "clearing disabled IPA interrupts 0x%08x\n", dev_dbg(dev, "clearing disabled IPA interrupts 0x%08x\n",
pending); pending);
reg = ipa_reg(ipa, IPA_IRQ_CLR); reg = ipa_reg(ipa, IPA_IRQ_CLR);
offset = ipa_reg_offset(reg); iowrite32(pending, ipa->reg_virt + reg_offset(reg));
iowrite32(pending, ipa->reg_virt + offset);
} }
out_power_put: out_power_put:
pm_runtime_mark_last_busy(dev); pm_runtime_mark_last_busy(dev);
...@@ -132,9 +131,9 @@ static irqreturn_t ipa_isr_thread(int irq, void *dev_id) ...@@ -132,9 +131,9 @@ static irqreturn_t ipa_isr_thread(int irq, void *dev_id)
static void ipa_interrupt_enabled_update(struct ipa *ipa) static void ipa_interrupt_enabled_update(struct ipa *ipa)
{ {
const struct ipa_reg *reg = ipa_reg(ipa, IPA_IRQ_EN); const struct reg *reg = ipa_reg(ipa, IPA_IRQ_EN);
iowrite32(ipa->interrupt->enabled, ipa->reg_virt + ipa_reg_offset(reg)); iowrite32(ipa->interrupt->enabled, ipa->reg_virt + reg_offset(reg));
} }
/* Enable an IPA interrupt type */ /* Enable an IPA interrupt type */
...@@ -170,7 +169,7 @@ static void ipa_interrupt_suspend_control(struct ipa_interrupt *interrupt, ...@@ -170,7 +169,7 @@ static void ipa_interrupt_suspend_control(struct ipa_interrupt *interrupt,
struct ipa *ipa = interrupt->ipa; struct ipa *ipa = interrupt->ipa;
u32 mask = BIT(endpoint_id % 32); u32 mask = BIT(endpoint_id % 32);
u32 unit = endpoint_id / 32; u32 unit = endpoint_id / 32;
const struct ipa_reg *reg; const struct reg *reg;
u32 offset; u32 offset;
u32 val; u32 val;
...@@ -181,7 +180,7 @@ static void ipa_interrupt_suspend_control(struct ipa_interrupt *interrupt, ...@@ -181,7 +180,7 @@ static void ipa_interrupt_suspend_control(struct ipa_interrupt *interrupt,
return; return;
reg = ipa_reg(ipa, IRQ_SUSPEND_EN); reg = ipa_reg(ipa, IRQ_SUSPEND_EN);
offset = ipa_reg_n_offset(reg, unit); offset = reg_n_offset(reg, unit);
val = ioread32(ipa->reg_virt + offset); val = ioread32(ipa->reg_virt + offset);
if (enable) if (enable)
...@@ -215,18 +214,18 @@ void ipa_interrupt_suspend_clear_all(struct ipa_interrupt *interrupt) ...@@ -215,18 +214,18 @@ void ipa_interrupt_suspend_clear_all(struct ipa_interrupt *interrupt)
unit_count = roundup(ipa->endpoint_count, 32); unit_count = roundup(ipa->endpoint_count, 32);
for (unit = 0; unit < unit_count; unit++) { for (unit = 0; unit < unit_count; unit++) {
const struct ipa_reg *reg; const struct reg *reg;
u32 val; u32 val;
reg = ipa_reg(ipa, IRQ_SUSPEND_INFO); reg = ipa_reg(ipa, IRQ_SUSPEND_INFO);
val = ioread32(ipa->reg_virt + ipa_reg_n_offset(reg, unit)); val = ioread32(ipa->reg_virt + reg_n_offset(reg, unit));
/* SUSPEND interrupt status isn't cleared on IPA version 3.0 */ /* SUSPEND interrupt status isn't cleared on IPA version 3.0 */
if (ipa->version == IPA_VERSION_3_0) if (ipa->version == IPA_VERSION_3_0)
continue; continue;
reg = ipa_reg(ipa, IRQ_SUSPEND_CLR); reg = ipa_reg(ipa, IRQ_SUSPEND_CLR);
iowrite32(val, ipa->reg_virt + ipa_reg_n_offset(reg, unit)); iowrite32(val, ipa->reg_virt + reg_n_offset(reg, unit));
} }
} }
...@@ -241,7 +240,7 @@ struct ipa_interrupt *ipa_interrupt_config(struct ipa *ipa) ...@@ -241,7 +240,7 @@ struct ipa_interrupt *ipa_interrupt_config(struct ipa *ipa)
{ {
struct device *dev = &ipa->pdev->dev; struct device *dev = &ipa->pdev->dev;
struct ipa_interrupt *interrupt; struct ipa_interrupt *interrupt;
const struct ipa_reg *reg; const struct reg *reg;
unsigned int irq; unsigned int irq;
int ret; int ret;
...@@ -261,7 +260,7 @@ struct ipa_interrupt *ipa_interrupt_config(struct ipa *ipa) ...@@ -261,7 +260,7 @@ struct ipa_interrupt *ipa_interrupt_config(struct ipa *ipa)
/* Start with all IPA interrupts disabled */ /* Start with all IPA interrupts disabled */
reg = ipa_reg(ipa, IPA_IRQ_EN); reg = ipa_reg(ipa, IPA_IRQ_EN);
iowrite32(0, ipa->reg_virt + ipa_reg_offset(reg)); iowrite32(0, ipa->reg_virt + reg_offset(reg));
ret = request_threaded_irq(irq, NULL, ipa_isr_thread, IRQF_ONESHOT, ret = request_threaded_irq(irq, NULL, ipa_isr_thread, IRQF_ONESHOT,
"ipa", interrupt); "ipa", interrupt);
......
...@@ -203,7 +203,7 @@ static void ipa_teardown(struct ipa *ipa) ...@@ -203,7 +203,7 @@ static void ipa_teardown(struct ipa *ipa)
static void static void
ipa_hardware_config_bcr(struct ipa *ipa, const struct ipa_data *data) ipa_hardware_config_bcr(struct ipa *ipa, const struct ipa_data *data)
{ {
const struct ipa_reg *reg; const struct reg *reg;
u32 val; u32 val;
/* IPA v4.5+ has no backward compatibility register */ /* IPA v4.5+ has no backward compatibility register */
...@@ -212,13 +212,13 @@ ipa_hardware_config_bcr(struct ipa *ipa, const struct ipa_data *data) ...@@ -212,13 +212,13 @@ ipa_hardware_config_bcr(struct ipa *ipa, const struct ipa_data *data)
reg = ipa_reg(ipa, IPA_BCR); reg = ipa_reg(ipa, IPA_BCR);
val = data->backward_compat; val = data->backward_compat;
iowrite32(val, ipa->reg_virt + ipa_reg_offset(reg)); iowrite32(val, ipa->reg_virt + reg_offset(reg));
} }
static void ipa_hardware_config_tx(struct ipa *ipa) static void ipa_hardware_config_tx(struct ipa *ipa)
{ {
enum ipa_version version = ipa->version; enum ipa_version version = ipa->version;
const struct ipa_reg *reg; const struct reg *reg;
u32 offset; u32 offset;
u32 val; u32 val;
...@@ -227,11 +227,11 @@ static void ipa_hardware_config_tx(struct ipa *ipa) ...@@ -227,11 +227,11 @@ static void ipa_hardware_config_tx(struct ipa *ipa)
/* Disable PA mask to allow HOLB drop */ /* Disable PA mask to allow HOLB drop */
reg = ipa_reg(ipa, IPA_TX_CFG); reg = ipa_reg(ipa, IPA_TX_CFG);
offset = ipa_reg_offset(reg); offset = reg_offset(reg);
val = ioread32(ipa->reg_virt + offset); val = ioread32(ipa->reg_virt + offset);
val &= ~ipa_reg_bit(reg, PA_MASK_EN); val &= ~reg_bit(reg, PA_MASK_EN);
iowrite32(val, ipa->reg_virt + offset); iowrite32(val, ipa->reg_virt + offset);
} }
...@@ -239,7 +239,7 @@ static void ipa_hardware_config_tx(struct ipa *ipa) ...@@ -239,7 +239,7 @@ static void ipa_hardware_config_tx(struct ipa *ipa)
static void ipa_hardware_config_clkon(struct ipa *ipa) static void ipa_hardware_config_clkon(struct ipa *ipa)
{ {
enum ipa_version version = ipa->version; enum ipa_version version = ipa->version;
const struct ipa_reg *reg; const struct reg *reg;
u32 val; u32 val;
if (version >= IPA_VERSION_4_5) if (version >= IPA_VERSION_4_5)
...@@ -252,20 +252,20 @@ static void ipa_hardware_config_clkon(struct ipa *ipa) ...@@ -252,20 +252,20 @@ static void ipa_hardware_config_clkon(struct ipa *ipa)
reg = ipa_reg(ipa, CLKON_CFG); reg = ipa_reg(ipa, CLKON_CFG);
if (version == IPA_VERSION_3_1) { if (version == IPA_VERSION_3_1) {
/* Disable MISC clock gating */ /* Disable MISC clock gating */
val = ipa_reg_bit(reg, CLKON_MISC); val = reg_bit(reg, CLKON_MISC);
} else { /* IPA v4.0+ */ } else { /* IPA v4.0+ */
/* Enable open global clocks in the CLKON configuration */ /* Enable open global clocks in the CLKON configuration */
val = ipa_reg_bit(reg, CLKON_GLOBAL); val = reg_bit(reg, CLKON_GLOBAL);
val |= ipa_reg_bit(reg, GLOBAL_2X_CLK); val |= reg_bit(reg, GLOBAL_2X_CLK);
} }
iowrite32(val, ipa->reg_virt + ipa_reg_offset(reg)); iowrite32(val, ipa->reg_virt + reg_offset(reg));
} }
/* Configure bus access behavior for IPA components */ /* Configure bus access behavior for IPA components */
static void ipa_hardware_config_comp(struct ipa *ipa) static void ipa_hardware_config_comp(struct ipa *ipa)
{ {
const struct ipa_reg *reg; const struct reg *reg;
u32 offset; u32 offset;
u32 val; u32 val;
...@@ -274,21 +274,22 @@ static void ipa_hardware_config_comp(struct ipa *ipa) ...@@ -274,21 +274,22 @@ static void ipa_hardware_config_comp(struct ipa *ipa)
return; return;
reg = ipa_reg(ipa, COMP_CFG); reg = ipa_reg(ipa, COMP_CFG);
offset = ipa_reg_offset(reg); offset = reg_offset(reg);
val = ioread32(ipa->reg_virt + offset); val = ioread32(ipa->reg_virt + offset);
if (ipa->version == IPA_VERSION_4_0) { if (ipa->version == IPA_VERSION_4_0) {
val &= ~ipa_reg_bit(reg, IPA_QMB_SELECT_CONS_EN); val &= ~reg_bit(reg, IPA_QMB_SELECT_CONS_EN);
val &= ~ipa_reg_bit(reg, IPA_QMB_SELECT_PROD_EN); val &= ~reg_bit(reg, IPA_QMB_SELECT_PROD_EN);
val &= ~ipa_reg_bit(reg, IPA_QMB_SELECT_GLOBAL_EN); val &= ~reg_bit(reg, IPA_QMB_SELECT_GLOBAL_EN);
} else if (ipa->version < IPA_VERSION_4_5) { } else if (ipa->version < IPA_VERSION_4_5) {
val |= ipa_reg_bit(reg, GSI_MULTI_AXI_MASTERS_DIS); val |= reg_bit(reg, GSI_MULTI_AXI_MASTERS_DIS);
} else { } else {
/* For IPA v4.5 FULL_FLUSH_WAIT_RS_CLOSURE_EN is 0 */ /* For IPA v4.5 FULL_FLUSH_WAIT_RS_CLOSURE_EN is 0 */
} }
val |= ipa_reg_bit(reg, GSI_MULTI_INORDER_RD_DIS); val |= reg_bit(reg, GSI_MULTI_INORDER_RD_DIS);
val |= ipa_reg_bit(reg, GSI_MULTI_INORDER_WR_DIS); val |= reg_bit(reg, GSI_MULTI_INORDER_WR_DIS);
iowrite32(val, ipa->reg_virt + offset); iowrite32(val, ipa->reg_virt + offset);
} }
...@@ -299,7 +300,7 @@ ipa_hardware_config_qsb(struct ipa *ipa, const struct ipa_data *data) ...@@ -299,7 +300,7 @@ ipa_hardware_config_qsb(struct ipa *ipa, const struct ipa_data *data)
{ {
const struct ipa_qsb_data *data0; const struct ipa_qsb_data *data0;
const struct ipa_qsb_data *data1; const struct ipa_qsb_data *data1;
const struct ipa_reg *reg; const struct reg *reg;
u32 val; u32 val;
/* QMB 0 represents DDR; QMB 1 (if present) represents PCIe */ /* QMB 0 represents DDR; QMB 1 (if present) represents PCIe */
...@@ -310,29 +311,27 @@ ipa_hardware_config_qsb(struct ipa *ipa, const struct ipa_data *data) ...@@ -310,29 +311,27 @@ ipa_hardware_config_qsb(struct ipa *ipa, const struct ipa_data *data)
/* Max outstanding write accesses for QSB masters */ /* Max outstanding write accesses for QSB masters */
reg = ipa_reg(ipa, QSB_MAX_WRITES); reg = ipa_reg(ipa, QSB_MAX_WRITES);
val = ipa_reg_encode(reg, GEN_QMB_0_MAX_WRITES, data0->max_writes); val = reg_encode(reg, GEN_QMB_0_MAX_WRITES, data0->max_writes);
if (data->qsb_count > 1) if (data->qsb_count > 1)
val |= ipa_reg_encode(reg, GEN_QMB_1_MAX_WRITES, val |= reg_encode(reg, GEN_QMB_1_MAX_WRITES, data1->max_writes);
data1->max_writes);
iowrite32(val, ipa->reg_virt + ipa_reg_offset(reg)); iowrite32(val, ipa->reg_virt + reg_offset(reg));
/* Max outstanding read accesses for QSB masters */ /* Max outstanding read accesses for QSB masters */
reg = ipa_reg(ipa, QSB_MAX_READS); reg = ipa_reg(ipa, QSB_MAX_READS);
val = ipa_reg_encode(reg, GEN_QMB_0_MAX_READS, data0->max_reads); val = reg_encode(reg, GEN_QMB_0_MAX_READS, data0->max_reads);
if (ipa->version >= IPA_VERSION_4_0) if (ipa->version >= IPA_VERSION_4_0)
val |= ipa_reg_encode(reg, GEN_QMB_0_MAX_READS_BEATS, val |= reg_encode(reg, GEN_QMB_0_MAX_READS_BEATS,
data0->max_reads_beats); data0->max_reads_beats);
if (data->qsb_count > 1) { if (data->qsb_count > 1) {
val = ipa_reg_encode(reg, GEN_QMB_1_MAX_READS, val = reg_encode(reg, GEN_QMB_1_MAX_READS, data1->max_reads);
data1->max_reads);
if (ipa->version >= IPA_VERSION_4_0) if (ipa->version >= IPA_VERSION_4_0)
val |= ipa_reg_encode(reg, GEN_QMB_1_MAX_READS_BEATS, val |= reg_encode(reg, GEN_QMB_1_MAX_READS_BEATS,
data1->max_reads_beats); data1->max_reads_beats);
} }
iowrite32(val, ipa->reg_virt + ipa_reg_offset(reg)); iowrite32(val, ipa->reg_virt + reg_offset(reg));
} }
/* The internal inactivity timer clock is used for the aggregation timer */ /* The internal inactivity timer clock is used for the aggregation timer */
...@@ -368,46 +367,47 @@ static __always_inline u32 ipa_aggr_granularity_val(u32 usec) ...@@ -368,46 +367,47 @@ static __always_inline u32 ipa_aggr_granularity_val(u32 usec)
*/ */
static void ipa_qtime_config(struct ipa *ipa) static void ipa_qtime_config(struct ipa *ipa)
{ {
const struct ipa_reg *reg; const struct reg *reg;
u32 offset; u32 offset;
u32 val; u32 val;
/* Timer clock divider must be disabled when we change the rate */ /* Timer clock divider must be disabled when we change the rate */
reg = ipa_reg(ipa, TIMERS_XO_CLK_DIV_CFG); reg = ipa_reg(ipa, TIMERS_XO_CLK_DIV_CFG);
iowrite32(0, ipa->reg_virt + ipa_reg_offset(reg)); iowrite32(0, ipa->reg_virt + reg_offset(reg));
reg = ipa_reg(ipa, QTIME_TIMESTAMP_CFG); reg = ipa_reg(ipa, QTIME_TIMESTAMP_CFG);
/* Set DPL time stamp resolution to use Qtime (instead of 1 msec) */ /* Set DPL time stamp resolution to use Qtime (instead of 1 msec) */
val = ipa_reg_encode(reg, DPL_TIMESTAMP_LSB, DPL_TIMESTAMP_SHIFT); val = reg_encode(reg, DPL_TIMESTAMP_LSB, DPL_TIMESTAMP_SHIFT);
val |= ipa_reg_bit(reg, DPL_TIMESTAMP_SEL); val |= reg_bit(reg, DPL_TIMESTAMP_SEL);
/* Configure tag and NAT Qtime timestamp resolution as well */ /* Configure tag and NAT Qtime timestamp resolution as well */
val = ipa_reg_encode(reg, TAG_TIMESTAMP_LSB, TAG_TIMESTAMP_SHIFT); val = reg_encode(reg, TAG_TIMESTAMP_LSB, TAG_TIMESTAMP_SHIFT);
val = ipa_reg_encode(reg, NAT_TIMESTAMP_LSB, NAT_TIMESTAMP_SHIFT); val = reg_encode(reg, NAT_TIMESTAMP_LSB, NAT_TIMESTAMP_SHIFT);
iowrite32(val, ipa->reg_virt + ipa_reg_offset(reg)); iowrite32(val, ipa->reg_virt + reg_offset(reg));
/* Set granularity of pulse generators used for other timers */ /* Set granularity of pulse generators used for other timers */
reg = ipa_reg(ipa, TIMERS_PULSE_GRAN_CFG); reg = ipa_reg(ipa, TIMERS_PULSE_GRAN_CFG);
val = ipa_reg_encode(reg, PULSE_GRAN_0, IPA_GRAN_100_US); val = reg_encode(reg, PULSE_GRAN_0, IPA_GRAN_100_US);
val |= ipa_reg_encode(reg, PULSE_GRAN_1, IPA_GRAN_1_MS); val |= reg_encode(reg, PULSE_GRAN_1, IPA_GRAN_1_MS);
if (ipa->version >= IPA_VERSION_5_0) { if (ipa->version >= IPA_VERSION_5_0) {
val |= ipa_reg_encode(reg, PULSE_GRAN_2, IPA_GRAN_10_MS); val |= reg_encode(reg, PULSE_GRAN_2, IPA_GRAN_10_MS);
val |= ipa_reg_encode(reg, PULSE_GRAN_3, IPA_GRAN_10_MS); val |= reg_encode(reg, PULSE_GRAN_3, IPA_GRAN_10_MS);
} else { } else {
val |= ipa_reg_encode(reg, PULSE_GRAN_2, IPA_GRAN_1_MS); val |= reg_encode(reg, PULSE_GRAN_2, IPA_GRAN_1_MS);
} }
iowrite32(val, ipa->reg_virt + ipa_reg_offset(reg)); iowrite32(val, ipa->reg_virt + reg_offset(reg));
/* Actual divider is 1 more than value supplied here */ /* Actual divider is 1 more than value supplied here */
reg = ipa_reg(ipa, TIMERS_XO_CLK_DIV_CFG); reg = ipa_reg(ipa, TIMERS_XO_CLK_DIV_CFG);
offset = ipa_reg_offset(reg); offset = reg_offset(reg);
val = ipa_reg_encode(reg, DIV_VALUE, IPA_XO_CLOCK_DIVIDER - 1);
val = reg_encode(reg, DIV_VALUE, IPA_XO_CLOCK_DIVIDER - 1);
iowrite32(val, ipa->reg_virt + offset); iowrite32(val, ipa->reg_virt + offset);
/* Divider value is set; re-enable the common timer clock divider */ /* Divider value is set; re-enable the common timer clock divider */
val |= ipa_reg_bit(reg, DIV_ENABLE); val |= reg_bit(reg, DIV_ENABLE);
iowrite32(val, ipa->reg_virt + offset); iowrite32(val, ipa->reg_virt + offset);
} }
...@@ -416,13 +416,13 @@ static void ipa_qtime_config(struct ipa *ipa) ...@@ -416,13 +416,13 @@ static void ipa_qtime_config(struct ipa *ipa)
static void ipa_hardware_config_counter(struct ipa *ipa) static void ipa_hardware_config_counter(struct ipa *ipa)
{ {
u32 granularity = ipa_aggr_granularity_val(IPA_AGGR_GRANULARITY); u32 granularity = ipa_aggr_granularity_val(IPA_AGGR_GRANULARITY);
const struct ipa_reg *reg; const struct reg *reg;
u32 val; u32 val;
reg = ipa_reg(ipa, COUNTER_CFG); reg = ipa_reg(ipa, COUNTER_CFG);
/* If defined, EOT_COAL_GRANULARITY is 0 */ /* If defined, EOT_COAL_GRANULARITY is 0 */
val = ipa_reg_encode(reg, AGGR_GRANULARITY, granularity); val = reg_encode(reg, AGGR_GRANULARITY, granularity);
iowrite32(val, ipa->reg_virt + ipa_reg_offset(reg)); iowrite32(val, ipa->reg_virt + reg_offset(reg));
} }
static void ipa_hardware_config_timing(struct ipa *ipa) static void ipa_hardware_config_timing(struct ipa *ipa)
...@@ -435,7 +435,7 @@ static void ipa_hardware_config_timing(struct ipa *ipa) ...@@ -435,7 +435,7 @@ static void ipa_hardware_config_timing(struct ipa *ipa)
static void ipa_hardware_config_hashing(struct ipa *ipa) static void ipa_hardware_config_hashing(struct ipa *ipa)
{ {
const struct ipa_reg *reg; const struct reg *reg;
/* Other than IPA v4.2, all versions enable "hashing". Starting /* Other than IPA v4.2, all versions enable "hashing". Starting
* with IPA v5.0, the filter and router tables are implemented * with IPA v5.0, the filter and router tables are implemented
...@@ -451,26 +451,26 @@ static void ipa_hardware_config_hashing(struct ipa *ipa) ...@@ -451,26 +451,26 @@ static void ipa_hardware_config_hashing(struct ipa *ipa)
/* IPV6_ROUTER_HASH, IPV6_FILTER_HASH, IPV4_ROUTER_HASH, /* IPV6_ROUTER_HASH, IPV6_FILTER_HASH, IPV4_ROUTER_HASH,
* IPV4_FILTER_HASH are all zero. * IPV4_FILTER_HASH are all zero.
*/ */
iowrite32(0, ipa->reg_virt + ipa_reg_offset(reg)); iowrite32(0, ipa->reg_virt + reg_offset(reg));
} }
static void ipa_idle_indication_cfg(struct ipa *ipa, static void ipa_idle_indication_cfg(struct ipa *ipa,
u32 enter_idle_debounce_thresh, u32 enter_idle_debounce_thresh,
bool const_non_idle_enable) bool const_non_idle_enable)
{ {
const struct ipa_reg *reg; const struct reg *reg;
u32 val; u32 val;
if (ipa->version < IPA_VERSION_3_5_1) if (ipa->version < IPA_VERSION_3_5_1)
return; return;
reg = ipa_reg(ipa, IDLE_INDICATION_CFG); reg = ipa_reg(ipa, IDLE_INDICATION_CFG);
val = ipa_reg_encode(reg, ENTER_IDLE_DEBOUNCE_THRESH, val = reg_encode(reg, ENTER_IDLE_DEBOUNCE_THRESH,
enter_idle_debounce_thresh); enter_idle_debounce_thresh);
if (const_non_idle_enable) if (const_non_idle_enable)
val |= ipa_reg_bit(reg, CONST_NON_IDLE_ENABLE); val |= reg_bit(reg, CONST_NON_IDLE_ENABLE);
iowrite32(val, ipa->reg_virt + ipa_reg_offset(reg)); iowrite32(val, ipa->reg_virt + reg_offset(reg));
} }
/** /**
......
...@@ -75,7 +75,7 @@ ipa_mem_zero_region_add(struct gsi_trans *trans, enum ipa_mem_id mem_id) ...@@ -75,7 +75,7 @@ ipa_mem_zero_region_add(struct gsi_trans *trans, enum ipa_mem_id mem_id)
int ipa_mem_setup(struct ipa *ipa) int ipa_mem_setup(struct ipa *ipa)
{ {
dma_addr_t addr = ipa->zero_addr; dma_addr_t addr = ipa->zero_addr;
const struct ipa_reg *reg; const struct reg *reg;
const struct ipa_mem *mem; const struct ipa_mem *mem;
struct gsi_trans *trans; struct gsi_trans *trans;
u32 offset; u32 offset;
...@@ -115,8 +115,8 @@ int ipa_mem_setup(struct ipa *ipa) ...@@ -115,8 +115,8 @@ int ipa_mem_setup(struct ipa *ipa)
offset = ipa->mem_offset + mem->offset; offset = ipa->mem_offset + mem->offset;
reg = ipa_reg(ipa, LOCAL_PKT_PROC_CNTXT); reg = ipa_reg(ipa, LOCAL_PKT_PROC_CNTXT);
val = ipa_reg_encode(reg, IPA_BASE_ADDR, offset); val = reg_encode(reg, IPA_BASE_ADDR, offset);
iowrite32(val, ipa->reg_virt + ipa_reg_offset(reg)); iowrite32(val, ipa->reg_virt + reg_offset(reg));
return 0; return 0;
} }
...@@ -318,8 +318,8 @@ static bool ipa_mem_size_valid(struct ipa *ipa) ...@@ -318,8 +318,8 @@ static bool ipa_mem_size_valid(struct ipa *ipa)
int ipa_mem_config(struct ipa *ipa) int ipa_mem_config(struct ipa *ipa)
{ {
struct device *dev = &ipa->pdev->dev; struct device *dev = &ipa->pdev->dev;
const struct ipa_reg *reg;
const struct ipa_mem *mem; const struct ipa_mem *mem;
const struct reg *reg;
dma_addr_t addr; dma_addr_t addr;
u32 mem_size; u32 mem_size;
void *virt; void *virt;
...@@ -328,13 +328,13 @@ int ipa_mem_config(struct ipa *ipa) ...@@ -328,13 +328,13 @@ int ipa_mem_config(struct ipa *ipa)
/* Check the advertised location and size of the shared memory area */ /* Check the advertised location and size of the shared memory area */
reg = ipa_reg(ipa, SHARED_MEM_SIZE); reg = ipa_reg(ipa, SHARED_MEM_SIZE);
val = ioread32(ipa->reg_virt + ipa_reg_offset(reg)); val = ioread32(ipa->reg_virt + reg_offset(reg));
/* The fields in the register are in 8 byte units */ /* The fields in the register are in 8 byte units */
ipa->mem_offset = 8 * ipa_reg_decode(reg, MEM_BADDR, val); ipa->mem_offset = 8 * reg_decode(reg, MEM_BADDR, val);
/* Make sure the end is within the region's mapped space */ /* Make sure the end is within the region's mapped space */
mem_size = 8 * ipa_reg_decode(reg, MEM_SIZE, val); mem_size = 8 * reg_decode(reg, MEM_SIZE, val);
/* If the sizes don't match, issue a warning */ /* If the sizes don't match, issue a warning */
if (ipa->mem_offset + mem_size < ipa->mem_size) { if (ipa->mem_offset + mem_size < ipa->mem_size) {
......
...@@ -9,73 +9,96 @@ ...@@ -9,73 +9,96 @@
#include "ipa.h" #include "ipa.h"
#include "ipa_reg.h" #include "ipa_reg.h"
/* Is this register valid and defined for the current IPA version? */ /* Is this register ID valid for the current IPA version? */
static bool ipa_reg_valid(struct ipa *ipa, enum ipa_reg_id reg_id) static bool ipa_reg_id_valid(struct ipa *ipa, enum ipa_reg_id reg_id)
{ {
enum ipa_version version = ipa->version; enum ipa_version version = ipa->version;
bool valid;
/* Check for bogus (out of range) register IDs */
if ((u32)reg_id >= ipa->regs->reg_count)
return false;
switch (reg_id) { switch (reg_id) {
case IPA_BCR: case IPA_BCR:
case COUNTER_CFG: case COUNTER_CFG:
valid = version < IPA_VERSION_4_5; return version < IPA_VERSION_4_5;
break;
case IPA_TX_CFG: case IPA_TX_CFG:
case FLAVOR_0: case FLAVOR_0:
case IDLE_INDICATION_CFG: case IDLE_INDICATION_CFG:
valid = version >= IPA_VERSION_3_5; return version >= IPA_VERSION_3_5;
break;
case QTIME_TIMESTAMP_CFG: case QTIME_TIMESTAMP_CFG:
case TIMERS_XO_CLK_DIV_CFG: case TIMERS_XO_CLK_DIV_CFG:
case TIMERS_PULSE_GRAN_CFG: case TIMERS_PULSE_GRAN_CFG:
valid = version >= IPA_VERSION_4_5; return version >= IPA_VERSION_4_5;
break;
case SRC_RSRC_GRP_45_RSRC_TYPE: case SRC_RSRC_GRP_45_RSRC_TYPE:
case DST_RSRC_GRP_45_RSRC_TYPE: case DST_RSRC_GRP_45_RSRC_TYPE:
valid = version <= IPA_VERSION_3_1 || return version <= IPA_VERSION_3_1 ||
version == IPA_VERSION_4_5; version == IPA_VERSION_4_5;
break;
case SRC_RSRC_GRP_67_RSRC_TYPE: case SRC_RSRC_GRP_67_RSRC_TYPE:
case DST_RSRC_GRP_67_RSRC_TYPE: case DST_RSRC_GRP_67_RSRC_TYPE:
valid = version <= IPA_VERSION_3_1; return version <= IPA_VERSION_3_1;
break;
case ENDP_FILTER_ROUTER_HSH_CFG: case ENDP_FILTER_ROUTER_HSH_CFG:
valid = version != IPA_VERSION_4_2; return version != IPA_VERSION_4_2;
break;
case IRQ_SUSPEND_EN: case IRQ_SUSPEND_EN:
case IRQ_SUSPEND_CLR: case IRQ_SUSPEND_CLR:
valid = version >= IPA_VERSION_3_1; return version >= IPA_VERSION_3_1;
break;
case COMP_CFG:
case CLKON_CFG:
case ROUTE:
case SHARED_MEM_SIZE:
case QSB_MAX_WRITES:
case QSB_MAX_READS:
case FILT_ROUT_HASH_EN:
case FILT_ROUT_CACHE_CFG:
case FILT_ROUT_HASH_FLUSH:
case FILT_ROUT_CACHE_FLUSH:
case STATE_AGGR_ACTIVE:
case LOCAL_PKT_PROC_CNTXT:
case AGGR_FORCE_CLOSE:
case SRC_RSRC_GRP_01_RSRC_TYPE:
case SRC_RSRC_GRP_23_RSRC_TYPE:
case DST_RSRC_GRP_01_RSRC_TYPE:
case DST_RSRC_GRP_23_RSRC_TYPE:
case ENDP_INIT_CTRL:
case ENDP_INIT_CFG:
case ENDP_INIT_NAT:
case ENDP_INIT_HDR:
case ENDP_INIT_HDR_EXT:
case ENDP_INIT_HDR_METADATA_MASK:
case ENDP_INIT_MODE:
case ENDP_INIT_AGGR:
case ENDP_INIT_HOL_BLOCK_EN:
case ENDP_INIT_HOL_BLOCK_TIMER:
case ENDP_INIT_DEAGGR:
case ENDP_INIT_RSRC_GRP:
case ENDP_INIT_SEQ:
case ENDP_STATUS:
case ENDP_FILTER_CACHE_CFG:
case ENDP_ROUTER_CACHE_CFG:
case IPA_IRQ_STTS:
case IPA_IRQ_EN:
case IPA_IRQ_CLR:
case IPA_IRQ_UC:
case IRQ_SUSPEND_INFO:
return true; /* These should be defined for all versions */
default: default:
valid = true; /* Others should be defined for all versions */ return false;
break;
} }
/* To be valid, it must be defined */
return valid && ipa->regs->reg[reg_id];
} }
const struct ipa_reg *ipa_reg(struct ipa *ipa, enum ipa_reg_id reg_id) const struct reg *ipa_reg(struct ipa *ipa, enum ipa_reg_id reg_id)
{ {
if (WARN_ON(!ipa_reg_valid(ipa, reg_id))) if (WARN(!ipa_reg_id_valid(ipa, reg_id), "invalid reg %u\n", reg_id))
return NULL; return NULL;
return ipa->regs->reg[reg_id]; return reg(ipa->regs, reg_id);
} }
static const struct ipa_regs *ipa_regs(enum ipa_version version) static const struct regs *ipa_regs(enum ipa_version version)
{ {
switch (version) { switch (version) {
case IPA_VERSION_3_1: case IPA_VERSION_3_1:
...@@ -100,7 +123,7 @@ static const struct ipa_regs *ipa_regs(enum ipa_version version) ...@@ -100,7 +123,7 @@ static const struct ipa_regs *ipa_regs(enum ipa_version version)
int ipa_reg_init(struct ipa *ipa) int ipa_reg_init(struct ipa *ipa)
{ {
struct device *dev = &ipa->pdev->dev; struct device *dev = &ipa->pdev->dev;
const struct ipa_regs *regs; const struct regs *regs;
struct resource *res; struct resource *res;
regs = ipa_regs(ipa->version); regs = ipa_regs(ipa->version);
...@@ -123,7 +146,6 @@ int ipa_reg_init(struct ipa *ipa) ...@@ -123,7 +146,6 @@ int ipa_reg_init(struct ipa *ipa)
dev_err(dev, "unable to remap \"ipa-reg\" memory\n"); dev_err(dev, "unable to remap \"ipa-reg\" memory\n");
return -ENOMEM; return -ENOMEM;
} }
ipa->reg_addr = res->start;
ipa->regs = regs; ipa->regs = regs;
return 0; return 0;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <linux/bug.h> #include <linux/bug.h>
#include "ipa_version.h" #include "ipa_version.h"
#include "reg.h"
struct ipa; struct ipa;
...@@ -35,7 +36,7 @@ struct ipa; ...@@ -35,7 +36,7 @@ struct ipa;
* by register ID. Each entry in the array specifies the base offset and * by register ID. Each entry in the array specifies the base offset and
* (for parameterized registers) a non-zero stride value. Not all versions * (for parameterized registers) a non-zero stride value. Not all versions
* of IPA define all registers. The offset for a register is returned by * of IPA define all registers. The offset for a register is returned by
* ipa_reg_offset() when the register's ipa_reg structure is supplied; * reg_offset() when the register's ipa_reg structure is supplied;
* zero is returned for an undefined register (this should never happen). * zero is returned for an undefined register (this should never happen).
* *
* Some registers encode multiple fields within them. Each field in * Some registers encode multiple fields within them. Each field in
...@@ -44,9 +45,9 @@ struct ipa; ...@@ -44,9 +45,9 @@ struct ipa;
* an array of field masks, indexed by field ID. Two functions are * an array of field masks, indexed by field ID. Two functions are
* used to access register fields; both take an ipa_reg structure as * used to access register fields; both take an ipa_reg structure as
* argument. To encode a value to be represented in a register field, * argument. To encode a value to be represented in a register field,
* the value and field ID are passed to ipa_reg_encode(). To extract * the value and field ID are passed to reg_encode(). To extract
* a value encoded in a register field, the field ID is passed to * a value encoded in a register field, the field ID is passed to
* ipa_reg_decode(). In addition, for single-bit fields, ipa_reg_bit() * reg_decode(). In addition, for single-bit fields, reg_bit()
* can be used to either encode the bit value, or to generate a mask * can be used to either encode the bit value, or to generate a mask
* used to extract the bit value. * used to extract the bit value.
*/ */
...@@ -110,56 +111,6 @@ enum ipa_reg_id { ...@@ -110,56 +111,6 @@ enum ipa_reg_id {
IPA_REG_ID_COUNT, /* Last; not an ID */ IPA_REG_ID_COUNT, /* Last; not an ID */
}; };
/**
* struct ipa_reg - An IPA register descriptor
* @offset: Register offset relative to base of the "ipa-reg" 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 IPA register
*/
struct ipa_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 IPA_REG(__NAME, __reg_id, __offset) \
IPA_REG_STRIDE(__NAME, __reg_id, __offset, 0)
/* Helper macro for defining parameterized registers, specifying stride */
#define IPA_REG_STRIDE(__NAME, __reg_id, __offset, __stride) \
static const struct ipa_reg ipa_reg_ ## __reg_id = { \
.name = #__NAME, \
.offset = __offset, \
.stride = __stride, \
}
#define IPA_REG_FIELDS(__NAME, __name, __offset) \
IPA_REG_STRIDE_FIELDS(__NAME, __name, __offset, 0)
#define IPA_REG_STRIDE_FIELDS(__NAME, __name, __offset, __stride) \
static const struct ipa_reg ipa_reg_ ## __name = { \
.name = #__NAME, \
.offset = __offset, \
.stride = __stride, \
.fcount = ARRAY_SIZE(ipa_reg_ ## __name ## _fmask), \
.fmask = ipa_reg_ ## __name ## _fmask, \
}
/**
* struct ipa_regs - Description of registers supported by hardware
* @reg_count: Number of registers in the @reg[] array
* @reg: Array of register descriptors
*/
struct ipa_regs {
u32 reg_count;
const struct ipa_reg **reg;
};
/* COMP_CFG register */ /* COMP_CFG register */
enum ipa_reg_comp_cfg_field_id { enum ipa_reg_comp_cfg_field_id {
COMP_CFG_ENABLE, /* Not IPA v4.0+ */ COMP_CFG_ENABLE, /* Not IPA v4.0+ */
...@@ -687,79 +638,15 @@ enum ipa_reg_ipa_irq_uc_field_id { ...@@ -687,79 +638,15 @@ enum ipa_reg_ipa_irq_uc_field_id {
UC_INTR, UC_INTR,
}; };
extern const struct ipa_regs ipa_regs_v3_1; extern const struct regs ipa_regs_v3_1;
extern const struct ipa_regs ipa_regs_v3_5_1; extern const struct regs ipa_regs_v3_5_1;
extern const struct ipa_regs ipa_regs_v4_2; extern const struct regs ipa_regs_v4_2;
extern const struct ipa_regs ipa_regs_v4_5; extern const struct regs ipa_regs_v4_5;
extern const struct ipa_regs ipa_regs_v4_7; extern const struct regs ipa_regs_v4_7;
extern const struct ipa_regs ipa_regs_v4_9; extern const struct regs ipa_regs_v4_9;
extern const struct ipa_regs ipa_regs_v4_11; extern const struct regs ipa_regs_v4_11;
/* Return the field mask for a field in a register */
static inline u32 ipa_reg_fmask(const struct ipa_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 */
static inline u32 ipa_reg_bit(const struct ipa_reg *reg, u32 field_id)
{
u32 fmask = ipa_reg_fmask(reg, field_id);
WARN_ON(!is_power_of_2(fmask));
return fmask;
}
/* Encode a value into the given field of a register */
static inline u32
ipa_reg_encode(const struct ipa_reg *reg, u32 field_id, u32 val)
{
u32 fmask = ipa_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
ipa_reg_decode(const struct ipa_reg *reg, u32 field_id, u32 val)
{
u32 fmask = ipa_reg_fmask(reg, field_id);
return fmask ? (val & fmask) >> __ffs(fmask) : 0;
}
/* Return the maximum value representable by the given field; always 2^n - 1 */
static inline u32 ipa_reg_field_max(const struct ipa_reg *reg, u32 field_id)
{
u32 fmask = ipa_reg_fmask(reg, field_id);
return fmask ? fmask >> __ffs(fmask) : 0;
}
const struct ipa_reg *ipa_reg(struct ipa *ipa, enum ipa_reg_id reg_id);
/* Returns 0 for NULL reg; warning will have already been issued */
static inline u32 ipa_reg_offset(const struct ipa_reg *reg)
{
return reg ? reg->offset : 0;
}
/* Returns 0 for NULL reg; warning will have already been issued */ const struct reg *ipa_reg(struct ipa *ipa, enum ipa_reg_id reg_id);
static inline u32 ipa_reg_n_offset(const struct ipa_reg *reg, u32 n)
{
return reg ? reg->offset + n * reg->stride : 0;
}
int ipa_reg_init(struct ipa *ipa); int ipa_reg_init(struct ipa *ipa);
void ipa_reg_exit(struct ipa *ipa); void ipa_reg_exit(struct ipa *ipa);
......
...@@ -70,20 +70,20 @@ static bool ipa_resource_limits_valid(struct ipa *ipa, ...@@ -70,20 +70,20 @@ static bool ipa_resource_limits_valid(struct ipa *ipa,
static void static void
ipa_resource_config_common(struct ipa *ipa, u32 resource_type, ipa_resource_config_common(struct ipa *ipa, u32 resource_type,
const struct ipa_reg *reg, const struct reg *reg,
const struct ipa_resource_limits *xlimits, const struct ipa_resource_limits *xlimits,
const struct ipa_resource_limits *ylimits) const struct ipa_resource_limits *ylimits)
{ {
u32 val; u32 val;
val = ipa_reg_encode(reg, X_MIN_LIM, xlimits->min); val = reg_encode(reg, X_MIN_LIM, xlimits->min);
val |= ipa_reg_encode(reg, X_MAX_LIM, xlimits->max); val |= reg_encode(reg, X_MAX_LIM, xlimits->max);
if (ylimits) { if (ylimits) {
val |= ipa_reg_encode(reg, Y_MIN_LIM, ylimits->min); val |= reg_encode(reg, Y_MIN_LIM, ylimits->min);
val |= ipa_reg_encode(reg, Y_MAX_LIM, ylimits->max); val |= reg_encode(reg, Y_MAX_LIM, ylimits->max);
} }
iowrite32(val, ipa->reg_virt + ipa_reg_n_offset(reg, resource_type)); iowrite32(val, ipa->reg_virt + reg_n_offset(reg, resource_type));
} }
static void ipa_resource_config_src(struct ipa *ipa, u32 resource_type, static void ipa_resource_config_src(struct ipa *ipa, u32 resource_type,
...@@ -92,7 +92,7 @@ static void ipa_resource_config_src(struct ipa *ipa, u32 resource_type, ...@@ -92,7 +92,7 @@ static void ipa_resource_config_src(struct ipa *ipa, u32 resource_type,
u32 group_count = data->rsrc_group_src_count; u32 group_count = data->rsrc_group_src_count;
const struct ipa_resource_limits *ylimits; const struct ipa_resource_limits *ylimits;
const struct ipa_resource *resource; const struct ipa_resource *resource;
const struct ipa_reg *reg; const struct reg *reg;
resource = &data->resource_src[resource_type]; resource = &data->resource_src[resource_type];
...@@ -129,7 +129,7 @@ static void ipa_resource_config_dst(struct ipa *ipa, u32 resource_type, ...@@ -129,7 +129,7 @@ static void ipa_resource_config_dst(struct ipa *ipa, u32 resource_type,
u32 group_count = data->rsrc_group_dst_count; u32 group_count = data->rsrc_group_dst_count;
const struct ipa_resource_limits *ylimits; const struct ipa_resource_limits *ylimits;
const struct ipa_resource *resource; const struct ipa_resource *resource;
const struct ipa_reg *reg; const struct reg *reg;
resource = &data->resource_dst[resource_type]; resource = &data->resource_dst[resource_type];
......
...@@ -345,9 +345,8 @@ void ipa_table_reset(struct ipa *ipa, bool modem) ...@@ -345,9 +345,8 @@ void ipa_table_reset(struct ipa *ipa, bool modem)
int ipa_table_hash_flush(struct ipa *ipa) int ipa_table_hash_flush(struct ipa *ipa)
{ {
const struct ipa_reg *reg;
struct gsi_trans *trans; struct gsi_trans *trans;
u32 offset; const struct reg *reg;
u32 val; u32 val;
if (!ipa_table_hash_support(ipa)) if (!ipa_table_hash_support(ipa))
...@@ -361,22 +360,20 @@ int ipa_table_hash_flush(struct ipa *ipa) ...@@ -361,22 +360,20 @@ int ipa_table_hash_flush(struct ipa *ipa)
if (ipa->version < IPA_VERSION_5_0) { if (ipa->version < IPA_VERSION_5_0) {
reg = ipa_reg(ipa, FILT_ROUT_HASH_FLUSH); reg = ipa_reg(ipa, FILT_ROUT_HASH_FLUSH);
offset = ipa_reg_offset(reg);
val = ipa_reg_bit(reg, IPV6_ROUTER_HASH); val = reg_bit(reg, IPV6_ROUTER_HASH);
val |= ipa_reg_bit(reg, IPV6_FILTER_HASH); val |= reg_bit(reg, IPV6_FILTER_HASH);
val |= ipa_reg_bit(reg, IPV4_ROUTER_HASH); val |= reg_bit(reg, IPV4_ROUTER_HASH);
val |= ipa_reg_bit(reg, IPV4_FILTER_HASH); val |= reg_bit(reg, IPV4_FILTER_HASH);
} else { } else {
reg = ipa_reg(ipa, FILT_ROUT_CACHE_FLUSH); reg = ipa_reg(ipa, FILT_ROUT_CACHE_FLUSH);
offset = ipa_reg_offset(reg);
/* IPA v5.0+ uses a unified cache (both IPv4 and IPv6) */ /* IPA v5.0+ uses a unified cache (both IPv4 and IPv6) */
val = ipa_reg_bit(reg, ROUTER_CACHE); val = reg_bit(reg, ROUTER_CACHE);
val |= ipa_reg_bit(reg, FILTER_CACHE); val |= reg_bit(reg, FILTER_CACHE);
} }
ipa_cmd_register_write_add(trans, offset, val, val, false); ipa_cmd_register_write_add(trans, reg_offset(reg), val, val, false);
gsi_trans_commit_wait(trans); gsi_trans_commit_wait(trans);
...@@ -495,22 +492,22 @@ static void ipa_filter_tuple_zero(struct ipa_endpoint *endpoint) ...@@ -495,22 +492,22 @@ static void ipa_filter_tuple_zero(struct ipa_endpoint *endpoint)
{ {
u32 endpoint_id = endpoint->endpoint_id; u32 endpoint_id = endpoint->endpoint_id;
struct ipa *ipa = endpoint->ipa; struct ipa *ipa = endpoint->ipa;
const struct ipa_reg *reg; const struct reg *reg;
u32 offset; u32 offset;
u32 val; u32 val;
if (ipa->version < IPA_VERSION_5_0) { if (ipa->version < IPA_VERSION_5_0) {
reg = ipa_reg(ipa, ENDP_FILTER_ROUTER_HSH_CFG); reg = ipa_reg(ipa, ENDP_FILTER_ROUTER_HSH_CFG);
offset = ipa_reg_n_offset(reg, endpoint_id); offset = reg_n_offset(reg, endpoint_id);
val = ioread32(endpoint->ipa->reg_virt + offset); val = ioread32(endpoint->ipa->reg_virt + offset);
/* Zero all filter-related fields, preserving the rest */ /* Zero all filter-related fields, preserving the rest */
val &= ~ipa_reg_fmask(reg, FILTER_HASH_MSK_ALL); val &= ~reg_fmask(reg, FILTER_HASH_MSK_ALL);
} else { } else {
/* IPA v5.0 separates filter and router cache configuration */ /* IPA v5.0 separates filter and router cache configuration */
reg = ipa_reg(ipa, ENDP_FILTER_CACHE_CFG); reg = ipa_reg(ipa, ENDP_FILTER_CACHE_CFG);
offset = ipa_reg_n_offset(reg, endpoint_id); offset = reg_n_offset(reg, endpoint_id);
/* Zero all filter-related fields */ /* Zero all filter-related fields */
val = 0; val = 0;
...@@ -554,22 +551,22 @@ static bool ipa_route_id_modem(struct ipa *ipa, u32 route_id) ...@@ -554,22 +551,22 @@ static bool ipa_route_id_modem(struct ipa *ipa, u32 route_id)
*/ */
static void ipa_route_tuple_zero(struct ipa *ipa, u32 route_id) static void ipa_route_tuple_zero(struct ipa *ipa, u32 route_id)
{ {
const struct ipa_reg *reg; const struct reg *reg;
u32 offset; u32 offset;
u32 val; u32 val;
if (ipa->version < IPA_VERSION_5_0) { if (ipa->version < IPA_VERSION_5_0) {
reg = ipa_reg(ipa, ENDP_FILTER_ROUTER_HSH_CFG); reg = ipa_reg(ipa, ENDP_FILTER_ROUTER_HSH_CFG);
offset = ipa_reg_n_offset(reg, route_id); offset = reg_n_offset(reg, route_id);
val = ioread32(ipa->reg_virt + offset); val = ioread32(ipa->reg_virt + offset);
/* Zero all route-related fields, preserving the rest */ /* Zero all route-related fields, preserving the rest */
val &= ~ipa_reg_fmask(reg, ROUTER_HASH_MSK_ALL); val &= ~reg_fmask(reg, ROUTER_HASH_MSK_ALL);
} else { } else {
/* IPA v5.0 separates filter and router cache configuration */ /* IPA v5.0 separates filter and router cache configuration */
reg = ipa_reg(ipa, ENDP_ROUTER_CACHE_CFG); reg = ipa_reg(ipa, ENDP_ROUTER_CACHE_CFG);
offset = ipa_reg_n_offset(reg, route_id); offset = reg_n_offset(reg, route_id);
/* Zero all route-related fields */ /* Zero all route-related fields */
val = 0; val = 0;
......
...@@ -231,7 +231,7 @@ void ipa_uc_power(struct ipa *ipa) ...@@ -231,7 +231,7 @@ void ipa_uc_power(struct ipa *ipa)
static void send_uc_command(struct ipa *ipa, u32 command, u32 command_param) static void send_uc_command(struct ipa *ipa, u32 command, u32 command_param)
{ {
struct ipa_uc_mem_area *shared = ipa_uc_shared(ipa); struct ipa_uc_mem_area *shared = ipa_uc_shared(ipa);
const struct ipa_reg *reg; const struct reg *reg;
u32 val; u32 val;
/* Fill in the command data */ /* Fill in the command data */
...@@ -243,9 +243,9 @@ static void send_uc_command(struct ipa *ipa, u32 command, u32 command_param) ...@@ -243,9 +243,9 @@ static void send_uc_command(struct ipa *ipa, u32 command, u32 command_param)
/* Use an interrupt to tell the microcontroller the command is ready */ /* Use an interrupt to tell the microcontroller the command is ready */
reg = ipa_reg(ipa, IPA_IRQ_UC); reg = ipa_reg(ipa, IPA_IRQ_UC);
val = ipa_reg_bit(reg, UC_INTR); val = reg_bit(reg, UC_INTR);
iowrite32(val, ipa->reg_virt + ipa_reg_offset(reg)); iowrite32(val, ipa->reg_virt + reg_offset(reg));
} }
/* Tell the microcontroller the AP is shutting down */ /* Tell the microcontroller the AP is shutting down */
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
/** /**
* enum ipa_version * enum ipa_version
* @IPA_VERSION_3_0: IPA version 3.0/GSI version 1.0 * @IPA_VERSION_3_0: IPA version 3.0/GSI version 1.0
* @IPA_VERSION_3_1: IPA version 3.1/GSI version 1.1 * @IPA_VERSION_3_1: IPA version 3.1/GSI version 1.0
* @IPA_VERSION_3_5: IPA version 3.5/GSI version 1.2 * @IPA_VERSION_3_5: IPA version 3.5/GSI version 1.2
* @IPA_VERSION_3_5_1: IPA version 3.5.1/GSI version 1.3 * @IPA_VERSION_3_5_1: IPA version 3.5.1/GSI version 1.3
* @IPA_VERSION_4_0: IPA version 4.0/GSI version 2.0 * @IPA_VERSION_4_0: IPA version 4.0/GSI version 2.0
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
* @IPA_VERSION_4_9: IPA version 4.9/GSI version 2.9 * @IPA_VERSION_4_9: IPA version 4.9/GSI version 2.9
* @IPA_VERSION_4_11: IPA version 4.11/GSI version 2.11 (2.1.1) * @IPA_VERSION_4_11: IPA version 4.11/GSI version 2.11 (2.1.1)
* @IPA_VERSION_5_0: IPA version 5.0/GSI version 3.0 * @IPA_VERSION_5_0: IPA version 5.0/GSI version 3.0
* @IPA_VERSION_5_1: IPA version 5.1/GSI version 3.0
* @IPA_VERSION_5_5: IPA version 5.5/GSI version 5.5
* @IPA_VERSION_COUNT: Number of defined IPA versions * @IPA_VERSION_COUNT: Number of defined IPA versions
* *
* Defines the version of IPA (and GSI) hardware present on the platform. * Defines the version of IPA (and GSI) hardware present on the platform.
...@@ -38,6 +40,8 @@ enum ipa_version { ...@@ -38,6 +40,8 @@ enum ipa_version {
IPA_VERSION_4_9, IPA_VERSION_4_9,
IPA_VERSION_4_11, IPA_VERSION_4_11,
IPA_VERSION_5_0, IPA_VERSION_5_0,
IPA_VERSION_5_1,
IPA_VERSION_5_5,
IPA_VERSION_COUNT, /* Last; not a version */ IPA_VERSION_COUNT, /* Last; not a version */
}; };
......
/* SPDX-License-Identifier: GPL-2.0 */
/* *Copyright (C) 2022-2023 Linaro Ltd. */
#ifndef _REG_H_
#define _REG_H_
#include <linux/types.h>
#include <linux/bits.h>
/**
* 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];
}
/* 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;
}
/* 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;
}
#endif /* _REG_H_ */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment