dpaa_eth: add NETIF_F_RXHASH
authorMadalin Bucur <madalin.bucur@nxp.com>
Sun, 27 Aug 2017 13:13:41 +0000 (16:13 +0300)
committerDavid S. Miller <davem@davemloft.net>
Mon, 28 Aug 2017 23:41:00 +0000 (16:41 -0700)
Set the skb hash when then FMan Keygen hash result is available.

Signed-off-by: Madalin Bucur <madalin.bucur@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
drivers/net/ethernet/freescale/dpaa/dpaa_eth.h
drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c
drivers/net/ethernet/freescale/fman/fman_port.c
drivers/net/ethernet/freescale/fman/fman_port.h

index 6d89e74ded5cb1be40251d220cf058da58e346bd..73ca8d761e184d0040f1981b574d7f928774d260 100644 (file)
@@ -236,7 +236,7 @@ static int dpaa_netdev_init(struct net_device *net_dev,
        net_dev->max_mtu = dpaa_get_max_mtu();
 
        net_dev->hw_features |= (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
-                                NETIF_F_LLTX);
+                                NETIF_F_LLTX | NETIF_F_RXHASH);
 
        net_dev->hw_features |= NETIF_F_SG | NETIF_F_HIGHDMA;
        /* The kernels enables GSO automatically, if we declare NETIF_F_SG.
@@ -2237,12 +2237,13 @@ static enum qman_cb_dqrr_result rx_default_dqrr(struct qman_portal *portal,
        dma_addr_t addr = qm_fd_addr(fd);
        enum qm_fd_format fd_format;
        struct net_device *net_dev;
-       u32 fd_status;
+       u32 fd_status, hash_offset;
        struct dpaa_bp *dpaa_bp;
        struct dpaa_priv *priv;
        unsigned int skb_len;
        struct sk_buff *skb;
        int *count_ptr;
+       void *vaddr;
 
        fd_status = be32_to_cpu(fd->status);
        fd_format = qm_fd_get_format(fd);
@@ -2288,7 +2289,8 @@ static enum qman_cb_dqrr_result rx_default_dqrr(struct qman_portal *portal,
        dma_unmap_single(dpaa_bp->dev, addr, dpaa_bp->size, DMA_FROM_DEVICE);
 
        /* prefetch the first 64 bytes of the frame or the SGT start */
-       prefetch(phys_to_virt(addr) + qm_fd_get_offset(fd));
+       vaddr = phys_to_virt(addr);
+       prefetch(vaddr + qm_fd_get_offset(fd));
 
        fd_format = qm_fd_get_format(fd);
        /* The only FD types that we may receive are contig and S/G */
@@ -2309,6 +2311,18 @@ static enum qman_cb_dqrr_result rx_default_dqrr(struct qman_portal *portal,
 
        skb->protocol = eth_type_trans(skb, net_dev);
 
+       if (net_dev->features & NETIF_F_RXHASH && priv->keygen_in_use &&
+           !fman_port_get_hash_result_offset(priv->mac_dev->port[RX],
+                                             &hash_offset)) {
+               enum pkt_hash_types type;
+
+               /* if L4 exists, it was used in the hash generation */
+               type = be32_to_cpu(fd->status) & FM_FD_STAT_L4CV ?
+                       PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3;
+               skb_set_hash(skb, be32_to_cpu(*(u32 *)(vaddr + hash_offset)),
+                            type);
+       }
+
        skb_len = skb->len;
 
        if (unlikely(netif_receive_skb(skb) == NET_RX_DROP))
@@ -2774,6 +2788,9 @@ static int dpaa_eth_probe(struct platform_device *pdev)
        if (err)
                goto init_ports_failed;
 
+       /* Rx traffic distribution based on keygen hashing defaults to on */
+       priv->keygen_in_use = true;
+
        priv->percpu_priv = devm_alloc_percpu(dev, *priv->percpu_priv);
        if (!priv->percpu_priv) {
                dev_err(dev, "devm_alloc_percpu() failed\n");
index 496a12c50ada8de9f6ad694f39a530e8a10286c5..bd9422082f83c8cffd9e12116a155ac185a190f1 100644 (file)
@@ -159,6 +159,7 @@ struct dpaa_priv {
        struct list_head dpaa_fq_list;
 
        u8 num_tc;
+       bool keygen_in_use;
        u32 msg_enable; /* net_device message level */
 
        struct {
index 965f6520d58ade0ea1118ef1336e76928f5e2667..faea674094b96743168f1c8edc6e875d0467f59c 100644 (file)
@@ -402,6 +402,8 @@ static void dpaa_get_strings(struct net_device *net_dev, u32 stringset,
 static int dpaa_get_hash_opts(struct net_device *dev,
                              struct ethtool_rxnfc *cmd)
 {
+       struct dpaa_priv *priv = netdev_priv(dev);
+
        cmd->data = 0;
 
        switch (cmd->flow_type) {
@@ -409,7 +411,8 @@ static int dpaa_get_hash_opts(struct net_device *dev,
        case TCP_V6_FLOW:
        case UDP_V4_FLOW:
        case UDP_V6_FLOW:
-               cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
+               if (priv->keygen_in_use)
+                       cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
                /* Fall through */
        case IPV4_FLOW:
        case IPV6_FLOW:
@@ -421,7 +424,8 @@ static int dpaa_get_hash_opts(struct net_device *dev,
        case AH_V6_FLOW:
        case ESP_V4_FLOW:
        case ESP_V6_FLOW:
-               cmd->data |= RXH_IP_SRC | RXH_IP_DST;
+               if (priv->keygen_in_use)
+                       cmd->data |= RXH_IP_SRC | RXH_IP_DST;
                break;
        default:
                cmd->data = 0;
@@ -458,6 +462,7 @@ static void dpaa_set_hash(struct net_device *net_dev, bool enable)
        rxport = mac_dev->port[0];
 
        fman_port_use_kg_hash(rxport, enable);
+       priv->keygen_in_use = enable;
 }
 
 static int dpaa_set_hash_opts(struct net_device *dev,
index f571b3c37f2770408f83d614dfb42f8bbcafda67..1789b206be58396f3d1eca908d3f36289375ac9b 100644 (file)
@@ -1720,6 +1720,17 @@ u32 fman_port_get_qman_channel_id(struct fman_port *port)
 }
 EXPORT_SYMBOL(fman_port_get_qman_channel_id);
 
+int fman_port_get_hash_result_offset(struct fman_port *port, u32 *offset)
+{
+       if (port->buffer_offsets.hash_result_offset == ILLEGAL_BASE)
+               return -EINVAL;
+
+       *offset = port->buffer_offsets.hash_result_offset;
+
+       return 0;
+}
+EXPORT_SYMBOL(fman_port_get_hash_result_offset);
+
 static int fman_port_probe(struct platform_device *of_dev)
 {
        struct fman_port *port;
index 5a99611fa1dce0b38ca503863fe58c36b640d2fc..e86ca6a34e4e296051258df2b4d268bf4ade09a6 100644 (file)
@@ -151,6 +151,8 @@ int fman_port_enable(struct fman_port *port);
 
 u32 fman_port_get_qman_channel_id(struct fman_port *port);
 
+int fman_port_get_hash_result_offset(struct fman_port *port, u32 *offset);
+
 struct fman_port *fman_port_bind(struct device *dev);
 
 #endif /* __FMAN_PORT_H */