aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/linux/kni/ethtool/igb/igb_vmdq.c
blob: cdd807b96c88d472968b5dccefd19189ac5b9665 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
// SPDX-License-Identifier: GPL-2.0
/*******************************************************************************

  Intel(R) Gigabit Ethernet Linux driver
  Copyright(c) 2007-2013 Intel Corporation.

  Contact Information:
  e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497

*******************************************************************************/


#include <linux/tcp.h>

#include "igb.h"
#include "igb_vmdq.h"
#include <linux/if_vlan.h>

#ifdef CONFIG_IGB_VMDQ_NETDEV
int igb_vmdq_open(struct net_device *dev)
{
	struct igb_vmdq_adapter *vadapter = netdev_priv(dev);
	struct igb_adapter *adapter = vadapter->real_adapter;
	struct net_device *main_netdev = adapter->netdev;
	int hw_queue = vadapter->rx_ring->queue_index +
		       adapter->vfs_allocated_count;

	if (test_bit(__IGB_DOWN, &adapter->state)) {
		DPRINTK(DRV, WARNING,
			"Open %s before opening this device.\n",
			main_netdev->name);
		return -EAGAIN;
	}
	netif_carrier_off(dev);
	vadapter->tx_ring->vmdq_netdev = dev;
	vadapter->rx_ring->vmdq_netdev = dev;
	if (is_valid_ether_addr(dev->dev_addr)) {
		igb_del_mac_filter(adapter, dev->dev_addr, hw_queue);
		igb_add_mac_filter(adapter, dev->dev_addr, hw_queue);
	}
	netif_carrier_on(dev);
	return 0;
}

int igb_vmdq_close(struct net_device *dev)
{
	struct igb_vmdq_adapter *vadapter = netdev_priv(dev);
	struct igb_adapter *adapter = vadapter->real_adapter;
	int hw_queue = vadapter->rx_ring->queue_index +
		       adapter->vfs_allocated_count;

	netif_carrier_off(dev);
	igb_del_mac_filter(adapter, dev->dev_addr, hw_queue);

	vadapter->tx_ring->vmdq_netdev = NULL;
	vadapter->rx_ring->vmdq_netdev = NULL;
	return 0;
}

netdev_tx_t igb_vmdq_xmit_frame(struct sk_buff *skb, struct net_device *dev)
{
	struct igb_vmdq_adapter *vadapter = netdev_priv(dev);

	return igb_xmit_frame_ring(skb, vadapter->tx_ring);
}

struct net_device_stats *igb_vmdq_get_stats(struct net_device *dev)
{
	struct igb_vmdq_adapter *vadapter = netdev_priv(dev);
        struct igb_adapter *adapter = vadapter->real_adapter;
        struct e1000_hw *hw = &adapter->hw;
	int hw_queue = vadapter->rx_ring->queue_index +
		       adapter->vfs_allocated_count;

	vadapter->net_stats.rx_packets +=
			E1000_READ_REG(hw, E1000_PFVFGPRC(hw_queue));
	E1000_WRITE_REG(hw, E1000_PFVFGPRC(hw_queue), 0);
        vadapter->net_stats.tx_packets +=
			E1000_READ_REG(hw, E1000_PFVFGPTC(hw_queue));
        E1000_WRITE_REG(hw, E1000_PFVFGPTC(hw_queue), 0);
        vadapter->net_stats.rx_bytes +=
			E1000_READ_REG(hw, E1000_PFVFGORC(hw_queue));
        E1000_WRITE_REG(hw, E1000_PFVFGORC(hw_queue), 0);
        vadapter->net_stats.tx_bytes +=
			E1000_READ_REG(hw, E1000_PFVFGOTC(hw_queue));
        E1000_WRITE_REG(hw, E1000_PFVFGOTC(hw_queue), 0);
        vadapter->net_stats.multicast +=
			E1000_READ_REG(hw, E1000_PFVFMPRC(hw_queue));
        E1000_WRITE_REG(hw, E1000_PFVFMPRC(hw_queue), 0);
	/* only return the current stats */
	return &vadapter->net_stats;
}

