[PATCH net-next 2/9] net: hns3: Add support of the HNAE3 framework
This patch adds the support of the HNAE3 (Hisilicon Network Acceleration Engine 3) framework support to the HNS3 driver. Framework facilitates clients like ENET(HNS3 Ethernet Driver), RoCE and user-space Ethernet drivers (like ODP etc.) to register with HNAE3 devices and their associated operations. Signed-off-by: Daode HuangSigned-off-by: lipeng Signed-off-by: Salil Mehta Signed-off-by: Yisen Zhuang --- drivers/net/ethernet/hisilicon/hns3/hnae3.c | 305 +++ drivers/net/ethernet/hisilicon/hns3/hnae3.h | 449 2 files changed, 754 insertions(+) create mode 100644 drivers/net/ethernet/hisilicon/hns3/hnae3.c create mode 100644 drivers/net/ethernet/hisilicon/hns3/hnae3.h diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.c b/drivers/net/ethernet/hisilicon/hns3/hnae3.c new file mode 100644 index 000..f133e1d --- /dev/null +++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.c @@ -0,0 +1,305 @@ +/* + * Copyright (c) 2016-2017 Hisilicon Limited. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include + +#include "hnae3.h" + +static LIST_HEAD(hnae3_ae_algo_list); +static LIST_HEAD(hnae3_client_list); +static LIST_HEAD(hnae3_ae_dev_list); + +static DEFINE_SPINLOCK(hnae3_list_ae_algo_lock); +static DEFINE_SPINLOCK(hnae3_list_client_lock); +static DEFINE_SPINLOCK(hnae3_list_ae_dev_lock); + +static void hnae3_list_add(spinlock_t *lock, struct list_head *node, + struct list_head *head) +{ + unsigned long flags; + + spin_lock_irqsave(lock, flags); + list_add_tail_rcu(node, head); + spin_unlock_irqrestore(lock, flags); +} + +static void hnae3_list_del(spinlock_t *lock, struct list_head *node) +{ + unsigned long flags; + + spin_lock_irqsave(lock, flags); + list_del_rcu(node); + spin_unlock_irqrestore(lock, flags); +} + +static bool hnae3_client_match(enum hnae3_client_type client_type, + enum hnae3_dev_type dev_type) +{ + if (dev_type == HNAE3_DEV_KNIC) { + switch (client_type) { + case HNAE3_CLIENT_KNIC: + case HNAE3_CLIENT_ROCE: + return true; + default: + return false; + } + } else if (dev_type == HNAE3_DEV_UNIC) { + switch (client_type) { + case HNAE3_CLIENT_UNIC: + return true; + default: + return false; + } + } else { + return false; + } +} + +int hnae3_register_client(struct hnae3_client *client) +{ + struct hnae3_client *client_tmp; + struct hnae3_ae_dev *ae_dev; + int ret; + + /* One system should only have one client for every type */ + list_for_each_entry(client_tmp, _client_list, node) { + if (client_tmp->type == client->type) + return 0; + } + + hnae3_list_add(_list_client_lock, >node, + _client_list); + + /* Check if there are matched ae_dev */ + list_for_each_entry(ae_dev, _ae_dev_list, node) { + if (hnae3_client_match(client->type, ae_dev->dev_type) && + hnae_get_bit(ae_dev->flag, HNAE3_DEV_INITED_B)) { + if (ae_dev->ops && ae_dev->ops->register_client) { + ret = ae_dev->ops->register_client(client, + ae_dev); + if (ret) { + dev_err(_dev->pdev->dev, + "init ae_dev error.\n"); + return ret; + } + } + } + } + + return 0; +} +EXPORT_SYMBOL(hnae3_register_client); + +void hnae3_unregister_client(struct hnae3_client *client) +{ + struct hnae3_ae_dev *ae_dev; + + /* Check if there are matched ae_dev */ + list_for_each_entry(ae_dev, _ae_dev_list, node) { + if (hnae3_client_match(client->type, ae_dev->dev_type) && + hnae_get_bit(ae_dev->flag, HNAE3_DEV_INITED_B)) + if (ae_dev->ops && ae_dev->ops->unregister_client) + ae_dev->ops->unregister_client(client, ae_dev); + } + hnae3_list_del(_list_client_lock, >node); +} +EXPORT_SYMBOL(hnae3_unregister_client); + +/* hnae_ae_register - register a AE engine to hnae framework + * @hdev: the hnae ae engine device + * @owner: the module who
[PATCH net-next 2/9] net: hns3: Add support of the HNAE3 framework
This patch adds the support of the HNAE3 (Hisilicon Network Acceleration Engine 3) framework support to the HNS3 driver. Framework facilitates clients like ENET(HNS3 Ethernet Driver), RoCE and user-space Ethernet drivers (like ODP etc.) to register with HNAE3 devices and their associated operations. Signed-off-by: Daode Huang Signed-off-by: lipeng Signed-off-by: Salil Mehta Signed-off-by: Yisen Zhuang --- drivers/net/ethernet/hisilicon/hns3/hnae3.c | 305 +++ drivers/net/ethernet/hisilicon/hns3/hnae3.h | 449 2 files changed, 754 insertions(+) create mode 100644 drivers/net/ethernet/hisilicon/hns3/hnae3.c create mode 100644 drivers/net/ethernet/hisilicon/hns3/hnae3.h diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.c b/drivers/net/ethernet/hisilicon/hns3/hnae3.c new file mode 100644 index 000..f133e1d --- /dev/null +++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.c @@ -0,0 +1,305 @@ +/* + * Copyright (c) 2016-2017 Hisilicon Limited. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include + +#include "hnae3.h" + +static LIST_HEAD(hnae3_ae_algo_list); +static LIST_HEAD(hnae3_client_list); +static LIST_HEAD(hnae3_ae_dev_list); + +static DEFINE_SPINLOCK(hnae3_list_ae_algo_lock); +static DEFINE_SPINLOCK(hnae3_list_client_lock); +static DEFINE_SPINLOCK(hnae3_list_ae_dev_lock); + +static void hnae3_list_add(spinlock_t *lock, struct list_head *node, + struct list_head *head) +{ + unsigned long flags; + + spin_lock_irqsave(lock, flags); + list_add_tail_rcu(node, head); + spin_unlock_irqrestore(lock, flags); +} + +static void hnae3_list_del(spinlock_t *lock, struct list_head *node) +{ + unsigned long flags; + + spin_lock_irqsave(lock, flags); + list_del_rcu(node); + spin_unlock_irqrestore(lock, flags); +} + +static bool hnae3_client_match(enum hnae3_client_type client_type, + enum hnae3_dev_type dev_type) +{ + if (dev_type == HNAE3_DEV_KNIC) { + switch (client_type) { + case HNAE3_CLIENT_KNIC: + case HNAE3_CLIENT_ROCE: + return true; + default: + return false; + } + } else if (dev_type == HNAE3_DEV_UNIC) { + switch (client_type) { + case HNAE3_CLIENT_UNIC: + return true; + default: + return false; + } + } else { + return false; + } +} + +int hnae3_register_client(struct hnae3_client *client) +{ + struct hnae3_client *client_tmp; + struct hnae3_ae_dev *ae_dev; + int ret; + + /* One system should only have one client for every type */ + list_for_each_entry(client_tmp, _client_list, node) { + if (client_tmp->type == client->type) + return 0; + } + + hnae3_list_add(_list_client_lock, >node, + _client_list); + + /* Check if there are matched ae_dev */ + list_for_each_entry(ae_dev, _ae_dev_list, node) { + if (hnae3_client_match(client->type, ae_dev->dev_type) && + hnae_get_bit(ae_dev->flag, HNAE3_DEV_INITED_B)) { + if (ae_dev->ops && ae_dev->ops->register_client) { + ret = ae_dev->ops->register_client(client, + ae_dev); + if (ret) { + dev_err(_dev->pdev->dev, + "init ae_dev error.\n"); + return ret; + } + } + } + } + + return 0; +} +EXPORT_SYMBOL(hnae3_register_client); + +void hnae3_unregister_client(struct hnae3_client *client) +{ + struct hnae3_ae_dev *ae_dev; + + /* Check if there are matched ae_dev */ + list_for_each_entry(ae_dev, _ae_dev_list, node) { + if (hnae3_client_match(client->type, ae_dev->dev_type) && + hnae_get_bit(ae_dev->flag, HNAE3_DEV_INITED_B)) + if (ae_dev->ops && ae_dev->ops->unregister_client) + ae_dev->ops->unregister_client(client, ae_dev); + } + hnae3_list_del(_list_client_lock, >node); +} +EXPORT_SYMBOL(hnae3_unregister_client); + +/* hnae_ae_register - register a AE engine to hnae framework + * @hdev: the hnae ae engine device + * @owner: the module who provides this dev + * NOTE: the duplicated name will not be checked + */ +int