blob: 7969d104189d1579f939d6385b880395b8387e02 [file] [log] [blame]
Joe Perches0e4e06a2011-05-02 16:49:14 -07001#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
2
Javier Cardona15dbaac2008-05-17 21:01:24 -07003#include <linux/delay.h>
4#include <linux/etherdevice.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +00005#include <linux/hardirq.h>
Javier Cardona15dbaac2008-05-17 21:01:24 -07006#include <linux/netdevice.h>
Daniel Drake1f044932009-12-24 08:11:24 +00007#include <linux/if_ether.h>
Javier Cardona15dbaac2008-05-17 21:01:24 -07008#include <linux/if_arp.h>
9#include <linux/kthread.h>
10#include <linux/kfifo.h>
Kiran Divekare86dc1c2010-06-14 22:01:26 +053011#include <net/cfg80211.h>
Javier Cardona15dbaac2008-05-17 21:01:24 -070012
Holger Schurige0e42da2009-11-25 13:10:15 +010013#include "mesh.h"
Javier Cardona15dbaac2008-05-17 21:01:24 -070014#include "decl.h"
Javier Cardona15dbaac2008-05-17 21:01:24 -070015#include "cmd.h"
16
Holger Schurige0e42da2009-11-25 13:10:15 +010017
18/***************************************************************************
19 * Mesh sysfs support
20 */
21
Randy Dunlap8973a6e2011-04-26 15:25:29 -070022/*
Holger Schurige0e42da2009-11-25 13:10:15 +010023 * Attributes exported through sysfs
24 */
25
26/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -070027 * lbs_anycast_get - Get function for sysfs attribute anycast_mask
28 * @dev: the &struct device
29 * @attr: device attributes
30 * @buf: buffer where data will be returned
Holger Schurige0e42da2009-11-25 13:10:15 +010031 */
32static ssize_t lbs_anycast_get(struct device *dev,
33 struct device_attribute *attr, char * buf)
34{
35 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
36 struct cmd_ds_mesh_access mesh_access;
37 int ret;
38
39 memset(&mesh_access, 0, sizeof(mesh_access));
40
41 ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_ANYCAST, &mesh_access);
42 if (ret)
43 return ret;
44
45 return snprintf(buf, 12, "0x%X\n", le32_to_cpu(mesh_access.data[0]));
46}
47
48/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -070049 * lbs_anycast_set - Set function for sysfs attribute anycast_mask
50 * @dev: the &struct device
51 * @attr: device attributes
52 * @buf: buffer that contains new attribute value
53 * @count: size of buffer
Holger Schurige0e42da2009-11-25 13:10:15 +010054 */
55static ssize_t lbs_anycast_set(struct device *dev,
56 struct device_attribute *attr, const char * buf, size_t count)
57{
58 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
59 struct cmd_ds_mesh_access mesh_access;
60 uint32_t datum;
61 int ret;
62
63 memset(&mesh_access, 0, sizeof(mesh_access));
64 sscanf(buf, "%x", &datum);
65 mesh_access.data[0] = cpu_to_le32(datum);
66
67 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_ANYCAST, &mesh_access);
68 if (ret)
69 return ret;
70
71 return strlen(buf);
72}
73
74/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -070075 * lbs_prb_rsp_limit_get - Get function for sysfs attribute prb_rsp_limit
76 * @dev: the &struct device
77 * @attr: device attributes
78 * @buf: buffer where data will be returned
Holger Schurige0e42da2009-11-25 13:10:15 +010079 */
80static ssize_t lbs_prb_rsp_limit_get(struct device *dev,
81 struct device_attribute *attr, char *buf)
82{
83 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
84 struct cmd_ds_mesh_access mesh_access;
85 int ret;
86 u32 retry_limit;
87
88 memset(&mesh_access, 0, sizeof(mesh_access));
89 mesh_access.data[0] = cpu_to_le32(CMD_ACT_GET);
90
91 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT,
92 &mesh_access);
93 if (ret)
94 return ret;
95
96 retry_limit = le32_to_cpu(mesh_access.data[1]);
97 return snprintf(buf, 10, "%d\n", retry_limit);
98}
99
100/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700101 * lbs_prb_rsp_limit_set - Set function for sysfs attribute prb_rsp_limit
102 * @dev: the &struct device
103 * @attr: device attributes
104 * @buf: buffer that contains new attribute value
105 * @count: size of buffer
Holger Schurige0e42da2009-11-25 13:10:15 +0100106 */
107static ssize_t lbs_prb_rsp_limit_set(struct device *dev,
108 struct device_attribute *attr, const char *buf, size_t count)
109{
110 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
111 struct cmd_ds_mesh_access mesh_access;
112 int ret;
113 unsigned long retry_limit;
114
115 memset(&mesh_access, 0, sizeof(mesh_access));
116 mesh_access.data[0] = cpu_to_le32(CMD_ACT_SET);
117
118 if (!strict_strtoul(buf, 10, &retry_limit))
119 return -ENOTSUPP;
120 if (retry_limit > 15)
121 return -ENOTSUPP;
122
123 mesh_access.data[1] = cpu_to_le32(retry_limit);
124
125 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT,
126 &mesh_access);
127 if (ret)
128 return ret;
129
130 return strlen(buf);
131}
132
133/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700134 * lbs_mesh_get - Get function for sysfs attribute mesh
135 * @dev: the &struct device
136 * @attr: device attributes
137 * @buf: buffer where data will be returned
Holger Schurige0e42da2009-11-25 13:10:15 +0100138 */
139static ssize_t lbs_mesh_get(struct device *dev,
140 struct device_attribute *attr, char * buf)
141{
142 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
143 return snprintf(buf, 5, "0x%X\n", !!priv->mesh_dev);
144}
145
146/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700147 * lbs_mesh_set - Set function for sysfs attribute mesh
148 * @dev: the &struct device
149 * @attr: device attributes
150 * @buf: buffer that contains new attribute value
151 * @count: size of buffer
Holger Schurige0e42da2009-11-25 13:10:15 +0100152 */
153static ssize_t lbs_mesh_set(struct device *dev,
154 struct device_attribute *attr, const char * buf, size_t count)
155{
156 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
157 int enable;
158 int ret, action = CMD_ACT_MESH_CONFIG_STOP;
159
160 sscanf(buf, "%x", &enable);
161 enable = !!enable;
162 if (enable == !!priv->mesh_dev)
163 return count;
164 if (enable)
165 action = CMD_ACT_MESH_CONFIG_START;
166 ret = lbs_mesh_config(priv, action, priv->channel);
167 if (ret)
168 return ret;
169
170 if (enable)
171 lbs_add_mesh(priv);
172 else
173 lbs_remove_mesh(priv);
174
175 return count;
176}
177
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700178/*
Holger Schurige0e42da2009-11-25 13:10:15 +0100179 * lbs_mesh attribute to be exported per ethX interface
180 * through sysfs (/sys/class/net/ethX/lbs_mesh)
181 */
182static DEVICE_ATTR(lbs_mesh, 0644, lbs_mesh_get, lbs_mesh_set);
183
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700184/*
Holger Schurige0e42da2009-11-25 13:10:15 +0100185 * anycast_mask attribute to be exported per mshX interface
186 * through sysfs (/sys/class/net/mshX/anycast_mask)
187 */
188static DEVICE_ATTR(anycast_mask, 0644, lbs_anycast_get, lbs_anycast_set);
189
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700190/*
Holger Schurige0e42da2009-11-25 13:10:15 +0100191 * prb_rsp_limit attribute to be exported per mshX interface
192 * through sysfs (/sys/class/net/mshX/prb_rsp_limit)
193 */
194static DEVICE_ATTR(prb_rsp_limit, 0644, lbs_prb_rsp_limit_get,
195 lbs_prb_rsp_limit_set);
196
197static struct attribute *lbs_mesh_sysfs_entries[] = {
198 &dev_attr_anycast_mask.attr,
199 &dev_attr_prb_rsp_limit.attr,
200 NULL,
201};
202
203static struct attribute_group lbs_mesh_attr_group = {
204 .attrs = lbs_mesh_sysfs_entries,
205};
206
207
208
209/***************************************************************************
210 * Initializing and starting, stopping mesh
211 */
212
213/*
214 * Check mesh FW version and appropriately send the mesh start
215 * command
216 */
217int lbs_init_mesh(struct lbs_private *priv)
218{
219 struct net_device *dev = priv->dev;
220 int ret = 0;
221
222 lbs_deb_enter(LBS_DEB_MESH);
223
Holger Schurig602114a2009-12-02 15:26:01 +0100224 priv->mesh_connect_status = LBS_DISCONNECTED;
225
Holger Schurigc24ef462009-12-02 15:25:56 +0100226 /* Determine mesh_fw_ver from fwrelease and fwcapinfo */
227 /* 5.0.16p0 9.0.0.p0 is known to NOT support any mesh */
228 /* 5.110.22 have mesh command with 0xa3 command id */
229 /* 10.0.0.p0 FW brings in mesh config command with different id */
230 /* Check FW version MSB and initialize mesh_fw_ver */
231 if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V5) {
Holger Schurige0e42da2009-11-25 13:10:15 +0100232 /* Enable mesh, if supported, and work out which TLV it uses.
233 0x100 + 291 is an unofficial value used in 5.110.20.pXX
234 0x100 + 37 is the official value used in 5.110.21.pXX
235 but we check them in that order because 20.pXX doesn't
236 give an error -- it just silently fails. */
237
238 /* 5.110.20.pXX firmware will fail the command if the channel
239 doesn't match the existing channel. But only if the TLV
240 is correct. If the channel is wrong, _BOTH_ versions will
241 give an error to 0x100+291, and allow 0x100+37 to succeed.
242 It's just that 5.110.20.pXX will not have done anything
243 useful */
244
245 priv->mesh_tlv = TLV_TYPE_OLD_MESH_ID;
246 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
247 priv->channel)) {
248 priv->mesh_tlv = TLV_TYPE_MESH_ID;
249 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
250 priv->channel))
251 priv->mesh_tlv = 0;
252 }
Holger Schurigc24ef462009-12-02 15:25:56 +0100253 } else
254 if ((MRVL_FW_MAJOR_REV(priv->fwrelease) >= MRVL_FW_V10) &&
255 (priv->fwcapinfo & MESH_CAPINFO_ENABLE_MASK)) {
Holger Schurige0e42da2009-11-25 13:10:15 +0100256 /* 10.0.0.pXX new firmwares should succeed with TLV
257 * 0x100+37; Do not invoke command with old TLV.
258 */
259 priv->mesh_tlv = TLV_TYPE_MESH_ID;
260 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
261 priv->channel))
262 priv->mesh_tlv = 0;
263 }
Holger Schurigc24ef462009-12-02 15:25:56 +0100264
265
Holger Schurige0e42da2009-11-25 13:10:15 +0100266 if (priv->mesh_tlv) {
Holger Schurige4da1a82009-12-02 15:26:00 +0100267 sprintf(priv->mesh_ssid, "mesh");
268 priv->mesh_ssid_len = 4;
269
Holger Schurige0e42da2009-11-25 13:10:15 +0100270 lbs_add_mesh(priv);
271
272 if (device_create_file(&dev->dev, &dev_attr_lbs_mesh))
Joe Perchesf3a57fd2011-05-02 16:49:15 -0700273 netdev_err(dev, "cannot register lbs_mesh attribute\n");
Holger Schurige0e42da2009-11-25 13:10:15 +0100274
275 ret = 1;
276 }
277
278 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
279 return ret;
280}
281
282
283int lbs_deinit_mesh(struct lbs_private *priv)
284{
285 struct net_device *dev = priv->dev;
286 int ret = 0;
287
288 lbs_deb_enter(LBS_DEB_MESH);
289
290 if (priv->mesh_tlv) {
291 device_remove_file(&dev->dev, &dev_attr_lbs_mesh);
292 ret = 1;
293 }
294
295 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
296 return ret;
297}
298
299
300/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700301 * lbs_mesh_stop - close the mshX interface
Holger Schurige0e42da2009-11-25 13:10:15 +0100302 *
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700303 * @dev: A pointer to &net_device structure
304 * returns: 0
Holger Schurige0e42da2009-11-25 13:10:15 +0100305 */
306static int lbs_mesh_stop(struct net_device *dev)
307{
308 struct lbs_private *priv = dev->ml_priv;
309
310 lbs_deb_enter(LBS_DEB_MESH);
311 spin_lock_irq(&priv->driver_lock);
312
313 priv->mesh_open = 0;
314 priv->mesh_connect_status = LBS_DISCONNECTED;
315
316 netif_stop_queue(dev);
317 netif_carrier_off(dev);
318
319 spin_unlock_irq(&priv->driver_lock);
320
321 schedule_work(&priv->mcast_work);
322
323 lbs_deb_leave(LBS_DEB_MESH);
324 return 0;
325}
326
327/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700328 * lbs_mesh_dev_open - open the mshX interface
Holger Schurige0e42da2009-11-25 13:10:15 +0100329 *
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700330 * @dev: A pointer to &net_device structure
331 * returns: 0 or -EBUSY if monitor mode active
Holger Schurige0e42da2009-11-25 13:10:15 +0100332 */
333static int lbs_mesh_dev_open(struct net_device *dev)
334{
335 struct lbs_private *priv = dev->ml_priv;
336 int ret = 0;
337
338 lbs_deb_enter(LBS_DEB_NET);
339
340 spin_lock_irq(&priv->driver_lock);
341
Kiran Divekare86dc1c2010-06-14 22:01:26 +0530342 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR) {
Holger Schurige0e42da2009-11-25 13:10:15 +0100343 ret = -EBUSY;
344 goto out;
345 }
346
347 priv->mesh_open = 1;
348 priv->mesh_connect_status = LBS_CONNECTED;
349 netif_carrier_on(dev);
350
351 if (!priv->tx_pending_len)
352 netif_wake_queue(dev);
353 out:
354
355 spin_unlock_irq(&priv->driver_lock);
356 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
357 return ret;
358}
359
360static const struct net_device_ops mesh_netdev_ops = {
361 .ndo_open = lbs_mesh_dev_open,
362 .ndo_stop = lbs_mesh_stop,
363 .ndo_start_xmit = lbs_hard_start_xmit,
364 .ndo_set_mac_address = lbs_set_mac_address,
365 .ndo_set_multicast_list = lbs_set_multicast_list,
366};
367
368/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700369 * lbs_add_mesh - add mshX interface
Holger Schurige0e42da2009-11-25 13:10:15 +0100370 *
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700371 * @priv: A pointer to the &struct lbs_private structure
372 * returns: 0 if successful, -X otherwise
Holger Schurige0e42da2009-11-25 13:10:15 +0100373 */
374int lbs_add_mesh(struct lbs_private *priv)
375{
376 struct net_device *mesh_dev = NULL;
377 int ret = 0;
378
379 lbs_deb_enter(LBS_DEB_MESH);
380
381 /* Allocate a virtual mesh device */
382 mesh_dev = alloc_netdev(0, "msh%d", ether_setup);
383 if (!mesh_dev) {
384 lbs_deb_mesh("init mshX device failed\n");
385 ret = -ENOMEM;
386 goto done;
387 }
388 mesh_dev->ml_priv = priv;
389 priv->mesh_dev = mesh_dev;
390
391 mesh_dev->netdev_ops = &mesh_netdev_ops;
392 mesh_dev->ethtool_ops = &lbs_ethtool_ops;
Daniel Drake1f044932009-12-24 08:11:24 +0000393 memcpy(mesh_dev->dev_addr, priv->dev->dev_addr, ETH_ALEN);
Holger Schurige0e42da2009-11-25 13:10:15 +0100394
395 SET_NETDEV_DEV(priv->mesh_dev, priv->dev->dev.parent);
396
Holger Schurige0e42da2009-11-25 13:10:15 +0100397 mesh_dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
398 /* Register virtual mesh interface */
399 ret = register_netdev(mesh_dev);
400 if (ret) {
Joe Perches0e4e06a2011-05-02 16:49:14 -0700401 pr_err("cannot register mshX virtual interface\n");
Holger Schurige0e42da2009-11-25 13:10:15 +0100402 goto err_free;
403 }
404
405 ret = sysfs_create_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
406 if (ret)
407 goto err_unregister;
408
409 lbs_persist_config_init(mesh_dev);
410
411 /* Everything successful */
412 ret = 0;
413 goto done;
414
415err_unregister:
416 unregister_netdev(mesh_dev);
417
418err_free:
419 free_netdev(mesh_dev);
420
421done:
422 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
423 return ret;
424}
425
426void lbs_remove_mesh(struct lbs_private *priv)
427{
428 struct net_device *mesh_dev;
429
430 mesh_dev = priv->mesh_dev;
431 if (!mesh_dev)
432 return;
433
434 lbs_deb_enter(LBS_DEB_MESH);
435 netif_stop_queue(mesh_dev);
436 netif_carrier_off(mesh_dev);
437 sysfs_remove_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
438 lbs_persist_config_remove(mesh_dev);
439 unregister_netdev(mesh_dev);
440 priv->mesh_dev = NULL;
441 free_netdev(mesh_dev);
442 lbs_deb_leave(LBS_DEB_MESH);
443}
444
445
446
447/***************************************************************************
448 * Sending and receiving
449 */
450struct net_device *lbs_mesh_set_dev(struct lbs_private *priv,
451 struct net_device *dev, struct rxpd *rxpd)
452{
453 if (priv->mesh_dev) {
Holger Schurigc24ef462009-12-02 15:25:56 +0100454 if (priv->mesh_tlv == TLV_TYPE_OLD_MESH_ID) {
Holger Schurige0e42da2009-11-25 13:10:15 +0100455 if (rxpd->rx_control & RxPD_MESH_FRAME)
456 dev = priv->mesh_dev;
Holger Schurigc24ef462009-12-02 15:25:56 +0100457 } else if (priv->mesh_tlv == TLV_TYPE_MESH_ID) {
Holger Schurige0e42da2009-11-25 13:10:15 +0100458 if (rxpd->u.bss.bss_num == MESH_IFACE_ID)
459 dev = priv->mesh_dev;
460 }
461 }
462 return dev;
463}
464
465
466void lbs_mesh_set_txpd(struct lbs_private *priv,
467 struct net_device *dev, struct txpd *txpd)
468{
469 if (dev == priv->mesh_dev) {
Holger Schurigc24ef462009-12-02 15:25:56 +0100470 if (priv->mesh_tlv == TLV_TYPE_OLD_MESH_ID)
Holger Schurige0e42da2009-11-25 13:10:15 +0100471 txpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
Holger Schurigc24ef462009-12-02 15:25:56 +0100472 else if (priv->mesh_tlv == TLV_TYPE_MESH_ID)
Holger Schurige0e42da2009-11-25 13:10:15 +0100473 txpd->u.bss.bss_num = MESH_IFACE_ID;
474 }
475}
476
477
478/***************************************************************************
Holger Schurigece1e3c2009-11-25 13:11:16 +0100479 * Mesh command handling
480 */
481
Dan Williams52148652010-07-27 13:01:47 -0700482/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700483 * lbs_mesh_bt_add_del - Add or delete Mesh Blinding Table entries
Dan Williams52148652010-07-27 13:01:47 -0700484 *
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700485 * @priv: A pointer to &struct lbs_private structure
486 * @add: TRUE to add the entry, FALSE to delete it
487 * @addr1: Destination address to blind or unblind
Dan Williams52148652010-07-27 13:01:47 -0700488 *
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700489 * returns: 0 on success, error on failure
Dan Williams52148652010-07-27 13:01:47 -0700490 */
491int lbs_mesh_bt_add_del(struct lbs_private *priv, bool add, u8 *addr1)
Holger Schurigece1e3c2009-11-25 13:11:16 +0100492{
Dan Williams52148652010-07-27 13:01:47 -0700493 struct cmd_ds_bt_access cmd;
494 int ret = 0;
Holger Schurigece1e3c2009-11-25 13:11:16 +0100495
Dan Williams52148652010-07-27 13:01:47 -0700496 lbs_deb_enter(LBS_DEB_CMD);
Holger Schurigece1e3c2009-11-25 13:11:16 +0100497
Dan Williams52148652010-07-27 13:01:47 -0700498 BUG_ON(addr1 == NULL);
499
500 memset(&cmd, 0, sizeof(cmd));
501 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
502 memcpy(cmd.addr1, addr1, ETH_ALEN);
503 if (add) {
504 cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_ADD);
Holger Schurigece1e3c2009-11-25 13:11:16 +0100505 lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr",
Dan Williams52148652010-07-27 13:01:47 -0700506 addr1, ETH_ALEN);
507 } else {
508 cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_DEL);
Holger Schurigece1e3c2009-11-25 13:11:16 +0100509 lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr",
Dan Williams52148652010-07-27 13:01:47 -0700510 addr1, ETH_ALEN);
Holger Schurigece1e3c2009-11-25 13:11:16 +0100511 }
Dan Williams52148652010-07-27 13:01:47 -0700512
513 ret = lbs_cmd_with_response(priv, CMD_BT_ACCESS, &cmd);
514
515 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
516 return ret;
517}
518
519/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700520 * lbs_mesh_bt_reset - Reset/clear the mesh blinding table
Dan Williams52148652010-07-27 13:01:47 -0700521 *
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700522 * @priv: A pointer to &struct lbs_private structure
Dan Williams52148652010-07-27 13:01:47 -0700523 *
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700524 * returns: 0 on success, error on failure
Dan Williams52148652010-07-27 13:01:47 -0700525 */
526int lbs_mesh_bt_reset(struct lbs_private *priv)
527{
528 struct cmd_ds_bt_access cmd;
529 int ret = 0;
530
531 lbs_deb_enter(LBS_DEB_CMD);
532
533 memset(&cmd, 0, sizeof(cmd));
534 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
535 cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_RESET);
536
537 ret = lbs_cmd_with_response(priv, CMD_BT_ACCESS, &cmd);
538
539 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
540 return ret;
541}
542
543/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700544 * lbs_mesh_bt_get_inverted - Gets the inverted status of the mesh
545 * blinding table
Dan Williams52148652010-07-27 13:01:47 -0700546 *
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700547 * Normally the firmware "blinds" or ignores traffic from mesh nodes in the
548 * table, but an inverted table allows *only* traffic from nodes listed in
549 * the table.
Dan Williams52148652010-07-27 13:01:47 -0700550 *
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700551 * @priv: A pointer to &struct lbs_private structure
552 * @inverted: On success, TRUE if the blinding table is inverted,
553 * FALSE if it is not inverted
Dan Williams52148652010-07-27 13:01:47 -0700554 *
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700555 * returns: 0 on success, error on failure
Dan Williams52148652010-07-27 13:01:47 -0700556 */
557int lbs_mesh_bt_get_inverted(struct lbs_private *priv, bool *inverted)
558{
559 struct cmd_ds_bt_access cmd;
560 int ret = 0;
561
562 lbs_deb_enter(LBS_DEB_CMD);
563
564 BUG_ON(inverted == NULL);
565
566 memset(&cmd, 0, sizeof(cmd));
567 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
568 cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_GET_INVERT);
569
570 ret = lbs_cmd_with_response(priv, CMD_BT_ACCESS, &cmd);
571 if (ret == 0)
572 *inverted = !!cmd.id;
573
574 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
575 return ret;
576}
577
578/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700579 * lbs_mesh_bt_set_inverted - Sets the inverted status of the mesh
580 * blinding table
Dan Williams52148652010-07-27 13:01:47 -0700581 *
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700582 * Normally the firmware "blinds" or ignores traffic from mesh nodes in the
583 * table, but an inverted table allows *only* traffic from nodes listed in
584 * the table.
Dan Williams52148652010-07-27 13:01:47 -0700585 *
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700586 * @priv: A pointer to &struct lbs_private structure
587 * @inverted: TRUE to invert the blinding table (only traffic from
588 * listed nodes allowed), FALSE to return it
589 * to normal state (listed nodes ignored)
Dan Williams52148652010-07-27 13:01:47 -0700590 *
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700591 * returns: 0 on success, error on failure
Dan Williams52148652010-07-27 13:01:47 -0700592 */
593int lbs_mesh_bt_set_inverted(struct lbs_private *priv, bool inverted)
594{
595 struct cmd_ds_bt_access cmd;
596 int ret = 0;
597
598 lbs_deb_enter(LBS_DEB_CMD);
599
600 memset(&cmd, 0, sizeof(cmd));
601 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
602 cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_SET_INVERT);
John W. Linville65a602d2010-09-15 15:40:12 -0400603 cmd.id = cpu_to_le32(!!inverted);
Dan Williams52148652010-07-27 13:01:47 -0700604
605 ret = lbs_cmd_with_response(priv, CMD_BT_ACCESS, &cmd);
606
607 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
608 return ret;
609}
610
611/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700612 * lbs_mesh_bt_get_entry - List an entry in the mesh blinding table
Dan Williams52148652010-07-27 13:01:47 -0700613 *
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700614 * @priv: A pointer to &struct lbs_private structure
615 * @id: The ID of the entry to list
616 * @addr1: MAC address associated with the table entry
Dan Williams52148652010-07-27 13:01:47 -0700617 *
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700618 * returns: 0 on success, error on failure
Dan Williams52148652010-07-27 13:01:47 -0700619 */
620int lbs_mesh_bt_get_entry(struct lbs_private *priv, u32 id, u8 *addr1)
621{
622 struct cmd_ds_bt_access cmd;
623 int ret = 0;
624
625 lbs_deb_enter(LBS_DEB_CMD);
626
627 BUG_ON(addr1 == NULL);
628
629 memset(&cmd, 0, sizeof(cmd));
630 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
631 cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_SET_INVERT);
632 cmd.id = cpu_to_le32(id);
633
634 ret = lbs_cmd_with_response(priv, CMD_BT_ACCESS, &cmd);
635 if (ret == 0)
636 memcpy(addr1, cmd.addr1, sizeof(cmd.addr1));
637
638 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
639 return ret;
Holger Schurigece1e3c2009-11-25 13:11:16 +0100640}
641
Dan Williamsa6bb1bc2010-07-27 13:03:46 -0700642/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700643 * lbs_cmd_fwt_access - Access the mesh forwarding table
Dan Williamsa6bb1bc2010-07-27 13:03:46 -0700644 *
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700645 * @priv: A pointer to &struct lbs_private structure
646 * @cmd_action: The forwarding table action to perform
647 * @cmd: The pre-filled FWT_ACCESS command
Dan Williamsa6bb1bc2010-07-27 13:03:46 -0700648 *
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700649 * returns: 0 on success and 'cmd' will be filled with the
650 * firmware's response
Dan Williamsa6bb1bc2010-07-27 13:03:46 -0700651 */
652int lbs_cmd_fwt_access(struct lbs_private *priv, u16 cmd_action,
653 struct cmd_ds_fwt_access *cmd)
Holger Schurigece1e3c2009-11-25 13:11:16 +0100654{
Dan Williamsa6bb1bc2010-07-27 13:03:46 -0700655 int ret;
656
Holger Schurigece1e3c2009-11-25 13:11:16 +0100657 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
658
Dan Williamsa6bb1bc2010-07-27 13:03:46 -0700659 cmd->hdr.command = cpu_to_le16(CMD_FWT_ACCESS);
660 cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access));
661 cmd->hdr.result = 0;
662 cmd->action = cpu_to_le16(cmd_action);
Holger Schurigece1e3c2009-11-25 13:11:16 +0100663
Dan Williamsa6bb1bc2010-07-27 13:03:46 -0700664 ret = lbs_cmd_with_response(priv, CMD_FWT_ACCESS, cmd);
Holger Schurigece1e3c2009-11-25 13:11:16 +0100665
Dan Williamsa6bb1bc2010-07-27 13:03:46 -0700666 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Holger Schurigece1e3c2009-11-25 13:11:16 +0100667 return 0;
668}
669
670int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
671 struct cmd_ds_mesh_access *cmd)
672{
673 int ret;
674
675 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
676
677 cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
678 cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
679 cmd->hdr.result = 0;
680
681 cmd->action = cpu_to_le16(cmd_action);
682
683 ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
684
685 lbs_deb_leave(LBS_DEB_CMD);
686 return ret;
687}
688
689static int __lbs_mesh_config_send(struct lbs_private *priv,
690 struct cmd_ds_mesh_config *cmd,
691 uint16_t action, uint16_t type)
692{
693 int ret;
694 u16 command = CMD_MESH_CONFIG_OLD;
695
696 lbs_deb_enter(LBS_DEB_CMD);
697
698 /*
699 * Command id is 0xac for v10 FW along with mesh interface
700 * id in bits 14-13-12.
701 */
Holger Schurigc24ef462009-12-02 15:25:56 +0100702 if (priv->mesh_tlv == TLV_TYPE_MESH_ID)
Holger Schurigece1e3c2009-11-25 13:11:16 +0100703 command = CMD_MESH_CONFIG |
704 (MESH_IFACE_ID << MESH_IFACE_BIT_OFFSET);
705
706 cmd->hdr.command = cpu_to_le16(command);
707 cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config));
708 cmd->hdr.result = 0;
709
710 cmd->type = cpu_to_le16(type);
711 cmd->action = cpu_to_le16(action);
712
713 ret = lbs_cmd_with_response(priv, command, cmd);
714
715 lbs_deb_leave(LBS_DEB_CMD);
716 return ret;
717}
718
719int lbs_mesh_config_send(struct lbs_private *priv,
720 struct cmd_ds_mesh_config *cmd,
721 uint16_t action, uint16_t type)
722{
723 int ret;
724
725 if (!(priv->fwcapinfo & FW_CAPINFO_PERSISTENT_CONFIG))
726 return -EOPNOTSUPP;
727
728 ret = __lbs_mesh_config_send(priv, cmd, action, type);
729 return ret;
730}
731
732/* This function is the CMD_MESH_CONFIG legacy function. It only handles the
733 * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG
734 * are all handled by preparing a struct cmd_ds_mesh_config and passing it to
735 * lbs_mesh_config_send.
736 */
737int lbs_mesh_config(struct lbs_private *priv, uint16_t action, uint16_t chan)
738{
739 struct cmd_ds_mesh_config cmd;
740 struct mrvl_meshie *ie;
741 DECLARE_SSID_BUF(ssid);
742
743 memset(&cmd, 0, sizeof(cmd));
744 cmd.channel = cpu_to_le16(chan);
745 ie = (struct mrvl_meshie *)cmd.data;
746
747 switch (action) {
748 case CMD_ACT_MESH_CONFIG_START:
749 ie->id = WLAN_EID_GENERIC;
750 ie->val.oui[0] = 0x00;
751 ie->val.oui[1] = 0x50;
752 ie->val.oui[2] = 0x43;
753 ie->val.type = MARVELL_MESH_IE_TYPE;
754 ie->val.subtype = MARVELL_MESH_IE_SUBTYPE;
755 ie->val.version = MARVELL_MESH_IE_VERSION;
756 ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP;
757 ie->val.active_metric_id = MARVELL_MESH_METRIC_ID;
758 ie->val.mesh_capability = MARVELL_MESH_CAPABILITY;
759 ie->val.mesh_id_len = priv->mesh_ssid_len;
760 memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len);
761 ie->len = sizeof(struct mrvl_meshie_val) -
762 IEEE80211_MAX_SSID_LEN + priv->mesh_ssid_len;
763 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val));
764 break;
765 case CMD_ACT_MESH_CONFIG_STOP:
766 break;
767 default:
768 return -1;
769 }
770 lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n",
771 action, priv->mesh_tlv, chan,
772 print_ssid(ssid, priv->mesh_ssid, priv->mesh_ssid_len));
773
774 return __lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv);
775}
776
777
778
779/***************************************************************************
Holger Schurige0e42da2009-11-25 13:10:15 +0100780 * Persistent configuration support
781 */
782
Javier Cardona15dbaac2008-05-17 21:01:24 -0700783static int mesh_get_default_parameters(struct device *dev,
784 struct mrvl_mesh_defaults *defs)
785{
Kiran Divekarab65f642009-02-19 19:32:39 -0500786 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
Javier Cardona15dbaac2008-05-17 21:01:24 -0700787 struct cmd_ds_mesh_config cmd;
788 int ret;
789
790 memset(&cmd, 0, sizeof(struct cmd_ds_mesh_config));
791 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_GET,
792 CMD_TYPE_MESH_GET_DEFAULTS);
793
794 if (ret)
795 return -EOPNOTSUPP;
796
797 memcpy(defs, &cmd.data[0], sizeof(struct mrvl_mesh_defaults));
798
799 return 0;
800}
801
802/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700803 * bootflag_get - Get function for sysfs attribute bootflag
804 * @dev: the &struct device
805 * @attr: device attributes
806 * @buf: buffer where data will be returned
Javier Cardona15dbaac2008-05-17 21:01:24 -0700807 */
808static ssize_t bootflag_get(struct device *dev,
809 struct device_attribute *attr, char *buf)
810{
811 struct mrvl_mesh_defaults defs;
812 int ret;
813
814 ret = mesh_get_default_parameters(dev, &defs);
815
816 if (ret)
817 return ret;
818
Brian Cavagnolofb904902008-07-16 12:15:26 -0700819 return snprintf(buf, 12, "%d\n", le32_to_cpu(defs.bootflag));
Javier Cardona15dbaac2008-05-17 21:01:24 -0700820}
821
822/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700823 * bootflag_set - Set function for sysfs attribute bootflag
824 * @dev: the &struct device
825 * @attr: device attributes
826 * @buf: buffer that contains new attribute value
827 * @count: size of buffer
Javier Cardona15dbaac2008-05-17 21:01:24 -0700828 */
829static ssize_t bootflag_set(struct device *dev, struct device_attribute *attr,
830 const char *buf, size_t count)
831{
Kiran Divekarab65f642009-02-19 19:32:39 -0500832 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
Javier Cardona15dbaac2008-05-17 21:01:24 -0700833 struct cmd_ds_mesh_config cmd;
834 uint32_t datum;
835 int ret;
836
837 memset(&cmd, 0, sizeof(cmd));
Brian Cavagnolofb904902008-07-16 12:15:26 -0700838 ret = sscanf(buf, "%d", &datum);
839 if ((ret != 1) || (datum > 1))
Javier Cardona15dbaac2008-05-17 21:01:24 -0700840 return -EINVAL;
841
842 *((__le32 *)&cmd.data[0]) = cpu_to_le32(!!datum);
843 cmd.length = cpu_to_le16(sizeof(uint32_t));
844 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
845 CMD_TYPE_MESH_SET_BOOTFLAG);
846 if (ret)
847 return ret;
848
849 return strlen(buf);
850}
851
852/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700853 * boottime_get - Get function for sysfs attribute boottime
854 * @dev: the &struct device
855 * @attr: device attributes
856 * @buf: buffer where data will be returned
Javier Cardona15dbaac2008-05-17 21:01:24 -0700857 */
858static ssize_t boottime_get(struct device *dev,
859 struct device_attribute *attr, char *buf)
860{
861 struct mrvl_mesh_defaults defs;
862 int ret;
863
864 ret = mesh_get_default_parameters(dev, &defs);
865
866 if (ret)
867 return ret;
868
Brian Cavagnolofb904902008-07-16 12:15:26 -0700869 return snprintf(buf, 12, "%d\n", defs.boottime);
Javier Cardona15dbaac2008-05-17 21:01:24 -0700870}
871
872/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700873 * boottime_set - Set function for sysfs attribute boottime
874 * @dev: the &struct device
875 * @attr: device attributes
876 * @buf: buffer that contains new attribute value
877 * @count: size of buffer
Javier Cardona15dbaac2008-05-17 21:01:24 -0700878 */
879static ssize_t boottime_set(struct device *dev,
880 struct device_attribute *attr, const char *buf, size_t count)
881{
Kiran Divekarab65f642009-02-19 19:32:39 -0500882 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
Javier Cardona15dbaac2008-05-17 21:01:24 -0700883 struct cmd_ds_mesh_config cmd;
884 uint32_t datum;
885 int ret;
886
887 memset(&cmd, 0, sizeof(cmd));
Brian Cavagnolofb904902008-07-16 12:15:26 -0700888 ret = sscanf(buf, "%d", &datum);
889 if ((ret != 1) || (datum > 255))
Javier Cardona15dbaac2008-05-17 21:01:24 -0700890 return -EINVAL;
891
892 /* A too small boot time will result in the device booting into
893 * standalone (no-host) mode before the host can take control of it,
894 * so the change will be hard to revert. This may be a desired
895 * feature (e.g to configure a very fast boot time for devices that
896 * will not be attached to a host), but dangerous. So I'm enforcing a
897 * lower limit of 20 seconds: remove and recompile the driver if this
898 * does not work for you.
899 */
900 datum = (datum < 20) ? 20 : datum;
901 cmd.data[0] = datum;
902 cmd.length = cpu_to_le16(sizeof(uint8_t));
903 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
904 CMD_TYPE_MESH_SET_BOOTTIME);
905 if (ret)
906 return ret;
907
908 return strlen(buf);
909}
910
911/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700912 * channel_get - Get function for sysfs attribute channel
913 * @dev: the &struct device
914 * @attr: device attributes
915 * @buf: buffer where data will be returned
Javier Cardonab679aeb2008-05-20 15:18:49 -0700916 */
917static ssize_t channel_get(struct device *dev,
918 struct device_attribute *attr, char *buf)
919{
920 struct mrvl_mesh_defaults defs;
921 int ret;
922
923 ret = mesh_get_default_parameters(dev, &defs);
924
925 if (ret)
926 return ret;
927
Brian Cavagnolofb904902008-07-16 12:15:26 -0700928 return snprintf(buf, 12, "%d\n", le16_to_cpu(defs.channel));
Javier Cardonab679aeb2008-05-20 15:18:49 -0700929}
930
931/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700932 * channel_set - Set function for sysfs attribute channel
933 * @dev: the &struct device
934 * @attr: device attributes
935 * @buf: buffer that contains new attribute value
936 * @count: size of buffer
Javier Cardonab679aeb2008-05-20 15:18:49 -0700937 */
938static ssize_t channel_set(struct device *dev, struct device_attribute *attr,
939 const char *buf, size_t count)
940{
Kiran Divekarab65f642009-02-19 19:32:39 -0500941 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
Javier Cardonab679aeb2008-05-20 15:18:49 -0700942 struct cmd_ds_mesh_config cmd;
Brian Cavagnolofb904902008-07-16 12:15:26 -0700943 uint32_t datum;
Javier Cardonab679aeb2008-05-20 15:18:49 -0700944 int ret;
945
946 memset(&cmd, 0, sizeof(cmd));
Brian Cavagnolofb904902008-07-16 12:15:26 -0700947 ret = sscanf(buf, "%d", &datum);
Javier Cardonab679aeb2008-05-20 15:18:49 -0700948 if (ret != 1 || datum < 1 || datum > 11)
949 return -EINVAL;
950
951 *((__le16 *)&cmd.data[0]) = cpu_to_le16(datum);
952 cmd.length = cpu_to_le16(sizeof(uint16_t));
953 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
954 CMD_TYPE_MESH_SET_DEF_CHANNEL);
955 if (ret)
956 return ret;
957
958 return strlen(buf);
959}
960
961/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700962 * mesh_id_get - Get function for sysfs attribute mesh_id
963 * @dev: the &struct device
964 * @attr: device attributes
965 * @buf: buffer where data will be returned
Javier Cardona15dbaac2008-05-17 21:01:24 -0700966 */
967static ssize_t mesh_id_get(struct device *dev, struct device_attribute *attr,
968 char *buf)
969{
970 struct mrvl_mesh_defaults defs;
Javier Cardona15dbaac2008-05-17 21:01:24 -0700971 int ret;
972
973 ret = mesh_get_default_parameters(dev, &defs);
974
975 if (ret)
976 return ret;
977
Holger Schurig243e84e2009-10-22 15:30:47 +0200978 if (defs.meshie.val.mesh_id_len > IEEE80211_MAX_SSID_LEN) {
Joe Perchesf3a57fd2011-05-02 16:49:15 -0700979 dev_err(dev, "inconsistent mesh ID length\n");
Holger Schurig243e84e2009-10-22 15:30:47 +0200980 defs.meshie.val.mesh_id_len = IEEE80211_MAX_SSID_LEN;
Javier Cardona15dbaac2008-05-17 21:01:24 -0700981 }
982
Dan Carpenterd89dba72011-03-10 18:23:26 +0300983 memcpy(buf, defs.meshie.val.mesh_id, defs.meshie.val.mesh_id_len);
984 buf[defs.meshie.val.mesh_id_len] = '\n';
985 buf[defs.meshie.val.mesh_id_len + 1] = '\0';
Javier Cardona15dbaac2008-05-17 21:01:24 -0700986
Dan Carpenterd89dba72011-03-10 18:23:26 +0300987 return defs.meshie.val.mesh_id_len + 1;
Javier Cardona15dbaac2008-05-17 21:01:24 -0700988}
989
990/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700991 * mesh_id_set - Set function for sysfs attribute mesh_id
992 * @dev: the &struct device
993 * @attr: device attributes
994 * @buf: buffer that contains new attribute value
995 * @count: size of buffer
Javier Cardona15dbaac2008-05-17 21:01:24 -0700996 */
997static ssize_t mesh_id_set(struct device *dev, struct device_attribute *attr,
998 const char *buf, size_t count)
999{
1000 struct cmd_ds_mesh_config cmd;
1001 struct mrvl_mesh_defaults defs;
1002 struct mrvl_meshie *ie;
Kiran Divekarab65f642009-02-19 19:32:39 -05001003 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
Javier Cardona15dbaac2008-05-17 21:01:24 -07001004 int len;
1005 int ret;
1006
Holger Schurig243e84e2009-10-22 15:30:47 +02001007 if (count < 2 || count > IEEE80211_MAX_SSID_LEN + 1)
Javier Cardona15dbaac2008-05-17 21:01:24 -07001008 return -EINVAL;
1009
1010 memset(&cmd, 0, sizeof(struct cmd_ds_mesh_config));
1011 ie = (struct mrvl_meshie *) &cmd.data[0];
1012
1013 /* fetch all other Information Element parameters */
1014 ret = mesh_get_default_parameters(dev, &defs);
1015
1016 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
1017
1018 /* transfer IE elements */
1019 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
1020
1021 len = count - 1;
1022 memcpy(ie->val.mesh_id, buf, len);
1023 /* SSID len */
1024 ie->val.mesh_id_len = len;
1025 /* IE len */
Holger Schurig243e84e2009-10-22 15:30:47 +02001026 ie->len = sizeof(struct mrvl_meshie_val) - IEEE80211_MAX_SSID_LEN + len;
Javier Cardona15dbaac2008-05-17 21:01:24 -07001027
1028 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
1029 CMD_TYPE_MESH_SET_MESH_IE);
1030 if (ret)
1031 return ret;
1032
1033 return strlen(buf);
1034}
1035
1036/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -07001037 * protocol_id_get - Get function for sysfs attribute protocol_id
1038 * @dev: the &struct device
1039 * @attr: device attributes
1040 * @buf: buffer where data will be returned
Javier Cardona15dbaac2008-05-17 21:01:24 -07001041 */
1042static ssize_t protocol_id_get(struct device *dev,
1043 struct device_attribute *attr, char *buf)
1044{
1045 struct mrvl_mesh_defaults defs;
1046 int ret;
1047
1048 ret = mesh_get_default_parameters(dev, &defs);
1049
1050 if (ret)
1051 return ret;
1052
1053 return snprintf(buf, 5, "%d\n", defs.meshie.val.active_protocol_id);
1054}
1055
1056/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -07001057 * protocol_id_set - Set function for sysfs attribute protocol_id
1058 * @dev: the &struct device
1059 * @attr: device attributes
1060 * @buf: buffer that contains new attribute value
1061 * @count: size of buffer
Javier Cardona15dbaac2008-05-17 21:01:24 -07001062 */
1063static ssize_t protocol_id_set(struct device *dev,
1064 struct device_attribute *attr, const char *buf, size_t count)
1065{
1066 struct cmd_ds_mesh_config cmd;
1067 struct mrvl_mesh_defaults defs;
1068 struct mrvl_meshie *ie;
Kiran Divekarab65f642009-02-19 19:32:39 -05001069 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
Javier Cardona15dbaac2008-05-17 21:01:24 -07001070 uint32_t datum;
1071 int ret;
1072
1073 memset(&cmd, 0, sizeof(cmd));
Brian Cavagnolofb904902008-07-16 12:15:26 -07001074 ret = sscanf(buf, "%d", &datum);
1075 if ((ret != 1) || (datum > 255))
Javier Cardona15dbaac2008-05-17 21:01:24 -07001076 return -EINVAL;
1077
1078 /* fetch all other Information Element parameters */
1079 ret = mesh_get_default_parameters(dev, &defs);
1080
1081 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
1082
1083 /* transfer IE elements */
1084 ie = (struct mrvl_meshie *) &cmd.data[0];
1085 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
1086 /* update protocol id */
1087 ie->val.active_protocol_id = datum;
1088
1089 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
1090 CMD_TYPE_MESH_SET_MESH_IE);
1091 if (ret)
1092 return ret;
1093
1094 return strlen(buf);
1095}
1096
1097/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -07001098 * metric_id_get - Get function for sysfs attribute metric_id
1099 * @dev: the &struct device
1100 * @attr: device attributes
1101 * @buf: buffer where data will be returned
Javier Cardona15dbaac2008-05-17 21:01:24 -07001102 */
1103static ssize_t metric_id_get(struct device *dev,
1104 struct device_attribute *attr, char *buf)
1105{
1106 struct mrvl_mesh_defaults defs;
1107 int ret;
1108
1109 ret = mesh_get_default_parameters(dev, &defs);
1110
1111 if (ret)
1112 return ret;
1113
1114 return snprintf(buf, 5, "%d\n", defs.meshie.val.active_metric_id);
1115}
1116
1117/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -07001118 * metric_id_set - Set function for sysfs attribute metric_id
1119 * @dev: the &struct device
1120 * @attr: device attributes
1121 * @buf: buffer that contains new attribute value
1122 * @count: size of buffer
Javier Cardona15dbaac2008-05-17 21:01:24 -07001123 */
1124static ssize_t metric_id_set(struct device *dev, struct device_attribute *attr,
1125 const char *buf, size_t count)
1126{
1127 struct cmd_ds_mesh_config cmd;
1128 struct mrvl_mesh_defaults defs;
1129 struct mrvl_meshie *ie;
Kiran Divekarab65f642009-02-19 19:32:39 -05001130 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
Javier Cardona15dbaac2008-05-17 21:01:24 -07001131 uint32_t datum;
1132 int ret;
1133
1134 memset(&cmd, 0, sizeof(cmd));
Brian Cavagnolofb904902008-07-16 12:15:26 -07001135 ret = sscanf(buf, "%d", &datum);
1136 if ((ret != 1) || (datum > 255))
Javier Cardona15dbaac2008-05-17 21:01:24 -07001137 return -EINVAL;
1138
1139 /* fetch all other Information Element parameters */
1140 ret = mesh_get_default_parameters(dev, &defs);
1141
1142 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
1143
1144 /* transfer IE elements */
1145 ie = (struct mrvl_meshie *) &cmd.data[0];
1146 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
1147 /* update metric id */
1148 ie->val.active_metric_id = datum;
1149
1150 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
1151 CMD_TYPE_MESH_SET_MESH_IE);
1152 if (ret)
1153 return ret;
1154
1155 return strlen(buf);
1156}
1157
1158/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -07001159 * capability_get - Get function for sysfs attribute capability
1160 * @dev: the &struct device
1161 * @attr: device attributes
1162 * @buf: buffer where data will be returned
Javier Cardona15dbaac2008-05-17 21:01:24 -07001163 */
1164static ssize_t capability_get(struct device *dev,
1165 struct device_attribute *attr, char *buf)
1166{
1167 struct mrvl_mesh_defaults defs;
1168 int ret;
1169
1170 ret = mesh_get_default_parameters(dev, &defs);
1171
1172 if (ret)
1173 return ret;
1174
1175 return snprintf(buf, 5, "%d\n", defs.meshie.val.mesh_capability);
1176}
1177
1178/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -07001179 * capability_set - Set function for sysfs attribute capability
1180 * @dev: the &struct device
1181 * @attr: device attributes
1182 * @buf: buffer that contains new attribute value
1183 * @count: size of buffer
Javier Cardona15dbaac2008-05-17 21:01:24 -07001184 */
1185static ssize_t capability_set(struct device *dev, struct device_attribute *attr,
1186 const char *buf, size_t count)
1187{
1188 struct cmd_ds_mesh_config cmd;
1189 struct mrvl_mesh_defaults defs;
1190 struct mrvl_meshie *ie;
Kiran Divekarab65f642009-02-19 19:32:39 -05001191 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
Javier Cardona15dbaac2008-05-17 21:01:24 -07001192 uint32_t datum;
1193 int ret;
1194
1195 memset(&cmd, 0, sizeof(cmd));
Brian Cavagnolofb904902008-07-16 12:15:26 -07001196 ret = sscanf(buf, "%d", &datum);
1197 if ((ret != 1) || (datum > 255))
Javier Cardona15dbaac2008-05-17 21:01:24 -07001198 return -EINVAL;
1199
1200 /* fetch all other Information Element parameters */
1201 ret = mesh_get_default_parameters(dev, &defs);
1202
1203 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
1204
1205 /* transfer IE elements */
1206 ie = (struct mrvl_meshie *) &cmd.data[0];
1207 memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
1208 /* update value */
1209 ie->val.mesh_capability = datum;
1210
1211 ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
1212 CMD_TYPE_MESH_SET_MESH_IE);
1213 if (ret)
1214 return ret;
1215
1216 return strlen(buf);
1217}
1218
1219
1220static DEVICE_ATTR(bootflag, 0644, bootflag_get, bootflag_set);
1221static DEVICE_ATTR(boottime, 0644, boottime_get, boottime_set);
Javier Cardonab679aeb2008-05-20 15:18:49 -07001222static DEVICE_ATTR(channel, 0644, channel_get, channel_set);
Javier Cardona15dbaac2008-05-17 21:01:24 -07001223static DEVICE_ATTR(mesh_id, 0644, mesh_id_get, mesh_id_set);
1224static DEVICE_ATTR(protocol_id, 0644, protocol_id_get, protocol_id_set);
1225static DEVICE_ATTR(metric_id, 0644, metric_id_get, metric_id_set);
1226static DEVICE_ATTR(capability, 0644, capability_get, capability_set);
1227
1228static struct attribute *boot_opts_attrs[] = {
1229 &dev_attr_bootflag.attr,
1230 &dev_attr_boottime.attr,
Javier Cardonab679aeb2008-05-20 15:18:49 -07001231 &dev_attr_channel.attr,
Javier Cardona15dbaac2008-05-17 21:01:24 -07001232 NULL
1233};
1234
1235static struct attribute_group boot_opts_group = {
1236 .name = "boot_options",
1237 .attrs = boot_opts_attrs,
1238};
1239
1240static struct attribute *mesh_ie_attrs[] = {
1241 &dev_attr_mesh_id.attr,
1242 &dev_attr_protocol_id.attr,
1243 &dev_attr_metric_id.attr,
1244 &dev_attr_capability.attr,
1245 NULL
1246};
1247
1248static struct attribute_group mesh_ie_group = {
1249 .name = "mesh_ie",
1250 .attrs = mesh_ie_attrs,
1251};
1252
1253void lbs_persist_config_init(struct net_device *dev)
1254{
1255 int ret;
1256 ret = sysfs_create_group(&(dev->dev.kobj), &boot_opts_group);
1257 ret = sysfs_create_group(&(dev->dev.kobj), &mesh_ie_group);
1258}
1259
1260void lbs_persist_config_remove(struct net_device *dev)
1261{
1262 sysfs_remove_group(&(dev->dev.kobj), &boot_opts_group);
1263 sysfs_remove_group(&(dev->dev.kobj), &mesh_ie_group);
1264}
Holger Schurigc7fe64c2009-11-25 13:10:49 +01001265
1266
1267
1268/***************************************************************************
1269 * Ethtool related
1270 */
1271
1272static const char *mesh_stat_strings[] = {
1273 "drop_duplicate_bcast",
1274 "drop_ttl_zero",
1275 "drop_no_fwd_route",
1276 "drop_no_buffers",
1277 "fwded_unicast_cnt",
1278 "fwded_bcast_cnt",
1279 "drop_blind_table",
1280 "tx_failed_cnt"
1281};
1282
1283void lbs_mesh_ethtool_get_stats(struct net_device *dev,
1284 struct ethtool_stats *stats, uint64_t *data)
1285{
1286 struct lbs_private *priv = dev->ml_priv;
1287 struct cmd_ds_mesh_access mesh_access;
1288 int ret;
1289
1290 lbs_deb_enter(LBS_DEB_ETHTOOL);
1291
1292 /* Get Mesh Statistics */
1293 ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_STATS, &mesh_access);
1294
1295 if (ret) {
1296 memset(data, 0, MESH_STATS_NUM*(sizeof(uint64_t)));
1297 return;
1298 }
1299
1300 priv->mstats.fwd_drop_rbt = le32_to_cpu(mesh_access.data[0]);
1301 priv->mstats.fwd_drop_ttl = le32_to_cpu(mesh_access.data[1]);
1302 priv->mstats.fwd_drop_noroute = le32_to_cpu(mesh_access.data[2]);
1303 priv->mstats.fwd_drop_nobuf = le32_to_cpu(mesh_access.data[3]);
1304 priv->mstats.fwd_unicast_cnt = le32_to_cpu(mesh_access.data[4]);
1305 priv->mstats.fwd_bcast_cnt = le32_to_cpu(mesh_access.data[5]);
1306 priv->mstats.drop_blind = le32_to_cpu(mesh_access.data[6]);
1307 priv->mstats.tx_failed_cnt = le32_to_cpu(mesh_access.data[7]);
1308
1309 data[0] = priv->mstats.fwd_drop_rbt;
1310 data[1] = priv->mstats.fwd_drop_ttl;
1311 data[2] = priv->mstats.fwd_drop_noroute;
1312 data[3] = priv->mstats.fwd_drop_nobuf;
1313 data[4] = priv->mstats.fwd_unicast_cnt;
1314 data[5] = priv->mstats.fwd_bcast_cnt;
1315 data[6] = priv->mstats.drop_blind;
1316 data[7] = priv->mstats.tx_failed_cnt;
1317
1318 lbs_deb_enter(LBS_DEB_ETHTOOL);
1319}
1320
1321int lbs_mesh_ethtool_get_sset_count(struct net_device *dev, int sset)
1322{
1323 struct lbs_private *priv = dev->ml_priv;
1324
1325 if (sset == ETH_SS_STATS && dev == priv->mesh_dev)
1326 return MESH_STATS_NUM;
1327
1328 return -EOPNOTSUPP;
1329}
1330
1331void lbs_mesh_ethtool_get_strings(struct net_device *dev,
1332 uint32_t stringset, uint8_t *s)
1333{
1334 int i;
1335
1336 lbs_deb_enter(LBS_DEB_ETHTOOL);
1337
1338 switch (stringset) {
1339 case ETH_SS_STATS:
1340 for (i = 0; i < MESH_STATS_NUM; i++) {
1341 memcpy(s + i * ETH_GSTRING_LEN,
1342 mesh_stat_strings[i],
1343 ETH_GSTRING_LEN);
1344 }
1345 break;
1346 }
1347 lbs_deb_enter(LBS_DEB_ETHTOOL);
1348}