108135eecSEdward Cree // SPDX-License-Identifier: GPL-2.0-only 208135eecSEdward Cree /**************************************************************************** 308135eecSEdward Cree * Driver for Solarflare network controllers and boards 408135eecSEdward Cree * Copyright 2019 Solarflare Communications Inc. 508135eecSEdward Cree * Copyright 2020-2022 Xilinx Inc. 608135eecSEdward Cree * 708135eecSEdward Cree * This program is free software; you can redistribute it and/or modify it 808135eecSEdward Cree * under the terms of the GNU General Public License version 2 as published 908135eecSEdward Cree * by the Free Software Foundation, incorporated herein by reference. 1008135eecSEdward Cree */ 1108135eecSEdward Cree 1208135eecSEdward Cree #include "ef100_rep.h" 13f72c38faSEdward Cree #include "ef100_netdev.h" 1408135eecSEdward Cree #include "ef100_nic.h" 15da56552dSEdward Cree #include "mae.h" 169fe00c80SEdward Cree #include "rx_common.h" 179dc0cad2SEdward Cree #include "tc_bindings.h" 1808135eecSEdward Cree 195687eb34SEdward Cree #define EFX_EF100_REP_DRIVER "efx_ef100_rep" 205687eb34SEdward Cree 219fe00c80SEdward Cree #define EFX_REP_DEFAULT_PSEUDO_RING_SIZE 64 229fe00c80SEdward Cree 2369bb5fa7SEdward Cree static int efx_ef100_rep_poll(struct napi_struct *napi, int weight); 2469bb5fa7SEdward Cree 25e1479556SEdward Cree static int efx_ef100_rep_init_struct(struct efx_nic *efx, struct efx_rep *efv, 26e1479556SEdward Cree unsigned int i) 2708135eecSEdward Cree { 2808135eecSEdward Cree efv->parent = efx; 29e1479556SEdward Cree efv->idx = i; 3008135eecSEdward Cree INIT_LIST_HEAD(&efv->list); 3167ab160eSEdward Cree efv->dflt.fw_id = MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL; 3267ab160eSEdward Cree INIT_LIST_HEAD(&efv->dflt.acts.list); 3369bb5fa7SEdward Cree INIT_LIST_HEAD(&efv->rx_list); 3469bb5fa7SEdward Cree spin_lock_init(&efv->rx_lock); 3508135eecSEdward Cree efv->msg_enable = NETIF_MSG_DRV | NETIF_MSG_PROBE | 3608135eecSEdward Cree NETIF_MSG_LINK | NETIF_MSG_IFDOWN | 3708135eecSEdward Cree NETIF_MSG_IFUP | NETIF_MSG_RX_ERR | 3808135eecSEdward Cree NETIF_MSG_TX_ERR | NETIF_MSG_HW; 3908135eecSEdward Cree return 0; 4008135eecSEdward Cree } 4108135eecSEdward Cree 4269bb5fa7SEdward Cree static int efx_ef100_rep_open(struct net_device *net_dev) 4369bb5fa7SEdward Cree { 4469bb5fa7SEdward Cree struct efx_rep *efv = netdev_priv(net_dev); 4569bb5fa7SEdward Cree 46*b48b89f9SJakub Kicinski netif_napi_add(net_dev, &efv->napi, efx_ef100_rep_poll); 4769bb5fa7SEdward Cree napi_enable(&efv->napi); 4869bb5fa7SEdward Cree return 0; 4969bb5fa7SEdward Cree } 5069bb5fa7SEdward Cree 5169bb5fa7SEdward Cree static int efx_ef100_rep_close(struct net_device *net_dev) 5269bb5fa7SEdward Cree { 5369bb5fa7SEdward Cree struct efx_rep *efv = netdev_priv(net_dev); 5469bb5fa7SEdward Cree 5569bb5fa7SEdward Cree napi_disable(&efv->napi); 5669bb5fa7SEdward Cree netif_napi_del(&efv->napi); 5769bb5fa7SEdward Cree return 0; 5869bb5fa7SEdward Cree } 5969bb5fa7SEdward Cree 60f72c38faSEdward Cree static netdev_tx_t efx_ef100_rep_xmit(struct sk_buff *skb, 61f72c38faSEdward Cree struct net_device *dev) 62f72c38faSEdward Cree { 63f72c38faSEdward Cree struct efx_rep *efv = netdev_priv(dev); 64f72c38faSEdward Cree struct efx_nic *efx = efv->parent; 65f72c38faSEdward Cree netdev_tx_t rc; 66f72c38faSEdward Cree 67f72c38faSEdward Cree /* __ef100_hard_start_xmit() will always return success even in the 68f72c38faSEdward Cree * case of TX drops, where it will increment efx's tx_dropped. The 69f72c38faSEdward Cree * efv stats really only count attempted TX, not success/failure. 70f72c38faSEdward Cree */ 71f72c38faSEdward Cree atomic64_inc(&efv->stats.tx_packets); 72f72c38faSEdward Cree atomic64_add(skb->len, &efv->stats.tx_bytes); 73f72c38faSEdward Cree netif_tx_lock(efx->net_dev); 74f72c38faSEdward Cree rc = __ef100_hard_start_xmit(skb, efx, dev, efv); 75f72c38faSEdward Cree netif_tx_unlock(efx->net_dev); 76f72c38faSEdward Cree return rc; 77f72c38faSEdward Cree } 78f72c38faSEdward Cree 79e1479556SEdward Cree static int efx_ef100_rep_get_port_parent_id(struct net_device *dev, 80e1479556SEdward Cree struct netdev_phys_item_id *ppid) 81e1479556SEdward Cree { 82e1479556SEdward Cree struct efx_rep *efv = netdev_priv(dev); 83e1479556SEdward Cree struct efx_nic *efx = efv->parent; 84e1479556SEdward Cree struct ef100_nic_data *nic_data; 85e1479556SEdward Cree 86e1479556SEdward Cree nic_data = efx->nic_data; 87e1479556SEdward Cree /* nic_data->port_id is a u8[] */ 88e1479556SEdward Cree ppid->id_len = sizeof(nic_data->port_id); 89e1479556SEdward Cree memcpy(ppid->id, nic_data->port_id, sizeof(nic_data->port_id)); 90e1479556SEdward Cree return 0; 91e1479556SEdward Cree } 92e1479556SEdward Cree 93e1479556SEdward Cree static int efx_ef100_rep_get_phys_port_name(struct net_device *dev, 94e1479556SEdward Cree char *buf, size_t len) 95e1479556SEdward Cree { 96e1479556SEdward Cree struct efx_rep *efv = netdev_priv(dev); 97e1479556SEdward Cree struct efx_nic *efx = efv->parent; 98e1479556SEdward Cree struct ef100_nic_data *nic_data; 99e1479556SEdward Cree int ret; 100e1479556SEdward Cree 101e1479556SEdward Cree nic_data = efx->nic_data; 102e1479556SEdward Cree ret = snprintf(buf, len, "p%upf%uvf%u", efx->port_num, 103e1479556SEdward Cree nic_data->pf_index, efv->idx); 104e1479556SEdward Cree if (ret >= len) 105e1479556SEdward Cree return -EOPNOTSUPP; 106e1479556SEdward Cree 107e1479556SEdward Cree return 0; 108e1479556SEdward Cree } 109e1479556SEdward Cree 1109dc0cad2SEdward Cree static int efx_ef100_rep_setup_tc(struct net_device *net_dev, 1119dc0cad2SEdward Cree enum tc_setup_type type, void *type_data) 1129dc0cad2SEdward Cree { 1139dc0cad2SEdward Cree struct efx_rep *efv = netdev_priv(net_dev); 1149dc0cad2SEdward Cree struct efx_nic *efx = efv->parent; 1159dc0cad2SEdward Cree 1169dc0cad2SEdward Cree if (type == TC_SETUP_CLSFLOWER) 1179dc0cad2SEdward Cree return efx_tc_flower(efx, net_dev, type_data, efv); 1189dc0cad2SEdward Cree if (type == TC_SETUP_BLOCK) 1199dc0cad2SEdward Cree return efx_tc_setup_block(net_dev, efx, type_data, efv); 1209dc0cad2SEdward Cree 1219dc0cad2SEdward Cree return -EOPNOTSUPP; 1229dc0cad2SEdward Cree } 1239dc0cad2SEdward Cree 124a95115c4SEdward Cree static void efx_ef100_rep_get_stats64(struct net_device *dev, 125a95115c4SEdward Cree struct rtnl_link_stats64 *stats) 126a95115c4SEdward Cree { 127a95115c4SEdward Cree struct efx_rep *efv = netdev_priv(dev); 128a95115c4SEdward Cree 129a95115c4SEdward Cree stats->rx_packets = atomic64_read(&efv->stats.rx_packets); 130a95115c4SEdward Cree stats->tx_packets = atomic64_read(&efv->stats.tx_packets); 131a95115c4SEdward Cree stats->rx_bytes = atomic64_read(&efv->stats.rx_bytes); 132a95115c4SEdward Cree stats->tx_bytes = atomic64_read(&efv->stats.tx_bytes); 133a95115c4SEdward Cree stats->rx_dropped = atomic64_read(&efv->stats.rx_dropped); 134a95115c4SEdward Cree stats->tx_errors = atomic64_read(&efv->stats.tx_errors); 135a95115c4SEdward Cree } 136a95115c4SEdward Cree 137f54a28a2SEdward Cree const struct net_device_ops efx_ef100_rep_netdev_ops = { 13869bb5fa7SEdward Cree .ndo_open = efx_ef100_rep_open, 13969bb5fa7SEdward Cree .ndo_stop = efx_ef100_rep_close, 140f72c38faSEdward Cree .ndo_start_xmit = efx_ef100_rep_xmit, 141e1479556SEdward Cree .ndo_get_port_parent_id = efx_ef100_rep_get_port_parent_id, 142e1479556SEdward Cree .ndo_get_phys_port_name = efx_ef100_rep_get_phys_port_name, 143a95115c4SEdward Cree .ndo_get_stats64 = efx_ef100_rep_get_stats64, 1449dc0cad2SEdward Cree .ndo_setup_tc = efx_ef100_rep_setup_tc, 14508135eecSEdward Cree }; 14608135eecSEdward Cree 1475687eb34SEdward Cree static void efx_ef100_rep_get_drvinfo(struct net_device *dev, 1485687eb34SEdward Cree struct ethtool_drvinfo *drvinfo) 1495687eb34SEdward Cree { 1505687eb34SEdward Cree strscpy(drvinfo->driver, EFX_EF100_REP_DRIVER, sizeof(drvinfo->driver)); 1515687eb34SEdward Cree } 1525687eb34SEdward Cree 1535687eb34SEdward Cree static u32 efx_ef100_rep_ethtool_get_msglevel(struct net_device *net_dev) 1545687eb34SEdward Cree { 1555687eb34SEdward Cree struct efx_rep *efv = netdev_priv(net_dev); 1565687eb34SEdward Cree 1575687eb34SEdward Cree return efv->msg_enable; 1585687eb34SEdward Cree } 1595687eb34SEdward Cree 1605687eb34SEdward Cree static void efx_ef100_rep_ethtool_set_msglevel(struct net_device *net_dev, 1615687eb34SEdward Cree u32 msg_enable) 1625687eb34SEdward Cree { 1635687eb34SEdward Cree struct efx_rep *efv = netdev_priv(net_dev); 1645687eb34SEdward Cree 1655687eb34SEdward Cree efv->msg_enable = msg_enable; 1665687eb34SEdward Cree } 1675687eb34SEdward Cree 1687267aa6dSEdward Cree static void efx_ef100_rep_ethtool_get_ringparam(struct net_device *net_dev, 1697267aa6dSEdward Cree struct ethtool_ringparam *ring, 1707267aa6dSEdward Cree struct kernel_ethtool_ringparam *kring, 1717267aa6dSEdward Cree struct netlink_ext_ack *ext_ack) 1727267aa6dSEdward Cree { 1737267aa6dSEdward Cree struct efx_rep *efv = netdev_priv(net_dev); 1747267aa6dSEdward Cree 1757267aa6dSEdward Cree ring->rx_max_pending = U32_MAX; 1767267aa6dSEdward Cree ring->rx_pending = efv->rx_pring_size; 1777267aa6dSEdward Cree } 1787267aa6dSEdward Cree 1797267aa6dSEdward Cree static int efx_ef100_rep_ethtool_set_ringparam(struct net_device *net_dev, 1807267aa6dSEdward Cree struct ethtool_ringparam *ring, 1817267aa6dSEdward Cree struct kernel_ethtool_ringparam *kring, 1827267aa6dSEdward Cree struct netlink_ext_ack *ext_ack) 1837267aa6dSEdward Cree { 1847267aa6dSEdward Cree struct efx_rep *efv = netdev_priv(net_dev); 1857267aa6dSEdward Cree 1867267aa6dSEdward Cree if (ring->rx_mini_pending || ring->rx_jumbo_pending || ring->tx_pending) 1877267aa6dSEdward Cree return -EINVAL; 1887267aa6dSEdward Cree 1897267aa6dSEdward Cree efv->rx_pring_size = ring->rx_pending; 1907267aa6dSEdward Cree return 0; 1917267aa6dSEdward Cree } 1927267aa6dSEdward Cree 19308135eecSEdward Cree static const struct ethtool_ops efx_ef100_rep_ethtool_ops = { 1945687eb34SEdward Cree .get_drvinfo = efx_ef100_rep_get_drvinfo, 1955687eb34SEdward Cree .get_msglevel = efx_ef100_rep_ethtool_get_msglevel, 1965687eb34SEdward Cree .set_msglevel = efx_ef100_rep_ethtool_set_msglevel, 1977267aa6dSEdward Cree .get_ringparam = efx_ef100_rep_ethtool_get_ringparam, 1987267aa6dSEdward Cree .set_ringparam = efx_ef100_rep_ethtool_set_ringparam, 19908135eecSEdward Cree }; 20008135eecSEdward Cree 20108135eecSEdward Cree static struct efx_rep *efx_ef100_rep_create_netdev(struct efx_nic *efx, 20208135eecSEdward Cree unsigned int i) 20308135eecSEdward Cree { 20408135eecSEdward Cree struct net_device *net_dev; 20508135eecSEdward Cree struct efx_rep *efv; 20608135eecSEdward Cree int rc; 20708135eecSEdward Cree 20808135eecSEdward Cree net_dev = alloc_etherdev_mq(sizeof(*efv), 1); 20908135eecSEdward Cree if (!net_dev) 21008135eecSEdward Cree return ERR_PTR(-ENOMEM); 21108135eecSEdward Cree 21208135eecSEdward Cree efv = netdev_priv(net_dev); 213e1479556SEdward Cree rc = efx_ef100_rep_init_struct(efx, efv, i); 21408135eecSEdward Cree if (rc) 21508135eecSEdward Cree goto fail1; 21608135eecSEdward Cree efv->net_dev = net_dev; 21708135eecSEdward Cree rtnl_lock(); 21808135eecSEdward Cree spin_lock_bh(&efx->vf_reps_lock); 21908135eecSEdward Cree list_add_tail(&efv->list, &efx->vf_reps); 22008135eecSEdward Cree spin_unlock_bh(&efx->vf_reps_lock); 22184e7fc25SEdward Cree if (netif_running(efx->net_dev) && efx->state == STATE_NET_UP) { 22284e7fc25SEdward Cree netif_device_attach(net_dev); 22384e7fc25SEdward Cree netif_carrier_on(net_dev); 22484e7fc25SEdward Cree } else { 22508135eecSEdward Cree netif_carrier_off(net_dev); 22608135eecSEdward Cree netif_tx_stop_all_queues(net_dev); 22784e7fc25SEdward Cree } 22808135eecSEdward Cree rtnl_unlock(); 22908135eecSEdward Cree 23008135eecSEdward Cree net_dev->netdev_ops = &efx_ef100_rep_netdev_ops; 23108135eecSEdward Cree net_dev->ethtool_ops = &efx_ef100_rep_ethtool_ops; 23208135eecSEdward Cree net_dev->min_mtu = EFX_MIN_MTU; 23308135eecSEdward Cree net_dev->max_mtu = EFX_MAX_MTU; 234f72c38faSEdward Cree net_dev->features |= NETIF_F_LLTX; 235f72c38faSEdward Cree net_dev->hw_features |= NETIF_F_LLTX; 23608135eecSEdward Cree return efv; 23708135eecSEdward Cree fail1: 23808135eecSEdward Cree free_netdev(net_dev); 23908135eecSEdward Cree return ERR_PTR(rc); 24008135eecSEdward Cree } 24108135eecSEdward Cree 242da56552dSEdward Cree static int efx_ef100_configure_rep(struct efx_rep *efv) 243da56552dSEdward Cree { 244da56552dSEdward Cree struct efx_nic *efx = efv->parent; 245da56552dSEdward Cree u32 selector; 246da56552dSEdward Cree int rc; 247da56552dSEdward Cree 2489fe00c80SEdward Cree efv->rx_pring_size = EFX_REP_DEFAULT_PSEUDO_RING_SIZE; 249da56552dSEdward Cree /* Construct mport selector for corresponding VF */ 250da56552dSEdward Cree efx_mae_mport_vf(efx, efv->idx, &selector); 251da56552dSEdward Cree /* Look up actual mport ID */ 252da56552dSEdward Cree rc = efx_mae_lookup_mport(efx, selector, &efv->mport); 253da56552dSEdward Cree if (rc) 254da56552dSEdward Cree return rc; 255da56552dSEdward Cree pci_dbg(efx->pci_dev, "VF %u has mport ID %#x\n", efv->idx, efv->mport); 256da56552dSEdward Cree /* mport label should fit in 16 bits */ 257da56552dSEdward Cree WARN_ON(efv->mport >> 16); 258da56552dSEdward Cree 25967ab160eSEdward Cree return efx_tc_configure_default_rule_rep(efv); 26067ab160eSEdward Cree } 26167ab160eSEdward Cree 26267ab160eSEdward Cree static void efx_ef100_deconfigure_rep(struct efx_rep *efv) 26367ab160eSEdward Cree { 26467ab160eSEdward Cree struct efx_nic *efx = efv->parent; 26567ab160eSEdward Cree 26667ab160eSEdward Cree efx_tc_deconfigure_default_rule(efx, &efv->dflt); 267da56552dSEdward Cree } 268da56552dSEdward Cree 26908135eecSEdward Cree static void efx_ef100_rep_destroy_netdev(struct efx_rep *efv) 27008135eecSEdward Cree { 27108135eecSEdward Cree struct efx_nic *efx = efv->parent; 27208135eecSEdward Cree 27384e7fc25SEdward Cree rtnl_lock(); 27408135eecSEdward Cree spin_lock_bh(&efx->vf_reps_lock); 27508135eecSEdward Cree list_del(&efv->list); 27608135eecSEdward Cree spin_unlock_bh(&efx->vf_reps_lock); 27784e7fc25SEdward Cree rtnl_unlock(); 278f50e8fcdSEdward Cree synchronize_rcu(); 27908135eecSEdward Cree free_netdev(efv->net_dev); 28008135eecSEdward Cree } 28108135eecSEdward Cree 28208135eecSEdward Cree int efx_ef100_vfrep_create(struct efx_nic *efx, unsigned int i) 28308135eecSEdward Cree { 28408135eecSEdward Cree struct efx_rep *efv; 28508135eecSEdward Cree int rc; 28608135eecSEdward Cree 28708135eecSEdward Cree efv = efx_ef100_rep_create_netdev(efx, i); 28808135eecSEdward Cree if (IS_ERR(efv)) { 28908135eecSEdward Cree rc = PTR_ERR(efv); 29008135eecSEdward Cree pci_err(efx->pci_dev, 29108135eecSEdward Cree "Failed to create representor for VF %d, rc %d\n", i, 29208135eecSEdward Cree rc); 29308135eecSEdward Cree return rc; 29408135eecSEdward Cree } 295da56552dSEdward Cree rc = efx_ef100_configure_rep(efv); 296da56552dSEdward Cree if (rc) { 297da56552dSEdward Cree pci_err(efx->pci_dev, 298da56552dSEdward Cree "Failed to configure representor for VF %d, rc %d\n", 299da56552dSEdward Cree i, rc); 30067ab160eSEdward Cree goto fail1; 301da56552dSEdward Cree } 30208135eecSEdward Cree rc = register_netdev(efv->net_dev); 30308135eecSEdward Cree if (rc) { 30408135eecSEdward Cree pci_err(efx->pci_dev, 30508135eecSEdward Cree "Failed to register representor for VF %d, rc %d\n", 30608135eecSEdward Cree i, rc); 30767ab160eSEdward Cree goto fail2; 30808135eecSEdward Cree } 30908135eecSEdward Cree pci_dbg(efx->pci_dev, "Representor for VF %d is %s\n", i, 31008135eecSEdward Cree efv->net_dev->name); 31108135eecSEdward Cree return 0; 31267ab160eSEdward Cree fail2: 31367ab160eSEdward Cree efx_ef100_deconfigure_rep(efv); 31467ab160eSEdward Cree fail1: 31508135eecSEdward Cree efx_ef100_rep_destroy_netdev(efv); 31608135eecSEdward Cree return rc; 31708135eecSEdward Cree } 31808135eecSEdward Cree 31908135eecSEdward Cree void efx_ef100_vfrep_destroy(struct efx_nic *efx, struct efx_rep *efv) 32008135eecSEdward Cree { 32108135eecSEdward Cree struct net_device *rep_dev; 32208135eecSEdward Cree 32308135eecSEdward Cree rep_dev = efv->net_dev; 32408135eecSEdward Cree if (!rep_dev) 32508135eecSEdward Cree return; 32608135eecSEdward Cree netif_dbg(efx, drv, rep_dev, "Removing VF representor\n"); 32708135eecSEdward Cree unregister_netdev(rep_dev); 32867ab160eSEdward Cree efx_ef100_deconfigure_rep(efv); 32908135eecSEdward Cree efx_ef100_rep_destroy_netdev(efv); 33008135eecSEdward Cree } 33108135eecSEdward Cree 33208135eecSEdward Cree void efx_ef100_fini_vfreps(struct efx_nic *efx) 33308135eecSEdward Cree { 33408135eecSEdward Cree struct ef100_nic_data *nic_data = efx->nic_data; 33508135eecSEdward Cree struct efx_rep *efv, *next; 33608135eecSEdward Cree 33708135eecSEdward Cree if (!nic_data->grp_mae) 33808135eecSEdward Cree return; 33908135eecSEdward Cree 34008135eecSEdward Cree list_for_each_entry_safe(efv, next, &efx->vf_reps, list) 34108135eecSEdward Cree efx_ef100_vfrep_destroy(efx, efv); 34208135eecSEdward Cree } 34369bb5fa7SEdward Cree 34469bb5fa7SEdward Cree static int efx_ef100_rep_poll(struct napi_struct *napi, int weight) 34569bb5fa7SEdward Cree { 34669bb5fa7SEdward Cree struct efx_rep *efv = container_of(napi, struct efx_rep, napi); 34769bb5fa7SEdward Cree unsigned int read_index; 34869bb5fa7SEdward Cree struct list_head head; 34969bb5fa7SEdward Cree struct sk_buff *skb; 35069bb5fa7SEdward Cree bool need_resched; 35169bb5fa7SEdward Cree int spent = 0; 35269bb5fa7SEdward Cree 35369bb5fa7SEdward Cree INIT_LIST_HEAD(&head); 35469bb5fa7SEdward Cree /* Grab up to 'weight' pending SKBs */ 35569bb5fa7SEdward Cree spin_lock_bh(&efv->rx_lock); 35669bb5fa7SEdward Cree read_index = efv->write_index; 35769bb5fa7SEdward Cree while (spent < weight && !list_empty(&efv->rx_list)) { 35869bb5fa7SEdward Cree skb = list_first_entry(&efv->rx_list, struct sk_buff, list); 35969bb5fa7SEdward Cree list_del(&skb->list); 36069bb5fa7SEdward Cree list_add_tail(&skb->list, &head); 36169bb5fa7SEdward Cree spent++; 36269bb5fa7SEdward Cree } 36369bb5fa7SEdward Cree spin_unlock_bh(&efv->rx_lock); 36469bb5fa7SEdward Cree /* Receive them */ 36569bb5fa7SEdward Cree netif_receive_skb_list(&head); 36669bb5fa7SEdward Cree if (spent < weight) 36769bb5fa7SEdward Cree if (napi_complete_done(napi, spent)) { 36869bb5fa7SEdward Cree spin_lock_bh(&efv->rx_lock); 36969bb5fa7SEdward Cree efv->read_index = read_index; 37069bb5fa7SEdward Cree /* If write_index advanced while we were doing the 37169bb5fa7SEdward Cree * RX, then storing our read_index won't re-prime the 37269bb5fa7SEdward Cree * fake-interrupt. In that case, we need to schedule 37369bb5fa7SEdward Cree * NAPI again to consume the additional packet(s). 37469bb5fa7SEdward Cree */ 37569bb5fa7SEdward Cree need_resched = efv->write_index != read_index; 37669bb5fa7SEdward Cree spin_unlock_bh(&efv->rx_lock); 37769bb5fa7SEdward Cree if (need_resched) 37869bb5fa7SEdward Cree napi_schedule(&efv->napi); 37969bb5fa7SEdward Cree } 38069bb5fa7SEdward Cree return spent; 38169bb5fa7SEdward Cree } 3829fe00c80SEdward Cree 3839fe00c80SEdward Cree void efx_ef100_rep_rx_packet(struct efx_rep *efv, struct efx_rx_buffer *rx_buf) 3849fe00c80SEdward Cree { 3859fe00c80SEdward Cree u8 *eh = efx_rx_buf_va(rx_buf); 3869fe00c80SEdward Cree struct sk_buff *skb; 3879fe00c80SEdward Cree bool primed; 3889fe00c80SEdward Cree 3899fe00c80SEdward Cree /* Don't allow too many queued SKBs to build up, as they consume 3909fe00c80SEdward Cree * GFP_ATOMIC memory. If we overrun, just start dropping. 3919fe00c80SEdward Cree */ 3929fe00c80SEdward Cree if (efv->write_index - READ_ONCE(efv->read_index) > efv->rx_pring_size) { 3939fe00c80SEdward Cree atomic64_inc(&efv->stats.rx_dropped); 3949fe00c80SEdward Cree if (net_ratelimit()) 3959fe00c80SEdward Cree netif_dbg(efv->parent, rx_err, efv->net_dev, 3969fe00c80SEdward Cree "nodesc-dropped packet of length %u\n", 3979fe00c80SEdward Cree rx_buf->len); 3989fe00c80SEdward Cree return; 3999fe00c80SEdward Cree } 4009fe00c80SEdward Cree 4019fe00c80SEdward Cree skb = netdev_alloc_skb(efv->net_dev, rx_buf->len); 4029fe00c80SEdward Cree if (!skb) { 4039fe00c80SEdward Cree atomic64_inc(&efv->stats.rx_dropped); 4049fe00c80SEdward Cree if (net_ratelimit()) 4059fe00c80SEdward Cree netif_dbg(efv->parent, rx_err, efv->net_dev, 4069fe00c80SEdward Cree "noskb-dropped packet of length %u\n", 4079fe00c80SEdward Cree rx_buf->len); 4089fe00c80SEdward Cree return; 4099fe00c80SEdward Cree } 4109fe00c80SEdward Cree memcpy(skb->data, eh, rx_buf->len); 4119fe00c80SEdward Cree __skb_put(skb, rx_buf->len); 4129fe00c80SEdward Cree 4139fe00c80SEdward Cree skb_record_rx_queue(skb, 0); /* rep is single-queue */ 4149fe00c80SEdward Cree 4159fe00c80SEdward Cree /* Move past the ethernet header */ 4169fe00c80SEdward Cree skb->protocol = eth_type_trans(skb, efv->net_dev); 4179fe00c80SEdward Cree 4189fe00c80SEdward Cree skb_checksum_none_assert(skb); 4199fe00c80SEdward Cree 4209fe00c80SEdward Cree atomic64_inc(&efv->stats.rx_packets); 4219fe00c80SEdward Cree atomic64_add(rx_buf->len, &efv->stats.rx_bytes); 4229fe00c80SEdward Cree 4239fe00c80SEdward Cree /* Add it to the rx list */ 4249fe00c80SEdward Cree spin_lock_bh(&efv->rx_lock); 4259fe00c80SEdward Cree primed = efv->read_index == efv->write_index; 4269fe00c80SEdward Cree list_add_tail(&skb->list, &efv->rx_list); 4279fe00c80SEdward Cree efv->write_index++; 4289fe00c80SEdward Cree spin_unlock_bh(&efv->rx_lock); 4299fe00c80SEdward Cree /* Trigger rx work */ 4309fe00c80SEdward Cree if (primed) 4319fe00c80SEdward Cree napi_schedule(&efv->napi); 4329fe00c80SEdward Cree } 433f50e8fcdSEdward Cree 434f50e8fcdSEdward Cree struct efx_rep *efx_ef100_find_rep_by_mport(struct efx_nic *efx, u16 mport) 435f50e8fcdSEdward Cree { 436f50e8fcdSEdward Cree struct efx_rep *efv, *out = NULL; 437f50e8fcdSEdward Cree 438f50e8fcdSEdward Cree /* spinlock guards against list mutation while we're walking it; 439f50e8fcdSEdward Cree * but caller must also hold rcu_read_lock() to ensure the netdev 440f50e8fcdSEdward Cree * isn't freed after we drop the spinlock. 441f50e8fcdSEdward Cree */ 442f50e8fcdSEdward Cree spin_lock_bh(&efx->vf_reps_lock); 443f50e8fcdSEdward Cree list_for_each_entry(efv, &efx->vf_reps, list) 444f50e8fcdSEdward Cree if (efv->mport == mport) { 445f50e8fcdSEdward Cree out = efv; 446f50e8fcdSEdward Cree break; 447f50e8fcdSEdward Cree } 448f50e8fcdSEdward Cree spin_unlock_bh(&efx->vf_reps_lock); 449f50e8fcdSEdward Cree return out; 450f50e8fcdSEdward Cree } 451