All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christophe Ricard <christophe.ricard-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: sameo-VuQAYsv1563Yd54FQh9/CA@public.gmane.org
Cc: linux-nfc-hn68Rpc1hR1g9hUCZPvPmw@public.gmane.org,
	christophe.ricard-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	christophe-h.ricard-qxv4g6HH51o@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH v1 06/34] NFC: hci: Add pipes table to reference them with a tuple {gate, host}
Date: Mon,  8 Dec 2014 22:08:11 +0100	[thread overview]
Message-ID: <1418072919-10535-7-git-send-email-christophe-h.ricard@st.com> (raw)
In-Reply-To: <1418072919-10535-1-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>

In order to keep host source information on specific hci event (such as
evt_connectivity or evt_transaction) and because 2 pipes can be connected
to the same gate, it is necessary to add a table referencing every pipe
with a {gate, host} tuple.

Signed-off-by: Christophe Ricard <christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
---
 include/net/nfc/hci.h | 15 +++++++++++++--
 net/nfc/hci/command.c |  6 ++++--
 net/nfc/hci/core.c    | 35 ++++++++++++++++++++++++++++++-----
 3 files changed, 47 insertions(+), 9 deletions(-)

diff --git a/include/net/nfc/hci.h b/include/net/nfc/hci.h
index 031c0be..c1c644b 100644
--- a/include/net/nfc/hci.h
+++ b/include/net/nfc/hci.h
@@ -63,17 +63,25 @@ struct nfc_hci_ops {
 };
 
 /* Pipes */
-#define NFC_HCI_INVALID_PIPE	0x80
 #define NFC_HCI_DO_NOT_CREATE_PIPE	0x81
+#define NFC_HCI_INVALID_PIPE	0x80
+#define NFC_HCI_INVALID_GATE	0xFF
+#define NFC_HCI_INVALID_HOST	0x80
 #define NFC_HCI_LINK_MGMT_PIPE	0x00
 #define NFC_HCI_ADMIN_PIPE	0x01
 
 struct nfc_hci_gate {
 	u8 gate;
 	u8 pipe;
-};
+} __packed;
+
+struct nfc_hci_pipe {
+	u8 gate;
+	u8 dest_host;
+} __packed;
 
 #define NFC_HCI_MAX_CUSTOM_GATES	50
+#define NFC_HCI_MAX_PIPES		127
 struct nfc_hci_init_data {
 	u8 gate_count;
 	struct nfc_hci_gate gates[NFC_HCI_MAX_CUSTOM_GATES];
@@ -125,6 +133,7 @@ struct nfc_hci_dev {
 	void *clientdata;
 
 	u8 gate2pipe[NFC_HCI_MAX_GATES];
+	struct nfc_hci_pipe pipes[NFC_HCI_MAX_PIPES];
 
 	u8 sw_romlib;
 	u8 sw_patch;
@@ -167,6 +176,8 @@ void *nfc_hci_get_clientdata(struct nfc_hci_dev *hdev);
 void nfc_hci_driver_failure(struct nfc_hci_dev *hdev, int err);
 
 int nfc_hci_result_to_errno(u8 result);
+void nfc_hci_reset_pipes(struct nfc_hci_dev *dev);
+void nfc_hci_reset_pipes_per_host(struct nfc_hci_dev *hdev, u8 host);
 
 /* Host IDs */
 #define NFC_HCI_HOST_CONTROLLER_ID	0x00
diff --git a/net/nfc/hci/command.c b/net/nfc/hci/command.c
index 91df487..9acf586 100644
--- a/net/nfc/hci/command.c
+++ b/net/nfc/hci/command.c
@@ -331,7 +331,7 @@ int nfc_hci_disconnect_all_gates(struct nfc_hci_dev *hdev)
 	if (r < 0)
 		return r;
 
-	memset(hdev->gate2pipe, NFC_HCI_INVALID_PIPE, sizeof(hdev->gate2pipe));
+	nfc_hci_reset_pipes(hdev);
 
 	return 0;
 }
@@ -345,7 +345,7 @@ int nfc_hci_connect_gate(struct nfc_hci_dev *hdev, u8 dest_host, u8 dest_gate,
 
 	pr_debug("\n");
 
-	if (hdev->gate2pipe[dest_gate] == NFC_HCI_DO_NOT_CREATE_PIPE)
+	if (pipe == NFC_HCI_DO_NOT_CREATE_PIPE)
 		return 0;
 
 	if (hdev->gate2pipe[dest_gate] != NFC_HCI_INVALID_PIPE)
@@ -380,6 +380,8 @@ open_pipe:
 		return r;
 	}
 
+	hdev->pipes[pipe].gate = dest_gate;
+	hdev->pipes[pipe].dest_host = dest_host;
 	hdev->gate2pipe[dest_gate] = pipe;
 
 	return 0;
diff --git a/net/nfc/hci/core.c b/net/nfc/hci/core.c
index 12a9a4b..88af43a 100644
--- a/net/nfc/hci/core.c
+++ b/net/nfc/hci/core.c
@@ -46,6 +46,31 @@ int nfc_hci_result_to_errno(u8 result)
 }
 EXPORT_SYMBOL(nfc_hci_result_to_errno);
 