/**
 * igb_write_vm_addr_list - write unicast addresses to RAR table
 * @netdev: network interface device structure
 *
 * Writes unicast address list to the RAR table.
 * Returns: -ENOMEM on failure/insufficient address space
 *                0 on no addresses written
 *                X on writing X addresses to the RAR table
 **/
static int igb_write_vm_addr_list(struct net_device *netdev)
{
	struct igb_vmdq_adapter *vadapter = netdev_priv(netdev);
        struct igb_adapter *adapter = vadapter->real_adapter;
	int count = 0;
	int hw_queue = vadapter->rx_ring->queue_index +
		       adapter->vfs_allocated_count;

	/* return ENOMEM indicating insufficient memory for addresses */
	if (netdev_uc_count(netdev) > igb_available_rars(adapter))
		return -ENOMEM;

	if (!netdev_uc_empty(netdev)) {
#ifdef NETDEV_HW_ADDR_T_UNICAST
		struct netdev_hw_addr *ha;
#else
		struct dev_mc_list *ha;
#endif
		netdev_for_each_uc_addr(ha, netdev) {
#ifdef NETDEV_HW_ADDR_T_UNICAST
			igb_del_mac_filter(adapter, ha->addr, hw_queue);
			igb_add_mac_filter(adapter, ha->addr, hw_queue);
#else
			igb_del_mac_filter(adapter, ha->da_addr, hw_queue);
			igb_add_mac_filter(adapter, ha->da_addr, hw_queue);
#endif
			count++;
		}
	}
	return count;
}


#define E1000_VMOLR_UPE		0x20000000 /* Unicast promiscuous mode */
void igb_vmdq_set_rx_mode(struct net_device *dev)
{
	struct igb_vmdq_adapter *vadapter = netdev_priv(dev);
        struct igb_adapter *adapter = vadapter->real_adapter;
        struct e1000_hw *hw = &adapter->hw;
	u32 vmolr, rctl;
	int hw_queue = vadapter->rx_ring->queue_index +
		       adapter->vfs_allocated_count;

	/* Check for Promiscuous and All Multicast modes */
	vmolr = E1000_READ_REG(hw, E1000_VMOLR(hw_queue));

	/* clear the affected bits */
	vmolr &= ~(E1000_VMOLR_UPE | E1000_VMOLR_MPME |
		   E1000_VMOLR_ROPE | E1000_VMOLR_ROMPE);

	if (dev->flags & IFF_PROMISC) {
		vmolr |= E1000_VMOLR_UPE;
		rctl = E1000_READ_REG(hw, E1000_RCTL);
		rctl |= E1000_RCTL_UPE;
		E1000_WRITE_REG(hw, E1000_RCTL, rctl);
	} else {
		rctl = E1000_READ_REG(hw, E1000_RCTL);
		rctl &= ~E1000_RCTL_UPE;
		E1000_WRITE_REG(hw, E1000_RCTL, rctl);
		if (dev->flags & IFF_ALLMULTI) {
			vmolr |= E1000_VMOLR_MPME;
		} else {
			/*
			 * Write addresses to the MTA, if the attempt fails
			 * then we should just turn on promiscuous mode so
			 * that we can at least receive multicast traffic
			 */
			if (igb_write_mc_addr_list(adapter->netdev) != 0)
				vmolr |= E1000_VMOLR_ROMPE;
		}
#ifdef HAVE_SET_RX_MODE
		/*
		 * Write addresses to available RAR registers, if there is not
		 * sufficient space to store all the addresses then enable
		 * unicast promiscuous mode
		 */
		if (igb_write_vm_addr_list(dev) < 0)
			vmolr |= E1000_VMOLR_UPE;
#endif
	}
	E1000_WRITE_REG(hw, E1000_VMOLR(hw_queue), vmolr);

	return;
}

int igb_vmdq_set_mac(struct net_device *dev, void *p)
{
	struct sockaddr *addr = p;
	struct igb_vmdq_adapter *vadapter = netdev_priv(dev);
        struct igb_adapter *adapter = vadapter->real_adapter;
	int hw_queue = vadapter->rx_ring->queue_index +
		       adapter->vfs_allocated_count;

	igb_del_mac_filter(adapter, dev->dev_addr, hw_queue);
	memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
	return igb_add_mac_filter(adapter, dev->dev_addr, hw_queue);
}

