1 #include <linux/delay.h>
2 #include <linux/etherdevice.h>
3 #include <linux/netdevice.h>
4 #include <linux/if_ether.h>
5 #include <linux/if_arp.h>
6 #include <linux/kthread.h>
7 #include <linux/kfifo.h>
8 #include <net/cfg80211.h>
15 /***************************************************************************
20 * Attributes exported through sysfs
24 * lbs_anycast_get - Get function for sysfs attribute anycast_mask
25 * @dev: the &struct device
26 * @attr: device attributes
27 * @buf: buffer where data will be returned
29 static ssize_t lbs_anycast_get(struct device *dev,
30 struct device_attribute *attr, char * buf)
32 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
33 struct cmd_ds_mesh_access mesh_access;
36 memset(&mesh_access, 0, sizeof(mesh_access));
38 ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_ANYCAST, &mesh_access);
42 return snprintf(buf, 12, "0x%X\n", le32_to_cpu(mesh_access.data[0]));
46 * lbs_anycast_set - Set function for sysfs attribute anycast_mask
47 * @dev: the &struct device
48 * @attr: device attributes
49 * @buf: buffer that contains new attribute value
50 * @count: size of buffer
52 static ssize_t lbs_anycast_set(struct device *dev,
53 struct device_attribute *attr, const char * buf, size_t count)
55 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
56 struct cmd_ds_mesh_access mesh_access;
60 memset(&mesh_access, 0, sizeof(mesh_access));
61 sscanf(buf, "%x", &datum);
62 mesh_access.data[0] = cpu_to_le32(datum);
64 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_ANYCAST, &mesh_access);
72 * lbs_prb_rsp_limit_get - Get function for sysfs attribute prb_rsp_limit
73 * @dev: the &struct device
74 * @attr: device attributes
75 * @buf: buffer where data will be returned
77 static ssize_t lbs_prb_rsp_limit_get(struct device *dev,
78 struct device_attribute *attr, char *buf)
80 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
81 struct cmd_ds_mesh_access mesh_access;
85 memset(&mesh_access, 0, sizeof(mesh_access));
86 mesh_access.data[0] = cpu_to_le32(CMD_ACT_GET);
88 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT,
93 retry_limit = le32_to_cpu(mesh_access.data[1]);
94 return snprintf(buf, 10, "%d\n", retry_limit);
98 * lbs_prb_rsp_limit_set - Set function for sysfs attribute prb_rsp_limit
99 * @dev: the &struct device
100 * @attr: device attributes
101 * @buf: buffer that contains new attribute value
102 * @count: size of buffer
104 static ssize_t lbs_prb_rsp_limit_set(struct device *dev,
105 struct device_attribute *attr, const char *buf, size_t count)
107 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
108 struct cmd_ds_mesh_access mesh_access;
110 unsigned long retry_limit;
112 memset(&mesh_access, 0, sizeof(mesh_access));
113 mesh_access.data[0] = cpu_to_le32(CMD_ACT_SET);
115 if (!strict_strtoul(buf, 10, &retry_limit))
117 if (retry_limit > 15)
120 mesh_access.data[1] = cpu_to_le32(retry_limit);
122 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT,
131 * lbs_mesh_get - Get function for sysfs attribute mesh
132 * @dev: the &struct device
133 * @attr: device attributes
134 * @buf: buffer where data will be returned
136 static ssize_t lbs_mesh_get(struct device *dev,
137 struct device_attribute *attr, char * buf)
139 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
140 return snprintf(buf, 5, "0x%X\n", !!priv->mesh_dev);
144 * lbs_mesh_set - Set function for sysfs attribute mesh
145 * @dev: the &struct device
146 * @attr: device attributes
147 * @buf: buffer that contains new attribute value
148 * @count: size of buffer
150 static ssize_t lbs_mesh_set(struct device *dev,
151 struct device_attribute *attr, const char * buf, size_t count)
153 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
155 int ret, action = CMD_ACT_MESH_CONFIG_STOP;
157 sscanf(buf, "%x", &enable);
159 if (enable == !!priv->mesh_dev)
162 action = CMD_ACT_MESH_CONFIG_START;
163 ret = lbs_mesh_config(priv, action, priv->channel);
170 lbs_remove_mesh(priv);
176 * lbs_mesh attribute to be exported per ethX interface
177 * through sysfs (/sys/class/net/ethX/lbs_mesh)
179 static DEVICE_ATTR(lbs_mesh, 0644, lbs_mesh_get, lbs_mesh_set);
182 * anycast_mask attribute to be exported per mshX interface
183 * through sysfs (/sys/class/net/mshX/anycast_mask)
185 static DEVICE_ATTR(anycast_mask, 0644, lbs_anycast_get, lbs_anycast_set);
188 * prb_rsp_limit attribute to be exported per mshX interface
189 * through sysfs (/sys/class/net/mshX/prb_rsp_limit)
191 static DEVICE_ATTR(prb_rsp_limit, 0644, lbs_prb_rsp_limit_get,
192 lbs_prb_rsp_limit_set);
194 static struct attribute *lbs_mesh_sysfs_entries[] = {
195 &dev_attr_anycast_mask.attr,
196 &dev_attr_prb_rsp_limit.attr,
200 static struct attribute_group lbs_mesh_attr_group = {
201 .attrs = lbs_mesh_sysfs_entries,
206 /***************************************************************************
207 * Initializing and starting, stopping mesh
211 * Check mesh FW version and appropriately send the mesh start
214 int lbs_init_mesh(struct lbs_private *priv)
216 struct net_device *dev = priv->dev;
219 lbs_deb_enter(LBS_DEB_MESH);
221 priv->mesh_connect_status = LBS_DISCONNECTED;
223 /* Determine mesh_fw_ver from fwrelease and fwcapinfo */
224 /* 5.0.16p0 9.0.0.p0 is known to NOT support any mesh */
225 /* 5.110.22 have mesh command with 0xa3 command id */
226 /* 10.0.0.p0 FW brings in mesh config command with different id */
227 /* Check FW version MSB and initialize mesh_fw_ver */
228 if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V5) {
229 /* Enable mesh, if supported, and work out which TLV it uses.
230 0x100 + 291 is an unofficial value used in 5.110.20.pXX
231 0x100 + 37 is the official value used in 5.110.21.pXX
232 but we check them in that order because 20.pXX doesn't
233 give an error -- it just silently fails. */
235 /* 5.110.20.pXX firmware will fail the command if the channel
236 doesn't match the existing channel. But only if the TLV
237 is correct. If the channel is wrong, _BOTH_ versions will
238 give an error to 0x100+291, and allow 0x100+37 to succeed.
239 It's just that 5.110.20.pXX will not have done anything
242 priv->mesh_tlv = TLV_TYPE_OLD_MESH_ID;
243 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
245 priv->mesh_tlv = TLV_TYPE_MESH_ID;
246 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
251 if ((MRVL_FW_MAJOR_REV(priv->fwrelease) >= MRVL_FW_V10) &&
252 (priv->fwcapinfo & MESH_CAPINFO_ENABLE_MASK)) {
253 /* 10.0.0.pXX new firmwares should succeed with TLV
254 * 0x100+37; Do not invoke command with old TLV.
256 priv->mesh_tlv = TLV_TYPE_MESH_ID;
257 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
263 if (priv->mesh_tlv) {
264 sprintf(priv->mesh_ssid, "mesh");
265 priv->mesh_ssid_len = 4;
269 if (device_create_file(&dev->dev, &dev_attr_lbs_mesh))
270 lbs_pr_err("cannot register lbs_mesh attribute\n");
275 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
280 int lbs_deinit_mesh(struct lbs_private *priv)
282 struct net_device *dev = priv->dev;
285 lbs_deb_enter(LBS_DEB_MESH);
287 if (priv->mesh_tlv) {
288 device_remove_file(&dev->dev, &dev_attr_lbs_mesh);
292 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
298 * lbs_mesh_stop - close the mshX interface
300 * @dev: A pointer to &net_device structure
303 static int lbs_mesh_stop(struct net_device *dev)
305 struct lbs_private *priv = dev->ml_priv;
307 lbs_deb_enter(LBS_DEB_MESH);
308 spin_lock_irq(&priv->driver_lock);
311 priv->mesh_connect_status = LBS_DISCONNECTED;
313 netif_stop_queue(dev);
314 netif_carrier_off(dev);
316 spin_unlock_irq(&priv->driver_lock);
318 schedule_work(&priv->mcast_work);
320 lbs_deb_leave(LBS_DEB_MESH);
325 * lbs_mesh_dev_open - open the mshX interface
327 * @dev: A pointer to &net_device structure
328 * returns: 0 or -EBUSY if monitor mode active
330 static int lbs_mesh_dev_open(struct net_device *dev)
332 struct lbs_private *priv = dev->ml_priv;
335 lbs_deb_enter(LBS_DEB_NET);
337 spin_lock_irq(&priv->driver_lock);
339 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR) {
345 priv->mesh_connect_status = LBS_CONNECTED;
346 netif_carrier_on(dev);
348 if (!priv->tx_pending_len)
349 netif_wake_queue(dev);
352 spin_unlock_irq(&priv->driver_lock);
353 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
357 static const struct net_device_ops mesh_netdev_ops = {
358 .ndo_open = lbs_mesh_dev_open,
359 .ndo_stop = lbs_mesh_stop,
360 .ndo_start_xmit = lbs_hard_start_xmit,
361 .ndo_set_mac_address = lbs_set_mac_address,
362 .ndo_set_multicast_list = lbs_set_multicast_list,
366 * lbs_add_mesh - add mshX interface
368 * @priv: A pointer to the &struct lbs_private structure
369 * returns: 0 if successful, -X otherwise
371 int lbs_add_mesh(struct lbs_private *priv)
373 struct net_device *mesh_dev = NULL;
376 lbs_deb_enter(LBS_DEB_MESH);
378 /* Allocate a virtual mesh device */
379 mesh_dev = alloc_netdev(0, "msh%d", ether_setup);
381 lbs_deb_mesh("init mshX device failed\n");
385 mesh_dev->ml_priv = priv;
386 priv->mesh_dev = mesh_dev;
388 mesh_dev->netdev_ops = &mesh_netdev_ops;
389 mesh_dev->ethtool_ops = &lbs_ethtool_ops;
390 memcpy(mesh_dev->dev_addr, priv->dev->dev_addr, ETH_ALEN);
392 SET_NETDEV_DEV(priv->mesh_dev, priv->dev->dev.parent);
394 mesh_dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
395 /* Register virtual mesh interface */
396 ret = register_netdev(mesh_dev);
398 lbs_pr_err("cannot register mshX virtual interface\n");
402 ret = sysfs_create_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
406 lbs_persist_config_init(mesh_dev);
408 /* Everything successful */
413 unregister_netdev(mesh_dev);
416 free_netdev(mesh_dev);
419 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
423 void lbs_remove_mesh(struct lbs_private *priv)
425 struct net_device *mesh_dev;
427 mesh_dev = priv->mesh_dev;
431 lbs_deb_enter(LBS_DEB_MESH);
432 netif_stop_queue(mesh_dev);
433 netif_carrier_off(mesh_dev);
434 sysfs_remove_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
435 lbs_persist_config_remove(mesh_dev);
436 unregister_netdev(mesh_dev);
437 priv->mesh_dev = NULL;
438 free_netdev(mesh_dev);
439 lbs_deb_leave(LBS_DEB_MESH);
444 /***************************************************************************
445 * Sending and receiving
447 struct net_device *lbs_mesh_set_dev(struct lbs_private *priv,
448 struct net_device *dev, struct rxpd *rxpd)
450 if (priv->mesh_dev) {
451 if (priv->mesh_tlv == TLV_TYPE_OLD_MESH_ID) {
452 if (rxpd->rx_control & RxPD_MESH_FRAME)
453 dev = priv->mesh_dev;
454 } else if (priv->mesh_tlv == TLV_TYPE_MESH_ID) {
455 if (rxpd->u.bss.bss_num == MESH_IFACE_ID)
456 dev = priv->mesh_dev;
463 void lbs_mesh_set_txpd(struct lbs_private *priv,
464 struct net_device *dev, struct txpd *txpd)
466 if (dev == priv->mesh_dev) {
467 if (priv->mesh_tlv == TLV_TYPE_OLD_MESH_ID)
468 txpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
469 else if (priv->mesh_tlv == TLV_TYPE_MESH_ID)
470 txpd->u.bss.bss_num = MESH_IFACE_ID;
475 /***************************************************************************
476 * Mesh command handling
480 * lbs_mesh_bt_add_del - Add or delete Mesh Blinding Table entries
482 * @priv: A pointer to &struct lbs_private structure
483 * @add: TRUE to add the entry, FALSE to delete it
484 * @addr1: Destination address to blind or unblind
486 * returns: 0 on success, error on failure
488 int lbs_mesh_bt_add_del(struct lbs_private *priv, bool add, u8 *addr1)
490 struct cmd_ds_bt_access cmd;
493 lbs_deb_enter(LBS_DEB_CMD);
495 BUG_ON(addr1 == NULL);
497 memset(&cmd, 0, sizeof(cmd));
498 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
499 memcpy(cmd.addr1, addr1, ETH_ALEN);
501 cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_ADD);
502 lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr",
505 cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_DEL);
506 lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr",
510 ret = lbs_cmd_with_response(priv, CMD_BT_ACCESS, &cmd);
512 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
517 * lbs_mesh_bt_reset - Reset/clear the mesh blinding table
519 * @priv: A pointer to &struct lbs_private structure
521 * returns: 0 on success, error on failure
523 int lbs_mesh_bt_reset(struct lbs_private *priv)
525 struct cmd_ds_bt_access cmd;
528 lbs_deb_enter(LBS_DEB_CMD);
530 memset(&cmd, 0, sizeof(cmd));
531 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
532 cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_RESET);
534 ret = lbs_cmd_with_response(priv, CMD_BT_ACCESS, &cmd);
536 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
541 * lbs_mesh_bt_get_inverted - Gets the inverted status of the mesh
544 * Normally the firmware "blinds" or ignores traffic from mesh nodes in the
545 * table, but an inverted table allows *only* traffic from nodes listed in
548 * @priv: A pointer to &struct lbs_private structure
549 * @inverted: On success, TRUE if the blinding table is inverted,
550 * FALSE if it is not inverted
552 * returns: 0 on success, error on failure
554 int lbs_mesh_bt_get_inverted(struct lbs_private *priv, bool *inverted)
556 struct cmd_ds_bt_access cmd;
559 lbs_deb_enter(LBS_DEB_CMD);
561 BUG_ON(inverted == NULL);
563 memset(&cmd, 0, sizeof(cmd));
564 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
565 cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_GET_INVERT);
567 ret = lbs_cmd_with_response(priv, CMD_BT_ACCESS, &cmd);
569 *inverted = !!cmd.id;
571 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
576 * lbs_mesh_bt_set_inverted - Sets the inverted status of the mesh
579 * Normally the firmware "blinds" or ignores traffic from mesh nodes in the
580 * table, but an inverted table allows *only* traffic from nodes listed in
583 * @priv: A pointer to &struct lbs_private structure
584 * @inverted: TRUE to invert the blinding table (only traffic from
585 * listed nodes allowed), FALSE to return it
586 * to normal state (listed nodes ignored)
588 * returns: 0 on success, error on failure
590 int lbs_mesh_bt_set_inverted(struct lbs_private *priv, bool inverted)
592 struct cmd_ds_bt_access cmd;
595 lbs_deb_enter(LBS_DEB_CMD);
597 memset(&cmd, 0, sizeof(cmd));
598 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
599 cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_SET_INVERT);
600 cmd.id = cpu_to_le32(!!inverted);
602 ret = lbs_cmd_with_response(priv, CMD_BT_ACCESS, &cmd);
604 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
609 * lbs_mesh_bt_get_entry - List an entry in the mesh blinding table
611 * @priv: A pointer to &struct lbs_private structure
612 * @id: The ID of the entry to list
613 * @addr1: MAC address associated with the table entry
615 * returns: 0 on success, error on failure
617 int lbs_mesh_bt_get_entry(struct lbs_private *priv, u32 id, u8 *addr1)
619 struct cmd_ds_bt_access cmd;
622 lbs_deb_enter(LBS_DEB_CMD);
624 BUG_ON(addr1 == NULL);
626 memset(&cmd, 0, sizeof(cmd));
627 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
628 cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_SET_INVERT);
629 cmd.id = cpu_to_le32(id);
631 ret = lbs_cmd_with_response(priv, CMD_BT_ACCESS, &cmd);
633 memcpy(addr1, cmd.addr1, sizeof(cmd.addr1));
635 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
640 * lbs_cmd_fwt_access - Access the mesh forwarding table
642 * @priv: A pointer to &struct lbs_private structure
643 * @cmd_action: The forwarding table action to perform
644 * @cmd: The pre-filled FWT_ACCESS command
646 * returns: 0 on success and 'cmd' will be filled with the
647 * firmware's response
649 int lbs_cmd_fwt_access(struct lbs_private *priv, u16 cmd_action,
650 struct cmd_ds_fwt_access *cmd)
654 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
656 cmd->hdr.command = cpu_to_le16(CMD_FWT_ACCESS);
657 cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access));
659 cmd->action = cpu_to_le16(cmd_action);
661 ret = lbs_cmd_with_response(priv, CMD_FWT_ACCESS, cmd);
663 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
667 int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
668 struct cmd_ds_mesh_access *cmd)
672 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
674 cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
675 cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
678 cmd->action = cpu_to_le16(cmd_action);
680 ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
682 lbs_deb_leave(LBS_DEB_CMD);
686 static int __lbs_mesh_config_send(struct lbs_private *priv,
687 struct cmd_ds_mesh_config *cmd,
688 uint16_t action, uint16_t type)
691 u16 command = CMD_MESH_CONFIG_OLD;
693 lbs_deb_enter(LBS_DEB_CMD);
696 * Command id is 0xac for v10 FW along with mesh interface
697 * id in bits 14-13-12.
699 if (priv->mesh_tlv == TLV_TYPE_MESH_ID)
700 command = CMD_MESH_CONFIG |
701 (MESH_IFACE_ID << MESH_IFACE_BIT_OFFSET);
703 cmd->hdr.command = cpu_to_le16(command);
704 cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config));
707 cmd->type = cpu_to_le16(type);
708 cmd->action = cpu_to_le16(action);
710 ret = lbs_cmd_with_response(priv, command, cmd);
712 lbs_deb_leave(LBS_DEB_CMD);
716 int lbs_mesh_config_send(struct lbs_private *priv,
717 struct cmd_ds_mesh_config *cmd,
718 uint16_t action, uint16_t type)
722 if (!(priv->fwcapinfo & FW_CAPINFO_PERSISTENT_CONFIG))
725 ret = __lbs_mesh_config_send(priv, cmd, action, type);
729 /* This function is the CMD_MESH_CONFIG legacy function. It only handles the
730 * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG
731 * are all handled by preparing a struct cmd_ds_mesh_config and passing it to
732 * lbs_mesh_config_send.
734 int lbs_mesh_config(struct lbs_private *priv, uint16_t action, uint16_t chan)
736 struct cmd_ds_mesh_config cmd;
737 struct mrvl_meshie *ie;
738 DECLARE_SSID_BUF(ssid);
740 memset(&cmd, 0, sizeof(cmd));
741 cmd.channel = cpu_to_le16(chan);
742 ie = (struct mrvl_meshie *)cmd.data;
745 case CMD_ACT_MESH_CONFIG_START:
746 ie->id = WLAN_EID_GENERIC;
747 ie->val.oui[0] = 0x00;
748 ie->val.oui[1] = 0x50;
749 ie->val.oui[2] = 0x43;
750 ie->val.type = MARVELL_MESH_IE_TYPE;
751 ie->val.subtype = MARVELL_MESH_IE_SUBTYPE;
752 ie->val.version = MARVELL_MESH_IE_VERSION;
753 ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP;
754 ie->val.active_metric_id = MARVELL_MESH_METRIC_ID;
755 ie->val.mesh_capability = MARVELL_MESH_CAPABILITY;
756 ie->val.mesh_id_len = priv->mesh_ssid_len;
757 memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len);
758 ie->len = sizeof(struct mrvl_meshie_val) -
759 IEEE80211_MAX_SSID_LEN + priv->mesh_ssid_len;
760 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val));
762 case CMD_ACT_MESH_CONFIG_STOP:
767 lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n",
768 action, priv->mesh_tlv, chan,
769 print_ssid(ssid, priv->mesh_ssid, priv->mesh_ssid_len));
771 return __lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv);
776 /***************************************************************************
777 * Persistent configuration support
780 static int mesh_get_default_parameters(struct device *dev,
781 struct mrvl_mesh_defaults *defs)
783 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
784 struct cmd_ds_mesh_config cmd;
787 memset(&cmd, 0, sizeof(struct cmd_ds_mesh_config));
788 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_GET,
789 CMD_TYPE_MESH_GET_DEFAULTS);
794 memcpy(defs, &cmd.data[0], sizeof(struct mrvl_mesh_defaults));
800 * bootflag_get - Get function for sysfs attribute bootflag
801 * @dev: the &struct device
802 * @attr: device attributes
803 * @buf: buffer where data will be returned
805 static ssize_t bootflag_get(struct device *dev,
806 struct device_attribute *attr, char *buf)
808 struct mrvl_mesh_defaults defs;
811 ret = mesh_get_default_parameters(dev, &defs);
816 return snprintf(buf, 12, "%d\n", le32_to_cpu(defs.bootflag));
820 * bootflag_set - Set function for sysfs attribute bootflag
821 * @dev: the &struct device
822 * @attr: device attributes
823 * @buf: buffer that contains new attribute value
824 * @count: size of buffer
826 static ssize_t bootflag_set(struct device *dev, struct device_attribute *attr,
827 const char *buf, size_t count)
829 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
830 struct cmd_ds_mesh_config cmd;
834 memset(&cmd, 0, sizeof(cmd));
835 ret = sscanf(buf, "%d", &datum);
836 if ((ret != 1) || (datum > 1))
839 *((__le32 *)&cmd.data[0]) = cpu_to_le32(!!datum);
840 cmd.length = cpu_to_le16(sizeof(uint32_t));
841 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
842 CMD_TYPE_MESH_SET_BOOTFLAG);
850 * boottime_get - Get function for sysfs attribute boottime
851 * @dev: the &struct device
852 * @attr: device attributes
853 * @buf: buffer where data will be returned
855 static ssize_t boottime_get(struct device *dev,
856 struct device_attribute *attr, char *buf)
858 struct mrvl_mesh_defaults defs;
861 ret = mesh_get_default_parameters(dev, &defs);
866 return snprintf(buf, 12, "%d\n", defs.boottime);
870 * boottime_set - Set function for sysfs attribute boottime
871 * @dev: the &struct device
872 * @attr: device attributes
873 * @buf: buffer that contains new attribute value
874 * @count: size of buffer
876 static ssize_t boottime_set(struct device *dev,
877 struct device_attribute *attr, const char *buf, size_t count)
879 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
880 struct cmd_ds_mesh_config cmd;
884 memset(&cmd, 0, sizeof(cmd));
885 ret = sscanf(buf, "%d", &datum);
886 if ((ret != 1) || (datum > 255))
889 /* A too small boot time will result in the device booting into
890 * standalone (no-host) mode before the host can take control of it,
891 * so the change will be hard to revert. This may be a desired
892 * feature (e.g to configure a very fast boot time for devices that
893 * will not be attached to a host), but dangerous. So I'm enforcing a
894 * lower limit of 20 seconds: remove and recompile the driver if this
895 * does not work for you.
897 datum = (datum < 20) ? 20 : datum;
899 cmd.length = cpu_to_le16(sizeof(uint8_t));
900 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
901 CMD_TYPE_MESH_SET_BOOTTIME);
909 * channel_get - Get function for sysfs attribute channel
910 * @dev: the &struct device
911 * @attr: device attributes
912 * @buf: buffer where data will be returned
914 static ssize_t channel_get(struct device *dev,
915 struct device_attribute *attr, char *buf)
917 struct mrvl_mesh_defaults defs;
920 ret = mesh_get_default_parameters(dev, &defs);
925 return snprintf(buf, 12, "%d\n", le16_to_cpu(defs.channel));
929 * channel_set - Set function for sysfs attribute channel
930 * @dev: the &struct device
931 * @attr: device attributes
932 * @buf: buffer that contains new attribute value
933 * @count: size of buffer
935 static ssize_t channel_set(struct device *dev, struct device_attribute *attr,
936 const char *buf, size_t count)
938 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
939 struct cmd_ds_mesh_config cmd;
943 memset(&cmd, 0, sizeof(cmd));
944 ret = sscanf(buf, "%d", &datum);
945 if (ret != 1 || datum < 1 || datum > 11)
948 *((__le16 *)&cmd.data[0]) = cpu_to_le16(datum);
949 cmd.length = cpu_to_le16(sizeof(uint16_t));
950 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
951 CMD_TYPE_MESH_SET_DEF_CHANNEL);
959 * mesh_id_get - Get function for sysfs attribute mesh_id
960 * @dev: the &struct device
961 * @attr: device attributes
962 * @buf: buffer where data will be returned
964 static ssize_t mesh_id_get(struct device *dev, struct device_attribute *attr,
967 struct mrvl_mesh_defaults defs;
970 ret = mesh_get_default_parameters(dev, &defs);
975 if (defs.meshie.val.mesh_id_len > IEEE80211_MAX_SSID_LEN) {
976 lbs_pr_err("inconsistent mesh ID length");
977 defs.meshie.val.mesh_id_len = IEEE80211_MAX_SSID_LEN;
980 memcpy(buf, defs.meshie.val.mesh_id, defs.meshie.val.mesh_id_len);
981 buf[defs.meshie.val.mesh_id_len] = '\n';
982 buf[defs.meshie.val.mesh_id_len + 1] = '\0';
984 return defs.meshie.val.mesh_id_len + 1;
988 * mesh_id_set - Set function for sysfs attribute mesh_id
989 * @dev: the &struct device
990 * @attr: device attributes
991 * @buf: buffer that contains new attribute value
992 * @count: size of buffer
994 static ssize_t mesh_id_set(struct device *dev, struct device_attribute *attr,
995 const char *buf, size_t count)
997 struct cmd_ds_mesh_config cmd;
998 struct mrvl_mesh_defaults defs;
999 struct mrvl_meshie *ie;
1000 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
1004 if (count < 2 || count > IEEE80211_MAX_SSID_LEN + 1)
1007 memset(&cmd, 0, sizeof(struct cmd_ds_mesh_config));
1008 ie = (struct mrvl_meshie *) &cmd.data[0];
1010 /* fetch all other Information Element parameters */
1011 ret = mesh_get_default_parameters(dev, &defs);
1013 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
1015 /* transfer IE elements */
1016 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
1019 memcpy(ie->val.mesh_id, buf, len);
1021 ie->val.mesh_id_len = len;
1023 ie->len = sizeof(struct mrvl_meshie_val) - IEEE80211_MAX_SSID_LEN + len;
1025 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
1026 CMD_TYPE_MESH_SET_MESH_IE);
1034 * protocol_id_get - Get function for sysfs attribute protocol_id
1035 * @dev: the &struct device
1036 * @attr: device attributes
1037 * @buf: buffer where data will be returned
1039 static ssize_t protocol_id_get(struct device *dev,
1040 struct device_attribute *attr, char *buf)
1042 struct mrvl_mesh_defaults defs;
1045 ret = mesh_get_default_parameters(dev, &defs);
1050 return snprintf(buf, 5, "%d\n", defs.meshie.val.active_protocol_id);
1054 * protocol_id_set - Set function for sysfs attribute protocol_id
1055 * @dev: the &struct device
1056 * @attr: device attributes
1057 * @buf: buffer that contains new attribute value
1058 * @count: size of buffer
1060 static ssize_t protocol_id_set(struct device *dev,
1061 struct device_attribute *attr, const char *buf, size_t count)
1063 struct cmd_ds_mesh_config cmd;
1064 struct mrvl_mesh_defaults defs;
1065 struct mrvl_meshie *ie;
1066 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
1070 memset(&cmd, 0, sizeof(cmd));
1071 ret = sscanf(buf, "%d", &datum);
1072 if ((ret != 1) || (datum > 255))
1075 /* fetch all other Information Element parameters */
1076 ret = mesh_get_default_parameters(dev, &defs);
1078 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
1080 /* transfer IE elements */
1081 ie = (struct mrvl_meshie *) &cmd.data[0];
1082 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
1083 /* update protocol id */
1084 ie->val.active_protocol_id = datum;
1086 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
1087 CMD_TYPE_MESH_SET_MESH_IE);
1095 * metric_id_get - Get function for sysfs attribute metric_id
1096 * @dev: the &struct device
1097 * @attr: device attributes
1098 * @buf: buffer where data will be returned
1100 static ssize_t metric_id_get(struct device *dev,
1101 struct device_attribute *attr, char *buf)
1103 struct mrvl_mesh_defaults defs;
1106 ret = mesh_get_default_parameters(dev, &defs);
1111 return snprintf(buf, 5, "%d\n", defs.meshie.val.active_metric_id);
1115 * metric_id_set - Set function for sysfs attribute metric_id
1116 * @dev: the &struct device
1117 * @attr: device attributes
1118 * @buf: buffer that contains new attribute value
1119 * @count: size of buffer
1121 static ssize_t metric_id_set(struct device *dev, struct device_attribute *attr,
1122 const char *buf, size_t count)
1124 struct cmd_ds_mesh_config cmd;
1125 struct mrvl_mesh_defaults defs;
1126 struct mrvl_meshie *ie;
1127 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
1131 memset(&cmd, 0, sizeof(cmd));
1132 ret = sscanf(buf, "%d", &datum);
1133 if ((ret != 1) || (datum > 255))
1136 /* fetch all other Information Element parameters */
1137 ret = mesh_get_default_parameters(dev, &defs);
1139 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
1141 /* transfer IE elements */
1142 ie = (struct mrvl_meshie *) &cmd.data[0];
1143 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
1144 /* update metric id */
1145 ie->val.active_metric_id = datum;
1147 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
1148 CMD_TYPE_MESH_SET_MESH_IE);
1156 * capability_get - Get function for sysfs attribute capability
1157 * @dev: the &struct device
1158 * @attr: device attributes
1159 * @buf: buffer where data will be returned
1161 static ssize_t capability_get(struct device *dev,
1162 struct device_attribute *attr, char *buf)
1164 struct mrvl_mesh_defaults defs;
1167 ret = mesh_get_default_parameters(dev, &defs);
1172 return snprintf(buf, 5, "%d\n", defs.meshie.val.mesh_capability);
1176 * capability_set - Set function for sysfs attribute capability
1177 * @dev: the &struct device
1178 * @attr: device attributes
1179 * @buf: buffer that contains new attribute value
1180 * @count: size of buffer
1182 static ssize_t capability_set(struct device *dev, struct device_attribute *attr,
1183 const char *buf, size_t count)
1185 struct cmd_ds_mesh_config cmd;
1186 struct mrvl_mesh_defaults defs;
1187 struct mrvl_meshie *ie;
1188 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
1192 memset(&cmd, 0, sizeof(cmd));
1193 ret = sscanf(buf, "%d", &datum);
1194 if ((ret != 1) || (datum > 255))
1197 /* fetch all other Information Element parameters */
1198 ret = mesh_get_default_parameters(dev, &defs);
1200 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
1202 /* transfer IE elements */
1203 ie = (struct mrvl_meshie *) &cmd.data[0];
1204 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
1206 ie->val.mesh_capability = datum;
1208 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
1209 CMD_TYPE_MESH_SET_MESH_IE);
1217 static DEVICE_ATTR(bootflag, 0644, bootflag_get, bootflag_set);
1218 static DEVICE_ATTR(boottime, 0644, boottime_get, boottime_set);
1219 static DEVICE_ATTR(channel, 0644, channel_get, channel_set);
1220 static DEVICE_ATTR(mesh_id, 0644, mesh_id_get, mesh_id_set);
1221 static DEVICE_ATTR(protocol_id, 0644, protocol_id_get, protocol_id_set);
1222 static DEVICE_ATTR(metric_id, 0644, metric_id_get, metric_id_set);
1223 static DEVICE_ATTR(capability, 0644, capability_get, capability_set);
1225 static struct attribute *boot_opts_attrs[] = {
1226 &dev_attr_bootflag.attr,
1227 &dev_attr_boottime.attr,
1228 &dev_attr_channel.attr,
1232 static struct attribute_group boot_opts_group = {
1233 .name = "boot_options",
1234 .attrs = boot_opts_attrs,
1237 static struct attribute *mesh_ie_attrs[] = {
1238 &dev_attr_mesh_id.attr,
1239 &dev_attr_protocol_id.attr,
1240 &dev_attr_metric_id.attr,
1241 &dev_attr_capability.attr,
1245 static struct attribute_group mesh_ie_group = {
1247 .attrs = mesh_ie_attrs,
1250 void lbs_persist_config_init(struct net_device *dev)
1253 ret = sysfs_create_group(&(dev->dev.kobj), &boot_opts_group);
1254 ret = sysfs_create_group(&(dev->dev.kobj), &mesh_ie_group);
1257 void lbs_persist_config_remove(struct net_device *dev)
1259 sysfs_remove_group(&(dev->dev.kobj), &boot_opts_group);
1260 sysfs_remove_group(&(dev->dev.kobj), &mesh_ie_group);
1265 /***************************************************************************
1269 static const char *mesh_stat_strings[] = {
1270 "drop_duplicate_bcast",
1272 "drop_no_fwd_route",
1274 "fwded_unicast_cnt",
1280 void lbs_mesh_ethtool_get_stats(struct net_device *dev,
1281 struct ethtool_stats *stats, uint64_t *data)
1283 struct lbs_private *priv = dev->ml_priv;
1284 struct cmd_ds_mesh_access mesh_access;
1287 lbs_deb_enter(LBS_DEB_ETHTOOL);
1289 /* Get Mesh Statistics */
1290 ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_STATS, &mesh_access);
1293 memset(data, 0, MESH_STATS_NUM*(sizeof(uint64_t)));
1297 priv->mstats.fwd_drop_rbt = le32_to_cpu(mesh_access.data[0]);
1298 priv->mstats.fwd_drop_ttl = le32_to_cpu(mesh_access.data[1]);
1299 priv->mstats.fwd_drop_noroute = le32_to_cpu(mesh_access.data[2]);
1300 priv->mstats.fwd_drop_nobuf = le32_to_cpu(mesh_access.data[3]);
1301 priv->mstats.fwd_unicast_cnt = le32_to_cpu(mesh_access.data[4]);
1302 priv->mstats.fwd_bcast_cnt = le32_to_cpu(mesh_access.data[5]);
1303 priv->mstats.drop_blind = le32_to_cpu(mesh_access.data[6]);
1304 priv->mstats.tx_failed_cnt = le32_to_cpu(mesh_access.data[7]);
1306 data[0] = priv->mstats.fwd_drop_rbt;
1307 data[1] = priv->mstats.fwd_drop_ttl;
1308 data[2] = priv->mstats.fwd_drop_noroute;
1309 data[3] = priv->mstats.fwd_drop_nobuf;
1310 data[4] = priv->mstats.fwd_unicast_cnt;
1311 data[5] = priv->mstats.fwd_bcast_cnt;
1312 data[6] = priv->mstats.drop_blind;
1313 data[7] = priv->mstats.tx_failed_cnt;
1315 lbs_deb_enter(LBS_DEB_ETHTOOL);
1318 int lbs_mesh_ethtool_get_sset_count(struct net_device *dev, int sset)
1320 struct lbs_private *priv = dev->ml_priv;
1322 if (sset == ETH_SS_STATS && dev == priv->mesh_dev)
1323 return MESH_STATS_NUM;
1328 void lbs_mesh_ethtool_get_strings(struct net_device *dev,
1329 uint32_t stringset, uint8_t *s)
1333 lbs_deb_enter(LBS_DEB_ETHTOOL);
1335 switch (stringset) {
1337 for (i = 0; i < MESH_STATS_NUM; i++) {
1338 memcpy(s + i * ETH_GSTRING_LEN,
1339 mesh_stat_strings[i],
1344 lbs_deb_enter(LBS_DEB_ETHTOOL);