Skip to content

Commit f4b2a42

Browse files
committed
Merge branch 'hns3-ethernet-driver'
Salil Mehta says: ==================== Hisilicon Network Subsystem 3 Ethernet Driver This patch-set contains the support of the HNS3 (Hisilicon Network Subsystem 3) Ethernet driver for hip08 family of SoCs and future upcoming SoCs. Hisilicon's new hip08 SoCs have integrated ethernet based on PCI Express and hence there was a need of new driver over the previous HNS driver which is already part of the Linux mainline. This new driver is NOT backward compatible with HNS. This current driver is meant to control the Physical Function and there would soon be a support of a separate driver for Virtual Function once this base PF driver has been accepted. Also, this driver is the ongoing development work and HNS3 Ethernet driver would be incrementally enhanced with more new features. High Level Architecture: [ Ethtool ] ^ | | | [Ethernet Client] [ODP/UIO Client] . . . [ RoCE Client ] | | [ HNAE Device ] | | | --------------------------------------------- | | | [ HNAE3 Framework (Register/unregister) ] | | | --------------------------------------------- | | | [ HCLGE Layer] | ________________|_________________ | | | | | [ MDIO ] [ Scheduler/Shaper ] [ Debugfs* ] | | | | | |________________|_________________| | | | [ IMP command Interface ] | --------------------------------------------- | HIP08 H A R D W A R E * Current patch-set broadly adds the support of the following PF functionality: 1. Basic Rx and Tx functionality 2. TSO support 3. Ethtool support 4. * Debugfs support -> this patch for now has been taken off. 5. HNAE framework and hardware compatability layer 6. Scheduler and Shaper support in transmit function 7. MDIO support Change Log: V5->V6: Addressed below comments: * Andrew Lunn: Comments on MDIO and ethtool link mode * Leon Romanvosky: Some comments on HNAE layer tidy-up * Internal comments on redundant code removal, fixing error types etc. V4->V5: Addressed below concerns: * Florian Fanelli: Miscellaneous comments on ethtool & enet layer * Stephen Hemminger: comment of Netdev stats in ethool layer * Leon Romanvosky: Comments on Driver Version String, naming & Kconfig * Rochard Cochran: Redundant function prototype V3->V4: Addressed below comments: * Andrew Lunn: Various comments on MDIO, ethtool, ENET driver etc, * Stephen Hemminger: change access and updation to 64 but statistics * Bo You: some spelling mistakes and checkpatch.pl errors. V2->V3: Addressed comments * Yuval Mintz: Removal of redundant userprio-to-tc code * Stephen Hemminger: Ethtool & interuupt enable * Andrew Lunn: On C45/C22 PHy support, HNAE, ethtool * Florian Fainelli: C45/C22 and phy_connect/attach * Intel kbuild errors V1->V2: Addressed some comments by kbuild, Yuval MIntz, Andrew Lunn & Florian Fainelli in the following patches: * Add support of HNS3 Ethernet Driver for hip08 SoC * Add MDIO support to HNS3 Ethernet driver for hip08 SoC * Add support of debugfs interface to HNS3 driver ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 5477f7f + 15e8e5f commit f4b2a42

File tree

18 files changed

+11953
-0
lines changed

18 files changed

+11953
-0
lines changed

MAINTAINERS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6148,6 +6148,14 @@ S: Maintained
61486148
F: drivers/net/ethernet/hisilicon/
61496149
F: Documentation/devicetree/bindings/net/hisilicon*.txt
61506150

6151+
HISILICON NETWORK SUBSYSTEM 3 DRIVER (HNS3)
6152+
M: Yisen Zhuang <yisen.zhuang@huawei.com>
6153+
M: Salil Mehta <salil.mehta@huawei.com>
6154+
L: netdev@vger.kernel.org
6155+
W: http://www.hisilicon.com
6156+
S: Maintained
6157+
F: drivers/net/ethernet/hisilicon/hns3/
6158+
61516159
HISILICON ROCE DRIVER
61526160
M: Lijun Ou <oulijun@huawei.com>
61536161
M: Wei Hu(Xavier) <xavier.huwei@huawei.com>

drivers/net/ethernet/hisilicon/Kconfig

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,31 @@ config HNS_ENET
7676
This selects the general ethernet driver for HNS. This module make
7777
use of any HNS AE driver, such as HNS_DSAF
7878