int igb_vmdq_change_mtu(struct net_device *dev, int new_mtu)
{
	struct igb_vmdq_adapter *vadapter = netdev_priv(dev);
	struct igb_adapter *adapter = vadapter->real_adapter;

	if (adapter->netdev->mtu < new_mtu) {
		DPRINTK(PROBE, INFO,
			"Set MTU on %s to >= %d "
			"before changing MTU on %s\n",
			adapter->netdev->name, new_mtu, dev->name);
		return -EINVAL;
	}
	dev->mtu = new_mtu;
	return 0;
}

void igb_vmdq_tx_timeout(struct net_device *dev)
{
	return;
}

void igb_vmdq_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
{
	struct igb_vmdq_adapter *vadapter = netdev_priv(dev);
	struct igb_adapter *adapter = vadapter->real_adapter;
	struct e1000_hw *hw = &adapter->hw;
	int hw_queue = vadapter->rx_ring->queue_index +
		       adapter->vfs_allocated_count;

	vadapter->vlgrp = grp;

	igb_enable_vlan_tags(adapter);
	E1000_WRITE_REG(hw, E1000_VMVIR(hw_queue), 0);

	return;
}
void igb_vmdq_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
{
	struct igb_vmdq_adapter *vadapter = netdev_priv(dev);
	struct igb_adapter *adapter = vadapter->real_adapter;
#ifndef HAVE_NETDEV_VLAN_FEATURES
	struct net_device *v_netdev;
#endif
	int hw_queue = vadapter->rx_ring->queue_index +
		       adapter->vfs_allocated_count;

	/* attempt to add filter to vlvf array */
	igb_vlvf_set(adapter, vid, TRUE, hw_queue);

#ifndef HAVE_NETDEV_VLAN_FEATURES

	/* Copy feature flags from netdev to the vlan netdev for this vid.
	 * This allows things like TSO to bubble down to our vlan device.
	 */
	v_netdev = vlan_group_get_device(vadapter->vlgrp, vid);
	v_netdev->features |= adapter->netdev->features;
	vlan_group_set_device(vadapter->vlgrp, vid, v_netdev);
#endif

	return;
}
void igb_vmdq_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
{
	struct igb_vmdq_adapter *vadapter = netdev_priv(dev);
	struct igb_adapter *adapter = vadapter->real_adapter;
	int hw_queue = vadapter->rx_ring->queue_index +
		       adapter->vfs_allocated_count;

	vlan_group_set_device(vadapter->vlgrp, vid, NULL);
	/* remove vlan from VLVF table array */
	igb_vlvf_set(adapter, vid, FALSE, hw_queue);


	return;
}

static int igb_vmdq_get_settings(struct net_device *netdev,
				   struct ethtool_cmd *ecmd)
{
	struct igb_vmdq_adapter *vadapter = netdev_priv(netdev);
	struct igb_adapter *adapter = vadapter->real_adapter;
	struct e1000_hw *hw = &adapter->hw;
	u32 status;

	if (hw->phy.media_type == e1000_media_type_copper) {

		ecmd->supported = (SUPPORTED_10baseT_Half |
				   SUPPORTED_10baseT_Full |
				   SUPPORTED_100baseT_Half |
				   SUPPORTED_100baseT_Full |
				   SUPPORTED_1000baseT_Full|
				   SUPPORTED_Autoneg |
				   SUPPORTED_TP);
		ecmd->advertising = ADVERTISED_TP;

		if (hw->mac.autoneg == 1) {
			ecmd->advertising |= ADVERTISED_Autoneg;
			/* the e1000 autoneg seems to match ethtool nicely */
			ecmd->advertising |= hw->phy.autoneg_advertised;
		}

		ecmd->port = PORT_TP;
		ecmd->phy_address = hw->phy.addr;
	} else {
		ecmd->supported   = (SUPPORTED_1000baseT_Full |
				     SUPPORTED_FIBRE |
				     SUPPORTED_Autoneg);

		ecmd->advertising = (ADVERTISED_1000baseT_Full |
				     ADVERTISED_FIBRE |
				     ADVERTISED_Autoneg);

		ecmd->port = PORT_FIBRE;
	}

