blob: f8d2a6a34282d4dc481d3af21a8dce35788bd24f [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
Tony Camuso8e091342014-06-23 16:08:03 +053032 spin_lock_bh(&enic->devcmd_lock);
Vasanthy Kolluri51987462011-02-04 16:17:05 +000033 err = vnic_dev_fw_info(enic->vdev, fw_info);
Tony Camuso8e091342014-06-23 16:08:03 +053034 spin_unlock_bh(&enic->devcmd_lock);
Vasanthy Kolluri51987462011-02-04 16:17:05 +000035
36 return err;
37}
38
39int enic_dev_stats_dump(struct enic *enic, struct vnic_stats **vstats)
40{
41 int err;
42
Tony Camuso8e091342014-06-23 16:08:03 +053043 spin_lock_bh(&enic->devcmd_lock);
Vasanthy Kolluri51987462011-02-04 16:17:05 +000044 err = vnic_dev_stats_dump(enic->vdev, vstats);
Tony Camuso8e091342014-06-23 16:08:03 +053045 spin_unlock_bh(&enic->devcmd_lock);
Vasanthy Kolluri51987462011-02-04 16:17:05 +000046
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
Tony Camuso8e091342014-06-23 16:08:03 +053057 spin_lock_bh(&enic->devcmd_lock);
Vasanthy Kolluri115d56f2011-02-04 16:17:10 +000058 err = vnic_dev_add_addr(enic->vdev, enic->netdev->dev_addr);
Tony Camuso8e091342014-06-23 16:08:03 +053059 spin_unlock_bh(&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
Tony Camuso8e091342014-06-23 16:08:03 +053071 spin_lock_bh(&enic->devcmd_lock);
Vasanthy Kolluri115d56f2011-02-04 16:17:10 +000072 err = vnic_dev_del_addr(enic->vdev, enic->netdev->dev_addr);
Tony Camuso8e091342014-06-23 16:08:03 +053073 spin_unlock_bh(&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
Tony Camuso8e091342014-06-23 16:08:03 +053083 spin_lock_bh(&enic->devcmd_lock);
Vasanthy Kolluri51987462011-02-04 16:17:05 +000084 err = vnic_dev_packet_filter(enic->vdev, directed,
85 multicast, broadcast, promisc, allmulti);
Tony Camuso8e091342014-06-23 16:08:03 +053086 spin_unlock_bh(&enic->devcmd_lock);
Vasanthy Kolluri51987462011-02-04 16:17:05 +000087
88 return err;
89}
90
Alexander Duyckf0096182014-05-28 18:44:52 -070091int enic_dev_add_addr(struct enic *enic, const u8 *addr)
Vasanthy Kolluri51987462011-02-04 16:17:05 +000092{
93 int err;
94
Tony Camuso8e091342014-06-23 16:08:03 +053095 spin_lock_bh(&enic->devcmd_lock);
Vasanthy Kolluri51987462011-02-04 16:17:05 +000096 err = vnic_dev_add_addr(enic->vdev, addr);
Tony Camuso8e091342014-06-23 16:08:03 +053097 spin_unlock_bh(&enic->devcmd_lock);
Vasanthy Kolluri51987462011-02-04 16:17:05 +000098
99 return err;
100}
101
Alexander Duyckf0096182014-05-28 18:44:52 -0700102int enic_dev_del_addr(struct enic *enic, const u8 *addr)
Vasanthy Kolluri51987462011-02-04 16:17:05 +0000103{
104 int err;
105
Tony Camuso8e091342014-06-23 16:08:03 +0530106 spin_lock_bh(&enic->devcmd_lock);
Vasanthy Kolluri51987462011-02-04 16:17:05 +0000107 err = vnic_dev_del_addr(enic->vdev, addr);
Tony Camuso8e091342014-06-23 16:08:03 +0530108 spin_unlock_bh(&enic->devcmd_lock);
Vasanthy Kolluri51987462011-02-04 16:17:05 +0000109
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
Tony Camuso8e091342014-06-23 16:08:03 +0530117 spin_lock_bh(&enic->devcmd_lock);
Vasanthy Kolluri51987462011-02-04 16:17:05 +0000118 err = vnic_dev_notify_unset(enic->vdev);
Tony Camuso8e091342014-06-23 16:08:03 +0530119 spin_unlock_bh(&enic->devcmd_lock);
Vasanthy Kolluri51987462011-02-04 16:17:05 +0000120
121 return err;
122}
123
124int enic_dev_hang_notify(struct enic *enic)
125{
126 int err;
127
Tony Camuso8e091342014-06-23 16:08:03 +0530128 spin_lock_bh(&enic->devcmd_lock);
Vasanthy Kolluri51987462011-02-04 16:17:05 +0000129 err = vnic_dev_hang_notify(enic->vdev);
Tony Camuso8e091342014-06-23 16:08:03 +0530130 spin_unlock_bh(&enic->devcmd_lock);
Vasanthy Kolluri51987462011-02-04 16:17:05 +0000131
132 return err;
133}
134
135int enic_dev_set_ig_vlan_rewrite_mode(struct enic *enic)
136{
137 int err;
138
Tony Camuso8e091342014-06-23 16:08:03 +0530139 spin_lock_bh(&enic->devcmd_lock);
Vasanthy Kolluri51987462011-02-04 16:17:05 +0000140 err = vnic_dev_set_ig_vlan_rewrite_mode(enic->vdev,
141 IG_VLAN_REWRITE_MODE_PRIORITY_TAG_DEFAULT_VLAN);
Tony Camuso8e091342014-06-23 16:08:03 +0530142 spin_unlock_bh(&enic->devcmd_lock);
Vasanthy Kolluri51987462011-02-04 16:17:05 +0000143
144 return err;
145}
146
147int enic_dev_enable(struct enic *enic)
148{
149 int err;
150
Tony Camuso8e091342014-06-23 16:08:03 +0530151 spin_lock_bh(&enic->devcmd_lock);
Vasanthy Kolluri51987462011-02-04 16:17:05 +0000152 err = vnic_dev_enable_wait(enic->vdev);
Tony Camuso8e091342014-06-23 16:08:03 +0530153 spin_unlock_bh(&enic->devcmd_lock);
Vasanthy Kolluri51987462011-02-04 16:17:05 +0000154
155 return err;
156}
157
158int enic_dev_disable(struct enic *enic)
159{
160 int err;
161
Tony Camuso8e091342014-06-23 16:08:03 +0530162 spin_lock_bh(&enic->devcmd_lock);
Vasanthy Kolluri51987462011-02-04 16:17:05 +0000163 err = vnic_dev_disable(enic->vdev);
Tony Camuso8e091342014-06-23 16:08:03 +0530164 spin_unlock_bh(&enic->devcmd_lock);
Vasanthy Kolluri51987462011-02-04 16:17:05 +0000165
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
Tony Camuso8e091342014-06-23 16:08:03 +0530173 spin_lock_bh(&enic->devcmd_lock);
Vasanthy Kolluriea7ea652011-06-17 07:56:48 +0000174 err = vnic_dev_intr_coal_timer_info(enic->vdev);
Tony Camuso8e091342014-06-23 16:08:03 +0530175 spin_unlock_bh(&enic->devcmd_lock);
Vasanthy Kolluriea7ea652011-06-17 07:56:48 +0000176
177 return err;
178}
179
Vasanthy Kolluri51987462011-02-04 16:17:05 +0000180/* rtnl lock is held */
Patrick McHardy80d5c362013-04-19 02:04:28 +0000181int enic_vlan_rx_add_vid(struct net_device *netdev, __be16 proto, u16 vid)
Vasanthy Kolluri51987462011-02-04 16:17:05 +0000182{
183 struct enic *enic = netdev_priv(netdev);
Jiri Pirko8e586132011-12-08 19:52:37 -0500184 int err;
Vasanthy Kolluri51987462011-02-04 16:17:05 +0000185
Tony Camuso8e091342014-06-23 16:08:03 +0530186 spin_lock_bh(&enic->devcmd_lock);
Jiri Pirko8e586132011-12-08 19:52:37 -0500187 err = enic_add_vlan(enic, vid);
Tony Camuso8e091342014-06-23 16:08:03 +0530188 spin_unlock_bh(&enic->devcmd_lock);
Jiri Pirko8e586132011-12-08 19:52:37 -0500189
190 return err;
Vasanthy Kolluri51987462011-02-04 16:17:05 +0000191}
192
193/* rtnl lock is held */
Patrick McHardy80d5c362013-04-19 02:04:28 +0000194int enic_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto, u16 vid)
Vasanthy Kolluri51987462011-02-04 16:17:05 +0000195{
196 struct enic *enic = netdev_priv(netdev);
Jiri Pirko8e586132011-12-08 19:52:37 -0500197 int err;
Vasanthy Kolluri51987462011-02-04 16:17:05 +0000198
Tony Camuso8e091342014-06-23 16:08:03 +0530199 spin_lock_bh(&enic->devcmd_lock);
Jiri Pirko8e586132011-12-08 19:52:37 -0500200 err = enic_del_vlan(enic, vid);
Tony Camuso8e091342014-06-23 16:08:03 +0530201 spin_unlock_bh(&enic->devcmd_lock);
Jiri Pirko8e586132011-12-08 19:52:37 -0500202
203 return err;
Vasanthy Kolluri51987462011-02-04 16:17:05 +0000204}
Roopa Prabhu18714ff2011-03-29 20:35:56 +0000205
Roopa Prabhu18714ff2011-03-29 20:35:56 +0000206int enic_dev_status_to_errno(int devcmd_status)
207{
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;
235 }
236}