Commit | Line | Data |
---|---|---|
17367270 GR |
1 | /******************************************************************************* |
2 | ||
3 | Intel 10 Gigabit PCI Express Linux driver | |
a52055e0 | 4 | Copyright(c) 1999 - 2011 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" | |
43 | ||
44 | #include "ixgbe_sriov.h" | |
45 | ||
5d5b7c39 ET |
46 | static int ixgbe_set_vf_multicasts(struct ixgbe_adapter *adapter, |
47 | int entries, u16 *hash_list, u32 vf) | |
17367270 GR |
48 | { |
49 | struct vf_data_storage *vfinfo = &adapter->vfinfo[vf]; | |
8a07a22d | 50 | struct ixgbe_hw *hw = &adapter->hw; |
17367270 | 51 | int i; |
8a07a22d GR |
52 | u32 vector_bit; |
53 | u32 vector_reg; | |
54 | u32 mta_reg; | |
17367270 GR |
55 | |
56 | /* only so many hash values supported */ | |
57 | entries = min(entries, IXGBE_MAX_VF_MC_ENTRIES); | |
58 | ||
59 | /* | |
60 | * salt away the number of multi cast addresses assigned | |
61 | * to this VF for later use to restore when the PF multi cast | |
62 | * list changes | |
63 | */ | |
64 | vfinfo->num_vf_mc_hashes = entries; | |
65 | ||
66 | /* | |
67 | * VFs are limited to using the MTA hash table for their multicast | |
68 | * addresses | |
69 | */ | |
70 | for (i = 0; i < entries; i++) { | |
e81a1ba8 | 71 | vfinfo->vf_mc_hashes[i] = hash_list[i]; |
17367270 GR |
72 | } |
73 | ||
8a07a22d GR |
74 | for (i = 0; i < vfinfo->num_vf_mc_hashes; i++) { |
75 | vector_reg = (vfinfo->vf_mc_hashes[i] >> 5) & 0x7F; | |
76 | vector_bit = vfinfo->vf_mc_hashes[i] & 0x1F; | |
77 | mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg)); | |
78 | mta_reg |= (1 << vector_bit); | |
79 | IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg); | |
80 | } | |
17367270 GR |
81 | |
82 | return 0; | |
83 | } | |
84 | ||
85 | void ixgbe_restore_vf_multicasts(struct ixgbe_adapter *adapter) | |
86 | { | |
87 | struct ixgbe_hw *hw = &adapter->hw; | |
88 | struct vf_data_storage *vfinfo; | |
89 | int i, j; | |
90 | u32 vector_bit; | |
91 | u32 vector_reg; | |
92 | u32 mta_reg; | |
93 | ||
94 | for (i = 0; i < adapter->num_vfs; i++) { | |
95 | vfinfo = &adapter->vfinfo[i]; | |
96 | for (j = 0; j < vfinfo->num_vf_mc_hashes; j++) { | |
97 | hw->addr_ctrl.mta_in_use++; | |
98 | vector_reg = (vfinfo->vf_mc_hashes[j] >> 5) & 0x7F; | |
99 | vector_bit = vfinfo->vf_mc_hashes[j] & 0x1F; | |
100 | mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg)); | |
101 | mta_reg |= (1 << vector_bit); | |
102 | IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg); | |
103 | } | |
104 | } | |
105 | } | |
106 | ||
5d5b7c39 ET |
107 | static int ixgbe_set_vf_vlan(struct ixgbe_adapter *adapter, int add, int vid, |
108 | u32 vf) | |
17367270 | 109 | { |
17367270 GR |
110 | return adapter->hw.mac.ops.set_vfta(&adapter->hw, vid, vf, (bool)add); |
111 | } | |
112 | ||
b32c8dcc | 113 | static void ixgbe_set_vf_lpe(struct ixgbe_adapter *adapter, u32 *msgbuf) |
e9f98072 GR |
114 | { |
115 | struct ixgbe_hw *hw = &adapter->hw; | |
116 | int new_mtu = msgbuf[1]; | |
117 | u32 max_frs; | |
118 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; | |
119 | ||
120 | /* Only X540 supports jumbo frames in IOV mode */ | |
121 | if (adapter->hw.mac.type != ixgbe_mac_X540) | |
122 | return; | |
123 | ||
124 | /* MTU < 68 is an error and causes problems on some kernels */ | |
125 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) { | |
126 | e_err(drv, "VF mtu %d out of range\n", new_mtu); | |
127 | return; | |
128 | } | |
129 | ||
130 | max_frs = (IXGBE_READ_REG(hw, IXGBE_MAXFRS) & | |
131 | IXGBE_MHADD_MFS_MASK) >> IXGBE_MHADD_MFS_SHIFT; | |
132 | if (max_frs < new_mtu) { | |
133 | max_frs = new_mtu << IXGBE_MHADD_MFS_SHIFT; | |
134 | IXGBE_WRITE_REG(hw, IXGBE_MAXFRS, max_frs); | |
135 | } | |
136 | ||
137 | e_info(hw, "VF requests change max MTU to %d\n", new_mtu); | |
138 | } | |
139 | ||
5d5b7c39 | 140 | static void ixgbe_set_vmolr(struct ixgbe_hw *hw, u32 vf, bool aupe) |
17367270 GR |
141 | { |
142 | u32 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf)); | |
f0412776 | 143 | vmolr |= (IXGBE_VMOLR_ROMPE | |
17367270 | 144 | IXGBE_VMOLR_BAM); |
f0412776 GR |
145 | if (aupe) |
146 | vmolr |= IXGBE_VMOLR_AUPE; | |
147 | else | |
148 | vmolr &= ~IXGBE_VMOLR_AUPE; | |
17367270 GR |
149 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr); |
150 | } | |
151 | ||
7f01648a GR |
152 | static void ixgbe_set_vmvir(struct ixgbe_adapter *adapter, u32 vid, u32 vf) |
153 | { | |
154 | struct ixgbe_hw *hw = &adapter->hw; | |
155 | ||
156 | if (vid) | |
157 | IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf), | |
158 | (vid | IXGBE_VMVIR_VLANA_DEFAULT)); | |
159 | else | |
160 | IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf), 0); | |
161 | } | |
162 | ||
5d5b7c39 | 163 | static inline void ixgbe_vf_reset_event(struct ixgbe_adapter *adapter, u32 vf) |
17367270 GR |
164 | { |
165 | struct ixgbe_hw *hw = &adapter->hw; | |
2850062a | 166 | int rar_entry = hw->mac.num_rar_entries - (vf + 1); |
17367270 GR |
167 | |
168 | /* reset offloads to defaults */ | |
7f01648a GR |
169 | if (adapter->vfinfo[vf].pf_vlan) { |
170 | ixgbe_set_vf_vlan(adapter, true, | |
171 | adapter->vfinfo[vf].pf_vlan, vf); | |
172 | ixgbe_set_vmvir(adapter, | |
173 | (adapter->vfinfo[vf].pf_vlan | | |
174 | (adapter->vfinfo[vf].pf_qos << | |
175 | VLAN_PRIO_SHIFT)), vf); | |
176 | ixgbe_set_vmolr(hw, vf, false); | |
177 | } else { | |
178 | ixgbe_set_vmvir(adapter, 0, vf); | |
179 | ixgbe_set_vmolr(hw, vf, true); | |
180 | } | |
17367270 GR |
181 | |
182 | /* reset multicast table array for vf */ | |
183 | adapter->vfinfo[vf].num_vf_mc_hashes = 0; | |
184 | ||
185 | /* Flush and reset the mta with the new values */ | |
186 | ixgbe_set_rx_mode(adapter->netdev); | |
187 | ||
2850062a | 188 | hw->mac.ops.clear_rar(hw, rar_entry); |
17367270 GR |
189 | } |
190 | ||
5d5b7c39 ET |
191 | static int ixgbe_set_vf_mac(struct ixgbe_adapter *adapter, |
192 | int vf, unsigned char *mac_addr) | |
17367270 GR |
193 | { |
194 | struct ixgbe_hw *hw = &adapter->hw; | |
2850062a | 195 | int rar_entry = hw->mac.num_rar_entries - (vf + 1); |
17367270 GR |
196 | |
197 | memcpy(adapter->vfinfo[vf].vf_mac_addresses, mac_addr, 6); | |
2850062a | 198 | hw->mac.ops.set_rar(hw, rar_entry, mac_addr, vf, IXGBE_RAH_AV); |
17367270 GR |
199 | |
200 | return 0; | |
201 | } | |
202 | ||
203 | int ixgbe_vf_configuration(struct pci_dev *pdev, unsigned int event_mask) | |
204 | { | |
205 | unsigned char vf_mac_addr[6]; | |
c60fbb00 | 206 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
17367270 GR |
207 | unsigned int vfn = (event_mask & 0x3f); |
208 | ||
209 | bool enable = ((event_mask & 0x10000000U) != 0); | |
210 | ||
211 | if (enable) { | |
212 | random_ether_addr(vf_mac_addr); | |
396e799c ET |
213 | e_info(probe, "IOV: VF %d is enabled MAC %pM\n", |
214 | vfn, vf_mac_addr); | |
17367270 GR |
215 | /* |
216 | * Store away the VF "permananet" MAC address, it will ask | |
217 | * for it later. | |
218 | */ | |
219 | memcpy(adapter->vfinfo[vfn].vf_mac_addresses, vf_mac_addr, 6); | |
220 | } | |
221 | ||
222 | return 0; | |
223 | } | |
224 | ||
5d5b7c39 | 225 | static inline void ixgbe_vf_reset_msg(struct ixgbe_adapter *adapter, u32 vf) |
17367270 GR |
226 | { |
227 | struct ixgbe_hw *hw = &adapter->hw; | |
228 | u32 reg; | |
229 | u32 reg_offset, vf_shift; | |
230 | ||
231 | vf_shift = vf % 32; | |
232 | reg_offset = vf / 32; | |
233 | ||
234 | /* enable transmit and receive for vf */ | |
235 | reg = IXGBE_READ_REG(hw, IXGBE_VFTE(reg_offset)); | |
236 | reg |= (reg | (1 << vf_shift)); | |
237 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), reg); | |
238 | ||
239 | reg = IXGBE_READ_REG(hw, IXGBE_VFRE(reg_offset)); | |
240 | reg |= (reg | (1 << vf_shift)); | |
241 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), reg); | |
242 | ||
a985b6c3 GR |
243 | /* Enable counting of spoofed packets in the SSVPC register */ |
244 | reg = IXGBE_READ_REG(hw, IXGBE_VMECM(reg_offset)); | |
245 | reg |= (1 << vf_shift); | |
246 | IXGBE_WRITE_REG(hw, IXGBE_VMECM(reg_offset), reg); | |
247 | ||
17367270 GR |
248 | ixgbe_vf_reset_event(adapter, vf); |
249 | } | |
250 | ||
251 | static int ixgbe_rcv_msg_from_vf(struct ixgbe_adapter *adapter, u32 vf) | |
252 | { | |
253 | u32 mbx_size = IXGBE_VFMAILBOX_SIZE; | |
254 | u32 msgbuf[mbx_size]; | |
255 | struct ixgbe_hw *hw = &adapter->hw; | |
256 | s32 retval; | |
257 | int entries; | |
258 | u16 *hash_list; | |
259 | int add, vid; | |
d3306c29 | 260 | u8 *new_mac; |
17367270 GR |
261 | |
262 | retval = ixgbe_read_mbx(hw, msgbuf, mbx_size, vf); | |
263 | ||
264 | if (retval) | |
849c4542 | 265 | pr_err("Error receiving message from VF\n"); |
17367270 GR |
266 | |
267 | /* this is a message we already processed, do nothing */ | |
268 | if (msgbuf[0] & (IXGBE_VT_MSGTYPE_ACK | IXGBE_VT_MSGTYPE_NACK)) | |
269 | return retval; | |
270 | ||
271 | /* | |
272 | * until the vf completes a virtual function reset it should not be | |
273 | * allowed to start any configuration. | |
274 | */ | |
275 | ||
276 | if (msgbuf[0] == IXGBE_VF_RESET) { | |
277 | unsigned char *vf_mac = adapter->vfinfo[vf].vf_mac_addresses; | |
d3306c29 | 278 | new_mac = (u8 *)(&msgbuf[1]); |
396e799c | 279 | e_info(probe, "VF Reset msg received from vf %d\n", vf); |
17367270 GR |
280 | adapter->vfinfo[vf].clear_to_send = false; |
281 | ixgbe_vf_reset_msg(adapter, vf); | |
282 | adapter->vfinfo[vf].clear_to_send = true; | |
283 | ||
d3306c29 GR |
284 | if (is_valid_ether_addr(new_mac) && |
285 | !adapter->vfinfo[vf].pf_set_mac) | |
286 | ixgbe_set_vf_mac(adapter, vf, vf_mac); | |
287 | else | |
288 | ixgbe_set_vf_mac(adapter, | |
289 | vf, adapter->vfinfo[vf].vf_mac_addresses); | |
290 | ||
17367270 GR |
291 | /* reply to reset with ack and vf mac address */ |
292 | msgbuf[0] = IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_ACK; | |
d3306c29 | 293 | memcpy(new_mac, vf_mac, IXGBE_ETH_LENGTH_OF_ADDRESS); |
17367270 GR |
294 | /* |
295 | * Piggyback the multicast filter type so VF can compute the | |
296 | * correct vectors | |
297 | */ | |
298 | msgbuf[3] = hw->mac.mc_filter_type; | |
299 | ixgbe_write_mbx(hw, msgbuf, IXGBE_VF_PERMADDR_MSG_LEN, vf); | |
300 | ||
301 | return retval; | |
302 | } | |
303 | ||
304 | if (!adapter->vfinfo[vf].clear_to_send) { | |
305 | msgbuf[0] |= IXGBE_VT_MSGTYPE_NACK; | |
306 | ixgbe_write_mbx(hw, msgbuf, 1, vf); | |
307 | return retval; | |
308 | } | |
309 | ||
310 | switch ((msgbuf[0] & 0xFFFF)) { | |
311 | case IXGBE_VF_SET_MAC_ADDR: | |
d3306c29 GR |
312 | new_mac = ((u8 *)(&msgbuf[1])); |
313 | if (is_valid_ether_addr(new_mac) && | |
314 | !adapter->vfinfo[vf].pf_set_mac) { | |
315 | ixgbe_set_vf_mac(adapter, vf, new_mac); | |
316 | } else if (memcmp(adapter->vfinfo[vf].vf_mac_addresses, | |
317 | new_mac, ETH_ALEN)) { | |
318 | e_warn(drv, "VF %d attempted to override " | |
319 | "administratively set MAC address\nReload " | |
320 | "the VF driver to resume operations\n", vf); | |
321 | retval = -1; | |
17367270 GR |
322 | } |
323 | break; | |
324 | case IXGBE_VF_SET_MULTICAST: | |
325 | entries = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) | |
326 | >> IXGBE_VT_MSGINFO_SHIFT; | |
327 | hash_list = (u16 *)&msgbuf[1]; | |
328 | retval = ixgbe_set_vf_multicasts(adapter, entries, | |
329 | hash_list, vf); | |
330 | break; | |
331 | case IXGBE_VF_SET_LPE: | |
e9f98072 | 332 | ixgbe_set_vf_lpe(adapter, msgbuf); |
17367270 GR |
333 | break; |
334 | case IXGBE_VF_SET_VLAN: | |
335 | add = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) | |
336 | >> IXGBE_VT_MSGINFO_SHIFT; | |
337 | vid = (msgbuf[1] & IXGBE_VLVF_VLANID_MASK); | |
d3306c29 GR |
338 | if (adapter->vfinfo[vf].pf_vlan) { |
339 | e_warn(drv, "VF %d attempted to override " | |
340 | "administratively set VLAN configuration\n" | |
341 | "Reload the VF driver to resume operations\n", | |
342 | vf); | |
343 | retval = -1; | |
344 | } else { | |
345 | retval = ixgbe_set_vf_vlan(adapter, add, vid, vf); | |
346 | } | |
17367270 GR |
347 | break; |
348 | default: | |
396e799c | 349 | e_err(drv, "Unhandled Msg %8.8x\n", msgbuf[0]); |
17367270 GR |
350 | retval = IXGBE_ERR_MBX; |
351 | break; | |
352 | } | |
353 | ||
354 | /* notify the VF of the results of what it sent us */ | |
355 | if (retval) | |
356 | msgbuf[0] |= IXGBE_VT_MSGTYPE_NACK; | |
357 | else | |
358 | msgbuf[0] |= IXGBE_VT_MSGTYPE_ACK; | |
359 | ||
360 | msgbuf[0] |= IXGBE_VT_MSGTYPE_CTS; | |
361 | ||
362 | ixgbe_write_mbx(hw, msgbuf, 1, vf); | |
363 | ||
364 | return retval; | |
365 | } | |
366 | ||
367 | static void ixgbe_rcv_ack_from_vf(struct ixgbe_adapter *adapter, u32 vf) | |
368 | { | |
369 | struct ixgbe_hw *hw = &adapter->hw; | |
370 | u32 msg = IXGBE_VT_MSGTYPE_NACK; | |
371 | ||
372 | /* if device isn't clear to send it shouldn't be reading either */ | |
373 | if (!adapter->vfinfo[vf].clear_to_send) | |
374 | ixgbe_write_mbx(hw, &msg, 1, vf); | |
375 | } | |
376 | ||
377 | void ixgbe_msg_task(struct ixgbe_adapter *adapter) | |
378 | { | |
379 | struct ixgbe_hw *hw = &adapter->hw; | |
380 | u32 vf; | |
381 | ||
382 | for (vf = 0; vf < adapter->num_vfs; vf++) { | |
383 | /* process any reset requests */ | |
384 | if (!ixgbe_check_for_rst(hw, vf)) | |
385 | ixgbe_vf_reset_event(adapter, vf); | |
386 | ||
387 | /* process any messages pending */ | |
388 | if (!ixgbe_check_for_msg(hw, vf)) | |
389 | ixgbe_rcv_msg_from_vf(adapter, vf); | |
390 | ||
391 | /* process any acks */ | |
392 | if (!ixgbe_check_for_ack(hw, vf)) | |
393 | ixgbe_rcv_ack_from_vf(adapter, vf); | |
394 | } | |
395 | } | |
396 | ||
767081ad GR |
397 | void ixgbe_disable_tx_rx(struct ixgbe_adapter *adapter) |
398 | { | |
399 | struct ixgbe_hw *hw = &adapter->hw; | |
400 | ||
401 | /* disable transmit and receive for all vfs */ | |
402 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(0), 0); | |
403 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(1), 0); | |
404 | ||
405 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(0), 0); | |
406 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(1), 0); | |
407 | } | |
408 | ||
409 | void ixgbe_ping_all_vfs(struct ixgbe_adapter *adapter) | |
410 | { | |
411 | struct ixgbe_hw *hw = &adapter->hw; | |
412 | u32 ping; | |
413 | int i; | |
414 | ||
415 | for (i = 0 ; i < adapter->num_vfs; i++) { | |
416 | ping = IXGBE_PF_CONTROL_MSG; | |
417 | if (adapter->vfinfo[i].clear_to_send) | |
418 | ping |= IXGBE_VT_MSGTYPE_CTS; | |
419 | ixgbe_write_mbx(hw, &ping, 1, i); | |
420 | } | |
421 | } | |
422 | ||
7f01648a GR |
423 | int ixgbe_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac) |
424 | { | |
425 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
426 | if (!is_valid_ether_addr(mac) || (vf >= adapter->num_vfs)) | |
427 | return -EINVAL; | |
428 | adapter->vfinfo[vf].pf_set_mac = true; | |
429 | dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n", mac, vf); | |
430 | dev_info(&adapter->pdev->dev, "Reload the VF driver to make this" | |
431 | " change effective."); | |
432 | if (test_bit(__IXGBE_DOWN, &adapter->state)) { | |
433 | dev_warn(&adapter->pdev->dev, "The VF MAC address has been set," | |
434 | " but the PF device is not up.\n"); | |
435 | dev_warn(&adapter->pdev->dev, "Bring the PF device up before" | |
436 | " attempting to use the VF device.\n"); | |
437 | } | |
438 | return ixgbe_set_vf_mac(adapter, vf, mac); | |
439 | } | |
440 | ||
441 | int ixgbe_ndo_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan, u8 qos) | |
442 | { | |
443 | int err = 0; | |
444 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
a985b6c3 | 445 | struct ixgbe_hw *hw = &adapter->hw; |
7f01648a GR |
446 | |
447 | if ((vf >= adapter->num_vfs) || (vlan > 4095) || (qos > 7)) | |
448 | return -EINVAL; | |
449 | if (vlan || qos) { | |
450 | err = ixgbe_set_vf_vlan(adapter, true, vlan, vf); | |
451 | if (err) | |
452 | goto out; | |
453 | ixgbe_set_vmvir(adapter, vlan | (qos << VLAN_PRIO_SHIFT), vf); | |
a985b6c3 GR |
454 | ixgbe_set_vmolr(hw, vf, false); |
455 | hw->mac.ops.set_vlan_anti_spoofing(hw, true, vf); | |
7f01648a GR |
456 | adapter->vfinfo[vf].pf_vlan = vlan; |
457 | adapter->vfinfo[vf].pf_qos = qos; | |
458 | dev_info(&adapter->pdev->dev, | |
459 | "Setting VLAN %d, QOS 0x%x on VF %d\n", vlan, qos, vf); | |
460 | if (test_bit(__IXGBE_DOWN, &adapter->state)) { | |
461 | dev_warn(&adapter->pdev->dev, | |
462 | "The VF VLAN has been set," | |
463 | " but the PF device is not up.\n"); | |
464 | dev_warn(&adapter->pdev->dev, | |
465 | "Bring the PF device up before" | |
466 | " attempting to use the VF device.\n"); | |
467 | } | |
468 | } else { | |
469 | err = ixgbe_set_vf_vlan(adapter, false, | |
470 | adapter->vfinfo[vf].pf_vlan, vf); | |
471 | ixgbe_set_vmvir(adapter, vlan, vf); | |
a985b6c3 GR |
472 | ixgbe_set_vmolr(hw, vf, true); |
473 | hw->mac.ops.set_vlan_anti_spoofing(hw, false, vf); | |
7f01648a GR |
474 | adapter->vfinfo[vf].pf_vlan = 0; |
475 | adapter->vfinfo[vf].pf_qos = 0; | |
476 | } | |
477 | out: | |
478 | return err; | |
479 | } | |
480 | ||
ff4ab206 LL |
481 | static int ixgbe_link_mbps(int internal_link_speed) |
482 | { | |
483 | switch (internal_link_speed) { | |
484 | case IXGBE_LINK_SPEED_100_FULL: | |
485 | return 100; | |
486 | case IXGBE_LINK_SPEED_1GB_FULL: | |
487 | return 1000; | |
488 | case IXGBE_LINK_SPEED_10GB_FULL: | |
489 | return 10000; | |
490 | default: | |
491 | return 0; | |
492 | } | |
493 | } | |
494 | ||
495 | static void ixgbe_set_vf_rate_limit(struct ixgbe_hw *hw, int vf, int tx_rate, | |
496 | int link_speed) | |
497 | { | |
498 | int rf_dec, rf_int; | |
499 | u32 bcnrc_val; | |
500 | ||
501 | if (tx_rate != 0) { | |
502 | /* Calculate the rate factor values to set */ | |
503 | rf_int = link_speed / tx_rate; | |
504 | rf_dec = (link_speed - (rf_int * tx_rate)); | |
505 | rf_dec = (rf_dec * (1<<IXGBE_RTTBCNRC_RF_INT_SHIFT)) / tx_rate; | |
506 | ||
507 | bcnrc_val = IXGBE_RTTBCNRC_RS_ENA; | |
508 | bcnrc_val |= ((rf_int<<IXGBE_RTTBCNRC_RF_INT_SHIFT) & | |
509 | IXGBE_RTTBCNRC_RF_INT_MASK); | |
510 | bcnrc_val |= (rf_dec & IXGBE_RTTBCNRC_RF_DEC_MASK); | |
511 | } else { | |
512 | bcnrc_val = 0; | |
513 | } | |
514 | ||
515 | IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, 2*vf); /* vf Y uses queue 2*Y */ | |
516 | IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val); | |
517 | } | |
518 | ||
519 | void ixgbe_check_vf_rate_limit(struct ixgbe_adapter *adapter) | |
520 | { | |
521 | int actual_link_speed, i; | |
522 | bool reset_rate = false; | |
523 | ||
524 | /* VF Tx rate limit was not set */ | |
525 | if (adapter->vf_rate_link_speed == 0) | |
526 | return; | |
527 | ||
528 | actual_link_speed = ixgbe_link_mbps(adapter->link_speed); | |
529 | if (actual_link_speed != adapter->vf_rate_link_speed) { | |
530 | reset_rate = true; | |
531 | adapter->vf_rate_link_speed = 0; | |
532 | dev_info(&adapter->pdev->dev, | |
533 | "Link speed has been changed. VF Transmit rate " | |
534 | "is disabled\n"); | |
535 | } | |
536 | ||
537 | for (i = 0; i < adapter->num_vfs; i++) { | |
538 | if (reset_rate) | |
539 | adapter->vfinfo[i].tx_rate = 0; | |
540 | ||
541 | ixgbe_set_vf_rate_limit(&adapter->hw, i, | |
542 | adapter->vfinfo[i].tx_rate, | |
543 | actual_link_speed); | |
544 | } | |
545 | } | |
546 | ||
7f01648a GR |
547 | int ixgbe_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate) |
548 | { | |
ff4ab206 LL |
549 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
550 | struct ixgbe_hw *hw = &adapter->hw; | |
551 | int actual_link_speed; | |
552 | ||
553 | actual_link_speed = ixgbe_link_mbps(adapter->link_speed); | |
554 | if ((vf >= adapter->num_vfs) || (!adapter->link_up) || | |
555 | (tx_rate > actual_link_speed) || (actual_link_speed != 10000) || | |
556 | ((tx_rate != 0) && (tx_rate <= 10))) | |
557 | /* rate limit cannot be set to 10Mb or less in 10Gb adapters */ | |
558 | return -EINVAL; | |
559 | ||
560 | adapter->vf_rate_link_speed = actual_link_speed; | |
561 | adapter->vfinfo[vf].tx_rate = (u16)tx_rate; | |
562 | ixgbe_set_vf_rate_limit(hw, vf, tx_rate, actual_link_speed); | |
563 | ||
564 | return 0; | |
7f01648a GR |
565 | } |
566 | ||
567 | int ixgbe_ndo_get_vf_config(struct net_device *netdev, | |
568 | int vf, struct ifla_vf_info *ivi) | |
569 | { | |
570 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
571 | if (vf >= adapter->num_vfs) | |
572 | return -EINVAL; | |
573 | ivi->vf = vf; | |
574 | memcpy(&ivi->mac, adapter->vfinfo[vf].vf_mac_addresses, ETH_ALEN); | |
ff4ab206 | 575 | ivi->tx_rate = adapter->vfinfo[vf].tx_rate; |
7f01648a GR |
576 | ivi->vlan = adapter->vfinfo[vf].pf_vlan; |
577 | ivi->qos = adapter->vfinfo[vf].pf_qos; | |
578 | return 0; | |
579 | } |