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