Skip to contentSkip to conversation

Adds Intel FieldsPeak NFC solution driver

PATCH Superseded Robert Dolca 7 participants 29 messages Feb 24, 2015 – Aug 28, 2015

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Adds Intel FieldsPeak NFC solution driver

This patch adds support for Intel's FieldsPeak NFC solution. The device is enumerated with ACPI and platform init.

In order to implement the driver the nci_core_conn_create was modified in order to report the ID of the newly created connection. Fixed a bug that prevented to close a connection from the driver while the dev was down.

The max packet size of a connection can be retrieved by the driver.

The init, reset NCI functions can be called from the driver. The driver can also send command to the device using the NFC subsystem using the request - response blocking method.

Robert Dolca (8):
NFC: NCI: Allow connection close with dev down
NFC: NCI: Exporting NFC command and data send API
NFC: NCI: Adds NCI init and reset API for drivers
NFC: NCI: Add a special nci_request for driver
NFC: NCI: Don't call setup if previous NCI request failed
NFC: NCI: Add function to get max packet size for conn
NFC: NCI: Adds a way to get the new connection ID
NFC: Add Intel FieldsPeak NFC solution driver

 drivers/nfc/Kconfig                |   1 +
 drivers/nfc/fdp/Kconfig            |  22 ++
 drivers/nfc/fdp/Makefile           |  10 +
 drivers/nfc/fdp/cmd.c              | 196 +++++++++++++++
 drivers/nfc/fdp/core.c             | 503 +++++++++++++++++++++++++++++++++++++
 drivers/nfc/fdp/fdp.h              | 115 +++++++++
 drivers/nfc/fdp/i2c.c              | 454 +++++++++++++++++++++++++++++++++
 drivers/nfc/fdp/ntf.c              |  68 +++++
 drivers/nfc/fdp/rsp.c              | 117 +++++++++
 drivers/nfc/st21nfcb/st21nfcb_se.c |   2 +-
 include/linux/platform_data/fdp.h  |  33 +++
 include/net/nfc/nci_core.h         |  18 +-
 net/nfc/nci/core.c                 |  53 +++-
 net/nfc/nci/data.c                 |  13 +
 net/nfc/nci/rsp.c                  |   6 +
 15 files changed, 1601 insertions(+), 10 deletions(-)
 create mode 100644 drivers/nfc/fdp/Kconfig
 create mode 100644 drivers/nfc/fdp/Makefile
 create mode 100644 drivers/nfc/fdp/cmd.c
 create mode 100644 drivers/nfc/fdp/core.c
 create mode 100644 drivers/nfc/fdp/fdp.h
 create mode 100644 drivers/nfc/fdp/i2c.c
 create mode 100644 drivers/nfc/fdp/ntf.c
 create mode 100644 drivers/nfc/fdp/rsp.c
 create mode 100644 include/linux/platform_data/fdp.h
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/8 NFC: NCI: Allow connection close with dev down

By calling __nci_request instead of nci_request allows the driver to use the function while initializing the device (setup stage)

---
 net/nfc/nci/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/nfc/nci/core.c +1 -1
index 9575a18..c4dd5d8 100644
@@ -558,7 +558,7 @@ static void nci_core_conn_close_req(struct nci_dev *ndev, unsigned long opt)
 
 int nci_core_conn_close(struct nci_dev *ndev, u8 conn_id)
 {
-	return nci_request(ndev, nci_core_conn_close_req, conn_id,
+	return __nci_request(ndev, nci_core_conn_close_req, conn_id,
 				msecs_to_jiffies(NCI_CMD_TIMEOUT));
 }
 EXPORT_SYMBOL(nci_core_conn_close);
Signature · 1 line
1.9.1
#7 lore raw

PATCH 3/8 NFC: NCI: Adds NCI init and reset API for drivers

In reply to Robert Dolca

In order to communicate with the device during the setup phase, the driver may need to initialize the device. After the setup is done the driver should reset the device to leave it in the same state that it was before the setup function call.

---
 include/net/nfc/nci_core.h |  2 ++
 net/nfc/nci/core.c         | 14 ++++++++++++++
 2 files changed, 16 insertions(+)
include/net/nfc/nci_core.h +2 -0
index 34a6e09..4358d0a 100644
@@ -314,6 +314,8 @@ static inline void *nci_get_drvdata(struct nci_dev *ndev)
 	return ndev->driver_data;
 }
 
+int nci_init(struct nci_dev *ndev);
+int nci_reset(struct nci_dev *ndev);
 void nci_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb);
 void nci_ntf_packet(struct nci_dev *ndev, struct sk_buff *skb);
 void nci_rx_data_packet(struct nci_dev *ndev, struct sk_buff *skb);
net/nfc/nci/core.c +14 -0
index 9605b9c..317b94b 100644
@@ -458,6 +458,20 @@ static int nci_dev_down(struct nfc_dev *nfc_dev)
 	return nci_close_device(ndev);
 }
 
+int nci_init(struct nci_dev *ndev)
+{
+	return __nci_request(ndev, nci_init_req, 0,
+			  msecs_to_jiffies(NCI_INIT_TIMEOUT));
+}
+EXPORT_SYMBOL(nci_init);
+
+int nci_reset(struct nci_dev *ndev)
+{
+	return __nci_request(ndev, nci_reset_req, 0,
+			     msecs_to_jiffies(NCI_RESET_TIMEOUT));
+}
+EXPORT_SYMBOL(nci_reset);
+
 int nci_set_config(struct nci_dev *ndev, __u8 id, size_t len, __u8 *val)
 {
 	struct nci_set_config_param param;
Signature · 1 line
1.9.1
#11 lore raw

PATCH 4/8 NFC: NCI: Add a special nci_request for driver

In reply to Robert Dolca

This patch adds nci_request_driver and nci_req_complete_driver as a wrapper for __nci_request. When nci_req_complete_driver is called it also sets cmd_cnt to 1. This is done because the response is not sent to the NFC subsystem so cmd_cnt is not decremented there.

nci_send_cmd was previously exported in order to send commands to the device from the driver. It shouldn't be used without nci_req_complete_driver because cmd_cnt will have the wrong value.

---
 include/net/nfc/nci_core.h |  4 ++++
 net/nfc/nci/core.c         | 19 +++++++++++++++++++
 2 files changed, 23 insertions(+)
include/net/nfc/nci_core.h +4 -0
index 4358d0a..42ec342 100644
@@ -333,6 +333,10 @@ void nci_clear_target_list(struct nci_dev *ndev);
 #define NCI_REQ_CANCELED	2
 
 void nci_req_complete(struct nci_dev *ndev, int result);
+int nci_request_driver(struct nci_dev *ndev,
+		       void (*req)(struct nci_dev *ndev, unsigned long opt),
+		       unsigned long opt, __u32 timeout);
+void nci_req_complete_driver(struct nci_dev *ndev, int result);
 struct nci_conn_info *nci_get_conn_info_by_conn_id(struct nci_dev *ndev,
 						   int conn_id);
 
net/nfc/nci/core.c +19 -0
index 317b94b..1a449ac 100644
@@ -74,6 +74,17 @@ void nci_req_complete(struct nci_dev *ndev, int result)
 	}
 }
 