79+
config HNS3
80+
tristate "Hisilicon Network Subsystem Support HNS3 (Framework)"
81+
depends on PCI
82+
---help---
83+
This selects the framework support for Hisilicon Network Subsystem 3.
84+
This layer facilitates clients like ENET, RoCE and user-space ethernet
85+
drivers(like ODP)to register with HNAE devices and their associated
86+
operations.
87+
88+
config HNS3_HCLGE
89+
tristate "Hisilicon HNS3 HCLGE Acceleration Engine & Compatibility Layer Support"
90+
depends on PCI_MSI
91+
depends on HNS3
92+
---help---
93+
This selects the HNS3_HCLGE network acceleration engine & its hardware
94+
compatibility layer. The engine would be used in Hisilicon hip08 family of
95+
SoCs and further upcoming SoCs.
96+
97+
config HNS3_ENET
98+
tristate "Hisilicon HNS3 Ethernet Device Support"
99+
depends on 64BIT && PCI
100+
depends on HNS3 && HNS3_HCLGE
101+
---help---
102+
This selects the Ethernet Driver for Hisilicon Network Subsystem 3 for hip08
103+
family of SoCs. This module depends upon HNAE3 driver to access the HNAE3
104+
devices and their associated operations.
105+
79106
endif # NET_VENDOR_HISILICON

