1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2013 - 2019 Intel Corporation. */
5 #include <linux/vmalloc.h>
6 #include <net/udp_tunnel.h>
7 #include <linux/if_macvlan.h>
10 * fm10k_setup_tx_resources - allocate Tx resources (Descriptors)
11 * @tx_ring: tx descriptor ring (for a specific queue) to setup
13 * Return 0 on success, negative on failure
15 int fm10k_setup_tx_resources(struct fm10k_ring
*tx_ring
)
17 struct device
*dev
= tx_ring
->dev
;
20 size
= sizeof(struct fm10k_tx_buffer
) * tx_ring
->count
;
22 tx_ring
->tx_buffer
= vzalloc(size
);
23 if (!tx_ring
->tx_buffer
)
26 u64_stats_init(&tx_ring
->syncp
);
28 /* round up to nearest 4K */
29 tx_ring
->size
= tx_ring
->count
* sizeof(struct fm10k_tx_desc
);
30 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
32 tx_ring
->desc
= dma_alloc_coherent(dev
, tx_ring
->size
,
33 &tx_ring
->dma
, GFP_KERNEL
);
40 vfree(tx_ring
->tx_buffer
);
41 tx_ring
->tx_buffer
= NULL
;
46 * fm10k_setup_all_tx_resources - allocate all queues Tx resources
47 * @interface: board private structure
49 * If this function returns with an error, then it's possible one or
50 * more of the rings is populated (while the rest are not). It is the
51 * callers duty to clean those orphaned rings.
53 * Return 0 on success, negative on failure
55 static int fm10k_setup_all_tx_resources(struct fm10k_intfc
*interface
)
59 for (i
= 0; i
< interface
->num_tx_queues
; i
++) {
60 err
= fm10k_setup_tx_resources(interface
->tx_ring
[i
]);
64 netif_err(interface
, probe
, interface
->netdev
,
65 "Allocation for Tx Queue %u failed\n", i
);
71 /* rewind the index freeing the rings as we go */
73 fm10k_free_tx_resources(interface
->tx_ring
[i
]);
78 * fm10k_setup_rx_resources - allocate Rx resources (Descriptors)
79 * @rx_ring: rx descriptor ring (for a specific queue) to setup
81 * Returns 0 on success, negative on failure
83 int fm10k_setup_rx_resources(struct fm10k_ring
*rx_ring
)
85 struct device
*dev
= rx_ring
->dev
;
88 size
= sizeof(struct fm10k_rx_buffer
) * rx_ring
->count
;
90 rx_ring
->rx_buffer
= vzalloc(size
);
91 if (!rx_ring
->rx_buffer
)
94 u64_stats_init(&rx_ring
->syncp
);
96 /* Round up to nearest 4K */
97 rx_ring
->size
= rx_ring
->count
* sizeof(union fm10k_rx_desc
);
98 rx_ring
->size
= ALIGN(rx_ring
->size
, 4096);
100 rx_ring
->desc
= dma_alloc_coherent(dev
, rx_ring
->size
,
101 &rx_ring
->dma
, GFP_KERNEL
);
107 vfree(rx_ring
->rx_buffer
);
108 rx_ring
->rx_buffer
= NULL
;
113 * fm10k_setup_all_rx_resources - allocate all queues Rx resources
114 * @interface: board private structure
116 * If this function returns with an error, then it's possible one or
117 * more of the rings is populated (while the rest are not). It is the
118 * callers duty to clean those orphaned rings.
120 * Return 0 on success, negative on failure
122 static int fm10k_setup_all_rx_resources(struct fm10k_intfc
*interface
)
126 for (i
= 0; i
< interface
->num_rx_queues
; i
++) {
127 err
= fm10k_setup_rx_resources(interface
->rx_ring
[i
]);
131 netif_err(interface
, probe
, interface
->netdev
,
132 "Allocation for Rx Queue %u failed\n", i
);
138 /* rewind the index freeing the rings as we go */
140 fm10k_free_rx_resources(interface
->rx_ring
[i
]);
144 void fm10k_unmap_and_free_tx_resource(struct fm10k_ring
*ring
,
145 struct fm10k_tx_buffer
*tx_buffer
)
147 if (tx_buffer
->skb
) {
148 dev_kfree_skb_any(tx_buffer
->skb
);
149 if (dma_unmap_len(tx_buffer
, len
))
150 dma_unmap_single(ring
->dev
,
151 dma_unmap_addr(tx_buffer
, dma
),
152 dma_unmap_len(tx_buffer
, len
),
154 } else if (dma_unmap_len(tx_buffer
, len
)) {
155 dma_unmap_page(ring
->dev
,
156 dma_unmap_addr(tx_buffer
, dma
),
157 dma_unmap_len(tx_buffer
, len
),
160 tx_buffer
->next_to_watch
= NULL
;
161 tx_buffer
->skb
= NULL
;
162 dma_unmap_len_set(tx_buffer
, len
, 0);
163 /* tx_buffer must be completely set up in the transmit path */
167 * fm10k_clean_tx_ring - Free Tx Buffers
168 * @tx_ring: ring to be cleaned
170 static void fm10k_clean_tx_ring(struct fm10k_ring
*tx_ring
)
175 /* ring already cleared, nothing to do */
176 if (!tx_ring
->tx_buffer
)
179 /* Free all the Tx ring sk_buffs */
180 for (i
= 0; i
< tx_ring
->count
; i
++) {
181 struct fm10k_tx_buffer
*tx_buffer
= &tx_ring
->tx_buffer
[i
];
183 fm10k_unmap_and_free_tx_resource(tx_ring
, tx_buffer
);
186 /* reset BQL values */
187 netdev_tx_reset_queue(txring_txq(tx_ring
));
189 size
= sizeof(struct fm10k_tx_buffer
) * tx_ring
->count
;
190 memset(tx_ring
->tx_buffer
, 0, size
);
192 /* Zero out the descriptor ring */
193 memset(tx_ring
->desc
, 0, tx_ring
->size
);
197 * fm10k_free_tx_resources - Free Tx Resources per Queue
198 * @tx_ring: Tx descriptor ring for a specific queue
200 * Free all transmit software resources
202 void fm10k_free_tx_resources(struct fm10k_ring
*tx_ring
)
204 fm10k_clean_tx_ring(tx_ring
);
206 vfree(tx_ring
->tx_buffer
);
207 tx_ring
->tx_buffer
= NULL
;
209 /* if not set, then don't free */
213 dma_free_coherent(tx_ring
->dev
, tx_ring
->size
,
214 tx_ring
->desc
, tx_ring
->dma
);
215 tx_ring
->desc
= NULL
;
219 * fm10k_clean_all_tx_rings - Free Tx Buffers for all queues
220 * @interface: board private structure
222 void fm10k_clean_all_tx_rings(struct fm10k_intfc
*interface
)
226 for (i
= 0; i
< interface
->num_tx_queues
; i
++)
227 fm10k_clean_tx_ring(interface
->tx_ring
[i
]);
231 * fm10k_free_all_tx_resources - Free Tx Resources for All Queues
232 * @interface: board private structure
234 * Free all transmit software resources
236 static void fm10k_free_all_tx_resources(struct fm10k_intfc
*interface
)
238 int i
= interface
->num_tx_queues
;
241 fm10k_free_tx_resources(interface
->tx_ring
[i
]);
245 * fm10k_clean_rx_ring - Free Rx Buffers per Queue
246 * @rx_ring: ring to free buffers from
248 static void fm10k_clean_rx_ring(struct fm10k_ring
*rx_ring
)
253 if (!rx_ring
->rx_buffer
)
256 dev_kfree_skb(rx_ring
->skb
);
259 /* Free all the Rx ring sk_buffs */
260 for (i
= 0; i
< rx_ring
->count
; i
++) {
261 struct fm10k_rx_buffer
*buffer
= &rx_ring
->rx_buffer
[i
];
262 /* clean-up will only set page pointer to NULL */
266 dma_unmap_page(rx_ring
->dev
, buffer
->dma
,
267 PAGE_SIZE
, DMA_FROM_DEVICE
);
268 __free_page(buffer
->page
);
273 size
= sizeof(struct fm10k_rx_buffer
) * rx_ring
->count
;
274 memset(rx_ring
->rx_buffer
, 0, size
);
276 /* Zero out the descriptor ring */
277 memset(rx_ring
->desc
, 0, rx_ring
->size
);
279 rx_ring
->next_to_alloc
= 0;
280 rx_ring
->next_to_clean
= 0;
281 rx_ring
->next_to_use
= 0;
285 * fm10k_free_rx_resources - Free Rx Resources
286 * @rx_ring: ring to clean the resources from
288 * Free all receive software resources
290 void fm10k_free_rx_resources(struct fm10k_ring
*rx_ring
)
292 fm10k_clean_rx_ring(rx_ring
);
294 vfree(rx_ring
->rx_buffer
);
295 rx_ring
->rx_buffer
= NULL
;
297 /* if not set, then don't free */
301 dma_free_coherent(rx_ring
->dev
, rx_ring
->size
,
302 rx_ring
->desc
, rx_ring
->dma
);
304 rx_ring
->desc
= NULL
;
308 * fm10k_clean_all_rx_rings - Free Rx Buffers for all queues
309 * @interface: board private structure
311 void fm10k_clean_all_rx_rings(struct fm10k_intfc
*interface
)
315 for (i
= 0; i
< interface
->num_rx_queues
; i
++)
316 fm10k_clean_rx_ring(interface
->rx_ring
[i
]);
320 * fm10k_free_all_rx_resources - Free Rx Resources for All Queues
321 * @interface: board private structure
323 * Free all receive software resources
325 static void fm10k_free_all_rx_resources(struct fm10k_intfc
*interface
)
327 int i
= interface
->num_rx_queues
;
330 fm10k_free_rx_resources(interface
->rx_ring
[i
]);
334 * fm10k_request_glort_range - Request GLORTs for use in configuring rules
335 * @interface: board private structure
337 * This function allocates a range of glorts for this interface to use.
339 static void fm10k_request_glort_range(struct fm10k_intfc
*interface
)
341 struct fm10k_hw
*hw
= &interface
->hw
;
342 u16 mask
= (~hw
->mac
.dglort_map
) >> FM10K_DGLORTMAP_MASK_SHIFT
;
344 /* establish GLORT base */
345 interface
->glort
= hw
->mac
.dglort_map
& FM10K_DGLORTMAP_NONE
;
346 interface
->glort_count
= 0;
348 /* nothing we can do until mask is allocated */
349 if (hw
->mac
.dglort_map
== FM10K_DGLORTMAP_NONE
)
352 /* we support 3 possible GLORT configurations.
353 * 1: VFs consume all but the last 1
354 * 2: VFs and PF split glorts with possible gap between
355 * 3: VFs allocated first 64, all others belong to PF
357 if (mask
<= hw
->iov
.total_vfs
) {
358 interface
->glort_count
= 1;
359 interface
->glort
+= mask
;
360 } else if (mask
< 64) {
361 interface
->glort_count
= (mask
+ 1) / 2;
362 interface
->glort
+= interface
->glort_count
;
364 interface
->glort_count
= mask
- 63;
365 interface
->glort
+= 64;
370 * fm10k_restore_udp_port_info
371 * @interface: board private structure
373 * This function restores the value in the tunnel_cfg register(s) after reset
375 static void fm10k_restore_udp_port_info(struct fm10k_intfc
*interface
)
377 struct fm10k_hw
*hw
= &interface
->hw
;
379 /* only the PF supports configuring tunnels */
380 if (hw
->mac
.type
!= fm10k_mac_pf
)
383 /* restore tunnel configuration register */
384 fm10k_write_reg(hw
, FM10K_TUNNEL_CFG
,
385 ntohs(interface
->vxlan_port
) |
386 (ETH_P_TEB
<< FM10K_TUNNEL_CFG_NVGRE_SHIFT
));
388 /* restore Geneve tunnel configuration register */
389 fm10k_write_reg(hw
, FM10K_TUNNEL_CFG_GENEVE
,
390 ntohs(interface
->geneve_port
));
394 * fm10k_udp_tunnel_sync - Called when UDP tunnel ports change
395 * @dev: network interface device structure
396 * @table: Tunnel table (according to tables of @fm10k_udp_tunnels)
398 * This function is called when a new UDP tunnel port is added or deleted.
399 * Due to hardware restrictions, only one port per type can be offloaded at
400 * once. Core will send to the driver a port of its choice.
402 static int fm10k_udp_tunnel_sync(struct net_device
*dev
, unsigned int table
)
404 struct fm10k_intfc
*interface
= netdev_priv(dev
);
405 struct udp_tunnel_info ti
;
407 udp_tunnel_nic_get_port(dev
, table
, 0, &ti
);
409 interface
->vxlan_port
= ti
.port
;
411 interface
->geneve_port
= ti
.port
;
413 fm10k_restore_udp_port_info(interface
);
417 static const struct udp_tunnel_nic_info fm10k_udp_tunnels
= {
418 .sync_table
= fm10k_udp_tunnel_sync
,
420 { .n_entries
= 1, .tunnel_types
= UDP_TUNNEL_TYPE_VXLAN
, },
421 { .n_entries
= 1, .tunnel_types
= UDP_TUNNEL_TYPE_GENEVE
, },
426 * fm10k_open - Called when a network interface is made active
427 * @netdev: network interface device structure
429 * Returns 0 on success, negative value on failure
431 * The open entry point is called when a network interface is made
432 * active by the system (IFF_UP). At this point all resources needed
433 * for transmit and receive operations are allocated, the interrupt
434 * handler is registered with the OS, the watchdog timer is started,
435 * and the stack is notified that the interface is ready.
437 int fm10k_open(struct net_device
*netdev
)
439 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
442 /* allocate transmit descriptors */
443 err
= fm10k_setup_all_tx_resources(interface
);
447 /* allocate receive descriptors */
448 err
= fm10k_setup_all_rx_resources(interface
);
452 /* allocate interrupt resources */
453 err
= fm10k_qv_request_irq(interface
);
457 /* setup GLORT assignment for this port */
458 fm10k_request_glort_range(interface
);
460 /* Notify the stack of the actual queue counts */
461 err
= netif_set_real_num_tx_queues(netdev
,
462 interface
->num_tx_queues
);
466 err
= netif_set_real_num_rx_queues(netdev
,
467 interface
->num_rx_queues
);
476 fm10k_qv_free_irq(interface
);
478 fm10k_free_all_rx_resources(interface
);
480 fm10k_free_all_tx_resources(interface
);
486 * fm10k_close - Disables a network interface
487 * @netdev: network interface device structure
489 * Returns 0, this is not allowed to fail
491 * The close entry point is called when an interface is de-activated
492 * by the OS. The hardware is still under the drivers control, but
493 * needs to be disabled. A global MAC reset is issued to stop the
494 * hardware, and all transmit and receive resources are freed.
496 int fm10k_close(struct net_device
*netdev
)
498 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
500 fm10k_down(interface
);
502 fm10k_qv_free_irq(interface
);
504 fm10k_free_all_tx_resources(interface
);
505 fm10k_free_all_rx_resources(interface
);
510 static netdev_tx_t
fm10k_xmit_frame(struct sk_buff
*skb
, struct net_device
*dev
)
512 struct fm10k_intfc
*interface
= netdev_priv(dev
);
513 int num_tx_queues
= READ_ONCE(interface
->num_tx_queues
);
514 unsigned int r_idx
= skb
->queue_mapping
;
518 return NETDEV_TX_BUSY
;
520 if ((skb
->protocol
== htons(ETH_P_8021Q
)) &&
521 !skb_vlan_tag_present(skb
)) {
522 /* FM10K only supports hardware tagging, any tags in frame
523 * are considered 2nd level or "outer" tags
525 struct vlan_hdr
*vhdr
;
528 /* make sure skb is not shared */
529 skb
= skb_share_check(skb
, GFP_ATOMIC
);
533 /* make sure there is enough room to move the ethernet header */
534 if (unlikely(!pskb_may_pull(skb
, VLAN_ETH_HLEN
)))
537 /* verify the skb head is not shared */
538 err
= skb_cow_head(skb
, 0);
544 /* locate VLAN header */
545 vhdr
= (struct vlan_hdr
*)(skb
->data
+ ETH_HLEN
);
547 /* pull the 2 key pieces of data out of it */
548 __vlan_hwaccel_put_tag(skb
,
550 ntohs(vhdr
->h_vlan_TCI
));
551 proto
= vhdr
->h_vlan_encapsulated_proto
;
552 skb
->protocol
= (ntohs(proto
) >= 1536) ? proto
:
555 /* squash it by moving the ethernet addresses up 4 bytes */
556 memmove(skb
->data
+ VLAN_HLEN
, skb
->data
, 12);
557 __skb_pull(skb
, VLAN_HLEN
);
558 skb_reset_mac_header(skb
);
561 /* The minimum packet size for a single buffer is 17B so pad the skb
562 * in order to meet this minimum size requirement.
564 if (unlikely(skb
->len
< 17)) {
565 int pad_len
= 17 - skb
->len
;
567 if (skb_pad(skb
, pad_len
))
569 __skb_put(skb
, pad_len
);
572 if (r_idx
>= num_tx_queues
)
573 r_idx
%= num_tx_queues
;
575 err
= fm10k_xmit_frame_ring(skb
, interface
->tx_ring
[r_idx
]);
581 * fm10k_tx_timeout - Respond to a Tx Hang
582 * @netdev: network interface device structure
583 * @txqueue: the index of the Tx queue that timed out
585 static void fm10k_tx_timeout(struct net_device
*netdev
, unsigned int txqueue
)
587 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
588 struct fm10k_ring
*tx_ring
;
589 bool real_tx_hang
= false;
591 if (txqueue
>= interface
->num_tx_queues
) {
592 WARN(1, "invalid Tx queue index %d", txqueue
);
596 tx_ring
= interface
->tx_ring
[txqueue
];
597 if (check_for_tx_hang(tx_ring
) && fm10k_check_tx_hang(tx_ring
))
600 #define TX_TIMEO_LIMIT 16000
602 fm10k_tx_timeout_reset(interface
);
604 netif_info(interface
, drv
, netdev
,
605 "Fake Tx hang detected with timeout of %d seconds\n",
606 netdev
->watchdog_timeo
/ HZ
);
608 /* fake Tx hang - increase the kernel timeout */
609 if (netdev
->watchdog_timeo
< TX_TIMEO_LIMIT
)
610 netdev
->watchdog_timeo
*= 2;
615 * fm10k_host_mbx_ready - Check PF interface's mailbox readiness
616 * @interface: board private structure
618 * This function checks if the PF interface's mailbox is ready before queueing
619 * mailbox messages for transmission. This will prevent filling the TX mailbox
620 * queue when the receiver is not ready. VF interfaces are exempt from this
621 * check since it will block all PF-VF mailbox messages from being sent from
622 * the VF to the PF at initialization.
624 static bool fm10k_host_mbx_ready(struct fm10k_intfc
*interface
)
626 struct fm10k_hw
*hw
= &interface
->hw
;
628 return (hw
->mac
.type
== fm10k_mac_vf
|| interface
->host_ready
);
632 * fm10k_queue_vlan_request - Queue a VLAN update request
633 * @interface: the fm10k interface structure
635 * @vsi: VSI index number
636 * @set: whether to set or clear
638 * This function queues up a VLAN update. For VFs, this must be sent to the
639 * managing PF over the mailbox. For PFs, we'll use the same handling so that
640 * it's similar to the VF. This avoids storming the PF<->VF mailbox with too
641 * many VLAN updates during reset.
643 int fm10k_queue_vlan_request(struct fm10k_intfc
*interface
,
644 u32 vid
, u8 vsi
, bool set
)
646 struct fm10k_macvlan_request
*request
;
649 /* This must be atomic since we may be called while the netdev
650 * addr_list_lock is held
652 request
= kzalloc(sizeof(*request
), GFP_ATOMIC
);
656 request
->type
= FM10K_VLAN_REQUEST
;
657 request
->vlan
.vid
= vid
;
658 request
->vlan
.vsi
= vsi
;
661 spin_lock_irqsave(&interface
->macvlan_lock
, flags
);
662 list_add_tail(&request
->list
, &interface
->macvlan_requests
);
663 spin_unlock_irqrestore(&interface
->macvlan_lock
, flags
);
665 fm10k_macvlan_schedule(interface
);
671 * fm10k_queue_mac_request - Queue a MAC update request
672 * @interface: the fm10k interface structure
673 * @glort: the target glort for this update
674 * @addr: the address to update
675 * @vid: the vid to update
676 * @set: whether to add or remove
678 * This function queues up a MAC request for sending to the switch manager.
679 * A separate thread monitors the queue and sends updates to the switch
680 * manager. Return 0 on success, and negative error code on failure.
682 int fm10k_queue_mac_request(struct fm10k_intfc
*interface
, u16 glort
,
683 const unsigned char *addr
, u16 vid
, bool set
)
685 struct fm10k_macvlan_request
*request
;
688 /* This must be atomic since we may be called while the netdev
689 * addr_list_lock is held
691 request
= kzalloc(sizeof(*request
), GFP_ATOMIC
);
695 if (is_multicast_ether_addr(addr
))
696 request
->type
= FM10K_MC_MAC_REQUEST
;
698 request
->type
= FM10K_UC_MAC_REQUEST
;
700 ether_addr_copy(request
->mac
.addr
, addr
);
701 request
->mac
.glort
= glort
;
702 request
->mac
.vid
= vid
;
705 spin_lock_irqsave(&interface
->macvlan_lock
, flags
);
706 list_add_tail(&request
->list
, &interface
->macvlan_requests
);
707 spin_unlock_irqrestore(&interface
->macvlan_lock
, flags
);
709 fm10k_macvlan_schedule(interface
);
715 * fm10k_clear_macvlan_queue - Cancel pending updates for a given glort
716 * @interface: the fm10k interface structure
717 * @glort: the target glort to clear
718 * @vlans: true to clear VLAN messages, false to ignore them
720 * Cancel any outstanding MAC/VLAN requests for a given glort. This is
721 * expected to be called when a logical port goes down.
723 void fm10k_clear_macvlan_queue(struct fm10k_intfc
*interface
,
724 u16 glort
, bool vlans
)
727 struct fm10k_macvlan_request
*r
, *tmp
;
730 spin_lock_irqsave(&interface
->macvlan_lock
, flags
);
732 /* Free any outstanding MAC/VLAN requests for this interface */
733 list_for_each_entry_safe(r
, tmp
, &interface
->macvlan_requests
, list
) {
735 case FM10K_MC_MAC_REQUEST
:
736 case FM10K_UC_MAC_REQUEST
:
737 /* Don't free requests for other interfaces */
738 if (r
->mac
.glort
!= glort
)
741 case FM10K_VLAN_REQUEST
:
750 spin_unlock_irqrestore(&interface
->macvlan_lock
, flags
);
753 static int fm10k_uc_vlan_unsync(struct net_device
*netdev
,
754 const unsigned char *uc_addr
)
756 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
757 u16 glort
= interface
->glort
;
758 u16 vid
= interface
->vid
;
759 bool set
= !!(vid
/ VLAN_N_VID
);
762 /* drop any leading bits on the VLAN ID */
763 vid
&= VLAN_N_VID
- 1;
765 err
= fm10k_queue_mac_request(interface
, glort
, uc_addr
, vid
, set
);
769 /* return non-zero value as we are only doing a partial sync/unsync */
773 static int fm10k_mc_vlan_unsync(struct net_device
*netdev
,
774 const unsigned char *mc_addr
)
776 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
777 u16 glort
= interface
->glort
;
778 u16 vid
= interface
->vid
;
779 bool set
= !!(vid
/ VLAN_N_VID
);
782 /* drop any leading bits on the VLAN ID */
783 vid
&= VLAN_N_VID
- 1;
785 err
= fm10k_queue_mac_request(interface
, glort
, mc_addr
, vid
, set
);
789 /* return non-zero value as we are only doing a partial sync/unsync */
793 static int fm10k_update_vid(struct net_device
*netdev
, u16 vid
, bool set
)
795 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
796 struct fm10k_l2_accel
*l2_accel
= interface
->l2_accel
;
797 struct fm10k_hw
*hw
= &interface
->hw
;
802 /* updates do not apply to VLAN 0 */
806 if (vid
>= VLAN_N_VID
)
809 /* Verify that we have permission to add VLANs. If this is a request
810 * to remove a VLAN, we still want to allow the user to remove the
811 * VLAN device. In that case, we need to clear the bit in the
812 * active_vlans bitmask.
814 if (set
&& hw
->mac
.vlan_override
)
817 /* update active_vlans bitmask */
818 set_bit(vid
, interface
->active_vlans
);
820 clear_bit(vid
, interface
->active_vlans
);
822 /* disable the default VLAN ID on ring if we have an active VLAN */
823 for (i
= 0; i
< interface
->num_rx_queues
; i
++) {
824 struct fm10k_ring
*rx_ring
= interface
->rx_ring
[i
];
825 u16 rx_vid
= rx_ring
->vid
& (VLAN_N_VID
- 1);
827 if (test_bit(rx_vid
, interface
->active_vlans
))
828 rx_ring
->vid
|= FM10K_VLAN_CLEAR
;
830 rx_ring
->vid
&= ~FM10K_VLAN_CLEAR
;
833 /* If our VLAN has been overridden, there is no reason to send VLAN
834 * removal requests as they will be silently ignored.
836 if (hw
->mac
.vlan_override
)
839 /* Do not remove default VLAN ID related entries from VLAN and MAC
842 if (!set
&& vid
== hw
->mac
.default_vid
)
845 /* Do not throw an error if the interface is down. We will sync once
848 if (test_bit(__FM10K_DOWN
, interface
->state
))
851 fm10k_mbx_lock(interface
);
853 /* only need to update the VLAN if not in promiscuous mode */
854 if (!(netdev
->flags
& IFF_PROMISC
)) {
855 err
= fm10k_queue_vlan_request(interface
, vid
, 0, set
);
860 /* Update our base MAC address */
861 err
= fm10k_queue_mac_request(interface
, interface
->glort
,
862 hw
->mac
.addr
, vid
, set
);
866 /* Update L2 accelerated macvlan addresses */
868 for (i
= 0; i
< l2_accel
->size
; i
++) {
869 struct net_device
*sdev
= l2_accel
->macvlan
[i
];
874 glort
= l2_accel
->dglort
+ 1 + i
;
876 fm10k_queue_mac_request(interface
, glort
,
882 /* set VLAN ID prior to syncing/unsyncing the VLAN */
883 interface
->vid
= vid
+ (set
? VLAN_N_VID
: 0);
885 /* Update the unicast and multicast address list to add/drop VLAN */
886 __dev_uc_unsync(netdev
, fm10k_uc_vlan_unsync
);
887 __dev_mc_unsync(netdev
, fm10k_mc_vlan_unsync
);
890 fm10k_mbx_unlock(interface
);
895 static int fm10k_vlan_rx_add_vid(struct net_device
*netdev
,
896 __always_unused __be16 proto
, u16 vid
)
898 /* update VLAN and address table based on changes */
899 return fm10k_update_vid(netdev
, vid
, true);
902 static int fm10k_vlan_rx_kill_vid(struct net_device
*netdev
,
903 __always_unused __be16 proto
, u16 vid
)
905 /* update VLAN and address table based on changes */
906 return fm10k_update_vid(netdev
, vid
, false);
909 static u16
fm10k_find_next_vlan(struct fm10k_intfc
*interface
, u16 vid
)
911 struct fm10k_hw
*hw
= &interface
->hw
;
912 u16 default_vid
= hw
->mac
.default_vid
;
913 u16 vid_limit
= vid
< default_vid
? default_vid
: VLAN_N_VID
;
915 vid
= find_next_bit(interface
->active_vlans
, vid_limit
, ++vid
);
920 static void fm10k_clear_unused_vlans(struct fm10k_intfc
*interface
)
924 /* loop through and find any gaps in the table */
925 for (vid
= 0, prev_vid
= 0;
926 prev_vid
< VLAN_N_VID
;
927 prev_vid
= vid
+ 1, vid
= fm10k_find_next_vlan(interface
, vid
)) {
931 /* send request to clear multiple bits at a time */
932 prev_vid
+= (vid
- prev_vid
- 1) << FM10K_VLAN_LENGTH_SHIFT
;
933 fm10k_queue_vlan_request(interface
, prev_vid
, 0, false);
937 static int __fm10k_uc_sync(struct net_device
*dev
,
938 const unsigned char *addr
, bool sync
)
940 struct fm10k_intfc
*interface
= netdev_priv(dev
);
941 u16 vid
, glort
= interface
->glort
;
944 if (!is_valid_ether_addr(addr
))
945 return -EADDRNOTAVAIL
;
947 for (vid
= fm10k_find_next_vlan(interface
, 0);
949 vid
= fm10k_find_next_vlan(interface
, vid
)) {
950 err
= fm10k_queue_mac_request(interface
, glort
,
959 static int fm10k_uc_sync(struct net_device
*dev
,
960 const unsigned char *addr
)
962 return __fm10k_uc_sync(dev
, addr
, true);
965 static int fm10k_uc_unsync(struct net_device
*dev
,
966 const unsigned char *addr
)
968 return __fm10k_uc_sync(dev
, addr
, false);
971 static int fm10k_set_mac(struct net_device
*dev
, void *p
)
973 struct fm10k_intfc
*interface
= netdev_priv(dev
);
974 struct fm10k_hw
*hw
= &interface
->hw
;
975 struct sockaddr
*addr
= p
;
978 if (!is_valid_ether_addr(addr
->sa_data
))
979 return -EADDRNOTAVAIL
;
981 if (dev
->flags
& IFF_UP
) {
982 /* setting MAC address requires mailbox */
983 fm10k_mbx_lock(interface
);
985 err
= fm10k_uc_sync(dev
, addr
->sa_data
);
987 fm10k_uc_unsync(dev
, hw
->mac
.addr
);
989 fm10k_mbx_unlock(interface
);
993 eth_hw_addr_set(dev
, addr
->sa_data
);
994 ether_addr_copy(hw
->mac
.addr
, addr
->sa_data
);
995 dev
->addr_assign_type
&= ~NET_ADDR_RANDOM
;
998 /* if we had a mailbox error suggest trying again */
999 return err
? -EAGAIN
: 0;
1002 static int __fm10k_mc_sync(struct net_device
*dev
,
1003 const unsigned char *addr
, bool sync
)
1005 struct fm10k_intfc
*interface
= netdev_priv(dev
);
1006 u16 vid
, glort
= interface
->glort
;
1009 if (!is_multicast_ether_addr(addr
))
1010 return -EADDRNOTAVAIL
;
1012 for (vid
= fm10k_find_next_vlan(interface
, 0);
1014 vid
= fm10k_find_next_vlan(interface
, vid
)) {
1015 err
= fm10k_queue_mac_request(interface
, glort
,
1024 static int fm10k_mc_sync(struct net_device
*dev
,
1025 const unsigned char *addr
)
1027 return __fm10k_mc_sync(dev
, addr
, true);
1030 static int fm10k_mc_unsync(struct net_device
*dev
,
1031 const unsigned char *addr
)
1033 return __fm10k_mc_sync(dev
, addr
, false);
1036 static void fm10k_set_rx_mode(struct net_device
*dev
)
1038 struct fm10k_intfc
*interface
= netdev_priv(dev
);
1039 struct fm10k_hw
*hw
= &interface
->hw
;
1042 /* no need to update the harwdare if we are not running */
1043 if (!(dev
->flags
& IFF_UP
))
1046 /* determine new mode based on flags */
1047 xcast_mode
= (dev
->flags
& IFF_PROMISC
) ? FM10K_XCAST_MODE_PROMISC
:
1048 (dev
->flags
& IFF_ALLMULTI
) ? FM10K_XCAST_MODE_ALLMULTI
:
1049 (dev
->flags
& (IFF_BROADCAST
| IFF_MULTICAST
)) ?
1050 FM10K_XCAST_MODE_MULTI
: FM10K_XCAST_MODE_NONE
;
1052 fm10k_mbx_lock(interface
);
1054 /* update xcast mode first, but only if it changed */
1055 if (interface
->xcast_mode
!= xcast_mode
) {
1056 /* update VLAN table when entering promiscuous mode */
1057 if (xcast_mode
== FM10K_XCAST_MODE_PROMISC
)
1058 fm10k_queue_vlan_request(interface
, FM10K_VLAN_ALL
,
1061 /* clear VLAN table when exiting promiscuous mode */
1062 if (interface
->xcast_mode
== FM10K_XCAST_MODE_PROMISC
)
1063 fm10k_clear_unused_vlans(interface
);
1065 /* update xcast mode if host's mailbox is ready */
1066 if (fm10k_host_mbx_ready(interface
))
1067 hw
->mac
.ops
.update_xcast_mode(hw
, interface
->glort
,
1070 /* record updated xcast mode state */
1071 interface
->xcast_mode
= xcast_mode
;
1074 /* synchronize all of the addresses */
1075 __dev_uc_sync(dev
, fm10k_uc_sync
, fm10k_uc_unsync
);
1076 __dev_mc_sync(dev
, fm10k_mc_sync
, fm10k_mc_unsync
);
1078 fm10k_mbx_unlock(interface
);
1081 void fm10k_restore_rx_state(struct fm10k_intfc
*interface
)
1083 struct fm10k_l2_accel
*l2_accel
= interface
->l2_accel
;
1084 struct net_device
*netdev
= interface
->netdev
;
1085 struct fm10k_hw
*hw
= &interface
->hw
;
1089 /* record glort for this interface */
1090 glort
= interface
->glort
;
1092 /* convert interface flags to xcast mode */
1093 if (netdev
->flags
& IFF_PROMISC
)
1094 xcast_mode
= FM10K_XCAST_MODE_PROMISC
;
1095 else if (netdev
->flags
& IFF_ALLMULTI
)
1096 xcast_mode
= FM10K_XCAST_MODE_ALLMULTI
;
1097 else if (netdev
->flags
& (IFF_BROADCAST
| IFF_MULTICAST
))
1098 xcast_mode
= FM10K_XCAST_MODE_MULTI
;
1100 xcast_mode
= FM10K_XCAST_MODE_NONE
;
1102 fm10k_mbx_lock(interface
);
1104 /* Enable logical port if host's mailbox is ready */
1105 if (fm10k_host_mbx_ready(interface
))
1106 hw
->mac
.ops
.update_lport_state(hw
, glort
,
1107 interface
->glort_count
, true);
1109 /* update VLAN table */
1110 fm10k_queue_vlan_request(interface
, FM10K_VLAN_ALL
, 0,
1111 xcast_mode
== FM10K_XCAST_MODE_PROMISC
);
1113 /* update table with current entries */
1114 for (vid
= fm10k_find_next_vlan(interface
, 0);
1116 vid
= fm10k_find_next_vlan(interface
, vid
)) {
1117 fm10k_queue_vlan_request(interface
, vid
, 0, true);
1119 fm10k_queue_mac_request(interface
, glort
,
1120 hw
->mac
.addr
, vid
, true);
1122 /* synchronize macvlan addresses */
1124 for (i
= 0; i
< l2_accel
->size
; i
++) {
1125 struct net_device
*sdev
= l2_accel
->macvlan
[i
];
1130 glort
= l2_accel
->dglort
+ 1 + i
;
1132 fm10k_queue_mac_request(interface
, glort
,
1139 /* update xcast mode before synchronizing addresses if host's mailbox
1142 if (fm10k_host_mbx_ready(interface
))
1143 hw
->mac
.ops
.update_xcast_mode(hw
, glort
, xcast_mode
);
1145 /* synchronize all of the addresses */
1146 __dev_uc_sync(netdev
, fm10k_uc_sync
, fm10k_uc_unsync
);
1147 __dev_mc_sync(netdev
, fm10k_mc_sync
, fm10k_mc_unsync
);
1149 /* synchronize macvlan addresses */
1151 for (i
= 0; i
< l2_accel
->size
; i
++) {
1152 struct net_device
*sdev
= l2_accel
->macvlan
[i
];
1157 glort
= l2_accel
->dglort
+ 1 + i
;
1159 hw
->mac
.ops
.update_xcast_mode(hw
, glort
,
1160 FM10K_XCAST_MODE_NONE
);
1161 fm10k_queue_mac_request(interface
, glort
,
1163 hw
->mac
.default_vid
, true);
1167 fm10k_mbx_unlock(interface
);
1169 /* record updated xcast mode state */
1170 interface
->xcast_mode
= xcast_mode
;
1172 /* Restore tunnel configuration */
1173 fm10k_restore_udp_port_info(interface
);
1176 void fm10k_reset_rx_state(struct fm10k_intfc
*interface
)
1178 struct net_device
*netdev
= interface
->netdev
;
1179 struct fm10k_hw
*hw
= &interface
->hw
;
1181 /* Wait for MAC/VLAN work to finish */
1182 while (test_bit(__FM10K_MACVLAN_SCHED
, interface
->state
))
1183 usleep_range(1000, 2000);
1185 /* Cancel pending MAC/VLAN requests */
1186 fm10k_clear_macvlan_queue(interface
, interface
->glort
, true);
1188 fm10k_mbx_lock(interface
);
1190 /* clear the logical port state on lower device if host's mailbox is
1193 if (fm10k_host_mbx_ready(interface
))
1194 hw
->mac
.ops
.update_lport_state(hw
, interface
->glort
,
1195 interface
->glort_count
, false);
1197 fm10k_mbx_unlock(interface
);
1199 /* reset flags to default state */
1200 interface
->xcast_mode
= FM10K_XCAST_MODE_NONE
;
1202 /* clear the sync flag since the lport has been dropped */
1203 __dev_uc_unsync(netdev
, NULL
);
1204 __dev_mc_unsync(netdev
, NULL
);
1208 * fm10k_get_stats64 - Get System Network Statistics
1209 * @netdev: network interface device structure
1210 * @stats: storage space for 64bit statistics
1212 * Obtain 64bit statistics in a way that is safe for both 32bit and 64bit
1215 static void fm10k_get_stats64(struct net_device
*netdev
,
1216 struct rtnl_link_stats64
*stats
)
1218 struct fm10k_intfc
*interface
= netdev_priv(netdev
);
1219 struct fm10k_ring
*ring
;
1220 unsigned int start
, i
;
1225 for (i
= 0; i
< interface
->num_rx_queues
; i
++) {
1226 ring
= READ_ONCE(interface
->rx_ring
[i
]);
1232 start
= u64_stats_fetch_begin(&ring
->syncp
);
1233 packets
= ring
->stats
.packets
;
1234 bytes
= ring
->stats
.bytes
;
1235 } while (u64_stats_fetch_retry(&ring
->syncp
, start
));
1237 stats
->rx_packets
+= packets
;
1238 stats
->rx_bytes
+= bytes
;
1241 for (i
= 0; i
< interface
->num_tx_queues
; i
++) {
1242 ring
= READ_ONCE(interface
->tx_ring
[i
]);
1248 start
= u64_stats_fetch_begin(&ring
->syncp
);
1249 packets
= ring
->stats
.packets
;
1250 bytes
= ring
->stats
.bytes
;
1251 } while (u64_stats_fetch_retry(&ring
->syncp
, start
));
1253 stats
->tx_packets
+= packets
;
1254 stats
->tx_bytes
+= bytes
;
1259 /* following stats updated by fm10k_service_task() */
1260 stats
->rx_missed_errors
= netdev
->stats
.rx_missed_errors
;
1263 int fm10k_setup_tc(struct net_device
*dev
, u8 tc
)
1265 struct fm10k_intfc
*interface
= netdev_priv(dev
);
1268 /* Currently only the PF supports priority classes */
1269 if (tc
&& (interface
->hw
.mac
.type
!= fm10k_mac_pf
))
1272 /* Hardware supports up to 8 traffic classes */
1276 /* Hardware has to reinitialize queues to match packet
1277 * buffer alignment. Unfortunately, the hardware is not
1278 * flexible enough to do this dynamically.
1280 if (netif_running(dev
))
1283 fm10k_mbx_free_irq(interface
);
1285 fm10k_clear_queueing_scheme(interface
);
1287 /* we expect the prio_tc map to be repopulated later */
1288 netdev_reset_tc(dev
);
1289 netdev_set_num_tc(dev
, tc
);
1291 err
= fm10k_init_queueing_scheme(interface
);
1293 goto err_queueing_scheme
;
1295 err
= fm10k_mbx_request_irq(interface
);
1299 err
= netif_running(dev
) ? fm10k_open(dev
) : 0;
1303 /* flag to indicate SWPRI has yet to be updated */
1304 set_bit(FM10K_FLAG_SWPRI_CONFIG
, interface
->flags
);
1308 fm10k_mbx_free_irq(interface
);
1310 fm10k_clear_queueing_scheme(interface
);
1311 err_queueing_scheme
:
1312 netif_device_detach(dev
);
1317 static int __fm10k_setup_tc(struct net_device
*dev
, enum tc_setup_type type
,
1320 struct tc_mqprio_qopt
*mqprio
= type_data
;
1322 if (type
!= TC_SETUP_QDISC_MQPRIO
)
1325 mqprio
->hw
= TC_MQPRIO_HW_OFFLOAD_TCS
;
1327 return fm10k_setup_tc(dev
, mqprio
->num_tc
);
1330 static void fm10k_assign_l2_accel(struct fm10k_intfc
*interface
,
1331 struct fm10k_l2_accel
*l2_accel
)
1335 for (i
= 0; i
< interface
->num_rx_queues
; i
++) {
1336 struct fm10k_ring
*ring
= interface
->rx_ring
[i
];
1338 rcu_assign_pointer(ring
->l2_accel
, l2_accel
);
1341 interface
->l2_accel
= l2_accel
;
1344 static void *fm10k_dfwd_add_station(struct net_device
*dev
,
1345 struct net_device
*sdev
)
1347 struct fm10k_intfc
*interface
= netdev_priv(dev
);
1348 struct fm10k_l2_accel
*l2_accel
= interface
->l2_accel
;
1349 struct fm10k_l2_accel
*old_l2_accel
= NULL
;
1350 struct fm10k_dglort_cfg dglort
= { 0 };
1351 struct fm10k_hw
*hw
= &interface
->hw
;
1355 /* The hardware supported by fm10k only filters on the destination MAC
1356 * address. In order to avoid issues we only support offloading modes
1357 * where the hardware can actually provide the functionality.
1359 if (!macvlan_supports_dest_filter(sdev
))
1360 return ERR_PTR(-EMEDIUMTYPE
);
1362 /* allocate l2 accel structure if it is not available */
1364 /* verify there is enough free GLORTs to support l2_accel */
1365 if (interface
->glort_count
< 7)
1366 return ERR_PTR(-EBUSY
);
1368 size
= offsetof(struct fm10k_l2_accel
, macvlan
[7]);
1369 l2_accel
= kzalloc(size
, GFP_KERNEL
);
1371 return ERR_PTR(-ENOMEM
);
1374 l2_accel
->dglort
= interface
->glort
;
1376 /* update pointers */
1377 fm10k_assign_l2_accel(interface
, l2_accel
);
1378 /* do not expand if we are at our limit */
1379 } else if ((l2_accel
->count
== FM10K_MAX_STATIONS
) ||
1380 (l2_accel
->count
== (interface
->glort_count
- 1))) {
1381 return ERR_PTR(-EBUSY
);
1382 /* expand if we have hit the size limit */
1383 } else if (l2_accel
->count
== l2_accel
->size
) {
1384 old_l2_accel
= l2_accel
;
1385 size
= offsetof(struct fm10k_l2_accel
,
1386 macvlan
[(l2_accel
->size
* 2) + 1]);
1387 l2_accel
= kzalloc(size
, GFP_KERNEL
);
1389 return ERR_PTR(-ENOMEM
);
1391 memcpy(l2_accel
, old_l2_accel
,
1392 offsetof(struct fm10k_l2_accel
,
1393 macvlan
[old_l2_accel
->size
]));
1395 l2_accel
->size
= (old_l2_accel
->size
* 2) + 1;
1397 /* update pointers */
1398 fm10k_assign_l2_accel(interface
, l2_accel
);
1399 kfree_rcu(old_l2_accel
, rcu
);
1402 /* add macvlan to accel table, and record GLORT for position */
1403 for (i
= 0; i
< l2_accel
->size
; i
++) {
1404 if (!l2_accel
->macvlan
[i
])
1408 /* record station */
1409 l2_accel
->macvlan
[i
] = sdev
;
1412 /* configure default DGLORT mapping for RSS/DCB */
1413 dglort
.idx
= fm10k_dglort_pf_rss
;
1414 dglort
.inner_rss
= 1;
1415 dglort
.rss_l
= fls(interface
->ring_feature
[RING_F_RSS
].mask
);
1416 dglort
.pc_l
= fls(interface
->ring_feature
[RING_F_QOS
].mask
);
1417 dglort
.glort
= interface
->glort
;
1418 dglort
.shared_l
= fls(l2_accel
->size
);
1419 hw
->mac
.ops
.configure_dglort_map(hw
, &dglort
);
1421 /* Add rules for this specific dglort to the switch */
1422 fm10k_mbx_lock(interface
);
1424 glort
= l2_accel
->dglort
+ 1 + i
;
1426 if (fm10k_host_mbx_ready(interface
))
1427 hw
->mac
.ops
.update_xcast_mode(hw
, glort
,
1428 FM10K_XCAST_MODE_NONE
);
1430 fm10k_queue_mac_request(interface
, glort
, sdev
->dev_addr
,
1431 hw
->mac
.default_vid
, true);
1433 for (vid
= fm10k_find_next_vlan(interface
, 0);
1435 vid
= fm10k_find_next_vlan(interface
, vid
))
1436 fm10k_queue_mac_request(interface
, glort
, sdev
->dev_addr
,
1439 fm10k_mbx_unlock(interface
);
1444 static void fm10k_dfwd_del_station(struct net_device
*dev
, void *priv
)
1446 struct fm10k_intfc
*interface
= netdev_priv(dev
);
1447 struct fm10k_l2_accel
*l2_accel
= READ_ONCE(interface
->l2_accel
);
1448 struct fm10k_dglort_cfg dglort
= { 0 };
1449 struct fm10k_hw
*hw
= &interface
->hw
;
1450 struct net_device
*sdev
= priv
;
1457 /* search table for matching interface */
1458 for (i
= 0; i
< l2_accel
->size
; i
++) {
1459 if (l2_accel
->macvlan
[i
] == sdev
)
1463 /* exit if macvlan not found */
1464 if (i
== l2_accel
->size
)
1467 /* Remove any rules specific to this dglort */
1468 fm10k_mbx_lock(interface
);
1470 glort
= l2_accel
->dglort
+ 1 + i
;
1472 if (fm10k_host_mbx_ready(interface
))
1473 hw
->mac
.ops
.update_xcast_mode(hw
, glort
,
1474 FM10K_XCAST_MODE_NONE
);
1476 fm10k_queue_mac_request(interface
, glort
, sdev
->dev_addr
,
1477 hw
->mac
.default_vid
, false);
1479 for (vid
= fm10k_find_next_vlan(interface
, 0);
1481 vid
= fm10k_find_next_vlan(interface
, vid
))
1482 fm10k_queue_mac_request(interface
, glort
, sdev
->dev_addr
,
1485 fm10k_mbx_unlock(interface
);
1487 /* record removal */
1488 l2_accel
->macvlan
[i
] = NULL
;
1491 /* configure default DGLORT mapping for RSS/DCB */
1492 dglort
.idx
= fm10k_dglort_pf_rss
;
1493 dglort
.inner_rss
= 1;
1494 dglort
.rss_l
= fls(interface
->ring_feature
[RING_F_RSS
].mask
);
1495 dglort
.pc_l
= fls(interface
->ring_feature
[RING_F_QOS
].mask
);
1496 dglort
.glort
= interface
->glort
;
1497 dglort
.shared_l
= fls(l2_accel
->size
);
1498 hw
->mac
.ops
.configure_dglort_map(hw
, &dglort
);
1500 /* If table is empty remove it */
1501 if (l2_accel
->count
== 0) {
1502 fm10k_assign_l2_accel(interface
, NULL
);
1503 kfree_rcu(l2_accel
, rcu
);
1507 static netdev_features_t
fm10k_features_check(struct sk_buff
*skb
,
1508 struct net_device
*dev
,
1509 netdev_features_t features
)
1511 if (!skb
->encapsulation
|| fm10k_tx_encap_offload(skb
))
1514 return features
& ~(NETIF_F_CSUM_MASK
| NETIF_F_GSO_MASK
);
1517 static const struct net_device_ops fm10k_netdev_ops
= {
1518 .ndo_open
= fm10k_open
,
1519 .ndo_stop
= fm10k_close
,
1520 .ndo_validate_addr
= eth_validate_addr
,
1521 .ndo_start_xmit
= fm10k_xmit_frame
,
1522 .ndo_set_mac_address
= fm10k_set_mac
,
1523 .ndo_tx_timeout
= fm10k_tx_timeout
,
1524 .ndo_vlan_rx_add_vid
= fm10k_vlan_rx_add_vid
,
1525 .ndo_vlan_rx_kill_vid
= fm10k_vlan_rx_kill_vid
,
1526 .ndo_set_rx_mode
= fm10k_set_rx_mode
,
1527 .ndo_get_stats64
= fm10k_get_stats64
,
1528 .ndo_setup_tc
= __fm10k_setup_tc
,
1529 .ndo_set_vf_mac
= fm10k_ndo_set_vf_mac
,
1530 .ndo_set_vf_vlan
= fm10k_ndo_set_vf_vlan
,
1531 .ndo_set_vf_rate
= fm10k_ndo_set_vf_bw
,
1532 .ndo_get_vf_config
= fm10k_ndo_get_vf_config
,
1533 .ndo_get_vf_stats
= fm10k_ndo_get_vf_stats
,
1534 .ndo_dfwd_add_station
= fm10k_dfwd_add_station
,
1535 .ndo_dfwd_del_station
= fm10k_dfwd_del_station
,
1536 .ndo_features_check
= fm10k_features_check
,
1539 #define DEFAULT_DEBUG_LEVEL_SHIFT 3
1541 struct net_device
*fm10k_alloc_netdev(const struct fm10k_info
*info
)
1543 netdev_features_t hw_features
;
1544 struct fm10k_intfc
*interface
;
1545 struct net_device
*dev
;
1547 dev
= alloc_etherdev_mq(sizeof(struct fm10k_intfc
), MAX_QUEUES
);
1551 /* set net device and ethtool ops */
1552 dev
->netdev_ops
= &fm10k_netdev_ops
;
1553 fm10k_set_ethtool_ops(dev
);
1555 /* configure default debug level */
1556 interface
= netdev_priv(dev
);
1557 interface
->msg_enable
= BIT(DEFAULT_DEBUG_LEVEL_SHIFT
) - 1;
1559 /* configure default features */
1560 dev
->features
|= NETIF_F_IP_CSUM
|
1569 /* Only the PF can support VXLAN and NVGRE tunnel offloads */
1570 if (info
->mac
== fm10k_mac_pf
) {
1571 dev
->hw_enc_features
= NETIF_F_IP_CSUM
|
1575 NETIF_F_GSO_UDP_TUNNEL
|
1579 dev
->features
|= NETIF_F_GSO_UDP_TUNNEL
;
1581 dev
->udp_tunnel_nic_info
= &fm10k_udp_tunnels
;
1584 /* all features defined to this point should be changeable */
1585 hw_features
= dev
->features
;
1587 /* allow user to enable L2 forwarding acceleration */
1588 hw_features
|= NETIF_F_HW_L2FW_DOFFLOAD
;
1590 /* configure VLAN features */
1591 dev
->vlan_features
|= dev
->features
;
1593 /* we want to leave these both on as we cannot disable VLAN tag
1594 * insertion or stripping on the hardware since it is contained
1595 * in the FTAG and not in the frame itself.
1597 dev
->features
|= NETIF_F_HW_VLAN_CTAG_TX
|
1598 NETIF_F_HW_VLAN_CTAG_RX
|
1599 NETIF_F_HW_VLAN_CTAG_FILTER
;
1601 dev
->priv_flags
|= IFF_UNICAST_FLT
;
1603 dev
->hw_features
|= hw_features
;
1605 /* MTU range: 68 - 15342 */
1606 dev
->min_mtu
= ETH_MIN_MTU
;
1607 dev
->max_mtu
= FM10K_MAX_JUMBO_FRAME_SIZE
;