]>
Commit | Line | Data |
---|---|---|
17367270 GR |
1 | /******************************************************************************* |
2 | ||
3 | Intel 10 Gigabit PCI Express Linux driver | |
3a338cbb | 4 | Copyright(c) 1999 - 2010 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 | ||
113 | ||
5d5b7c39 | 114 | static void ixgbe_set_vmolr(struct ixgbe_hw *hw, u32 vf, bool aupe) |
17367270 GR |
115 | { |
116 | u32 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf)); | |
f0412776 | 117 | vmolr |= (IXGBE_VMOLR_ROMPE | |
17367270 GR |
118 | IXGBE_VMOLR_ROPE | |
119 | IXGBE_VMOLR_BAM); | |
f0412776 GR |
120 | if (aupe) |
121 | vmolr |= IXGBE_VMOLR_AUPE; | |
122 | else | |
123 | vmolr &= ~IXGBE_VMOLR_AUPE; | |
17367270 GR |
124 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr); |
125 | } | |
126 | ||
7f01648a GR |
127 | static void ixgbe_set_vmvir(struct ixgbe_adapter *adapter, u32 vid, u32 vf) |
128 | { | |
129 | struct ixgbe_hw *hw = &adapter->hw; | |
130 | ||
131 | if (vid) | |
132 | IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf), | |
133 | (vid | IXGBE_VMVIR_VLANA_DEFAULT)); | |
134 | else | |
135 | IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf), 0); | |
136 | } | |
137 | ||
5d5b7c39 | 138 | static inline void ixgbe_vf_reset_event(struct ixgbe_adapter *adapter, u32 vf) |
17367270 GR |
139 | { |
140 | struct ixgbe_hw *hw = &adapter->hw; | |
2850062a | 141 | int rar_entry = hw->mac.num_rar_entries - (vf + 1); |
17367270 GR |
142 | |
143 | /* reset offloads to defaults */ | |
7f01648a GR |
144 | if (adapter->vfinfo[vf].pf_vlan) { |
145 | ixgbe_set_vf_vlan(adapter, true, | |
146 | adapter->vfinfo[vf].pf_vlan, vf); | |
147 | ixgbe_set_vmvir(adapter, | |
148 | (adapter->vfinfo[vf].pf_vlan | | |
149 | (adapter->vfinfo[vf].pf_qos << | |
150 | VLAN_PRIO_SHIFT)), vf); | |
151 | ixgbe_set_vmolr(hw, vf, false); | |
152 | } else { | |
153 | ixgbe_set_vmvir(adapter, 0, vf); | |
154 | ixgbe_set_vmolr(hw, vf, true); | |
155 | } | |
17367270 GR |
156 | |
157 | /* reset multicast table array for vf */ | |
158 | adapter->vfinfo[vf].num_vf_mc_hashes = 0; | |
159 | ||
160 | /* Flush and reset the mta with the new values */ | |
161 | ixgbe_set_rx_mode(adapter->netdev); | |
162 | ||
2850062a | 163 | hw->mac.ops.clear_rar(hw, rar_entry); |
17367270 GR |
164 | } |
165 | ||
5d5b7c39 ET |
166 | static int ixgbe_set_vf_mac(struct ixgbe_adapter *adapter, |
167 | int vf, unsigned char *mac_addr) | |
17367270 GR |
168 | { |
169 | struct ixgbe_hw *hw = &adapter->hw; | |
2850062a | 170 | int rar_entry = hw->mac.num_rar_entries - (vf + 1); |
17367270 GR |
171 | |
172 | memcpy(adapter->vfinfo[vf].vf_mac_addresses, mac_addr, 6); | |
2850062a | 173 | hw->mac.ops.set_rar(hw, rar_entry, mac_addr, vf, IXGBE_RAH_AV); |
17367270 GR |
174 | |
175 | return 0; | |
176 | } | |
177 | ||
178 | int ixgbe_vf_configuration(struct pci_dev *pdev, unsigned int event_mask) | |
179 | { | |
180 | unsigned char vf_mac_addr[6]; | |
c60fbb00 | 181 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
17367270 GR |
182 | unsigned int vfn = (event_mask & 0x3f); |
183 | ||
184 | bool enable = ((event_mask & 0x10000000U) != 0); | |
185 | ||
186 | if (enable) { | |
187 | random_ether_addr(vf_mac_addr); | |
396e799c ET |
188 | e_info(probe, "IOV: VF %d is enabled MAC %pM\n", |
189 | vfn, vf_mac_addr); | |
17367270 GR |
190 | /* |
191 | * Store away the VF "permananet" MAC address, it will ask | |
192 | * for it later. | |
193 | */ | |
194 | memcpy(adapter->vfinfo[vfn].vf_mac_addresses, vf_mac_addr, 6); | |
195 | } | |
196 | ||
197 | return 0; | |
198 | } | |
199 | ||
5d5b7c39 | 200 | static inline void ixgbe_vf_reset_msg(struct ixgbe_adapter *adapter, u32 vf) |
17367270 GR |
201 | { |
202 | struct ixgbe_hw *hw = &adapter->hw; | |
203 | u32 reg; | |
204 | u32 reg_offset, vf_shift; | |
205 | ||
206 | vf_shift = vf % 32; | |
207 | reg_offset = vf / 32; | |
208 | ||
209 | /* enable transmit and receive for vf */ | |
210 | reg = IXGBE_READ_REG(hw, IXGBE_VFTE(reg_offset)); | |
211 | reg |= (reg | (1 << vf_shift)); | |
212 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), reg); | |
213 | ||
214 | reg = IXGBE_READ_REG(hw, IXGBE_VFRE(reg_offset)); | |
215 | reg |= (reg | (1 << vf_shift)); | |
216 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), reg); | |
217 | ||
218 | ixgbe_vf_reset_event(adapter, vf); | |
219 | } | |
220 | ||
221 | static int ixgbe_rcv_msg_from_vf(struct ixgbe_adapter *adapter, u32 vf) | |
222 | { | |
223 | u32 mbx_size = IXGBE_VFMAILBOX_SIZE; | |
224 | u32 msgbuf[mbx_size]; | |
225 | struct ixgbe_hw *hw = &adapter->hw; | |
226 | s32 retval; | |
227 | int entries; | |
228 | u16 *hash_list; | |
229 | int add, vid; | |
d3306c29 | 230 | u8 *new_mac; |
17367270 GR |
231 | |
232 | retval = ixgbe_read_mbx(hw, msgbuf, mbx_size, vf); | |
233 | ||
234 | if (retval) | |
849c4542 | 235 | pr_err("Error receiving message from VF\n"); |
17367270 GR |
236 | |
237 | /* this is a message we already processed, do nothing */ | |
238 | if (msgbuf[0] & (IXGBE_VT_MSGTYPE_ACK | IXGBE_VT_MSGTYPE_NACK)) | |
239 | return retval; | |
240 | ||
241 | /* | |
242 | * until the vf completes a virtual function reset it should not be | |
243 | * allowed to start any configuration. | |
244 | */ | |
245 | ||
246 | if (msgbuf[0] == IXGBE_VF_RESET) { | |
247 | unsigned char *vf_mac = adapter->vfinfo[vf].vf_mac_addresses; | |
d3306c29 | 248 | new_mac = (u8 *)(&msgbuf[1]); |
396e799c | 249 | e_info(probe, "VF Reset msg received from vf %d\n", vf); |
17367270 GR |
250 | adapter->vfinfo[vf].clear_to_send = false; |
251 | ixgbe_vf_reset_msg(adapter, vf); | |
252 | adapter->vfinfo[vf].clear_to_send = true; | |
253 | ||
d3306c29 GR |
254 | if (is_valid_ether_addr(new_mac) && |
255 | !adapter->vfinfo[vf].pf_set_mac) | |
256 | ixgbe_set_vf_mac(adapter, vf, vf_mac); | |
257 | else | |
258 | ixgbe_set_vf_mac(adapter, | |
259 | vf, adapter->vfinfo[vf].vf_mac_addresses); | |
260 | ||
17367270 GR |
261 | /* reply to reset with ack and vf mac address */ |
262 | msgbuf[0] = IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_ACK; | |
d3306c29 | 263 | memcpy(new_mac, vf_mac, IXGBE_ETH_LENGTH_OF_ADDRESS); |
17367270 GR |
264 | /* |
265 | * Piggyback the multicast filter type so VF can compute the | |
266 | * correct vectors | |
267 | */ | |
268 | msgbuf[3] = hw->mac.mc_filter_type; | |
269 | ixgbe_write_mbx(hw, msgbuf, IXGBE_VF_PERMADDR_MSG_LEN, vf); | |
270 | ||
271 | return retval; | |
272 | } | |
273 | ||
274 | if (!adapter->vfinfo[vf].clear_to_send) { | |
275 | msgbuf[0] |= IXGBE_VT_MSGTYPE_NACK; | |
276 | ixgbe_write_mbx(hw, msgbuf, 1, vf); | |
277 | return retval; | |
278 | } | |
279 | ||
280 | switch ((msgbuf[0] & 0xFFFF)) { | |
281 | case IXGBE_VF_SET_MAC_ADDR: | |
d3306c29 GR |
282 | new_mac = ((u8 *)(&msgbuf[1])); |
283 | if (is_valid_ether_addr(new_mac) && | |
284 | !adapter->vfinfo[vf].pf_set_mac) { | |
285 | ixgbe_set_vf_mac(adapter, vf, new_mac); | |
286 | } else if (memcmp(adapter->vfinfo[vf].vf_mac_addresses, | |
287 | new_mac, ETH_ALEN)) { | |
288 | e_warn(drv, "VF %d attempted to override " | |
289 | "administratively set MAC address\nReload " | |
290 | "the VF driver to resume operations\n", vf); | |
291 | retval = -1; | |
17367270 GR |
292 | } |
293 | break; | |
294 | case IXGBE_VF_SET_MULTICAST: | |
295 | entries = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) | |
296 | >> IXGBE_VT_MSGINFO_SHIFT; | |
297 | hash_list = (u16 *)&msgbuf[1]; | |
298 | retval = ixgbe_set_vf_multicasts(adapter, entries, | |
299 | hash_list, vf); | |
300 | break; | |
301 | case IXGBE_VF_SET_LPE: | |
302 | WARN_ON((msgbuf[0] & 0xFFFF) == IXGBE_VF_SET_LPE); | |
303 | break; | |
304 | case IXGBE_VF_SET_VLAN: | |
305 | add = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) | |
306 | >> IXGBE_VT_MSGINFO_SHIFT; | |
307 | vid = (msgbuf[1] & IXGBE_VLVF_VLANID_MASK); | |
d3306c29 GR |
308 | if (adapter->vfinfo[vf].pf_vlan) { |
309 | e_warn(drv, "VF %d attempted to override " | |
310 | "administratively set VLAN configuration\n" | |
311 | "Reload the VF driver to resume operations\n", | |
312 | vf); | |
313 | retval = -1; | |
314 | } else { | |
315 | retval = ixgbe_set_vf_vlan(adapter, add, vid, vf); | |
316 | } | |
17367270 GR |
317 | break; |
318 | default: | |
396e799c | 319 | e_err(drv, "Unhandled Msg %8.8x\n", msgbuf[0]); |
17367270 GR |
320 | retval = IXGBE_ERR_MBX; |
321 | break; | |
322 | } | |
323 | ||
324 | /* notify the VF of the results of what it sent us */ | |
325 | if (retval) | |
326 | msgbuf[0] |= IXGBE_VT_MSGTYPE_NACK; | |
327 | else | |
328 | msgbuf[0] |= IXGBE_VT_MSGTYPE_ACK; | |
329 | ||
330 | msgbuf[0] |= IXGBE_VT_MSGTYPE_CTS; | |
331 | ||
332 | ixgbe_write_mbx(hw, msgbuf, 1, vf); | |
333 | ||
334 | return retval; | |
335 | } | |
336 | ||
337 | static void ixgbe_rcv_ack_from_vf(struct ixgbe_adapter *adapter, u32 vf) | |
338 | { | |
339 | struct ixgbe_hw *hw = &adapter->hw; | |
340 | u32 msg = IXGBE_VT_MSGTYPE_NACK; | |
341 | ||
342 | /* if device isn't clear to send it shouldn't be reading either */ | |
343 | if (!adapter->vfinfo[vf].clear_to_send) | |
344 | ixgbe_write_mbx(hw, &msg, 1, vf); | |
345 | } | |
346 | ||
347 | void ixgbe_msg_task(struct ixgbe_adapter *adapter) | |
348 | { | |
349 | struct ixgbe_hw *hw = &adapter->hw; | |
350 | u32 vf; | |
351 | ||
352 | for (vf = 0; vf < adapter->num_vfs; vf++) { | |
353 | /* process any reset requests */ | |
354 | if (!ixgbe_check_for_rst(hw, vf)) | |
355 | ixgbe_vf_reset_event(adapter, vf); | |
356 | ||
357 | /* process any messages pending */ | |
358 | if (!ixgbe_check_for_msg(hw, vf)) | |
359 | ixgbe_rcv_msg_from_vf(adapter, vf); | |
360 | ||
361 | /* process any acks */ | |
362 | if (!ixgbe_check_for_ack(hw, vf)) | |
363 | ixgbe_rcv_ack_from_vf(adapter, vf); | |
364 | } | |
365 | } | |
366 | ||
767081ad GR |
367 | void ixgbe_disable_tx_rx(struct ixgbe_adapter *adapter) |
368 | { | |
369 | struct ixgbe_hw *hw = &adapter->hw; | |
370 | ||
371 | /* disable transmit and receive for all vfs */ | |
372 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(0), 0); | |
373 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(1), 0); | |
374 | ||
375 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(0), 0); | |
376 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(1), 0); | |
377 | } | |
378 | ||
379 | void ixgbe_ping_all_vfs(struct ixgbe_adapter *adapter) | |
380 | { | |
381 | struct ixgbe_hw *hw = &adapter->hw; | |
382 | u32 ping; | |
383 | int i; | |
384 | ||
385 | for (i = 0 ; i < adapter->num_vfs; i++) { | |
386 | ping = IXGBE_PF_CONTROL_MSG; | |
387 | if (adapter->vfinfo[i].clear_to_send) | |
388 | ping |= IXGBE_VT_MSGTYPE_CTS; | |
389 | ixgbe_write_mbx(hw, &ping, 1, i); | |
390 | } | |
391 | } | |
392 | ||
7f01648a GR |
393 | int ixgbe_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac) |
394 | { | |
395 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
396 | if (!is_valid_ether_addr(mac) || (vf >= adapter->num_vfs)) | |
397 | return -EINVAL; | |
398 | adapter->vfinfo[vf].pf_set_mac = true; | |
399 | dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n", mac, vf); | |
400 | dev_info(&adapter->pdev->dev, "Reload the VF driver to make this" | |
401 | " change effective."); | |
402 | if (test_bit(__IXGBE_DOWN, &adapter->state)) { | |
403 | dev_warn(&adapter->pdev->dev, "The VF MAC address has been set," | |
404 | " but the PF device is not up.\n"); | |
405 | dev_warn(&adapter->pdev->dev, "Bring the PF device up before" | |
406 | " attempting to use the VF device.\n"); | |
407 | } | |
408 | return ixgbe_set_vf_mac(adapter, vf, mac); | |
409 | } | |
410 | ||
411 | int ixgbe_ndo_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan, u8 qos) | |
412 | { | |
413 | int err = 0; | |
414 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
415 | ||
416 | if ((vf >= adapter->num_vfs) || (vlan > 4095) || (qos > 7)) | |
417 | return -EINVAL; | |
418 | if (vlan || qos) { | |
419 | err = ixgbe_set_vf_vlan(adapter, true, vlan, vf); | |
420 | if (err) | |
421 | goto out; | |
422 | ixgbe_set_vmvir(adapter, vlan | (qos << VLAN_PRIO_SHIFT), vf); | |
423 | ixgbe_set_vmolr(&adapter->hw, vf, false); | |
424 | adapter->vfinfo[vf].pf_vlan = vlan; | |
425 | adapter->vfinfo[vf].pf_qos = qos; | |
426 | dev_info(&adapter->pdev->dev, | |
427 | "Setting VLAN %d, QOS 0x%x on VF %d\n", vlan, qos, vf); | |
428 | if (test_bit(__IXGBE_DOWN, &adapter->state)) { | |
429 | dev_warn(&adapter->pdev->dev, | |
430 | "The VF VLAN has been set," | |
431 | " but the PF device is not up.\n"); | |
432 | dev_warn(&adapter->pdev->dev, | |
433 | "Bring the PF device up before" | |
434 | " attempting to use the VF device.\n"); | |
435 | } | |
436 | } else { | |
437 | err = ixgbe_set_vf_vlan(adapter, false, | |
438 | adapter->vfinfo[vf].pf_vlan, vf); | |
439 | ixgbe_set_vmvir(adapter, vlan, vf); | |
440 | ixgbe_set_vmolr(&adapter->hw, vf, true); | |
441 | adapter->vfinfo[vf].pf_vlan = 0; | |
442 | adapter->vfinfo[vf].pf_qos = 0; | |
443 | } | |
444 | out: | |
445 | return err; | |
446 | } | |
447 | ||
448 | int ixgbe_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate) | |
449 | { | |
450 | return -EOPNOTSUPP; | |
451 | } | |
452 | ||
453 | int ixgbe_ndo_get_vf_config(struct net_device *netdev, | |
454 | int vf, struct ifla_vf_info *ivi) | |
455 | { | |
456 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
457 | if (vf >= adapter->num_vfs) | |
458 | return -EINVAL; | |
459 | ivi->vf = vf; | |
460 | memcpy(&ivi->mac, adapter->vfinfo[vf].vf_mac_addresses, ETH_ALEN); | |
461 | ivi->tx_rate = 0; | |
462 | ivi->vlan = adapter->vfinfo[vf].pf_vlan; | |
463 | ivi->qos = adapter->vfinfo[vf].pf_qos; | |
464 | return 0; | |
465 | } |