Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / drivers / net / ethernet / cisco / enic / enic_dev.c
blobf8d2a6a34282d4dc481d3af21a8dce35788bd24f
1 /*
2 * Copyright 2011 Cisco Systems, Inc. All rights reserved.
4 * This program is free software; you may redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
9 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
10 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
11 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
12 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
13 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
14 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
15 * SOFTWARE.
19 #include <linux/pci.h>
20 #include <linux/etherdevice.h>
22 #include "vnic_dev.h"
23 #include "vnic_vic.h"
24 #include "enic_res.h"
25 #include "enic.h"
26 #include "enic_dev.h"
28 int enic_dev_fw_info(struct enic *enic, struct vnic_devcmd_fw_info **fw_info)
30 int err;
32 spin_lock_bh(&enic->devcmd_lock);
33 err = vnic_dev_fw_info(enic->vdev, fw_info);
34 spin_unlock_bh(&enic->devcmd_lock);
36 return err;
39 int enic_dev_stats_dump(struct enic *enic, struct vnic_stats **vstats)
41 int err;
43 spin_lock_bh(&enic->devcmd_lock);
44 err = vnic_dev_stats_dump(enic->vdev, vstats);
45 spin_unlock_bh(&enic->devcmd_lock);
47 return err;
50 int enic_dev_add_station_addr(struct enic *enic)
52 int err;
54 if (!is_valid_ether_addr(enic->netdev->dev_addr))
55 return -EADDRNOTAVAIL;
57 spin_lock_bh(&enic->devcmd_lock);
58 err = vnic_dev_add_addr(enic->vdev, enic->netdev->dev_addr);
59 spin_unlock_bh(&enic->devcmd_lock);
61 return err;
64 int enic_dev_del_station_addr(struct enic *enic)
66 int err;
68 if (!is_valid_ether_addr(enic->netdev->dev_addr))
69 return -EADDRNOTAVAIL;
71 spin_lock_bh(&enic->devcmd_lock);
72 err = vnic_dev_del_addr(enic->vdev, enic->netdev->dev_addr);
73 spin_unlock_bh(&enic->devcmd_lock);
75 return err;
78 int enic_dev_packet_filter(struct enic *enic, int directed, int multicast,
79 int broadcast, int promisc, int allmulti)
81 int err;
83 spin_lock_bh(&enic->devcmd_lock);
84 err = vnic_dev_packet_filter(enic->vdev, directed,
85 multicast, broadcast, promisc, allmulti);
86 spin_unlock_bh(&enic->devcmd_lock);
88 return err;
91 int enic_dev_add_addr(struct enic *enic, const u8 *addr)
93 int err;
95 spin_lock_bh(&enic->devcmd_lock);
96 err = vnic_dev_add_addr(enic->vdev, addr);
97 spin_unlock_bh(&enic->devcmd_lock);
99 return err;
102 int enic_dev_del_addr(struct enic *enic, const u8 *addr)
104 int err;
106 spin_lock_bh(&enic->devcmd_lock);
107 err = vnic_dev_del_addr(enic->vdev, addr);
108 spin_unlock_bh(&enic->devcmd_lock);
110 return err;
113 int enic_dev_notify_unset(struct enic *enic)
115 int err;
117 spin_lock_bh(&enic->devcmd_lock);
118 err = vnic_dev_notify_unset(enic->vdev);
119 spin_unlock_bh(&enic->devcmd_lock);
121 return err;
124 int enic_dev_hang_notify(struct enic *enic)
126 int err;
128 spin_lock_bh(&enic->devcmd_lock);
129 err = vnic_dev_hang_notify(enic->vdev);
130 spin_unlock_bh(&enic->devcmd_lock);
132 return err;
135 int enic_dev_set_ig_vlan_rewrite_mode(struct enic *enic)
137 int err;
139 spin_lock_bh(&enic->devcmd_lock);
140 err = vnic_dev_set_ig_vlan_rewrite_mode(enic->vdev,
141 IG_VLAN_REWRITE_MODE_PRIORITY_TAG_DEFAULT_VLAN);
142 spin_unlock_bh(&enic->devcmd_lock);
144 return err;
147 int enic_dev_enable(struct enic *enic)
149 int err;
151 spin_lock_bh(&enic->devcmd_lock);
152 err = vnic_dev_enable_wait(enic->vdev);
153 spin_unlock_bh(&enic->devcmd_lock);
155 return err;
158 int enic_dev_disable(struct enic *enic)
160 int err;
162 spin_lock_bh(&enic->devcmd_lock);
163 err = vnic_dev_disable(enic->vdev);
164 spin_unlock_bh(&enic->devcmd_lock);
166 return err;
169 int enic_dev_intr_coal_timer_info(struct enic *enic)
171 int err;
173 spin_lock_bh(&enic->devcmd_lock);
174 err = vnic_dev_intr_coal_timer_info(enic->vdev);
175 spin_unlock_bh(&enic->devcmd_lock);
177 return err;
180 /* rtnl lock is held */
181 int enic_vlan_rx_add_vid(struct net_device *netdev, __be16 proto, u16 vid)
183 struct enic *enic = netdev_priv(netdev);
184 int err;
186 spin_lock_bh(&enic->devcmd_lock);
187 err = enic_add_vlan(enic, vid);
188 spin_unlock_bh(&enic->devcmd_lock);
190 return err;
193 /* rtnl lock is held */
194 int enic_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto, u16 vid)
196 struct enic *enic = netdev_priv(netdev);
197 int err;
199 spin_lock_bh(&enic->devcmd_lock);
200 err = enic_del_vlan(enic, vid);
201 spin_unlock_bh(&enic->devcmd_lock);
203 return err;
206 int enic_dev_status_to_errno(int devcmd_status)
208 switch (devcmd_status) {
209 case ERR_SUCCESS:
210 return 0;
211 case ERR_EINVAL:
212 return -EINVAL;
213 case ERR_EFAULT:
214 return -EFAULT;
215 case ERR_EPERM:
216 return -EPERM;
217 case ERR_EBUSY:
218 return -EBUSY;
219 case ERR_ECMDUNKNOWN:
220 case ERR_ENOTSUPPORTED:
221 return -EOPNOTSUPP;
222 case ERR_EBADSTATE:
223 return -EINVAL;
224 case ERR_ENOMEM:
225 return -ENOMEM;
226 case ERR_ETIMEDOUT:
227 return -ETIMEDOUT;
228 case ERR_ELINKDOWN:
229 return -ENETDOWN;
230 case ERR_EINPROGRESS:
231 return -EINPROGRESS;
232 case ERR_EMAXRES:
233 default:
234 return (devcmd_status < 0) ? devcmd_status : -1;