1// SPDX-License-Identifier: GPL-2.0-only
2// Copyright 2011 Cisco Systems, Inc. All rights reserved.
3
4#include <linux/pci.h>
5#include <linux/etherdevice.h>
6
7#include "vnic_dev.h"
8#include "vnic_vic.h"
9#include "enic_res.h"
10#include "enic.h"
11#include "enic_dev.h"
12
13int enic_dev_fw_info(struct enic *enic, struct vnic_devcmd_fw_info **fw_info)
14{
15 int err;
16
17 spin_lock_bh(lock: &enic->devcmd_lock);
18 err = vnic_dev_fw_info(vdev: enic->vdev, fw_info);
19 spin_unlock_bh(lock: &enic->devcmd_lock);
20
21 return err;
22}
23
24int enic_dev_stats_dump(struct enic *enic, struct vnic_stats **vstats)
25{
26 int err;
27
28 spin_lock_bh(lock: &enic->devcmd_lock);
29 err = vnic_dev_stats_dump(vdev: enic->vdev, stats: vstats);
30 spin_unlock_bh(lock: &enic->devcmd_lock);
31
32 return err;
33}
34
35int enic_dev_add_station_addr(struct enic *enic)
36{
37 int err;
38
39 if (!is_valid_ether_addr(addr: enic->netdev->dev_addr))
40 return -EADDRNOTAVAIL;
41
42 spin_lock_bh(lock: &enic->devcmd_lock);
43 err = vnic_dev_add_addr(vdev: enic->vdev, addr: enic->netdev->dev_addr);
44 spin_unlock_bh(lock: &enic->devcmd_lock);
45
46 return err;
47}
48
49int enic_dev_del_station_addr(struct enic *enic)
50{
51 int err;
52
53 if (!is_valid_ether_addr(addr: enic->netdev->dev_addr))
54 return -EADDRNOTAVAIL;
55
56 spin_lock_bh(lock: &enic->devcmd_lock);
57 err = vnic_dev_del_addr(vdev: enic->vdev, addr: enic->netdev->dev_addr);
58 spin_unlock_bh(lock: &enic->devcmd_lock);
59
60 return err;
61}
62
63int enic_dev_packet_filter(struct enic *enic, int directed, int multicast,
64 int broadcast, int promisc, int allmulti)
65{
66 int err;
67
68 spin_lock_bh(lock: &enic->devcmd_lock);
69 err = vnic_dev_packet_filter(vdev: enic->vdev, directed,
70 multicast, broadcast, promisc, allmulti);
71 spin_unlock_bh(lock: &enic->devcmd_lock);
72
73 return err;
74}
75
76int enic_dev_add_addr(struct enic *enic, const u8 *addr)
77{
78 int err;
79
80 spin_lock_bh(lock: &enic->devcmd_lock);
81 err = vnic_dev_add_addr(vdev: enic->vdev, addr);
82 spin_unlock_bh(lock: &enic->devcmd_lock);
83
84 return err;
85}
86
87int enic_dev_del_addr(struct enic *enic, const u8 *addr)
88{
89 int err;
90
91 spin_lock_bh(lock: &enic->devcmd_lock);
92 err = vnic_dev_del_addr(vdev: enic->vdev, addr);
93 spin_unlock_bh(lock: &enic->devcmd_lock);
94
95 return err;
96}
97
98int enic_dev_notify_unset(struct enic *enic)
99{
100 int err;
101
102 spin_lock_bh(lock: &enic->devcmd_lock);
103 err = vnic_dev_notify_unset(vdev: enic->vdev);
104 spin_unlock_bh(lock: &enic->devcmd_lock);
105
106 return err;
107}
108
109int enic_dev_hang_notify(struct enic *enic)
110{
111 int err;
112
113 spin_lock_bh(lock: &enic->devcmd_lock);
114 err = vnic_dev_hang_notify(vdev: enic->vdev);
115 spin_unlock_bh(lock: &enic->devcmd_lock);
116
117 return err;
118}
119
120int enic_dev_set_ig_vlan_rewrite_mode(struct enic *enic)
121{
122 int err;
123
124 spin_lock_bh(lock: &enic->devcmd_lock);
125 err = vnic_dev_set_ig_vlan_rewrite_mode(vdev: enic->vdev,
126 IG_VLAN_REWRITE_MODE_PRIORITY_TAG_DEFAULT_VLAN);
127 spin_unlock_bh(lock: &enic->devcmd_lock);
128
129 return err;
130}
131
132int enic_dev_enable(struct enic *enic)
133{
134 int err;
135
136 spin_lock_bh(lock: &enic->devcmd_lock);
137 err = vnic_dev_enable_wait(vdev: enic->vdev);
138 spin_unlock_bh(lock: &enic->devcmd_lock);
139
140 return err;
141}
142
143int enic_dev_disable(struct enic *enic)
144{
145 int err;
146
147 spin_lock_bh(lock: &enic->devcmd_lock);
148 err = vnic_dev_disable(vdev: enic->vdev);
149 spin_unlock_bh(lock: &enic->devcmd_lock);
150
151 return err;
152}
153
154int enic_dev_intr_coal_timer_info(struct enic *enic)
155{
156 int err;
157
158 spin_lock_bh(lock: &enic->devcmd_lock);
159 err = vnic_dev_intr_coal_timer_info(vdev: enic->vdev);
160 spin_unlock_bh(lock: &enic->devcmd_lock);
161
162 return err;
163}
164
165/* rtnl lock is held */
166int enic_vlan_rx_add_vid(struct net_device *netdev, __be16 proto, u16 vid)
167{
168 struct enic *enic = netdev_priv(dev: netdev);
169 int err;
170
171 spin_lock_bh(lock: &enic->devcmd_lock);
172 err = enic_add_vlan(enic, vlanid: vid);
173 spin_unlock_bh(lock: &enic->devcmd_lock);
174
175 return err;
176}
177
178/* rtnl lock is held */
179int enic_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto, u16 vid)
180{
181 struct enic *enic = netdev_priv(dev: netdev);
182 int err;
183
184 spin_lock_bh(lock: &enic->devcmd_lock);
185 err = enic_del_vlan(enic, vlanid: vid);
186 spin_unlock_bh(lock: &enic->devcmd_lock);
187
188 return err;
189}
190
191int enic_dev_status_to_errno(int devcmd_status)
192{
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;
220 }
221}
222

source code of linux/drivers/net/ethernet/cisco/enic/enic_dev.c