ENIC driver patch to fix MAC address add and remove
[vpp.git] / dpdk / dpdk-16.11_patches / 0003-enic-fix-MAC-address-add-and-remove.patch
1 From 0cd0ed7b0b966704236e07fc1d3bd099deb407a7 Mon Sep 17 00:00:00 2001
2 From: John Daley <johndale@cisco.com>
3 Date: Tue, 31 Jan 2017 12:59:23 -0800
4 Subject: [PATCH] The mac_addr_add callback function was simply replacing the
5  primary MAC address instead of adding new ones and the mac_addr_remove
6  callback would only remove the primary MAC form the adapter. Fix the
7  functions to add or remove new address. Allow up to 64 MAC addresses per
8  port.
9
10 Signed-off-by: John Daley <johndale@cisco.com>
11 ---
12  drivers/net/enic/enic.h        |  5 +++--
13  drivers/net/enic/enic_ethdev.c |  6 +++---
14  drivers/net/enic/enic_main.c   | 21 ++++++++-------------
15  3 files changed, 14 insertions(+), 18 deletions(-)
16
17 diff --git a/drivers/net/enic/enic.h b/drivers/net/enic/enic.h
18 index 865cd76..5a807d4 100644
19 --- a/drivers/net/enic/enic.h
20 +++ b/drivers/net/enic/enic.h
21 @@ -60,6 +60,7 @@
22  #define ENIC_RQ_MAX            16
23  #define ENIC_CQ_MAX            (ENIC_WQ_MAX + (ENIC_RQ_MAX / 2))
24  #define ENIC_INTR_MAX          (ENIC_CQ_MAX + 2)
25 +#define ENIC_MAX_MAC_ADDR      64
26  
27  #define VLAN_ETH_HLEN           18
28  
29 @@ -277,8 +278,8 @@ extern void enic_dev_stats_get(struct enic *enic,
30         struct rte_eth_stats *r_stats);
31  extern void enic_dev_stats_clear(struct enic *enic);
32  extern void enic_add_packet_filter(struct enic *enic);
33 -extern void enic_set_mac_address(struct enic *enic, uint8_t *mac_addr);
34 -extern void enic_del_mac_address(struct enic *enic);
35 +void enic_set_mac_address(struct enic *enic, uint8_t *mac_addr);
36 +void enic_del_mac_address(struct enic *enic, int mac_index);
37  extern unsigned int enic_cleanup_wq(struct enic *enic, struct vnic_wq *wq);
38  extern void enic_send_pkt(struct enic *enic, struct vnic_wq *wq,
39                           struct rte_mbuf *tx_pkt, unsigned short len,
40 diff --git a/drivers/net/enic/enic_ethdev.c b/drivers/net/enic/enic_ethdev.c
41 index 2b154ec..d2d04a9 100644
42 --- a/drivers/net/enic/enic_ethdev.c
43 +++ b/drivers/net/enic/enic_ethdev.c
44 @@ -464,7 +464,7 @@ static void enicpmd_dev_info_get(struct rte_eth_dev *eth_dev,
45         device_info->max_tx_queues = enic->conf_wq_count;
46         device_info->min_rx_bufsize = ENIC_MIN_MTU;
47         device_info->max_rx_pktlen = enic->max_mtu + ETHER_HDR_LEN + 4;
48 -       device_info->max_mac_addrs = 1;
49 +       device_info->max_mac_addrs = ENIC_MAX_MAC_ADDR;
50         device_info->rx_offload_capa =
51                 DEV_RX_OFFLOAD_VLAN_STRIP |
52                 DEV_RX_OFFLOAD_IPV4_CKSUM |
53 @@ -545,12 +545,12 @@ static void enicpmd_add_mac_addr(struct rte_eth_dev *eth_dev,
54         enic_set_mac_address(enic, mac_addr->addr_bytes);
55  }
56  
57 -static void enicpmd_remove_mac_addr(struct rte_eth_dev *eth_dev, __rte_unused uint32_t index)
58 +static void enicpmd_remove_mac_addr(struct rte_eth_dev *eth_dev, uint32_t index)
59  {
60         struct enic *enic = pmd_priv(eth_dev);
61  
62         ENICPMD_FUNC_TRACE();
63 -       enic_del_mac_address(enic);
64 +       enic_del_mac_address(enic, index);
65  }
66  
67  static int enicpmd_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
68 diff --git a/drivers/net/enic/enic_main.c b/drivers/net/enic/enic_main.c
69 index f0b15ac..21e8ede 100644
70 --- a/drivers/net/enic/enic_main.c
71 +++ b/drivers/net/enic/enic_main.c
72 @@ -190,9 +190,12 @@ void enic_dev_stats_get(struct enic *enic, struct rte_eth_stats *r_stats)
73         r_stats->rx_nombuf = rte_atomic64_read(&soft_stats->rx_nombuf);
74  }
75  
76 -void enic_del_mac_address(struct enic *enic)
77 +void enic_del_mac_address(struct enic *enic, int mac_index)
78  {
79 -       if (vnic_dev_del_addr(enic->vdev, enic->mac_addr))
80 +       struct rte_eth_dev *eth_dev = enic->rte_dev;
81 +       uint8_t *mac_addr = eth_dev->data->mac_addrs[mac_index].addr_bytes;
82 +
83 +       if (vnic_dev_del_addr(enic->vdev, mac_addr))
84                 dev_err(enic, "del mac addr failed\n");
85  }
86  
87 @@ -205,15 +208,6 @@ void enic_set_mac_address(struct enic *enic, uint8_t *mac_addr)
88                 return;
89         }
90  
91 -       err = vnic_dev_del_addr(enic->vdev, enic->mac_addr);
92 -       if (err) {
93 -               dev_err(enic, "del mac addr failed\n");
94 -               return;
95 -       }
96 -
97 -       ether_addr_copy((struct ether_addr *)mac_addr,
98 -               (struct ether_addr *)enic->mac_addr);
99 -
100         err = vnic_dev_add_addr(enic->vdev, mac_addr);
101         if (err) {
102                 dev_err(enic, "add mac addr failed\n");
103 @@ -1308,13 +1302,14 @@ static int enic_dev_init(struct enic *enic)
104         /* Get the supported filters */
105         enic_fdir_info(enic);
106  
107 -       eth_dev->data->mac_addrs = rte_zmalloc("enic_mac_addr", ETH_ALEN, 0);
108 +       eth_dev->data->mac_addrs = rte_zmalloc("enic_mac_addr", ETH_ALEN
109 +                                               * ENIC_MAX_MAC_ADDR, 0);
110         if (!eth_dev->data->mac_addrs) {
111                 dev_err(enic, "mac addr storage alloc failed, aborting.\n");
112                 return -1;
113         }
114         ether_addr_copy((struct ether_addr *) enic->mac_addr,
115 -               &eth_dev->data->mac_addrs[0]);
116 +                       eth_dev->data->mac_addrs);
117  
118         vnic_dev_set_reset_flag(enic->vdev, 0);
119  
120 -- 
121 1.9.1
122