mesh.c 34 KB

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