Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8939e47f authored by Ilan Elias's avatar Ilan Elias Committed by John W. Linville
Browse files

NFC: Clearly separate NCI states from flags



Make a clear separation between NCI states and flags.
This is required in order to support more NCI states (e.g.
for multiple targets support).

Signed-off-by: default avatarIlan Elias <ilane@ti.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 6d810f10
Loading
Loading
Loading
Loading
+10 −4
Original line number Original line Diff line number Diff line
@@ -34,16 +34,21 @@
#include <net/nfc/nfc.h>
#include <net/nfc/nfc.h>
#include <net/nfc/nci.h>
#include <net/nfc/nci.h>


/* NCI device state */
/* NCI device flags */
enum {
enum nci_flag {
	NCI_INIT,
	NCI_INIT,
	NCI_UP,
	NCI_UP,
	NCI_DISCOVERY,
	NCI_POLL_ACTIVE,
	NCI_DATA_EXCHANGE,
	NCI_DATA_EXCHANGE,
	NCI_DATA_EXCHANGE_TO,
	NCI_DATA_EXCHANGE_TO,
};
};


/* NCI device states */
enum nci_state {
	NCI_IDLE,
	NCI_DISCOVERY,
	NCI_POLL_ACTIVE,
};

/* NCI timeouts */
/* NCI timeouts */
#define NCI_RESET_TIMEOUT			5000
#define NCI_RESET_TIMEOUT			5000
#define NCI_INIT_TIMEOUT			5000
#define NCI_INIT_TIMEOUT			5000
@@ -70,6 +75,7 @@ struct nci_dev {
	int			tx_headroom;
	int			tx_headroom;
	int			tx_tailroom;
	int			tx_tailroom;


	atomic_t		state;
	unsigned long		flags;
	unsigned long		flags;


	atomic_t		cmd_cnt;
	atomic_t		cmd_cnt;
+6 −5
Original line number Original line Diff line number Diff line
@@ -264,6 +264,7 @@ static int nci_open_device(struct nci_dev *ndev)


	if (!rc) {
	if (!rc) {
		set_bit(NCI_UP, &ndev->flags);
		set_bit(NCI_UP, &ndev->flags);
		atomic_set(&ndev->state, NCI_IDLE);
	} else {
	} else {
		/* Init failed, cleanup */
		/* Init failed, cleanup */
		skb_queue_purge(&ndev->cmd_q);
		skb_queue_purge(&ndev->cmd_q);
@@ -360,7 +361,7 @@ static int nci_start_poll(struct nfc_dev *nfc_dev, __u32 protocols)
	struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
	struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
	int rc;
	int rc;


	if (test_bit(NCI_DISCOVERY, &ndev->flags)) {
	if (atomic_read(&ndev->state) == NCI_DISCOVERY) {
		pr_err("unable to start poll, since poll is already active\n");
		pr_err("unable to start poll, since poll is already active\n");
		return -EBUSY;
		return -EBUSY;
	}
	}
@@ -370,7 +371,7 @@ static int nci_start_poll(struct nfc_dev *nfc_dev, __u32 protocols)
		return -EBUSY;
		return -EBUSY;
	}
	}


	if (test_bit(NCI_POLL_ACTIVE, &ndev->flags)) {
	if (atomic_read(&ndev->state) == NCI_POLL_ACTIVE) {
		pr_debug("target is active, implicitly deactivate...\n");
		pr_debug("target is active, implicitly deactivate...\n");


		rc = nci_request(ndev, nci_rf_deactivate_req, 0,
		rc = nci_request(ndev, nci_rf_deactivate_req, 0,
@@ -392,7 +393,7 @@ static void nci_stop_poll(struct nfc_dev *nfc_dev)
{
{
	struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
	struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);


	if (!test_bit(NCI_DISCOVERY, &ndev->flags)) {
	if (atomic_read(&ndev->state) != NCI_DISCOVERY) {
		pr_err("unable to stop poll, since poll is not active\n");
		pr_err("unable to stop poll, since poll is not active\n");
		return;
		return;
	}
	}
@@ -408,7 +409,7 @@ static int nci_activate_target(struct nfc_dev *nfc_dev, __u32 target_idx,


	pr_debug("target_idx %d, protocol 0x%x\n", target_idx, protocol);
	pr_debug("target_idx %d, protocol 0x%x\n", target_idx, protocol);


	if (!test_bit(NCI_POLL_ACTIVE, &ndev->flags)) {
	if (atomic_read(&ndev->state) != NCI_POLL_ACTIVE) {
		pr_err("there is no available target to activate\n");
		pr_err("there is no available target to activate\n");
		return -EINVAL;
		return -EINVAL;
	}
	}
@@ -443,7 +444,7 @@ static void nci_deactivate_target(struct nfc_dev *nfc_dev, __u32 target_idx)


	ndev->target_active_prot = 0;
	ndev->target_active_prot = 0;


	if (test_bit(NCI_POLL_ACTIVE, &ndev->flags)) {
	if (atomic_read(&ndev->state) == NCI_POLL_ACTIVE) {
		nci_request(ndev, nci_rf_deactivate_req, 0,
		nci_request(ndev, nci_rf_deactivate_req, 0,
			msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT));
			msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT));
	}
	}
+2 −3
Original line number Original line Diff line number Diff line
@@ -261,8 +261,7 @@ static void nci_rf_intf_activated_ntf_packet(struct nci_dev *ndev,
	__u8 *data = skb->data;
	__u8 *data = skb->data;
	int err = 0;
	int err = 0;


	clear_bit(NCI_DISCOVERY, &ndev->flags);
	atomic_set(&ndev->state, NCI_POLL_ACTIVE);
	set_bit(NCI_POLL_ACTIVE, &ndev->flags);


	ntf.rf_discovery_id = *data++;
	ntf.rf_discovery_id = *data++;
	ntf.rf_interface = *data++;
	ntf.rf_interface = *data++;
@@ -350,7 +349,7 @@ static void nci_rf_deactivate_ntf_packet(struct nci_dev *ndev,


	pr_debug("entry, type 0x%x, reason 0x%x\n", ntf->type, ntf->reason);
	pr_debug("entry, type 0x%x, reason 0x%x\n", ntf->type, ntf->reason);


	clear_bit(NCI_POLL_ACTIVE, &ndev->flags);
	atomic_set(&ndev->state, NCI_IDLE);
	ndev->target_active_prot = 0;
	ndev->target_active_prot = 0;


	/* drop tx data queue */
	/* drop tx data queue */
+4 −4
Original line number Original line Diff line number Diff line
@@ -137,7 +137,7 @@ static void nci_rf_disc_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
	pr_debug("status 0x%x\n", status);
	pr_debug("status 0x%x\n", status);


	if (status == NCI_STATUS_OK)
	if (status == NCI_STATUS_OK)
		set_bit(NCI_DISCOVERY, &ndev->flags);
		atomic_set(&ndev->state, NCI_DISCOVERY);


	nci_req_complete(ndev, status);
	nci_req_complete(ndev, status);
}
}
@@ -149,13 +149,13 @@ static void nci_rf_deactivate_rsp_packet(struct nci_dev *ndev,


	pr_debug("status 0x%x\n", status);
	pr_debug("status 0x%x\n", status);


	clear_bit(NCI_DISCOVERY, &ndev->flags);

	/* If target was active, complete the request only in deactivate_ntf */
	/* If target was active, complete the request only in deactivate_ntf */
	if ((status != NCI_STATUS_OK) ||
	if ((status != NCI_STATUS_OK) ||
		(!test_bit(NCI_POLL_ACTIVE, &ndev->flags)))
		(atomic_read(&ndev->state) != NCI_POLL_ACTIVE)) {
		atomic_set(&ndev->state, NCI_IDLE);
		nci_req_complete(ndev, status);
		nci_req_complete(ndev, status);
	}
	}
}


void nci_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
void nci_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
{
{