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