1 // SPDX-License-Identifier: GPL-2.0
2 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
4 #include <linux/delay.h>
5 #include <linux/etherdevice.h>
6 #include <linux/hardirq.h>
7 #include <linux/netdevice.h>
8 #include <linux/if_ether.h>
9 #include <linux/if_arp.h>
10 #include <linux/kthread.h>
11 #include <linux/kfifo.h>
12 #include <net/cfg80211.h>
19 static int lbs_add_mesh(struct lbs_private *priv);
21 /***************************************************************************
22 * Mesh command handling
25 static int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
26 struct cmd_ds_mesh_access *cmd)
30 cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
31 cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
34 cmd->action = cpu_to_le16(cmd_action);
36 ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
41 static int __lbs_mesh_config_send(struct lbs_private *priv,
42 struct cmd_ds_mesh_config *cmd,
43 uint16_t action, uint16_t type)
46 u16 command = CMD_MESH_CONFIG_OLD;
49 * Command id is 0xac for v10 FW along with mesh interface
50 * id in bits 14-13-12.
52 if (priv->mesh_tlv == TLV_TYPE_MESH_ID)
53 command = CMD_MESH_CONFIG |
54 (MESH_IFACE_ID << MESH_IFACE_BIT_OFFSET);
56 cmd->hdr.command = cpu_to_le16(command);
57 cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config));
60 cmd->type = cpu_to_le16(type);
61 cmd->action = cpu_to_le16(action);
63 ret = lbs_cmd_with_response(priv, command, cmd);
68 static int lbs_mesh_config_send(struct lbs_private *priv,
69 struct cmd_ds_mesh_config *cmd,
70 uint16_t action, uint16_t type)
74 if (!(priv->fwcapinfo & FW_CAPINFO_PERSISTENT_CONFIG))
77 ret = __lbs_mesh_config_send(priv, cmd, action, type);
81 /* This function is the CMD_MESH_CONFIG legacy function. It only handles the
82 * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG
83 * are all handled by preparing a struct cmd_ds_mesh_config and passing it to
84 * lbs_mesh_config_send.
86 static int lbs_mesh_config(struct lbs_private *priv, uint16_t action,
89 struct cmd_ds_mesh_config cmd;
90 struct mrvl_meshie *ie;
92 memset(&cmd, 0, sizeof(cmd));
93 cmd.channel = cpu_to_le16(chan);
94 ie = (struct mrvl_meshie *)cmd.data;
97 case CMD_ACT_MESH_CONFIG_START:
98 ie->id = WLAN_EID_VENDOR_SPECIFIC;
99 ie->val.oui[0] = 0x00;
100 ie->val.oui[1] = 0x50;
101 ie->val.oui[2] = 0x43;
102 ie->val.type = MARVELL_MESH_IE_TYPE;
103 ie->val.subtype = MARVELL_MESH_IE_SUBTYPE;
104 ie->val.version = MARVELL_MESH_IE_VERSION;
105 ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP;
106 ie->val.active_metric_id = MARVELL_MESH_METRIC_ID;
107 ie->val.mesh_capability = MARVELL_MESH_CAPABILITY;
108 ie->val.mesh_id_len = priv->mesh_ssid_len;
109 memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len);
110 ie->len = sizeof(struct mrvl_meshie_val) -
111 IEEE80211_MAX_SSID_LEN + priv->mesh_ssid_len;
112 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val));
114 case CMD_ACT_MESH_CONFIG_STOP:
119 lbs_deb_cmd("mesh config action %d type %x channel %d SSID %*pE\n",
120 action, priv->mesh_tlv, chan, priv->mesh_ssid_len,
123 return __lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv);
126 int lbs_mesh_set_channel(struct lbs_private *priv, u8 channel)
128 priv->mesh_channel = channel;
129 return lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, channel);
132 static uint16_t lbs_mesh_get_channel(struct lbs_private *priv)
134 return priv->mesh_channel ?: 1;
137 /***************************************************************************
142 * Attributes exported through sysfs
146 * lbs_anycast_get - Get function for sysfs attribute anycast_mask
147 * @dev: the &struct device
148 * @attr: device attributes
149 * @buf: buffer where data will be returned
151 static ssize_t lbs_anycast_get(struct device *dev,
152 struct device_attribute *attr, char * buf)
154 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
155 struct cmd_ds_mesh_access mesh_access;
158 memset(&mesh_access, 0, sizeof(mesh_access));
160 ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_ANYCAST, &mesh_access);
164 return snprintf(buf, 12, "0x%X\n", le32_to_cpu(mesh_access.data[0]));
168 * lbs_anycast_set - Set function for sysfs attribute anycast_mask
169 * @dev: the &struct device
170 * @attr: device attributes
171 * @buf: buffer that contains new attribute value
172 * @count: size of buffer
174 static ssize_t lbs_anycast_set(struct device *dev,
175 struct device_attribute *attr, const char * buf, size_t count)
177 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
178 struct cmd_ds_mesh_access mesh_access;
182 memset(&mesh_access, 0, sizeof(mesh_access));
183 sscanf(buf, "%x", &datum);
184 mesh_access.data[0] = cpu_to_le32(datum);
186 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_ANYCAST, &mesh_access);
194 * lbs_prb_rsp_limit_get - Get function for sysfs attribute prb_rsp_limit
195 * @dev: the &struct device
196 * @attr: device attributes
197 * @buf: buffer where data will be returned
199 static ssize_t lbs_prb_rsp_limit_get(struct device *dev,
200 struct device_attribute *attr, char *buf)
202 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
203 struct cmd_ds_mesh_access mesh_access;
207 memset(&mesh_access, 0, sizeof(mesh_access));
208 mesh_access.data[0] = cpu_to_le32(CMD_ACT_GET);
210 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT,
215 retry_limit = le32_to_cpu(mesh_access.data[1]);
216 return snprintf(buf, 10, "%d\n", retry_limit);
220 * lbs_prb_rsp_limit_set - Set function for sysfs attribute prb_rsp_limit
221 * @dev: the &struct device
222 * @attr: device attributes
223 * @buf: buffer that contains new attribute value
224 * @count: size of buffer
226 static ssize_t lbs_prb_rsp_limit_set(struct device *dev,
227 struct device_attribute *attr, const char *buf, size_t count)
229 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
230 struct cmd_ds_mesh_access mesh_access;
232 unsigned long retry_limit;
234 memset(&mesh_access, 0, sizeof(mesh_access));
235 mesh_access.data[0] = cpu_to_le32(CMD_ACT_SET);
237 ret = kstrtoul(buf, 10, &retry_limit);
240 if (retry_limit > 15)
243 mesh_access.data[1] = cpu_to_le32(retry_limit);
245 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT,
254 * lbs_mesh_get - Get function for sysfs attribute mesh
255 * @dev: the &struct device
256 * @attr: device attributes
257 * @buf: buffer where data will be returned
259 static ssize_t lbs_mesh_get(struct device *dev,
260 struct device_attribute *attr, char * buf)
262 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
263 return snprintf(buf, 5, "0x%X\n", !!priv->mesh_dev);
267 * lbs_mesh_set - Set function for sysfs attribute mesh
268 * @dev: the &struct device
269 * @attr: device attributes
270 * @buf: buffer that contains new attribute value
271 * @count: size of buffer
273 static ssize_t lbs_mesh_set(struct device *dev,
274 struct device_attribute *attr, const char * buf, size_t count)
276 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
279 sscanf(buf, "%x", &enable);
281 if (enable == !!priv->mesh_dev)
287 lbs_remove_mesh(priv);
293 * lbs_mesh attribute to be exported per ethX interface
294 * through sysfs (/sys/class/net/ethX/lbs_mesh)
296 static DEVICE_ATTR(lbs_mesh, 0644, lbs_mesh_get, lbs_mesh_set);
299 * anycast_mask attribute to be exported per mshX interface
300 * through sysfs (/sys/class/net/mshX/anycast_mask)
302 static DEVICE_ATTR(anycast_mask, 0644, lbs_anycast_get, lbs_anycast_set);
305 * prb_rsp_limit attribute to be exported per mshX interface
306 * through sysfs (/sys/class/net/mshX/prb_rsp_limit)
308 static DEVICE_ATTR(prb_rsp_limit, 0644, lbs_prb_rsp_limit_get,
309 lbs_prb_rsp_limit_set);
311 static struct attribute *lbs_mesh_sysfs_entries[] = {
312 &dev_attr_anycast_mask.attr,
313 &dev_attr_prb_rsp_limit.attr,
317 static const struct attribute_group lbs_mesh_attr_group = {
318 .attrs = lbs_mesh_sysfs_entries,
322 /***************************************************************************
323 * Persistent configuration support
326 static int mesh_get_default_parameters(struct device *dev,
327 struct mrvl_mesh_defaults *defs)
329 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
330 struct cmd_ds_mesh_config cmd;
333 memset(&cmd, 0, sizeof(struct cmd_ds_mesh_config));
334 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_GET,
335 CMD_TYPE_MESH_GET_DEFAULTS);
340 memcpy(defs, &cmd.data[0], sizeof(struct mrvl_mesh_defaults));
346 * bootflag_get - Get function for sysfs attribute bootflag
347 * @dev: the &struct device
348 * @attr: device attributes
349 * @buf: buffer where data will be returned
351 static ssize_t bootflag_get(struct device *dev,
352 struct device_attribute *attr, char *buf)
354 struct mrvl_mesh_defaults defs;
357 ret = mesh_get_default_parameters(dev, &defs);
362 return snprintf(buf, 12, "%d\n", le32_to_cpu(defs.bootflag));
366 * bootflag_set - Set function for sysfs attribute bootflag
367 * @dev: the &struct device
368 * @attr: device attributes
369 * @buf: buffer that contains new attribute value
370 * @count: size of buffer
372 static ssize_t bootflag_set(struct device *dev, struct device_attribute *attr,
373 const char *buf, size_t count)
375 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
376 struct cmd_ds_mesh_config cmd;
380 memset(&cmd, 0, sizeof(cmd));
381 ret = sscanf(buf, "%d", &datum);
382 if ((ret != 1) || (datum > 1))
385 *((__le32 *)&cmd.data[0]) = cpu_to_le32(!!datum);
386 cmd.length = cpu_to_le16(sizeof(uint32_t));
387 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
388 CMD_TYPE_MESH_SET_BOOTFLAG);
396 * boottime_get - Get function for sysfs attribute boottime
397 * @dev: the &struct device
398 * @attr: device attributes
399 * @buf: buffer where data will be returned
401 static ssize_t boottime_get(struct device *dev,
402 struct device_attribute *attr, char *buf)
404 struct mrvl_mesh_defaults defs;
407 ret = mesh_get_default_parameters(dev, &defs);
412 return snprintf(buf, 12, "%d\n", defs.boottime);
416 * boottime_set - Set function for sysfs attribute boottime
417 * @dev: the &struct device
418 * @attr: device attributes
419 * @buf: buffer that contains new attribute value
420 * @count: size of buffer
422 static ssize_t boottime_set(struct device *dev,
423 struct device_attribute *attr, const char *buf, size_t count)
425 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
426 struct cmd_ds_mesh_config cmd;
430 memset(&cmd, 0, sizeof(cmd));
431 ret = sscanf(buf, "%d", &datum);
432 if ((ret != 1) || (datum > 255))
435 /* A too small boot time will result in the device booting into
436 * standalone (no-host) mode before the host can take control of it,
437 * so the change will be hard to revert. This may be a desired
438 * feature (e.g to configure a very fast boot time for devices that
439 * will not be attached to a host), but dangerous. So I'm enforcing a
440 * lower limit of 20 seconds: remove and recompile the driver if this
441 * does not work for you.
443 datum = (datum < 20) ? 20 : datum;
445 cmd.length = cpu_to_le16(sizeof(uint8_t));
446 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
447 CMD_TYPE_MESH_SET_BOOTTIME);
455 * channel_get - Get function for sysfs attribute channel
456 * @dev: the &struct device
457 * @attr: device attributes
458 * @buf: buffer where data will be returned
460 static ssize_t channel_get(struct device *dev,
461 struct device_attribute *attr, char *buf)
463 struct mrvl_mesh_defaults defs;
466 ret = mesh_get_default_parameters(dev, &defs);
471 return snprintf(buf, 12, "%d\n", le16_to_cpu(defs.channel));
475 * channel_set - Set function for sysfs attribute channel
476 * @dev: the &struct device
477 * @attr: device attributes
478 * @buf: buffer that contains new attribute value
479 * @count: size of buffer
481 static ssize_t channel_set(struct device *dev, struct device_attribute *attr,
482 const char *buf, size_t count)
484 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
485 struct cmd_ds_mesh_config cmd;
489 memset(&cmd, 0, sizeof(cmd));
490 ret = sscanf(buf, "%d", &datum);
491 if (ret != 1 || datum < 1 || datum > 11)
494 *((__le16 *)&cmd.data[0]) = cpu_to_le16(datum);
495 cmd.length = cpu_to_le16(sizeof(uint16_t));
496 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
497 CMD_TYPE_MESH_SET_DEF_CHANNEL);
505 * mesh_id_get - Get function for sysfs attribute mesh_id
506 * @dev: the &struct device
507 * @attr: device attributes
508 * @buf: buffer where data will be returned
510 static ssize_t mesh_id_get(struct device *dev, struct device_attribute *attr,
513 struct mrvl_mesh_defaults defs;
516 ret = mesh_get_default_parameters(dev, &defs);
521 if (defs.meshie.val.mesh_id_len > IEEE80211_MAX_SSID_LEN) {
522 dev_err(dev, "inconsistent mesh ID length\n");
523 defs.meshie.val.mesh_id_len = IEEE80211_MAX_SSID_LEN;
526 memcpy(buf, defs.meshie.val.mesh_id, defs.meshie.val.mesh_id_len);
527 buf[defs.meshie.val.mesh_id_len] = '\n';
528 buf[defs.meshie.val.mesh_id_len + 1] = '\0';
530 return defs.meshie.val.mesh_id_len + 1;
534 * mesh_id_set - Set function for sysfs attribute mesh_id
535 * @dev: the &struct device
536 * @attr: device attributes
537 * @buf: buffer that contains new attribute value
538 * @count: size of buffer
540 static ssize_t mesh_id_set(struct device *dev, struct device_attribute *attr,
541 const char *buf, size_t count)
543 struct cmd_ds_mesh_config cmd;
544 struct mrvl_mesh_defaults defs;
545 struct mrvl_meshie *ie;
546 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
550 if (count < 2 || count > IEEE80211_MAX_SSID_LEN + 1)
553 memset(&cmd, 0, sizeof(struct cmd_ds_mesh_config));
554 ie = (struct mrvl_meshie *) &cmd.data[0];
556 /* fetch all other Information Element parameters */
557 ret = mesh_get_default_parameters(dev, &defs);
559 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
561 /* transfer IE elements */
562 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
565 memcpy(ie->val.mesh_id, buf, len);
567 ie->val.mesh_id_len = len;
569 ie->len = sizeof(struct mrvl_meshie_val) - IEEE80211_MAX_SSID_LEN + len;
571 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
572 CMD_TYPE_MESH_SET_MESH_IE);
580 * protocol_id_get - Get function for sysfs attribute protocol_id
581 * @dev: the &struct device
582 * @attr: device attributes
583 * @buf: buffer where data will be returned
585 static ssize_t protocol_id_get(struct device *dev,
586 struct device_attribute *attr, char *buf)
588 struct mrvl_mesh_defaults defs;
591 ret = mesh_get_default_parameters(dev, &defs);
596 return snprintf(buf, 5, "%d\n", defs.meshie.val.active_protocol_id);
600 * protocol_id_set - Set function for sysfs attribute protocol_id
601 * @dev: the &struct device
602 * @attr: device attributes
603 * @buf: buffer that contains new attribute value
604 * @count: size of buffer
606 static ssize_t protocol_id_set(struct device *dev,
607 struct device_attribute *attr, const char *buf, size_t count)
609 struct cmd_ds_mesh_config cmd;
610 struct mrvl_mesh_defaults defs;
611 struct mrvl_meshie *ie;
612 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
616 memset(&cmd, 0, sizeof(cmd));
617 ret = sscanf(buf, "%d", &datum);
618 if ((ret != 1) || (datum > 255))
621 /* fetch all other Information Element parameters */
622 ret = mesh_get_default_parameters(dev, &defs);
624 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
626 /* transfer IE elements */
627 ie = (struct mrvl_meshie *) &cmd.data[0];
628 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
629 /* update protocol id */
630 ie->val.active_protocol_id = datum;
632 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
633 CMD_TYPE_MESH_SET_MESH_IE);
641 * metric_id_get - Get function for sysfs attribute metric_id
642 * @dev: the &struct device
643 * @attr: device attributes
644 * @buf: buffer where data will be returned
646 static ssize_t metric_id_get(struct device *dev,
647 struct device_attribute *attr, char *buf)
649 struct mrvl_mesh_defaults defs;
652 ret = mesh_get_default_parameters(dev, &defs);
657 return snprintf(buf, 5, "%d\n", defs.meshie.val.active_metric_id);
661 * metric_id_set - Set function for sysfs attribute metric_id
662 * @dev: the &struct device
663 * @attr: device attributes
664 * @buf: buffer that contains new attribute value
665 * @count: size of buffer
667 static ssize_t metric_id_set(struct device *dev, struct device_attribute *attr,
668 const char *buf, size_t count)
670 struct cmd_ds_mesh_config cmd;
671 struct mrvl_mesh_defaults defs;
672 struct mrvl_meshie *ie;
673 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
677 memset(&cmd, 0, sizeof(cmd));
678 ret = sscanf(buf, "%d", &datum);
679 if ((ret != 1) || (datum > 255))
682 /* fetch all other Information Element parameters */
683 ret = mesh_get_default_parameters(dev, &defs);
685 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
687 /* transfer IE elements */
688 ie = (struct mrvl_meshie *) &cmd.data[0];
689 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
690 /* update metric id */
691 ie->val.active_metric_id = datum;
693 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
694 CMD_TYPE_MESH_SET_MESH_IE);
702 * capability_get - Get function for sysfs attribute capability
703 * @dev: the &struct device
704 * @attr: device attributes
705 * @buf: buffer where data will be returned
707 static ssize_t capability_get(struct device *dev,
708 struct device_attribute *attr, char *buf)
710 struct mrvl_mesh_defaults defs;
713 ret = mesh_get_default_parameters(dev, &defs);
718 return snprintf(buf, 5, "%d\n", defs.meshie.val.mesh_capability);
722 * capability_set - Set function for sysfs attribute capability
723 * @dev: the &struct device
724 * @attr: device attributes
725 * @buf: buffer that contains new attribute value
726 * @count: size of buffer
728 static ssize_t capability_set(struct device *dev, struct device_attribute *attr,
729 const char *buf, size_t count)
731 struct cmd_ds_mesh_config cmd;
732 struct mrvl_mesh_defaults defs;
733 struct mrvl_meshie *ie;
734 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
738 memset(&cmd, 0, sizeof(cmd));
739 ret = sscanf(buf, "%d", &datum);
740 if ((ret != 1) || (datum > 255))
743 /* fetch all other Information Element parameters */
744 ret = mesh_get_default_parameters(dev, &defs);
746 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
748 /* transfer IE elements */
749 ie = (struct mrvl_meshie *) &cmd.data[0];
750 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
752 ie->val.mesh_capability = datum;
754 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
755 CMD_TYPE_MESH_SET_MESH_IE);
763 static DEVICE_ATTR(bootflag, 0644, bootflag_get, bootflag_set);
764 static DEVICE_ATTR(boottime, 0644, boottime_get, boottime_set);
765 static DEVICE_ATTR(channel, 0644, channel_get, channel_set);
766 static DEVICE_ATTR(mesh_id, 0644, mesh_id_get, mesh_id_set);
767 static DEVICE_ATTR(protocol_id, 0644, protocol_id_get, protocol_id_set);
768 static DEVICE_ATTR(metric_id, 0644, metric_id_get, metric_id_set);
769 static DEVICE_ATTR(capability, 0644, capability_get, capability_set);
771 static struct attribute *boot_opts_attrs[] = {
772 &dev_attr_bootflag.attr,
773 &dev_attr_boottime.attr,
774 &dev_attr_channel.attr,
778 static const struct attribute_group boot_opts_group = {
779 .name = "boot_options",
780 .attrs = boot_opts_attrs,
783 static struct attribute *mesh_ie_attrs[] = {
784 &dev_attr_mesh_id.attr,
785 &dev_attr_protocol_id.attr,
786 &dev_attr_metric_id.attr,
787 &dev_attr_capability.attr,
791 static const struct attribute_group mesh_ie_group = {
793 .attrs = mesh_ie_attrs,
797 /***************************************************************************
798 * Initializing and starting, stopping mesh
802 * Check mesh FW version and appropriately send the mesh start
805 int lbs_init_mesh(struct lbs_private *priv)
809 /* Determine mesh_fw_ver from fwrelease and fwcapinfo */
810 /* 5.0.16p0 9.0.0.p0 is known to NOT support any mesh */
811 /* 5.110.22 have mesh command with 0xa3 command id */
812 /* 10.0.0.p0 FW brings in mesh config command with different id */
813 /* Check FW version MSB and initialize mesh_fw_ver */
814 if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V5) {
815 /* Enable mesh, if supported, and work out which TLV it uses.
816 0x100 + 291 is an unofficial value used in 5.110.20.pXX
817 0x100 + 37 is the official value used in 5.110.21.pXX
818 but we check them in that order because 20.pXX doesn't
819 give an error -- it just silently fails. */
821 /* 5.110.20.pXX firmware will fail the command if the channel
822 doesn't match the existing channel. But only if the TLV
823 is correct. If the channel is wrong, _BOTH_ versions will
824 give an error to 0x100+291, and allow 0x100+37 to succeed.
825 It's just that 5.110.20.pXX will not have done anything
828 priv->mesh_tlv = TLV_TYPE_OLD_MESH_ID;
829 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, 1)) {
830 priv->mesh_tlv = TLV_TYPE_MESH_ID;
831 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, 1))
835 if ((MRVL_FW_MAJOR_REV(priv->fwrelease) >= MRVL_FW_V10) &&
836 (priv->fwcapinfo & MESH_CAPINFO_ENABLE_MASK)) {
837 /* 10.0.0.pXX new firmwares should succeed with TLV
838 * 0x100+37; Do not invoke command with old TLV.
840 priv->mesh_tlv = TLV_TYPE_MESH_ID;
841 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, 1))
845 /* Stop meshing until interface is brought up */
846 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_STOP, 1);
848 if (priv->mesh_tlv) {
849 sprintf(priv->mesh_ssid, "mesh");
850 priv->mesh_ssid_len = 4;
857 void lbs_start_mesh(struct lbs_private *priv)
861 if (device_create_file(&priv->dev->dev, &dev_attr_lbs_mesh))
862 netdev_err(priv->dev, "cannot register lbs_mesh attribute\n");
865 int lbs_deinit_mesh(struct lbs_private *priv)
867 struct net_device *dev = priv->dev;
870 if (priv->mesh_tlv) {
871 device_remove_file(&dev->dev, &dev_attr_lbs_mesh);
880 * lbs_mesh_stop - close the mshX interface
882 * @dev: A pointer to &net_device structure
885 static int lbs_mesh_stop(struct net_device *dev)
887 struct lbs_private *priv = dev->ml_priv;
889 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_STOP,
890 lbs_mesh_get_channel(priv));
892 spin_lock_irq(&priv->driver_lock);
894 netif_stop_queue(dev);
895 netif_carrier_off(dev);
897 spin_unlock_irq(&priv->driver_lock);
899 lbs_update_mcast(priv);
900 if (!lbs_iface_active(priv))
901 lbs_stop_iface(priv);
907 * lbs_mesh_dev_open - open the mshX interface
909 * @dev: A pointer to &net_device structure
910 * returns: 0 or -EBUSY if monitor mode active
912 static int lbs_mesh_dev_open(struct net_device *dev)
914 struct lbs_private *priv = dev->ml_priv;
917 if (!priv->iface_running) {
918 ret = lbs_start_iface(priv);
923 spin_lock_irq(&priv->driver_lock);
925 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR) {
927 spin_unlock_irq(&priv->driver_lock);
931 netif_carrier_on(dev);
933 if (!priv->tx_pending_len)
934 netif_wake_queue(dev);
936 spin_unlock_irq(&priv->driver_lock);
938 ret = lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
939 lbs_mesh_get_channel(priv));
945 static const struct net_device_ops mesh_netdev_ops = {
946 .ndo_open = lbs_mesh_dev_open,
947 .ndo_stop = lbs_mesh_stop,
948 .ndo_start_xmit = lbs_hard_start_xmit,
949 .ndo_set_mac_address = lbs_set_mac_address,
950 .ndo_set_rx_mode = lbs_set_multicast_list,
954 * lbs_add_mesh - add mshX interface
956 * @priv: A pointer to the &struct lbs_private structure
957 * returns: 0 if successful, -X otherwise
959 static int lbs_add_mesh(struct lbs_private *priv)
961 struct net_device *mesh_dev = NULL;
962 struct wireless_dev *mesh_wdev;
965 /* Allocate a virtual mesh device */
966 mesh_wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
968 lbs_deb_mesh("init mshX wireless device failed\n");
973 mesh_dev = alloc_netdev(0, "msh%d", NET_NAME_UNKNOWN, ether_setup);
975 lbs_deb_mesh("init mshX device failed\n");
980 mesh_wdev->iftype = NL80211_IFTYPE_MESH_POINT;
981 mesh_wdev->wiphy = priv->wdev->wiphy;
982 mesh_wdev->netdev = mesh_dev;
984 mesh_dev->ml_priv = priv;
985 mesh_dev->ieee80211_ptr = mesh_wdev;
986 priv->mesh_dev = mesh_dev;
988 mesh_dev->netdev_ops = &mesh_netdev_ops;
989 mesh_dev->ethtool_ops = &lbs_ethtool_ops;
990 eth_hw_addr_inherit(mesh_dev, priv->dev);
992 SET_NETDEV_DEV(priv->mesh_dev, priv->dev->dev.parent);
994 mesh_dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
995 mesh_dev->sysfs_groups[0] = &lbs_mesh_attr_group;
996 mesh_dev->sysfs_groups[1] = &boot_opts_group;
997 mesh_dev->sysfs_groups[2] = &mesh_ie_group;
999 /* Register virtual mesh interface */
1000 ret = register_netdev(mesh_dev);
1002 pr_err("cannot register mshX virtual interface\n");
1003 goto err_free_netdev;
1006 /* Everything successful */
1011 free_netdev(mesh_dev);
1020 void lbs_remove_mesh(struct lbs_private *priv)
1022 struct net_device *mesh_dev;
1024 mesh_dev = priv->mesh_dev;
1028 netif_stop_queue(mesh_dev);
1029 netif_carrier_off(mesh_dev);
1030 unregister_netdev(mesh_dev);
1031 priv->mesh_dev = NULL;
1032 kfree(mesh_dev->ieee80211_ptr);
1033 free_netdev(mesh_dev);
1037 /***************************************************************************
1038 * Sending and receiving
1040 struct net_device *lbs_mesh_set_dev(struct lbs_private *priv,
1041 struct net_device *dev, struct rxpd *rxpd)
1043 if (priv->mesh_dev) {
1044 if (priv->mesh_tlv == TLV_TYPE_OLD_MESH_ID) {
1045 if (rxpd->rx_control & RxPD_MESH_FRAME)
1046 dev = priv->mesh_dev;
1047 } else if (priv->mesh_tlv == TLV_TYPE_MESH_ID) {
1048 if (rxpd->u.bss.bss_num == MESH_IFACE_ID)
1049 dev = priv->mesh_dev;
1056 void lbs_mesh_set_txpd(struct lbs_private *priv,
1057 struct net_device *dev, struct txpd *txpd)
1059 if (dev == priv->mesh_dev) {
1060 if (priv->mesh_tlv == TLV_TYPE_OLD_MESH_ID)
1061 txpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
1062 else if (priv->mesh_tlv == TLV_TYPE_MESH_ID)
1063 txpd->u.bss.bss_num = MESH_IFACE_ID;
1068 /***************************************************************************
1072 static const char mesh_stat_strings[MESH_STATS_NUM][ETH_GSTRING_LEN] = {
1073 "drop_duplicate_bcast",
1075 "drop_no_fwd_route",
1077 "fwded_unicast_cnt",
1083 void lbs_mesh_ethtool_get_stats(struct net_device *dev,
1084 struct ethtool_stats *stats, uint64_t *data)
1086 struct lbs_private *priv = dev->ml_priv;
1087 struct cmd_ds_mesh_access mesh_access;
1090 /* Get Mesh Statistics */
1091 ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_STATS, &mesh_access);
1094 memset(data, 0, MESH_STATS_NUM*(sizeof(uint64_t)));
1098 priv->mstats.fwd_drop_rbt = le32_to_cpu(mesh_access.data[0]);
1099 priv->mstats.fwd_drop_ttl = le32_to_cpu(mesh_access.data[1]);
1100 priv->mstats.fwd_drop_noroute = le32_to_cpu(mesh_access.data[2]);
1101 priv->mstats.fwd_drop_nobuf = le32_to_cpu(mesh_access.data[3]);
1102 priv->mstats.fwd_unicast_cnt = le32_to_cpu(mesh_access.data[4]);
1103 priv->mstats.fwd_bcast_cnt = le32_to_cpu(mesh_access.data[5]);
1104 priv->mstats.drop_blind = le32_to_cpu(mesh_access.data[6]);
1105 priv->mstats.tx_failed_cnt = le32_to_cpu(mesh_access.data[7]);
1107 data[0] = priv->mstats.fwd_drop_rbt;
1108 data[1] = priv->mstats.fwd_drop_ttl;
1109 data[2] = priv->mstats.fwd_drop_noroute;
1110 data[3] = priv->mstats.fwd_drop_nobuf;
1111 data[4] = priv->mstats.fwd_unicast_cnt;
1112 data[5] = priv->mstats.fwd_bcast_cnt;
1113 data[6] = priv->mstats.drop_blind;
1114 data[7] = priv->mstats.tx_failed_cnt;
1117 int lbs_mesh_ethtool_get_sset_count(struct net_device *dev, int sset)
1119 struct lbs_private *priv = dev->ml_priv;
1121 if (sset == ETH_SS_STATS && dev == priv->mesh_dev)
1122 return MESH_STATS_NUM;
1127 void lbs_mesh_ethtool_get_strings(struct net_device *dev,
1128 uint32_t stringset, uint8_t *s)
1130 switch (stringset) {
1132 memcpy(s, mesh_stat_strings, sizeof(mesh_stat_strings));