aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorHolger Schurig <holgerschurig@gmail.com>2009-11-25 07:10:15 -0500
committerJohn W. Linville <linville@tuxdriver.com>2009-11-28 15:04:57 -0500
commite0e42da3a4df6f487b59dad608db56e25001bcdb (patch)
tree713a1535e7a1d4828ff1162dee545fd4af5592e2 /drivers/net
parent5e8e8b5759566b76bdf36046ae015796676a423c (diff)
libertas: moveing mesh-related functions into mesh.c
This moves mesh initialization, start/stop and rx/tx handling from into mesh.c. Signed-off-by: Holger Schurig <holgerschurig@gmail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/wireless/libertas/decl.h3
-rw-r--r--drivers/net/wireless/libertas/main.c357
-rw-r--r--drivers/net/wireless/libertas/mesh.c441
-rw-r--r--drivers/net/wireless/libertas/mesh.h24
-rw-r--r--drivers/net/wireless/libertas/rx.c11
-rw-r--r--drivers/net/wireless/libertas/tx.c7
6 files changed, 480 insertions, 363 deletions
diff --git a/drivers/net/wireless/libertas/decl.h b/drivers/net/wireless/libertas/decl.h
index cf3196a7343d..709ffcad22ad 100644
--- a/drivers/net/wireless/libertas/decl.h
+++ b/drivers/net/wireless/libertas/decl.h
@@ -34,6 +34,9 @@ int lbs_start_card(struct lbs_private *priv);
34void lbs_stop_card(struct lbs_private *priv); 34void lbs_stop_card(struct lbs_private *priv);
35void lbs_host_to_card_done(struct lbs_private *priv); 35void lbs_host_to_card_done(struct lbs_private *priv);
36 36
37int lbs_set_mac_address(struct net_device *dev, void *addr);
38void lbs_set_multicast_list(struct net_device *dev);
39
37int lbs_suspend(struct lbs_private *priv); 40int lbs_suspend(struct lbs_private *priv);
38void lbs_resume(struct lbs_private *priv); 41void lbs_resume(struct lbs_private *priv);
39 42
diff --git a/drivers/net/wireless/libertas/main.c b/drivers/net/wireless/libertas/main.c
index 01f46cf288d7..db38a5a719fa 100644
--- a/drivers/net/wireless/libertas/main.c
+++ b/drivers/net/wireless/libertas/main.c
@@ -94,107 +94,9 @@ u8 lbs_data_rate_to_fw_index(u32 rate)
94 return 0; 94 return 0;
95} 95}
96 96
97/**
98 * Attributes exported through sysfs
99 */
100
101/**
102 * @brief Get function for sysfs attribute anycast_mask
103 */
104static ssize_t lbs_anycast_get(struct device *dev,
105 struct device_attribute *attr, char * buf)
106{
107 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
108 struct cmd_ds_mesh_access mesh_access;
109 int ret;
110
111 memset(&mesh_access, 0, sizeof(mesh_access));
112
113 ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_ANYCAST, &mesh_access);
114 if (ret)
115 return ret;
116
117 return snprintf(buf, 12, "0x%X\n", le32_to_cpu(mesh_access.data[0]));
118}
119
120/**
121 * @brief Set function for sysfs attribute anycast_mask
122 */
123static ssize_t lbs_anycast_set(struct device *dev,
124 struct device_attribute *attr, const char * buf, size_t count)
125{
126 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
127 struct cmd_ds_mesh_access mesh_access;
128 uint32_t datum;
129 int ret;
130
131 memset(&mesh_access, 0, sizeof(mesh_access));
132 sscanf(buf, "%x", &datum);
133 mesh_access.data[0] = cpu_to_le32(datum);
134
135 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_ANYCAST, &mesh_access);
136 if (ret)
137 return ret;
138
139 return strlen(buf);
140}
141
142/**
143 * @brief Get function for sysfs attribute prb_rsp_limit
144 */
145static ssize_t lbs_prb_rsp_limit_get(struct device *dev,
146 struct device_attribute *attr, char *buf)
147{
148 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
149 struct cmd_ds_mesh_access mesh_access;
150 int ret;
151 u32 retry_limit;
152
153 memset(&mesh_access, 0, sizeof(mesh_access));
154 mesh_access.data[0] = cpu_to_le32(CMD_ACT_GET);
155
156 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT,
157 &mesh_access);
158 if (ret)
159 return ret;
160
161 retry_limit = le32_to_cpu(mesh_access.data[1]);
162 return snprintf(buf, 10, "%d\n", retry_limit);
163}
164
165/**
166 * @brief Set function for sysfs attribute prb_rsp_limit
167 */
168static ssize_t lbs_prb_rsp_limit_set(struct device *dev,
169 struct device_attribute *attr, const char *buf, size_t count)
170{
171 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
172 struct cmd_ds_mesh_access mesh_access;
173 int ret;
174 unsigned long retry_limit;
175
176 memset(&mesh_access, 0, sizeof(mesh_access));
177 mesh_access.data[0] = cpu_to_le32(CMD_ACT_SET);
178
179 if (!strict_strtoul(buf, 10, &retry_limit))
180 return -ENOTSUPP;
181 if (retry_limit > 15)
182 return -ENOTSUPP;
183
184 mesh_access.data[1] = cpu_to_le32(retry_limit);
185
186 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT,
187 &mesh_access);
188 if (ret)
189 return ret;
190
191 return strlen(buf);
192}
193 97
194static int lbs_add_rtap(struct lbs_private *priv); 98static int lbs_add_rtap(struct lbs_private *priv);
195static void lbs_remove_rtap(struct lbs_private *priv); 99static void lbs_remove_rtap(struct lbs_private *priv);
196static int lbs_add_mesh(struct lbs_private *priv);
197static void lbs_remove_mesh(struct lbs_private *priv);
198 100
199 101
200/** 102/**
@@ -260,74 +162,7 @@ static ssize_t lbs_rtap_set(struct device *dev,
260static DEVICE_ATTR(lbs_rtap, 0644, lbs_rtap_get, lbs_rtap_set ); 162static DEVICE_ATTR(lbs_rtap, 0644, lbs_rtap_get, lbs_rtap_set );
261 163
262/** 164/**
263 * Get function for sysfs attribute mesh 165 * @brief This function opens the ethX interface
264 */
265static ssize_t lbs_mesh_get(struct device *dev,
266 struct device_attribute *attr, char * buf)
267{
268 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
269 return snprintf(buf, 5, "0x%X\n", !!priv->mesh_dev);
270}
271
272/**
273 * Set function for sysfs attribute mesh
274 */
275static ssize_t lbs_mesh_set(struct device *dev,
276 struct device_attribute *attr, const char * buf, size_t count)
277{
278 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
279 int enable;
280 int ret, action = CMD_ACT_MESH_CONFIG_STOP;
281
282 sscanf(buf, "%x", &enable);
283 enable = !!enable;
284 if (enable == !!priv->mesh_dev)
285 return count;
286 if (enable)
287 action = CMD_ACT_MESH_CONFIG_START;
288 ret = lbs_mesh_config(priv, action, priv->channel);
289 if (ret)
290 return ret;
291
292 if (enable)
293 lbs_add_mesh(priv);
294 else
295 lbs_remove_mesh(priv);
296
297 return count;
298}
299
300/**
301 * lbs_mesh attribute to be exported per ethX interface
302 * through sysfs (/sys/class/net/ethX/lbs_mesh)
303 */
304static DEVICE_ATTR(lbs_mesh, 0644, lbs_mesh_get, lbs_mesh_set);
305
306/**
307 * anycast_mask attribute to be exported per mshX interface
308 * through sysfs (/sys/class/net/mshX/anycast_mask)
309 */
310static DEVICE_ATTR(anycast_mask, 0644, lbs_anycast_get, lbs_anycast_set);
311
312/**
313 * prb_rsp_limit attribute to be exported per mshX interface
314 * through sysfs (/sys/class/net/mshX/prb_rsp_limit)
315 */
316static DEVICE_ATTR(prb_rsp_limit, 0644, lbs_prb_rsp_limit_get,
317 lbs_prb_rsp_limit_set);
318
319static struct attribute *lbs_mesh_sysfs_entries[] = {
320 &dev_attr_anycast_mask.attr,
321 &dev_attr_prb_rsp_limit.attr,
322 NULL,
323};
324
325static struct attribute_group lbs_mesh_attr_group = {
326 .attrs = lbs_mesh_sysfs_entries,
327};
328
329/**
330 * @brief This function opens the ethX or mshX interface
331 * 166 *
332 * @param dev A pointer to net_device structure 167 * @param dev A pointer to net_device structure
333 * @return 0 or -EBUSY if monitor mode active 168 * @return 0 or -EBUSY if monitor mode active
@@ -346,18 +181,12 @@ static int lbs_dev_open(struct net_device *dev)
346 goto out; 181 goto out;
347 } 182 }
348 183
349 if (dev == priv->mesh_dev) { 184 priv->infra_open = 1;
350 priv->mesh_open = 1;
351 priv->mesh_connect_status = LBS_CONNECTED;
352 netif_carrier_on(dev);
353 } else {
354 priv->infra_open = 1;
355 185
356 if (priv->connect_status == LBS_CONNECTED) 186 if (priv->connect_status == LBS_CONNECTED)
357 netif_carrier_on(dev); 187 netif_carrier_on(dev);
358 else 188 else
359 netif_carrier_off(dev); 189 netif_carrier_off(dev);
360 }
361 190
362 if (!priv->tx_pending_len) 191 if (!priv->tx_pending_len)
363 netif_wake_queue(dev); 192 netif_wake_queue(dev);
@@ -369,33 +198,6 @@ static int lbs_dev_open(struct net_device *dev)
369} 198}
370 199
371/** 200/**
372 * @brief This function closes the mshX interface
373 *
374 * @param dev A pointer to net_device structure
375 * @return 0
376 */
377static int lbs_mesh_stop(struct net_device *dev)
378{
379 struct lbs_private *priv = dev->ml_priv;
380
381 lbs_deb_enter(LBS_DEB_MESH);
382 spin_lock_irq(&priv->driver_lock);
383
384 priv->mesh_open = 0;
385 priv->mesh_connect_status = LBS_DISCONNECTED;
386
387 netif_stop_queue(dev);
388 netif_carrier_off(dev);
389
390 spin_unlock_irq(&priv->driver_lock);
391
392 schedule_work(&priv->mcast_work);
393
394 lbs_deb_leave(LBS_DEB_MESH);
395 return 0;
396}
397
398/**
399 * @brief This function closes the ethX interface 201 * @brief This function closes the ethX interface
400 * 202 *
401 * @param dev A pointer to net_device structure 203 * @param dev A pointer to net_device structure
@@ -466,7 +268,7 @@ void lbs_host_to_card_done(struct lbs_private *priv)
466} 268}
467EXPORT_SYMBOL_GPL(lbs_host_to_card_done); 269EXPORT_SYMBOL_GPL(lbs_host_to_card_done);
468 270
469static int lbs_set_mac_address(struct net_device *dev, void *addr) 271int lbs_set_mac_address(struct net_device *dev, void *addr)
470{ 272{
471 int ret = 0; 273 int ret = 0;
472 struct lbs_private *priv = dev->ml_priv; 274 struct lbs_private *priv = dev->ml_priv;
@@ -600,7 +402,7 @@ static void lbs_set_mcast_worker(struct work_struct *work)
600 lbs_deb_leave(LBS_DEB_NET); 402 lbs_deb_leave(LBS_DEB_NET);
601} 403}
602 404
603static void lbs_set_multicast_list(struct net_device *dev) 405void lbs_set_multicast_list(struct net_device *dev)
604{ 406{
605 struct lbs_private *priv = dev->ml_priv; 407 struct lbs_private *priv = dev->ml_priv;
606 408
@@ -1177,7 +979,6 @@ struct lbs_private *lbs_add_card(void *card, struct device *dmdev)
1177 979
1178 980
1179 priv->card = card; 981 priv->card = card;
1180 priv->mesh_open = 0;
1181 priv->infra_open = 0; 982 priv->infra_open = 0;
1182 983
1183 984
@@ -1198,6 +999,7 @@ struct lbs_private *lbs_add_card(void *card, struct device *dmdev)
1198 INIT_WORK(&priv->mcast_work, lbs_set_mcast_worker); 999 INIT_WORK(&priv->mcast_work, lbs_set_mcast_worker);
1199 INIT_WORK(&priv->sync_channel, lbs_sync_channel_worker); 1000 INIT_WORK(&priv->sync_channel, lbs_sync_channel_worker);
1200 1001
1002 priv->mesh_open = 0;
1201 sprintf(priv->mesh_ssid, "mesh"); 1003 sprintf(priv->mesh_ssid, "mesh");
1202 priv->mesh_ssid_len = 4; 1004 priv->mesh_ssid_len = 4;
1203 1005
@@ -1292,50 +1094,12 @@ int lbs_start_card(struct lbs_private *priv)
1292 1094
1293 lbs_update_channel(priv); 1095 lbs_update_channel(priv);
1294 1096
1295 /* Check mesh FW version and appropriately send the mesh start 1097 /*
1296 * command 1098 * While rtap isn't related to mesh, only mesh-enabled
1099 * firmware implements the rtap functionality via
1100 * CMD_802_11_MONITOR_MODE.
1297 */ 1101 */
1298 if (priv->mesh_fw_ver == MESH_FW_OLD) { 1102 if (lbs_init_mesh(priv)) {
1299 /* Enable mesh, if supported, and work out which TLV it uses.
1300 0x100 + 291 is an unofficial value used in 5.110.20.pXX
1301 0x100 + 37 is the official value used in 5.110.21.pXX
1302 but we check them in that order because 20.pXX doesn't
1303 give an error -- it just silently fails. */
1304
1305 /* 5.110.20.pXX firmware will fail the command if the channel
1306 doesn't match the existing channel. But only if the TLV
1307 is correct. If the channel is wrong, _BOTH_ versions will
1308 give an error to 0x100+291, and allow 0x100+37 to succeed.
1309 It's just that 5.110.20.pXX will not have done anything
1310 useful */
1311
1312 priv->mesh_tlv = TLV_TYPE_OLD_MESH_ID;
1313 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
1314 priv->channel)) {
1315 priv->mesh_tlv = TLV_TYPE_MESH_ID;
1316 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
1317 priv->channel))
1318 priv->mesh_tlv = 0;
1319 }
1320 } else if (priv->mesh_fw_ver == MESH_FW_NEW) {
1321 /* 10.0.0.pXX new firmwares should succeed with TLV
1322 * 0x100+37; Do not invoke command with old TLV.
1323 */
1324 priv->mesh_tlv = TLV_TYPE_MESH_ID;
1325 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
1326 priv->channel))
1327 priv->mesh_tlv = 0;
1328 }
1329 if (priv->mesh_tlv) {
1330 lbs_add_mesh(priv);
1331
1332 if (device_create_file(&dev->dev, &dev_attr_lbs_mesh))
1333 lbs_pr_err("cannot register lbs_mesh attribute\n");
1334
1335 /* While rtap isn't related to mesh, only mesh-enabled
1336 * firmware implements the rtap functionality via
1337 * CMD_802_11_MONITOR_MODE.
1338 */
1339 if (device_create_file(&dev->dev, &dev_attr_lbs_rtap)) 1103 if (device_create_file(&dev->dev, &dev_attr_lbs_rtap))
1340 lbs_pr_err("cannot register lbs_rtap attribute\n"); 1104 lbs_pr_err("cannot register lbs_rtap attribute\n");
1341 } 1105 }
@@ -1369,10 +1133,8 @@ void lbs_stop_card(struct lbs_private *priv)
1369 netif_carrier_off(dev); 1133 netif_carrier_off(dev);
1370 1134
1371 lbs_debugfs_remove_one(priv); 1135 lbs_debugfs_remove_one(priv);
1372 if (priv->mesh_tlv) { 1136 if (lbs_deinit_mesh(priv))
1373 device_remove_file(&dev->dev, &dev_attr_lbs_mesh);
1374 device_remove_file(&dev->dev, &dev_attr_lbs_rtap); 1137 device_remove_file(&dev->dev, &dev_attr_lbs_rtap);
1375 }
1376 1138
1377 /* Delete the timeout of the currently processing command */ 1139 /* Delete the timeout of the currently processing command */
1378 del_timer_sync(&priv->command_timer); 1140 del_timer_sync(&priv->command_timer);
@@ -1405,95 +1167,6 @@ out:
1405EXPORT_SYMBOL_GPL(lbs_stop_card); 1167EXPORT_SYMBOL_GPL(lbs_stop_card);
1406 1168
1407 1169
1408static const struct net_device_ops mesh_netdev_ops = {
1409 .ndo_open = lbs_dev_open,
1410 .ndo_stop = lbs_mesh_stop,
1411 .ndo_start_xmit = lbs_hard_start_xmit,
1412 .ndo_set_mac_address = lbs_set_mac_address,
1413 .ndo_set_multicast_list = lbs_set_multicast_list,
1414};
1415
1416/**
1417 * @brief This function adds mshX interface
1418 *
1419 * @param priv A pointer to the struct lbs_private structure
1420 * @return 0 if successful, -X otherwise
1421 */
1422static int lbs_add_mesh(struct lbs_private *priv)
1423{
1424 struct net_device *mesh_dev = NULL;
1425 int ret = 0;
1426
1427 lbs_deb_enter(LBS_DEB_MESH);
1428
1429 /* Allocate a virtual mesh device */
1430 if (!(mesh_dev = alloc_netdev(0, "msh%d", ether_setup))) {
1431 lbs_deb_mesh("init mshX device failed\n");
1432 ret = -ENOMEM;
1433 goto done;
1434 }
1435 mesh_dev->ml_priv = priv;
1436 priv->mesh_dev = mesh_dev;
1437
1438 mesh_dev->netdev_ops = &mesh_netdev_ops;
1439 mesh_dev->ethtool_ops = &lbs_ethtool_ops;
1440 memcpy(mesh_dev->dev_addr, priv->dev->dev_addr,
1441 sizeof(priv->dev->dev_addr));
1442
1443 SET_NETDEV_DEV(priv->mesh_dev, priv->dev->dev.parent);
1444
1445#ifdef WIRELESS_EXT
1446 mesh_dev->wireless_handlers = (struct iw_handler_def *)&mesh_handler_def;
1447#endif
1448 mesh_dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
1449 /* Register virtual mesh interface */
1450 ret = register_netdev(mesh_dev);
1451 if (ret) {
1452 lbs_pr_err("cannot register mshX virtual interface\n");
1453 goto err_free;
1454 }
1455
1456 ret = sysfs_create_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
1457 if (ret)
1458 goto err_unregister;
1459
1460 lbs_persist_config_init(mesh_dev);
1461
1462 /* Everything successful */
1463 ret = 0;
1464 goto done;
1465
1466err_unregister:
1467 unregister_netdev(mesh_dev);
1468
1469err_free:
1470 free_netdev(mesh_dev);
1471
1472done:
1473 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
1474 return ret;
1475}
1476
1477static void lbs_remove_mesh(struct lbs_private *priv)
1478{
1479 struct net_device *mesh_dev;
1480
1481
1482 mesh_dev = priv->mesh_dev;
1483 if (!mesh_dev)
1484 return;
1485
1486 lbs_deb_enter(LBS_DEB_MESH);
1487 netif_stop_queue(mesh_dev);
1488 netif_carrier_off(mesh_dev);
1489 sysfs_remove_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
1490 lbs_persist_config_remove(mesh_dev);
1491 unregister_netdev(mesh_dev);
1492 priv->mesh_dev = NULL;
1493 free_netdev(mesh_dev);
1494 lbs_deb_leave(LBS_DEB_MESH);
1495}
1496
1497void lbs_queue_event(struct lbs_private *priv, u32 event) 1170void lbs_queue_event(struct lbs_private *priv, u32 event)
1498{ 1171{
1499 unsigned long flags; 1172 unsigned long flags;
diff --git a/drivers/net/wireless/libertas/mesh.c b/drivers/net/wireless/libertas/mesh.c
index 871f914a75fc..80c2c7a31c8e 100644
--- a/drivers/net/wireless/libertas/mesh.c
+++ b/drivers/net/wireless/libertas/mesh.c
@@ -6,15 +6,444 @@
6#include <linux/kthread.h> 6#include <linux/kthread.h>
7#include <linux/kfifo.h> 7#include <linux/kfifo.h>
8 8
9#include "host.h" 9#include "mesh.h"
10#include "decl.h" 10#include "decl.h"
11#include "dev.h"
12#include "wext.h"
13#include "debugfs.h"
14#include "scan.h"
15#include "assoc.h"
16#include "cmd.h" 11#include "cmd.h"
17 12
13
14/***************************************************************************
15 * Mesh sysfs support
16 */
17
18/**
19 * Attributes exported through sysfs
20 */
21
22/**
23 * @brief Get function for sysfs attribute anycast_mask
24 */
25static ssize_t lbs_anycast_get(struct device *dev,
26 struct device_attribute *attr, char * buf)
27{
28 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
29 struct cmd_ds_mesh_access mesh_access;
30 int ret;
31
32 memset(&mesh_access, 0, sizeof(mesh_access));
33
34 ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_ANYCAST, &mesh_access);
35 if (ret)
36 return ret;
37
38 return snprintf(buf, 12, "0x%X\n", le32_to_cpu(mesh_access.data[0]));
39}
40
41/**
42 * @brief Set function for sysfs attribute anycast_mask
43 */
44static ssize_t lbs_anycast_set(struct device *dev,
45 struct device_attribute *attr, const char * buf, size_t count)
46{
47 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
48 struct cmd_ds_mesh_access mesh_access;
49 uint32_t datum;
50 int ret;
51
52 memset(&mesh_access, 0, sizeof(mesh_access));
53 sscanf(buf, "%x", &datum);
54 mesh_access.data[0] = cpu_to_le32(datum);
55
56 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_ANYCAST, &mesh_access);
57 if (ret)
58 return ret;
59
60 return strlen(buf);
61}
62
63/**
64 * @brief Get function for sysfs attribute prb_rsp_limit
65 */
66static ssize_t lbs_prb_rsp_limit_get(struct device *dev,
67 struct device_attribute *attr, char *buf)
68{
69 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
70 struct cmd_ds_mesh_access mesh_access;
71 int ret;
72 u32 retry_limit;
73
74 memset(&mesh_access, 0, sizeof(mesh_access));
75 mesh_access.data[0] = cpu_to_le32(CMD_ACT_GET);
76
77 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT,
78 &mesh_access);
79 if (ret)
80 return ret;
81
82 retry_limit = le32_to_cpu(mesh_access.data[1]);
83 return snprintf(buf, 10, "%d\n", retry_limit);
84}
85
86/**
87 * @brief Set function for sysfs attribute prb_rsp_limit
88 */
89static ssize_t lbs_prb_rsp_limit_set(struct device *dev,
90 struct device_attribute *attr, const char *buf, size_t count)
91{
92 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
93 struct cmd_ds_mesh_access mesh_access;
94 int ret;
95 unsigned long retry_limit;
96
97 memset(&mesh_access, 0, sizeof(mesh_access));
98 mesh_access.data[0] = cpu_to_le32(CMD_ACT_SET);
99
100 if (!strict_strtoul(buf, 10, &retry_limit))
101 return -ENOTSUPP;
102 if (retry_limit > 15)
103 return -ENOTSUPP;
104
105 mesh_access.data[1] = cpu_to_le32(retry_limit);
106
107 ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT,
108 &mesh_access);
109 if (ret)
110 return ret;
111
112 return strlen(buf);
113}
114
115/**
116 * Get function for sysfs attribute mesh
117 */
118static ssize_t lbs_mesh_get(struct device *dev,
119 struct device_attribute *attr, char * buf)
120{
121 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
122 return snprintf(buf, 5, "0x%X\n", !!priv->mesh_dev);
123}
124
125/**
126 * Set function for sysfs attribute mesh
127 */
128static ssize_t lbs_mesh_set(struct device *dev,
129 struct device_attribute *attr, const char * buf, size_t count)
130{
131 struct lbs_private *priv = to_net_dev(dev)->ml_priv;
132 int enable;
133 int ret, action = CMD_ACT_MESH_CONFIG_STOP;
134
135 sscanf(buf, "%x", &enable);
136 enable = !!enable;
137 if (enable == !!priv->mesh_dev)
138 return count;
139 if (enable)
140 action = CMD_ACT_MESH_CONFIG_START;
141 ret = lbs_mesh_config(priv, action, priv->channel);
142 if (ret)
143 return ret;
144
145 if (enable)
146 lbs_add_mesh(priv);
147 else
148 lbs_remove_mesh(priv);
149
150 return count;
151}
152
153/**
154 * lbs_mesh attribute to be exported per ethX interface
155 * through sysfs (/sys/class/net/ethX/lbs_mesh)
156 */
157static DEVICE_ATTR(lbs_mesh, 0644, lbs_mesh_get, lbs_mesh_set);
158
159/**
160 * anycast_mask attribute to be exported per mshX interface
161 * through sysfs (/sys/class/net/mshX/anycast_mask)
162 */
163static DEVICE_ATTR(anycast_mask, 0644, lbs_anycast_get, lbs_anycast_set);
164
165/**
166 * prb_rsp_limit attribute to be exported per mshX interface
167 * through sysfs (/sys/class/net/mshX/prb_rsp_limit)
168 */
169static DEVICE_ATTR(prb_rsp_limit, 0644, lbs_prb_rsp_limit_get,
170 lbs_prb_rsp_limit_set);
171
172static struct attribute *lbs_mesh_sysfs_entries[] = {
173 &dev_attr_anycast_mask.attr,
174 &dev_attr_prb_rsp_limit.attr,
175 NULL,
176};
177
178static struct attribute_group lbs_mesh_attr_group = {
179 .attrs = lbs_mesh_sysfs_entries,
180};
181
182
183
184/***************************************************************************
185 * Initializing and starting, stopping mesh
186 */
187
188/*
189 * Check mesh FW version and appropriately send the mesh start
190 * command
191 */
192int lbs_init_mesh(struct lbs_private *priv)
193{
194 struct net_device *dev = priv->dev;
195 int ret = 0;
196
197 lbs_deb_enter(LBS_DEB_MESH);
198
199 if (priv->mesh_fw_ver == MESH_FW_OLD) {
200 /* Enable mesh, if supported, and work out which TLV it uses.
201 0x100 + 291 is an unofficial value used in 5.110.20.pXX
202 0x100 + 37 is the official value used in 5.110.21.pXX
203 but we check them in that order because 20.pXX doesn't
204 give an error -- it just silently fails. */
205
206 /* 5.110.20.pXX firmware will fail the command if the channel
207 doesn't match the existing channel. But only if the TLV
208 is correct. If the channel is wrong, _BOTH_ versions will
209 give an error to 0x100+291, and allow 0x100+37 to succeed.
210 It's just that 5.110.20.pXX will not have done anything
211 useful */
212
213 priv->mesh_tlv = TLV_TYPE_OLD_MESH_ID;
214 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
215 priv->channel)) {
216 priv->mesh_tlv = TLV_TYPE_MESH_ID;
217 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
218 priv->channel))
219 priv->mesh_tlv = 0;
220 }
221 } else if (priv->mesh_fw_ver == MESH_FW_NEW) {
222 /* 10.0.0.pXX new firmwares should succeed with TLV
223 * 0x100+37; Do not invoke command with old TLV.
224 */
225 priv->mesh_tlv = TLV_TYPE_MESH_ID;
226 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
227 priv->channel))
228 priv->mesh_tlv = 0;
229 }
230 if (priv->mesh_tlv) {
231 lbs_add_mesh(priv);
232
233 if (device_create_file(&dev->dev, &dev_attr_lbs_mesh))
234 lbs_pr_err("cannot register lbs_mesh attribute\n");
235
236 ret = 1;
237 }
238
239 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
240 return ret;
241}
242
243
244int lbs_deinit_mesh(struct lbs_private *priv)
245{
246 struct net_device *dev = priv->dev;
247 int ret = 0;
248
249 lbs_deb_enter(LBS_DEB_MESH);
250
251 if (priv->mesh_tlv) {
252 device_remove_file(&dev->dev, &dev_attr_lbs_mesh);
253 ret = 1;
254 }
255
256 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
257 return ret;
258}
259
260
261/**
262 * @brief This function closes the mshX interface
263 *
264 * @param dev A pointer to net_device structure
265 * @return 0
266 */
267static int lbs_mesh_stop(struct net_device *dev)
268{
269 struct lbs_private *priv = dev->ml_priv;
270
271 lbs_deb_enter(LBS_DEB_MESH);
272 spin_lock_irq(&priv->driver_lock);
273
274 priv->mesh_open = 0;
275 priv->mesh_connect_status = LBS_DISCONNECTED;
276
277 netif_stop_queue(dev);
278 netif_carrier_off(dev);
279
280 spin_unlock_irq(&priv->driver_lock);
281
282 schedule_work(&priv->mcast_work);
283
284 lbs_deb_leave(LBS_DEB_MESH);
285 return 0;
286}
287
288/**
289 * @brief This function opens the mshX interface
290 *
291 * @param dev A pointer to net_device structure
292 * @return 0 or -EBUSY if monitor mode active
293 */
294static int lbs_mesh_dev_open(struct net_device *dev)
295{
296 struct lbs_private *priv = dev->ml_priv;
297 int ret = 0;
298
299 lbs_deb_enter(LBS_DEB_NET);
300
301 spin_lock_irq(&priv->driver_lock);
302
303 if (priv->monitormode) {
304 ret = -EBUSY;
305 goto out;
306 }
307
308 priv->mesh_open = 1;
309 priv->mesh_connect_status = LBS_CONNECTED;
310 netif_carrier_on(dev);
311
312 if (!priv->tx_pending_len)
313 netif_wake_queue(dev);
314 out:
315
316 spin_unlock_irq(&priv->driver_lock);
317 lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
318 return ret;
319}
320
321static const struct net_device_ops mesh_netdev_ops = {
322 .ndo_open = lbs_mesh_dev_open,
323 .ndo_stop = lbs_mesh_stop,
324 .ndo_start_xmit = lbs_hard_start_xmit,
325 .ndo_set_mac_address = lbs_set_mac_address,
326 .ndo_set_multicast_list = lbs_set_multicast_list,
327};
328
329/**
330 * @brief This function adds mshX interface
331 *
332 * @param priv A pointer to the struct lbs_private structure
333 * @return 0 if successful, -X otherwise
334 */
335int lbs_add_mesh(struct lbs_private *priv)
336{
337 struct net_device *mesh_dev = NULL;
338 int ret = 0;
339
340 lbs_deb_enter(LBS_DEB_MESH);
341
342 /* Allocate a virtual mesh device */
343 mesh_dev = alloc_netdev(0, "msh%d", ether_setup);
344 if (!mesh_dev) {
345 lbs_deb_mesh("init mshX device failed\n");
346 ret = -ENOMEM;
347 goto done;
348 }
349 mesh_dev->ml_priv = priv;
350 priv->mesh_dev = mesh_dev;
351
352 mesh_dev->netdev_ops = &mesh_netdev_ops;
353 mesh_dev->ethtool_ops = &lbs_ethtool_ops;
354 memcpy(mesh_dev->dev_addr, priv->dev->dev_addr,
355 sizeof(priv->dev->dev_addr));
356
357 SET_NETDEV_DEV(priv->mesh_dev, priv->dev->dev.parent);
358
359#ifdef WIRELESS_EXT
360 mesh_dev->wireless_handlers = &mesh_handler_def;
361#endif
362 mesh_dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
363 /* Register virtual mesh interface */
364 ret = register_netdev(mesh_dev);
365 if (ret) {
366 lbs_pr_err("cannot register mshX virtual interface\n");
367 goto err_free;
368 }
369
370 ret = sysfs_create_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
371 if (ret)
372 goto err_unregister;
373
374 lbs_persist_config_init(mesh_dev);
375
376 /* Everything successful */
377 ret = 0;
378 goto done;
379
380err_unregister:
381 unregister_netdev(mesh_dev);
382
383err_free:
384 free_netdev(mesh_dev);
385
386done:
387 lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
388 return ret;
389}
390
391void lbs_remove_mesh(struct lbs_private *priv)
392{
393 struct net_device *mesh_dev;
394
395 mesh_dev = priv->mesh_dev;
396 if (!mesh_dev)
397 return;
398
399 lbs_deb_enter(LBS_DEB_MESH);
400 netif_stop_queue(mesh_dev);
401 netif_carrier_off(mesh_dev);
402 sysfs_remove_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
403 lbs_persist_config_remove(mesh_dev);
404 unregister_netdev(mesh_dev);
405 priv->mesh_dev = NULL;
406 free_netdev(mesh_dev);
407 lbs_deb_leave(LBS_DEB_MESH);
408}
409
410
411
412/***************************************************************************
413 * Sending and receiving
414 */
415struct net_device *lbs_mesh_set_dev(struct lbs_private *priv,
416 struct net_device *dev, struct rxpd *rxpd)
417{
418 if (priv->mesh_dev) {
419 if (priv->mesh_fw_ver == MESH_FW_OLD) {
420 if (rxpd->rx_control & RxPD_MESH_FRAME)
421 dev = priv->mesh_dev;
422 } else if (priv->mesh_fw_ver == MESH_FW_NEW) {
423 if (rxpd->u.bss.bss_num == MESH_IFACE_ID)
424 dev = priv->mesh_dev;
425 }
426 }
427 return dev;
428}
429
430
431void lbs_mesh_set_txpd(struct lbs_private *priv,
432 struct net_device *dev, struct txpd *txpd)
433{
434 if (dev == priv->mesh_dev) {
435 if (priv->mesh_fw_ver == MESH_FW_OLD)
436 txpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
437 else if (priv->mesh_fw_ver == MESH_FW_NEW)
438 txpd->u.bss.bss_num = MESH_IFACE_ID;
439 }
440}
441
442
443/***************************************************************************
444 * Persistent configuration support
445 */
446
18static int mesh_get_default_parameters(struct device *dev, 447static int mesh_get_default_parameters(struct device *dev,
19 struct mrvl_mesh_defaults *defs) 448 struct mrvl_mesh_defaults *defs)
20{ 449{
diff --git a/drivers/net/wireless/libertas/mesh.h b/drivers/net/wireless/libertas/mesh.h
index 3708b6b386cb..d683c6eef83c 100644
--- a/drivers/net/wireless/libertas/mesh.h
+++ b/drivers/net/wireless/libertas/mesh.h
@@ -22,10 +22,34 @@ struct lbs_mesh_stats {
22 22
23 23
24struct net_device; 24struct net_device;
25struct lbs_private;
26
27int lbs_init_mesh(struct lbs_private *priv);
28int lbs_deinit_mesh(struct lbs_private *priv);
29
30int lbs_add_mesh(struct lbs_private *priv);
31void lbs_remove_mesh(struct lbs_private *priv);
32
33
34/* Sending / Receiving */
35
36struct rxpd;
37struct txpd;
38
39struct net_device *lbs_mesh_set_dev(struct lbs_private *priv,
40 struct net_device *dev, struct rxpd *rxpd);
41void lbs_mesh_set_txpd(struct lbs_private *priv,
42 struct net_device *dev, struct txpd *txpd);
43
44
45/* Persistent configuration */
25 46
26void lbs_persist_config_init(struct net_device *net); 47void lbs_persist_config_init(struct net_device *net);
27void lbs_persist_config_remove(struct net_device *net); 48void lbs_persist_config_remove(struct net_device *net);
28 49
50
51/* WEXT handler */
52
29extern struct iw_handler_def mesh_handler_def; 53extern struct iw_handler_def mesh_handler_def;
30 54
31 55
diff --git a/drivers/net/wireless/libertas/rx.c b/drivers/net/wireless/libertas/rx.c
index 9f18a19cc49d..2daf8ffdb7e1 100644
--- a/drivers/net/wireless/libertas/rx.c
+++ b/drivers/net/wireless/libertas/rx.c
@@ -160,15 +160,8 @@ int lbs_process_rxed_packet(struct lbs_private *priv, struct sk_buff *skb)
160 p_rx_pd = (struct rxpd *) skb->data; 160 p_rx_pd = (struct rxpd *) skb->data;
161 p_rx_pkt = (struct rxpackethdr *) ((u8 *)p_rx_pd + 161 p_rx_pkt = (struct rxpackethdr *) ((u8 *)p_rx_pd +
162 le32_to_cpu(p_rx_pd->pkt_ptr)); 162 le32_to_cpu(p_rx_pd->pkt_ptr));
163 if (priv->mesh_dev) { 163
164 if (priv->mesh_fw_ver == MESH_FW_OLD) { 164 dev = lbs_mesh_set_dev(priv, dev, p_rx_pd);
165 if (p_rx_pd->rx_control & RxPD_MESH_FRAME)
166 dev = priv->mesh_dev;
167 } else if (priv->mesh_fw_ver == MESH_FW_NEW) {
168 if (p_rx_pd->u.bss.bss_num == MESH_IFACE_ID)
169 dev = priv->mesh_dev;
170 }
171 }
172 165
173 lbs_deb_hex(LBS_DEB_RX, "RX Data: Before chop rxpd", skb->data, 166 lbs_deb_hex(LBS_DEB_RX, "RX Data: Before chop rxpd", skb->data,
174 min_t(unsigned int, skb->len, 100)); 167 min_t(unsigned int, skb->len, 100));
diff --git a/drivers/net/wireless/libertas/tx.c b/drivers/net/wireless/libertas/tx.c
index eb856adbf8ea..315d1ce286ca 100644
--- a/drivers/net/wireless/libertas/tx.c
+++ b/drivers/net/wireless/libertas/tx.c
@@ -131,12 +131,7 @@ netdev_tx_t lbs_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
131 txpd->tx_packet_length = cpu_to_le16(pkt_len); 131 txpd->tx_packet_length = cpu_to_le16(pkt_len);
132 txpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd)); 132 txpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd));
133 133
134 if (dev == priv->mesh_dev) { 134 lbs_mesh_set_txpd(priv, dev, txpd);
135 if (priv->mesh_fw_ver == MESH_FW_OLD)
136 txpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
137 else if (priv->mesh_fw_ver == MESH_FW_NEW)
138 txpd->u.bss.bss_num = MESH_IFACE_ID;
139 }
140 135
141 lbs_deb_hex(LBS_DEB_TX, "txpd", (u8 *) &txpd, sizeof(struct txpd)); 136 lbs_deb_hex(LBS_DEB_TX, "txpd", (u8 *) &txpd, sizeof(struct txpd));
142 137