list_for_each_entry(ae_dev, &hnae3_ae_dev_list, node) { if (!hnae3_get_bit(ae_dev->flag, HNAE3_DEV_INITED_B)) continue;
pci_id = pci_match_id(ae_algo->pdev_id_table, ae_dev->pdev); if (!pci_id) continue; if (IS_ENABLED(CONFIG_PCI_IOV)) {
device_lock(&ae_dev->pdev->dev);
pci_disable_sriov(ae_dev->pdev);
device_unlock(&ae_dev->pdev->dev);
}
}
}
EXPORT_SYMBOL(hnae3_unregister_ae_algo_prepare);
/* we are keeping things simple and using single lock for all the * list. This is a non-critical code so other updations, if happen * in parallel, can wait.
*/ static DEFINE_MUTEX(hnae3_common_lock);
/* ensure the drivers being unloaded one by one */ static DEFINE_MUTEX(hnae3_unload_lock);
switch (client->type) { case HNAE3_CLIENT_KNIC:
inited = hnae3_get_bit(ae_dev->flag,
HNAE3_KNIC_CLIENT_INITED_B); break; case HNAE3_CLIENT_ROCE:
inited = hnae3_get_bit(ae_dev->flag,
HNAE3_ROCE_CLIENT_INITED_B); break; default: break;
}
return inited;
}
staticint hnae3_init_client_instance(struct hnae3_client *client, struct hnae3_ae_dev *ae_dev)
{ int ret;
/* check if this client matches the type of ae_dev */ if (!(hnae3_client_match(client->type) &&
hnae3_get_bit(ae_dev->flag, HNAE3_DEV_INITED_B))) { return 0;
}
ret = ae_dev->ops->init_client_instance(client, ae_dev); if (ret)
dev_err(&ae_dev->pdev->dev, "fail to instantiate client, ret = %d\n", ret);
return ret;
}
staticvoid hnae3_uninit_client_instance(struct hnae3_client *client, struct hnae3_ae_dev *ae_dev)
{ /* check if this client matches the type of ae_dev */ if (!(hnae3_client_match(client->type) &&
hnae3_get_bit(ae_dev->flag, HNAE3_DEV_INITED_B))) return;
if (hnae3_get_client_init_flag(client, ae_dev)) {
ae_dev->ops->uninit_client_instance(client, ae_dev);
mutex_lock(&hnae3_common_lock); /* one system should only have one client for every type */
list_for_each_entry(client_tmp, &hnae3_client_list, node) { if (client_tmp->type == client->type) gotoexit;
}
list_add_tail(&client->node, &hnae3_client_list);
/* initialize the client on every matched port */
list_for_each_entry(ae_dev, &hnae3_ae_dev_list, node) { /* if the client could not be initialized on current port, for * any error reasons, move on to next available port
*/ int ret = hnae3_init_client_instance(client, ae_dev); if (ret)
dev_err(&ae_dev->pdev->dev, "match and instantiation failed for port, ret = %d\n",
ret);
}
mutex_lock(&hnae3_common_lock); /* one system should only have one client for every type */
list_for_each_entry(client_tmp, &hnae3_client_list, node) { if (client_tmp->type == client->type) {
existed = true; break;
}
}
if (!existed) {
mutex_unlock(&hnae3_common_lock);
pr_err("client %s does not exist!\n", client->name); return;
}
/* un-initialize the client on every matched port */
list_for_each_entry(ae_dev, &hnae3_ae_dev_list, node) {
hnae3_uninit_client_instance(client, ae_dev);
}
/* hnae3_register_ae_algo - register a AE algorithm to hnae3 framework * @ae_algo: AE algorithm * NOTE: the duplicated name will not be checked
*/ void hnae3_register_ae_algo(struct hnae3_ae_algo *ae_algo)
{ conststruct pci_device_id *id; struct hnae3_ae_dev *ae_dev; struct hnae3_client *client; int ret;
/* Check if this algo/ops matches the list of ae_devs */
list_for_each_entry(ae_dev, &hnae3_ae_dev_list, node) {
id = pci_match_id(ae_algo->pdev_id_table, ae_dev->pdev); if (!id) continue;
if (!ae_algo->ops) {
dev_err(&ae_dev->pdev->dev, "ae_algo ops are null\n"); continue;
}
ae_dev->ops = ae_algo->ops;
ret = ae_algo->ops->init_ae_dev(ae_dev); if (ret) {
dev_err(&ae_dev->pdev->dev, "init ae_dev error, ret = %d\n", ret); continue;
}
/* ae_dev init should set flag */
hnae3_set_bit(ae_dev->flag, HNAE3_DEV_INITED_B, 1);
/* check the client list for the match with this ae_dev type and * initialize the figure out client instance
*/
list_for_each_entry(client, &hnae3_client_list, node) {
ret = hnae3_init_client_instance(client, ae_dev); if (ret)
dev_err(&ae_dev->pdev->dev, "match and instantiation failed, ret = %d\n",
ret);
}
}
/* hnae3_unregister_ae_algo - unregisters a AE algorithm * @ae_algo: the AE algorithm to unregister
*/ void hnae3_unregister_ae_algo(struct hnae3_ae_algo *ae_algo)
{ conststruct pci_device_id *id; struct hnae3_ae_dev *ae_dev; struct hnae3_client *client;
if (!ae_algo) return;
mutex_lock(&hnae3_common_lock); /* Check if there are matched ae_dev */
list_for_each_entry(ae_dev, &hnae3_ae_dev_list, node) { if (!hnae3_get_bit(ae_dev->flag, HNAE3_DEV_INITED_B)) continue;
id = pci_match_id(ae_algo->pdev_id_table, ae_dev->pdev); if (!id) continue;
/* check the client list for the match with this ae_dev type and * un-initialize the figure out client instance
*/
list_for_each_entry(client, &hnae3_client_list, node)
hnae3_uninit_client_instance(client, ae_dev);
/* hnae3_register_ae_dev - registers a AE device to hnae3 framework * @ae_dev: the AE device * NOTE: the duplicated name will not be checked
*/ int hnae3_register_ae_dev(struct hnae3_ae_dev *ae_dev)
{ conststruct pci_device_id *id; struct hnae3_ae_algo *ae_algo; struct hnae3_client *client; int ret;
if (!ae_dev) return -ENODEV;
mutex_lock(&hnae3_common_lock);
list_add_tail(&ae_dev->node, &hnae3_ae_dev_list);
/* Check if there are matched ae_algo */
list_for_each_entry(ae_algo, &hnae3_ae_algo_list, node) {
id = pci_match_id(ae_algo->pdev_id_table, ae_dev->pdev); if (!id) continue;
if (!ae_algo->ops) {
dev_err(&ae_dev->pdev->dev, "ae_algo ops are null\n");
ret = -EOPNOTSUPP; goto out_err;
}
ae_dev->ops = ae_algo->ops;
ret = ae_dev->ops->init_ae_dev(ae_dev); if (ret) {
dev_err(&ae_dev->pdev->dev, "init ae_dev error, ret = %d\n", ret); goto out_err;
}
/* ae_dev init should set flag */
hnae3_set_bit(ae_dev->flag, HNAE3_DEV_INITED_B, 1); break;
}
/* check the client list for the match with this ae_dev type and * initialize the figure out client instance
*/
list_for_each_entry(client, &hnae3_client_list, node) {
ret = hnae3_init_client_instance(client, ae_dev); if (ret)
dev_err(&ae_dev->pdev->dev, "match and instantiation failed, ret = %d\n",
ret);
}
/* hnae3_unregister_ae_dev - unregisters a AE device * @ae_dev: the AE device to unregister
*/ void hnae3_unregister_ae_dev(struct hnae3_ae_dev *ae_dev)
{ conststruct pci_device_id *id; struct hnae3_ae_algo *ae_algo; struct hnae3_client *client;
if (!ae_dev) return;
mutex_lock(&hnae3_common_lock); /* Check if there are matched ae_algo */
list_for_each_entry(ae_algo, &hnae3_ae_algo_list, node) { if (!hnae3_get_bit(ae_dev->flag, HNAE3_DEV_INITED_B)) continue;
id = pci_match_id(ae_algo->pdev_id_table, ae_dev->pdev); if (!id) continue;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.