	ecmd->transceiver = XCVR_INTERNAL;

	status = E1000_READ_REG(hw, E1000_STATUS);

	if (status & E1000_STATUS_LU) {

		if ((status & E1000_STATUS_SPEED_1000) ||
		    hw->phy.media_type != e1000_media_type_copper)
			ecmd->speed = SPEED_1000;
		else if (status & E1000_STATUS_SPEED_100)
			ecmd->speed = SPEED_100;
		else
			ecmd->speed = SPEED_10;

		if ((status & E1000_STATUS_FD) ||
		    hw->phy.media_type != e1000_media_type_copper)
			ecmd->duplex = DUPLEX_FULL;
		else
			ecmd->duplex = DUPLEX_HALF;
	} else {
		ecmd->speed = -1;
		ecmd->duplex = -1;
	}

	ecmd->autoneg = hw->mac.autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE;
	return 0;
}


static u32 igb_vmdq_get_msglevel(struct net_device *netdev)
{
	struct igb_vmdq_adapter *vadapter = netdev_priv(netdev);
	struct igb_adapter *adapter = vadapter->real_adapter;
	return adapter->msg_enable;
}

static void igb_vmdq_get_drvinfo(struct net_device *netdev,
				   struct ethtool_drvinfo *drvinfo)
{
	struct igb_vmdq_adapter *vadapter = netdev_priv(netdev);
	struct igb_adapter *adapter = vadapter->real_adapter;
	struct net_device *main_netdev = adapter->netdev;

	strncpy(drvinfo->driver, igb_driver_name, 32);
	strncpy(drvinfo->version, igb_driver_version, 32);

	strncpy(drvinfo->fw_version, "N/A", 4);
	snprintf(drvinfo->bus_info, 32, "%s VMDQ %d", main_netdev->name,
		 vadapter->rx_ring->queue_index);
	drvinfo->n_stats = 0;
	drvinfo->testinfo_len = 0;
	drvinfo->regdump_len = 0;
}

static void igb_vmdq_get_ringparam(struct net_device *netdev,
				     struct ethtool_ringparam *ring)
{
	struct igb_vmdq_adapter *vadapter = netdev_priv(netdev);

	struct igb_ring *tx_ring = vadapter->tx_ring;
	struct igb_ring *rx_ring = vadapter->rx_ring;

	ring->rx_max_pending = IGB_MAX_RXD;
	ring->tx_max_pending = IGB_MAX_TXD;
	ring->rx_mini_max_pending = 0;
	ring->rx_jumbo_max_pending = 0;
	ring->rx_pending = rx_ring->count;
	ring->tx_pending = tx_ring->count;
	ring->rx_mini_pending = 0;
	ring->rx_jumbo_pending = 0;
}
static u32 igb_vmdq_get_rx_csum(struct net_device *netdev)
{
	struct igb_vmdq_adapter *vadapter = netdev_priv(netdev);
	struct igb_adapter *adapter = vadapter->real_adapter;

	return test_bit(IGB_RING_FLAG_RX_CSUM, &adapter->rx_ring[0]->flags);
}


static struct ethtool_ops igb_vmdq_ethtool_ops = {
	.get_settings           = igb_vmdq_get_settings,
	.get_drvinfo            = igb_vmdq_get_drvinfo,
	.get_link               = ethtool_op_get_link,
	.get_ringparam          = igb_vmdq_get_ringparam,
	.get_rx_csum            = igb_vmdq_get_rx_csum,
	.get_tx_csum            = ethtool_op_get_tx_csum,
	.get_sg                 = ethtool_op_get_sg,
	.set_sg                 = ethtool_op_set_sg,
	.get_msglevel           = igb_vmdq_get_msglevel,
#ifdef NETIF_F_TSO
	.get_tso                = ethtool_op_get_tso,
#endif
#ifdef HAVE_ETHTOOL_GET_PERM_ADDR
	.get_perm_addr          = ethtool_op_get_perm_addr,
#endif
};

void igb_vmdq_set_ethtool_ops(struct net_device *netdev)
{
	SET_ETHTOOL_OPS(netdev, &igb_vmdq_ethtool_ops);
}


#endif /* CONFIG_IGB_VMDQ_NETDEV */