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