aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/libertas/main.c
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/wireless/libertas/main.c
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/wireless/libertas/main.c')
-rw-r--r--drivers/net/wireless/libertas/main.c357
1 files changed, 15 insertions, 342 deletions
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;