Jitendra Kalsaria | 577ae39 | 2013-02-04 12:33:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * QLogic qlcnic NIC Driver |
| 3 | * Copyright (c) 2009-2013 QLogic Corporation |
| 4 | * |
| 5 | * See LICENSE.qlcnic for copyright and licensing details. |
| 6 | */ |
| 7 | |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 8 | #include <linux/slab.h> |
| 9 | #include <linux/vmalloc.h> |
| 10 | #include <linux/interrupt.h> |
| 11 | |
| 12 | #include "qlcnic.h" |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 13 | #include "qlcnic_hw.h" |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 14 | |
| 15 | #include <linux/swab.h> |
| 16 | #include <linux/dma-mapping.h> |
| 17 | #include <net/ip.h> |
| 18 | #include <linux/ipv6.h> |
| 19 | #include <linux/inetdevice.h> |
| 20 | #include <linux/sysfs.h> |
| 21 | #include <linux/aer.h> |
| 22 | #include <linux/log2.h> |
| 23 | |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 24 | #define QLC_STATUS_UNSUPPORTED_CMD -2 |
| 25 | |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 26 | int qlcnicvf_config_bridged_mode(struct qlcnic_adapter *adapter, u32 enable) |
| 27 | { |
| 28 | return -EOPNOTSUPP; |
| 29 | } |
| 30 | |
| 31 | int qlcnicvf_config_led(struct qlcnic_adapter *adapter, u32 state, u32 rate) |
| 32 | { |
| 33 | return -EOPNOTSUPP; |
| 34 | } |
| 35 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 36 | static ssize_t qlcnic_store_bridged_mode(struct device *dev, |
| 37 | struct device_attribute *attr, |
| 38 | const char *buf, size_t len) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 39 | { |
| 40 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 41 | unsigned long new; |
| 42 | int ret = -EINVAL; |
| 43 | |
Sony Chacko | 7978845 | 2012-12-04 03:33:53 +0000 | [diff] [blame] | 44 | if (!(adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_BDG)) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 45 | goto err_out; |
| 46 | |
| 47 | if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) |
| 48 | goto err_out; |
| 49 | |
Jingoo Han | 67d6bfa | 2013-05-31 21:21:35 +0000 | [diff] [blame] | 50 | if (kstrtoul(buf, 2, &new)) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 51 | goto err_out; |
| 52 | |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 53 | if (!qlcnic_config_bridged_mode(adapter, !!new)) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 54 | ret = len; |
| 55 | |
| 56 | err_out: |
| 57 | return ret; |
| 58 | } |
| 59 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 60 | static ssize_t qlcnic_show_bridged_mode(struct device *dev, |
| 61 | struct device_attribute *attr, |
| 62 | char *buf) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 63 | { |
| 64 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 65 | int bridged_mode = 0; |
| 66 | |
Sony Chacko | 7978845 | 2012-12-04 03:33:53 +0000 | [diff] [blame] | 67 | if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_BDG) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 68 | bridged_mode = !!(adapter->flags & QLCNIC_BRIDGE_ENABLED); |
| 69 | |
| 70 | return sprintf(buf, "%d\n", bridged_mode); |
| 71 | } |
| 72 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 73 | static ssize_t qlcnic_store_diag_mode(struct device *dev, |
| 74 | struct device_attribute *attr, |
| 75 | const char *buf, size_t len) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 76 | { |
| 77 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 78 | unsigned long new; |
| 79 | |
Jingoo Han | 67d6bfa | 2013-05-31 21:21:35 +0000 | [diff] [blame] | 80 | if (kstrtoul(buf, 2, &new)) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 81 | return -EINVAL; |
| 82 | |
| 83 | if (!!new != !!(adapter->flags & QLCNIC_DIAG_ENABLED)) |
| 84 | adapter->flags ^= QLCNIC_DIAG_ENABLED; |
| 85 | |
| 86 | return len; |
| 87 | } |
| 88 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 89 | static ssize_t qlcnic_show_diag_mode(struct device *dev, |
| 90 | struct device_attribute *attr, char *buf) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 91 | { |
| 92 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 93 | return sprintf(buf, "%d\n", !!(adapter->flags & QLCNIC_DIAG_ENABLED)); |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 96 | static int qlcnic_validate_beacon(struct qlcnic_adapter *adapter, u16 beacon, |
| 97 | u8 *state, u8 *rate) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 98 | { |
| 99 | *rate = LSB(beacon); |
| 100 | *state = MSB(beacon); |
| 101 | |
| 102 | QLCDB(adapter, DRV, "rate %x state %x\n", *rate, *state); |
| 103 | |
| 104 | if (!*state) { |
| 105 | *rate = __QLCNIC_MAX_LED_RATE; |
| 106 | return 0; |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 107 | } else if (*state > __QLCNIC_MAX_LED_STATE) { |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 108 | return -EINVAL; |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 109 | } |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 110 | |
| 111 | if ((!*rate) || (*rate > __QLCNIC_MAX_LED_RATE)) |
| 112 | return -EINVAL; |
| 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | |
Himanshu Madhani | 487042a | 2013-05-23 21:04:33 +0000 | [diff] [blame] | 117 | static int qlcnic_83xx_store_beacon(struct qlcnic_adapter *adapter, |
| 118 | const char *buf, size_t len) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 119 | { |
Himanshu Madhani | 487042a | 2013-05-23 21:04:33 +0000 | [diff] [blame] | 120 | struct qlcnic_hardware_context *ahw = adapter->ahw; |
| 121 | unsigned long h_beacon; |
| 122 | int err; |
| 123 | |
| 124 | if (test_bit(__QLCNIC_RESETTING, &adapter->state)) |
| 125 | return -EIO; |
| 126 | |
| 127 | if (kstrtoul(buf, 2, &h_beacon)) |
| 128 | return -EINVAL; |
| 129 | |
| 130 | if (ahw->beacon_state == h_beacon) |
| 131 | return len; |
| 132 | |
| 133 | rtnl_lock(); |
| 134 | if (!ahw->beacon_state) { |
| 135 | if (test_and_set_bit(__QLCNIC_LED_ENABLE, &adapter->state)) { |
| 136 | rtnl_unlock(); |
| 137 | return -EBUSY; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | if (h_beacon) |
| 142 | err = qlcnic_83xx_config_led(adapter, 1, h_beacon); |
| 143 | else |
| 144 | err = qlcnic_83xx_config_led(adapter, 0, !h_beacon); |
| 145 | if (!err) |
| 146 | ahw->beacon_state = h_beacon; |
| 147 | |
| 148 | if (!ahw->beacon_state) |
| 149 | clear_bit(__QLCNIC_LED_ENABLE, &adapter->state); |
| 150 | |
| 151 | rtnl_unlock(); |
| 152 | return len; |
| 153 | } |
| 154 | |
| 155 | static int qlcnic_82xx_store_beacon(struct qlcnic_adapter *adapter, |
| 156 | const char *buf, size_t len) |
| 157 | { |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 158 | struct qlcnic_hardware_context *ahw = adapter->ahw; |
| 159 | int err, max_sds_rings = adapter->max_sds_rings; |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 160 | u16 beacon; |
Himanshu Madhani | 487042a | 2013-05-23 21:04:33 +0000 | [diff] [blame] | 161 | u8 h_beacon_state, b_state, b_rate; |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 162 | |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 163 | if (len != sizeof(u16)) |
| 164 | return QL_STATUS_INVALID_PARAM; |
| 165 | |
| 166 | memcpy(&beacon, buf, sizeof(u16)); |
| 167 | err = qlcnic_validate_beacon(adapter, beacon, &b_state, &b_rate); |
| 168 | if (err) |
| 169 | return err; |
| 170 | |
Pratik Pujar | db13178 | 2013-06-22 04:12:04 -0400 | [diff] [blame] | 171 | if (ahw->extra_capability[0] & QLCNIC_FW_CAPABILITY_2_BEACON) { |
Himanshu Madhani | 487042a | 2013-05-23 21:04:33 +0000 | [diff] [blame] | 172 | err = qlcnic_get_beacon_state(adapter, &h_beacon_state); |
Sucheta Chakraborty | 482b3c3 | 2013-08-15 08:29:28 -0400 | [diff] [blame] | 173 | if (err) { |
| 174 | netdev_err(adapter->netdev, |
| 175 | "Failed to get current beacon state\n"); |
Himanshu Madhani | 487042a | 2013-05-23 21:04:33 +0000 | [diff] [blame] | 176 | } else { |
| 177 | if (h_beacon_state == QLCNIC_BEACON_DISABLE) |
| 178 | ahw->beacon_state = 0; |
| 179 | else if (h_beacon_state == QLCNIC_BEACON_EANBLE) |
| 180 | ahw->beacon_state = 2; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | if (ahw->beacon_state == b_state) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 185 | return len; |
| 186 | |
| 187 | rtnl_lock(); |
Himanshu Madhani | 487042a | 2013-05-23 21:04:33 +0000 | [diff] [blame] | 188 | if (!ahw->beacon_state) { |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 189 | if (test_and_set_bit(__QLCNIC_LED_ENABLE, &adapter->state)) { |
| 190 | rtnl_unlock(); |
| 191 | return -EBUSY; |
| 192 | } |
Himanshu Madhani | 487042a | 2013-05-23 21:04:33 +0000 | [diff] [blame] | 193 | } |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 194 | |
| 195 | if (test_bit(__QLCNIC_RESETTING, &adapter->state)) { |
| 196 | err = -EIO; |
| 197 | goto out; |
| 198 | } |
| 199 | |
| 200 | if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) { |
| 201 | err = qlcnic_diag_alloc_res(adapter->netdev, QLCNIC_LED_TEST); |
| 202 | if (err) |
| 203 | goto out; |
| 204 | set_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state); |
| 205 | } |
| 206 | |
| 207 | err = qlcnic_config_led(adapter, b_state, b_rate); |
Himanshu Madhani | 361cd29 | 2013-04-16 18:11:10 +0000 | [diff] [blame] | 208 | if (!err) { |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 209 | err = len; |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 210 | ahw->beacon_state = b_state; |
Himanshu Madhani | 361cd29 | 2013-04-16 18:11:10 +0000 | [diff] [blame] | 211 | } |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 212 | |
| 213 | if (test_and_clear_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state)) |
| 214 | qlcnic_diag_free_res(adapter->netdev, max_sds_rings); |
| 215 | |
Himanshu Madhani | 487042a | 2013-05-23 21:04:33 +0000 | [diff] [blame] | 216 | out: |
| 217 | if (!ahw->beacon_state) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 218 | clear_bit(__QLCNIC_LED_ENABLE, &adapter->state); |
| 219 | rtnl_unlock(); |
| 220 | |
| 221 | return err; |
| 222 | } |
| 223 | |
Himanshu Madhani | 487042a | 2013-05-23 21:04:33 +0000 | [diff] [blame] | 224 | static ssize_t qlcnic_store_beacon(struct device *dev, |
| 225 | struct device_attribute *attr, |
| 226 | const char *buf, size_t len) |
| 227 | { |
| 228 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 229 | int err = 0; |
| 230 | |
| 231 | if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC) { |
| 232 | dev_warn(dev, |
| 233 | "LED test not supported in non privileged mode\n"); |
| 234 | return -EOPNOTSUPP; |
| 235 | } |
| 236 | |
| 237 | if (qlcnic_82xx_check(adapter)) |
| 238 | err = qlcnic_82xx_store_beacon(adapter, buf, len); |
| 239 | else if (qlcnic_83xx_check(adapter)) |
| 240 | err = qlcnic_83xx_store_beacon(adapter, buf, len); |
| 241 | else |
| 242 | return -EIO; |
| 243 | |
| 244 | return err; |
| 245 | } |
| 246 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 247 | static ssize_t qlcnic_show_beacon(struct device *dev, |
| 248 | struct device_attribute *attr, char *buf) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 249 | { |
| 250 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 251 | |
| 252 | return sprintf(buf, "%d\n", adapter->ahw->beacon_state); |
| 253 | } |
| 254 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 255 | static int qlcnic_sysfs_validate_crb(struct qlcnic_adapter *adapter, |
| 256 | loff_t offset, size_t size) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 257 | { |
| 258 | size_t crb_size = 4; |
| 259 | |
| 260 | if (!(adapter->flags & QLCNIC_DIAG_ENABLED)) |
| 261 | return -EIO; |
| 262 | |
| 263 | if (offset < QLCNIC_PCI_CRBSPACE) { |
| 264 | if (ADDR_IN_RANGE(offset, QLCNIC_PCI_CAMQM, |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 265 | QLCNIC_PCI_CAMQM_END)) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 266 | crb_size = 8; |
| 267 | else |
| 268 | return -EINVAL; |
| 269 | } |
| 270 | |
| 271 | if ((size != crb_size) || (offset & (crb_size-1))) |
| 272 | return -EINVAL; |
| 273 | |
| 274 | return 0; |
| 275 | } |
| 276 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 277 | static ssize_t qlcnic_sysfs_read_crb(struct file *filp, struct kobject *kobj, |
| 278 | struct bin_attribute *attr, char *buf, |
| 279 | loff_t offset, size_t size) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 280 | { |
| 281 | struct device *dev = container_of(kobj, struct device, kobj); |
| 282 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 283 | int ret; |
| 284 | |
| 285 | ret = qlcnic_sysfs_validate_crb(adapter, offset, size); |
| 286 | if (ret != 0) |
| 287 | return ret; |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 288 | qlcnic_read_crb(adapter, buf, offset, size); |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 289 | |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 290 | return size; |
| 291 | } |
| 292 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 293 | static ssize_t qlcnic_sysfs_write_crb(struct file *filp, struct kobject *kobj, |
| 294 | struct bin_attribute *attr, char *buf, |
| 295 | loff_t offset, size_t size) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 296 | { |
| 297 | struct device *dev = container_of(kobj, struct device, kobj); |
| 298 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 299 | int ret; |
| 300 | |
| 301 | ret = qlcnic_sysfs_validate_crb(adapter, offset, size); |
| 302 | if (ret != 0) |
| 303 | return ret; |
| 304 | |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 305 | qlcnic_write_crb(adapter, buf, offset, size); |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 306 | return size; |
| 307 | } |
| 308 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 309 | static int qlcnic_sysfs_validate_mem(struct qlcnic_adapter *adapter, |
| 310 | loff_t offset, size_t size) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 311 | { |
| 312 | if (!(adapter->flags & QLCNIC_DIAG_ENABLED)) |
| 313 | return -EIO; |
| 314 | |
| 315 | if ((size != 8) || (offset & 0x7)) |
| 316 | return -EIO; |
| 317 | |
| 318 | return 0; |
| 319 | } |
| 320 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 321 | static ssize_t qlcnic_sysfs_read_mem(struct file *filp, struct kobject *kobj, |
| 322 | struct bin_attribute *attr, char *buf, |
| 323 | loff_t offset, size_t size) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 324 | { |
| 325 | struct device *dev = container_of(kobj, struct device, kobj); |
| 326 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 327 | u64 data; |
| 328 | int ret; |
| 329 | |
| 330 | ret = qlcnic_sysfs_validate_mem(adapter, offset, size); |
| 331 | if (ret != 0) |
| 332 | return ret; |
| 333 | |
| 334 | if (qlcnic_pci_mem_read_2M(adapter, offset, &data)) |
| 335 | return -EIO; |
| 336 | |
| 337 | memcpy(buf, &data, size); |
| 338 | |
| 339 | return size; |
| 340 | } |
| 341 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 342 | static ssize_t qlcnic_sysfs_write_mem(struct file *filp, struct kobject *kobj, |
| 343 | struct bin_attribute *attr, char *buf, |
| 344 | loff_t offset, size_t size) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 345 | { |
| 346 | struct device *dev = container_of(kobj, struct device, kobj); |
| 347 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 348 | u64 data; |
| 349 | int ret; |
| 350 | |
| 351 | ret = qlcnic_sysfs_validate_mem(adapter, offset, size); |
| 352 | if (ret != 0) |
| 353 | return ret; |
| 354 | |
| 355 | memcpy(&data, buf, size); |
| 356 | |
| 357 | if (qlcnic_pci_mem_write_2M(adapter, offset, data)) |
| 358 | return -EIO; |
| 359 | |
| 360 | return size; |
| 361 | } |
| 362 | |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 363 | static int qlcnic_is_valid_nic_func(struct qlcnic_adapter *adapter, u8 pci_func) |
| 364 | { |
| 365 | int i; |
| 366 | for (i = 0; i < adapter->ahw->act_pci_func; i++) { |
| 367 | if (adapter->npars[i].pci_func == pci_func) |
| 368 | return i; |
| 369 | } |
| 370 | |
| 371 | return -1; |
| 372 | } |
| 373 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 374 | static int validate_pm_config(struct qlcnic_adapter *adapter, |
| 375 | struct qlcnic_pm_func_cfg *pm_cfg, int count) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 376 | { |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 377 | u8 src_pci_func, s_esw_id, d_esw_id; |
| 378 | u8 dest_pci_func; |
| 379 | int i, src_index, dest_index; |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 380 | |
| 381 | for (i = 0; i < count; i++) { |
| 382 | src_pci_func = pm_cfg[i].pci_func; |
| 383 | dest_pci_func = pm_cfg[i].dest_npar; |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 384 | src_index = qlcnic_is_valid_nic_func(adapter, src_pci_func); |
| 385 | |
| 386 | if (src_index < 0) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 387 | return QL_STATUS_INVALID_PARAM; |
| 388 | |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 389 | dest_index = qlcnic_is_valid_nic_func(adapter, dest_pci_func); |
| 390 | if (dest_index < 0) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 391 | return QL_STATUS_INVALID_PARAM; |
| 392 | |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 393 | s_esw_id = adapter->npars[src_index].phy_port; |
| 394 | d_esw_id = adapter->npars[dest_index].phy_port; |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 395 | |
| 396 | if (s_esw_id != d_esw_id) |
| 397 | return QL_STATUS_INVALID_PARAM; |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 398 | } |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 399 | |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 400 | return 0; |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 401 | } |
| 402 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 403 | static ssize_t qlcnic_sysfs_write_pm_config(struct file *filp, |
| 404 | struct kobject *kobj, |
| 405 | struct bin_attribute *attr, |
| 406 | char *buf, loff_t offset, |
| 407 | size_t size) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 408 | { |
| 409 | struct device *dev = container_of(kobj, struct device, kobj); |
| 410 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 411 | struct qlcnic_pm_func_cfg *pm_cfg; |
| 412 | u32 id, action, pci_func; |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 413 | int count, rem, i, ret, index; |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 414 | |
| 415 | count = size / sizeof(struct qlcnic_pm_func_cfg); |
| 416 | rem = size % sizeof(struct qlcnic_pm_func_cfg); |
| 417 | if (rem) |
| 418 | return QL_STATUS_INVALID_PARAM; |
| 419 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 420 | pm_cfg = (struct qlcnic_pm_func_cfg *)buf; |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 421 | ret = validate_pm_config(adapter, pm_cfg, count); |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 422 | |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 423 | if (ret) |
| 424 | return ret; |
| 425 | for (i = 0; i < count; i++) { |
| 426 | pci_func = pm_cfg[i].pci_func; |
| 427 | action = !!pm_cfg[i].action; |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 428 | index = qlcnic_is_valid_nic_func(adapter, pci_func); |
| 429 | if (index < 0) |
| 430 | return QL_STATUS_INVALID_PARAM; |
| 431 | |
| 432 | id = adapter->npars[index].phy_port; |
| 433 | ret = qlcnic_config_port_mirroring(adapter, id, |
| 434 | action, pci_func); |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 435 | if (ret) |
| 436 | return ret; |
| 437 | } |
| 438 | |
| 439 | for (i = 0; i < count; i++) { |
| 440 | pci_func = pm_cfg[i].pci_func; |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 441 | index = qlcnic_is_valid_nic_func(adapter, pci_func); |
| 442 | id = adapter->npars[index].phy_port; |
| 443 | adapter->npars[index].enable_pm = !!pm_cfg[i].action; |
| 444 | adapter->npars[index].dest_npar = id; |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 445 | } |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 446 | |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 447 | return size; |
| 448 | } |
| 449 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 450 | static ssize_t qlcnic_sysfs_read_pm_config(struct file *filp, |
| 451 | struct kobject *kobj, |
| 452 | struct bin_attribute *attr, |
| 453 | char *buf, loff_t offset, |
| 454 | size_t size) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 455 | { |
| 456 | struct device *dev = container_of(kobj, struct device, kobj); |
| 457 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 458 | struct qlcnic_pm_func_cfg pm_cfg[QLCNIC_MAX_PCI_FUNC]; |
| 459 | int i; |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 460 | u8 pci_func; |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 461 | |
| 462 | if (size != sizeof(pm_cfg)) |
| 463 | return QL_STATUS_INVALID_PARAM; |
| 464 | |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 465 | memset(&pm_cfg, 0, |
| 466 | sizeof(struct qlcnic_pm_func_cfg) * QLCNIC_MAX_PCI_FUNC); |
| 467 | |
Sony Chacko | 35dafcb | 2013-08-30 13:51:23 -0400 | [diff] [blame^] | 468 | for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 469 | pci_func = adapter->npars[i].pci_func; |
Sony Chacko | 35dafcb | 2013-08-30 13:51:23 -0400 | [diff] [blame^] | 470 | if (!adapter->npars[i].active) |
| 471 | continue; |
| 472 | |
| 473 | if (!adapter->npars[i].eswitch_status) |
| 474 | continue; |
| 475 | |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 476 | pm_cfg[pci_func].action = adapter->npars[i].enable_pm; |
| 477 | pm_cfg[pci_func].dest_npar = 0; |
| 478 | pm_cfg[pci_func].pci_func = i; |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 479 | } |
| 480 | memcpy(buf, &pm_cfg, size); |
| 481 | |
| 482 | return size; |
| 483 | } |
| 484 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 485 | static int validate_esw_config(struct qlcnic_adapter *adapter, |
| 486 | struct qlcnic_esw_func_cfg *esw_cfg, int count) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 487 | { |
| 488 | u32 op_mode; |
| 489 | u8 pci_func; |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 490 | int i, ret; |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 491 | |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 492 | if (qlcnic_82xx_check(adapter)) |
| 493 | op_mode = readl(adapter->ahw->pci_base0 + QLCNIC_DRV_OP_MODE); |
| 494 | else |
| 495 | op_mode = QLCRDX(adapter->ahw, QLC_83XX_DRV_OP_MODE); |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 496 | |
| 497 | for (i = 0; i < count; i++) { |
| 498 | pci_func = esw_cfg[i].pci_func; |
| 499 | if (pci_func >= QLCNIC_MAX_PCI_FUNC) |
| 500 | return QL_STATUS_INVALID_PARAM; |
| 501 | |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 502 | if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC) |
| 503 | if (qlcnic_is_valid_nic_func(adapter, pci_func) < 0) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 504 | return QL_STATUS_INVALID_PARAM; |
| 505 | |
| 506 | switch (esw_cfg[i].op_mode) { |
| 507 | case QLCNIC_PORT_DEFAULTS: |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 508 | if (qlcnic_82xx_check(adapter)) { |
| 509 | ret = QLC_DEV_GET_DRV(op_mode, pci_func); |
| 510 | } else { |
| 511 | ret = QLC_83XX_GET_FUNC_PRIVILEGE(op_mode, |
| 512 | pci_func); |
| 513 | esw_cfg[i].offload_flags = 0; |
| 514 | } |
| 515 | |
| 516 | if (ret != QLCNIC_NON_PRIV_FUNC) { |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 517 | if (esw_cfg[i].mac_anti_spoof != 0) |
| 518 | return QL_STATUS_INVALID_PARAM; |
| 519 | if (esw_cfg[i].mac_override != 1) |
| 520 | return QL_STATUS_INVALID_PARAM; |
| 521 | if (esw_cfg[i].promisc_mode != 1) |
| 522 | return QL_STATUS_INVALID_PARAM; |
| 523 | } |
| 524 | break; |
| 525 | case QLCNIC_ADD_VLAN: |
| 526 | if (!IS_VALID_VLAN(esw_cfg[i].vlan_id)) |
| 527 | return QL_STATUS_INVALID_PARAM; |
| 528 | if (!esw_cfg[i].op_type) |
| 529 | return QL_STATUS_INVALID_PARAM; |
| 530 | break; |
| 531 | case QLCNIC_DEL_VLAN: |
| 532 | if (!esw_cfg[i].op_type) |
| 533 | return QL_STATUS_INVALID_PARAM; |
| 534 | break; |
| 535 | default: |
| 536 | return QL_STATUS_INVALID_PARAM; |
| 537 | } |
| 538 | } |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 539 | |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 540 | return 0; |
| 541 | } |
| 542 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 543 | static ssize_t qlcnic_sysfs_write_esw_config(struct file *file, |
| 544 | struct kobject *kobj, |
| 545 | struct bin_attribute *attr, |
| 546 | char *buf, loff_t offset, |
| 547 | size_t size) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 548 | { |
| 549 | struct device *dev = container_of(kobj, struct device, kobj); |
| 550 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 551 | struct qlcnic_esw_func_cfg *esw_cfg; |
| 552 | struct qlcnic_npar_info *npar; |
| 553 | int count, rem, i, ret; |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 554 | int index; |
| 555 | u8 op_mode = 0, pci_func; |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 556 | |
| 557 | count = size / sizeof(struct qlcnic_esw_func_cfg); |
| 558 | rem = size % sizeof(struct qlcnic_esw_func_cfg); |
| 559 | if (rem) |
| 560 | return QL_STATUS_INVALID_PARAM; |
| 561 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 562 | esw_cfg = (struct qlcnic_esw_func_cfg *)buf; |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 563 | ret = validate_esw_config(adapter, esw_cfg, count); |
| 564 | if (ret) |
| 565 | return ret; |
| 566 | |
| 567 | for (i = 0; i < count; i++) { |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 568 | if (adapter->ahw->op_mode == QLCNIC_MGMT_FUNC) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 569 | if (qlcnic_config_switch_port(adapter, &esw_cfg[i])) |
| 570 | return QL_STATUS_INVALID_PARAM; |
| 571 | |
| 572 | if (adapter->ahw->pci_func != esw_cfg[i].pci_func) |
| 573 | continue; |
| 574 | |
| 575 | op_mode = esw_cfg[i].op_mode; |
| 576 | qlcnic_get_eswitch_port_config(adapter, &esw_cfg[i]); |
| 577 | esw_cfg[i].op_mode = op_mode; |
| 578 | esw_cfg[i].pci_func = adapter->ahw->pci_func; |
| 579 | |
| 580 | switch (esw_cfg[i].op_mode) { |
| 581 | case QLCNIC_PORT_DEFAULTS: |
| 582 | qlcnic_set_eswitch_port_features(adapter, &esw_cfg[i]); |
Shahed Shaikh | 147a908 | 2013-05-21 09:27:01 +0000 | [diff] [blame] | 583 | rtnl_lock(); |
| 584 | qlcnic_set_netdev_features(adapter, &esw_cfg[i]); |
| 585 | rtnl_unlock(); |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 586 | break; |
| 587 | case QLCNIC_ADD_VLAN: |
| 588 | qlcnic_set_vlan_config(adapter, &esw_cfg[i]); |
| 589 | break; |
| 590 | case QLCNIC_DEL_VLAN: |
| 591 | esw_cfg[i].vlan_id = 0; |
| 592 | qlcnic_set_vlan_config(adapter, &esw_cfg[i]); |
| 593 | break; |
| 594 | } |
| 595 | } |
| 596 | |
Sony Chacko | 7978845 | 2012-12-04 03:33:53 +0000 | [diff] [blame] | 597 | if (adapter->ahw->op_mode != QLCNIC_MGMT_FUNC) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 598 | goto out; |
| 599 | |
| 600 | for (i = 0; i < count; i++) { |
| 601 | pci_func = esw_cfg[i].pci_func; |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 602 | index = qlcnic_is_valid_nic_func(adapter, pci_func); |
| 603 | npar = &adapter->npars[index]; |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 604 | switch (esw_cfg[i].op_mode) { |
| 605 | case QLCNIC_PORT_DEFAULTS: |
| 606 | npar->promisc_mode = esw_cfg[i].promisc_mode; |
| 607 | npar->mac_override = esw_cfg[i].mac_override; |
| 608 | npar->offload_flags = esw_cfg[i].offload_flags; |
| 609 | npar->mac_anti_spoof = esw_cfg[i].mac_anti_spoof; |
| 610 | npar->discard_tagged = esw_cfg[i].discard_tagged; |
| 611 | break; |
| 612 | case QLCNIC_ADD_VLAN: |
| 613 | npar->pvid = esw_cfg[i].vlan_id; |
| 614 | break; |
| 615 | case QLCNIC_DEL_VLAN: |
| 616 | npar->pvid = 0; |
| 617 | break; |
| 618 | } |
| 619 | } |
| 620 | out: |
| 621 | return size; |
| 622 | } |
| 623 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 624 | static ssize_t qlcnic_sysfs_read_esw_config(struct file *file, |
| 625 | struct kobject *kobj, |
| 626 | struct bin_attribute *attr, |
| 627 | char *buf, loff_t offset, |
| 628 | size_t size) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 629 | { |
| 630 | struct device *dev = container_of(kobj, struct device, kobj); |
| 631 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 632 | struct qlcnic_esw_func_cfg esw_cfg[QLCNIC_MAX_PCI_FUNC]; |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 633 | u8 i, pci_func; |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 634 | |
| 635 | if (size != sizeof(esw_cfg)) |
| 636 | return QL_STATUS_INVALID_PARAM; |
| 637 | |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 638 | memset(&esw_cfg, 0, |
| 639 | sizeof(struct qlcnic_esw_func_cfg) * QLCNIC_MAX_PCI_FUNC); |
| 640 | |
Sony Chacko | 35dafcb | 2013-08-30 13:51:23 -0400 | [diff] [blame^] | 641 | for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 642 | pci_func = adapter->npars[i].pci_func; |
Sony Chacko | 35dafcb | 2013-08-30 13:51:23 -0400 | [diff] [blame^] | 643 | if (!adapter->npars[i].active) |
| 644 | continue; |
| 645 | |
| 646 | if (!adapter->npars[i].eswitch_status) |
| 647 | continue; |
| 648 | |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 649 | esw_cfg[pci_func].pci_func = pci_func; |
| 650 | if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg[pci_func])) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 651 | return QL_STATUS_INVALID_PARAM; |
| 652 | } |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 653 | |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 654 | memcpy(buf, &esw_cfg, size); |
| 655 | |
| 656 | return size; |
| 657 | } |
| 658 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 659 | static int validate_npar_config(struct qlcnic_adapter *adapter, |
| 660 | struct qlcnic_npar_func_cfg *np_cfg, |
| 661 | int count) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 662 | { |
| 663 | u8 pci_func, i; |
| 664 | |
| 665 | for (i = 0; i < count; i++) { |
| 666 | pci_func = np_cfg[i].pci_func; |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 667 | if (qlcnic_is_valid_nic_func(adapter, pci_func) < 0) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 668 | return QL_STATUS_INVALID_PARAM; |
| 669 | |
| 670 | if (!IS_VALID_BW(np_cfg[i].min_bw) || |
| 671 | !IS_VALID_BW(np_cfg[i].max_bw)) |
| 672 | return QL_STATUS_INVALID_PARAM; |
| 673 | } |
| 674 | return 0; |
| 675 | } |
| 676 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 677 | static ssize_t qlcnic_sysfs_write_npar_config(struct file *file, |
| 678 | struct kobject *kobj, |
| 679 | struct bin_attribute *attr, |
| 680 | char *buf, loff_t offset, |
| 681 | size_t size) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 682 | { |
| 683 | struct device *dev = container_of(kobj, struct device, kobj); |
| 684 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 685 | struct qlcnic_info nic_info; |
| 686 | struct qlcnic_npar_func_cfg *np_cfg; |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 687 | int i, count, rem, ret, index; |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 688 | u8 pci_func; |
| 689 | |
| 690 | count = size / sizeof(struct qlcnic_npar_func_cfg); |
| 691 | rem = size % sizeof(struct qlcnic_npar_func_cfg); |
| 692 | if (rem) |
| 693 | return QL_STATUS_INVALID_PARAM; |
| 694 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 695 | np_cfg = (struct qlcnic_npar_func_cfg *)buf; |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 696 | ret = validate_npar_config(adapter, np_cfg, count); |
| 697 | if (ret) |
| 698 | return ret; |
| 699 | |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 700 | for (i = 0; i < count; i++) { |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 701 | pci_func = np_cfg[i].pci_func; |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 702 | |
| 703 | memset(&nic_info, 0, sizeof(struct qlcnic_info)); |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 704 | ret = qlcnic_get_nic_info(adapter, &nic_info, pci_func); |
| 705 | if (ret) |
| 706 | return ret; |
| 707 | nic_info.pci_func = pci_func; |
| 708 | nic_info.min_tx_bw = np_cfg[i].min_bw; |
| 709 | nic_info.max_tx_bw = np_cfg[i].max_bw; |
| 710 | ret = qlcnic_set_nic_info(adapter, &nic_info); |
| 711 | if (ret) |
| 712 | return ret; |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 713 | index = qlcnic_is_valid_nic_func(adapter, pci_func); |
| 714 | adapter->npars[index].min_bw = nic_info.min_tx_bw; |
| 715 | adapter->npars[index].max_bw = nic_info.max_tx_bw; |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | return size; |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 719 | } |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 720 | |
| 721 | static ssize_t qlcnic_sysfs_read_npar_config(struct file *file, |
| 722 | struct kobject *kobj, |
| 723 | struct bin_attribute *attr, |
| 724 | char *buf, loff_t offset, |
| 725 | size_t size) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 726 | { |
| 727 | struct device *dev = container_of(kobj, struct device, kobj); |
| 728 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 729 | struct qlcnic_info nic_info; |
| 730 | struct qlcnic_npar_func_cfg np_cfg[QLCNIC_MAX_PCI_FUNC]; |
| 731 | int i, ret; |
| 732 | |
| 733 | if (size != sizeof(np_cfg)) |
| 734 | return QL_STATUS_INVALID_PARAM; |
| 735 | |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 736 | memset(&nic_info, 0, sizeof(struct qlcnic_info)); |
| 737 | memset(&np_cfg, 0, |
| 738 | sizeof(struct qlcnic_npar_func_cfg) * QLCNIC_MAX_PCI_FUNC); |
| 739 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 740 | for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 741 | if (qlcnic_is_valid_nic_func(adapter, i) < 0) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 742 | continue; |
| 743 | ret = qlcnic_get_nic_info(adapter, &nic_info, i); |
| 744 | if (ret) |
| 745 | return ret; |
| 746 | |
Sony Chacko | 35dafcb | 2013-08-30 13:51:23 -0400 | [diff] [blame^] | 747 | if (!adapter->npars[i].eswitch_status) |
| 748 | continue; |
| 749 | |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 750 | np_cfg[i].pci_func = i; |
| 751 | np_cfg[i].op_mode = (u8)nic_info.op_mode; |
| 752 | np_cfg[i].port_num = nic_info.phys_port; |
| 753 | np_cfg[i].fw_capab = nic_info.capabilities; |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 754 | np_cfg[i].min_bw = nic_info.min_tx_bw; |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 755 | np_cfg[i].max_bw = nic_info.max_tx_bw; |
| 756 | np_cfg[i].max_tx_queues = nic_info.max_tx_ques; |
| 757 | np_cfg[i].max_rx_queues = nic_info.max_rx_ques; |
| 758 | } |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 759 | |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 760 | memcpy(buf, &np_cfg, size); |
| 761 | return size; |
| 762 | } |
| 763 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 764 | static ssize_t qlcnic_sysfs_get_port_stats(struct file *file, |
| 765 | struct kobject *kobj, |
| 766 | struct bin_attribute *attr, |
| 767 | char *buf, loff_t offset, |
| 768 | size_t size) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 769 | { |
| 770 | struct device *dev = container_of(kobj, struct device, kobj); |
| 771 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 772 | struct qlcnic_esw_statistics port_stats; |
| 773 | int ret; |
| 774 | |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 775 | if (qlcnic_83xx_check(adapter)) |
| 776 | return QLC_STATUS_UNSUPPORTED_CMD; |
| 777 | |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 778 | if (size != sizeof(struct qlcnic_esw_statistics)) |
| 779 | return QL_STATUS_INVALID_PARAM; |
| 780 | |
| 781 | if (offset >= QLCNIC_MAX_PCI_FUNC) |
| 782 | return QL_STATUS_INVALID_PARAM; |
| 783 | |
| 784 | memset(&port_stats, 0, size); |
| 785 | ret = qlcnic_get_port_stats(adapter, offset, QLCNIC_QUERY_RX_COUNTER, |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 786 | &port_stats.rx); |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 787 | if (ret) |
| 788 | return ret; |
| 789 | |
| 790 | ret = qlcnic_get_port_stats(adapter, offset, QLCNIC_QUERY_TX_COUNTER, |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 791 | &port_stats.tx); |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 792 | if (ret) |
| 793 | return ret; |
| 794 | |
| 795 | memcpy(buf, &port_stats, size); |
| 796 | return size; |
| 797 | } |
| 798 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 799 | static ssize_t qlcnic_sysfs_get_esw_stats(struct file *file, |
| 800 | struct kobject *kobj, |
| 801 | struct bin_attribute *attr, |
| 802 | char *buf, loff_t offset, |
| 803 | size_t size) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 804 | { |
| 805 | struct device *dev = container_of(kobj, struct device, kobj); |
| 806 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 807 | struct qlcnic_esw_statistics esw_stats; |
| 808 | int ret; |
| 809 | |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 810 | if (qlcnic_83xx_check(adapter)) |
| 811 | return QLC_STATUS_UNSUPPORTED_CMD; |
| 812 | |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 813 | if (size != sizeof(struct qlcnic_esw_statistics)) |
| 814 | return QL_STATUS_INVALID_PARAM; |
| 815 | |
| 816 | if (offset >= QLCNIC_NIU_MAX_XG_PORTS) |
| 817 | return QL_STATUS_INVALID_PARAM; |
| 818 | |
| 819 | memset(&esw_stats, 0, size); |
| 820 | ret = qlcnic_get_eswitch_stats(adapter, offset, QLCNIC_QUERY_RX_COUNTER, |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 821 | &esw_stats.rx); |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 822 | if (ret) |
| 823 | return ret; |
| 824 | |
| 825 | ret = qlcnic_get_eswitch_stats(adapter, offset, QLCNIC_QUERY_TX_COUNTER, |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 826 | &esw_stats.tx); |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 827 | if (ret) |
| 828 | return ret; |
| 829 | |
| 830 | memcpy(buf, &esw_stats, size); |
| 831 | return size; |
| 832 | } |
| 833 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 834 | static ssize_t qlcnic_sysfs_clear_esw_stats(struct file *file, |
| 835 | struct kobject *kobj, |
| 836 | struct bin_attribute *attr, |
| 837 | char *buf, loff_t offset, |
| 838 | size_t size) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 839 | { |
| 840 | struct device *dev = container_of(kobj, struct device, kobj); |
| 841 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 842 | int ret; |
| 843 | |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 844 | if (qlcnic_83xx_check(adapter)) |
| 845 | return QLC_STATUS_UNSUPPORTED_CMD; |
| 846 | |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 847 | if (offset >= QLCNIC_NIU_MAX_XG_PORTS) |
| 848 | return QL_STATUS_INVALID_PARAM; |
| 849 | |
| 850 | ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_ESWITCH, offset, |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 851 | QLCNIC_QUERY_RX_COUNTER); |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 852 | if (ret) |
| 853 | return ret; |
| 854 | |
| 855 | ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_ESWITCH, offset, |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 856 | QLCNIC_QUERY_TX_COUNTER); |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 857 | if (ret) |
| 858 | return ret; |
| 859 | |
| 860 | return size; |
| 861 | } |
| 862 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 863 | static ssize_t qlcnic_sysfs_clear_port_stats(struct file *file, |
| 864 | struct kobject *kobj, |
| 865 | struct bin_attribute *attr, |
| 866 | char *buf, loff_t offset, |
| 867 | size_t size) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 868 | { |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 869 | |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 870 | struct device *dev = container_of(kobj, struct device, kobj); |
| 871 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 872 | int ret; |
| 873 | |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 874 | if (qlcnic_83xx_check(adapter)) |
| 875 | return QLC_STATUS_UNSUPPORTED_CMD; |
| 876 | |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 877 | if (offset >= QLCNIC_MAX_PCI_FUNC) |
| 878 | return QL_STATUS_INVALID_PARAM; |
| 879 | |
| 880 | ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset, |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 881 | QLCNIC_QUERY_RX_COUNTER); |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 882 | if (ret) |
| 883 | return ret; |
| 884 | |
| 885 | ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset, |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 886 | QLCNIC_QUERY_TX_COUNTER); |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 887 | if (ret) |
| 888 | return ret; |
| 889 | |
| 890 | return size; |
| 891 | } |
| 892 | |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 893 | static ssize_t qlcnic_sysfs_read_pci_config(struct file *file, |
| 894 | struct kobject *kobj, |
| 895 | struct bin_attribute *attr, |
| 896 | char *buf, loff_t offset, |
| 897 | size_t size) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 898 | { |
| 899 | struct device *dev = container_of(kobj, struct device, kobj); |
| 900 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 901 | struct qlcnic_pci_func_cfg pci_cfg[QLCNIC_MAX_PCI_FUNC]; |
| 902 | struct qlcnic_pci_info *pci_info; |
| 903 | int i, ret; |
| 904 | |
| 905 | if (size != sizeof(pci_cfg)) |
| 906 | return QL_STATUS_INVALID_PARAM; |
| 907 | |
| 908 | pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL); |
| 909 | if (!pci_info) |
| 910 | return -ENOMEM; |
| 911 | |
| 912 | ret = qlcnic_get_pci_info(adapter, pci_info); |
| 913 | if (ret) { |
| 914 | kfree(pci_info); |
| 915 | return ret; |
| 916 | } |
| 917 | |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 918 | memset(&pci_cfg, 0, |
| 919 | sizeof(struct qlcnic_pci_func_cfg) * QLCNIC_MAX_PCI_FUNC); |
| 920 | |
| 921 | for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 922 | pci_cfg[i].pci_func = pci_info[i].id; |
| 923 | pci_cfg[i].func_type = pci_info[i].type; |
| 924 | pci_cfg[i].port_num = pci_info[i].default_port; |
| 925 | pci_cfg[i].min_bw = pci_info[i].tx_min_bw; |
| 926 | pci_cfg[i].max_bw = pci_info[i].tx_max_bw; |
| 927 | memcpy(&pci_cfg[i].def_mac_addr, &pci_info[i].mac, ETH_ALEN); |
| 928 | } |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 929 | |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 930 | memcpy(buf, &pci_cfg, size); |
| 931 | kfree(pci_info); |
| 932 | return size; |
| 933 | } |
| 934 | |
Himanshu Madhani | a520030 | 2013-03-12 09:02:16 +0000 | [diff] [blame] | 935 | static ssize_t qlcnic_83xx_sysfs_flash_read_handler(struct file *filp, |
| 936 | struct kobject *kobj, |
| 937 | struct bin_attribute *attr, |
| 938 | char *buf, loff_t offset, |
| 939 | size_t size) |
| 940 | { |
| 941 | unsigned char *p_read_buf; |
| 942 | int ret, count; |
| 943 | struct device *dev = container_of(kobj, struct device, kobj); |
| 944 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 945 | |
| 946 | if (!size) |
| 947 | return QL_STATUS_INVALID_PARAM; |
| 948 | if (!buf) |
| 949 | return QL_STATUS_INVALID_PARAM; |
| 950 | |
| 951 | count = size / sizeof(u32); |
| 952 | |
| 953 | if (size % sizeof(u32)) |
| 954 | count++; |
| 955 | |
| 956 | p_read_buf = kcalloc(size, sizeof(unsigned char), GFP_KERNEL); |
| 957 | if (!p_read_buf) |
| 958 | return -ENOMEM; |
| 959 | if (qlcnic_83xx_lock_flash(adapter) != 0) { |
| 960 | kfree(p_read_buf); |
| 961 | return -EIO; |
| 962 | } |
| 963 | |
| 964 | ret = qlcnic_83xx_lockless_flash_read32(adapter, offset, p_read_buf, |
| 965 | count); |
| 966 | |
| 967 | if (ret) { |
| 968 | qlcnic_83xx_unlock_flash(adapter); |
| 969 | kfree(p_read_buf); |
| 970 | return ret; |
| 971 | } |
| 972 | |
| 973 | qlcnic_83xx_unlock_flash(adapter); |
| 974 | memcpy(buf, p_read_buf, size); |
| 975 | kfree(p_read_buf); |
| 976 | |
| 977 | return size; |
| 978 | } |
| 979 | |
| 980 | static int qlcnic_83xx_sysfs_flash_bulk_write(struct qlcnic_adapter *adapter, |
| 981 | char *buf, loff_t offset, |
| 982 | size_t size) |
| 983 | { |
| 984 | int i, ret, count; |
| 985 | unsigned char *p_cache, *p_src; |
| 986 | |
| 987 | p_cache = kcalloc(size, sizeof(unsigned char), GFP_KERNEL); |
| 988 | if (!p_cache) |
| 989 | return -ENOMEM; |
| 990 | |
| 991 | memcpy(p_cache, buf, size); |
| 992 | p_src = p_cache; |
| 993 | count = size / sizeof(u32); |
| 994 | |
| 995 | if (qlcnic_83xx_lock_flash(adapter) != 0) { |
| 996 | kfree(p_cache); |
| 997 | return -EIO; |
| 998 | } |
| 999 | |
| 1000 | if (adapter->ahw->fdt.mfg_id == adapter->flash_mfg_id) { |
| 1001 | ret = qlcnic_83xx_enable_flash_write(adapter); |
| 1002 | if (ret) { |
| 1003 | kfree(p_cache); |
| 1004 | qlcnic_83xx_unlock_flash(adapter); |
| 1005 | return -EIO; |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | for (i = 0; i < count / QLC_83XX_FLASH_WRITE_MAX; i++) { |
| 1010 | ret = qlcnic_83xx_flash_bulk_write(adapter, offset, |
| 1011 | (u32 *)p_src, |
| 1012 | QLC_83XX_FLASH_WRITE_MAX); |
| 1013 | |
| 1014 | if (ret) { |
| 1015 | if (adapter->ahw->fdt.mfg_id == adapter->flash_mfg_id) { |
| 1016 | ret = qlcnic_83xx_disable_flash_write(adapter); |
| 1017 | if (ret) { |
| 1018 | kfree(p_cache); |
| 1019 | qlcnic_83xx_unlock_flash(adapter); |
| 1020 | return -EIO; |
| 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | kfree(p_cache); |
| 1025 | qlcnic_83xx_unlock_flash(adapter); |
| 1026 | return -EIO; |
| 1027 | } |
| 1028 | |
| 1029 | p_src = p_src + sizeof(u32)*QLC_83XX_FLASH_WRITE_MAX; |
| 1030 | offset = offset + sizeof(u32)*QLC_83XX_FLASH_WRITE_MAX; |
| 1031 | } |
| 1032 | |
| 1033 | if (adapter->ahw->fdt.mfg_id == adapter->flash_mfg_id) { |
| 1034 | ret = qlcnic_83xx_disable_flash_write(adapter); |
| 1035 | if (ret) { |
| 1036 | kfree(p_cache); |
| 1037 | qlcnic_83xx_unlock_flash(adapter); |
| 1038 | return -EIO; |
| 1039 | } |
| 1040 | } |
| 1041 | |
| 1042 | kfree(p_cache); |
| 1043 | qlcnic_83xx_unlock_flash(adapter); |
| 1044 | |
| 1045 | return 0; |
| 1046 | } |
| 1047 | |
| 1048 | static int qlcnic_83xx_sysfs_flash_write(struct qlcnic_adapter *adapter, |
| 1049 | char *buf, loff_t offset, size_t size) |
| 1050 | { |
| 1051 | int i, ret, count; |
| 1052 | unsigned char *p_cache, *p_src; |
| 1053 | |
| 1054 | p_cache = kcalloc(size, sizeof(unsigned char), GFP_KERNEL); |
| 1055 | if (!p_cache) |
| 1056 | return -ENOMEM; |
| 1057 | |
| 1058 | memcpy(p_cache, buf, size); |
| 1059 | p_src = p_cache; |
| 1060 | count = size / sizeof(u32); |
| 1061 | |
| 1062 | if (qlcnic_83xx_lock_flash(adapter) != 0) { |
| 1063 | kfree(p_cache); |
| 1064 | return -EIO; |
| 1065 | } |
| 1066 | |
| 1067 | if (adapter->ahw->fdt.mfg_id == adapter->flash_mfg_id) { |
| 1068 | ret = qlcnic_83xx_enable_flash_write(adapter); |
| 1069 | if (ret) { |
| 1070 | kfree(p_cache); |
| 1071 | qlcnic_83xx_unlock_flash(adapter); |
| 1072 | return -EIO; |
| 1073 | } |
| 1074 | } |
| 1075 | |
| 1076 | for (i = 0; i < count; i++) { |
| 1077 | ret = qlcnic_83xx_flash_write32(adapter, offset, (u32 *)p_src); |
| 1078 | if (ret) { |
| 1079 | if (adapter->ahw->fdt.mfg_id == adapter->flash_mfg_id) { |
| 1080 | ret = qlcnic_83xx_disable_flash_write(adapter); |
| 1081 | if (ret) { |
| 1082 | kfree(p_cache); |
| 1083 | qlcnic_83xx_unlock_flash(adapter); |
| 1084 | return -EIO; |
| 1085 | } |
| 1086 | } |
| 1087 | kfree(p_cache); |
| 1088 | qlcnic_83xx_unlock_flash(adapter); |
| 1089 | return -EIO; |
| 1090 | } |
| 1091 | |
| 1092 | p_src = p_src + sizeof(u32); |
| 1093 | offset = offset + sizeof(u32); |
| 1094 | } |
| 1095 | |
| 1096 | if (adapter->ahw->fdt.mfg_id == adapter->flash_mfg_id) { |
| 1097 | ret = qlcnic_83xx_disable_flash_write(adapter); |
| 1098 | if (ret) { |
| 1099 | kfree(p_cache); |
| 1100 | qlcnic_83xx_unlock_flash(adapter); |
| 1101 | return -EIO; |
| 1102 | } |
| 1103 | } |
| 1104 | |
| 1105 | kfree(p_cache); |
| 1106 | qlcnic_83xx_unlock_flash(adapter); |
| 1107 | |
| 1108 | return 0; |
| 1109 | } |
| 1110 | |
| 1111 | static ssize_t qlcnic_83xx_sysfs_flash_write_handler(struct file *filp, |
| 1112 | struct kobject *kobj, |
| 1113 | struct bin_attribute *attr, |
| 1114 | char *buf, loff_t offset, |
| 1115 | size_t size) |
| 1116 | { |
| 1117 | int ret; |
| 1118 | static int flash_mode; |
| 1119 | unsigned long data; |
| 1120 | struct device *dev = container_of(kobj, struct device, kobj); |
| 1121 | struct qlcnic_adapter *adapter = dev_get_drvdata(dev); |
| 1122 | |
| 1123 | if (!buf) |
| 1124 | return QL_STATUS_INVALID_PARAM; |
| 1125 | |
| 1126 | ret = kstrtoul(buf, 16, &data); |
| 1127 | |
| 1128 | switch (data) { |
| 1129 | case QLC_83XX_FLASH_SECTOR_ERASE_CMD: |
| 1130 | flash_mode = QLC_83XX_ERASE_MODE; |
| 1131 | ret = qlcnic_83xx_erase_flash_sector(adapter, offset); |
| 1132 | if (ret) { |
| 1133 | dev_err(&adapter->pdev->dev, |
| 1134 | "%s failed at %d\n", __func__, __LINE__); |
| 1135 | return -EIO; |
| 1136 | } |
| 1137 | break; |
| 1138 | |
| 1139 | case QLC_83XX_FLASH_BULK_WRITE_CMD: |
| 1140 | flash_mode = QLC_83XX_BULK_WRITE_MODE; |
| 1141 | break; |
| 1142 | |
| 1143 | case QLC_83XX_FLASH_WRITE_CMD: |
| 1144 | flash_mode = QLC_83XX_WRITE_MODE; |
| 1145 | break; |
| 1146 | default: |
| 1147 | if (flash_mode == QLC_83XX_BULK_WRITE_MODE) { |
| 1148 | ret = qlcnic_83xx_sysfs_flash_bulk_write(adapter, buf, |
| 1149 | offset, size); |
| 1150 | if (ret) { |
| 1151 | dev_err(&adapter->pdev->dev, |
| 1152 | "%s failed at %d\n", |
| 1153 | __func__, __LINE__); |
| 1154 | return -EIO; |
| 1155 | } |
| 1156 | } |
| 1157 | |
| 1158 | if (flash_mode == QLC_83XX_WRITE_MODE) { |
| 1159 | ret = qlcnic_83xx_sysfs_flash_write(adapter, buf, |
| 1160 | offset, size); |
| 1161 | if (ret) { |
| 1162 | dev_err(&adapter->pdev->dev, |
| 1163 | "%s failed at %d\n", __func__, |
| 1164 | __LINE__); |
| 1165 | return -EIO; |
| 1166 | } |
| 1167 | } |
| 1168 | } |
| 1169 | |
| 1170 | return size; |
| 1171 | } |
| 1172 | |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 1173 | static struct device_attribute dev_attr_bridged_mode = { |
| 1174 | .attr = {.name = "bridged_mode", .mode = (S_IRUGO | S_IWUSR)}, |
| 1175 | .show = qlcnic_show_bridged_mode, |
| 1176 | .store = qlcnic_store_bridged_mode, |
| 1177 | }; |
| 1178 | |
| 1179 | static struct device_attribute dev_attr_diag_mode = { |
| 1180 | .attr = {.name = "diag_mode", .mode = (S_IRUGO | S_IWUSR)}, |
| 1181 | .show = qlcnic_show_diag_mode, |
| 1182 | .store = qlcnic_store_diag_mode, |
| 1183 | }; |
| 1184 | |
| 1185 | static struct device_attribute dev_attr_beacon = { |
| 1186 | .attr = {.name = "beacon", .mode = (S_IRUGO | S_IWUSR)}, |
| 1187 | .show = qlcnic_show_beacon, |
| 1188 | .store = qlcnic_store_beacon, |
| 1189 | }; |
| 1190 | |
| 1191 | static struct bin_attribute bin_attr_crb = { |
| 1192 | .attr = {.name = "crb", .mode = (S_IRUGO | S_IWUSR)}, |
| 1193 | .size = 0, |
| 1194 | .read = qlcnic_sysfs_read_crb, |
| 1195 | .write = qlcnic_sysfs_write_crb, |
| 1196 | }; |
| 1197 | |
| 1198 | static struct bin_attribute bin_attr_mem = { |
| 1199 | .attr = {.name = "mem", .mode = (S_IRUGO | S_IWUSR)}, |
| 1200 | .size = 0, |
| 1201 | .read = qlcnic_sysfs_read_mem, |
| 1202 | .write = qlcnic_sysfs_write_mem, |
| 1203 | }; |
| 1204 | |
| 1205 | static struct bin_attribute bin_attr_npar_config = { |
| 1206 | .attr = {.name = "npar_config", .mode = (S_IRUGO | S_IWUSR)}, |
| 1207 | .size = 0, |
| 1208 | .read = qlcnic_sysfs_read_npar_config, |
| 1209 | .write = qlcnic_sysfs_write_npar_config, |
| 1210 | }; |
| 1211 | |
| 1212 | static struct bin_attribute bin_attr_pci_config = { |
| 1213 | .attr = {.name = "pci_config", .mode = (S_IRUGO | S_IWUSR)}, |
| 1214 | .size = 0, |
| 1215 | .read = qlcnic_sysfs_read_pci_config, |
| 1216 | .write = NULL, |
| 1217 | }; |
| 1218 | |
| 1219 | static struct bin_attribute bin_attr_port_stats = { |
| 1220 | .attr = {.name = "port_stats", .mode = (S_IRUGO | S_IWUSR)}, |
| 1221 | .size = 0, |
| 1222 | .read = qlcnic_sysfs_get_port_stats, |
| 1223 | .write = qlcnic_sysfs_clear_port_stats, |
| 1224 | }; |
| 1225 | |
| 1226 | static struct bin_attribute bin_attr_esw_stats = { |
| 1227 | .attr = {.name = "esw_stats", .mode = (S_IRUGO | S_IWUSR)}, |
| 1228 | .size = 0, |
| 1229 | .read = qlcnic_sysfs_get_esw_stats, |
| 1230 | .write = qlcnic_sysfs_clear_esw_stats, |
| 1231 | }; |
| 1232 | |
| 1233 | static struct bin_attribute bin_attr_esw_config = { |
| 1234 | .attr = {.name = "esw_config", .mode = (S_IRUGO | S_IWUSR)}, |
| 1235 | .size = 0, |
| 1236 | .read = qlcnic_sysfs_read_esw_config, |
| 1237 | .write = qlcnic_sysfs_write_esw_config, |
| 1238 | }; |
| 1239 | |
| 1240 | static struct bin_attribute bin_attr_pm_config = { |
| 1241 | .attr = {.name = "pm_config", .mode = (S_IRUGO | S_IWUSR)}, |
| 1242 | .size = 0, |
| 1243 | .read = qlcnic_sysfs_read_pm_config, |
| 1244 | .write = qlcnic_sysfs_write_pm_config, |
| 1245 | }; |
| 1246 | |
Himanshu Madhani | a520030 | 2013-03-12 09:02:16 +0000 | [diff] [blame] | 1247 | static struct bin_attribute bin_attr_flash = { |
| 1248 | .attr = {.name = "flash", .mode = (S_IRUGO | S_IWUSR)}, |
| 1249 | .size = 0, |
| 1250 | .read = qlcnic_83xx_sysfs_flash_read_handler, |
| 1251 | .write = qlcnic_83xx_sysfs_flash_write_handler, |
| 1252 | }; |
| 1253 | |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 1254 | void qlcnic_create_sysfs_entries(struct qlcnic_adapter *adapter) |
| 1255 | { |
| 1256 | struct device *dev = &adapter->pdev->dev; |
| 1257 | |
Sony Chacko | 7978845 | 2012-12-04 03:33:53 +0000 | [diff] [blame] | 1258 | if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_BDG) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 1259 | if (device_create_file(dev, &dev_attr_bridged_mode)) |
| 1260 | dev_warn(dev, |
Sony Chacko | b66e29c | 2012-11-28 04:34:29 +0000 | [diff] [blame] | 1261 | "failed to create bridged_mode sysfs entry\n"); |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | void qlcnic_remove_sysfs_entries(struct qlcnic_adapter *adapter) |
| 1265 | { |
| 1266 | struct device *dev = &adapter->pdev->dev; |
| 1267 | |
Sony Chacko | 7978845 | 2012-12-04 03:33:53 +0000 | [diff] [blame] | 1268 | if (adapter->ahw->capabilities & QLCNIC_FW_CAPABILITY_BDG) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 1269 | device_remove_file(dev, &dev_attr_bridged_mode); |
| 1270 | } |
| 1271 | |
| 1272 | void qlcnic_create_diag_entries(struct qlcnic_adapter *adapter) |
| 1273 | { |
| 1274 | struct device *dev = &adapter->pdev->dev; |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 1275 | |
| 1276 | if (device_create_bin_file(dev, &bin_attr_port_stats)) |
| 1277 | dev_info(dev, "failed to create port stats sysfs entry"); |
| 1278 | |
Sony Chacko | 7978845 | 2012-12-04 03:33:53 +0000 | [diff] [blame] | 1279 | if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 1280 | return; |
| 1281 | if (device_create_file(dev, &dev_attr_diag_mode)) |
| 1282 | dev_info(dev, "failed to create diag_mode sysfs entry\n"); |
| 1283 | if (device_create_bin_file(dev, &bin_attr_crb)) |
| 1284 | dev_info(dev, "failed to create crb sysfs entry\n"); |
| 1285 | if (device_create_bin_file(dev, &bin_attr_mem)) |
| 1286 | dev_info(dev, "failed to create mem sysfs entry\n"); |
| 1287 | |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 1288 | if (device_create_bin_file(dev, &bin_attr_pci_config)) |
| 1289 | dev_info(dev, "failed to create pci config sysfs entry"); |
| 1290 | if (device_create_file(dev, &dev_attr_beacon)) |
| 1291 | dev_info(dev, "failed to create beacon sysfs entry"); |
| 1292 | |
| 1293 | if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) |
| 1294 | return; |
| 1295 | if (device_create_bin_file(dev, &bin_attr_esw_config)) |
| 1296 | dev_info(dev, "failed to create esw config sysfs entry"); |
Sony Chacko | 7978845 | 2012-12-04 03:33:53 +0000 | [diff] [blame] | 1297 | if (adapter->ahw->op_mode != QLCNIC_MGMT_FUNC) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 1298 | return; |
| 1299 | if (device_create_bin_file(dev, &bin_attr_npar_config)) |
| 1300 | dev_info(dev, "failed to create npar config sysfs entry"); |
| 1301 | if (device_create_bin_file(dev, &bin_attr_pm_config)) |
| 1302 | dev_info(dev, "failed to create pm config sysfs entry"); |
| 1303 | if (device_create_bin_file(dev, &bin_attr_esw_stats)) |
| 1304 | dev_info(dev, "failed to create eswitch stats sysfs entry"); |
| 1305 | } |
| 1306 | |
| 1307 | void qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter) |
| 1308 | { |
| 1309 | struct device *dev = &adapter->pdev->dev; |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 1310 | |
| 1311 | device_remove_bin_file(dev, &bin_attr_port_stats); |
| 1312 | |
Sony Chacko | 7978845 | 2012-12-04 03:33:53 +0000 | [diff] [blame] | 1313 | if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 1314 | return; |
| 1315 | device_remove_file(dev, &dev_attr_diag_mode); |
| 1316 | device_remove_bin_file(dev, &bin_attr_crb); |
| 1317 | device_remove_bin_file(dev, &bin_attr_mem); |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 1318 | device_remove_bin_file(dev, &bin_attr_pci_config); |
| 1319 | device_remove_file(dev, &dev_attr_beacon); |
| 1320 | if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) |
| 1321 | return; |
| 1322 | device_remove_bin_file(dev, &bin_attr_esw_config); |
Sony Chacko | 7978845 | 2012-12-04 03:33:53 +0000 | [diff] [blame] | 1323 | if (adapter->ahw->op_mode != QLCNIC_MGMT_FUNC) |
Sony Chacko | ec079a0 | 2012-11-28 04:34:28 +0000 | [diff] [blame] | 1324 | return; |
| 1325 | device_remove_bin_file(dev, &bin_attr_npar_config); |
| 1326 | device_remove_bin_file(dev, &bin_attr_pm_config); |
| 1327 | device_remove_bin_file(dev, &bin_attr_esw_stats); |
| 1328 | } |
Sony Chacko | 7e2cf4f | 2013-01-01 03:20:17 +0000 | [diff] [blame] | 1329 | |
| 1330 | void qlcnic_82xx_add_sysfs(struct qlcnic_adapter *adapter) |
| 1331 | { |
| 1332 | qlcnic_create_diag_entries(adapter); |
| 1333 | } |
| 1334 | |
| 1335 | void qlcnic_82xx_remove_sysfs(struct qlcnic_adapter *adapter) |
| 1336 | { |
| 1337 | qlcnic_remove_diag_entries(adapter); |
| 1338 | } |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 1339 | |
| 1340 | void qlcnic_83xx_add_sysfs(struct qlcnic_adapter *adapter) |
| 1341 | { |
Himanshu Madhani | a520030 | 2013-03-12 09:02:16 +0000 | [diff] [blame] | 1342 | struct device *dev = &adapter->pdev->dev; |
| 1343 | |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 1344 | qlcnic_create_diag_entries(adapter); |
Himanshu Madhani | a520030 | 2013-03-12 09:02:16 +0000 | [diff] [blame] | 1345 | |
| 1346 | if (sysfs_create_bin_file(&dev->kobj, &bin_attr_flash)) |
| 1347 | dev_info(dev, "failed to create flash sysfs entry\n"); |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | void qlcnic_83xx_remove_sysfs(struct qlcnic_adapter *adapter) |
| 1351 | { |
Himanshu Madhani | a520030 | 2013-03-12 09:02:16 +0000 | [diff] [blame] | 1352 | struct device *dev = &adapter->pdev->dev; |
| 1353 | |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 1354 | qlcnic_remove_diag_entries(adapter); |
Himanshu Madhani | a520030 | 2013-03-12 09:02:16 +0000 | [diff] [blame] | 1355 | sysfs_remove_bin_file(&dev->kobj, &bin_attr_flash); |
Sony Chacko | 319ecf1 | 2013-01-01 03:20:22 +0000 | [diff] [blame] | 1356 | } |