aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Drake <dsd@laptop.org>2011-07-20 12:53:50 -0400
committerJohn W. Linville <linville@tuxdriver.com>2011-07-20 15:04:40 -0400
commit3db4f989384c90f5f6be14e88c19732bfb0ac331 (patch)
treea8dc2816adb4773b96f6e90c7ecbd55d7ea6b317
parent037b559a167c76f3457582d1b84b4d1e36e38925 (diff)
libertas: mesh: misc cleanup
Remove unused blindlist code. Mark a few items const and static where possible. Involved some code re-ordering, but no code changes. Signed-off-by: Daniel Drake <dsd@laptop.org> Acked-by: Dan Williams <dcbw@redhat.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r--drivers/net/wireless/libertas/mesh.c965
-rw-r--r--drivers/net/wireless/libertas/mesh.h24
2 files changed, 388 insertions, 601 deletions
diff --git a/drivers/net/wireless/libertas/mesh.c b/drivers/net/wireless/libertas/mesh.c
index 24cf06680c6b..ffe9c1e400cf 100644
--- a/drivers/net/wireless/libertas/mesh.c
+++ b/drivers/net/wireless/libertas/mesh.c
@@ -14,6 +14,121 @@
14#include "cmd.h" 14#include "cmd.h"
15 15
16 16
17static int lbs_add_mesh(struct lbs_private *priv);
18
19/***************************************************************************
20 * Mesh command handling
21 */
22
23static int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
24 struct cmd_ds_mesh_access *cmd)
25{
26 int ret;
27
28 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
29
30 cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
31 cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
32 cmd->hdr.result = 0;
33
34 cmd->action = cpu_to_le16(cmd_action);
35
36 ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
37
38 lbs_deb_leave(LBS_DEB_CMD);
39 return ret;
40}
41
42static int __lbs_mesh_config_send(struct lbs_private *priv,
43 struct cmd_ds_mesh_config *cmd,
44 uint16_t action, uint16_t type)
45{
46 int ret;
47 u16 command = CMD_MESH_CONFIG_OLD;
48
49 lbs_deb_enter(LBS_DEB_CMD);
50
51 /*
52 * Command id is 0xac for v10 FW along with mesh interface
53 * id in bits 14-13-12.
54 */
55 if (priv->mesh_tlv == TLV_TYPE_MESH_ID)
56 command = CMD_MESH_CONFIG |
57 (MESH_IFACE_ID << MESH_IFACE_BIT_OFFSET);
58
59 cmd->hdr.command = cpu_to_le16(command);
60 cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config));
61 cmd->hdr.result = 0;
62
63 cmd->type = cpu_to_le16(type);
64 cmd->action = cpu_to_le16(action);
65
66 ret = lbs_cmd_with_response(priv, command, cmd);
67
68 lbs_deb_leave(LBS_DEB_CMD);
69 return ret;
70}
71
72static int lbs_mesh_config_send(struct lbs_private *priv,
73 struct cmd_ds_mesh_config *cmd,
74 uint16_t action, uint16_t type)
75{
76 int ret;
77
78 if (!(priv->fwcapinfo & FW_CAPINFO_PERSISTENT_CONFIG))
79 return -EOPNOTSUPP;
80
81 ret = __lbs_mesh_config_send(priv, cmd, action, type);
82 return ret;
83}
84
85/* This function is the CMD_MESH_CONFIG legacy function. It only handles the
86 * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG
87 * are all handled by preparing a struct cmd_ds_mesh_config and passing it to
88 * lbs_mesh_config_send.
89 */
90static int lbs_mesh_config(struct lbs_private *priv, uint16_t action,
91 uint16_t chan)
92{
93 struct cmd_ds_mesh_config cmd;
94 struct mrvl_meshie *ie;
95 DECLARE_SSID_BUF(ssid);
96
97 memset(&cmd, 0, sizeof(cmd));
98 cmd.channel = cpu_to_le16(chan);
99 ie = (struct mrvl_meshie *)cmd.data;
100
101 switch (action) {
102 case CMD_ACT_MESH_CONFIG_START:
103 ie->id = WLAN_EID_GENERIC;
104 ie->val.oui[0] = 0x00;
105 ie->val.oui[1] = 0x50;
106 ie->val.oui[2] = 0x43;
107 ie->val.type = MARVELL_MESH_IE_TYPE;
108 ie->val.subtype = MARVELL_MESH_IE_SUBTYPE;
109 ie->val.version = MARVELL_MESH_IE_VERSION;
110 ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP;
111 ie->val.active_metric_id = MARVELL_MESH_METRIC_ID;
112 ie->val.mesh_capability = MARVELL_MESH_CAPABILITY;
113 ie->val.mesh_id_len = priv->mesh_ssid_len;
114 memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len);
115 ie->len = sizeof(struct mrvl_meshie_val) -
116 IEEE80211_MAX_SSID_LEN + priv->mesh_ssid_len;
117 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val));
118 break;
119 case CMD_ACT_MESH_CONFIG_STOP:
120 break;
121 default:
122 return -1;
123 }
124 lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n",
125 action, priv->mesh_tlv, chan,
126 print_ssid(ssid, priv->mesh_ssid, priv->mesh_ssid_len));
127
128 return __lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv);
129}
130
131
17/*************************************************************************** 132/***************************************************************************
18 * Mesh sysfs support 133 * Mesh sysfs support
19 */ 134 */
@@ -199,582 +314,11 @@ static struct attribute *lbs_mesh_sysfs_entries[] = {
199 NULL, 314 NULL,
200}; 315};
201 316
202static struct attribute_group lbs_mesh_attr_group = { 317static const struct attribute_group lbs_mesh_attr_group = {
203 .attrs = lbs_mesh_sysfs_entries, 318 .attrs = lbs_mesh_sysfs_entries,
204}; 319};
205 320
206 321
207
208/***************************************************************************
209 * Initializing and starting, stopping mesh
210 */
211
212/*
213 * Check mesh FW version and appropriately send the mesh start
214 * command
215 */
216int lbs_init_mesh(struct lbs_private *priv)
217{
218 struct net_device *dev = priv->dev;
219 int ret = 0;
220
221 lbs_deb_enter(LBS_DEB_MESH);
222
223 priv->mesh_connect_status = LBS_DISCONNECTED;
224
225 /* Determine mesh_fw_ver from fwrelease and fwcapinfo */
226 /* 5.0.16p0 9.0.0.p0 is known to NOT support any mesh */
227 /* 5.110.22 have mesh command with 0xa3 command id */
228 /* 10.0.0.p0 FW brings in mesh config command with different id */
229 /* Check FW version MSB and initialize mesh_fw_ver */
230 if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V5) {
231 /* Enable mesh, if supported, and work out which TLV it uses.
232 0x100 + 291 is an unofficial value used in 5.110.20.pXX
233 0x100 + 37 is the official value used in 5.110.21.pXX
234 but we check them in that order because 20.pXX doesn't
235 give an error -- it just silently fails. */
236
237 /* 5.110.20.pXX firmware will fail the command if the channel
238 doesn't match the existing channel. But only if the TLV
239 is correct. If the channel is wrong, _BOTH_ versions will
240 give an error to 0x100+291, and allow 0x100+37 to succeed.
241 It's just that 5.110.20.pXX will not have done anything
242 useful */
243
244 priv->mesh_tlv = TLV_TYPE_OLD_MESH_ID;
245 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
246 priv->channel)) {
247 priv->mesh_tlv = TLV_TYPE_MESH_ID;
248 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
249 priv->channel))
250 priv->mesh_tlv = 0;
251 }
252 } else
253 if ((MRVL_FW_MAJOR_REV(priv->fwrelease) >= MRVL_FW_V10) &&
254 (priv->fwcapinfo & MESH_CAPINFO_ENABLE_MASK)) {
255 /* 10.0.0.pXX new firmwares should succeed with TLV
256 * 0x100+37; Do not invoke command with old TLV.
257 */
258 priv->mesh_tlv = TLV_TYPE_MESH_ID;
259 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
260 priv->channel))
261 priv->mesh_tlv = 0;
262 }
263
264
265 if (priv->mesh_tlv) {
266 sprintf(priv->mesh_ssid, "mesh");
267 priv->mesh_ssid_len = 4;
268
269 lbs_add_mesh(priv);
270
271 if (device_create_file(&dev->dev, &dev_attr_lbs_mesh))
272 netdev_err(dev, "cannot register lbs_mesh attribute\n");
273
274 ret = 1;
275 }
276
277 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
278 return ret;
279}
280
281
282int lbs_deinit_mesh(struct lbs_private *priv)
283{
284 struct net_device *dev = priv->dev;
285 int ret = 0;
286
287 lbs_deb_enter(LBS_DEB_MESH);
288
289 if (priv->mesh_tlv) {
290 device_remove_file(&dev->dev, &dev_attr_lbs_mesh);
291 ret = 1;
292 }
293
294 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
295 return ret;
296}
297
298
299/**
300 * lbs_mesh_stop - close the mshX interface
301 *
302 * @dev: A pointer to &net_device structure
303 * returns: 0
304 */
305static int lbs_mesh_stop(struct net_device *dev)
306{
307 struct lbs_private *priv = dev->ml_priv;
308
309 lbs_deb_enter(LBS_DEB_MESH);
310 spin_lock_irq(&priv->driver_lock);
311
312 priv->mesh_open = 0;
313 priv->mesh_connect_status = LBS_DISCONNECTED;
314
315 netif_stop_queue(dev);
316 netif_carrier_off(dev);
317
318 spin_unlock_irq(&priv->driver_lock);
319
320 schedule_work(&priv->mcast_work);
321
322 lbs_deb_leave(LBS_DEB_MESH);
323 return 0;
324}
325
326/**
327 * lbs_mesh_dev_open - open the mshX interface
328 *
329 * @dev: A pointer to &net_device structure
330 * returns: 0 or -EBUSY if monitor mode active
331 */
332static int lbs_mesh_dev_open(struct net_device *dev)
333{
334 struct lbs_private *priv = dev->ml_priv;
335 int ret = 0;
336
337 lbs_deb_enter(LBS_DEB_NET);
338
339 spin_lock_irq(&priv->driver_lock);
340
341 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR) {
342 ret = -EBUSY;
343 goto out;
344 }
345
346 priv->mesh_open = 1;
347 priv->mesh_connect_status = LBS_CONNECTED;
348 netif_carrier_on(dev);
349
350 if (!priv->tx_pending_len)
351 netif_wake_queue(dev);
352 out:
353
354 spin_unlock_irq(&priv->driver_lock);
355 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
356 return ret;
357}
358
359static const struct net_device_ops mesh_netdev_ops = {
360 .ndo_open = lbs_mesh_dev_open,
361 .ndo_stop = lbs_mesh_stop,
362 .ndo_start_xmit = lbs_hard_start_xmit,
363 .ndo_set_mac_address = lbs_set_mac_address,
364 .ndo_set_multicast_list = lbs_set_multicast_list,
365};
366
367/**
368 * lbs_add_mesh - add mshX interface
369 *
370 * @priv: A pointer to the &struct lbs_private structure
371 * returns: 0 if successful, -X otherwise
372 */
373int lbs_add_mesh(struct lbs_private *priv)
374{
375 struct net_device *mesh_dev = NULL;
376 int ret = 0;
377
378 lbs_deb_enter(LBS_DEB_MESH);
379
380 /* Allocate a virtual mesh device */
381 mesh_dev = alloc_netdev(0, "msh%d", ether_setup);
382 if (!mesh_dev) {
383 lbs_deb_mesh("init mshX device failed\n");
384 ret = -ENOMEM;
385 goto done;
386 }
387 mesh_dev->ml_priv = priv;
388 priv->mesh_dev = mesh_dev;
389
390 mesh_dev->netdev_ops = &mesh_netdev_ops;
391 mesh_dev->ethtool_ops = &lbs_ethtool_ops;
392 memcpy(mesh_dev->dev_addr, priv->dev->dev_addr, ETH_ALEN);
393
394 SET_NETDEV_DEV(priv->mesh_dev, priv->dev->dev.parent);
395
396 mesh_dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
397 /* Register virtual mesh interface */
398 ret = register_netdev(mesh_dev);
399 if (ret) {
400 pr_err("cannot register mshX virtual interface\n");
401 goto err_free;
402 }
403
404 ret = sysfs_create_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
405 if (ret)
406 goto err_unregister;
407
408 lbs_persist_config_init(mesh_dev);
409
410 /* Everything successful */
411 ret = 0;
412 goto done;
413
414err_unregister:
415 unregister_netdev(mesh_dev);
416
417err_free:
418 free_netdev(mesh_dev);
419
420done:
421 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
422 return ret;
423}
424
425void lbs_remove_mesh(struct lbs_private *priv)
426{
427 struct net_device *mesh_dev;
428
429 mesh_dev = priv->mesh_dev;
430 if (!mesh_dev)
431 return;
432
433 lbs_deb_enter(LBS_DEB_MESH);
434 netif_stop_queue(mesh_dev);
435 netif_carrier_off(mesh_dev);
436 sysfs_remove_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
437 lbs_persist_config_remove(mesh_dev);
438 unregister_netdev(mesh_dev);
439 priv->mesh_dev = NULL;
440 free_netdev(mesh_dev);
441 lbs_deb_leave(LBS_DEB_MESH);
442}
443
444
445
446/***************************************************************************
447 * Sending and receiving
448 */
449struct net_device *lbs_mesh_set_dev(struct lbs_private *priv,
450 struct net_device *dev, struct rxpd *rxpd)
451{
452 if (priv->mesh_dev) {
453 if (priv->mesh_tlv == TLV_TYPE_OLD_MESH_ID) {
454 if (rxpd->rx_control & RxPD_MESH_FRAME)
455 dev = priv->mesh_dev;
456 } else if (priv->mesh_tlv == TLV_TYPE_MESH_ID) {
457 if (rxpd->u.bss.bss_num == MESH_IFACE_ID)
458 dev = priv->mesh_dev;
459 }
460 }
461 return dev;
462}
463
464
465void lbs_mesh_set_txpd(struct lbs_private *priv,
466 struct net_device *dev, struct txpd *txpd)
467{
468 if (dev == priv->mesh_dev) {
469 if (priv->mesh_tlv == TLV_TYPE_OLD_MESH_ID)
470 txpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
471 else if (priv->mesh_tlv == TLV_TYPE_MESH_ID)
472 txpd->u.bss.bss_num = MESH_IFACE_ID;
473 }
474}
475
476
477/***************************************************************************
478 * Mesh command handling
479 */
480
481/**
482 * lbs_mesh_bt_add_del - Add or delete Mesh Blinding Table entries
483 *
484 * @priv: A pointer to &struct lbs_private structure
485 * @add: TRUE to add the entry, FALSE to delete it
486 * @addr1: Destination address to blind or unblind
487 *
488 * returns: 0 on success, error on failure
489 */
490int lbs_mesh_bt_add_del(struct lbs_private *priv, bool add, u8 *addr1)
491{
492 struct cmd_ds_bt_access cmd;
493 int ret = 0;
494
495 lbs_deb_enter(LBS_DEB_CMD);
496
497 BUG_ON(addr1 == NULL);
498
499 memset(&cmd, 0, sizeof(cmd));
500 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
501 memcpy(cmd.addr1, addr1, ETH_ALEN);
502 if (add) {
503 cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_ADD);
504 lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr",
505 addr1, ETH_ALEN);
506 } else {
507 cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_DEL);
508 lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr",
509 addr1, ETH_ALEN);
510 }
511
512 ret = lbs_cmd_with_response(priv, CMD_BT_ACCESS, &cmd);
513
514 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
515 return ret;
516}
517
518/**
519 * lbs_mesh_bt_reset - Reset/clear the mesh blinding table
520 *
521 * @priv: A pointer to &struct lbs_private structure
522 *
523 * returns: 0 on success, error on failure
524 */
525int lbs_mesh_bt_reset(struct lbs_private *priv)
526{
527 struct cmd_ds_bt_access cmd;
528 int ret = 0;
529
530 lbs_deb_enter(LBS_DEB_CMD);
531
532 memset(&cmd, 0, sizeof(cmd));
533 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
534 cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_RESET);
535
536 ret = lbs_cmd_with_response(priv, CMD_BT_ACCESS, &cmd);
537
538 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
539 return ret;
540}
541
542/**
543 * lbs_mesh_bt_get_inverted - Gets the inverted status of the mesh
544 * blinding table
545 *
546 * Normally the firmware "blinds" or ignores traffic from mesh nodes in the
547 * table, but an inverted table allows *only* traffic from nodes listed in
548 * the table.
549 *
550 * @priv: A pointer to &struct lbs_private structure
551 * @inverted: On success, TRUE if the blinding table is inverted,
552 * FALSE if it is not inverted
553 *
554 * returns: 0 on success, error on failure
555 */
556int lbs_mesh_bt_get_inverted(struct lbs_private *priv, bool *inverted)
557{
558 struct cmd_ds_bt_access cmd;
559 int ret = 0;
560
561 lbs_deb_enter(LBS_DEB_CMD);
562
563 BUG_ON(inverted == NULL);
564
565 memset(&cmd, 0, sizeof(cmd));
566 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
567 cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_GET_INVERT);
568
569 ret = lbs_cmd_with_response(priv, CMD_BT_ACCESS, &cmd);
570 if (ret == 0)
571 *inverted = !!cmd.id;
572
573 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
574 return ret;
575}
576
577/**
578 * lbs_mesh_bt_set_inverted - Sets the inverted status of the mesh
579 * blinding table
580 *
581 * Normally the firmware "blinds" or ignores traffic from mesh nodes in the
582 * table, but an inverted table allows *only* traffic from nodes listed in
583 * the table.
584 *
585 * @priv: A pointer to &struct lbs_private structure
586 * @inverted: TRUE to invert the blinding table (only traffic from
587 * listed nodes allowed), FALSE to return it
588 * to normal state (listed nodes ignored)
589 *
590 * returns: 0 on success, error on failure
591 */
592int lbs_mesh_bt_set_inverted(struct lbs_private *priv, bool inverted)
593{
594 struct cmd_ds_bt_access cmd;
595 int ret = 0;
596
597 lbs_deb_enter(LBS_DEB_CMD);
598
599 memset(&cmd, 0, sizeof(cmd));
600 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
601 cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_SET_INVERT);
602 cmd.id = cpu_to_le32(!!inverted);
603
604 ret = lbs_cmd_with_response(priv, CMD_BT_ACCESS, &cmd);
605
606 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
607 return ret;
608}
609
610/**
611 * lbs_mesh_bt_get_entry - List an entry in the mesh blinding table
612 *
613 * @priv: A pointer to &struct lbs_private structure
614 * @id: The ID of the entry to list
615 * @addr1: MAC address associated with the table entry
616 *
617 * returns: 0 on success, error on failure
618 */
619int lbs_mesh_bt_get_entry(struct lbs_private *priv, u32 id, u8 *addr1)
620{
621 struct cmd_ds_bt_access cmd;
622 int ret = 0;
623
624 lbs_deb_enter(LBS_DEB_CMD);
625
626 BUG_ON(addr1 == NULL);
627
628 memset(&cmd, 0, sizeof(cmd));
629 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
630 cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_SET_INVERT);
631 cmd.id = cpu_to_le32(id);
632
633 ret = lbs_cmd_with_response(priv, CMD_BT_ACCESS, &cmd);
634 if (ret == 0)
635 memcpy(addr1, cmd.addr1, sizeof(cmd.addr1));
636
637 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
638 return ret;
639}
640
641/**
642 * lbs_cmd_fwt_access - Access the mesh forwarding table
643 *
644 * @priv: A pointer to &struct lbs_private structure
645 * @cmd_action: The forwarding table action to perform
646 * @cmd: The pre-filled FWT_ACCESS command
647 *
648 * returns: 0 on success and 'cmd' will be filled with the
649 * firmware's response
650 */
651int lbs_cmd_fwt_access(struct lbs_private *priv, u16 cmd_action,
652 struct cmd_ds_fwt_access *cmd)
653{
654 int ret;
655
656 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
657
658 cmd->hdr.command = cpu_to_le16(CMD_FWT_ACCESS);
659 cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access));
660 cmd->hdr.result = 0;
661 cmd->action = cpu_to_le16(cmd_action);
662
663 ret = lbs_cmd_with_response(priv, CMD_FWT_ACCESS, cmd);
664
665 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
666 return 0;
667}
668
669int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
670 struct cmd_ds_mesh_access *cmd)
671{
672 int ret;
673
674 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
675
676 cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
677 cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
678 cmd->hdr.result = 0;
679
680 cmd->action = cpu_to_le16(cmd_action);
681
682 ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
683
684 lbs_deb_leave(LBS_DEB_CMD);
685 return ret;
686}
687
688static int __lbs_mesh_config_send(struct lbs_private *priv,
689 struct cmd_ds_mesh_config *cmd,
690 uint16_t action, uint16_t type)
691{
692 int ret;
693 u16 command = CMD_MESH_CONFIG_OLD;
694
695 lbs_deb_enter(LBS_DEB_CMD);
696
697 /*
698 * Command id is 0xac for v10 FW along with mesh interface
699 * id in bits 14-13-12.
700 */
701 if (priv->mesh_tlv == TLV_TYPE_MESH_ID)
702 command = CMD_MESH_CONFIG |
703 (MESH_IFACE_ID << MESH_IFACE_BIT_OFFSET);
704
705 cmd->hdr.command = cpu_to_le16(command);
706 cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config));
707 cmd->hdr.result = 0;
708
709 cmd->type = cpu_to_le16(type);
710 cmd->action = cpu_to_le16(action);
711
712 ret = lbs_cmd_with_response(priv, command, cmd);
713
714 lbs_deb_leave(LBS_DEB_CMD);
715 return ret;
716}
717
718int lbs_mesh_config_send(struct lbs_private *priv,
719 struct cmd_ds_mesh_config *cmd,
720 uint16_t action, uint16_t type)
721{
722 int ret;
723
724 if (!(priv->fwcapinfo & FW_CAPINFO_PERSISTENT_CONFIG))
725 return -EOPNOTSUPP;
726
727 ret = __lbs_mesh_config_send(priv, cmd, action, type);
728 return ret;
729}
730
731/* This function is the CMD_MESH_CONFIG legacy function. It only handles the
732 * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG
733 * are all handled by preparing a struct cmd_ds_mesh_config and passing it to
734 * lbs_mesh_config_send.
735 */
736int lbs_mesh_config(struct lbs_private *priv, uint16_t action, uint16_t chan)
737{
738 struct cmd_ds_mesh_config cmd;
739 struct mrvl_meshie *ie;
740 DECLARE_SSID_BUF(ssid);
741
742 memset(&cmd, 0, sizeof(cmd));
743 cmd.channel = cpu_to_le16(chan);
744 ie = (struct mrvl_meshie *)cmd.data;
745
746 switch (action) {
747 case CMD_ACT_MESH_CONFIG_START:
748 ie->id = WLAN_EID_GENERIC;
749 ie->val.oui[0] = 0x00;
750 ie->val.oui[1] = 0x50;
751 ie->val.oui[2] = 0x43;
752 ie->val.type = MARVELL_MESH_IE_TYPE;
753 ie->val.subtype = MARVELL_MESH_IE_SUBTYPE;
754 ie->val.version = MARVELL_MESH_IE_VERSION;
755 ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP;
756 ie->val.active_metric_id = MARVELL_MESH_METRIC_ID;
757 ie->val.mesh_capability = MARVELL_MESH_CAPABILITY;
758 ie->val.mesh_id_len = priv->mesh_ssid_len;
759 memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len);
760 ie->len = sizeof(struct mrvl_meshie_val) -
761 IEEE80211_MAX_SSID_LEN + priv->mesh_ssid_len;
762 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val));
763 break;
764 case CMD_ACT_MESH_CONFIG_STOP:
765 break;
766 default:
767 return -1;
768 }
769 lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n",
770 action, priv->mesh_tlv, chan,
771 print_ssid(ssid, priv->mesh_ssid, priv->mesh_ssid_len));
772
773 return __lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv);
774}
775
776
777
778/*************************************************************************** 322/***************************************************************************
779 * Persistent configuration support 323 * Persistent configuration support
780 */ 324 */
@@ -1231,7 +775,7 @@ static struct attribute *boot_opts_attrs[] = {
1231 NULL 775 NULL
1232}; 776};
1233 777
1234static struct attribute_group boot_opts_group = { 778static const struct attribute_group boot_opts_group = {
1235 .name = "boot_options", 779 .name = "boot_options",
1236 .attrs = boot_opts_attrs, 780 .attrs = boot_opts_attrs,
1237}; 781};
@@ -1244,31 +788,298 @@ static struct attribute *mesh_ie_attrs[] = {
1244 NULL 788 NULL
1245}; 789};
1246 790
1247static struct attribute_group mesh_ie_group = { 791static const struct attribute_group mesh_ie_group = {
1248 .name = "mesh_ie", 792 .name = "mesh_ie",
1249 .attrs = mesh_ie_attrs, 793 .attrs = mesh_ie_attrs,
1250}; 794};
1251 795
1252void lbs_persist_config_init(struct net_device *dev) 796static void lbs_persist_config_init(struct net_device *dev)
1253{ 797{
1254 int ret; 798 int ret;
1255 ret = sysfs_create_group(&(dev->dev.kobj), &boot_opts_group); 799 ret = sysfs_create_group(&(dev->dev.kobj), &boot_opts_group);
1256 ret = sysfs_create_group(&(dev->dev.kobj), &mesh_ie_group); 800 ret = sysfs_create_group(&(dev->dev.kobj), &mesh_ie_group);
1257} 801}
1258 802
1259void lbs_persist_config_remove(struct net_device *dev) 803static void lbs_persist_config_remove(struct net_device *dev)
1260{ 804{
1261 sysfs_remove_group(&(dev->dev.kobj), &boot_opts_group); 805 sysfs_remove_group(&(dev->dev.kobj), &boot_opts_group);
1262 sysfs_remove_group(&(dev->dev.kobj), &mesh_ie_group); 806 sysfs_remove_group(&(dev->dev.kobj), &mesh_ie_group);
1263} 807}
1264 808
1265 809
810/***************************************************************************
811 * Initializing and starting, stopping mesh
812 */
813
814/*
815 * Check mesh FW version and appropriately send the mesh start
816 * command
817 */
818int lbs_init_mesh(struct lbs_private *priv)
819{
820 struct net_device *dev = priv->dev;
821 int ret = 0;
822
823 lbs_deb_enter(LBS_DEB_MESH);
824
825 priv->mesh_connect_status = LBS_DISCONNECTED;
826
827 /* Determine mesh_fw_ver from fwrelease and fwcapinfo */
828 /* 5.0.16p0 9.0.0.p0 is known to NOT support any mesh */
829 /* 5.110.22 have mesh command with 0xa3 command id */
830 /* 10.0.0.p0 FW brings in mesh config command with different id */
831 /* Check FW version MSB and initialize mesh_fw_ver */
832 if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V5) {
833 /* Enable mesh, if supported, and work out which TLV it uses.
834 0x100 + 291 is an unofficial value used in 5.110.20.pXX
835 0x100 + 37 is the official value used in 5.110.21.pXX
836 but we check them in that order because 20.pXX doesn't
837 give an error -- it just silently fails. */
838
839 /* 5.110.20.pXX firmware will fail the command if the channel
840 doesn't match the existing channel. But only if the TLV
841 is correct. If the channel is wrong, _BOTH_ versions will
842 give an error to 0x100+291, and allow 0x100+37 to succeed.
843 It's just that 5.110.20.pXX will not have done anything
844 useful */
845
846 priv->mesh_tlv = TLV_TYPE_OLD_MESH_ID;
847 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
848 priv->channel)) {
849 priv->mesh_tlv = TLV_TYPE_MESH_ID;
850 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
851 priv->channel))
852 priv->mesh_tlv = 0;
853 }
854 } else
855 if ((MRVL_FW_MAJOR_REV(priv->fwrelease) >= MRVL_FW_V10) &&
856 (priv->fwcapinfo & MESH_CAPINFO_ENABLE_MASK)) {
857 /* 10.0.0.pXX new firmwares should succeed with TLV
858 * 0x100+37; Do not invoke command with old TLV.
859 */
860 priv->mesh_tlv = TLV_TYPE_MESH_ID;
861 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
862 priv->channel))
863 priv->mesh_tlv = 0;
864 }
865
866
867 if (priv->mesh_tlv) {
868 sprintf(priv->mesh_ssid, "mesh");
869 priv->mesh_ssid_len = 4;
870
871 lbs_add_mesh(priv);
872
873 if (device_create_file(&dev->dev, &dev_attr_lbs_mesh))
874 netdev_err(dev, "cannot register lbs_mesh attribute\n");
875
876 ret = 1;
877 }
878
879 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
880 return ret;
881}
882
883
884int lbs_deinit_mesh(struct lbs_private *priv)
885{
886 struct net_device *dev = priv->dev;
887 int ret = 0;
888
889 lbs_deb_enter(LBS_DEB_MESH);
890
891 if (priv->mesh_tlv) {
892 device_remove_file(&dev->dev, &dev_attr_lbs_mesh);
893 ret = 1;
894 }
895
896 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
897 return ret;
898}
899
900
901/**
902 * lbs_mesh_stop - close the mshX interface
903 *
904 * @dev: A pointer to &net_device structure
905 * returns: 0
906 */
907static int lbs_mesh_stop(struct net_device *dev)
908{
909 struct lbs_private *priv = dev->ml_priv;
910
911 lbs_deb_enter(LBS_DEB_MESH);
912 spin_lock_irq(&priv->driver_lock);
913
914 priv->mesh_open = 0;
915 priv->mesh_connect_status = LBS_DISCONNECTED;
916
917 netif_stop_queue(dev);
918 netif_carrier_off(dev);
919
920 spin_unlock_irq(&priv->driver_lock);
921
922 schedule_work(&priv->mcast_work);
923
924 lbs_deb_leave(LBS_DEB_MESH);
925 return 0;
926}
927
928/**
929 * lbs_mesh_dev_open - open the mshX interface
930 *
931 * @dev: A pointer to &net_device structure
932 * returns: 0 or -EBUSY if monitor mode active
933 */
934static int lbs_mesh_dev_open(struct net_device *dev)
935{
936 struct lbs_private *priv = dev->ml_priv;
937 int ret = 0;
938
939 lbs_deb_enter(LBS_DEB_NET);
940
941 spin_lock_irq(&priv->driver_lock);
942
943 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR) {
944 ret = -EBUSY;
945 goto out;
946 }
947
948 priv->mesh_open = 1;
949 priv->mesh_connect_status = LBS_CONNECTED;
950 netif_carrier_on(dev);
951
952 if (!priv->tx_pending_len)
953 netif_wake_queue(dev);
954 out:
955
956 spin_unlock_irq(&priv->driver_lock);
957 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
958 return ret;
959}
960
961static const struct net_device_ops mesh_netdev_ops = {
962 .ndo_open = lbs_mesh_dev_open,
963 .ndo_stop = lbs_mesh_stop,
964 .ndo_start_xmit = lbs_hard_start_xmit,
965 .ndo_set_mac_address = lbs_set_mac_address,
966 .ndo_set_multicast_list = lbs_set_multicast_list,
967};
968
969/**
970 * lbs_add_mesh - add mshX interface
971 *
972 * @priv: A pointer to the &struct lbs_private structure
973 * returns: 0 if successful, -X otherwise
974 */
975static int lbs_add_mesh(struct lbs_private *priv)
976{
977 struct net_device *mesh_dev = NULL;
978 int ret = 0;
979
980 lbs_deb_enter(LBS_DEB_MESH);
981
982 /* Allocate a virtual mesh device */
983 mesh_dev = alloc_netdev(0, "msh%d", ether_setup);
984 if (!mesh_dev) {
985 lbs_deb_mesh("init mshX device failed\n");
986 ret = -ENOMEM;
987 goto done;
988 }
989 mesh_dev->ml_priv = priv;
990 priv->mesh_dev = mesh_dev;
991
992 mesh_dev->netdev_ops = &mesh_netdev_ops;
993 mesh_dev->ethtool_ops = &lbs_ethtool_ops;
994 memcpy(mesh_dev->dev_addr, priv->dev->dev_addr, ETH_ALEN);
995
996 SET_NETDEV_DEV(priv->mesh_dev, priv->dev->dev.parent);
997
998 mesh_dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
999 /* Register virtual mesh interface */
1000 ret = register_netdev(mesh_dev);
1001 if (ret) {
1002 pr_err("cannot register mshX virtual interface\n");
1003 goto err_free;
1004 }
1005
1006 ret = sysfs_create_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
1007 if (ret)
1008 goto err_unregister;
1009
1010 lbs_persist_config_init(mesh_dev);
1011
1012 /* Everything successful */
1013 ret = 0;
1014 goto done;
1015
1016err_unregister:
1017 unregister_netdev(mesh_dev);
1018
1019err_free:
1020 free_netdev(mesh_dev);
1021
1022done:
1023 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
1024 return ret;
1025}
1026
1027void lbs_remove_mesh(struct lbs_private *priv)
1028{
1029 struct net_device *mesh_dev;
1030
1031 mesh_dev = priv->mesh_dev;
1032 if (!mesh_dev)
1033 return;
1034
1035 lbs_deb_enter(LBS_DEB_MESH);
1036 netif_stop_queue(mesh_dev);
1037 netif_carrier_off(mesh_dev);
1038 sysfs_remove_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
1039 lbs_persist_config_remove(mesh_dev);
1040 unregister_netdev(mesh_dev);
1041 priv->mesh_dev = NULL;
1042 free_netdev(mesh_dev);
1043 lbs_deb_leave(LBS_DEB_MESH);
1044}
1045
1046
1047/***************************************************************************
1048 * Sending and receiving
1049 */
1050struct net_device *lbs_mesh_set_dev(struct lbs_private *priv,
1051 struct net_device *dev, struct rxpd *rxpd)
1052{
1053 if (priv->mesh_dev) {
1054 if (priv->mesh_tlv == TLV_TYPE_OLD_MESH_ID) {
1055 if (rxpd->rx_control & RxPD_MESH_FRAME)
1056 dev = priv->mesh_dev;
1057 } else if (priv->mesh_tlv == TLV_TYPE_MESH_ID) {
1058 if (rxpd->u.bss.bss_num == MESH_IFACE_ID)
1059 dev = priv->mesh_dev;
1060 }
1061 }
1062 return dev;
1063}
1064
1065
1066void lbs_mesh_set_txpd(struct lbs_private *priv,
1067 struct net_device *dev, struct txpd *txpd)
1068{
1069 if (dev == priv->mesh_dev) {
1070 if (priv->mesh_tlv == TLV_TYPE_OLD_MESH_ID)
1071 txpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
1072 else if (priv->mesh_tlv == TLV_TYPE_MESH_ID)
1073 txpd->u.bss.bss_num = MESH_IFACE_ID;
1074 }
1075}
1076
1266 1077
1267/*************************************************************************** 1078/***************************************************************************
1268 * Ethtool related 1079 * Ethtool related
1269 */ 1080 */
1270 1081
1271static const char *mesh_stat_strings[] = { 1082static const char * const mesh_stat_strings[] = {
1272 "drop_duplicate_bcast", 1083 "drop_duplicate_bcast",
1273 "drop_ttl_zero", 1084 "drop_ttl_zero",
1274 "drop_no_fwd_route", 1085 "drop_no_fwd_route",
diff --git a/drivers/net/wireless/libertas/mesh.h b/drivers/net/wireless/libertas/mesh.h
index ee95c73ed5f4..7d3dd8171fc0 100644
--- a/drivers/net/wireless/libertas/mesh.h
+++ b/drivers/net/wireless/libertas/mesh.h
@@ -31,7 +31,6 @@ struct lbs_private;
31int lbs_init_mesh(struct lbs_private *priv); 31int lbs_init_mesh(struct lbs_private *priv);
32int lbs_deinit_mesh(struct lbs_private *priv); 32int lbs_deinit_mesh(struct lbs_private *priv);
33 33
34int lbs_add_mesh(struct lbs_private *priv);
35void lbs_remove_mesh(struct lbs_private *priv); 34void lbs_remove_mesh(struct lbs_private *priv);
36 35
37 36
@@ -52,29 +51,6 @@ struct cmd_ds_command;
52struct cmd_ds_mesh_access; 51struct cmd_ds_mesh_access;
53struct cmd_ds_mesh_config; 52struct cmd_ds_mesh_config;
54 53
55int lbs_mesh_bt_add_del(struct lbs_private *priv, bool add, u8 *addr1);
56int lbs_mesh_bt_reset(struct lbs_private *priv);
57int lbs_mesh_bt_get_inverted(struct lbs_private *priv, bool *inverted);
58int lbs_mesh_bt_set_inverted(struct lbs_private *priv, bool inverted);
59int lbs_mesh_bt_get_entry(struct lbs_private *priv, u32 id, u8 *addr1);
60
61int lbs_cmd_fwt_access(struct lbs_private *priv, u16 cmd_action,
62 struct cmd_ds_fwt_access *cmd);
63
64int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
65 struct cmd_ds_mesh_access *cmd);
66int lbs_mesh_config_send(struct lbs_private *priv,
67 struct cmd_ds_mesh_config *cmd,
68 uint16_t action, uint16_t type);
69int lbs_mesh_config(struct lbs_private *priv, uint16_t enable, uint16_t chan);
70
71
72
73/* Persistent configuration */
74
75void lbs_persist_config_init(struct net_device *net);
76void lbs_persist_config_remove(struct net_device *net);
77
78 54
79/* Ethtool statistics */ 55/* Ethtool statistics */
80 56