Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 66355f52 authored by Kejian Yan's avatar Kejian Yan Committed by David S. Miller
Browse files

net: hns: add the support to add/remove the ucast entry to/from table



This patch adds the support to add or remove the unicast entries
to the table and remove from the table.

Reported-by: default avatarDaode Huang <huangdaode@hisilicon.com>
Signed-off-by: default avatarKejian Yan <yankejian@huawei.com>
Reviewed-by: default avatarYisen Zhuang <yisen.zhuang@huawei.com>
Signed-off-by: default avatarSalil Mehta <salil.mehta@huawei.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ec2cafe6
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -430,6 +430,10 @@ enum hnae_media_type {
 *   clear mcast tcam table
 * set_mc_addr()
 *   set multicast mode
 * add_uc_addr()
 *   add ucast address
 * rm_uc_addr()
 *   remove ucast address
 * set_mtu()
 *   set mtu
 * update_stats()
@@ -490,6 +494,10 @@ struct hnae_ae_ops {
	void (*set_promisc_mode)(struct hnae_handle *handle, u32 en);
	int (*get_mac_addr)(struct hnae_handle *handle, void **p);
	int (*set_mac_addr)(struct hnae_handle *handle, void *p);
	int (*add_uc_addr)(struct hnae_handle *handle,
			   const unsigned char *addr);
	int (*rm_uc_addr)(struct hnae_handle *handle,
			  const unsigned char *addr);
	int (*clr_mc_addr)(struct hnae_handle *handle);
	int (*set_mc_addr)(struct hnae_handle *handle, void *addr);
	int (*set_mtu)(struct hnae_handle *handle, int new_mtu);
+24 −0
Original line number Diff line number Diff line
@@ -199,6 +199,28 @@ static int hns_ae_set_mac_address(struct hnae_handle *handle, void *p)
	return 0;
}

static int hns_ae_add_uc_address(struct hnae_handle *handle,
				 const unsigned char *addr)
{
	struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);

	if (mac_cb->mac_type != HNAE_PORT_SERVICE)
		return -ENOSPC;

	return hns_mac_add_uc_addr(mac_cb, handle->vf_id, addr);
}

static int hns_ae_rm_uc_address(struct hnae_handle *handle,
				const unsigned char *addr)
{
	struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);

	if (mac_cb->mac_type != HNAE_PORT_SERVICE)
		return -ENOSPC;

	return hns_mac_rm_uc_addr(mac_cb, handle->vf_id, addr);
}

