blob: fd6247b3c0ee4dd4d105b7d1a827f2bd3e40d906 [file] [log] [blame]
Vasanthy Kolluri51987462011-02-04 16:17:05 +00001/*
2 * Copyright 2011 Cisco Systems, Inc. All rights reserved.
3 *
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.
7 *
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.
16 *
17 */
18
19#include <linux/pci.h>
20#include <linux/etherdevice.h>
21
22#include "vnic_dev.h"
23#include "vnic_vic.h"
24#include "enic_res.h"
25#include "enic.h"
26#include "enic_dev.h"
27
28int enic_dev_fw_info(struct enic *enic, struct vnic_devcmd_fw_info **fw_info)
29{
30 int err;
31
32 spin_lock(&enic->devcmd_lock);
33 err = vnic_dev_fw_info(enic->vdev, fw_info);
34 spin_unlock(&enic->devcmd_lock);
35
36 return err;
37}
38
39int enic_dev_stats_dump(struct enic *enic, struct vnic_stats **vstats)
40{
41 int err;
42
43 spin_lock(&enic->devcmd_lock);
44 err = vnic_dev_stats_dump(enic->vdev, vstats);
45 spin_unlock(&enic->devcmd_lock);
46
47 return err;
48}
49
50int enic_dev_add_station_addr(struct enic *enic)
51{
Vasanthy Kolluri115d56f2011-02-04 16:17:10 +000052 int err;
Vasanthy Kolluri51987462011-02-04 16:17:05 +000053
Vasanthy Kolluri115d56f2011-02-04 16:17:10 +000054 if (!is_valid_ether_addr(enic->netdev->dev_addr))
55 return -EADDRNOTAVAIL;
56
57 spin_lock(&enic->devcmd_lock);
58 err = vnic_dev_add_addr(enic->vdev, enic->netdev->dev_addr);
59 spin_unlock(&enic->devcmd_lock);
Vasanthy Kolluri51987462011-02-04 16:17:05 +000060
61 return err;
62}
63
64int enic_dev_del_station_addr(struct enic *enic)
65{
Vasanthy Kolluri115d56f2011-02-04 16:17:10 +000066 int err;
Vasanthy Kolluri51987462011-02-04 16:17:05 +000067
Vasanthy Kolluri115d56f2011-02-04 16:17:10 +000068 if (!is_valid_ether_addr(enic->netdev->dev_addr))
69 return -EADDRNOTAVAIL;
70
71 spin_lock(&enic->devcmd_lock);
72 err = vnic_dev_del_addr(enic->vdev, enic->netdev->dev_addr);
73 spin_unlock(&enic->devcmd_lock);
Vasanthy Kolluri51987462011-02-04 16:17:05 +000074
75 return err;
76}
77
78int enic_dev_packet_filter(struct enic *enic, int directed, int multicast,
79 int broadcast, int promisc, int allmulti)
80{
81 int err;
82
83 spin_lock(&enic->devcmd_lock);
84 err = vnic_dev_packet_filter(enic->vdev, directed,
85 multicast, broadcast, promisc, allmulti);
86 spin_unlock(&enic->devcmd_lock);
87
88 return err;
89}
90
91int enic_dev_add_addr(struct enic *enic, u8 *addr)
92{
93 int err;
94
95 spin_lock(&enic->devcmd_lock);
96 err = vnic_dev_add_addr(enic->vdev, addr);
97 spin_unlock(&enic->devcmd_lock);
98
99 return err;
100}
101
102int enic_dev_del_addr(struct enic *enic, u8 *addr)
103{
104 int err;
105
106 spin_lock(&enic->devcmd_lock);
107 err = vnic_dev_del_addr(enic->vdev, addr);
108 spin_unlock(&enic->devcmd_lock);
109
110 return err;
111}
112
Vasanthy Kolluri51987462011-02-04 16:17:05 +0000113int enic_dev_notify_unset(struct enic *enic)
114{
115 int err;
116
117 spin_lock(&enic->devcmd_lock);
118 err = vnic_dev_notify_unset(enic->vdev);
119 spin_unlock(&enic->devcmd_lock);
120
121 return err;
122}
123
124int enic_dev_hang_notify(struct enic *enic)
125{
126 int err;
127
128 spin_lock(&enic->devcmd_lock);
129 err = vnic_dev_hang_notify(enic->vdev);
130 spin_unlock(&enic->devcmd_lock);
131
132 return err;
133}
134
135int enic_dev_set_ig_vlan_rewrite_mode(struct enic *enic)
136{
137 int err;
138
139 spin_lock(&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(&enic->devcmd_lock);
143
144 return err;
145}
146
147int enic_dev_enable(struct enic *enic)
148{
149 int err;
150
151 spin_lock(&enic->devcmd_lock);
152 err = vnic_dev_enable_wait(enic->vdev);
153 spin_unlock(&enic->devcmd_lock);
154
155 return err;
156}
157
158int enic_dev_disable(struct enic *enic)
159{
160 int err;
161
162 spin_lock(&enic->devcmd_lock);
163 err = vnic_dev_disable(enic->vdev);
164 spin_unlock(&enic->devcmd_lock);
165
166 return err;
167}
168
Vasanthy Kolluriea7ea652011-06-17 07:56:48 +0000169int enic_dev_intr_coal_timer_info(struct enic *enic)
170{
171 int err;
172
173 spin_lock(&enic->devcmd_lock);
174 err = vnic_dev_intr_coal_timer_info(enic->vdev);
175 spin_unlock(&enic->devcmd_lock);
176
177 return err;
178}
179
Vasanthy Kolluri51987462011-02-04 16:17:05 +0000180int enic_vnic_dev_deinit(struct enic *enic)
181{
182 int err;
183
184 spin_lock(&enic->devcmd_lock);
185 err = vnic_dev_deinit(enic->vdev);
186 spin_unlock(&enic->devcmd_lock);
187
188 return err;
189}
190
Roopa Prabhu18714ff2011-03-29 20:35:56 +0000191int enic_dev_init_prov2(struct enic *enic, struct vic_provinfo *vp)
Vasanthy Kolluri51987462011-02-04 16:17:05 +0000192{
193 int err;
194
195 spin_lock(&enic->devcmd_lock);
Roopa Prabhu18714ff2011-03-29 20:35:56 +0000196 err = vnic_dev_init_prov2(enic->vdev,
Vasanthy Kolluri51987462011-02-04 16:17:05 +0000197 (u8 *)vp, vic_provinfo_size(vp));
198 spin_unlock(&enic->devcmd_lock);
199
200 return err;
201}
202
Roopa Prabhu18714ff2011-03-29 20:35:56 +0000203int enic_dev_deinit_done(struct enic *enic, int *status)
Vasanthy Kolluri51987462011-02-04 16:17:05 +0000204{
205 int err;
206
207 spin_lock(&enic->devcmd_lock);
Roopa Prabhu18714ff2011-03-29 20:35:56 +0000208 err = vnic_dev_deinit_done(enic->vdev, status);
Vasanthy Kolluri51987462011-02-04 16:17:05 +0000209 spin_unlock(&enic->devcmd_lock);
210
211 return err;
212}
213
214/* rtnl lock is held */
215void enic_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
216{
217 struct enic *enic = netdev_priv(netdev);
218
219 spin_lock(&enic->devcmd_lock);
220 enic_add_vlan(enic, vid);
221 spin_unlock(&enic->devcmd_lock);
222}
223
224/* rtnl lock is held */
225void enic_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
226{
227 struct enic *enic = netdev_priv(netdev);
228
229 spin_lock(&enic->devcmd_lock);
230 enic_del_vlan(enic, vid);
231 spin_unlock(&enic->devcmd_lock);
232}
Roopa Prabhu18714ff2011-03-29 20:35:56 +0000233
234int enic_dev_enable2(struct enic *enic, int active)
235{
236 int err;
237
238 spin_lock(&enic->devcmd_lock);
239 err = vnic_dev_enable2(enic->vdev, active);
240 spin_unlock(&enic->devcmd_lock);
241
242 return err;
243}
244
245int enic_dev_enable2_done(struct enic *enic, int *status)
246{
247 int err;
248
249 spin_lock(&enic->devcmd_lock);
250 err = vnic_dev_enable2_done(enic->vdev, status);
251 spin_unlock(&enic->devcmd_lock);
252
253 return err;
254}
255
256int enic_dev_status_to_errno(int devcmd_status)
257{
258 switch (devcmd_status) {
259 case ERR_SUCCESS:
260 return 0;
261 case ERR_EINVAL:
262 return -EINVAL;
263 case ERR_EFAULT:
264 return -EFAULT;
265 case ERR_EPERM:
266 return -EPERM;
267 case ERR_EBUSY:
268 return -EBUSY;
269 case ERR_ECMDUNKNOWN:
270 case ERR_ENOTSUPPORTED:
271 return -EOPNOTSUPP;
272 case ERR_EBADSTATE:
273 return -EINVAL;
274 case ERR_ENOMEM:
275 return -ENOMEM;
276 case ERR_ETIMEDOUT:
277 return -ETIMEDOUT;
278 case ERR_ELINKDOWN:
279 return -ENETDOWN;
280 case ERR_EINPROGRESS:
281 return -EINPROGRESS;
282 case ERR_EMAXRES:
283 default:
284 return (devcmd_status < 0) ? devcmd_status : -1;
285 }
286}