Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp2835589rwb; Mon, 5 Sep 2022 02:12:16 -0700 (PDT) X-Google-Smtp-Source: AA6agR6lFBDp/CUSTsyHIPEfe6IZE7Q2Rk1SEe/y9ZTSdglf4mTal98VsXPWTg5zxHuyVF+vm5hS X-Received: by 2002:a17:90a:4fc2:b0:1fb:3486:7b3d with SMTP id q60-20020a17090a4fc200b001fb34867b3dmr18769092pjh.49.1662369136706; Mon, 05 Sep 2022 02:12:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662369136; cv=none; d=google.com; s=arc-20160816; b=LOI9jvIr9WJdAdPWKxXiMox9/76kntzDps1gjETE1OE6l0J40osASoWnTybPAuqk95 I8xo636ihrVe2eyvNIEwWNKb964KxBNRBBvaeQDTVMwbd7Gc7ZVuJF8fAOe/OfK3ZD5f tyrvhwuhLXwuZiTO/1FUHyuYybJSVy++AK9TC4a0k5nxMJt+FEF8j8dOE9BuDRV4DMSz L2e1knwsDrJL1dd53+RUW6mGQCNN/e6cfEKaJ27YejdpdTN6B/0lNobHY4kN9qIGNa8J 6zW5+ozJ85IpulehrfN0q4ll6tcFMGU/Kqe8a1vfmt0h1WjFVEFoLQ6xfX6kEBo1h4ZH Ktyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=qj5yGt2zTwJuwNg3jeo9HoOfktcfo88Kr0LpgSRTSNk=; b=c9J0jNsH7g5g9lYEKl5hPV1JwJZJiIFSqDw8V20GZTEPVCvzcgE0cv+63R9pofS7mh uUTNNKk4JMPk6wQA+W1phz7sz0MhkSHSeurMRiprHQ0GndGdC/E/7SIJbrNnKVirrBLU uapuzWRfQQQIkV2qgLOIsalIauAtD5Oa6ZEWSLoTidDSy0w8H3GUZPcWB9t5N7GGmYv2 fyQmMzyY79VKOdVaBCrMuCBXYqosowCGo43TbChKNZDqrksxrDlbVqExpLj/Y0WUyker 76yjF/aMI+I+UGi/VwhMc5H7AdJfNu5zuGQjofqHV5JGnqfyCSAiGhVjMJpUVvxbO66C vQ/w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f10-20020a170902860a00b00174cd29888bsi9230647plo.235.2022.09.05.02.12.05; Mon, 05 Sep 2022 02:12:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237327AbiIEISs (ORCPT + 99 others); Mon, 5 Sep 2022 04:18:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236960AbiIEISU (ORCPT ); Mon, 5 Sep 2022 04:18:20 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1073F31DDC; Mon, 5 Sep 2022 01:18:17 -0700 (PDT) Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MLhBr2f7RzmV7W; Mon, 5 Sep 2022 16:14:44 +0800 (CST) Received: from kwepemm600016.china.huawei.com (7.193.23.20) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 5 Sep 2022 16:18:16 +0800 Received: from localhost.localdomain (10.69.192.56) by kwepemm600016.china.huawei.com (7.193.23.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 5 Sep 2022 16:18:13 +0800 From: Guangbin Huang To: , CC: , , , , , , Subject: [PATCH net-next 2/5] net: hns3: support ndo_select_queue() Date: Mon, 5 Sep 2022 16:15:36 +0800 Message-ID: <20220905081539.62131-3-huangguangbin2@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220905081539.62131-1-huangguangbin2@huawei.com> References: <20220905081539.62131-1-huangguangbin2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600016.china.huawei.com (7.193.23.20) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To support tx packets to select queue according to its dscp field after setting dscp and tc map relationship, this patch implements ndo_select_queue() to set skb->priority according to the user's setting dscp and priority map relationship. Signed-off-by: Guangbin Huang --- .../net/ethernet/hisilicon/hns3/hns3_enet.c | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c index 481a300819ad..82f83e3f8162 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c @@ -2963,6 +2963,51 @@ static int hns3_nic_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac) return h->ae_algo->ops->set_vf_mac(h, vf_id, mac); } +#define HNS3_INVALID_DSCP 0xff +#define HNS3_DSCP_SHIFT 2 + +static u8 hns3_get_skb_dscp(struct sk_buff *skb) +{ + __be16 protocol = skb->protocol; + u8 dscp = HNS3_INVALID_DSCP; + + if (protocol == htons(ETH_P_8021Q)) + protocol = vlan_get_protocol(skb); + + if (protocol == htons(ETH_P_IP)) + dscp = ipv4_get_dsfield(ip_hdr(skb)) >> HNS3_DSCP_SHIFT; + else if (protocol == htons(ETH_P_IPV6)) + dscp = ipv6_get_dsfield(ipv6_hdr(skb)) >> HNS3_DSCP_SHIFT; + + return dscp; +} + +static u16 hns3_nic_select_queue(struct net_device *netdev, + struct sk_buff *skb, + struct net_device *sb_dev) +{ + struct hnae3_handle *h = hns3_get_handle(netdev); + u8 dscp, priority; + int ret; + + if (h->kinfo.tc_map_mode != HNAE3_TC_MAP_MODE_DSCP || + !h->ae_algo->ops->get_dscp_prio) + goto out; + + dscp = hns3_get_skb_dscp(skb); + if (unlikely(dscp == HNS3_INVALID_DSCP)) + goto out; + + ret = h->ae_algo->ops->get_dscp_prio(h, dscp, NULL, &priority); + if (ret) + goto out; + + skb->priority = priority; + +out: + return netdev_pick_tx(netdev, skb, sb_dev); +} + static const struct net_device_ops hns3_nic_netdev_ops = { .ndo_open = hns3_nic_net_open, .ndo_stop = hns3_nic_net_stop, @@ -2988,6 +3033,7 @@ static const struct net_device_ops hns3_nic_netdev_ops = { .ndo_set_vf_link_state = hns3_nic_set_vf_link_state, .ndo_set_vf_rate = hns3_nic_set_vf_rate, .ndo_set_vf_mac = hns3_nic_set_vf_mac, + .ndo_select_queue = hns3_nic_select_queue, }; bool hns3_is_phys_func(struct pci_dev *pdev) -- 2.33.0