Skip to content

Commit 493bc90

Browse files
alexaringholtmann
authored andcommitted
at86rf230: add debugfs support
This patch introduce debugfs support for collect trac status stats. To clear the stats ifdown the interface of at86rf230 and start the interface again. Signed-off-by: Alexander Aring <alex.aring@gmail.com> Reviewed-by: Stefan Schmidt <stefan@osg.samsung.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent ed4a26b commit 493bc90

3 files changed

Lines changed: 159 additions & 14 deletions

File tree

‎drivers/net/ieee802154/Kconfig‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ config IEEE802154_AT86RF230
3232
This driver can also be built as a module. To do so, say M here.
3333
the module will be called 'at86rf230'.
3434

35+
config IEEE802154_AT86RF230_DEBUGFS
36+
depends on IEEE802154_AT86RF230
37+
bool "AT86RF230 debugfs interface"
38+
depends on DEBUG_FS
39+
---help---
40+
This option compiles debugfs code for the at86rf230 driver.
41+
3542
config IEEE802154_MRF24J40
3643
tristate "Microchip MRF24J40 transceiver driver"
3744
depends on IEEE802154_DRIVERS && MAC802154

‎drivers/net/ieee802154/at86rf230.c‎

Lines changed: 144 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <linux/skbuff.h>
3232
#include <linux/of_gpio.h>
3333
#include <linux/ieee802154.h>
34+
#include <linux/debugfs.h>
3435

3536
#include <net/mac802154.h>
3637
#include <net/cfg802154.h>
@@ -83,6 +84,15 @@ struct at86rf230_state_change {
8384
bool irq_enable;
8485
};
8586

87+
struct at86rf230_trac {
88+
u64 success;
89+
u64 success_data_pending;
90+
u64 success_wait_for_ack;
91+
u64 channel_access_failure;
92+
u64 no_ack;
93+
u64 invalid;
94+
};
95+
8696
struct at86rf230_local {
8797
struct spi_device *spi;
8898

@@ -103,6 +113,8 @@ struct at86rf230_local {
103113
u8 tx_retry;
104114
struct sk_buff *tx_skb;
105115
struct at86rf230_state_change tx;
116+
117+
struct at86rf230_trac trac;
106118
};
107119

108120
#define AT86RF2XX_NUMREGS 0x3F
@@ -660,6 +672,31 @@ at86rf230_tx_trac_check(void *context)
660672
struct at86rf230_state_change *ctx = context;
661673
struct at86rf230_local *lp = ctx->lp;
662674

675+
if (IS_ENABLED(CONFIG_IEEE802154_AT86RF230_DEBUGFS)) {
676+
u8 trac = TRAC_MASK(ctx->buf[1]);
677+
678+
switch (trac) {
679+
case TRAC_SUCCESS:
680+
lp->trac.success++;
681+
break;
682+
case TRAC_SUCCESS_DATA_PENDING:
683+
lp->trac.success_data_pending++;
684+
break;
685+
case TRAC_CHANNEL_ACCESS_FAILURE:
686+
lp->trac.channel_access_failure++;
687+
break;
688+
case TRAC_NO_ACK:
689+
lp->trac.no_ack++;
690+
break;
691+
case TRAC_INVALID:
692+
lp->trac.invalid++;
693+
break;
694+
default:
695+
WARN_ONCE(1, "received tx trac status %d\n", trac);
696+
break;
697+
}
698+
}
699+
663700
at86rf230_async_state_change(lp, &lp->irq, STATE_TX_ON,
664701
at86rf230_tx_on, true);
665702
}
@@ -696,13 +733,32 @@ at86rf230_rx_read_frame_complete(void *context)
696733
}
697734

698735
static void
699-
at86rf230_rx_read_frame(void *context)
736+
at86rf230_rx_trac_check(void *context)
700737
{
701738
struct at86rf230_state_change *ctx = context;
702739
struct at86rf230_local *lp = ctx->lp;
703740
u8 *buf = ctx->buf;
704741
int rc;
705742

743+
if (IS_ENABLED(CONFIG_IEEE802154_AT86RF230_DEBUGFS)) {
744+
u8 trac = TRAC_MASK(buf[1]);
745+
746+
switch (trac) {
747+
case TRAC_SUCCESS:
748+
lp->trac.success++;
749+
break;
750+
case TRAC_SUCCESS_WAIT_FOR_ACK:
751+
lp->trac.success_wait_for_ack++;
752+
break;
753+
case TRAC_INVALID:
754+
lp->trac.invalid++;
755+
break;
756+
default:
757+
WARN_ONCE(1, "received rx trac status %d\n", trac);
758+
break;
759+
}
760+
}
761+
706762
buf[0] = CMD_FB;
707763
ctx->trx.len = AT86RF2XX_MAX_BUF;
708764
ctx->msg.complete = at86rf230_rx_read_frame_complete;
@@ -714,18 +770,6 @@ at86rf230_rx_read_frame(void *context)
714770
}
715771
}
716772