+void nci_req_complete_driver(struct nci_dev *ndev, int result)
+{
+	nci_req_complete(ndev, result);
+
+	/* trigger the next cmd */
+	atomic_set(&ndev->cmd_cnt, 1);
+	if (!skb_queue_empty(&ndev->cmd_q))
+		queue_work(ndev->cmd_wq, &ndev->cmd_work);
+}
+EXPORT_SYMBOL(nci_req_complete_driver);
+
 static void nci_req_cancel(struct nci_dev *ndev, int err)
 {
 	if (ndev->req_status == NCI_REQ_PEND) {
@@ -127,6 +138,14 @@ static int __nci_request(struct nci_dev *ndev,
 	return rc;
 }
 
+int nci_request_driver(struct nci_dev *ndev,
+		       void (*req)(struct nci_dev *ndev, unsigned long opt),
+		       unsigned long opt, __u32 timeout)
+{
+	return __nci_request(ndev, req, opt, timeout);
+}
+EXPORT_SYMBOL(nci_request_driver);
+
 inline int nci_request(struct nci_dev *ndev,
 		       void (*req)(struct nci_dev *ndev,
 				   unsigned long opt),
Signature · 1 line
1.9.1
#14 lore raw

PATCH 5/8 NFC: NCI: Don't call setup if previous NCI request failed

In reply to Robert Dolca

If the previous nci_request (NCI reset) failed the setup function was being called anyway. It shouldn't be called if the reset failed.

The result of the setup function is taken into consideration. If it fails the init should fail.

---
 net/nfc/nci/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/nfc/nci/core.c +2 -2
index 1a449ac..d2e7adf 100644
@@ -365,8 +365,8 @@ static int nci_open_device(struct nci_dev *ndev)
 	rc = __nci_request(ndev, nci_reset_req, 0,
 			   msecs_to_jiffies(NCI_RESET_TIMEOUT));
 
-	if (ndev->ops->setup)
-		ndev->ops->setup(ndev);
+	if (!rc && ndev->ops->setup)
+		rc = ndev->ops->setup(ndev);
 
 	if (!rc) {
 		rc = __nci_request(ndev, nci_init_req, 0,
Signature · 1 line
1.9.1
#16 lore raw

PATCH 6/8 NFC: NCI: Add function to get max packet size for conn

In reply to Robert Dolca

FDP driver needs to send the firmware as regular packets (not fragmented). That's whay the driver should have a way to get the max packet size for a given connection.

---
 include/net/nfc/nci_core.h |  1 +
 net/nfc/nci/data.c         | 12 ++++++++++++
 2 files changed, 13 insertions(+)
include/net/nfc/nci_core.h +1 -0
index 42ec342..d79f90e 100644
@@ -321,6 +321,7 @@ void nci_ntf_packet(struct nci_dev *ndev, struct sk_buff *skb);
 void nci_rx_data_packet(struct nci_dev *ndev, struct sk_buff *skb);
 int nci_send_cmd(struct nci_dev *ndev, __u16 opcode, __u8 plen, void *payload);
 int nci_send_data(struct nci_dev *ndev, __u8 conn_id, struct sk_buff *skb);
+__u8 nci_conn_max_data_pkt_payload_size(struct nci_dev *ndev, __u8 conn_id);
 void nci_data_exchange_complete(struct nci_dev *ndev, struct sk_buff *skb,
 				__u8 conn_id, int err);
 void nci_hci_data_received_cb(void *context, struct sk_buff *skb, int err);
net/nfc/nci/data.c +12 -0
index 83acd18..056f841 100644
@@ -90,6 +90,18 @@ static inline void nci_push_data_hdr(struct nci_dev *ndev,
 	nci_pbf_set((__u8 *)hdr, pbf);
 }
 
+__u8 nci_conn_max_data_pkt_payload_size(struct nci_dev *ndev, __u8 conn_id)
+{
+	struct nci_conn_info *conn_info;
+
+	conn_info = nci_get_conn_info_by_conn_id(ndev, conn_id);
+	if (!conn_info)
+		return 0;
+
+	return conn_info->max_pkt_payload_len;
+}
+EXPORT_SYMBOL(nci_conn_max_data_pkt_payload_size);
+
 static int nci_queue_tx_data_frags(struct nci_dev *ndev,
 				   __u8 conn_id,
 				   struct sk_buff *skb) {
Signature · 1 line
1.9.1
#17 lore raw

PATCH 7/8 NFC: NCI: Adds a way to get the new connection ID

In reply to Robert Dolca

nci_core_conn_create not has a new parameter so it can return the ID of the new connection. Also not you can't call nci_core_conn_create without waiting the answer for the previous call.

---
 drivers/nfc/st21nfcb/st21nfcb_se.c |  2 +-
 include/net/nfc/nci_core.h         | 11 ++++++++---
 net/nfc/nci/core.c                 | 13 ++++++++++---
 net/nfc/nci/rsp.c                  |  6 ++++++
 4 files changed, 25 insertions(+), 7 deletions(-)
drivers/nfc/st21nfcb/st21nfcb_se.c +1 -1
index 7c82e9d..8694675 100644
@@ -515,7 +515,7 @@ static int st21nfcb_hci_network_init(struct nci_dev *ndev)
 	r = nci_core_conn_create(ndev, NCI_DESTINATION_NFCEE, 1,
 				 sizeof(struct core_conn_create_dest_spec_params) +
 				 sizeof(struct dest_spec_params),
-				 dest_params);
+				 dest_params, NULL);
 	if (r != NCI_STATUS_OK)
 		goto free_dest_params;
 
include/net/nfc/nci_core.h +8 -3
index d79f90e..a331755 100644
@@ -240,6 +240,11 @@ struct nci_dev {
 	/* Save RF Discovery ID or NFCEE ID under conn_create */
 	__u8			cur_id;
 
+	/* Pointer to the address where the next connection ID
+	 * will be stored */
+	__u8			*next_conn_id;
+	__u8			conn_busy;
+
 	/* stored during nci_data_exchange */
 	struct sk_buff		*rx_data_reassembly;
 
@@ -266,9 +271,9 @@ int nci_set_config(struct nci_dev *ndev, __u8 id, size_t len, __u8 *val);
 int nci_nfcee_discover(struct nci_dev *ndev, u8 action);
 int nci_nfcee_mode_set(struct nci_dev *ndev, u8 nfcee_id, u8 nfcee_mode);
 int nci_core_conn_create(struct nci_dev *ndev, u8 destination_type,
-			 u8 number_destination_params,
-			 size_t params_len,
-			 struct core_conn_create_dest_spec_params *params);
+			 u8 number_destination_params, size_t params_len,
+			 struct core_conn_create_dest_spec_params *params,
+			 u8 *conn_id);
 int nci_core_conn_close(struct nci_dev *ndev, u8 conn_id);
 
 struct nci_hci_dev *nci_hci_allocate(struct nci_dev *ndev);
net/nfc/nci/core.c +10 -3
index d2e7adf..aaa56f1 100644
@@ -554,14 +554,19 @@ static void nci_core_conn_create_req(struct nci_dev *ndev, unsigned long opt)
 }
 
 int nci_core_conn_create(struct nci_dev *ndev, u8 destination_type,
-			 u8 number_destination_params,
-			 size_t params_len,
-			 struct core_conn_create_dest_spec_params *params)
+			 u8 number_destination_params, size_t params_len,
+			 struct core_conn_create_dest_spec_params *params,
+			 u8 *conn_id)
 {
 	int r;
 	struct nci_core_conn_create_cmd *cmd;
 	struct core_conn_create_data data;
 
+	if (ndev->conn_busy)
+		return -EBUSY;
+
+	ndev->conn_busy = 1;
+
 	data.length = params_len + sizeof(struct nci_core_conn_create_cmd);
 	cmd = kzalloc(data.length, GFP_KERNEL);
 	if (!cmd)
@@ -573,11 +578,13 @@ int nci_core_conn_create(struct nci_dev *ndev, u8 destination_type,
 
 	data.cmd = cmd;
 	ndev->cur_id = params->value[DEST_SPEC_PARAMS_ID_INDEX];
+	ndev->next_conn_id = conn_id;
 
 	r = __nci_request(ndev, nci_core_conn_create_req,
 			  (unsigned long)&data,
 			  msecs_to_jiffies(NCI_CMD_TIMEOUT));
 	kfree(cmd);
+	ndev->conn_busy = 0;
 	return r;
 }
 EXPORT_SYMBOL(nci_core_conn_create);
net/nfc/nci/rsp.c +6 -0
index 02486bc..9aa9de2 100644
@@ -244,6 +244,12 @@ static void nci_core_conn_create_rsp_packet(struct nci_dev *ndev,
 		conn_info->id = ndev->cur_id;
 		conn_info->conn_id = rsp->conn_id;
 
+		/* Set the conn ID to the address provided by the caller */
+		if (ndev->next_conn_id) {
+			*ndev->next_conn_id = rsp->conn_id;
+			ndev->next_conn_id = NULL;
+		}
+
 		/* Note: data_exchange_cb and data_exchange_cb_context need to
 		 * be specify out of nci_core_conn_create_rsp_packet
 		 */
Signature · 1 line
1.9.1
#18 lore raw

PATCH 8/8 NFC: Add Intel FieldsPeak NFC solution driver

In reply to Robert Dolca

The device can be enumerated using ACPI using the id INT339A. The 1st GPIO is the IRQ and the 2nd is the RESET pin. I can be also enumerated using platform init.

---
 drivers/nfc/Kconfig               |   1 +
 drivers/nfc/fdp/Kconfig           |  22 ++
 drivers/nfc/fdp/Makefile          |  10 +
 drivers/nfc/fdp/cmd.c             | 196 +++++++++++++++
 drivers/nfc/fdp/core.c            | 503 ++++++++++++++++++++++++++++++++++++++
 drivers/nfc/fdp/fdp.h             | 115 +++++++++
 drivers/nfc/fdp/i2c.c             | 454 ++++++++++++++++++++++++++++++++++
 drivers/nfc/fdp/ntf.c             |  68 ++++++
 drivers/nfc/fdp/rsp.c             | 117 +++++++++
 include/linux/platform_data/fdp.h |  33 +++
 10 files changed, 1519 insertions(+)
 create mode 100644 drivers/nfc/fdp/Kconfig
 create mode 100644 drivers/nfc/fdp/Makefile
 create mode 100644 drivers/nfc/fdp/cmd.c
 create mode 100644 drivers/nfc/fdp/core.c
 create mode 100644 drivers/nfc/fdp/fdp.h
 create mode 100644 drivers/nfc/fdp/i2c.c
 create mode 100644 drivers/nfc/fdp/ntf.c
 create mode 100644 drivers/nfc/fdp/rsp.c
 create mode 100644 include/linux/platform_data/fdp.h
drivers/nfc/Kconfig +1 -0
index 6ee2e8d..302fe59 100644
@@ -68,6 +68,7 @@ config NFC_PORT100
 
 	  If unsure, say N.
 
+source "drivers/nfc/fdp/Kconfig"
 source "drivers/nfc/pn544/Kconfig"
 source "drivers/nfc/microread/Kconfig"
 source "drivers/nfc/nfcmrvl/Kconfig"
drivers/nfc/fdp/Kconfig new file +22 -0
new file mode 100644
index 0000000..130a235
@@ -0,0 +1,22 @@
+config NFC_FDP
+	tristate "Intel FDP NFC driver"
+	depends on NFC_NCI
+	select CRC_CCITT
+	default n
+	---help---
+	  Intel FDP core driver.
+	  This is a driver based on the NCI NFC kernel layers.
+
+	  To compile this driver as a module, choose m here. The module will
+	  be called pn547.
+	  Say N if unsure.
+
+config NFC_FDP_I2C
+	tristate "NFC FDP i2c support"
+	depends on NFC_FDP && I2C
+	---help---
+	  This module adds support for the Intel FDP i2c interface.
+	  Select this if your platform is using the i2c bus.
+
+	  If you choose to build a module, it'll be called fdp_i2c.
+	  Say N if unsure.
drivers/nfc/fdp/Makefile new file +10 -0
new file mode 100644
index 0000000..caad636
@@ -0,0 +1,10 @@
+#
+# Makefile for FDP NCI based NFC driver
+#
+
+obj-$(CONFIG_NFC_FDP)     += fdp.o
+obj-$(CONFIG_NFC_FDP_I2C) += fdp_i2c.o
+
+fdp-objs = core.o cmd.o ntf.o rsp.o
+fdp_i2c-objs  = i2c.o
+
drivers/nfc/fdp/cmd.c new file +196 -0

196 lines not on this page · raw message

drivers/nfc/fdp/core.c new file +503 -0

503 lines not on this page · raw message

drivers/nfc/fdp/fdp.h new file +115 -0

115 lines not on this page · raw message

drivers/nfc/fdp/i2c.c new file +454 -0

454 lines not on this page · raw message

drivers/nfc/fdp/ntf.c new file +68 -0

68 lines not on this page · raw message

drivers/nfc/fdp/rsp.c new file +117 -0

117 lines not on this page · raw message

include/linux/platform_data/fdp.h new file +33 -0
new file mode 100644
index 0000000..5a77095
@@ -0,0 +1,33 @@
+/* -------------------------------------------------------------------------
+ * Copyright (C) 2014-2016, Intel Corporation
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ * ------------------------------------------------------------------------- */
+
+
+#ifndef _FDP_H_
+#define _FDP_H_
+
+#include <linux/i2c.h>
+
+enum {
+	NFC_GPIO_ENABLE,
+	NFC_GPIO_IRQ,
+};
+
+/* board config */
+struct fdp_nfc_platform_data {
+	int (*request_resources)(struct i2c_client *client);
+	void (*free_resources)(void);
+	int (*get_gpio)(int type);
+};
+
+#endif /* _FDP_H_ */
Signature · 1 line
1.9.1
#6 lore raw

PATCH 2/8 NFC: NCI: Exporting NFC command and data send API

In reply to Robert Dolca

nci_send_cmd was exported in order to send commands to the device from the driver. For the firmware update the driver may use nci_send_data.

---
 net/nfc/nci/core.c | 1 +
 net/nfc/nci/data.c | 1 +
 2 files changed, 2 insertions(+)
net/nfc/nci/core.c +1 -0
index c4dd5d8..9605b9c 100644
@@ -1153,6 +1153,7 @@ int nci_send_cmd(struct nci_dev *ndev, __u16 opcode, __u8 plen, void *payload)
 
 	return 0;
 }
+EXPORT_SYMBOL(nci_send_cmd);
 
 /* ---- NCI TX Data worker thread ---- */
 
net/nfc/nci/data.c +1 -0
index 566466d..83acd18 100644
@@ -203,6 +203,7 @@ free_exit:
 exit:
 	return rc;
 }
+EXPORT_SYMBOL(nci_send_data);
 
 /* ----------------- NCI RX Data ----------------- */
 
Signature · 1 line
1.9.1
#19 lore raw

Re: [PATCH 8/8] NFC: Add Intel FieldsPeak NFC solution driver

In reply to Robert Dolca

I have no idea about NFC, but

drivers/nfc/fdp/Kconfig line 11

Quoted 11 lines
drivers/nfc/fdp/Kconfig new file +11 -0
+config NFC_FDP
+	tristate "Intel FDP NFC driver"
+	depends on NFC_NCI
+	select CRC_CCITT
+	default n
+	---help---
+	  Intel FDP core driver.
+	  This is a driver based on the NCI NFC kernel layers.
+
+	  To compile this driver as a module, choose m here. The module will
+	  be called pn547.

this seems like a copy/paste error? Certainly it's called fdp?

johannes

#20 lore raw

Re: [PATCH 8/8] NFC: Add Intel FieldsPeak NFC solution driver

Quoted 5 lines · Johannes Berg
Quoted 5 lines
drivers/nfc/fdp/Kconfig new file +5 -0
+config NFC_FDP
+	tristate "Intel FDP NFC driver"
+	depends on NFC_NCI
+	select CRC_CCITT
+	default n
Quoted 8 lines

drivers/nfc/fdp/Kconfig line 11

Quoted 6 lines
drivers/nfc/fdp/Kconfig new file +6 -0
+	---help---
+	  Intel FDP core driver.
+	  This is a driver based on the NCI NFC kernel layers.
+
+	  To compile this driver as a module, choose m here. The module will
+	  be called pn547.

this seems like a copy/paste error? Certainly it's called fdp?

You are right. It should be FDP instead of pn547.

I will also rename the menu entry name from "Intel FDP NFC driver" to "Intel FieldsPeak (FDP) NFC driver" to be more clear what FDP means.

Thanks,
Robert

#26 lore raw
In reply to Robert Dolca

I'm excited - what's NFC?

- Greg

Quoted 57 lines · Robert Dolca

This patch adds support for Intel's FieldsPeak NFC solution. The device is enumerated with ACPI and platform init.

In order to implement the driver the nci_core_conn_create was modified in order to report the ID of the newly created connection. Fixed a bug that prevented to close a connection from the driver while the dev was down.

The max packet size of a connection can be retrieved by the driver.

The init, reset NCI functions can be called from the driver. The driver can also send command to the device using the NFC subsystem using the request - response blocking method.

Robert Dolca (8):
NFC: NCI: Allow connection close with dev down
NFC: NCI: Exporting NFC command and data send API
NFC: NCI: Adds NCI init and reset API for drivers
NFC: NCI: Add a special nci_request for driver
NFC: NCI: Don't call setup if previous NCI request failed
NFC: NCI: Add function to get max packet size for conn
NFC: NCI: Adds a way to get the new connection ID
NFC: Add Intel FieldsPeak NFC solution driver

 drivers/nfc/Kconfig                |   1 +
 drivers/nfc/fdp/Kconfig            |  22 ++
 drivers/nfc/fdp/Makefile           |  10 +
 drivers/nfc/fdp/cmd.c              | 196 +++++++++++++++
 drivers/nfc/fdp/core.c             | 503 +++++++++++++++++++++++++++++++++++++
 drivers/nfc/fdp/fdp.h              | 115 +++++++++
 drivers/nfc/fdp/i2c.c              | 454 +++++++++++++++++++++++++++++++++
 drivers/nfc/fdp/ntf.c              |  68 +++++
 drivers/nfc/fdp/rsp.c              | 117 +++++++++
 drivers/nfc/st21nfcb/st21nfcb_se.c |   2 +-
 include/linux/platform_data/fdp.h  |  33 +++
 include/net/nfc/nci_core.h         |  18 +-
 net/nfc/nci/core.c                 |  53 +++-
 net/nfc/nci/data.c                 |  13 +
 net/nfc/nci/rsp.c                  |   6 +
 15 files changed, 1601 insertions(+), 10 deletions(-)
 create mode 100644 drivers/nfc/fdp/Kconfig
 create mode 100644 drivers/nfc/fdp/Makefile
 create mode 100644 drivers/nfc/fdp/cmd.c
 create mode 100644 drivers/nfc/fdp/core.c
 create mode 100644 drivers/nfc/fdp/fdp.h
 create mode 100644 drivers/nfc/fdp/i2c.c
 create mode 100644 drivers/nfc/fdp/ntf.c
 create mode 100644 drivers/nfc/fdp/rsp.c
 create mode 100644 include/linux/platform_data/fdp.h

--
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw

Re: [PATCH 1/8] NFC: NCI: Allow connection close with dev down

In reply to Robert Dolca

Hi Robert,

Quoted 13 lines · Robert Dolca

By calling __nci_request instead of nci_request allows the driver to use the function while initializing the device (setup stage)

---
 net/nfc/nci/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/nfc/nci/core.c +0 -0
index 9575a18..c4dd5d8 100644

net/nfc/nci/core.c static void nci_core_conn_close_req(struct nci_dev *ndev, unsigned long opt) · line 562

Quoted 6 lines
net/nfc/nci/core.c +1 -1
@@ -558,7 +558,7 @@ static void nci_core_conn_close_req(struct nci_dev *ndev, unsigned long opt)
 
 int nci_core_conn_close(struct nci_dev *ndev, u8 conn_id)
 {
-	return nci_request(ndev, nci_core_conn_close_req, conn_id,
+	return __nci_request(ndev, nci_core_conn_close_req, conn_id,
 				msecs_to_jiffies(NCI_CMD_TIMEOUT));

You're fixing your problem by removing the NCI request serialization and removing the check for your device being UP.
I assume you need to open and close a proprietary connection from your setup hook ? Then please extend nci_request() to check for both NCI_UP and NCI_INIT.

Cheers,
Samuel.

#8 lore raw

Re: [PATCH 3/8] NFC: NCI: Adds NCI init and reset API for drivers

In reply to Robert Dolca

Hi Robert,

Quoted 5 lines · Robert Dolca

In order to communicate with the device during the setup phase, the driver may need to initialize the device. After the setup is done the driver should reset the device to leave it in the same state that it was before the setup function call.

I would prefer not to export those symbols, but instead introduce a quirk bitmap to let the NCI core know that your device expects the core to be initialized before calling the setup ops.
That would be done from nci_open_device().

Cheers,
Samuel.
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#12 lore raw

Re: [PATCH 4/8] NFC: NCI: Add a special nci_request for driver

In reply to Robert Dolca

Hi Robert,

Quoted 8 lines · Robert Dolca

This patch adds nci_request_driver and nci_req_complete_driver as a wrapper for __nci_request. When nci_req_complete_driver is called it also sets cmd_cnt to 1. This is done because the response is not sent to the NFC subsystem so cmd_cnt is not decremented there.

nci_send_cmd was previously exported in order to send commands to the device from the driver. It shouldn't be used without nci_req_complete_driver because cmd_cnt will have the wrong value.

Any NCI packet should make it to the NCI core first, because the logic and synchornization between Tx and Rx, commands and response is implemented there. When exporting this kind of symbols, you're opening a can of worms by potentially allowing each driver to implement the same kind of logic that's already implemented in the NCI core.

The solution I'd like to see implemented is the following one: Add 1 additional nci_ops entry for handling proprietary packets on the Rx path. From your driver perspective, you call nci_recv_frame for each and every packet that you receive: No intercept, no trap. The core will call your proprietary packets handler for each packet (NTF or RSP) with a proprietary GID.
You should then be able to remove all the rx work, rx queue and intercept logic from your driver.

Cheers,
Samuel.
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#15 lore raw

Re: [PATCH 5/8] NFC: NCI: Don't call setup if previous NCI request failed

In reply to Robert Dolca

Hi Robert,

Quoted 16 lines · Robert Dolca

If the previous nci_request (NCI reset) failed the setup function was being called anyway. It shouldn't be called if the reset failed.

The result of the setup function is taken into consideration. If it fails the init should fail.

---
 net/nfc/nci/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/nfc/nci/core.c +0 -0
index 1a449ac..d2e7adf 100644

net/nfc/nci/core.c static int nci_open_device(struct nci_dev *ndev) · line 369

Quoted 7 lines
net/nfc/nci/core.c +2 -2
@@ -365,8 +365,8 @@ static int nci_open_device(struct nci_dev *ndev)
 	rc = __nci_request(ndev, nci_reset_req, 0,
 			   msecs_to_jiffies(NCI_RESET_TIMEOUT));
 
-	if (ndev->ops->setup)
-		ndev->ops->setup(ndev);
+	if (!rc && ndev->ops->setup)
+		rc = ndev->ops->setup(ndev);

That one makes sense.

Cheers,
Samuel.

#21 lore raw

Re: [PATCH 8/8] NFC: Add Intel FieldsPeak NFC solution driver

In reply to Robert Dolca

Hi Robert,

Quoted 1 line · Robert Dolca

The device can be enumerated using ACPI using the id INT339A.

Please give us some more details about the device. NCI ? HCI ? Features ? What does the initial patchset support ?

drivers/nfc/fdp/Kconfig line 7

Quoted 7 lines
drivers/nfc/fdp/Kconfig new file +7 -0
+config NFC_FDP
+	tristate "Intel FDP NFC driver"
+	depends on NFC_NCI
+	select CRC_CCITT
+	default n
+	---help---
+	  Intel FDP core driver.

What's FDP ?

drivers/nfc/fdp/Kconfig line 8

Quoted 1 line
drivers/nfc/fdp/Kconfig new file +1 -0
+	  This is a driver based on the NCI NFC kernel layers.

What does it support ?

drivers/nfc/fdp/Kconfig line 11

Quoted 3 lines
drivers/nfc/fdp/Kconfig new file +3 -0
+
+	  To compile this driver as a module, choose m here. The module will
+	  be called pn547.

pn547, that's a typo.

drivers/nfc/fdp/cmd.c line 25

Quoted 3 lines
drivers/nfc/fdp/cmd.c new file +3 -0
+#define NCI_OP_PROP_PATCH_CMD		     nci_opcode_pack(NCI_GID_PROP, 0x08)
+#define NCI_OP_PROP_SET_PRODUCTION_DATA_CMD  nci_opcode_pack(NCI_GID_PROP, 0x23)
+#define NCI_OP_CORE_GET_CONFIG_CMD           nci_opcode_pack(NCI_GID_CORE, 0x03)

This is an NFC Forum spcified command, it should be defined in nci.h.

drivers/nfc/fdp/cmd.c line 46

Quoted 5 lines
drivers/nfc/fdp/cmd.c new file +5 -0
+static void fdp_nci_get_version_req(struct nci_dev *ndev, unsigned long opt)
+{
+	fdp_nci_send_cmd(ndev, NCI_OP_CORE_GET_CONFIG_CMD,
+			 sizeof(nci_core_get_config_otp_ram_version),
+			 &nci_core_get_config_otp_ram_version);

I don't think you need the intercept logic, so this should be a simple wrapper around nci_send_cmd().

drivers/nfc/fdp/cmd.c line 71

Quoted 7 lines
drivers/nfc/fdp/cmd.c new file +7 -0
+int fdp_nci_create_conn(struct nci_dev *ndev)
+{
+	struct fdp_nci_info *info = nci_get_drvdata(ndev);
+	struct core_conn_create_dest_spec_params param;
+
+	param.type = 0xA0;
+	param.length = 0x00;

Would you please describe what those parameters are for ?

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	return nci_core_conn_create(info->ndev, 0xC2, 1, sizeof(param), &param,

Please define 0xC2, #define FDP_FW_UPDATE_DEST 0xC2

Quoted 28 lines
drivers/nfc/fdp/cmd.c new file +28 -0
+int fdp_nci_send_patch(struct nci_dev *ndev, u8 type)
+{
+	struct fdp_nci_info *info = nci_get_drvdata(ndev);
+	const struct firmware *fw;
+	struct sk_buff *skb;
+	unsigned long len;
+	u8 max_size, payload_size;
+	int rc = 0;
+
+	if ((type == NCI_PATCH_TYPE_OTP && !info->otp_patch) ||
+	    (type == NCI_PATCH_TYPE_RAM && !info->ram_patch))
+		return -EINVAL;
+
+	if (type == NCI_PATCH_TYPE_OTP)
+		fw = info->otp_patch;
+	else
+		fw = info->ram_patch;
+
+	max_size = nci_conn_max_data_pkt_payload_size(ndev, info->conn_id);
+	if (!max_size)
+		return -EINVAL;
+
+	len = fw->size;
+
+	fdp_nci_set_data_pkt_counter(ndev, fdp_nci_send_patch_cb,
+				     DIV_ROUND_UP(fw->size, max_size));
+
+	while (len) {

drivers/nfc/fdp/cmd.c line 183

Quoted 10 lines
drivers/nfc/fdp/cmd.c new file +10 -0
+
+		payload_size = min_t(unsigned long, (unsigned long) max_size,
+				     len);
+
+		skb = nci_skb_alloc(ndev, (NCI_CTRL_HDR_SIZE + payload_size),
+				    GFP_KERNEL);
+		skb_reserve(skb, NCI_CTRL_HDR_SIZE);
+
+		memcpy(skb_put(skb, payload_size), fw->data + (fw->size - len),
+		       payload_size);

Where is your control header set ? How does your boot ROM know how much bytes are expected ?

drivers/nfc/fdp/core.c line 98

Quoted 7 lines
drivers/nfc/fdp/core.c new file +7 -0
+void fdp_nci_intercept_disable(struct nci_dev *ndev)
+{
+	struct fdp_nci_info *info = nci_get_drvdata(ndev);
+
+	pr_info("FDP NCI intercept disabled\n");
+	atomic_set(&info->intercept, 0);
+}

Please remove all the intercept stuff here, go through the NCI core and have a prop_rx ops called.

Quoted 5 lines
drivers/nfc/fdp/core.c new file +5 -0
+int fdp_nci_recv_frame(struct nci_dev *ndev, struct sk_buff *skb)
+{
+	struct fdp_nci_info *info = nci_get_drvdata(ndev);
+
+	pr_debug("%s\n", __func__);

drivers/nfc/fdp/core.c line 124

Quoted 10 lines
drivers/nfc/fdp/core.c new file +10 -0
+
+	if (atomic_read(&info->intercept)) {
+		skb_queue_tail(&info->rx_q, skb);
+		schedule_work(&info->rx_work);
+		return 0;
+	}
+
+	return nci_recv_frame(ndev, skb);
+}
+EXPORT_SYMBOL(fdp_nci_recv_frame);

Without the intercept stuff, this should only be nci_recv_frame().

drivers/nfc/fdp/core.c line 163

Quoted 6 lines
drivers/nfc/fdp/core.c new file +6 -0
+int fdp_nci_send_cmd(struct nci_dev *ndev, u16 opcode, u8 plen,
+		     void *payload)
+{
+	fdp_nci_intercept_inc(ndev);
+	return nci_send_cmd(ndev, opcode, plen, payload);
+}

Ditto

Quoted 6 lines
drivers/nfc/fdp/core.c new file +6 -0
+int fdp_nci_setup(struct nci_dev *ndev)
+{
+	/* Format: total length followed by an NCI packet */
+	struct fdp_nci_info *info = nci_get_drvdata(ndev);
+	char fdp_post_fw_vsc_cfg[] = {  0x1A, 0x2F, 0x23, 0x17,
+					0x00, 0x00, 0x00,

drivers/nfc/fdp/core.c line 226

Quoted 10 lines
drivers/nfc/fdp/core.c new file +10 -0
+					0x00, 0x04, 0x04, 0x2B, 0x20, 0xFF,
+					0x09, 0x07, 0xFF, 0xFF, 0xFF, 0xFF,
+					0x02, 0xFF, 0xFF,
+					0x08, 0x03, 0x00, 0xFF, 0xFF };
+	int r;
+	u8 patched = 0;
+
+	pr_debug("%s\n", __func__);
+
+	r = nci_init(ndev);

I won't comment further on the fact that I'd prefer to not export nci_init().

Quoted 132 lines
drivers/nfc/fdp/core.c new file +132 -0
+	if (r)
+		goto error;
+
+	/* Get RAM and OTP version */
+	r = fdp_nci_get_versions(ndev);
+	if (r)
+		goto error;
+
+	/* Load firmware from disk */
+	r = fdp_nci_request_firmware(ndev);
+	if (r)
+		goto error;
+
+	/* Update OTP */
+	if (info->otp_version < info->otp_patch_version) {
+
+		info->setup_patch_sent = 0;
+		info->setup_reset_ntf = 0;
+		info->setup_patch_ntf = 0;
+
+		/* Patch init request */
+		r = fdp_nci_patch_start(ndev, NCI_PATCH_TYPE_OTP);
+		if (r)
+			goto error;
+
+		/* Patch data connection creation */
+		r = fdp_nci_create_conn(ndev);
+		if (r)
+			goto error;
+
+		/* Send the patch over the data connection */
+		r = fdp_nci_send_patch(ndev, NCI_PATCH_TYPE_OTP);
+		if (r)
+			goto error;
+
+		/* Wait for all the packets to be send over i2c */
+		wait_event_interruptible(info->setup_wq,
+					 info->setup_patch_sent == 1);
+
+		/* Close the data connection */
+		r = fdp_nci_close_conn(ndev);
+		if (r)
+			goto error;
+
+		/*
+		 * After we send the patch finish message we expect two
+		 * notifications: NCI_OP_PROP_PATCH_NTF,
+		 * NCI_OP_CORE_RESET_NTF
+		 */
+		fdp_nci_intercept_add(ndev, 2);
+
+		/* Patch finish message */
+		r = fdp_nci_patch_end(ndev);
+		if (r) {
+			pr_err("FDP OTP patch error %d\n", r);
+			r = -EINVAL;
+			goto error;
+		}
+
+		/* If the patch notification didn't arrive yet, wait for it */
+		wait_event_interruptible(info->setup_wq, info->setup_patch_ntf);
+
+		/* Check if the patching was successful */
+		r = info->setup_patch_status;
+		if (r) {
+			pr_err("FDP OTP patch error %d\n", r);
+			r = -EINVAL;
+			goto error;
+		}
+
+		/*
+		 * We need to wait for the reset notification before we
+		 * can continue
+		 */
+		wait_event_interruptible(info->setup_wq, info->setup_reset_ntf);
+
+		patched = 1;
+	}
+
+	/* Update RAM */
+	if (info->ram_version < info->ram_patch_version) {
+
+		info->setup_patch_sent = 0;
+		info->setup_reset_ntf = 0;
+		info->setup_patch_ntf = 0;
+
+		/* Patch init request */
+		r = fdp_nci_patch_start(ndev, NCI_PATCH_TYPE_RAM);
+		if (r)
+			goto error;
+
+		/* Patch data connection creation */
+		r = fdp_nci_create_conn(ndev);
+		if (r)
+			goto error;
+
+		/* Send the patch over the data connection */
+		r = fdp_nci_send_patch(ndev, NCI_PATCH_TYPE_RAM);
+		if (r)
+			goto error;
+
+		/* Wait for all the packets to be send over i2c */
+		wait_event_interruptible(info->setup_wq,
+					 info->setup_patch_sent == 1);
+
+		/* Close the data connection */
+		r = fdp_nci_close_conn(ndev);
+		if (r)
+			goto error;
+
+		/*
+		 * After we send the patch finish message we expect two
+		 * notifications: NCI_OP_PROP_PATCH_NTF,
+		 * NCI_OP_CORE_RESET_NTF
+		 */
+		fdp_nci_intercept_add(ndev, 2);
+
+		/* Patch finish message */
+		if (fdp_nci_patch_end(ndev)) {
+			r = -EINVAL;
+			goto error;
+		}
+
+		/* If the patch notification didn't arrive yet, wait for it*/
+		wait_event_interruptible(info->setup_wq, info->setup_patch_ntf);
+
+		/* Check if the patching was successful */
+		r = info->setup_patch_status;
+		if (r) {
+			pr_err("FDP RAM patch error %d\n", r);
+			r = -EINVAL;
+			goto error;

drivers/nfc/fdp/core.c line 368

Quoted 10 lines
drivers/nfc/fdp/core.c new file +10 -0
+		}
+
+		/*
+		 * We need to wait for the reset notification before we
+		 * can continue
+		 */
+		wait_event_interruptible(info->setup_wq, info->setup_reset_ntf);
+
+		patched = 1;
+	}

You probably want to release your OTP and RAM buffers here.

Quoted 20 lines
drivers/nfc/fdp/core.c new file +20 -0
+	/* If a patch was applied the new version is checked */
+	if (patched) {
+		r = nci_init(ndev);
+		if (r)
+			goto error;
+
+		r = fdp_nci_get_versions(ndev);
+		if (r)
+			goto error;
+
+		if (info->otp_version != info->otp_patch_version ||
+		    info->ram_version != info->ram_patch_version) {
+			pr_err("FRP firmware update failed");
+			r = -EINVAL;
+		}
+	}
+
+	/* Check if the device has VSC */
+	if (fdp_post_fw_vsc_cfg[0]) {
+		/* Set the vendor specific configuration */

drivers/nfc/fdp/core.c line 399

Quoted 10 lines
drivers/nfc/fdp/core.c new file +10 -0
+		r = fdp_nci_set_production_data(ndev, fdp_post_fw_vsc_cfg[3],
+						&fdp_post_fw_vsc_cfg[4]);
+		if (r)
+			goto error;
+	}
+
+	/* Set clock type and frequency */
+	r = fdp_nci_set_clock(ndev, 0, 26000);
+	if (r)
+		goto error;

The version checking, production data setting and clock setting should be part of a post setup notification call. Please add an nci_dev notify() ops that could get called on certain events, for example when NCI is up. Bluetooth's HCI does something along those lines already.

Quoted 1 line

From this notification hook you could implement this post setup stage.

The idea is for your setup routine to only do firmware update and nothing else. It will make it shorter, and thus easier to read as well.

Quoted 20 lines
drivers/nfc/fdp/fdp.h new file +20 -0
+struct fdp_nci_info {
+	struct nfc_phy_ops *phy_ops;
+	struct fdp_i2c_phy *phy;
+	struct nci_dev *ndev;
+
+	enum fdp_state state;
+	struct mutex lock;
+
+	const struct firmware *otp_patch;
+	const struct firmware *ram_patch;
+	u32 otp_patch_version;
+	u32 ram_patch_version;
+
+	u32 otp_version;
+	u32 ram_version;
+	u32 limited_otp_version;
+	u8 key_index;
+
+	u8 conn_id;
+	atomic_t intercept;

drivers/nfc/fdp/fdp.h line 90

Quoted 10 lines
drivers/nfc/fdp/fdp.h new file +10 -0
+	atomic_t data_pkt_counter;
+	void (*data_pkt_counter_cb)(struct nci_dev *ndev);
+	u8 setup_patch_sent;
+	u8 setup_patch_ntf;
+	u8 setup_patch_status;
+	u8 setup_reset_ntf;
+	wait_queue_head_t setup_wq;
+
+	struct sk_buff_head      rx_q;
+	struct work_struct	 rx_work;

I expect those 2 ones to go away as well.

Cheers,
Samuel.

#24 lore raw

Re: [PATCH 8/8] NFC: Add Intel FieldsPeak NFC solution driver

In reply to Robert Dolca

Robert,

Another comment:

drivers/nfc/fdp/i2c.c line 438

Quoted 12 lines · Robert Dolca
drivers/nfc/fdp/i2c.c new file +12 -0
+static struct i2c_device_id fdp_nci_i2c_id_table[] = {
+	{"INT339A", 0},
+	{}
+};
+
+MODULE_DEVICE_TABLE(i2c, fdp_nci_i2c_id_table);
+
+
+static const struct acpi_device_id fdp_nci_i2c_acpi_match[] = {
+	{"INT339A", 0},
+	{}
+};

Why don't we have a MODULE_DEVICE_TABLE(acpi, fdp_nci_i2c_acpi_match); here ?

Cheers,
Samuel.

#25 lore raw

Re: [PATCH 8/8] NFC: Add Intel FieldsPeak NFC solution driver

In reply to Robert Dolca

Review

Quoted 2 lines · Robert Dolca
(quoted diff) +2 -0
+static struct i2c_device_id fdp_nci_i2c_id_table[] = {
+	{"INT339A", 0},

If this is ACPI only device you can remove the above line.

drivers/nfc/fdp/i2c.c line 432

Quoted 4 lines
drivers/nfc/fdp/i2c.c new file +4 -0
+	{}
+};
+
+MODULE_DEVICE_TABLE(i2c, fdp_nci_i2c_id_table);

And this as well.

Quoted 17 lines
drivers/nfc/fdp/i2c.c new file +17 -0
+
+
+static const struct acpi_device_id fdp_nci_i2c_acpi_match[] = {
+	{"INT339A", 0},
+	{}
+};
+
+static struct i2c_driver fdp_nci_i2c_driver = {
+	.driver = {
+		   .name = FDP_NCI_I2C_DRIVER_NAME,
+		   .owner  = THIS_MODULE,
+		   .acpi_match_table = ACPI_PTR(fdp_nci_i2c_acpi_match),
+		  },
+	.id_table = fdp_nci_i2c_id_table,
+	.probe = fdp_nci_i2c_probe,
+	.remove = fdp_nci_i2c_remove,
+};
#3 lore raw

Re: [linux-nfc] [PATCH 1/8] NFC: NCI: Allow connection close with dev down

In reply to Samuel Ortiz
Quoted 17 lines · Samuel Ortiz

Hi Robert,

Quoted 14 lines · Robert Dolca

By calling __nci_request instead of nci_request allows the driver to use the function while initializing the device (setup stage)

---
 net/nfc/nci/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/nfc/nci/core.c +0 -0
index 9575a18..c4dd5d8 100644
@@ -558,7 +558,7 @@ static void nci_core_conn_close_req(struct nci_dev *ndev, unsigned long opt)
 
Quoted 10 lines

net/nfc/nci/core.c static void nci_core_conn_close_req(struct nci_dev *ndev, unsigned long opt) · line 562

Quoted 5 lines
net/nfc/nci/core.c +1 -1
 int nci_core_conn_close(struct nci_dev *ndev, u8 conn_id)
 {
-     return nci_request(ndev, nci_core_conn_close_req, conn_id,
+     return __nci_request(ndev, nci_core_conn_close_req, conn_id,
                              msecs_to_jiffies(NCI_CMD_TIMEOUT));

You're fixing your problem by removing the NCI request serialization and removing the check for your device being UP.
I assume you need to open and close a proprietary connection from your setup hook ? Then please extend nci_request() to check for both NCI_UP and NCI_INIT.

You are right, I am opening and closing a connection from the setup function. The setup is called by nci_open_device. At the beginning of nci_open_device, req_lock is being acquired and it is release at the end of the function. That means that when setup is being called req_lock is acuired. As you said I can modify nci_request to check for NCI_INIT but it tries to acquire req_lock and it can not succeed.

We could use another mutex for nci_request but I am not sure if that is a good idea.

Regards,
Robert

#9 lore raw

Re: [linux-nfc] [PATCH 3/8] NFC: NCI: Adds NCI init and reset API for drivers

In reply to Samuel Ortiz
Quoted 8 lines · Samuel Ortiz

Hi Robert,

Quoted 5 lines · Robert Dolca

In order to communicate with the device during the setup phase, the driver may need to initialize the device. After the setup is done the driver should reset the device to leave it in the same state that it was before the setup function call.

Quoted 4 lines

I would prefer not to export those symbols, but instead introduce a quirk bitmap to let the NCI core know that your device expects the core to be initialized before calling the setup ops.
That would be done from nci_open_device().

As part of the initialization / firmware upgrade procedure the driver needs to reset and initialize the NCI connection multiple times. Having the connection initialized before calling setup is not enough.

Regards,
Robert
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#13 lore raw

Re: [linux-nfc] [PATCH 4/8] NFC: NCI: Add a special nci_request for driver

In reply to Samuel Ortiz
Quoted 17 lines · Samuel Ortiz

Hi Robert,

Quoted 8 lines · Robert Dolca

This patch adds nci_request_driver and nci_req_complete_driver as a wrapper for __nci_request. When nci_req_complete_driver is called it also sets cmd_cnt to 1. This is done because the response is not sent to the NFC subsystem so cmd_cnt is not decremented there.

nci_send_cmd was previously exported in order to send commands to the device from the driver. It shouldn't be used without nci_req_complete_driver because cmd_cnt will have the wrong value.

Any NCI packet should make it to the NCI core first, because the logic and synchornization between Tx and Rx, commands and response is implemented there. When exporting this kind of symbols, you're opening a can of worms by potentially allowing each driver to implement the same kind of logic that's already implemented in the NCI core.

Quoted 8 lines

The solution I'd like to see implemented is the following one: Add 1 additional nci_ops entry for handling proprietary packets on the Rx path. From your driver perspective, you call nci_recv_frame for each and every packet that you receive: No intercept, no trap. The core will call your proprietary packets handler for each packet (NTF or RSP) with a proprietary GID.
You should then be able to remove all the rx work, rx queue and intercept logic from your driver.

Thanks for the suggestion. Will do.

Robert

#22 lore raw

Re: [linux-nfc] [PATCH 8/8] NFC: Add Intel FieldsPeak NFC solution driver

In reply to Samuel Ortiz
Quoted 36 lines · Samuel Ortiz
Quoted 20 lines
drivers/nfc/fdp/core.c new file +20 -0
+     /* If a patch was applied the new version is checked */
+     if (patched) {
+             r = nci_init(ndev);
+             if (r)
+                     goto error;
+
+             r = fdp_nci_get_versions(ndev);
+             if (r)
+                     goto error;
+
+             if (info->otp_version != info->otp_patch_version ||
+                 info->ram_version != info->ram_patch_version) {
+                     pr_err("FRP firmware update failed");
+                     r = -EINVAL;
+             }
+     }
+
+     /* Check if the device has VSC */
+     if (fdp_post_fw_vsc_cfg[0]) {
+             /* Set the vendor specific configuration */

drivers/nfc/fdp/core.c line 399

Quoted 10 lines
drivers/nfc/fdp/core.c new file +10 -0
+             r = fdp_nci_set_production_data(ndev, fdp_post_fw_vsc_cfg[3],
+                                             &fdp_post_fw_vsc_cfg[4]);
+             if (r)
+                     goto error;
+     }
+
+     /* Set clock type and frequency */
+     r = fdp_nci_set_clock(ndev, 0, 26000);
+     if (r)
+             goto error;

The version checking, production data setting and clock setting should be part of a post setup notification call. Please add an nci_dev notify() ops that could get called on certain events, for example when NCI is up. Bluetooth's HCI does something along those lines already. From this notification hook you could implement this post setup stage.

Quoted 2 lines

The idea is for your setup routine to only do firmware update and nothing else. It will make it shorter, and thus easier to read as well.

Hi Samuel,

If the RAM patch wasn't applied successfully the device can't be used so the setup function should fail.
If the production data (specifically the clock frequency) is not set the device can not be used. If the user space tries to start polling before the notification is sent the polling will fail. Having it called later would mean introducing a race condition.

Cheers,
Robert

#4 lore raw

Re: [linux-nfc] [PATCH 1/8] NFC: NCI: Allow connection close with dev down

In reply to Robert Dolca

Hi Robert,

Quoted 29 lines · Robert Dolca
Quoted 17 lines · Samuel Ortiz

Hi Robert,

Quoted 14 lines · Robert Dolca

By calling __nci_request instead of nci_request allows the driver to use the function while initializing the device (setup stage)

---
 net/nfc/nci/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/nfc/nci/core.c +0 -0
index 9575a18..c4dd5d8 100644
@@ -558,7 +558,7 @@ static void nci_core_conn_close_req(struct nci_dev *ndev, unsigned long opt)
 
Quoted 10 lines

net/nfc/nci/core.c static void nci_core_conn_close_req(struct nci_dev *ndev, unsigned long opt) · line 562

Quoted 5 lines
net/nfc/nci/core.c +1 -1
 int nci_core_conn_close(struct nci_dev *ndev, u8 conn_id)
 {
-     return nci_request(ndev, nci_core_conn_close_req, conn_id,
+     return __nci_request(ndev, nci_core_conn_close_req, conn_id,
                              msecs_to_jiffies(NCI_CMD_TIMEOUT));

You're fixing your problem by removing the NCI request serialization and removing the check for your device being UP.
I assume you need to open and close a proprietary connection from your setup hook ? Then please extend nci_request() to check for both NCI_UP and NCI_INIT.

Quoted 6 lines

You are right, I am opening and closing a connection from the setup function. The setup is called by nci_open_device. At the beginning of nci_open_device, req_lock is being acquired and it is release at the end of the function. That means that when setup is being called req_lock is acuired. As you said I can modify nci_request to check for NCI_INIT but it tries to acquire req_lock and it can not succeed.

I see, I thought the issue was only about checking the NCI_* flags.

As a short term solution, I propose you do the following:

a) Export nci_core_conn_create_req, nci_core_conn_close_req and __nci_request.
b) Call __nci_request() directly from your fdp_nci_close_conn() and fdp_nci_create_conn() routines.

The long term, scalable fix would be to implement and export an __nci_send_cmd_sync() routine, that would transparently build an NCI request and tail it to the ndev req skb queue, and put the caller on a wait queue. The created request's response callback would then wake the caller up.

Cheers,
Samuel.

#10 lore raw

Re: [linux-nfc] [PATCH 3/8] NFC: NCI: Adds NCI init and reset API for drivers

In reply to Robert Dolca

Hi Robert,

Quoted 9 lines · Robert Dolca
Quoted 8 lines · Samuel Ortiz

Hi Robert,

Quoted 5 lines · Robert Dolca

In order to communicate with the device during the setup phase, the driver may need to initialize the device. After the setup is done the driver should reset the device to leave it in the same state that it was before the setup function call.

Quoted 8 lines
Quoted 4 lines

I would prefer not to export those symbols, but instead introduce a quirk bitmap to let the NCI core know that your device expects the core to be initialized before calling the setup ops.
That would be done from nci_open_device().

As part of the initialization / firmware upgrade procedure the driver needs to reset and initialize the NCI connection multiple times. Having the connection initialized before calling setup is not enough.

Fair enough, I am ok with exporting those symbols.

BTW after looking at your setup routine, I think this is wrong:

+ /* Load firmware from disk */
+ r = fdp_nci_request_firmware(ndev);
+ if (r)
+ goto error;

You should be able to boot your NFC chipset without a local patch. If there is one, then you can try patching your device, but otherwise we should continue with the exisiting one.

Cheers,
Samuel.

#23 lore raw

Re: [linux-nfc] [PATCH 8/8] NFC: Add Intel FieldsPeak NFC solution driver

In reply to Robert Dolca

Hi Robert,

Quoted 37 lines · Robert Dolca
Quoted 36 lines · Samuel Ortiz
Quoted 20 lines
drivers/nfc/fdp/core.c new file +20 -0
+     /* If a patch was applied the new version is checked */
+     if (patched) {
+             r = nci_init(ndev);
+             if (r)
+                     goto error;
+
+             r = fdp_nci_get_versions(ndev);
+             if (r)
+                     goto error;
+
+             if (info->otp_version != info->otp_patch_version ||
+                 info->ram_version != info->ram_patch_version) {
+                     pr_err("FRP firmware update failed");
+                     r = -EINVAL;
+             }
+     }
+
+     /* Check if the device has VSC */
+     if (fdp_post_fw_vsc_cfg[0]) {
+             /* Set the vendor specific configuration */

drivers/nfc/fdp/core.c line 399

Quoted 10 lines
drivers/nfc/fdp/core.c new file +10 -0
+             r = fdp_nci_set_production_data(ndev, fdp_post_fw_vsc_cfg[3],
+                                             &fdp_post_fw_vsc_cfg[4]);
+             if (r)
+                     goto error;
+     }
+
+     /* Set clock type and frequency */
+     r = fdp_nci_set_clock(ndev, 0, 26000);
+     if (r)
+             goto error;

The version checking, production data setting and clock setting should be part of a post setup notification call. Please add an nci_dev notify() ops that could get called on certain events, for example when NCI is up. Bluetooth's HCI does something along those lines already. From this notification hook you could implement this post setup stage.

Quoted 8 lines
Quoted 2 lines

The idea is for your setup routine to only do firmware update and nothing else. It will make it shorter, and thus easier to read as well.

If the RAM patch wasn't applied successfully the device can't be used so the setup function should fail.
If the production data (specifically the clock frequency) is not set the device can not be used. If the user space tries to start polling before the notification is sent the polling will fail. Having it called later would mean introducing a race condition.

Sure. Then I'd rather have an additional NCI hook (e.g. ndev->ops->open()) called synchronously after the setup stage that could fail and make open fail as well. The idea here is to separate the 2 parts of your logic and make the code more readable.

Cheers,
Samuel.

#5 lore raw

Re: [linux-nfc] [PATCH 1/8] NFC: NCI: Allow connection close with dev down

In reply to Samuel Ortiz
Quoted 47 lines · Samuel Ortiz

Hi Robert,

Quoted 29 lines · Robert Dolca
Quoted 17 lines · Samuel Ortiz

Hi Robert,

Quoted 14 lines · Robert Dolca

By calling __nci_request instead of nci_request allows the driver to use the function while initializing the device (setup stage)

---
 net/nfc/nci/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/nfc/nci/core.c +0 -0
index 9575a18..c4dd5d8 100644
@@ -558,7 +558,7 @@ static void nci_core_conn_close_req(struct nci_dev *ndev, unsigned long opt)
 
Quoted 10 lines

net/nfc/nci/core.c static void nci_core_conn_close_req(struct nci_dev *ndev, unsigned long opt) · line 562

Quoted 5 lines
net/nfc/nci/core.c +1 -1
 int nci_core_conn_close(struct nci_dev *ndev, u8 conn_id)
 {
-     return nci_request(ndev, nci_core_conn_close_req, conn_id,
+     return __nci_request(ndev, nci_core_conn_close_req, conn_id,
                              msecs_to_jiffies(NCI_CMD_TIMEOUT));

You're fixing your problem by removing the NCI request serialization and removing the check for your device being UP.
I assume you need to open and close a proprietary connection from your setup hook ? Then please extend nci_request() to check for both NCI_UP and NCI_INIT.

Quoted 6 lines

You are right, I am opening and closing a connection from the setup function. The setup is called by nci_open_device. At the beginning of nci_open_device, req_lock is being acquired and it is release at the end of the function. That means that when setup is being called req_lock is acuired. As you said I can modify nci_request to check for NCI_INIT but it tries to acquire req_lock and it can not succeed.

I see, I thought the issue was only about checking the NCI_* flags.

As a short term solution, I propose you do the following:

a) Export nci_core_conn_create_req, nci_core_conn_close_req and __nci_request.
b) Call __nci_request() directly from your fdp_nci_close_conn() and fdp_nci_create_conn() routines.

Quoted 5 lines

The long term, scalable fix would be to implement and export an __nci_send_cmd_sync() routine, that would transparently build an NCI request and tail it to the ndev req skb queue, and put the caller on a wait queue. The created request's response callback would then wake the caller up.

If nci_open_device would use another mutex instead of req_lock this wouldn't be necessary.
I don't see any reason why nci_open_device should block the send queue. Of course, in nci_open_device all calls to __nci_request would have to be replaced with nci_request.

Samuel, would that be an acceptable solution?

Regards,
Robert