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 wireless_dev *mesh_wdev;
90 struct cmd_ds_mesh_config cmd;
91 struct mrvl_meshie *ie;
93 memset(&cmd, 0, sizeof(cmd));
94 cmd.channel = cpu_to_le16(chan);
95 ie = (struct mrvl_meshie *)cmd.data;
98 case CMD_ACT_MESH_CONFIG_START:
99 ie->id = WLAN_EID_VENDOR_SPECIFIC;
100 ie->val.oui[0] = 0x00;
101 ie->val.oui[1] = 0x50;
102 ie->val.oui[2] = 0x43;
103 ie->val.type = MARVELL_MESH_IE_TYPE;
104 ie->val.subtype = MARVELL_MESH_IE_SUBTYPE;
105 ie->val.version = MARVELL_MESH_IE_VERSION;
106 ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP;
107 ie->val.active_metric_id = MARVELL_MESH_METRIC_ID;
108 ie->val.mesh_capability = MARVELL_MESH_CAPABILITY;
110 if (priv->mesh_dev) {
111 mesh_wdev = priv->mesh_dev->ieee80211_ptr;
112 ie->val.mesh_id_len = mesh_wdev->mesh_id_up_len;
113 memcpy(ie->val.mesh_id, mesh_wdev->ssid,
114 mesh_wdev->mesh_id_up_len);
117 ie->len = sizeof(struct mrvl_meshie_val) -
118 IEEE80211_MAX_SSID_LEN + ie->val.mesh_id_len;
120 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val));
122 case CMD_ACT_MESH_CONFIG_STOP:
127 lbs_deb_cmd("mesh config action %d type %x channel %d SSID %*pE\n",
128 action, priv->mesh_tlv, chan, ie->val.mesh_id_len,
131 return __lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv);
134 int lbs_mesh_set_channel(struct lbs_private *priv, u8 channel)
136 priv->mesh_channel = channel;
137 return lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, channel);
140 static uint16_t lbs_mesh_get_channel(struct lbs_private *priv)
142 return priv->mesh_channel ?: 1;
145 /***************************************************************************
150 * Attributes exported through sysfs
154 * anycast_mask_show - Get function for sysfs attribute anycast_mask
155 * @dev: the &struct device
156 * @attr: device attributes
157 * @buf: buffer where data will be returned
159 static ssize_t anycast_mask_show(struct device *dev,
160 struct device_attribute *attr, char *buf)
162 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
163 struct cmd_ds_mesh_access mesh_access;
166 memset(&mesh_access, 0, sizeof(mesh_access));
168 ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_ANYCAST, &mesh_access);
172 return sysfs_emit(buf, "0x%X\n", le32_to_cpu(mesh_access.data[0]));
176 * anycast_mask_store - Set function for sysfs attribute anycast_mask
177 * @dev: the &struct device
178 * @attr: device attributes
179 * @buf: buffer that contains new attribute value
180 * @count: size of buffer
182 static ssize_t anycast_mask_store(struct device *dev,
183 struct device_attribute *attr,
184 const char *buf, size_t count)
186 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
187 struct cmd_ds_mesh_access mesh_access;
191 memset(&mesh_access, 0, sizeof(mesh_access));
192 sscanf(buf, "%x", &datum);
193 mesh_access.data[0] = cpu_to_le32(datum);
195 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_ANYCAST, &mesh_access);
203 * prb_rsp_limit_show - Get function for sysfs attribute prb_rsp_limit
204 * @dev: the &struct device
205 * @attr: device attributes
206 * @buf: buffer where data will be returned
208 static ssize_t prb_rsp_limit_show(struct device *dev,
209 struct device_attribute *attr, char *buf)
211 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
212 struct cmd_ds_mesh_access mesh_access;
216 memset(&mesh_access, 0, sizeof(mesh_access));
217 mesh_access.data[0] = cpu_to_le32(CMD_ACT_GET);
219 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT,
224 retry_limit = le32_to_cpu(mesh_access.data[1]);
225 return sysfs_emit(buf, "%d\n", retry_limit);
229 * prb_rsp_limit_store - Set function for sysfs attribute prb_rsp_limit
230 * @dev: the &struct device
231 * @attr: device attributes
232 * @buf: buffer that contains new attribute value
233 * @count: size of buffer
235 static ssize_t prb_rsp_limit_store(struct device *dev,
236 struct device_attribute *attr,
237 const char *buf, size_t count)
239 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
240 struct cmd_ds_mesh_access mesh_access;
242 unsigned long retry_limit;
244 memset(&mesh_access, 0, sizeof(mesh_access));
245 mesh_access.data[0] = cpu_to_le32(CMD_ACT_SET);
247 ret = kstrtoul(buf, 10, &retry_limit);
250 if (retry_limit > 15)
253 mesh_access.data[1] = cpu_to_le32(retry_limit);
255 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT,
264 * lbs_mesh_show - Get function for sysfs attribute mesh
265 * @dev: the &struct device
266 * @attr: device attributes
267 * @buf: buffer where data will be returned
269 static ssize_t lbs_mesh_show(struct device *dev,
270 struct device_attribute *attr, char *buf)
272 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
273 return sysfs_emit(buf, "0x%X\n", !!priv->mesh_dev);
277 * lbs_mesh_store - Set function for sysfs attribute mesh
278 * @dev: the &struct device
279 * @attr: device attributes
280 * @buf: buffer that contains new attribute value
281 * @count: size of buffer
283 static ssize_t lbs_mesh_store(struct device *dev,
284 struct device_attribute *attr,
285 const char *buf, size_t count)
287 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
290 sscanf(buf, "%x", &enable);
292 if (enable == !!priv->mesh_dev)
298 lbs_remove_mesh(priv);
304 * lbs_mesh attribute to be exported per ethX interface
305 * through sysfs (/sys/class/net/ethX/lbs_mesh)
307 static DEVICE_ATTR_RW(lbs_mesh);
310 * anycast_mask attribute to be exported per mshX interface
311 * through sysfs (/sys/class/net/mshX/anycast_mask)
313 static DEVICE_ATTR_RW(anycast_mask);
316 * prb_rsp_limit attribute to be exported per mshX interface
317 * through sysfs (/sys/class/net/mshX/prb_rsp_limit)
319 static DEVICE_ATTR_RW(prb_rsp_limit);
321 static struct attribute *lbs_mesh_sysfs_entries[] = {
322 &dev_attr_anycast_mask.attr,
323 &dev_attr_prb_rsp_limit.attr,
327 static const struct attribute_group lbs_mesh_attr_group = {
328 .attrs = lbs_mesh_sysfs_entries,
332 /***************************************************************************
333 * Persistent configuration support
336 static int mesh_get_default_parameters(struct device *dev,
337 struct mrvl_mesh_defaults *defs)
339 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
340 struct cmd_ds_mesh_config cmd;
343 memset(&cmd, 0, sizeof(struct cmd_ds_mesh_config));
344 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_GET,
345 CMD_TYPE_MESH_GET_DEFAULTS);
350 memcpy(defs, &cmd.data[0], sizeof(struct mrvl_mesh_defaults));
356 * bootflag_show - Get function for sysfs attribute bootflag
357 * @dev: the &struct device
358 * @attr: device attributes
359 * @buf: buffer where data will be returned
361 static ssize_t bootflag_show(struct device *dev,
362 struct device_attribute *attr, char *buf)
364 struct mrvl_mesh_defaults defs;
367 ret = mesh_get_default_parameters(dev, &defs);
372 return sysfs_emit(buf, "%d\n", le32_to_cpu(defs.bootflag));
376 * bootflag_store - Set function for sysfs attribute bootflag
377 * @dev: the &struct device
378 * @attr: device attributes
379 * @buf: buffer that contains new attribute value
380 * @count: size of buffer
382 static ssize_t bootflag_store(struct device *dev, struct device_attribute *attr,
383 const char *buf, size_t count)
385 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
386 struct cmd_ds_mesh_config cmd;
390 memset(&cmd, 0, sizeof(cmd));
391 ret = sscanf(buf, "%d", &datum);
392 if ((ret != 1) || (datum > 1))
395 *((__le32 *)&cmd.data[0]) = cpu_to_le32(!!datum);
396 cmd.length = cpu_to_le16(sizeof(uint32_t));
397 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
398 CMD_TYPE_MESH_SET_BOOTFLAG);
406 * boottime_show - Get function for sysfs attribute boottime
407 * @dev: the &struct device
408 * @attr: device attributes
409 * @buf: buffer where data will be returned
411 static ssize_t boottime_show(struct device *dev,
412 struct device_attribute *attr, char *buf)
414 struct mrvl_mesh_defaults defs;
417 ret = mesh_get_default_parameters(dev, &defs);
422 return sysfs_emit(buf, "%d\n", defs.boottime);
426 * boottime_store - Set function for sysfs attribute boottime
427 * @dev: the &struct device
428 * @attr: device attributes
429 * @buf: buffer that contains new attribute value
430 * @count: size of buffer
432 static ssize_t boottime_store(struct device *dev,
433 struct device_attribute *attr,
434 const char *buf, size_t count)
436 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
437 struct cmd_ds_mesh_config cmd;
441 memset(&cmd, 0, sizeof(cmd));
442 ret = sscanf(buf, "%d", &datum);
443 if ((ret != 1) || (datum > 255))
446 /* A too small boot time will result in the device booting into
447 * standalone (no-host) mode before the host can take control of it,
448 * so the change will be hard to revert. This may be a desired
449 * feature (e.g to configure a very fast boot time for devices that
450 * will not be attached to a host), but dangerous. So I'm enforcing a
451 * lower limit of 20 seconds: remove and recompile the driver if this
452 * does not work for you.
454 datum = (datum < 20) ? 20 : datum;
456 cmd.length = cpu_to_le16(sizeof(uint8_t));
457 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
458 CMD_TYPE_MESH_SET_BOOTTIME);
466 * channel_show - Get function for sysfs attribute channel
467 * @dev: the &struct device
468 * @attr: device attributes
469 * @buf: buffer where data will be returned
471 static ssize_t channel_show(struct device *dev,
472 struct device_attribute *attr, char *buf)
474 struct mrvl_mesh_defaults defs;
477 ret = mesh_get_default_parameters(dev, &defs);
482 return sysfs_emit(buf, "%d\n", le16_to_cpu(defs.channel));
486 * channel_store - Set function for sysfs attribute channel
487 * @dev: the &struct device
488 * @attr: device attributes
489 * @buf: buffer that contains new attribute value
490 * @count: size of buffer
492 static ssize_t channel_store(struct device *dev, struct device_attribute *attr,
493 const char *buf, size_t count)
495 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
496 struct cmd_ds_mesh_config cmd;
500 memset(&cmd, 0, sizeof(cmd));
501 ret = sscanf(buf, "%d", &datum);
502 if (ret != 1 || datum < 1 || datum > 11)
505 *((__le16 *)&cmd.data[0]) = cpu_to_le16(datum);
506 cmd.length = cpu_to_le16(sizeof(uint16_t));
507 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
508 CMD_TYPE_MESH_SET_DEF_CHANNEL);
516 * mesh_id_show - Get function for sysfs attribute mesh_id
517 * @dev: the &struct device
518 * @attr: device attributes
519 * @buf: buffer where data will be returned
521 static ssize_t mesh_id_show(struct device *dev, struct device_attribute *attr,
524 struct mrvl_mesh_defaults defs;
527 ret = mesh_get_default_parameters(dev, &defs);
532 if (defs.meshie.val.mesh_id_len > IEEE80211_MAX_SSID_LEN) {
533 dev_err(dev, "inconsistent mesh ID length\n");
534 defs.meshie.val.mesh_id_len = IEEE80211_MAX_SSID_LEN;
537 memcpy(buf, defs.meshie.val.mesh_id, defs.meshie.val.mesh_id_len);
538 buf[defs.meshie.val.mesh_id_len] = '\n';
539 buf[defs.meshie.val.mesh_id_len + 1] = '\0';
541 return defs.meshie.val.mesh_id_len + 1;
545 * mesh_id_store - Set function for sysfs attribute mesh_id
546 * @dev: the &struct device
547 * @attr: device attributes
548 * @buf: buffer that contains new attribute value
549 * @count: size of buffer
551 static ssize_t mesh_id_store(struct device *dev, struct device_attribute *attr,
552 const char *buf, size_t count)
554 struct cmd_ds_mesh_config cmd;
555 struct mrvl_mesh_defaults defs;
556 struct mrvl_meshie *ie;
557 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
561 if (count < 2 || count > IEEE80211_MAX_SSID_LEN + 1)
564 memset(&cmd, 0, sizeof(struct cmd_ds_mesh_config));
565 ie = (struct mrvl_meshie *) &cmd.data[0];
567 /* fetch all other Information Element parameters */
568 ret = mesh_get_default_parameters(dev, &defs);
570 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
572 /* transfer IE elements */
573 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
576 memcpy(ie->val.mesh_id, buf, len);
578 ie->val.mesh_id_len = len;
580 ie->len = sizeof(struct mrvl_meshie_val) - IEEE80211_MAX_SSID_LEN + len;
582 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
583 CMD_TYPE_MESH_SET_MESH_IE);
591 * protocol_id_show - Get function for sysfs attribute protocol_id
592 * @dev: the &struct device
593 * @attr: device attributes
594 * @buf: buffer where data will be returned
596 static ssize_t protocol_id_show(struct device *dev,
597 struct device_attribute *attr,
600 struct mrvl_mesh_defaults defs;
603 ret = mesh_get_default_parameters(dev, &defs);
608 return sysfs_emit(buf, "%d\n", defs.meshie.val.active_protocol_id);
612 * protocol_id_store - Set function for sysfs attribute protocol_id
613 * @dev: the &struct device
614 * @attr: device attributes
615 * @buf: buffer that contains new attribute value
616 * @count: size of buffer
618 static ssize_t protocol_id_store(struct device *dev,
619 struct device_attribute *attr,
620 const char *buf, size_t count)
622 struct cmd_ds_mesh_config cmd;
623 struct mrvl_mesh_defaults defs;
624 struct mrvl_meshie *ie;
625 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
629 memset(&cmd, 0, sizeof(cmd));
630 ret = sscanf(buf, "%d", &datum);
631 if ((ret != 1) || (datum > 255))
634 /* fetch all other Information Element parameters */
635 ret = mesh_get_default_parameters(dev, &defs);
637 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
639 /* transfer IE elements */
640 ie = (struct mrvl_meshie *) &cmd.data[0];
641 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
642 /* update protocol id */
643 ie->val.active_protocol_id = datum;
645 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
646 CMD_TYPE_MESH_SET_MESH_IE);
654 * metric_id_show - Get function for sysfs attribute metric_id
655 * @dev: the &struct device
656 * @attr: device attributes
657 * @buf: buffer where data will be returned
659 static ssize_t metric_id_show(struct device *dev,
660 struct device_attribute *attr, char *buf)
662 struct mrvl_mesh_defaults defs;
665 ret = mesh_get_default_parameters(dev, &defs);
670 return sysfs_emit(buf, "%d\n", defs.meshie.val.active_metric_id);
674 * metric_id_store - Set function for sysfs attribute metric_id
675 * @dev: the &struct device
676 * @attr: device attributes
677 * @buf: buffer that contains new attribute value
678 * @count: size of buffer
680 static ssize_t metric_id_store(struct device *dev,
681 struct device_attribute *attr,
682 const char *buf, size_t count)
684 struct cmd_ds_mesh_config cmd;
685 struct mrvl_mesh_defaults defs;
686 struct mrvl_meshie *ie;
687 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
691 memset(&cmd, 0, sizeof(cmd));
692 ret = sscanf(buf, "%d", &datum);
693 if ((ret != 1) || (datum > 255))
696 /* fetch all other Information Element parameters */
697 ret = mesh_get_default_parameters(dev, &defs);
699 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
701 /* transfer IE elements */
702 ie = (struct mrvl_meshie *) &cmd.data[0];
703 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
704 /* update metric id */
705 ie->val.active_metric_id = datum;
707 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
708 CMD_TYPE_MESH_SET_MESH_IE);
716 * capability_show - Get function for sysfs attribute capability
717 * @dev: the &struct device
718 * @attr: device attributes
719 * @buf: buffer where data will be returned
721 static ssize_t capability_show(struct device *dev,
722 struct device_attribute *attr, char *buf)
724 struct mrvl_mesh_defaults defs;
727 ret = mesh_get_default_parameters(dev, &defs);
732 return sysfs_emit(buf, "%d\n", defs.meshie.val.mesh_capability);
736 * capability_store - Set function for sysfs attribute capability
737 * @dev: the &struct device
738 * @attr: device attributes
739 * @buf: buffer that contains new attribute value
740 * @count: size of buffer
742 static ssize_t capability_store(struct device *dev,
743 struct device_attribute *attr,
744 const char *buf, size_t count)
746 struct cmd_ds_mesh_config cmd;
747 struct mrvl_mesh_defaults defs;
748 struct mrvl_meshie *ie;
749 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
753 memset(&cmd, 0, sizeof(cmd));
754 ret = sscanf(buf, "%d", &datum);
755 if ((ret != 1) || (datum > 255))
758 /* fetch all other Information Element parameters */
759 ret = mesh_get_default_parameters(dev, &defs);
761 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
763 /* transfer IE elements */
764 ie = (struct mrvl_meshie *) &cmd.data[0];
765 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
767 ie->val.mesh_capability = datum;
769 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
770 CMD_TYPE_MESH_SET_MESH_IE);
778 static DEVICE_ATTR_RW(bootflag);
779 static DEVICE_ATTR_RW(boottime);
780 static DEVICE_ATTR_RW(channel);
781 static DEVICE_ATTR_RW(mesh_id);
782 static DEVICE_ATTR_RW(protocol_id);
783 static DEVICE_ATTR_RW(metric_id);
784 static DEVICE_ATTR_RW(capability);
786 static struct attribute *boot_opts_attrs[] = {
787 &dev_attr_bootflag.attr,
788 &dev_attr_boottime.attr,
789 &dev_attr_channel.attr,
793 static const struct attribute_group boot_opts_group = {
794 .name = "boot_options",
795 .attrs = boot_opts_attrs,
798 static struct attribute *mesh_ie_attrs[] = {
799 &dev_attr_mesh_id.attr,
800 &dev_attr_protocol_id.attr,
801 &dev_attr_metric_id.attr,
802 &dev_attr_capability.attr,
806 static const struct attribute_group mesh_ie_group = {
808 .attrs = mesh_ie_attrs,
812 /***************************************************************************
813 * Initializing and starting, stopping mesh
817 * Check mesh FW version and appropriately send the mesh start
820 void lbs_init_mesh(struct lbs_private *priv)
822 /* Determine mesh_fw_ver from fwrelease and fwcapinfo */
823 /* 5.0.16p0 9.0.0.p0 is known to NOT support any mesh */
824 /* 5.110.22 have mesh command with 0xa3 command id */
825 /* 10.0.0.p0 FW brings in mesh config command with different id */
826 /* Check FW version MSB and initialize mesh_fw_ver */
827 if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V5) {
828 /* Enable mesh, if supported, and work out which TLV it uses.
829 0x100 + 291 is an unofficial value used in 5.110.20.pXX
830 0x100 + 37 is the official value used in 5.110.21.pXX
831 but we check them in that order because 20.pXX doesn't
832 give an error -- it just silently fails. */
834 /* 5.110.20.pXX firmware will fail the command if the channel
835 doesn't match the existing channel. But only if the TLV
836 is correct. If the channel is wrong, _BOTH_ versions will
837 give an error to 0x100+291, and allow 0x100+37 to succeed.
838 It's just that 5.110.20.pXX will not have done anything
841 priv->mesh_tlv = TLV_TYPE_OLD_MESH_ID;
842 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, 1)) {
843 priv->mesh_tlv = TLV_TYPE_MESH_ID;
844 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, 1))
848 if ((MRVL_FW_MAJOR_REV(priv->fwrelease) >= MRVL_FW_V10) &&
849 (priv->fwcapinfo & MESH_CAPINFO_ENABLE_MASK)) {
850 /* 10.0.0.pXX new firmwares should succeed with TLV
851 * 0x100+37; Do not invoke command with old TLV.
853 priv->mesh_tlv = TLV_TYPE_MESH_ID;
854 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, 1))
858 /* Stop meshing until interface is brought up */
859 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_STOP, 1);
862 void lbs_start_mesh(struct lbs_private *priv)
866 if (device_create_file(&priv->dev->dev, &dev_attr_lbs_mesh))
867 netdev_err(priv->dev, "cannot register lbs_mesh attribute\n");
870 int lbs_deinit_mesh(struct lbs_private *priv)
872 struct net_device *dev = priv->dev;
875 if (priv->mesh_tlv) {
876 device_remove_file(&dev->dev, &dev_attr_lbs_mesh);
885 * lbs_mesh_stop - close the mshX interface
887 * @dev: A pointer to &net_device structure
890 static int lbs_mesh_stop(struct net_device *dev)
892 struct lbs_private *priv = dev->ml_priv;
894 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_STOP,
895 lbs_mesh_get_channel(priv));
897 spin_lock_irq(&priv->driver_lock);
899 netif_stop_queue(dev);
900 netif_carrier_off(dev);
902 spin_unlock_irq(&priv->driver_lock);
904 lbs_update_mcast(priv);
905 if (!lbs_iface_active(priv))
906 lbs_stop_iface(priv);
912 * lbs_mesh_dev_open - open the mshX interface
914 * @dev: A pointer to &net_device structure
915 * returns: 0 or -EBUSY if monitor mode active
917 static int lbs_mesh_dev_open(struct net_device *dev)
919 struct lbs_private *priv = dev->ml_priv;
922 if (!priv->iface_running) {
923 ret = lbs_start_iface(priv);
928 spin_lock_irq(&priv->driver_lock);
930 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR) {
932 spin_unlock_irq(&priv->driver_lock);
936 netif_carrier_on(dev);
938 if (!priv->tx_pending_len)
939 netif_wake_queue(dev);
941 spin_unlock_irq(&priv->driver_lock);
943 ret = lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
944 lbs_mesh_get_channel(priv));
950 static const struct net_device_ops mesh_netdev_ops = {
951 .ndo_open = lbs_mesh_dev_open,
952 .ndo_stop = lbs_mesh_stop,
953 .ndo_start_xmit = lbs_hard_start_xmit,
954 .ndo_set_mac_address = lbs_set_mac_address,
955 .ndo_set_rx_mode = lbs_set_multicast_list,
959 * lbs_add_mesh - add mshX interface
961 * @priv: A pointer to the &struct lbs_private structure
962 * returns: 0 if successful, -X otherwise
964 static int lbs_add_mesh(struct lbs_private *priv)
966 struct net_device *mesh_dev = NULL;
967 struct wireless_dev *mesh_wdev;
970 /* Allocate a virtual mesh device */
971 mesh_wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
973 lbs_deb_mesh("init mshX wireless device failed\n");
978 mesh_dev = alloc_netdev(0, "msh%d", NET_NAME_UNKNOWN, ether_setup);
980 lbs_deb_mesh("init mshX device failed\n");
985 mesh_wdev->iftype = NL80211_IFTYPE_MESH_POINT;
986 mesh_wdev->wiphy = priv->wdev->wiphy;
988 if (priv->mesh_tlv) {
989 sprintf(mesh_wdev->ssid, "mesh");
990 mesh_wdev->mesh_id_up_len = 4;
993 mesh_wdev->netdev = mesh_dev;
995 mesh_dev->ml_priv = priv;
996 mesh_dev->ieee80211_ptr = mesh_wdev;
997 priv->mesh_dev = mesh_dev;
999 mesh_dev->netdev_ops = &mesh_netdev_ops;
1000 mesh_dev->ethtool_ops = &lbs_ethtool_ops;
1001 eth_hw_addr_inherit(mesh_dev, priv->dev);
1003 SET_NETDEV_DEV(priv->mesh_dev, priv->dev->dev.parent);
1005 mesh_dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
1006 mesh_dev->sysfs_groups[0] = &lbs_mesh_attr_group;
1007 mesh_dev->sysfs_groups[1] = &boot_opts_group;
1008 mesh_dev->sysfs_groups[2] = &mesh_ie_group;
1010 /* Register virtual mesh interface */
1011 ret = register_netdev(mesh_dev);
1013 pr_err("cannot register mshX virtual interface\n");
1014 goto err_free_netdev;
1017 /* Everything successful */
1022 free_netdev(mesh_dev);
1031 void lbs_remove_mesh(struct lbs_private *priv)
1033 struct net_device *mesh_dev;
1035 mesh_dev = priv->mesh_dev;
1039 netif_stop_queue(mesh_dev);
1040 netif_carrier_off(mesh_dev);
1041 unregister_netdev(mesh_dev);
1042 priv->mesh_dev = NULL;
1043 kfree(mesh_dev->ieee80211_ptr);
1044 free_netdev(mesh_dev);
1048 /***************************************************************************
1049 * Sending and receiving
1051 struct net_device *lbs_mesh_set_dev(struct lbs_private *priv,
1052 struct net_device *dev, struct rxpd *rxpd)
1054 if (priv->mesh_dev) {
1055 if (priv->mesh_tlv == TLV_TYPE_OLD_MESH_ID) {
1056 if (rxpd->rx_control & RxPD_MESH_FRAME)
1057 dev = priv->mesh_dev;
1058 } else if (priv->mesh_tlv == TLV_TYPE_MESH_ID) {
1059 if (rxpd->u.bss.bss_num == MESH_IFACE_ID)
1060 dev = priv->mesh_dev;
1067 void lbs_mesh_set_txpd(struct lbs_private *priv,
1068 struct net_device *dev, struct txpd *txpd)
1070 if (dev == priv->mesh_dev) {
1071 if (priv->mesh_tlv == TLV_TYPE_OLD_MESH_ID)
1072 txpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
1073 else if (priv->mesh_tlv == TLV_TYPE_MESH_ID)
1074 txpd->u.bss.bss_num = MESH_IFACE_ID;
1079 /***************************************************************************
1083 static const char mesh_stat_strings[MESH_STATS_NUM][ETH_GSTRING_LEN] = {
1084 "drop_duplicate_bcast",
1086 "drop_no_fwd_route",
1088 "fwded_unicast_cnt",
1094 void lbs_mesh_ethtool_get_stats(struct net_device *dev,
1095 struct ethtool_stats *stats, uint64_t *data)
1097 struct lbs_private *priv = dev->ml_priv;
1098 struct cmd_ds_mesh_access mesh_access;
1101 /* Get Mesh Statistics */
1102 ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_STATS, &mesh_access);
1105 memset(data, 0, MESH_STATS_NUM*(sizeof(uint64_t)));
1109 priv->mstats.fwd_drop_rbt = le32_to_cpu(mesh_access.data[0]);
1110 priv->mstats.fwd_drop_ttl = le32_to_cpu(mesh_access.data[1]);
1111 priv->mstats.fwd_drop_noroute = le32_to_cpu(mesh_access.data[2]);
1112 priv->mstats.fwd_drop_nobuf = le32_to_cpu(mesh_access.data[3]);
1113 priv->mstats.fwd_unicast_cnt = le32_to_cpu(mesh_access.data[4]);
1114 priv->mstats.fwd_bcast_cnt = le32_to_cpu(mesh_access.data[5]);
1115 priv->mstats.drop_blind = le32_to_cpu(mesh_access.data[6]);
1116 priv->mstats.tx_failed_cnt = le32_to_cpu(mesh_access.data[7]);
1118 data[0] = priv->mstats.fwd_drop_rbt;
1119 data[1] = priv->mstats.fwd_drop_ttl;
1120 data[2] = priv->mstats.fwd_drop_noroute;
1121 data[3] = priv->mstats.fwd_drop_nobuf;
1122 data[4] = priv->mstats.fwd_unicast_cnt;
1123 data[5] = priv->mstats.fwd_bcast_cnt;
1124 data[6] = priv->mstats.drop_blind;
1125 data[7] = priv->mstats.tx_failed_cnt;
1128 int lbs_mesh_ethtool_get_sset_count(struct net_device *dev, int sset)
1130 struct lbs_private *priv = dev->ml_priv;
1132 if (sset == ETH_SS_STATS && dev == priv->mesh_dev)
1133 return MESH_STATS_NUM;
1138 void lbs_mesh_ethtool_get_strings(struct net_device *dev,
1139 uint32_t stringset, uint8_t *s)
1141 switch (stringset) {
1143 memcpy(s, mesh_stat_strings, sizeof(mesh_stat_strings));