+void nfc_hci_reset_pipes(struct nfc_hci_dev *hdev)
+{
+	int i = 0;
+
+	for (i = 0; i < NFC_HCI_MAX_PIPES; i++) {
+		hdev->pipes[i].gate = NFC_HCI_INVALID_GATE;
+		hdev->pipes[i].dest_host = NFC_HCI_INVALID_HOST;
+	}
+	memset(hdev->gate2pipe, NFC_HCI_INVALID_PIPE, sizeof(hdev->gate2pipe));
+}
+EXPORT_SYMBOL(nfc_hci_reset_pipes);
+
+void nfc_hci_reset_pipes_per_host(struct nfc_hci_dev *hdev, u8 host)
+{
+	int i = 0;
+
+	for (i = 0; i < NFC_HCI_MAX_PIPES; i++) {
+		if (hdev->pipes[i].dest_host == host) {
+			hdev->pipes[i].gate = NFC_HCI_INVALID_GATE;
+			hdev->pipes[i].dest_host = NFC_HCI_INVALID_HOST;
+		}
+	}
+}
+EXPORT_SYMBOL(nfc_hci_reset_pipes_per_host);
+
 static void nfc_hci_msg_tx_work(struct work_struct *work)
 {
 	struct nfc_hci_dev *hdev = container_of(work, struct nfc_hci_dev,
@@ -168,7 +193,7 @@ void nfc_hci_cmd_received(struct nfc_hci_dev *hdev, u8 pipe, u8 cmd,
 			  struct sk_buff *skb)
 {
 	int r = 0;
-	u8 gate = nfc_hci_pipe2gate(hdev, pipe);
+	u8 gate = hdev->pipes[pipe].gate;
 	u8 local_gate, new_pipe;
 	u8 gate_opened = 0x00;
 
@@ -330,9 +355,9 @@ void nfc_hci_event_received(struct nfc_hci_dev *hdev, u8 pipe, u8 event,
 			    struct sk_buff *skb)
 {
 	int r = 0;
-	u8 gate = nfc_hci_pipe2gate(hdev, pipe);
+	u8 gate = hdev->pipes[pipe].gate;
 
-	if (gate == 0xff) {
+	if (gate == NFC_HCI_INVALID_GATE) {
 		pr_err("Discarded event %x to unopened pipe %x\n", event, pipe);
 		goto exit;
 	}
@@ -573,7 +598,7 @@ static int hci_dev_down(struct nfc_dev *nfc_dev)
 	if (hdev->ops->close)
 		hdev->ops->close(hdev);
 
-	memset(hdev->gate2pipe, NFC_HCI_INVALID_PIPE, sizeof(hdev->gate2pipe));
+	nfc_hci_reset_pipes(hdev);
 
 	return 0;
 }
@@ -932,7 +957,7 @@ struct nfc_hci_dev *nfc_hci_allocate_device(struct nfc_hci_ops *ops,
 
 	nfc_set_drvdata(hdev->ndev, hdev);
 
-	memset(hdev->gate2pipe, NFC_HCI_INVALID_PIPE, sizeof(hdev->gate2pipe));
+	nfc_hci_reset_pipes(hdev);
 
 	hdev->quirks = quirks;
 
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2014-12-08 21:08 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-08 21:08 [PATCH v1 00/34] Minor clean & Secure Element support for ST21NFCA/ST21NFCB Christophe Ricard
     [not found] ` <1418072919-10535-1-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2014-12-08 21:08   ` [PATCH v1 01/34] NFC: dts: st21nfca: Fix compatible string spelling to follow other drivers Christophe Ricard
2014-12-08 21:08   ` [PATCH v1 02/34] NFC: dts: st21nfcb: " Christophe Ricard
2014-12-08 21:08   ` [PATCH v1 03/34] NFC: st21nfcb: Fix "WARNING: invalid free of devm_ allocated data" Christophe Ricard
2014-12-08 21:08   ` [PATCH v1 04/34] NFC: st21nfca: Remove unreachable code Christophe Ricard
     [not found]     ` <1418072919-10535-5-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2015-01-26  1:10       ` Samuel Ortiz
     [not found]         ` <20150126011001.GB28592-41CF7WKNp/FoDWY/xQGDymt3HXsI98Cx0E9HWUfgJXw@public.gmane.org>
2015-01-26 23:07           ` christophe.ricard
2014-12-08 21:08   ` [PATCH v1 05/34] NFC: hci: Change event_received handler gate parameter to pipe Christophe Ricard
     [not found]     ` <1418072919-10535-6-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2015-01-26  1:10       ` Samuel Ortiz
2014-12-08 21:08   ` Christophe Ricard [this message]
     [not found]     ` <1418072919-10535-7-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2015-01-26  1:11       ` [PATCH v1 06/34] NFC: hci: Add pipes table to reference them with a tuple {gate, host} Samuel Ortiz
2014-12-08 21:08   ` [PATCH v1 07/34] NFC: hci: Change nfc_hci_send_response gate parameter to pipe Christophe Ricard
     [not found]     ` <1418072919-10535-8-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2015-01-26  1:11       ` Samuel Ortiz
2014-12-08 21:08   ` [PATCH v1 08/34] NFC: hci: Reference every pipe information according to notification Christophe Ricard
     [not found]     ` <1418072919-10535-9-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2015-01-26  1:11       ` Samuel Ortiz
2014-12-08 21:08   ` [PATCH v1 09/34] NFC: hci: Add cmd_received handler Christophe Ricard
2014-12-08 21:08   ` [PATCH v1 10/34] NFC: pn544: Change event_received gate parameter to pipe Christophe Ricard
2014-12-08 21:08   ` [PATCH v1 11/34] NFC: microread: " Christophe Ricard
2014-12-08 21:08   ` [PATCH v1 12/34] NFC: hci: Remove nfc_hci_pipe2gate function Christophe Ricard
2014-12-08 21:08   ` [PATCH v1 13/34] NFC: nfc_enable_se Remove useless blank line at beginning of function Christophe Ricard
2014-12-08 21:08   ` [PATCH v1 14/34] NFC: nfc_disable_se " Christophe Ricard
2014-12-08 21:08   ` [PATCH v1 15/34] NFC: st21nfca: Adding support for secure element Christophe Ricard
2014-12-08 21:08   ` [PATCH v1 16/34] NFC: st21nfca: Remove useless ST21NFCA_SE_HOST_EVT_HOT_PLUG macro Christophe Ricard
2014-12-08 21:08   ` [PATCH v1 17/34] NFC: st21nfca: Remove skb_pipe_list and skb_pipe_info useless allocation Christophe Ricard
2014-12-08 21:08   ` [PATCH v1 18/34] NFC: st21nfca: Remove checkpatch.pl warning Possible unnecessary 'out of memory' message Christophe Ricard
2014-12-08 21:08   ` [PATCH v1 19/34] NFC: dts: st21nfca: Document ese-present & uicc-present DTS property Christophe Ricard
2014-12-08 21:08   ` [PATCH v1 20/34] NFC: nci: Add dynamic conn_id NCI concept Christophe Ricard
     [not found]     ` <1418072919-10535-21-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2015-01-27  0:44       ` Samuel Ortiz
2014-12-08 21:08   ` [PATCH v1 21/34] NFC: nci: Make nci_request available for nfc driver Christophe Ricard
2014-12-08 21:08   ` [PATCH v1 22/34] NFC: nci: Add NCI NFCEE constant Christophe Ricard
2014-12-08 21:08   ` [PATCH v1 23/34] NFC: nci: Add nci_nfcee_discover handler command/response/notification Christophe Ricard
2014-12-08 21:08   ` [PATCH v1 24/34] NFC: nci: Add nci_nfcee_mode_set handler command/response Christophe Ricard
2014-12-08 21:08   ` [PATCH v1 25/34] NFC: nci: Add nci_core_conn_create " Christophe Ricard
2014-12-08 21:08   ` [PATCH v1 26/34] NFC: nci: Add nci_core_conn_close " Christophe Ricard
2014-12-08 21:08   ` [PATCH v1 27/34] NFC: st21nfcb: Add HCI protocol over NCI protocol support Christophe Ricard
     [not found]     ` <1418072919-10535-28-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2015-01-27  0:49       ` Samuel Ortiz
     [not found]         ` <20150127004958.GB31396-41CF7WKNp/FoDWY/xQGDymt3HXsI98Cx0E9HWUfgJXw@public.gmane.org>
2015-01-27 22:16           ` christophe.ricard
     [not found]             ` <54C80E40.7020707-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-01-28  0:04               ` Samuel Ortiz
2014-12-08 21:08   ` [PATCH v1 28/34] NFC: st21nfcb: Adding support for secure element Christophe Ricard
2014-12-08 21:08   ` [PATCH v1 29/34] NFC: Forward NFC_EVT_TRANSACTION up to user space Christophe Ricard
2014-12-08 21:08   ` [PATCH v1 30/34] NFC: nci: Add support RF_NFCEE_ACTION_NTF Christophe Ricard
2014-12-08 21:08   ` [PATCH v1 31/34] NFC: nci: Change NCI state machine to LISTEN_ACTIVE and ignore parameters in rf_intf_activated_ntf Christophe Ricard
2014-12-08 21:08   ` [PATCH v1 32/34] NFC: st21nfcb: Add support for HCI event transaction Christophe Ricard
2014-12-08 21:08   ` [PATCH v1 33/34] NFC: st21nfca: " Christophe Ricard
2014-12-08 21:08   ` [PATCH v1 34/34] NFC: st21nfca: Fix some skb memory leaks Christophe Ricard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1418072919-10535-7-git-send-email-christophe-h.ricard@st.com \
    --to=christophe.ricard-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=christophe-h.ricard-qxv4g6HH51o@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-nfc-hn68Rpc1hR1g9hUCZPvPmw@public.gmane.org \
    --cc=sameo-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.