All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] NFC: Add deactivate target functionality
@ 2017-06-16  3:34 Mark Greer
  2017-06-16  3:34 ` [PATCH 1/2] NFC: digital: Abort cmd when deactivating target Mark Greer
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Mark Greer @ 2017-06-16  3:34 UTC (permalink / raw)
  To: Samuel Ortiz; +Cc: linux-wireless, linux-nfc, Mark Greer

There is currently no way for userspace to deactivate an active target.
Since the target is active, the adapter cannot be powered down which
wastes wastes power when the target has been read and isn't needed
anymore (but remains within range).  To solve this, add a way to
deactivate a currently active target which will then allow the adapter
to be powered down.

To be fully operational, this requires companion patches for neard.
Those patches will be submitted shortly.

Mark Greer (2):
  NFC: digital: Abort cmd when deactivating target
  NFC: Add NFC_CMD_DEACTIVATE_TARGET support

 include/uapi/linux/nfc.h |  2 ++
 net/nfc/digital_core.c   |  1 +
 net/nfc/netlink.c        | 29 +++++++++++++++++++++++++++++
 3 files changed, 32 insertions(+)

-- 
2.13.0

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] NFC: digital: Abort cmd when deactivating target
  2017-06-16  3:34 [PATCH 0/2] NFC: Add deactivate target functionality Mark Greer
@ 2017-06-16  3:34 ` Mark Greer
  2017-06-16  3:34 ` [PATCH 2/2] NFC: Add NFC_CMD_DEACTIVATE_TARGET support Mark Greer
  2017-11-09 23:05 ` [PATCH 0/2] NFC: Add deactivate target functionality Samuel Ortiz
  2 siblings, 0 replies; 4+ messages in thread
From: Mark Greer @ 2017-06-16  3:34 UTC (permalink / raw)
  To: Samuel Ortiz; +Cc: linux-wireless, linux-nfc, Mark Greer

When deactivating an active target, the outstanding command should
be aborted.

Signed-off-by: Mark Greer <mgreer@animalcreek.com>
---
 net/nfc/digital_core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/nfc/digital_core.c b/net/nfc/digital_core.c
index 0fd5518bf252..145dd74927c4 100644
--- a/net/nfc/digital_core.c
+++ b/net/nfc/digital_core.c
@@ -650,6 +650,7 @@ static void digital_deactivate_target(struct nfc_dev *nfc_dev,
 		return;
 	}
 
