mesh.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270
  1. #include <linux/delay.h>
  2. #include <linux/etherdevice.h>
  3. #include <linux/netdevice.h>
  4. #include <linux/if_ether.h>
  5. #include <linux/if_arp.h>
  6. #include <linux/kthread.h>
  7. #include <linux/kfifo.h>
  8. #include <net/cfg80211.h>
  9. #include "mesh.h"
  10. #include "decl.h"
  11. #include "cmd.h"
  12. /***************************************************************************
  13. * Mesh sysfs support
  14. */
  15. /**
  16. * Attributes exported through sysfs
  17. */
  18. /**
  19. * @brief Get function for sysfs attribute anycast_mask
  20. */
  21. static ssize_t lbs_anycast_get(struct device *dev,
  22. struct device_attribute *attr, char * buf)
  23. {
  24. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  25. struct cmd_ds_mesh_access mesh_access;
  26. int ret;
  27. memset(&mesh_access, 0, sizeof(mesh_access));
  28. ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_ANYCAST, &mesh_access);
  29. if (ret)
  30. return ret;
  31. return snprintf(buf, 12, "0x%X\n", le32_to_cpu(mesh_access.data[0]));
  32. }
  33. /**
  34. * @brief Set function for sysfs attribute anycast_mask
  35. */
  36. static ssize_t lbs_anycast_set(struct device *dev,
  37. struct device_attribute *attr, const char * buf, size_t count)
  38. {
  39. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  40. struct cmd_ds_mesh_access mesh_access;
  41. uint32_t datum;
  42. int ret;
  43. memset(&mesh_access, 0, sizeof(mesh_access));
  44. sscanf(buf, "%x", &datum);
  45. mesh_access.data[0] = cpu_to_le32(datum);
  46. ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_ANYCAST, &mesh_access);
  47. if (ret)
  48. return ret;
  49. return strlen(buf);
  50. }
  51. /**
  52. * @brief Get function for sysfs attribute prb_rsp_limit
  53. */
  54. static ssize_t lbs_prb_rsp_limit_get(struct device *dev,
  55. struct device_attribute *attr, char *buf)
  56. {
  57. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  58. struct cmd_ds_mesh_access mesh_access;
  59. int ret;
  60. u32 retry_limit;
  61. memset(&mesh_access, 0, sizeof(mesh_access));
  62. mesh_access.data[0] = cpu_to_le32(CMD_ACT_GET);
  63. ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT,
  64. &mesh_access);
  65. if (ret)
  66. return ret;
  67. retry_limit = le32_to_cpu(mesh_access.data[1]);
  68. return snprintf(buf, 10, "%d\n", retry_limit);
  69. }
  70. /**
  71. * @brief Set function for sysfs attribute prb_rsp_limit
  72. */
  73. static ssize_t lbs_prb_rsp_limit_set(struct device *dev,
  74. struct device_attribute *attr, const char *buf, size_t count)
  75. {
  76. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  77. struct cmd_ds_mesh_access mesh_access;
  78. int ret;
  79. unsigned long retry_limit;
  80. memset(&mesh_access, 0, sizeof(mesh_access));
  81. mesh_access.data[0] = cpu_to_le32(CMD_ACT_SET);
  82. if (!strict_strtoul(buf, 10, &retry_limit))
  83. return -ENOTSUPP;
  84. if (retry_limit > 15)
  85. return -ENOTSUPP;
  86. mesh_access.data[1] = cpu_to_le32(retry_limit);
  87. ret = lbs_mesh_access(priv, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT,
  88. &mesh_access);
  89. if (ret)
  90. return ret;
  91. return strlen(buf);
  92. }
  93. /**
  94. * Get function for sysfs attribute mesh
  95. */
  96. static ssize_t lbs_mesh_get(struct device *dev,
  97. struct device_attribute *attr, char * buf)
  98. {
  99. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  100. return snprintf(buf, 5, "0x%X\n", !!priv->mesh_dev);
  101. }
  102. /**
  103. * Set function for sysfs attribute mesh
  104. */
  105. static ssize_t lbs_mesh_set(struct device *dev,
  106. struct device_attribute *attr, const char * buf, size_t count)
  107. {
  108. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  109. int enable;
  110. int ret, action = CMD_ACT_MESH_CONFIG_STOP;
  111. sscanf(buf, "%x", &enable);
  112. enable = !!enable;
  113. if (enable == !!priv->mesh_dev)
  114. return count;
  115. if (enable)
  116. action = CMD_ACT_MESH_CONFIG_START;
  117. ret = lbs_mesh_config(priv, action, priv->channel);
  118. if (ret)
  119. return ret;
  120. if (enable)
  121. lbs_add_mesh(priv);
  122. else
  123. lbs_remove_mesh(priv);
  124. return count;
  125. }
  126. /**
  127. * lbs_mesh attribute to be exported per ethX interface
  128. * through sysfs (/sys/class/net/ethX/lbs_mesh)
  129. */
  130. static DEVICE_ATTR(lbs_mesh, 0644, lbs_mesh_get, lbs_mesh_set);
  131. /**
  132. * anycast_mask attribute to be exported per mshX interface
  133. * through sysfs (/sys/class/net/mshX/anycast_mask)
  134. */
  135. static DEVICE_ATTR(anycast_mask, 0644, lbs_anycast_get, lbs_anycast_set);
  136. /**
  137. * prb_rsp_limit attribute to be exported per mshX interface
  138. * through sysfs (/sys/class/net/mshX/prb_rsp_limit)
  139. */
  140. static DEVICE_ATTR(prb_rsp_limit, 0644, lbs_prb_rsp_limit_get,
  141. lbs_prb_rsp_limit_set);
  142. static struct attribute *lbs_mesh_sysfs_entries[] = {
  143. &dev_attr_anycast_mask.attr,
  144. &dev_attr_prb_rsp_limit.attr,
  145. NULL,
  146. };
  147. static struct attribute_group lbs_mesh_attr_group = {
  148. .attrs = lbs_mesh_sysfs_entries,
  149. };
  150. /***************************************************************************
  151. * Initializing and starting, stopping mesh
  152. */
  153. /*
  154. * Check mesh FW version and appropriately send the mesh start
  155. * command
  156. */
  157. int lbs_init_mesh(struct lbs_private *priv)
  158. {
  159. struct net_device *dev = priv->dev;
  160. int ret = 0;
  161. lbs_deb_enter(LBS_DEB_MESH);
  162. priv->mesh_connect_status = LBS_DISCONNECTED;
  163. /* Determine mesh_fw_ver from fwrelease and fwcapinfo */
  164. /* 5.0.16p0 9.0.0.p0 is known to NOT support any mesh */
  165. /* 5.110.22 have mesh command with 0xa3 command id */
  166. /* 10.0.0.p0 FW brings in mesh config command with different id */
  167. /* Check FW version MSB and initialize mesh_fw_ver */
  168. if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V5) {
  169. /* Enable mesh, if supported, and work out which TLV it uses.
  170. 0x100 + 291 is an unofficial value used in 5.110.20.pXX
  171. 0x100 + 37 is the official value used in 5.110.21.pXX
  172. but we check them in that order because 20.pXX doesn't
  173. give an error -- it just silently fails. */
  174. /* 5.110.20.pXX firmware will fail the command if the channel
  175. doesn't match the existing channel. But only if the TLV
  176. is correct. If the channel is wrong, _BOTH_ versions will
  177. give an error to 0x100+291, and allow 0x100+37 to succeed.
  178. It's just that 5.110.20.pXX will not have done anything
  179. useful */
  180. priv->mesh_tlv = TLV_TYPE_OLD_MESH_ID;
  181. if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
  182. priv->channel)) {
  183. priv->mesh_tlv = TLV_TYPE_MESH_ID;
  184. if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
  185. priv->channel))
  186. priv->mesh_tlv = 0;
  187. }
  188. } else
  189. if ((MRVL_FW_MAJOR_REV(priv->fwrelease) >= MRVL_FW_V10) &&
  190. (priv->fwcapinfo & MESH_CAPINFO_ENABLE_MASK)) {
  191. /* 10.0.0.pXX new firmwares should succeed with TLV
  192. * 0x100+37; Do not invoke command with old TLV.
  193. */
  194. priv->mesh_tlv = TLV_TYPE_MESH_ID;
  195. if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
  196. priv->channel))
  197. priv->mesh_tlv = 0;
  198. }
  199. if (priv->mesh_tlv) {
  200. sprintf(priv->mesh_ssid, "mesh");
  201. priv->mesh_ssid_len = 4;
  202. lbs_add_mesh(priv);
  203. if (device_create_file(&dev->dev, &dev_attr_lbs_mesh))
  204. lbs_pr_err("cannot register lbs_mesh attribute\n");
  205. ret = 1;
  206. }
  207. lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
  208. return ret;
  209. }
  210. int lbs_deinit_mesh(struct lbs_private *priv)
  211. {
  212. struct net_device *dev = priv->dev;
  213. int ret = 0;
  214. lbs_deb_enter(LBS_DEB_MESH);
  215. if (priv->mesh_tlv) {
  216. device_remove_file(&dev->dev, &dev_attr_lbs_mesh);
  217. ret = 1;
  218. }
  219. lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
  220. return ret;
  221. }
  222. /**
  223. * @brief This function closes the mshX interface
  224. *
  225. * @param dev A pointer to net_device structure
  226. * @return 0
  227. */
  228. static int lbs_mesh_stop(struct net_device *dev)
  229. {
  230. struct lbs_private *priv = dev->ml_priv;
  231. lbs_deb_enter(LBS_DEB_MESH);
  232. spin_lock_irq(&priv->driver_lock);
  233. priv->mesh_open = 0;
  234. priv->mesh_connect_status = LBS_DISCONNECTED;
  235. netif_stop_queue(dev);
  236. netif_carrier_off(dev);
  237. spin_unlock_irq(&priv->driver_lock);
  238. schedule_work(&priv->mcast_work);
  239. lbs_deb_leave(LBS_DEB_MESH);
  240. return 0;
  241. }
  242. /**
  243. * @brief This function opens the mshX interface
  244. *
  245. * @param dev A pointer to net_device structure
  246. * @return 0 or -EBUSY if monitor mode active
  247. */
  248. static int lbs_mesh_dev_open(struct net_device *dev)
  249. {
  250. struct lbs_private *priv = dev->ml_priv;
  251. int ret = 0;
  252. lbs_deb_enter(LBS_DEB_NET);
  253. spin_lock_irq(&priv->driver_lock);
  254. if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR) {
  255. ret = -EBUSY;
  256. goto out;
  257. }
  258. priv->mesh_open = 1;
  259. priv->mesh_connect_status = LBS_CONNECTED;
  260. netif_carrier_on(dev);
  261. if (!priv->tx_pending_len)
  262. netif_wake_queue(dev);
  263. out:
  264. spin_unlock_irq(&priv->driver_lock);
  265. lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret);
  266. return ret;
  267. }
  268. static const struct net_device_ops mesh_netdev_ops = {
  269. .ndo_open = lbs_mesh_dev_open,
  270. .ndo_stop = lbs_mesh_stop,
  271. .ndo_start_xmit = lbs_hard_start_xmit,
  272. .ndo_set_mac_address = lbs_set_mac_address,
  273. .ndo_set_multicast_list = lbs_set_multicast_list,
  274. };
  275. /**
  276. * @brief This function adds mshX interface
  277. *
  278. * @param priv A pointer to the struct lbs_private structure
  279. * @return 0 if successful, -X otherwise
  280. */
  281. int lbs_add_mesh(struct lbs_private *priv)
  282. {
  283. struct net_device *mesh_dev = NULL;
  284. int ret = 0;
  285. lbs_deb_enter(LBS_DEB_MESH);
  286. /* Allocate a virtual mesh device */
  287. mesh_dev = alloc_netdev(0, "msh%d", ether_setup);
  288. if (!mesh_dev) {
  289. lbs_deb_mesh("init mshX device failed\n");
  290. ret = -ENOMEM;
  291. goto done;
  292. }
  293. mesh_dev->ml_priv = priv;
  294. priv->mesh_dev = mesh_dev;
  295. mesh_dev->netdev_ops = &mesh_netdev_ops;
  296. mesh_dev->ethtool_ops = &lbs_ethtool_ops;
  297. memcpy(mesh_dev->dev_addr, priv->dev->dev_addr, ETH_ALEN);
  298. SET_NETDEV_DEV(priv->mesh_dev, priv->dev->dev.parent);
  299. mesh_dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
  300. /* Register virtual mesh interface */
  301. ret = register_netdev(mesh_dev);
  302. if (ret) {
  303. lbs_pr_err("cannot register mshX virtual interface\n");
  304. goto err_free;
  305. }
  306. ret = sysfs_create_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
  307. if (ret)
  308. goto err_unregister;
  309. lbs_persist_config_init(mesh_dev);
  310. /* Everything successful */
  311. ret = 0;
  312. goto done;
  313. err_unregister:
  314. unregister_netdev(mesh_dev);
  315. err_free:
  316. free_netdev(mesh_dev);
  317. done:
  318. lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
  319. return ret;
  320. }
  321. void lbs_remove_mesh(struct lbs_private *priv)
  322. {
  323. struct net_device *mesh_dev;
  324. mesh_dev = priv->mesh_dev;
  325. if (!mesh_dev)
  326. return;
  327. lbs_deb_enter(LBS_DEB_MESH);
  328. netif_stop_queue(mesh_dev);
  329. netif_carrier_off(mesh_dev);
  330. sysfs_remove_group(&(mesh_dev->dev.kobj), &lbs_mesh_attr_group);
  331. lbs_persist_config_remove(mesh_dev);
  332. unregister_netdev(mesh_dev);
  333. priv->mesh_dev = NULL;
  334. free_netdev(mesh_dev);
  335. lbs_deb_leave(LBS_DEB_MESH);
  336. }
  337. /***************************************************************************
  338. * Sending and receiving
  339. */
  340. struct net_device *lbs_mesh_set_dev(struct lbs_private *priv,
  341. struct net_device *dev, struct rxpd *rxpd)
  342. {
  343. if (priv->mesh_dev) {
  344. if (priv->mesh_tlv == TLV_TYPE_OLD_MESH_ID) {
  345. if (rxpd->rx_control & RxPD_MESH_FRAME)
  346. dev = priv->mesh_dev;
  347. } else if (priv->mesh_tlv == TLV_TYPE_MESH_ID) {
  348. if (rxpd->u.bss.bss_num == MESH_IFACE_ID)
  349. dev = priv->mesh_dev;
  350. }
  351. }
  352. return dev;
  353. }
  354. void lbs_mesh_set_txpd(struct lbs_private *priv,
  355. struct net_device *dev, struct txpd *txpd)
  356. {
  357. if (dev == priv->mesh_dev) {
  358. if (priv->mesh_tlv == TLV_TYPE_OLD_MESH_ID)
  359. txpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
  360. else if (priv->mesh_tlv == TLV_TYPE_MESH_ID)
  361. txpd->u.bss.bss_num = MESH_IFACE_ID;
  362. }
  363. }
  364. /***************************************************************************
  365. * Mesh command handling
  366. */
  367. /**
  368. * @brief Add or delete Mesh Blinding Table entries
  369. *
  370. * @param priv A pointer to struct lbs_private structure
  371. * @param add TRUE to add the entry, FALSE to delete it
  372. * @param addr1 Destination address to blind or unblind
  373. *
  374. * @return 0 on success, error on failure
  375. */
  376. int lbs_mesh_bt_add_del(struct lbs_private *priv, bool add, u8 *addr1)
  377. {
  378. struct cmd_ds_bt_access cmd;
  379. int ret = 0;
  380. lbs_deb_enter(LBS_DEB_CMD);
  381. BUG_ON(addr1 == NULL);
  382. memset(&cmd, 0, sizeof(cmd));
  383. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  384. memcpy(cmd.addr1, addr1, ETH_ALEN);
  385. if (add) {
  386. cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_ADD);
  387. lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr",
  388. addr1, ETH_ALEN);
  389. } else {
  390. cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_DEL);
  391. lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr",
  392. addr1, ETH_ALEN);
  393. }
  394. ret = lbs_cmd_with_response(priv, CMD_BT_ACCESS, &cmd);
  395. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  396. return ret;
  397. }
  398. /**
  399. * @brief Reset/clear the mesh blinding table
  400. *
  401. * @param priv A pointer to struct lbs_private structure
  402. *
  403. * @return 0 on success, error on failure
  404. */
  405. int lbs_mesh_bt_reset(struct lbs_private *priv)
  406. {
  407. struct cmd_ds_bt_access cmd;
  408. int ret = 0;
  409. lbs_deb_enter(LBS_DEB_CMD);
  410. memset(&cmd, 0, sizeof(cmd));
  411. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  412. cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_RESET);
  413. ret = lbs_cmd_with_response(priv, CMD_BT_ACCESS, &cmd);
  414. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  415. return ret;
  416. }
  417. /**
  418. * @brief Gets the inverted status of the mesh blinding table
  419. *
  420. * Normally the firmware "blinds" or ignores traffic from mesh nodes in the
  421. * table, but an inverted table allows *only* traffic from nodes listed in
  422. * the table.
  423. *
  424. * @param priv A pointer to struct lbs_private structure
  425. * @param invert On success, TRUE if the blinding table is inverted,
  426. * FALSE if it is not inverted
  427. *
  428. * @return 0 on success, error on failure
  429. */
  430. int lbs_mesh_bt_get_inverted(struct lbs_private *priv, bool *inverted)
  431. {
  432. struct cmd_ds_bt_access cmd;
  433. int ret = 0;
  434. lbs_deb_enter(LBS_DEB_CMD);
  435. BUG_ON(inverted == NULL);
  436. memset(&cmd, 0, sizeof(cmd));
  437. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  438. cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_GET_INVERT);
  439. ret = lbs_cmd_with_response(priv, CMD_BT_ACCESS, &cmd);
  440. if (ret == 0)
  441. *inverted = !!cmd.id;
  442. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  443. return ret;
  444. }
  445. /**
  446. * @brief Sets the inverted status of the mesh blinding table
  447. *
  448. * Normally the firmware "blinds" or ignores traffic from mesh nodes in the
  449. * table, but an inverted table allows *only* traffic from nodes listed in
  450. * the table.
  451. *
  452. * @param priv A pointer to struct lbs_private structure
  453. * @param invert TRUE to invert the blinding table (only traffic from
  454. * listed nodes allowed), FALSE to return it
  455. * to normal state (listed nodes ignored)
  456. *
  457. * @return 0 on success, error on failure
  458. */
  459. int lbs_mesh_bt_set_inverted(struct lbs_private *priv, bool inverted)
  460. {
  461. struct cmd_ds_bt_access cmd;
  462. int ret = 0;
  463. lbs_deb_enter(LBS_DEB_CMD);
  464. memset(&cmd, 0, sizeof(cmd));
  465. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  466. cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_SET_INVERT);
  467. cmd.id = !!inverted;
  468. ret = lbs_cmd_with_response(priv, CMD_BT_ACCESS, &cmd);
  469. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  470. return ret;
  471. }
  472. /**
  473. * @brief List an entry in the mesh blinding table
  474. *
  475. * @param priv A pointer to struct lbs_private structure
  476. * @param id The ID of the entry to list
  477. * @param addr1 MAC address associated with the table entry
  478. *
  479. * @return 0 on success, error on failure
  480. */
  481. int lbs_mesh_bt_get_entry(struct lbs_private *priv, u32 id, u8 *addr1)
  482. {
  483. struct cmd_ds_bt_access cmd;
  484. int ret = 0;
  485. lbs_deb_enter(LBS_DEB_CMD);
  486. BUG_ON(addr1 == NULL);
  487. memset(&cmd, 0, sizeof(cmd));
  488. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  489. cmd.action = cpu_to_le16(CMD_ACT_BT_ACCESS_SET_INVERT);
  490. cmd.id = cpu_to_le32(id);
  491. ret = lbs_cmd_with_response(priv, CMD_BT_ACCESS, &cmd);
  492. if (ret == 0)
  493. memcpy(addr1, cmd.addr1, sizeof(cmd.addr1));
  494. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  495. return ret;
  496. }
  497. int lbs_cmd_fwt_access(struct cmd_ds_command *cmd,
  498. u16 cmd_action, void *pdata_buf)
  499. {
  500. struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
  501. lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
  502. cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
  503. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) +
  504. sizeof(struct cmd_header));
  505. cmd->result = 0;
  506. if (pdata_buf)
  507. memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
  508. else
  509. memset(fwt_access, 0, sizeof(*fwt_access));
  510. fwt_access->action = cpu_to_le16(cmd_action);
  511. lbs_deb_leave(LBS_DEB_CMD);
  512. return 0;
  513. }
  514. int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
  515. struct cmd_ds_mesh_access *cmd)
  516. {
  517. int ret;
  518. lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
  519. cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
  520. cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
  521. cmd->hdr.result = 0;
  522. cmd->action = cpu_to_le16(cmd_action);
  523. ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
  524. lbs_deb_leave(LBS_DEB_CMD);
  525. return ret;
  526. }
  527. static int __lbs_mesh_config_send(struct lbs_private *priv,
  528. struct cmd_ds_mesh_config *cmd,
  529. uint16_t action, uint16_t type)
  530. {
  531. int ret;
  532. u16 command = CMD_MESH_CONFIG_OLD;
  533. lbs_deb_enter(LBS_DEB_CMD);
  534. /*
  535. * Command id is 0xac for v10 FW along with mesh interface
  536. * id in bits 14-13-12.
  537. */
  538. if (priv->mesh_tlv == TLV_TYPE_MESH_ID)
  539. command = CMD_MESH_CONFIG |
  540. (MESH_IFACE_ID << MESH_IFACE_BIT_OFFSET);
  541. cmd->hdr.command = cpu_to_le16(command);
  542. cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config));
  543. cmd->hdr.result = 0;
  544. cmd->type = cpu_to_le16(type);
  545. cmd->action = cpu_to_le16(action);
  546. ret = lbs_cmd_with_response(priv, command, cmd);
  547. lbs_deb_leave(LBS_DEB_CMD);
  548. return ret;
  549. }
  550. int lbs_mesh_config_send(struct lbs_private *priv,
  551. struct cmd_ds_mesh_config *cmd,
  552. uint16_t action, uint16_t type)
  553. {
  554. int ret;
  555. if (!(priv->fwcapinfo & FW_CAPINFO_PERSISTENT_CONFIG))
  556. return -EOPNOTSUPP;
  557. ret = __lbs_mesh_config_send(priv, cmd, action, type);
  558. return ret;
  559. }
  560. /* This function is the CMD_MESH_CONFIG legacy function. It only handles the
  561. * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG
  562. * are all handled by preparing a struct cmd_ds_mesh_config and passing it to
  563. * lbs_mesh_config_send.
  564. */
  565. int lbs_mesh_config(struct lbs_private *priv, uint16_t action, uint16_t chan)
  566. {
  567. struct cmd_ds_mesh_config cmd;
  568. struct mrvl_meshie *ie;
  569. DECLARE_SSID_BUF(ssid);
  570. memset(&cmd, 0, sizeof(cmd));
  571. cmd.channel = cpu_to_le16(chan);
  572. ie = (struct mrvl_meshie *)cmd.data;
  573. switch (action) {
  574. case CMD_ACT_MESH_CONFIG_START:
  575. ie->id = WLAN_EID_GENERIC;
  576. ie->val.oui[0] = 0x00;
  577. ie->val.oui[1] = 0x50;
  578. ie->val.oui[2] = 0x43;
  579. ie->val.type = MARVELL_MESH_IE_TYPE;
  580. ie->val.subtype = MARVELL_MESH_IE_SUBTYPE;
  581. ie->val.version = MARVELL_MESH_IE_VERSION;
  582. ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP;
  583. ie->val.active_metric_id = MARVELL_MESH_METRIC_ID;
  584. ie->val.mesh_capability = MARVELL_MESH_CAPABILITY;
  585. ie->val.mesh_id_len = priv->mesh_ssid_len;
  586. memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len);
  587. ie->len = sizeof(struct mrvl_meshie_val) -
  588. IEEE80211_MAX_SSID_LEN + priv->mesh_ssid_len;
  589. cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val));
  590. break;
  591. case CMD_ACT_MESH_CONFIG_STOP:
  592. break;
  593. default:
  594. return -1;
  595. }
  596. lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n",
  597. action, priv->mesh_tlv, chan,
  598. print_ssid(ssid, priv->mesh_ssid, priv->mesh_ssid_len));
  599. return __lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv);
  600. }
  601. /***************************************************************************
  602. * Persistent configuration support
  603. */
  604. static int mesh_get_default_parameters(struct device *dev,
  605. struct mrvl_mesh_defaults *defs)
  606. {
  607. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  608. struct cmd_ds_mesh_config cmd;
  609. int ret;
  610. memset(&cmd, 0, sizeof(struct cmd_ds_mesh_config));
  611. ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_GET,
  612. CMD_TYPE_MESH_GET_DEFAULTS);
  613. if (ret)
  614. return -EOPNOTSUPP;
  615. memcpy(defs, &cmd.data[0], sizeof(struct mrvl_mesh_defaults));
  616. return 0;
  617. }
  618. /**
  619. * @brief Get function for sysfs attribute bootflag
  620. */
  621. static ssize_t bootflag_get(struct device *dev,
  622. struct device_attribute *attr, char *buf)
  623. {
  624. struct mrvl_mesh_defaults defs;
  625. int ret;
  626. ret = mesh_get_default_parameters(dev, &defs);
  627. if (ret)
  628. return ret;
  629. return snprintf(buf, 12, "%d\n", le32_to_cpu(defs.bootflag));
  630. }
  631. /**
  632. * @brief Set function for sysfs attribute bootflag
  633. */
  634. static ssize_t bootflag_set(struct device *dev, struct device_attribute *attr,
  635. const char *buf, size_t count)
  636. {
  637. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  638. struct cmd_ds_mesh_config cmd;
  639. uint32_t datum;
  640. int ret;
  641. memset(&cmd, 0, sizeof(cmd));
  642. ret = sscanf(buf, "%d", &datum);
  643. if ((ret != 1) || (datum > 1))
  644. return -EINVAL;
  645. *((__le32 *)&cmd.data[0]) = cpu_to_le32(!!datum);
  646. cmd.length = cpu_to_le16(sizeof(uint32_t));
  647. ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
  648. CMD_TYPE_MESH_SET_BOOTFLAG);
  649. if (ret)
  650. return ret;
  651. return strlen(buf);
  652. }
  653. /**
  654. * @brief Get function for sysfs attribute boottime
  655. */
  656. static ssize_t boottime_get(struct device *dev,
  657. struct device_attribute *attr, char *buf)
  658. {
  659. struct mrvl_mesh_defaults defs;
  660. int ret;
  661. ret = mesh_get_default_parameters(dev, &defs);
  662. if (ret)
  663. return ret;
  664. return snprintf(buf, 12, "%d\n", defs.boottime);
  665. }
  666. /**
  667. * @brief Set function for sysfs attribute boottime
  668. */
  669. static ssize_t boottime_set(struct device *dev,
  670. struct device_attribute *attr, const char *buf, size_t count)
  671. {
  672. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  673. struct cmd_ds_mesh_config cmd;
  674. uint32_t datum;
  675. int ret;
  676. memset(&cmd, 0, sizeof(cmd));
  677. ret = sscanf(buf, "%d", &datum);
  678. if ((ret != 1) || (datum > 255))
  679. return -EINVAL;
  680. /* A too small boot time will result in the device booting into
  681. * standalone (no-host) mode before the host can take control of it,
  682. * so the change will be hard to revert. This may be a desired
  683. * feature (e.g to configure a very fast boot time for devices that
  684. * will not be attached to a host), but dangerous. So I'm enforcing a
  685. * lower limit of 20 seconds: remove and recompile the driver if this
  686. * does not work for you.
  687. */
  688. datum = (datum < 20) ? 20 : datum;
  689. cmd.data[0] = datum;
  690. cmd.length = cpu_to_le16(sizeof(uint8_t));
  691. ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
  692. CMD_TYPE_MESH_SET_BOOTTIME);
  693. if (ret)
  694. return ret;
  695. return strlen(buf);
  696. }
  697. /**
  698. * @brief Get function for sysfs attribute channel
  699. */
  700. static ssize_t channel_get(struct device *dev,
  701. struct device_attribute *attr, char *buf)
  702. {
  703. struct mrvl_mesh_defaults defs;
  704. int ret;
  705. ret = mesh_get_default_parameters(dev, &defs);
  706. if (ret)
  707. return ret;
  708. return snprintf(buf, 12, "%d\n", le16_to_cpu(defs.channel));
  709. }
  710. /**
  711. * @brief Set function for sysfs attribute channel
  712. */
  713. static ssize_t channel_set(struct device *dev, struct device_attribute *attr,
  714. const char *buf, size_t count)
  715. {
  716. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  717. struct cmd_ds_mesh_config cmd;
  718. uint32_t datum;
  719. int ret;
  720. memset(&cmd, 0, sizeof(cmd));
  721. ret = sscanf(buf, "%d", &datum);
  722. if (ret != 1 || datum < 1 || datum > 11)
  723. return -EINVAL;
  724. *((__le16 *)&cmd.data[0]) = cpu_to_le16(datum);
  725. cmd.length = cpu_to_le16(sizeof(uint16_t));
  726. ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
  727. CMD_TYPE_MESH_SET_DEF_CHANNEL);
  728. if (ret)
  729. return ret;
  730. return strlen(buf);
  731. }
  732. /**
  733. * @brief Get function for sysfs attribute mesh_id
  734. */
  735. static ssize_t mesh_id_get(struct device *dev, struct device_attribute *attr,
  736. char *buf)
  737. {
  738. struct mrvl_mesh_defaults defs;
  739. int maxlen;
  740. int ret;
  741. ret = mesh_get_default_parameters(dev, &defs);
  742. if (ret)
  743. return ret;
  744. if (defs.meshie.val.mesh_id_len > IEEE80211_MAX_SSID_LEN) {
  745. lbs_pr_err("inconsistent mesh ID length");
  746. defs.meshie.val.mesh_id_len = IEEE80211_MAX_SSID_LEN;
  747. }
  748. /* SSID not null terminated: reserve room for \0 + \n */
  749. maxlen = defs.meshie.val.mesh_id_len + 2;
  750. maxlen = (PAGE_SIZE > maxlen) ? maxlen : PAGE_SIZE;
  751. defs.meshie.val.mesh_id[defs.meshie.val.mesh_id_len] = '\0';
  752. return snprintf(buf, maxlen, "%s\n", defs.meshie.val.mesh_id);
  753. }
  754. /**
  755. * @brief Set function for sysfs attribute mesh_id
  756. */
  757. static ssize_t mesh_id_set(struct device *dev, struct device_attribute *attr,
  758. const char *buf, size_t count)
  759. {
  760. struct cmd_ds_mesh_config cmd;
  761. struct mrvl_mesh_defaults defs;
  762. struct mrvl_meshie *ie;
  763. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  764. int len;
  765. int ret;
  766. if (count < 2 || count > IEEE80211_MAX_SSID_LEN + 1)
  767. return -EINVAL;
  768. memset(&cmd, 0, sizeof(struct cmd_ds_mesh_config));
  769. ie = (struct mrvl_meshie *) &cmd.data[0];
  770. /* fetch all other Information Element parameters */
  771. ret = mesh_get_default_parameters(dev, &defs);
  772. cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
  773. /* transfer IE elements */
  774. memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
  775. len = count - 1;
  776. memcpy(ie->val.mesh_id, buf, len);
  777. /* SSID len */
  778. ie->val.mesh_id_len = len;
  779. /* IE len */
  780. ie->len = sizeof(struct mrvl_meshie_val) - IEEE80211_MAX_SSID_LEN + len;
  781. ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
  782. CMD_TYPE_MESH_SET_MESH_IE);
  783. if (ret)
  784. return ret;
  785. return strlen(buf);
  786. }
  787. /**
  788. * @brief Get function for sysfs attribute protocol_id
  789. */
  790. static ssize_t protocol_id_get(struct device *dev,
  791. struct device_attribute *attr, char *buf)
  792. {
  793. struct mrvl_mesh_defaults defs;
  794. int ret;
  795. ret = mesh_get_default_parameters(dev, &defs);
  796. if (ret)
  797. return ret;
  798. return snprintf(buf, 5, "%d\n", defs.meshie.val.active_protocol_id);
  799. }
  800. /**
  801. * @brief Set function for sysfs attribute protocol_id
  802. */
  803. static ssize_t protocol_id_set(struct device *dev,
  804. struct device_attribute *attr, const char *buf, size_t count)
  805. {
  806. struct cmd_ds_mesh_config cmd;
  807. struct mrvl_mesh_defaults defs;
  808. struct mrvl_meshie *ie;
  809. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  810. uint32_t datum;
  811. int ret;
  812. memset(&cmd, 0, sizeof(cmd));
  813. ret = sscanf(buf, "%d", &datum);
  814. if ((ret != 1) || (datum > 255))
  815. return -EINVAL;
  816. /* fetch all other Information Element parameters */
  817. ret = mesh_get_default_parameters(dev, &defs);
  818. cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
  819. /* transfer IE elements */
  820. ie = (struct mrvl_meshie *) &cmd.data[0];
  821. memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
  822. /* update protocol id */
  823. ie->val.active_protocol_id = datum;
  824. ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
  825. CMD_TYPE_MESH_SET_MESH_IE);
  826. if (ret)
  827. return ret;
  828. return strlen(buf);
  829. }
  830. /**
  831. * @brief Get function for sysfs attribute metric_id
  832. */
  833. static ssize_t metric_id_get(struct device *dev,
  834. struct device_attribute *attr, char *buf)
  835. {
  836. struct mrvl_mesh_defaults defs;
  837. int ret;
  838. ret = mesh_get_default_parameters(dev, &defs);
  839. if (ret)
  840. return ret;
  841. return snprintf(buf, 5, "%d\n", defs.meshie.val.active_metric_id);
  842. }
  843. /**
  844. * @brief Set function for sysfs attribute metric_id
  845. */
  846. static ssize_t metric_id_set(struct device *dev, struct device_attribute *attr,
  847. const char *buf, size_t count)
  848. {
  849. struct cmd_ds_mesh_config cmd;
  850. struct mrvl_mesh_defaults defs;
  851. struct mrvl_meshie *ie;
  852. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  853. uint32_t datum;
  854. int ret;
  855. memset(&cmd, 0, sizeof(cmd));
  856. ret = sscanf(buf, "%d", &datum);
  857. if ((ret != 1) || (datum > 255))
  858. return -EINVAL;
  859. /* fetch all other Information Element parameters */
  860. ret = mesh_get_default_parameters(dev, &defs);
  861. cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
  862. /* transfer IE elements */
  863. ie = (struct mrvl_meshie *) &cmd.data[0];
  864. memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
  865. /* update metric id */
  866. ie->val.active_metric_id = datum;
  867. ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
  868. CMD_TYPE_MESH_SET_MESH_IE);
  869. if (ret)
  870. return ret;
  871. return strlen(buf);
  872. }
  873. /**
  874. * @brief Get function for sysfs attribute capability
  875. */
  876. static ssize_t capability_get(struct device *dev,
  877. struct device_attribute *attr, char *buf)
  878. {
  879. struct mrvl_mesh_defaults defs;
  880. int ret;
  881. ret = mesh_get_default_parameters(dev, &defs);
  882. if (ret)
  883. return ret;
  884. return snprintf(buf, 5, "%d\n", defs.meshie.val.mesh_capability);
  885. }
  886. /**
  887. * @brief Set function for sysfs attribute capability
  888. */
  889. static ssize_t capability_set(struct device *dev, struct device_attribute *attr,
  890. const char *buf, size_t count)
  891. {
  892. struct cmd_ds_mesh_config cmd;
  893. struct mrvl_mesh_defaults defs;
  894. struct mrvl_meshie *ie;
  895. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  896. uint32_t datum;
  897. int ret;
  898. memset(&cmd, 0, sizeof(cmd));
  899. ret = sscanf(buf, "%d", &datum);
  900. if ((ret != 1) || (datum > 255))
  901. return -EINVAL;
  902. /* fetch all other Information Element parameters */
  903. ret = mesh_get_default_parameters(dev, &defs);
  904. cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
  905. /* transfer IE elements */
  906. ie = (struct mrvl_meshie *) &cmd.data[0];
  907. memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
  908. /* update value */
  909. ie->val.mesh_capability = datum;
  910. ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
  911. CMD_TYPE_MESH_SET_MESH_IE);
  912. if (ret)
  913. return ret;
  914. return strlen(buf);
  915. }
  916. static DEVICE_ATTR(bootflag, 0644, bootflag_get, bootflag_set);
  917. static DEVICE_ATTR(boottime, 0644, boottime_get, boottime_set);
  918. static DEVICE_ATTR(channel, 0644, channel_get, channel_set);
  919. static DEVICE_ATTR(mesh_id, 0644, mesh_id_get, mesh_id_set);
  920. static DEVICE_ATTR(protocol_id, 0644, protocol_id_get, protocol_id_set);
  921. static DEVICE_ATTR(metric_id, 0644, metric_id_get, metric_id_set);
  922. static DEVICE_ATTR(capability, 0644, capability_get, capability_set);
  923. static struct attribute *boot_opts_attrs[] = {
  924. &dev_attr_bootflag.attr,
  925. &dev_attr_boottime.attr,
  926. &dev_attr_channel.attr,
  927. NULL
  928. };
  929. static struct attribute_group boot_opts_group = {
  930. .name = "boot_options",
  931. .attrs = boot_opts_attrs,
  932. };
  933. static struct attribute *mesh_ie_attrs[] = {
  934. &dev_attr_mesh_id.attr,
  935. &dev_attr_protocol_id.attr,
  936. &dev_attr_metric_id.attr,
  937. &dev_attr_capability.attr,
  938. NULL
  939. };
  940. static struct attribute_group mesh_ie_group = {
  941. .name = "mesh_ie",
  942. .attrs = mesh_ie_attrs,
  943. };
  944. void lbs_persist_config_init(struct net_device *dev)
  945. {
  946. int ret;
  947. ret = sysfs_create_group(&(dev->dev.kobj), &boot_opts_group);
  948. ret = sysfs_create_group(&(dev->dev.kobj), &mesh_ie_group);
  949. }
  950. void lbs_persist_config_remove(struct net_device *dev)
  951. {
  952. sysfs_remove_group(&(dev->dev.kobj), &boot_opts_group);
  953. sysfs_remove_group(&(dev->dev.kobj), &mesh_ie_group);
  954. }
  955. /***************************************************************************
  956. * Ethtool related
  957. */
  958. static const char *mesh_stat_strings[] = {
  959. "drop_duplicate_bcast",
  960. "drop_ttl_zero",
  961. "drop_no_fwd_route",
  962. "drop_no_buffers",
  963. "fwded_unicast_cnt",
  964. "fwded_bcast_cnt",
  965. "drop_blind_table",
  966. "tx_failed_cnt"
  967. };
  968. void lbs_mesh_ethtool_get_stats(struct net_device *dev,
  969. struct ethtool_stats *stats, uint64_t *data)
  970. {
  971. struct lbs_private *priv = dev->ml_priv;
  972. struct cmd_ds_mesh_access mesh_access;
  973. int ret;
  974. lbs_deb_enter(LBS_DEB_ETHTOOL);
  975. /* Get Mesh Statistics */
  976. ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_STATS, &mesh_access);
  977. if (ret) {
  978. memset(data, 0, MESH_STATS_NUM*(sizeof(uint64_t)));
  979. return;
  980. }
  981. priv->mstats.fwd_drop_rbt = le32_to_cpu(mesh_access.data[0]);
  982. priv->mstats.fwd_drop_ttl = le32_to_cpu(mesh_access.data[1]);
  983. priv->mstats.fwd_drop_noroute = le32_to_cpu(mesh_access.data[2]);
  984. priv->mstats.fwd_drop_nobuf = le32_to_cpu(mesh_access.data[3]);
  985. priv->mstats.fwd_unicast_cnt = le32_to_cpu(mesh_access.data[4]);
  986. priv->mstats.fwd_bcast_cnt = le32_to_cpu(mesh_access.data[5]);
  987. priv->mstats.drop_blind = le32_to_cpu(mesh_access.data[6]);
  988. priv->mstats.tx_failed_cnt = le32_to_cpu(mesh_access.data[7]);
  989. data[0] = priv->mstats.fwd_drop_rbt;
  990. data[1] = priv->mstats.fwd_drop_ttl;
  991. data[2] = priv->mstats.fwd_drop_noroute;
  992. data[3] = priv->mstats.fwd_drop_nobuf;
  993. data[4] = priv->mstats.fwd_unicast_cnt;
  994. data[5] = priv->mstats.fwd_bcast_cnt;
  995. data[6] = priv->mstats.drop_blind;
  996. data[7] = priv->mstats.tx_failed_cnt;
  997. lbs_deb_enter(LBS_DEB_ETHTOOL);
  998. }
  999. int lbs_mesh_ethtool_get_sset_count(struct net_device *dev, int sset)
  1000. {
  1001. struct lbs_private *priv = dev->ml_priv;
  1002. if (sset == ETH_SS_STATS && dev == priv->mesh_dev)
  1003. return MESH_STATS_NUM;
  1004. return -EOPNOTSUPP;
  1005. }
  1006. void lbs_mesh_ethtool_get_strings(struct net_device *dev,
  1007. uint32_t stringset, uint8_t *s)
  1008. {
  1009. int i;
  1010. lbs_deb_enter(LBS_DEB_ETHTOOL);
  1011. switch (stringset) {
  1012. case ETH_SS_STATS:
  1013. for (i = 0; i < MESH_STATS_NUM; i++) {
  1014. memcpy(s + i * ETH_GSTRING_LEN,
  1015. mesh_stat_strings[i],
  1016. ETH_GSTRING_LEN);
  1017. }
  1018. break;
  1019. }
  1020. lbs_deb_enter(LBS_DEB_ETHTOOL);
  1021. }