Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 // Copyright 2011 Cisco Systems, Inc.  All rights reserved.
0003 
0004 #include <linux/pci.h>
0005 #include <linux/etherdevice.h>
0006 
0007 #include "vnic_dev.h"
0008 #include "vnic_vic.h"
0009 #include "enic_res.h"
0010 #include "enic.h"
0011 #include "enic_dev.h"
0012 
0013 int enic_dev_fw_info(struct enic *enic, struct vnic_devcmd_fw_info **fw_info)
0014 {
0015     int err;
0016 
0017     spin_lock_bh(&enic->devcmd_lock);
0018     err = vnic_dev_fw_info(enic->vdev, fw_info);
0019     spin_unlock_bh(&enic->devcmd_lock);
0020 
0021     return err;
0022 }
0023 
0024 int enic_dev_stats_dump(struct enic *enic, struct vnic_stats **vstats)
0025 {
0026     int err;
0027 
0028     spin_lock_bh(&enic->devcmd_lock);
0029     err = vnic_dev_stats_dump(enic->vdev, vstats);
0030     spin_unlock_bh(&enic->devcmd_lock);
0031 
0032     return err;
0033 }
0034 
0035 int enic_dev_add_station_addr(struct enic *enic)
0036 {
0037     int err;
0038 
0039     if (!is_valid_ether_addr(enic->netdev->dev_addr))
0040         return -EADDRNOTAVAIL;
0041 
0042     spin_lock_bh(&enic->devcmd_lock);
0043     err = vnic_dev_add_addr(enic->vdev, enic->netdev->dev_addr);
0044     spin_unlock_bh(&enic->devcmd_lock);
0045 
0046     return err;
0047 }
0048 
0049 int enic_dev_del_station_addr(struct enic *enic)
0050 {
0051     int err;
0052 
0053     if (!is_valid_ether_addr(enic->netdev->dev_addr))
0054         return -EADDRNOTAVAIL;
0055 
0056     spin_lock_bh(&enic->devcmd_lock);
0057     err = vnic_dev_del_addr(enic->vdev, enic->netdev->dev_addr);
0058     spin_unlock_bh(&enic->devcmd_lock);
0059 
0060     return err;
0061 }
0062 
0063 int enic_dev_packet_filter(struct enic *enic, int directed, int multicast,
0064     int broadcast, int promisc, int allmulti)
0065 {
0066     int err;
0067 
0068     spin_lock_bh(&enic->devcmd_lock);
0069     err = vnic_dev_packet_filter(enic->vdev, directed,
0070         multicast, broadcast, promisc, allmulti);
0071     spin_unlock_bh(&enic->devcmd_lock);
0072 
0073     return err;
0074 }
0075 
0076 int enic_dev_add_addr(struct enic *enic, const u8 *addr)
0077 {
0078     int err;
0079 
0080     spin_lock_bh(&enic->devcmd_lock);
0081     err = vnic_dev_add_addr(enic->vdev, addr);
0082     spin_unlock_bh(&enic->devcmd_lock);
0083 
0084     return err;
0085 }
0086 
0087 int enic_dev_del_addr(struct enic *enic, const u8 *addr)
0088 {
0089     int err;
0090 
0091     spin_lock_bh(&enic->devcmd_lock);
0092     err = vnic_dev_del_addr(enic->vdev, addr);
0093     spin_unlock_bh(&enic->devcmd_lock);
0094 
0095     return err;
0096 }
0097 
0098 int enic_dev_notify_unset(struct enic *enic)
0099 {
0100     int err;
0101 
0102     spin_lock_bh(&enic->devcmd_lock);
0103     err = vnic_dev_notify_unset(enic->vdev);
0104     spin_unlock_bh(&enic->devcmd_lock);
0105 
0106     return err;
0107 }
0108 
0109 int enic_dev_hang_notify(struct enic *enic)
0110 {
0111     int err;
0112 
0113     spin_lock_bh(&enic->devcmd_lock);
0114     err = vnic_dev_hang_notify(enic->vdev);
0115     spin_unlock_bh(&enic->devcmd_lock);
0116 
0117     return err;
0118 }
0119 
0120 int enic_dev_set_ig_vlan_rewrite_mode(struct enic *enic)
0121 {
0122     int err;
0123 
0124     spin_lock_bh(&enic->devcmd_lock);
0125     err = vnic_dev_set_ig_vlan_rewrite_mode(enic->vdev,
0126         IG_VLAN_REWRITE_MODE_PRIORITY_TAG_DEFAULT_VLAN);
0127     spin_unlock_bh(&enic->devcmd_lock);
0128 
0129     return err;
0130 }
0131 
0132 int enic_dev_enable(struct enic *enic)
0133 {
0134     int err;
0135 
0136     spin_lock_bh(&enic->devcmd_lock);
0137     err = vnic_dev_enable_wait(enic->vdev);
0138     spin_unlock_bh(&enic->devcmd_lock);
0139 
0140     return err;
0141 }
0142 
0143 int enic_dev_disable(struct enic *enic)
0144 {
0145     int err;
0146 
0147     spin_lock_bh(&enic->devcmd_lock);
0148     err = vnic_dev_disable(enic->vdev);
0149     spin_unlock_bh(&enic->devcmd_lock);
0150 
0151     return err;
0152 }
0153 
0154 int enic_dev_intr_coal_timer_info(struct enic *enic)
0155 {
0156     int err;
0157 
0158     spin_lock_bh(&enic->devcmd_lock);
0159     err = vnic_dev_intr_coal_timer_info(enic->vdev);
0160     spin_unlock_bh(&enic->devcmd_lock);
0161 
0162     return err;
0163 }
0164 
0165 /* rtnl lock is held */
0166 int enic_vlan_rx_add_vid(struct net_device *netdev, __be16 proto, u16 vid)
0167 {
0168     struct enic *enic = netdev_priv(netdev);
0169     int err;
0170 
0171     spin_lock_bh(&enic->devcmd_lock);
0172     err = enic_add_vlan(enic, vid);
0173     spin_unlock_bh(&enic->devcmd_lock);
0174 
0175     return err;
0176 }
0177 
0178 /* rtnl lock is held */
0179 int enic_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto, u16 vid)
0180 {
0181     struct enic *enic = netdev_priv(netdev);
0182     int err;
0183 
0184     spin_lock_bh(&enic->devcmd_lock);
0185     err = enic_del_vlan(enic, vid);
0186     spin_unlock_bh(&enic->devcmd_lock);
0187 
0188     return err;
0189 }
0190 
0191 int enic_dev_status_to_errno(int devcmd_status)
0192 {
0193     switch (devcmd_status) {
0194     case ERR_SUCCESS:
0195         return 0;
0196     case ERR_EINVAL:
0197         return -EINVAL;
0198     case ERR_EFAULT:
0199         return -EFAULT;
0200     case ERR_EPERM:
0201         return -EPERM;
0202     case ERR_EBUSY:
0203         return -EBUSY;
0204     case ERR_ECMDUNKNOWN:
0205     case ERR_ENOTSUPPORTED:
0206         return -EOPNOTSUPP;
0207     case ERR_EBADSTATE:
0208         return -EINVAL;
0209     case ERR_ENOMEM:
0210         return -ENOMEM;
0211     case ERR_ETIMEDOUT:
0212         return -ETIMEDOUT;
0213     case ERR_ELINKDOWN:
0214         return -ENETDOWN;
0215     case ERR_EINPROGRESS:
0216         return -EINPROGRESS;
0217     case ERR_EMAXRES:
0218     default:
0219         return (devcmd_status < 0) ? devcmd_status : -1;
0220     }
0221 }