/** * fm10k_setup_all_tx_resources - allocate all queues Tx resources * @interface: board private structure * * If this function returns with an error, then it's possible one or * more of the rings is populated (while the rest are not). It is the * callers duty to clean those orphaned rings. * * Return 0 on success, negative on failure
**/ staticint fm10k_setup_all_tx_resources(struct fm10k_intfc *interface)
{ int i, err;
for (i = 0; i < interface->num_tx_queues; i++) {
err = fm10k_setup_tx_resources(interface->tx_ring[i]); if (!err) continue;
/** * fm10k_setup_all_rx_resources - allocate all queues Rx resources * @interface: board private structure * * If this function returns with an error, then it's possible one or * more of the rings is populated (while the rest are not). It is the * callers duty to clean those orphaned rings. * * Return 0 on success, negative on failure
**/ staticint fm10k_setup_all_rx_resources(struct fm10k_intfc *interface)
{ int i, err;
for (i = 0; i < interface->num_rx_queues; i++) {
err = fm10k_setup_rx_resources(interface->rx_ring[i]); if (!err) continue;
/** * fm10k_clean_all_tx_rings - Free Tx Buffers for all queues * @interface: board private structure
**/ void fm10k_clean_all_tx_rings(struct fm10k_intfc *interface)
{ int i;
for (i = 0; i < interface->num_tx_queues; i++)
fm10k_clean_tx_ring(interface->tx_ring[i]);
}
/** * fm10k_free_all_tx_resources - Free Tx Resources for All Queues * @interface: board private structure * * Free all transmit software resources
**/ staticvoid fm10k_free_all_tx_resources(struct fm10k_intfc *interface)
{ int i = interface->num_tx_queues;
while (i--)
fm10k_free_tx_resources(interface->tx_ring[i]);
}
/** * fm10k_clean_rx_ring - Free Rx Buffers per Queue * @rx_ring: ring to free buffers from
**/ staticvoid fm10k_clean_rx_ring(struct fm10k_ring *rx_ring)
{ unsignedlong size;
u16 i;
if (!rx_ring->rx_buffer) return;
dev_kfree_skb(rx_ring->skb);
rx_ring->skb = NULL;
/* Free all the Rx ring sk_buffs */ for (i = 0; i < rx_ring->count; i++) { struct fm10k_rx_buffer *buffer = &rx_ring->rx_buffer[i]; /* clean-up will only set page pointer to NULL */ if (!buffer->page) continue;
/** * fm10k_clean_all_rx_rings - Free Rx Buffers for all queues * @interface: board private structure
**/ void fm10k_clean_all_rx_rings(struct fm10k_intfc *interface)
{ int i;
for (i = 0; i < interface->num_rx_queues; i++)
fm10k_clean_rx_ring(interface->rx_ring[i]);
}
/** * fm10k_free_all_rx_resources - Free Rx Resources for All Queues * @interface: board private structure * * Free all receive software resources
**/ staticvoid fm10k_free_all_rx_resources(struct fm10k_intfc *interface)
{ int i = interface->num_rx_queues;
while (i--)
fm10k_free_rx_resources(interface->rx_ring[i]);
}
/** * fm10k_request_glort_range - Request GLORTs for use in configuring rules * @interface: board private structure * * This function allocates a range of glorts for this interface to use.
**/ staticvoid fm10k_request_glort_range(struct fm10k_intfc *interface)
{ struct fm10k_hw *hw = &interface->hw;
u16 mask = (~hw->mac.dglort_map) >> FM10K_DGLORTMAP_MASK_SHIFT;
/* nothing we can do until mask is allocated */ if (hw->mac.dglort_map == FM10K_DGLORTMAP_NONE) return;
/* we support 3 possible GLORT configurations. * 1: VFs consume all but the last 1 * 2: VFs and PF split glorts with possible gap between * 3: VFs allocated first 64, all others belong to PF
*/ if (mask <= hw->iov.total_vfs) {
interface->glort_count = 1;
interface->glort += mask;
} elseif (mask < 64) {
interface->glort_count = (mask + 1) / 2;
interface->glort += interface->glort_count;
} else {
interface->glort_count = mask - 63;
interface->glort += 64;
}
}
/** * fm10k_restore_udp_port_info * @interface: board private structure * * This function restores the value in the tunnel_cfg register(s) after reset
**/ staticvoid fm10k_restore_udp_port_info(struct fm10k_intfc *interface)
{ struct fm10k_hw *hw = &interface->hw;
/* only the PF supports configuring tunnels */ if (hw->mac.type != fm10k_mac_pf) return;
/** * fm10k_udp_tunnel_sync - Called when UDP tunnel ports change * @dev: network interface device structure * @table: Tunnel table (according to tables of @fm10k_udp_tunnels) * * This function is called when a new UDP tunnel port is added or deleted. * Due to hardware restrictions, only one port per type can be offloaded at * once. Core will send to the driver a port of its choice.
**/ staticint fm10k_udp_tunnel_sync(struct net_device *dev, unsignedint table)
{ struct fm10k_intfc *interface = netdev_priv(dev); struct udp_tunnel_info ti;
/** * fm10k_open - Called when a network interface is made active * @netdev: network interface device structure * * Returns 0 on success, negative value on failure * * The open entry point is called when a network interface is made * active by the system (IFF_UP). At this point all resources needed * for transmit and receive operations are allocated, the interrupt * handler is registered with the OS, the watchdog timer is started, * and the stack is notified that the interface is ready.
**/ int fm10k_open(struct net_device *netdev)
{ struct fm10k_intfc *interface = netdev_priv(netdev); int err;
/** * fm10k_close - Disables a network interface * @netdev: network interface device structure * * Returns 0, this is not allowed to fail * * The close entry point is called when an interface is de-activated * by the OS. The hardware is still under the drivers control, but * needs to be disabled. A global MAC reset is issued to stop the * hardware, and all transmit and receive resources are freed.
**/ int fm10k_close(struct net_device *netdev)
{ struct fm10k_intfc *interface = netdev_priv(netdev);
if ((skb->protocol == htons(ETH_P_8021Q)) &&
!skb_vlan_tag_present(skb)) { /* FM10K only supports hardware tagging, any tags in frame * are considered 2nd level or "outer" tags
*/ struct vlan_hdr *vhdr;
__be16 proto;
/* make sure skb is not shared */
skb = skb_share_check(skb, GFP_ATOMIC); if (!skb) return NETDEV_TX_OK;
/* make sure there is enough room to move the ethernet header */ if (unlikely(!pskb_may_pull(skb, VLAN_ETH_HLEN))) return NETDEV_TX_OK;
/* verify the skb head is not shared */
err = skb_cow_head(skb, 0); if (err) {
dev_kfree_skb(skb); return NETDEV_TX_OK;
}
/* pull the 2 key pieces of data out of it */
__vlan_hwaccel_put_tag(skb,
htons(ETH_P_8021Q),
ntohs(vhdr->h_vlan_TCI));
proto = vhdr->h_vlan_encapsulated_proto;
skb->protocol = (ntohs(proto) >= 1536) ? proto :
htons(ETH_P_802_2);
/* squash it by moving the ethernet addresses up 4 bytes */
memmove(skb->data + VLAN_HLEN, skb->data, 12);
__skb_pull(skb, VLAN_HLEN);
skb_reset_mac_header(skb);
}
/* The minimum packet size for a single buffer is 17B so pad the skb * in order to meet this minimum size requirement.
*/ if (unlikely(skb->len < 17)) { int pad_len = 17 - skb->len;
if (skb_pad(skb, pad_len)) return NETDEV_TX_OK;
__skb_put(skb, pad_len);
}
if (r_idx >= num_tx_queues)
r_idx %= num_tx_queues;
/** * fm10k_tx_timeout - Respond to a Tx Hang * @netdev: network interface device structure * @txqueue: the index of the Tx queue that timed out
**/ staticvoid fm10k_tx_timeout(struct net_device *netdev, unsignedint txqueue)
{ struct fm10k_intfc *interface = netdev_priv(netdev); struct fm10k_ring *tx_ring; bool real_tx_hang = false;
if (txqueue >= interface->num_tx_queues) {
WARN(1, "invalid Tx queue index %d", txqueue); return;
}
tx_ring = interface->tx_ring[txqueue]; if (check_for_tx_hang(tx_ring) && fm10k_check_tx_hang(tx_ring))
real_tx_hang = true;
#define TX_TIMEO_LIMIT 16000 if (real_tx_hang) {
fm10k_tx_timeout_reset(interface);
} else {
netif_info(interface, drv, netdev, "Fake Tx hang detected with timeout of %d seconds\n",
netdev->watchdog_timeo / HZ);
/* fake Tx hang - increase the kernel timeout */ if (netdev->watchdog_timeo < TX_TIMEO_LIMIT)
netdev->watchdog_timeo *= 2;
}
}
/** * fm10k_host_mbx_ready - Check PF interface's mailbox readiness * @interface: board private structure * * This function checks if the PF interface's mailbox is ready before queueing * mailbox messages for transmission. This will prevent filling the TX mailbox * queue when the receiver is not ready. VF interfaces are exempt from this * check since it will block all PF-VF mailbox messages from being sent from * the VF to the PF at initialization.
**/ staticbool fm10k_host_mbx_ready(struct fm10k_intfc *interface)
{ struct fm10k_hw *hw = &interface->hw;
/** * fm10k_queue_vlan_request - Queue a VLAN update request * @interface: the fm10k interface structure * @vid: the VLAN vid * @vsi: VSI index number * @set: whether to set or clear * * This function queues up a VLAN update. For VFs, this must be sent to the * managing PF over the mailbox. For PFs, we'll use the same handling so that * it's similar to the VF. This avoids storming the PF<->VF mailbox with too * many VLAN updates during reset.
*/ int fm10k_queue_vlan_request(struct fm10k_intfc *interface,
u32 vid, u8 vsi, bool set)
{ struct fm10k_macvlan_request *request; unsignedlong flags;
/* This must be atomic since we may be called while the netdev * addr_list_lock is held
*/
request = kzalloc(sizeof(*request), GFP_ATOMIC); if (!request) return -ENOMEM;
/** * fm10k_queue_mac_request - Queue a MAC update request * @interface: the fm10k interface structure * @glort: the target glort for this update * @addr: the address to update * @vid: the vid to update * @set: whether to add or remove * * This function queues up a MAC request for sending to the switch manager. * A separate thread monitors the queue and sends updates to the switch * manager. Return 0 on success, and negative error code on failure.
**/ int fm10k_queue_mac_request(struct fm10k_intfc *interface, u16 glort, constunsignedchar *addr, u16 vid, bool set)
{ struct fm10k_macvlan_request *request; unsignedlong flags;
/* This must be atomic since we may be called while the netdev * addr_list_lock is held
*/
request = kzalloc(sizeof(*request), GFP_ATOMIC); if (!request) return -ENOMEM;
if (is_multicast_ether_addr(addr))
request->type = FM10K_MC_MAC_REQUEST; else
request->type = FM10K_UC_MAC_REQUEST;
/** * fm10k_clear_macvlan_queue - Cancel pending updates for a given glort * @interface: the fm10k interface structure * @glort: the target glort to clear * @vlans: true to clear VLAN messages, false to ignore them * * Cancel any outstanding MAC/VLAN requests for a given glort. This is * expected to be called when a logical port goes down.
**/ void fm10k_clear_macvlan_queue(struct fm10k_intfc *interface,
u16 glort, bool vlans)
/* Free any outstanding MAC/VLAN requests for this interface */
list_for_each_entry_safe(r, tmp, &interface->macvlan_requests, list) { switch (r->type) { case FM10K_MC_MAC_REQUEST: case FM10K_UC_MAC_REQUEST: /* Don't free requests for other interfaces */ if (r->mac.glort != glort) break;
fallthrough; case FM10K_VLAN_REQUEST: if (vlans) {
list_del(&r->list);
kfree(r);
} break;
}
}
/* updates do not apply to VLAN 0 */ if (!vid) return 0;
if (vid >= VLAN_N_VID) return -EINVAL;
/* Verify that we have permission to add VLANs. If this is a request * to remove a VLAN, we still want to allow the user to remove the * VLAN device. In that case, we need to clear the bit in the * active_vlans bitmask.
*/ if (set && hw->mac.vlan_override) return -EACCES;
/* disable the default VLAN ID on ring if we have an active VLAN */ for (i = 0; i < interface->num_rx_queues; i++) { struct fm10k_ring *rx_ring = interface->rx_ring[i];
u16 rx_vid = rx_ring->vid & (VLAN_N_VID - 1);
/* If our VLAN has been overridden, there is no reason to send VLAN * removal requests as they will be silently ignored.
*/ if (hw->mac.vlan_override) return 0;
/* Do not remove default VLAN ID related entries from VLAN and MAC * tables
*/ if (!set && vid == hw->mac.default_vid) return 0;
/* Do not throw an error if the interface is down. We will sync once * we come up
*/ if (test_bit(__FM10K_DOWN, interface->state)) return 0;
fm10k_mbx_lock(interface);
/* only need to update the VLAN if not in promiscuous mode */ if (!(netdev->flags & IFF_PROMISC)) {
err = fm10k_queue_vlan_request(interface, vid, 0, set); if (err) goto err_out;
}
/* Update our base MAC address */
err = fm10k_queue_mac_request(interface, interface->glort,
hw->mac.addr, vid, set); if (err) goto err_out;
/* Update L2 accelerated macvlan addresses */ if (l2_accel) { for (i = 0; i < l2_accel->size; i++) { struct net_device *sdev = l2_accel->macvlan[i];
/* set VLAN ID prior to syncing/unsyncing the VLAN */
interface->vid = vid + (set ? VLAN_N_VID : 0);
/* Update the unicast and multicast address list to add/drop VLAN */
__dev_uc_unsync(netdev, fm10k_uc_vlan_unsync);
__dev_mc_unsync(netdev, fm10k_mc_vlan_unsync);
err_out:
fm10k_mbx_unlock(interface);
return err;
}
staticint fm10k_vlan_rx_add_vid(struct net_device *netdev,
__always_unused __be16 proto, u16 vid)
{ /* update VLAN and address table based on changes */ return fm10k_update_vid(netdev, vid, true);
}
staticint fm10k_vlan_rx_kill_vid(struct net_device *netdev,
__always_unused __be16 proto, u16 vid)
{ /* update VLAN and address table based on changes */ return fm10k_update_vid(netdev, vid, false);
}
/* loop through and find any gaps in the table */ for (vid = 0, prev_vid = 0;
prev_vid < VLAN_N_VID;
prev_vid = vid + 1, vid = fm10k_find_next_vlan(interface, vid)) { if (prev_vid == vid) continue;
/* send request to clear multiple bits at a time */
prev_vid += (vid - prev_vid - 1) << FM10K_VLAN_LENGTH_SHIFT;
fm10k_queue_vlan_request(interface, prev_vid, 0, false);
}
}
/* update xcast mode first, but only if it changed */ if (interface->xcast_mode != xcast_mode) { /* update VLAN table when entering promiscuous mode */ if (xcast_mode == FM10K_XCAST_MODE_PROMISC)
fm10k_queue_vlan_request(interface, FM10K_VLAN_ALL,
0, true);
/* clear VLAN table when exiting promiscuous mode */ if (interface->xcast_mode == FM10K_XCAST_MODE_PROMISC)
fm10k_clear_unused_vlans(interface);
/* update xcast mode if host's mailbox is ready */ if (fm10k_host_mbx_ready(interface))
hw->mac.ops.update_xcast_mode(hw, interface->glort,
xcast_mode);
/* record updated xcast mode state */
interface->xcast_mode = xcast_mode;
}
/* synchronize all of the addresses */
__dev_uc_sync(dev, fm10k_uc_sync, fm10k_uc_unsync);
__dev_mc_sync(dev, fm10k_mc_sync, fm10k_mc_unsync);
/* Enable logical port if host's mailbox is ready */ if (fm10k_host_mbx_ready(interface))
hw->mac.ops.update_lport_state(hw, glort,
interface->glort_count, true);
/* update table with current entries */ for (vid = fm10k_find_next_vlan(interface, 0);
vid < VLAN_N_VID;
vid = fm10k_find_next_vlan(interface, vid)) {
fm10k_queue_vlan_request(interface, vid, 0, true);
/* update xcast mode before synchronizing addresses if host's mailbox * is ready
*/ if (fm10k_host_mbx_ready(interface))
hw->mac.ops.update_xcast_mode(hw, glort, xcast_mode);
/* synchronize all of the addresses */
__dev_uc_sync(netdev, fm10k_uc_sync, fm10k_uc_unsync);
__dev_mc_sync(netdev, fm10k_mc_sync, fm10k_mc_unsync);
/* synchronize macvlan addresses */ if (l2_accel) { for (i = 0; i < l2_accel->size; i++) { struct net_device *sdev = l2_accel->macvlan[i];
/* clear the logical port state on lower device if host's mailbox is * ready
*/ if (fm10k_host_mbx_ready(interface))
hw->mac.ops.update_lport_state(hw, interface->glort,
interface->glort_count, false);
fm10k_mbx_unlock(interface);
/* reset flags to default state */
interface->xcast_mode = FM10K_XCAST_MODE_NONE;
/* clear the sync flag since the lport has been dropped */
__dev_uc_unsync(netdev, NULL);
__dev_mc_unsync(netdev, NULL);
}
/** * fm10k_get_stats64 - Get System Network Statistics * @netdev: network interface device structure * @stats: storage space for 64bit statistics * * Obtain 64bit statistics in a way that is safe for both 32bit and 64bit * architectures.
*/ staticvoid fm10k_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats)
{ struct fm10k_intfc *interface = netdev_priv(netdev); struct fm10k_ring *ring; unsignedint start, i;
u64 bytes, packets;
rcu_read_lock();
for (i = 0; i < interface->num_rx_queues; i++) {
ring = READ_ONCE(interface->rx_ring[i]);
if (!ring) continue;
do {
start = u64_stats_fetch_begin(&ring->syncp);
packets = ring->stats.packets;
bytes = ring->stats.bytes;
} while (u64_stats_fetch_retry(&ring->syncp, start));
/* following stats updated by fm10k_service_task() */
stats->rx_missed_errors = netdev->stats.rx_missed_errors;
}
int fm10k_setup_tc(struct net_device *dev, u8 tc)
{ struct fm10k_intfc *interface = netdev_priv(dev); int err;
/* Currently only the PF supports priority classes */ if (tc && (interface->hw.mac.type != fm10k_mac_pf)) return -EINVAL;
/* Hardware supports up to 8 traffic classes */ if (tc > 8) return -EINVAL;
/* Hardware has to reinitialize queues to match packet * buffer alignment. Unfortunately, the hardware is not * flexible enough to do this dynamically.
*/ if (netif_running(dev))
fm10k_close(dev);
fm10k_mbx_free_irq(interface);
fm10k_clear_queueing_scheme(interface);
/* we expect the prio_tc map to be repopulated later */
netdev_reset_tc(dev);
netdev_set_num_tc(dev, tc);
err = fm10k_init_queueing_scheme(interface); if (err) goto err_queueing_scheme;
err = fm10k_mbx_request_irq(interface); if (err) goto err_mbx_irq;
/* The hardware supported by fm10k only filters on the destination MAC * address. In order to avoid issues we only support offloading modes * where the hardware can actually provide the functionality.
*/ if (!macvlan_supports_dest_filter(sdev)) return ERR_PTR(-EMEDIUMTYPE);
/* allocate l2 accel structure if it is not available */ if (!l2_accel) { /* verify there is enough free GLORTs to support l2_accel */ if (interface->glort_count < 7) return ERR_PTR(-EBUSY);
/* Only the PF can support VXLAN and NVGRE tunnel offloads */ if (info->mac == fm10k_mac_pf) {
dev->hw_enc_features = NETIF_F_IP_CSUM |
NETIF_F_TSO |
NETIF_F_TSO6 |
NETIF_F_TSO_ECN |
NETIF_F_GSO_UDP_TUNNEL |
NETIF_F_IPV6_CSUM |
NETIF_F_SG;
dev->features |= NETIF_F_GSO_UDP_TUNNEL;
dev->udp_tunnel_nic_info = &fm10k_udp_tunnels;
}
/* all features defined to this point should be changeable */
hw_features = dev->features;
/* allow user to enable L2 forwarding acceleration */
hw_features |= NETIF_F_HW_L2FW_DOFFLOAD;
/* configure VLAN features */
dev->vlan_features |= dev->features;
/* we want to leave these both on as we cannot disable VLAN tag * insertion or stripping on the hardware since it is contained * in the FTAG and not in the frame itself.
*/
dev->features |= NETIF_F_HW_VLAN_CTAG_TX |
NETIF_F_HW_VLAN_CTAG_RX |
NETIF_F_HW_VLAN_CTAG_FILTER;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.