drivers/net/ethernet/hisilicon/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ obj-$(CONFIG_HIX5HD2_GMAC) += hix5hd2_gmac.o
66
obj-$(CONFIG_HIP04_ETH) += hip04_eth.o
77
obj-$(CONFIG_HNS_MDIO) += hns_mdio.o
88
obj-$(CONFIG_HNS) += hns/
9+
obj-$(CONFIG_HNS3) += hns3/
910
obj-$(CONFIG_HISI_FEMAC) += hisi_femac.o
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#
2+
# Makefile for the HISILICON network device drivers.
3+
#
4+
5+
obj-$(CONFIG_HNS3) += hns3pf/
6+
7+
obj-$(CONFIG_HNS3) += hnae3.o
Lines changed: 300 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,300 @@
1+
/*
2+
* Copyright (c) 2016-2017 Hisilicon Limited.
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*/
9+
10+
#include <linux/list.h>
11+
#include <linux/slab.h>
12+
#include <linux/spinlock.h>
13+
14+
#include "hnae3.h"
15+
16+
static LIST_HEAD(hnae3_ae_algo_list);
17+
static LIST_HEAD(hnae3_client_list);
18+
static LIST_HEAD(hnae3_ae_dev_list);
19+
20+
/* we are keeping things simple and using single lock for all the
21+
* list. This is a non-critical code so other updations, if happen
22+
* in parallel, can wait.
23+
*/
24+
static DEFINE_MUTEX(hnae3_common_lock);
25+
26+
static bool hnae3_client_match(enum hnae3_client_type client_type,
27+
enum hnae3_dev_type dev_type)
28+
{
29+
if ((dev_type == HNAE3_DEV_KNIC) && (client_type == HNAE3_CLIENT_KNIC ||
30+
client_type == HNAE3_CLIENT_ROCE))
31+
return true;
32+
33+
if (dev_type == HNAE3_DEV_UNIC && client_type == HNAE3_CLIENT_UNIC)
34+
return true;
35+
36+
return false;
37+
}
38+
39+
static int hnae3_match_n_instantiate(struct hnae3_client *client,
40+
struct hnae3_ae_dev *ae_dev,
41+
bool is_reg, bool *matched)
42+
{
43+
int ret;
44+
45+
*matched = false;
46+
47+
/* check if this client matches the type of ae_dev */
48+
if (!(hnae3_client_match(client->type, ae_dev->dev_type) &&
49+
hnae_get_bit(ae_dev->flag, HNAE3_DEV_INITED_B))) {
50+
return 0;
51+
}
52+
/* there is a match of client and dev */
53+
*matched = true;
54+
55+
/* now, (un-)instantiate client by calling lower layer */
56+
if (is_reg) {
57+
ret = ae_dev->ops->init_client_instance(client, ae_dev);
58+
if (ret)
59+
dev_err(&ae_dev->pdev->dev,
60+
"fail to instantiate client\n");
61+
return ret;
62+
}
63+
64+
ae_dev->ops->uninit_client_instance(client, ae_dev);
65+
return 0;
66+
}
67+
68+
int hnae3_register_client(struct hnae3_client *client)
69+
{
70+
struct hnae3_client *client_tmp;
71+
struct hnae3_ae_dev *ae_dev;
72+
bool matched;
73+
int ret = 0;
74+
75+
mutex_lock(&hnae3_common_lock);
76+
/* one system should only have one client for every type */
77+
list_for_each_entry(client_tmp, &hnae3_client_list, node) {
78+
if (client_tmp->type == client->type)
79+
goto exit;
80+
}
81+
82+
list_add_tail(&client->node, &hnae3_client_list);
83+
84+
/* initialize the client on every matched port */
85+
list_for_each_entry(ae_dev, &hnae3_ae_dev_list, node) {
86+
/* if the client could not be initialized on current port, for
87+
* any error reasons, move on to next available port
88+
*/
89+
ret = hnae3_match_n_instantiate(client, ae_dev, true, &matched);
90+
if (ret)
91+
dev_err(&ae_dev->pdev->dev,
92+
"match and instantiation failed for port\n");
93+
}
94+
95+
exit:
96+
mutex_unlock(&hnae3_common_lock);
97+
98+
return ret;
99+
}
100+
EXPORT_SYMBOL(hnae3_register_client);
101+
102+
void hnae3_unregister_client(struct hnae3_client *client)
103+
{
104+
struct hnae3_ae_dev *ae_dev;
105+
bool matched;
106+
107+
mutex_lock(&hnae3_common_lock);
108+
/* un-initialize the client on every matched port */
109+
list_for_each_entry(ae_dev, &hnae3_ae_dev_list, node) {
110+
hnae3_match_n_instantiate(client, ae_dev, false, &matched);
111+
}
112+
113+
list_del(&client->node);
114+
mutex_unlock(&hnae3_common_lock);
115+
}
116+
EXPORT_SYMBOL(hnae3_unregister_client);
117+
118+
/* hnae3_register_ae_algo - register a AE algorithm to hnae3 framework
119+
* @ae_algo: AE algorithm
120+
* NOTE: the duplicated name will not be checked
121+
*/
122+
int hnae3_register_ae_algo(struct hnae3_ae_algo *ae_algo)
123+
{
124+
const struct pci_device_id *id;
125+
struct hnae3_ae_dev *ae_dev;
126+
struct hnae3_client *client;
127+
bool matched;
128+
int ret = 0;
129+
130+
mutex_lock(&hnae3_common_lock);
131+
132+
list_add_tail(&ae_algo->node, &hnae3_ae_algo_list);
133+
134+
/* Check if this algo/ops matches the list of ae_devs */
135+
list_for_each_entry(ae_dev, &hnae3_ae_dev_list, node) {
136+
id = pci_match_id(ae_algo->pdev_id_table, ae_dev->pdev);
137+
if (!id)
138+
continue;
139+
140+
/* ae_dev init should set flag */
141+
ae_dev->ops = ae_algo->ops;
142+
ret = ae_algo->ops->init_ae_dev(ae_dev);
143+
if (ret) {
144+
dev_err(&ae_dev->pdev->dev, "init ae_dev error.\n");
145+
continue;
146+
}
147+
148+
hnae_set_bit(ae_dev->flag, HNAE3_DEV_INITED_B, 1);
149+
150+
/* check the client list for the match with this ae_dev type and
151+
* initialize the figure out client instance
152+
*/
153+
list_for_each_entry(client, &hnae3_client_list, node) {
154+
ret = hnae3_match_n_instantiate(client, ae_dev, true,
155+
&matched);
156+
if (ret)
157+
dev_err(&ae_dev->pdev->dev,
158+
"match and instantiation failed\n");
159+
if (matched)
160+
break;
161+
}
162+
}
163+
164+
mutex_unlock(&hnae3_common_lock);
165+
166+
return ret;
167+
}
168+
EXPORT_SYMBOL(hnae3_register_ae_algo);
169+
170+
/* hnae3_unregister_ae_algo - unregisters a AE algorithm
171+
* @ae_algo: the AE algorithm to unregister
172+
*/
173+
void hnae3_unregister_ae_algo(struct hnae3_ae_algo *ae_algo)
174+
{
175+
const struct pci_device_id *id;
176+
struct hnae3_ae_dev *ae_dev;
177+
struct hnae3_client *client;
178+
bool matched;
179+
180+
mutex_lock(&hnae3_common_lock);
181+
/* Check if there are matched ae_dev */
182+
list_for_each_entry(ae_dev, &hnae3_ae_dev_list, node) {
183+
id = pci_match_id(ae_algo->pdev_id_table, ae_dev->pdev);
184+
if (!id)
185+
continue;
186+
187+
/* check the client list for the match with this ae_dev type and
188+
* un-initialize the figure out client instance
189+
*/
190+
list_for_each_entry(client, &hnae3_client_list, node) {
191+
hnae3_match_n_instantiate(client, ae_dev, false,
192+
&matched);
193+
if (matched)
194+
break;
195+
}
196+
197+
ae_algo->ops->uninit_ae_dev(ae_dev);
198+
hnae_set_bit(ae_dev->flag, HNAE3_DEV_INITED_B, 0);
199+
}
200+
201+
list_del(&ae_algo->node);
202+
mutex_unlock(&hnae3_common_lock);
203+
}
204+
EXPORT_SYMBOL(hnae3_unregister_ae_algo);
205+
206+
/* hnae3_register_ae_dev - registers a AE device to hnae3 framework
207+
* @ae_dev: the AE device
208+
* NOTE: the duplicated name will not be checked
209+
*/
210+
int hnae3_register_ae_dev(struct hnae3_ae_dev *ae_dev)
211+
{
212+
const struct pci_device_id *id;
213+
struct hnae3_ae_algo *ae_algo;
214+
struct hnae3_client *client;
215+
bool matched;
216+
int ret = 0;
217+
218+
mutex_lock(&hnae3_common_lock);
219+
list_add_tail(&ae_dev->node, &hnae3_ae_dev_list);
220+
221+
/* Check if there are matched ae_algo */
222+
list_for_each_entry(ae_algo, &hnae3_ae_algo_list, node) {
223+
id = pci_match_id(ae_algo->pdev_id_table, ae_dev->pdev);
224+
if (!id)
225+
continue;
226+
227+
ae_dev->ops = ae_algo->ops;
228+
229+
if (!ae_dev->ops) {
230+
dev_err(&ae_dev->pdev->dev, "ae_dev ops are null\n");
231+
goto out_err;
232+
}
233+
234+
/* ae_dev init should set flag */
235+
ret = ae_dev->ops->init_ae_dev(ae_dev);
236+
if (ret) {
237+
dev_err(&ae_dev->pdev->dev, "init ae_dev error\n");
238+
goto out_err;
239+
}
240+
241+
hnae_set_bit(ae_dev->flag, HNAE3_DEV_INITED_B, 1);
242+
break;
243+
}
244+
245+
/* check the client list for the match with this ae_dev type and
246+
* initialize the figure out client instance
247+
*/
248+
list_for_each_entry(client, &hnae3_client_list, node) {
249+
ret = hnae3_match_n_instantiate(client, ae_dev, true,
250+
&matched);
251+
if (ret)
252+
dev_err(&ae_dev->pdev->dev,
253+
"match and instantiation failed\n");
254+
if (matched)
255+
break;
256+
}
257+
258+
out_err:
259+
mutex_unlock(&hnae3_common_lock);
260+
261+
return ret;
262+
}
263+
EXPORT_SYMBOL(hnae3_register_ae_dev);
264+
265+
/* hnae3_unregister_ae_dev - unregisters a AE device
266+
* @ae_dev: the AE device to unregister
267+
*/
268+
void hnae3_unregister_ae_dev(struct hnae3_ae_dev *ae_dev)
269+
{
270+
const struct pci_device_id *id;
271+
struct hnae3_ae_algo *ae_algo;
272+
struct hnae3_client *client;
273+
bool matched;
274+
275+
mutex_lock(&hnae3_common_lock);
276+
/* Check if there are matched ae_algo */
277+
list_for_each_entry(ae_algo, &hnae3_ae_algo_list, node) {
278+
id = pci_match_id(ae_algo->pdev_id_table, ae_dev->pdev);
279+
if (!id)
280+
continue;
281+
282+
list_for_each_entry(client, &hnae3_client_list, node) {
283+
hnae3_match_n_instantiate(client, ae_dev, false,
284+
&matched);
285+
if (matched)
286+
break;
287+
}
288+
289+
ae_algo->ops->uninit_ae_dev(ae_dev);
290+
hnae_set_bit(ae_dev->flag, HNAE3_DEV_INITED_B, 0);
291+
}
292+
293+
list_del(&ae_dev->node);
294+
mutex_unlock(&hnae3_common_lock);
295+
}
296+
EXPORT_SYMBOL(hnae3_unregister_ae_dev);
297+
298+
MODULE_AUTHOR("Huawei Tech. Co., Ltd.");
299+
MODULE_LICENSE("GPL");
300+
MODULE_DESCRIPTION("HNAE3(Hisilicon Network Acceleration Engine) Framework");

0 commit comments

Comments
 (0)