xref: /linux/drivers/net/ethernet/cisco/enic/enic_api.c (revision cbecf716ca618fd44feda6bd9a64a8179d031fc5)
1d0ea5cbdSJesse Brandeburg /*
20b038566SNeel Patel  * Copyright 2013 Cisco Systems, Inc.  All rights reserved.
30b038566SNeel Patel  *
40b038566SNeel Patel  * This program is free software; you may redistribute it and/or modify
50b038566SNeel Patel  * it under the terms of the GNU General Public License as published by
60b038566SNeel Patel  * the Free Software Foundation; version 2 of the License.
70b038566SNeel Patel  *
80b038566SNeel Patel  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
90b038566SNeel Patel  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
100b038566SNeel Patel  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
110b038566SNeel Patel  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
120b038566SNeel Patel  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
130b038566SNeel Patel  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
140b038566SNeel Patel  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
150b038566SNeel Patel  * SOFTWARE.
160b038566SNeel Patel  *
170b038566SNeel Patel  */
180b038566SNeel Patel 
190b038566SNeel Patel #include <linux/netdevice.h>
200b038566SNeel Patel #include <linux/spinlock.h>
210b038566SNeel Patel 
220b038566SNeel Patel #include "vnic_dev.h"
230b038566SNeel Patel #include "vnic_devcmd.h"
240b038566SNeel Patel 
250b038566SNeel Patel #include "enic_res.h"
260b038566SNeel Patel #include "enic.h"
270b038566SNeel Patel #include "enic_api.h"
280b038566SNeel Patel 
290b038566SNeel Patel int enic_api_devcmd_proxy_by_index(struct net_device *netdev, int vf,
300b038566SNeel Patel 	enum vnic_devcmd_cmd cmd, u64 *a0, u64 *a1, int wait)
310b038566SNeel Patel {
320b038566SNeel Patel 	int err;
330b038566SNeel Patel 	struct enic *enic = netdev_priv(netdev);
340b038566SNeel Patel 	struct vnic_dev *vdev = enic->vdev;
350b038566SNeel Patel 
360b038566SNeel Patel 	spin_lock(&enic->enic_api_lock);
37*a53b59ecSThomas Gleixner 	while (enic->enic_api_busy) {
38*a53b59ecSThomas Gleixner 		spin_unlock(&enic->enic_api_lock);
39*a53b59ecSThomas Gleixner 		cpu_relax();
40*a53b59ecSThomas Gleixner 		spin_lock(&enic->enic_api_lock);
41*a53b59ecSThomas Gleixner 	}
42*a53b59ecSThomas Gleixner 
438e091340STony Camuso 	spin_lock_bh(&enic->devcmd_lock);
440b038566SNeel Patel 
450b038566SNeel Patel 	vnic_dev_cmd_proxy_by_index_start(vdev, vf);
460b038566SNeel Patel 	err = vnic_dev_cmd(vdev, cmd, a0, a1, wait);
470b038566SNeel Patel 	vnic_dev_cmd_proxy_end(vdev);
480b038566SNeel Patel 
498e091340STony Camuso 	spin_unlock_bh(&enic->devcmd_lock);
500b038566SNeel Patel 	spin_unlock(&enic->enic_api_lock);
510b038566SNeel Patel 
520b038566SNeel Patel 	return err;
530b038566SNeel Patel }
540b038566SNeel Patel EXPORT_SYMBOL(enic_api_devcmd_proxy_by_index);
55