Commit 34e48383 authored by Arun Ramadoss's avatar Arun Ramadoss Committed by David S. Miller

net: dsa: microchip: move ksz8->shifts to ksz_common

This patch moves ksz8->shifts from ksz8795.c to ksz_common.c. The shifts
are dereferenced using dev->info->shifts.
Signed-off-by: default avatarArun Ramadoss <arun.ramadoss@microchip.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d23a5e18
...@@ -12,20 +12,7 @@ ...@@ -12,20 +12,7 @@
#include <net/dsa.h> #include <net/dsa.h>
#include "ksz_common.h" #include "ksz_common.h"
enum ksz_shifts {
VLAN_TABLE_MEMBERSHIP_S,
VLAN_TABLE,
STATIC_MAC_FWD_PORTS,
STATIC_MAC_FID,
DYNAMIC_MAC_ENTRIES_H,
DYNAMIC_MAC_ENTRIES,
DYNAMIC_MAC_FID,
DYNAMIC_MAC_TIMESTAMP,
DYNAMIC_MAC_SRC_PORT,
};
struct ksz8 { struct ksz8 {
const u8 *shifts;
void *priv; void *priv;
}; };
......
...@@ -26,29 +26,6 @@ ...@@ -26,29 +26,6 @@
#include "ksz8795_reg.h" #include "ksz8795_reg.h"
#include "ksz8.h" #include "ksz8.h"
static const u8 ksz8795_shifts[] = {
[VLAN_TABLE_MEMBERSHIP_S] = 7,
[VLAN_TABLE] = 16,
[STATIC_MAC_FWD_PORTS] = 16,
[STATIC_MAC_FID] = 24,
[DYNAMIC_MAC_ENTRIES_H] = 3,
[DYNAMIC_MAC_ENTRIES] = 29,
[DYNAMIC_MAC_FID] = 16,
[DYNAMIC_MAC_TIMESTAMP] = 27,
[DYNAMIC_MAC_SRC_PORT] = 24,
};
static u8 ksz8863_shifts[] = {
[VLAN_TABLE_MEMBERSHIP_S] = 16,
[STATIC_MAC_FWD_PORTS] = 16,
[STATIC_MAC_FID] = 22,
[DYNAMIC_MAC_ENTRIES_H] = 3,
[DYNAMIC_MAC_ENTRIES] = 24,
[DYNAMIC_MAC_FID] = 16,
[DYNAMIC_MAC_TIMESTAMP] = 24,
[DYNAMIC_MAC_SRC_PORT] = 20,
};
static bool ksz_is_ksz88x3(struct ksz_device *dev) static bool ksz_is_ksz88x3(struct ksz_device *dev)
{ {
return dev->chip_id == 0x8830; return dev->chip_id == 0x8830;
...@@ -374,7 +351,6 @@ static int ksz8_valid_dyn_entry(struct ksz_device *dev, u8 *data) ...@@ -374,7 +351,6 @@ static int ksz8_valid_dyn_entry(struct ksz_device *dev, u8 *data)
int ksz8_r_dyn_mac_table(struct ksz_device *dev, u16 addr, u8 *mac_addr, int ksz8_r_dyn_mac_table(struct ksz_device *dev, u16 addr, u8 *mac_addr,
u8 *fid, u8 *src_port, u8 *timestamp, u16 *entries) u8 *fid, u8 *src_port, u8 *timestamp, u16 *entries)
{ {
struct ksz8 *ksz8 = dev->priv;
u32 data_hi, data_lo; u32 data_hi, data_lo;
const u8 *shifts; const u8 *shifts;
const u32 *masks; const u32 *masks;
...@@ -383,7 +359,7 @@ int ksz8_r_dyn_mac_table(struct ksz_device *dev, u16 addr, u8 *mac_addr, ...@@ -383,7 +359,7 @@ int ksz8_r_dyn_mac_table(struct ksz_device *dev, u16 addr, u8 *mac_addr,
u8 data; u8 data;
int rc; int rc;
shifts = ksz8->shifts; shifts = dev->info->shifts;
masks = dev->info->masks; masks = dev->info->masks;
regs = dev->info->regs; regs = dev->info->regs;
...@@ -438,13 +414,12 @@ int ksz8_r_dyn_mac_table(struct ksz_device *dev, u16 addr, u8 *mac_addr, ...@@ -438,13 +414,12 @@ int ksz8_r_dyn_mac_table(struct ksz_device *dev, u16 addr, u8 *mac_addr,
int ksz8_r_sta_mac_table(struct ksz_device *dev, u16 addr, int ksz8_r_sta_mac_table(struct ksz_device *dev, u16 addr,
struct alu_struct *alu) struct alu_struct *alu)
{ {
struct ksz8 *ksz8 = dev->priv;
u32 data_hi, data_lo; u32 data_hi, data_lo;
const u8 *shifts; const u8 *shifts;
const u32 *masks; const u32 *masks;
u64 data; u64 data;
shifts = ksz8->shifts; shifts = dev->info->shifts;
masks = dev->info->masks; masks = dev->info->masks;
ksz8_r_table(dev, TABLE_STATIC_MAC, addr, &data); ksz8_r_table(dev, TABLE_STATIC_MAC, addr, &data);
...@@ -477,13 +452,12 @@ int ksz8_r_sta_mac_table(struct ksz_device *dev, u16 addr, ...@@ -477,13 +452,12 @@ int ksz8_r_sta_mac_table(struct ksz_device *dev, u16 addr,
void ksz8_w_sta_mac_table(struct ksz_device *dev, u16 addr, void ksz8_w_sta_mac_table(struct ksz_device *dev, u16 addr,
struct alu_struct *alu) struct alu_struct *alu)
{ {
struct ksz8 *ksz8 = dev->priv;
u32 data_hi, data_lo; u32 data_hi, data_lo;
const u8 *shifts; const u8 *shifts;
const u32 *masks; const u32 *masks;
u64 data; u64 data;
shifts = ksz8->shifts; shifts = dev->info->shifts;
masks = dev->info->masks; masks = dev->info->masks;
data_lo = ((u32)alu->mac[2] << 24) | data_lo = ((u32)alu->mac[2] << 24) |
...@@ -510,11 +484,10 @@ void ksz8_w_sta_mac_table(struct ksz_device *dev, u16 addr, ...@@ -510,11 +484,10 @@ void ksz8_w_sta_mac_table(struct ksz_device *dev, u16 addr,
static void ksz8_from_vlan(struct ksz_device *dev, u32 vlan, u8 *fid, static void ksz8_from_vlan(struct ksz_device *dev, u32 vlan, u8 *fid,
u8 *member, u8 *valid) u8 *member, u8 *valid)
{ {
struct ksz8 *ksz8 = dev->priv;
const u8 *shifts; const u8 *shifts;
const u32 *masks; const u32 *masks;
shifts = ksz8->shifts; shifts = dev->info->shifts;
masks = dev->info->masks; masks = dev->info->masks;
*fid = vlan & masks[VLAN_TABLE_FID]; *fid = vlan & masks[VLAN_TABLE_FID];
...@@ -526,11 +499,10 @@ static void ksz8_from_vlan(struct ksz_device *dev, u32 vlan, u8 *fid, ...@@ -526,11 +499,10 @@ static void ksz8_from_vlan(struct ksz_device *dev, u32 vlan, u8 *fid,
static void ksz8_to_vlan(struct ksz_device *dev, u8 fid, u8 member, u8 valid, static void ksz8_to_vlan(struct ksz_device *dev, u8 fid, u8 member, u8 valid,
u16 *vlan) u16 *vlan)
{ {
struct ksz8 *ksz8 = dev->priv;
const u8 *shifts; const u8 *shifts;
const u32 *masks; const u32 *masks;
shifts = ksz8->shifts; shifts = dev->info->shifts;
masks = dev->info->masks; masks = dev->info->masks;
*vlan = fid; *vlan = fid;
...@@ -541,12 +513,11 @@ static void ksz8_to_vlan(struct ksz_device *dev, u8 fid, u8 member, u8 valid, ...@@ -541,12 +513,11 @@ static void ksz8_to_vlan(struct ksz_device *dev, u8 fid, u8 member, u8 valid,
static void ksz8_r_vlan_entries(struct ksz_device *dev, u16 addr) static void ksz8_r_vlan_entries(struct ksz_device *dev, u16 addr)
{ {
struct ksz8 *ksz8 = dev->priv;
const u8 *shifts; const u8 *shifts;
u64 data; u64 data;
int i; int i;
shifts = ksz8->shifts; shifts = dev->info->shifts;
ksz8_r_table(dev, TABLE_VLAN, addr, &data); ksz8_r_table(dev, TABLE_VLAN, addr, &data);
addr *= 4; addr *= 4;
...@@ -1366,18 +1337,10 @@ u32 ksz8_get_port_addr(int port, int offset) ...@@ -1366,18 +1337,10 @@ u32 ksz8_get_port_addr(int port, int offset)
int ksz8_switch_init(struct ksz_device *dev) int ksz8_switch_init(struct ksz_device *dev)
{ {
struct ksz8 *ksz8 = dev->priv;
dev->cpu_port = fls(dev->info->cpu_ports) - 1; dev->cpu_port = fls(dev->info->cpu_ports) - 1;
dev->phy_port_cnt = dev->info->port_cnt - 1; dev->phy_port_cnt = dev->info->port_cnt - 1;
dev->port_mask = (BIT(dev->phy_port_cnt) - 1) | dev->info->cpu_ports; dev->port_mask = (BIT(dev->phy_port_cnt) - 1) | dev->info->cpu_ports;
if (ksz_is_ksz88x3(dev)) {
ksz8->shifts = ksz8863_shifts;
} else {
ksz8->shifts = ksz8795_shifts;
}
/* We rely on software untagging on the CPU port, so that we /* We rely on software untagging on the CPU port, so that we
* can support both tagged and untagged VLANs * can support both tagged and untagged VLANs
*/ */
......
...@@ -240,6 +240,18 @@ static const u32 ksz8795_masks[] = { ...@@ -240,6 +240,18 @@ static const u32 ksz8795_masks[] = {
[DYNAMIC_MAC_TABLE_TIMESTAMP] = GENMASK(28, 27), [DYNAMIC_MAC_TABLE_TIMESTAMP] = GENMASK(28, 27),
}; };
static const u8 ksz8795_shifts[] = {
[VLAN_TABLE_MEMBERSHIP_S] = 7,
[VLAN_TABLE] = 16,
[STATIC_MAC_FWD_PORTS] = 16,
[STATIC_MAC_FID] = 24,
[DYNAMIC_MAC_ENTRIES_H] = 3,
[DYNAMIC_MAC_ENTRIES] = 29,
[DYNAMIC_MAC_FID] = 16,
[DYNAMIC_MAC_TIMESTAMP] = 27,
[DYNAMIC_MAC_SRC_PORT] = 24,
};
static const u8 ksz8863_regs[] = { static const u8 ksz8863_regs[] = {
[REG_IND_CTRL_0] = 0x79, [REG_IND_CTRL_0] = 0x79,
[REG_IND_DATA_8] = 0x7B, [REG_IND_DATA_8] = 0x7B,
...@@ -278,6 +290,17 @@ static const u32 ksz8863_masks[] = { ...@@ -278,6 +290,17 @@ static const u32 ksz8863_masks[] = {
[DYNAMIC_MAC_TABLE_TIMESTAMP] = GENMASK(23, 22), [DYNAMIC_MAC_TABLE_TIMESTAMP] = GENMASK(23, 22),
}; };
static u8 ksz8863_shifts[] = {
[VLAN_TABLE_MEMBERSHIP_S] = 16,
[STATIC_MAC_FWD_PORTS] = 16,
[STATIC_MAC_FID] = 22,
[DYNAMIC_MAC_ENTRIES_H] = 3,
[DYNAMIC_MAC_ENTRIES] = 24,
[DYNAMIC_MAC_FID] = 16,
[DYNAMIC_MAC_TIMESTAMP] = 24,
[DYNAMIC_MAC_SRC_PORT] = 20,
};
const struct ksz_chip_data ksz_switch_chips[] = { const struct ksz_chip_data ksz_switch_chips[] = {
[KSZ8795] = { [KSZ8795] = {
.chip_id = KSZ8795_CHIP_ID, .chip_id = KSZ8795_CHIP_ID,
...@@ -294,6 +317,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { ...@@ -294,6 +317,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.reg_mib_cnt = MIB_COUNTER_NUM, .reg_mib_cnt = MIB_COUNTER_NUM,
.regs = ksz8795_regs, .regs = ksz8795_regs,
.masks = ksz8795_masks, .masks = ksz8795_masks,
.shifts = ksz8795_shifts,
.stp_ctrl_reg = 0x02, .stp_ctrl_reg = 0x02,
.broadcast_ctrl_reg = 0x06, .broadcast_ctrl_reg = 0x06,
.multicast_ctrl_reg = 0x04, .multicast_ctrl_reg = 0x04,
...@@ -333,6 +357,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { ...@@ -333,6 +357,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.reg_mib_cnt = MIB_COUNTER_NUM, .reg_mib_cnt = MIB_COUNTER_NUM,
.regs = ksz8795_regs, .regs = ksz8795_regs,
.masks = ksz8795_masks, .masks = ksz8795_masks,
.shifts = ksz8795_shifts,
.stp_ctrl_reg = 0x02, .stp_ctrl_reg = 0x02,
.broadcast_ctrl_reg = 0x06, .broadcast_ctrl_reg = 0x06,
.multicast_ctrl_reg = 0x04, .multicast_ctrl_reg = 0x04,
...@@ -358,6 +383,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { ...@@ -358,6 +383,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.reg_mib_cnt = MIB_COUNTER_NUM, .reg_mib_cnt = MIB_COUNTER_NUM,
.regs = ksz8795_regs, .regs = ksz8795_regs,
.masks = ksz8795_masks, .masks = ksz8795_masks,
.shifts = ksz8795_shifts,
.stp_ctrl_reg = 0x02, .stp_ctrl_reg = 0x02,
.broadcast_ctrl_reg = 0x06, .broadcast_ctrl_reg = 0x06,
.multicast_ctrl_reg = 0x04, .multicast_ctrl_reg = 0x04,
...@@ -382,6 +408,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { ...@@ -382,6 +408,7 @@ const struct ksz_chip_data ksz_switch_chips[] = {
.reg_mib_cnt = MIB_COUNTER_NUM, .reg_mib_cnt = MIB_COUNTER_NUM,
.regs = ksz8863_regs, .regs = ksz8863_regs,
.masks = ksz8863_masks, .masks = ksz8863_masks,
.shifts = ksz8863_shifts,
.stp_ctrl_reg = 0x02, .stp_ctrl_reg = 0x02,
.broadcast_ctrl_reg = 0x06, .broadcast_ctrl_reg = 0x06,
.multicast_ctrl_reg = 0x04, .multicast_ctrl_reg = 0x04,
......
...@@ -49,6 +49,7 @@ struct ksz_chip_data { ...@@ -49,6 +49,7 @@ struct ksz_chip_data {
u8 reg_mib_cnt; u8 reg_mib_cnt;
const u8 *regs; const u8 *regs;
const u32 *masks; const u32 *masks;
const u8 *shifts;
int stp_ctrl_reg; int stp_ctrl_reg;
int broadcast_ctrl_reg; int broadcast_ctrl_reg;
int multicast_ctrl_reg; int multicast_ctrl_reg;
...@@ -187,6 +188,18 @@ enum ksz_masks { ...@@ -187,6 +188,18 @@ enum ksz_masks {
DYNAMIC_MAC_TABLE_TIMESTAMP, DYNAMIC_MAC_TABLE_TIMESTAMP,
}; };
enum ksz_shifts {
VLAN_TABLE_MEMBERSHIP_S,
VLAN_TABLE,
STATIC_MAC_FWD_PORTS,
STATIC_MAC_FID,
DYNAMIC_MAC_ENTRIES_H,
DYNAMIC_MAC_ENTRIES,
DYNAMIC_MAC_FID,
DYNAMIC_MAC_TIMESTAMP,
DYNAMIC_MAC_SRC_PORT,
};
struct alu_struct { struct alu_struct {
/* entry 1 */ /* entry 1 */
u8 is_static:1; u8 is_static:1;
......
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