Joe Perches | 0e4e06a | 2011-05-02 16:49:14 -0700 | [diff] [blame] | 1 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 2 | |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 3 | #include <linux/delay.h> |
| 4 | #include <linux/etherdevice.h> |
| 5 | #include <linux/netdevice.h> |
Daniel Drake | 1f04493 | 2009-12-24 08:11:24 +0000 | [diff] [blame] | 6 | #include <linux/if_ether.h> |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 7 | #include <linux/if_arp.h> |
| 8 | #include <linux/kthread.h> |
| 9 | #include <linux/kfifo.h> |
Kiran Divekar | e86dc1c | 2010-06-14 22:01:26 +0530 | [diff] [blame] | 10 | #include <net/cfg80211.h> |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 11 | |
Holger Schurig | e0e42da | 2009-11-25 13:10:15 +0100 | [diff] [blame] | 12 | #include "mesh.h" |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 13 | #include "decl.h" |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 14 | #include "cmd.h" |
| 15 | |
Holger Schurig | e0e42da | 2009-11-25 13:10:15 +0100 | [diff] [blame] | 16 | |
Daniel Drake | 3db4f98 | 2011-07-20 17:53:50 +0100 | [diff] [blame] | 17 | static int lbs_add_mesh(struct lbs_private *priv); |
| 18 | |
| 19 | /*************************************************************************** |
| 20 | * Mesh command handling |
| 21 | */ |
| 22 | |
| 23 | static int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action, |
| 24 | struct cmd_ds_mesh_access *cmd) |
| 25 | { |
| 26 | int ret; |
| 27 | |
| 28 | lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action); |
| 29 | |
| 30 | cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS); |
| 31 | cmd->hdr.size = cpu_to_le16(sizeof(*cmd)); |
| 32 | cmd->hdr.result = 0; |
| 33 | |
| 34 | cmd->action = cpu_to_le16(cmd_action); |
| 35 | |
| 36 | ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd); |
| 37 | |
| 38 | lbs_deb_leave(LBS_DEB_CMD); |
| 39 | return ret; |
| 40 | } |
| 41 | |
| 42 | static int __lbs_mesh_config_send(struct lbs_private *priv, |
| 43 | struct cmd_ds_mesh_config *cmd, |
| 44 | uint16_t action, uint16_t type) |
| 45 | { |
| 46 | int ret; |
| 47 | u16 command = CMD_MESH_CONFIG_OLD; |
| 48 | |
| 49 | lbs_deb_enter(LBS_DEB_CMD); |
| 50 | |
| 51 | /* |
| 52 | * Command id is 0xac for v10 FW along with mesh interface |
| 53 | * id in bits 14-13-12. |
| 54 | */ |
| 55 | if (priv->mesh_tlv == TLV_TYPE_MESH_ID) |
| 56 | command = CMD_MESH_CONFIG | |
| 57 | (MESH_IFACE_ID << MESH_IFACE_BIT_OFFSET); |
| 58 | |
| 59 | cmd->hdr.command = cpu_to_le16(command); |
| 60 | cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config)); |
| 61 | cmd->hdr.result = 0; |
| 62 | |
| 63 | cmd->type = cpu_to_le16(type); |
| 64 | cmd->action = cpu_to_le16(action); |
| 65 | |
| 66 | ret = lbs_cmd_with_response(priv, command, cmd); |
| 67 | |
| 68 | lbs_deb_leave(LBS_DEB_CMD); |
| 69 | return ret; |
| 70 | } |
| 71 | |
| 72 | static int lbs_mesh_config_send(struct lbs_private *priv, |
| 73 | struct cmd_ds_mesh_config *cmd, |
| 74 | uint16_t action, uint16_t type) |
| 75 | { |
| 76 | int ret; |
| 77 | |
| 78 | if (!(priv->fwcapinfo & FW_CAPINFO_PERSISTENT_CONFIG)) |
| 79 | return -EOPNOTSUPP; |
| 80 | |
| 81 | ret = __lbs_mesh_config_send(priv, cmd, action, type); |
| 82 | return ret; |
| 83 | } |
| 84 | |
| 85 | /* This function is the CMD_MESH_CONFIG legacy function. It only handles the |
| 86 | * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG |
| 87 | * are all handled by preparing a struct cmd_ds_mesh_config and passing it to |
| 88 | * lbs_mesh_config_send. |
| 89 | */ |
| 90 | static int lbs_mesh_config(struct lbs_private *priv, uint16_t action, |
| 91 | uint16_t chan) |
| 92 | { |
| 93 | struct cmd_ds_mesh_config cmd; |
| 94 | struct mrvl_meshie *ie; |
| 95 | DECLARE_SSID_BUF(ssid); |
| 96 | |
| 97 | memset(&cmd, 0, sizeof(cmd)); |
| 98 | cmd.channel = cpu_to_le16(chan); |
| 99 | ie = (struct mrvl_meshie *)cmd.data; |
| 100 | |
| 101 | switch (action) { |
| 102 | case CMD_ACT_MESH_CONFIG_START: |
| 103 | ie->id = WLAN_EID_GENERIC; |
| 104 | ie->val.oui[0] = 0x00; |
| 105 | ie->val.oui[1] = 0x50; |
| 106 | ie->val.oui[2] = 0x43; |
| 107 | ie->val.type = MARVELL_MESH_IE_TYPE; |
| 108 | ie->val.subtype = MARVELL_MESH_IE_SUBTYPE; |
| 109 | ie->val.version = MARVELL_MESH_IE_VERSION; |
| 110 | ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP; |
| 111 | ie->val.active_metric_id = MARVELL_MESH_METRIC_ID; |
| 112 | ie->val.mesh_capability = MARVELL_MESH_CAPABILITY; |
| 113 | ie->val.mesh_id_len = priv->mesh_ssid_len; |
| 114 | memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len); |
| 115 | ie->len = sizeof(struct mrvl_meshie_val) - |
| 116 | IEEE80211_MAX_SSID_LEN + priv->mesh_ssid_len; |
| 117 | cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val)); |
| 118 | break; |
| 119 | case CMD_ACT_MESH_CONFIG_STOP: |
| 120 | break; |
| 121 | default: |
| 122 | return -1; |
| 123 | } |
| 124 | lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n", |
| 125 | action, priv->mesh_tlv, chan, |
| 126 | print_ssid(ssid, priv->mesh_ssid, priv->mesh_ssid_len)); |
| 127 | |
| 128 | return __lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv); |
| 129 | } |
| 130 | |
| 131 | |
Holger Schurig | e0e42da | 2009-11-25 13:10:15 +0100 | [diff] [blame] | 132 | /*************************************************************************** |
| 133 | * Mesh sysfs support |
| 134 | */ |
| 135 | |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 136 | /* |
Holger Schurig | e0e42da | 2009-11-25 13:10:15 +0100 | [diff] [blame] | 137 | * Attributes exported through sysfs |
| 138 | */ |
| 139 | |
| 140 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 141 | * lbs_anycast_get - Get function for sysfs attribute anycast_mask |
| 142 | * @dev: the &struct device |
| 143 | * @attr: device attributes |
| 144 | * @buf: buffer where data will be returned |
Holger Schurig | e0e42da | 2009-11-25 13:10:15 +0100 | [diff] [blame] | 145 | */ |
| 146 | static ssize_t lbs_anycast_get(struct device *dev, |
| 147 | struct device_attribute *attr, char * buf) |
| 148 | { |
| 149 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
| 150 | struct cmd_ds_mesh_access mesh_access; |
| 151 | int ret; |
| 152 | |
| 153 | memset(&mesh_access, 0, sizeof(mesh_access)); |
| 154 | |
| 155 | ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_ANYCAST, &mesh_access); |
| 156 | if (ret) |
| 157 | return ret; |
| 158 | |
| 159 | return snprintf(buf, 12, "0x%X\n", le32_to_cpu(mesh_access.data[0])); |
| 160 | } |
| 161 | |
| 162 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 163 | * lbs_anycast_set - Set function for sysfs attribute anycast_mask |
| 164 | * @dev: the &struct device |
| 165 | * @attr: device attributes |
| 166 | * @buf: buffer that contains new attribute value |
| 167 | * @count: size of buffer |
Holger Schurig | e0e42da | 2009-11-25 13:10:15 +0100 | [diff] [blame] | 168 | */ |
| 169 | static ssize_t lbs_anycast_set(struct device *dev, |
| 170 | struct device_attribute *attr, const char * buf, size_t count) |
| 171 | { |
| 172 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
| 173 | struct cmd_ds_mesh_access mesh_access; |
| 174 | uint32_t datum; |
| 175 | int ret; |
| 176 | |
| 177 | memset(&mesh_access, 0, sizeof(mesh_access)); |
| 178 | sscanf(buf, "%x", &datum); |
| 179 | mesh_access.data[0] = cpu_to_le32(datum); |
| 180 | |
| 181 | ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_ANYCAST, &mesh_access); |
| 182 | if (ret) |
| 183 | return ret; |
| 184 | |
| 185 | return strlen(buf); |
| 186 | } |
| 187 | |
| 188 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 189 | * lbs_prb_rsp_limit_get - Get function for sysfs attribute prb_rsp_limit |
| 190 | * @dev: the &struct device |
| 191 | * @attr: device attributes |
| 192 | * @buf: buffer where data will be returned |
Holger Schurig | e0e42da | 2009-11-25 13:10:15 +0100 | [diff] [blame] | 193 | */ |
| 194 | static ssize_t lbs_prb_rsp_limit_get(struct device *dev, |
| 195 | struct device_attribute *attr, char *buf) |
| 196 | { |
| 197 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
| 198 | struct cmd_ds_mesh_access mesh_access; |
| 199 | int ret; |
| 200 | u32 retry_limit; |
| 201 | |
| 202 | memset(&mesh_access, 0, sizeof(mesh_access)); |
| 203 | mesh_access.data[0] = cpu_to_le32(CMD_ACT_GET); |
| 204 | |
| 205 | ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT, |
| 206 | &mesh_access); |
| 207 | if (ret) |
| 208 | return ret; |
| 209 | |
| 210 | retry_limit = le32_to_cpu(mesh_access.data[1]); |
| 211 | return snprintf(buf, 10, "%d\n", retry_limit); |
| 212 | } |
| 213 | |
| 214 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 215 | * lbs_prb_rsp_limit_set - Set function for sysfs attribute prb_rsp_limit |
| 216 | * @dev: the &struct device |
| 217 | * @attr: device attributes |
| 218 | * @buf: buffer that contains new attribute value |
| 219 | * @count: size of buffer |
Holger Schurig | e0e42da | 2009-11-25 13:10:15 +0100 | [diff] [blame] | 220 | */ |
| 221 | static ssize_t lbs_prb_rsp_limit_set(struct device *dev, |
| 222 | struct device_attribute *attr, const char *buf, size_t count) |
| 223 | { |
| 224 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
| 225 | struct cmd_ds_mesh_access mesh_access; |
| 226 | int ret; |
| 227 | unsigned long retry_limit; |
| 228 | |
| 229 | memset(&mesh_access, 0, sizeof(mesh_access)); |
| 230 | mesh_access.data[0] = cpu_to_le32(CMD_ACT_SET); |
| 231 | |
| 232 | if (!strict_strtoul(buf, 10, &retry_limit)) |
| 233 | return -ENOTSUPP; |
| 234 | if (retry_limit > 15) |
| 235 | return -ENOTSUPP; |
| 236 | |
| 237 | mesh_access.data[1] = cpu_to_le32(retry_limit); |
| 238 | |
| 239 | ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT, |
| 240 | &mesh_access); |
| 241 | if (ret) |
| 242 | return ret; |
| 243 | |
| 244 | return strlen(buf); |
| 245 | } |
| 246 | |
| 247 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 248 | * lbs_mesh_get - Get function for sysfs attribute mesh |
| 249 | * @dev: the &struct device |
| 250 | * @attr: device attributes |
| 251 | * @buf: buffer where data will be returned |
Holger Schurig | e0e42da | 2009-11-25 13:10:15 +0100 | [diff] [blame] | 252 | */ |
| 253 | static ssize_t lbs_mesh_get(struct device *dev, |
| 254 | struct device_attribute *attr, char * buf) |
| 255 | { |
| 256 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
| 257 | return snprintf(buf, 5, "0x%X\n", !!priv->mesh_dev); |
| 258 | } |
| 259 | |
| 260 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 261 | * lbs_mesh_set - Set function for sysfs attribute mesh |
| 262 | * @dev: the &struct device |
| 263 | * @attr: device attributes |
| 264 | * @buf: buffer that contains new attribute value |
| 265 | * @count: size of buffer |
Holger Schurig | e0e42da | 2009-11-25 13:10:15 +0100 | [diff] [blame] | 266 | */ |
| 267 | static ssize_t lbs_mesh_set(struct device *dev, |
| 268 | struct device_attribute *attr, const char * buf, size_t count) |
| 269 | { |
| 270 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
| 271 | int enable; |
Holger Schurig | e0e42da | 2009-11-25 13:10:15 +0100 | [diff] [blame] | 272 | |
| 273 | sscanf(buf, "%x", &enable); |
| 274 | enable = !!enable; |
| 275 | if (enable == !!priv->mesh_dev) |
| 276 | return count; |
Holger Schurig | e0e42da | 2009-11-25 13:10:15 +0100 | [diff] [blame] | 277 | |
| 278 | if (enable) |
| 279 | lbs_add_mesh(priv); |
| 280 | else |
| 281 | lbs_remove_mesh(priv); |
| 282 | |
| 283 | return count; |
| 284 | } |
| 285 | |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 286 | /* |
Holger Schurig | e0e42da | 2009-11-25 13:10:15 +0100 | [diff] [blame] | 287 | * lbs_mesh attribute to be exported per ethX interface |
| 288 | * through sysfs (/sys/class/net/ethX/lbs_mesh) |
| 289 | */ |
| 290 | static DEVICE_ATTR(lbs_mesh, 0644, lbs_mesh_get, lbs_mesh_set); |
| 291 | |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 292 | /* |
Holger Schurig | e0e42da | 2009-11-25 13:10:15 +0100 | [diff] [blame] | 293 | * anycast_mask attribute to be exported per mshX interface |
| 294 | * through sysfs (/sys/class/net/mshX/anycast_mask) |
| 295 | */ |
| 296 | static DEVICE_ATTR(anycast_mask, 0644, lbs_anycast_get, lbs_anycast_set); |
| 297 | |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 298 | /* |
Holger Schurig | e0e42da | 2009-11-25 13:10:15 +0100 | [diff] [blame] | 299 | * prb_rsp_limit attribute to be exported per mshX interface |
| 300 | * through sysfs (/sys/class/net/mshX/prb_rsp_limit) |
| 301 | */ |
| 302 | static DEVICE_ATTR(prb_rsp_limit, 0644, lbs_prb_rsp_limit_get, |
| 303 | lbs_prb_rsp_limit_set); |
| 304 | |
| 305 | static struct attribute *lbs_mesh_sysfs_entries[] = { |
| 306 | &dev_attr_anycast_mask.attr, |
| 307 | &dev_attr_prb_rsp_limit.attr, |
| 308 | NULL, |
| 309 | }; |
| 310 | |
Daniel Drake | 3db4f98 | 2011-07-20 17:53:50 +0100 | [diff] [blame] | 311 | static const struct attribute_group lbs_mesh_attr_group = { |
Holger Schurig | e0e42da | 2009-11-25 13:10:15 +0100 | [diff] [blame] | 312 | .attrs = lbs_mesh_sysfs_entries, |
| 313 | }; |
| 314 | |
| 315 | |
Holger Schurig | ece1e3c | 2009-11-25 13:11:16 +0100 | [diff] [blame] | 316 | /*************************************************************************** |
Holger Schurig | e0e42da | 2009-11-25 13:10:15 +0100 | [diff] [blame] | 317 | * Persistent configuration support |
| 318 | */ |
| 319 | |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 320 | static int mesh_get_default_parameters(struct device *dev, |
| 321 | struct mrvl_mesh_defaults *defs) |
| 322 | { |
Kiran Divekar | ab65f64 | 2009-02-19 19:32:39 -0500 | [diff] [blame] | 323 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 324 | struct cmd_ds_mesh_config cmd; |
| 325 | int ret; |
| 326 | |
| 327 | memset(&cmd, 0, sizeof(struct cmd_ds_mesh_config)); |
| 328 | ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_GET, |
| 329 | CMD_TYPE_MESH_GET_DEFAULTS); |
| 330 | |
| 331 | if (ret) |
| 332 | return -EOPNOTSUPP; |
| 333 | |
| 334 | memcpy(defs, &cmd.data[0], sizeof(struct mrvl_mesh_defaults)); |
| 335 | |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 340 | * bootflag_get - Get function for sysfs attribute bootflag |
| 341 | * @dev: the &struct device |
| 342 | * @attr: device attributes |
| 343 | * @buf: buffer where data will be returned |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 344 | */ |
| 345 | static ssize_t bootflag_get(struct device *dev, |
| 346 | struct device_attribute *attr, char *buf) |
| 347 | { |
| 348 | struct mrvl_mesh_defaults defs; |
| 349 | int ret; |
| 350 | |
| 351 | ret = mesh_get_default_parameters(dev, &defs); |
| 352 | |
| 353 | if (ret) |
| 354 | return ret; |
| 355 | |
Brian Cavagnolo | fb90490 | 2008-07-16 12:15:26 -0700 | [diff] [blame] | 356 | return snprintf(buf, 12, "%d\n", le32_to_cpu(defs.bootflag)); |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 360 | * bootflag_set - Set function for sysfs attribute bootflag |
| 361 | * @dev: the &struct device |
| 362 | * @attr: device attributes |
| 363 | * @buf: buffer that contains new attribute value |
| 364 | * @count: size of buffer |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 365 | */ |
| 366 | static ssize_t bootflag_set(struct device *dev, struct device_attribute *attr, |
| 367 | const char *buf, size_t count) |
| 368 | { |
Kiran Divekar | ab65f64 | 2009-02-19 19:32:39 -0500 | [diff] [blame] | 369 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 370 | struct cmd_ds_mesh_config cmd; |
| 371 | uint32_t datum; |
| 372 | int ret; |
| 373 | |
| 374 | memset(&cmd, 0, sizeof(cmd)); |
Brian Cavagnolo | fb90490 | 2008-07-16 12:15:26 -0700 | [diff] [blame] | 375 | ret = sscanf(buf, "%d", &datum); |
| 376 | if ((ret != 1) || (datum > 1)) |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 377 | return -EINVAL; |
| 378 | |
| 379 | *((__le32 *)&cmd.data[0]) = cpu_to_le32(!!datum); |
| 380 | cmd.length = cpu_to_le16(sizeof(uint32_t)); |
| 381 | ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET, |
| 382 | CMD_TYPE_MESH_SET_BOOTFLAG); |
| 383 | if (ret) |
| 384 | return ret; |
| 385 | |
| 386 | return strlen(buf); |
| 387 | } |
| 388 | |
| 389 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 390 | * boottime_get - Get function for sysfs attribute boottime |
| 391 | * @dev: the &struct device |
| 392 | * @attr: device attributes |
| 393 | * @buf: buffer where data will be returned |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 394 | */ |
| 395 | static ssize_t boottime_get(struct device *dev, |
| 396 | struct device_attribute *attr, char *buf) |
| 397 | { |
| 398 | struct mrvl_mesh_defaults defs; |
| 399 | int ret; |
| 400 | |
| 401 | ret = mesh_get_default_parameters(dev, &defs); |
| 402 | |
| 403 | if (ret) |
| 404 | return ret; |
| 405 | |
Brian Cavagnolo | fb90490 | 2008-07-16 12:15:26 -0700 | [diff] [blame] | 406 | return snprintf(buf, 12, "%d\n", defs.boottime); |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 410 | * boottime_set - Set function for sysfs attribute boottime |
| 411 | * @dev: the &struct device |
| 412 | * @attr: device attributes |
| 413 | * @buf: buffer that contains new attribute value |
| 414 | * @count: size of buffer |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 415 | */ |
| 416 | static ssize_t boottime_set(struct device *dev, |
| 417 | struct device_attribute *attr, const char *buf, size_t count) |
| 418 | { |
Kiran Divekar | ab65f64 | 2009-02-19 19:32:39 -0500 | [diff] [blame] | 419 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 420 | struct cmd_ds_mesh_config cmd; |
| 421 | uint32_t datum; |
| 422 | int ret; |
| 423 | |
| 424 | memset(&cmd, 0, sizeof(cmd)); |
Brian Cavagnolo | fb90490 | 2008-07-16 12:15:26 -0700 | [diff] [blame] | 425 | ret = sscanf(buf, "%d", &datum); |
| 426 | if ((ret != 1) || (datum > 255)) |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 427 | return -EINVAL; |
| 428 | |
| 429 | /* A too small boot time will result in the device booting into |
| 430 | * standalone (no-host) mode before the host can take control of it, |
| 431 | * so the change will be hard to revert. This may be a desired |
| 432 | * feature (e.g to configure a very fast boot time for devices that |
| 433 | * will not be attached to a host), but dangerous. So I'm enforcing a |
| 434 | * lower limit of 20 seconds: remove and recompile the driver if this |
| 435 | * does not work for you. |
| 436 | */ |
| 437 | datum = (datum < 20) ? 20 : datum; |
| 438 | cmd.data[0] = datum; |
| 439 | cmd.length = cpu_to_le16(sizeof(uint8_t)); |
| 440 | ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET, |
| 441 | CMD_TYPE_MESH_SET_BOOTTIME); |
| 442 | if (ret) |
| 443 | return ret; |
| 444 | |
| 445 | return strlen(buf); |
| 446 | } |
| 447 | |
| 448 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 449 | * channel_get - Get function for sysfs attribute channel |
| 450 | * @dev: the &struct device |
| 451 | * @attr: device attributes |
| 452 | * @buf: buffer where data will be returned |
Javier Cardona | b679aeb | 2008-05-20 15:18:49 -0700 | [diff] [blame] | 453 | */ |
| 454 | static ssize_t channel_get(struct device *dev, |
| 455 | struct device_attribute *attr, char *buf) |
| 456 | { |
| 457 | struct mrvl_mesh_defaults defs; |
| 458 | int ret; |
| 459 | |
| 460 | ret = mesh_get_default_parameters(dev, &defs); |
| 461 | |
| 462 | if (ret) |
| 463 | return ret; |
| 464 | |
Brian Cavagnolo | fb90490 | 2008-07-16 12:15:26 -0700 | [diff] [blame] | 465 | return snprintf(buf, 12, "%d\n", le16_to_cpu(defs.channel)); |
Javier Cardona | b679aeb | 2008-05-20 15:18:49 -0700 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 469 | * channel_set - Set function for sysfs attribute channel |
| 470 | * @dev: the &struct device |
| 471 | * @attr: device attributes |
| 472 | * @buf: buffer that contains new attribute value |
| 473 | * @count: size of buffer |
Javier Cardona | b679aeb | 2008-05-20 15:18:49 -0700 | [diff] [blame] | 474 | */ |
| 475 | static ssize_t channel_set(struct device *dev, struct device_attribute *attr, |
| 476 | const char *buf, size_t count) |
| 477 | { |
Kiran Divekar | ab65f64 | 2009-02-19 19:32:39 -0500 | [diff] [blame] | 478 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
Javier Cardona | b679aeb | 2008-05-20 15:18:49 -0700 | [diff] [blame] | 479 | struct cmd_ds_mesh_config cmd; |
Brian Cavagnolo | fb90490 | 2008-07-16 12:15:26 -0700 | [diff] [blame] | 480 | uint32_t datum; |
Javier Cardona | b679aeb | 2008-05-20 15:18:49 -0700 | [diff] [blame] | 481 | int ret; |
| 482 | |
| 483 | memset(&cmd, 0, sizeof(cmd)); |
Brian Cavagnolo | fb90490 | 2008-07-16 12:15:26 -0700 | [diff] [blame] | 484 | ret = sscanf(buf, "%d", &datum); |
Javier Cardona | b679aeb | 2008-05-20 15:18:49 -0700 | [diff] [blame] | 485 | if (ret != 1 || datum < 1 || datum > 11) |
| 486 | return -EINVAL; |
| 487 | |
| 488 | *((__le16 *)&cmd.data[0]) = cpu_to_le16(datum); |
| 489 | cmd.length = cpu_to_le16(sizeof(uint16_t)); |
| 490 | ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET, |
| 491 | CMD_TYPE_MESH_SET_DEF_CHANNEL); |
| 492 | if (ret) |
| 493 | return ret; |
| 494 | |
| 495 | return strlen(buf); |
| 496 | } |
| 497 | |
| 498 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 499 | * mesh_id_get - Get function for sysfs attribute mesh_id |
| 500 | * @dev: the &struct device |
| 501 | * @attr: device attributes |
| 502 | * @buf: buffer where data will be returned |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 503 | */ |
| 504 | static ssize_t mesh_id_get(struct device *dev, struct device_attribute *attr, |
| 505 | char *buf) |
| 506 | { |
| 507 | struct mrvl_mesh_defaults defs; |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 508 | int ret; |
| 509 | |
| 510 | ret = mesh_get_default_parameters(dev, &defs); |
| 511 | |
| 512 | if (ret) |
| 513 | return ret; |
| 514 | |
Holger Schurig | 243e84e | 2009-10-22 15:30:47 +0200 | [diff] [blame] | 515 | if (defs.meshie.val.mesh_id_len > IEEE80211_MAX_SSID_LEN) { |
Joe Perches | f3a57fd | 2011-05-02 16:49:15 -0700 | [diff] [blame] | 516 | dev_err(dev, "inconsistent mesh ID length\n"); |
Holger Schurig | 243e84e | 2009-10-22 15:30:47 +0200 | [diff] [blame] | 517 | defs.meshie.val.mesh_id_len = IEEE80211_MAX_SSID_LEN; |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 518 | } |
| 519 | |
Dan Carpenter | d89dba7 | 2011-03-10 18:23:26 +0300 | [diff] [blame] | 520 | memcpy(buf, defs.meshie.val.mesh_id, defs.meshie.val.mesh_id_len); |
| 521 | buf[defs.meshie.val.mesh_id_len] = '\n'; |
| 522 | buf[defs.meshie.val.mesh_id_len + 1] = '\0'; |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 523 | |
Dan Carpenter | d89dba7 | 2011-03-10 18:23:26 +0300 | [diff] [blame] | 524 | return defs.meshie.val.mesh_id_len + 1; |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 528 | * mesh_id_set - Set function for sysfs attribute mesh_id |
| 529 | * @dev: the &struct device |
| 530 | * @attr: device attributes |
| 531 | * @buf: buffer that contains new attribute value |
| 532 | * @count: size of buffer |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 533 | */ |
| 534 | static ssize_t mesh_id_set(struct device *dev, struct device_attribute *attr, |
| 535 | const char *buf, size_t count) |
| 536 | { |
| 537 | struct cmd_ds_mesh_config cmd; |
| 538 | struct mrvl_mesh_defaults defs; |
| 539 | struct mrvl_meshie *ie; |
Kiran Divekar | ab65f64 | 2009-02-19 19:32:39 -0500 | [diff] [blame] | 540 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 541 | int len; |
| 542 | int ret; |
| 543 | |
Holger Schurig | 243e84e | 2009-10-22 15:30:47 +0200 | [diff] [blame] | 544 | if (count < 2 || count > IEEE80211_MAX_SSID_LEN + 1) |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 545 | return -EINVAL; |
| 546 | |
| 547 | memset(&cmd, 0, sizeof(struct cmd_ds_mesh_config)); |
| 548 | ie = (struct mrvl_meshie *) &cmd.data[0]; |
| 549 | |
| 550 | /* fetch all other Information Element parameters */ |
| 551 | ret = mesh_get_default_parameters(dev, &defs); |
| 552 | |
| 553 | cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie)); |
| 554 | |
| 555 | /* transfer IE elements */ |
| 556 | memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie)); |
| 557 | |
| 558 | len = count - 1; |
| 559 | memcpy(ie->val.mesh_id, buf, len); |
| 560 | /* SSID len */ |
| 561 | ie->val.mesh_id_len = len; |
| 562 | /* IE len */ |
Holger Schurig | 243e84e | 2009-10-22 15:30:47 +0200 | [diff] [blame] | 563 | ie->len = sizeof(struct mrvl_meshie_val) - IEEE80211_MAX_SSID_LEN + len; |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 564 | |
| 565 | ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET, |
| 566 | CMD_TYPE_MESH_SET_MESH_IE); |
| 567 | if (ret) |
| 568 | return ret; |
| 569 | |
| 570 | return strlen(buf); |
| 571 | } |
| 572 | |
| 573 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 574 | * protocol_id_get - Get function for sysfs attribute protocol_id |
| 575 | * @dev: the &struct device |
| 576 | * @attr: device attributes |
| 577 | * @buf: buffer where data will be returned |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 578 | */ |
| 579 | static ssize_t protocol_id_get(struct device *dev, |
| 580 | struct device_attribute *attr, char *buf) |
| 581 | { |
| 582 | struct mrvl_mesh_defaults defs; |
| 583 | int ret; |
| 584 | |
| 585 | ret = mesh_get_default_parameters(dev, &defs); |
| 586 | |
| 587 | if (ret) |
| 588 | return ret; |
| 589 | |
| 590 | return snprintf(buf, 5, "%d\n", defs.meshie.val.active_protocol_id); |
| 591 | } |
| 592 | |
| 593 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 594 | * protocol_id_set - Set function for sysfs attribute protocol_id |
| 595 | * @dev: the &struct device |
| 596 | * @attr: device attributes |
| 597 | * @buf: buffer that contains new attribute value |
| 598 | * @count: size of buffer |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 599 | */ |
| 600 | static ssize_t protocol_id_set(struct device *dev, |
| 601 | struct device_attribute *attr, const char *buf, size_t count) |
| 602 | { |
| 603 | struct cmd_ds_mesh_config cmd; |
| 604 | struct mrvl_mesh_defaults defs; |
| 605 | struct mrvl_meshie *ie; |
Kiran Divekar | ab65f64 | 2009-02-19 19:32:39 -0500 | [diff] [blame] | 606 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 607 | uint32_t datum; |
| 608 | int ret; |
| 609 | |
| 610 | memset(&cmd, 0, sizeof(cmd)); |
Brian Cavagnolo | fb90490 | 2008-07-16 12:15:26 -0700 | [diff] [blame] | 611 | ret = sscanf(buf, "%d", &datum); |
| 612 | if ((ret != 1) || (datum > 255)) |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 613 | return -EINVAL; |
| 614 | |
| 615 | /* fetch all other Information Element parameters */ |
| 616 | ret = mesh_get_default_parameters(dev, &defs); |
| 617 | |
| 618 | cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie)); |
| 619 | |
| 620 | /* transfer IE elements */ |
| 621 | ie = (struct mrvl_meshie *) &cmd.data[0]; |
| 622 | memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie)); |
| 623 | /* update protocol id */ |
| 624 | ie->val.active_protocol_id = datum; |
| 625 | |
| 626 | ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET, |
| 627 | CMD_TYPE_MESH_SET_MESH_IE); |
| 628 | if (ret) |
| 629 | return ret; |
| 630 | |
| 631 | return strlen(buf); |
| 632 | } |
| 633 | |
| 634 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 635 | * metric_id_get - Get function for sysfs attribute metric_id |
| 636 | * @dev: the &struct device |
| 637 | * @attr: device attributes |
| 638 | * @buf: buffer where data will be returned |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 639 | */ |
| 640 | static ssize_t metric_id_get(struct device *dev, |
| 641 | struct device_attribute *attr, char *buf) |
| 642 | { |
| 643 | struct mrvl_mesh_defaults defs; |
| 644 | int ret; |
| 645 | |
| 646 | ret = mesh_get_default_parameters(dev, &defs); |
| 647 | |
| 648 | if (ret) |
| 649 | return ret; |
| 650 | |
| 651 | return snprintf(buf, 5, "%d\n", defs.meshie.val.active_metric_id); |
| 652 | } |
| 653 | |
| 654 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 655 | * metric_id_set - Set function for sysfs attribute metric_id |
| 656 | * @dev: the &struct device |
| 657 | * @attr: device attributes |
| 658 | * @buf: buffer that contains new attribute value |
| 659 | * @count: size of buffer |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 660 | */ |
| 661 | static ssize_t metric_id_set(struct device *dev, struct device_attribute *attr, |
| 662 | const char *buf, size_t count) |
| 663 | { |
| 664 | struct cmd_ds_mesh_config cmd; |
| 665 | struct mrvl_mesh_defaults defs; |
| 666 | struct mrvl_meshie *ie; |
Kiran Divekar | ab65f64 | 2009-02-19 19:32:39 -0500 | [diff] [blame] | 667 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 668 | uint32_t datum; |
| 669 | int ret; |
| 670 | |
| 671 | memset(&cmd, 0, sizeof(cmd)); |
Brian Cavagnolo | fb90490 | 2008-07-16 12:15:26 -0700 | [diff] [blame] | 672 | ret = sscanf(buf, "%d", &datum); |
| 673 | if ((ret != 1) || (datum > 255)) |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 674 | return -EINVAL; |
| 675 | |
| 676 | /* fetch all other Information Element parameters */ |
| 677 | ret = mesh_get_default_parameters(dev, &defs); |
| 678 | |
| 679 | cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie)); |
| 680 | |
| 681 | /* transfer IE elements */ |
| 682 | ie = (struct mrvl_meshie *) &cmd.data[0]; |
| 683 | memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie)); |
| 684 | /* update metric id */ |
| 685 | ie->val.active_metric_id = datum; |
| 686 | |
| 687 | ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET, |
| 688 | CMD_TYPE_MESH_SET_MESH_IE); |
| 689 | if (ret) |
| 690 | return ret; |
| 691 | |
| 692 | return strlen(buf); |
| 693 | } |
| 694 | |
| 695 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 696 | * capability_get - Get function for sysfs attribute capability |
| 697 | * @dev: the &struct device |
| 698 | * @attr: device attributes |
| 699 | * @buf: buffer where data will be returned |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 700 | */ |
| 701 | static ssize_t capability_get(struct device *dev, |
| 702 | struct device_attribute *attr, char *buf) |
| 703 | { |
| 704 | struct mrvl_mesh_defaults defs; |
| 705 | int ret; |
| 706 | |
| 707 | ret = mesh_get_default_parameters(dev, &defs); |
| 708 | |
| 709 | if (ret) |
| 710 | return ret; |
| 711 | |
| 712 | return snprintf(buf, 5, "%d\n", defs.meshie.val.mesh_capability); |
| 713 | } |
| 714 | |
| 715 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 716 | * capability_set - Set function for sysfs attribute capability |
| 717 | * @dev: the &struct device |
| 718 | * @attr: device attributes |
| 719 | * @buf: buffer that contains new attribute value |
| 720 | * @count: size of buffer |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 721 | */ |
| 722 | static ssize_t capability_set(struct device *dev, struct device_attribute *attr, |
| 723 | const char *buf, size_t count) |
| 724 | { |
| 725 | struct cmd_ds_mesh_config cmd; |
| 726 | struct mrvl_mesh_defaults defs; |
| 727 | struct mrvl_meshie *ie; |
Kiran Divekar | ab65f64 | 2009-02-19 19:32:39 -0500 | [diff] [blame] | 728 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 729 | uint32_t datum; |
| 730 | int ret; |
| 731 | |
| 732 | memset(&cmd, 0, sizeof(cmd)); |
Brian Cavagnolo | fb90490 | 2008-07-16 12:15:26 -0700 | [diff] [blame] | 733 | ret = sscanf(buf, "%d", &datum); |
| 734 | if ((ret != 1) || (datum > 255)) |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 735 | return -EINVAL; |
| 736 | |
| 737 | /* fetch all other Information Element parameters */ |
| 738 | ret = mesh_get_default_parameters(dev, &defs); |
| 739 | |
| 740 | cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie)); |
| 741 | |
| 742 | /* transfer IE elements */ |
| 743 | ie = (struct mrvl_meshie *) &cmd.data[0]; |
| 744 | memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie)); |
| 745 | /* update value */ |
| 746 | ie->val.mesh_capability = datum; |
| 747 | |
| 748 | ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET, |
| 749 | CMD_TYPE_MESH_SET_MESH_IE); |
| 750 | if (ret) |
| 751 | return ret; |
| 752 | |
| 753 | return strlen(buf); |
| 754 | } |
| 755 | |
| 756 | |
| 757 | static DEVICE_ATTR(bootflag, 0644, bootflag_get, bootflag_set); |
| 758 | static DEVICE_ATTR(boottime, 0644, boottime_get, boottime_set); |
Javier Cardona | b679aeb | 2008-05-20 15:18:49 -0700 | [diff] [blame] | 759 | static DEVICE_ATTR(channel, 0644, channel_get, channel_set); |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 760 | static DEVICE_ATTR(mesh_id, 0644, mesh_id_get, mesh_id_set); |
| 761 | static DEVICE_ATTR(protocol_id, 0644, protocol_id_get, protocol_id_set); |
| 762 | static DEVICE_ATTR(metric_id, 0644, metric_id_get, metric_id_set); |
| 763 | static DEVICE_ATTR(capability, 0644, capability_get, capability_set); |
| 764 | |
| 765 | static struct attribute *boot_opts_attrs[] = { |
| 766 | &dev_attr_bootflag.attr, |
| 767 | &dev_attr_boottime.attr, |
Javier Cardona | b679aeb | 2008-05-20 15:18:49 -0700 | [diff] [blame] | 768 | &dev_attr_channel.attr, |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 769 | NULL |
| 770 | }; |
| 771 | |
Daniel Drake | 3db4f98 | 2011-07-20 17:53:50 +0100 | [diff] [blame] | 772 | static const struct attribute_group boot_opts_group = { |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 773 | .name = "boot_options", |
| 774 | .attrs = boot_opts_attrs, |
| 775 | }; |
| 776 | |
| 777 | static struct attribute *mesh_ie_attrs[] = { |
| 778 | &dev_attr_mesh_id.attr, |
| 779 | &dev_attr_protocol_id.attr, |
| 780 | &dev_attr_metric_id.attr, |
| 781 | &dev_attr_capability.attr, |
| 782 | NULL |
| 783 | }; |
| 784 | |
Daniel Drake | 3db4f98 | 2011-07-20 17:53:50 +0100 | [diff] [blame] | 785 | static const struct attribute_group mesh_ie_group = { |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 786 | .name = "mesh_ie", |
| 787 | .attrs = mesh_ie_attrs, |
| 788 | }; |
| 789 | |
Daniel Drake | 3db4f98 | 2011-07-20 17:53:50 +0100 | [diff] [blame] | 790 | static void lbs_persist_config_init(struct net_device *dev) |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 791 | { |
| 792 | int ret; |
| 793 | ret = sysfs_create_group(&(dev->dev.kobj), &boot_opts_group); |
| 794 | ret = sysfs_create_group(&(dev->dev.kobj), &mesh_ie_group); |
| 795 | } |
| 796 | |
Daniel Drake | 3db4f98 | 2011-07-20 17:53:50 +0100 | [diff] [blame] | 797 | static void lbs_persist_config_remove(struct net_device *dev) |
Javier Cardona | 15dbaac | 2008-05-17 21:01:24 -0700 | [diff] [blame] | 798 | { |
| 799 | sysfs_remove_group(&(dev->dev.kobj), &boot_opts_group); |
| 800 | sysfs_remove_group(&(dev->dev.kobj), &mesh_ie_group); |
| 801 | } |
Holger Schurig | c7fe64c | 2009-11-25 13:10:49 +0100 | [diff] [blame] | 802 | |
| 803 | |
Daniel Drake | 3db4f98 | 2011-07-20 17:53:50 +0100 | [diff] [blame] | 804 | /*************************************************************************** |
| 805 | * Initializing and starting, stopping mesh |
| 806 | */ |
| 807 | |
| 808 | /* |
| 809 | * Check mesh FW version and appropriately send the mesh start |
| 810 | * command |
| 811 | */ |
| 812 | int lbs_init_mesh(struct lbs_private *priv) |
| 813 | { |
| 814 | struct net_device *dev = priv->dev; |
| 815 | int ret = 0; |
| 816 | |
| 817 | lbs_deb_enter(LBS_DEB_MESH); |
| 818 | |
Daniel Drake | 3db4f98 | 2011-07-20 17:53:50 +0100 | [diff] [blame] | 819 | /* Determine mesh_fw_ver from fwrelease and fwcapinfo */ |
| 820 | /* 5.0.16p0 9.0.0.p0 is known to NOT support any mesh */ |
| 821 | /* 5.110.22 have mesh command with 0xa3 command id */ |
| 822 | /* 10.0.0.p0 FW brings in mesh config command with different id */ |
| 823 | /* Check FW version MSB and initialize mesh_fw_ver */ |
| 824 | if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V5) { |
| 825 | /* Enable mesh, if supported, and work out which TLV it uses. |
| 826 | 0x100 + 291 is an unofficial value used in 5.110.20.pXX |
| 827 | 0x100 + 37 is the official value used in 5.110.21.pXX |
| 828 | but we check them in that order because 20.pXX doesn't |
| 829 | give an error -- it just silently fails. */ |
| 830 | |
| 831 | /* 5.110.20.pXX firmware will fail the command if the channel |
| 832 | doesn't match the existing channel. But only if the TLV |
| 833 | is correct. If the channel is wrong, _BOTH_ versions will |
| 834 | give an error to 0x100+291, and allow 0x100+37 to succeed. |
| 835 | It's just that 5.110.20.pXX will not have done anything |
| 836 | useful */ |
| 837 | |
| 838 | priv->mesh_tlv = TLV_TYPE_OLD_MESH_ID; |
| 839 | if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, |
| 840 | priv->channel)) { |
| 841 | priv->mesh_tlv = TLV_TYPE_MESH_ID; |
| 842 | if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, |
| 843 | priv->channel)) |
| 844 | priv->mesh_tlv = 0; |
| 845 | } |
| 846 | } else |
| 847 | if ((MRVL_FW_MAJOR_REV(priv->fwrelease) >= MRVL_FW_V10) && |
| 848 | (priv->fwcapinfo & MESH_CAPINFO_ENABLE_MASK)) { |
| 849 | /* 10.0.0.pXX new firmwares should succeed with TLV |
| 850 | * 0x100+37; Do not invoke command with old TLV. |
| 851 | */ |
| 852 | priv->mesh_tlv = TLV_TYPE_MESH_ID; |
| 853 | if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, |
| 854 | priv->channel)) |
| 855 | priv->mesh_tlv = 0; |
| 856 | } |
| 857 | |
Daniel Drake | d931998 | 2011-07-20 17:53:56 +0100 | [diff] [blame^] | 858 | /* Stop meshing until interface is brought up */ |
| 859 | lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_STOP, priv->channel); |
Daniel Drake | 3db4f98 | 2011-07-20 17:53:50 +0100 | [diff] [blame] | 860 | |
| 861 | if (priv->mesh_tlv) { |
| 862 | sprintf(priv->mesh_ssid, "mesh"); |
| 863 | priv->mesh_ssid_len = 4; |
| 864 | |
| 865 | lbs_add_mesh(priv); |
| 866 | |
| 867 | if (device_create_file(&dev->dev, &dev_attr_lbs_mesh)) |
| 868 | netdev_err(dev, "cannot register lbs_mesh attribute\n"); |
| 869 | |
| 870 | ret = 1; |
| 871 | } |
| 872 | |
| 873 | lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret); |
| 874 | return ret; |
| 875 | } |
| 876 | |
| 877 | |
| 878 | int lbs_deinit_mesh(struct lbs_private *priv) |
| 879 | { |
| 880 | struct net_device *dev = priv->dev; |
| 881 | int ret = 0; |
| 882 | |
| 883 | lbs_deb_enter(LBS_DEB_MESH); |
| 884 | |
| 885 | if (priv->mesh_tlv) { |
| 886 | device_remove_file(&dev->dev, &dev_attr_lbs_mesh); |
| 887 | ret = 1; |
| 888 | } |
| 889 | |
| 890 | lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret); |
| 891 | return ret; |
| 892 | } |
| 893 | |
| 894 | |
| 895 | /** |
| 896 | * lbs_mesh_stop - close the mshX interface |
| 897 | * |
| 898 | * @dev: A pointer to &net_device structure |
| 899 | * returns: 0 |
| 900 | */ |
| 901 | static int lbs_mesh_stop(struct net_device *dev) |
| 902 | { |
| 903 | struct lbs_private *priv = dev->ml_priv; |
| 904 | |
| 905 | lbs_deb_enter(LBS_DEB_MESH); |
Daniel Drake | d931998 | 2011-07-20 17:53:56 +0100 | [diff] [blame^] | 906 | lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_STOP, priv->channel); |
Daniel Drake | 3db4f98 | 2011-07-20 17:53:50 +0100 | [diff] [blame] | 907 | |
Daniel Drake | d931998 | 2011-07-20 17:53:56 +0100 | [diff] [blame^] | 908 | spin_lock_irq(&priv->driver_lock); |
Daniel Drake | 3db4f98 | 2011-07-20 17:53:50 +0100 | [diff] [blame] | 909 | |
| 910 | netif_stop_queue(dev); |
| 911 | netif_carrier_off(dev); |
| 912 | |
| 913 | spin_unlock_irq(&priv->driver_lock); |
| 914 | |
| 915 | schedule_work(&priv->mcast_work); |
| 916 | |
| 917 | lbs_deb_leave(LBS_DEB_MESH); |
| 918 | return 0; |
| 919 | } |
| 920 | |
| 921 | /** |
| 922 | * lbs_mesh_dev_open - open the mshX interface |
| 923 | * |
| 924 | * @dev: A pointer to &net_device structure |
| 925 | * returns: 0 or -EBUSY if monitor mode active |
| 926 | */ |
| 927 | static int lbs_mesh_dev_open(struct net_device *dev) |
| 928 | { |
| 929 | struct lbs_private *priv = dev->ml_priv; |
| 930 | int ret = 0; |
| 931 | |
| 932 | lbs_deb_enter(LBS_DEB_NET); |
| 933 | |
| 934 | spin_lock_irq(&priv->driver_lock); |
| 935 | |
| 936 | if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR) { |
| 937 | ret = -EBUSY; |
Daniel Drake | d931998 | 2011-07-20 17:53:56 +0100 | [diff] [blame^] | 938 | spin_unlock_irq(&priv->driver_lock); |
Daniel Drake | 3db4f98 | 2011-07-20 17:53:50 +0100 | [diff] [blame] | 939 | goto out; |
| 940 | } |
| 941 | |
Daniel Drake | 3db4f98 | 2011-07-20 17:53:50 +0100 | [diff] [blame] | 942 | netif_carrier_on(dev); |
| 943 | |
| 944 | if (!priv->tx_pending_len) |
| 945 | netif_wake_queue(dev); |
Daniel Drake | 3db4f98 | 2011-07-20 17:53:50 +0100 | [diff] [blame] | 946 | |
| 947 | spin_unlock_irq(&priv->driver_lock); |
Daniel Drake | d931998 | 2011-07-20 17:53:56 +0100 | [diff] [blame^] | 948 | |
| 949 | ret = lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, priv->channel); |
| 950 | |
| 951 | out: |
Daniel Drake | 3db4f98 | 2011-07-20 17:53:50 +0100 | [diff] [blame] | 952 | lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret); |
| 953 | return ret; |
| 954 | } |
| 955 | |
| 956 | static const struct net_device_ops mesh_netdev_ops = { |
| 957 | .ndo_open = lbs_mesh_dev_open, |
| 958 | .ndo_stop = lbs_mesh_stop, |
| 959 | .ndo_start_xmit = lbs_hard_start_xmit, |
| 960 | .ndo_set_mac_address = lbs_set_mac_address, |
| 961 | .ndo_set_multicast_list = lbs_set_multicast_list, |
| 962 | }; |
| 963 | |
| 964 | /** |
| 965 | * lbs_add_mesh - add mshX interface |
| 966 | * |
| 967 | * @priv: A pointer to the &struct lbs_private structure |
| 968 | * returns: 0 if successful, -X otherwise |
| 969 | */ |
| 970 | static int lbs_add_mesh(struct lbs_private *priv) |
| 971 | { |
| 972 | struct net_device *mesh_dev = NULL; |
| 973 | int ret = 0; |
| 974 | |
| 975 | lbs_deb_enter(LBS_DEB_MESH); |
| 976 | |
| 977 | /* Allocate a virtual mesh device */ |
| 978 | mesh_dev = alloc_netdev(0, "msh%d", ether_setup); |
| 979 | if (!mesh_dev) { |
| 980 | lbs_deb_mesh("init mshX device failed\n"); |
| 981 | ret = -ENOMEM; |
| 982 | goto done; |
| 983 | } |
| 984 | mesh_dev->ml_priv = priv; |
| 985 | priv->mesh_dev = mesh_dev; |
| 986 | |
| 987 | mesh_dev->netdev_ops = &mesh_netdev_ops; |
| 988 | mesh_dev->ethtool_ops = &lbs_ethtool_ops; |
| 989 | memcpy(mesh_dev->dev_addr, priv->dev->dev_addr, ETH_ALEN); |
| 990 | |
| 991 | SET_NETDEV_DEV(priv->mesh_dev, priv->dev->dev.parent); |
| 992 | |
| 993 | mesh_dev->flags |= IFF_BROADCAST | IFF_MULTICAST; |
| 994 | /* Register virtual mesh interface */ |
| 995 | ret = register_netdev(mesh_dev); |
| 996 | if (ret) { |
| 997 | pr_err("cannot register mshX virtual interface\n"); |
| 998 | goto err_free; |
| 999 | } |
| 1000 | |
| 1001 | ret = sysfs_create_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group); |
| 1002 | if (ret) |
| 1003 | goto err_unregister; |
| 1004 | |
| 1005 | lbs_persist_config_init(mesh_dev); |
| 1006 | |
| 1007 | /* Everything successful */ |
| 1008 | ret = 0; |
| 1009 | goto done; |
| 1010 | |
| 1011 | err_unregister: |
| 1012 | unregister_netdev(mesh_dev); |
| 1013 | |
| 1014 | err_free: |
| 1015 | free_netdev(mesh_dev); |
| 1016 | |
| 1017 | done: |
| 1018 | lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret); |
| 1019 | return ret; |
| 1020 | } |
| 1021 | |
| 1022 | void lbs_remove_mesh(struct lbs_private *priv) |
| 1023 | { |
| 1024 | struct net_device *mesh_dev; |
| 1025 | |
| 1026 | mesh_dev = priv->mesh_dev; |
| 1027 | if (!mesh_dev) |
| 1028 | return; |
| 1029 | |
| 1030 | lbs_deb_enter(LBS_DEB_MESH); |
| 1031 | netif_stop_queue(mesh_dev); |
| 1032 | netif_carrier_off(mesh_dev); |
| 1033 | sysfs_remove_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group); |
| 1034 | lbs_persist_config_remove(mesh_dev); |
| 1035 | unregister_netdev(mesh_dev); |
| 1036 | priv->mesh_dev = NULL; |
| 1037 | free_netdev(mesh_dev); |
| 1038 | lbs_deb_leave(LBS_DEB_MESH); |
| 1039 | } |
| 1040 | |
| 1041 | |
| 1042 | /*************************************************************************** |
| 1043 | * Sending and receiving |
| 1044 | */ |
| 1045 | struct net_device *lbs_mesh_set_dev(struct lbs_private *priv, |
| 1046 | struct net_device *dev, struct rxpd *rxpd) |
| 1047 | { |
| 1048 | if (priv->mesh_dev) { |
| 1049 | if (priv->mesh_tlv == TLV_TYPE_OLD_MESH_ID) { |
| 1050 | if (rxpd->rx_control & RxPD_MESH_FRAME) |
| 1051 | dev = priv->mesh_dev; |
| 1052 | } else if (priv->mesh_tlv == TLV_TYPE_MESH_ID) { |
| 1053 | if (rxpd->u.bss.bss_num == MESH_IFACE_ID) |
| 1054 | dev = priv->mesh_dev; |
| 1055 | } |
| 1056 | } |
| 1057 | return dev; |
| 1058 | } |
| 1059 | |
| 1060 | |
| 1061 | void lbs_mesh_set_txpd(struct lbs_private *priv, |
| 1062 | struct net_device *dev, struct txpd *txpd) |
| 1063 | { |
| 1064 | if (dev == priv->mesh_dev) { |
| 1065 | if (priv->mesh_tlv == TLV_TYPE_OLD_MESH_ID) |
| 1066 | txpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME); |
| 1067 | else if (priv->mesh_tlv == TLV_TYPE_MESH_ID) |
| 1068 | txpd->u.bss.bss_num = MESH_IFACE_ID; |
| 1069 | } |
| 1070 | } |
| 1071 | |
Holger Schurig | c7fe64c | 2009-11-25 13:10:49 +0100 | [diff] [blame] | 1072 | |
| 1073 | /*************************************************************************** |
| 1074 | * Ethtool related |
| 1075 | */ |
| 1076 | |
Daniel Drake | 3db4f98 | 2011-07-20 17:53:50 +0100 | [diff] [blame] | 1077 | static const char * const mesh_stat_strings[] = { |
Holger Schurig | c7fe64c | 2009-11-25 13:10:49 +0100 | [diff] [blame] | 1078 | "drop_duplicate_bcast", |
| 1079 | "drop_ttl_zero", |
| 1080 | "drop_no_fwd_route", |
| 1081 | "drop_no_buffers", |
| 1082 | "fwded_unicast_cnt", |
| 1083 | "fwded_bcast_cnt", |
| 1084 | "drop_blind_table", |
| 1085 | "tx_failed_cnt" |
| 1086 | }; |
| 1087 | |
| 1088 | void lbs_mesh_ethtool_get_stats(struct net_device *dev, |
| 1089 | struct ethtool_stats *stats, uint64_t *data) |
| 1090 | { |
| 1091 | struct lbs_private *priv = dev->ml_priv; |
| 1092 | struct cmd_ds_mesh_access mesh_access; |
| 1093 | int ret; |
| 1094 | |
| 1095 | lbs_deb_enter(LBS_DEB_ETHTOOL); |
| 1096 | |
| 1097 | /* Get Mesh Statistics */ |
| 1098 | ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_STATS, &mesh_access); |
| 1099 | |
| 1100 | if (ret) { |
| 1101 | memset(data, 0, MESH_STATS_NUM*(sizeof(uint64_t))); |
| 1102 | return; |
| 1103 | } |
| 1104 | |
| 1105 | priv->mstats.fwd_drop_rbt = le32_to_cpu(mesh_access.data[0]); |
| 1106 | priv->mstats.fwd_drop_ttl = le32_to_cpu(mesh_access.data[1]); |
| 1107 | priv->mstats.fwd_drop_noroute = le32_to_cpu(mesh_access.data[2]); |
| 1108 | priv->mstats.fwd_drop_nobuf = le32_to_cpu(mesh_access.data[3]); |
| 1109 | priv->mstats.fwd_unicast_cnt = le32_to_cpu(mesh_access.data[4]); |
| 1110 | priv->mstats.fwd_bcast_cnt = le32_to_cpu(mesh_access.data[5]); |
| 1111 | priv->mstats.drop_blind = le32_to_cpu(mesh_access.data[6]); |
| 1112 | priv->mstats.tx_failed_cnt = le32_to_cpu(mesh_access.data[7]); |
| 1113 | |
| 1114 | data[0] = priv->mstats.fwd_drop_rbt; |
| 1115 | data[1] = priv->mstats.fwd_drop_ttl; |
| 1116 | data[2] = priv->mstats.fwd_drop_noroute; |
| 1117 | data[3] = priv->mstats.fwd_drop_nobuf; |
| 1118 | data[4] = priv->mstats.fwd_unicast_cnt; |
| 1119 | data[5] = priv->mstats.fwd_bcast_cnt; |
| 1120 | data[6] = priv->mstats.drop_blind; |
| 1121 | data[7] = priv->mstats.tx_failed_cnt; |
| 1122 | |
| 1123 | lbs_deb_enter(LBS_DEB_ETHTOOL); |
| 1124 | } |
| 1125 | |
| 1126 | int lbs_mesh_ethtool_get_sset_count(struct net_device *dev, int sset) |
| 1127 | { |
| 1128 | struct lbs_private *priv = dev->ml_priv; |
| 1129 | |
| 1130 | if (sset == ETH_SS_STATS && dev == priv->mesh_dev) |
| 1131 | return MESH_STATS_NUM; |
| 1132 | |
| 1133 | return -EOPNOTSUPP; |
| 1134 | } |
| 1135 | |
| 1136 | void lbs_mesh_ethtool_get_strings(struct net_device *dev, |
| 1137 | uint32_t stringset, uint8_t *s) |
| 1138 | { |
| 1139 | int i; |
| 1140 | |
| 1141 | lbs_deb_enter(LBS_DEB_ETHTOOL); |
| 1142 | |
| 1143 | switch (stringset) { |
| 1144 | case ETH_SS_STATS: |
| 1145 | for (i = 0; i < MESH_STATS_NUM; i++) { |
| 1146 | memcpy(s + i * ETH_GSTRING_LEN, |
| 1147 | mesh_stat_strings[i], |
| 1148 | ETH_GSTRING_LEN); |
| 1149 | } |
| 1150 | break; |
| 1151 | } |
| 1152 | lbs_deb_enter(LBS_DEB_ETHTOOL); |
| 1153 | } |