Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 28 | int enic_dev_fw_info(struct enic *enic, struct vnic_devcmd_fw_info **fw_info) |
| 29 | { |
| 30 | int err; |
| 31 | |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 32 | spin_lock_bh(&enic->devcmd_lock); |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 33 | err = vnic_dev_fw_info(enic->vdev, fw_info); |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 34 | spin_unlock_bh(&enic->devcmd_lock); |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 35 | |
| 36 | return err; |
| 37 | } |
| 38 | |
| 39 | int enic_dev_stats_dump(struct enic *enic, struct vnic_stats **vstats) |
| 40 | { |
| 41 | int err; |
| 42 | |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 43 | spin_lock_bh(&enic->devcmd_lock); |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 44 | err = vnic_dev_stats_dump(enic->vdev, vstats); |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 45 | spin_unlock_bh(&enic->devcmd_lock); |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 46 | |
| 47 | return err; |
| 48 | } |
| 49 | |
| 50 | int enic_dev_add_station_addr(struct enic *enic) |
| 51 | { |
Vasanthy Kolluri | 115d56f | 2011-02-04 16:17:10 +0000 | [diff] [blame] | 52 | int err; |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 53 | |
Vasanthy Kolluri | 115d56f | 2011-02-04 16:17:10 +0000 | [diff] [blame] | 54 | if (!is_valid_ether_addr(enic->netdev->dev_addr)) |
| 55 | return -EADDRNOTAVAIL; |
| 56 | |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 57 | spin_lock_bh(&enic->devcmd_lock); |
Vasanthy Kolluri | 115d56f | 2011-02-04 16:17:10 +0000 | [diff] [blame] | 58 | err = vnic_dev_add_addr(enic->vdev, enic->netdev->dev_addr); |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 59 | spin_unlock_bh(&enic->devcmd_lock); |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 60 | |
| 61 | return err; |
| 62 | } |
| 63 | |
| 64 | int enic_dev_del_station_addr(struct enic *enic) |
| 65 | { |
Vasanthy Kolluri | 115d56f | 2011-02-04 16:17:10 +0000 | [diff] [blame] | 66 | int err; |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 67 | |
Vasanthy Kolluri | 115d56f | 2011-02-04 16:17:10 +0000 | [diff] [blame] | 68 | if (!is_valid_ether_addr(enic->netdev->dev_addr)) |
| 69 | return -EADDRNOTAVAIL; |
| 70 | |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 71 | spin_lock_bh(&enic->devcmd_lock); |
Vasanthy Kolluri | 115d56f | 2011-02-04 16:17:10 +0000 | [diff] [blame] | 72 | err = vnic_dev_del_addr(enic->vdev, enic->netdev->dev_addr); |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 73 | spin_unlock_bh(&enic->devcmd_lock); |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 74 | |
| 75 | return err; |
| 76 | } |
| 77 | |
| 78 | int enic_dev_packet_filter(struct enic *enic, int directed, int multicast, |
| 79 | int broadcast, int promisc, int allmulti) |
| 80 | { |
| 81 | int err; |
| 82 | |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 83 | spin_lock_bh(&enic->devcmd_lock); |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 84 | err = vnic_dev_packet_filter(enic->vdev, directed, |
| 85 | multicast, broadcast, promisc, allmulti); |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 86 | spin_unlock_bh(&enic->devcmd_lock); |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 87 | |
| 88 | return err; |
| 89 | } |
| 90 | |
Alexander Duyck | f009618 | 2014-05-28 18:44:52 -0700 | [diff] [blame] | 91 | int enic_dev_add_addr(struct enic *enic, const u8 *addr) |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 92 | { |
| 93 | int err; |
| 94 | |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 95 | spin_lock_bh(&enic->devcmd_lock); |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 96 | err = vnic_dev_add_addr(enic->vdev, addr); |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 97 | spin_unlock_bh(&enic->devcmd_lock); |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 98 | |
| 99 | return err; |
| 100 | } |
| 101 | |
Alexander Duyck | f009618 | 2014-05-28 18:44:52 -0700 | [diff] [blame] | 102 | int enic_dev_del_addr(struct enic *enic, const u8 *addr) |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 103 | { |
| 104 | int err; |
| 105 | |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 106 | spin_lock_bh(&enic->devcmd_lock); |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 107 | err = vnic_dev_del_addr(enic->vdev, addr); |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 108 | spin_unlock_bh(&enic->devcmd_lock); |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 109 | |
| 110 | return err; |
| 111 | } |
| 112 | |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 113 | int enic_dev_notify_unset(struct enic *enic) |
| 114 | { |
| 115 | int err; |
| 116 | |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 117 | spin_lock_bh(&enic->devcmd_lock); |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 118 | err = vnic_dev_notify_unset(enic->vdev); |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 119 | spin_unlock_bh(&enic->devcmd_lock); |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 120 | |
| 121 | return err; |
| 122 | } |
| 123 | |
| 124 | int enic_dev_hang_notify(struct enic *enic) |
| 125 | { |
| 126 | int err; |
| 127 | |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 128 | spin_lock_bh(&enic->devcmd_lock); |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 129 | err = vnic_dev_hang_notify(enic->vdev); |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 130 | spin_unlock_bh(&enic->devcmd_lock); |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 131 | |
| 132 | return err; |
| 133 | } |
| 134 | |
| 135 | int enic_dev_set_ig_vlan_rewrite_mode(struct enic *enic) |
| 136 | { |
| 137 | int err; |
| 138 | |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 139 | spin_lock_bh(&enic->devcmd_lock); |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 140 | err = vnic_dev_set_ig_vlan_rewrite_mode(enic->vdev, |
| 141 | IG_VLAN_REWRITE_MODE_PRIORITY_TAG_DEFAULT_VLAN); |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 142 | spin_unlock_bh(&enic->devcmd_lock); |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 143 | |
| 144 | return err; |
| 145 | } |
| 146 | |
| 147 | int enic_dev_enable(struct enic *enic) |
| 148 | { |
| 149 | int err; |
| 150 | |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 151 | spin_lock_bh(&enic->devcmd_lock); |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 152 | err = vnic_dev_enable_wait(enic->vdev); |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 153 | spin_unlock_bh(&enic->devcmd_lock); |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 154 | |
| 155 | return err; |
| 156 | } |
| 157 | |
| 158 | int enic_dev_disable(struct enic *enic) |
| 159 | { |
| 160 | int err; |
| 161 | |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 162 | spin_lock_bh(&enic->devcmd_lock); |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 163 | err = vnic_dev_disable(enic->vdev); |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 164 | spin_unlock_bh(&enic->devcmd_lock); |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 165 | |
| 166 | return err; |
| 167 | } |
| 168 | |
Vasanthy Kolluri | ea7ea65 | 2011-06-17 07:56:48 +0000 | [diff] [blame] | 169 | int enic_dev_intr_coal_timer_info(struct enic *enic) |
| 170 | { |
| 171 | int err; |
| 172 | |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 173 | spin_lock_bh(&enic->devcmd_lock); |
Vasanthy Kolluri | ea7ea65 | 2011-06-17 07:56:48 +0000 | [diff] [blame] | 174 | err = vnic_dev_intr_coal_timer_info(enic->vdev); |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 175 | spin_unlock_bh(&enic->devcmd_lock); |
Vasanthy Kolluri | ea7ea65 | 2011-06-17 07:56:48 +0000 | [diff] [blame] | 176 | |
| 177 | return err; |
| 178 | } |
| 179 | |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 180 | /* rtnl lock is held */ |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 181 | int enic_vlan_rx_add_vid(struct net_device *netdev, __be16 proto, u16 vid) |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 182 | { |
| 183 | struct enic *enic = netdev_priv(netdev); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 184 | int err; |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 185 | |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 186 | spin_lock_bh(&enic->devcmd_lock); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 187 | err = enic_add_vlan(enic, vid); |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 188 | spin_unlock_bh(&enic->devcmd_lock); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 189 | |
| 190 | return err; |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | /* rtnl lock is held */ |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 194 | int enic_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto, u16 vid) |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 195 | { |
| 196 | struct enic *enic = netdev_priv(netdev); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 197 | int err; |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 198 | |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 199 | spin_lock_bh(&enic->devcmd_lock); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 200 | err = enic_del_vlan(enic, vid); |
Tony Camuso | 8e09134 | 2014-06-23 16:08:03 +0530 | [diff] [blame] | 201 | spin_unlock_bh(&enic->devcmd_lock); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 202 | |
| 203 | return err; |
Vasanthy Kolluri | 5198746 | 2011-02-04 16:17:05 +0000 | [diff] [blame] | 204 | } |
Roopa Prabhu | 18714ff | 2011-03-29 20:35:56 +0000 | [diff] [blame] | 205 | |
Roopa Prabhu | 18714ff | 2011-03-29 20:35:56 +0000 | [diff] [blame] | 206 | int 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 | } |