Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / net / ethernet / cisco / enic / enic_dev.c
blob2cbae7c6cc3d68439b9977bc78f3b620f954b797
1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright 2011 Cisco Systems, Inc. All rights reserved.
4 #include <linux/pci.h>
5 #include <linux/etherdevice.h>
7 #include "vnic_dev.h"
8 #include "vnic_vic.h"
9 #include "enic_res.h"
10 #include "enic.h"
11 #include "enic_dev.h"
13 int enic_dev_fw_info(struct enic *enic, struct vnic_devcmd_fw_info **fw_info)
15 int err;
17 spin_lock_bh(&enic->devcmd_lock);
18 err = vnic_dev_fw_info(enic->vdev, fw_info);
19 spin_unlock_bh(&enic->devcmd_lock);
21 return err;
24 int enic_dev_stats_dump(struct enic *enic, struct vnic_stats **vstats)
26 int err;
28 spin_lock_bh(&enic->devcmd_lock);
29 err = vnic_dev_stats_dump(enic->vdev, vstats);
30 spin_unlock_bh(&enic->devcmd_lock);
32 return err;
35 int enic_dev_add_station_addr(struct enic *enic)
37 int err;
39 if (!is_valid_ether_addr(enic->netdev->dev_addr))
40 return -EADDRNOTAVAIL;
42 spin_lock_bh(&enic->devcmd_lock);
43 err = vnic_dev_add_addr(enic->vdev, enic->netdev->dev_addr);
44 spin_unlock_bh(&enic->devcmd_lock);
46 return err;
49 int enic_dev_del_station_addr(struct enic *enic)
51 int err;
53 if (!is_valid_ether_addr(enic->netdev->dev_addr))
54 return -EADDRNOTAVAIL;
56 spin_lock_bh(&enic->devcmd_lock);
57 err = vnic_dev_del_addr(enic->vdev, enic->netdev->dev_addr);
58 spin_unlock_bh(&enic->devcmd_lock);
60 return err;
63 int enic_dev_packet_filter(struct enic *enic, int directed, int multicast,
64 int broadcast, int promisc, int allmulti)
66 int err;
68 spin_lock_bh(&enic->devcmd_lock);
69 err = vnic_dev_packet_filter(enic->vdev, directed,
70 multicast, broadcast, promisc, allmulti);
71 spin_unlock_bh(&enic->devcmd_lock);
73 return err;
76 int enic_dev_add_addr(struct enic *enic, const u8 *addr)
78 int err;
80 spin_lock_bh(&enic->devcmd_lock);
81 err = vnic_dev_add_addr(enic->vdev, addr);
82 spin_unlock_bh(&enic->devcmd_lock);
84 return err;
87 int enic_dev_del_addr(struct enic *enic, const u8 *addr)
89 int err;
91 spin_lock_bh(&enic->devcmd_lock);
92 err = vnic_dev_del_addr(enic->vdev, addr);
93 spin_unlock_bh(&enic->devcmd_lock);
95 return err;
98 int enic_dev_notify_unset(struct enic *enic)
100 int err;
102 spin_lock_bh(&enic->devcmd_lock);
103 err = vnic_dev_notify_unset(enic->vdev);
104 spin_unlock_bh(&enic->devcmd_lock);
106 return err;
109 int enic_dev_hang_notify(struct enic *enic)
111 int err;
113 spin_lock_bh(&enic->devcmd_lock);
114 err = vnic_dev_hang_notify(enic->vdev);
115 spin_unlock_bh(&enic->devcmd_lock);
117 return err;
120 int enic_dev_set_ig_vlan_rewrite_mode(struct enic *enic)
122 int err;
124 spin_lock_bh(&enic->devcmd_lock);
125 err = vnic_dev_set_ig_vlan_rewrite_mode(enic->vdev,
126 IG_VLAN_REWRITE_MODE_PRIORITY_TAG_DEFAULT_VLAN);
127 spin_unlock_bh(&enic->devcmd_lock);
129 return err;
132 int enic_dev_enable(struct enic *enic)
134 int err;
136 spin_lock_bh(&enic->devcmd_lock);
137 err = vnic_dev_enable_wait(enic->vdev);
138 spin_unlock_bh(&enic->devcmd_lock);
140 return err;
143 int enic_dev_disable(struct enic *enic)
145 int err;
147 spin_lock_bh(&enic->devcmd_lock);
148 err = vnic_dev_disable(enic->vdev);
149 spin_unlock_bh(&enic->devcmd_lock);
151 return err;
154 int enic_dev_intr_coal_timer_info(struct enic *enic)
156 int err;
158 spin_lock_bh(&enic->devcmd_lock);
159 err = vnic_dev_intr_coal_timer_info(enic->vdev);
160 spin_unlock_bh(&enic->devcmd_lock);
162 return err;
165 /* rtnl lock is held */
166 int enic_vlan_rx_add_vid(struct net_device *netdev, __be16 proto, u16 vid)
168 struct enic *enic = netdev_priv(netdev);
169 int err;
171 spin_lock_bh(&enic->devcmd_lock);
172 err = enic_add_vlan(enic, vid);
173 spin_unlock_bh(&enic->devcmd_lock);
175 return err;
178 /* rtnl lock is held */
179 int enic_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto, u16 vid)
181 struct enic *enic = netdev_priv(netdev);
182 int err;
184 spin_lock_bh(&enic->devcmd_lock);
185 err = enic_del_vlan(enic, vid);
186 spin_unlock_bh(&enic->devcmd_lock);
188 return err;
191 int enic_dev_status_to_errno(int devcmd_status)
193 switch (devcmd_status) {
194 case ERR_SUCCESS:
195 return 0;
196 case ERR_EINVAL:
197 return -EINVAL;
198 case ERR_EFAULT:
199 return -EFAULT;
200 case ERR_EPERM:
201 return -EPERM;
202 case ERR_EBUSY:
203 return -EBUSY;
204 case ERR_ECMDUNKNOWN:
205 case ERR_ENOTSUPPORTED:
206 return -EOPNOTSUPP;
207 case ERR_EBADSTATE:
208 return -EINVAL;
209 case ERR_ENOMEM:
210 return -ENOMEM;
211 case ERR_ETIMEDOUT:
212 return -ETIMEDOUT;
213 case ERR_ELINKDOWN:
214 return -ENETDOWN;
215 case ERR_EINPROGRESS:
216 return -EINPROGRESS;
217 case ERR_EMAXRES:
218 default:
219 return (devcmd_status < 0) ? devcmd_status : -1;