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