1 /* Intel Ethernet Switch Host Interface Driver
2 * Copyright(c) 2013 - 2014 Intel Corporation.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
16 * Contact Information:
17 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
18 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
22 #include <linux/vmalloc.h>
25 * fm10k_setup_tx_resources - allocate Tx resources (Descriptors)
26 * @tx_ring: tx descriptor ring (for a specific queue) to setup
28 * Return 0 on success, negative on failure
30 int fm10k_setup_tx_resources(struct fm10k_ring *tx_ring)
32 struct device *dev = tx_ring->dev;
35 size = sizeof(struct fm10k_tx_buffer) * tx_ring->count;
37 tx_ring->tx_buffer = vzalloc(size);
38 if (!tx_ring->tx_buffer)
41 u64_stats_init(&tx_ring->syncp);
43 /* round up to nearest 4K */
44 tx_ring->size = tx_ring->count * sizeof(struct fm10k_tx_desc);
45 tx_ring->size = ALIGN(tx_ring->size, 4096);
47 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
48 &tx_ring->dma, GFP_KERNEL);
55 vfree(tx_ring->tx_buffer);
56 tx_ring->tx_buffer = NULL;
61 * fm10k_setup_all_tx_resources - allocate all queues Tx resources
62 * @interface: board private structure
64 * If this function returns with an error, then it's possible one or
65 * more of the rings is populated (while the rest are not). It is the
66 * callers duty to clean those orphaned rings.
68 * Return 0 on success, negative on failure
70 static int fm10k_setup_all_tx_resources(struct fm10k_intfc *interface)
74 for (i = 0; i < interface->num_tx_queues; i++) {
75 err = fm10k_setup_tx_resources(interface->tx_ring[i]);
79 netif_err(interface, probe, interface->netdev,
80 "Allocation for Tx Queue %u failed\n", i);
86 /* rewind the index freeing the rings as we go */
88 fm10k_free_tx_resources(interface->tx_ring[i]);
93 * fm10k_setup_rx_resources - allocate Rx resources (Descriptors)
94 * @rx_ring: rx descriptor ring (for a specific queue) to setup
96 * Returns 0 on success, negative on failure
98 int fm10k_setup_rx_resources(struct fm10k_ring *rx_ring)
100 struct device *dev = rx_ring->dev;
103 size = sizeof(struct fm10k_rx_buffer) * rx_ring->count;
105 rx_ring->rx_buffer = vzalloc(size);
106 if (!rx_ring->rx_buffer)
109 u64_stats_init(&rx_ring->syncp);
111 /* Round up to nearest 4K */
112 rx_ring->size = rx_ring->count * sizeof(union fm10k_rx_desc);
113 rx_ring->size = ALIGN(rx_ring->size, 4096);
115 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
116 &rx_ring->dma, GFP_KERNEL);
122 vfree(rx_ring->rx_buffer);
123 rx_ring->rx_buffer = NULL;
128 * fm10k_setup_all_rx_resources - allocate all queues Rx resources
129 * @interface: board private structure
131 * If this function returns with an error, then it's possible one or
132 * more of the rings is populated (while the rest are not). It is the
133 * callers duty to clean those orphaned rings.
135 * Return 0 on success, negative on failure
137 static int fm10k_setup_all_rx_resources(struct fm10k_intfc *interface)
141 for (i = 0; i < interface->num_rx_queues; i++) {
142 err = fm10k_setup_rx_resources(interface->rx_ring[i]);
146 netif_err(interface, probe, interface->netdev,
147 "Allocation for Rx Queue %u failed\n", i);
153 /* rewind the index freeing the rings as we go */
155 fm10k_free_rx_resources(interface->rx_ring[i]);
159 void fm10k_unmap_and_free_tx_resource(struct fm10k_ring *ring,
160 struct fm10k_tx_buffer *tx_buffer)
162 if (tx_buffer->skb) {
163 dev_kfree_skb_any(tx_buffer->skb);
164 if (dma_unmap_len(tx_buffer, len))
165 dma_unmap_single(ring->dev,
166 dma_unmap_addr(tx_buffer, dma),
167 dma_unmap_len(tx_buffer, len),
169 } else if (dma_unmap_len(tx_buffer, len)) {
170 dma_unmap_page(ring->dev,
171 dma_unmap_addr(tx_buffer, dma),
172 dma_unmap_len(tx_buffer, len),
175 tx_buffer->next_to_watch = NULL;
176 tx_buffer->skb = NULL;
177 dma_unmap_len_set(tx_buffer, len, 0);
178 /* tx_buffer must be completely set up in the transmit path */
182 * fm10k_clean_tx_ring - Free Tx Buffers
183 * @tx_ring: ring to be cleaned
185 static void fm10k_clean_tx_ring(struct fm10k_ring *tx_ring)
187 struct fm10k_tx_buffer *tx_buffer;
191 /* ring already cleared, nothing to do */
192 if (!tx_ring->tx_buffer)
195 /* Free all the Tx ring sk_buffs */
196 for (i = 0; i < tx_ring->count; i++) {
197 tx_buffer = &tx_ring->tx_buffer[i];
198 fm10k_unmap_and_free_tx_resource(tx_ring, tx_buffer);
201 /* reset BQL values */
202 netdev_tx_reset_queue(txring_txq(tx_ring));
204 size = sizeof(struct fm10k_tx_buffer) * tx_ring->count;
205 memset(tx_ring->tx_buffer, 0, size);
207 /* Zero out the descriptor ring */
208 memset(tx_ring->desc, 0, tx_ring->size);
212 * fm10k_free_tx_resources - Free Tx Resources per Queue
213 * @tx_ring: Tx descriptor ring for a specific queue
215 * Free all transmit software resources
217 void fm10k_free_tx_resources(struct fm10k_ring *tx_ring)
219 fm10k_clean_tx_ring(tx_ring);
221 vfree(tx_ring->tx_buffer);
222 tx_ring->tx_buffer = NULL;
224 /* if not set, then don't free */
228 dma_free_coherent(tx_ring->dev, tx_ring->size,
229 tx_ring->desc, tx_ring->dma);
230 tx_ring->desc = NULL;
234 * fm10k_clean_all_tx_rings - Free Tx Buffers for all queues
235 * @interface: board private structure
237 void fm10k_clean_all_tx_rings(struct fm10k_intfc *interface)
241 for (i = 0; i < interface->num_tx_queues; i++)
242 fm10k_clean_tx_ring(interface->tx_ring[i]);
246 * fm10k_free_all_tx_resources - Free Tx Resources for All Queues
247 * @interface: board private structure
249 * Free all transmit software resources
251 static void fm10k_free_all_tx_resources(struct fm10k_intfc *interface)
253 int i = interface->num_tx_queues;
256 fm10k_free_tx_resources(interface->tx_ring[i]);
260 * fm10k_clean_rx_ring - Free Rx Buffers per Queue
261 * @rx_ring: ring to free buffers from
263 static void fm10k_clean_rx_ring(struct fm10k_ring *rx_ring)
268 if (!rx_ring->rx_buffer)
272 dev_kfree_skb(rx_ring->skb);
275 /* Free all the Rx ring sk_buffs */
276 for (i = 0; i < rx_ring->count; i++) {
277 struct fm10k_rx_buffer *buffer = &rx_ring->rx_buffer[i];
278 /* clean-up will only set page pointer to NULL */
282 dma_unmap_page(rx_ring->dev, buffer->dma,
283 PAGE_SIZE, DMA_FROM_DEVICE);
284 __free_page(buffer->page);
289 size = sizeof(struct fm10k_rx_buffer) * rx_ring->count;
290 memset(rx_ring->rx_buffer, 0, size);
292 /* Zero out the descriptor ring */
293 memset(rx_ring->desc, 0, rx_ring->size);
295 rx_ring->next_to_alloc = 0;
296 rx_ring->next_to_clean = 0;
297 rx_ring->next_to_use = 0;
301 * fm10k_free_rx_resources - Free Rx Resources
302 * @rx_ring: ring to clean the resources from
304 * Free all receive software resources
306 void fm10k_free_rx_resources(struct fm10k_ring *rx_ring)
308 fm10k_clean_rx_ring(rx_ring);
310 vfree(rx_ring->rx_buffer);
311 rx_ring->rx_buffer = NULL;
313 /* if not set, then don't free */
317 dma_free_coherent(rx_ring->dev, rx_ring->size,
318 rx_ring->desc, rx_ring->dma);
320 rx_ring->desc = NULL;
324 * fm10k_clean_all_rx_rings - Free Rx Buffers for all queues
325 * @interface: board private structure
327 void fm10k_clean_all_rx_rings(struct fm10k_intfc *interface)
331 for (i = 0; i < interface->num_rx_queues; i++)
332 fm10k_clean_rx_ring(interface->rx_ring[i]);
336 * fm10k_free_all_rx_resources - Free Rx Resources for All Queues
337 * @interface: board private structure
339 * Free all receive software resources
341 static void fm10k_free_all_rx_resources(struct fm10k_intfc *interface)
343 int i = interface->num_rx_queues;
346 fm10k_free_rx_resources(interface->rx_ring[i]);
350 * fm10k_request_glort_range - Request GLORTs for use in configuring rules
351 * @interface: board private structure
353 * This function allocates a range of glorts for this inteface to use.
355 static void fm10k_request_glort_range(struct fm10k_intfc *interface)
357 struct fm10k_hw *hw = &interface->hw;
358 u16 mask = (~hw->mac.dglort_map) >> FM10K_DGLORTMAP_MASK_SHIFT;
360 /* establish GLORT base */
361 interface->glort = hw->mac.dglort_map & FM10K_DGLORTMAP_NONE;
362 interface->glort_count = 0;
364 /* nothing we can do until mask is allocated */
365 if (hw->mac.dglort_map == FM10K_DGLORTMAP_NONE)
368 interface->glort_count = mask + 1;
372 * fm10k_open - Called when a network interface is made active
373 * @netdev: network interface device structure
375 * Returns 0 on success, negative value on failure
377 * The open entry point is called when a network interface is made
378 * active by the system (IFF_UP). At this point all resources needed
379 * for transmit and receive operations are allocated, the interrupt
380 * handler is registered with the OS, the watchdog timer is started,
381 * and the stack is notified that the interface is ready.
383 int fm10k_open(struct net_device *netdev)
385 struct fm10k_intfc *interface = netdev_priv(netdev);
388 /* allocate transmit descriptors */
389 err = fm10k_setup_all_tx_resources(interface);
393 /* allocate receive descriptors */
394 err = fm10k_setup_all_rx_resources(interface);
398 /* allocate interrupt resources */
399 err = fm10k_qv_request_irq(interface);
403 /* setup GLORT assignment for this port */
404 fm10k_request_glort_range(interface);
406 /* Notify the stack of the actual queue counts */
408 err = netif_set_real_num_rx_queues(netdev,
409 interface->num_rx_queues);
418 fm10k_qv_free_irq(interface);
420 fm10k_free_all_rx_resources(interface);
422 fm10k_free_all_tx_resources(interface);
428 * fm10k_close - Disables a network interface
429 * @netdev: network interface device structure
431 * Returns 0, this is not allowed to fail
433 * The close entry point is called when an interface is de-activated
434 * by the OS. The hardware is still under the drivers control, but
435 * needs to be disabled. A global MAC reset is issued to stop the
436 * hardware, and all transmit and receive resources are freed.
438 int fm10k_close(struct net_device *netdev)
440 struct fm10k_intfc *interface = netdev_priv(netdev);
442 fm10k_down(interface);
444 fm10k_qv_free_irq(interface);
446 fm10k_free_all_tx_resources(interface);
447 fm10k_free_all_rx_resources(interface);
452 static netdev_tx_t fm10k_xmit_frame(struct sk_buff *skb, struct net_device *dev)
454 dev_kfree_skb_any(skb);
458 static int fm10k_change_mtu(struct net_device *dev, int new_mtu)
460 if (new_mtu < 68 || new_mtu > FM10K_MAX_JUMBO_FRAME_SIZE)
468 static int fm10k_uc_vlan_unsync(struct net_device *netdev,
469 const unsigned char *uc_addr)
471 struct fm10k_intfc *interface = netdev_priv(netdev);
472 struct fm10k_hw *hw = &interface->hw;
473 u16 glort = interface->glort;
474 u16 vid = interface->vid;
475 bool set = !!(vid / VLAN_N_VID);
478 /* drop any leading bits on the VLAN ID */
479 vid &= VLAN_N_VID - 1;
481 err = hw->mac.ops.update_uc_addr(hw, glort, uc_addr, vid, set, 0);
485 /* return non-zero value as we are only doing a partial sync/unsync */
489 static int fm10k_mc_vlan_unsync(struct net_device *netdev,
490 const unsigned char *mc_addr)
492 struct fm10k_intfc *interface = netdev_priv(netdev);
493 struct fm10k_hw *hw = &interface->hw;
494 u16 glort = interface->glort;
495 u16 vid = interface->vid;
496 bool set = !!(vid / VLAN_N_VID);
499 /* drop any leading bits on the VLAN ID */
500 vid &= VLAN_N_VID - 1;
502 err = hw->mac.ops.update_mc_addr(hw, glort, mc_addr, vid, set);
506 /* return non-zero value as we are only doing a partial sync/unsync */
510 static int fm10k_update_vid(struct net_device *netdev, u16 vid, bool set)
512 struct fm10k_intfc *interface = netdev_priv(netdev);
513 struct fm10k_hw *hw = &interface->hw;
516 /* updates do not apply to VLAN 0 */
520 if (vid >= VLAN_N_VID)
523 /* Verify we have permission to add VLANs */
524 if (hw->mac.vlan_override)
527 /* if default VLAN is already present do nothing */
528 if (vid == hw->mac.default_vid)
531 /* update active_vlans bitmask */
532 set_bit(vid, interface->active_vlans);
534 clear_bit(vid, interface->active_vlans);
536 fm10k_mbx_lock(interface);
538 /* only need to update the VLAN if not in promiscous mode */
539 if (!(netdev->flags & IFF_PROMISC)) {
540 err = hw->mac.ops.update_vlan(hw, vid, 0, set);
545 /* update our base MAC address */
546 err = hw->mac.ops.update_uc_addr(hw, interface->glort, hw->mac.addr,
551 /* set vid prior to syncing/unsyncing the VLAN */
552 interface->vid = vid + (set ? VLAN_N_VID : 0);
554 /* Update the unicast and multicast address list to add/drop VLAN */
555 __dev_uc_unsync(netdev, fm10k_uc_vlan_unsync);
556 __dev_mc_unsync(netdev, fm10k_mc_vlan_unsync);
558 fm10k_mbx_unlock(interface);
563 static int fm10k_vlan_rx_add_vid(struct net_device *netdev,
564 __always_unused __be16 proto, u16 vid)
566 /* update VLAN and address table based on changes */
567 return fm10k_update_vid(netdev, vid, true);
570 static int fm10k_vlan_rx_kill_vid(struct net_device *netdev,
571 __always_unused __be16 proto, u16 vid)
573 /* update VLAN and address table based on changes */
574 return fm10k_update_vid(netdev, vid, false);
577 static u16 fm10k_find_next_vlan(struct fm10k_intfc *interface, u16 vid)
579 struct fm10k_hw *hw = &interface->hw;
580 u16 default_vid = hw->mac.default_vid;
581 u16 vid_limit = vid < default_vid ? default_vid : VLAN_N_VID;
583 vid = find_next_bit(interface->active_vlans, vid_limit, ++vid);
588 static void fm10k_clear_unused_vlans(struct fm10k_intfc *interface)
590 struct fm10k_hw *hw = &interface->hw;
593 /* loop through and find any gaps in the table */
594 for (vid = 0, prev_vid = 0;
595 prev_vid < VLAN_N_VID;
596 prev_vid = vid + 1, vid = fm10k_find_next_vlan(interface, vid)) {
600 /* send request to clear multiple bits at a time */
601 prev_vid += (vid - prev_vid - 1) << FM10K_VLAN_LENGTH_SHIFT;
602 hw->mac.ops.update_vlan(hw, prev_vid, 0, false);
606 static int __fm10k_uc_sync(struct net_device *dev,
607 const unsigned char *addr, bool sync)
609 struct fm10k_intfc *interface = netdev_priv(dev);
610 struct fm10k_hw *hw = &interface->hw;
611 u16 vid, glort = interface->glort;
614 if (!is_valid_ether_addr(addr))
615 return -EADDRNOTAVAIL;
617 /* update table with current entries */
618 for (vid = hw->mac.default_vid ? fm10k_find_next_vlan(interface, 0) : 0;
620 vid = fm10k_find_next_vlan(interface, vid)) {
621 err = hw->mac.ops.update_uc_addr(hw, glort, addr,
630 static int fm10k_uc_sync(struct net_device *dev,
631 const unsigned char *addr)
633 return __fm10k_uc_sync(dev, addr, true);
636 static int fm10k_uc_unsync(struct net_device *dev,
637 const unsigned char *addr)
639 return __fm10k_uc_sync(dev, addr, false);
642 static int fm10k_set_mac(struct net_device *dev, void *p)
644 struct fm10k_intfc *interface = netdev_priv(dev);
645 struct fm10k_hw *hw = &interface->hw;
646 struct sockaddr *addr = p;
649 if (!is_valid_ether_addr(addr->sa_data))
650 return -EADDRNOTAVAIL;
652 if (dev->flags & IFF_UP) {
653 /* setting MAC address requires mailbox */
654 fm10k_mbx_lock(interface);
656 err = fm10k_uc_sync(dev, addr->sa_data);
658 fm10k_uc_unsync(dev, hw->mac.addr);
660 fm10k_mbx_unlock(interface);
664 ether_addr_copy(dev->dev_addr, addr->sa_data);
665 ether_addr_copy(hw->mac.addr, addr->sa_data);
666 dev->addr_assign_type &= ~NET_ADDR_RANDOM;
669 /* if we had a mailbox error suggest trying again */
670 return err ? -EAGAIN : 0;
673 static int __fm10k_mc_sync(struct net_device *dev,
674 const unsigned char *addr, bool sync)
676 struct fm10k_intfc *interface = netdev_priv(dev);
677 struct fm10k_hw *hw = &interface->hw;
678 u16 vid, glort = interface->glort;
681 if (!is_multicast_ether_addr(addr))
682 return -EADDRNOTAVAIL;
684 /* update table with current entries */
685 for (vid = hw->mac.default_vid ? fm10k_find_next_vlan(interface, 0) : 0;
687 vid = fm10k_find_next_vlan(interface, vid)) {
688 err = hw->mac.ops.update_mc_addr(hw, glort, addr, vid, sync);
696 static int fm10k_mc_sync(struct net_device *dev,
697 const unsigned char *addr)
699 return __fm10k_mc_sync(dev, addr, true);
702 static int fm10k_mc_unsync(struct net_device *dev,
703 const unsigned char *addr)
705 return __fm10k_mc_sync(dev, addr, false);
708 static void fm10k_set_rx_mode(struct net_device *dev)
710 struct fm10k_intfc *interface = netdev_priv(dev);
711 struct fm10k_hw *hw = &interface->hw;
714 /* no need to update the harwdare if we are not running */
715 if (!(dev->flags & IFF_UP))
718 /* determine new mode based on flags */
719 xcast_mode = (dev->flags & IFF_PROMISC) ? FM10K_XCAST_MODE_PROMISC :
720 (dev->flags & IFF_ALLMULTI) ? FM10K_XCAST_MODE_ALLMULTI :
721 (dev->flags & (IFF_BROADCAST | IFF_MULTICAST)) ?
722 FM10K_XCAST_MODE_MULTI : FM10K_XCAST_MODE_NONE;
724 fm10k_mbx_lock(interface);
726 /* syncronize all of the addresses */
727 if (xcast_mode != FM10K_XCAST_MODE_PROMISC) {
728 __dev_uc_sync(dev, fm10k_uc_sync, fm10k_uc_unsync);
729 if (xcast_mode != FM10K_XCAST_MODE_ALLMULTI)
730 __dev_mc_sync(dev, fm10k_mc_sync, fm10k_mc_unsync);
733 /* if we aren't changing modes there is nothing to do */
734 if (interface->xcast_mode != xcast_mode) {
735 /* update VLAN table */
736 if (xcast_mode == FM10K_XCAST_MODE_PROMISC)
737 hw->mac.ops.update_vlan(hw, FM10K_VLAN_ALL, 0, true);
738 if (interface->xcast_mode == FM10K_XCAST_MODE_PROMISC)
739 fm10k_clear_unused_vlans(interface);
741 /* update xcast mode */
742 hw->mac.ops.update_xcast_mode(hw, interface->glort, xcast_mode);
744 /* record updated xcast mode state */
745 interface->xcast_mode = xcast_mode;
748 fm10k_mbx_unlock(interface);
751 void fm10k_restore_rx_state(struct fm10k_intfc *interface)
753 struct net_device *netdev = interface->netdev;
754 struct fm10k_hw *hw = &interface->hw;
758 /* record glort for this interface */
759 glort = interface->glort;
761 /* convert interface flags to xcast mode */
762 if (netdev->flags & IFF_PROMISC)
763 xcast_mode = FM10K_XCAST_MODE_PROMISC;
764 else if (netdev->flags & IFF_ALLMULTI)
765 xcast_mode = FM10K_XCAST_MODE_ALLMULTI;
766 else if (netdev->flags & (IFF_BROADCAST | IFF_MULTICAST))
767 xcast_mode = FM10K_XCAST_MODE_MULTI;
769 xcast_mode = FM10K_XCAST_MODE_NONE;
771 fm10k_mbx_lock(interface);
773 /* Enable logical port */
774 hw->mac.ops.update_lport_state(hw, glort, interface->glort_count, true);
776 /* update VLAN table */
777 hw->mac.ops.update_vlan(hw, FM10K_VLAN_ALL, 0,
778 xcast_mode == FM10K_XCAST_MODE_PROMISC);
780 /* Add filter for VLAN 0 */
781 hw->mac.ops.update_vlan(hw, 0, 0, true);
783 /* update table with current entries */
784 for (vid = hw->mac.default_vid ? fm10k_find_next_vlan(interface, 0) : 0;
786 vid = fm10k_find_next_vlan(interface, vid)) {
787 hw->mac.ops.update_vlan(hw, vid, 0, true);
788 hw->mac.ops.update_uc_addr(hw, glort, hw->mac.addr,
792 /* syncronize all of the addresses */
793 if (xcast_mode != FM10K_XCAST_MODE_PROMISC) {
794 __dev_uc_sync(netdev, fm10k_uc_sync, fm10k_uc_unsync);
795 if (xcast_mode != FM10K_XCAST_MODE_ALLMULTI)
796 __dev_mc_sync(netdev, fm10k_mc_sync, fm10k_mc_unsync);
799 /* update xcast mode */
800 hw->mac.ops.update_xcast_mode(hw, glort, xcast_mode);
802 fm10k_mbx_unlock(interface);
804 /* record updated xcast mode state */
805 interface->xcast_mode = xcast_mode;
808 void fm10k_reset_rx_state(struct fm10k_intfc *interface)
810 struct net_device *netdev = interface->netdev;
811 struct fm10k_hw *hw = &interface->hw;
813 fm10k_mbx_lock(interface);
815 /* clear the logical port state on lower device */
816 hw->mac.ops.update_lport_state(hw, interface->glort,
817 interface->glort_count, false);
819 fm10k_mbx_unlock(interface);
821 /* reset flags to default state */
822 interface->xcast_mode = FM10K_XCAST_MODE_NONE;
824 /* clear the sync flag since the lport has been dropped */
825 __dev_uc_unsync(netdev, NULL);
826 __dev_mc_unsync(netdev, NULL);
830 * fm10k_get_stats64 - Get System Network Statistics
831 * @netdev: network interface device structure
832 * @stats: storage space for 64bit statistics
834 * Returns 64bit statistics, for use in the ndo_get_stats64 callback. This
835 * function replaces fm10k_get_stats for kernels which support it.
837 static struct rtnl_link_stats64 *fm10k_get_stats64(struct net_device *netdev,
838 struct rtnl_link_stats64 *stats)
840 struct fm10k_intfc *interface = netdev_priv(netdev);
841 struct fm10k_ring *ring;
842 unsigned int start, i;
847 for (i = 0; i < interface->num_rx_queues; i++) {
848 ring = ACCESS_ONCE(interface->rx_ring[i]);
854 start = u64_stats_fetch_begin_irq(&ring->syncp);
855 packets = ring->stats.packets;
856 bytes = ring->stats.bytes;
857 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
859 stats->rx_packets += packets;
860 stats->rx_bytes += bytes;
863 for (i = 0; i < interface->num_tx_queues; i++) {
864 ring = ACCESS_ONCE(interface->rx_ring[i]);
870 start = u64_stats_fetch_begin_irq(&ring->syncp);
871 packets = ring->stats.packets;
872 bytes = ring->stats.bytes;
873 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
875 stats->tx_packets += packets;
876 stats->tx_bytes += bytes;
881 /* following stats updated by fm10k_service_task() */
882 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
887 static const struct net_device_ops fm10k_netdev_ops = {
888 .ndo_open = fm10k_open,
889 .ndo_stop = fm10k_close,
890 .ndo_validate_addr = eth_validate_addr,
891 .ndo_start_xmit = fm10k_xmit_frame,
892 .ndo_set_mac_address = fm10k_set_mac,
893 .ndo_change_mtu = fm10k_change_mtu,
894 .ndo_vlan_rx_add_vid = fm10k_vlan_rx_add_vid,
895 .ndo_vlan_rx_kill_vid = fm10k_vlan_rx_kill_vid,
896 .ndo_set_rx_mode = fm10k_set_rx_mode,
897 .ndo_get_stats64 = fm10k_get_stats64,
900 #define DEFAULT_DEBUG_LEVEL_SHIFT 3
902 struct net_device *fm10k_alloc_netdev(void)
904 struct fm10k_intfc *interface;
905 struct net_device *dev;
907 dev = alloc_etherdev_mq(sizeof(struct fm10k_intfc), MAX_QUEUES);
911 /* set net device and ethtool ops */
912 dev->netdev_ops = &fm10k_netdev_ops;
914 /* configure default debug level */
915 interface = netdev_priv(dev);
916 interface->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
918 /* configure default features */
919 dev->features |= NETIF_F_SG;
921 /* all features defined to this point should be changeable */
922 dev->hw_features |= dev->features;
924 /* configure VLAN features */
925 dev->vlan_features |= dev->features;
927 /* configure tunnel offloads */
928 dev->hw_enc_features = NETIF_F_SG;
930 /* we want to leave these both on as we cannot disable VLAN tag
931 * insertion or stripping on the hardware since it is contained
932 * in the FTAG and not in the frame itself.
934 dev->features |= NETIF_F_HW_VLAN_CTAG_TX |
935 NETIF_F_HW_VLAN_CTAG_RX |
936 NETIF_F_HW_VLAN_CTAG_FILTER;
938 dev->priv_flags |= IFF_UNICAST_FLT;