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