aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/intel/ice
diff options
context:
space:
mode:
authorAnirudh Venkataramanan <anirudh.venkataramanan@intel.com>2018-09-19 20:23:04 -0400
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>2018-10-01 15:39:40 -0400
commit45d3d428eafcbb18027c419624ce950b4db3a4b4 (patch)
treec33223eb6b3dca3b909a32fc09b284a0eee61ba4 /drivers/net/ethernet/intel/ice
parent3b6bf296c44f2b1233b7622c847a6ac5b1aeba0f (diff)
ice: Move common functions out of ice_main.c part 1/7
The functions that are used for PF VSI/netdev setup will also be used for SR-IOV support. To allow reuse of these functions, move these functions out of ice_main.c to ice_common.c/ice_lib.c This move is done across multiple patches. Each patch moves a few functions and may have minor adjustments. For example, a function that was previously static in ice_main.c will be made non-static temporarily in its new location to allow the driver to build cleanly. These adjustments will be removed in subsequent patches where more code is moved out of ice_main.c In this particular patch, the following functions were moved out of ice_main.c: int ice_add_mac_to_list ice_free_fltr_list ice_stat_update40 ice_stat_update32 ice_update_eth_stats ice_vsi_add_vlan ice_vsi_kill_vlan ice_vsi_manage_vlan_insertion ice_vsi_manage_vlan_stripping Signed-off-by: Anirudh Venkataramanan <anirudh.venkataramanan@intel.com> Tested-by: Andrew Bowers <andrewx.bowers@intel.com> Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Diffstat (limited to 'drivers/net/ethernet/intel/ice')
-rw-r--r--drivers/net/ethernet/intel/ice/Makefile1
-rw-r--r--drivers/net/ethernet/intel/ice/ice_common.c61
-rw-r--r--drivers/net/ethernet/intel/ice/ice_common.h4
-rw-r--r--drivers/net/ethernet/intel/ice/ice_lib.c258
-rw-r--r--drivers/net/ethernet/intel/ice/ice_lib.h23
-rw-r--r--drivers/net/ethernet/intel/ice/ice_main.c316
6 files changed, 348 insertions, 315 deletions
diff --git a/drivers/net/ethernet/intel/ice/Makefile b/drivers/net/ethernet/intel/ice/Makefile
index 4058673fd853..45125bd074d9 100644
--- a/drivers/net/ethernet/intel/ice/Makefile
+++ b/drivers/net/ethernet/intel/ice/Makefile
@@ -13,5 +13,6 @@ ice-y := ice_main.o \
13 ice_nvm.o \ 13 ice_nvm.o \
14 ice_switch.o \ 14 ice_switch.o \
15 ice_sched.o \ 15 ice_sched.o \
16 ice_lib.o \
16 ice_txrx.o \ 17 ice_txrx.o \
17 ice_ethtool.o 18 ice_ethtool.o
diff --git a/drivers/net/ethernet/intel/ice/ice_common.c b/drivers/net/ethernet/intel/ice/ice_common.c
index decfdb065a20..ef9229fa5510 100644
--- a/drivers/net/ethernet/intel/ice/ice_common.c
+++ b/drivers/net/ethernet/intel/ice/ice_common.c
@@ -2652,3 +2652,64 @@ ice_cfg_vsi_lan(struct ice_port_info *pi, u16 vsi_id, u8 tc_bitmap,
2652 return ice_cfg_vsi_qs(pi, vsi_id, tc_bitmap, max_lanqs, 2652 return ice_cfg_vsi_qs(pi, vsi_id, tc_bitmap, max_lanqs,
2653 ICE_SCHED_NODE_OWNER_LAN); 2653 ICE_SCHED_NODE_OWNER_LAN);
2654} 2654}
2655
2656/**
2657 * ice_stat_update40 - read 40 bit stat from the chip and update stat values
2658 * @hw: ptr to the hardware info
2659 * @hireg: high 32 bit HW register to read from
2660 * @loreg: low 32 bit HW register to read from
2661 * @prev_stat_loaded: bool to specify if previous stats are loaded
2662 * @prev_stat: ptr to previous loaded stat value
2663 * @cur_stat: ptr to current stat value
2664 */
2665void ice_stat_update40(struct ice_hw *hw, u32 hireg, u32 loreg,
2666 bool prev_stat_loaded, u64 *prev_stat, u64 *cur_stat)
2667{
2668 u64 new_data;
2669
2670 new_data = rd32(hw, loreg);
2671 new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
2672
2673 /* device stats are not reset at PFR, they likely will not be zeroed
2674 * when the driver starts. So save the first values read and use them as
2675 * offsets to be subtracted from the raw values in order to report stats
2676 * that count from zero.
2677 */
2678 if (!prev_stat_loaded)
2679 *prev_stat = new_data;
2680 if (new_data >= *prev_stat)
2681 *cur_stat = new_data - *prev_stat;
2682 else
2683 /* to manage the potential roll-over */
2684 *cur_stat = (new_data + BIT_ULL(40)) - *prev_stat;
2685 *cur_stat &= 0xFFFFFFFFFFULL;
2686}
2687
2688/**
2689 * ice_stat_update32 - read 32 bit stat from the chip and update stat values
2690 * @hw: ptr to the hardware info
2691 * @reg: HW register to read from
2692 * @prev_stat_loaded: bool to specify if previous stats are loaded
2693 * @prev_stat: ptr to previous loaded stat value
2694 * @cur_stat: ptr to current stat value
2695 */
2696void ice_stat_update32(struct ice_hw *hw, u32 reg, bool prev_stat_loaded,
2697 u64 *prev_stat, u64 *cur_stat)
2698{
2699 u32 new_data;
2700
2701 new_data = rd32(hw, reg);
2702
2703 /* device stats are not reset at PFR, they likely will not be zeroed
2704 * when the driver starts. So save the first values read and use them as
2705 * offsets to be subtracted from the raw values in order to report stats
2706 * that count from zero.
2707 */
2708 if (!prev_stat_loaded)
2709 *prev_stat = new_data;
2710 if (new_data >= *prev_stat)
2711 *cur_stat = new_data - *prev_stat;
2712 else
2713 /* to manage the potential roll-over */
2714 *cur_stat = (new_data + BIT_ULL(32)) - *prev_stat;
2715}
diff --git a/drivers/net/ethernet/intel/ice/ice_common.h b/drivers/net/ethernet/intel/ice/ice_common.h
index aac2d6cadaaf..80d288a07731 100644
--- a/drivers/net/ethernet/intel/ice/ice_common.h
+++ b/drivers/net/ethernet/intel/ice/ice_common.h
@@ -96,4 +96,8 @@ ice_ena_vsi_txq(struct ice_port_info *pi, u16 vsi_id, u8 tc, u8 num_qgrps,
96 struct ice_aqc_add_tx_qgrp *buf, u16 buf_size, 96 struct ice_aqc_add_tx_qgrp *buf, u16 buf_size,
97 struct ice_sq_cd *cd); 97 struct ice_sq_cd *cd);
98void ice_output_fw_log(struct ice_hw *hw, struct ice_aq_desc *desc, void *buf); 98void ice_output_fw_log(struct ice_hw *hw, struct ice_aq_desc *desc, void *buf);
99void ice_stat_update40(struct ice_hw *hw, u32 hireg, u32 loreg,
100 bool prev_stat_loaded, u64 *prev_stat, u64 *cur_stat);
101void ice_stat_update32(struct ice_hw *hw, u32 reg, bool prev_stat_loaded,
102 u64 *prev_stat, u64 *cur_stat);
99#endif /* _ICE_COMMON_H_ */ 103#endif /* _ICE_COMMON_H_ */
diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c
new file mode 100644
index 000000000000..1cf4dca12495
--- /dev/null
+++ b/drivers/net/ethernet/intel/ice/ice_lib.c
@@ -0,0 +1,258 @@
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2018, Intel Corporation. */
3
4#include "ice.h"
5#include "ice_lib.h"
6
7/**
8 * ice_add_mac_to_list - Add a mac address filter entry to the list
9 * @vsi: the VSI to be forwarded to
10 * @add_list: pointer to the list which contains MAC filter entries
11 * @macaddr: the MAC address to be added.
12 *
13 * Adds mac address filter entry to the temp list
14 *
15 * Returns 0 on success or ENOMEM on failure.
16 */
17int ice_add_mac_to_list(struct ice_vsi *vsi, struct list_head *add_list,
18 const u8 *macaddr)
19{
20 struct ice_fltr_list_entry *tmp;
21 struct ice_pf *pf = vsi->back;
22
23 tmp = devm_kzalloc(&pf->pdev->dev, sizeof(*tmp), GFP_ATOMIC);
24 if (!tmp)
25 return -ENOMEM;
26
27 tmp->fltr_info.flag = ICE_FLTR_TX;
28 tmp->fltr_info.src = vsi->vsi_num;
29 tmp->fltr_info.lkup_type = ICE_SW_LKUP_MAC;
30 tmp->fltr_info.fltr_act = ICE_FWD_TO_VSI;
31 tmp->fltr_info.fwd_id.vsi_id = vsi->vsi_num;
32 ether_addr_copy(tmp->fltr_info.l_data.mac.mac_addr, macaddr);
33
34 INIT_LIST_HEAD(&tmp->list_entry);
35 list_add(&tmp->list_entry, add_list);
36
37 return 0;
38}
39
40/**
41 * ice_update_eth_stats - Update VSI-specific ethernet statistics counters
42 * @vsi: the VSI to be updated
43 */
44void ice_update_eth_stats(struct ice_vsi *vsi)
45{
46 struct ice_eth_stats *prev_es, *cur_es;
47 struct ice_hw *hw = &vsi->back->hw;
48 u16 vsi_num = vsi->vsi_num; /* HW absolute index of a VSI */
49
50 prev_es = &vsi->eth_stats_prev;
51 cur_es = &vsi->eth_stats;
52
53 ice_stat_update40(hw, GLV_GORCH(vsi_num), GLV_GORCL(vsi_num),
54 vsi->stat_offsets_loaded, &prev_es->rx_bytes,
55 &cur_es->rx_bytes);
56
57 ice_stat_update40(hw, GLV_UPRCH(vsi_num), GLV_UPRCL(vsi_num),
58 vsi->stat_offsets_loaded, &prev_es->rx_unicast,
59 &cur_es->rx_unicast);
60
61 ice_stat_update40(hw, GLV_MPRCH(vsi_num), GLV_MPRCL(vsi_num),
62 vsi->stat_offsets_loaded, &prev_es->rx_multicast,
63 &cur_es->rx_multicast);
64
65 ice_stat_update40(hw, GLV_BPRCH(vsi_num), GLV_BPRCL(vsi_num),
66 vsi->stat_offsets_loaded, &prev_es->rx_broadcast,
67 &cur_es->rx_broadcast);
68
69 ice_stat_update32(hw, GLV_RDPC(vsi_num), vsi->stat_offsets_loaded,
70 &prev_es->rx_discards, &cur_es->rx_discards);
71
72 ice_stat_update40(hw, GLV_GOTCH(vsi_num), GLV_GOTCL(vsi_num),
73 vsi->stat_offsets_loaded, &prev_es->tx_bytes,
74 &cur_es->tx_bytes);
75
76 ice_stat_update40(hw, GLV_UPTCH(vsi_num), GLV_UPTCL(vsi_num),
77 vsi->stat_offsets_loaded, &prev_es->tx_unicast,
78 &cur_es->tx_unicast);
79
80 ice_stat_update40(hw, GLV_MPTCH(vsi_num), GLV_MPTCL(vsi_num),
81 vsi->stat_offsets_loaded, &prev_es->tx_multicast,
82 &cur_es->tx_multicast);
83
84 ice_stat_update40(hw, GLV_BPTCH(vsi_num), GLV_BPTCL(vsi_num),
85 vsi->stat_offsets_loaded, &prev_es->tx_broadcast,
86 &cur_es->tx_broadcast);
87
88 ice_stat_update32(hw, GLV_TEPC(vsi_num), vsi->stat_offsets_loaded,
89 &prev_es->tx_errors, &cur_es->tx_errors);
90
91 vsi->stat_offsets_loaded = true;
92}
93
94/**
95 * ice_free_fltr_list - free filter lists helper
96 * @dev: pointer to the device struct
97 * @h: pointer to the list head to be freed
98 *
99 * Helper function to free filter lists previously created using
100 * ice_add_mac_to_list
101 */
102void ice_free_fltr_list(struct device *dev, struct list_head *h)
103{
104 struct ice_fltr_list_entry *e, *tmp;
105
106 list_for_each_entry_safe(e, tmp, h, list_entry) {
107 list_del(&e->list_entry);
108 devm_kfree(dev, e);
109 }
110}
111
112/**
113 * ice_vsi_add_vlan - Add VSI membership for given VLAN
114 * @vsi: the VSI being configured
115 * @vid: VLAN id to be added
116 */
117int ice_vsi_add_vlan(struct ice_vsi *vsi, u16 vid)
118{
119 struct ice_fltr_list_entry *tmp;
120 struct ice_pf *pf = vsi->back;
121 LIST_HEAD(tmp_add_list);
122 enum ice_status status;
123 int err = 0;
124
125 tmp = devm_kzalloc(&pf->pdev->dev, sizeof(*tmp), GFP_KERNEL);
126 if (!tmp)
127 return -ENOMEM;
128
129 tmp->fltr_info.lkup_type = ICE_SW_LKUP_VLAN;
130 tmp->fltr_info.fltr_act = ICE_FWD_TO_VSI;
131 tmp->fltr_info.flag = ICE_FLTR_TX;
132 tmp->fltr_info.src = vsi->vsi_num;
133 tmp->fltr_info.fwd_id.vsi_id = vsi->vsi_num;
134 tmp->fltr_info.l_data.vlan.vlan_id = vid;
135
136 INIT_LIST_HEAD(&tmp->list_entry);
137 list_add(&tmp->list_entry, &tmp_add_list);
138
139 status = ice_add_vlan(&pf->hw, &tmp_add_list);
140 if (status) {
141 err = -ENODEV;
142 dev_err(&pf->pdev->dev, "Failure Adding VLAN %d on VSI %i\n",
143 vid, vsi->vsi_num);
144 }
145
146 ice_free_fltr_list(&pf->pdev->dev, &tmp_add_list);
147 return err;
148}
149
150/**
151 * ice_vsi_kill_vlan - Remove VSI membership for a given VLAN
152 * @vsi: the VSI being configured
153 * @vid: VLAN id to be removed
154 *
155 * Returns 0 on success and negative on failure
156 */
157int ice_vsi_kill_vlan(struct ice_vsi *vsi, u16 vid)
158{
159 struct ice_fltr_list_entry *list;
160 struct ice_pf *pf = vsi->back;
161 LIST_HEAD(tmp_add_list);
162 int status = 0;
163
164 list = devm_kzalloc(&pf->pdev->dev, sizeof(*list), GFP_KERNEL);
165 if (!list)
166 return -ENOMEM;
167
168 list->fltr_info.lkup_type = ICE_SW_LKUP_VLAN;
169 list->fltr_info.fwd_id.vsi_id = vsi->vsi_num;
170 list->fltr_info.fltr_act = ICE_FWD_TO_VSI;
171 list->fltr_info.l_data.vlan.vlan_id = vid;
172 list->fltr_info.flag = ICE_FLTR_TX;
173 list->fltr_info.src = vsi->vsi_num;
174
175 INIT_LIST_HEAD(&list->list_entry);
176 list_add(&list->list_entry, &tmp_add_list);
177
178 if (ice_remove_vlan(&pf->hw, &tmp_add_list)) {
179 dev_err(&pf->pdev->dev, "Error removing VLAN %d on vsi %i\n",
180 vid, vsi->vsi_num);
181 status = -EIO;
182 }
183
184 ice_free_fltr_list(&pf->pdev->dev, &tmp_add_list);
185 return status;
186}
187
188/**
189 * ice_vsi_manage_vlan_insertion - Manage VLAN insertion for the VSI for Tx
190 * @vsi: the VSI being changed
191 */
192int ice_vsi_manage_vlan_insertion(struct ice_vsi *vsi)
193{
194 struct device *dev = &vsi->back->pdev->dev;
195 struct ice_hw *hw = &vsi->back->hw;
196 struct ice_vsi_ctx ctxt = { 0 };
197 enum ice_status status;
198
199 /* Here we are configuring the VSI to let the driver add VLAN tags by
200 * setting vlan_flags to ICE_AQ_VSI_VLAN_MODE_ALL. The actual VLAN tag
201 * insertion happens in the Tx hot path, in ice_tx_map.
202 */
203 ctxt.info.vlan_flags = ICE_AQ_VSI_VLAN_MODE_ALL;
204
205 ctxt.info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID);
206 ctxt.vsi_num = vsi->vsi_num;
207
208 status = ice_aq_update_vsi(hw, &ctxt, NULL);
209 if (status) {
210 dev_err(dev, "update VSI for VLAN insert failed, err %d aq_err %d\n",
211 status, hw->adminq.sq_last_status);
212 return -EIO;
213 }
214
215 vsi->info.vlan_flags = ctxt.info.vlan_flags;
216 return 0;
217}
218
219/**
220 * ice_vsi_manage_vlan_stripping - Manage VLAN stripping for the VSI for Rx
221 * @vsi: the VSI being changed
222 * @ena: boolean value indicating if this is a enable or disable request
223 */
224int ice_vsi_manage_vlan_stripping(struct ice_vsi *vsi, bool ena)
225{
226 struct device *dev = &vsi->back->pdev->dev;
227 struct ice_hw *hw = &vsi->back->hw;
228 struct ice_vsi_ctx ctxt = { 0 };
229 enum ice_status status;
230
231 /* Here we are configuring what the VSI should do with the VLAN tag in
232 * the Rx packet. We can either leave the tag in the packet or put it in
233 * the Rx descriptor.
234 */
235 if (ena) {
236 /* Strip VLAN tag from Rx packet and put it in the desc */
237 ctxt.info.vlan_flags = ICE_AQ_VSI_VLAN_EMOD_STR_BOTH;
238 } else {
239 /* Disable stripping. Leave tag in packet */
240 ctxt.info.vlan_flags = ICE_AQ_VSI_VLAN_EMOD_NOTHING;
241 }
242
243 /* Allow all packets untagged/tagged */
244 ctxt.info.vlan_flags |= ICE_AQ_VSI_VLAN_MODE_ALL;
245
246 ctxt.info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID);
247 ctxt.vsi_num = vsi->vsi_num;
248
249 status = ice_aq_update_vsi(hw, &ctxt, NULL);
250 if (status) {
251 dev_err(dev, "update VSI for VLAN strip failed, ena = %d err %d aq_err %d\n",
252 ena, status, hw->adminq.sq_last_status);
253 return -EIO;
254 }
255
256 vsi->info.vlan_flags = ctxt.info.vlan_flags;
257 return 0;
258}
diff --git a/drivers/net/ethernet/intel/ice/ice_lib.h b/drivers/net/ethernet/intel/ice/ice_lib.h
new file mode 100644
index 000000000000..c10874d26eee
--- /dev/null
+++ b/drivers/net/ethernet/intel/ice/ice_lib.h
@@ -0,0 +1,23 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright (c) 2018, Intel Corporation. */
3
4#ifndef _ICE_LIB_H_
5#define _ICE_LIB_H_
6
7#include "ice.h"
8
9int ice_add_mac_to_list(struct ice_vsi *vsi, struct list_head *add_list,
10 const u8 *macaddr);
11
12void ice_free_fltr_list(struct device *dev, struct list_head *h);
13
14void ice_update_eth_stats(struct ice_vsi *vsi);
15
16int ice_vsi_add_vlan(struct ice_vsi *vsi, u16 vid);
17
18int ice_vsi_kill_vlan(struct ice_vsi *vsi, u16 vid);
19
20int ice_vsi_manage_vlan_insertion(struct ice_vsi *vsi);
21
22int ice_vsi_manage_vlan_stripping(struct ice_vsi *vsi, bool ena);
23#endif /* !_ICE_LIB_H_ */
diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c
index b02942efcaea..2673430ec2e9 100644
--- a/drivers/net/ethernet/intel/ice/ice_main.c
+++ b/drivers/net/ethernet/intel/ice/ice_main.c
@@ -6,6 +6,7 @@
6#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 6#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
7 7
8#include "ice.h" 8#include "ice.h"
9#include "ice_lib.h"
9 10
10#define DRV_VERSION "0.7.1-k" 11#define DRV_VERSION "0.7.1-k"
11#define DRV_SUMMARY "Intel(R) Ethernet Connection E800 Series Linux Driver" 12#define DRV_SUMMARY "Intel(R) Ethernet Connection E800 Series Linux Driver"
@@ -244,39 +245,6 @@ static int ice_free_res(struct ice_res_tracker *res, u16 index, u16 id)
244} 245}
245 246
246/** 247/**
247 * ice_add_mac_to_list - Add a mac address filter entry to the list
248 * @vsi: the VSI to be forwarded to
249 * @add_list: pointer to the list which contains MAC filter entries
250 * @macaddr: the MAC address to be added.
251 *
252 * Adds mac address filter entry to the temp list
253 *
254 * Returns 0 on success or ENOMEM on failure.
255 */
256static int ice_add_mac_to_list(struct ice_vsi *vsi, struct list_head *add_list,
257 const u8 *macaddr)
258{
259 struct ice_fltr_list_entry *tmp;
260 struct ice_pf *pf = vsi->back;
261
262 tmp = devm_kzalloc(&pf->pdev->dev, sizeof(*tmp), GFP_ATOMIC);
263 if (!tmp)
264 return -ENOMEM;
265
266 tmp->fltr_info.flag = ICE_FLTR_TX;
267 tmp->fltr_info.src = vsi->vsi_num;
268 tmp->fltr_info.lkup_type = ICE_SW_LKUP_MAC;
269 tmp->fltr_info.fltr_act = ICE_FWD_TO_VSI;
270 tmp->fltr_info.fwd_id.vsi_id = vsi->vsi_num;
271 ether_addr_copy(tmp->fltr_info.l_data.mac.mac_addr, macaddr);
272
273 INIT_LIST_HEAD(&tmp->list_entry);
274 list_add(&tmp->list_entry, add_list);
275
276 return 0;
277}
278
279/**
280 * ice_add_mac_to_sync_list - creates list of mac addresses to be synced 248 * ice_add_mac_to_sync_list - creates list of mac addresses to be synced
281 * @netdev: the net device on which the sync is happening 249 * @netdev: the net device on which the sync is happening
282 * @addr: mac address to sync 250 * @addr: mac address to sync
@@ -319,24 +287,6 @@ static int ice_add_mac_to_unsync_list(struct net_device *netdev, const u8 *addr)
319} 287}
320 288
321/** 289/**
322 * ice_free_fltr_list - free filter lists helper
323 * @dev: pointer to the device struct
324 * @h: pointer to the list head to be freed
325 *
326 * Helper function to free filter lists previously created using
327 * ice_add_mac_to_list
328 */
329static void ice_free_fltr_list(struct device *dev, struct list_head *h)
330{
331 struct ice_fltr_list_entry *e, *tmp;
332
333 list_for_each_entry_safe(e, tmp, h, list_entry) {
334 list_del(&e->list_entry);
335 devm_kfree(dev, e);
336 }
337}
338
339/**
340 * ice_vsi_fltr_changed - check if filter state changed 290 * ice_vsi_fltr_changed - check if filter state changed
341 * @vsi: VSI to be checked 291 * @vsi: VSI to be checked
342 * 292 *
@@ -3149,44 +3099,6 @@ ice_pf_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
3149} 3099}
3150 3100
3151/** 3101/**
3152 * ice_vsi_add_vlan - Add vsi membership for given vlan
3153 * @vsi: the vsi being configured
3154 * @vid: vlan id to be added
3155 */
3156static int ice_vsi_add_vlan(struct ice_vsi *vsi, u16 vid)
3157{
3158 struct ice_fltr_list_entry *tmp;
3159 struct ice_pf *pf = vsi->back;
3160 LIST_HEAD(tmp_add_list);
3161 enum ice_status status;
3162 int err = 0;
3163
3164 tmp = devm_kzalloc(&pf->pdev->dev, sizeof(*tmp), GFP_KERNEL);
3165 if (!tmp)
3166 return -ENOMEM;
3167
3168 tmp->fltr_info.lkup_type = ICE_SW_LKUP_VLAN;
3169 tmp->fltr_info.fltr_act = ICE_FWD_TO_VSI;
3170 tmp->fltr_info.flag = ICE_FLTR_TX;
3171 tmp->fltr_info.src = vsi->vsi_num;
3172 tmp->fltr_info.fwd_id.vsi_id = vsi->vsi_num;
3173 tmp->fltr_info.l_data.vlan.vlan_id = vid;
3174
3175 INIT_LIST_HEAD(&tmp->list_entry);
3176 list_add(&tmp->list_entry, &tmp_add_list);
3177
3178 status = ice_add_vlan(&pf->hw, &tmp_add_list);
3179 if (status) {
3180 err = -ENODEV;
3181 dev_err(&pf->pdev->dev, "Failure Adding VLAN %d on VSI %i\n",
3182 vid, vsi->vsi_num);
3183 }
3184
3185 ice_free_fltr_list(&pf->pdev->dev, &tmp_add_list);
3186 return err;
3187}
3188
3189/**
3190 * ice_vlan_rx_add_vid - Add a vlan id filter to HW offload 3102 * ice_vlan_rx_add_vid - Add a vlan id filter to HW offload
3191 * @netdev: network interface to be adjusted 3103 * @netdev: network interface to be adjusted
3192 * @proto: unused protocol 3104 * @proto: unused protocol
@@ -3230,44 +3142,6 @@ static int ice_vlan_rx_add_vid(struct net_device *netdev,
3230} 3142}
3231 3143
3232/** 3144/**
3233 * ice_vsi_kill_vlan - Remove VSI membership for a given VLAN
3234 * @vsi: the VSI being configured
3235 * @vid: VLAN id to be removed
3236 *
3237 * Returns 0 on success and negative on failure
3238 */
3239static int ice_vsi_kill_vlan(struct ice_vsi *vsi, u16 vid)
3240{
3241 struct ice_fltr_list_entry *list;
3242 struct ice_pf *pf = vsi->back;
3243 LIST_HEAD(tmp_add_list);
3244 int status = 0;
3245
3246 list = devm_kzalloc(&pf->pdev->dev, sizeof(*list), GFP_KERNEL);
3247 if (!list)
3248 return -ENOMEM;
3249
3250 list->fltr_info.lkup_type = ICE_SW_LKUP_VLAN;
3251 list->fltr_info.fwd_id.vsi_id = vsi->vsi_num;
3252 list->fltr_info.fltr_act = ICE_FWD_TO_VSI;
3253 list->fltr_info.l_data.vlan.vlan_id = vid;
3254 list->fltr_info.flag = ICE_FLTR_TX;
3255 list->fltr_info.src = vsi->vsi_num;
3256
3257 INIT_LIST_HEAD(&list->list_entry);
3258 list_add(&list->list_entry, &tmp_add_list);
3259
3260 if (ice_remove_vlan(&pf->hw, &tmp_add_list)) {
3261 dev_err(&pf->pdev->dev, "Error removing VLAN %d on vsi %i\n",
3262 vid, vsi->vsi_num);
3263 status = -EIO;
3264 }
3265
3266 ice_free_fltr_list(&pf->pdev->dev, &tmp_add_list);
3267 return status;
3268}
3269
3270/**
3271 * ice_vlan_rx_kill_vid - Remove a vlan id filter from HW offload 3145 * ice_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
3272 * @netdev: network interface to be adjusted 3146 * @netdev: network interface to be adjusted
3273 * @proto: unused protocol 3147 * @proto: unused protocol
@@ -4024,78 +3898,6 @@ static int ice_fdb_del(struct ndmsg *ndm, __always_unused struct nlattr *tb[],
4024} 3898}
4025 3899
4026/** 3900/**
4027 * ice_vsi_manage_vlan_insertion - Manage VLAN insertion for the VSI for Tx
4028 * @vsi: the vsi being changed
4029 */
4030static int ice_vsi_manage_vlan_insertion(struct ice_vsi *vsi)
4031{
4032 struct device *dev = &vsi->back->pdev->dev;
4033 struct ice_hw *hw = &vsi->back->hw;
4034 struct ice_vsi_ctx ctxt = { 0 };
4035 enum ice_status status;
4036
4037 /* Here we are configuring the VSI to let the driver add VLAN tags by
4038 * setting vlan_flags to ICE_AQ_VSI_VLAN_MODE_ALL. The actual VLAN tag
4039 * insertion happens in the Tx hot path, in ice_tx_map.
4040 */
4041 ctxt.info.vlan_flags = ICE_AQ_VSI_VLAN_MODE_ALL;
4042
4043 ctxt.info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID);
4044 ctxt.vsi_num = vsi->vsi_num;
4045
4046 status = ice_aq_update_vsi(hw, &ctxt, NULL);
4047 if (status) {
4048 dev_err(dev, "update VSI for VLAN insert failed, err %d aq_err %d\n",
4049 status, hw->adminq.sq_last_status);
4050 return -EIO;
4051 }
4052
4053 vsi->info.vlan_flags = ctxt.info.vlan_flags;
4054 return 0;
4055}
4056
4057/**
4058 * ice_vsi_manage_vlan_stripping - Manage VLAN stripping for the VSI for Rx
4059 * @vsi: the vsi being changed
4060 * @ena: boolean value indicating if this is a enable or disable request
4061 */
4062static int ice_vsi_manage_vlan_stripping(struct ice_vsi *vsi, bool ena)
4063{
4064 struct device *dev = &vsi->back->pdev->dev;
4065 struct ice_hw *hw = &vsi->back->hw;
4066 struct ice_vsi_ctx ctxt = { 0 };
4067 enum ice_status status;
4068
4069 /* Here we are configuring what the VSI should do with the VLAN tag in
4070 * the Rx packet. We can either leave the tag in the packet or put it in
4071 * the Rx descriptor.
4072 */
4073 if (ena) {
4074 /* Strip VLAN tag from Rx packet and put it in the desc */
4075 ctxt.info.vlan_flags = ICE_AQ_VSI_VLAN_EMOD_STR_BOTH;
4076 } else {
4077 /* Disable stripping. Leave tag in packet */
4078 ctxt.info.vlan_flags = ICE_AQ_VSI_VLAN_EMOD_NOTHING;
4079 }
4080
4081 /* Allow all packets untagged/tagged */
4082 ctxt.info.vlan_flags |= ICE_AQ_VSI_VLAN_MODE_ALL;
4083
4084 ctxt.info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID);
4085 ctxt.vsi_num = vsi->vsi_num;
4086
4087 status = ice_aq_update_vsi(hw, &ctxt, NULL);
4088 if (status) {
4089 dev_err(dev, "update VSI for VALN strip failed, ena = %d err %d aq_err %d\n",
4090 ena, status, hw->adminq.sq_last_status);
4091 return -EIO;
4092 }
4093
4094 vsi->info.vlan_flags = ctxt.info.vlan_flags;
4095 return 0;
4096}
4097
4098/**
4099 * ice_set_features - set the netdev feature flags 3901 * ice_set_features - set the netdev feature flags
4100 * @netdev: ptr to the netdev being adjusted 3902 * @netdev: ptr to the netdev being adjusted
4101 * @features: the feature set that the stack is suggesting 3903 * @features: the feature set that the stack is suggesting
@@ -4728,122 +4530,6 @@ static void ice_fetch_u64_stats_per_ring(struct ice_ring *ring, u64 *pkts,
4728} 4530}
4729 4531
4730/** 4532/**
4731 * ice_stat_update40 - read 40 bit stat from the chip and update stat values
4732 * @hw: ptr to the hardware info
4733 * @hireg: high 32 bit HW register to read from
4734 * @loreg: low 32 bit HW register to read from
4735 * @prev_stat_loaded: bool to specify if previous stats are loaded
4736 * @prev_stat: ptr to previous loaded stat value
4737 * @cur_stat: ptr to current stat value
4738 */
4739static void ice_stat_update40(struct ice_hw *hw, u32 hireg, u32 loreg,
4740 bool prev_stat_loaded, u64 *prev_stat,
4741 u64 *cur_stat)
4742{
4743 u64 new_data;
4744
4745 new_data = rd32(hw, loreg);
4746 new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
4747
4748 /* device stats are not reset at PFR, they likely will not be zeroed
4749 * when the driver starts. So save the first values read and use them as
4750 * offsets to be subtracted from the raw values in order to report stats
4751 * that count from zero.
4752 */
4753 if (!prev_stat_loaded)
4754 *prev_stat = new_data;
4755 if (likely(new_data >= *prev_stat))
4756 *cur_stat = new_data - *prev_stat;
4757 else
4758 /* to manage the potential roll-over */
4759 *cur_stat = (new_data + BIT_ULL(40)) - *prev_stat;
4760 *cur_stat &= 0xFFFFFFFFFFULL;
4761}
4762
4763/**
4764 * ice_stat_update32 - read 32 bit stat from the chip and update stat values
4765 * @hw: ptr to the hardware info
4766 * @reg: HW register to read from
4767 * @prev_stat_loaded: bool to specify if previous stats are loaded
4768 * @prev_stat: ptr to previous loaded stat value
4769 * @cur_stat: ptr to current stat value
4770 */
4771static void ice_stat_update32(struct ice_hw *hw, u32 reg, bool prev_stat_loaded,
4772 u64 *prev_stat, u64 *cur_stat)
4773{
4774 u32 new_data;
4775
4776 new_data = rd32(hw, reg);
4777
4778 /* device stats are not reset at PFR, they likely will not be zeroed
4779 * when the driver starts. So save the first values read and use them as
4780 * offsets to be subtracted from the raw values in order to report stats
4781 * that count from zero.
4782 */
4783 if (!prev_stat_loaded)
4784 *prev_stat = new_data;
4785 if (likely(new_data >= *prev_stat))
4786 *cur_stat = new_data - *prev_stat;
4787 else
4788 /* to manage the potential roll-over */
4789 *cur_stat = (new_data + BIT_ULL(32)) - *prev_stat;
4790}
4791
4792/**
4793 * ice_update_eth_stats - Update VSI-specific ethernet statistics counters
4794 * @vsi: the VSI to be updated
4795 */
4796static void ice_update_eth_stats(struct ice_vsi *vsi)
4797{
4798 struct ice_eth_stats *prev_es, *cur_es;
4799 struct ice_hw *hw = &vsi->back->hw;
4800 u16 vsi_num = vsi->vsi_num; /* HW absolute index of a VSI */
4801
4802 prev_es = &vsi->eth_stats_prev;
4803 cur_es = &vsi->eth_stats;
4804
4805 ice_stat_update40(hw, GLV_GORCH(vsi_num), GLV_GORCL(vsi_num),
4806 vsi->stat_offsets_loaded, &prev_es->rx_bytes,
4807 &cur_es->rx_bytes);
4808
4809 ice_stat_update40(hw, GLV_UPRCH(vsi_num), GLV_UPRCL(vsi_num),
4810 vsi->stat_offsets_loaded, &prev_es->rx_unicast,
4811 &cur_es->rx_unicast);
4812
4813 ice_stat_update40(hw, GLV_MPRCH(vsi_num), GLV_MPRCL(vsi_num),
4814 vsi->stat_offsets_loaded, &prev_es->rx_multicast,
4815 &cur_es->rx_multicast);
4816
4817 ice_stat_update40(hw, GLV_BPRCH(vsi_num), GLV_BPRCL(vsi_num),
4818 vsi->stat_offsets_loaded, &prev_es->rx_broadcast,
4819 &cur_es->rx_broadcast);
4820
4821 ice_stat_update32(hw, GLV_RDPC(vsi_num), vsi->stat_offsets_loaded,
4822 &prev_es->rx_discards, &cur_es->rx_discards);
4823
4824 ice_stat_update40(hw, GLV_GOTCH(vsi_num), GLV_GOTCL(vsi_num),
4825 vsi->stat_offsets_loaded, &prev_es->tx_bytes,
4826 &cur_es->tx_bytes);
4827
4828 ice_stat_update40(hw, GLV_UPTCH(vsi_num), GLV_UPTCL(vsi_num),
4829 vsi->stat_offsets_loaded, &prev_es->tx_unicast,
4830 &cur_es->tx_unicast);
4831
4832 ice_stat_update40(hw, GLV_MPTCH(vsi_num), GLV_MPTCL(vsi_num),
4833 vsi->stat_offsets_loaded, &prev_es->tx_multicast,
4834 &cur_es->tx_multicast);
4835
4836 ice_stat_update40(hw, GLV_BPTCH(vsi_num), GLV_BPTCL(vsi_num),
4837 vsi->stat_offsets_loaded, &prev_es->tx_broadcast,
4838 &cur_es->tx_broadcast);
4839
4840 ice_stat_update32(hw, GLV_TEPC(vsi_num), vsi->stat_offsets_loaded,
4841 &prev_es->tx_errors, &cur_es->tx_errors);
4842
4843 vsi->stat_offsets_loaded = true;
4844}
4845
4846/**
4847 * ice_update_vsi_ring_stats - Update VSI stats counters 4533 * ice_update_vsi_ring_stats - Update VSI stats counters
4848 * @vsi: the VSI to be updated 4534 * @vsi: the VSI to be updated
4849 */ 4535 */