Skip to content

Commit

Permalink
net: hns: add dsaf misc operation method
Browse files Browse the repository at this point in the history
The misc operation for different hw platform may be different, if using
current implementation, it will add a new branch on each function for
every new hw platform, so we add a method for this operation.

Signed-off-by: Kejian Yan <yankejian@huawei.com>
Signed-off-by: Yisen Zhuang <Yisen.Zhuang@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Kejian Yan authored and David S. Miller committed Jun 5, 2016
1 parent 652d39b commit a24274a
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 70 deletions.
4 changes: 3 additions & 1 deletion drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,13 +637,15 @@ static int hns_ae_config_loopback(struct hnae_handle *handle,
int ret;
struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(handle);
struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
struct dsaf_device *dsaf_dev = mac_cb->dsaf_dev;

switch (loop) {
case MAC_INTERNALLOOP_PHY:
ret = 0;
break;
case MAC_INTERNALLOOP_SERDES:
ret = hns_mac_config_sds_loopback(vf_cb->mac_cb, en);
ret = dsaf_dev->misc_op->cfg_serdes_loopback(vf_cb->mac_cb,
!!en);
break;
case MAC_INTERNALLOOP_MAC:
ret = hns_mac_config_mac_loopback(vf_cb->mac_cb, loop, en);
Expand Down
6 changes: 3 additions & 3 deletions drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static void hns_gmac_free(void *mac_drv)

u32 mac_id = drv->mac_id;

hns_dsaf_ge_srst_by_port(dsaf_dev, mac_id, 0);
dsaf_dev->misc_op->ge_srst(dsaf_dev, mac_id, 0);
}

static void hns_gmac_set_tx_auto_pause_frames(void *mac_drv, u16 newval)
Expand Down Expand Up @@ -317,9 +317,9 @@ static void hns_gmac_init(void *mac_drv)

port = drv->mac_id;

hns_dsaf_ge_srst_by_port(dsaf_dev, port, 0);
dsaf_dev->misc_op->ge_srst(dsaf_dev, port, 0);
mdelay(10);
hns_dsaf_ge_srst_by_port(dsaf_dev, port, 1);
dsaf_dev->misc_op->ge_srst(dsaf_dev, port, 1);
mdelay(10);
hns_gmac_disable(mac_drv, MAC_COMM_MODE_RX_AND_TX);
hns_gmac_tx_loop_pkt_dis(mac_drv);
Expand Down
14 changes: 7 additions & 7 deletions drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void hns_mac_get_link_status(struct hns_mac_cb *mac_cb, u32 *link_status)
else
*link_status = 0;

ret = hns_mac_get_sfp_prsnt(mac_cb, &sfp_prsnt);
ret = mac_cb->dsaf_dev->misc_op->get_sfp_prsnt(mac_cb, &sfp_prsnt);
if (!ret)
*link_status = *link_status && sfp_prsnt;

Expand Down Expand Up @@ -512,7 +512,7 @@ void hns_mac_stop(struct hns_mac_cb *mac_cb)

mac_ctrl_drv->mac_en_flg = 0;
mac_cb->link = 0;
cpld_led_reset(mac_cb);
mac_cb->dsaf_dev->misc_op->cpld_reset_led(mac_cb);
}

