1 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
3 #include <linux/delay.h>
4 #include <linux/etherdevice.h>
5 #include <linux/hardirq.h>
6 #include <linux/netdevice.h>
7 #include <linux/if_ether.h>
8 #include <linux/if_arp.h>
9 #include <linux/kthread.h>
10 #include <linux/kfifo.h>
11 #include <net/cfg80211.h>
18 /***************************************************************************
23 * Attributes exported through sysfs
27 * lbs_anycast_get - Get function for sysfs attribute anycast_mask
28 * @dev: the &struct device
29 * @attr: device attributes
30 * @buf: buffer where data will be returned
32 static ssize_t
lbs_anycast_get(struct device
*dev
,
33 struct device_attribute
*attr
, char * buf
)
35 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
36 struct cmd_ds_mesh_access mesh_access
;
39 memset(&mesh_access
, 0, sizeof(mesh_access
));
41 ret
= lbs_mesh_access(priv
, CMD_ACT_MESH_GET_ANYCAST
, &mesh_access
);
45 return snprintf(buf
, 12, "0x%X\n", le32_to_cpu(mesh_access
.data
[0]));
49 * lbs_anycast_set - Set function for sysfs attribute anycast_mask
50 * @dev: the &struct device
51 * @attr: device attributes
52 * @buf: buffer that contains new attribute value
53 * @count: size of buffer
55 static ssize_t
lbs_anycast_set(struct device
*dev
,
56 struct device_attribute
*attr
, const char * buf
, size_t count
)
58 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
59 struct cmd_ds_mesh_access mesh_access
;
63 memset(&mesh_access
, 0, sizeof(mesh_access
));
64 sscanf(buf
, "%x", &datum
);
65 mesh_access
.data
[0] = cpu_to_le32(datum
);
67 ret
= lbs_mesh_access(priv
, CMD_ACT_MESH_SET_ANYCAST
, &mesh_access
);
75 * lbs_prb_rsp_limit_get - Get function for sysfs attribute prb_rsp_limit
76 * @dev: the &struct device
77 * @attr: device attributes
78 * @buf: buffer where data will be returned
80 static ssize_t
lbs_prb_rsp_limit_get(struct device
*dev
,
81 struct device_attribute
*attr
, char *buf
)
83 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
84 struct cmd_ds_mesh_access mesh_access
;
88 memset(&mesh_access
, 0, sizeof(mesh_access
));
89 mesh_access
.data
[0] = cpu_to_le32(CMD_ACT_GET
);
91 ret
= lbs_mesh_access(priv
, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT
,
96 retry_limit
= le32_to_cpu(mesh_access
.data
[1]);
97 return snprintf(buf
, 10, "%d\n", retry_limit
);
101 * lbs_prb_rsp_limit_set - Set function for sysfs attribute prb_rsp_limit
102 * @dev: the &struct device
103 * @attr: device attributes
104 * @buf: buffer that contains new attribute value
105 * @count: size of buffer
107 static ssize_t
lbs_prb_rsp_limit_set(struct device
*dev
,
108 struct device_attribute
*attr
, const char *buf
, size_t count
)
110 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
111 struct cmd_ds_mesh_access mesh_access
;
113 unsigned long retry_limit
;
115 memset(&mesh_access
, 0, sizeof(mesh_access
));
116 mesh_access
.data
[0] = cpu_to_le32(CMD_ACT_SET
);
118 if (!strict_strtoul(buf
, 10, &retry_limit
))
120 if (retry_limit
> 15)
123 mesh_access
.data
[1] = cpu_to_le32(retry_limit
);
125 ret
= lbs_mesh_access(priv
, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT
,
134 * lbs_mesh_get - Get function for sysfs attribute mesh
135 * @dev: the &struct device
136 * @attr: device attributes
137 * @buf: buffer where data will be returned
139 static ssize_t
lbs_mesh_get(struct device
*dev
,
140 struct device_attribute
*attr
, char * buf
)
142 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
143 return snprintf(buf
, 5, "0x%X\n", !!priv
->mesh_dev
);
147 * lbs_mesh_set - Set function for sysfs attribute mesh
148 * @dev: the &struct device
149 * @attr: device attributes
150 * @buf: buffer that contains new attribute value
151 * @count: size of buffer
153 static ssize_t
lbs_mesh_set(struct device
*dev
,
154 struct device_attribute
*attr
, const char * buf
, size_t count
)
156 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
158 int ret
, action
= CMD_ACT_MESH_CONFIG_STOP
;
160 sscanf(buf
, "%x", &enable
);
162 if (enable
== !!priv
->mesh_dev
)
165 action
= CMD_ACT_MESH_CONFIG_START
;
166 ret
= lbs_mesh_config(priv
, action
, priv
->channel
);
173 lbs_remove_mesh(priv
);
179 * lbs_mesh attribute to be exported per ethX interface
180 * through sysfs (/sys/class/net/ethX/lbs_mesh)
182 static DEVICE_ATTR(lbs_mesh
, 0644, lbs_mesh_get
, lbs_mesh_set
);
185 * anycast_mask attribute to be exported per mshX interface
186 * through sysfs (/sys/class/net/mshX/anycast_mask)
188 static DEVICE_ATTR(anycast_mask
, 0644, lbs_anycast_get
, lbs_anycast_set
);
191 * prb_rsp_limit attribute to be exported per mshX interface
192 * through sysfs (/sys/class/net/mshX/prb_rsp_limit)
194 static DEVICE_ATTR(prb_rsp_limit
, 0644, lbs_prb_rsp_limit_get
,
195 lbs_prb_rsp_limit_set
);
197 static struct attribute
*lbs_mesh_sysfs_entries
[] = {
198 &dev_attr_anycast_mask
.attr
,
199 &dev_attr_prb_rsp_limit
.attr
,
203 static struct attribute_group lbs_mesh_attr_group
= {
204 .attrs
= lbs_mesh_sysfs_entries
,
209 /***************************************************************************
210 * Initializing and starting, stopping mesh
214 * Check mesh FW version and appropriately send the mesh start
217 int lbs_init_mesh(struct lbs_private
*priv
)
219 struct net_device
*dev
= priv
->dev
;
222 lbs_deb_enter(LBS_DEB_MESH
);
224 priv
->mesh_connect_status
= LBS_DISCONNECTED
;
226 /* Determine mesh_fw_ver from fwrelease and fwcapinfo */
227 /* 5.0.16p0 9.0.0.p0 is known to NOT support any mesh */
228 /* 5.110.22 have mesh command with 0xa3 command id */
229 /* 10.0.0.p0 FW brings in mesh config command with different id */
230 /* Check FW version MSB and initialize mesh_fw_ver */
231 if (MRVL_FW_MAJOR_REV(priv
->fwrelease
) == MRVL_FW_V5
) {
232 /* Enable mesh, if supported, and work out which TLV it uses.
233 0x100 + 291 is an unofficial value used in 5.110.20.pXX
234 0x100 + 37 is the official value used in 5.110.21.pXX
235 but we check them in that order because 20.pXX doesn't
236 give an error -- it just silently fails. */
238 /* 5.110.20.pXX firmware will fail the command if the channel
239 doesn't match the existing channel. But only if the TLV
240 is correct. If the channel is wrong, _BOTH_ versions will
241 give an error to 0x100+291, and allow 0x100+37 to succeed.
242 It's just that 5.110.20.pXX will not have done anything
245 priv
->mesh_tlv
= TLV_TYPE_OLD_MESH_ID
;
246 if (lbs_mesh_config(priv
, CMD_ACT_MESH_CONFIG_START
,
248 priv
->mesh_tlv
= TLV_TYPE_MESH_ID
;
249 if (lbs_mesh_config(priv
, CMD_ACT_MESH_CONFIG_START
,
254 if ((MRVL_FW_MAJOR_REV(priv
->fwrelease
) >= MRVL_FW_V10
) &&
255 (priv
->fwcapinfo
& MESH_CAPINFO_ENABLE_MASK
)) {
256 /* 10.0.0.pXX new firmwares should succeed with TLV
257 * 0x100+37; Do not invoke command with old TLV.
259 priv
->mesh_tlv
= TLV_TYPE_MESH_ID
;
260 if (lbs_mesh_config(priv
, CMD_ACT_MESH_CONFIG_START
,
266 if (priv
->mesh_tlv
) {
267 sprintf(priv
->mesh_ssid
, "mesh");
268 priv
->mesh_ssid_len
= 4;
272 if (device_create_file(&dev
->dev
, &dev_attr_lbs_mesh
))
273 netdev_err(dev
, "cannot register lbs_mesh attribute\n");
278 lbs_deb_leave_args(LBS_DEB_MESH
, "ret %d", ret
);
283 int lbs_deinit_mesh(struct lbs_private
*priv
)
285 struct net_device
*dev
= priv
->dev
;
288 lbs_deb_enter(LBS_DEB_MESH
);
290 if (priv
->mesh_tlv
) {
291 device_remove_file(&dev
->dev
, &dev_attr_lbs_mesh
);
295 lbs_deb_leave_args(LBS_DEB_MESH
, "ret %d", ret
);
301 * lbs_mesh_stop - close the mshX interface
303 * @dev: A pointer to &net_device structure
306 static int lbs_mesh_stop(struct net_device
*dev
)
308 struct lbs_private
*priv
= dev
->ml_priv
;
310 lbs_deb_enter(LBS_DEB_MESH
);
311 spin_lock_irq(&priv
->driver_lock
);
314 priv
->mesh_connect_status
= LBS_DISCONNECTED
;
316 netif_stop_queue(dev
);
317 netif_carrier_off(dev
);
319 spin_unlock_irq(&priv
->driver_lock
);
321 schedule_work(&priv
->mcast_work
);
323 lbs_deb_leave(LBS_DEB_MESH
);
328 * lbs_mesh_dev_open - open the mshX interface
330 * @dev: A pointer to &net_device structure
331 * returns: 0 or -EBUSY if monitor mode active
333 static int lbs_mesh_dev_open(struct net_device
*dev
)
335 struct lbs_private
*priv
= dev
->ml_priv
;
338 lbs_deb_enter(LBS_DEB_NET
);
340 spin_lock_irq(&priv
->driver_lock
);
342 if (priv
->wdev
->iftype
== NL80211_IFTYPE_MONITOR
) {
348 priv
->mesh_connect_status
= LBS_CONNECTED
;
349 netif_carrier_on(dev
);
351 if (!priv
->tx_pending_len
)
352 netif_wake_queue(dev
);
355 spin_unlock_irq(&priv
->driver_lock
);
356 lbs_deb_leave_args(LBS_DEB_NET
, "ret %d", ret
);
360 static const struct net_device_ops mesh_netdev_ops
= {
361 .ndo_open
= lbs_mesh_dev_open
,
362 .ndo_stop
= lbs_mesh_stop
,
363 .ndo_start_xmit
= lbs_hard_start_xmit
,
364 .ndo_set_mac_address
= lbs_set_mac_address
,
365 .ndo_set_multicast_list
= lbs_set_multicast_list
,
369 * lbs_add_mesh - add mshX interface
371 * @priv: A pointer to the &struct lbs_private structure
372 * returns: 0 if successful, -X otherwise
374 int lbs_add_mesh(struct lbs_private
*priv
)
376 struct net_device
*mesh_dev
= NULL
;
379 lbs_deb_enter(LBS_DEB_MESH
);
381 /* Allocate a virtual mesh device */
382 mesh_dev
= alloc_netdev(0, "msh%d", ether_setup
);
384 lbs_deb_mesh("init mshX device failed\n");
388 mesh_dev
->ml_priv
= priv
;
389 priv
->mesh_dev
= mesh_dev
;
391 mesh_dev
->netdev_ops
= &mesh_netdev_ops
;
392 mesh_dev
->ethtool_ops
= &lbs_ethtool_ops
;
393 memcpy(mesh_dev
->dev_addr
, priv
->dev
->dev_addr
, ETH_ALEN
);
395 SET_NETDEV_DEV(priv
->mesh_dev
, priv
->dev
->dev
.parent
);
397 mesh_dev
->flags
|= IFF_BROADCAST
| IFF_MULTICAST
;
398 /* Register virtual mesh interface */
399 ret
= register_netdev(mesh_dev
);
401 pr_err("cannot register mshX virtual interface\n");
405 ret
= sysfs_create_group(&(mesh_dev
->dev
.kobj
), &lbs_mesh_attr_group
);
409 lbs_persist_config_init(mesh_dev
);
411 /* Everything successful */
416 unregister_netdev(mesh_dev
);
419 free_netdev(mesh_dev
);
422 lbs_deb_leave_args(LBS_DEB_MESH
, "ret %d", ret
);
426 void lbs_remove_mesh(struct lbs_private
*priv
)
428 struct net_device
*mesh_dev
;
430 mesh_dev
= priv
->mesh_dev
;
434 lbs_deb_enter(LBS_DEB_MESH
);
435 netif_stop_queue(mesh_dev
);
436 netif_carrier_off(mesh_dev
);
437 sysfs_remove_group(&(mesh_dev
->dev
.kobj
), &lbs_mesh_attr_group
);
438 lbs_persist_config_remove(mesh_dev
);
439 unregister_netdev(mesh_dev
);
440 priv
->mesh_dev
= NULL
;
441 free_netdev(mesh_dev
);
442 lbs_deb_leave(LBS_DEB_MESH
);
447 /***************************************************************************
448 * Sending and receiving
450 struct net_device
*lbs_mesh_set_dev(struct lbs_private
*priv
,
451 struct net_device
*dev
, struct rxpd
*rxpd
)
453 if (priv
->mesh_dev
) {
454 if (priv
->mesh_tlv
== TLV_TYPE_OLD_MESH_ID
) {
455 if (rxpd
->rx_control
& RxPD_MESH_FRAME
)
456 dev
= priv
->mesh_dev
;
457 } else if (priv
->mesh_tlv
== TLV_TYPE_MESH_ID
) {
458 if (rxpd
->u
.bss
.bss_num
== MESH_IFACE_ID
)
459 dev
= priv
->mesh_dev
;
466 void lbs_mesh_set_txpd(struct lbs_private
*priv
,
467 struct net_device
*dev
, struct txpd
*txpd
)
469 if (dev
== priv
->mesh_dev
) {
470 if (priv
->mesh_tlv
== TLV_TYPE_OLD_MESH_ID
)
471 txpd
->tx_control
|= cpu_to_le32(TxPD_MESH_FRAME
);
472 else if (priv
->mesh_tlv
== TLV_TYPE_MESH_ID
)
473 txpd
->u
.bss
.bss_num
= MESH_IFACE_ID
;
478 /***************************************************************************
479 * Mesh command handling
483 * lbs_mesh_bt_add_del - Add or delete Mesh Blinding Table entries
485 * @priv: A pointer to &struct lbs_private structure
486 * @add: TRUE to add the entry, FALSE to delete it
487 * @addr1: Destination address to blind or unblind
489 * returns: 0 on success, error on failure
491 int lbs_mesh_bt_add_del(struct lbs_private
*priv
, bool add
, u8
*addr1
)
493 struct cmd_ds_bt_access cmd
;
496 lbs_deb_enter(LBS_DEB_CMD
);
498 BUG_ON(addr1
== NULL
);
500 memset(&cmd
, 0, sizeof(cmd
));
501 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
502 memcpy(cmd
.addr1
, addr1
, ETH_ALEN
);
504 cmd
.action
= cpu_to_le16(CMD_ACT_BT_ACCESS_ADD
);
505 lbs_deb_hex(LBS_DEB_MESH
, "BT_ADD: blinded MAC addr",
508 cmd
.action
= cpu_to_le16(CMD_ACT_BT_ACCESS_DEL
);
509 lbs_deb_hex(LBS_DEB_MESH
, "BT_DEL: blinded MAC addr",
513 ret
= lbs_cmd_with_response(priv
, CMD_BT_ACCESS
, &cmd
);
515 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
520 * lbs_mesh_bt_reset - Reset/clear the mesh blinding table
522 * @priv: A pointer to &struct lbs_private structure
524 * returns: 0 on success, error on failure
526 int lbs_mesh_bt_reset(struct lbs_private
*priv
)
528 struct cmd_ds_bt_access cmd
;
531 lbs_deb_enter(LBS_DEB_CMD
);
533 memset(&cmd
, 0, sizeof(cmd
));
534 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
535 cmd
.action
= cpu_to_le16(CMD_ACT_BT_ACCESS_RESET
);
537 ret
= lbs_cmd_with_response(priv
, CMD_BT_ACCESS
, &cmd
);
539 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
544 * lbs_mesh_bt_get_inverted - Gets the inverted status of the mesh
547 * Normally the firmware "blinds" or ignores traffic from mesh nodes in the
548 * table, but an inverted table allows *only* traffic from nodes listed in
551 * @priv: A pointer to &struct lbs_private structure
552 * @inverted: On success, TRUE if the blinding table is inverted,
553 * FALSE if it is not inverted
555 * returns: 0 on success, error on failure
557 int lbs_mesh_bt_get_inverted(struct lbs_private
*priv
, bool *inverted
)
559 struct cmd_ds_bt_access cmd
;
562 lbs_deb_enter(LBS_DEB_CMD
);
564 BUG_ON(inverted
== NULL
);
566 memset(&cmd
, 0, sizeof(cmd
));
567 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
568 cmd
.action
= cpu_to_le16(CMD_ACT_BT_ACCESS_GET_INVERT
);
570 ret
= lbs_cmd_with_response(priv
, CMD_BT_ACCESS
, &cmd
);
572 *inverted
= !!cmd
.id
;
574 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
579 * lbs_mesh_bt_set_inverted - Sets the inverted status of the mesh
582 * Normally the firmware "blinds" or ignores traffic from mesh nodes in the
583 * table, but an inverted table allows *only* traffic from nodes listed in
586 * @priv: A pointer to &struct lbs_private structure
587 * @inverted: TRUE to invert the blinding table (only traffic from
588 * listed nodes allowed), FALSE to return it
589 * to normal state (listed nodes ignored)
591 * returns: 0 on success, error on failure
593 int lbs_mesh_bt_set_inverted(struct lbs_private
*priv
, bool inverted
)
595 struct cmd_ds_bt_access cmd
;
598 lbs_deb_enter(LBS_DEB_CMD
);
600 memset(&cmd
, 0, sizeof(cmd
));
601 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
602 cmd
.action
= cpu_to_le16(CMD_ACT_BT_ACCESS_SET_INVERT
);
603 cmd
.id
= cpu_to_le32(!!inverted
);
605 ret
= lbs_cmd_with_response(priv
, CMD_BT_ACCESS
, &cmd
);
607 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
612 * lbs_mesh_bt_get_entry - List an entry in the mesh blinding table
614 * @priv: A pointer to &struct lbs_private structure
615 * @id: The ID of the entry to list
616 * @addr1: MAC address associated with the table entry
618 * returns: 0 on success, error on failure
620 int lbs_mesh_bt_get_entry(struct lbs_private
*priv
, u32 id
, u8
*addr1
)
622 struct cmd_ds_bt_access cmd
;
625 lbs_deb_enter(LBS_DEB_CMD
);
627 BUG_ON(addr1
== NULL
);
629 memset(&cmd
, 0, sizeof(cmd
));
630 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
631 cmd
.action
= cpu_to_le16(CMD_ACT_BT_ACCESS_SET_INVERT
);
632 cmd
.id
= cpu_to_le32(id
);
634 ret
= lbs_cmd_with_response(priv
, CMD_BT_ACCESS
, &cmd
);
636 memcpy(addr1
, cmd
.addr1
, sizeof(cmd
.addr1
));
638 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
643 * lbs_cmd_fwt_access - Access the mesh forwarding table
645 * @priv: A pointer to &struct lbs_private structure
646 * @cmd_action: The forwarding table action to perform
647 * @cmd: The pre-filled FWT_ACCESS command
649 * returns: 0 on success and 'cmd' will be filled with the
650 * firmware's response
652 int lbs_cmd_fwt_access(struct lbs_private
*priv
, u16 cmd_action
,
653 struct cmd_ds_fwt_access
*cmd
)
657 lbs_deb_enter_args(LBS_DEB_CMD
, "action %d", cmd_action
);
659 cmd
->hdr
.command
= cpu_to_le16(CMD_FWT_ACCESS
);
660 cmd
->hdr
.size
= cpu_to_le16(sizeof(struct cmd_ds_fwt_access
));
662 cmd
->action
= cpu_to_le16(cmd_action
);
664 ret
= lbs_cmd_with_response(priv
, CMD_FWT_ACCESS
, cmd
);
666 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
670 int lbs_mesh_access(struct lbs_private
*priv
, uint16_t cmd_action
,
671 struct cmd_ds_mesh_access
*cmd
)
675 lbs_deb_enter_args(LBS_DEB_CMD
, "action %d", cmd_action
);
677 cmd
->hdr
.command
= cpu_to_le16(CMD_MESH_ACCESS
);
678 cmd
->hdr
.size
= cpu_to_le16(sizeof(*cmd
));
681 cmd
->action
= cpu_to_le16(cmd_action
);
683 ret
= lbs_cmd_with_response(priv
, CMD_MESH_ACCESS
, cmd
);
685 lbs_deb_leave(LBS_DEB_CMD
);
689 static int __lbs_mesh_config_send(struct lbs_private
*priv
,
690 struct cmd_ds_mesh_config
*cmd
,
691 uint16_t action
, uint16_t type
)
694 u16 command
= CMD_MESH_CONFIG_OLD
;
696 lbs_deb_enter(LBS_DEB_CMD
);
699 * Command id is 0xac for v10 FW along with mesh interface
700 * id in bits 14-13-12.
702 if (priv
->mesh_tlv
== TLV_TYPE_MESH_ID
)
703 command
= CMD_MESH_CONFIG
|
704 (MESH_IFACE_ID
<< MESH_IFACE_BIT_OFFSET
);
706 cmd
->hdr
.command
= cpu_to_le16(command
);
707 cmd
->hdr
.size
= cpu_to_le16(sizeof(struct cmd_ds_mesh_config
));
710 cmd
->type
= cpu_to_le16(type
);
711 cmd
->action
= cpu_to_le16(action
);
713 ret
= lbs_cmd_with_response(priv
, command
, cmd
);
715 lbs_deb_leave(LBS_DEB_CMD
);
719 int lbs_mesh_config_send(struct lbs_private
*priv
,
720 struct cmd_ds_mesh_config
*cmd
,
721 uint16_t action
, uint16_t type
)
725 if (!(priv
->fwcapinfo
& FW_CAPINFO_PERSISTENT_CONFIG
))
728 ret
= __lbs_mesh_config_send(priv
, cmd
, action
, type
);
732 /* This function is the CMD_MESH_CONFIG legacy function. It only handles the
733 * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG
734 * are all handled by preparing a struct cmd_ds_mesh_config and passing it to
735 * lbs_mesh_config_send.
737 int lbs_mesh_config(struct lbs_private
*priv
, uint16_t action
, uint16_t chan
)
739 struct cmd_ds_mesh_config cmd
;
740 struct mrvl_meshie
*ie
;
741 DECLARE_SSID_BUF(ssid
);
743 memset(&cmd
, 0, sizeof(cmd
));
744 cmd
.channel
= cpu_to_le16(chan
);
745 ie
= (struct mrvl_meshie
*)cmd
.data
;
748 case CMD_ACT_MESH_CONFIG_START
:
749 ie
->id
= WLAN_EID_GENERIC
;
750 ie
->val
.oui
[0] = 0x00;
751 ie
->val
.oui
[1] = 0x50;
752 ie
->val
.oui
[2] = 0x43;
753 ie
->val
.type
= MARVELL_MESH_IE_TYPE
;
754 ie
->val
.subtype
= MARVELL_MESH_IE_SUBTYPE
;
755 ie
->val
.version
= MARVELL_MESH_IE_VERSION
;
756 ie
->val
.active_protocol_id
= MARVELL_MESH_PROTO_ID_HWMP
;
757 ie
->val
.active_metric_id
= MARVELL_MESH_METRIC_ID
;
758 ie
->val
.mesh_capability
= MARVELL_MESH_CAPABILITY
;
759 ie
->val
.mesh_id_len
= priv
->mesh_ssid_len
;
760 memcpy(ie
->val
.mesh_id
, priv
->mesh_ssid
, priv
->mesh_ssid_len
);
761 ie
->len
= sizeof(struct mrvl_meshie_val
) -
762 IEEE80211_MAX_SSID_LEN
+ priv
->mesh_ssid_len
;
763 cmd
.length
= cpu_to_le16(sizeof(struct mrvl_meshie_val
));
765 case CMD_ACT_MESH_CONFIG_STOP
:
770 lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n",
771 action
, priv
->mesh_tlv
, chan
,
772 print_ssid(ssid
, priv
->mesh_ssid
, priv
->mesh_ssid_len
));
774 return __lbs_mesh_config_send(priv
, &cmd
, action
, priv
->mesh_tlv
);
779 /***************************************************************************
780 * Persistent configuration support
783 static int mesh_get_default_parameters(struct device
*dev
,
784 struct mrvl_mesh_defaults
*defs
)
786 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
787 struct cmd_ds_mesh_config cmd
;
790 memset(&cmd
, 0, sizeof(struct cmd_ds_mesh_config
));
791 ret
= lbs_mesh_config_send(priv
, &cmd
, CMD_ACT_MESH_CONFIG_GET
,
792 CMD_TYPE_MESH_GET_DEFAULTS
);
797 memcpy(defs
, &cmd
.data
[0], sizeof(struct mrvl_mesh_defaults
));
803 * bootflag_get - Get function for sysfs attribute bootflag
804 * @dev: the &struct device
805 * @attr: device attributes
806 * @buf: buffer where data will be returned
808 static ssize_t
bootflag_get(struct device
*dev
,
809 struct device_attribute
*attr
, char *buf
)
811 struct mrvl_mesh_defaults defs
;
814 ret
= mesh_get_default_parameters(dev
, &defs
);
819 return snprintf(buf
, 12, "%d\n", le32_to_cpu(defs
.bootflag
));
823 * bootflag_set - Set function for sysfs attribute bootflag
824 * @dev: the &struct device
825 * @attr: device attributes
826 * @buf: buffer that contains new attribute value
827 * @count: size of buffer
829 static ssize_t
bootflag_set(struct device
*dev
, struct device_attribute
*attr
,
830 const char *buf
, size_t count
)
832 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
833 struct cmd_ds_mesh_config cmd
;
837 memset(&cmd
, 0, sizeof(cmd
));
838 ret
= sscanf(buf
, "%d", &datum
);
839 if ((ret
!= 1) || (datum
> 1))
842 *((__le32
*)&cmd
.data
[0]) = cpu_to_le32(!!datum
);
843 cmd
.length
= cpu_to_le16(sizeof(uint32_t));
844 ret
= lbs_mesh_config_send(priv
, &cmd
, CMD_ACT_MESH_CONFIG_SET
,
845 CMD_TYPE_MESH_SET_BOOTFLAG
);
853 * boottime_get - Get function for sysfs attribute boottime
854 * @dev: the &struct device
855 * @attr: device attributes
856 * @buf: buffer where data will be returned
858 static ssize_t
boottime_get(struct device
*dev
,
859 struct device_attribute
*attr
, char *buf
)
861 struct mrvl_mesh_defaults defs
;
864 ret
= mesh_get_default_parameters(dev
, &defs
);
869 return snprintf(buf
, 12, "%d\n", defs
.boottime
);
873 * boottime_set - Set function for sysfs attribute boottime
874 * @dev: the &struct device
875 * @attr: device attributes
876 * @buf: buffer that contains new attribute value
877 * @count: size of buffer
879 static ssize_t
boottime_set(struct device
*dev
,
880 struct device_attribute
*attr
, const char *buf
, size_t count
)
882 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
883 struct cmd_ds_mesh_config cmd
;
887 memset(&cmd
, 0, sizeof(cmd
));
888 ret
= sscanf(buf
, "%d", &datum
);
889 if ((ret
!= 1) || (datum
> 255))
892 /* A too small boot time will result in the device booting into
893 * standalone (no-host) mode before the host can take control of it,
894 * so the change will be hard to revert. This may be a desired
895 * feature (e.g to configure a very fast boot time for devices that
896 * will not be attached to a host), but dangerous. So I'm enforcing a
897 * lower limit of 20 seconds: remove and recompile the driver if this
898 * does not work for you.
900 datum
= (datum
< 20) ? 20 : datum
;
902 cmd
.length
= cpu_to_le16(sizeof(uint8_t));
903 ret
= lbs_mesh_config_send(priv
, &cmd
, CMD_ACT_MESH_CONFIG_SET
,
904 CMD_TYPE_MESH_SET_BOOTTIME
);
912 * channel_get - Get function for sysfs attribute channel
913 * @dev: the &struct device
914 * @attr: device attributes
915 * @buf: buffer where data will be returned
917 static ssize_t
channel_get(struct device
*dev
,
918 struct device_attribute
*attr
, char *buf
)
920 struct mrvl_mesh_defaults defs
;
923 ret
= mesh_get_default_parameters(dev
, &defs
);
928 return snprintf(buf
, 12, "%d\n", le16_to_cpu(defs
.channel
));
932 * channel_set - Set function for sysfs attribute channel
933 * @dev: the &struct device
934 * @attr: device attributes
935 * @buf: buffer that contains new attribute value
936 * @count: size of buffer
938 static ssize_t
channel_set(struct device
*dev
, struct device_attribute
*attr
,
939 const char *buf
, size_t count
)
941 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
942 struct cmd_ds_mesh_config cmd
;
946 memset(&cmd
, 0, sizeof(cmd
));
947 ret
= sscanf(buf
, "%d", &datum
);
948 if (ret
!= 1 || datum
< 1 || datum
> 11)
951 *((__le16
*)&cmd
.data
[0]) = cpu_to_le16(datum
);
952 cmd
.length
= cpu_to_le16(sizeof(uint16_t));
953 ret
= lbs_mesh_config_send(priv
, &cmd
, CMD_ACT_MESH_CONFIG_SET
,
954 CMD_TYPE_MESH_SET_DEF_CHANNEL
);
962 * mesh_id_get - Get function for sysfs attribute mesh_id
963 * @dev: the &struct device
964 * @attr: device attributes
965 * @buf: buffer where data will be returned
967 static ssize_t
mesh_id_get(struct device
*dev
, struct device_attribute
*attr
,
970 struct mrvl_mesh_defaults defs
;
973 ret
= mesh_get_default_parameters(dev
, &defs
);
978 if (defs
.meshie
.val
.mesh_id_len
> IEEE80211_MAX_SSID_LEN
) {
979 dev_err(dev
, "inconsistent mesh ID length\n");
980 defs
.meshie
.val
.mesh_id_len
= IEEE80211_MAX_SSID_LEN
;
983 memcpy(buf
, defs
.meshie
.val
.mesh_id
, defs
.meshie
.val
.mesh_id_len
);
984 buf
[defs
.meshie
.val
.mesh_id_len
] = '\n';
985 buf
[defs
.meshie
.val
.mesh_id_len
+ 1] = '\0';
987 return defs
.meshie
.val
.mesh_id_len
+ 1;
991 * mesh_id_set - Set function for sysfs attribute mesh_id
992 * @dev: the &struct device
993 * @attr: device attributes
994 * @buf: buffer that contains new attribute value
995 * @count: size of buffer
997 static ssize_t
mesh_id_set(struct device
*dev
, struct device_attribute
*attr
,
998 const char *buf
, size_t count
)
1000 struct cmd_ds_mesh_config cmd
;
1001 struct mrvl_mesh_defaults defs
;
1002 struct mrvl_meshie
*ie
;
1003 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
1007 if (count
< 2 || count
> IEEE80211_MAX_SSID_LEN
+ 1)
1010 memset(&cmd
, 0, sizeof(struct cmd_ds_mesh_config
));
1011 ie
= (struct mrvl_meshie
*) &cmd
.data
[0];
1013 /* fetch all other Information Element parameters */
1014 ret
= mesh_get_default_parameters(dev
, &defs
);
1016 cmd
.length
= cpu_to_le16(sizeof(struct mrvl_meshie
));
1018 /* transfer IE elements */
1019 memcpy(ie
, &defs
.meshie
, sizeof(struct mrvl_meshie
));
1022 memcpy(ie
->val
.mesh_id
, buf
, len
);
1024 ie
->val
.mesh_id_len
= len
;
1026 ie
->len
= sizeof(struct mrvl_meshie_val
) - IEEE80211_MAX_SSID_LEN
+ len
;
1028 ret
= lbs_mesh_config_send(priv
, &cmd
, CMD_ACT_MESH_CONFIG_SET
,
1029 CMD_TYPE_MESH_SET_MESH_IE
);
1037 * protocol_id_get - Get function for sysfs attribute protocol_id
1038 * @dev: the &struct device
1039 * @attr: device attributes
1040 * @buf: buffer where data will be returned
1042 static ssize_t
protocol_id_get(struct device
*dev
,
1043 struct device_attribute
*attr
, char *buf
)
1045 struct mrvl_mesh_defaults defs
;
1048 ret
= mesh_get_default_parameters(dev
, &defs
);
1053 return snprintf(buf
, 5, "%d\n", defs
.meshie
.val
.active_protocol_id
);
1057 * protocol_id_set - Set function for sysfs attribute protocol_id
1058 * @dev: the &struct device
1059 * @attr: device attributes
1060 * @buf: buffer that contains new attribute value
1061 * @count: size of buffer
1063 static ssize_t
protocol_id_set(struct device
*dev
,
1064 struct device_attribute
*attr
, const char *buf
, size_t count
)
1066 struct cmd_ds_mesh_config cmd
;
1067 struct mrvl_mesh_defaults defs
;
1068 struct mrvl_meshie
*ie
;
1069 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
1073 memset(&cmd
, 0, sizeof(cmd
));
1074 ret
= sscanf(buf
, "%d", &datum
);
1075 if ((ret
!= 1) || (datum
> 255))
1078 /* fetch all other Information Element parameters */
1079 ret
= mesh_get_default_parameters(dev
, &defs
);
1081 cmd
.length
= cpu_to_le16(sizeof(struct mrvl_meshie
));
1083 /* transfer IE elements */
1084 ie
= (struct mrvl_meshie
*) &cmd
.data
[0];
1085 memcpy(ie
, &defs
.meshie
, sizeof(struct mrvl_meshie
));
1086 /* update protocol id */
1087 ie
->val
.active_protocol_id
= datum
;
1089 ret
= lbs_mesh_config_send(priv
, &cmd
, CMD_ACT_MESH_CONFIG_SET
,
1090 CMD_TYPE_MESH_SET_MESH_IE
);
1098 * metric_id_get - Get function for sysfs attribute metric_id
1099 * @dev: the &struct device
1100 * @attr: device attributes
1101 * @buf: buffer where data will be returned
1103 static ssize_t
metric_id_get(struct device
*dev
,
1104 struct device_attribute
*attr
, char *buf
)
1106 struct mrvl_mesh_defaults defs
;
1109 ret
= mesh_get_default_parameters(dev
, &defs
);
1114 return snprintf(buf
, 5, "%d\n", defs
.meshie
.val
.active_metric_id
);
1118 * metric_id_set - Set function for sysfs attribute metric_id
1119 * @dev: the &struct device
1120 * @attr: device attributes
1121 * @buf: buffer that contains new attribute value
1122 * @count: size of buffer
1124 static ssize_t
metric_id_set(struct device
*dev
, struct device_attribute
*attr
,
1125 const char *buf
, size_t count
)
1127 struct cmd_ds_mesh_config cmd
;
1128 struct mrvl_mesh_defaults defs
;
1129 struct mrvl_meshie
*ie
;
1130 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
1134 memset(&cmd
, 0, sizeof(cmd
));
1135 ret
= sscanf(buf
, "%d", &datum
);
1136 if ((ret
!= 1) || (datum
> 255))
1139 /* fetch all other Information Element parameters */
1140 ret
= mesh_get_default_parameters(dev
, &defs
);
1142 cmd
.length
= cpu_to_le16(sizeof(struct mrvl_meshie
));
1144 /* transfer IE elements */
1145 ie
= (struct mrvl_meshie
*) &cmd
.data
[0];
1146 memcpy(ie
, &defs
.meshie
, sizeof(struct mrvl_meshie
));
1147 /* update metric id */
1148 ie
->val
.active_metric_id
= datum
;
1150 ret
= lbs_mesh_config_send(priv
, &cmd
, CMD_ACT_MESH_CONFIG_SET
,
1151 CMD_TYPE_MESH_SET_MESH_IE
);
1159 * capability_get - Get function for sysfs attribute capability
1160 * @dev: the &struct device
1161 * @attr: device attributes
1162 * @buf: buffer where data will be returned
1164 static ssize_t
capability_get(struct device
*dev
,
1165 struct device_attribute
*attr
, char *buf
)
1167 struct mrvl_mesh_defaults defs
;
1170 ret
= mesh_get_default_parameters(dev
, &defs
);
1175 return snprintf(buf
, 5, "%d\n", defs
.meshie
.val
.mesh_capability
);
1179 * capability_set - Set function for sysfs attribute capability
1180 * @dev: the &struct device
1181 * @attr: device attributes
1182 * @buf: buffer that contains new attribute value
1183 * @count: size of buffer
1185 static ssize_t
capability_set(struct device
*dev
, struct device_attribute
*attr
,
1186 const char *buf
, size_t count
)
1188 struct cmd_ds_mesh_config cmd
;
1189 struct mrvl_mesh_defaults defs
;
1190 struct mrvl_meshie
*ie
;
1191 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
1195 memset(&cmd
, 0, sizeof(cmd
));
1196 ret
= sscanf(buf
, "%d", &datum
);
1197 if ((ret
!= 1) || (datum
> 255))
1200 /* fetch all other Information Element parameters */
1201 ret
= mesh_get_default_parameters(dev
, &defs
);
1203 cmd
.length
= cpu_to_le16(sizeof(struct mrvl_meshie
));
1205 /* transfer IE elements */
1206 ie
= (struct mrvl_meshie
*) &cmd
.data
[0];
1207 memcpy(ie
, &defs
.meshie
, sizeof(struct mrvl_meshie
));
1209 ie
->val
.mesh_capability
= datum
;
1211 ret
= lbs_mesh_config_send(priv
, &cmd
, CMD_ACT_MESH_CONFIG_SET
,
1212 CMD_TYPE_MESH_SET_MESH_IE
);
1220 static DEVICE_ATTR(bootflag
, 0644, bootflag_get
, bootflag_set
);
1221 static DEVICE_ATTR(boottime
, 0644, boottime_get
, boottime_set
);
1222 static DEVICE_ATTR(channel
, 0644, channel_get
, channel_set
);
1223 static DEVICE_ATTR(mesh_id
, 0644, mesh_id_get
, mesh_id_set
);
1224 static DEVICE_ATTR(protocol_id
, 0644, protocol_id_get
, protocol_id_set
);
1225 static DEVICE_ATTR(metric_id
, 0644, metric_id_get
, metric_id_set
);
1226 static DEVICE_ATTR(capability
, 0644, capability_get
, capability_set
);
1228 static struct attribute
*boot_opts_attrs
[] = {
1229 &dev_attr_bootflag
.attr
,
1230 &dev_attr_boottime
.attr
,
1231 &dev_attr_channel
.attr
,
1235 static struct attribute_group boot_opts_group
= {
1236 .name
= "boot_options",
1237 .attrs
= boot_opts_attrs
,
1240 static struct attribute
*mesh_ie_attrs
[] = {
1241 &dev_attr_mesh_id
.attr
,
1242 &dev_attr_protocol_id
.attr
,
1243 &dev_attr_metric_id
.attr
,
1244 &dev_attr_capability
.attr
,
1248 static struct attribute_group mesh_ie_group
= {
1250 .attrs
= mesh_ie_attrs
,
1253 void lbs_persist_config_init(struct net_device
*dev
)
1256 ret
= sysfs_create_group(&(dev
->dev
.kobj
), &boot_opts_group
);
1257 ret
= sysfs_create_group(&(dev
->dev
.kobj
), &mesh_ie_group
);
1260 void lbs_persist_config_remove(struct net_device
*dev
)
1262 sysfs_remove_group(&(dev
->dev
.kobj
), &boot_opts_group
);
1263 sysfs_remove_group(&(dev
->dev
.kobj
), &mesh_ie_group
);
1268 /***************************************************************************
1272 static const char *mesh_stat_strings
[] = {
1273 "drop_duplicate_bcast",
1275 "drop_no_fwd_route",
1277 "fwded_unicast_cnt",
1283 void lbs_mesh_ethtool_get_stats(struct net_device
*dev
,
1284 struct ethtool_stats
*stats
, uint64_t *data
)
1286 struct lbs_private
*priv
= dev
->ml_priv
;
1287 struct cmd_ds_mesh_access mesh_access
;
1290 lbs_deb_enter(LBS_DEB_ETHTOOL
);
1292 /* Get Mesh Statistics */
1293 ret
= lbs_mesh_access(priv
, CMD_ACT_MESH_GET_STATS
, &mesh_access
);
1296 memset(data
, 0, MESH_STATS_NUM
*(sizeof(uint64_t)));
1300 priv
->mstats
.fwd_drop_rbt
= le32_to_cpu(mesh_access
.data
[0]);
1301 priv
->mstats
.fwd_drop_ttl
= le32_to_cpu(mesh_access
.data
[1]);
1302 priv
->mstats
.fwd_drop_noroute
= le32_to_cpu(mesh_access
.data
[2]);
1303 priv
->mstats
.fwd_drop_nobuf
= le32_to_cpu(mesh_access
.data
[3]);
1304 priv
->mstats
.fwd_unicast_cnt
= le32_to_cpu(mesh_access
.data
[4]);
1305 priv
->mstats
.fwd_bcast_cnt
= le32_to_cpu(mesh_access
.data
[5]);
1306 priv
->mstats
.drop_blind
= le32_to_cpu(mesh_access
.data
[6]);
1307 priv
->mstats
.tx_failed_cnt
= le32_to_cpu(mesh_access
.data
[7]);
1309 data
[0] = priv
->mstats
.fwd_drop_rbt
;
1310 data
[1] = priv
->mstats
.fwd_drop_ttl
;
1311 data
[2] = priv
->mstats
.fwd_drop_noroute
;
1312 data
[3] = priv
->mstats
.fwd_drop_nobuf
;
1313 data
[4] = priv
->mstats
.fwd_unicast_cnt
;
1314 data
[5] = priv
->mstats
.fwd_bcast_cnt
;
1315 data
[6] = priv
->mstats
.drop_blind
;
1316 data
[7] = priv
->mstats
.tx_failed_cnt
;
1318 lbs_deb_enter(LBS_DEB_ETHTOOL
);
1321 int lbs_mesh_ethtool_get_sset_count(struct net_device
*dev
, int sset
)
1323 struct lbs_private
*priv
= dev
->ml_priv
;
1325 if (sset
== ETH_SS_STATS
&& dev
== priv
->mesh_dev
)
1326 return MESH_STATS_NUM
;
1331 void lbs_mesh_ethtool_get_strings(struct net_device
*dev
,
1332 uint32_t stringset
, uint8_t *s
)
1336 lbs_deb_enter(LBS_DEB_ETHTOOL
);
1338 switch (stringset
) {
1340 for (i
= 0; i
< MESH_STATS_NUM
; i
++) {
1341 memcpy(s
+ i
* ETH_GSTRING_LEN
,
1342 mesh_stat_strings
[i
],
1347 lbs_deb_enter(LBS_DEB_ETHTOOL
);