static int hns_ae_set_multicast_one(struct hnae_handle *handle, void *addr)
{
	int ret;
@@ -830,6 +852,8 @@ static struct hnae_ae_ops hns_dsaf_ops = {
	.get_coalesce_range = hns_ae_get_coalesce_range,
	.set_promisc_mode = hns_ae_set_promisc_mode,
	.set_mac_addr = hns_ae_set_mac_address,
	.add_uc_addr = hns_ae_add_uc_address,
	.rm_uc_addr = hns_ae_rm_uc_address,
	.set_mc_addr = hns_ae_set_multicast_one,
	.clr_mc_addr = hns_ae_clr_multicast,
	.set_mtu = hns_ae_set_mtu,
+40 −0
Original line number Diff line number Diff line
@@ -263,6 +263,46 @@ int hns_mac_change_vf_addr(struct hns_mac_cb *mac_cb,
	return 0;
}

int hns_mac_add_uc_addr(struct hns_mac_cb *mac_cb, u8 vf_id,
			const unsigned char *addr)
{
	struct dsaf_device *dsaf_dev = mac_cb->dsaf_dev;
	struct dsaf_drv_mac_single_dest_entry mac_entry;
	int ret;

	if (HNS_DSAF_IS_DEBUG(dsaf_dev))
		return -ENOSPC;

	memset(&mac_entry, 0, sizeof(mac_entry));
	memcpy(mac_entry.addr, addr, sizeof(mac_entry.addr));
	mac_entry.in_port_num = mac_cb->mac_id;
	ret = hns_mac_get_inner_port_num(mac_cb, vf_id, &mac_entry.port_num);
	if (ret)
		return ret;

	return hns_dsaf_set_mac_uc_entry(dsaf_dev, &mac_entry);
}

int hns_mac_rm_uc_addr(struct hns_mac_cb *mac_cb, u8 vf_id,
		       const unsigned char *addr)
{
	struct dsaf_device *dsaf_dev = mac_cb->dsaf_dev;
	struct dsaf_drv_mac_single_dest_entry mac_entry;
	int ret;

	if (HNS_DSAF_IS_DEBUG(dsaf_dev))
		return -ENOSPC;

	memset(&mac_entry, 0, sizeof(mac_entry));
	memcpy(mac_entry.addr, addr, sizeof(mac_entry.addr));
	mac_entry.in_port_num = mac_cb->mac_id;
	ret = hns_mac_get_inner_port_num(mac_cb, vf_id, &mac_entry.port_num);
	if (ret)
		return ret;

	return hns_dsaf_rm_mac_addr(dsaf_dev, &mac_entry);
}

int hns_mac_set_multi(struct hns_mac_cb *mac_cb,
		      u32 port_num, char *addr, bool enable)
{
+4 −0
Original line number Diff line number Diff line
@@ -461,6 +461,10 @@ int hns_cpld_led_set_id(struct hns_mac_cb *mac_cb,
void hns_mac_set_promisc(struct hns_mac_cb *mac_cb, u8 en);
int hns_mac_get_inner_port_num(struct hns_mac_cb *mac_cb,
			       u8 vmid, u8 *port_num);
int hns_mac_add_uc_addr(struct hns_mac_cb *mac_cb, u8 vf_id,
			const unsigned char *addr);
int hns_mac_rm_uc_addr(struct hns_mac_cb *mac_cb, u8 vf_id,
		       const unsigned char *addr);
int hns_mac_clr_multicast(struct hns_mac_cb *mac_cb, int vfn);

#endif /* _HNS_DSAF_MAC_H */
+49 −0
Original line number Diff line number Diff line
@@ -1598,6 +1598,55 @@ int hns_dsaf_set_mac_uc_entry(
	return 0;
}

int hns_dsaf_rm_mac_addr(
	struct dsaf_device *dsaf_dev,
	struct dsaf_drv_mac_single_dest_entry *mac_entry)
{
	u16 entry_index = DSAF_INVALID_ENTRY_IDX;
	struct dsaf_tbl_tcam_ucast_cfg mac_data;
	struct dsaf_drv_tbl_tcam_key mac_key;

	/* mac addr check */
	if (!is_valid_ether_addr(mac_entry->addr)) {
		dev_err(dsaf_dev->dev, "rm_uc_addr %s Mac %pM err!\n",
			dsaf_dev->ae_dev.name, mac_entry->addr);
		return -EINVAL;
	}

	/* config key */
	hns_dsaf_set_mac_key(dsaf_dev, &mac_key, mac_entry->in_vlan_id,
			     mac_entry->in_port_num, mac_entry->addr);

	entry_index = hns_dsaf_find_soft_mac_entry(dsaf_dev, &mac_key);
	if (entry_index == DSAF_INVALID_ENTRY_IDX) {
		/* can not find the tcam entry, return 0 */
		dev_info(dsaf_dev->dev,
			 "rm_uc_addr no tcam, %s Mac key(%#x:%#x)\n",
			 dsaf_dev->ae_dev.name,
			 mac_key.high.val, mac_key.low.val);
		return 0;
	}

	dev_dbg(dsaf_dev->dev,
		"rm_uc_addr, %s Mac key(%#x:%#x) entry_index%d\n",
		dsaf_dev->ae_dev.name, mac_key.high.val,
		mac_key.low.val, entry_index);

	hns_dsaf_tcam_uc_get(
			dsaf_dev, entry_index,
			(struct dsaf_tbl_tcam_data *)&mac_key,
			&mac_data);

	/* unicast entry not used locally should not clear */
	if (mac_entry->port_num != mac_data.tbl_ucast_out_port)
		return -EFAULT;

	return hns_dsaf_del_mac_entry(dsaf_dev,
				      mac_entry->in_vlan_id,
				      mac_entry->in_port_num,
				      mac_entry->addr);
}

/**
 * hns_dsaf_set_mac_mc_entry - set mac mc-entry
 * @dsaf_dev: dsa fabric device struct pointer
Loading