NFC: added the sysfs entry for nfcsim workqueue delay
PATCH 1/1 NFC: added the sysfs entry for nfcsim workqueue delay
added the sysfs entry for nfcsim workqueue delay, as tx_delay
---
implementing the TODO task
drivers/nfc/nfcsim.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-)
drivers/nfc/nfcsim.c +35 -3
@@ -32,6 +32,8 @@#define NFCSIM_POLL_TARGET 2#define NFCSIM_POLL_DUAL (NFCSIM_POLL_INITIATOR | NFCSIM_POLL_TARGET) +#define TX_DEFAULT_DELAY 5 +struct nfcsim {struct nfc_dev *nfc_dev;
@@ -62,12 +64,41 @@ static struct nfcsim *dev1;static struct workqueue_struct *wq; + +static int tx_delay =TX_DEFAULT_DELAY ; + +static ssize_t show_tx_delay (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +int n; + + n =scnprintf (buf,PAGE_SIZE ,"%d\n" , tx_delay); +return n; +} + +static ssize_t store_tx_delay (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +if (kstrtouint (buf,0 , &tx_delay) <0 ) +return -EINVAL ; + +if (tx_delay <0 ) +return -EINVAL ; + +return count; +} + +static DEVICE_ATTR(tx_delay, 0644, show_tx_delay, store_tx_delay); +static void nfcsim_cleanup_dev (struct nfcsim *dev,u8 shutdown) {DEV_DBG (dev,"shutdown=%d\n" , shutdown);mutex_lock (&dev->lock); +device_remove_file (&dev->nfc_dev->dev, &dev_attr_tx_delay); dev->polling_mode =NFCSIM_POLL_NONE ; dev->shutting_down = shutdown; dev->cb =NULL ;
@@ -320,10 +351,8 @@ static int nfcsim_tx(struct nfc_dev *nfc_dev, struct nfc_target *target,* If packet transmission occurs immediately between them, we have a * non-stop flow of several tens of thousands SYMM packets per second * and a burning cpu. -* -* TODO: Add support for a sysfs entry to control this delay. */ -queue_delayed_work (wq, &peer->recv_work,msecs_to_jiffies (5 )); +queue_delayed_work (wq, &peer->recv_work,msecs_to_jiffies (tx_delay));mutex_unlock (&peer->lock);
@@ -461,6 +490,9 @@ static struct nfcsim *nfcsim_init_dev(void)if (rc) goto free_nfc_dev; + rc =device_create_file (&dev->nfc_dev->dev, &dev_attr_tx_delay); +if (rc) +pr_err ("error creating sysfs entry\n" );return dev; free_nfc_dev:
Signature · 1 line
1.9.1
I have also tested this module its successfully creating the tx_delay entry in nfc
root@saurabh:/home/saurabh# ls /sys/class/nfc/nfc0/tx_delay /sys/class/nfc/nfc0/tx_delay
its default value is set to 5
root@saurabh:/home/saurabh# cat /sys/class/nfc/nfc0/tx_delay 5
its changing the value correctly
root@saurabh:/home/saurabh# echo 15 > /sys/class/nfc/nfc0/tx_delay root@saurabh:/home/saurabh# cat /sys/class/nfc/nfc0/tx_delay 15
and on removing the module its cleaning up without any oops
Quoted 88 lines · Saurabh Sengar
added the sysfs entry for nfcsim workqueue delay, as
tx_delaySigned-off-by Saurabh Sengar <[email protected]>---
implementing the TODO taskdrivers/nfc/nfcsim.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-)drivers/nfc/nfcsim.c +35
-4@@ -32,6 +32,8 @@#define NFCSIM_POLL_TARGET 2#define NFCSIM_POLL_DUAL (NFCSIM_POLL_INITIATOR | NFCSIM_POLL_TARGET) +#define TX_DEFAULT_DELAY 5 +struct nfcsim {struct nfc_dev *nfc_dev;@@ -62,12 +64,41 @@ static struct nfcsim *dev1;static struct workqueue_struct *wq; + +static int tx_delay =TX_DEFAULT_DELAY ; + +static ssize_t show_tx_delay (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +int n; + + n =scnprintf (buf,PAGE_SIZE ,"%d\n" , tx_delay); +return n; +} + +static ssize_t store_tx_delay (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +if (kstrtouint (buf,0 , &tx_delay) <0 ) +return -EINVAL ; + +if (tx_delay <0 ) +return -EINVAL ; + +return count; +} + +static DEVICE_ATTR(tx_delay, 0644, show_tx_delay, store_tx_delay); +static void nfcsim_cleanup_dev (struct nfcsim *dev,u8 shutdown) {DEV_DBG (dev,"shutdown=%d\n" , shutdown);mutex_lock (&dev->lock); +device_remove_file (&dev->nfc_dev->dev, &dev_attr_tx_delay); dev->polling_mode =NFCSIM_POLL_NONE ; dev->shutting_down = shutdown; dev->cb =NULL ;@@ -320,10 +351,8 @@ static int nfcsim_tx(struct nfc_dev *nfc_dev, struct nfc_target *target,* If packet transmission occurs immediately between them, we have a * non-stop flow of several tens of thousands SYMM packets per second * and a burning cpu. -* -* TODO: Add support for a sysfs entry to control this delay. */ -queue_delayed_work (wq, &peer->recv_work,msecs_to_jiffies (5 )); +queue_delayed_work (wq, &peer->recv_work,msecs_to_jiffies (tx_delay));mutex_unlock (&peer->lock);@@ -461,6 +490,9 @@ static struct nfcsim *nfcsim_init_dev(void)if (rc) goto free_nfc_dev; + rc =device_create_file (&dev->nfc_dev->dev, &dev_attr_tx_delay); +if (rc) +pr_err ("error creating sysfs entry\n" );return dev; free_nfc_dev: --1.9.1
pinging for feedback.
Please respond.
Quoted 108 lines · Saurabh Sengar
I have also tested this module its successfully creating the
tx_delayentry in nfcroot@saurabh:/home/saurabh# ls /sys/class/nfc/nfc0/tx_delay /sys/class/nfc/nfc0/tx_delayits default value is set to 5
root@saurabh:/home/saurabh# cat /sys/class/nfc/nfc0/tx_delay 5its changing the value correctly
root@saurabh:/home/saurabh# echo 15 > /sys/class/nfc/nfc0/tx_delay root@saurabh:/home/saurabh# cat /sys/class/nfc/nfc0/tx_delay 15and on removing the module its cleaning up without any oops
Tested-by Saurabh Sengar <[email protected]>Quoted 88 lines · Saurabh Sengar
added the sysfs entry for nfcsim workqueue delay, as
tx_delaySigned-off-by Saurabh Sengar <[email protected]>---
implementing the TODO taskdrivers/nfc/nfcsim.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-)drivers/nfc/nfcsim.c +35
-4@@ -32,6 +32,8 @@#define NFCSIM_POLL_TARGET 2#define NFCSIM_POLL_DUAL (NFCSIM_POLL_INITIATOR | NFCSIM_POLL_TARGET) +#define TX_DEFAULT_DELAY 5 +struct nfcsim {struct nfc_dev *nfc_dev;@@ -62,12 +64,41 @@ static struct nfcsim *dev1;static struct workqueue_struct *wq; + +static int tx_delay =TX_DEFAULT_DELAY ; + +static ssize_t show_tx_delay (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +int n; + + n =scnprintf (buf,PAGE_SIZE ,"%d\n" , tx_delay); +return n; +} + +static ssize_t store_tx_delay (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +if (kstrtouint (buf,0 , &tx_delay) <0 ) +return -EINVAL ; + +if (tx_delay <0 ) +return -EINVAL ; + +return count; +} + +static DEVICE_ATTR(tx_delay, 0644, show_tx_delay, store_tx_delay); +static void nfcsim_cleanup_dev (struct nfcsim *dev,u8 shutdown) {DEV_DBG (dev,"shutdown=%d\n" , shutdown);mutex_lock (&dev->lock); +device_remove_file (&dev->nfc_dev->dev, &dev_attr_tx_delay); dev->polling_mode =NFCSIM_POLL_NONE ; dev->shutting_down = shutdown; dev->cb =NULL ;@@ -320,10 +351,8 @@ static int nfcsim_tx(struct nfc_dev *nfc_dev, struct nfc_target *target,* If packet transmission occurs immediately between them, we have a * non-stop flow of several tens of thousands SYMM packets per second * and a burning cpu. -* -* TODO: Add support for a sysfs entry to control this delay. */ -queue_delayed_work (wq, &peer->recv_work,msecs_to_jiffies (5 )); +queue_delayed_work (wq, &peer->recv_work,msecs_to_jiffies (tx_delay));mutex_unlock (&peer->lock);@@ -461,6 +490,9 @@ static struct nfcsim *nfcsim_init_dev(void)if (rc) goto free_nfc_dev; + rc =device_create_file (&dev->nfc_dev->dev, &dev_attr_tx_delay); +if (rc) +pr_err ("error creating sysfs entry\n" );return dev; free_nfc_dev: --1.9.1
ping again !!
Quoted 112 lines · Saurabh Sengar
pinging for feedback.
Please respond.Quoted 108 lines · Saurabh Sengar
I have also tested this module its successfully creating the
tx_delayentry in nfcroot@saurabh:/home/saurabh# ls /sys/class/nfc/nfc0/tx_delay /sys/class/nfc/nfc0/tx_delayits default value is set to 5
root@saurabh:/home/saurabh# cat /sys/class/nfc/nfc0/tx_delay 5its changing the value correctly
root@saurabh:/home/saurabh# echo 15 > /sys/class/nfc/nfc0/tx_delay root@saurabh:/home/saurabh# cat /sys/class/nfc/nfc0/tx_delay 15and on removing the module its cleaning up without any oops
Tested-by Saurabh Sengar <[email protected]>Quoted 88 lines · Saurabh Sengar
added the sysfs entry for nfcsim workqueue delay, as
tx_delaySigned-off-by Saurabh Sengar <[email protected]>---
implementing the TODO taskdrivers/nfc/nfcsim.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-)drivers/nfc/nfcsim.c +35
-4@@ -32,6 +32,8 @@#define NFCSIM_POLL_TARGET 2#define NFCSIM_POLL_DUAL (NFCSIM_POLL_INITIATOR | NFCSIM_POLL_TARGET) +#define TX_DEFAULT_DELAY 5 +struct nfcsim {struct nfc_dev *nfc_dev;@@ -62,12 +64,41 @@ static struct nfcsim *dev1;static struct workqueue_struct *wq; + +static int tx_delay =TX_DEFAULT_DELAY ; + +static ssize_t show_tx_delay (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +int n; + + n =scnprintf (buf,PAGE_SIZE ,"%d\n" , tx_delay); +return n; +} + +static ssize_t store_tx_delay (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +if (kstrtouint (buf,0 , &tx_delay) <0 ) +return -EINVAL ; + +if (tx_delay <0 ) +return -EINVAL ; + +return count; +} + +static DEVICE_ATTR(tx_delay, 0644, show_tx_delay, store_tx_delay); +static void nfcsim_cleanup_dev (struct nfcsim *dev,u8 shutdown) {DEV_DBG (dev,"shutdown=%d\n" , shutdown);mutex_lock (&dev->lock); +device_remove_file (&dev->nfc_dev->dev, &dev_attr_tx_delay); dev->polling_mode =NFCSIM_POLL_NONE ; dev->shutting_down = shutdown; dev->cb =NULL ;@@ -320,10 +351,8 @@ static int nfcsim_tx(struct nfc_dev *nfc_dev, struct nfc_target *target,* If packet transmission occurs immediately between them, we have a * non-stop flow of several tens of thousands SYMM packets per second * and a burning cpu. -* -* TODO: Add support for a sysfs entry to control this delay. */ -queue_delayed_work (wq, &peer->recv_work,msecs_to_jiffies (5 )); +queue_delayed_work (wq, &peer->recv_work,msecs_to_jiffies (tx_delay));mutex_unlock (&peer->lock);@@ -461,6 +490,9 @@ static struct nfcsim *nfcsim_init_dev(void)if (rc) goto free_nfc_dev; + rc =device_create_file (&dev->nfc_dev->dev, &dev_attr_tx_delay); +if (rc) +pr_err ("error creating sysfs entry\n" );return dev; free_nfc_dev: --1.9.1