/**
Expand Down Expand Up @@ -804,7 +804,7 @@ int hns_mac_get_cfg(struct dsaf_device *dsaf_dev, struct hns_mac_cb *mac_cb)
else
mac_cb->mac_type = HNAE_PORT_DEBUG;

mac_cb->phy_if = hns_mac_get_phy_if(mac_cb);
mac_cb->phy_if = dsaf_dev->misc_op->get_phy_if(mac_cb);

ret = hns_mac_get_mode(mac_cb->phy_if);
if (ret < 0) {
Expand All @@ -819,7 +819,7 @@ int hns_mac_get_cfg(struct dsaf_device *dsaf_dev, struct hns_mac_cb *mac_cb)
if (ret)
return ret;

cpld_led_reset(mac_cb);
mac_cb->dsaf_dev->misc_op->cpld_reset_led(mac_cb);
mac_cb->vaddr = hns_mac_get_vaddr(dsaf_dev, mac_cb, mac_mode_idx);

return 0;
Expand Down Expand Up @@ -906,7 +906,7 @@ void hns_mac_uninit(struct dsaf_device *dsaf_dev)
int max_port_num = hns_mac_get_max_port_num(dsaf_dev);

for (i = 0; i < max_port_num; i++) {
cpld_led_reset(dsaf_dev->mac_cb[i]);
dsaf_dev->misc_op->cpld_reset_led(dsaf_dev->mac_cb[i]);
dsaf_dev->mac_cb[i] = NULL;
}
}
Expand Down Expand Up @@ -989,7 +989,7 @@ void hns_set_led_opt(struct hns_mac_cb *mac_cb)
nic_data = 0;
mac_cb->txpkt_for_led = mac_cb->hw_stats.tx_good_pkts;
mac_cb->rxpkt_for_led = mac_cb->hw_stats.rx_good_pkts;
hns_cpld_set_led(mac_cb, (int)mac_cb->link,
mac_cb->dsaf_dev->misc_op->cpld_set_led(mac_cb, (int)mac_cb->link,
mac_cb->speed, nic_data);
}

Expand All @@ -999,5 +999,5 @@ int hns_cpld_led_set_id(struct hns_mac_cb *mac_cb,
if (!mac_cb || !mac_cb->cpld_ctrl)
return 0;

return cpld_set_led_id(mac_cb, status);
return mac_cb->dsaf_dev->misc_op->cpld_set_led_id(mac_cb, status);
}
2 changes: 0 additions & 2 deletions drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,6 @@ int hns_mac_set_pauseparam(struct hns_mac_cb *mac_cb, u32 rx_en, u32 tx_en);
int hns_mac_set_mtu(struct hns_mac_cb *mac_cb, u32 new_mtu);
int hns_mac_get_port_info(struct hns_mac_cb *mac_cb,
u8 *auto_neg, u16 *speed, u8 *duplex);
phy_interface_t hns_mac_get_phy_if(struct hns_mac_cb *mac_cb);
int hns_mac_config_sds_loopback(struct hns_mac_cb *mac_cb, u8 en);
int hns_mac_config_mac_loopback(struct hns_mac_cb *mac_cb,
enum hnae_loop loop, int en);
void hns_mac_update_stats(struct hns_mac_cb *mac_cb);
Expand Down
11 changes: 8 additions & 3 deletions drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "hns_dsaf_main.h"
#include "hns_dsaf_ppe.h"
#include "hns_dsaf_rcb.h"
#include "hns_dsaf_misc.h"

const char *g_dsaf_mode_match[DSAF_MODE_MAX] = {
[DSAF_MODE_DISABLE_2PORT_64VM] = "2port-64vf",
Expand Down Expand Up @@ -174,6 +175,10 @@ int hns_dsaf_get_cfg(struct dsaf_device *dsaf_dev)
goto unmap_base_addr;
}

dsaf_dev->misc_op = hns_misc_op_get(dsaf_dev);
if (!dsaf_dev->misc_op)
return -ENOMEM;

if (!dma_set_mask_and_coherent(dsaf_dev->dev, DMA_BIT_MASK(64ULL)))
dev_dbg(dsaf_dev->dev, "set mask to 64bit\n");
else
Expand Down Expand Up @@ -1296,9 +1301,9 @@ static int hns_dsaf_init_hw(struct dsaf_device *dsaf_dev)
dev_dbg(dsaf_dev->dev,
"hns_dsaf_init_hw begin %s !\n", dsaf_dev->ae_dev.name);

hns_dsaf_rst(dsaf_dev, 0);
dsaf_dev->misc_op->dsaf_reset(dsaf_dev, 0);
mdelay(10);
hns_dsaf_rst(dsaf_dev, 1);
dsaf_dev->misc_op->dsaf_reset(dsaf_dev, 1);

hns_dsaf_comm_init(dsaf_dev);

Expand Down Expand Up @@ -1326,7 +1331,7 @@ static int hns_dsaf_init_hw(struct dsaf_device *dsaf_dev)
static void hns_dsaf_remove_hw(struct dsaf_device *dsaf_dev)
{
/*reset*/
hns_dsaf_rst(dsaf_dev, 0);
dsaf_dev->misc_op->dsaf_reset(dsaf_dev, 0);
}