+	digital_abort_cmd(ddev);
 	ddev->curr_protocol = 0;
 }
 
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] NFC: Add NFC_CMD_DEACTIVATE_TARGET support
  2017-06-16  3:34 [PATCH 0/2] NFC: Add deactivate target functionality Mark Greer
  2017-06-16  3:34 ` [PATCH 1/2] NFC: digital: Abort cmd when deactivating target Mark Greer
@ 2017-06-16  3:34 ` Mark Greer
  2017-11-09 23:05 ` [PATCH 0/2] NFC: Add deactivate target functionality Samuel Ortiz
  2 siblings, 0 replies; 4+ messages in thread
From: Mark Greer @ 2017-06-16  3:34 UTC (permalink / raw)
  To: Samuel Ortiz; +Cc: linux-wireless, linux-nfc, Mark Greer

Once an NFC target (i.e., a tag) is found, it remains active until
there is a failure reading or writing it (often caused by the target
moving out of range).  While the target is active, the NFC adapter
and antenna must remain powered.  This wastes power when the target
remains in range but the client application no longer cares whether
it is there or not.

To mitigate this, add a new netlink command that allows userspace
to deactivate an active target.  When issued, this command will cause
the NFC subsystem to act as though the target was moved out of range.
Once the command has been executed, the client application can power
off the NFC adapter to reduce power consumption.

Signed-off-by: Mark Greer <mgreer@animalcreek.com>
---

I'm not really sure what the correct argument for the mode parameter
of digital_activate_target() is.  I do not have any NCI controllers
to test with.
---
 include/uapi/linux/nfc.h |  2 ++
 net/nfc/netlink.c        | 29 +++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/include/uapi/linux/nfc.h b/include/uapi/linux/nfc.h
index 399f39ff8048..f6e3c8c9c744 100644
--- a/include/uapi/linux/nfc.h
+++ b/include/uapi/linux/nfc.h
@@ -89,6 +89,7 @@
  * @NFC_CMD_ACTIVATE_TARGET: Request NFC controller to reactivate target.
  * @NFC_CMD_VENDOR: Vendor specific command, to be implemented directly
  *	from the driver in order to support hardware specific operations.
+ * @NFC_CMD_DEACTIVATE_TARGET: Request NFC controller to deactivate target.
  */
 enum nfc_commands {
 	NFC_CMD_UNSPEC,
@@ -121,6 +122,7 @@ enum nfc_commands {
 	NFC_CMD_SE_IO,
 	NFC_CMD_ACTIVATE_TARGET,
 	NFC_CMD_VENDOR,
+	NFC_CMD_DEACTIVATE_TARGET,
 /* private: internal use only */
 	__NFC_CMD_AFTER_LAST
 };
diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c
index 6b0850e63e09..43a27e43ef12 100644
--- a/net/nfc/netlink.c
+++ b/net/nfc/netlink.c
@@ -926,6 +926,30 @@ static int nfc_genl_activate_target(struct sk_buff *skb, struct genl_info *info)
 	return rc;
 }
 
+static int nfc_genl_deactivate_target(struct sk_buff *skb,
+				      struct genl_info *info)
+{
+	struct nfc_dev *dev;
+	u32 device_idx, target_idx;
+	int rc;
+
+	if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
+		return -EINVAL;
+
+	device_idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
+
+	dev = nfc_get_device(device_idx);
+	if (!dev)
+		return -ENODEV;
+
+	target_idx = nla_get_u32(info->attrs[NFC_ATTR_TARGET_INDEX]);
+
+	rc = nfc_deactivate_target(dev, target_idx, NFC_TARGET_MODE_SLEEP);
+
+	nfc_put_device(dev);
+	return rc;
+}
+
 static int nfc_genl_dep_link_up(struct sk_buff *skb, struct genl_info *info)
 {
 	struct nfc_dev *dev;
@@ -1749,6 +1773,11 @@ static const struct genl_ops nfc_genl_ops[] = {
 		.doit = nfc_genl_vendor_cmd,
 		.policy = nfc_genl_policy,
 	},
+	{
+		.cmd = NFC_CMD_DEACTIVATE_TARGET,
+		.doit = nfc_genl_deactivate_target,
+		.policy = nfc_genl_policy,
+	},
 };
 
 static struct genl_family nfc_genl_family __ro_after_init = {
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] NFC: Add deactivate target functionality
  2017-06-16  3:34 [PATCH 0/2] NFC: Add deactivate target functionality Mark Greer
  2017-06-16  3:34 ` [PATCH 1/2] NFC: digital: Abort cmd when deactivating target Mark Greer
  2017-06-16  3:34 ` [PATCH 2/2] NFC: Add NFC_CMD_DEACTIVATE_TARGET support Mark Greer
@ 2017-11-09 23:05 ` Samuel Ortiz
  2 siblings, 0 replies; 4+ messages in thread
From: Samuel Ortiz @ 2017-11-09 23:05 UTC (permalink / raw)
  To: Mark Greer; +Cc: linux-wireless, linux-nfc

Hi Mark,

On Thu, Jun 15, 2017 at 08:34:20PM -0700, Mark Greer wrote:
> There is currently no way for userspace to deactivate an active target.
> Since the target is active, the adapter cannot be powered down which
> wastes wastes power when the target has been read and isn't needed
> anymore (but remains within range).  To solve this, add a way to
> deactivate a currently active target which will then allow the adapter
> to be powered down.
> 
> To be fully operational, this requires companion patches for neard.
> Those patches will be submitted shortly.
> 
> Mark Greer (2):
>   NFC: digital: Abort cmd when deactivating target
>   NFC: Add NFC_CMD_DEACTIVATE_TARGET support
Both patches applied to nfc-next, thanks.

Cheers,
Samuel.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-11-09 23:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-16  3:34 [PATCH 0/2] NFC: Add deactivate target functionality Mark Greer
2017-06-16  3:34 ` [PATCH 1/2] NFC: digital: Abort cmd when deactivating target Mark Greer
2017-06-16  3:34 ` [PATCH 2/2] NFC: Add NFC_CMD_DEACTIVATE_TARGET support Mark Greer
2017-11-09 23:05 ` [PATCH 0/2] NFC: Add deactivate target functionality Samuel Ortiz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.