Commit 606f3993 authored by Ivan Khoronzhuk's avatar Ivan Khoronzhuk Committed by David S. Miller

net: ethernet: ti: cpsw: move platform data and slaves info to cpsw_common

These data are common for net devs in dual_emac mode. No need to hold
it for every priv instance, so move them under cpsw_common.
Signed-off-by: default avatarIvan Khoronzhuk <ivan.khoronzhuk@linaro.org>
Reviewed-by: default avatarMugunthan V N <mugunthanvnm@ti.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e38b5a3d
...@@ -140,9 +140,9 @@ do { \ ...@@ -140,9 +140,9 @@ do { \
#define CPSW_CMINTMAX_INTVL (1000 / CPSW_CMINTMIN_CNT) #define CPSW_CMINTMAX_INTVL (1000 / CPSW_CMINTMIN_CNT)
#define CPSW_CMINTMIN_INTVL ((1000 / CPSW_CMINTMAX_CNT) + 1) #define CPSW_CMINTMIN_INTVL ((1000 / CPSW_CMINTMAX_CNT) + 1)
#define cpsw_slave_index(priv) \ #define cpsw_slave_index(cpsw, priv) \
((priv->data.dual_emac) ? priv->emac_port : \ ((cpsw->data.dual_emac) ? priv->emac_port : \
priv->data.active_slave) cpsw->data.active_slave)
#define IRQ_NUM 2 #define IRQ_NUM 2
static int debug_level; static int debug_level;
...@@ -366,10 +366,12 @@ static inline void slave_write(struct cpsw_slave *slave, u32 val, u32 offset) ...@@ -366,10 +366,12 @@ static inline void slave_write(struct cpsw_slave *slave, u32 val, u32 offset)
struct cpsw_common { struct cpsw_common {
struct device *dev; struct device *dev;
struct cpsw_platform_data data;
struct cpsw_ss_regs __iomem *regs; struct cpsw_ss_regs __iomem *regs;
struct cpsw_wr_regs __iomem *wr_regs; struct cpsw_wr_regs __iomem *wr_regs;
u8 __iomem *hw_stats; u8 __iomem *hw_stats;
struct cpsw_host_regs __iomem *host_port_regs; struct cpsw_host_regs __iomem *host_port_regs;
struct cpsw_slave *slaves;
struct cpdma_ctlr *dma; struct cpdma_ctlr *dma;
struct cpdma_chan *txch, *rxch; struct cpdma_chan *txch, *rxch;
bool quirk_irq; bool quirk_irq;
...@@ -383,14 +385,12 @@ struct cpsw_priv { ...@@ -383,14 +385,12 @@ struct cpsw_priv {
struct napi_struct napi_rx; struct napi_struct napi_rx;
struct napi_struct napi_tx; struct napi_struct napi_tx;
struct device *dev; struct device *dev;
struct cpsw_platform_data data;
u32 msg_enable; u32 msg_enable;
u32 version; u32 version;
u32 coal_intvl; u32 coal_intvl;
u32 bus_freq_mhz; u32 bus_freq_mhz;
int rx_packet_max; int rx_packet_max;
u8 mac_addr[ETH_ALEN]; u8 mac_addr[ETH_ALEN];
struct cpsw_slave *slaves;
struct cpsw_ale *ale; struct cpsw_ale *ale;
bool rx_pause; bool rx_pause;
bool tx_pause; bool tx_pause;
...@@ -492,38 +492,39 @@ static const struct cpsw_stats cpsw_gstrings_stats[] = { ...@@ -492,38 +492,39 @@ static const struct cpsw_stats cpsw_gstrings_stats[] = {
#define for_each_slave(priv, func, arg...) \ #define for_each_slave(priv, func, arg...) \
do { \ do { \
struct cpsw_slave *slave; \ struct cpsw_slave *slave; \
struct cpsw_common *cpsw = (priv)->cpsw; \
int n; \ int n; \
if (priv->data.dual_emac) \ if (cpsw->data.dual_emac) \
(func)((priv)->slaves + priv->emac_port, ##arg);\ (func)((cpsw)->slaves + priv->emac_port, ##arg);\
else \ else \
for (n = (priv)->data.slaves, \ for (n = cpsw->data.slaves, \
slave = (priv)->slaves; \ slave = cpsw->slaves; \
n; n--) \ n; n--) \
(func)(slave++, ##arg); \ (func)(slave++, ##arg); \
} while (0) } while (0)
#define cpsw_get_slave_priv(priv, __slave_no__) \ #define cpsw_get_slave_priv(cpsw, __slave_no__) \
(((__slave_no__ < priv->data.slaves) && \ (((__slave_no__ < cpsw->data.slaves) && \
(priv->slaves[__slave_no__].ndev)) ? \ (cpsw->slaves[__slave_no__].ndev)) ? \
netdev_priv(priv->slaves[__slave_no__].ndev) : NULL) \ netdev_priv(cpsw->slaves[__slave_no__].ndev) : NULL) \
#define cpsw_dual_emac_src_port_detect(status, priv, ndev, skb) \ #define cpsw_dual_emac_src_port_detect(cpsw, status, priv, ndev, skb) \
do { \ do { \
if (!priv->data.dual_emac) \ if (!cpsw->data.dual_emac) \
break; \ break; \
if (CPDMA_RX_SOURCE_PORT(status) == 1) { \ if (CPDMA_RX_SOURCE_PORT(status) == 1) { \
ndev = priv->slaves[0].ndev; \ ndev = cpsw->slaves[0].ndev; \
priv = netdev_priv(ndev); \ priv = netdev_priv(ndev); \
skb->dev = ndev; \ skb->dev = ndev; \
} else if (CPDMA_RX_SOURCE_PORT(status) == 2) { \ } else if (CPDMA_RX_SOURCE_PORT(status) == 2) { \
ndev = priv->slaves[1].ndev; \ ndev = cpsw->slaves[1].ndev; \
priv = netdev_priv(ndev); \ priv = netdev_priv(ndev); \
skb->dev = ndev; \ skb->dev = ndev; \
} \ } \
} while (0) } while (0)
#define cpsw_add_mcast(priv, addr) \ #define cpsw_add_mcast(cpsw, priv, addr) \
do { \ do { \
if (priv->data.dual_emac) { \ if (cpsw->data.dual_emac) { \
struct cpsw_slave *slave = priv->slaves + \ struct cpsw_slave *slave = cpsw->slaves + \
priv->emac_port; \ priv->emac_port; \
int slave_port = cpsw_get_slave_port( \ int slave_port = cpsw_get_slave_port( \
slave->slave_num); \ slave->slave_num); \
...@@ -545,18 +546,19 @@ static inline int cpsw_get_slave_port(u32 slave_num) ...@@ -545,18 +546,19 @@ static inline int cpsw_get_slave_port(u32 slave_num)
static void cpsw_set_promiscious(struct net_device *ndev, bool enable) static void cpsw_set_promiscious(struct net_device *ndev, bool enable)
{ {
struct cpsw_priv *priv = netdev_priv(ndev); struct cpsw_priv *priv = netdev_priv(ndev);
struct cpsw_common *cpsw = priv->cpsw;
struct cpsw_ale *ale = priv->ale; struct cpsw_ale *ale = priv->ale;
int i; int i;
if (priv->data.dual_emac) { if (cpsw->data.dual_emac) {
bool flag = false; bool flag = false;
/* Enabling promiscuous mode for one interface will be /* Enabling promiscuous mode for one interface will be
* common for both the interface as the interface shares * common for both the interface as the interface shares
* the same hardware resource. * the same hardware resource.
*/ */
for (i = 0; i < priv->data.slaves; i++) for (i = 0; i < cpsw->data.slaves; i++)
if (priv->slaves[i].ndev->flags & IFF_PROMISC) if (cpsw->slaves[i].ndev->flags & IFF_PROMISC)
flag = true; flag = true;
if (!enable && flag) { if (!enable && flag) {
...@@ -579,7 +581,7 @@ static void cpsw_set_promiscious(struct net_device *ndev, bool enable) ...@@ -579,7 +581,7 @@ static void cpsw_set_promiscious(struct net_device *ndev, bool enable)
unsigned long timeout = jiffies + HZ; unsigned long timeout = jiffies + HZ;
/* Disable Learn for all ports (host is port 0 and slaves are port 1 and up */ /* Disable Learn for all ports (host is port 0 and slaves are port 1 and up */
for (i = 0; i <= priv->data.slaves; i++) { for (i = 0; i <= cpsw->data.slaves; i++) {
cpsw_ale_control_set(ale, i, cpsw_ale_control_set(ale, i,
ALE_PORT_NOLEARN, 1); ALE_PORT_NOLEARN, 1);
cpsw_ale_control_set(ale, i, cpsw_ale_control_set(ale, i,
...@@ -606,7 +608,7 @@ static void cpsw_set_promiscious(struct net_device *ndev, bool enable) ...@@ -606,7 +608,7 @@ static void cpsw_set_promiscious(struct net_device *ndev, bool enable)
cpsw_ale_control_set(ale, 0, ALE_P0_UNI_FLOOD, 0); cpsw_ale_control_set(ale, 0, ALE_P0_UNI_FLOOD, 0);
/* Enable Learn for all ports (host is port 0 and slaves are port 1 and up */ /* Enable Learn for all ports (host is port 0 and slaves are port 1 and up */
for (i = 0; i <= priv->data.slaves; i++) { for (i = 0; i <= cpsw->data.slaves; i++) {
cpsw_ale_control_set(ale, i, cpsw_ale_control_set(ale, i,
ALE_PORT_NOLEARN, 0); ALE_PORT_NOLEARN, 0);
cpsw_ale_control_set(ale, i, cpsw_ale_control_set(ale, i,
...@@ -620,12 +622,13 @@ static void cpsw_set_promiscious(struct net_device *ndev, bool enable) ...@@ -620,12 +622,13 @@ static void cpsw_set_promiscious(struct net_device *ndev, bool enable)
static void cpsw_ndo_set_rx_mode(struct net_device *ndev) static void cpsw_ndo_set_rx_mode(struct net_device *ndev)
{ {
struct cpsw_priv *priv = netdev_priv(ndev); struct cpsw_priv *priv = netdev_priv(ndev);
struct cpsw_common *cpsw = priv->cpsw;
int vid; int vid;
if (priv->data.dual_emac) if (cpsw->data.dual_emac)
vid = priv->slaves[priv->emac_port].port_vlan; vid = cpsw->slaves[priv->emac_port].port_vlan;
else else
vid = priv->data.default_vlan; vid = cpsw->data.default_vlan;
if (ndev->flags & IFF_PROMISC) { if (ndev->flags & IFF_PROMISC) {
/* Enable promiscuous mode */ /* Enable promiscuous mode */
...@@ -648,7 +651,7 @@ static void cpsw_ndo_set_rx_mode(struct net_device *ndev) ...@@ -648,7 +651,7 @@ static void cpsw_ndo_set_rx_mode(struct net_device *ndev)
/* program multicast address list into ALE register */ /* program multicast address list into ALE register */
netdev_for_each_mc_addr(ha, ndev) { netdev_for_each_mc_addr(ha, ndev) {
cpsw_add_mcast(priv, (u8 *)ha->addr); cpsw_add_mcast(cpsw, priv, (u8 *)ha->addr);
} }
} }
} }
...@@ -697,16 +700,16 @@ static void cpsw_rx_handler(void *token, int len, int status) ...@@ -697,16 +700,16 @@ static void cpsw_rx_handler(void *token, int len, int status)
int ret = 0; int ret = 0;
struct cpsw_common *cpsw = priv->cpsw; struct cpsw_common *cpsw = priv->cpsw;
cpsw_dual_emac_src_port_detect(status, priv, ndev, skb); cpsw_dual_emac_src_port_detect(cpsw, status, priv, ndev, skb);
if (unlikely(status < 0) || unlikely(!netif_running(ndev))) { if (unlikely(status < 0) || unlikely(!netif_running(ndev))) {
bool ndev_status = false; bool ndev_status = false;
struct cpsw_slave *slave = priv->slaves; struct cpsw_slave *slave = cpsw->slaves;
int n; int n;
if (priv->data.dual_emac) { if (cpsw->data.dual_emac) {
/* In dual emac mode check for all interfaces */ /* In dual emac mode check for all interfaces */
for (n = priv->data.slaves; n; n--, slave++) for (n = cpsw->data.slaves; n; n--, slave++)
if (netif_running(slave->ndev)) if (netif_running(slave->ndev))
ndev_status = true; ndev_status = true;
} }
...@@ -848,6 +851,7 @@ static void _cpsw_adjust_link(struct cpsw_slave *slave, ...@@ -848,6 +851,7 @@ static void _cpsw_adjust_link(struct cpsw_slave *slave,
struct phy_device *phy = slave->phy; struct phy_device *phy = slave->phy;
u32 mac_control = 0; u32 mac_control = 0;
u32 slave_port; u32 slave_port;
struct cpsw_common *cpsw = priv->cpsw;
if (!phy) if (!phy)
return; return;
...@@ -855,7 +859,7 @@ static void _cpsw_adjust_link(struct cpsw_slave *slave, ...@@ -855,7 +859,7 @@ static void _cpsw_adjust_link(struct cpsw_slave *slave,
slave_port = cpsw_get_slave_port(slave->slave_num); slave_port = cpsw_get_slave_port(slave->slave_num);
if (phy->link) { if (phy->link) {
mac_control = priv->data.mac_control; mac_control = cpsw->data.mac_control;
/* enable forwarding */ /* enable forwarding */
cpsw_ale_control_set(priv->ale, slave_port, cpsw_ale_control_set(priv->ale, slave_port,
...@@ -973,11 +977,11 @@ static int cpsw_set_coalesce(struct net_device *ndev, ...@@ -973,11 +977,11 @@ static int cpsw_set_coalesce(struct net_device *ndev,
writel(int_ctrl, &cpsw->wr_regs->int_control); writel(int_ctrl, &cpsw->wr_regs->int_control);
cpsw_notice(priv, timer, "Set coalesce to %d usecs.\n", coal_intvl); cpsw_notice(priv, timer, "Set coalesce to %d usecs.\n", coal_intvl);
if (priv->data.dual_emac) { if (cpsw->data.dual_emac) {
int i; int i;
for (i = 0; i < priv->data.slaves; i++) { for (i = 0; i < cpsw->data.slaves; i++) {
priv = netdev_priv(priv->slaves[i].ndev); priv = netdev_priv(cpsw->slaves[i].ndev);
priv->coal_intvl = coal_intvl; priv->coal_intvl = coal_intvl;
} }
} else { } else {
...@@ -1050,16 +1054,16 @@ static void cpsw_get_ethtool_stats(struct net_device *ndev, ...@@ -1050,16 +1054,16 @@ static void cpsw_get_ethtool_stats(struct net_device *ndev,
} }
} }
static int cpsw_common_res_usage_state(struct cpsw_priv *priv) static int cpsw_common_res_usage_state(struct cpsw_common *cpsw)
{ {
u32 i; u32 i;
u32 usage_count = 0; u32 usage_count = 0;
if (!priv->data.dual_emac) if (!cpsw->data.dual_emac)
return 0; return 0;
for (i = 0; i < priv->data.slaves; i++) for (i = 0; i < cpsw->data.slaves; i++)
if (priv->slaves[i].open_stat) if (cpsw->slaves[i].open_stat)
usage_count++; usage_count++;
return usage_count; return usage_count;
...@@ -1071,7 +1075,7 @@ static inline int cpsw_tx_packet_submit(struct cpsw_priv *priv, ...@@ -1071,7 +1075,7 @@ static inline int cpsw_tx_packet_submit(struct cpsw_priv *priv,
struct cpsw_common *cpsw = priv->cpsw; struct cpsw_common *cpsw = priv->cpsw;
return cpdma_chan_submit(cpsw->txch, skb, skb->data, skb->len, return cpdma_chan_submit(cpsw->txch, skb, skb->data, skb->len,
priv->emac_port + priv->data.dual_emac); priv->emac_port + cpsw->data.dual_emac);
} }
static inline void cpsw_add_dual_emac_def_ale_entries( static inline void cpsw_add_dual_emac_def_ale_entries(
...@@ -1129,7 +1133,7 @@ static void cpsw_slave_open(struct cpsw_slave *slave, struct cpsw_priv *priv) ...@@ -1129,7 +1133,7 @@ static void cpsw_slave_open(struct cpsw_slave *slave, struct cpsw_priv *priv)
slave_port = cpsw_get_slave_port(slave->slave_num); slave_port = cpsw_get_slave_port(slave->slave_num);
if (priv->data.dual_emac) if (cpsw->data.dual_emac)
cpsw_add_dual_emac_def_ale_entries(priv, slave, slave_port); cpsw_add_dual_emac_def_ale_entries(priv, slave, slave_port);
else else
cpsw_ale_add_mcast(priv->ale, priv->ndev->broadcast, cpsw_ale_add_mcast(priv->ale, priv->ndev->broadcast,
...@@ -1167,19 +1171,19 @@ static void cpsw_slave_open(struct cpsw_slave *slave, struct cpsw_priv *priv) ...@@ -1167,19 +1171,19 @@ static void cpsw_slave_open(struct cpsw_slave *slave, struct cpsw_priv *priv)
static inline void cpsw_add_default_vlan(struct cpsw_priv *priv) static inline void cpsw_add_default_vlan(struct cpsw_priv *priv)
{ {
const int vlan = priv->data.default_vlan; struct cpsw_common *cpsw = priv->cpsw;
const int vlan = cpsw->data.default_vlan;
u32 reg; u32 reg;
int i; int i;
int unreg_mcast_mask; int unreg_mcast_mask;
struct cpsw_common *cpsw = priv->cpsw;
reg = (priv->version == CPSW_VERSION_1) ? CPSW1_PORT_VLAN : reg = (priv->version == CPSW_VERSION_1) ? CPSW1_PORT_VLAN :
CPSW2_PORT_VLAN; CPSW2_PORT_VLAN;
writel(vlan, &cpsw->host_port_regs->port_vlan); writel(vlan, &cpsw->host_port_regs->port_vlan);
for (i = 0; i < priv->data.slaves; i++) for (i = 0; i < cpsw->data.slaves; i++)
slave_write(priv->slaves + i, vlan, reg); slave_write(cpsw->slaves + i, vlan, reg);
if (priv->ndev->flags & IFF_ALLMULTI) if (priv->ndev->flags & IFF_ALLMULTI)
unreg_mcast_mask = ALE_ALL_PORTS; unreg_mcast_mask = ALE_ALL_PORTS;
...@@ -1207,7 +1211,7 @@ static void cpsw_init_host_port(struct cpsw_priv *priv) ...@@ -1207,7 +1211,7 @@ static void cpsw_init_host_port(struct cpsw_priv *priv)
control_reg = readl(&cpsw->regs->control); control_reg = readl(&cpsw->regs->control);
control_reg |= CPSW_VLAN_AWARE; control_reg |= CPSW_VLAN_AWARE;
writel(control_reg, &cpsw->regs->control); writel(control_reg, &cpsw->regs->control);
fifo_mode = (priv->data.dual_emac) ? CPSW_FIFO_DUAL_MAC_MODE : fifo_mode = (cpsw->data.dual_emac) ? CPSW_FIFO_DUAL_MAC_MODE :
CPSW_FIFO_NORMAL_MODE; CPSW_FIFO_NORMAL_MODE;
writel(fifo_mode, &cpsw->host_port_regs->tx_in_ctl); writel(fifo_mode, &cpsw->host_port_regs->tx_in_ctl);
...@@ -1219,7 +1223,7 @@ static void cpsw_init_host_port(struct cpsw_priv *priv) ...@@ -1219,7 +1223,7 @@ static void cpsw_init_host_port(struct cpsw_priv *priv)
cpsw_ale_control_set(priv->ale, HOST_PORT_NUM, cpsw_ale_control_set(priv->ale, HOST_PORT_NUM,
ALE_PORT_STATE, ALE_PORT_STATE_FORWARD); ALE_PORT_STATE, ALE_PORT_STATE_FORWARD);
if (!priv->data.dual_emac) { if (!cpsw->data.dual_emac) {
cpsw_ale_add_ucast(priv->ale, priv->mac_addr, HOST_PORT_NUM, cpsw_ale_add_ucast(priv->ale, priv->mac_addr, HOST_PORT_NUM,
0, 0); 0, 0);
cpsw_ale_add_mcast(priv->ale, priv->ndev->broadcast, cpsw_ale_add_mcast(priv->ale, priv->ndev->broadcast,
...@@ -1256,7 +1260,7 @@ static int cpsw_ndo_open(struct net_device *ndev) ...@@ -1256,7 +1260,7 @@ static int cpsw_ndo_open(struct net_device *ndev)
return ret; return ret;
} }
if (!cpsw_common_res_usage_state(priv)) if (!cpsw_common_res_usage_state(cpsw))
cpsw_intr_disable(cpsw); cpsw_intr_disable(cpsw);
netif_carrier_off(ndev); netif_carrier_off(ndev);
...@@ -1267,19 +1271,19 @@ static int cpsw_ndo_open(struct net_device *ndev) ...@@ -1267,19 +1271,19 @@ static int cpsw_ndo_open(struct net_device *ndev)
CPSW_RTL_VERSION(reg)); CPSW_RTL_VERSION(reg));
/* initialize host and slave ports */ /* initialize host and slave ports */
if (!cpsw_common_res_usage_state(priv)) if (!cpsw_common_res_usage_state(cpsw))
cpsw_init_host_port(priv); cpsw_init_host_port(priv);
for_each_slave(priv, cpsw_slave_open, priv); for_each_slave(priv, cpsw_slave_open, priv);
/* Add default VLAN */ /* Add default VLAN */
if (!priv->data.dual_emac) if (!cpsw->data.dual_emac)
cpsw_add_default_vlan(priv); cpsw_add_default_vlan(priv);
else else
cpsw_ale_add_vlan(priv->ale, priv->data.default_vlan, cpsw_ale_add_vlan(priv->ale, cpsw->data.default_vlan,
ALE_ALL_PORTS, ALE_ALL_PORTS, 0, 0); ALE_ALL_PORTS, ALE_ALL_PORTS, 0, 0);
if (!cpsw_common_res_usage_state(priv)) { if (!cpsw_common_res_usage_state(cpsw)) {
struct cpsw_priv *priv_sl0 = cpsw_get_slave_priv(priv, 0); struct cpsw_priv *priv_sl0 = cpsw_get_slave_priv(cpsw, 0);
int buf_num; int buf_num;
/* setup tx dma to fixed prio and zero offset */ /* setup tx dma to fixed prio and zero offset */
...@@ -1330,8 +1334,8 @@ static int cpsw_ndo_open(struct net_device *ndev) ...@@ -1330,8 +1334,8 @@ static int cpsw_ndo_open(struct net_device *ndev)
cpsw_info(priv, ifup, "submitted %d rx descriptors\n", i); cpsw_info(priv, ifup, "submitted %d rx descriptors\n", i);
if (cpts_register(cpsw->dev, priv->cpts, if (cpts_register(cpsw->dev, priv->cpts,
priv->data.cpts_clock_mult, cpsw->data.cpts_clock_mult,
priv->data.cpts_clock_shift)) cpsw->data.cpts_clock_shift))
dev_err(priv->dev, "error registering cpts device\n"); dev_err(priv->dev, "error registering cpts device\n");
} }
...@@ -1347,8 +1351,8 @@ static int cpsw_ndo_open(struct net_device *ndev) ...@@ -1347,8 +1351,8 @@ static int cpsw_ndo_open(struct net_device *ndev)
cpdma_ctlr_start(cpsw->dma); cpdma_ctlr_start(cpsw->dma);
cpsw_intr_enable(cpsw); cpsw_intr_enable(cpsw);
if (priv->data.dual_emac) if (cpsw->data.dual_emac)
priv->slaves[priv->emac_port].open_stat = true; cpsw->slaves[priv->emac_port].open_stat = true;
return 0; return 0;
err_cleanup: err_cleanup:
...@@ -1368,8 +1372,8 @@ static int cpsw_ndo_stop(struct net_device *ndev) ...@@ -1368,8 +1372,8 @@ static int cpsw_ndo_stop(struct net_device *ndev)
netif_stop_queue(priv->ndev); netif_stop_queue(priv->ndev);
netif_carrier_off(priv->ndev); netif_carrier_off(priv->ndev);
if (cpsw_common_res_usage_state(priv) <= 1) { if (cpsw_common_res_usage_state(cpsw) <= 1) {
struct cpsw_priv *priv_sl0 = cpsw_get_slave_priv(priv, 0); struct cpsw_priv *priv_sl0 = cpsw_get_slave_priv(cpsw, 0);
napi_disable(&priv_sl0->napi_rx); napi_disable(&priv_sl0->napi_rx);
napi_disable(&priv_sl0->napi_tx); napi_disable(&priv_sl0->napi_tx);
...@@ -1380,8 +1384,8 @@ static int cpsw_ndo_stop(struct net_device *ndev) ...@@ -1380,8 +1384,8 @@ static int cpsw_ndo_stop(struct net_device *ndev)
} }
for_each_slave(priv, cpsw_slave_stop, priv); for_each_slave(priv, cpsw_slave_stop, priv);
pm_runtime_put_sync(cpsw->dev); pm_runtime_put_sync(cpsw->dev);
if (priv->data.dual_emac) if (cpsw->data.dual_emac)
priv->slaves[priv->emac_port].open_stat = false; cpsw->slaves[priv->emac_port].open_stat = false;
return 0; return 0;
} }
...@@ -1429,7 +1433,8 @@ static netdev_tx_t cpsw_ndo_start_xmit(struct sk_buff *skb, ...@@ -1429,7 +1433,8 @@ static netdev_tx_t cpsw_ndo_start_xmit(struct sk_buff *skb,
static void cpsw_hwtstamp_v1(struct cpsw_priv *priv) static void cpsw_hwtstamp_v1(struct cpsw_priv *priv)
{ {
struct cpsw_slave *slave = &priv->slaves[priv->data.active_slave]; struct cpsw_common *cpsw = priv->cpsw;
struct cpsw_slave *slave = &cpsw->slaves[cpsw->data.active_slave];
u32 ts_en, seq_id; u32 ts_en, seq_id;
if (!priv->cpts->tx_enable && !priv->cpts->rx_enable) { if (!priv->cpts->tx_enable && !priv->cpts->rx_enable) {
...@@ -1456,10 +1461,10 @@ static void cpsw_hwtstamp_v2(struct cpsw_priv *priv) ...@@ -1456,10 +1461,10 @@ static void cpsw_hwtstamp_v2(struct cpsw_priv *priv)
struct cpsw_common *cpsw = priv->cpsw; struct cpsw_common *cpsw = priv->cpsw;
u32 ctrl, mtype; u32 ctrl, mtype;
if (priv->data.dual_emac) if (cpsw->data.dual_emac)
slave = &priv->slaves[priv->emac_port]; slave = &cpsw->slaves[priv->emac_port];
else else
slave = &priv->slaves[priv->data.active_slave]; slave = &cpsw->slaves[cpsw->data.active_slave];
ctrl = slave_read(slave, CPSW2_CONTROL); ctrl = slave_read(slave, CPSW2_CONTROL);
switch (priv->version) { switch (priv->version) {
...@@ -1578,7 +1583,8 @@ static int cpsw_hwtstamp_get(struct net_device *dev, struct ifreq *ifr) ...@@ -1578,7 +1583,8 @@ static int cpsw_hwtstamp_get(struct net_device *dev, struct ifreq *ifr)
static int cpsw_ndo_ioctl(struct net_device *dev, struct ifreq *req, int cmd) static int cpsw_ndo_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
{ {
struct cpsw_priv *priv = netdev_priv(dev); struct cpsw_priv *priv = netdev_priv(dev);
int slave_no = cpsw_slave_index(priv); struct cpsw_common *cpsw = priv->cpsw;
int slave_no = cpsw_slave_index(cpsw, priv);
if (!netif_running(dev)) if (!netif_running(dev))
return -EINVAL; return -EINVAL;
...@@ -1592,9 +1598,9 @@ static int cpsw_ndo_ioctl(struct net_device *dev, struct ifreq *req, int cmd) ...@@ -1592,9 +1598,9 @@ static int cpsw_ndo_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
#endif #endif
} }
if (!priv->slaves[slave_no].phy) if (!cpsw->slaves[slave_no].phy)
return -EOPNOTSUPP; return -EOPNOTSUPP;
return phy_mii_ioctl(priv->slaves[slave_no].phy, req, cmd); return phy_mii_ioctl(cpsw->slaves[slave_no].phy, req, cmd);
} }
static void cpsw_ndo_tx_timeout(struct net_device *ndev) static void cpsw_ndo_tx_timeout(struct net_device *ndev)
...@@ -1628,8 +1634,8 @@ static int cpsw_ndo_set_mac_address(struct net_device *ndev, void *p) ...@@ -1628,8 +1634,8 @@ static int cpsw_ndo_set_mac_address(struct net_device *ndev, void *p)
return ret; return ret;
} }
if (priv->data.dual_emac) { if (cpsw->data.dual_emac) {
vid = priv->slaves[priv->emac_port].port_vlan; vid = cpsw->slaves[priv->emac_port].port_vlan;
flags = ALE_VLAN; flags = ALE_VLAN;
} }
...@@ -1666,8 +1672,9 @@ static inline int cpsw_add_vlan_ale_entry(struct cpsw_priv *priv, ...@@ -1666,8 +1672,9 @@ static inline int cpsw_add_vlan_ale_entry(struct cpsw_priv *priv,
int ret; int ret;
int unreg_mcast_mask = 0; int unreg_mcast_mask = 0;
u32 port_mask; u32 port_mask;
struct cpsw_common *cpsw = priv->cpsw;
if (priv->data.dual_emac) { if (cpsw->data.dual_emac) {
port_mask = (1 << (priv->emac_port + 1)) | ALE_PORT_HOST; port_mask = (1 << (priv->emac_port + 1)) | ALE_PORT_HOST;
if (priv->ndev->flags & IFF_ALLMULTI) if (priv->ndev->flags & IFF_ALLMULTI)
...@@ -1712,7 +1719,7 @@ static int cpsw_ndo_vlan_rx_add_vid(struct net_device *ndev, ...@@ -1712,7 +1719,7 @@ static int cpsw_ndo_vlan_rx_add_vid(struct net_device *ndev,
struct cpsw_common *cpsw = priv->cpsw; struct cpsw_common *cpsw = priv->cpsw;
int ret; int ret;
if (vid == priv->data.default_vlan) if (vid == cpsw->data.default_vlan)
return 0; return 0;
ret = pm_runtime_get_sync(cpsw->dev); ret = pm_runtime_get_sync(cpsw->dev);
...@@ -1721,15 +1728,15 @@ static int cpsw_ndo_vlan_rx_add_vid(struct net_device *ndev, ...@@ -1721,15 +1728,15 @@ static int cpsw_ndo_vlan_rx_add_vid(struct net_device *ndev,
return ret; return ret;
} }
if (priv->data.dual_emac) { if (cpsw->data.dual_emac) {
/* In dual EMAC, reserved VLAN id should not be used for /* In dual EMAC, reserved VLAN id should not be used for
* creating VLAN interfaces as this can break the dual * creating VLAN interfaces as this can break the dual
* EMAC port separation * EMAC port separation
*/ */
int i; int i;
for (i = 0; i < priv->data.slaves; i++) { for (i = 0; i < cpsw->data.slaves; i++) {
if (vid == priv->slaves[i].port_vlan) if (vid == cpsw->slaves[i].port_vlan)
return -EINVAL; return -EINVAL;
} }
} }
...@@ -1748,7 +1755,7 @@ static int cpsw_ndo_vlan_rx_kill_vid(struct net_device *ndev, ...@@ -1748,7 +1755,7 @@ static int cpsw_ndo_vlan_rx_kill_vid(struct net_device *ndev,
struct cpsw_common *cpsw = priv->cpsw; struct cpsw_common *cpsw = priv->cpsw;
int ret; int ret;
if (vid == priv->data.default_vlan) if (vid == cpsw->data.default_vlan)
return 0; return 0;
ret = pm_runtime_get_sync(cpsw->dev); ret = pm_runtime_get_sync(cpsw->dev);
...@@ -1757,11 +1764,11 @@ static int cpsw_ndo_vlan_rx_kill_vid(struct net_device *ndev, ...@@ -1757,11 +1764,11 @@ static int cpsw_ndo_vlan_rx_kill_vid(struct net_device *ndev,
return ret; return ret;
} }
if (priv->data.dual_emac) { if (cpsw->data.dual_emac) {
int i; int i;
for (i = 0; i < priv->data.slaves; i++) { for (i = 0; i < cpsw->data.slaves; i++) {
if (vid == priv->slaves[i].port_vlan) if (vid == cpsw->slaves[i].port_vlan)
return -EINVAL; return -EINVAL;
} }
} }
...@@ -1801,9 +1808,9 @@ static const struct net_device_ops cpsw_netdev_ops = { ...@@ -1801,9 +1808,9 @@ static const struct net_device_ops cpsw_netdev_ops = {
static int cpsw_get_regs_len(struct net_device *ndev) static int cpsw_get_regs_len(struct net_device *ndev)
{ {
struct cpsw_priv *priv = netdev_priv(ndev); struct cpsw_common *cpsw = ndev_to_cpsw(ndev);
return priv->data.ale_entries * ALE_ENTRY_WORDS * sizeof(u32); return cpsw->data.ale_entries * ALE_ENTRY_WORDS * sizeof(u32);
} }
static void cpsw_get_regs(struct net_device *ndev, static void cpsw_get_regs(struct net_device *ndev,
...@@ -1877,10 +1884,11 @@ static int cpsw_get_settings(struct net_device *ndev, ...@@ -1877,10 +1884,11 @@ static int cpsw_get_settings(struct net_device *ndev,
struct ethtool_cmd *ecmd) struct ethtool_cmd *ecmd)
{ {
struct cpsw_priv *priv = netdev_priv(ndev); struct cpsw_priv *priv = netdev_priv(ndev);
int slave_no = cpsw_slave_index(priv); struct cpsw_common *cpsw = priv->cpsw;
int slave_no = cpsw_slave_index(cpsw, priv);
if (priv->slaves[slave_no].phy) if (cpsw->slaves[slave_no].phy)
return phy_ethtool_gset(priv->slaves[slave_no].phy, ecmd); return phy_ethtool_gset(cpsw->slaves[slave_no].phy, ecmd);
else else
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
...@@ -1888,10 +1896,11 @@ static int cpsw_get_settings(struct net_device *ndev, ...@@ -1888,10 +1896,11 @@ static int cpsw_get_settings(struct net_device *ndev,
static int cpsw_set_settings(struct net_device *ndev, struct ethtool_cmd *ecmd) static int cpsw_set_settings(struct net_device *ndev, struct ethtool_cmd *ecmd)
{ {
struct cpsw_priv *priv = netdev_priv(ndev); struct cpsw_priv *priv = netdev_priv(ndev);
int slave_no = cpsw_slave_index(priv); struct cpsw_common *cpsw = priv->cpsw;
int slave_no = cpsw_slave_index(cpsw, priv);
if (priv->slaves[slave_no].phy) if (cpsw->slaves[slave_no].phy)
return phy_ethtool_sset(priv->slaves[slave_no].phy, ecmd); return phy_ethtool_sset(cpsw->slaves[slave_no].phy, ecmd);
else else
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
...@@ -1899,22 +1908,24 @@ static int cpsw_set_settings(struct net_device *ndev, struct ethtool_cmd *ecmd) ...@@ -1899,22 +1908,24 @@ static int cpsw_set_settings(struct net_device *ndev, struct ethtool_cmd *ecmd)
static void cpsw_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol) static void cpsw_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
{ {
struct cpsw_priv *priv = netdev_priv(ndev); struct cpsw_priv *priv = netdev_priv(ndev);
int slave_no = cpsw_slave_index(priv); struct cpsw_common *cpsw = priv->cpsw;
int slave_no = cpsw_slave_index(cpsw, priv);
wol->supported = 0; wol->supported = 0;
wol->wolopts = 0; wol->wolopts = 0;
if (priv->slaves[slave_no].phy) if (cpsw->slaves[slave_no].phy)
phy_ethtool_get_wol(priv->slaves[slave_no].phy, wol); phy_ethtool_get_wol(cpsw->slaves[slave_no].phy, wol);
} }
static int cpsw_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol) static int cpsw_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
{ {
struct cpsw_priv *priv = netdev_priv(ndev); struct cpsw_priv *priv = netdev_priv(ndev);
int slave_no = cpsw_slave_index(priv); struct cpsw_common *cpsw = priv->cpsw;
int slave_no = cpsw_slave_index(cpsw, priv);
if (priv->slaves[slave_no].phy) if (cpsw->slaves[slave_no].phy)
return phy_ethtool_set_wol(priv->slaves[slave_no].phy, wol); return phy_ethtool_set_wol(cpsw->slaves[slave_no].phy, wol);
else else
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
...@@ -1990,13 +2001,12 @@ static const struct ethtool_ops cpsw_ethtool_ops = { ...@@ -1990,13 +2001,12 @@ static const struct ethtool_ops cpsw_ethtool_ops = {
.complete = cpsw_ethtool_op_complete, .complete = cpsw_ethtool_op_complete,
}; };
static void cpsw_slave_init(struct cpsw_slave *slave, struct cpsw_priv *priv, static void cpsw_slave_init(struct cpsw_slave *slave, struct cpsw_common *cpsw,
u32 slave_reg_ofs, u32 sliver_reg_ofs) u32 slave_reg_ofs, u32 sliver_reg_ofs)
{ {
struct cpsw_common *cpsw = priv->cpsw;
void __iomem *regs = cpsw->regs; void __iomem *regs = cpsw->regs;
int slave_num = slave->slave_num; int slave_num = slave->slave_num;
struct cpsw_slave_data *data = priv->data.slave_data + slave_num; struct cpsw_slave_data *data = cpsw->data.slave_data + slave_num;
slave->data = data; slave->data = data;
slave->regs = regs + slave_reg_ofs; slave->regs = regs + slave_reg_ofs;
...@@ -2169,11 +2179,11 @@ static int cpsw_probe_dt(struct cpsw_platform_data *data, ...@@ -2169,11 +2179,11 @@ static int cpsw_probe_dt(struct cpsw_platform_data *data,
static int cpsw_probe_dual_emac(struct cpsw_priv *priv) static int cpsw_probe_dual_emac(struct cpsw_priv *priv)
{ {
struct cpsw_platform_data *data = &priv->data; struct cpsw_common *cpsw = priv->cpsw;
struct cpsw_platform_data *data = &cpsw->data;
struct net_device *ndev; struct net_device *ndev;
struct cpsw_priv *priv_sl2; struct cpsw_priv *priv_sl2;
int ret = 0; int ret = 0;
struct cpsw_common *cpsw = priv->cpsw;
ndev = alloc_etherdev(sizeof(struct cpsw_priv)); ndev = alloc_etherdev(sizeof(struct cpsw_priv));
if (!ndev) { if (!ndev) {
...@@ -2182,8 +2192,7 @@ static int cpsw_probe_dual_emac(struct cpsw_priv *priv) ...@@ -2182,8 +2192,7 @@ static int cpsw_probe_dual_emac(struct cpsw_priv *priv)
} }
priv_sl2 = netdev_priv(ndev); priv_sl2 = netdev_priv(ndev);
priv_sl2->cpsw = priv->cpsw; priv_sl2->cpsw = cpsw;
priv_sl2->data = *data;
priv_sl2->ndev = ndev; priv_sl2->ndev = ndev;
priv_sl2->dev = &ndev->dev; priv_sl2->dev = &ndev->dev;
priv_sl2->msg_enable = netif_msg_init(debug_level, CPSW_DEBUG); priv_sl2->msg_enable = netif_msg_init(debug_level, CPSW_DEBUG);
...@@ -2201,12 +2210,11 @@ static int cpsw_probe_dual_emac(struct cpsw_priv *priv) ...@@ -2201,12 +2210,11 @@ static int cpsw_probe_dual_emac(struct cpsw_priv *priv)
} }
memcpy(ndev->dev_addr, priv_sl2->mac_addr, ETH_ALEN); memcpy(ndev->dev_addr, priv_sl2->mac_addr, ETH_ALEN);
priv_sl2->slaves = priv->slaves;
priv_sl2->coal_intvl = 0; priv_sl2->coal_intvl = 0;
priv_sl2->bus_freq_mhz = priv->bus_freq_mhz; priv_sl2->bus_freq_mhz = priv->bus_freq_mhz;
priv_sl2->ale = priv->ale; priv_sl2->ale = priv->ale;
priv_sl2->emac_port = 1; priv_sl2->emac_port = 1;
priv->slaves[1].ndev = ndev; cpsw->slaves[1].ndev = ndev;
priv_sl2->cpts = priv->cpts; priv_sl2->cpts = priv->cpts;
priv_sl2->version = priv->version; priv_sl2->version = priv->version;
ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
...@@ -2319,12 +2327,12 @@ static int cpsw_probe(struct platform_device *pdev) ...@@ -2319,12 +2327,12 @@ static int cpsw_probe(struct platform_device *pdev)
/* Select default pin state */ /* Select default pin state */
pinctrl_pm_select_default_state(&pdev->dev); pinctrl_pm_select_default_state(&pdev->dev);
if (cpsw_probe_dt(&priv->data, pdev)) { if (cpsw_probe_dt(&cpsw->data, pdev)) {
dev_err(&pdev->dev, "cpsw: platform data missing\n"); dev_err(&pdev->dev, "cpsw: platform data missing\n");
ret = -ENODEV; ret = -ENODEV;
goto clean_runtime_disable_ret; goto clean_runtime_disable_ret;
} }
data = &priv->data; data = &cpsw->data;
if (is_valid_ether_addr(data->slave_data[0].mac_addr)) { if (is_valid_ether_addr(data->slave_data[0].mac_addr)) {
memcpy(priv->mac_addr, data->slave_data[0].mac_addr, ETH_ALEN); memcpy(priv->mac_addr, data->slave_data[0].mac_addr, ETH_ALEN);
...@@ -2336,17 +2344,17 @@ static int cpsw_probe(struct platform_device *pdev) ...@@ -2336,17 +2344,17 @@ static int cpsw_probe(struct platform_device *pdev)
memcpy(ndev->dev_addr, priv->mac_addr, ETH_ALEN); memcpy(ndev->dev_addr, priv->mac_addr, ETH_ALEN);
priv->slaves = devm_kzalloc(&pdev->dev, cpsw->slaves = devm_kzalloc(&pdev->dev,
sizeof(struct cpsw_slave) * data->slaves, sizeof(struct cpsw_slave) * data->slaves,
GFP_KERNEL); GFP_KERNEL);
if (!priv->slaves) { if (!cpsw->slaves) {
ret = -ENOMEM; ret = -ENOMEM;
goto clean_runtime_disable_ret; goto clean_runtime_disable_ret;
} }
for (i = 0; i < data->slaves; i++) for (i = 0; i < data->slaves; i++)
priv->slaves[i].slave_num = i; cpsw->slaves[i].slave_num = i;
priv->slaves[0].ndev = ndev; cpsw->slaves[0].ndev = ndev;
priv->emac_port = 0; priv->emac_port = 0;
clk = devm_clk_get(&pdev->dev, "fck"); clk = devm_clk_get(&pdev->dev, "fck");
...@@ -2420,9 +2428,10 @@ static int cpsw_probe(struct platform_device *pdev) ...@@ -2420,9 +2428,10 @@ static int cpsw_probe(struct platform_device *pdev)
ret = -ENODEV; ret = -ENODEV;
goto clean_runtime_disable_ret; goto clean_runtime_disable_ret;
} }
for (i = 0; i < priv->data.slaves; i++) { for (i = 0; i < cpsw->data.slaves; i++) {
struct cpsw_slave *slave = &priv->slaves[i]; struct cpsw_slave *slave = &cpsw->slaves[i];
cpsw_slave_init(slave, priv, slave_offset, sliver_offset);
cpsw_slave_init(slave, cpsw, slave_offset, sliver_offset);
slave_offset += slave_size; slave_offset += slave_size;
sliver_offset += SLIVER_SIZE; sliver_offset += SLIVER_SIZE;
} }
...@@ -2543,7 +2552,7 @@ static int cpsw_probe(struct platform_device *pdev) ...@@ -2543,7 +2552,7 @@ static int cpsw_probe(struct platform_device *pdev)
cpsw_notice(priv, probe, "initialized device (regs %pa, irq %d)\n", cpsw_notice(priv, probe, "initialized device (regs %pa, irq %d)\n",
&ss_res->start, ndev->irq); &ss_res->start, ndev->irq);
if (priv->data.dual_emac) { if (cpsw->data.dual_emac) {
ret = cpsw_probe_dual_emac(priv); ret = cpsw_probe_dual_emac(priv);
if (ret) { if (ret) {
cpsw_err(priv, probe, "error probe slave 2 emac interface\n"); cpsw_err(priv, probe, "error probe slave 2 emac interface\n");
...@@ -2577,8 +2586,8 @@ static int cpsw_remove(struct platform_device *pdev) ...@@ -2577,8 +2586,8 @@ static int cpsw_remove(struct platform_device *pdev)
return ret; return ret;
} }
if (priv->data.dual_emac) if (cpsw->data.dual_emac)
unregister_netdev(priv->slaves[1].ndev); unregister_netdev(cpsw->slaves[1].ndev);
unregister_netdev(ndev); unregister_netdev(ndev);
cpsw_ale_destroy(priv->ale); cpsw_ale_destroy(priv->ale);
...@@ -2586,8 +2595,8 @@ static int cpsw_remove(struct platform_device *pdev) ...@@ -2586,8 +2595,8 @@ static int cpsw_remove(struct platform_device *pdev)
of_platform_depopulate(&pdev->dev); of_platform_depopulate(&pdev->dev);
pm_runtime_put_sync(&pdev->dev); pm_runtime_put_sync(&pdev->dev);
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
if (priv->data.dual_emac) if (cpsw->data.dual_emac)
free_netdev(priv->slaves[1].ndev); free_netdev(cpsw->slaves[1].ndev);
free_netdev(ndev); free_netdev(ndev);
return 0; return 0;
} }
...@@ -2597,14 +2606,14 @@ static int cpsw_suspend(struct device *dev) ...@@ -2597,14 +2606,14 @@ static int cpsw_suspend(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct platform_device *pdev = to_platform_device(dev);
struct net_device *ndev = platform_get_drvdata(pdev); struct net_device *ndev = platform_get_drvdata(pdev);
struct cpsw_priv *priv = netdev_priv(ndev); struct cpsw_common *cpsw = ndev_to_cpsw(ndev);
if (priv->data.dual_emac) { if (cpsw->data.dual_emac) {
int i; int i;
for (i = 0; i < priv->data.slaves; i++) { for (i = 0; i < cpsw->data.slaves; i++) {
if (netif_running(priv->slaves[i].ndev)) if (netif_running(cpsw->slaves[i].ndev))
cpsw_ndo_stop(priv->slaves[i].ndev); cpsw_ndo_stop(cpsw->slaves[i].ndev);
} }
} else { } else {
if (netif_running(ndev)) if (netif_running(ndev))
...@@ -2621,17 +2630,17 @@ static int cpsw_resume(struct device *dev) ...@@ -2621,17 +2630,17 @@ static int cpsw_resume(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct platform_device *pdev = to_platform_device(dev);
struct net_device *ndev = platform_get_drvdata(pdev); struct net_device *ndev = platform_get_drvdata(pdev);
struct cpsw_priv *priv = netdev_priv(ndev); struct cpsw_common *cpsw = netdev_priv(ndev);
/* Select default pin state */ /* Select default pin state */
pinctrl_pm_select_default_state(dev); pinctrl_pm_select_default_state(dev);
if (priv->data.dual_emac) { if (cpsw->data.dual_emac) {
int i; int i;
for (i = 0; i < priv->data.slaves; i++) { for (i = 0; i < cpsw->data.slaves; i++) {
if (netif_running(priv->slaves[i].ndev)) if (netif_running(cpsw->slaves[i].ndev))
cpsw_ndo_open(priv->slaves[i].ndev); cpsw_ndo_open(cpsw->slaves[i].ndev);
} }
} else { } else {
if (netif_running(ndev)) if (netif_running(ndev))
......
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