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