717-
static void
718-
at86rf230_rx_trac_check(void *context)
719-
{
720-
/* Possible check on trac status here. This could be useful to make
721-
* some stats why receive is failed. Not used at the moment, but it's
722-
* maybe timing relevant. Datasheet doesn't say anything about this.
723-
* The programming guide say do it so.
724-
*/
725-
726-
at86rf230_rx_read_frame(context);
727-
}
728-
729773
static void
730774
at86rf230_irq_trx_end(struct at86rf230_local *lp)
731775
{
@@ -891,6 +935,10 @@ at86rf230_start(struct ieee802154_hw *hw)
891935
{
892936
struct at86rf230_local *lp = hw->priv;
893937

938+
/* reset trac stats on start */
939+
if (IS_ENABLED(CONFIG_IEEE802154_AT86RF230_DEBUGFS))
940+
memset(&lp->trac, 0, sizeof(struct at86rf230_trac));
941+
894942
at86rf230_awake(lp);
895943
enable_irq(lp->spi->irq);
896944

@@ -1591,6 +1639,81 @@ at86rf230_setup_spi_messages(struct at86rf230_local *lp)
15911639
lp->tx.timer.function = at86rf230_async_state_timer;
15921640
}
15931641

1642+
#ifdef CONFIG_IEEE802154_AT86RF230_DEBUGFS
1643+
static struct dentry *at86rf230_debugfs_root;
1644+
1645+
static int at86rf230_stats_show(struct seq_file *file, void *offset)
1646+
{
1647+
struct at86rf230_local *lp = file->private;
1648+
int ret;
1649+
1650+
ret = seq_printf(file, "SUCCESS:\t\t%8llu\n", lp->trac.success);
1651+
if (ret < 0)
1652+
return ret;
1653+
1654+
ret = seq_printf(file, "SUCCESS_DATA_PENDING:\t%8llu\n",
1655+
lp->trac.success_data_pending);
1656+
if (ret < 0)
1657+
return ret;
1658+
1659+
ret = seq_printf(file, "SUCCESS_WAIT_FOR_ACK:\t%8llu\n",
1660+
lp->trac.success_wait_for_ack);
1661+
if (ret < 0)
1662+
return ret;
1663+
1664+
ret = seq_printf(file, "CHANNEL_ACCESS_FAILURE:\t%8llu\n",
1665+
lp->trac.channel_access_failure);
1666+
if (ret < 0)
1667+
return ret;
1668+
1669+
ret = seq_printf(file, "NO_ACK:\t\t\t%8llu\n", lp->trac.no_ack);
1670+
if (ret < 0)
1671+
return ret;
1672+
1673+
return seq_printf(file, "INVALID:\t\t%8llu\n", lp->trac.invalid);
1674+
}
1675+
1676+
static int at86rf230_stats_open(struct inode *inode, struct file *file)
1677+
{
1678+
return single_open(file, at86rf230_stats_show, inode->i_private);
1679+
}
1680+
1681+
static const struct file_operations at86rf230_stats_fops = {
1682+
.open = at86rf230_stats_open,
1683+
.read = seq_read,
1684+
.llseek = seq_lseek,
1685+
.release = single_release,
1686+
};
1687+
1688+
static int at86rf230_debugfs_init(struct at86rf230_local *lp)
1689+
{
1690+
char debugfs_dir_name[DNAME_INLINE_LEN + 1] = "at86rf230-";
1691+
struct dentry *stats;
1692+
1693+
strncat(debugfs_dir_name, dev_name(&lp->spi->dev), DNAME_INLINE_LEN);
1694+
1695+
at86rf230_debugfs_root = debugfs_create_dir(debugfs_dir_name, NULL);
1696+
if (!at86rf230_debugfs_root)
1697+
return -ENOMEM;
1698+
1699+
stats = debugfs_create_file("trac_stats", S_IRUGO,
1700+
at86rf230_debugfs_root, lp,
1701+
&at86rf230_stats_fops);
1702+
if (!stats)
1703+
return -ENOMEM;
1704+
1705+
return 0;
1706+
}
1707+
1708+
static void at86rf230_debugfs_remove(void)
1709+
{
1710+
debugfs_remove_recursive(at86rf230_debugfs_root);
1711+
}
1712+
#else
1713+
static int at86rf230_debugfs_init(struct at86rf230_local *lp) { return 0; }
1714+
static void at86rf230_debugfs_remove(void) { }
1715+
#endif
1716+
15941717
static int at86rf230_probe(struct spi_device *spi)
15951718
{
15961719
struct ieee802154_hw *hw;
@@ -1686,12 +1809,18 @@ static int at86rf230_probe(struct spi_device *spi)
16861809
/* going into sleep by default */
16871810
at86rf230_sleep(lp);
16881811

1689-
rc = ieee802154_register_hw(lp->hw);
1812+
rc = at86rf230_debugfs_init(lp);
16901813
if (rc)
16911814
goto free_dev;
16921815

1816+
rc = ieee802154_register_hw(lp->hw);
1817+
if (rc)
1818+
goto free_debugfs;
1819+
16931820
return rc;
16941821

1822+
free_debugfs:
1823+
at86rf230_debugfs_remove();
16951824
free_dev:
16961825
ieee802154_free_hw(lp->hw);
16971826

@@ -1706,6 +1835,7 @@ static int at86rf230_remove(struct spi_device *spi)
17061835
at86rf230_write_subreg(lp, SR_IRQ_MASK, 0);
17071836
ieee802154_unregister_hw(lp->hw);
17081837
ieee802154_free_hw(lp->hw);
1838+
at86rf230_debugfs_remove();
17091839
dev_dbg(&spi->dev, "unregistered at86rf230\n");
17101840

17111841
return 0;

‎drivers/net/ieee802154/at86rf230.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,5 +216,13 @@
216216
#define STATE_TRANSITION_IN_PROGRESS 0x1F
217217

218218
#define TRX_STATE_MASK (0x1F)
219+
#define TRAC_MASK(x) ((x & 0xe0) >> 5)
220+
221+
#define TRAC_SUCCESS 0
222+
#define TRAC_SUCCESS_DATA_PENDING 1
223+
#define TRAC_SUCCESS_WAIT_FOR_ACK 2
224+
#define TRAC_CHANNEL_ACCESS_FAILURE 3
225+
#define TRAC_NO_ACK 5
226+
#define TRAC_INVALID 7
219227

220228
#endif /* !_AT86RF230_H */

0 commit comments

Comments
 (0)