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