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
->u
.mesh
.id_up_len
;
113 memcpy(ie
->val
.mesh_id
, mesh_wdev
->u
.mesh
.id
,
114 mesh_wdev
->u
.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 ret
= kstrtouint(buf
, 16, &datum
);
195 memset(&mesh_access
, 0, sizeof(mesh_access
));
196 mesh_access
.data
[0] = cpu_to_le32(datum
);
198 ret
= lbs_mesh_access(priv
, CMD_ACT_MESH_SET_ANYCAST
, &mesh_access
);
206 * prb_rsp_limit_show - Get function for sysfs attribute prb_rsp_limit
207 * @dev: the &struct device
208 * @attr: device attributes
209 * @buf: buffer where data will be returned
211 static ssize_t
prb_rsp_limit_show(struct device
*dev
,
212 struct device_attribute
*attr
, char *buf
)
214 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
215 struct cmd_ds_mesh_access mesh_access
;
219 memset(&mesh_access
, 0, sizeof(mesh_access
));
220 mesh_access
.data
[0] = cpu_to_le32(CMD_ACT_GET
);
222 ret
= lbs_mesh_access(priv
, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT
,
227 retry_limit
= le32_to_cpu(mesh_access
.data
[1]);
228 return sysfs_emit(buf
, "%d\n", retry_limit
);
232 * prb_rsp_limit_store - Set function for sysfs attribute prb_rsp_limit
233 * @dev: the &struct device
234 * @attr: device attributes
235 * @buf: buffer that contains new attribute value
236 * @count: size of buffer
238 static ssize_t
prb_rsp_limit_store(struct device
*dev
,
239 struct device_attribute
*attr
,
240 const char *buf
, size_t count
)
242 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
243 struct cmd_ds_mesh_access mesh_access
;
245 unsigned long retry_limit
;
247 ret
= kstrtoul(buf
, 10, &retry_limit
);
250 if (retry_limit
> 15)
253 memset(&mesh_access
, 0, sizeof(mesh_access
));
254 mesh_access
.data
[0] = cpu_to_le32(CMD_ACT_SET
);
255 mesh_access
.data
[1] = cpu_to_le32(retry_limit
);
257 ret
= lbs_mesh_access(priv
, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT
,
266 * lbs_mesh_show - Get function for sysfs attribute mesh
267 * @dev: the &struct device
268 * @attr: device attributes
269 * @buf: buffer where data will be returned
271 static ssize_t
lbs_mesh_show(struct device
*dev
,
272 struct device_attribute
*attr
, char *buf
)
274 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
275 return sysfs_emit(buf
, "0x%X\n", !!priv
->mesh_dev
);
279 * lbs_mesh_store - Set function for sysfs attribute mesh
280 * @dev: the &struct device
281 * @attr: device attributes
282 * @buf: buffer that contains new attribute value
283 * @count: size of buffer
285 static ssize_t
lbs_mesh_store(struct device
*dev
,
286 struct device_attribute
*attr
,
287 const char *buf
, size_t count
)
289 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
292 ret
= kstrtoint(buf
, 16, &enable
);
297 if (enable
== !!priv
->mesh_dev
)
303 lbs_remove_mesh(priv
);
309 * lbs_mesh attribute to be exported per ethX interface
310 * through sysfs (/sys/class/net/ethX/lbs_mesh)
312 static DEVICE_ATTR_RW(lbs_mesh
);
315 * anycast_mask attribute to be exported per mshX interface
316 * through sysfs (/sys/class/net/mshX/anycast_mask)
318 static DEVICE_ATTR_RW(anycast_mask
);
321 * prb_rsp_limit attribute to be exported per mshX interface
322 * through sysfs (/sys/class/net/mshX/prb_rsp_limit)
324 static DEVICE_ATTR_RW(prb_rsp_limit
);
326 static struct attribute
*lbs_mesh_sysfs_entries
[] = {
327 &dev_attr_anycast_mask
.attr
,
328 &dev_attr_prb_rsp_limit
.attr
,
332 static const struct attribute_group lbs_mesh_attr_group
= {
333 .attrs
= lbs_mesh_sysfs_entries
,
337 /***************************************************************************
338 * Persistent configuration support
341 static int mesh_get_default_parameters(struct device
*dev
,
342 struct mrvl_mesh_defaults
*defs
)
344 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
345 struct cmd_ds_mesh_config cmd
;
348 memset(&cmd
, 0, sizeof(struct cmd_ds_mesh_config
));
349 ret
= lbs_mesh_config_send(priv
, &cmd
, CMD_ACT_MESH_CONFIG_GET
,
350 CMD_TYPE_MESH_GET_DEFAULTS
);
355 memcpy(defs
, &cmd
.data
[0], sizeof(struct mrvl_mesh_defaults
));
361 * bootflag_show - Get function for sysfs attribute bootflag
362 * @dev: the &struct device
363 * @attr: device attributes
364 * @buf: buffer where data will be returned
366 static ssize_t
bootflag_show(struct device
*dev
,
367 struct device_attribute
*attr
, char *buf
)
369 struct mrvl_mesh_defaults defs
;
372 ret
= mesh_get_default_parameters(dev
, &defs
);
377 return sysfs_emit(buf
, "%d\n", le32_to_cpu(defs
.bootflag
));
381 * bootflag_store - Set function for sysfs attribute bootflag
382 * @dev: the &struct device
383 * @attr: device attributes
384 * @buf: buffer that contains new attribute value
385 * @count: size of buffer
387 static ssize_t
bootflag_store(struct device
*dev
, struct device_attribute
*attr
,
388 const char *buf
, size_t count
)
390 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
391 struct cmd_ds_mesh_config cmd
;
395 ret
= kstrtouint(buf
, 10, &datum
);
401 memset(&cmd
, 0, sizeof(cmd
));
402 *((__le32
*)&cmd
.data
[0]) = cpu_to_le32(!!datum
);
403 cmd
.length
= cpu_to_le16(sizeof(uint32_t));
404 ret
= lbs_mesh_config_send(priv
, &cmd
, CMD_ACT_MESH_CONFIG_SET
,
405 CMD_TYPE_MESH_SET_BOOTFLAG
);
413 * boottime_show - Get function for sysfs attribute boottime
414 * @dev: the &struct device
415 * @attr: device attributes
416 * @buf: buffer where data will be returned
418 static ssize_t
boottime_show(struct device
*dev
,
419 struct device_attribute
*attr
, char *buf
)
421 struct mrvl_mesh_defaults defs
;
424 ret
= mesh_get_default_parameters(dev
, &defs
);
429 return sysfs_emit(buf
, "%d\n", defs
.boottime
);
433 * boottime_store - Set function for sysfs attribute boottime
434 * @dev: the &struct device
435 * @attr: device attributes
436 * @buf: buffer that contains new attribute value
437 * @count: size of buffer
439 static ssize_t
boottime_store(struct device
*dev
,
440 struct device_attribute
*attr
,
441 const char *buf
, size_t count
)
443 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
444 struct cmd_ds_mesh_config cmd
;
448 ret
= kstrtouint(buf
, 10, &datum
);
454 memset(&cmd
, 0, sizeof(cmd
));
456 /* A too small boot time will result in the device booting into
457 * standalone (no-host) mode before the host can take control of it,
458 * so the change will be hard to revert. This may be a desired
459 * feature (e.g to configure a very fast boot time for devices that
460 * will not be attached to a host), but dangerous. So I'm enforcing a
461 * lower limit of 20 seconds: remove and recompile the driver if this
462 * does not work for you.
464 datum
= (datum
< 20) ? 20 : datum
;
466 cmd
.length
= cpu_to_le16(sizeof(uint8_t));
467 ret
= lbs_mesh_config_send(priv
, &cmd
, CMD_ACT_MESH_CONFIG_SET
,
468 CMD_TYPE_MESH_SET_BOOTTIME
);
476 * channel_show - Get function for sysfs attribute channel
477 * @dev: the &struct device
478 * @attr: device attributes
479 * @buf: buffer where data will be returned
481 static ssize_t
channel_show(struct device
*dev
,
482 struct device_attribute
*attr
, char *buf
)
484 struct mrvl_mesh_defaults defs
;
487 ret
= mesh_get_default_parameters(dev
, &defs
);
492 return sysfs_emit(buf
, "%d\n", le16_to_cpu(defs
.channel
));
496 * channel_store - Set function for sysfs attribute channel
497 * @dev: the &struct device
498 * @attr: device attributes
499 * @buf: buffer that contains new attribute value
500 * @count: size of buffer
502 static ssize_t
channel_store(struct device
*dev
, struct device_attribute
*attr
,
503 const char *buf
, size_t count
)
505 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
506 struct cmd_ds_mesh_config cmd
;
510 ret
= kstrtouint(buf
, 10, &datum
);
513 if (datum
< 1 || datum
> 11)
516 memset(&cmd
, 0, sizeof(cmd
));
517 *((__le16
*)&cmd
.data
[0]) = cpu_to_le16(datum
);
518 cmd
.length
= cpu_to_le16(sizeof(uint16_t));
519 ret
= lbs_mesh_config_send(priv
, &cmd
, CMD_ACT_MESH_CONFIG_SET
,
520 CMD_TYPE_MESH_SET_DEF_CHANNEL
);
528 * mesh_id_show - Get function for sysfs attribute mesh_id
529 * @dev: the &struct device
530 * @attr: device attributes
531 * @buf: buffer where data will be returned
533 static ssize_t
mesh_id_show(struct device
*dev
, struct device_attribute
*attr
,
536 struct mrvl_mesh_defaults defs
;
539 ret
= mesh_get_default_parameters(dev
, &defs
);
544 if (defs
.meshie
.val
.mesh_id_len
> IEEE80211_MAX_SSID_LEN
) {
545 dev_err(dev
, "inconsistent mesh ID length\n");
546 defs
.meshie
.val
.mesh_id_len
= IEEE80211_MAX_SSID_LEN
;
549 memcpy(buf
, defs
.meshie
.val
.mesh_id
, defs
.meshie
.val
.mesh_id_len
);
550 buf
[defs
.meshie
.val
.mesh_id_len
] = '\n';
551 buf
[defs
.meshie
.val
.mesh_id_len
+ 1] = '\0';
553 return defs
.meshie
.val
.mesh_id_len
+ 1;
557 * mesh_id_store - Set function for sysfs attribute mesh_id
558 * @dev: the &struct device
559 * @attr: device attributes
560 * @buf: buffer that contains new attribute value
561 * @count: size of buffer
563 static ssize_t
mesh_id_store(struct device
*dev
, struct device_attribute
*attr
,
564 const char *buf
, size_t count
)
566 struct cmd_ds_mesh_config cmd
;
567 struct mrvl_mesh_defaults defs
;
568 struct mrvl_meshie
*ie
;
569 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
573 if (count
< 2 || count
> IEEE80211_MAX_SSID_LEN
+ 1)
576 memset(&cmd
, 0, sizeof(struct cmd_ds_mesh_config
));
577 ie
= (struct mrvl_meshie
*) &cmd
.data
[0];
579 /* fetch all other Information Element parameters */
580 ret
= mesh_get_default_parameters(dev
, &defs
);
582 cmd
.length
= cpu_to_le16(sizeof(struct mrvl_meshie
));
584 /* transfer IE elements */
585 memcpy(ie
, &defs
.meshie
, sizeof(struct mrvl_meshie
));
588 memcpy(ie
->val
.mesh_id
, buf
, len
);
590 ie
->val
.mesh_id_len
= len
;
592 ie
->len
= sizeof(struct mrvl_meshie_val
) - IEEE80211_MAX_SSID_LEN
+ len
;
594 ret
= lbs_mesh_config_send(priv
, &cmd
, CMD_ACT_MESH_CONFIG_SET
,
595 CMD_TYPE_MESH_SET_MESH_IE
);
603 * protocol_id_show - Get function for sysfs attribute protocol_id
604 * @dev: the &struct device
605 * @attr: device attributes
606 * @buf: buffer where data will be returned
608 static ssize_t
protocol_id_show(struct device
*dev
,
609 struct device_attribute
*attr
,
612 struct mrvl_mesh_defaults defs
;
615 ret
= mesh_get_default_parameters(dev
, &defs
);
620 return sysfs_emit(buf
, "%d\n", defs
.meshie
.val
.active_protocol_id
);
624 * protocol_id_store - Set function for sysfs attribute protocol_id
625 * @dev: the &struct device
626 * @attr: device attributes
627 * @buf: buffer that contains new attribute value
628 * @count: size of buffer
630 static ssize_t
protocol_id_store(struct device
*dev
,
631 struct device_attribute
*attr
,
632 const char *buf
, size_t count
)
634 struct cmd_ds_mesh_config cmd
;
635 struct mrvl_mesh_defaults defs
;
636 struct mrvl_meshie
*ie
;
637 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
641 ret
= kstrtouint(buf
, 10, &datum
);
647 memset(&cmd
, 0, sizeof(cmd
));
649 /* fetch all other Information Element parameters */
650 ret
= mesh_get_default_parameters(dev
, &defs
);
652 cmd
.length
= cpu_to_le16(sizeof(struct mrvl_meshie
));
654 /* transfer IE elements */
655 ie
= (struct mrvl_meshie
*) &cmd
.data
[0];
656 memcpy(ie
, &defs
.meshie
, sizeof(struct mrvl_meshie
));
657 /* update protocol id */
658 ie
->val
.active_protocol_id
= datum
;
660 ret
= lbs_mesh_config_send(priv
, &cmd
, CMD_ACT_MESH_CONFIG_SET
,
661 CMD_TYPE_MESH_SET_MESH_IE
);
669 * metric_id_show - Get function for sysfs attribute metric_id
670 * @dev: the &struct device
671 * @attr: device attributes
672 * @buf: buffer where data will be returned
674 static ssize_t
metric_id_show(struct device
*dev
,
675 struct device_attribute
*attr
, char *buf
)
677 struct mrvl_mesh_defaults defs
;
680 ret
= mesh_get_default_parameters(dev
, &defs
);
685 return sysfs_emit(buf
, "%d\n", defs
.meshie
.val
.active_metric_id
);
689 * metric_id_store - Set function for sysfs attribute metric_id
690 * @dev: the &struct device
691 * @attr: device attributes
692 * @buf: buffer that contains new attribute value
693 * @count: size of buffer
695 static ssize_t
metric_id_store(struct device
*dev
,
696 struct device_attribute
*attr
,
697 const char *buf
, size_t count
)
699 struct cmd_ds_mesh_config cmd
;
700 struct mrvl_mesh_defaults defs
;
701 struct mrvl_meshie
*ie
;
702 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
706 memset(&cmd
, 0, sizeof(cmd
));
707 ret
= sscanf(buf
, "%d", &datum
);
708 if ((ret
!= 1) || (datum
> 255))
711 /* fetch all other Information Element parameters */
712 ret
= mesh_get_default_parameters(dev
, &defs
);
714 cmd
.length
= cpu_to_le16(sizeof(struct mrvl_meshie
));
716 /* transfer IE elements */
717 ie
= (struct mrvl_meshie
*) &cmd
.data
[0];
718 memcpy(ie
, &defs
.meshie
, sizeof(struct mrvl_meshie
));
719 /* update metric id */
720 ie
->val
.active_metric_id
= datum
;
722 ret
= lbs_mesh_config_send(priv
, &cmd
, CMD_ACT_MESH_CONFIG_SET
,
723 CMD_TYPE_MESH_SET_MESH_IE
);
731 * capability_show - Get function for sysfs attribute capability
732 * @dev: the &struct device
733 * @attr: device attributes
734 * @buf: buffer where data will be returned
736 static ssize_t
capability_show(struct device
*dev
,
737 struct device_attribute
*attr
, char *buf
)
739 struct mrvl_mesh_defaults defs
;
742 ret
= mesh_get_default_parameters(dev
, &defs
);
747 return sysfs_emit(buf
, "%d\n", defs
.meshie
.val
.mesh_capability
);
751 * capability_store - Set function for sysfs attribute capability
752 * @dev: the &struct device
753 * @attr: device attributes
754 * @buf: buffer that contains new attribute value
755 * @count: size of buffer
757 static ssize_t
capability_store(struct device
*dev
,
758 struct device_attribute
*attr
,
759 const char *buf
, size_t count
)
761 struct cmd_ds_mesh_config cmd
;
762 struct mrvl_mesh_defaults defs
;
763 struct mrvl_meshie
*ie
;
764 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
768 memset(&cmd
, 0, sizeof(cmd
));
769 ret
= sscanf(buf
, "%d", &datum
);
770 if ((ret
!= 1) || (datum
> 255))
773 /* fetch all other Information Element parameters */
774 ret
= mesh_get_default_parameters(dev
, &defs
);
776 cmd
.length
= cpu_to_le16(sizeof(struct mrvl_meshie
));
778 /* transfer IE elements */
779 ie
= (struct mrvl_meshie
*) &cmd
.data
[0];
780 memcpy(ie
, &defs
.meshie
, sizeof(struct mrvl_meshie
));
782 ie
->val
.mesh_capability
= datum
;
784 ret
= lbs_mesh_config_send(priv
, &cmd
, CMD_ACT_MESH_CONFIG_SET
,
785 CMD_TYPE_MESH_SET_MESH_IE
);
793 static DEVICE_ATTR_RW(bootflag
);
794 static DEVICE_ATTR_RW(boottime
);
795 static DEVICE_ATTR_RW(channel
);
796 static DEVICE_ATTR_RW(mesh_id
);
797 static DEVICE_ATTR_RW(protocol_id
);
798 static DEVICE_ATTR_RW(metric_id
);
799 static DEVICE_ATTR_RW(capability
);
801 static struct attribute
*boot_opts_attrs
[] = {
802 &dev_attr_bootflag
.attr
,
803 &dev_attr_boottime
.attr
,
804 &dev_attr_channel
.attr
,
808 static const struct attribute_group boot_opts_group
= {
809 .name
= "boot_options",
810 .attrs
= boot_opts_attrs
,
813 static struct attribute
*mesh_ie_attrs
[] = {
814 &dev_attr_mesh_id
.attr
,
815 &dev_attr_protocol_id
.attr
,
816 &dev_attr_metric_id
.attr
,
817 &dev_attr_capability
.attr
,
821 static const struct attribute_group mesh_ie_group
= {
823 .attrs
= mesh_ie_attrs
,
827 /***************************************************************************
828 * Initializing and starting, stopping mesh
832 * Check mesh FW version and appropriately send the mesh start
835 void lbs_init_mesh(struct lbs_private
*priv
)
837 /* Determine mesh_fw_ver from fwrelease and fwcapinfo */
838 /* 5.0.16p0 9.0.0.p0 is known to NOT support any mesh */
839 /* 5.110.22 have mesh command with 0xa3 command id */
840 /* 10.0.0.p0 FW brings in mesh config command with different id */
841 /* Check FW version MSB and initialize mesh_fw_ver */
842 if (MRVL_FW_MAJOR_REV(priv
->fwrelease
) == MRVL_FW_V5
) {
843 /* Enable mesh, if supported, and work out which TLV it uses.
844 0x100 + 291 is an unofficial value used in 5.110.20.pXX
845 0x100 + 37 is the official value used in 5.110.21.pXX
846 but we check them in that order because 20.pXX doesn't
847 give an error -- it just silently fails. */
849 /* 5.110.20.pXX firmware will fail the command if the channel
850 doesn't match the existing channel. But only if the TLV
851 is correct. If the channel is wrong, _BOTH_ versions will
852 give an error to 0x100+291, and allow 0x100+37 to succeed.
853 It's just that 5.110.20.pXX will not have done anything
856 priv
->mesh_tlv
= TLV_TYPE_OLD_MESH_ID
;
857 if (lbs_mesh_config(priv
, CMD_ACT_MESH_CONFIG_START
, 1)) {
858 priv
->mesh_tlv
= TLV_TYPE_MESH_ID
;
859 if (lbs_mesh_config(priv
, CMD_ACT_MESH_CONFIG_START
, 1))
863 if ((MRVL_FW_MAJOR_REV(priv
->fwrelease
) >= MRVL_FW_V10
) &&
864 (priv
->fwcapinfo
& MESH_CAPINFO_ENABLE_MASK
)) {
865 /* 10.0.0.pXX new firmwares should succeed with TLV
866 * 0x100+37; Do not invoke command with old TLV.
868 priv
->mesh_tlv
= TLV_TYPE_MESH_ID
;
869 if (lbs_mesh_config(priv
, CMD_ACT_MESH_CONFIG_START
, 1))
873 /* Stop meshing until interface is brought up */
874 lbs_mesh_config(priv
, CMD_ACT_MESH_CONFIG_STOP
, 1);
877 void lbs_start_mesh(struct lbs_private
*priv
)
881 if (device_create_file(&priv
->dev
->dev
, &dev_attr_lbs_mesh
))
882 netdev_err(priv
->dev
, "cannot register lbs_mesh attribute\n");
885 int lbs_deinit_mesh(struct lbs_private
*priv
)
887 struct net_device
*dev
= priv
->dev
;
890 if (priv
->mesh_tlv
) {
891 device_remove_file(&dev
->dev
, &dev_attr_lbs_mesh
);
900 * lbs_mesh_stop - close the mshX interface
902 * @dev: A pointer to &net_device structure
905 static int lbs_mesh_stop(struct net_device
*dev
)
907 struct lbs_private
*priv
= dev
->ml_priv
;
909 lbs_mesh_config(priv
, CMD_ACT_MESH_CONFIG_STOP
,
910 lbs_mesh_get_channel(priv
));
912 spin_lock_irq(&priv
->driver_lock
);
914 netif_stop_queue(dev
);
915 netif_carrier_off(dev
);
917 spin_unlock_irq(&priv
->driver_lock
);
919 lbs_update_mcast(priv
);
920 if (!lbs_iface_active(priv
))
921 lbs_stop_iface(priv
);
927 * lbs_mesh_dev_open - open the mshX interface
929 * @dev: A pointer to &net_device structure
930 * returns: 0 or -EBUSY if monitor mode active
932 static int lbs_mesh_dev_open(struct net_device
*dev
)
934 struct lbs_private
*priv
= dev
->ml_priv
;
937 if (!priv
->iface_running
) {
938 ret
= lbs_start_iface(priv
);
943 spin_lock_irq(&priv
->driver_lock
);
945 if (priv
->wdev
->iftype
== NL80211_IFTYPE_MONITOR
) {
947 spin_unlock_irq(&priv
->driver_lock
);
951 netif_carrier_on(dev
);
953 if (!priv
->tx_pending_len
)
954 netif_wake_queue(dev
);
956 spin_unlock_irq(&priv
->driver_lock
);
958 ret
= lbs_mesh_config(priv
, CMD_ACT_MESH_CONFIG_START
,
959 lbs_mesh_get_channel(priv
));
965 static const struct net_device_ops mesh_netdev_ops
= {
966 .ndo_open
= lbs_mesh_dev_open
,
967 .ndo_stop
= lbs_mesh_stop
,
968 .ndo_start_xmit
= lbs_hard_start_xmit
,
969 .ndo_set_mac_address
= lbs_set_mac_address
,
970 .ndo_set_rx_mode
= lbs_set_multicast_list
,
974 * lbs_add_mesh - add mshX interface
976 * @priv: A pointer to the &struct lbs_private structure
977 * returns: 0 if successful, -X otherwise
979 static int lbs_add_mesh(struct lbs_private
*priv
)
981 struct net_device
*mesh_dev
= NULL
;
982 struct wireless_dev
*mesh_wdev
;
985 /* Allocate a virtual mesh device */
986 mesh_wdev
= kzalloc(sizeof(struct wireless_dev
), GFP_KERNEL
);
988 lbs_deb_mesh("init mshX wireless device failed\n");
993 mesh_dev
= alloc_netdev(0, "msh%d", NET_NAME_UNKNOWN
, ether_setup
);
995 lbs_deb_mesh("init mshX device failed\n");
1000 mesh_wdev
->iftype
= NL80211_IFTYPE_MESH_POINT
;
1001 mesh_wdev
->wiphy
= priv
->wdev
->wiphy
;
1003 if (priv
->mesh_tlv
) {
1004 sprintf(mesh_wdev
->u
.mesh
.id
, "mesh");
1005 mesh_wdev
->u
.mesh
.id_up_len
= 4;
1008 mesh_wdev
->netdev
= mesh_dev
;
1010 mesh_dev
->ml_priv
= priv
;
1011 mesh_dev
->ieee80211_ptr
= mesh_wdev
;
1012 priv
->mesh_dev
= mesh_dev
;
1014 mesh_dev
->netdev_ops
= &mesh_netdev_ops
;
1015 mesh_dev
->ethtool_ops
= &lbs_ethtool_ops
;
1016 eth_hw_addr_inherit(mesh_dev
, priv
->dev
);
1018 SET_NETDEV_DEV(priv
->mesh_dev
, priv
->dev
->dev
.parent
);
1020 mesh_dev
->flags
|= IFF_BROADCAST
| IFF_MULTICAST
;
1021 mesh_dev
->sysfs_groups
[0] = &lbs_mesh_attr_group
;
1022 mesh_dev
->sysfs_groups
[1] = &boot_opts_group
;
1023 mesh_dev
->sysfs_groups
[2] = &mesh_ie_group
;
1025 /* Register virtual mesh interface */
1026 ret
= register_netdev(mesh_dev
);
1028 pr_err("cannot register mshX virtual interface\n");
1029 goto err_free_netdev
;
1032 /* Everything successful */
1037 free_netdev(mesh_dev
);
1046 void lbs_remove_mesh(struct lbs_private
*priv
)
1048 struct net_device
*mesh_dev
;
1050 mesh_dev
= priv
->mesh_dev
;
1054 netif_stop_queue(mesh_dev
);
1055 netif_carrier_off(mesh_dev
);
1056 unregister_netdev(mesh_dev
);
1057 priv
->mesh_dev
= NULL
;
1058 kfree(mesh_dev
->ieee80211_ptr
);
1059 free_netdev(mesh_dev
);
1063 /***************************************************************************
1064 * Sending and receiving
1066 struct net_device
*lbs_mesh_set_dev(struct lbs_private
*priv
,
1067 struct net_device
*dev
, struct rxpd
*rxpd
)
1069 if (priv
->mesh_dev
) {
1070 if (priv
->mesh_tlv
== TLV_TYPE_OLD_MESH_ID
) {
1071 if (rxpd
->rx_control
& RxPD_MESH_FRAME
)
1072 dev
= priv
->mesh_dev
;
1073 } else if (priv
->mesh_tlv
== TLV_TYPE_MESH_ID
) {
1074 if (rxpd
->u
.bss
.bss_num
== MESH_IFACE_ID
)
1075 dev
= priv
->mesh_dev
;
1082 void lbs_mesh_set_txpd(struct lbs_private
*priv
,
1083 struct net_device
*dev
, struct txpd
*txpd
)
1085 if (dev
== priv
->mesh_dev
) {
1086 if (priv
->mesh_tlv
== TLV_TYPE_OLD_MESH_ID
)
1087 txpd
->tx_control
|= cpu_to_le32(TxPD_MESH_FRAME
);
1088 else if (priv
->mesh_tlv
== TLV_TYPE_MESH_ID
)
1089 txpd
->u
.bss
.bss_num
= MESH_IFACE_ID
;
1094 /***************************************************************************
1098 static const char mesh_stat_strings
[MESH_STATS_NUM
][ETH_GSTRING_LEN
] = {
1099 "drop_duplicate_bcast",
1101 "drop_no_fwd_route",
1103 "fwded_unicast_cnt",
1109 void lbs_mesh_ethtool_get_stats(struct net_device
*dev
,
1110 struct ethtool_stats
*stats
, uint64_t *data
)
1112 struct lbs_private
*priv
= dev
->ml_priv
;
1113 struct cmd_ds_mesh_access mesh_access
;
1116 /* Get Mesh Statistics */
1117 ret
= lbs_mesh_access(priv
, CMD_ACT_MESH_GET_STATS
, &mesh_access
);
1120 memset(data
, 0, MESH_STATS_NUM
*(sizeof(uint64_t)));
1124 priv
->mstats
.fwd_drop_rbt
= le32_to_cpu(mesh_access
.data
[0]);
1125 priv
->mstats
.fwd_drop_ttl
= le32_to_cpu(mesh_access
.data
[1]);
1126 priv
->mstats
.fwd_drop_noroute
= le32_to_cpu(mesh_access
.data
[2]);
1127 priv
->mstats
.fwd_drop_nobuf
= le32_to_cpu(mesh_access
.data
[3]);
1128 priv
->mstats
.fwd_unicast_cnt
= le32_to_cpu(mesh_access
.data
[4]);
1129 priv
->mstats
.fwd_bcast_cnt
= le32_to_cpu(mesh_access
.data
[5]);
1130 priv
->mstats
.drop_blind
= le32_to_cpu(mesh_access
.data
[6]);
1131 priv
->mstats
.tx_failed_cnt
= le32_to_cpu(mesh_access
.data
[7]);
1133 data
[0] = priv
->mstats
.fwd_drop_rbt
;
1134 data
[1] = priv
->mstats
.fwd_drop_ttl
;
1135 data
[2] = priv
->mstats
.fwd_drop_noroute
;
1136 data
[3] = priv
->mstats
.fwd_drop_nobuf
;
1137 data
[4] = priv
->mstats
.fwd_unicast_cnt
;
1138 data
[5] = priv
->mstats
.fwd_bcast_cnt
;
1139 data
[6] = priv
->mstats
.drop_blind
;
1140 data
[7] = priv
->mstats
.tx_failed_cnt
;
1143 int lbs_mesh_ethtool_get_sset_count(struct net_device
*dev
, int sset
)
1145 struct lbs_private
*priv
= dev
->ml_priv
;
1147 if (sset
== ETH_SS_STATS
&& dev
== priv
->mesh_dev
)
1148 return MESH_STATS_NUM
;
1153 void lbs_mesh_ethtool_get_strings(struct net_device
*dev
,
1154 uint32_t stringset
, uint8_t *s
)
1156 switch (stringset
) {
1158 memcpy(s
, mesh_stat_strings
, sizeof(mesh_stat_strings
));