mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-03 15:47:36 +00:00
net: mscc: ocelot: refactor enum ocelot_reg decoding to helper
ocelot_io.c duplicates the decoding of an enum ocelot_reg (which holds an enum ocelot_target in the upper bits and an index into a regmap array in the lower bits) 4 times. We'd like to reuse that logic once more, from ocelot.c. In order to do that, let's consolidate the existing 4 instances into a header accessible both by ocelot.c as well as by ocelot_io.c. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Reviewed-by: Jacob Keller <jacob.e.keller@intel.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
9ecd05794b
commit
40cd07cb42
2 changed files with 25 additions and 14 deletions
|
@ -74,6 +74,15 @@ struct ocelot_multicast {
|
||||||
struct ocelot_pgid *pgid;
|
struct ocelot_pgid *pgid;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static inline void ocelot_reg_to_target_addr(struct ocelot *ocelot,
|
||||||
|
enum ocelot_reg reg,
|
||||||
|
enum ocelot_target *target,
|
||||||
|
u32 *addr)
|
||||||
|
{
|
||||||
|
*target = reg >> TARGET_OFFSET;
|
||||||
|
*addr = ocelot->map[*target][reg & REG_MASK];
|
||||||
|
}
|
||||||
|
|
||||||
int ocelot_bridge_num_find(struct ocelot *ocelot,
|
int ocelot_bridge_num_find(struct ocelot *ocelot,
|
||||||
const struct net_device *bridge);
|
const struct net_device *bridge);
|
||||||
|
|
||||||
|
|
|
@ -13,25 +13,26 @@
|
||||||
int __ocelot_bulk_read_ix(struct ocelot *ocelot, enum ocelot_reg reg,
|
int __ocelot_bulk_read_ix(struct ocelot *ocelot, enum ocelot_reg reg,
|
||||||
u32 offset, void *buf, int count)
|
u32 offset, void *buf, int count)
|
||||||
{
|
{
|
||||||
u16 target = reg >> TARGET_OFFSET;
|
enum ocelot_target target;
|
||||||
|
u32 addr;
|
||||||
|
|
||||||
|
ocelot_reg_to_target_addr(ocelot, reg, &target, &addr);
|
||||||
WARN_ON(!target);
|
WARN_ON(!target);
|
||||||
|
|
||||||
return regmap_bulk_read(ocelot->targets[target],
|
return regmap_bulk_read(ocelot->targets[target], addr + offset,
|
||||||
ocelot->map[target][reg & REG_MASK] + offset,
|
|
||||||
buf, count);
|
buf, count);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(__ocelot_bulk_read_ix);
|
EXPORT_SYMBOL_GPL(__ocelot_bulk_read_ix);
|
||||||
|
|
||||||
u32 __ocelot_read_ix(struct ocelot *ocelot, enum ocelot_reg reg, u32 offset)
|
u32 __ocelot_read_ix(struct ocelot *ocelot, enum ocelot_reg reg, u32 offset)
|
||||||
{
|
{
|
||||||
u16 target = reg >> TARGET_OFFSET;
|
enum ocelot_target target;
|
||||||
u32 val;
|
u32 addr, val;
|
||||||
|
|
||||||
|
ocelot_reg_to_target_addr(ocelot, reg, &target, &addr);
|
||||||
WARN_ON(!target);
|
WARN_ON(!target);
|
||||||
|
|
||||||
regmap_read(ocelot->targets[target],
|
regmap_read(ocelot->targets[target], addr + offset, &val);
|
||||||
ocelot->map[target][reg & REG_MASK] + offset, &val);
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(__ocelot_read_ix);
|
EXPORT_SYMBOL_GPL(__ocelot_read_ix);
|
||||||
|
@ -39,25 +40,26 @@ EXPORT_SYMBOL_GPL(__ocelot_read_ix);
|
||||||
void __ocelot_write_ix(struct ocelot *ocelot, u32 val, enum ocelot_reg reg,
|
void __ocelot_write_ix(struct ocelot *ocelot, u32 val, enum ocelot_reg reg,
|
||||||
u32 offset)
|
u32 offset)
|
||||||
{
|
{
|
||||||
u16 target = reg >> TARGET_OFFSET;
|
enum ocelot_target target;
|
||||||
|
u32 addr;
|
||||||
|
|
||||||
|
ocelot_reg_to_target_addr(ocelot, reg, &target, &addr);
|
||||||
WARN_ON(!target);
|
WARN_ON(!target);
|
||||||
|
|
||||||
regmap_write(ocelot->targets[target],
|
regmap_write(ocelot->targets[target], addr + offset, val);
|
||||||
ocelot->map[target][reg & REG_MASK] + offset, val);
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(__ocelot_write_ix);
|
EXPORT_SYMBOL_GPL(__ocelot_write_ix);
|
||||||
|
|
||||||
void __ocelot_rmw_ix(struct ocelot *ocelot, u32 val, u32 mask,
|
void __ocelot_rmw_ix(struct ocelot *ocelot, u32 val, u32 mask,
|
||||||
enum ocelot_reg reg, u32 offset)
|
enum ocelot_reg reg, u32 offset)
|
||||||
{
|
{
|
||||||
u16 target = reg >> TARGET_OFFSET;
|
enum ocelot_target target;
|
||||||
|
u32 addr;
|
||||||
|
|
||||||
|
ocelot_reg_to_target_addr(ocelot, reg, &target, &addr);
|
||||||
WARN_ON(!target);
|
WARN_ON(!target);
|
||||||
|
|
||||||
regmap_update_bits(ocelot->targets[target],
|
regmap_update_bits(ocelot->targets[target], addr + offset, mask, val);
|
||||||
ocelot->map[target][reg & REG_MASK] + offset,
|
|
||||||
mask, val);
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(__ocelot_rmw_ix);
|
EXPORT_SYMBOL_GPL(__ocelot_rmw_ix);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue