mac80211: dont try to use existing sta for AP
[deliverable/linux.git] / drivers / net / wireless / libertas / mesh.c
CommitLineData
15dbaac0
JC
1#include <linux/moduleparam.h>
2#include <linux/delay.h>
3#include <linux/etherdevice.h>
4#include <linux/netdevice.h>
5#include <linux/if_arp.h>
6#include <linux/kthread.h>
7#include <linux/kfifo.h>
8
e0e42da3 9#include "mesh.h"
15dbaac0 10#include "decl.h"
15dbaac0
JC
11#include "cmd.h"
12
e0e42da3
HS
13
14/***************************************************************************
15 * Mesh sysfs support
16 */
17
18/**
19 * Attributes exported through sysfs
20 */
21
22/**
23 * @brief Get function for sysfs attribute anycast_mask
24 */
25static ssize_t lbs_anycast_get(struct device *dev,
26 struct device_attribute *attr, char * buf)
27{
28 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
29 struct cmd_ds_mesh_access mesh_access;
30 int ret;
31
32 memset(&mesh_access, 0, sizeof(mesh_access));
33
34 ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_ANYCAST, &mesh_access);
35 if (ret)
36 return ret;
37
38 return snprintf(buf, 12, "0x%X\n", le32_to_cpu(mesh_access.data[0]));
39}
40
41/**
42 * @brief Set function for sysfs attribute anycast_mask
43 */
44static ssize_t lbs_anycast_set(struct device *dev,
45 struct device_attribute *attr, const char * buf, size_t count)
46{
47 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
48 struct cmd_ds_mesh_access mesh_access;
49 uint32_t datum;
50 int ret;
51
52 memset(&mesh_access, 0, sizeof(mesh_access));
53 sscanf(buf, "%x", &datum);
54 mesh_access.data[0] = cpu_to_le32(datum);
55
56 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_ANYCAST, &mesh_access);
57 if (ret)
58 return ret;
59
60 return strlen(buf);
61}
62
63/**
64 * @brief Get function for sysfs attribute prb_rsp_limit
65 */
66static ssize_t lbs_prb_rsp_limit_get(struct device *dev,
67 struct device_attribute *attr, char *buf)
68{
69 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
70 struct cmd_ds_mesh_access mesh_access;
71 int ret;
72 u32 retry_limit;
73
74 memset(&mesh_access, 0, sizeof(mesh_access));
75 mesh_access.data[0] = cpu_to_le32(CMD_ACT_GET);
76
77 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT,
78 &mesh_access);
79 if (ret)
80 return ret;
81
82 retry_limit = le32_to_cpu(mesh_access.data[1]);
83 return snprintf(buf, 10, "%d\n", retry_limit);
84}
85
86/**
87 * @brief Set function for sysfs attribute prb_rsp_limit
88 */
89static ssize_t lbs_prb_rsp_limit_set(struct device *dev,
90 struct device_attribute *attr, const char *buf, size_t count)
91{
92 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
93 struct cmd_ds_mesh_access mesh_access;
94 int ret;
95 unsigned long retry_limit;
96
97 memset(&mesh_access, 0, sizeof(mesh_access));
98 mesh_access.data[0] = cpu_to_le32(CMD_ACT_SET);
99
100 if (!strict_strtoul(buf, 10, &retry_limit))
101 return -ENOTSUPP;
102 if (retry_limit > 15)
103 return -ENOTSUPP;
104
105 mesh_access.data[1] = cpu_to_le32(retry_limit);
106
107 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT,
108 &mesh_access);
109 if (ret)
110 return ret;
111
112 return strlen(buf);
113}
114
115/**
116 * Get function for sysfs attribute mesh
117 */
118static ssize_t lbs_mesh_get(struct device *dev,
119 struct device_attribute *attr, char * buf)
120{
121 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
122 return snprintf(buf, 5, "0x%X\n", !!priv->mesh_dev);
123}
124
125/**
126 * Set function for sysfs attribute mesh
127 */
128static ssize_t lbs_mesh_set(struct device *dev,
129 struct device_attribute *attr, const char * buf, size_t count)
130{
131 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
132 int enable;
133 int ret, action = CMD_ACT_MESH_CONFIG_STOP;
134
135 sscanf(buf, "%x", &enable);
136 enable = !!enable;
137 if (enable == !!priv->mesh_dev)
138 return count;
139 if (enable)
140 action = CMD_ACT_MESH_CONFIG_START;
141 ret = lbs_mesh_config(priv, action, priv->channel);
142 if (ret)
143 return ret;
144
145 if (enable)
146 lbs_add_mesh(priv);
147 else
148 lbs_remove_mesh(priv);
149
150 return count;
151}
152
153/**
154 * lbs_mesh attribute to be exported per ethX interface
155 * through sysfs (/sys/class/net/ethX/lbs_mesh)
156 */
157static DEVICE_ATTR(lbs_mesh, 0644, lbs_mesh_get, lbs_mesh_set);
158
159/**
160 * anycast_mask attribute to be exported per mshX interface
161 * through sysfs (/sys/class/net/mshX/anycast_mask)
162 */
163static DEVICE_ATTR(anycast_mask, 0644, lbs_anycast_get, lbs_anycast_set);
164
165/**
166 * prb_rsp_limit attribute to be exported per mshX interface
167 * through sysfs (/sys/class/net/mshX/prb_rsp_limit)
168 */
169static DEVICE_ATTR(prb_rsp_limit, 0644, lbs_prb_rsp_limit_get,
170 lbs_prb_rsp_limit_set);
171
172static struct attribute *lbs_mesh_sysfs_entries[] = {
173 &dev_attr_anycast_mask.attr,
174 &dev_attr_prb_rsp_limit.attr,
175 NULL,
176};
177
178static struct attribute_group lbs_mesh_attr_group = {
179 .attrs = lbs_mesh_sysfs_entries,
180};
181
182
183
184/***************************************************************************
185 * Initializing and starting, stopping mesh
186 */
187
188/*
189 * Check mesh FW version and appropriately send the mesh start
190 * command
191 */
192int lbs_init_mesh(struct lbs_private *priv)
193{
194 struct net_device *dev = priv->dev;
195 int ret = 0;
196
197 lbs_deb_enter(LBS_DEB_MESH);
198
199 if (priv->mesh_fw_ver == MESH_FW_OLD) {
200 /* Enable mesh, if supported, and work out which TLV it uses.
201 0x100 + 291 is an unofficial value used in 5.110.20.pXX
202 0x100 + 37 is the official value used in 5.110.21.pXX
203 but we check them in that order because 20.pXX doesn't
204 give an error -- it just silently fails. */
205
206 /* 5.110.20.pXX firmware will fail the command if the channel
207 doesn't match the existing channel. But only if the TLV
208 is correct. If the channel is wrong, _BOTH_ versions will
209 give an error to 0x100+291, and allow 0x100+37 to succeed.
210 It's just that 5.110.20.pXX will not have done anything
211 useful */
212
213 priv->mesh_tlv = TLV_TYPE_OLD_MESH_ID;
214 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
215 priv->channel)) {
216 priv->mesh_tlv = TLV_TYPE_MESH_ID;
217 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
218 priv->channel))
219 priv->mesh_tlv = 0;
220 }
221 } else if (priv->mesh_fw_ver == MESH_FW_NEW) {
222 /* 10.0.0.pXX new firmwares should succeed with TLV
223 * 0x100+37; Do not invoke command with old TLV.
224 */
225 priv->mesh_tlv = TLV_TYPE_MESH_ID;
226 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
227 priv->channel))
228 priv->mesh_tlv = 0;
229 }
230 if (priv->mesh_tlv) {
231 lbs_add_mesh(priv);
232
233 if (device_create_file(&dev->dev, &dev_attr_lbs_mesh))
234 lbs_pr_err("cannot register lbs_mesh attribute\n");
235
236 ret = 1;
237 }
238
239 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
240 return ret;
241}
242
243
244int lbs_deinit_mesh(struct lbs_private *priv)
245{
246 struct net_device *dev = priv->dev;
247 int ret = 0;
248
249 lbs_deb_enter(LBS_DEB_MESH);
250
251 if (priv->mesh_tlv) {
252 device_remove_file(&dev->dev, &dev_attr_lbs_mesh);
253 ret = 1;
254 }
255
256 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
257 return ret;
258}
259
260
261/**
262 * @brief This function closes the mshX interface
263 *
264 * @param dev A pointer to net_device structure
265 * @return 0
266 */
267static int lbs_mesh_stop(struct net_device *dev)
268{
269 struct lbs_private *priv = dev->ml_priv;
270
271 lbs_deb_enter(LBS_DEB_MESH);
272 spin_lock_irq(&priv->driver_lock);
273
274 priv->mesh_open = 0;
275 priv->mesh_connect_status = LBS_DISCONNECTED;
276
277 netif_stop_queue(dev);
278 netif_carrier_off(dev);
279
280 spin_unlock_irq(&priv->driver_lock);
281
282 schedule_work(&priv->mcast_work);
283
284 lbs_deb_leave(LBS_DEB_MESH);
285 return 0;
286}
287
288/**
289 * @brief This function opens the mshX interface
290 *
291 * @param dev A pointer to net_device structure
292 * @return 0 or -EBUSY if monitor mode active
293 */
294static int lbs_mesh_dev_open(struct net_device *dev)
295{
296 struct lbs_private *priv = dev->ml_priv;
297 int ret = 0;
298
299 lbs_deb_enter(LBS_DEB_NET);
300
301 spin_lock_irq(&priv->driver_lock);
302
303 if (priv->monitormode) {
304 ret = -EBUSY;
305 goto out;
306 }
307
308 priv->mesh_open = 1;
309 priv->mesh_connect_status = LBS_CONNECTED;
310 netif_carrier_on(dev);
311
312 if (!priv->tx_pending_len)
313 netif_wake_queue(dev);
314 out:
315
316 spin_unlock_irq(&priv->driver_lock);
317 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
318 return ret;
319}
320
321static const struct net_device_ops mesh_netdev_ops = {
322 .ndo_open = lbs_mesh_dev_open,
323 .ndo_stop = lbs_mesh_stop,
324 .ndo_start_xmit = lbs_hard_start_xmit,
325 .ndo_set_mac_address = lbs_set_mac_address,
326 .ndo_set_multicast_list = lbs_set_multicast_list,
327};
328
329/**
330 * @brief This function adds mshX interface
331 *
332 * @param priv A pointer to the struct lbs_private structure
333 * @return 0 if successful, -X otherwise
334 */
335int lbs_add_mesh(struct lbs_private *priv)
336{
337 struct net_device *mesh_dev = NULL;
338 int ret = 0;
339
340 lbs_deb_enter(LBS_DEB_MESH);
341
342 /* Allocate a virtual mesh device */
343 mesh_dev = alloc_netdev(0, "msh%d", ether_setup);
344 if (!mesh_dev) {
345 lbs_deb_mesh("init mshX device failed\n");
346 ret = -ENOMEM;
347 goto done;
348 }
349 mesh_dev->ml_priv = priv;
350 priv->mesh_dev = mesh_dev;
351
352 mesh_dev->netdev_ops = &mesh_netdev_ops;
353 mesh_dev->ethtool_ops = &lbs_ethtool_ops;
354 memcpy(mesh_dev->dev_addr, priv->dev->dev_addr,
355 sizeof(priv->dev->dev_addr));
356
357 SET_NETDEV_DEV(priv->mesh_dev, priv->dev->dev.parent);
358
359#ifdef WIRELESS_EXT
360 mesh_dev->wireless_handlers = &mesh_handler_def;
361#endif
362 mesh_dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
363 /* Register virtual mesh interface */
364 ret = register_netdev(mesh_dev);
365 if (ret) {
366 lbs_pr_err("cannot register mshX virtual interface\n");
367 goto err_free;
368 }
369
370 ret = sysfs_create_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
371 if (ret)
372 goto err_unregister;
373
374 lbs_persist_config_init(mesh_dev);
375
376 /* Everything successful */
377 ret = 0;
378 goto done;
379
380err_unregister:
381 unregister_netdev(mesh_dev);
382
383err_free:
384 free_netdev(mesh_dev);
385
386done:
387 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
388 return ret;
389}
390
391void lbs_remove_mesh(struct lbs_private *priv)
392{
393 struct net_device *mesh_dev;
394
395 mesh_dev = priv->mesh_dev;
396 if (!mesh_dev)
397 return;
398
399 lbs_deb_enter(LBS_DEB_MESH);
400 netif_stop_queue(mesh_dev);
401 netif_carrier_off(mesh_dev);
402 sysfs_remove_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
403 lbs_persist_config_remove(mesh_dev);
404 unregister_netdev(mesh_dev);
405 priv->mesh_dev = NULL;
406 free_netdev(mesh_dev);
407 lbs_deb_leave(LBS_DEB_MESH);
408}
409
410
411
412/***************************************************************************
413 * Sending and receiving
414 */
415struct net_device *lbs_mesh_set_dev(struct lbs_private *priv,
416 struct net_device *dev, struct rxpd *rxpd)
417{
418 if (priv->mesh_dev) {
419 if (priv->mesh_fw_ver == MESH_FW_OLD) {
420 if (rxpd->rx_control & RxPD_MESH_FRAME)
421 dev = priv->mesh_dev;
422 } else if (priv->mesh_fw_ver == MESH_FW_NEW) {
423 if (rxpd->u.bss.bss_num == MESH_IFACE_ID)
424 dev = priv->mesh_dev;
425 }
426 }
427 return dev;
428}
429
430
431void lbs_mesh_set_txpd(struct lbs_private *priv,
432 struct net_device *dev, struct txpd *txpd)
433{
434 if (dev == priv->mesh_dev) {
435 if (priv->mesh_fw_ver == MESH_FW_OLD)
436 txpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
437 else if (priv->mesh_fw_ver == MESH_FW_NEW)
438 txpd->u.bss.bss_num = MESH_IFACE_ID;
439 }
440}
441
442
ece1e3c6
HS
443/***************************************************************************
444 * Mesh command handling
445 */
446
447int lbs_cmd_bt_access(struct cmd_ds_command *cmd,
448 u16 cmd_action, void *pdata_buf)
449{
450 struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
451 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
452
453 cmd->command = cpu_to_le16(CMD_BT_ACCESS);
454 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) +
455 sizeof(struct cmd_header));
456 cmd->result = 0;
457 bt_access->action = cpu_to_le16(cmd_action);
458
459 switch (cmd_action) {
460 case CMD_ACT_BT_ACCESS_ADD:
461 memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
462 lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr",
463 bt_access->addr1, 6);
464 break;
465 case CMD_ACT_BT_ACCESS_DEL:
466 memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
467 lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr",
468 bt_access->addr1, 6);
469 break;
470 case CMD_ACT_BT_ACCESS_LIST:
471 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
472 break;
473 case CMD_ACT_BT_ACCESS_RESET:
474 break;
475 case CMD_ACT_BT_ACCESS_SET_INVERT:
476 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
477 break;
478 case CMD_ACT_BT_ACCESS_GET_INVERT:
479 break;
480 default:
481 break;
482 }
483 lbs_deb_leave(LBS_DEB_CMD);
484 return 0;
485}
486
487int lbs_cmd_fwt_access(struct cmd_ds_command *cmd,
488 u16 cmd_action, void *pdata_buf)
489{
490 struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
491 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
492
493 cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
494 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) +
495 sizeof(struct cmd_header));
496 cmd->result = 0;
497
498 if (pdata_buf)
499 memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
500 else
501 memset(fwt_access, 0, sizeof(*fwt_access));
502
503 fwt_access->action = cpu_to_le16(cmd_action);
504
505 lbs_deb_leave(LBS_DEB_CMD);
506 return 0;
507}
508
509int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
510 struct cmd_ds_mesh_access *cmd)
511{
512 int ret;
513
514 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
515
516 cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
517 cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
518 cmd->hdr.result = 0;
519
520 cmd->action = cpu_to_le16(cmd_action);
521
522 ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
523
524 lbs_deb_leave(LBS_DEB_CMD);
525 return ret;
526}
527
528static int __lbs_mesh_config_send(struct lbs_private *priv,
529 struct cmd_ds_mesh_config *cmd,
530 uint16_t action, uint16_t type)
531{
532 int ret;
533 u16 command = CMD_MESH_CONFIG_OLD;
534
535 lbs_deb_enter(LBS_DEB_CMD);
536
537 /*
538 * Command id is 0xac for v10 FW along with mesh interface
539 * id in bits 14-13-12.
540 */
541 if (priv->mesh_fw_ver == MESH_FW_NEW)
542 command = CMD_MESH_CONFIG |
543 (MESH_IFACE_ID << MESH_IFACE_BIT_OFFSET);
544
545 cmd->hdr.command = cpu_to_le16(command);
546 cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config));
547 cmd->hdr.result = 0;
548
549 cmd->type = cpu_to_le16(type);
550 cmd->action = cpu_to_le16(action);
551
552 ret = lbs_cmd_with_response(priv, command, cmd);
553
554 lbs_deb_leave(LBS_DEB_CMD);
555 return ret;
556}
557
558int lbs_mesh_config_send(struct lbs_private *priv,
559 struct cmd_ds_mesh_config *cmd,
560 uint16_t action, uint16_t type)
561{
562 int ret;
563
564 if (!(priv->fwcapinfo & FW_CAPINFO_PERSISTENT_CONFIG))
565 return -EOPNOTSUPP;
566
567 ret = __lbs_mesh_config_send(priv, cmd, action, type);
568 return ret;
569}
570
571/* This function is the CMD_MESH_CONFIG legacy function. It only handles the
572 * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG
573 * are all handled by preparing a struct cmd_ds_mesh_config and passing it to
574 * lbs_mesh_config_send.
575 */
576int lbs_mesh_config(struct lbs_private *priv, uint16_t action, uint16_t chan)
577{
578 struct cmd_ds_mesh_config cmd;
579 struct mrvl_meshie *ie;
580 DECLARE_SSID_BUF(ssid);
581
582 memset(&cmd, 0, sizeof(cmd));
583 cmd.channel = cpu_to_le16(chan);
584 ie = (struct mrvl_meshie *)cmd.data;
585
586 switch (action) {
587 case CMD_ACT_MESH_CONFIG_START:
588 ie->id = WLAN_EID_GENERIC;
589 ie->val.oui[0] = 0x00;
590 ie->val.oui[1] = 0x50;
591 ie->val.oui[2] = 0x43;
592 ie->val.type = MARVELL_MESH_IE_TYPE;
593 ie->val.subtype = MARVELL_MESH_IE_SUBTYPE;
594 ie->val.version = MARVELL_MESH_IE_VERSION;
595 ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP;
596 ie->val.active_metric_id = MARVELL_MESH_METRIC_ID;
597 ie->val.mesh_capability = MARVELL_MESH_CAPABILITY;
598 ie->val.mesh_id_len = priv->mesh_ssid_len;
599 memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len);
600 ie->len = sizeof(struct mrvl_meshie_val) -
601 IEEE80211_MAX_SSID_LEN + priv->mesh_ssid_len;
602 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val));
603 break;
604 case CMD_ACT_MESH_CONFIG_STOP:
605 break;
606 default:
607 return -1;
608 }
609 lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n",
610 action, priv->mesh_tlv, chan,
611 print_ssid(ssid, priv->mesh_ssid, priv->mesh_ssid_len));
612
613 return __lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv);
614}
615
616
617
e0e42da3
HS
618/***************************************************************************
619 * Persistent configuration support
620 */
621
15dbaac0
JC
622static int mesh_get_default_parameters(struct device *dev,
623 struct mrvl_mesh_defaults *defs)
624{
ab65f649 625 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
15dbaac0
JC
626 struct cmd_ds_mesh_config cmd;
627 int ret;
628
629 memset(&cmd, 0, sizeof(struct cmd_ds_mesh_config));
630 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_GET,
631 CMD_TYPE_MESH_GET_DEFAULTS);
632
633 if (ret)
634 return -EOPNOTSUPP;
635
636 memcpy(defs, &cmd.data[0], sizeof(struct mrvl_mesh_defaults));
637
638 return 0;
639}
640
641/**
642 * @brief Get function for sysfs attribute bootflag
643 */
644static ssize_t bootflag_get(struct device *dev,
645 struct device_attribute *attr, char *buf)
646{
647 struct mrvl_mesh_defaults defs;
648 int ret;
649
650 ret = mesh_get_default_parameters(dev, &defs);
651
652 if (ret)
653 return ret;
654
fb904907 655 return snprintf(buf, 12, "%d\n", le32_to_cpu(defs.bootflag));
15dbaac0
JC
656}
657
658/**
659 * @brief Set function for sysfs attribute bootflag
660 */
661static ssize_t bootflag_set(struct device *dev, struct device_attribute *attr,
662 const char *buf, size_t count)
663{
ab65f649 664 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
15dbaac0
JC
665 struct cmd_ds_mesh_config cmd;
666 uint32_t datum;
667 int ret;
668
669 memset(&cmd, 0, sizeof(cmd));
fb904907
BC
670 ret = sscanf(buf, "%d", &datum);
671 if ((ret != 1) || (datum > 1))
15dbaac0
JC
672 return -EINVAL;
673
674 *((__le32 *)&cmd.data[0]) = cpu_to_le32(!!datum);
675 cmd.length = cpu_to_le16(sizeof(uint32_t));
676 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
677 CMD_TYPE_MESH_SET_BOOTFLAG);
678 if (ret)
679 return ret;
680
681 return strlen(buf);
682}
683
684/**
685 * @brief Get function for sysfs attribute boottime
686 */
687static ssize_t boottime_get(struct device *dev,
688 struct device_attribute *attr, char *buf)
689{
690 struct mrvl_mesh_defaults defs;
691 int ret;
692
693 ret = mesh_get_default_parameters(dev, &defs);
694
695 if (ret)
696 return ret;
697
fb904907 698 return snprintf(buf, 12, "%d\n", defs.boottime);
15dbaac0
JC
699}
700
701/**
702 * @brief Set function for sysfs attribute boottime
703 */
704static ssize_t boottime_set(struct device *dev,
705 struct device_attribute *attr, const char *buf, size_t count)
706{
ab65f649 707 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
15dbaac0
JC
708 struct cmd_ds_mesh_config cmd;
709 uint32_t datum;
710 int ret;
711
712 memset(&cmd, 0, sizeof(cmd));
fb904907
BC
713 ret = sscanf(buf, "%d", &datum);
714 if ((ret != 1) || (datum > 255))
15dbaac0
JC
715 return -EINVAL;
716
717 /* A too small boot time will result in the device booting into
718 * standalone (no-host) mode before the host can take control of it,
719 * so the change will be hard to revert. This may be a desired
720 * feature (e.g to configure a very fast boot time for devices that
721 * will not be attached to a host), but dangerous. So I'm enforcing a
722 * lower limit of 20 seconds: remove and recompile the driver if this
723 * does not work for you.
724 */
725 datum = (datum < 20) ? 20 : datum;
726 cmd.data[0] = datum;
727 cmd.length = cpu_to_le16(sizeof(uint8_t));
728 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
729 CMD_TYPE_MESH_SET_BOOTTIME);
730 if (ret)
731 return ret;
732
733 return strlen(buf);
734}
735
b679aeb3
JC
736/**
737 * @brief Get function for sysfs attribute channel
738 */
739static ssize_t channel_get(struct device *dev,
740 struct device_attribute *attr, char *buf)
741{
742 struct mrvl_mesh_defaults defs;
743 int ret;
744
745 ret = mesh_get_default_parameters(dev, &defs);
746
747 if (ret)
748 return ret;
749
fb904907 750 return snprintf(buf, 12, "%d\n", le16_to_cpu(defs.channel));
b679aeb3
JC
751}
752
753/**
754 * @brief Set function for sysfs attribute channel
755 */
756static ssize_t channel_set(struct device *dev, struct device_attribute *attr,
757 const char *buf, size_t count)
758{
ab65f649 759 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
b679aeb3 760 struct cmd_ds_mesh_config cmd;
fb904907 761 uint32_t datum;
b679aeb3
JC
762 int ret;
763
764 memset(&cmd, 0, sizeof(cmd));
fb904907 765 ret = sscanf(buf, "%d", &datum);
b679aeb3
JC
766 if (ret != 1 || datum < 1 || datum > 11)
767 return -EINVAL;
768
769 *((__le16 *)&cmd.data[0]) = cpu_to_le16(datum);
770 cmd.length = cpu_to_le16(sizeof(uint16_t));
771 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
772 CMD_TYPE_MESH_SET_DEF_CHANNEL);
773 if (ret)
774 return ret;
775
776 return strlen(buf);
777}
778
15dbaac0
JC
779/**
780 * @brief Get function for sysfs attribute mesh_id
781 */
782static ssize_t mesh_id_get(struct device *dev, struct device_attribute *attr,
783 char *buf)
784{
785 struct mrvl_mesh_defaults defs;
786 int maxlen;
787 int ret;
788
789 ret = mesh_get_default_parameters(dev, &defs);
790
791 if (ret)
792 return ret;
793
243e84e9 794 if (defs.meshie.val.mesh_id_len > IEEE80211_MAX_SSID_LEN) {
df349f9f 795 lbs_pr_err("inconsistent mesh ID length");
243e84e9 796 defs.meshie.val.mesh_id_len = IEEE80211_MAX_SSID_LEN;
15dbaac0
JC
797 }
798
799 /* SSID not null terminated: reserve room for \0 + \n */
800 maxlen = defs.meshie.val.mesh_id_len + 2;
801 maxlen = (PAGE_SIZE > maxlen) ? maxlen : PAGE_SIZE;
802
803 defs.meshie.val.mesh_id[defs.meshie.val.mesh_id_len] = '\0';
804
805 return snprintf(buf, maxlen, "%s\n", defs.meshie.val.mesh_id);
806}
807
808/**
809 * @brief Set function for sysfs attribute mesh_id
810 */
811static ssize_t mesh_id_set(struct device *dev, struct device_attribute *attr,
812 const char *buf, size_t count)
813{
814 struct cmd_ds_mesh_config cmd;
815 struct mrvl_mesh_defaults defs;
816 struct mrvl_meshie *ie;
ab65f649 817 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
15dbaac0
JC
818 int len;
819 int ret;
820
243e84e9 821 if (count < 2 || count > IEEE80211_MAX_SSID_LEN + 1)
15dbaac0
JC
822 return -EINVAL;
823
824 memset(&cmd, 0, sizeof(struct cmd_ds_mesh_config));
825 ie = (struct mrvl_meshie *) &cmd.data[0];
826
827 /* fetch all other Information Element parameters */
828 ret = mesh_get_default_parameters(dev, &defs);
829
830 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
831
832 /* transfer IE elements */
833 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
834
835 len = count - 1;
836 memcpy(ie->val.mesh_id, buf, len);
837 /* SSID len */
838 ie->val.mesh_id_len = len;
839 /* IE len */
243e84e9 840 ie->len = sizeof(struct mrvl_meshie_val) - IEEE80211_MAX_SSID_LEN + len;
15dbaac0
JC
841
842 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
843 CMD_TYPE_MESH_SET_MESH_IE);
844 if (ret)
845 return ret;
846
847 return strlen(buf);
848}
849
850/**
851 * @brief Get function for sysfs attribute protocol_id
852 */
853static ssize_t protocol_id_get(struct device *dev,
854 struct device_attribute *attr, char *buf)
855{
856 struct mrvl_mesh_defaults defs;
857 int ret;
858
859 ret = mesh_get_default_parameters(dev, &defs);
860
861 if (ret)
862 return ret;
863
864 return snprintf(buf, 5, "%d\n", defs.meshie.val.active_protocol_id);
865}
866
867/**
868 * @brief Set function for sysfs attribute protocol_id
869 */
870static ssize_t protocol_id_set(struct device *dev,
871 struct device_attribute *attr, const char *buf, size_t count)
872{
873 struct cmd_ds_mesh_config cmd;
874 struct mrvl_mesh_defaults defs;
875 struct mrvl_meshie *ie;
ab65f649 876 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
15dbaac0
JC
877 uint32_t datum;
878 int ret;
879
880 memset(&cmd, 0, sizeof(cmd));
fb904907
BC
881 ret = sscanf(buf, "%d", &datum);
882 if ((ret != 1) || (datum > 255))
15dbaac0
JC
883 return -EINVAL;
884
885 /* fetch all other Information Element parameters */
886 ret = mesh_get_default_parameters(dev, &defs);
887
888 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
889
890 /* transfer IE elements */
891 ie = (struct mrvl_meshie *) &cmd.data[0];
892 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
893 /* update protocol id */
894 ie->val.active_protocol_id = datum;
895
896 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
897 CMD_TYPE_MESH_SET_MESH_IE);
898 if (ret)
899 return ret;
900
901 return strlen(buf);
902}
903
904/**
905 * @brief Get function for sysfs attribute metric_id
906 */
907static ssize_t metric_id_get(struct device *dev,
908 struct device_attribute *attr, char *buf)
909{
910 struct mrvl_mesh_defaults defs;
911 int ret;
912
913 ret = mesh_get_default_parameters(dev, &defs);
914
915 if (ret)
916 return ret;
917
918 return snprintf(buf, 5, "%d\n", defs.meshie.val.active_metric_id);
919}
920
921/**
922 * @brief Set function for sysfs attribute metric_id
923 */
924static ssize_t metric_id_set(struct device *dev, struct device_attribute *attr,
925 const char *buf, size_t count)
926{
927 struct cmd_ds_mesh_config cmd;
928 struct mrvl_mesh_defaults defs;
929 struct mrvl_meshie *ie;
ab65f649 930 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
15dbaac0
JC
931 uint32_t datum;
932 int ret;
933
934 memset(&cmd, 0, sizeof(cmd));
fb904907
BC
935 ret = sscanf(buf, "%d", &datum);
936 if ((ret != 1) || (datum > 255))
15dbaac0
JC
937 return -EINVAL;
938
939 /* fetch all other Information Element parameters */
940 ret = mesh_get_default_parameters(dev, &defs);
941
942 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
943
944 /* transfer IE elements */
945 ie = (struct mrvl_meshie *) &cmd.data[0];
946 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
947 /* update metric id */
948 ie->val.active_metric_id = datum;
949
950 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
951 CMD_TYPE_MESH_SET_MESH_IE);
952 if (ret)
953 return ret;
954
955 return strlen(buf);
956}
957
958/**
959 * @brief Get function for sysfs attribute capability
960 */
961static ssize_t capability_get(struct device *dev,
962 struct device_attribute *attr, char *buf)
963{
964 struct mrvl_mesh_defaults defs;
965 int ret;
966
967 ret = mesh_get_default_parameters(dev, &defs);
968
969 if (ret)
970 return ret;
971
972 return snprintf(buf, 5, "%d\n", defs.meshie.val.mesh_capability);
973}
974
975/**
976 * @brief Set function for sysfs attribute capability
977 */
978static ssize_t capability_set(struct device *dev, struct device_attribute *attr,
979 const char *buf, size_t count)
980{
981 struct cmd_ds_mesh_config cmd;
982 struct mrvl_mesh_defaults defs;
983 struct mrvl_meshie *ie;
ab65f649 984 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
15dbaac0
JC
985 uint32_t datum;
986 int ret;
987
988 memset(&cmd, 0, sizeof(cmd));
fb904907
BC
989 ret = sscanf(buf, "%d", &datum);
990 if ((ret != 1) || (datum > 255))
15dbaac0
JC
991 return -EINVAL;
992
993 /* fetch all other Information Element parameters */
994 ret = mesh_get_default_parameters(dev, &defs);
995
996 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
997
998 /* transfer IE elements */
999 ie = (struct mrvl_meshie *) &cmd.data[0];
1000 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
1001 /* update value */
1002 ie->val.mesh_capability = datum;
1003
1004 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
1005 CMD_TYPE_MESH_SET_MESH_IE);
1006 if (ret)
1007 return ret;
1008
1009 return strlen(buf);
1010}
1011
1012
1013static DEVICE_ATTR(bootflag, 0644, bootflag_get, bootflag_set);
1014static DEVICE_ATTR(boottime, 0644, boottime_get, boottime_set);
b679aeb3 1015static DEVICE_ATTR(channel, 0644, channel_get, channel_set);
15dbaac0
JC
1016static DEVICE_ATTR(mesh_id, 0644, mesh_id_get, mesh_id_set);
1017static DEVICE_ATTR(protocol_id, 0644, protocol_id_get, protocol_id_set);
1018static DEVICE_ATTR(metric_id, 0644, metric_id_get, metric_id_set);
1019static DEVICE_ATTR(capability, 0644, capability_get, capability_set);
1020
1021static struct attribute *boot_opts_attrs[] = {
1022 &dev_attr_bootflag.attr,
1023 &dev_attr_boottime.attr,
b679aeb3 1024 &dev_attr_channel.attr,
15dbaac0
JC
1025 NULL
1026};
1027
1028static struct attribute_group boot_opts_group = {
1029 .name = "boot_options",
1030 .attrs = boot_opts_attrs,
1031};
1032
1033static struct attribute *mesh_ie_attrs[] = {
1034 &dev_attr_mesh_id.attr,
1035 &dev_attr_protocol_id.attr,
1036 &dev_attr_metric_id.attr,
1037 &dev_attr_capability.attr,
1038 NULL
1039};
1040
1041static struct attribute_group mesh_ie_group = {
1042 .name = "mesh_ie",
1043 .attrs = mesh_ie_attrs,
1044};
1045
1046void lbs_persist_config_init(struct net_device *dev)
1047{
1048 int ret;
1049 ret = sysfs_create_group(&(dev->dev.kobj), &boot_opts_group);
1050 ret = sysfs_create_group(&(dev->dev.kobj), &mesh_ie_group);
1051}
1052
1053void lbs_persist_config_remove(struct net_device *dev)
1054{
1055 sysfs_remove_group(&(dev->dev.kobj), &boot_opts_group);
1056 sysfs_remove_group(&(dev->dev.kobj), &mesh_ie_group);
1057}
c7fe64cf
HS
1058
1059
1060
1061/***************************************************************************
1062 * Ethtool related
1063 */
1064
1065static const char *mesh_stat_strings[] = {
1066 "drop_duplicate_bcast",
1067 "drop_ttl_zero",
1068 "drop_no_fwd_route",
1069 "drop_no_buffers",
1070 "fwded_unicast_cnt",
1071 "fwded_bcast_cnt",
1072 "drop_blind_table",
1073 "tx_failed_cnt"
1074};
1075
1076void lbs_mesh_ethtool_get_stats(struct net_device *dev,
1077 struct ethtool_stats *stats, uint64_t *data)
1078{
1079 struct lbs_private *priv = dev->ml_priv;
1080 struct cmd_ds_mesh_access mesh_access;
1081 int ret;
1082
1083 lbs_deb_enter(LBS_DEB_ETHTOOL);
1084
1085 /* Get Mesh Statistics */
1086 ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_STATS, &mesh_access);
1087
1088 if (ret) {
1089 memset(data, 0, MESH_STATS_NUM*(sizeof(uint64_t)));
1090 return;
1091 }
1092
1093 priv->mstats.fwd_drop_rbt = le32_to_cpu(mesh_access.data[0]);
1094 priv->mstats.fwd_drop_ttl = le32_to_cpu(mesh_access.data[1]);
1095 priv->mstats.fwd_drop_noroute = le32_to_cpu(mesh_access.data[2]);
1096 priv->mstats.fwd_drop_nobuf = le32_to_cpu(mesh_access.data[3]);
1097 priv->mstats.fwd_unicast_cnt = le32_to_cpu(mesh_access.data[4]);
1098 priv->mstats.fwd_bcast_cnt = le32_to_cpu(mesh_access.data[5]);
1099 priv->mstats.drop_blind = le32_to_cpu(mesh_access.data[6]);
1100 priv->mstats.tx_failed_cnt = le32_to_cpu(mesh_access.data[7]);
1101
1102 data[0] = priv->mstats.fwd_drop_rbt;
1103 data[1] = priv->mstats.fwd_drop_ttl;
1104 data[2] = priv->mstats.fwd_drop_noroute;
1105 data[3] = priv->mstats.fwd_drop_nobuf;
1106 data[4] = priv->mstats.fwd_unicast_cnt;
1107 data[5] = priv->mstats.fwd_bcast_cnt;
1108 data[6] = priv->mstats.drop_blind;
1109 data[7] = priv->mstats.tx_failed_cnt;
1110
1111 lbs_deb_enter(LBS_DEB_ETHTOOL);
1112}
1113
1114int lbs_mesh_ethtool_get_sset_count(struct net_device *dev, int sset)
1115{
1116 struct lbs_private *priv = dev->ml_priv;
1117
1118 if (sset == ETH_SS_STATS && dev == priv->mesh_dev)
1119 return MESH_STATS_NUM;
1120
1121 return -EOPNOTSUPP;
1122}
1123
1124void lbs_mesh_ethtool_get_strings(struct net_device *dev,
1125 uint32_t stringset, uint8_t *s)
1126{
1127 int i;
1128
1129 lbs_deb_enter(LBS_DEB_ETHTOOL);
1130
1131 switch (stringset) {
1132 case ETH_SS_STATS:
1133 for (i = 0; i < MESH_STATS_NUM; i++) {
1134 memcpy(s + i * ETH_GSTRING_LEN,
1135 mesh_stat_strings[i],
1136 ETH_GSTRING_LEN);
1137 }
1138 break;
1139 }
1140 lbs_deb_enter(LBS_DEB_ETHTOOL);
1141}
This page took 0.241885 seconds and 5 git commands to generate.