1 #include <linux/moduleparam.h>
2 #include <linux/delay.h>
3 #include <linux/etherdevice.h>
4 #include <linux/netdevice.h>
5 #include <linux/if_ether.h>
6 #include <linux/if_arp.h>
7 #include <linux/kthread.h>
8 #include <linux/kfifo.h>
15 /***************************************************************************
20 * Attributes exported through sysfs
24 * @brief Get function for sysfs attribute anycast_mask
26 static ssize_t lbs_anycast_get(struct device *dev,
27 struct device_attribute *attr, char * buf)
29 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
30 struct cmd_ds_mesh_access mesh_access;
33 memset(&mesh_access, 0, sizeof(mesh_access));
35 ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_ANYCAST, &mesh_access);
39 return snprintf(buf, 12, "0x%X\n", le32_to_cpu(mesh_access.data[0]));
43 * @brief Set function for sysfs attribute anycast_mask
45 static ssize_t lbs_anycast_set(struct device *dev,
46 struct device_attribute *attr, const char * buf, size_t count)
48 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
49 struct cmd_ds_mesh_access mesh_access;
53 memset(&mesh_access, 0, sizeof(mesh_access));
54 sscanf(buf, "%x", &datum);
55 mesh_access.data[0] = cpu_to_le32(datum);
57 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_ANYCAST, &mesh_access);
65 * @brief Get function for sysfs attribute prb_rsp_limit
67 static ssize_t lbs_prb_rsp_limit_get(struct device *dev,
68 struct device_attribute *attr, char *buf)
70 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
71 struct cmd_ds_mesh_access mesh_access;
75 memset(&mesh_access, 0, sizeof(mesh_access));
76 mesh_access.data[0] = cpu_to_le32(CMD_ACT_GET);
78 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT,
83 retry_limit = le32_to_cpu(mesh_access.data[1]);
84 return snprintf(buf, 10, "%d\n", retry_limit);
88 * @brief Set function for sysfs attribute prb_rsp_limit
90 static ssize_t lbs_prb_rsp_limit_set(struct device *dev,
91 struct device_attribute *attr, const char *buf, size_t count)
93 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
94 struct cmd_ds_mesh_access mesh_access;
96 unsigned long retry_limit;
98 memset(&mesh_access, 0, sizeof(mesh_access));
99 mesh_access.data[0] = cpu_to_le32(CMD_ACT_SET);
101 if (!strict_strtoul(buf, 10, &retry_limit))
103 if (retry_limit > 15)
106 mesh_access.data[1] = cpu_to_le32(retry_limit);
108 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT,
117 * Get function for sysfs attribute mesh
119 static ssize_t lbs_mesh_get(struct device *dev,
120 struct device_attribute *attr, char * buf)
122 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
123 return snprintf(buf, 5, "0x%X\n", !!priv->mesh_dev);
127 * Set function for sysfs attribute mesh
129 static ssize_t lbs_mesh_set(struct device *dev,
130 struct device_attribute *attr, const char * buf, size_t count)
132 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
134 int ret, action = CMD_ACT_MESH_CONFIG_STOP;
136 sscanf(buf, "%x", &enable);
138 if (enable == !!priv->mesh_dev)
141 action = CMD_ACT_MESH_CONFIG_START;
142 ret = lbs_mesh_config(priv, action, priv->channel);
149 lbs_remove_mesh(priv);
155 * lbs_mesh attribute to be exported per ethX interface
156 * through sysfs (/sys/class/net/ethX/lbs_mesh)
158 static DEVICE_ATTR(lbs_mesh, 0644, lbs_mesh_get, lbs_mesh_set);
161 * anycast_mask attribute to be exported per mshX interface
162 * through sysfs (/sys/class/net/mshX/anycast_mask)
164 static DEVICE_ATTR(anycast_mask, 0644, lbs_anycast_get, lbs_anycast_set);
167 * prb_rsp_limit attribute to be exported per mshX interface
168 * through sysfs (/sys/class/net/mshX/prb_rsp_limit)
170 static DEVICE_ATTR(prb_rsp_limit, 0644, lbs_prb_rsp_limit_get,
171 lbs_prb_rsp_limit_set);
173 static struct attribute *lbs_mesh_sysfs_entries[] = {
174 &dev_attr_anycast_mask.attr,
175 &dev_attr_prb_rsp_limit.attr,
179 static struct attribute_group lbs_mesh_attr_group = {
180 .attrs = lbs_mesh_sysfs_entries,
185 /***************************************************************************
186 * Initializing and starting, stopping mesh
190 * Check mesh FW version and appropriately send the mesh start
193 int lbs_init_mesh(struct lbs_private *priv)
195 struct net_device *dev = priv->dev;
198 lbs_deb_enter(LBS_DEB_MESH);
200 if (priv->mesh_fw_ver == MESH_FW_OLD) {
201 /* Enable mesh, if supported, and work out which TLV it uses.
202 0x100 + 291 is an unofficial value used in 5.110.20.pXX
203 0x100 + 37 is the official value used in 5.110.21.pXX
204 but we check them in that order because 20.pXX doesn't
205 give an error -- it just silently fails. */
207 /* 5.110.20.pXX firmware will fail the command if the channel
208 doesn't match the existing channel. But only if the TLV
209 is correct. If the channel is wrong, _BOTH_ versions will
210 give an error to 0x100+291, and allow 0x100+37 to succeed.
211 It's just that 5.110.20.pXX will not have done anything
214 priv->mesh_tlv = TLV_TYPE_OLD_MESH_ID;
215 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
217 priv->mesh_tlv = TLV_TYPE_MESH_ID;
218 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
222 } else if (priv->mesh_fw_ver == MESH_FW_NEW) {
223 /* 10.0.0.pXX new firmwares should succeed with TLV
224 * 0x100+37; Do not invoke command with old TLV.
226 priv->mesh_tlv = TLV_TYPE_MESH_ID;
227 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
231 if (priv->mesh_tlv) {
234 if (device_create_file(&dev->dev, &dev_attr_lbs_mesh))
235 lbs_pr_err("cannot register lbs_mesh attribute\n");
240 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
245 int lbs_deinit_mesh(struct lbs_private *priv)
247 struct net_device *dev = priv->dev;
250 lbs_deb_enter(LBS_DEB_MESH);
252 if (priv->mesh_tlv) {
253 device_remove_file(&dev->dev, &dev_attr_lbs_mesh);
257 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
263 * @brief This function closes the mshX interface
265 * @param dev A pointer to net_device structure
268 static int lbs_mesh_stop(struct net_device *dev)
270 struct lbs_private *priv = dev->ml_priv;
272 lbs_deb_enter(LBS_DEB_MESH);
273 spin_lock_irq(&priv->driver_lock);
276 priv->mesh_connect_status = LBS_DISCONNECTED;
278 netif_stop_queue(dev);
279 netif_carrier_off(dev);
281 spin_unlock_irq(&priv->driver_lock);
283 schedule_work(&priv->mcast_work);
285 lbs_deb_leave(LBS_DEB_MESH);
290 * @brief This function opens the mshX interface
292 * @param dev A pointer to net_device structure
293 * @return 0 or -EBUSY if monitor mode active
295 static int lbs_mesh_dev_open(struct net_device *dev)
297 struct lbs_private *priv = dev->ml_priv;
300 lbs_deb_enter(LBS_DEB_NET);
302 spin_lock_irq(&priv->driver_lock);
304 if (priv->monitormode) {
310 priv->mesh_connect_status = LBS_CONNECTED;
311 netif_carrier_on(dev);
313 if (!priv->tx_pending_len)
314 netif_wake_queue(dev);
317 spin_unlock_irq(&priv->driver_lock);
318 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
322 static const struct net_device_ops mesh_netdev_ops = {
323 .ndo_open = lbs_mesh_dev_open,
324 .ndo_stop = lbs_mesh_stop,
325 .ndo_start_xmit = lbs_hard_start_xmit,
326 .ndo_set_mac_address = lbs_set_mac_address,
327 .ndo_set_multicast_list = lbs_set_multicast_list,
331 * @brief This function adds mshX interface
333 * @param priv A pointer to the struct lbs_private structure
334 * @return 0 if successful, -X otherwise
336 int lbs_add_mesh(struct lbs_private *priv)
338 struct net_device *mesh_dev = NULL;
341 lbs_deb_enter(LBS_DEB_MESH);
343 /* Allocate a virtual mesh device */
344 mesh_dev = alloc_netdev(0, "msh%d", ether_setup);
346 lbs_deb_mesh("init mshX device failed\n");
350 mesh_dev->ml_priv = priv;
351 priv->mesh_dev = mesh_dev;
353 mesh_dev->netdev_ops = &mesh_netdev_ops;
354 mesh_dev->ethtool_ops = &lbs_ethtool_ops;
355 memcpy(mesh_dev->dev_addr, priv->dev->dev_addr, ETH_ALEN);
357 SET_NETDEV_DEV(priv->mesh_dev, priv->dev->dev.parent);
360 mesh_dev->wireless_handlers = &mesh_handler_def;
362 mesh_dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
363 /* Register virtual mesh interface */
364 ret = register_netdev(mesh_dev);
366 lbs_pr_err("cannot register mshX virtual interface\n");
370 ret = sysfs_create_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
374 lbs_persist_config_init(mesh_dev);
376 /* Everything successful */
381 unregister_netdev(mesh_dev);
384 free_netdev(mesh_dev);
387 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
391 void lbs_remove_mesh(struct lbs_private *priv)
393 struct net_device *mesh_dev;
395 mesh_dev = priv->mesh_dev;
399 lbs_deb_enter(LBS_DEB_MESH);
400 netif_stop_queue(mesh_dev);
401 netif_carrier_off(mesh_dev);
402 sysfs_remove_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
403 lbs_persist_config_remove(mesh_dev);
404 unregister_netdev(mesh_dev);
405 priv->mesh_dev = NULL;
406 free_netdev(mesh_dev);
407 lbs_deb_leave(LBS_DEB_MESH);
412 /***************************************************************************
413 * Sending and receiving
415 struct net_device *lbs_mesh_set_dev(struct lbs_private *priv,
416 struct net_device *dev, struct rxpd *rxpd)
418 if (priv->mesh_dev) {
419 if (priv->mesh_fw_ver == MESH_FW_OLD) {
420 if (rxpd->rx_control & RxPD_MESH_FRAME)
421 dev = priv->mesh_dev;
422 } else if (priv->mesh_fw_ver == MESH_FW_NEW) {
423 if (rxpd->u.bss.bss_num == MESH_IFACE_ID)
424 dev = priv->mesh_dev;
431 void lbs_mesh_set_txpd(struct lbs_private *priv,
432 struct net_device *dev, struct txpd *txpd)
434 if (dev == priv->mesh_dev) {
435 if (priv->mesh_fw_ver == MESH_FW_OLD)
436 txpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
437 else if (priv->mesh_fw_ver == MESH_FW_NEW)
438 txpd->u.bss.bss_num = MESH_IFACE_ID;
443 /***************************************************************************
444 * Mesh command handling
447 int lbs_cmd_bt_access(struct cmd_ds_command *cmd,
448 u16 cmd_action, void *pdata_buf)
450 struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
451 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
453 cmd->command = cpu_to_le16(CMD_BT_ACCESS);
454 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) +
455 sizeof(struct cmd_header));
457 bt_access->action = cpu_to_le16(cmd_action);
459 switch (cmd_action) {
460 case CMD_ACT_BT_ACCESS_ADD:
461 memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
462 lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr",
463 bt_access->addr1, 6);
465 case CMD_ACT_BT_ACCESS_DEL:
466 memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
467 lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr",
468 bt_access->addr1, 6);
470 case CMD_ACT_BT_ACCESS_LIST:
471 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
473 case CMD_ACT_BT_ACCESS_RESET:
475 case CMD_ACT_BT_ACCESS_SET_INVERT:
476 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
478 case CMD_ACT_BT_ACCESS_GET_INVERT:
483 lbs_deb_leave(LBS_DEB_CMD);
487 int lbs_cmd_fwt_access(struct cmd_ds_command *cmd,
488 u16 cmd_action, void *pdata_buf)
490 struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
491 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
493 cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
494 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) +
495 sizeof(struct cmd_header));
499 memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
501 memset(fwt_access, 0, sizeof(*fwt_access));
503 fwt_access->action = cpu_to_le16(cmd_action);
505 lbs_deb_leave(LBS_DEB_CMD);
509 int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
510 struct cmd_ds_mesh_access *cmd)
514 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
516 cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
517 cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
520 cmd->action = cpu_to_le16(cmd_action);
522 ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
524 lbs_deb_leave(LBS_DEB_CMD);
528 static int __lbs_mesh_config_send(struct lbs_private *priv,
529 struct cmd_ds_mesh_config *cmd,
530 uint16_t action, uint16_t type)
533 u16 command = CMD_MESH_CONFIG_OLD;
535 lbs_deb_enter(LBS_DEB_CMD);
538 * Command id is 0xac for v10 FW along with mesh interface
539 * id in bits 14-13-12.
541 if (priv->mesh_fw_ver == MESH_FW_NEW)
542 command = CMD_MESH_CONFIG |
543 (MESH_IFACE_ID << MESH_IFACE_BIT_OFFSET);
545 cmd->hdr.command = cpu_to_le16(command);
546 cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config));
549 cmd->type = cpu_to_le16(type);
550 cmd->action = cpu_to_le16(action);
552 ret = lbs_cmd_with_response(priv, command, cmd);
554 lbs_deb_leave(LBS_DEB_CMD);
558 int lbs_mesh_config_send(struct lbs_private *priv,
559 struct cmd_ds_mesh_config *cmd,
560 uint16_t action, uint16_t type)
564 if (!(priv->fwcapinfo & FW_CAPINFO_PERSISTENT_CONFIG))
567 ret = __lbs_mesh_config_send(priv, cmd, action, type);
571 /* This function is the CMD_MESH_CONFIG legacy function. It only handles the
572 * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG
573 * are all handled by preparing a struct cmd_ds_mesh_config and passing it to
574 * lbs_mesh_config_send.
576 int lbs_mesh_config(struct lbs_private *priv, uint16_t action, uint16_t chan)
578 struct cmd_ds_mesh_config cmd;
579 struct mrvl_meshie *ie;
580 DECLARE_SSID_BUF(ssid);
582 memset(&cmd, 0, sizeof(cmd));
583 cmd.channel = cpu_to_le16(chan);
584 ie = (struct mrvl_meshie *)cmd.data;
587 case CMD_ACT_MESH_CONFIG_START:
588 ie->id = WLAN_EID_GENERIC;
589 ie->val.oui[0] = 0x00;
590 ie->val.oui[1] = 0x50;
591 ie->val.oui[2] = 0x43;
592 ie->val.type = MARVELL_MESH_IE_TYPE;
593 ie->val.subtype = MARVELL_MESH_IE_SUBTYPE;
594 ie->val.version = MARVELL_MESH_IE_VERSION;
595 ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP;
596 ie->val.active_metric_id = MARVELL_MESH_METRIC_ID;
597 ie->val.mesh_capability = MARVELL_MESH_CAPABILITY;
598 ie->val.mesh_id_len = priv->mesh_ssid_len;
599 memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len);
600 ie->len = sizeof(struct mrvl_meshie_val) -
601 IEEE80211_MAX_SSID_LEN + priv->mesh_ssid_len;
602 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val));
604 case CMD_ACT_MESH_CONFIG_STOP:
609 lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n",
610 action, priv->mesh_tlv, chan,
611 print_ssid(ssid, priv->mesh_ssid, priv->mesh_ssid_len));
613 return __lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv);
618 /***************************************************************************
619 * Persistent configuration support
622 static int mesh_get_default_parameters(struct device *dev,
623 struct mrvl_mesh_defaults *defs)
625 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
626 struct cmd_ds_mesh_config cmd;
629 memset(&cmd, 0, sizeof(struct cmd_ds_mesh_config));
630 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_GET,
631 CMD_TYPE_MESH_GET_DEFAULTS);
636 memcpy(defs, &cmd.data[0], sizeof(struct mrvl_mesh_defaults));
642 * @brief Get function for sysfs attribute bootflag
644 static ssize_t bootflag_get(struct device *dev,
645 struct device_attribute *attr, char *buf)
647 struct mrvl_mesh_defaults defs;
650 ret = mesh_get_default_parameters(dev, &defs);
655 return snprintf(buf, 12, "%d\n", le32_to_cpu(defs.bootflag));
659 * @brief Set function for sysfs attribute bootflag
661 static ssize_t bootflag_set(struct device *dev, struct device_attribute *attr,
662 const char *buf, size_t count)
664 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
665 struct cmd_ds_mesh_config cmd;
669 memset(&cmd, 0, sizeof(cmd));
670 ret = sscanf(buf, "%d", &datum);
671 if ((ret != 1) || (datum > 1))
674 *((__le32 *)&cmd.data[0]) = cpu_to_le32(!!datum);
675 cmd.length = cpu_to_le16(sizeof(uint32_t));
676 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
677 CMD_TYPE_MESH_SET_BOOTFLAG);
685 * @brief Get function for sysfs attribute boottime
687 static ssize_t boottime_get(struct device *dev,
688 struct device_attribute *attr, char *buf)
690 struct mrvl_mesh_defaults defs;
693 ret = mesh_get_default_parameters(dev, &defs);
698 return snprintf(buf, 12, "%d\n", defs.boottime);
702 * @brief Set function for sysfs attribute boottime
704 static ssize_t boottime_set(struct device *dev,
705 struct device_attribute *attr, const char *buf, size_t count)
707 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
708 struct cmd_ds_mesh_config cmd;
712 memset(&cmd, 0, sizeof(cmd));
713 ret = sscanf(buf, "%d", &datum);
714 if ((ret != 1) || (datum > 255))
717 /* A too small boot time will result in the device booting into
718 * standalone (no-host) mode before the host can take control of it,
719 * so the change will be hard to revert. This may be a desired
720 * feature (e.g to configure a very fast boot time for devices that
721 * will not be attached to a host), but dangerous. So I'm enforcing a
722 * lower limit of 20 seconds: remove and recompile the driver if this
723 * does not work for you.
725 datum = (datum < 20) ? 20 : datum;
727 cmd.length = cpu_to_le16(sizeof(uint8_t));
728 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
729 CMD_TYPE_MESH_SET_BOOTTIME);
737 * @brief Get function for sysfs attribute channel
739 static ssize_t channel_get(struct device *dev,
740 struct device_attribute *attr, char *buf)
742 struct mrvl_mesh_defaults defs;
745 ret = mesh_get_default_parameters(dev, &defs);
750 return snprintf(buf, 12, "%d\n", le16_to_cpu(defs.channel));
754 * @brief Set function for sysfs attribute channel
756 static ssize_t channel_set(struct device *dev, struct device_attribute *attr,
757 const char *buf, size_t count)
759 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
760 struct cmd_ds_mesh_config cmd;
764 memset(&cmd, 0, sizeof(cmd));
765 ret = sscanf(buf, "%d", &datum);
766 if (ret != 1 || datum < 1 || datum > 11)
769 *((__le16 *)&cmd.data[0]) = cpu_to_le16(datum);
770 cmd.length = cpu_to_le16(sizeof(uint16_t));
771 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
772 CMD_TYPE_MESH_SET_DEF_CHANNEL);
780 * @brief Get function for sysfs attribute mesh_id
782 static ssize_t mesh_id_get(struct device *dev, struct device_attribute *attr,
785 struct mrvl_mesh_defaults defs;
789 ret = mesh_get_default_parameters(dev, &defs);
794 if (defs.meshie.val.mesh_id_len > IEEE80211_MAX_SSID_LEN) {
795 lbs_pr_err("inconsistent mesh ID length");
796 defs.meshie.val.mesh_id_len = IEEE80211_MAX_SSID_LEN;
799 /* SSID not null terminated: reserve room for \0 + \n */
800 maxlen = defs.meshie.val.mesh_id_len + 2;
801 maxlen = (PAGE_SIZE > maxlen) ? maxlen : PAGE_SIZE;
803 defs.meshie.val.mesh_id[defs.meshie.val.mesh_id_len] = '\0';
805 return snprintf(buf, maxlen, "%s\n", defs.meshie.val.mesh_id);
809 * @brief Set function for sysfs attribute mesh_id
811 static ssize_t mesh_id_set(struct device *dev, struct device_attribute *attr,
812 const char *buf, size_t count)
814 struct cmd_ds_mesh_config cmd;
815 struct mrvl_mesh_defaults defs;
816 struct mrvl_meshie *ie;
817 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
821 if (count < 2 || count > IEEE80211_MAX_SSID_LEN + 1)
824 memset(&cmd, 0, sizeof(struct cmd_ds_mesh_config));
825 ie = (struct mrvl_meshie *) &cmd.data[0];
827 /* fetch all other Information Element parameters */
828 ret = mesh_get_default_parameters(dev, &defs);
830 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
832 /* transfer IE elements */
833 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
836 memcpy(ie->val.mesh_id, buf, len);
838 ie->val.mesh_id_len = len;
840 ie->len = sizeof(struct mrvl_meshie_val) - IEEE80211_MAX_SSID_LEN + len;
842 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
843 CMD_TYPE_MESH_SET_MESH_IE);
851 * @brief Get function for sysfs attribute protocol_id
853 static ssize_t protocol_id_get(struct device *dev,
854 struct device_attribute *attr, char *buf)
856 struct mrvl_mesh_defaults defs;
859 ret = mesh_get_default_parameters(dev, &defs);
864 return snprintf(buf, 5, "%d\n", defs.meshie.val.active_protocol_id);
868 * @brief Set function for sysfs attribute protocol_id
870 static ssize_t protocol_id_set(struct device *dev,
871 struct device_attribute *attr, const char *buf, size_t count)
873 struct cmd_ds_mesh_config cmd;
874 struct mrvl_mesh_defaults defs;
875 struct mrvl_meshie *ie;
876 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
880 memset(&cmd, 0, sizeof(cmd));
881 ret = sscanf(buf, "%d", &datum);
882 if ((ret != 1) || (datum > 255))
885 /* fetch all other Information Element parameters */
886 ret = mesh_get_default_parameters(dev, &defs);
888 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
890 /* transfer IE elements */
891 ie = (struct mrvl_meshie *) &cmd.data[0];
892 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
893 /* update protocol id */
894 ie->val.active_protocol_id = datum;
896 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
897 CMD_TYPE_MESH_SET_MESH_IE);
905 * @brief Get function for sysfs attribute metric_id
907 static ssize_t metric_id_get(struct device *dev,
908 struct device_attribute *attr, char *buf)
910 struct mrvl_mesh_defaults defs;
913 ret = mesh_get_default_parameters(dev, &defs);
918 return snprintf(buf, 5, "%d\n", defs.meshie.val.active_metric_id);
922 * @brief Set function for sysfs attribute metric_id
924 static ssize_t metric_id_set(struct device *dev, struct device_attribute *attr,
925 const char *buf, size_t count)
927 struct cmd_ds_mesh_config cmd;
928 struct mrvl_mesh_defaults defs;
929 struct mrvl_meshie *ie;
930 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
934 memset(&cmd, 0, sizeof(cmd));
935 ret = sscanf(buf, "%d", &datum);
936 if ((ret != 1) || (datum > 255))
939 /* fetch all other Information Element parameters */
940 ret = mesh_get_default_parameters(dev, &defs);
942 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
944 /* transfer IE elements */
945 ie = (struct mrvl_meshie *) &cmd.data[0];
946 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
947 /* update metric id */
948 ie->val.active_metric_id = datum;
950 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
951 CMD_TYPE_MESH_SET_MESH_IE);
959 * @brief Get function for sysfs attribute capability
961 static ssize_t capability_get(struct device *dev,
962 struct device_attribute *attr, char *buf)
964 struct mrvl_mesh_defaults defs;
967 ret = mesh_get_default_parameters(dev, &defs);
972 return snprintf(buf, 5, "%d\n", defs.meshie.val.mesh_capability);
976 * @brief Set function for sysfs attribute capability
978 static ssize_t capability_set(struct device *dev, struct device_attribute *attr,
979 const char *buf, size_t count)
981 struct cmd_ds_mesh_config cmd;
982 struct mrvl_mesh_defaults defs;
983 struct mrvl_meshie *ie;
984 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
988 memset(&cmd, 0, sizeof(cmd));
989 ret = sscanf(buf, "%d", &datum);
990 if ((ret != 1) || (datum > 255))
993 /* fetch all other Information Element parameters */
994 ret = mesh_get_default_parameters(dev, &defs);
996 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
998 /* transfer IE elements */
999 ie = (struct mrvl_meshie *) &cmd.data[0];
1000 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
1002 ie->val.mesh_capability = datum;
1004 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
1005 CMD_TYPE_MESH_SET_MESH_IE);
1013 static DEVICE_ATTR(bootflag, 0644, bootflag_get, bootflag_set);
1014 static DEVICE_ATTR(boottime, 0644, boottime_get, boottime_set);
1015 static DEVICE_ATTR(channel, 0644, channel_get, channel_set);
1016 static DEVICE_ATTR(mesh_id, 0644, mesh_id_get, mesh_id_set);
1017 static DEVICE_ATTR(protocol_id, 0644, protocol_id_get, protocol_id_set);
1018 static DEVICE_ATTR(metric_id, 0644, metric_id_get, metric_id_set);
1019 static DEVICE_ATTR(capability, 0644, capability_get, capability_set);
1021 static struct attribute *boot_opts_attrs[] = {
1022 &dev_attr_bootflag.attr,
1023 &dev_attr_boottime.attr,
1024 &dev_attr_channel.attr,
1028 static struct attribute_group boot_opts_group = {
1029 .name = "boot_options",
1030 .attrs = boot_opts_attrs,
1033 static struct attribute *mesh_ie_attrs[] = {
1034 &dev_attr_mesh_id.attr,
1035 &dev_attr_protocol_id.attr,
1036 &dev_attr_metric_id.attr,
1037 &dev_attr_capability.attr,
1041 static struct attribute_group mesh_ie_group = {
1043 .attrs = mesh_ie_attrs,
1046 void lbs_persist_config_init(struct net_device *dev)
1049 ret = sysfs_create_group(&(dev->dev.kobj), &boot_opts_group);
1050 ret = sysfs_create_group(&(dev->dev.kobj), &mesh_ie_group);
1053 void lbs_persist_config_remove(struct net_device *dev)
1055 sysfs_remove_group(&(dev->dev.kobj), &boot_opts_group);
1056 sysfs_remove_group(&(dev->dev.kobj), &mesh_ie_group);
1061 /***************************************************************************
1065 static const char *mesh_stat_strings[] = {
1066 "drop_duplicate_bcast",
1068 "drop_no_fwd_route",
1070 "fwded_unicast_cnt",
1076 void lbs_mesh_ethtool_get_stats(struct net_device *dev,
1077 struct ethtool_stats *stats, uint64_t *data)
1079 struct lbs_private *priv = dev->ml_priv;
1080 struct cmd_ds_mesh_access mesh_access;
1083 lbs_deb_enter(LBS_DEB_ETHTOOL);
1085 /* Get Mesh Statistics */
1086 ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_STATS, &mesh_access);
1089 memset(data, 0, MESH_STATS_NUM*(sizeof(uint64_t)));
1093 priv->mstats.fwd_drop_rbt = le32_to_cpu(mesh_access.data[0]);
1094 priv->mstats.fwd_drop_ttl = le32_to_cpu(mesh_access.data[1]);
1095 priv->mstats.fwd_drop_noroute = le32_to_cpu(mesh_access.data[2]);
1096 priv->mstats.fwd_drop_nobuf = le32_to_cpu(mesh_access.data[3]);
1097 priv->mstats.fwd_unicast_cnt = le32_to_cpu(mesh_access.data[4]);
1098 priv->mstats.fwd_bcast_cnt = le32_to_cpu(mesh_access.data[5]);
1099 priv->mstats.drop_blind = le32_to_cpu(mesh_access.data[6]);
1100 priv->mstats.tx_failed_cnt = le32_to_cpu(mesh_access.data[7]);
1102 data[0] = priv->mstats.fwd_drop_rbt;
1103 data[1] = priv->mstats.fwd_drop_ttl;
1104 data[2] = priv->mstats.fwd_drop_noroute;
1105 data[3] = priv->mstats.fwd_drop_nobuf;
1106 data[4] = priv->mstats.fwd_unicast_cnt;
1107 data[5] = priv->mstats.fwd_bcast_cnt;
1108 data[6] = priv->mstats.drop_blind;
1109 data[7] = priv->mstats.tx_failed_cnt;
1111 lbs_deb_enter(LBS_DEB_ETHTOOL);
1114 int lbs_mesh_ethtool_get_sset_count(struct net_device *dev, int sset)
1116 struct lbs_private *priv = dev->ml_priv;
1118 if (sset == ETH_SS_STATS && dev == priv->mesh_dev)
1119 return MESH_STATS_NUM;
1124 void lbs_mesh_ethtool_get_strings(struct net_device *dev,
1125 uint32_t stringset, uint8_t *s)
1129 lbs_deb_enter(LBS_DEB_ETHTOOL);
1131 switch (stringset) {
1133 for (i = 0; i < MESH_STATS_NUM; i++) {
1134 memcpy(s + i * ETH_GSTRING_LEN,
1135 mesh_stat_strings[i],
1140 lbs_deb_enter(LBS_DEB_ETHTOOL);