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 * lbs_anycast_get - 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
lbs_anycast_get(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 snprintf(buf
, 12, "0x%X\n", le32_to_cpu(mesh_access
.data
[0]));
176 * lbs_anycast_set - 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
lbs_anycast_set(struct device
*dev
,
183 struct device_attribute
*attr
, const char * buf
, size_t count
)
185 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
186 struct cmd_ds_mesh_access mesh_access
;
190 memset(&mesh_access
, 0, sizeof(mesh_access
));
191 sscanf(buf
, "%x", &datum
);
192 mesh_access
.data
[0] = cpu_to_le32(datum
);
194 ret
= lbs_mesh_access(priv
, CMD_ACT_MESH_SET_ANYCAST
, &mesh_access
);
202 * lbs_prb_rsp_limit_get - Get function for sysfs attribute prb_rsp_limit
203 * @dev: the &struct device
204 * @attr: device attributes
205 * @buf: buffer where data will be returned
207 static ssize_t
lbs_prb_rsp_limit_get(struct device
*dev
,
208 struct device_attribute
*attr
, char *buf
)
210 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
211 struct cmd_ds_mesh_access mesh_access
;
215 memset(&mesh_access
, 0, sizeof(mesh_access
));
216 mesh_access
.data
[0] = cpu_to_le32(CMD_ACT_GET
);
218 ret
= lbs_mesh_access(priv
, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT
,
223 retry_limit
= le32_to_cpu(mesh_access
.data
[1]);
224 return snprintf(buf
, 10, "%d\n", retry_limit
);
228 * lbs_prb_rsp_limit_set - Set function for sysfs attribute prb_rsp_limit
229 * @dev: the &struct device
230 * @attr: device attributes
231 * @buf: buffer that contains new attribute value
232 * @count: size of buffer
234 static ssize_t
lbs_prb_rsp_limit_set(struct device
*dev
,
235 struct device_attribute
*attr
, const char *buf
, size_t count
)
237 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
238 struct cmd_ds_mesh_access mesh_access
;
240 unsigned long retry_limit
;
242 memset(&mesh_access
, 0, sizeof(mesh_access
));
243 mesh_access
.data
[0] = cpu_to_le32(CMD_ACT_SET
);
245 ret
= kstrtoul(buf
, 10, &retry_limit
);
248 if (retry_limit
> 15)
251 mesh_access
.data
[1] = cpu_to_le32(retry_limit
);
253 ret
= lbs_mesh_access(priv
, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT
,
262 * lbs_mesh_get - Get function for sysfs attribute mesh
263 * @dev: the &struct device
264 * @attr: device attributes
265 * @buf: buffer where data will be returned
267 static ssize_t
lbs_mesh_get(struct device
*dev
,
268 struct device_attribute
*attr
, char * buf
)
270 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
271 return snprintf(buf
, 5, "0x%X\n", !!priv
->mesh_dev
);
275 * lbs_mesh_set - Set function for sysfs attribute mesh
276 * @dev: the &struct device
277 * @attr: device attributes
278 * @buf: buffer that contains new attribute value
279 * @count: size of buffer
281 static ssize_t
lbs_mesh_set(struct device
*dev
,
282 struct device_attribute
*attr
, const char * buf
, size_t count
)
284 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
287 sscanf(buf
, "%x", &enable
);
289 if (enable
== !!priv
->mesh_dev
)
295 lbs_remove_mesh(priv
);
301 * lbs_mesh attribute to be exported per ethX interface
302 * through sysfs (/sys/class/net/ethX/lbs_mesh)
304 static DEVICE_ATTR(lbs_mesh
, 0644, lbs_mesh_get
, lbs_mesh_set
);
307 * anycast_mask attribute to be exported per mshX interface
308 * through sysfs (/sys/class/net/mshX/anycast_mask)
310 static DEVICE_ATTR(anycast_mask
, 0644, lbs_anycast_get
, lbs_anycast_set
);
313 * prb_rsp_limit attribute to be exported per mshX interface
314 * through sysfs (/sys/class/net/mshX/prb_rsp_limit)
316 static DEVICE_ATTR(prb_rsp_limit
, 0644, lbs_prb_rsp_limit_get
,
317 lbs_prb_rsp_limit_set
);
319 static struct attribute
*lbs_mesh_sysfs_entries
[] = {
320 &dev_attr_anycast_mask
.attr
,
321 &dev_attr_prb_rsp_limit
.attr
,
325 static const struct attribute_group lbs_mesh_attr_group
= {
326 .attrs
= lbs_mesh_sysfs_entries
,
330 /***************************************************************************
331 * Persistent configuration support
334 static int mesh_get_default_parameters(struct device
*dev
,
335 struct mrvl_mesh_defaults
*defs
)
337 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
338 struct cmd_ds_mesh_config cmd
;
341 memset(&cmd
, 0, sizeof(struct cmd_ds_mesh_config
));
342 ret
= lbs_mesh_config_send(priv
, &cmd
, CMD_ACT_MESH_CONFIG_GET
,
343 CMD_TYPE_MESH_GET_DEFAULTS
);
348 memcpy(defs
, &cmd
.data
[0], sizeof(struct mrvl_mesh_defaults
));
354 * bootflag_get - Get function for sysfs attribute bootflag
355 * @dev: the &struct device
356 * @attr: device attributes
357 * @buf: buffer where data will be returned
359 static ssize_t
bootflag_get(struct device
*dev
,
360 struct device_attribute
*attr
, char *buf
)
362 struct mrvl_mesh_defaults defs
;
365 ret
= mesh_get_default_parameters(dev
, &defs
);
370 return snprintf(buf
, 12, "%d\n", le32_to_cpu(defs
.bootflag
));
374 * bootflag_set - Set function for sysfs attribute bootflag
375 * @dev: the &struct device
376 * @attr: device attributes
377 * @buf: buffer that contains new attribute value
378 * @count: size of buffer
380 static ssize_t
bootflag_set(struct device
*dev
, struct device_attribute
*attr
,
381 const char *buf
, size_t count
)
383 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
384 struct cmd_ds_mesh_config cmd
;
388 memset(&cmd
, 0, sizeof(cmd
));
389 ret
= sscanf(buf
, "%d", &datum
);
390 if ((ret
!= 1) || (datum
> 1))
393 *((__le32
*)&cmd
.data
[0]) = cpu_to_le32(!!datum
);
394 cmd
.length
= cpu_to_le16(sizeof(uint32_t));
395 ret
= lbs_mesh_config_send(priv
, &cmd
, CMD_ACT_MESH_CONFIG_SET
,
396 CMD_TYPE_MESH_SET_BOOTFLAG
);
404 * boottime_get - Get function for sysfs attribute boottime
405 * @dev: the &struct device
406 * @attr: device attributes
407 * @buf: buffer where data will be returned
409 static ssize_t
boottime_get(struct device
*dev
,
410 struct device_attribute
*attr
, char *buf
)
412 struct mrvl_mesh_defaults defs
;
415 ret
= mesh_get_default_parameters(dev
, &defs
);
420 return snprintf(buf
, 12, "%d\n", defs
.boottime
);
424 * boottime_set - Set function for sysfs attribute boottime
425 * @dev: the &struct device
426 * @attr: device attributes
427 * @buf: buffer that contains new attribute value
428 * @count: size of buffer
430 static ssize_t
boottime_set(struct device
*dev
,
431 struct device_attribute
*attr
, const char *buf
, size_t count
)
433 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
434 struct cmd_ds_mesh_config cmd
;
438 memset(&cmd
, 0, sizeof(cmd
));
439 ret
= sscanf(buf
, "%d", &datum
);
440 if ((ret
!= 1) || (datum
> 255))
443 /* A too small boot time will result in the device booting into
444 * standalone (no-host) mode before the host can take control of it,
445 * so the change will be hard to revert. This may be a desired
446 * feature (e.g to configure a very fast boot time for devices that
447 * will not be attached to a host), but dangerous. So I'm enforcing a
448 * lower limit of 20 seconds: remove and recompile the driver if this
449 * does not work for you.
451 datum
= (datum
< 20) ? 20 : datum
;
453 cmd
.length
= cpu_to_le16(sizeof(uint8_t));
454 ret
= lbs_mesh_config_send(priv
, &cmd
, CMD_ACT_MESH_CONFIG_SET
,
455 CMD_TYPE_MESH_SET_BOOTTIME
);
463 * channel_get - Get function for sysfs attribute channel
464 * @dev: the &struct device
465 * @attr: device attributes
466 * @buf: buffer where data will be returned
468 static ssize_t
channel_get(struct device
*dev
,
469 struct device_attribute
*attr
, char *buf
)
471 struct mrvl_mesh_defaults defs
;
474 ret
= mesh_get_default_parameters(dev
, &defs
);
479 return snprintf(buf
, 12, "%d\n", le16_to_cpu(defs
.channel
));
483 * channel_set - Set function for sysfs attribute channel
484 * @dev: the &struct device
485 * @attr: device attributes
486 * @buf: buffer that contains new attribute value
487 * @count: size of buffer
489 static ssize_t
channel_set(struct device
*dev
, struct device_attribute
*attr
,
490 const char *buf
, size_t count
)
492 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
493 struct cmd_ds_mesh_config cmd
;
497 memset(&cmd
, 0, sizeof(cmd
));
498 ret
= sscanf(buf
, "%d", &datum
);
499 if (ret
!= 1 || datum
< 1 || datum
> 11)
502 *((__le16
*)&cmd
.data
[0]) = cpu_to_le16(datum
);
503 cmd
.length
= cpu_to_le16(sizeof(uint16_t));
504 ret
= lbs_mesh_config_send(priv
, &cmd
, CMD_ACT_MESH_CONFIG_SET
,
505 CMD_TYPE_MESH_SET_DEF_CHANNEL
);
513 * mesh_id_get - Get function for sysfs attribute mesh_id
514 * @dev: the &struct device
515 * @attr: device attributes
516 * @buf: buffer where data will be returned
518 static ssize_t
mesh_id_get(struct device
*dev
, struct device_attribute
*attr
,
521 struct mrvl_mesh_defaults defs
;
524 ret
= mesh_get_default_parameters(dev
, &defs
);
529 if (defs
.meshie
.val
.mesh_id_len
> IEEE80211_MAX_SSID_LEN
) {
530 dev_err(dev
, "inconsistent mesh ID length\n");
531 defs
.meshie
.val
.mesh_id_len
= IEEE80211_MAX_SSID_LEN
;
534 memcpy(buf
, defs
.meshie
.val
.mesh_id
, defs
.meshie
.val
.mesh_id_len
);
535 buf
[defs
.meshie
.val
.mesh_id_len
] = '\n';
536 buf
[defs
.meshie
.val
.mesh_id_len
+ 1] = '\0';
538 return defs
.meshie
.val
.mesh_id_len
+ 1;
542 * mesh_id_set - Set function for sysfs attribute mesh_id
543 * @dev: the &struct device
544 * @attr: device attributes
545 * @buf: buffer that contains new attribute value
546 * @count: size of buffer
548 static ssize_t
mesh_id_set(struct device
*dev
, struct device_attribute
*attr
,
549 const char *buf
, size_t count
)
551 struct cmd_ds_mesh_config cmd
;
552 struct mrvl_mesh_defaults defs
;
553 struct mrvl_meshie
*ie
;
554 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
558 if (count
< 2 || count
> IEEE80211_MAX_SSID_LEN
+ 1)
561 memset(&cmd
, 0, sizeof(struct cmd_ds_mesh_config
));
562 ie
= (struct mrvl_meshie
*) &cmd
.data
[0];
564 /* fetch all other Information Element parameters */
565 ret
= mesh_get_default_parameters(dev
, &defs
);
567 cmd
.length
= cpu_to_le16(sizeof(struct mrvl_meshie
));
569 /* transfer IE elements */
570 memcpy(ie
, &defs
.meshie
, sizeof(struct mrvl_meshie
));
573 memcpy(ie
->val
.mesh_id
, buf
, len
);
575 ie
->val
.mesh_id_len
= len
;
577 ie
->len
= sizeof(struct mrvl_meshie_val
) - IEEE80211_MAX_SSID_LEN
+ len
;
579 ret
= lbs_mesh_config_send(priv
, &cmd
, CMD_ACT_MESH_CONFIG_SET
,
580 CMD_TYPE_MESH_SET_MESH_IE
);
588 * protocol_id_get - Get function for sysfs attribute protocol_id
589 * @dev: the &struct device
590 * @attr: device attributes
591 * @buf: buffer where data will be returned
593 static ssize_t
protocol_id_get(struct device
*dev
,
594 struct device_attribute
*attr
, char *buf
)
596 struct mrvl_mesh_defaults defs
;
599 ret
= mesh_get_default_parameters(dev
, &defs
);
604 return snprintf(buf
, 5, "%d\n", defs
.meshie
.val
.active_protocol_id
);
608 * protocol_id_set - Set function for sysfs attribute protocol_id
609 * @dev: the &struct device
610 * @attr: device attributes
611 * @buf: buffer that contains new attribute value
612 * @count: size of buffer
614 static ssize_t
protocol_id_set(struct device
*dev
,
615 struct device_attribute
*attr
, const char *buf
, size_t count
)
617 struct cmd_ds_mesh_config cmd
;
618 struct mrvl_mesh_defaults defs
;
619 struct mrvl_meshie
*ie
;
620 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
624 memset(&cmd
, 0, sizeof(cmd
));
625 ret
= sscanf(buf
, "%d", &datum
);
626 if ((ret
!= 1) || (datum
> 255))
629 /* fetch all other Information Element parameters */
630 ret
= mesh_get_default_parameters(dev
, &defs
);
632 cmd
.length
= cpu_to_le16(sizeof(struct mrvl_meshie
));
634 /* transfer IE elements */
635 ie
= (struct mrvl_meshie
*) &cmd
.data
[0];
636 memcpy(ie
, &defs
.meshie
, sizeof(struct mrvl_meshie
));
637 /* update protocol id */
638 ie
->val
.active_protocol_id
= datum
;
640 ret
= lbs_mesh_config_send(priv
, &cmd
, CMD_ACT_MESH_CONFIG_SET
,
641 CMD_TYPE_MESH_SET_MESH_IE
);
649 * metric_id_get - Get function for sysfs attribute metric_id
650 * @dev: the &struct device
651 * @attr: device attributes
652 * @buf: buffer where data will be returned
654 static ssize_t
metric_id_get(struct device
*dev
,
655 struct device_attribute
*attr
, char *buf
)
657 struct mrvl_mesh_defaults defs
;
660 ret
= mesh_get_default_parameters(dev
, &defs
);
665 return snprintf(buf
, 5, "%d\n", defs
.meshie
.val
.active_metric_id
);
669 * metric_id_set - Set function for sysfs attribute metric_id
670 * @dev: the &struct device
671 * @attr: device attributes
672 * @buf: buffer that contains new attribute value
673 * @count: size of buffer
675 static ssize_t
metric_id_set(struct device
*dev
, struct device_attribute
*attr
,
676 const char *buf
, size_t count
)
678 struct cmd_ds_mesh_config cmd
;
679 struct mrvl_mesh_defaults defs
;
680 struct mrvl_meshie
*ie
;
681 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
685 memset(&cmd
, 0, sizeof(cmd
));
686 ret
= sscanf(buf
, "%d", &datum
);
687 if ((ret
!= 1) || (datum
> 255))
690 /* fetch all other Information Element parameters */
691 ret
= mesh_get_default_parameters(dev
, &defs
);
693 cmd
.length
= cpu_to_le16(sizeof(struct mrvl_meshie
));
695 /* transfer IE elements */
696 ie
= (struct mrvl_meshie
*) &cmd
.data
[0];
697 memcpy(ie
, &defs
.meshie
, sizeof(struct mrvl_meshie
));
698 /* update metric id */
699 ie
->val
.active_metric_id
= datum
;
701 ret
= lbs_mesh_config_send(priv
, &cmd
, CMD_ACT_MESH_CONFIG_SET
,
702 CMD_TYPE_MESH_SET_MESH_IE
);
710 * capability_get - Get function for sysfs attribute capability
711 * @dev: the &struct device
712 * @attr: device attributes
713 * @buf: buffer where data will be returned
715 static ssize_t
capability_get(struct device
*dev
,
716 struct device_attribute
*attr
, char *buf
)
718 struct mrvl_mesh_defaults defs
;
721 ret
= mesh_get_default_parameters(dev
, &defs
);
726 return snprintf(buf
, 5, "%d\n", defs
.meshie
.val
.mesh_capability
);
730 * capability_set - Set function for sysfs attribute capability
731 * @dev: the &struct device
732 * @attr: device attributes
733 * @buf: buffer that contains new attribute value
734 * @count: size of buffer
736 static ssize_t
capability_set(struct device
*dev
, struct device_attribute
*attr
,
737 const char *buf
, size_t count
)
739 struct cmd_ds_mesh_config cmd
;
740 struct mrvl_mesh_defaults defs
;
741 struct mrvl_meshie
*ie
;
742 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
746 memset(&cmd
, 0, sizeof(cmd
));
747 ret
= sscanf(buf
, "%d", &datum
);
748 if ((ret
!= 1) || (datum
> 255))
751 /* fetch all other Information Element parameters */
752 ret
= mesh_get_default_parameters(dev
, &defs
);
754 cmd
.length
= cpu_to_le16(sizeof(struct mrvl_meshie
));
756 /* transfer IE elements */
757 ie
= (struct mrvl_meshie
*) &cmd
.data
[0];
758 memcpy(ie
, &defs
.meshie
, sizeof(struct mrvl_meshie
));
760 ie
->val
.mesh_capability
= datum
;
762 ret
= lbs_mesh_config_send(priv
, &cmd
, CMD_ACT_MESH_CONFIG_SET
,
763 CMD_TYPE_MESH_SET_MESH_IE
);
771 static DEVICE_ATTR(bootflag
, 0644, bootflag_get
, bootflag_set
);
772 static DEVICE_ATTR(boottime
, 0644, boottime_get
, boottime_set
);
773 static DEVICE_ATTR(channel
, 0644, channel_get
, channel_set
);
774 static DEVICE_ATTR(mesh_id
, 0644, mesh_id_get
, mesh_id_set
);
775 static DEVICE_ATTR(protocol_id
, 0644, protocol_id_get
, protocol_id_set
);
776 static DEVICE_ATTR(metric_id
, 0644, metric_id_get
, metric_id_set
);
777 static DEVICE_ATTR(capability
, 0644, capability_get
, capability_set
);
779 static struct attribute
*boot_opts_attrs
[] = {
780 &dev_attr_bootflag
.attr
,
781 &dev_attr_boottime
.attr
,
782 &dev_attr_channel
.attr
,
786 static const struct attribute_group boot_opts_group
= {
787 .name
= "boot_options",
788 .attrs
= boot_opts_attrs
,
791 static struct attribute
*mesh_ie_attrs
[] = {
792 &dev_attr_mesh_id
.attr
,
793 &dev_attr_protocol_id
.attr
,
794 &dev_attr_metric_id
.attr
,
795 &dev_attr_capability
.attr
,
799 static const struct attribute_group mesh_ie_group
= {
801 .attrs
= mesh_ie_attrs
,
804 static void lbs_persist_config_init(struct net_device
*dev
)
807 ret
= sysfs_create_group(&(dev
->dev
.kobj
), &boot_opts_group
);
809 pr_err("failed to create boot_opts_group.\n");
811 ret
= sysfs_create_group(&(dev
->dev
.kobj
), &mesh_ie_group
);
813 pr_err("failed to create mesh_ie_group.\n");
816 static void lbs_persist_config_remove(struct net_device
*dev
)
818 sysfs_remove_group(&(dev
->dev
.kobj
), &boot_opts_group
);
819 sysfs_remove_group(&(dev
->dev
.kobj
), &mesh_ie_group
);
823 /***************************************************************************
824 * Initializing and starting, stopping mesh
828 * Check mesh FW version and appropriately send the mesh start
831 int lbs_init_mesh(struct lbs_private
*priv
)
835 /* Determine mesh_fw_ver from fwrelease and fwcapinfo */
836 /* 5.0.16p0 9.0.0.p0 is known to NOT support any mesh */
837 /* 5.110.22 have mesh command with 0xa3 command id */
838 /* 10.0.0.p0 FW brings in mesh config command with different id */
839 /* Check FW version MSB and initialize mesh_fw_ver */
840 if (MRVL_FW_MAJOR_REV(priv
->fwrelease
) == MRVL_FW_V5
) {
841 /* Enable mesh, if supported, and work out which TLV it uses.
842 0x100 + 291 is an unofficial value used in 5.110.20.pXX
843 0x100 + 37 is the official value used in 5.110.21.pXX
844 but we check them in that order because 20.pXX doesn't
845 give an error -- it just silently fails. */
847 /* 5.110.20.pXX firmware will fail the command if the channel
848 doesn't match the existing channel. But only if the TLV
849 is correct. If the channel is wrong, _BOTH_ versions will
850 give an error to 0x100+291, and allow 0x100+37 to succeed.
851 It's just that 5.110.20.pXX will not have done anything
854 priv
->mesh_tlv
= TLV_TYPE_OLD_MESH_ID
;
855 if (lbs_mesh_config(priv
, CMD_ACT_MESH_CONFIG_START
, 1)) {
856 priv
->mesh_tlv
= TLV_TYPE_MESH_ID
;
857 if (lbs_mesh_config(priv
, CMD_ACT_MESH_CONFIG_START
, 1))
861 if ((MRVL_FW_MAJOR_REV(priv
->fwrelease
) >= MRVL_FW_V10
) &&
862 (priv
->fwcapinfo
& MESH_CAPINFO_ENABLE_MASK
)) {
863 /* 10.0.0.pXX new firmwares should succeed with TLV
864 * 0x100+37; Do not invoke command with old TLV.
866 priv
->mesh_tlv
= TLV_TYPE_MESH_ID
;
867 if (lbs_mesh_config(priv
, CMD_ACT_MESH_CONFIG_START
, 1))
871 /* Stop meshing until interface is brought up */
872 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
->ssid
, "mesh");
1005 mesh_wdev
->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 /* Register virtual mesh interface */
1022 ret
= register_netdev(mesh_dev
);
1024 pr_err("cannot register mshX virtual interface\n");
1025 goto err_free_netdev
;
1028 ret
= sysfs_create_group(&(mesh_dev
->dev
.kobj
), &lbs_mesh_attr_group
);
1030 goto err_unregister
;
1032 lbs_persist_config_init(mesh_dev
);
1034 /* Everything successful */
1039 unregister_netdev(mesh_dev
);
1042 free_netdev(mesh_dev
);
1051 void lbs_remove_mesh(struct lbs_private
*priv
)
1053 struct net_device
*mesh_dev
;
1055 mesh_dev
= priv
->mesh_dev
;
1059 netif_stop_queue(mesh_dev
);
1060 netif_carrier_off(mesh_dev
);
1061 sysfs_remove_group(&(mesh_dev
->dev
.kobj
), &lbs_mesh_attr_group
);
1062 lbs_persist_config_remove(mesh_dev
);
1063 unregister_netdev(mesh_dev
);
1064 priv
->mesh_dev
= NULL
;
1065 kfree(mesh_dev
->ieee80211_ptr
);
1066 free_netdev(mesh_dev
);
1070 /***************************************************************************
1071 * Sending and receiving
1073 struct net_device
*lbs_mesh_set_dev(struct lbs_private
*priv
,
1074 struct net_device
*dev
, struct rxpd
*rxpd
)
1076 if (priv
->mesh_dev
) {
1077 if (priv
->mesh_tlv
== TLV_TYPE_OLD_MESH_ID
) {
1078 if (rxpd
->rx_control
& RxPD_MESH_FRAME
)
1079 dev
= priv
->mesh_dev
;
1080 } else if (priv
->mesh_tlv
== TLV_TYPE_MESH_ID
) {
1081 if (rxpd
->u
.bss
.bss_num
== MESH_IFACE_ID
)
1082 dev
= priv
->mesh_dev
;
1089 void lbs_mesh_set_txpd(struct lbs_private
*priv
,
1090 struct net_device
*dev
, struct txpd
*txpd
)
1092 if (dev
== priv
->mesh_dev
) {
1093 if (priv
->mesh_tlv
== TLV_TYPE_OLD_MESH_ID
)
1094 txpd
->tx_control
|= cpu_to_le32(TxPD_MESH_FRAME
);
1095 else if (priv
->mesh_tlv
== TLV_TYPE_MESH_ID
)
1096 txpd
->u
.bss
.bss_num
= MESH_IFACE_ID
;
1101 /***************************************************************************
1105 static const char mesh_stat_strings
[MESH_STATS_NUM
][ETH_GSTRING_LEN
] = {
1106 "drop_duplicate_bcast",
1108 "drop_no_fwd_route",
1110 "fwded_unicast_cnt",
1116 void lbs_mesh_ethtool_get_stats(struct net_device
*dev
,
1117 struct ethtool_stats
*stats
, uint64_t *data
)
1119 struct lbs_private
*priv
= dev
->ml_priv
;
1120 struct cmd_ds_mesh_access mesh_access
;
1123 /* Get Mesh Statistics */
1124 ret
= lbs_mesh_access(priv
, CMD_ACT_MESH_GET_STATS
, &mesh_access
);
1127 memset(data
, 0, MESH_STATS_NUM
*(sizeof(uint64_t)));
1131 priv
->mstats
.fwd_drop_rbt
= le32_to_cpu(mesh_access
.data
[0]);
1132 priv
->mstats
.fwd_drop_ttl
= le32_to_cpu(mesh_access
.data
[1]);
1133 priv
->mstats
.fwd_drop_noroute
= le32_to_cpu(mesh_access
.data
[2]);
1134 priv
->mstats
.fwd_drop_nobuf
= le32_to_cpu(mesh_access
.data
[3]);
1135 priv
->mstats
.fwd_unicast_cnt
= le32_to_cpu(mesh_access
.data
[4]);
1136 priv
->mstats
.fwd_bcast_cnt
= le32_to_cpu(mesh_access
.data
[5]);
1137 priv
->mstats
.drop_blind
= le32_to_cpu(mesh_access
.data
[6]);
1138 priv
->mstats
.tx_failed_cnt
= le32_to_cpu(mesh_access
.data
[7]);
1140 data
[0] = priv
->mstats
.fwd_drop_rbt
;
1141 data
[1] = priv
->mstats
.fwd_drop_ttl
;
1142 data
[2] = priv
->mstats
.fwd_drop_noroute
;
1143 data
[3] = priv
->mstats
.fwd_drop_nobuf
;
1144 data
[4] = priv
->mstats
.fwd_unicast_cnt
;
1145 data
[5] = priv
->mstats
.fwd_bcast_cnt
;
1146 data
[6] = priv
->mstats
.drop_blind
;
1147 data
[7] = priv
->mstats
.tx_failed_cnt
;
1150 int lbs_mesh_ethtool_get_sset_count(struct net_device
*dev
, int sset
)
1152 struct lbs_private
*priv
= dev
->ml_priv
;
1154 if (sset
== ETH_SS_STATS
&& dev
== priv
->mesh_dev
)
1155 return MESH_STATS_NUM
;
1160 void lbs_mesh_ethtool_get_strings(struct net_device
*dev
,
1161 uint32_t stringset
, uint8_t *s
)
1163 switch (stringset
) {
1165 memcpy(s
, mesh_stat_strings
, sizeof(mesh_stat_strings
));