Commit | Line | Data |
---|---|---|
0e4e06ae JP |
1 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
2 | ||
15dbaac0 JC |
3 | #include <linux/delay.h> |
4 | #include <linux/etherdevice.h> | |
a6b7a407 | 5 | #include <linux/hardirq.h> |
15dbaac0 | 6 | #include <linux/netdevice.h> |
1f044931 | 7 | #include <linux/if_ether.h> |
15dbaac0 JC |
8 | #include <linux/if_arp.h> |
9 | #include <linux/kthread.h> | |
10 | #include <linux/kfifo.h> | |
e86dc1ca | 11 | #include <net/cfg80211.h> |
15dbaac0 | 12 | |
e0e42da3 | 13 | #include "mesh.h" |
15dbaac0 | 14 | #include "decl.h" |
15dbaac0 JC |
15 | #include "cmd.h" |
16 | ||
e0e42da3 HS |
17 | |
18 | /*************************************************************************** | |
19 | * Mesh sysfs support | |
20 | */ | |
21 | ||
8973a6e7 | 22 | /* |
e0e42da3 HS |
23 | * Attributes exported through sysfs |
24 | */ | |
25 | ||
26 | /** | |
8973a6e7 RD |
27 | * 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 | |
e0e42da3 HS |
31 | */ |
32 | static 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 | /** | |
8973a6e7 RD |
49 | * 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 | |
e0e42da3 HS |
54 | */ |
55 | static 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 | /** | |
8973a6e7 RD |
75 | * 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 | |
e0e42da3 HS |
79 | */ |
80 | static 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 | /** | |
8973a6e7 RD |
101 | * 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 | |
e0e42da3 HS |
106 | */ |
107 | static 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 | /** | |
8973a6e7 RD |
134 | * 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 | |
e0e42da3 HS |
138 | */ |
139 | static 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 | /** | |
8973a6e7 RD |
147 | * 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 | |
e0e42da3 HS |
152 | */ |
153 | static 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 | ||
8973a6e7 | 178 | /* |
e0e42da3 HS |
179 | * lbs_mesh attribute to be exported per ethX interface |
180 | * through sysfs (/sys/class/net/ethX/lbs_mesh) | |
181 | */ | |
182 | static DEVICE_ATTR(lbs_mesh, 0644, lbs_mesh_get, lbs_mesh_set); | |
183 | ||
8973a6e7 | 184 | /* |
e0e42da3 HS |
185 | * anycast_mask attribute to be exported per mshX interface |
186 | * through sysfs (/sys/class/net/mshX/anycast_mask) | |
187 | */ | |
188 | static DEVICE_ATTR(anycast_mask, 0644, lbs_anycast_get, lbs_anycast_set); | |
189 | ||
8973a6e7 | 190 | /* |
e0e42da3 HS |
191 | * prb_rsp_limit attribute to be exported per mshX interface |
192 | * through sysfs (/sys/class/net/mshX/prb_rsp_limit) | |
193 | */ | |
194 | static DEVICE_ATTR(prb_rsp_limit, 0644, lbs_prb_rsp_limit_get, | |
195 | lbs_prb_rsp_limit_set); | |
196 | ||
197 | static struct attribute *lbs_mesh_sysfs_entries[] = { | |
198 | &dev_attr_anycast_mask.attr, | |
199 | &dev_attr_prb_rsp_limit.attr, | |
200 | NULL, | |
201 | }; | |
202 | ||
203 | static 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 | */ | |
217 | int 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 | ||
602114ae HS |
224 | priv->mesh_connect_status = LBS_DISCONNECTED; |
225 | ||
c24ef46e HS |
226 | /* 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) { | |
e0e42da3 HS |
232 | /* 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 | } | |
c24ef46e HS |
253 | } else |
254 | if ((MRVL_FW_MAJOR_REV(priv->fwrelease) >= MRVL_FW_V10) && | |
255 | (priv->fwcapinfo & MESH_CAPINFO_ENABLE_MASK)) { | |
e0e42da3 HS |
256 | /* 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 | } | |
c24ef46e HS |
264 | |
265 | ||
e0e42da3 | 266 | if (priv->mesh_tlv) { |
e4da1a81 HS |
267 | sprintf(priv->mesh_ssid, "mesh"); |
268 | priv->mesh_ssid_len = 4; | |
269 | ||
e0e42da3 HS |
270 | lbs_add_mesh(priv); |
271 | ||
272 | if (device_create_file(&dev->dev, &dev_attr_lbs_mesh)) | |
f3a57fd1 | 273 | netdev_err(dev, "cannot register lbs_mesh attribute\n"); |
e0e42da3 HS |
274 | |
275 | ret = 1; | |
276 | } | |
277 | ||
278 | lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret); | |
279 | return ret; | |
280 | } | |
281 | ||
282 | ||
283 | int 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 | /** | |
8973a6e7 | 301 | * lbs_mesh_stop - close the mshX interface |
e0e42da3 | 302 | * |
8973a6e7 RD |
303 | * @dev: A pointer to &net_device structure |
304 | * returns: 0 | |
e0e42da3 HS |
305 | */ |
306 | static 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 | /** | |
8973a6e7 | 328 | * lbs_mesh_dev_open - open the mshX interface |
e0e42da3 | 329 | * |
8973a6e7 RD |
330 | * @dev: A pointer to &net_device structure |
331 | * returns: 0 or -EBUSY if monitor mode active | |
e0e42da3 HS |
332 | */ |
333 | static 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 | ||
e86dc1ca | 342 | if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR) { |
e0e42da3 HS |
343 | 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 | ||
360 | static 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 | /** | |
8973a6e7 | 369 | * lbs_add_mesh - add mshX interface |
e0e42da3 | 370 | * |
8973a6e7 RD |
371 | * @priv: A pointer to the &struct lbs_private structure |
372 | * returns: 0 if successful, -X otherwise | |
e0e42da3 HS |
373 | */ |
374 | int 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; | |
1f044931 | 393 | memcpy(mesh_dev->dev_addr, priv->dev->dev_addr, ETH_ALEN); |
e0e42da3 HS |
394 | |
395 | SET_NETDEV_DEV(priv->mesh_dev, priv->dev->dev.parent); | |
396 | ||
e0e42da3 HS |
397 | mesh_dev->flags |= IFF_BROADCAST | IFF_MULTICAST; |
398 | /* Register virtual mesh interface */ | |
399 | ret = register_netdev(mesh_dev); | |
400 | if (ret) { | |
0e4e06ae | 401 | pr_err("cannot register mshX virtual interface\n"); |
e0e42da3 HS |
402 | 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 | ||
415 | err_unregister: | |
416 | unregister_netdev(mesh_dev); | |
417 | ||
418 | err_free: | |
419 | free_netdev(mesh_dev); | |
420 | ||
421 | done: | |
422 | lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret); | |
423 | return ret; | |
424 | } | |
425 | ||
426 | void 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 | */ | |
450 | struct net_device *lbs_mesh_set_dev(struct lbs_private *priv, | |
451 | struct net_device *dev, struct rxpd *rxpd) | |
452 | { | |
453 | if (priv->mesh_dev) { | |
c24ef46e | 454 | if (priv->mesh_tlv == TLV_TYPE_OLD_MESH_ID) { |
e0e42da3 HS |
455 | if (rxpd->rx_control & RxPD_MESH_FRAME) |
456 | dev = priv->mesh_dev; | |
c24ef46e | 457 | } else if (priv->mesh_tlv == TLV_TYPE_MESH_ID) { |
e0e42da3 HS |
458 | if (rxpd->u.bss.bss_num == MESH_IFACE_ID) |
459 | dev = priv->mesh_dev; | |
460 | } | |
461 | } | |
462 | return dev; | |
463 | } | |
464 | ||
465 | ||
466 | void lbs_mesh_set_txpd(struct lbs_private *priv, | |
467 | struct net_device *dev, struct txpd *txpd) | |
468 | { | |
469 | if (dev == priv->mesh_dev) { | |
c24ef46e | 470 | if (priv->mesh_tlv == TLV_TYPE_OLD_MESH_ID) |
e0e42da3 | 471 | txpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME); |
c24ef46e | 472 | else if (priv->mesh_tlv == TLV_TYPE_MESH_ID) |
e0e42da3 HS |
473 | txpd->u.bss.bss_num = MESH_IFACE_ID; |
474 | } | |
475 | } | |
476 | ||
477 | ||
ece1e3c6 HS |
478 | /*************************************************************************** |
479 | * Mesh command handling | |
480 | */ | |
481 | ||
52148655 | 482 | /** |
8973a6e7 | 483 | * lbs_mesh_bt_add_del - Add or delete Mesh Blinding Table entries |
52148655 | 484 | * |
8973a6e7 RD |
485 | * @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 | |
52148655 | 488 | * |
8973a6e7 | 489 | * returns: 0 on success, error on failure |
52148655 DW |
490 | */ |
491 | int lbs_mesh_bt_add_del(struct lbs_private *priv, bool add, u8 *addr1) | |
ece1e3c6 | 492 | { |
52148655 DW |
493 | struct cmd_ds_bt_access cmd; |
494 | int ret = 0; | |
ece1e3c6 | 495 | |
52148655 | 496 | lbs_deb_enter(LBS_DEB_CMD); |
ece1e3c6 | 497 | |
52148655 DW |
498 | 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); | |
ece1e3c6 | 505 | lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", |
52148655 DW |
506 | addr1, ETH_ALEN); |
507 | } else { | |
508 | cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_DEL); | |
ece1e3c6 | 509 | lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", |
52148655 | 510 | addr1, ETH_ALEN); |
ece1e3c6 | 511 | } |
52148655 DW |
512 | |
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 | /** | |
8973a6e7 | 520 | * lbs_mesh_bt_reset - Reset/clear the mesh blinding table |
52148655 | 521 | * |
8973a6e7 | 522 | * @priv: A pointer to &struct lbs_private structure |
52148655 | 523 | * |
8973a6e7 | 524 | * returns: 0 on success, error on failure |
52148655 DW |
525 | */ |
526 | int 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 | /** | |
8973a6e7 RD |
544 | * lbs_mesh_bt_get_inverted - Gets the inverted status of the mesh |
545 | * blinding table | |
52148655 | 546 | * |
8973a6e7 RD |
547 | * 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. | |
52148655 | 550 | * |
8973a6e7 RD |
551 | * @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 | |
52148655 | 554 | * |
8973a6e7 | 555 | * returns: 0 on success, error on failure |
52148655 DW |
556 | */ |
557 | int 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 | /** | |
8973a6e7 RD |
579 | * lbs_mesh_bt_set_inverted - Sets the inverted status of the mesh |
580 | * blinding table | |
52148655 | 581 | * |
8973a6e7 RD |
582 | * 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. | |
52148655 | 585 | * |
8973a6e7 RD |
586 | * @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) | |
52148655 | 590 | * |
8973a6e7 | 591 | * returns: 0 on success, error on failure |
52148655 DW |
592 | */ |
593 | int 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); | |
65a602dd | 603 | cmd.id = cpu_to_le32(!!inverted); |
52148655 DW |
604 | |
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 | /** | |
8973a6e7 | 612 | * lbs_mesh_bt_get_entry - List an entry in the mesh blinding table |
52148655 | 613 | * |
8973a6e7 RD |
614 | * @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 | |
52148655 | 617 | * |
8973a6e7 | 618 | * returns: 0 on success, error on failure |
52148655 DW |
619 | */ |
620 | int 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; | |
ece1e3c6 HS |
640 | } |
641 | ||
a6bb1bce | 642 | /** |
8973a6e7 | 643 | * lbs_cmd_fwt_access - Access the mesh forwarding table |
a6bb1bce | 644 | * |
8973a6e7 RD |
645 | * @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 | |
a6bb1bce | 648 | * |
8973a6e7 RD |
649 | * returns: 0 on success and 'cmd' will be filled with the |
650 | * firmware's response | |
a6bb1bce DW |
651 | */ |
652 | int lbs_cmd_fwt_access(struct lbs_private *priv, u16 cmd_action, | |
653 | struct cmd_ds_fwt_access *cmd) | |
ece1e3c6 | 654 | { |
a6bb1bce | 655 | int ret; |
ece1e3c6 | 656 | |
a6bb1bce | 657 | lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action); |
ece1e3c6 | 658 | |
a6bb1bce DW |
659 | 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); | |
ece1e3c6 | 663 | |
a6bb1bce | 664 | ret = lbs_cmd_with_response(priv, CMD_FWT_ACCESS, cmd); |
ece1e3c6 | 665 | |
a6bb1bce | 666 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); |
ece1e3c6 HS |
667 | return 0; |
668 | } | |
669 | ||
670 | int 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 | ||
689 | static 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 | */ | |
c24ef46e | 702 | if (priv->mesh_tlv == TLV_TYPE_MESH_ID) |
ece1e3c6 HS |
703 | 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 | ||
719 | int 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 | */ | |
737 | int 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 | ||
e0e42da3 HS |
779 | /*************************************************************************** |
780 | * Persistent configuration support | |
781 | */ | |
782 | ||
15dbaac0 JC |
783 | static int mesh_get_default_parameters(struct device *dev, |
784 | struct mrvl_mesh_defaults *defs) | |
785 | { | |
ab65f649 | 786 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
15dbaac0 JC |
787 | 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 | /** | |
8973a6e7 RD |
803 | * 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 | |
15dbaac0 JC |
807 | */ |
808 | static 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 | ||
fb904907 | 819 | return snprintf(buf, 12, "%d\n", le32_to_cpu(defs.bootflag)); |
15dbaac0 JC |
820 | } |
821 | ||
822 | /** | |
8973a6e7 RD |
823 | * 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 | |
15dbaac0 JC |
828 | */ |
829 | static ssize_t bootflag_set(struct device *dev, struct device_attribute *attr, | |
830 | const char *buf, size_t count) | |
831 | { | |
ab65f649 | 832 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
15dbaac0 JC |
833 | struct cmd_ds_mesh_config cmd; |
834 | uint32_t datum; | |
835 | int ret; | |
836 | ||
837 | memset(&cmd, 0, sizeof(cmd)); | |
fb904907 BC |
838 | ret = sscanf(buf, "%d", &datum); |
839 | if ((ret != 1) || (datum > 1)) | |
15dbaac0 JC |
840 | 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 | /** | |
8973a6e7 RD |
853 | * 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 | |
15dbaac0 JC |
857 | */ |
858 | static 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 | ||
fb904907 | 869 | return snprintf(buf, 12, "%d\n", defs.boottime); |
15dbaac0 JC |
870 | } |
871 | ||
872 | /** | |
8973a6e7 RD |
873 | * 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 | |
15dbaac0 JC |
878 | */ |
879 | static ssize_t boottime_set(struct device *dev, | |
880 | struct device_attribute *attr, const char *buf, size_t count) | |
881 | { | |
ab65f649 | 882 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
15dbaac0 JC |
883 | struct cmd_ds_mesh_config cmd; |
884 | uint32_t datum; | |
885 | int ret; | |
886 | ||
887 | memset(&cmd, 0, sizeof(cmd)); | |
fb904907 BC |
888 | ret = sscanf(buf, "%d", &datum); |
889 | if ((ret != 1) || (datum > 255)) | |
15dbaac0 JC |
890 | 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 | ||
b679aeb3 | 911 | /** |
8973a6e7 RD |
912 | * 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 | |
b679aeb3 JC |
916 | */ |
917 | static 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 | ||
fb904907 | 928 | return snprintf(buf, 12, "%d\n", le16_to_cpu(defs.channel)); |
b679aeb3 JC |
929 | } |
930 | ||
931 | /** | |
8973a6e7 RD |
932 | * 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 | |
b679aeb3 JC |
937 | */ |
938 | static ssize_t channel_set(struct device *dev, struct device_attribute *attr, | |
939 | const char *buf, size_t count) | |
940 | { | |
ab65f649 | 941 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
b679aeb3 | 942 | struct cmd_ds_mesh_config cmd; |
fb904907 | 943 | uint32_t datum; |
b679aeb3 JC |
944 | int ret; |
945 | ||
946 | memset(&cmd, 0, sizeof(cmd)); | |
fb904907 | 947 | ret = sscanf(buf, "%d", &datum); |
b679aeb3 JC |
948 | 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 | ||
15dbaac0 | 961 | /** |
8973a6e7 RD |
962 | * 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 | |
15dbaac0 JC |
966 | */ |
967 | static ssize_t mesh_id_get(struct device *dev, struct device_attribute *attr, | |
968 | char *buf) | |
969 | { | |
970 | struct mrvl_mesh_defaults defs; | |
15dbaac0 JC |
971 | int ret; |
972 | ||
973 | ret = mesh_get_default_parameters(dev, &defs); | |
974 | ||
975 | if (ret) | |
976 | return ret; | |
977 | ||
243e84e9 | 978 | if (defs.meshie.val.mesh_id_len > IEEE80211_MAX_SSID_LEN) { |
f3a57fd1 | 979 | dev_err(dev, "inconsistent mesh ID length\n"); |
243e84e9 | 980 | defs.meshie.val.mesh_id_len = IEEE80211_MAX_SSID_LEN; |
15dbaac0 JC |
981 | } |
982 | ||
d89dba7a DC |
983 | 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'; | |
15dbaac0 | 986 | |
d89dba7a | 987 | return defs.meshie.val.mesh_id_len + 1; |
15dbaac0 JC |
988 | } |
989 | ||
990 | /** | |
8973a6e7 RD |
991 | * 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 | |
15dbaac0 JC |
996 | */ |
997 | static 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; | |
ab65f649 | 1003 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
15dbaac0 JC |
1004 | int len; |
1005 | int ret; | |
1006 | ||
243e84e9 | 1007 | if (count < 2 || count > IEEE80211_MAX_SSID_LEN + 1) |
15dbaac0 JC |
1008 | 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 */ | |
243e84e9 | 1026 | ie->len = sizeof(struct mrvl_meshie_val) - IEEE80211_MAX_SSID_LEN + len; |
15dbaac0 JC |
1027 | |
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 | /** | |
8973a6e7 RD |
1037 | * 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 | |
15dbaac0 JC |
1041 | */ |
1042 | static 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 | /** | |
8973a6e7 RD |
1057 | * 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 | |
15dbaac0 JC |
1062 | */ |
1063 | static 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; | |
ab65f649 | 1069 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
15dbaac0 JC |
1070 | uint32_t datum; |
1071 | int ret; | |
1072 | ||
1073 | memset(&cmd, 0, sizeof(cmd)); | |
fb904907 BC |
1074 | ret = sscanf(buf, "%d", &datum); |
1075 | if ((ret != 1) || (datum > 255)) | |
15dbaac0 JC |
1076 | 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 | /** | |
8973a6e7 RD |
1098 | * 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 | |
15dbaac0 JC |
1102 | */ |
1103 | static 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 | /** | |
8973a6e7 RD |
1118 | * 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 | |
15dbaac0 JC |
1123 | */ |
1124 | static 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; | |
ab65f649 | 1130 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
15dbaac0 JC |
1131 | uint32_t datum; |
1132 | int ret; | |
1133 | ||
1134 | memset(&cmd, 0, sizeof(cmd)); | |
fb904907 BC |
1135 | ret = sscanf(buf, "%d", &datum); |
1136 | if ((ret != 1) || (datum > 255)) | |
15dbaac0 JC |
1137 | 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 | /** | |
8973a6e7 RD |
1159 | * 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 | |
15dbaac0 JC |
1163 | */ |
1164 | static 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 | /** | |
8973a6e7 RD |
1179 | * 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 | |
15dbaac0 JC |
1184 | */ |
1185 | static 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; | |
ab65f649 | 1191 | struct lbs_private *priv = to_net_dev(dev)->ml_priv; |
15dbaac0 JC |
1192 | uint32_t datum; |
1193 | int ret; | |
1194 | ||
1195 | memset(&cmd, 0, sizeof(cmd)); | |
fb904907 BC |
1196 | ret = sscanf(buf, "%d", &datum); |
1197 | if ((ret != 1) || (datum > 255)) | |
15dbaac0 JC |
1198 | 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 | ||
1220 | static DEVICE_ATTR(bootflag, 0644, bootflag_get, bootflag_set); | |
1221 | static DEVICE_ATTR(boottime, 0644, boottime_get, boottime_set); | |
b679aeb3 | 1222 | static DEVICE_ATTR(channel, 0644, channel_get, channel_set); |
15dbaac0 JC |
1223 | static DEVICE_ATTR(mesh_id, 0644, mesh_id_get, mesh_id_set); |
1224 | static DEVICE_ATTR(protocol_id, 0644, protocol_id_get, protocol_id_set); | |
1225 | static DEVICE_ATTR(metric_id, 0644, metric_id_get, metric_id_set); | |
1226 | static DEVICE_ATTR(capability, 0644, capability_get, capability_set); | |
1227 | ||
1228 | static struct attribute *boot_opts_attrs[] = { | |
1229 | &dev_attr_bootflag.attr, | |
1230 | &dev_attr_boottime.attr, | |
b679aeb3 | 1231 | &dev_attr_channel.attr, |
15dbaac0 JC |
1232 | NULL |
1233 | }; | |
1234 | ||
1235 | static struct attribute_group boot_opts_group = { | |
1236 | .name = "boot_options", | |
1237 | .attrs = boot_opts_attrs, | |
1238 | }; | |
1239 | ||
1240 | static 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 | ||
1248 | static struct attribute_group mesh_ie_group = { | |
1249 | .name = "mesh_ie", | |
1250 | .attrs = mesh_ie_attrs, | |
1251 | }; | |
1252 | ||
1253 | void 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 | ||
1260 | void 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 | } | |
c7fe64cf HS |
1265 | |
1266 | ||
1267 | ||
1268 | /*************************************************************************** | |
1269 | * Ethtool related | |
1270 | */ | |
1271 | ||
1272 | static 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 | ||
1283 | void 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 | ||
1321 | int 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 | ||
1331 | void 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 | } |