]>
Commit | Line | Data |
---|---|---|
17367270 GR |
1 | /******************************************************************************* |
2 | ||
3 | Intel 10 Gigabit PCI Express Linux driver | |
94971820 | 4 | Copyright(c) 1999 - 2012 Intel Corporation. |
17367270 GR |
5 | |
6 | This program is free software; you can redistribute it and/or modify it | |
7 | under the terms and conditions of the GNU General Public License, | |
8 | version 2, as published by the Free Software Foundation. | |
9 | ||
10 | This program is distributed in the hope it will be useful, but WITHOUT | |
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License along with | |
16 | this program; if not, write to the Free Software Foundation, Inc., | |
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | |
18 | ||
19 | The full GNU General Public License is included in this distribution in | |
20 | the file called "COPYING". | |
21 | ||
22 | Contact Information: | |
23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | |
24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | |
25 | ||
26 | *******************************************************************************/ | |
27 | ||
17367270 GR |
28 | #include <linux/types.h> |
29 | #include <linux/module.h> | |
30 | #include <linux/pci.h> | |
31 | #include <linux/netdevice.h> | |
32 | #include <linux/vmalloc.h> | |
33 | #include <linux/string.h> | |
34 | #include <linux/in.h> | |
35 | #include <linux/ip.h> | |
36 | #include <linux/tcp.h> | |
37 | #include <linux/ipv6.h> | |
38 | #ifdef NETIF_F_HW_VLAN_TX | |
39 | #include <linux/if_vlan.h> | |
40 | #endif | |
41 | ||
42 | #include "ixgbe.h" | |
c6bda30a | 43 | #include "ixgbe_type.h" |
17367270 GR |
44 | #include "ixgbe_sriov.h" |
45 | ||
c6bda30a GR |
46 | #ifdef CONFIG_PCI_IOV |
47 | static int ixgbe_find_enabled_vfs(struct ixgbe_adapter *adapter) | |
48 | { | |
49 | struct pci_dev *pdev = adapter->pdev; | |
50 | struct pci_dev *pvfdev; | |
51 | u16 vf_devfn = 0; | |
52 | int device_id; | |
53 | int vfs_found = 0; | |
54 | ||
55 | switch (adapter->hw.mac.type) { | |
56 | case ixgbe_mac_82599EB: | |
57 | device_id = IXGBE_DEV_ID_82599_VF; | |
58 | break; | |
59 | case ixgbe_mac_X540: | |
60 | device_id = IXGBE_DEV_ID_X540_VF; | |
61 | break; | |
62 | default: | |
63 | device_id = 0; | |
64 | break; | |
65 | } | |
66 | ||
67 | vf_devfn = pdev->devfn + 0x80; | |
36e90319 | 68 | pvfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL); |
c6bda30a | 69 | while (pvfdev) { |
a4b08329 GR |
70 | if (pvfdev->devfn == vf_devfn && |
71 | (pvfdev->bus->number >= pdev->bus->number)) | |
c6bda30a GR |
72 | vfs_found++; |
73 | vf_devfn += 2; | |
36e90319 | 74 | pvfdev = pci_get_device(PCI_VENDOR_ID_INTEL, |
c6bda30a GR |
75 | device_id, pvfdev); |
76 | } | |
77 | ||
78 | return vfs_found; | |
79 | } | |
80 | ||
81 | void ixgbe_enable_sriov(struct ixgbe_adapter *adapter, | |
82 | const struct ixgbe_info *ii) | |
83 | { | |
84 | struct ixgbe_hw *hw = &adapter->hw; | |
85 | int err = 0; | |
86 | int num_vf_macvlans, i; | |
87 | struct vf_macvlans *mv_list; | |
88 | int pre_existing_vfs = 0; | |
89 | ||
90 | pre_existing_vfs = ixgbe_find_enabled_vfs(adapter); | |
91 | if (!pre_existing_vfs && !adapter->num_vfs) | |
92 | return; | |
93 | ||
94 | /* If there are pre-existing VFs then we have to force | |
95 | * use of that many because they were not deleted the last | |
96 | * time someone removed the PF driver. That would have | |
97 | * been because they were allocated to guest VMs and can't | |
98 | * be removed. Go ahead and just re-enable the old amount. | |
99 | * If the user wants to change the number of VFs they can | |
100 | * use ethtool while making sure no VFs are allocated to | |
101 | * guest VMs... i.e. the right way. | |
102 | */ | |
103 | if (pre_existing_vfs) { | |
104 | adapter->num_vfs = pre_existing_vfs; | |
105 | dev_warn(&adapter->pdev->dev, "Virtual Functions already " | |
106 | "enabled for this device - Please reload all " | |
107 | "VF drivers to avoid spoofed packet errors\n"); | |
108 | } else { | |
109 | err = pci_enable_sriov(adapter->pdev, adapter->num_vfs); | |
73079ea0 AD |
110 | if (err) { |
111 | e_err(probe, "Failed to enable PCI sriov: %d\n", err); | |
112 | goto err_novfs; | |
113 | } | |
c6bda30a | 114 | } |
c6bda30a | 115 | |
73079ea0 | 116 | adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED; |
c6bda30a GR |
117 | e_info(probe, "SR-IOV enabled with %d VFs\n", adapter->num_vfs); |
118 | ||
73079ea0 AD |
119 | /* Enable VMDq flag so device will be set in VM mode */ |
120 | adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED; | |
121 | if (!adapter->ring_feature[RING_F_VMDQ].limit) | |
122 | adapter->ring_feature[RING_F_VMDQ].limit = 1; | |
123 | adapter->ring_feature[RING_F_VMDQ].offset = adapter->num_vfs; | |
124 | ||
c6bda30a GR |
125 | num_vf_macvlans = hw->mac.num_rar_entries - |
126 | (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs); | |
127 | ||
128 | adapter->mv_list = mv_list = kcalloc(num_vf_macvlans, | |
129 | sizeof(struct vf_macvlans), | |
130 | GFP_KERNEL); | |
131 | if (mv_list) { | |
132 | /* Initialize list of VF macvlans */ | |
133 | INIT_LIST_HEAD(&adapter->vf_mvs.l); | |
134 | for (i = 0; i < num_vf_macvlans; i++) { | |
135 | mv_list->vf = -1; | |
136 | mv_list->free = true; | |
137 | mv_list->rar_entry = hw->mac.num_rar_entries - | |
138 | (i + adapter->num_vfs + 1); | |
139 | list_add(&mv_list->l, &adapter->vf_mvs.l); | |
140 | mv_list++; | |
141 | } | |
142 | } | |
143 | ||
144 | /* If call to enable VFs succeeded then allocate memory | |
145 | * for per VF control structures. | |
146 | */ | |
147 | adapter->vfinfo = | |
148 | kcalloc(adapter->num_vfs, | |
149 | sizeof(struct vf_data_storage), GFP_KERNEL); | |
150 | if (adapter->vfinfo) { | |
151 | /* Now that we're sure SR-IOV is enabled | |
152 | * and memory allocated set up the mailbox parameters | |
153 | */ | |
154 | ixgbe_init_mbx_params_pf(hw); | |
73079ea0 AD |
155 | memcpy(&hw->mbx.ops, ii->mbx_ops, sizeof(hw->mbx.ops)); |
156 | ||
157 | /* limit trafffic classes based on VFs enabled */ | |
158 | if ((adapter->hw.mac.type == ixgbe_mac_82599EB) && | |
159 | (adapter->num_vfs < 16)) { | |
160 | adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS; | |
161 | adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS; | |
162 | } else if (adapter->num_vfs < 32) { | |
163 | adapter->dcb_cfg.num_tcs.pg_tcs = 4; | |
164 | adapter->dcb_cfg.num_tcs.pfc_tcs = 4; | |
165 | } else { | |
166 | adapter->dcb_cfg.num_tcs.pg_tcs = 1; | |
167 | adapter->dcb_cfg.num_tcs.pfc_tcs = 1; | |
168 | } | |
169 | ||
170 | /* We do not support RSS w/ SR-IOV */ | |
171 | adapter->ring_feature[RING_F_RSS].limit = 1; | |
c6bda30a GR |
172 | |
173 | /* Disable RSC when in SR-IOV mode */ | |
174 | adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE | | |
175 | IXGBE_FLAG2_RSC_ENABLED); | |
73079ea0 AD |
176 | |
177 | #ifdef IXGBE_FCOE | |
178 | /* | |
179 | * When SR-IOV is enabled 82599 cannot support jumbo frames | |
180 | * so we must disable FCoE because we cannot support FCoE MTU. | |
181 | */ | |
182 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) | |
183 | adapter->flags &= ~(IXGBE_FLAG_FCOE_ENABLED | | |
184 | IXGBE_FLAG_FCOE_CAPABLE); | |
185 | #endif | |
186 | ||
187 | /* enable spoof checking for all VFs */ | |
de4c7f65 GR |
188 | for (i = 0; i < adapter->num_vfs; i++) |
189 | adapter->vfinfo[i].spoofchk_enabled = true; | |
c6bda30a GR |
190 | return; |
191 | } | |
192 | ||
193 | /* Oh oh */ | |
194 | e_err(probe, "Unable to allocate memory for VF Data Storage - " | |
195 | "SRIOV disabled\n"); | |
196 | pci_disable_sriov(adapter->pdev); | |
197 | ||
198 | err_novfs: | |
199 | adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED; | |
200 | adapter->num_vfs = 0; | |
201 | } | |
202 | #endif /* #ifdef CONFIG_PCI_IOV */ | |
203 | ||
204 | void ixgbe_disable_sriov(struct ixgbe_adapter *adapter) | |
205 | { | |
206 | struct ixgbe_hw *hw = &adapter->hw; | |
c6bda30a GR |
207 | u32 gpie; |
208 | u32 vmdctl; | |
209 | int i; | |
210 | ||
211 | #ifdef CONFIG_PCI_IOV | |
212 | /* disable iov and allow time for transactions to clear */ | |
213 | pci_disable_sriov(adapter->pdev); | |
214 | #endif | |
215 | ||
216 | /* turn off device IOV mode */ | |
73079ea0 | 217 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, 0); |
c6bda30a GR |
218 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
219 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; | |
220 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); | |
221 | ||
222 | /* set default pool back to 0 */ | |
223 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); | |
224 | vmdctl &= ~IXGBE_VT_CTL_POOL_MASK; | |
225 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl); | |
226 | IXGBE_WRITE_FLUSH(hw); | |
227 | ||
228 | /* take a breather then clean up driver data */ | |
229 | msleep(100); | |
230 | ||
231 | /* Release reference to VF devices */ | |
232 | for (i = 0; i < adapter->num_vfs; i++) { | |
233 | if (adapter->vfinfo[i].vfdev) | |
234 | pci_dev_put(adapter->vfinfo[i].vfdev); | |
235 | } | |
236 | kfree(adapter->vfinfo); | |
237 | kfree(adapter->mv_list); | |
238 | adapter->vfinfo = NULL; | |
239 | ||
240 | adapter->num_vfs = 0; | |
241 | adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED; | |
242 | } | |
243 | ||
5d5b7c39 ET |
244 | static int ixgbe_set_vf_multicasts(struct ixgbe_adapter *adapter, |
245 | int entries, u16 *hash_list, u32 vf) | |
17367270 GR |
246 | { |
247 | struct vf_data_storage *vfinfo = &adapter->vfinfo[vf]; | |
8a07a22d | 248 | struct ixgbe_hw *hw = &adapter->hw; |
17367270 | 249 | int i; |
8a07a22d GR |
250 | u32 vector_bit; |
251 | u32 vector_reg; | |
252 | u32 mta_reg; | |
17367270 GR |
253 | |
254 | /* only so many hash values supported */ | |
255 | entries = min(entries, IXGBE_MAX_VF_MC_ENTRIES); | |
256 | ||
257 | /* | |
258 | * salt away the number of multi cast addresses assigned | |
259 | * to this VF for later use to restore when the PF multi cast | |
260 | * list changes | |
261 | */ | |
262 | vfinfo->num_vf_mc_hashes = entries; | |
263 | ||
264 | /* | |
265 | * VFs are limited to using the MTA hash table for their multicast | |
266 | * addresses | |
267 | */ | |
268 | for (i = 0; i < entries; i++) { | |
e81a1ba8 | 269 | vfinfo->vf_mc_hashes[i] = hash_list[i]; |
17367270 GR |
270 | } |
271 | ||
8a07a22d GR |
272 | for (i = 0; i < vfinfo->num_vf_mc_hashes; i++) { |
273 | vector_reg = (vfinfo->vf_mc_hashes[i] >> 5) & 0x7F; | |
274 | vector_bit = vfinfo->vf_mc_hashes[i] & 0x1F; | |
275 | mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg)); | |
276 | mta_reg |= (1 << vector_bit); | |
277 | IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg); | |
278 | } | |
17367270 GR |
279 | |
280 | return 0; | |
281 | } | |
282 | ||
a1cbb15c GR |
283 | static void ixgbe_restore_vf_macvlans(struct ixgbe_adapter *adapter) |
284 | { | |
285 | struct ixgbe_hw *hw = &adapter->hw; | |
286 | struct list_head *pos; | |
287 | struct vf_macvlans *entry; | |
288 | ||
289 | list_for_each(pos, &adapter->vf_mvs.l) { | |
290 | entry = list_entry(pos, struct vf_macvlans, l); | |
23677ce3 | 291 | if (!entry->free) |
a1cbb15c GR |
292 | hw->mac.ops.set_rar(hw, entry->rar_entry, |
293 | entry->vf_macvlan, | |
294 | entry->vf, IXGBE_RAH_AV); | |
295 | } | |
296 | } | |
297 | ||
17367270 GR |
298 | void ixgbe_restore_vf_multicasts(struct ixgbe_adapter *adapter) |
299 | { | |
300 | struct ixgbe_hw *hw = &adapter->hw; | |
301 | struct vf_data_storage *vfinfo; | |
302 | int i, j; | |
303 | u32 vector_bit; | |
304 | u32 vector_reg; | |
305 | u32 mta_reg; | |
306 | ||
307 | for (i = 0; i < adapter->num_vfs; i++) { | |
308 | vfinfo = &adapter->vfinfo[i]; | |
309 | for (j = 0; j < vfinfo->num_vf_mc_hashes; j++) { | |
310 | hw->addr_ctrl.mta_in_use++; | |
311 | vector_reg = (vfinfo->vf_mc_hashes[j] >> 5) & 0x7F; | |
312 | vector_bit = vfinfo->vf_mc_hashes[j] & 0x1F; | |
313 | mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg)); | |
314 | mta_reg |= (1 << vector_bit); | |
315 | IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg); | |
316 | } | |
317 | } | |
a1cbb15c GR |
318 | |
319 | /* Restore any VF macvlans */ | |
320 | ixgbe_restore_vf_macvlans(adapter); | |
17367270 GR |
321 | } |
322 | ||
5d5b7c39 ET |
323 | static int ixgbe_set_vf_vlan(struct ixgbe_adapter *adapter, int add, int vid, |
324 | u32 vf) | |
17367270 | 325 | { |
17367270 GR |
326 | return adapter->hw.mac.ops.set_vfta(&adapter->hw, vid, vf, (bool)add); |
327 | } | |
328 | ||
b32c8dcc | 329 | static void ixgbe_set_vf_lpe(struct ixgbe_adapter *adapter, u32 *msgbuf) |
e9f98072 GR |
330 | { |
331 | struct ixgbe_hw *hw = &adapter->hw; | |
332 | int new_mtu = msgbuf[1]; | |
333 | u32 max_frs; | |
334 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; | |
335 | ||
336 | /* Only X540 supports jumbo frames in IOV mode */ | |
337 | if (adapter->hw.mac.type != ixgbe_mac_X540) | |
338 | return; | |
339 | ||
340 | /* MTU < 68 is an error and causes problems on some kernels */ | |
341 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) { | |
342 | e_err(drv, "VF mtu %d out of range\n", new_mtu); | |
343 | return; | |
344 | } | |
345 | ||
346 | max_frs = (IXGBE_READ_REG(hw, IXGBE_MAXFRS) & | |
347 | IXGBE_MHADD_MFS_MASK) >> IXGBE_MHADD_MFS_SHIFT; | |
348 | if (max_frs < new_mtu) { | |
349 | max_frs = new_mtu << IXGBE_MHADD_MFS_SHIFT; | |
350 | IXGBE_WRITE_REG(hw, IXGBE_MAXFRS, max_frs); | |
351 | } | |
352 | ||
353 | e_info(hw, "VF requests change max MTU to %d\n", new_mtu); | |
354 | } | |
355 | ||
5d5b7c39 | 356 | static void ixgbe_set_vmolr(struct ixgbe_hw *hw, u32 vf, bool aupe) |
17367270 GR |
357 | { |
358 | u32 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf)); | |
f0412776 | 359 | vmolr |= (IXGBE_VMOLR_ROMPE | |
17367270 | 360 | IXGBE_VMOLR_BAM); |
f0412776 GR |
361 | if (aupe) |
362 | vmolr |= IXGBE_VMOLR_AUPE; | |
363 | else | |
364 | vmolr &= ~IXGBE_VMOLR_AUPE; | |
17367270 GR |
365 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr); |
366 | } | |
367 | ||
7f01648a GR |
368 | static void ixgbe_set_vmvir(struct ixgbe_adapter *adapter, u32 vid, u32 vf) |
369 | { | |
370 | struct ixgbe_hw *hw = &adapter->hw; | |
371 | ||
372 | if (vid) | |
373 | IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf), | |
374 | (vid | IXGBE_VMVIR_VLANA_DEFAULT)); | |
375 | else | |
376 | IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf), 0); | |
377 | } | |
378 | ||
5d5b7c39 | 379 | static inline void ixgbe_vf_reset_event(struct ixgbe_adapter *adapter, u32 vf) |
17367270 GR |
380 | { |
381 | struct ixgbe_hw *hw = &adapter->hw; | |
2850062a | 382 | int rar_entry = hw->mac.num_rar_entries - (vf + 1); |
17367270 GR |
383 | |
384 | /* reset offloads to defaults */ | |
7f01648a GR |
385 | if (adapter->vfinfo[vf].pf_vlan) { |
386 | ixgbe_set_vf_vlan(adapter, true, | |
387 | adapter->vfinfo[vf].pf_vlan, vf); | |
388 | ixgbe_set_vmvir(adapter, | |
389 | (adapter->vfinfo[vf].pf_vlan | | |
390 | (adapter->vfinfo[vf].pf_qos << | |
391 | VLAN_PRIO_SHIFT)), vf); | |
392 | ixgbe_set_vmolr(hw, vf, false); | |
393 | } else { | |
394 | ixgbe_set_vmvir(adapter, 0, vf); | |
395 | ixgbe_set_vmolr(hw, vf, true); | |
396 | } | |
17367270 GR |
397 | |
398 | /* reset multicast table array for vf */ | |
399 | adapter->vfinfo[vf].num_vf_mc_hashes = 0; | |
400 | ||
401 | /* Flush and reset the mta with the new values */ | |
402 | ixgbe_set_rx_mode(adapter->netdev); | |
403 | ||
2850062a | 404 | hw->mac.ops.clear_rar(hw, rar_entry); |
17367270 GR |
405 | } |
406 | ||
5d5b7c39 ET |
407 | static int ixgbe_set_vf_mac(struct ixgbe_adapter *adapter, |
408 | int vf, unsigned char *mac_addr) | |
17367270 GR |
409 | { |
410 | struct ixgbe_hw *hw = &adapter->hw; | |
2850062a | 411 | int rar_entry = hw->mac.num_rar_entries - (vf + 1); |
17367270 GR |
412 | |
413 | memcpy(adapter->vfinfo[vf].vf_mac_addresses, mac_addr, 6); | |
2850062a | 414 | hw->mac.ops.set_rar(hw, rar_entry, mac_addr, vf, IXGBE_RAH_AV); |
17367270 GR |
415 | |
416 | return 0; | |
417 | } | |
418 | ||
a1cbb15c GR |
419 | static int ixgbe_set_vf_macvlan(struct ixgbe_adapter *adapter, |
420 | int vf, int index, unsigned char *mac_addr) | |
421 | { | |
422 | struct ixgbe_hw *hw = &adapter->hw; | |
423 | struct list_head *pos; | |
424 | struct vf_macvlans *entry; | |
425 | ||
426 | if (index <= 1) { | |
427 | list_for_each(pos, &adapter->vf_mvs.l) { | |
428 | entry = list_entry(pos, struct vf_macvlans, l); | |
429 | if (entry->vf == vf) { | |
430 | entry->vf = -1; | |
431 | entry->free = true; | |
432 | entry->is_macvlan = false; | |
433 | hw->mac.ops.clear_rar(hw, entry->rar_entry); | |
434 | } | |
435 | } | |
436 | } | |
437 | ||
438 | /* | |
439 | * If index was zero then we were asked to clear the uc list | |
440 | * for the VF. We're done. | |
441 | */ | |
442 | if (!index) | |
443 | return 0; | |
444 | ||
445 | entry = NULL; | |
446 | ||
447 | list_for_each(pos, &adapter->vf_mvs.l) { | |
448 | entry = list_entry(pos, struct vf_macvlans, l); | |
449 | if (entry->free) | |
450 | break; | |
451 | } | |
452 | ||
453 | /* | |
454 | * If we traversed the entire list and didn't find a free entry | |
455 | * then we're out of space on the RAR table. Also entry may | |
456 | * be NULL because the original memory allocation for the list | |
457 | * failed, which is not fatal but does mean we can't support | |
458 | * VF requests for MACVLAN because we couldn't allocate | |
459 | * memory for the list management required. | |
460 | */ | |
461 | if (!entry || !entry->free) | |
462 | return -ENOSPC; | |
463 | ||
464 | entry->free = false; | |
465 | entry->is_macvlan = true; | |
466 | entry->vf = vf; | |
467 | memcpy(entry->vf_macvlan, mac_addr, ETH_ALEN); | |
468 | ||
469 | hw->mac.ops.set_rar(hw, entry->rar_entry, mac_addr, vf, IXGBE_RAH_AV); | |
470 | ||
471 | return 0; | |
472 | } | |
473 | ||
c6bda30a GR |
474 | int ixgbe_check_vf_assignment(struct ixgbe_adapter *adapter) |
475 | { | |
01264108 | 476 | #ifdef CONFIG_PCI_IOV |
c6bda30a GR |
477 | int i; |
478 | for (i = 0; i < adapter->num_vfs; i++) { | |
479 | if (adapter->vfinfo[i].vfdev->dev_flags & | |
480 | PCI_DEV_FLAGS_ASSIGNED) | |
481 | return true; | |
482 | } | |
01264108 | 483 | #endif |
c6bda30a GR |
484 | return false; |
485 | } | |
486 | ||
17367270 GR |
487 | int ixgbe_vf_configuration(struct pci_dev *pdev, unsigned int event_mask) |
488 | { | |
489 | unsigned char vf_mac_addr[6]; | |
c60fbb00 | 490 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
17367270 | 491 | unsigned int vfn = (event_mask & 0x3f); |
c6bda30a GR |
492 | struct pci_dev *pvfdev; |
493 | unsigned int device_id; | |
494 | u16 thisvf_devfn = (pdev->devfn + 0x80 + (vfn << 1)) | | |
495 | (pdev->devfn & 1); | |
17367270 GR |
496 | |
497 | bool enable = ((event_mask & 0x10000000U) != 0); | |
498 | ||
499 | if (enable) { | |
7efd26d0 | 500 | eth_random_addr(vf_mac_addr); |
396e799c ET |
501 | e_info(probe, "IOV: VF %d is enabled MAC %pM\n", |
502 | vfn, vf_mac_addr); | |
17367270 GR |
503 | /* |
504 | * Store away the VF "permananet" MAC address, it will ask | |
505 | * for it later. | |
506 | */ | |
507 | memcpy(adapter->vfinfo[vfn].vf_mac_addresses, vf_mac_addr, 6); | |
c6bda30a GR |
508 | |
509 | switch (adapter->hw.mac.type) { | |
510 | case ixgbe_mac_82599EB: | |
511 | device_id = IXGBE_DEV_ID_82599_VF; | |
512 | break; | |
513 | case ixgbe_mac_X540: | |
514 | device_id = IXGBE_DEV_ID_X540_VF; | |
515 | break; | |
516 | default: | |
517 | device_id = 0; | |
518 | break; | |
519 | } | |
520 | ||
36e90319 | 521 | pvfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL); |
c6bda30a GR |
522 | while (pvfdev) { |
523 | if (pvfdev->devfn == thisvf_devfn) | |
524 | break; | |
36e90319 | 525 | pvfdev = pci_get_device(PCI_VENDOR_ID_INTEL, |
c6bda30a GR |
526 | device_id, pvfdev); |
527 | } | |
528 | if (pvfdev) | |
529 | adapter->vfinfo[vfn].vfdev = pvfdev; | |
530 | else | |
531 | e_err(drv, "Couldn't find pci dev ptr for VF %4.4x\n", | |
532 | thisvf_devfn); | |
17367270 GR |
533 | } |
534 | ||
535 | return 0; | |
536 | } | |
537 | ||
5d5b7c39 | 538 | static inline void ixgbe_vf_reset_msg(struct ixgbe_adapter *adapter, u32 vf) |
17367270 GR |
539 | { |
540 | struct ixgbe_hw *hw = &adapter->hw; | |
541 | u32 reg; | |
542 | u32 reg_offset, vf_shift; | |
543 | ||
544 | vf_shift = vf % 32; | |
545 | reg_offset = vf / 32; | |
546 | ||
547 | /* enable transmit and receive for vf */ | |
548 | reg = IXGBE_READ_REG(hw, IXGBE_VFTE(reg_offset)); | |
549 | reg |= (reg | (1 << vf_shift)); | |
550 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), reg); | |
551 | ||
552 | reg = IXGBE_READ_REG(hw, IXGBE_VFRE(reg_offset)); | |
553 | reg |= (reg | (1 << vf_shift)); | |
554 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), reg); | |
555 | ||
a985b6c3 GR |
556 | /* Enable counting of spoofed packets in the SSVPC register */ |
557 | reg = IXGBE_READ_REG(hw, IXGBE_VMECM(reg_offset)); | |
558 | reg |= (1 << vf_shift); | |
559 | IXGBE_WRITE_REG(hw, IXGBE_VMECM(reg_offset), reg); | |
560 | ||
17367270 GR |
561 | ixgbe_vf_reset_event(adapter, vf); |
562 | } | |
563 | ||
564 | static int ixgbe_rcv_msg_from_vf(struct ixgbe_adapter *adapter, u32 vf) | |
565 | { | |
566 | u32 mbx_size = IXGBE_VFMAILBOX_SIZE; | |
c050999e | 567 | u32 msgbuf[IXGBE_VFMAILBOX_SIZE]; |
17367270 GR |
568 | struct ixgbe_hw *hw = &adapter->hw; |
569 | s32 retval; | |
570 | int entries; | |
571 | u16 *hash_list; | |
a1cbb15c | 572 | int add, vid, index; |
d3306c29 | 573 | u8 *new_mac; |
17367270 GR |
574 | |
575 | retval = ixgbe_read_mbx(hw, msgbuf, mbx_size, vf); | |
576 | ||
dcaccc82 | 577 | if (retval) { |
849c4542 | 578 | pr_err("Error receiving message from VF\n"); |
dcaccc82 AD |
579 | return retval; |
580 | } | |
17367270 GR |
581 | |
582 | /* this is a message we already processed, do nothing */ | |
583 | if (msgbuf[0] & (IXGBE_VT_MSGTYPE_ACK | IXGBE_VT_MSGTYPE_NACK)) | |
584 | return retval; | |
585 | ||
dcaccc82 AD |
586 | /* flush the ack before we write any messages back */ |
587 | IXGBE_WRITE_FLUSH(hw); | |
588 | ||
17367270 GR |
589 | /* |
590 | * until the vf completes a virtual function reset it should not be | |
591 | * allowed to start any configuration. | |
592 | */ | |
593 | ||
594 | if (msgbuf[0] == IXGBE_VF_RESET) { | |
595 | unsigned char *vf_mac = adapter->vfinfo[vf].vf_mac_addresses; | |
d3306c29 | 596 | new_mac = (u8 *)(&msgbuf[1]); |
396e799c | 597 | e_info(probe, "VF Reset msg received from vf %d\n", vf); |
17367270 GR |
598 | adapter->vfinfo[vf].clear_to_send = false; |
599 | ixgbe_vf_reset_msg(adapter, vf); | |
600 | adapter->vfinfo[vf].clear_to_send = true; | |
601 | ||
d3306c29 GR |
602 | if (is_valid_ether_addr(new_mac) && |
603 | !adapter->vfinfo[vf].pf_set_mac) | |
604 | ixgbe_set_vf_mac(adapter, vf, vf_mac); | |
605 | else | |
606 | ixgbe_set_vf_mac(adapter, | |
607 | vf, adapter->vfinfo[vf].vf_mac_addresses); | |
608 | ||
17367270 GR |
609 | /* reply to reset with ack and vf mac address */ |
610 | msgbuf[0] = IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_ACK; | |
ea99d832 | 611 | memcpy(new_mac, vf_mac, ETH_ALEN); |
17367270 GR |
612 | /* |
613 | * Piggyback the multicast filter type so VF can compute the | |
614 | * correct vectors | |
615 | */ | |
616 | msgbuf[3] = hw->mac.mc_filter_type; | |
617 | ixgbe_write_mbx(hw, msgbuf, IXGBE_VF_PERMADDR_MSG_LEN, vf); | |
618 | ||
619 | return retval; | |
620 | } | |
621 | ||
622 | if (!adapter->vfinfo[vf].clear_to_send) { | |
623 | msgbuf[0] |= IXGBE_VT_MSGTYPE_NACK; | |
624 | ixgbe_write_mbx(hw, msgbuf, 1, vf); | |
625 | return retval; | |
626 | } | |
627 | ||
628 | switch ((msgbuf[0] & 0xFFFF)) { | |
629 | case IXGBE_VF_SET_MAC_ADDR: | |
d3306c29 GR |
630 | new_mac = ((u8 *)(&msgbuf[1])); |
631 | if (is_valid_ether_addr(new_mac) && | |
632 | !adapter->vfinfo[vf].pf_set_mac) { | |
633 | ixgbe_set_vf_mac(adapter, vf, new_mac); | |
634 | } else if (memcmp(adapter->vfinfo[vf].vf_mac_addresses, | |
635 | new_mac, ETH_ALEN)) { | |
636 | e_warn(drv, "VF %d attempted to override " | |
637 | "administratively set MAC address\nReload " | |
638 | "the VF driver to resume operations\n", vf); | |
639 | retval = -1; | |
17367270 GR |
640 | } |
641 | break; | |
642 | case IXGBE_VF_SET_MULTICAST: | |
643 | entries = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) | |
644 | >> IXGBE_VT_MSGINFO_SHIFT; | |
645 | hash_list = (u16 *)&msgbuf[1]; | |
646 | retval = ixgbe_set_vf_multicasts(adapter, entries, | |
647 | hash_list, vf); | |
648 | break; | |
649 | case IXGBE_VF_SET_LPE: | |
e9f98072 | 650 | ixgbe_set_vf_lpe(adapter, msgbuf); |
17367270 GR |
651 | break; |
652 | case IXGBE_VF_SET_VLAN: | |
653 | add = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) | |
654 | >> IXGBE_VT_MSGINFO_SHIFT; | |
655 | vid = (msgbuf[1] & IXGBE_VLVF_VLANID_MASK); | |
d3306c29 GR |
656 | if (adapter->vfinfo[vf].pf_vlan) { |
657 | e_warn(drv, "VF %d attempted to override " | |
658 | "administratively set VLAN configuration\n" | |
659 | "Reload the VF driver to resume operations\n", | |
660 | vf); | |
661 | retval = -1; | |
662 | } else { | |
de4c7f65 GR |
663 | if (add) |
664 | adapter->vfinfo[vf].vlan_count++; | |
665 | else if (adapter->vfinfo[vf].vlan_count) | |
666 | adapter->vfinfo[vf].vlan_count--; | |
d3306c29 | 667 | retval = ixgbe_set_vf_vlan(adapter, add, vid, vf); |
de4c7f65 GR |
668 | if (!retval && adapter->vfinfo[vf].spoofchk_enabled) |
669 | hw->mac.ops.set_vlan_anti_spoofing(hw, true, vf); | |
d3306c29 | 670 | } |
17367270 | 671 | break; |
a1cbb15c | 672 | case IXGBE_VF_SET_MACVLAN: |
44b82dde GR |
673 | index = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) >> |
674 | IXGBE_VT_MSGINFO_SHIFT; | |
675 | if (adapter->vfinfo[vf].pf_set_mac && index > 0) { | |
2ee7065f GR |
676 | e_warn(drv, "VF %d requested MACVLAN filter but is " |
677 | "administratively denied\n", vf); | |
678 | retval = -1; | |
679 | break; | |
680 | } | |
a1cbb15c GR |
681 | /* |
682 | * If the VF is allowed to set MAC filters then turn off | |
683 | * anti-spoofing to avoid false positives. An index | |
684 | * greater than 0 will indicate the VF is setting a | |
685 | * macvlan MAC filter. | |
686 | */ | |
de4c7f65 GR |
687 | if (index > 0 && adapter->vfinfo[vf].spoofchk_enabled) |
688 | ixgbe_ndo_set_vf_spoofchk(adapter->netdev, vf, false); | |
a1cbb15c GR |
689 | retval = ixgbe_set_vf_macvlan(adapter, vf, index, |
690 | (unsigned char *)(&msgbuf[1])); | |
68d6d4ab GR |
691 | if (retval == -ENOSPC) |
692 | e_warn(drv, "VF %d has requested a MACVLAN filter " | |
693 | "but there is no space for it\n", vf); | |
a1cbb15c | 694 | break; |
17367270 | 695 | default: |
396e799c | 696 | e_err(drv, "Unhandled Msg %8.8x\n", msgbuf[0]); |
17367270 GR |
697 | retval = IXGBE_ERR_MBX; |
698 | break; | |
699 | } | |
700 | ||
701 | /* notify the VF of the results of what it sent us */ | |
702 | if (retval) | |
703 | msgbuf[0] |= IXGBE_VT_MSGTYPE_NACK; | |
704 | else | |
705 | msgbuf[0] |= IXGBE_VT_MSGTYPE_ACK; | |
706 | ||
707 | msgbuf[0] |= IXGBE_VT_MSGTYPE_CTS; | |
708 | ||
709 | ixgbe_write_mbx(hw, msgbuf, 1, vf); | |
710 | ||
711 | return retval; | |
712 | } | |
713 | ||
714 | static void ixgbe_rcv_ack_from_vf(struct ixgbe_adapter *adapter, u32 vf) | |
715 | { | |
716 | struct ixgbe_hw *hw = &adapter->hw; | |
717 | u32 msg = IXGBE_VT_MSGTYPE_NACK; | |
718 | ||
719 | /* if device isn't clear to send it shouldn't be reading either */ | |
720 | if (!adapter->vfinfo[vf].clear_to_send) | |
721 | ixgbe_write_mbx(hw, &msg, 1, vf); | |
722 | } | |
723 | ||
724 | void ixgbe_msg_task(struct ixgbe_adapter *adapter) | |
725 | { | |
726 | struct ixgbe_hw *hw = &adapter->hw; | |
727 | u32 vf; | |
728 | ||
729 | for (vf = 0; vf < adapter->num_vfs; vf++) { | |
730 | /* process any reset requests */ | |
731 | if (!ixgbe_check_for_rst(hw, vf)) | |
732 | ixgbe_vf_reset_event(adapter, vf); | |
733 | ||
734 | /* process any messages pending */ | |
735 | if (!ixgbe_check_for_msg(hw, vf)) | |
736 | ixgbe_rcv_msg_from_vf(adapter, vf); | |
737 | ||
738 | /* process any acks */ | |
739 | if (!ixgbe_check_for_ack(hw, vf)) | |
740 | ixgbe_rcv_ack_from_vf(adapter, vf); | |
741 | } | |
742 | } | |
743 | ||
767081ad GR |
744 | void ixgbe_disable_tx_rx(struct ixgbe_adapter *adapter) |
745 | { | |
746 | struct ixgbe_hw *hw = &adapter->hw; | |
747 | ||
748 | /* disable transmit and receive for all vfs */ | |
749 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(0), 0); | |
750 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(1), 0); | |
751 | ||
752 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(0), 0); | |
753 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(1), 0); | |
754 | } | |
755 | ||
756 | void ixgbe_ping_all_vfs(struct ixgbe_adapter *adapter) | |
757 | { | |
758 | struct ixgbe_hw *hw = &adapter->hw; | |
759 | u32 ping; | |
760 | int i; | |
761 | ||
762 | for (i = 0 ; i < adapter->num_vfs; i++) { | |
763 | ping = IXGBE_PF_CONTROL_MSG; | |
764 | if (adapter->vfinfo[i].clear_to_send) | |
765 | ping |= IXGBE_VT_MSGTYPE_CTS; | |
766 | ixgbe_write_mbx(hw, &ping, 1, i); | |
767 | } | |
768 | } | |
769 | ||
7f01648a GR |
770 | int ixgbe_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac) |
771 | { | |
772 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
773 | if (!is_valid_ether_addr(mac) || (vf >= adapter->num_vfs)) | |
774 | return -EINVAL; | |
775 | adapter->vfinfo[vf].pf_set_mac = true; | |
776 | dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n", mac, vf); | |
777 | dev_info(&adapter->pdev->dev, "Reload the VF driver to make this" | |
778 | " change effective."); | |
779 | if (test_bit(__IXGBE_DOWN, &adapter->state)) { | |
780 | dev_warn(&adapter->pdev->dev, "The VF MAC address has been set," | |
781 | " but the PF device is not up.\n"); | |
782 | dev_warn(&adapter->pdev->dev, "Bring the PF device up before" | |
783 | " attempting to use the VF device.\n"); | |
784 | } | |
785 | return ixgbe_set_vf_mac(adapter, vf, mac); | |
786 | } | |
787 | ||
788 | int ixgbe_ndo_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan, u8 qos) | |
789 | { | |
790 | int err = 0; | |
791 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
a985b6c3 | 792 | struct ixgbe_hw *hw = &adapter->hw; |
7f01648a GR |
793 | |
794 | if ((vf >= adapter->num_vfs) || (vlan > 4095) || (qos > 7)) | |
795 | return -EINVAL; | |
796 | if (vlan || qos) { | |
797 | err = ixgbe_set_vf_vlan(adapter, true, vlan, vf); | |
798 | if (err) | |
799 | goto out; | |
800 | ixgbe_set_vmvir(adapter, vlan | (qos << VLAN_PRIO_SHIFT), vf); | |
a985b6c3 | 801 | ixgbe_set_vmolr(hw, vf, false); |
de4c7f65 | 802 | if (adapter->vfinfo[vf].spoofchk_enabled) |
a1cbb15c | 803 | hw->mac.ops.set_vlan_anti_spoofing(hw, true, vf); |
de4c7f65 | 804 | adapter->vfinfo[vf].vlan_count++; |
7f01648a GR |
805 | adapter->vfinfo[vf].pf_vlan = vlan; |
806 | adapter->vfinfo[vf].pf_qos = qos; | |
807 | dev_info(&adapter->pdev->dev, | |
808 | "Setting VLAN %d, QOS 0x%x on VF %d\n", vlan, qos, vf); | |
809 | if (test_bit(__IXGBE_DOWN, &adapter->state)) { | |
810 | dev_warn(&adapter->pdev->dev, | |
811 | "The VF VLAN has been set," | |
812 | " but the PF device is not up.\n"); | |
813 | dev_warn(&adapter->pdev->dev, | |
814 | "Bring the PF device up before" | |
815 | " attempting to use the VF device.\n"); | |
816 | } | |
817 | } else { | |
818 | err = ixgbe_set_vf_vlan(adapter, false, | |
819 | adapter->vfinfo[vf].pf_vlan, vf); | |
820 | ixgbe_set_vmvir(adapter, vlan, vf); | |
a985b6c3 GR |
821 | ixgbe_set_vmolr(hw, vf, true); |
822 | hw->mac.ops.set_vlan_anti_spoofing(hw, false, vf); | |
de4c7f65 GR |
823 | if (adapter->vfinfo[vf].vlan_count) |
824 | adapter->vfinfo[vf].vlan_count--; | |
7f01648a GR |
825 | adapter->vfinfo[vf].pf_vlan = 0; |
826 | adapter->vfinfo[vf].pf_qos = 0; | |
827 | } | |
828 | out: | |
829 | return err; | |
830 | } | |
831 | ||
ff4ab206 LL |
832 | static int ixgbe_link_mbps(int internal_link_speed) |
833 | { | |
834 | switch (internal_link_speed) { | |
835 | case IXGBE_LINK_SPEED_100_FULL: | |
836 | return 100; | |
837 | case IXGBE_LINK_SPEED_1GB_FULL: | |
838 | return 1000; | |
839 | case IXGBE_LINK_SPEED_10GB_FULL: | |
840 | return 10000; | |
841 | default: | |
842 | return 0; | |
843 | } | |
844 | } | |
845 | ||
846 | static void ixgbe_set_vf_rate_limit(struct ixgbe_hw *hw, int vf, int tx_rate, | |
847 | int link_speed) | |
848 | { | |
849 | int rf_dec, rf_int; | |
850 | u32 bcnrc_val; | |
851 | ||
852 | if (tx_rate != 0) { | |
853 | /* Calculate the rate factor values to set */ | |
854 | rf_int = link_speed / tx_rate; | |
855 | rf_dec = (link_speed - (rf_int * tx_rate)); | |
856 | rf_dec = (rf_dec * (1<<IXGBE_RTTBCNRC_RF_INT_SHIFT)) / tx_rate; | |
857 | ||
858 | bcnrc_val = IXGBE_RTTBCNRC_RS_ENA; | |
859 | bcnrc_val |= ((rf_int<<IXGBE_RTTBCNRC_RF_INT_SHIFT) & | |
860 | IXGBE_RTTBCNRC_RF_INT_MASK); | |
861 | bcnrc_val |= (rf_dec & IXGBE_RTTBCNRC_RF_DEC_MASK); | |
862 | } else { | |
863 | bcnrc_val = 0; | |
864 | } | |
865 | ||
866 | IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, 2*vf); /* vf Y uses queue 2*Y */ | |
7555e83d LL |
867 | /* |
868 | * Set global transmit compensation time to the MMW_SIZE in RTTBCNRM | |
869 | * register. Typically MMW_SIZE=0x014 if 9728-byte jumbo is supported | |
870 | * and 0x004 otherwise. | |
871 | */ | |
872 | switch (hw->mac.type) { | |
873 | case ixgbe_mac_82599EB: | |
874 | IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM, 0x4); | |
875 | break; | |
876 | case ixgbe_mac_X540: | |
877 | IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM, 0x14); | |
878 | break; | |
879 | default: | |
880 | break; | |
881 | } | |
882 | ||
ff4ab206 LL |
883 | IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val); |
884 | } | |
885 | ||
886 | void ixgbe_check_vf_rate_limit(struct ixgbe_adapter *adapter) | |
887 | { | |
888 | int actual_link_speed, i; | |
889 | bool reset_rate = false; | |
890 | ||
891 | /* VF Tx rate limit was not set */ | |
892 | if (adapter->vf_rate_link_speed == 0) | |
893 | return; | |
894 | ||
895 | actual_link_speed = ixgbe_link_mbps(adapter->link_speed); | |
896 | if (actual_link_speed != adapter->vf_rate_link_speed) { | |
897 | reset_rate = true; | |
898 | adapter->vf_rate_link_speed = 0; | |
899 | dev_info(&adapter->pdev->dev, | |
900 | "Link speed has been changed. VF Transmit rate " | |
901 | "is disabled\n"); | |
902 | } | |
903 | ||
904 | for (i = 0; i < adapter->num_vfs; i++) { | |
905 | if (reset_rate) | |
906 | adapter->vfinfo[i].tx_rate = 0; | |
907 | ||
908 | ixgbe_set_vf_rate_limit(&adapter->hw, i, | |
909 | adapter->vfinfo[i].tx_rate, | |
910 | actual_link_speed); | |
911 | } | |
912 | } | |
913 | ||
7f01648a GR |
914 | int ixgbe_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate) |
915 | { | |
ff4ab206 LL |
916 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
917 | struct ixgbe_hw *hw = &adapter->hw; | |
918 | int actual_link_speed; | |
919 | ||
920 | actual_link_speed = ixgbe_link_mbps(adapter->link_speed); | |
921 | if ((vf >= adapter->num_vfs) || (!adapter->link_up) || | |
922 | (tx_rate > actual_link_speed) || (actual_link_speed != 10000) || | |
923 | ((tx_rate != 0) && (tx_rate <= 10))) | |
924 | /* rate limit cannot be set to 10Mb or less in 10Gb adapters */ | |
925 | return -EINVAL; | |
926 | ||
927 | adapter->vf_rate_link_speed = actual_link_speed; | |
928 | adapter->vfinfo[vf].tx_rate = (u16)tx_rate; | |
929 | ixgbe_set_vf_rate_limit(hw, vf, tx_rate, actual_link_speed); | |
930 | ||
931 | return 0; | |
7f01648a GR |
932 | } |
933 | ||
de4c7f65 GR |
934 | int ixgbe_ndo_set_vf_spoofchk(struct net_device *netdev, int vf, bool setting) |
935 | { | |
936 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
937 | int vf_target_reg = vf >> 3; | |
938 | int vf_target_shift = vf % 8; | |
939 | struct ixgbe_hw *hw = &adapter->hw; | |
940 | u32 regval; | |
941 | ||
942 | adapter->vfinfo[vf].spoofchk_enabled = setting; | |
943 | ||
944 | regval = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg)); | |
945 | regval &= ~(1 << vf_target_shift); | |
946 | regval |= (setting << vf_target_shift); | |
947 | IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), regval); | |
948 | ||
949 | if (adapter->vfinfo[vf].vlan_count) { | |
950 | vf_target_shift += IXGBE_SPOOF_VLANAS_SHIFT; | |
951 | regval = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg)); | |
952 | regval &= ~(1 << vf_target_shift); | |
953 | regval |= (setting << vf_target_shift); | |
954 | IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), regval); | |
955 | } | |
956 | ||
957 | return 0; | |
958 | } | |
959 | ||
7f01648a GR |
960 | int ixgbe_ndo_get_vf_config(struct net_device *netdev, |
961 | int vf, struct ifla_vf_info *ivi) | |
962 | { | |
963 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
964 | if (vf >= adapter->num_vfs) | |
965 | return -EINVAL; | |
966 | ivi->vf = vf; | |
967 | memcpy(&ivi->mac, adapter->vfinfo[vf].vf_mac_addresses, ETH_ALEN); | |
ff4ab206 | 968 | ivi->tx_rate = adapter->vfinfo[vf].tx_rate; |
7f01648a GR |
969 | ivi->vlan = adapter->vfinfo[vf].pf_vlan; |
970 | ivi->qos = adapter->vfinfo[vf].pf_qos; | |
de4c7f65 | 971 | ivi->spoofchk = adapter->vfinfo[vf].spoofchk_enabled; |
7f01648a GR |
972 | return 0; |
973 | } |