mesh.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  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 = cpu_to_le32(!!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. /**
  498. * @brief Access the mesh forwarding table
  499. *
  500. * @param priv A pointer to struct lbs_private structure
  501. * @param cmd_action The forwarding table action to perform
  502. * @param cmd The pre-filled FWT_ACCESS command
  503. *
  504. * @return 0 on success and 'cmd' will be filled with the
  505. * firmware's response
  506. */
  507. int lbs_cmd_fwt_access(struct lbs_private *priv, u16 cmd_action,
  508. struct cmd_ds_fwt_access *cmd)
  509. {
  510. int ret;
  511. lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
  512. cmd->hdr.command = cpu_to_le16(CMD_FWT_ACCESS);
  513. cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access));
  514. cmd->hdr.result = 0;
  515. cmd->action = cpu_to_le16(cmd_action);
  516. ret = lbs_cmd_with_response(priv, CMD_FWT_ACCESS, cmd);
  517. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  518. return 0;
  519. }
  520. int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
  521. struct cmd_ds_mesh_access *cmd)
  522. {
  523. int ret;
  524. lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
  525. cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
  526. cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
  527. cmd->hdr.result = 0;
  528. cmd->action = cpu_to_le16(cmd_action);
  529. ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
  530. lbs_deb_leave(LBS_DEB_CMD);
  531. return ret;
  532. }
  533. static int __lbs_mesh_config_send(struct lbs_private *priv,
  534. struct cmd_ds_mesh_config *cmd,
  535. uint16_t action, uint16_t type)
  536. {
  537. int ret;
  538. u16 command = CMD_MESH_CONFIG_OLD;
  539. lbs_deb_enter(LBS_DEB_CMD);
  540. /*
  541. * Command id is 0xac for v10 FW along with mesh interface
  542. * id in bits 14-13-12.
  543. */
  544. if (priv->mesh_tlv == TLV_TYPE_MESH_ID)
  545. command = CMD_MESH_CONFIG |
  546. (MESH_IFACE_ID << MESH_IFACE_BIT_OFFSET);
  547. cmd->hdr.command = cpu_to_le16(command);
  548. cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config));
  549. cmd->hdr.result = 0;
  550. cmd->type = cpu_to_le16(type);
  551. cmd->action = cpu_to_le16(action);
  552. ret = lbs_cmd_with_response(priv, command, cmd);
  553. lbs_deb_leave(LBS_DEB_CMD);
  554. return ret;
  555. }
  556. int lbs_mesh_config_send(struct lbs_private *priv,
  557. struct cmd_ds_mesh_config *cmd,
  558. uint16_t action, uint16_t type)
  559. {
  560. int ret;
  561. if (!(priv->fwcapinfo & FW_CAPINFO_PERSISTENT_CONFIG))
  562. return -EOPNOTSUPP;
  563. ret = __lbs_mesh_config_send(priv, cmd, action, type);
  564. return ret;
  565. }
  566. /* This function is the CMD_MESH_CONFIG legacy function. It only handles the
  567. * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG
  568. * are all handled by preparing a struct cmd_ds_mesh_config and passing it to
  569. * lbs_mesh_config_send.
  570. */
  571. int lbs_mesh_config(struct lbs_private *priv, uint16_t action, uint16_t chan)
  572. {
  573. struct cmd_ds_mesh_config cmd;
  574. struct mrvl_meshie *ie;
  575. DECLARE_SSID_BUF(ssid);
  576. memset(&cmd, 0, sizeof(cmd));
  577. cmd.channel = cpu_to_le16(chan);
  578. ie = (struct mrvl_meshie *)cmd.data;
  579. switch (action) {
  580. case CMD_ACT_MESH_CONFIG_START:
  581. ie->id = WLAN_EID_GENERIC;
  582. ie->val.oui[0] = 0x00;
  583. ie->val.oui[1] = 0x50;
  584. ie->val.oui[2] = 0x43;
  585. ie->val.type = MARVELL_MESH_IE_TYPE;
  586. ie->val.subtype = MARVELL_MESH_IE_SUBTYPE;
  587. ie->val.version = MARVELL_MESH_IE_VERSION;
  588. ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP;
  589. ie->val.active_metric_id = MARVELL_MESH_METRIC_ID;
  590. ie->val.mesh_capability = MARVELL_MESH_CAPABILITY;
  591. ie->val.mesh_id_len = priv->mesh_ssid_len;
  592. memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len);
  593. ie->len = sizeof(struct mrvl_meshie_val) -
  594. IEEE80211_MAX_SSID_LEN + priv->mesh_ssid_len;
  595. cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val));
  596. break;
  597. case CMD_ACT_MESH_CONFIG_STOP:
  598. break;
  599. default:
  600. return -1;
  601. }
  602. lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n",
  603. action, priv->mesh_tlv, chan,
  604. print_ssid(ssid, priv->mesh_ssid, priv->mesh_ssid_len));
  605. return __lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv);
  606. }
  607. /***************************************************************************
  608. * Persistent configuration support
  609. */
  610. static int mesh_get_default_parameters(struct device *dev,
  611. struct mrvl_mesh_defaults *defs)
  612. {
  613. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  614. struct cmd_ds_mesh_config cmd;
  615. int ret;
  616. memset(&cmd, 0, sizeof(struct cmd_ds_mesh_config));
  617. ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_GET,
  618. CMD_TYPE_MESH_GET_DEFAULTS);
  619. if (ret)
  620. return -EOPNOTSUPP;
  621. memcpy(defs, &cmd.data[0], sizeof(struct mrvl_mesh_defaults));
  622. return 0;
  623. }
  624. /**
  625. * @brief Get function for sysfs attribute bootflag
  626. */
  627. static ssize_t bootflag_get(struct device *dev,
  628. struct device_attribute *attr, char *buf)
  629. {
  630. struct mrvl_mesh_defaults defs;
  631. int ret;
  632. ret = mesh_get_default_parameters(dev, &defs);
  633. if (ret)
  634. return ret;
  635. return snprintf(buf, 12, "%d\n", le32_to_cpu(defs.bootflag));
  636. }
  637. /**
  638. * @brief Set function for sysfs attribute bootflag
  639. */
  640. static ssize_t bootflag_set(struct device *dev, struct device_attribute *attr,
  641. const char *buf, size_t count)
  642. {
  643. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  644. struct cmd_ds_mesh_config cmd;
  645. uint32_t datum;
  646. int ret;
  647. memset(&cmd, 0, sizeof(cmd));
  648. ret = sscanf(buf, "%d", &datum);
  649. if ((ret != 1) || (datum > 1))
  650. return -EINVAL;
  651. *((__le32 *)&cmd.data[0]) = cpu_to_le32(!!datum);
  652. cmd.length = cpu_to_le16(sizeof(uint32_t));
  653. ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
  654. CMD_TYPE_MESH_SET_BOOTFLAG);
  655. if (ret)
  656. return ret;
  657. return strlen(buf);
  658. }
  659. /**
  660. * @brief Get function for sysfs attribute boottime
  661. */
  662. static ssize_t boottime_get(struct device *dev,
  663. struct device_attribute *attr, char *buf)
  664. {
  665. struct mrvl_mesh_defaults defs;
  666. int ret;
  667. ret = mesh_get_default_parameters(dev, &defs);
  668. if (ret)
  669. return ret;
  670. return snprintf(buf, 12, "%d\n", defs.boottime);
  671. }
  672. /**
  673. * @brief Set function for sysfs attribute boottime
  674. */
  675. static ssize_t boottime_set(struct device *dev,
  676. struct device_attribute *attr, const char *buf, size_t count)
  677. {
  678. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  679. struct cmd_ds_mesh_config cmd;
  680. uint32_t datum;
  681. int ret;
  682. memset(&cmd, 0, sizeof(cmd));
  683. ret = sscanf(buf, "%d", &datum);
  684. if ((ret != 1) || (datum > 255))
  685. return -EINVAL;
  686. /* A too small boot time will result in the device booting into
  687. * standalone (no-host) mode before the host can take control of it,
  688. * so the change will be hard to revert. This may be a desired
  689. * feature (e.g to configure a very fast boot time for devices that
  690. * will not be attached to a host), but dangerous. So I'm enforcing a
  691. * lower limit of 20 seconds: remove and recompile the driver if this
  692. * does not work for you.
  693. */
  694. datum = (datum < 20) ? 20 : datum;
  695. cmd.data[0] = datum;
  696. cmd.length = cpu_to_le16(sizeof(uint8_t));
  697. ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
  698. CMD_TYPE_MESH_SET_BOOTTIME);
  699. if (ret)
  700. return ret;
  701. return strlen(buf);
  702. }
  703. /**
  704. * @brief Get function for sysfs attribute channel
  705. */
  706. static ssize_t channel_get(struct device *dev,
  707. struct device_attribute *attr, char *buf)
  708. {
  709. struct mrvl_mesh_defaults defs;
  710. int ret;
  711. ret = mesh_get_default_parameters(dev, &defs);
  712. if (ret)
  713. return ret;
  714. return snprintf(buf, 12, "%d\n", le16_to_cpu(defs.channel));
  715. }
  716. /**
  717. * @brief Set function for sysfs attribute channel
  718. */
  719. static ssize_t channel_set(struct device *dev, struct device_attribute *attr,
  720. const char *buf, size_t count)
  721. {
  722. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  723. struct cmd_ds_mesh_config cmd;
  724. uint32_t datum;
  725. int ret;
  726. memset(&cmd, 0, sizeof(cmd));
  727. ret = sscanf(buf, "%d", &datum);
  728. if (ret != 1 || datum < 1 || datum > 11)
  729. return -EINVAL;
  730. *((__le16 *)&cmd.data[0]) = cpu_to_le16(datum);
  731. cmd.length = cpu_to_le16(sizeof(uint16_t));
  732. ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
  733. CMD_TYPE_MESH_SET_DEF_CHANNEL);
  734. if (ret)
  735. return ret;
  736. return strlen(buf);
  737. }
  738. /**
  739. * @brief Get function for sysfs attribute mesh_id
  740. */
  741. static ssize_t mesh_id_get(struct device *dev, struct device_attribute *attr,
  742. char *buf)
  743. {
  744. struct mrvl_mesh_defaults defs;
  745. int maxlen;
  746. int ret;
  747. ret = mesh_get_default_parameters(dev, &defs);
  748. if (ret)
  749. return ret;
  750. if (defs.meshie.val.mesh_id_len > IEEE80211_MAX_SSID_LEN) {
  751. lbs_pr_err("inconsistent mesh ID length");
  752. defs.meshie.val.mesh_id_len = IEEE80211_MAX_SSID_LEN;
  753. }
  754. /* SSID not null terminated: reserve room for \0 + \n */
  755. maxlen = defs.meshie.val.mesh_id_len + 2;
  756. maxlen = (PAGE_SIZE > maxlen) ? maxlen : PAGE_SIZE;
  757. defs.meshie.val.mesh_id[defs.meshie.val.mesh_id_len] = '\0';
  758. return snprintf(buf, maxlen, "%s\n", defs.meshie.val.mesh_id);
  759. }
  760. /**
  761. * @brief Set function for sysfs attribute mesh_id
  762. */
  763. static ssize_t mesh_id_set(struct device *dev, struct device_attribute *attr,
  764. const char *buf, size_t count)
  765. {
  766. struct cmd_ds_mesh_config cmd;
  767. struct mrvl_mesh_defaults defs;
  768. struct mrvl_meshie *ie;
  769. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  770. int len;
  771. int ret;
  772. if (count < 2 || count > IEEE80211_MAX_SSID_LEN + 1)
  773. return -EINVAL;
  774. memset(&cmd, 0, sizeof(struct cmd_ds_mesh_config));
  775. ie = (struct mrvl_meshie *) &cmd.data[0];
  776. /* fetch all other Information Element parameters */
  777. ret = mesh_get_default_parameters(dev, &defs);
  778. cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
  779. /* transfer IE elements */
  780. memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
  781. len = count - 1;
  782. memcpy(ie->val.mesh_id, buf, len);
  783. /* SSID len */
  784. ie->val.mesh_id_len = len;
  785. /* IE len */
  786. ie->len = sizeof(struct mrvl_meshie_val) - IEEE80211_MAX_SSID_LEN + len;
  787. ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
  788. CMD_TYPE_MESH_SET_MESH_IE);
  789. if (ret)
  790. return ret;
  791. return strlen(buf);
  792. }
  793. /**
  794. * @brief Get function for sysfs attribute protocol_id
  795. */
  796. static ssize_t protocol_id_get(struct device *dev,
  797. struct device_attribute *attr, char *buf)
  798. {
  799. struct mrvl_mesh_defaults defs;
  800. int ret;
  801. ret = mesh_get_default_parameters(dev, &defs);
  802. if (ret)
  803. return ret;
  804. return snprintf(buf, 5, "%d\n", defs.meshie.val.active_protocol_id);
  805. }
  806. /**
  807. * @brief Set function for sysfs attribute protocol_id
  808. */
  809. static ssize_t protocol_id_set(struct device *dev,
  810. struct device_attribute *attr, const char *buf, size_t count)
  811. {
  812. struct cmd_ds_mesh_config cmd;
  813. struct mrvl_mesh_defaults defs;
  814. struct mrvl_meshie *ie;
  815. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  816. uint32_t datum;
  817. int ret;
  818. memset(&cmd, 0, sizeof(cmd));
  819. ret = sscanf(buf, "%d", &datum);
  820. if ((ret != 1) || (datum > 255))
  821. return -EINVAL;
  822. /* fetch all other Information Element parameters */
  823. ret = mesh_get_default_parameters(dev, &defs);
  824. cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
  825. /* transfer IE elements */
  826. ie = (struct mrvl_meshie *) &cmd.data[0];
  827. memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
  828. /* update protocol id */
  829. ie->val.active_protocol_id = datum;
  830. ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
  831. CMD_TYPE_MESH_SET_MESH_IE);
  832. if (ret)
  833. return ret;
  834. return strlen(buf);
  835. }
  836. /**
  837. * @brief Get function for sysfs attribute metric_id
  838. */
  839. static ssize_t metric_id_get(struct device *dev,
  840. struct device_attribute *attr, char *buf)
  841. {
  842. struct mrvl_mesh_defaults defs;
  843. int ret;
  844. ret = mesh_get_default_parameters(dev, &defs);
  845. if (ret)
  846. return ret;
  847. return snprintf(buf, 5, "%d\n", defs.meshie.val.active_metric_id);
  848. }
  849. /**
  850. * @brief Set function for sysfs attribute metric_id
  851. */
  852. static ssize_t metric_id_set(struct device *dev, struct device_attribute *attr,
  853. const char *buf, size_t count)
  854. {
  855. struct cmd_ds_mesh_config cmd;
  856. struct mrvl_mesh_defaults defs;
  857. struct mrvl_meshie *ie;
  858. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  859. uint32_t datum;
  860. int ret;
  861. memset(&cmd, 0, sizeof(cmd));
  862. ret = sscanf(buf, "%d", &datum);
  863. if ((ret != 1) || (datum > 255))
  864. return -EINVAL;
  865. /* fetch all other Information Element parameters */
  866. ret = mesh_get_default_parameters(dev, &defs);
  867. cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
  868. /* transfer IE elements */
  869. ie = (struct mrvl_meshie *) &cmd.data[0];
  870. memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
  871. /* update metric id */
  872. ie->val.active_metric_id = datum;
  873. ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
  874. CMD_TYPE_MESH_SET_MESH_IE);
  875. if (ret)
  876. return ret;
  877. return strlen(buf);
  878. }
  879. /**
  880. * @brief Get function for sysfs attribute capability
  881. */
  882. static ssize_t capability_get(struct device *dev,
  883. struct device_attribute *attr, char *buf)
  884. {
  885. struct mrvl_mesh_defaults defs;
  886. int ret;
  887. ret = mesh_get_default_parameters(dev, &defs);
  888. if (ret)
  889. return ret;
  890. return snprintf(buf, 5, "%d\n", defs.meshie.val.mesh_capability);
  891. }
  892. /**
  893. * @brief Set function for sysfs attribute capability
  894. */
  895. static ssize_t capability_set(struct device *dev, struct device_attribute *attr,
  896. const char *buf, size_t count)
  897. {
  898. struct cmd_ds_mesh_config cmd;
  899. struct mrvl_mesh_defaults defs;
  900. struct mrvl_meshie *ie;
  901. struct lbs_private *priv = to_net_dev(dev)->ml_priv;
  902. uint32_t datum;
  903. int ret;
  904. memset(&cmd, 0, sizeof(cmd));
  905. ret = sscanf(buf, "%d", &datum);
  906. if ((ret != 1) || (datum > 255))
  907. return -EINVAL;
  908. /* fetch all other Information Element parameters */
  909. ret = mesh_get_default_parameters(dev, &defs);
  910. cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie));
  911. /* transfer IE elements */
  912. ie = (struct mrvl_meshie *) &cmd.data[0];
  913. memcpy(ie, &defs.meshie, sizeof(struct mrvl_meshie));
  914. /* update value */
  915. ie->val.mesh_capability = datum;
  916. ret = lbs_mesh_config_send(priv, &cmd, CMD_ACT_MESH_CONFIG_SET,
  917. CMD_TYPE_MESH_SET_MESH_IE);
  918. if (ret)
  919. return ret;
  920. return strlen(buf);
  921. }
  922. static DEVICE_ATTR(bootflag, 0644, bootflag_get, bootflag_set);
  923. static DEVICE_ATTR(boottime, 0644, boottime_get, boottime_set);
  924. static DEVICE_ATTR(channel, 0644, channel_get, channel_set);
  925. static DEVICE_ATTR(mesh_id, 0644, mesh_id_get, mesh_id_set);
  926. static DEVICE_ATTR(protocol_id, 0644, protocol_id_get, protocol_id_set);
  927. static DEVICE_ATTR(metric_id, 0644, metric_id_get, metric_id_set);
  928. static DEVICE_ATTR(capability, 0644, capability_get, capability_set);
  929. static struct attribute *boot_opts_attrs[] = {
  930. &dev_attr_bootflag.attr,
  931. &dev_attr_boottime.attr,
  932. &dev_attr_channel.attr,
  933. NULL
  934. };
  935. static struct attribute_group boot_opts_group = {
  936. .name = "boot_options",
  937. .attrs = boot_opts_attrs,
  938. };
  939. static struct attribute *mesh_ie_attrs[] = {
  940. &dev_attr_mesh_id.attr,
  941. &dev_attr_protocol_id.attr,
  942. &dev_attr_metric_id.attr,
  943. &dev_attr_capability.attr,
  944. NULL
  945. };
  946. static struct attribute_group mesh_ie_group = {
  947. .name = "mesh_ie",
  948. .attrs = mesh_ie_attrs,
  949. };
  950. void lbs_persist_config_init(struct net_device *dev)
  951. {
  952. int ret;
  953. ret = sysfs_create_group(&(dev->dev.kobj), &boot_opts_group);
  954. ret = sysfs_create_group(&(dev->dev.kobj), &mesh_ie_group);
  955. }
  956. void lbs_persist_config_remove(struct net_device *dev)
  957. {
  958. sysfs_remove_group(&(dev->dev.kobj), &boot_opts_group);
  959. sysfs_remove_group(&(dev->dev.kobj), &mesh_ie_group);
  960. }
  961. /***************************************************************************
  962. * Ethtool related
  963. */
  964. static const char *mesh_stat_strings[] = {
  965. "drop_duplicate_bcast",
  966. "drop_ttl_zero",
  967. "drop_no_fwd_route",
  968. "drop_no_buffers",
  969. "fwded_unicast_cnt",
  970. "fwded_bcast_cnt",
  971. "drop_blind_table",
  972. "tx_failed_cnt"
  973. };
  974. void lbs_mesh_ethtool_get_stats(struct net_device *dev,
  975. struct ethtool_stats *stats, uint64_t *data)
  976. {
  977. struct lbs_private *priv = dev->ml_priv;
  978. struct cmd_ds_mesh_access mesh_access;
  979. int ret;
  980. lbs_deb_enter(LBS_DEB_ETHTOOL);
  981. /* Get Mesh Statistics */
  982. ret = lbs_mesh_access(priv, CMD_ACT_MESH_GET_STATS, &mesh_access);
  983. if (ret) {
  984. memset(data, 0, MESH_STATS_NUM*(sizeof(uint64_t)));
  985. return;
  986. }
  987. priv->mstats.fwd_drop_rbt = le32_to_cpu(mesh_access.data[0]);
  988. priv->mstats.fwd_drop_ttl = le32_to_cpu(mesh_access.data[1]);
  989. priv->mstats.fwd_drop_noroute = le32_to_cpu(mesh_access.data[2]);
  990. priv->mstats.fwd_drop_nobuf = le32_to_cpu(mesh_access.data[3]);
  991. priv->mstats.fwd_unicast_cnt = le32_to_cpu(mesh_access.data[4]);
  992. priv->mstats.fwd_bcast_cnt = le32_to_cpu(mesh_access.data[5]);
  993. priv->mstats.drop_blind = le32_to_cpu(mesh_access.data[6]);
  994. priv->mstats.tx_failed_cnt = le32_to_cpu(mesh_access.data[7]);
  995. data[0] = priv->mstats.fwd_drop_rbt;
  996. data[1] = priv->mstats.fwd_drop_ttl;
  997. data[2] = priv->mstats.fwd_drop_noroute;
  998. data[3] = priv->mstats.fwd_drop_nobuf;
  999. data[4] = priv->mstats.fwd_unicast_cnt;
  1000. data[5] = priv->mstats.fwd_bcast_cnt;
  1001. data[6] = priv->mstats.drop_blind;
  1002. data[7] = priv->mstats.tx_failed_cnt;
  1003. lbs_deb_enter(LBS_DEB_ETHTOOL);
  1004. }
  1005. int lbs_mesh_ethtool_get_sset_count(struct net_device *dev, int sset)
  1006. {
  1007. struct lbs_private *priv = dev->ml_priv;
  1008. if (sset == ETH_SS_STATS && dev == priv->mesh_dev)
  1009. return MESH_STATS_NUM;
  1010. return -EOPNOTSUPP;
  1011. }
  1012. void lbs_mesh_ethtool_get_strings(struct net_device *dev,
  1013. uint32_t stringset, uint8_t *s)
  1014. {
  1015. int i;
  1016. lbs_deb_enter(LBS_DEB_ETHTOOL);
  1017. switch (stringset) {
  1018. case ETH_SS_STATS:
  1019. for (i = 0; i < MESH_STATS_NUM; i++) {
  1020. memcpy(s + i * ETH_GSTRING_LEN,
  1021. mesh_stat_strings[i],
  1022. ETH_GSTRING_LEN);
  1023. }
  1024. break;
  1025. }
  1026. lbs_deb_enter(LBS_DEB_ETHTOOL);
  1027. }