/**
Expand Down
33 changes: 22 additions & 11 deletions drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,27 @@ struct dsaf_int_stat {

};

struct dsaf_misc_op {
void (*cpld_set_led)(struct hns_mac_cb *mac_cb, int link_status,
u16 speed, int data);
void (*cpld_reset_led)(struct hns_mac_cb *mac_cb);
int (*cpld_set_led_id)(struct hns_mac_cb *mac_cb,
enum hnae_led_state status);
/* reset seris function, it will be reset if the dereseet is 0 */
void (*dsaf_reset)(struct dsaf_device *dsaf_dev, bool dereset);
void (*xge_srst)(struct dsaf_device *dsaf_dev, u32 port, bool dereset);
void (*xge_core_srst)(struct dsaf_device *dsaf_dev, u32 port,
bool dereset);
void (*ge_srst)(struct dsaf_device *dsaf_dev, u32 port, bool dereset);
void (*ppe_srst)(struct dsaf_device *dsaf_dev, u32 port, bool dereset);
void (*ppe_comm_srst)(struct dsaf_device *dsaf_dev, bool dereset);

phy_interface_t (*get_phy_if)(struct hns_mac_cb *mac_cb);
int (*get_sfp_prsnt)(struct hns_mac_cb *mac_cb, int *sfp_prsnt);

int (*cfg_serdes_loopback)(struct hns_mac_cb *mac_cb, bool en);
};

/* Dsaf device struct define ,and mac -> dsaf */
struct dsaf_device {
struct device *dev;
Expand All @@ -292,6 +313,7 @@ struct dsaf_device {
struct ppe_common_cb *ppe_common[DSAF_COMM_DEV_NUM];
struct rcb_common_cb *rcb_common[DSAF_COMM_DEV_NUM];
struct hns_mac_cb *mac_cb[DSAF_MAX_PORT_NUM];
struct dsaf_misc_op *misc_op;

struct dsaf_hw_stats hw_stats[DSAF_NODE_NUM];
struct dsaf_int_stat int_stat;
Expand Down Expand Up @@ -388,22 +410,11 @@ int hns_dsaf_get_mac_entry_by_index(
u16 entry_index,
struct dsaf_drv_mac_multi_dest_entry *mac_entry);

void hns_dsaf_rst(struct dsaf_device *dsaf_dev, u32 val);

void hns_ppe_srst_by_port(struct dsaf_device *dsaf_dev, u32 port, u32 val);

void hns_ppe_com_srst(struct ppe_common_cb *ppe_common, u32 val);

void hns_dsaf_fix_mac_mode(struct hns_mac_cb *mac_cb);

int hns_dsaf_ae_init(struct dsaf_device *dsaf_dev);
void hns_dsaf_ae_uninit(struct dsaf_device *dsaf_dev);

void hns_dsaf_xge_srst_by_port(struct dsaf_device *dsaf_dev, u32 port, u32 val);
void hns_dsaf_ge_srst_by_port(struct dsaf_device *dsaf_dev, u32 port, u32 val);
void hns_dsaf_xge_core_srst_by_port(struct dsaf_device *dsaf_dev,
u32 port, u32 val);

void hns_dsaf_update_stats(struct dsaf_device *dsaf_dev, u32 inode_num);

int hns_dsaf_get_sset_count(int stringset);
Expand Down
Loading

0 comments on commit a24274a

Please sign in to comment.