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 struct fm10k_intfc *interface = netdev_priv(dev);
455 unsigned int r_idx = 0;
458 if ((skb->protocol == htons(ETH_P_8021Q)) &&
459 !vlan_tx_tag_present(skb)) {
460 /* FM10K only supports hardware tagging, any tags in frame
461 * are considered 2nd level or "outer" tags
463 struct vlan_hdr *vhdr;
466 /* make sure skb is not shared */
467 skb = skb_share_check(skb, GFP_ATOMIC);
471 /* make sure there is enough room to move the ethernet header */
472 if (unlikely(!pskb_may_pull(skb, VLAN_ETH_HLEN)))
475 /* verify the skb head is not shared */
476 err = skb_cow_head(skb, 0);
480 /* locate vlan header */
481 vhdr = (struct vlan_hdr *)(skb->data + ETH_HLEN);
483 /* pull the 2 key pieces of data out of it */
484 __vlan_hwaccel_put_tag(skb,
486 ntohs(vhdr->h_vlan_TCI));
487 proto = vhdr->h_vlan_encapsulated_proto;
488 skb->protocol = (ntohs(proto) >= 1536) ? proto :
491 /* squash it by moving the ethernet addresses up 4 bytes */
492 memmove(skb->data + VLAN_HLEN, skb->data, 12);
493 __skb_pull(skb, VLAN_HLEN);
494 skb_reset_mac_header(skb);
497 /* The minimum packet size for a single buffer is 17B so pad the skb
498 * in order to meet this minimum size requirement.
500 if (unlikely(skb->len < 17)) {
501 int pad_len = 17 - skb->len;
503 if (skb_pad(skb, pad_len))
505 __skb_put(skb, pad_len);
508 if (r_idx >= interface->num_tx_queues)
509 r_idx %= interface->num_tx_queues;
511 err = fm10k_xmit_frame_ring(skb, interface->tx_ring[r_idx]);
516 static int fm10k_change_mtu(struct net_device *dev, int new_mtu)
518 if (new_mtu < 68 || new_mtu > FM10K_MAX_JUMBO_FRAME_SIZE)
527 * fm10k_tx_timeout - Respond to a Tx Hang
528 * @netdev: network interface device structure
530 static void fm10k_tx_timeout(struct net_device *netdev)
532 struct fm10k_intfc *interface = netdev_priv(netdev);
533 bool real_tx_hang = false;
536 #define TX_TIMEO_LIMIT 16000
537 for (i = 0; i < interface->num_tx_queues; i++) {
538 struct fm10k_ring *tx_ring = interface->tx_ring[i];
540 if (check_for_tx_hang(tx_ring) && fm10k_check_tx_hang(tx_ring))
545 fm10k_tx_timeout_reset(interface);
547 netif_info(interface, drv, netdev,
548 "Fake Tx hang detected with timeout of %d seconds\n",
549 netdev->watchdog_timeo/HZ);
551 /* fake Tx hang - increase the kernel timeout */
552 if (netdev->watchdog_timeo < TX_TIMEO_LIMIT)
553 netdev->watchdog_timeo *= 2;
557 static int fm10k_uc_vlan_unsync(struct net_device *netdev,
558 const unsigned char *uc_addr)
560 struct fm10k_intfc *interface = netdev_priv(netdev);
561 struct fm10k_hw *hw = &interface->hw;
562 u16 glort = interface->glort;
563 u16 vid = interface->vid;
564 bool set = !!(vid / VLAN_N_VID);
567 /* drop any leading bits on the VLAN ID */
568 vid &= VLAN_N_VID - 1;
570 err = hw->mac.ops.update_uc_addr(hw, glort, uc_addr, vid, set, 0);
574 /* return non-zero value as we are only doing a partial sync/unsync */
578 static int fm10k_mc_vlan_unsync(struct net_device *netdev,
579 const unsigned char *mc_addr)
581 struct fm10k_intfc *interface = netdev_priv(netdev);
582 struct fm10k_hw *hw = &interface->hw;
583 u16 glort = interface->glort;
584 u16 vid = interface->vid;
585 bool set = !!(vid / VLAN_N_VID);
588 /* drop any leading bits on the VLAN ID */
589 vid &= VLAN_N_VID - 1;
591 err = hw->mac.ops.update_mc_addr(hw, glort, mc_addr, vid, set);
595 /* return non-zero value as we are only doing a partial sync/unsync */
599 static int fm10k_update_vid(struct net_device *netdev, u16 vid, bool set)
601 struct fm10k_intfc *interface = netdev_priv(netdev);
602 struct fm10k_hw *hw = &interface->hw;
605 /* updates do not apply to VLAN 0 */
609 if (vid >= VLAN_N_VID)
612 /* Verify we have permission to add VLANs */
613 if (hw->mac.vlan_override)
616 /* if default VLAN is already present do nothing */
617 if (vid == hw->mac.default_vid)
620 /* update active_vlans bitmask */
621 set_bit(vid, interface->active_vlans);
623 clear_bit(vid, interface->active_vlans);
625 fm10k_mbx_lock(interface);
627 /* only need to update the VLAN if not in promiscous mode */
628 if (!(netdev->flags & IFF_PROMISC)) {
629 err = hw->mac.ops.update_vlan(hw, vid, 0, set);
634 /* update our base MAC address */
635 err = hw->mac.ops.update_uc_addr(hw, interface->glort, hw->mac.addr,
640 /* set vid prior to syncing/unsyncing the VLAN */
641 interface->vid = vid + (set ? VLAN_N_VID : 0);
643 /* Update the unicast and multicast address list to add/drop VLAN */
644 __dev_uc_unsync(netdev, fm10k_uc_vlan_unsync);
645 __dev_mc_unsync(netdev, fm10k_mc_vlan_unsync);
647 fm10k_mbx_unlock(interface);
652 static int fm10k_vlan_rx_add_vid(struct net_device *netdev,
653 __always_unused __be16 proto, u16 vid)
655 /* update VLAN and address table based on changes */
656 return fm10k_update_vid(netdev, vid, true);
659 static int fm10k_vlan_rx_kill_vid(struct net_device *netdev,
660 __always_unused __be16 proto, u16 vid)
662 /* update VLAN and address table based on changes */
663 return fm10k_update_vid(netdev, vid, false);
666 static u16 fm10k_find_next_vlan(struct fm10k_intfc *interface, u16 vid)
668 struct fm10k_hw *hw = &interface->hw;
669 u16 default_vid = hw->mac.default_vid;
670 u16 vid_limit = vid < default_vid ? default_vid : VLAN_N_VID;
672 vid = find_next_bit(interface->active_vlans, vid_limit, ++vid);
677 static void fm10k_clear_unused_vlans(struct fm10k_intfc *interface)
679 struct fm10k_hw *hw = &interface->hw;
682 /* loop through and find any gaps in the table */
683 for (vid = 0, prev_vid = 0;
684 prev_vid < VLAN_N_VID;
685 prev_vid = vid + 1, vid = fm10k_find_next_vlan(interface, vid)) {
689 /* send request to clear multiple bits at a time */
690 prev_vid += (vid - prev_vid - 1) << FM10K_VLAN_LENGTH_SHIFT;
691 hw->mac.ops.update_vlan(hw, prev_vid, 0, false);
695 static int __fm10k_uc_sync(struct net_device *dev,
696 const unsigned char *addr, bool sync)
698 struct fm10k_intfc *interface = netdev_priv(dev);
699 struct fm10k_hw *hw = &interface->hw;
700 u16 vid, glort = interface->glort;
703 if (!is_valid_ether_addr(addr))
704 return -EADDRNOTAVAIL;
706 /* update table with current entries */
707 for (vid = hw->mac.default_vid ? fm10k_find_next_vlan(interface, 0) : 0;
709 vid = fm10k_find_next_vlan(interface, vid)) {
710 err = hw->mac.ops.update_uc_addr(hw, glort, addr,
719 static int fm10k_uc_sync(struct net_device *dev,
720 const unsigned char *addr)
722 return __fm10k_uc_sync(dev, addr, true);
725 static int fm10k_uc_unsync(struct net_device *dev,
726 const unsigned char *addr)
728 return __fm10k_uc_sync(dev, addr, false);
731 static int fm10k_set_mac(struct net_device *dev, void *p)
733 struct fm10k_intfc *interface = netdev_priv(dev);
734 struct fm10k_hw *hw = &interface->hw;
735 struct sockaddr *addr = p;
738 if (!is_valid_ether_addr(addr->sa_data))
739 return -EADDRNOTAVAIL;
741 if (dev->flags & IFF_UP) {
742 /* setting MAC address requires mailbox */
743 fm10k_mbx_lock(interface);
745 err = fm10k_uc_sync(dev, addr->sa_data);
747 fm10k_uc_unsync(dev, hw->mac.addr);
749 fm10k_mbx_unlock(interface);
753 ether_addr_copy(dev->dev_addr, addr->sa_data);
754 ether_addr_copy(hw->mac.addr, addr->sa_data);
755 dev->addr_assign_type &= ~NET_ADDR_RANDOM;
758 /* if we had a mailbox error suggest trying again */
759 return err ? -EAGAIN : 0;
762 static int __fm10k_mc_sync(struct net_device *dev,
763 const unsigned char *addr, bool sync)
765 struct fm10k_intfc *interface = netdev_priv(dev);
766 struct fm10k_hw *hw = &interface->hw;
767 u16 vid, glort = interface->glort;
770 if (!is_multicast_ether_addr(addr))
771 return -EADDRNOTAVAIL;
773 /* update table with current entries */
774 for (vid = hw->mac.default_vid ? fm10k_find_next_vlan(interface, 0) : 0;
776 vid = fm10k_find_next_vlan(interface, vid)) {
777 err = hw->mac.ops.update_mc_addr(hw, glort, addr, vid, sync);
785 static int fm10k_mc_sync(struct net_device *dev,
786 const unsigned char *addr)
788 return __fm10k_mc_sync(dev, addr, true);
791 static int fm10k_mc_unsync(struct net_device *dev,
792 const unsigned char *addr)
794 return __fm10k_mc_sync(dev, addr, false);
797 static void fm10k_set_rx_mode(struct net_device *dev)
799 struct fm10k_intfc *interface = netdev_priv(dev);
800 struct fm10k_hw *hw = &interface->hw;
803 /* no need to update the harwdare if we are not running */
804 if (!(dev->flags & IFF_UP))
807 /* determine new mode based on flags */
808 xcast_mode = (dev->flags & IFF_PROMISC) ? FM10K_XCAST_MODE_PROMISC :
809 (dev->flags & IFF_ALLMULTI) ? FM10K_XCAST_MODE_ALLMULTI :
810 (dev->flags & (IFF_BROADCAST | IFF_MULTICAST)) ?
811 FM10K_XCAST_MODE_MULTI : FM10K_XCAST_MODE_NONE;
813 fm10k_mbx_lock(interface);
815 /* syncronize all of the addresses */
816 if (xcast_mode != FM10K_XCAST_MODE_PROMISC) {
817 __dev_uc_sync(dev, fm10k_uc_sync, fm10k_uc_unsync);
818 if (xcast_mode != FM10K_XCAST_MODE_ALLMULTI)
819 __dev_mc_sync(dev, fm10k_mc_sync, fm10k_mc_unsync);
822 /* if we aren't changing modes there is nothing to do */
823 if (interface->xcast_mode != xcast_mode) {
824 /* update VLAN table */
825 if (xcast_mode == FM10K_XCAST_MODE_PROMISC)
826 hw->mac.ops.update_vlan(hw, FM10K_VLAN_ALL, 0, true);
827 if (interface->xcast_mode == FM10K_XCAST_MODE_PROMISC)
828 fm10k_clear_unused_vlans(interface);
830 /* update xcast mode */
831 hw->mac.ops.update_xcast_mode(hw, interface->glort, xcast_mode);
833 /* record updated xcast mode state */
834 interface->xcast_mode = xcast_mode;
837 fm10k_mbx_unlock(interface);
840 void fm10k_restore_rx_state(struct fm10k_intfc *interface)
842 struct net_device *netdev = interface->netdev;
843 struct fm10k_hw *hw = &interface->hw;
847 /* record glort for this interface */
848 glort = interface->glort;
850 /* convert interface flags to xcast mode */
851 if (netdev->flags & IFF_PROMISC)
852 xcast_mode = FM10K_XCAST_MODE_PROMISC;
853 else if (netdev->flags & IFF_ALLMULTI)
854 xcast_mode = FM10K_XCAST_MODE_ALLMULTI;
855 else if (netdev->flags & (IFF_BROADCAST | IFF_MULTICAST))
856 xcast_mode = FM10K_XCAST_MODE_MULTI;
858 xcast_mode = FM10K_XCAST_MODE_NONE;
860 fm10k_mbx_lock(interface);
862 /* Enable logical port */
863 hw->mac.ops.update_lport_state(hw, glort, interface->glort_count, true);
865 /* update VLAN table */
866 hw->mac.ops.update_vlan(hw, FM10K_VLAN_ALL, 0,
867 xcast_mode == FM10K_XCAST_MODE_PROMISC);
869 /* Add filter for VLAN 0 */
870 hw->mac.ops.update_vlan(hw, 0, 0, true);
872 /* update table with current entries */
873 for (vid = hw->mac.default_vid ? fm10k_find_next_vlan(interface, 0) : 0;
875 vid = fm10k_find_next_vlan(interface, vid)) {
876 hw->mac.ops.update_vlan(hw, vid, 0, true);
877 hw->mac.ops.update_uc_addr(hw, glort, hw->mac.addr,
881 /* syncronize all of the addresses */
882 if (xcast_mode != FM10K_XCAST_MODE_PROMISC) {
883 __dev_uc_sync(netdev, fm10k_uc_sync, fm10k_uc_unsync);
884 if (xcast_mode != FM10K_XCAST_MODE_ALLMULTI)
885 __dev_mc_sync(netdev, fm10k_mc_sync, fm10k_mc_unsync);
888 /* update xcast mode */
889 hw->mac.ops.update_xcast_mode(hw, glort, xcast_mode);
891 fm10k_mbx_unlock(interface);
893 /* record updated xcast mode state */
894 interface->xcast_mode = xcast_mode;
897 void fm10k_reset_rx_state(struct fm10k_intfc *interface)
899 struct net_device *netdev = interface->netdev;
900 struct fm10k_hw *hw = &interface->hw;
902 fm10k_mbx_lock(interface);
904 /* clear the logical port state on lower device */
905 hw->mac.ops.update_lport_state(hw, interface->glort,
906 interface->glort_count, false);
908 fm10k_mbx_unlock(interface);
910 /* reset flags to default state */
911 interface->xcast_mode = FM10K_XCAST_MODE_NONE;
913 /* clear the sync flag since the lport has been dropped */
914 __dev_uc_unsync(netdev, NULL);
915 __dev_mc_unsync(netdev, NULL);
919 * fm10k_get_stats64 - Get System Network Statistics
920 * @netdev: network interface device structure
921 * @stats: storage space for 64bit statistics
923 * Returns 64bit statistics, for use in the ndo_get_stats64 callback. This
924 * function replaces fm10k_get_stats for kernels which support it.
926 static struct rtnl_link_stats64 *fm10k_get_stats64(struct net_device *netdev,
927 struct rtnl_link_stats64 *stats)
929 struct fm10k_intfc *interface = netdev_priv(netdev);
930 struct fm10k_ring *ring;
931 unsigned int start, i;
936 for (i = 0; i < interface->num_rx_queues; i++) {
937 ring = ACCESS_ONCE(interface->rx_ring[i]);
943 start = u64_stats_fetch_begin_irq(&ring->syncp);
944 packets = ring->stats.packets;
945 bytes = ring->stats.bytes;
946 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
948 stats->rx_packets += packets;
949 stats->rx_bytes += bytes;
952 for (i = 0; i < interface->num_tx_queues; i++) {
953 ring = ACCESS_ONCE(interface->rx_ring[i]);
959 start = u64_stats_fetch_begin_irq(&ring->syncp);
960 packets = ring->stats.packets;
961 bytes = ring->stats.bytes;
962 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
964 stats->tx_packets += packets;
965 stats->tx_bytes += bytes;
970 /* following stats updated by fm10k_service_task() */
971 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
976 int fm10k_setup_tc(struct net_device *dev, u8 tc)
978 struct fm10k_intfc *interface = netdev_priv(dev);
980 /* Currently only the PF supports priority classes */
981 if (tc && (interface->hw.mac.type != fm10k_mac_pf))
984 /* Hardware supports up to 8 traffic classes */
988 /* Hardware has to reinitialize queues to match packet
989 * buffer alignment. Unfortunately, the hardware is not
990 * flexible enough to do this dynamically.
992 if (netif_running(dev))
995 fm10k_mbx_free_irq(interface);
997 fm10k_clear_queueing_scheme(interface);
999 /* we expect the prio_tc map to be repopulated later */
1000 netdev_reset_tc(dev);
1001 netdev_set_num_tc(dev, tc);
1003 fm10k_init_queueing_scheme(interface);
1005 fm10k_mbx_request_irq(interface);
1007 if (netif_running(dev))
1010 /* flag to indicate SWPRI has yet to be updated */
1011 interface->flags |= FM10K_FLAG_SWPRI_CONFIG;
1016 static const struct net_device_ops fm10k_netdev_ops = {
1017 .ndo_open = fm10k_open,
1018 .ndo_stop = fm10k_close,
1019 .ndo_validate_addr = eth_validate_addr,
1020 .ndo_start_xmit = fm10k_xmit_frame,
1021 .ndo_set_mac_address = fm10k_set_mac,
1022 .ndo_change_mtu = fm10k_change_mtu,
1023 .ndo_tx_timeout = fm10k_tx_timeout,
1024 .ndo_vlan_rx_add_vid = fm10k_vlan_rx_add_vid,
1025 .ndo_vlan_rx_kill_vid = fm10k_vlan_rx_kill_vid,
1026 .ndo_set_rx_mode = fm10k_set_rx_mode,
1027 .ndo_get_stats64 = fm10k_get_stats64,
1028 .ndo_setup_tc = fm10k_setup_tc,
1031 #define DEFAULT_DEBUG_LEVEL_SHIFT 3
1033 struct net_device *fm10k_alloc_netdev(void)
1035 struct fm10k_intfc *interface;
1036 struct net_device *dev;
1038 dev = alloc_etherdev_mq(sizeof(struct fm10k_intfc), MAX_QUEUES);
1042 /* set net device and ethtool ops */
1043 dev->netdev_ops = &fm10k_netdev_ops;
1044 fm10k_set_ethtool_ops(dev);
1046 /* configure default debug level */
1047 interface = netdev_priv(dev);
1048 interface->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
1050 /* configure default features */
1051 dev->features |= NETIF_F_SG;
1053 /* all features defined to this point should be changeable */
1054 dev->hw_features |= dev->features;
1056 /* configure VLAN features */
1057 dev->vlan_features |= dev->features;
1059 /* configure tunnel offloads */
1060 dev->hw_enc_features = NETIF_F_SG;
1062 /* we want to leave these both on as we cannot disable VLAN tag
1063 * insertion or stripping on the hardware since it is contained
1064 * in the FTAG and not in the frame itself.
1066 dev->features |= NETIF_F_HW_VLAN_CTAG_TX |
1067 NETIF_F_HW_VLAN_CTAG_RX |
1068 NETIF_F_HW_VLAN_CTAG_FILTER;
1070 dev->priv_flags |= IFF_UNICAST_FLT;