Commit de624864 authored by Diana Wang's avatar Diana Wang Committed by David S. Miller

nfp: add support for multicast filter

Rewrite nfp_net_set_rx_mode() to implement interface to delivery
mc address and operations to firmware by using general mailbox
for filtering multicast packets.

The operations include add mc address and delete mc address.
And the limitation of mc addresses number is 1024 for each net
device.

User triggers adding mc address by using command below:
ip maddress add <mc address> dev <interface name>

User triggers deleting mc address by using command below:
ip maddress del <mc address> dev <interface name>
Signed-off-by: default avatarDiana Wang <na.wang@corigine.com>
Signed-off-by: default avatarSimon Horman <simon.horman@corigine.com>
Reviewed-by: default avatarLeon Romanovsky <leonro@nvidia.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 38db82e2
...@@ -88,6 +88,9 @@ ...@@ -88,6 +88,9 @@
#define NFP_NET_FL_BATCH 16 /* Add freelist in this Batch size */ #define NFP_NET_FL_BATCH 16 /* Add freelist in this Batch size */
#define NFP_NET_XDP_MAX_COMPLETE 2048 /* XDP bufs to reclaim in NAPI poll */ #define NFP_NET_XDP_MAX_COMPLETE 2048 /* XDP bufs to reclaim in NAPI poll */
/* MC definitions */
#define NFP_NET_CFG_MAC_MC_MAX 1024 /* The maximum number of MC address per port*/
/* Offload definitions */ /* Offload definitions */
#define NFP_NET_N_VXLAN_PORTS (NFP_NET_CFG_VXLAN_SZ / sizeof(__be16)) #define NFP_NET_N_VXLAN_PORTS (NFP_NET_CFG_VXLAN_SZ / sizeof(__be16))
...@@ -476,6 +479,7 @@ struct nfp_stat_pair { ...@@ -476,6 +479,7 @@ struct nfp_stat_pair {
* @rx_dma_off: Offset at which DMA packets (for XDP headroom) * @rx_dma_off: Offset at which DMA packets (for XDP headroom)
* @rx_offset: Offset in the RX buffers where packet data starts * @rx_offset: Offset in the RX buffers where packet data starts
* @ctrl: Local copy of the control register/word. * @ctrl: Local copy of the control register/word.
* @ctrl_w1: Local copy of the control register/word1.
* @fl_bufsz: Currently configured size of the freelist buffers * @fl_bufsz: Currently configured size of the freelist buffers
* @xdp_prog: Installed XDP program * @xdp_prog: Installed XDP program
* @tx_rings: Array of pre-allocated TX ring structures * @tx_rings: Array of pre-allocated TX ring structures
...@@ -508,6 +512,7 @@ struct nfp_net_dp { ...@@ -508,6 +512,7 @@ struct nfp_net_dp {
u32 rx_dma_off; u32 rx_dma_off;
u32 ctrl; u32 ctrl;
u32 ctrl_w1;
u32 fl_bufsz; u32 fl_bufsz;
struct bpf_prog *xdp_prog; struct bpf_prog *xdp_prog;
......
...@@ -1007,6 +1007,7 @@ static int nfp_net_set_config_and_enable(struct nfp_net *nn) ...@@ -1007,6 +1007,7 @@ static int nfp_net_set_config_and_enable(struct nfp_net *nn)
new_ctrl |= NFP_NET_CFG_CTRL_RINGCFG; new_ctrl |= NFP_NET_CFG_CTRL_RINGCFG;
nn_writel(nn, NFP_NET_CFG_CTRL, new_ctrl); nn_writel(nn, NFP_NET_CFG_CTRL, new_ctrl);
nn_writel(nn, NFP_NET_CFG_CTRL_WORD1, nn->dp.ctrl_w1);
err = nfp_net_reconfig(nn, update); err = nfp_net_reconfig(nn, update);
if (err) { if (err) {
nfp_net_clear_config_and_disable(nn); nfp_net_clear_config_and_disable(nn);
...@@ -1333,18 +1334,59 @@ int nfp_ctrl_open(struct nfp_net *nn) ...@@ -1333,18 +1334,59 @@ int nfp_ctrl_open(struct nfp_net *nn)
return err; return err;
} }
static int nfp_net_mc_cfg(struct net_device *netdev, const unsigned char *addr, const u32 cmd)
{
struct nfp_net *nn = netdev_priv(netdev);
int ret;
ret = nfp_net_mbox_lock(nn, NFP_NET_CFG_MULTICAST_SZ);
if (ret)
return ret;
nn_writel(nn, nn->tlv_caps.mbox_off + NFP_NET_CFG_MULTICAST_MAC_HI,
get_unaligned_be32(addr));
nn_writew(nn, nn->tlv_caps.mbox_off + NFP_NET_CFG_MULTICAST_MAC_LO,
get_unaligned_be16(addr + 4));
return nfp_net_mbox_reconfig_and_unlock(nn, cmd);
}
static int nfp_net_mc_sync(struct net_device *netdev, const unsigned char *addr)
{
struct nfp_net *nn = netdev_priv(netdev);
if (netdev_mc_count(netdev) > NFP_NET_CFG_MAC_MC_MAX) {
nn_err(nn, "Requested number of MC addresses (%d) exceeds maximum (%d).\n",
netdev_mc_count(netdev), NFP_NET_CFG_MAC_MC_MAX);
return -EINVAL;
}
return nfp_net_mc_cfg(netdev, addr, NFP_NET_CFG_MBOX_CMD_MULTICAST_ADD);
}
static int nfp_net_mc_unsync(struct net_device *netdev, const unsigned char *addr)
{
return nfp_net_mc_cfg(netdev, addr, NFP_NET_CFG_MBOX_CMD_MULTICAST_DEL);
}
static void nfp_net_set_rx_mode(struct net_device *netdev) static void nfp_net_set_rx_mode(struct net_device *netdev)
{ {
struct nfp_net *nn = netdev_priv(netdev); struct nfp_net *nn = netdev_priv(netdev);
u32 new_ctrl; u32 new_ctrl, new_ctrl_w1;
new_ctrl = nn->dp.ctrl; new_ctrl = nn->dp.ctrl;
new_ctrl_w1 = nn->dp.ctrl_w1;
if (!netdev_mc_empty(netdev) || netdev->flags & IFF_ALLMULTI) if (!netdev_mc_empty(netdev) || netdev->flags & IFF_ALLMULTI)
new_ctrl |= nn->cap & NFP_NET_CFG_CTRL_L2MC; new_ctrl |= nn->cap & NFP_NET_CFG_CTRL_L2MC;
else else
new_ctrl &= ~NFP_NET_CFG_CTRL_L2MC; new_ctrl &= ~NFP_NET_CFG_CTRL_L2MC;
if (netdev->flags & IFF_ALLMULTI)
new_ctrl_w1 &= ~NFP_NET_CFG_CTRL_MCAST_FILTER;
else
new_ctrl_w1 |= nn->cap_w1 & NFP_NET_CFG_CTRL_MCAST_FILTER;
if (netdev->flags & IFF_PROMISC) { if (netdev->flags & IFF_PROMISC) {
if (nn->cap & NFP_NET_CFG_CTRL_PROMISC) if (nn->cap & NFP_NET_CFG_CTRL_PROMISC)
new_ctrl |= NFP_NET_CFG_CTRL_PROMISC; new_ctrl |= NFP_NET_CFG_CTRL_PROMISC;
...@@ -1354,13 +1396,21 @@ static void nfp_net_set_rx_mode(struct net_device *netdev) ...@@ -1354,13 +1396,21 @@ static void nfp_net_set_rx_mode(struct net_device *netdev)
new_ctrl &= ~NFP_NET_CFG_CTRL_PROMISC; new_ctrl &= ~NFP_NET_CFG_CTRL_PROMISC;
} }
if (new_ctrl == nn->dp.ctrl) if ((nn->cap_w1 & NFP_NET_CFG_CTRL_MCAST_FILTER) &&
__dev_mc_sync(netdev, nfp_net_mc_sync, nfp_net_mc_unsync))
netdev_err(netdev, "Sync mc address failed\n");
if (new_ctrl == nn->dp.ctrl && new_ctrl_w1 == nn->dp.ctrl_w1)
return; return;
if (new_ctrl != nn->dp.ctrl)
nn_writel(nn, NFP_NET_CFG_CTRL, new_ctrl); nn_writel(nn, NFP_NET_CFG_CTRL, new_ctrl);
if (new_ctrl_w1 != nn->dp.ctrl_w1)
nn_writel(nn, NFP_NET_CFG_CTRL_WORD1, new_ctrl_w1);
nfp_net_reconfig_post(nn, NFP_NET_CFG_UPDATE_GEN); nfp_net_reconfig_post(nn, NFP_NET_CFG_UPDATE_GEN);
nn->dp.ctrl = new_ctrl; nn->dp.ctrl = new_ctrl;
nn->dp.ctrl_w1 = new_ctrl_w1;
} }
static void nfp_net_rss_init_itbl(struct nfp_net *nn) static void nfp_net_rss_init_itbl(struct nfp_net *nn)
...@@ -2092,7 +2142,7 @@ void nfp_net_info(struct nfp_net *nn) ...@@ -2092,7 +2142,7 @@ void nfp_net_info(struct nfp_net *nn)
nn->fw_ver.extend, nn->fw_ver.class, nn->fw_ver.extend, nn->fw_ver.class,
nn->fw_ver.major, nn->fw_ver.minor, nn->fw_ver.major, nn->fw_ver.minor,
nn->max_mtu); nn->max_mtu);
nn_info(nn, "CAP: %#x %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", nn_info(nn, "CAP: %#x %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
nn->cap, nn->cap,
nn->cap & NFP_NET_CFG_CTRL_PROMISC ? "PROMISC " : "", nn->cap & NFP_NET_CFG_CTRL_PROMISC ? "PROMISC " : "",
nn->cap & NFP_NET_CFG_CTRL_L2BC ? "L2BCFILT " : "", nn->cap & NFP_NET_CFG_CTRL_L2BC ? "L2BCFILT " : "",
...@@ -2120,6 +2170,7 @@ void nfp_net_info(struct nfp_net *nn) ...@@ -2120,6 +2170,7 @@ void nfp_net_info(struct nfp_net *nn)
nn->cap & NFP_NET_CFG_CTRL_CSUM_COMPLETE ? nn->cap & NFP_NET_CFG_CTRL_CSUM_COMPLETE ?
"RXCSUM_COMPLETE " : "", "RXCSUM_COMPLETE " : "",
nn->cap & NFP_NET_CFG_CTRL_LIVE_ADDR ? "LIVE_ADDR " : "", nn->cap & NFP_NET_CFG_CTRL_LIVE_ADDR ? "LIVE_ADDR " : "",
nn->cap_w1 & NFP_NET_CFG_CTRL_MCAST_FILTER ? "MULTICAST_FILTER " : "",
nfp_app_extra_cap(nn->app, nn)); nfp_app_extra_cap(nn->app, nn));
} }
...@@ -2548,6 +2599,9 @@ int nfp_net_init(struct nfp_net *nn) ...@@ -2548,6 +2599,9 @@ int nfp_net_init(struct nfp_net *nn)
if (nn->cap & NFP_NET_CFG_CTRL_TXRWB) if (nn->cap & NFP_NET_CFG_CTRL_TXRWB)
nn->dp.ctrl |= NFP_NET_CFG_CTRL_TXRWB; nn->dp.ctrl |= NFP_NET_CFG_CTRL_TXRWB;
if (nn->cap_w1 & NFP_NET_CFG_CTRL_MCAST_FILTER)
nn->dp.ctrl_w1 |= NFP_NET_CFG_CTRL_MCAST_FILTER;
/* Stash the re-configuration queue away. First odd queue in TX Bar */ /* Stash the re-configuration queue away. First odd queue in TX Bar */
nn->qcp_cfg = nn->tx_bar + NFP_QCP_QUEUE_ADDR_SZ; nn->qcp_cfg = nn->tx_bar + NFP_QCP_QUEUE_ADDR_SZ;
...@@ -2555,6 +2609,7 @@ int nfp_net_init(struct nfp_net *nn) ...@@ -2555,6 +2609,7 @@ int nfp_net_init(struct nfp_net *nn)
nn_writel(nn, NFP_NET_CFG_CTRL, 0); nn_writel(nn, NFP_NET_CFG_CTRL, 0);
nn_writeq(nn, NFP_NET_CFG_TXRS_ENABLE, 0); nn_writeq(nn, NFP_NET_CFG_TXRS_ENABLE, 0);
nn_writeq(nn, NFP_NET_CFG_RXRS_ENABLE, 0); nn_writeq(nn, NFP_NET_CFG_RXRS_ENABLE, 0);
nn_writel(nn, NFP_NET_CFG_CTRL_WORD1, 0);
err = nfp_net_reconfig(nn, NFP_NET_CFG_UPDATE_RING | err = nfp_net_reconfig(nn, NFP_NET_CFG_UPDATE_RING |
NFP_NET_CFG_UPDATE_GEN); NFP_NET_CFG_UPDATE_GEN);
if (err) if (err)
......
...@@ -267,6 +267,7 @@ ...@@ -267,6 +267,7 @@
#define NFP_NET_CFG_CTRL_WORD1 0x0098 #define NFP_NET_CFG_CTRL_WORD1 0x0098
#define NFP_NET_CFG_CTRL_PKT_TYPE (0x1 << 0) /* Pkttype offload */ #define NFP_NET_CFG_CTRL_PKT_TYPE (0x1 << 0) /* Pkttype offload */
#define NFP_NET_CFG_CTRL_IPSEC (0x1 << 1) /* IPsec offload */ #define NFP_NET_CFG_CTRL_IPSEC (0x1 << 1) /* IPsec offload */
#define NFP_NET_CFG_CTRL_MCAST_FILTER (0x1 << 2) /* Multicast Filter */
#define NFP_NET_CFG_CAP_WORD1 0x00a4 #define NFP_NET_CFG_CAP_WORD1 0x00a4
...@@ -413,6 +414,9 @@ ...@@ -413,6 +414,9 @@
#define NFP_NET_CFG_MBOX_CMD_PCI_DSCP_PRIOMAP_SET 5 #define NFP_NET_CFG_MBOX_CMD_PCI_DSCP_PRIOMAP_SET 5
#define NFP_NET_CFG_MBOX_CMD_TLV_CMSG 6 #define NFP_NET_CFG_MBOX_CMD_TLV_CMSG 6
#define NFP_NET_CFG_MBOX_CMD_MULTICAST_ADD 8
#define NFP_NET_CFG_MBOX_CMD_MULTICAST_DEL 9
/* VLAN filtering using general use mailbox /* VLAN filtering using general use mailbox
* %NFP_NET_CFG_VLAN_FILTER: Base address of VLAN filter mailbox * %NFP_NET_CFG_VLAN_FILTER: Base address of VLAN filter mailbox
* %NFP_NET_CFG_VLAN_FILTER_VID: VLAN ID to filter * %NFP_NET_CFG_VLAN_FILTER_VID: VLAN ID to filter
...@@ -424,6 +428,17 @@ ...@@ -424,6 +428,17 @@
#define NFP_NET_CFG_VLAN_FILTER_PROTO (NFP_NET_CFG_VLAN_FILTER + 2) #define NFP_NET_CFG_VLAN_FILTER_PROTO (NFP_NET_CFG_VLAN_FILTER + 2)
#define NFP_NET_CFG_VLAN_FILTER_SZ 0x0004 #define NFP_NET_CFG_VLAN_FILTER_SZ 0x0004
/* Multicast filtering using general use mailbox
* %NFP_NET_CFG_MULTICAST: Base address of Multicast filter mailbox
* %NFP_NET_CFG_MULTICAST_MAC_HI: High 32-bits of Multicast MAC address
* %NFP_NET_CFG_MULTICAST_MAC_LO: Low 16-bits of Multicast MAC address
* %NFP_NET_CFG_MULTICAST_SZ: Size of the Multicast filter mailbox in bytes
*/
#define NFP_NET_CFG_MULTICAST NFP_NET_CFG_MBOX_SIMPLE_VAL
#define NFP_NET_CFG_MULTICAST_MAC_HI NFP_NET_CFG_MULTICAST
#define NFP_NET_CFG_MULTICAST_MAC_LO (NFP_NET_CFG_MULTICAST + 6)
#define NFP_NET_CFG_MULTICAST_SZ 0x0006
/* TLV capabilities /* TLV capabilities
* %NFP_NET_CFG_TLV_TYPE: Offset of type within the TLV * %NFP_NET_CFG_TLV_TYPE: Offset of type within the TLV
* %NFP_NET_CFG_TLV_TYPE_REQUIRED: Driver must be able to parse the TLV * %NFP_NET_CFG_TLV_TYPE_REQUIRED: Driver must be able to parse the TLV
......
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