xref: /openbmc/linux/drivers/net/ethernet/cisco/enic/enic_api.c (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1*e6550b3eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2*e6550b3eSThomas Gleixner // Copyright 2013 Cisco Systems, Inc.  All rights reserved.
30b038566SNeel Patel 
40b038566SNeel Patel #include <linux/netdevice.h>
50b038566SNeel Patel #include <linux/spinlock.h>
60b038566SNeel Patel 
70b038566SNeel Patel #include "vnic_dev.h"
80b038566SNeel Patel #include "vnic_devcmd.h"
90b038566SNeel Patel 
100b038566SNeel Patel #include "enic_res.h"
110b038566SNeel Patel #include "enic.h"
120b038566SNeel Patel #include "enic_api.h"
130b038566SNeel Patel 
enic_api_devcmd_proxy_by_index(struct net_device * netdev,int vf,enum vnic_devcmd_cmd cmd,u64 * a0,u64 * a1,int wait)140b038566SNeel Patel int enic_api_devcmd_proxy_by_index(struct net_device *netdev, int vf,
150b038566SNeel Patel 	enum vnic_devcmd_cmd cmd, u64 *a0, u64 *a1, int wait)
160b038566SNeel Patel {
170b038566SNeel Patel 	int err;
180b038566SNeel Patel 	struct enic *enic = netdev_priv(netdev);
190b038566SNeel Patel 	struct vnic_dev *vdev = enic->vdev;
200b038566SNeel Patel 
210b038566SNeel Patel 	spin_lock(&enic->enic_api_lock);
22a53b59ecSThomas Gleixner 	while (enic->enic_api_busy) {
23a53b59ecSThomas Gleixner 		spin_unlock(&enic->enic_api_lock);
24a53b59ecSThomas Gleixner 		cpu_relax();
25a53b59ecSThomas Gleixner 		spin_lock(&enic->enic_api_lock);
26a53b59ecSThomas Gleixner 	}
27a53b59ecSThomas Gleixner 
288e091340STony Camuso 	spin_lock_bh(&enic->devcmd_lock);
290b038566SNeel Patel 
300b038566SNeel Patel 	vnic_dev_cmd_proxy_by_index_start(vdev, vf);
310b038566SNeel Patel 	err = vnic_dev_cmd(vdev, cmd, a0, a1, wait);
320b038566SNeel Patel 	vnic_dev_cmd_proxy_end(vdev);
330b038566SNeel Patel 
348e091340STony Camuso 	spin_unlock_bh(&enic->devcmd_lock);
350b038566SNeel Patel 	spin_unlock(&enic->enic_api_lock);
360b038566SNeel Patel 
370b038566SNeel Patel 	return err;
380b038566SNeel Patel }
390b038566SNeel Patel EXPORT_SYMBOL(enic_api_devcmd_proxy_by_index);
40