[PATCH v3 28/35] nfc: netlink: Add mode parameter to deactivate_target functions

2015-10-25 Thread Christophe Ricard
In order to manage in a better way the nci poll mode state machine, add
mode parameter to deactivate_target functions. This way we can manage
different target state. mode parameter make sense only in nci core.

Signed-off-by: Christophe Ricard 
---
 include/net/nfc/nfc.h  |  2 +-
 net/nfc/core.c |  4 ++--
 net/nfc/digital_core.c |  3 ++-
 net/nfc/hci/core.c |  3 ++-
 net/nfc/nci/core.c | 15 +++
 net/nfc/netlink.c  |  2 +-
 net/nfc/nfc.h  |  5 -
 net/nfc/rawsock.c  |  3 ++-
 8 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/include/net/nfc/nfc.h b/include/net/nfc/nfc.h
index 30afc9a..dcfcfc9 100644
--- a/include/net/nfc/nfc.h
+++ b/include/net/nfc/nfc.h
@@ -68,7 +68,7 @@ struct nfc_ops {
int (*activate_target)(struct nfc_dev *dev, struct nfc_target *target,
   u32 protocol);
void (*deactivate_target)(struct nfc_dev *dev,
- struct nfc_target *target);
+ struct nfc_target *target, u8 mode);
int (*im_transceive)(struct nfc_dev *dev, struct nfc_target *target,
 struct sk_buff *skb, data_exchange_cb_t cb,
 void *cb_context);
diff --git a/net/nfc/core.c b/net/nfc/core.c
index cff3f16..1fe3d3b 100644
--- a/net/nfc/core.c
+++ b/net/nfc/core.c
@@ -449,7 +449,7 @@ error:
  * @dev: The nfc device that found the target
  * @target_idx: index of the target that must be deactivated
  */
-int nfc_deactivate_target(struct nfc_dev *dev, u32 target_idx)
+int nfc_deactivate_target(struct nfc_dev *dev, u32 target_idx, u8 mode)
 {
int rc = 0;
 
@@ -476,7 +476,7 @@ int nfc_deactivate_target(struct nfc_dev *dev, u32 
target_idx)
if (dev->ops->check_presence)
del_timer_sync(&dev->check_pres_timer);
 
-   dev->ops->deactivate_target(dev, dev->active_target);
+   dev->ops->deactivate_target(dev, dev->active_target, mode);
dev->active_target = NULL;
 
 error:
diff --git a/net/nfc/digital_core.c b/net/nfc/digital_core.c
index 009bcf3..23c2a11 100644
--- a/net/nfc/digital_core.c
+++ b/net/nfc/digital_core.c
@@ -631,7 +631,8 @@ static int digital_activate_target(struct nfc_dev *nfc_dev,
 }
 
 static void digital_deactivate_target(struct nfc_dev *nfc_dev,
- struct nfc_target *target)
+ struct nfc_target *target,
+ u8 mode)
 {
struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev);
 
diff --git a/net/nfc/hci/core.c b/net/nfc/hci/core.c
index 6e061da..2b0f0ac 100644
--- a/net/nfc/hci/core.c
+++ b/net/nfc/hci/core.c
@@ -678,7 +678,8 @@ static int hci_activate_target(struct nfc_dev *nfc_dev,
 }
 
 static void hci_deactivate_target(struct nfc_dev *nfc_dev,
- struct nfc_target *target)
+ struct nfc_target *target,
+ u8 mode)
 {
 }
 
diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c
index 0909720..b7f548b 100644
--- a/net/nfc/nci/core.c
+++ b/net/nfc/nci/core.c
@@ -802,9 +802,11 @@ static int nci_activate_target(struct nfc_dev *nfc_dev,
 }
 
 static void nci_deactivate_target(struct nfc_dev *nfc_dev,
- struct nfc_target *target)
+ struct nfc_target *target,
+ __u8 mode)
 {
struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
+   u8 nci_mode = NCI_DEACTIVATE_TYPE_IDLE_MODE;
 
pr_debug("entry\n");
 
@@ -815,9 +817,14 @@ static void nci_deactivate_target(struct nfc_dev *nfc_dev,
 
ndev->target_active_prot = 0;
 
+   switch (mode) {
+   case NFC_TARGET_MODE_SLEEP:
+   nci_mode = NCI_DEACTIVATE_TYPE_SLEEP_MODE;
+   break;
+   }
+
if (atomic_read(&ndev->state) == NCI_POLL_ACTIVE) {
-   nci_request(ndev, nci_rf_deactivate_req,
-   NCI_DEACTIVATE_TYPE_IDLE_MODE,
+   nci_request(ndev, nci_rf_deactivate_req, nci_mode,
msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT));
}
 }
@@ -851,7 +858,7 @@ static int nci_dep_link_down(struct nfc_dev *nfc_dev)
pr_debug("entry\n");
 
if (nfc_dev->rf_mode == NFC_RF_INITIATOR) {
-   nci_deactivate_target(nfc_dev, NULL);
+   nci_deactivate_target(nfc_dev, NULL, 
NCI_DEACTIVATE_TYPE_IDLE_MODE);
} else {
if (atomic_read(&ndev->state) == NCI_LISTEN_ACTIVE ||
atomic_read(&ndev->state) == NCI_DISCOVERY) {
diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c
index f040532..f58c1fb 100644
--- a/net/nfc/netlink.c
+++ b/net/nfc/netlink.c
@@ -885,7 +885,7 @@ static int nfc_genl_activate_target(struct sk_buff *skb, 
struct genl_info *info)
 

[PATCH v3 30/35] nfc: st21nfca: Add few code style fixes

2015-10-25 Thread Christophe Ricard
Add a minor code style fixes

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st21nfca/core.c | 2 --
 drivers/nfc/st21nfca/i2c.c  | 1 +
 drivers/nfc/st21nfca/se.c   | 2 +-
 3 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/nfc/st21nfca/core.c b/drivers/nfc/st21nfca/core.c
index 814d8ff4..6fc60bb 100644
--- a/drivers/nfc/st21nfca/core.c
+++ b/drivers/nfc/st21nfca/core.c
@@ -162,7 +162,6 @@ static int st21nfca_hci_load_session(struct nfc_hci_dev 
*hdev)
r = nfc_hci_send_cmd(hdev, ST21NFCA_DEVICE_MGNT_GATE,
ST21NFCA_DM_GETINFO, pipe_info,
sizeof(pipe_info), &skb_pipe_info);
-
if (r)
continue;
 
@@ -982,7 +981,6 @@ int st21nfca_hci_probe(void *phy_id, struct nfc_phy_ops 
*phy_ops,
 * persistent info to discriminate 2 identical chips
 */
dev_num = find_first_zero_bit(dev_mask, ST21NFCA_NUM_DEVICES);
-
if (dev_num >= ST21NFCA_NUM_DEVICES)
return -ENODEV;
 
diff --git a/drivers/nfc/st21nfca/i2c.c b/drivers/nfc/st21nfca/i2c.c
index b2c914b..84c2cb0 100644
--- a/drivers/nfc/st21nfca/i2c.c
+++ b/drivers/nfc/st21nfca/i2c.c
@@ -94,6 +94,7 @@ struct st21nfca_i2c_phy {
int hard_fault;
struct mutex phy_lock;
 };
+
 static u8 len_seq[] = { 16, 24, 12, 29 };
 static u16 wait_tab[] = { 2, 3, 5, 15, 20, 40};
 
diff --git a/drivers/nfc/st21nfca/se.c b/drivers/nfc/st21nfca/se.c
index 8e05d73..d3347c7 100644
--- a/drivers/nfc/st21nfca/se.c
+++ b/drivers/nfc/st21nfca/se.c
@@ -19,7 +19,7 @@
 #include "st21nfca.h"
 
 #define ST21NFCA_EVT_UICC_ACTIVATE 0x10
-#define ST21NFCA_EVT_UICC_DEACTIVATE   0x13
+#define ST21NFCA_EVT_UICC_DEACTIVATE   0x13
 #define ST21NFCA_EVT_SE_HARD_RESET 0x20
 #define ST21NFCA_EVT_SE_SOFT_RESET 0x11
 #define ST21NFCA_EVT_SE_END_OF_APDU_TRANSFER   0x21
-- 
2.1.4

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


[PATCH v3 32/35] nfc: st21nfca: Add error messages when an unexpected HCI event occurs

2015-10-25 Thread Christophe Ricard
Potentially an unexpected HCI event may occur because of a firmware bug.
It could be transparent for the user but at least log this.

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st21nfca/core.c | 2 ++
 drivers/nfc/st21nfca/dep.c  | 1 +
 drivers/nfc/st21nfca/se.c   | 4 
 3 files changed, 7 insertions(+)

diff --git a/drivers/nfc/st21nfca/core.c b/drivers/nfc/st21nfca/core.c
index d36e290..dd8b150 100644
--- a/drivers/nfc/st21nfca/core.c
+++ b/drivers/nfc/st21nfca/core.c
@@ -893,6 +893,8 @@ static int st21nfca_admin_event_received(struct nfc_hci_dev 
*hdev, u8 event,
}
}
break;
+   default:
+   nfc_err(&hdev->ndev->dev, "Unexpected event on admin gate\n");
}
kfree_skb(skb);
return 0;
diff --git a/drivers/nfc/st21nfca/dep.c b/drivers/nfc/st21nfca/dep.c
index c011712..798a32b 100644
--- a/drivers/nfc/st21nfca/dep.c
+++ b/drivers/nfc/st21nfca/dep.c
@@ -435,6 +435,7 @@ int st21nfca_dep_event_received(struct nfc_hci_dev *hdev,
return r;
return 0;
default:
+   nfc_err(&hdev->ndev->dev, "Unexpected event on card f gate\n");
return 1;
}
kfree_skb(skb);
diff --git a/drivers/nfc/st21nfca/se.c b/drivers/nfc/st21nfca/se.c
index e04f603..c79d99b 100644
--- a/drivers/nfc/st21nfca/se.c
+++ b/drivers/nfc/st21nfca/se.c
@@ -344,6 +344,7 @@ int st21nfca_connectivity_event_received(struct nfc_hci_dev 
*hdev, u8 host,
r = nfc_se_transaction(hdev->ndev, host, transaction);
break;
default:
+   nfc_err(&hdev->ndev->dev, "Unexpected event on connectivity 
gate\n");
return 1;
}
kfree_skb(skb);
@@ -375,6 +376,9 @@ int st21nfca_apdu_reader_event_received(struct nfc_hci_dev 
*hdev,
mod_timer(&info->se_info.bwi_timer, jiffies +
msecs_to_jiffies(info->se_info.wt_timeout));
break;
+   default:
+   nfc_err(&hdev->ndev->dev, "Unexpected event on apdu reader 
gate\n");
+   return 1;
}
 
 exit:
-- 
2.1.4

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


[PATCH v3 34/35] nfc: st-nci: remove duplicated skb dump

2015-10-25 Thread Christophe Ricard
Remove SPI_DUMP_SKB and I2C_DUMP_SKB as skb is already dumped in ndlc
layer.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/i2c.c | 11 ---
 drivers/nfc/st-nci/spi.c | 11 ---
 2 files changed, 22 deletions(-)

diff --git a/drivers/nfc/st-nci/i2c.c b/drivers/nfc/st-nci/i2c.c
index 25e5042..15e3ce2 100644
--- a/drivers/nfc/st-nci/i2c.c
+++ b/drivers/nfc/st-nci/i2c.c
@@ -58,13 +58,6 @@ struct st_nci_i2c_phy {
struct st_nci_se_status se_status;
 };
 
-#define I2C_DUMP_SKB(info, skb)\
-do {   \
-   pr_debug("%s:\n", info);\
-   print_hex_dump(KERN_DEBUG, "i2c: ", DUMP_PREFIX_OFFSET, \
-  16, 1, (skb)->data, (skb)->len, 0);  \
-} while (0)
-
 static int st_nci_i2c_enable(void *phy_id)
 {
struct st_nci_i2c_phy *phy = phy_id;
@@ -101,8 +94,6 @@ static int st_nci_i2c_write(void *phy_id, struct sk_buff 
*skb)
struct st_nci_i2c_phy *phy = phy_id;
struct i2c_client *client = phy->i2c_dev;
 
-   I2C_DUMP_SKB("st_nci_i2c_write", skb);
-
if (phy->ndlc->hard_fault != 0)
return phy->ndlc->hard_fault;
 
@@ -173,8 +164,6 @@ static int st_nci_i2c_read(struct st_nci_i2c_phy *phy,
skb_put(*skb, len);
memcpy((*skb)->data + ST_NCI_I2C_MIN_SIZE, buf, len);
 
-   I2C_DUMP_SKB("i2c frame read", *skb);
-
return 0;
 }
 
diff --git a/drivers/nfc/st-nci/spi.c b/drivers/nfc/st-nci/spi.c
index bf6643c..cf7ad81 100644
--- a/drivers/nfc/st-nci/spi.c
+++ b/drivers/nfc/st-nci/spi.c
@@ -59,13 +59,6 @@ struct st_nci_spi_phy {
struct st_nci_se_status se_status;
 };
 
-#define SPI_DUMP_SKB(info, skb)\
-do {   \
-   pr_debug("%s:\n", info);\
-   print_hex_dump(KERN_DEBUG, "spi: ", DUMP_PREFIX_OFFSET, \
-  16, 1, (skb)->data, (skb)->len, 0);  \
-} while (0)
-
 static int st_nci_spi_enable(void *phy_id)
 {
struct st_nci_spi_phy *phy = phy_id;
@@ -110,8 +103,6 @@ static int st_nci_spi_write(void *phy_id, struct sk_buff 
*skb)
.len = skb->len,
};
 
-   SPI_DUMP_SKB("st_nci_spi_write", skb);
-
if (phy->ndlc->hard_fault != 0)
return phy->ndlc->hard_fault;
 
@@ -188,8 +179,6 @@ static int st_nci_spi_read(struct st_nci_spi_phy *phy,
skb_put(*skb, len);
memcpy((*skb)->data + ST_NCI_SPI_MIN_SIZE, buf, len);
 
-   SPI_DUMP_SKB("spi frame read", *skb);
-
return 0;
 }
 
-- 
2.1.4

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


[PATCH v3 31/35] nfc: st21nfca: Add support for proprietary commands for factory tests

2015-10-25 Thread Christophe Ricard
Add support for proprietary commands useful mainly for factory testings.
Here is a list:
- FACTORY_MODE: Allow to set the driver into a mode where no secure element
are activated. It does not consider any NFC_ATTR_VENDOR_DATA.
- HCI_CLEAR_ALL_PIPES: Allow to execute a HCI clear all pipes command.
It does not consider any NFC_ATTR_VENDOR_DATA.
- HCI_DM_PUT_DATA: Allow to configure specific CLF registry as for example
RF trimmings or low level drivers configurations (I2C, SPI, SWP).
- HCI_DM_UPDATE_AID: Allow to configure an AID routing into the CLF routing
table following RF technology, CLF mode or protocol.
- HCI_DM_GET_INFO: Allow to retrieve CLF information.
- HCI_DM_GET_DATA: Allow to retrieve CLF configurable data such as low
level drivers configurations or RF trimmings.
- HCI_DM_LOAD: Allow to load a firmware into the CLF. A complete
packet can be more than 8KB.
- HCI_DM_RESET: Allow to run a CLF reset in order to "commit" CLF
configuration changes without CLF power off.
-  HCI_GET_PARAM: Allow to retrieve an HCI CLF parameter (for example the
white list).
- HCI_DM_FIELD_GENERATOR: Allow to generate different kind of RF
technology. When using this command to anti-collision is done.
- HCI_LOOPBACK: Allow to echo a command and test the Dh to CLF
connectivity.

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st21nfca/Makefile  |   2 +-
 drivers/nfc/st21nfca/core.c|   3 +
 drivers/nfc/st21nfca/se.c  |   4 +-
 drivers/nfc/st21nfca/st21nfca.h|  54 +-
 drivers/nfc/st21nfca/vendor_cmds.c | 369 +
 net/nfc/hci/llc.c  |   2 +
 6 files changed, 431 insertions(+), 3 deletions(-)
 create mode 100644 drivers/nfc/st21nfca/vendor_cmds.c

diff --git a/drivers/nfc/st21nfca/Makefile b/drivers/nfc/st21nfca/Makefile
index 82434c3..ded6489 100644
--- a/drivers/nfc/st21nfca/Makefile
+++ b/drivers/nfc/st21nfca/Makefile
@@ -2,7 +2,7 @@
 # Makefile for ST21NFCA HCI based NFC driver
 #
 
-st21nfca_hci-objs = core.o dep.o se.o
+st21nfca_hci-objs = core.o dep.o se.o vendor_cmds.o
 obj-$(CONFIG_NFC_ST21NFCA) += st21nfca_hci.o
 
 st21nfca_i2c-objs  = i2c.o
diff --git a/drivers/nfc/st21nfca/core.c b/drivers/nfc/st21nfca/core.c
index 6fc60bb..d36e290 100644
--- a/drivers/nfc/st21nfca/core.c
+++ b/drivers/nfc/st21nfca/core.c
@@ -921,6 +921,8 @@ static int st21nfca_hci_event_received(struct nfc_hci_dev 
*hdev, u8 pipe,
event, skb);
case ST21NFCA_APDU_READER_GATE:
return st21nfca_apdu_reader_event_received(hdev, event, skb);
+   case NFC_HCI_LOOPBACK_GATE:
+   return st21nfca_hci_loopback_event_received(hdev, event, skb);
default:
return 1;
}
@@ -1022,6 +1024,7 @@ int st21nfca_hci_probe(void *phy_id, struct nfc_phy_ops 
*phy_ops,
*hdev = info->hdev;
st21nfca_dep_init(info->hdev);
st21nfca_se_init(info->hdev);
+   st21nfca_vendor_cmds_init(info->hdev);
 
return 0;
 
diff --git a/drivers/nfc/st21nfca/se.c b/drivers/nfc/st21nfca/se.c
index d3347c7..e04f603 100644
--- a/drivers/nfc/st21nfca/se.c
+++ b/drivers/nfc/st21nfca/se.c
@@ -167,6 +167,9 @@ int st21nfca_hci_discover_se(struct nfc_hci_dev *hdev)
struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
int se_count = 0;
 
+   if (test_bit(ST21NFCA_FACTORY_MODE, &hdev->quirks))
+   return 0;
+
if (info->se_status->is_uicc_present) {
nfc_add_se(hdev->ndev, NFC_HCI_UICC_HOST_ID, NFC_SE_UICC);
se_count++;
@@ -191,7 +194,6 @@ int st21nfca_hci_enable_se(struct nfc_hci_dev *hdev, u32 
se_idx)
 * Same for eSE.
 */
r = st21nfca_hci_control_se(hdev, se_idx, ST21NFCA_SE_MODE_ON);
-
if (r == ST21NFCA_ESE_HOST_ID) {
st21nfca_se_get_atr(hdev);
r = nfc_hci_send_event(hdev, ST21NFCA_APDU_READER_GATE,
diff --git a/drivers/nfc/st21nfca/st21nfca.h b/drivers/nfc/st21nfca/st21nfca.h
index 70e2d43..94ffb05 100644
--- a/drivers/nfc/st21nfca/st21nfca.h
+++ b/drivers/nfc/st21nfca/st21nfca.h
@@ -66,6 +66,9 @@
 #define ST21NFCA_HCI_MODE  0
 #define ST21NFCA_NUM_DEVICES   256
 
+#define ST21NFCA_VENDOR_OUI0x0080E1 /* STMicroelectronics */
+#define ST21NFCA_FACTORY_MODE  2
+
 struct st21nfca_se_status {
bool is_ese_present;
bool is_uicc_present;
@@ -76,6 +79,50 @@ enum st21nfca_state {
ST21NFCA_ST_READY,
 };
 
+/**
+ * enum nfc_vendor_cmds - supported nfc vendor commands
+ *
+ * @FACTORY_MODE: Allow to set the driver into a mode where no secure element
+ * are activated. It does not consider any NFC_ATTR_VENDOR_DATA.
+ * @HCI_CLEAR_ALL_PIPES: Allow to execute a HCI clear all pipes command.
+ * It does not consider any NFC_ATTR_VENDOR_DATA.
+ * @HCI_DM_PUT_DATA: Allow to configure specific CLF registry as for example
+ *

[PATCH v3 27/35] nfc: st21nfca: Fix host_list verification after secure element activation

2015-10-25 Thread Christophe Ricard
A secure element can be activated in different order. The host_list is
updated keeping a fixed order: .

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st21nfca/se.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/nfc/st21nfca/se.c b/drivers/nfc/st21nfca/se.c
index 6aa4e34..8e05d73 100644
--- a/drivers/nfc/st21nfca/se.c
+++ b/drivers/nfc/st21nfca/se.c
@@ -100,7 +100,7 @@ static int st21nfca_hci_control_se(struct nfc_hci_dev 
*hdev, u32 se_idx,
u8 state)
 {
struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
-   int r;
+   int r, i;
struct sk_buff *sk_host_list;
u8 se_event, host_id;
 
@@ -148,7 +148,10 @@ static int st21nfca_hci_control_se(struct nfc_hci_dev 
*hdev, u32 se_idx,
if (r < 0)
return r;
 
-   host_id = sk_host_list->data[sk_host_list->len - 1];
+   for (i = 0; i < sk_host_list->len &&
+   sk_host_list->data[i] != se_idx; i++)
+   ;
+   host_id = sk_host_list->data[i];
kfree_skb(sk_host_list);
 
if (state == ST21NFCA_SE_MODE_ON && host_id == se_idx)
-- 
2.1.4

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


[PATCH v3 26/35] nfc: st-nci: Fix host_list verification after secure element activation

2015-10-25 Thread Christophe Ricard
A secure element can be activated in different order. The host_list is
updated keeping a fixed order: .

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/se.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/nfc/st-nci/se.c b/drivers/nfc/st-nci/se.c
index 3059baa..1cc24b6 100644
--- a/drivers/nfc/st-nci/se.c
+++ b/drivers/nfc/st-nci/se.c
@@ -423,7 +423,7 @@ static int st_nci_control_se(struct nci_dev *ndev, u8 
se_idx,
 u8 state)
 {
struct st_nci_info *info = nci_get_drvdata(ndev);
-   int r;
+   int r, i;
struct sk_buff *sk_host_list;
u8 host_id;
 
@@ -470,7 +470,10 @@ static int st_nci_control_se(struct nci_dev *ndev, u8 
se_idx,
if (r != NCI_HCI_ANY_OK)
return r;
 
-   host_id = sk_host_list->data[sk_host_list->len - 1];
+   for (i = 0; i < sk_host_list->len &&
+   sk_host_list->data[i] != se_idx; i++)
+   ;
+   host_id = sk_host_list->data[i];
kfree_skb(sk_host_list);
if (state == ST_NCI_SE_MODE_ON && host_id == se_idx)
return se_idx;
-- 
2.1.4

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


[PATCH v3 29/35] nfc: st-nci: Add few code style fixes

2015-10-25 Thread Christophe Ricard
Add some few code style fixes.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/i2c.c | 2 +-
 drivers/nfc/st-nci/se.c  | 2 +-
 net/nfc/nci/hci.c| 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/nfc/st-nci/i2c.c b/drivers/nfc/st-nci/i2c.c
index 172cbc3..2a96f1a 100644
--- a/drivers/nfc/st-nci/i2c.c
+++ b/drivers/nfc/st-nci/i2c.c
@@ -32,7 +32,7 @@
 #define DRIVER_DESC "NCI NFC driver for ST_NCI"
 
 /* ndlc header */
-#define ST_NCI_FRAME_HEADROOM  1
+#define ST_NCI_FRAME_HEADROOM 1
 #define ST_NCI_FRAME_TAILROOM 0
 
 #define ST_NCI_I2C_MIN_SIZE 4   /* PCB(1) + NCI Packet header(3) */
diff --git a/drivers/nfc/st-nci/se.c b/drivers/nfc/st-nci/se.c
index 1cc24b6..dbab722 100644
--- a/drivers/nfc/st-nci/se.c
+++ b/drivers/nfc/st-nci/se.c
@@ -62,7 +62,7 @@ struct st_nci_pipe_info {
 
 #define ST_NCI_EVT_SE_HARD_RESET   0x20
 #define ST_NCI_EVT_TRANSMIT_DATA   0x10
-#define ST_NCI_EVT_WTX_REQUEST 0x11
+#define ST_NCI_EVT_WTX_REQUEST 0x11
 #define ST_NCI_EVT_SE_SOFT_RESET   0x11
 #define ST_NCI_EVT_SE_END_OF_APDU_TRANSFER 0x21
 #define ST_NCI_EVT_HOT_PLUG0x03
diff --git a/net/nfc/nci/hci.c b/net/nfc/nci/hci.c
index 1d6aa5d..984d451 100644
--- a/net/nfc/nci/hci.c
+++ b/net/nfc/nci/hci.c
@@ -405,7 +405,7 @@ static void nci_hci_hcp_message_rx(struct nci_dev *ndev, u8 
pipe,
break;
}
 
-   nci_req_complete(ndev, 0);
+   nci_req_complete(ndev, NCI_STATUS_OK);
 }
 
 static void nci_hci_msg_rx_work(struct work_struct *work)
-- 
2.1.4

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


[PATCH v3 33/35] nfc: st-nci: Make sure irq is not already active when powering the device

2015-10-25 Thread Christophe Ricard
Upon some conditions (timing, CLF errors, platform errors...), the irq might
be already active when powering the device.

Add irq_active variable as a guard to avoid kernel warning message

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/i2c.c | 8 +++-
 drivers/nfc/st-nci/spi.c | 8 +++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/nfc/st-nci/i2c.c b/drivers/nfc/st-nci/i2c.c
index 2a96f1a..25e5042 100644
--- a/drivers/nfc/st-nci/i2c.c
+++ b/drivers/nfc/st-nci/i2c.c
@@ -50,6 +50,8 @@ struct st_nci_i2c_phy {
struct i2c_client *i2c_dev;
struct llt_ndlc *ndlc;
 
+   bool irq_active;
+
unsigned int gpio_reset;
unsigned int irq_polarity;
 
@@ -72,8 +74,10 @@ static int st_nci_i2c_enable(void *phy_id)
gpio_set_value(phy->gpio_reset, 1);
usleep_range(8, 85000);
 
-   if (phy->ndlc->powered == 0)
+   if (phy->ndlc->powered == 0 && phy->irq_active == 0) {
enable_irq(phy->i2c_dev->irq);
+   phy->irq_active = true;
+   }
 
return 0;
 }
@@ -83,6 +87,7 @@ static void st_nci_i2c_disable(void *phy_id)
struct st_nci_i2c_phy *phy = phy_id;
 
disable_irq_nosync(phy->i2c_dev->irq);
+   phy->irq_active = false;
 }
 
 /*
@@ -342,6 +347,7 @@ static int st_nci_i2c_probe(struct i2c_client *client,
return r;
}
 
+   phy->irq_active = true;
r = devm_request_threaded_irq(&client->dev, client->irq, NULL,
st_nci_irq_thread_fn,
phy->irq_polarity | IRQF_ONESHOT,
diff --git a/drivers/nfc/st-nci/spi.c b/drivers/nfc/st-nci/spi.c
index 8897203..bf6643c 100644
--- a/drivers/nfc/st-nci/spi.c
+++ b/drivers/nfc/st-nci/spi.c
@@ -51,6 +51,8 @@ struct st_nci_spi_phy {
struct spi_device *spi_dev;
struct llt_ndlc *ndlc;
 
+   bool irq_active;
+
unsigned int gpio_reset;
unsigned int irq_polarity;
 
@@ -73,8 +75,10 @@ static int st_nci_spi_enable(void *phy_id)
gpio_set_value(phy->gpio_reset, 1);
usleep_range(8, 85000);
 
-   if (phy->ndlc->powered == 0)
+   if (phy->ndlc->powered == 0 && phy->irq_active == 0) {
enable_irq(phy->spi_dev->irq);
+   phy->irq_active = true;
+   }
 
return 0;
 }
@@ -84,6 +88,7 @@ static void st_nci_spi_disable(void *phy_id)
struct st_nci_spi_phy *phy = phy_id;
 
disable_irq_nosync(phy->spi_dev->irq);
+   phy->irq_active = false;
 }
 
 /*
@@ -358,6 +363,7 @@ static int st_nci_spi_probe(struct spi_device *dev)
return r;
}
 
+   phy->irq_active = true;
r = devm_request_threaded_irq(&dev->dev, dev->irq, NULL,
st_nci_irq_thread_fn,
phy->irq_polarity | IRQF_ONESHOT,
-- 
2.1.4

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


[PATCH v3 35/35] nfc: st-nci: Replace st21nfcb by st_nci in makefile

2015-10-25 Thread Christophe Ricard
Replace 1 missing st21nfcb by st_nci

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nfc/st-nci/Makefile b/drivers/nfc/st-nci/Makefile
index ea40ace..439b2fa 100644
--- a/drivers/nfc/st-nci/Makefile
+++ b/drivers/nfc/st-nci/Makefile
@@ -1,5 +1,5 @@
 #
-# Makefile for ST21NFCB NCI based NFC driver
+# Makefile for ST_NCI NCI based NFC driver
 #
 
 st-nci-objs = ndlc.o core.o se.o vendor_cmds.o
-- 
2.1.4

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


[PATCH v3 14/35] nfc: st21nfca: Open NFC_HCI_LINK_MGMT_PIPE

2015-10-25 Thread Christophe Ricard
NFC_HCI_LINK_MGMT_PIPE was never open in nfc_hci_load_session.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st21nfca/core.c | 19 +--
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/drivers/nfc/st21nfca/core.c b/drivers/nfc/st21nfca/core.c
index 67d1c27..819a94a 100644
--- a/drivers/nfc/st21nfca/core.c
+++ b/drivers/nfc/st21nfca/core.c
@@ -203,22 +203,13 @@ static int st21nfca_hci_load_session(struct nfc_hci_dev 
*hdev)
}
 
/*
-* 3 gates have a well known pipe ID.
-* They will never appear in the pipe list
+* 3 gates have a well known pipe ID. Only NFC_HCI_LINK_MGMT_GATE
+* is not yet open at this stage.
 */
-   if (skb_pipe_list->len + 3 < ARRAY_SIZE(st21nfca_gates)) {
-   for (i = skb_pipe_list->len + 3;
-   i < ARRAY_SIZE(st21nfca_gates) - 2; i++) {
-   r = nfc_hci_connect_gate(hdev,
-   NFC_HCI_HOST_CONTROLLER_ID,
-   st21nfca_gates[i].gate,
-   st21nfca_gates[i].pipe);
-   if (r < 0)
-   goto free_list;
-   }
-   }
+   r = nfc_hci_connect_gate(hdev, NFC_HCI_HOST_CONTROLLER_ID,
+NFC_HCI_LINK_MGMT_GATE,
+NFC_HCI_LINK_MGMT_PIPE);
 
-free_list:
kfree_skb(skb_pipe_list);
return r;
 }
-- 
2.1.4

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


[PATCH v3 20/35] nfc: st21nfca: Change st21nfca_gates offset when looking for a pipe in the table

2015-10-25 Thread Christophe Ricard
It is useless to start from index 0 when looking for a gate because only
dynamic pipes are retrieved with 
ST21NFCA_DM_GETINFO(ST21NFCA_DM_GETINFO_PIPE_LIST).

The first dynamic pipe is present at index 3.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st21nfca/core.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/nfc/st21nfca/core.c b/drivers/nfc/st21nfca/core.c
index b4451f8..814d8ff4 100644
--- a/drivers/nfc/st21nfca/core.c
+++ b/drivers/nfc/st21nfca/core.c
@@ -85,12 +85,13 @@ static DECLARE_BITMAP(dev_mask, ST21NFCA_NUM_DEVICES);
 
 static struct nfc_hci_gate st21nfca_gates[] = {
{NFC_HCI_ADMIN_GATE, NFC_HCI_ADMIN_PIPE},
+   {NFC_HCI_LINK_MGMT_GATE, NFC_HCI_LINK_MGMT_PIPE},
+   {ST21NFCA_DEVICE_MGNT_GATE, ST21NFCA_DEVICE_MGNT_PIPE},
+
{NFC_HCI_LOOPBACK_GATE, NFC_HCI_INVALID_PIPE},
{NFC_HCI_ID_MGMT_GATE, NFC_HCI_INVALID_PIPE},
-   {NFC_HCI_LINK_MGMT_GATE, NFC_HCI_LINK_MGMT_PIPE},
{NFC_HCI_RF_READER_B_GATE, NFC_HCI_INVALID_PIPE},
{NFC_HCI_RF_READER_A_GATE, NFC_HCI_INVALID_PIPE},
-   {ST21NFCA_DEVICE_MGNT_GATE, ST21NFCA_DEVICE_MGNT_PIPE},
{ST21NFCA_RF_READER_F_GATE, NFC_HCI_INVALID_PIPE},
{ST21NFCA_RF_READER_14443_3_A_GATE, NFC_HCI_INVALID_PIPE},
{ST21NFCA_RF_READER_ISO15693_GATE, NFC_HCI_INVALID_PIPE},
@@ -183,7 +184,7 @@ static int st21nfca_hci_load_session(struct nfc_hci_dev 
*hdev)
continue;
}
 
-   for (j = 0; (j < ARRAY_SIZE(st21nfca_gates)) &&
+   for (j = 3; (j < ARRAY_SIZE(st21nfca_gates)) &&
(st21nfca_gates[j].gate != info->dst_gate_id) ; j++)
;
 
-- 
2.1.4

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


[PATCH v3 23/35] nfc: netlink: Add missing NFC_ATTR comments

2015-10-25 Thread Christophe Ricard
NFC_CMD_ACTIVATE_TARGET and NFC_ATTR_SE_PARAMS comments are missing.

Signed-off-by: Christophe Ricard 
---
 include/uapi/linux/nfc.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/uapi/linux/nfc.h b/include/uapi/linux/nfc.h
index dd3f753..399f39f 100644
--- a/include/uapi/linux/nfc.h
+++ b/include/uapi/linux/nfc.h
@@ -86,6 +86,7 @@
  * for this event is the application ID (AID).
  * @NFC_CMD_GET_SE: Dump all discovered secure elements from an NFC controller.
  * @NFC_CMD_SE_IO: Send/Receive APDUs to/from the selected secure element.
+ * @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.
  */
@@ -156,6 +157,7 @@ enum nfc_commands {
  * @NFC_ATTR_APDU: Secure element APDU
  * @NFC_ATTR_TARGET_ISO15693_DSFID: ISO 15693 Data Storage Format Identifier
  * @NFC_ATTR_TARGET_ISO15693_UID: ISO 15693 Unique Identifier
+ * @NFC_ATTR_SE_PARAMS: Parameters data from an evt_transaction
  * @NFC_ATTR_VENDOR_ID: NFC manufacturer unique ID, typically an OUI
  * @NFC_ATTR_VENDOR_SUBCMD: Vendor specific sub command
  * @NFC_ATTR_VENDOR_DATA: Vendor specific data, to be optionally passed
-- 
2.1.4

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


[PATCH v3 17/35] nfc: st-nci: initialize gate_count in st_nci_hci_network_init

2015-10-25 Thread Christophe Ricard
When initializing ndev->hci_dev->init_data, only gates field was set.
gate_count needs to be initialized as well.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/se.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/nfc/st-nci/se.c b/drivers/nfc/st-nci/se.c
index df2dc54..11e49a5 100644
--- a/drivers/nfc/st-nci/se.c
+++ b/drivers/nfc/st-nci/se.c
@@ -536,6 +536,7 @@ static int st_nci_hci_network_init(struct nci_dev *ndev)
if (!conn_info)
goto free_dest_params;
 
+   ndev->hci_dev->init_data.gate_count = ARRAY_SIZE(st_nci_gates);
memcpy(ndev->hci_dev->init_data.gates, st_nci_gates,
   sizeof(st_nci_gates));
 
-- 
2.1.4

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


[PATCH v3 25/35] nfc: st-nci: Increase waiting time between 2 secure element activation

2015-10-25 Thread Christophe Ricard
After internal discussion, it appears this timing should be increase to
20 ms for interoperability reason.

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/se.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nfc/st-nci/se.c b/drivers/nfc/st-nci/se.c
index 147e2d9..3059baa 100644
--- a/drivers/nfc/st-nci/se.c
+++ b/drivers/nfc/st-nci/se.c
@@ -463,7 +463,7 @@ static int st_nci_control_se(struct nci_dev *ndev, u8 
se_idx,
 */
if (info->se_info.se_status->is_ese_present &&
info->se_info.se_status->is_uicc_present)
-   usleep_range(3000, 5000);
+   usleep_range(15000, 2);
 
r = nci_hci_get_param(ndev, NCI_HCI_ADMIN_GATE,
NCI_HCI_ADMIN_PARAM_HOST_LIST, &sk_host_list);
-- 
2.1.4

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


[PATCH v3 19/35] nfc: st-nci: Change st_nci_gates offset when looking for a pipe in the table

2015-10-25 Thread Christophe Ricard
It is useless to start from index 0 when looking for a gate because only
dynamic pipes are retrieved with ST_NCI_DM_GETINFO(ST_NCI_DM_GETINFO_PIPE_LIST).

The first dynamic pipe is present at index 3.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/se.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nfc/st-nci/se.c b/drivers/nfc/st-nci/se.c
index 5d1747d..4c98346 100644
--- a/drivers/nfc/st-nci/se.c
+++ b/drivers/nfc/st-nci/se.c
@@ -228,7 +228,7 @@ int st_nci_hci_load_session(struct nci_dev *ndev)
continue;
}
 
-   for (j = 0; (j < ARRAY_SIZE(st_nci_gates)) &&
+   for (j = 3; (j < ARRAY_SIZE(st_nci_gates)) &&
 (st_nci_gates[j].gate != dm_pipe_info->dst_gate_id); j++)
;
 
-- 
2.1.4

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


[PATCH v3 16/35] nfc: st21nfca: Keep st21nfca_gates unchanged in load_session

2015-10-25 Thread Christophe Ricard
We need to keep initial st_nci_gates values in order for
nfc_hci_dev_connect_gates to create and open pipe when necessary.

For example after a firmware update CLF pipes are cleared. Changing pipe
values in st21nfca_gates was causing nfc_hci_dev_connect_gates not using
accurate pipes value.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st21nfca/core.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/nfc/st21nfca/core.c b/drivers/nfc/st21nfca/core.c
index 819a94a..b4451f8 100644
--- a/drivers/nfc/st21nfca/core.c
+++ b/drivers/nfc/st21nfca/core.c
@@ -190,14 +190,14 @@ static int st21nfca_hci_load_session(struct nfc_hci_dev 
*hdev)
if (j < ARRAY_SIZE(st21nfca_gates) &&
st21nfca_gates[j].gate == info->dst_gate_id &&
ST21NFCA_DM_IS_PIPE_OPEN(info->pipe_state)) {
-   st21nfca_gates[j].pipe = pipe_info[2];
+   hdev->init_data.gates[j].pipe = pipe_info[2];
 
hdev->gate2pipe[st21nfca_gates[j].gate] =
-   st21nfca_gates[j].pipe;
-   hdev->pipes[st21nfca_gates[j].pipe].gate =
-   st21nfca_gates[j].gate;
-   hdev->pipes[st21nfca_gates[j].pipe].dest_host =
-   info->src_host_id;
+   pipe_info[2];
+   hdev->pipes[pipe_info[2]].gate =
+   st21nfca_gates[j].gate;
+   hdev->pipes[pipe_info[2]].dest_host =
+   info->src_host_id;
}
kfree_skb(skb_pipe_info);
}
-- 
2.1.4

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


[PATCH v3 18/35] nfc: st-nci: Add support for NCI_HCI_IDENTITY_MGMT_GATE

2015-10-25 Thread Christophe Ricard
NCI_HCI_IDENTITY_MGMT_GATE might be useful to get information for example
about hardware or firmware version.

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/se.c| 3 +++
 include/net/nfc/nci_core.h | 1 +
 2 files changed, 4 insertions(+)

diff --git a/drivers/nfc/st-nci/se.c b/drivers/nfc/st-nci/se.c
index 11e49a5..5d1747d 100644
--- a/drivers/nfc/st-nci/se.c
+++ b/drivers/nfc/st-nci/se.c
@@ -112,6 +112,9 @@ static struct nci_hci_gate st_nci_gates[] = {
{ST_NCI_DEVICE_MGNT_GATE, ST_NCI_DEVICE_MGNT_PIPE,
ST_NCI_HOST_CONTROLLER_ID},
 
+   {NCI_HCI_IDENTITY_MGMT_GATE, NCI_HCI_INVALID_PIPE,
+   ST_NCI_HOST_CONTROLLER_ID},
+
/* Secure element pipes are created by secure element host */
{ST_NCI_CONNECTIVITY_GATE, NCI_HCI_DO_NOT_OPEN_PIPE,
ST_NCI_HOST_CONTROLLER_ID},
diff --git a/include/net/nfc/nci_core.h b/include/net/nfc/nci_core.h
index b2f2e04..377f3de 100644
--- a/include/net/nfc/nci_core.h
+++ b/include/net/nfc/nci_core.h
@@ -125,6 +125,7 @@ struct nci_conn_info {
 
 /* Gates */
 #define NCI_HCI_ADMIN_GATE 0x00
+#define NCI_HCI_IDENTITY_MGMT_GATE 0x05
 #define NCI_HCI_LINK_MGMT_GATE 0x06
 
 /* Pipes */
-- 
2.1.4

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


[PATCH v3 22/35] nfc: st-nci: Add error messages when an unexpected HCI event occurs

2015-10-25 Thread Christophe Ricard
Potentially an unexpected HCI event may occur because of a firmware bug.
It could be transparent for the user but at least log this.

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/se.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/nfc/st-nci/se.c b/drivers/nfc/st-nci/se.c
index 7ec4dba..2812884 100644
--- a/drivers/nfc/st-nci/se.c
+++ b/drivers/nfc/st-nci/se.c
@@ -280,6 +280,8 @@ static void st_nci_hci_admin_event_received(struct nci_dev 
*ndev,
}
}
break;
+   default:
+   nfc_err(&ndev->nfc_dev->dev, "Unexpected event on admin 
gate\n");
}
 }
 
@@ -303,6 +305,9 @@ static int st_nci_hci_apdu_reader_event_received(struct 
nci_dev *ndev,
mod_timer(&info->se_info.bwi_timer, jiffies +
  msecs_to_jiffies(info->se_info.wt_timeout));
break;
+   default:
+   nfc_err(&ndev->nfc_dev->dev, "Unexpected event on apdu reader 
gate\n");
+   return 1;
}
 
kfree_skb(skb);
@@ -357,6 +362,7 @@ static int st_nci_hci_connectivity_event_received(struct 
nci_dev *ndev,
r = nfc_se_transaction(ndev->nfc_dev, host, transaction);
break;
default:
+   nfc_err(&ndev->nfc_dev->dev, "Unexpected event on connectivity 
gate\n");
return 1;
}
kfree_skb(skb);
-- 
2.1.4

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


[PATCH v3 21/35] nfc: st-nci: Add support for proprietary commands for factory tests

2015-10-25 Thread Christophe Ricard
Add support for proprietary commands useful mainly for factory testings.
Here is a list:
- FACTORY_MODE: Allow to set the driver into a mode where no secure element
are activated. It does not consider any NFC_ATTR_VENDOR_DATA.
- HCI_CLEAR_ALL_PIPES: Allow to execute a HCI clear all pipes command.
It does not consider any NFC_ATTR_VENDOR_DATA.
- HCI_DM_PUT_DATA: Allow to configure specific CLF registry as for example
RF trimmings or low level drivers configurations (I2C, SPI, SWP).
- HCI_DM_UPDATE_AID: Allow to configure an AID routing into the CLF routing
table following RF technology, CLF mode or protocol.
- HCI_DM_GET_INFO: Allow to retrieve CLF information.
- HCI_DM_GET_DATA: Allow to retrieve CLF configurable data such as low
level drivers configurations or RF trimmings.
- HCI_DM_DIRECT_LOAD: Allow to load a firmware into the CLF. A complete
packet can be more than 8KB.
- HCI_DM_RESET: Allow to run a CLF reset in order to "commit" CLF
configuration changes without CLF power off.
-  HCI_GET_PARAM: Allow to retrieve an HCI CLF parameter (for example the
white list).
- HCI_DM_FIELD_GENERATOR: Allow to generate different kind of RF
technology. When using this command to anti-collision is done.
- HCI_LOOPBACK: Allow to echo a command and test the Dh to CLF
connectivity.
- HCI_DM_VDC_MEASUREMENT_VALUE: Allow to measure the field applied on the
CLF antenna. A value between 0 and 0x0f is returned. 0 is maximum.
- HCI_DM_FWUPD_START: Allow to put CLF into firmware update mode. It is a
specific CLF command as there is no GPIO for this.
- HCI_DM_FWUPD_END:  Allow to complete firmware update.
- HCI_DM_VDC_VALUE_COMPARISON: Allow to compare the field applied on the
CLF antenna to a reference value.
- MANUFACTURER_SPECIFIC: Allow to retrieve manufacturer specific data
received during a NCI_CORE_INIT_CMD.

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/Makefile  |   2 +-
 drivers/nfc/st-nci/core.c|  13 +-
 drivers/nfc/st-nci/se.c  |  29 ++-
 drivers/nfc/st-nci/st-nci.h  |  68 ++
 drivers/nfc/st-nci/vendor_cmds.c | 516 +++
 include/net/nfc/nci_core.h   |   1 +
 6 files changed, 619 insertions(+), 10 deletions(-)
 create mode 100644 drivers/nfc/st-nci/vendor_cmds.c

diff --git a/drivers/nfc/st-nci/Makefile b/drivers/nfc/st-nci/Makefile
index 594c63d..ea40ace 100644
--- a/drivers/nfc/st-nci/Makefile
+++ b/drivers/nfc/st-nci/Makefile
@@ -2,7 +2,7 @@
 # Makefile for ST21NFCB NCI based NFC driver
 #
 
-st-nci-objs = ndlc.o core.o se.o
+st-nci-objs = ndlc.o core.o se.o vendor_cmds.o
 obj-$(CONFIG_NFC_ST_NCI) += st-nci.o
 
 st-nci_i2c-objs = i2c.o
diff --git a/drivers/nfc/st-nci/core.c b/drivers/nfc/st-nci/core.c
index 96997e6..6b083ed 100644
--- a/drivers/nfc/st-nci/core.c
+++ b/drivers/nfc/st-nci/core.c
@@ -152,14 +152,23 @@ int st_nci_probe(struct llt_ndlc *ndlc, int phy_headroom,
 
nci_set_drvdata(ndlc->ndev, info);
 
+   r = st_nci_vendor_cmds_init(ndlc->ndev);
+   if (r) {
+   pr_err("Cannot register proprietary vendor cmds\n");
+   goto err_reg_dev;
+   }
+
r = nci_register_device(ndlc->ndev);
if (r) {
pr_err("Cannot register nfc device to nci core\n");
-   nci_free_device(ndlc->ndev);
-   return r;
+   goto err_reg_dev;
}
 
return st_nci_se_init(ndlc->ndev);
+
+err_reg_dev:
+   nci_free_device(ndlc->ndev);
+   return r;
 }
 EXPORT_SYMBOL_GPL(st_nci_probe);
 
diff --git a/drivers/nfc/st-nci/se.c b/drivers/nfc/st-nci/se.c
index 4c98346..7ec4dba 100644
--- a/drivers/nfc/st-nci/se.c
+++ b/drivers/nfc/st-nci/se.c
@@ -39,7 +39,6 @@ struct st_nci_pipe_info {
 #define ST_NCI_ESE_HOST_ID0xc0
 
 /* Gates */
-#define ST_NCI_DEVICE_MGNT_GATE   0x01
 #define ST_NCI_APDU_READER_GATE   0xf0
 #define ST_NCI_CONNECTIVITY_GATE  0x41
 
@@ -114,6 +113,8 @@ static struct nci_hci_gate st_nci_gates[] = {
 
{NCI_HCI_IDENTITY_MGMT_GATE, NCI_HCI_INVALID_PIPE,
ST_NCI_HOST_CONTROLLER_ID},
+   {NCI_HCI_LOOPBACK_GATE, NCI_HCI_INVALID_PIPE,
+   ST_NCI_HOST_CONTROLLER_ID},
 
/* Secure element pipes are created by secure element host */
{ST_NCI_CONNECTIVITY_GATE, NCI_HCI_DO_NOT_OPEN_PIPE,
@@ -376,8 +377,10 @@ void st_nci_hci_event_received(struct nci_dev *ndev, u8 
pipe,
st_nci_hci_apdu_reader_event_received(ndev, event, skb);
break;
case ST_NCI_CONNECTIVITY_GATE:
-   st_nci_hci_connectivity_event_received(ndev, host, event,
-skb);
+   st_nci_hci_connectivity_event_received(ndev, host, event, skb);
+   break;
+   case NCI_HCI_LOOPBACK_GATE:
+   st_nci_hci_loopback_event_received(ndev, event, skb);
break;
}
 }
@@ -50

[PATCH v3 15/35] nfc: st-nci: Keep st_nci_gates unchanged in load_session

2015-10-25 Thread Christophe Ricard
We need to keep initial st_nci_gates values in order for
nci_hci_dev_connect_gates to create and open pipe when necessary.

For example after a firmware update CLF pipes are cleared. Changing pipe
values in st_nci_gates was causing nci_hci_dev_connect_gates not using
accurate pipes value.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/se.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/nfc/st-nci/se.c b/drivers/nfc/st-nci/se.c
index 3522165..df2dc54 100644
--- a/drivers/nfc/st-nci/se.c
+++ b/drivers/nfc/st-nci/se.c
@@ -232,13 +232,13 @@ int st_nci_hci_load_session(struct nci_dev *ndev)
if (j < ARRAY_SIZE(st_nci_gates) &&
st_nci_gates[j].gate == dm_pipe_info->dst_gate_id &&
ST_NCI_DM_IS_PIPE_OPEN(dm_pipe_info->pipe_state)) {
-   st_nci_gates[j].pipe = pipe_info[2];
+   ndev->hci_dev->init_data.gates[j].pipe = pipe_info[2];
 
ndev->hci_dev->gate2pipe[st_nci_gates[j].gate] =
-   st_nci_gates[j].pipe;
-   ndev->hci_dev->pipes[st_nci_gates[j].pipe].gate =
+   pipe_info[2];
+   ndev->hci_dev->pipes[pipe_info[2]].gate =
st_nci_gates[j].gate;
-   ndev->hci_dev->pipes[st_nci_gates[j].pipe].host =
+   ndev->hci_dev->pipes[pipe_info[2]].host =
dm_pipe_info->src_host_id;
}
kfree_skb(skb_pipe_info);
-- 
2.1.4

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


[PATCH v3 24/35] nfc: st-nci: Add ese-present/uicc-present dts properties

2015-10-25 Thread Christophe Ricard
In order to align with st21nfca, dts configuration properties ese_present
and uicc_present are made available in st-nci driver.

So far, in early development firmware, because nci_nfcee_mode_set(DISABLE)
was not supported pushed us to try to enable during the secure element
discovery phase.

After several trials on commercial and qualified firmware it appears that
nci_nfcee_mode_set(ENABLE) and nci_nfcee_mode_set(DISABLE) are properly
supported.

Such feature also help us to eventually save some time (~5ms) if only
one secure element is connected.

Acked-by: Rob Herring 
Signed-off-by: Christophe Ricard 
---
 .../devicetree/bindings/net/nfc/st-nci-i2c.txt |  7 ++
 .../devicetree/bindings/net/nfc/st-nci-spi.txt |  9 +-
 drivers/nfc/st-nci/core.c  |  4 +-
 drivers/nfc/st-nci/i2c.c   | 12 ++-
 drivers/nfc/st-nci/ndlc.c  |  6 +-
 drivers/nfc/st-nci/ndlc.h  |  5 +-
 drivers/nfc/st-nci/se.c| 98 ++
 drivers/nfc/st-nci/spi.c   | 12 ++-
 drivers/nfc/st-nci/st-nci.h| 13 ++-
 include/linux/platform_data/st-nci.h   |  2 +
 10 files changed, 122 insertions(+), 46 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/nfc/st-nci-i2c.txt 
b/Documentation/devicetree/bindings/net/nfc/st-nci-i2c.txt
index d707588..263732e 100644
--- a/Documentation/devicetree/bindings/net/nfc/st-nci-i2c.txt
+++ b/Documentation/devicetree/bindings/net/nfc/st-nci-i2c.txt
@@ -11,6 +11,10 @@ Required properties:
 Optional SoC Specific Properties:
 - pinctrl-names: Contains only one value - "default".
 - pintctrl-0: Specifies the pin control groups used for this controller.
+- ese-present: Specifies that an ese is physically connected to the nfc
+controller.
+- uicc-present: Specifies that the uicc swp signal can be physically
+connected to the nfc controller.
 
 Example (for ARM-based BeagleBoard xM with ST21NFCB on I2C2):
 
@@ -29,5 +33,8 @@ Example (for ARM-based BeagleBoard xM with ST21NFCB on I2C2):
interrupts = <2 IRQ_TYPE_LEVEL_HIGH>;
 
reset-gpios = <&gpio5 29 GPIO_ACTIVE_HIGH>;
+
+   ese-present;
+   uicc-present;
};
 };
diff --git a/Documentation/devicetree/bindings/net/nfc/st-nci-spi.txt 
b/Documentation/devicetree/bindings/net/nfc/st-nci-spi.txt
index 525681b..711ca85 100644
--- a/Documentation/devicetree/bindings/net/nfc/st-nci-spi.txt
+++ b/Documentation/devicetree/bindings/net/nfc/st-nci-spi.txt
@@ -2,7 +2,7 @@
 
 Required properties:
 - compatible: Should be "st,st21nfcb-spi"
-- spi-max-frequency: Maximum SPI frequency (<= 1000).
+- spi-max-frequency: Maximum SPI frequency (<= 400).
 - interrupt-parent: phandle for the interrupt gpio controller
 - interrupts: GPIO interrupt to which the chip is connected
 - reset-gpios: Output GPIO pin used to reset the ST21NFCB
@@ -10,6 +10,10 @@ Required properties:
 Optional SoC Specific Properties:
 - pinctrl-names: Contains only one value - "default".
 - pintctrl-0: Specifies the pin control groups used for this controller.
+- ese-present: Specifies that an ese is physically connected to the nfc
+controller.
+- uicc-present: Specifies that the uicc swp signal can be physically
+connected to the nfc controller.
 
 Example (for ARM-based BeagleBoard xM with ST21NFCB on SPI4):
 
@@ -27,5 +31,8 @@ Example (for ARM-based BeagleBoard xM with ST21NFCB on SPI4):
interrupts = <2 IRQ_TYPE_EDGE_RISING>;
 
reset-gpios = <&gpio5 29 GPIO_ACTIVE_HIGH>;
+
+   ese-present;
+   uicc-present;
};
 };
diff --git a/drivers/nfc/st-nci/core.c b/drivers/nfc/st-nci/core.c
index 6b083ed..ccf7237 100644
--- a/drivers/nfc/st-nci/core.c
+++ b/drivers/nfc/st-nci/core.c
@@ -123,7 +123,7 @@ static struct nci_ops st_nci_ops = {
 };
 
 int st_nci_probe(struct llt_ndlc *ndlc, int phy_headroom,
-  int phy_tailroom)
+int phy_tailroom, struct st_nci_se_status *se_status)
 {
struct st_nci_info *info;
int r;
@@ -164,7 +164,7 @@ int st_nci_probe(struct llt_ndlc *ndlc, int phy_headroom,
goto err_reg_dev;
}
 
-   return st_nci_se_init(ndlc->ndev);
+   return st_nci_se_init(ndlc->ndev, se_status);
 
 err_reg_dev:
nci_free_device(ndlc->ndev);
diff --git a/drivers/nfc/st-nci/i2c.c b/drivers/nfc/st-nci/i2c.c
index 02e585f..172cbc3 100644
--- a/drivers/nfc/st-nci/i2c.c
+++ b/drivers/nfc/st-nci/i2c.c
@@ -52,6 +52,8 @@ struct st_nci_i2c_phy {
 
unsigned int gpio_reset;
unsigned int irq_polarity;
+
+   struct st_nci_se_status se_status;
 };
 
 #define I2C_DUMP_SKB(info, skb)\
@@ -245,6 +247,11 @@ static int st_nci_i2c_of_request_resources(struct 
i2c_c

[PATCH v3 11/35] nfc: st-nci: Remove ndev->hci_dev->init_data.gates initialization in load_session

2015-10-25 Thread Christophe Ricard
ndev->hci_dev->init_data.gates is already initialized in st_nci_hci_network.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/se.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/nfc/st-nci/se.c b/drivers/nfc/st-nci/se.c
index 4acb945..3ffac0e 100644
--- a/drivers/nfc/st-nci/se.c
+++ b/drivers/nfc/st-nci/se.c
@@ -244,9 +244,6 @@ int st_nci_hci_load_session(struct nci_dev *ndev)
kfree_skb(skb_pipe_info);
}
 
-   memcpy(ndev->hci_dev->init_data.gates, st_nci_gates,
-  sizeof(st_nci_gates));
-
kfree_skb(skb_pipe_list);
return r;
 }
-- 
2.1.4

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


[PATCH v3 09/35] nfc: nci: Add a call to nci_hci_clear_all_pipes at HCI initial activation.

2015-10-25 Thread Christophe Ricard
When session_id is filled to ff, the pipe configuration is probably
incorrect.

Signed-off-by: Christophe Ricard 
---
 net/nfc/nci/hci.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/net/nfc/nci/hci.c b/net/nfc/nci/hci.c
index 43d7931..a937bc6 100644
--- a/net/nfc/nci/hci.c
+++ b/net/nfc/nci/hci.c
@@ -701,6 +701,10 @@ int nci_hci_dev_session_init(struct nci_dev *ndev)
/* Restore gate<->pipe table from some proprietary location. */
r = ndev->ops->hci_load_session(ndev);
} else {
+   r = nci_hci_clear_all_pipes(ndev);
+   if (r < 0)
+   goto exit;
+
r = nci_hci_dev_connect_gates(ndev,
  
ndev->hci_dev->init_data.gate_count,
  ndev->hci_dev->init_data.gates);
-- 
2.1.4

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


[PATCH v3 00/35] Few fixes and st21nfca/st-nci vendor_cmds support

2015-10-25 Thread Christophe Ricard
Hi Samuel,

Please find in the following patchset severals fixes as well as vendor_cmds 
support
for st21nfca and st-nci.
vendor_cmds includes production test, trimmings & firmware update commands.

v3:
- Fix st21nfca vendor_cmds by exporting nfc_llc_start/stop
- Remove #include "st21nfca_vendor_cmds.h" in vendor_cmds as this one does not 
exist.

v2:
- Propose a more elegant way to switch between NFC target mode (SLEEP, IDLE).
- Remove st21nfca_ and st-nci_ file name prefix.
- Merge st21nfca_xxx.h headers into st21nfca.h. Same for st-nci_xxx.h

Best Regards
Christophe

Christophe Ricard (35):
  nfc: st-nci: Align st-nci driver with other nfc driver
  nfc: st-nci: include st-nci.h instead of ndlc.h
  nfc: st21nfca: Align st21nfca driver with other nfc driver
  nfc: st-nci: Fix incorrect spi buffer size
  nfc: nci: Fix incorrect data chaining when sending data
  nfc: nci: Fix improper management of HCI return code
  nfc: nci: extract pipe value using NCI_HCP_MSG_GET_PIPE
  nfc: nci: add nci_hci_clear_all_pipes functions
  nfc: nci: Add a call to nci_hci_clear_all_pipes at HCI initial
activation.
  nfc: nci: add capability to create pipe on specific gate in
nci_hci_connect_gate
  nfc: st-nci: Remove ndev->hci_dev->init_data.gates initialization in
load_session
  nfc: st21nfca: Remove hdev->init_data.gates initialization in
load_session
  nfc: st-nci: Open NCI_HCI_LINK_MGMT_PIPE
  nfc: st21nfca: Open NFC_HCI_LINK_MGMT_PIPE
  nfc: st-nci: Keep st_nci_gates unchanged in load_session
  nfc: st21nfca: Keep st21nfca_gates unchanged in load_session
  nfc: st-nci: initialize gate_count in st_nci_hci_network_init
  nfc: st-nci: Add support for NCI_HCI_IDENTITY_MGMT_GATE
  nfc: st-nci: Change st_nci_gates offset when looking for a pipe in the
table
  nfc: st21nfca: Change st21nfca_gates offset when looking for a pipe in
the table
  nfc: st-nci: Add support for proprietary commands for factory tests
  nfc: st-nci: Add error messages when an unexpected HCI event occurs
  nfc: netlink: Add missing NFC_ATTR comments
  nfc: st-nci: Add ese-present/uicc-present dts properties
  nfc: st-nci: Increase waiting time between 2 secure element activation
  nfc: st-nci: Fix host_list verification after secure element
activation
  nfc: st21nfca: Fix host_list verification after secure element
activation
  nfc: netlink: Add mode parameter to deactivate_target functions
  nfc: st-nci: Add few code style fixes
  nfc: st21nfca: Add few code style fixes
  nfc: st21nfca: Add support for proprietary commands for factory tests
  nfc: st21nfca: Add error messages when an unexpected HCI event occurs
  nfc: st-nci: Make sure irq is not already active when powering the
device
  nfc: st-nci: remove duplicated skb dump
  nfc: st-nci: Replace st21nfcb by st_nci in makefile

 .../devicetree/bindings/net/nfc/st-nci-i2c.txt |7 +
 .../devicetree/bindings/net/nfc/st-nci-spi.txt |9 +-
 drivers/nfc/st-nci/Makefile|4 +-
 drivers/nfc/st-nci/core.c  |   18 +-
 drivers/nfc/st-nci/i2c.c   |   35 +-
 drivers/nfc/st-nci/ndlc.c  |7 +-
 drivers/nfc/st-nci/ndlc.h  |5 +-
 drivers/nfc/st-nci/se.c|  166 ++-
 drivers/nfc/st-nci/se.h|   61 --
 drivers/nfc/st-nci/spi.c   |   37 +-
 drivers/nfc/st-nci/st-nci.h|  117 ++-
 drivers/nfc/st-nci/vendor_cmds.c   |  516 ++
 drivers/nfc/st21nfca/Makefile  |2 +-
 drivers/nfc/st21nfca/core.c| 1056 +++
 drivers/nfc/st21nfca/dep.c |  689 +
 drivers/nfc/st21nfca/i2c.c |1 +
 drivers/nfc/st21nfca/se.c  |  428 
 drivers/nfc/st21nfca/st21nfca.c| 1064 
 drivers/nfc/st21nfca/st21nfca.h|  148 ++-
 drivers/nfc/st21nfca/st21nfca_dep.c|  689 -
 drivers/nfc/st21nfca/st21nfca_dep.h|   43 -
 drivers/nfc/st21nfca/st21nfca_se.c |  420 
 drivers/nfc/st21nfca/st21nfca_se.h |   63 --
 drivers/nfc/st21nfca/vendor_cmds.c |  369 +++
 include/linux/platform_data/st-nci.h   |2 +
 include/net/nfc/nci_core.h |3 +
 include/net/nfc/nfc.h  |2 +-
 include/uapi/linux/nfc.h   |2 +
 net/nfc/core.c |4 +-
 net/nfc/digital_core.c |3 +-
 net/nfc/hci/core.c |3 +-
 net/nfc/hci/llc.c  |2 +
 net/nfc/nci/core.c |   1

[PATCH v3 08/35] nfc: nci: add nci_hci_clear_all_pipes functions

2015-10-25 Thread Christophe Ricard
nci_hci_clear_all_pipes might be use full in some cases for example after
a firmware update.

Signed-off-by: Christophe Ricard 
---
 include/net/nfc/nci_core.h |  1 +
 net/nfc/nci/hci.c  | 15 +++
 2 files changed, 16 insertions(+)

diff --git a/include/net/nfc/nci_core.h b/include/net/nfc/nci_core.h
index d0d0f1e..b2f2e04 100644
--- a/include/net/nfc/nci_core.h
+++ b/include/net/nfc/nci_core.h
@@ -305,6 +305,7 @@ int nci_hci_set_param(struct nci_dev *ndev, u8 gate, u8 idx,
  const u8 *param, size_t param_len);
 int nci_hci_get_param(struct nci_dev *ndev, u8 gate, u8 idx,
  struct sk_buff **skb);
+int nci_hci_clear_all_pipes(struct nci_dev *ndev);
 int nci_hci_dev_session_init(struct nci_dev *ndev);
 
 static inline struct sk_buff *nci_skb_alloc(struct nci_dev *ndev,
diff --git a/net/nfc/nci/hci.c b/net/nfc/nci/hci.c
index abe0200..43d7931 100644
--- a/net/nfc/nci/hci.c
+++ b/net/nfc/nci/hci.c
@@ -70,6 +70,7 @@ struct nci_hcp_packet {
 #define NCI_HCI_ANY_SET_PARAMETER  0x01
 #define NCI_HCI_ANY_GET_PARAMETER  0x02
 #define NCI_HCI_ANY_CLOSE_PIPE 0x04
+#define NCI_HCI_ADM_CLEAR_ALL_PIPE 0x14
 
 #define NCI_HFP_NO_CHAINING0x80
 
@@ -265,6 +266,20 @@ int nci_hci_send_cmd(struct nci_dev *ndev, u8 gate, u8 cmd,
 }
 EXPORT_SYMBOL(nci_hci_send_cmd);
 
+int nci_hci_clear_all_pipes(struct nci_dev *ndev)
+{
+   int r;
+
+   r = nci_hci_send_cmd(ndev, NCI_HCI_ADMIN_GATE,
+NCI_HCI_ADM_CLEAR_ALL_PIPE, NULL, 0, NULL);
+   if (r < 0)
+   return r;
+
+   nci_hci_reset_pipes(ndev->hci_dev);
+   return r;
+}
+EXPORT_SYMBOL(nci_hci_clear_all_pipes);
+
 static void nci_hci_event_received(struct nci_dev *ndev, u8 pipe,
   u8 event, struct sk_buff *skb)
 {
-- 
2.1.4

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


[PATCH v3 03/35] nfc: st21nfca: Align st21nfca driver with other nfc driver

2015-10-25 Thread Christophe Ricard
Align st21nfca driver with or nfc driver:
- Remove st21nfca_ prefix
- Merge st21nfca_se.h, st21nfca_dep.h in st21nfca.h

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st21nfca/Makefile   |2 +-
 drivers/nfc/st21nfca/core.c | 1062 ++
 drivers/nfc/st21nfca/dep.c  |  688 ++
 drivers/nfc/st21nfca/se.c   |  419 ++
 drivers/nfc/st21nfca/st21nfca.c | 1064 ---
 drivers/nfc/st21nfca/st21nfca.h |   98 +++-
 drivers/nfc/st21nfca/st21nfca_dep.c |  689 ---
 drivers/nfc/st21nfca/st21nfca_dep.h |   43 --
 drivers/nfc/st21nfca/st21nfca_se.c  |  420 --
 drivers/nfc/st21nfca/st21nfca_se.h  |   63 ---
 10 files changed, 2249 insertions(+), 2299 deletions(-)
 create mode 100644 drivers/nfc/st21nfca/core.c
 create mode 100644 drivers/nfc/st21nfca/dep.c
 create mode 100644 drivers/nfc/st21nfca/se.c
 delete mode 100644 drivers/nfc/st21nfca/st21nfca.c
 delete mode 100644 drivers/nfc/st21nfca/st21nfca_dep.c
 delete mode 100644 drivers/nfc/st21nfca/st21nfca_dep.h
 delete mode 100644 drivers/nfc/st21nfca/st21nfca_se.c
 delete mode 100644 drivers/nfc/st21nfca/st21nfca_se.h

diff --git a/drivers/nfc/st21nfca/Makefile b/drivers/nfc/st21nfca/Makefile
index 97edab4..82434c3 100644
--- a/drivers/nfc/st21nfca/Makefile
+++ b/drivers/nfc/st21nfca/Makefile
@@ -2,7 +2,7 @@
 # Makefile for ST21NFCA HCI based NFC driver
 #
 
-st21nfca_hci-objs = st21nfca.o st21nfca_dep.o st21nfca_se.o
+st21nfca_hci-objs = core.o dep.o se.o
 obj-$(CONFIG_NFC_ST21NFCA) += st21nfca_hci.o
 
 st21nfca_i2c-objs  = i2c.o
diff --git a/drivers/nfc/st21nfca/core.c b/drivers/nfc/st21nfca/core.c
new file mode 100644
index 000..42f1974
--- /dev/null
+++ b/drivers/nfc/st21nfca/core.c
@@ -0,0 +1,1062 @@
+/*
+ * HCI based Driver for STMicroelectronics NFC Chip
+ *
+ * Copyright (C) 2014  STMicroelectronics SAS. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "st21nfca.h"
+
+#define DRIVER_DESC "HCI NFC driver for ST21NFCA"
+
+#define FULL_VERSION_LEN 3
+
+/* Proprietary gates, events, commands and registers */
+
+/* Commands that apply to all RF readers */
+#define ST21NFCA_RF_READER_CMD_PRESENCE_CHECK  0x30
+
+#define ST21NFCA_RF_READER_ISO15693_GATE   0x12
+#define ST21NFCA_RF_READER_ISO15693_INVENTORY  0x01
+
+/*
+ * Reader gate for communication with contact-less cards using Type A
+ * protocol ISO14443-3 but not compliant with ISO14443-4
+ */
+#define ST21NFCA_RF_READER_14443_3_A_GATE  0x15
+#define ST21NFCA_RF_READER_14443_3_A_UID   0x02
+#define ST21NFCA_RF_READER_14443_3_A_ATQA  0x03
+#define ST21NFCA_RF_READER_14443_3_A_SAK   0x04
+
+#define ST21NFCA_RF_READER_F_DATARATE  0x01
+#define ST21NFCA_RF_READER_F_DATARATE_106  0x01
+#define ST21NFCA_RF_READER_F_DATARATE_212  0x02
+#define ST21NFCA_RF_READER_F_DATARATE_424  0x04
+#define ST21NFCA_RF_READER_F_POL_REQ   0x02
+#define ST21NFCA_RF_READER_F_POL_REQ_DEFAULT   0x
+#define ST21NFCA_RF_READER_F_NFCID20x03
+#define ST21NFCA_RF_READER_F_NFCID10x04
+
+#define ST21NFCA_RF_CARD_F_MODE0x01
+#define ST21NFCA_RF_CARD_F_NFCID2_LIST 0x04
+#define ST21NFCA_RF_CARD_F_NFCID1  0x05
+#define ST21NFCA_RF_CARD_F_SENS_RES0x06
+#define ST21NFCA_RF_CARD_F_SEL_RES 0x07
+#define ST21NFCA_RF_CARD_F_DATARATE0x08
+#define ST21NFCA_RF_CARD_F_DATARATE_212_4240x01
+
+#define ST21NFCA_DEVICE_MGNT_PIPE  0x02
+
+#define ST21NFCA_DM_GETINFO0x13
+#define ST21NFCA_DM_GETINFO_PIPE_LIST  0x02
+#define ST21NFCA_DM_GETINFO_PIPE_INFO  0x01
+#define ST21NFCA_DM_PIPE_CREATED   0x02
+#define ST21NFCA_DM_PIPE_OPEN  0x04
+#define ST21NFCA_DM_RF_ACTIVE  0x80
+#define ST21NFCA_DM_DISCONNECT 0x30
+
+#define ST21NFCA_DM_IS_PIPE_OPEN(p) \
+   ((p & 0x0f) == (ST21NFCA_DM_PIPE_CREATED | ST21NFCA_DM_PIPE_OPEN))
+
+#define ST21NFCA_NFC_MODE  0x03/* NFC_MODE parameter*/
+
+#define ST21NFCA_EVT_HOT_PLUG  0x03
+#define ST21NFCA_EVT_HOT_PLUG_IS_INHIBITED(x) (x->data[0] & 0x80)
+
+#define ST21NFCA_SE_TO_P

[PATCH v3 07/35] nfc: nci: extract pipe value using NCI_HCP_MSG_GET_PIPE

2015-10-25 Thread Christophe Ricard
When receiving data in nci_hci_msg_rx_work, extract pipe value using
NCI_HCP_MSG_GET_PIPE macro.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 net/nfc/nci/hci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/nfc/nci/hci.c b/net/nfc/nci/hci.c
index 73afb47..abe0200 100644
--- a/net/nfc/nci/hci.c
+++ b/net/nfc/nci/hci.c
@@ -400,7 +400,7 @@ static void nci_hci_msg_rx_work(struct work_struct *work)
u8 pipe, type, instruction;
 
while ((skb = skb_dequeue(&hdev->msg_rx_queue)) != NULL) {
-   pipe = skb->data[0];
+   pipe = NCI_HCP_MSG_GET_PIPE(skb->data[0]);
skb_pull(skb, NCI_HCI_HCP_PACKET_HEADER_LEN);
message = (struct nci_hcp_message *)skb->data;
type = NCI_HCP_MSG_GET_TYPE(message->header);
@@ -437,7 +437,7 @@ void nci_hci_data_received_cb(void *context,
 
/* it's the last fragment. Does it need re-aggregation? */
if (skb_queue_len(&ndev->hci_dev->rx_hcp_frags)) {
-   pipe = packet->header & NCI_HCI_FRAGMENT;
+   pipe = NCI_HCP_MSG_GET_PIPE(packet->header);
skb_queue_tail(&ndev->hci_dev->rx_hcp_frags, skb);
 
msg_len = 0;
-- 
2.1.4

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


[PATCH v3 04/35] nfc: st-nci: Fix incorrect spi buffer size

2015-10-25 Thread Christophe Ricard
When sending data over SPI, the maximum expected length is the maximum
nci packet payload + data header size + the frame head room (1 for the
ndlc header) + the frame trail room (0).

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/spi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/nfc/st-nci/spi.c b/drivers/nfc/st-nci/spi.c
index 9a39871..b43f448 100644
--- a/drivers/nfc/st-nci/spi.c
+++ b/drivers/nfc/st-nci/spi.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "st-nci.h"
@@ -94,7 +95,8 @@ static int st_nci_spi_write(void *phy_id, struct sk_buff *skb)
struct st_nci_spi_phy *phy = phy_id;
struct spi_device *dev = phy->spi_dev;
struct sk_buff *skb_rx;
-   u8 buf[ST_NCI_SPI_MAX_SIZE];
+   u8 buf[ST_NCI_SPI_MAX_SIZE + NCI_DATA_HDR_SIZE +
+  ST_NCI_FRAME_HEADROOM + ST_NCI_FRAME_TAILROOM];
struct spi_transfer spi_xfer = {
.tx_buf = skb->data,
.rx_buf = buf,
-- 
2.1.4

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


[PATCH v3 02/35] nfc: st-nci: include st-nci.h instead of ndlc.h

2015-10-25 Thread Christophe Ricard
st-nci.h already include ndlc.h.

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/i2c.c  | 2 +-
 drivers/nfc/st-nci/ndlc.c | 1 -
 drivers/nfc/st-nci/spi.c  | 2 +-
 3 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/nfc/st-nci/i2c.c b/drivers/nfc/st-nci/i2c.c
index 707ed2e..02e585f 100644
--- a/drivers/nfc/st-nci/i2c.c
+++ b/drivers/nfc/st-nci/i2c.c
@@ -27,7 +27,7 @@
 #include 
 #include 
 
-#include "ndlc.h"
+#include "st-nci.h"
 
 #define DRIVER_DESC "NCI NFC driver for ST_NCI"
 
diff --git a/drivers/nfc/st-nci/ndlc.c b/drivers/nfc/st-nci/ndlc.c
index d2cf84e..fb50007 100644
--- a/drivers/nfc/st-nci/ndlc.c
+++ b/drivers/nfc/st-nci/ndlc.c
@@ -19,7 +19,6 @@
 #include 
 #include 
 
-#include "ndlc.h"
 #include "st-nci.h"
 
 #define NDLC_TIMER_T1  100
diff --git a/drivers/nfc/st-nci/spi.c b/drivers/nfc/st-nci/spi.c
index 598a58c..9a39871 100644
--- a/drivers/nfc/st-nci/spi.c
+++ b/drivers/nfc/st-nci/spi.c
@@ -27,7 +27,7 @@
 #include 
 #include 
 
-#include "ndlc.h"
+#include "st-nci.h"
 
 #define DRIVER_DESC "NCI NFC driver for ST_NCI"
 
-- 
2.1.4

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


[PATCH v3 10/35] nfc: nci: add capability to create pipe on specific gate in nci_hci_connect_gate

2015-10-25 Thread Christophe Ricard
Some gates might be interesting to have their pipes created.
Add in nci_hci_connect_gate a call to nci_hci_create_pipe for every gate
different than NCI_HCI_LINK_MGMT_GATE or NCI_HCI_ADMIN_GATE.

In case of an error when opening a pipe, like in hci layer, delete the pipe
if it was created.

Signed-off-by: Christophe Ricard 
---
 net/nfc/nci/hci.c | 55 ++-
 1 file changed, 54 insertions(+), 1 deletion(-)

diff --git a/net/nfc/nci/hci.c b/net/nfc/nci/hci.c
index a937bc6..1d6aa5d 100644
--- a/net/nfc/nci/hci.c
+++ b/net/nfc/nci/hci.c
@@ -79,6 +79,8 @@ struct nci_hcp_packet {
 #define NCI_EVT_HOT_PLUG   0x03
 
 #define NCI_HCI_ADMIN_PARAM_SESSION_IDENTITY   0x01
+#define NCI_HCI_ADM_CREATE_PIPE0x10
+#define NCI_HCI_ADM_DELETE_PIPE0x11
 
 /* HCP headers */
 #define NCI_HCI_HCP_PACKET_HEADER_LEN  1
@@ -520,6 +522,42 @@ int nci_hci_open_pipe(struct nci_dev *ndev, u8 pipe)
 }
 EXPORT_SYMBOL(nci_hci_open_pipe);
 
+static u8 nci_hci_create_pipe(struct nci_dev *ndev, u8 dest_host,
+ u8 dest_gate, int *result)
+{
+   u8 pipe;
+   struct sk_buff *skb;
+   struct nci_hci_create_pipe_params params;
+   struct nci_hci_create_pipe_resp *resp;
+
+   pr_debug("gate=%d\n", dest_gate);
+
+   params.src_gate = NCI_HCI_ADMIN_GATE;
+   params.dest_host = dest_host;
+   params.dest_gate = dest_gate;
+
+   *result = nci_hci_send_cmd(ndev, NCI_HCI_ADMIN_GATE, 
NCI_HCI_ADM_CREATE_PIPE,
+  (u8 *)¶ms, sizeof(params), &skb);
+   if (*result < 0)
+   return NCI_HCI_INVALID_PIPE;
+
+   resp = (struct nci_hci_create_pipe_resp *)skb->data;
+   pipe = resp->pipe;
+   kfree_skb(skb);
+
+   pr_debug("pipe created=%d\n", pipe);
+
+   return pipe;
+}
+
+static int nci_hci_delete_pipe(struct nci_dev *ndev, u8 pipe)
+{
+   pr_debug("\n");
+
+   return nci_hci_send_cmd(ndev, NCI_HCI_ADMIN_GATE,
+   NCI_HCI_ADM_DELETE_PIPE, &pipe, 1, NULL);
+}
+
 int nci_hci_set_param(struct nci_dev *ndev, u8 gate, u8 idx,
  const u8 *param, size_t param_len)
 {
@@ -611,6 +649,7 @@ EXPORT_SYMBOL(nci_hci_get_param);
 int nci_hci_connect_gate(struct nci_dev *ndev,
 u8 dest_host, u8 dest_gate, u8 pipe)
 {
+   bool pipe_created = false;
int r;
 
if (pipe == NCI_HCI_DO_NOT_OPEN_PIPE)
@@ -629,12 +668,26 @@ int nci_hci_connect_gate(struct nci_dev *ndev,
case NCI_HCI_ADMIN_GATE:
pipe = NCI_HCI_ADMIN_PIPE;
break;
+   default:
+   pipe = nci_hci_create_pipe(ndev, dest_host, dest_gate, &r);
+   if (pipe < 0)
+   return r;
+   pipe_created = true;
+   break;
}
 
 open_pipe:
r = nci_hci_open_pipe(ndev, pipe);
-   if (r < 0)
+   if (r < 0) {
+   if (pipe_created) {
+   if (nci_hci_delete_pipe(ndev, pipe) < 0) {
+   /* TODO: Cannot clean by deleting pipe...
+* -> inconsistent state
+*/
+   }
+   }
return r;
+   }
 
ndev->hci_dev->pipes[pipe].gate = dest_gate;
ndev->hci_dev->pipes[pipe].host = dest_host;
-- 
2.1.4

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


[PATCH v3 06/35] nfc: nci: Fix improper management of HCI return code

2015-10-25 Thread Christophe Ricard
When sending HCI data over NCI, HCI return code is part of the NCI data.
In order to get correctly the HCI return code, we assume the NCI
communication is successful and extract the return code for the nci_hci
functions return code.

This is done because nci_to_errno does not match hci return code value.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 net/nfc/nci/hci.c | 60 ---
 1 file changed, 44 insertions(+), 16 deletions(-)

diff --git a/net/nfc/nci/hci.c b/net/nfc/nci/hci.c
index bc6b9d5..73afb47 100644
--- a/net/nfc/nci/hci.c
+++ b/net/nfc/nci/hci.c
@@ -101,6 +101,20 @@ struct nci_hcp_packet {
 #define NCI_HCP_MSG_GET_CMD(header)  (header & 0x3f)
 #define NCI_HCP_MSG_GET_PIPE(header) (header & 0x7f)
 
+static int nci_hci_result_to_errno(u8 result)
+{
+   switch (result) {
+   case NCI_HCI_ANY_OK:
+   return 0;
+   case NCI_HCI_ANY_E_REG_PAR_UNKNOWN:
+   return -EOPNOTSUPP;
+   case NCI_HCI_ANY_E_TIMEOUT:
+   return -ETIME;
+   default:
+   return -1;
+   }
+}
+
 /* HCI core */
 static void nci_hci_reset_pipes(struct nci_hci_dev *hdev)
 {
@@ -217,7 +231,8 @@ int nci_hci_send_cmd(struct nci_dev *ndev, u8 gate, u8 cmd,
 const u8 *param, size_t param_len,
 struct sk_buff **skb)
 {
-   struct nci_conn_info*conn_info;
+   struct nci_hcp_message *message;
+   struct nci_conn_info   *conn_info;
struct nci_data data;
int r;
u8 pipe = ndev->hci_dev->gate2pipe[gate];
@@ -237,9 +252,14 @@ int nci_hci_send_cmd(struct nci_dev *ndev, u8 gate, u8 cmd,
 
r = nci_request(ndev, nci_hci_send_data_req, (unsigned long)&data,
msecs_to_jiffies(NCI_DATA_TIMEOUT));
+   if (r == NCI_STATUS_OK) {
+   message = (struct nci_hcp_message *)conn_info->rx_skb->data;
+   r = 
nci_hci_result_to_errno(NCI_HCP_MSG_GET_CMD(message->header));
+   skb_pull(conn_info->rx_skb, NCI_HCI_HCP_MESSAGE_HEADER_LEN);
 
-   if (r == NCI_STATUS_OK && skb)
-   *skb = conn_info->rx_skb;
+   if (!r && skb)
+   *skb = conn_info->rx_skb;
+   }
 
return r;
 }
@@ -333,9 +353,6 @@ static void nci_hci_resp_received(struct nci_dev *ndev, u8 
pipe,
struct nci_conn_info*conn_info;
u8 status = result;
 
-   if (result != NCI_HCI_ANY_OK)
-   goto exit;
-
conn_info = ndev->hci_dev->conn_info;
if (!conn_info) {
status = NCI_STATUS_REJECTED;
@@ -345,7 +362,7 @@ static void nci_hci_resp_received(struct nci_dev *ndev, u8 
pipe,
conn_info->rx_skb = skb;
 
 exit:
-   nci_req_complete(ndev, status);
+   nci_req_complete(ndev, NCI_STATUS_OK);
 }
 
 /* Receive hcp message for pipe, with type and cmd.
@@ -400,7 +417,7 @@ void nci_hci_data_received_cb(void *context,
 {
struct nci_dev *ndev = (struct nci_dev *)context;
struct nci_hcp_packet *packet;
-   u8 pipe, type, instruction;
+   u8 pipe, type;
struct sk_buff *hcp_skb;
struct sk_buff *frag_skb;
int msg_len;
@@ -439,7 +456,7 @@ void nci_hci_data_received_cb(void *context,
*skb_put(hcp_skb, NCI_HCI_HCP_PACKET_HEADER_LEN) = pipe;
 
skb_queue_walk(&ndev->hci_dev->rx_hcp_frags, frag_skb) {
-  msg_len = frag_skb->len - NCI_HCI_HCP_PACKET_HEADER_LEN;
+   msg_len = frag_skb->len - NCI_HCI_HCP_PACKET_HEADER_LEN;
memcpy(skb_put(hcp_skb, msg_len), frag_skb->data +
   NCI_HCI_HCP_PACKET_HEADER_LEN, msg_len);
}
@@ -457,11 +474,9 @@ void nci_hci_data_received_cb(void *context,
packet = (struct nci_hcp_packet *)hcp_skb->data;
type = NCI_HCP_MSG_GET_TYPE(packet->message.header);
if (type == NCI_HCI_HCP_RESPONSE) {
-   pipe = packet->header;
-   instruction = NCI_HCP_MSG_GET_CMD(packet->message.header);
-   skb_pull(hcp_skb, NCI_HCI_HCP_PACKET_HEADER_LEN +
-NCI_HCI_HCP_MESSAGE_HEADER_LEN);
-   nci_hci_hcp_message_rx(ndev, pipe, type, instruction, hcp_skb);
+   pipe = NCI_HCP_MSG_GET_PIPE(packet->header);
+   skb_pull(hcp_skb, NCI_HCI_HCP_PACKET_HEADER_LEN);
+   nci_hci_hcp_message_rx(ndev, pipe, type, NCI_STATUS_OK, 
hcp_skb);
} else {
skb_queue_tail(&ndev->hci_dev->msg_rx_queue, hcp_skb);
schedule_work(&ndev->hci_dev->msg_rx_work);
@@ -493,6 +508,7 @@ EXPORT_SYMBOL(nci_hci_open_pipe);
 int nci_hci_set_param(struct nci_dev *ndev, u8 gate, u8 idx,
  const u8 *param, size_t param_len)
 {
+   struct nci_hcp_message *mess

[PATCH v3 05/35] nfc: nci: Fix incorrect data chaining when sending data

2015-10-25 Thread Christophe Ricard
When sending HCI data over NCI, cmd information should be present only on
the first packet. Each packet shall be specifically allocated and sent to
the NCI layer.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 net/nfc/nci/hci.c | 19 ---
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/net/nfc/nci/hci.c b/net/nfc/nci/hci.c
index 609f922..bc6b9d5 100644
--- a/net/nfc/nci/hci.c
+++ b/net/nfc/nci/hci.c
@@ -146,18 +146,18 @@ static int nci_hci_send_data(struct nci_dev *ndev, u8 
pipe,
if (!conn_info)
return -EPROTO;
 
-   skb = nci_skb_alloc(ndev, 2 + conn_info->max_pkt_payload_len +
+   i = 0;
+   skb = nci_skb_alloc(ndev, conn_info->max_pkt_payload_len +
NCI_DATA_HDR_SIZE, GFP_KERNEL);
if (!skb)
return -ENOMEM;
 
-   skb_reserve(skb, 2 + NCI_DATA_HDR_SIZE);
+   skb_reserve(skb, NCI_DATA_HDR_SIZE + 2);
*skb_push(skb, 1) = data_type;
 
-   i = 0;
-   len = conn_info->max_pkt_payload_len;
-
do {
+   len = conn_info->max_pkt_payload_len;
+
/* If last packet add NCI_HFP_NO_CHAINING */
if (i + conn_info->max_pkt_payload_len -
(skb->len + 1) >= data_len) {
@@ -177,9 +177,14 @@ static int nci_hci_send_data(struct nci_dev *ndev, u8 pipe,
return r;
 
i += len;
+
if (i < data_len) {
-   skb_trim(skb, 0);
-   skb_pull(skb, len);
+   skb = nci_skb_alloc(ndev, 
conn_info->max_pkt_payload_len +
+   NCI_DATA_HDR_SIZE, GFP_KERNEL);
+   if (!skb)
+   return -ENOMEM;
+
+   skb_reserve(skb, NCI_DATA_HDR_SIZE + 1);
}
} while (i < data_len);
 
-- 
2.1.4

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


[PATCH v3 13/35] nfc: st-nci: Open NCI_HCI_LINK_MGMT_PIPE

2015-10-25 Thread Christophe Ricard
NCI_HCI_LINK_MGMT_PIPE was never open in st_nci_hci_load_session.

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/se.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/nfc/st-nci/se.c b/drivers/nfc/st-nci/se.c
index 3ffac0e..3522165 100644
--- a/drivers/nfc/st-nci/se.c
+++ b/drivers/nfc/st-nci/se.c
@@ -244,6 +244,14 @@ int st_nci_hci_load_session(struct nci_dev *ndev)
kfree_skb(skb_pipe_info);
}
 
+   /*
+* 3 gates have a well known pipe ID. Only NCI_HCI_LINK_MGMT_GATE
+* is not yet open at this stage.
+*/
+   r = nci_hci_connect_gate(ndev, ST_NCI_HOST_CONTROLLER_ID,
+NCI_HCI_LINK_MGMT_GATE,
+NCI_HCI_LINK_MGMT_PIPE);
+
kfree_skb(skb_pipe_list);
return r;
 }
-- 
2.1.4

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


[PATCH v3 12/35] nfc: st21nfca: Remove hdev->init_data.gates initialization in load_session

2015-10-25 Thread Christophe Ricard
hdev->init_data.gates is already initialized in st21nfca_hci_probe.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st21nfca/core.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/nfc/st21nfca/core.c b/drivers/nfc/st21nfca/core.c
index 42f1974..67d1c27 100644
--- a/drivers/nfc/st21nfca/core.c
+++ b/drivers/nfc/st21nfca/core.c
@@ -218,7 +218,6 @@ static int st21nfca_hci_load_session(struct nfc_hci_dev 
*hdev)
}
}
 
-   memcpy(hdev->init_data.gates, st21nfca_gates, sizeof(st21nfca_gates));
 free_list:
kfree_skb(skb_pipe_list);
return r;
-- 
2.1.4

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


[PATCH v3 01/35] nfc: st-nci: Align st-nci driver with other nfc driver

2015-10-25 Thread Christophe Ricard
Align st-nci driver with or nfc driver:
- Remove st-nci_ prefix
- Merge se.h in st-nci.h

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/core.c   |  1 -
 drivers/nfc/st-nci/se.c |  1 -
 drivers/nfc/st-nci/se.h | 61 -
 drivers/nfc/st-nci/st-nci.h | 40 -
 4 files changed, 39 insertions(+), 64 deletions(-)
 delete mode 100644 drivers/nfc/st-nci/se.h

diff --git a/drivers/nfc/st-nci/core.c b/drivers/nfc/st-nci/core.c
index c419d39..96997e6 100644
--- a/drivers/nfc/st-nci/core.c
+++ b/drivers/nfc/st-nci/core.c
@@ -24,7 +24,6 @@
 #include 
 
 #include "st-nci.h"
-#include "st-nci_se.h"
 
 #define DRIVER_DESC "NCI NFC driver for ST_NCI"
 
diff --git a/drivers/nfc/st-nci/se.c b/drivers/nfc/st-nci/se.c
index c742ef6..4acb945 100644
--- a/drivers/nfc/st-nci/se.c
+++ b/drivers/nfc/st-nci/se.c
@@ -23,7 +23,6 @@
 #include 
 
 #include "st-nci.h"
-#include "st-nci_se.h"
 
 struct st_nci_pipe_info {
u8 pipe_state;
diff --git a/drivers/nfc/st-nci/se.h b/drivers/nfc/st-nci/se.h
deleted file mode 100644
index ea66e87..000
--- a/drivers/nfc/st-nci/se.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Secure Element Driver for STMicroelectronics NFC NCI Chip
- *
- * Copyright (C) 2014-2015 STMicroelectronics SAS. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-#ifndef __LOCAL_ST_NCI_SE_H_
-#define __LOCAL_ST_NCI_SE_H_
-
-/*
- * ref ISO7816-3 chap 8.1. the initial character TS is followed by a
- * sequence of at most 32 characters.
- */
-#define ST_NCI_ESE_MAX_LENGTH  33
-#define ST_NCI_HCI_HOST_ID_ESE 0xc0
-
-struct st_nci_se_info {
-   u8 atr[ST_NCI_ESE_MAX_LENGTH];
-   struct completion req_completion;
-
-   struct timer_list bwi_timer;
-   int wt_timeout; /* in msecs */
-   bool bwi_active;
-
-   struct timer_list se_active_timer;
-   bool se_active;
-
-   bool xch_error;
-
-   se_io_cb_t cb;
-   void *cb_context;
-};
-
-int st_nci_se_init(struct nci_dev *ndev);
-void st_nci_se_deinit(struct nci_dev *ndev);
-
-int st_nci_discover_se(struct nci_dev *ndev);
-int st_nci_enable_se(struct nci_dev *ndev, u32 se_idx);
-int st_nci_disable_se(struct nci_dev *ndev, u32 se_idx);
-int st_nci_se_io(struct nci_dev *ndev, u32 se_idx,
-   u8 *apdu, size_t apdu_length,
-   se_io_cb_t cb, void *cb_context);
-int st_nci_hci_load_session(struct nci_dev *ndev);
-void st_nci_hci_event_received(struct nci_dev *ndev, u8 pipe,
-   u8 event, struct sk_buff *skb);
-void st_nci_hci_cmd_received(struct nci_dev *ndev, u8 pipe, u8 cmd,
-   struct sk_buff *skb);
-
-
-#endif /* __LOCAL_ST_NCI_SE_H_ */
diff --git a/drivers/nfc/st-nci/st-nci.h b/drivers/nfc/st-nci/st-nci.h
index 850a239..5d3f4d9 100644
--- a/drivers/nfc/st-nci/st-nci.h
+++ b/drivers/nfc/st-nci/st-nci.h
@@ -19,7 +19,6 @@
 #ifndef __LOCAL_ST_NCI_H_
 #define __LOCAL_ST_NCI_H_
 
-#include "st-nci_se.h"
 #include "ndlc.h"
 
 /* Define private flags: */
@@ -28,6 +27,13 @@
 #define ST_NCI_CORE_PROP0x01
 #define ST_NCI_SET_NFC_MODE 0x02
 
+/*
+ * ref ISO7816-3 chap 8.1. the initial character TS is followed by a
+ * sequence of at most 32 characters.
+ */
+#define ST_NCI_ESE_MAX_LENGTH  33
+#define ST_NCI_HCI_HOST_ID_ESE 0xc0
+
 struct nci_mode_set_cmd {
u8 cmd_type;
u8 mode;
@@ -37,6 +43,23 @@ struct nci_mode_set_rsp {
u8 status;
 } __packed;
 
+struct st_nci_se_info {
+   u8 atr[ST_NCI_ESE_MAX_LENGTH];
+   struct completion req_completion;
+
+   struct timer_list bwi_timer;
+   int wt_timeout; /* in msecs */
+   bool bwi_active;
+
+   struct timer_list se_active_timer;
+   bool se_active;
+
+   bool xch_error;
+
+   se_io_cb_t cb;
+   void *cb_context;
+};
+
 struct st_nci_info {
struct llt_ndlc *ndlc;
unsigned long flags;
@@ -47,4 +70,19 @@ void st_nci_remove(struct nci_dev *ndev);
 int st_nci_probe(struct llt_ndlc *ndlc, int phy_headroom,
int phy_tailroom);
 
+int st_nci_se_init(struct nci_dev *ndev);
+void st_nci_se_deinit(struct nci_dev *ndev);
+
+int st_nci_discover_se(struct nci_dev *ndev);
+int st_nci_enable_se(struct nci_dev *ndev, u32 se_idx);
+int st_nci_disable_se(struct nci_dev *ndev, u32 se_idx);
+int st_

Re: [PATCH v2 00/35] Few fixes and st21nfca/st-nci vendor_cmds support

2015-10-25 Thread Christophe Ricard

Hi Samuel,

I believe there was an issue when you applied my last series.
drivers/nfc/st-nci/vendor_cmds.c is not present and this introduce a 
build fix already reported by kbuild robot.


I am sending a new version fixing the points you mention.

Best Regards
Christophe

On 26/10/2015 07:01, Samuel Ortiz wrote:

Hi Christophe,

On Sun, Oct 25, 2015 at 10:54:15PM +0100, Christophe Ricard wrote:

Hi Samuel,

Please find in the following patchset severals fixes as well as vendor_cmds 
support
for st21nfca and st-nci.
vendor_cmds includes production test, trimmings & firmware update commands.

v2:
- Propose a more elegant way to switch between NFC target mode (SLEEP, IDLE).
- Remove st21nfca_ and st-nci_ file name prefix.
- Merge st21nfca_xxx.h headers into st21nfca.h. Same for st-nci_xxx.h

Best Regards
Christophe
Christophe Ricard (35):

All patches applied except:


   nfc: st21nfca: Add support for proprietary commands for factory tests

- nfc_llc_start/stop need to be exported
- There is no st21nfca_vendor_cmds.h header file

Cheers,
Samuel.


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


[PATCH v2 25/35] nfc: st-nci: Increase waiting time between 2 secure element activation

2015-10-25 Thread Christophe Ricard
After internal discussion, it appears this timing should be increase to
20 ms for interoperability reason.

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/se.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nfc/st-nci/se.c b/drivers/nfc/st-nci/se.c
index 147e2d9..3059baa 100644
--- a/drivers/nfc/st-nci/se.c
+++ b/drivers/nfc/st-nci/se.c
@@ -463,7 +463,7 @@ static int st_nci_control_se(struct nci_dev *ndev, u8 
se_idx,
 */
if (info->se_info.se_status->is_ese_present &&
info->se_info.se_status->is_uicc_present)
-   usleep_range(3000, 5000);
+   usleep_range(15000, 2);
 
r = nci_hci_get_param(ndev, NCI_HCI_ADMIN_GATE,
NCI_HCI_ADMIN_PARAM_HOST_LIST, &sk_host_list);
-- 
2.1.4

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


[PATCH v2 22/35] nfc: st-nci: Add error messages when an unexpected HCI event occurs

2015-10-25 Thread Christophe Ricard
Potentially an unexpected HCI event may occur because of a firmware bug.
It could be transparent for the user but at least log this.

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/se.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/nfc/st-nci/se.c b/drivers/nfc/st-nci/se.c
index 7ec4dba..2812884 100644
--- a/drivers/nfc/st-nci/se.c
+++ b/drivers/nfc/st-nci/se.c
@@ -280,6 +280,8 @@ static void st_nci_hci_admin_event_received(struct nci_dev 
*ndev,
}
}
break;
+   default:
+   nfc_err(&ndev->nfc_dev->dev, "Unexpected event on admin 
gate\n");
}
 }
 
@@ -303,6 +305,9 @@ static int st_nci_hci_apdu_reader_event_received(struct 
nci_dev *ndev,
mod_timer(&info->se_info.bwi_timer, jiffies +
  msecs_to_jiffies(info->se_info.wt_timeout));
break;
+   default:
+   nfc_err(&ndev->nfc_dev->dev, "Unexpected event on apdu reader 
gate\n");
+   return 1;
}
 
kfree_skb(skb);
@@ -357,6 +362,7 @@ static int st_nci_hci_connectivity_event_received(struct 
nci_dev *ndev,
r = nfc_se_transaction(ndev->nfc_dev, host, transaction);
break;
default:
+   nfc_err(&ndev->nfc_dev->dev, "Unexpected event on connectivity 
gate\n");
return 1;
}
kfree_skb(skb);
-- 
2.1.4

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


[PATCH v2 23/35] nfc: netlink: Add missing NFC_ATTR comments

2015-10-25 Thread Christophe Ricard
NFC_CMD_ACTIVATE_TARGET and NFC_ATTR_SE_PARAMS comments are missing.

Signed-off-by: Christophe Ricard 
---
 include/uapi/linux/nfc.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/uapi/linux/nfc.h b/include/uapi/linux/nfc.h
index dd3f753..399f39f 100644
--- a/include/uapi/linux/nfc.h
+++ b/include/uapi/linux/nfc.h
@@ -86,6 +86,7 @@
  * for this event is the application ID (AID).
  * @NFC_CMD_GET_SE: Dump all discovered secure elements from an NFC controller.
  * @NFC_CMD_SE_IO: Send/Receive APDUs to/from the selected secure element.
+ * @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.
  */
@@ -156,6 +157,7 @@ enum nfc_commands {
  * @NFC_ATTR_APDU: Secure element APDU
  * @NFC_ATTR_TARGET_ISO15693_DSFID: ISO 15693 Data Storage Format Identifier
  * @NFC_ATTR_TARGET_ISO15693_UID: ISO 15693 Unique Identifier
+ * @NFC_ATTR_SE_PARAMS: Parameters data from an evt_transaction
  * @NFC_ATTR_VENDOR_ID: NFC manufacturer unique ID, typically an OUI
  * @NFC_ATTR_VENDOR_SUBCMD: Vendor specific sub command
  * @NFC_ATTR_VENDOR_DATA: Vendor specific data, to be optionally passed
-- 
2.1.4

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


[PATCH v2 26/35] nfc: st-nci: Fix host_list verification after secure element activation

2015-10-25 Thread Christophe Ricard
A secure element can be activated in different order. The host_list is
updated keeping a fixed order: .

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/se.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/nfc/st-nci/se.c b/drivers/nfc/st-nci/se.c
index 3059baa..1cc24b6 100644
--- a/drivers/nfc/st-nci/se.c
+++ b/drivers/nfc/st-nci/se.c
@@ -423,7 +423,7 @@ static int st_nci_control_se(struct nci_dev *ndev, u8 
se_idx,
 u8 state)
 {
struct st_nci_info *info = nci_get_drvdata(ndev);
-   int r;
+   int r, i;
struct sk_buff *sk_host_list;
u8 host_id;
 
@@ -470,7 +470,10 @@ static int st_nci_control_se(struct nci_dev *ndev, u8 
se_idx,
if (r != NCI_HCI_ANY_OK)
return r;
 
-   host_id = sk_host_list->data[sk_host_list->len - 1];
+   for (i = 0; i < sk_host_list->len &&
+   sk_host_list->data[i] != se_idx; i++)
+   ;
+   host_id = sk_host_list->data[i];
kfree_skb(sk_host_list);
if (state == ST_NCI_SE_MODE_ON && host_id == se_idx)
return se_idx;
-- 
2.1.4

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


[PATCH v2 27/35] nfc: st21nfca: Fix host_list verification after secure element activation

2015-10-25 Thread Christophe Ricard
A secure element can be activated in different order. The host_list is
updated keeping a fixed order: .

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st21nfca/se.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/nfc/st21nfca/se.c b/drivers/nfc/st21nfca/se.c
index 6aa4e34..8e05d73 100644
--- a/drivers/nfc/st21nfca/se.c
+++ b/drivers/nfc/st21nfca/se.c
@@ -100,7 +100,7 @@ static int st21nfca_hci_control_se(struct nfc_hci_dev 
*hdev, u32 se_idx,
u8 state)
 {
struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
-   int r;
+   int r, i;
struct sk_buff *sk_host_list;
u8 se_event, host_id;
 
@@ -148,7 +148,10 @@ static int st21nfca_hci_control_se(struct nfc_hci_dev 
*hdev, u32 se_idx,
if (r < 0)
return r;
 
-   host_id = sk_host_list->data[sk_host_list->len - 1];
+   for (i = 0; i < sk_host_list->len &&
+   sk_host_list->data[i] != se_idx; i++)
+   ;
+   host_id = sk_host_list->data[i];
kfree_skb(sk_host_list);
 
if (state == ST21NFCA_SE_MODE_ON && host_id == se_idx)
-- 
2.1.4

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


[PATCH v2 35/35] nfc: st-nci: Replace st21nfcb by st_nci in makefile

2015-10-25 Thread Christophe Ricard
Replace 1 missing st21nfcb by st_nci

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nfc/st-nci/Makefile b/drivers/nfc/st-nci/Makefile
index ea40ace..439b2fa 100644
--- a/drivers/nfc/st-nci/Makefile
+++ b/drivers/nfc/st-nci/Makefile
@@ -1,5 +1,5 @@
 #
-# Makefile for ST21NFCB NCI based NFC driver
+# Makefile for ST_NCI NCI based NFC driver
 #
 
 st-nci-objs = ndlc.o core.o se.o vendor_cmds.o
-- 
2.1.4

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


[PATCH v2 24/35] nfc: st-nci: Add ese-present/uicc-present dts properties

2015-10-25 Thread Christophe Ricard
In order to align with st21nfca, dts configuration properties ese_present
and uicc_present are made available in st-nci driver.

So far, in early development firmware, because nci_nfcee_mode_set(DISABLE)
was not supported pushed us to try to enable during the secure element
discovery phase.

After several trials on commercial and qualified firmware it appears that
nci_nfcee_mode_set(ENABLE) and nci_nfcee_mode_set(DISABLE) are properly
supported.

Such feature also help us to eventually save some time (~5ms) if only
one secure element is connected.

Acked-by: Rob Herring 
Signed-off-by: Christophe Ricard 
---
 .../devicetree/bindings/net/nfc/st-nci-i2c.txt |  7 ++
 .../devicetree/bindings/net/nfc/st-nci-spi.txt |  9 +-
 drivers/nfc/st-nci/core.c  |  4 +-
 drivers/nfc/st-nci/i2c.c   | 12 ++-
 drivers/nfc/st-nci/ndlc.c  |  6 +-
 drivers/nfc/st-nci/ndlc.h  |  5 +-
 drivers/nfc/st-nci/se.c| 98 ++
 drivers/nfc/st-nci/spi.c   | 12 ++-
 drivers/nfc/st-nci/st-nci.h| 13 ++-
 include/linux/platform_data/st-nci.h   |  2 +
 10 files changed, 122 insertions(+), 46 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/nfc/st-nci-i2c.txt 
b/Documentation/devicetree/bindings/net/nfc/st-nci-i2c.txt
index d707588..263732e 100644
--- a/Documentation/devicetree/bindings/net/nfc/st-nci-i2c.txt
+++ b/Documentation/devicetree/bindings/net/nfc/st-nci-i2c.txt
@@ -11,6 +11,10 @@ Required properties:
 Optional SoC Specific Properties:
 - pinctrl-names: Contains only one value - "default".
 - pintctrl-0: Specifies the pin control groups used for this controller.
+- ese-present: Specifies that an ese is physically connected to the nfc
+controller.
+- uicc-present: Specifies that the uicc swp signal can be physically
+connected to the nfc controller.
 
 Example (for ARM-based BeagleBoard xM with ST21NFCB on I2C2):
 
@@ -29,5 +33,8 @@ Example (for ARM-based BeagleBoard xM with ST21NFCB on I2C2):
interrupts = <2 IRQ_TYPE_LEVEL_HIGH>;
 
reset-gpios = <&gpio5 29 GPIO_ACTIVE_HIGH>;
+
+   ese-present;
+   uicc-present;
};
 };
diff --git a/Documentation/devicetree/bindings/net/nfc/st-nci-spi.txt 
b/Documentation/devicetree/bindings/net/nfc/st-nci-spi.txt
index 525681b..711ca85 100644
--- a/Documentation/devicetree/bindings/net/nfc/st-nci-spi.txt
+++ b/Documentation/devicetree/bindings/net/nfc/st-nci-spi.txt
@@ -2,7 +2,7 @@
 
 Required properties:
 - compatible: Should be "st,st21nfcb-spi"
-- spi-max-frequency: Maximum SPI frequency (<= 1000).
+- spi-max-frequency: Maximum SPI frequency (<= 400).
 - interrupt-parent: phandle for the interrupt gpio controller
 - interrupts: GPIO interrupt to which the chip is connected
 - reset-gpios: Output GPIO pin used to reset the ST21NFCB
@@ -10,6 +10,10 @@ Required properties:
 Optional SoC Specific Properties:
 - pinctrl-names: Contains only one value - "default".
 - pintctrl-0: Specifies the pin control groups used for this controller.
+- ese-present: Specifies that an ese is physically connected to the nfc
+controller.
+- uicc-present: Specifies that the uicc swp signal can be physically
+connected to the nfc controller.
 
 Example (for ARM-based BeagleBoard xM with ST21NFCB on SPI4):
 
@@ -27,5 +31,8 @@ Example (for ARM-based BeagleBoard xM with ST21NFCB on SPI4):
interrupts = <2 IRQ_TYPE_EDGE_RISING>;
 
reset-gpios = <&gpio5 29 GPIO_ACTIVE_HIGH>;
+
+   ese-present;
+   uicc-present;
};
 };
diff --git a/drivers/nfc/st-nci/core.c b/drivers/nfc/st-nci/core.c
index 6b083ed..ccf7237 100644
--- a/drivers/nfc/st-nci/core.c
+++ b/drivers/nfc/st-nci/core.c
@@ -123,7 +123,7 @@ static struct nci_ops st_nci_ops = {
 };
 
 int st_nci_probe(struct llt_ndlc *ndlc, int phy_headroom,
-  int phy_tailroom)
+int phy_tailroom, struct st_nci_se_status *se_status)
 {
struct st_nci_info *info;
int r;
@@ -164,7 +164,7 @@ int st_nci_probe(struct llt_ndlc *ndlc, int phy_headroom,
goto err_reg_dev;
}
 
-   return st_nci_se_init(ndlc->ndev);
+   return st_nci_se_init(ndlc->ndev, se_status);
 
 err_reg_dev:
nci_free_device(ndlc->ndev);
diff --git a/drivers/nfc/st-nci/i2c.c b/drivers/nfc/st-nci/i2c.c
index 02e585f..172cbc3 100644
--- a/drivers/nfc/st-nci/i2c.c
+++ b/drivers/nfc/st-nci/i2c.c
@@ -52,6 +52,8 @@ struct st_nci_i2c_phy {
 
unsigned int gpio_reset;
unsigned int irq_polarity;
+
+   struct st_nci_se_status se_status;
 };
 
 #define I2C_DUMP_SKB(info, skb)\
@@ -245,6 +247,11 @@ static int st_nci_i2c_of_request_resources(struct 
i2c_c

[PATCH v2 28/35] nfc: netlink: Add mode parameter to deactivate_target functions

2015-10-25 Thread Christophe Ricard
In order to manage in a better way the nci poll mode state machine, add
mode parameter to deactivate_target functions. This way we can manage
different target state. mode parameter make sense only in nci core.

Signed-off-by: Christophe Ricard 
---
 include/net/nfc/nfc.h  |  2 +-
 net/nfc/core.c |  4 ++--
 net/nfc/digital_core.c |  3 ++-
 net/nfc/hci/core.c |  3 ++-
 net/nfc/nci/core.c | 15 +++
 net/nfc/netlink.c  |  2 +-
 net/nfc/nfc.h  |  5 -
 net/nfc/rawsock.c  |  3 ++-
 8 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/include/net/nfc/nfc.h b/include/net/nfc/nfc.h
index 30afc9a..dcfcfc9 100644
--- a/include/net/nfc/nfc.h
+++ b/include/net/nfc/nfc.h
@@ -68,7 +68,7 @@ struct nfc_ops {
int (*activate_target)(struct nfc_dev *dev, struct nfc_target *target,
   u32 protocol);
void (*deactivate_target)(struct nfc_dev *dev,
- struct nfc_target *target);
+ struct nfc_target *target, u8 mode);
int (*im_transceive)(struct nfc_dev *dev, struct nfc_target *target,
 struct sk_buff *skb, data_exchange_cb_t cb,
 void *cb_context);
diff --git a/net/nfc/core.c b/net/nfc/core.c
index cff3f16..1fe3d3b 100644
--- a/net/nfc/core.c
+++ b/net/nfc/core.c
@@ -449,7 +449,7 @@ error:
  * @dev: The nfc device that found the target
  * @target_idx: index of the target that must be deactivated
  */
-int nfc_deactivate_target(struct nfc_dev *dev, u32 target_idx)
+int nfc_deactivate_target(struct nfc_dev *dev, u32 target_idx, u8 mode)
 {
int rc = 0;
 
@@ -476,7 +476,7 @@ int nfc_deactivate_target(struct nfc_dev *dev, u32 
target_idx)
if (dev->ops->check_presence)
del_timer_sync(&dev->check_pres_timer);
 
-   dev->ops->deactivate_target(dev, dev->active_target);
+   dev->ops->deactivate_target(dev, dev->active_target, mode);
dev->active_target = NULL;
 
 error:
diff --git a/net/nfc/digital_core.c b/net/nfc/digital_core.c
index 009bcf3..23c2a11 100644
--- a/net/nfc/digital_core.c
+++ b/net/nfc/digital_core.c
@@ -631,7 +631,8 @@ static int digital_activate_target(struct nfc_dev *nfc_dev,
 }
 
 static void digital_deactivate_target(struct nfc_dev *nfc_dev,
- struct nfc_target *target)
+ struct nfc_target *target,
+ u8 mode)
 {
struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev);
 
diff --git a/net/nfc/hci/core.c b/net/nfc/hci/core.c
index 6e061da..2b0f0ac 100644
--- a/net/nfc/hci/core.c
+++ b/net/nfc/hci/core.c
@@ -678,7 +678,8 @@ static int hci_activate_target(struct nfc_dev *nfc_dev,
 }
 
 static void hci_deactivate_target(struct nfc_dev *nfc_dev,
- struct nfc_target *target)
+ struct nfc_target *target,
+ u8 mode)
 {
 }
 
diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c
index 0909720..b7f548b 100644
--- a/net/nfc/nci/core.c
+++ b/net/nfc/nci/core.c
@@ -802,9 +802,11 @@ static int nci_activate_target(struct nfc_dev *nfc_dev,
 }
 
 static void nci_deactivate_target(struct nfc_dev *nfc_dev,
- struct nfc_target *target)
+ struct nfc_target *target,
+ __u8 mode)
 {
struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
+   u8 nci_mode = NCI_DEACTIVATE_TYPE_IDLE_MODE;
 
pr_debug("entry\n");
 
@@ -815,9 +817,14 @@ static void nci_deactivate_target(struct nfc_dev *nfc_dev,
 
ndev->target_active_prot = 0;
 
+   switch (mode) {
+   case NFC_TARGET_MODE_SLEEP:
+   nci_mode = NCI_DEACTIVATE_TYPE_SLEEP_MODE;
+   break;
+   }
+
if (atomic_read(&ndev->state) == NCI_POLL_ACTIVE) {
-   nci_request(ndev, nci_rf_deactivate_req,
-   NCI_DEACTIVATE_TYPE_IDLE_MODE,
+   nci_request(ndev, nci_rf_deactivate_req, nci_mode,
msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT));
}
 }
@@ -851,7 +858,7 @@ static int nci_dep_link_down(struct nfc_dev *nfc_dev)
pr_debug("entry\n");
 
if (nfc_dev->rf_mode == NFC_RF_INITIATOR) {
-   nci_deactivate_target(nfc_dev, NULL);
+   nci_deactivate_target(nfc_dev, NULL, 
NCI_DEACTIVATE_TYPE_IDLE_MODE);
} else {
if (atomic_read(&ndev->state) == NCI_LISTEN_ACTIVE ||
atomic_read(&ndev->state) == NCI_DISCOVERY) {
diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c
index f040532..f58c1fb 100644
--- a/net/nfc/netlink.c
+++ b/net/nfc/netlink.c
@@ -885,7 +885,7 @@ static int nfc_genl_activate_target(struct sk_buff *skb, 
struct genl_info *info)
 

[PATCH v2 06/35] nfc: nci: Fix improper management of HCI return code

2015-10-25 Thread Christophe Ricard
When sending HCI data over NCI, HCI return code is part of the NCI data.
In order to get correctly the HCI return code, we assume the NCI
communication is successful and extract the return code for the nci_hci
functions return code.

This is done because nci_to_errno does not match hci return code value.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 net/nfc/nci/hci.c | 60 ---
 1 file changed, 44 insertions(+), 16 deletions(-)

diff --git a/net/nfc/nci/hci.c b/net/nfc/nci/hci.c
index bc6b9d5..73afb47 100644
--- a/net/nfc/nci/hci.c
+++ b/net/nfc/nci/hci.c
@@ -101,6 +101,20 @@ struct nci_hcp_packet {
 #define NCI_HCP_MSG_GET_CMD(header)  (header & 0x3f)
 #define NCI_HCP_MSG_GET_PIPE(header) (header & 0x7f)
 
+static int nci_hci_result_to_errno(u8 result)
+{
+   switch (result) {
+   case NCI_HCI_ANY_OK:
+   return 0;
+   case NCI_HCI_ANY_E_REG_PAR_UNKNOWN:
+   return -EOPNOTSUPP;
+   case NCI_HCI_ANY_E_TIMEOUT:
+   return -ETIME;
+   default:
+   return -1;
+   }
+}
+
 /* HCI core */
 static void nci_hci_reset_pipes(struct nci_hci_dev *hdev)
 {
@@ -217,7 +231,8 @@ int nci_hci_send_cmd(struct nci_dev *ndev, u8 gate, u8 cmd,
 const u8 *param, size_t param_len,
 struct sk_buff **skb)
 {
-   struct nci_conn_info*conn_info;
+   struct nci_hcp_message *message;
+   struct nci_conn_info   *conn_info;
struct nci_data data;
int r;
u8 pipe = ndev->hci_dev->gate2pipe[gate];
@@ -237,9 +252,14 @@ int nci_hci_send_cmd(struct nci_dev *ndev, u8 gate, u8 cmd,
 
r = nci_request(ndev, nci_hci_send_data_req, (unsigned long)&data,
msecs_to_jiffies(NCI_DATA_TIMEOUT));
+   if (r == NCI_STATUS_OK) {
+   message = (struct nci_hcp_message *)conn_info->rx_skb->data;
+   r = 
nci_hci_result_to_errno(NCI_HCP_MSG_GET_CMD(message->header));
+   skb_pull(conn_info->rx_skb, NCI_HCI_HCP_MESSAGE_HEADER_LEN);
 
-   if (r == NCI_STATUS_OK && skb)
-   *skb = conn_info->rx_skb;
+   if (!r && skb)
+   *skb = conn_info->rx_skb;
+   }
 
return r;
 }
@@ -333,9 +353,6 @@ static void nci_hci_resp_received(struct nci_dev *ndev, u8 
pipe,
struct nci_conn_info*conn_info;
u8 status = result;
 
-   if (result != NCI_HCI_ANY_OK)
-   goto exit;
-
conn_info = ndev->hci_dev->conn_info;
if (!conn_info) {
status = NCI_STATUS_REJECTED;
@@ -345,7 +362,7 @@ static void nci_hci_resp_received(struct nci_dev *ndev, u8 
pipe,
conn_info->rx_skb = skb;
 
 exit:
-   nci_req_complete(ndev, status);
+   nci_req_complete(ndev, NCI_STATUS_OK);
 }
 
 /* Receive hcp message for pipe, with type and cmd.
@@ -400,7 +417,7 @@ void nci_hci_data_received_cb(void *context,
 {
struct nci_dev *ndev = (struct nci_dev *)context;
struct nci_hcp_packet *packet;
-   u8 pipe, type, instruction;
+   u8 pipe, type;
struct sk_buff *hcp_skb;
struct sk_buff *frag_skb;
int msg_len;
@@ -439,7 +456,7 @@ void nci_hci_data_received_cb(void *context,
*skb_put(hcp_skb, NCI_HCI_HCP_PACKET_HEADER_LEN) = pipe;
 
skb_queue_walk(&ndev->hci_dev->rx_hcp_frags, frag_skb) {
-  msg_len = frag_skb->len - NCI_HCI_HCP_PACKET_HEADER_LEN;
+   msg_len = frag_skb->len - NCI_HCI_HCP_PACKET_HEADER_LEN;
memcpy(skb_put(hcp_skb, msg_len), frag_skb->data +
   NCI_HCI_HCP_PACKET_HEADER_LEN, msg_len);
}
@@ -457,11 +474,9 @@ void nci_hci_data_received_cb(void *context,
packet = (struct nci_hcp_packet *)hcp_skb->data;
type = NCI_HCP_MSG_GET_TYPE(packet->message.header);
if (type == NCI_HCI_HCP_RESPONSE) {
-   pipe = packet->header;
-   instruction = NCI_HCP_MSG_GET_CMD(packet->message.header);
-   skb_pull(hcp_skb, NCI_HCI_HCP_PACKET_HEADER_LEN +
-NCI_HCI_HCP_MESSAGE_HEADER_LEN);
-   nci_hci_hcp_message_rx(ndev, pipe, type, instruction, hcp_skb);
+   pipe = NCI_HCP_MSG_GET_PIPE(packet->header);
+   skb_pull(hcp_skb, NCI_HCI_HCP_PACKET_HEADER_LEN);
+   nci_hci_hcp_message_rx(ndev, pipe, type, NCI_STATUS_OK, 
hcp_skb);
} else {
skb_queue_tail(&ndev->hci_dev->msg_rx_queue, hcp_skb);
schedule_work(&ndev->hci_dev->msg_rx_work);
@@ -493,6 +508,7 @@ EXPORT_SYMBOL(nci_hci_open_pipe);
 int nci_hci_set_param(struct nci_dev *ndev, u8 gate, u8 idx,
  const u8 *param, size_t param_len)
 {
+   struct nci_hcp_message *mess

[PATCH v2 17/35] nfc: st-nci: initialize gate_count in st_nci_hci_network_init

2015-10-25 Thread Christophe Ricard
When initializing ndev->hci_dev->init_data, only gates field was set.
gate_count needs to be initialized as well.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/se.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/nfc/st-nci/se.c b/drivers/nfc/st-nci/se.c
index df2dc54..11e49a5 100644
--- a/drivers/nfc/st-nci/se.c
+++ b/drivers/nfc/st-nci/se.c
@@ -536,6 +536,7 @@ static int st_nci_hci_network_init(struct nci_dev *ndev)
if (!conn_info)
goto free_dest_params;
 
+   ndev->hci_dev->init_data.gate_count = ARRAY_SIZE(st_nci_gates);
memcpy(ndev->hci_dev->init_data.gates, st_nci_gates,
   sizeof(st_nci_gates));
 
-- 
2.1.4

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


[PATCH v2 30/35] nfc: st21nfca: Add few code style fixes

2015-10-25 Thread Christophe Ricard
Add a minor code style fixes

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st21nfca/core.c | 2 --
 drivers/nfc/st21nfca/i2c.c  | 1 +
 drivers/nfc/st21nfca/se.c   | 2 +-
 3 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/nfc/st21nfca/core.c b/drivers/nfc/st21nfca/core.c
index 814d8ff4..6fc60bb 100644
--- a/drivers/nfc/st21nfca/core.c
+++ b/drivers/nfc/st21nfca/core.c
@@ -162,7 +162,6 @@ static int st21nfca_hci_load_session(struct nfc_hci_dev 
*hdev)
r = nfc_hci_send_cmd(hdev, ST21NFCA_DEVICE_MGNT_GATE,
ST21NFCA_DM_GETINFO, pipe_info,
sizeof(pipe_info), &skb_pipe_info);
-
if (r)
continue;
 
@@ -982,7 +981,6 @@ int st21nfca_hci_probe(void *phy_id, struct nfc_phy_ops 
*phy_ops,
 * persistent info to discriminate 2 identical chips
 */
dev_num = find_first_zero_bit(dev_mask, ST21NFCA_NUM_DEVICES);
-
if (dev_num >= ST21NFCA_NUM_DEVICES)
return -ENODEV;
 
diff --git a/drivers/nfc/st21nfca/i2c.c b/drivers/nfc/st21nfca/i2c.c
index b2c914b..84c2cb0 100644
--- a/drivers/nfc/st21nfca/i2c.c
+++ b/drivers/nfc/st21nfca/i2c.c
@@ -94,6 +94,7 @@ struct st21nfca_i2c_phy {
int hard_fault;
struct mutex phy_lock;
 };
+
 static u8 len_seq[] = { 16, 24, 12, 29 };
 static u16 wait_tab[] = { 2, 3, 5, 15, 20, 40};
 
diff --git a/drivers/nfc/st21nfca/se.c b/drivers/nfc/st21nfca/se.c
index 8e05d73..d3347c7 100644
--- a/drivers/nfc/st21nfca/se.c
+++ b/drivers/nfc/st21nfca/se.c
@@ -19,7 +19,7 @@
 #include "st21nfca.h"
 
 #define ST21NFCA_EVT_UICC_ACTIVATE 0x10
-#define ST21NFCA_EVT_UICC_DEACTIVATE   0x13
+#define ST21NFCA_EVT_UICC_DEACTIVATE   0x13
 #define ST21NFCA_EVT_SE_HARD_RESET 0x20
 #define ST21NFCA_EVT_SE_SOFT_RESET 0x11
 #define ST21NFCA_EVT_SE_END_OF_APDU_TRANSFER   0x21
-- 
2.1.4

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


[PATCH v2 32/35] nfc: st21nfca: Add error messages when an unexpected HCI event occurs

2015-10-25 Thread Christophe Ricard
Potentially an unexpected HCI event may occur because of a firmware bug.
It could be transparent for the user but at least log this.

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st21nfca/core.c | 2 ++
 drivers/nfc/st21nfca/dep.c  | 1 +
 drivers/nfc/st21nfca/se.c   | 4 
 3 files changed, 7 insertions(+)

diff --git a/drivers/nfc/st21nfca/core.c b/drivers/nfc/st21nfca/core.c
index d36e290..dd8b150 100644
--- a/drivers/nfc/st21nfca/core.c
+++ b/drivers/nfc/st21nfca/core.c
@@ -893,6 +893,8 @@ static int st21nfca_admin_event_received(struct nfc_hci_dev 
*hdev, u8 event,
}
}
break;
+   default:
+   nfc_err(&hdev->ndev->dev, "Unexpected event on admin gate\n");
}
kfree_skb(skb);
return 0;
diff --git a/drivers/nfc/st21nfca/dep.c b/drivers/nfc/st21nfca/dep.c
index c011712..798a32b 100644
--- a/drivers/nfc/st21nfca/dep.c
+++ b/drivers/nfc/st21nfca/dep.c
@@ -435,6 +435,7 @@ int st21nfca_dep_event_received(struct nfc_hci_dev *hdev,
return r;
return 0;
default:
+   nfc_err(&hdev->ndev->dev, "Unexpected event on card f gate\n");
return 1;
}
kfree_skb(skb);
diff --git a/drivers/nfc/st21nfca/se.c b/drivers/nfc/st21nfca/se.c
index e04f603..85fe3cc 100644
--- a/drivers/nfc/st21nfca/se.c
+++ b/drivers/nfc/st21nfca/se.c
@@ -344,6 +344,7 @@ int st21nfca_connectivity_event_received(struct nfc_hci_dev 
*hdev, u8 host,
r = nfc_se_transaction(hdev->ndev, host, transaction);
break;
default:
+   nfc_err(&hdev->ndev->dev, "Unexpected event on connectivity 
gate\n");
return 1;
}
kfree_skb(skb);
@@ -375,6 +376,9 @@ int st21nfca_apdu_reader_event_received(struct nfc_hci_dev 
*hdev,
mod_timer(&info->se_info.bwi_timer, jiffies +
msecs_to_jiffies(info->se_info.wt_timeout));
break;
+   default:
+   nfc_err(&ndev->nfc_dev->dev, "Unexpected event on apdu reader 
gate\n");
+   return 1;
}
 
 exit:
-- 
2.1.4

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


[PATCH v2 31/35] nfc: st21nfca: Add support for proprietary commands for factory tests

2015-10-25 Thread Christophe Ricard
Add support for proprietary commands useful mainly for factory testings.
Here is a list:
- FACTORY_MODE: Allow to set the driver into a mode where no secure element
are activated. It does not consider any NFC_ATTR_VENDOR_DATA.
- HCI_CLEAR_ALL_PIPES: Allow to execute a HCI clear all pipes command.
It does not consider any NFC_ATTR_VENDOR_DATA.
- HCI_DM_PUT_DATA: Allow to configure specific CLF registry as for example
RF trimmings or low level drivers configurations (I2C, SPI, SWP).
- HCI_DM_UPDATE_AID: Allow to configure an AID routing into the CLF routing
table following RF technology, CLF mode or protocol.
- HCI_DM_GET_INFO: Allow to retrieve CLF information.
- HCI_DM_GET_DATA: Allow to retrieve CLF configurable data such as low
level drivers configurations or RF trimmings.
- HCI_DM_LOAD: Allow to load a firmware into the CLF. A complete
packet can be more than 8KB.
- HCI_DM_RESET: Allow to run a CLF reset in order to "commit" CLF
configuration changes without CLF power off.
-  HCI_GET_PARAM: Allow to retrieve an HCI CLF parameter (for example the
white list).
- HCI_DM_FIELD_GENERATOR: Allow to generate different kind of RF
technology. When using this command to anti-collision is done.
- HCI_LOOPBACK: Allow to echo a command and test the Dh to CLF
connectivity.

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st21nfca/Makefile  |   2 +-
 drivers/nfc/st21nfca/core.c|   3 +
 drivers/nfc/st21nfca/se.c  |   4 +-
 drivers/nfc/st21nfca/st21nfca.h|  54 +-
 drivers/nfc/st21nfca/vendor_cmds.c | 370 +
 5 files changed, 430 insertions(+), 3 deletions(-)
 create mode 100644 drivers/nfc/st21nfca/vendor_cmds.c

diff --git a/drivers/nfc/st21nfca/Makefile b/drivers/nfc/st21nfca/Makefile
index 82434c3..ded6489 100644
--- a/drivers/nfc/st21nfca/Makefile
+++ b/drivers/nfc/st21nfca/Makefile
@@ -2,7 +2,7 @@
 # Makefile for ST21NFCA HCI based NFC driver
 #
 
-st21nfca_hci-objs = core.o dep.o se.o
+st21nfca_hci-objs = core.o dep.o se.o vendor_cmds.o
 obj-$(CONFIG_NFC_ST21NFCA) += st21nfca_hci.o
 
 st21nfca_i2c-objs  = i2c.o
diff --git a/drivers/nfc/st21nfca/core.c b/drivers/nfc/st21nfca/core.c
index 6fc60bb..d36e290 100644
--- a/drivers/nfc/st21nfca/core.c
+++ b/drivers/nfc/st21nfca/core.c
@@ -921,6 +921,8 @@ static int st21nfca_hci_event_received(struct nfc_hci_dev 
*hdev, u8 pipe,
event, skb);
case ST21NFCA_APDU_READER_GATE:
return st21nfca_apdu_reader_event_received(hdev, event, skb);
+   case NFC_HCI_LOOPBACK_GATE:
+   return st21nfca_hci_loopback_event_received(hdev, event, skb);
default:
return 1;
}
@@ -1022,6 +1024,7 @@ int st21nfca_hci_probe(void *phy_id, struct nfc_phy_ops 
*phy_ops,
*hdev = info->hdev;
st21nfca_dep_init(info->hdev);
st21nfca_se_init(info->hdev);
+   st21nfca_vendor_cmds_init(info->hdev);
 
return 0;
 
diff --git a/drivers/nfc/st21nfca/se.c b/drivers/nfc/st21nfca/se.c
index d3347c7..e04f603 100644
--- a/drivers/nfc/st21nfca/se.c
+++ b/drivers/nfc/st21nfca/se.c
@@ -167,6 +167,9 @@ int st21nfca_hci_discover_se(struct nfc_hci_dev *hdev)
struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
int se_count = 0;
 
+   if (test_bit(ST21NFCA_FACTORY_MODE, &hdev->quirks))
+   return 0;
+
if (info->se_status->is_uicc_present) {
nfc_add_se(hdev->ndev, NFC_HCI_UICC_HOST_ID, NFC_SE_UICC);
se_count++;
@@ -191,7 +194,6 @@ int st21nfca_hci_enable_se(struct nfc_hci_dev *hdev, u32 
se_idx)
 * Same for eSE.
 */
r = st21nfca_hci_control_se(hdev, se_idx, ST21NFCA_SE_MODE_ON);
-
if (r == ST21NFCA_ESE_HOST_ID) {
st21nfca_se_get_atr(hdev);
r = nfc_hci_send_event(hdev, ST21NFCA_APDU_READER_GATE,
diff --git a/drivers/nfc/st21nfca/st21nfca.h b/drivers/nfc/st21nfca/st21nfca.h
index 70e2d43..94ffb05 100644
--- a/drivers/nfc/st21nfca/st21nfca.h
+++ b/drivers/nfc/st21nfca/st21nfca.h
@@ -66,6 +66,9 @@
 #define ST21NFCA_HCI_MODE  0
 #define ST21NFCA_NUM_DEVICES   256
 
+#define ST21NFCA_VENDOR_OUI0x0080E1 /* STMicroelectronics */
+#define ST21NFCA_FACTORY_MODE  2
+
 struct st21nfca_se_status {
bool is_ese_present;
bool is_uicc_present;
@@ -76,6 +79,50 @@ enum st21nfca_state {
ST21NFCA_ST_READY,
 };
 
+/**
+ * enum nfc_vendor_cmds - supported nfc vendor commands
+ *
+ * @FACTORY_MODE: Allow to set the driver into a mode where no secure element
+ * are activated. It does not consider any NFC_ATTR_VENDOR_DATA.
+ * @HCI_CLEAR_ALL_PIPES: Allow to execute a HCI clear all pipes command.
+ * It does not consider any NFC_ATTR_VENDOR_DATA.
+ * @HCI_DM_PUT_DATA: Allow to configure specific CLF registry as for example
+ * RF trimmings or low level

[PATCH v2 15/35] nfc: st-nci: Keep st_nci_gates unchanged in load_session

2015-10-25 Thread Christophe Ricard
We need to keep initial st_nci_gates values in order for
nci_hci_dev_connect_gates to create and open pipe when necessary.

For example after a firmware update CLF pipes are cleared. Changing pipe
values in st_nci_gates was causing nci_hci_dev_connect_gates not using
accurate pipes value.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/se.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/nfc/st-nci/se.c b/drivers/nfc/st-nci/se.c
index 3522165..df2dc54 100644
--- a/drivers/nfc/st-nci/se.c
+++ b/drivers/nfc/st-nci/se.c
@@ -232,13 +232,13 @@ int st_nci_hci_load_session(struct nci_dev *ndev)
if (j < ARRAY_SIZE(st_nci_gates) &&
st_nci_gates[j].gate == dm_pipe_info->dst_gate_id &&
ST_NCI_DM_IS_PIPE_OPEN(dm_pipe_info->pipe_state)) {
-   st_nci_gates[j].pipe = pipe_info[2];
+   ndev->hci_dev->init_data.gates[j].pipe = pipe_info[2];
 
ndev->hci_dev->gate2pipe[st_nci_gates[j].gate] =
-   st_nci_gates[j].pipe;
-   ndev->hci_dev->pipes[st_nci_gates[j].pipe].gate =
+   pipe_info[2];
+   ndev->hci_dev->pipes[pipe_info[2]].gate =
st_nci_gates[j].gate;
-   ndev->hci_dev->pipes[st_nci_gates[j].pipe].host =
+   ndev->hci_dev->pipes[pipe_info[2]].host =
dm_pipe_info->src_host_id;
}
kfree_skb(skb_pipe_info);
-- 
2.1.4

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


[PATCH v2 34/35] nfc: st-nci: remove duplicated skb dump

2015-10-25 Thread Christophe Ricard
Remove SPI_DUMP_SKB and I2C_DUMP_SKB as skb is already dumped in ndlc
layer.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/i2c.c | 11 ---
 drivers/nfc/st-nci/spi.c | 11 ---
 2 files changed, 22 deletions(-)

diff --git a/drivers/nfc/st-nci/i2c.c b/drivers/nfc/st-nci/i2c.c
index 25e5042..15e3ce2 100644
--- a/drivers/nfc/st-nci/i2c.c
+++ b/drivers/nfc/st-nci/i2c.c
@@ -58,13 +58,6 @@ struct st_nci_i2c_phy {
struct st_nci_se_status se_status;
 };
 
-#define I2C_DUMP_SKB(info, skb)\
-do {   \
-   pr_debug("%s:\n", info);\
-   print_hex_dump(KERN_DEBUG, "i2c: ", DUMP_PREFIX_OFFSET, \
-  16, 1, (skb)->data, (skb)->len, 0);  \
-} while (0)
-
 static int st_nci_i2c_enable(void *phy_id)
 {
struct st_nci_i2c_phy *phy = phy_id;
@@ -101,8 +94,6 @@ static int st_nci_i2c_write(void *phy_id, struct sk_buff 
*skb)
struct st_nci_i2c_phy *phy = phy_id;
struct i2c_client *client = phy->i2c_dev;
 
-   I2C_DUMP_SKB("st_nci_i2c_write", skb);
-
if (phy->ndlc->hard_fault != 0)
return phy->ndlc->hard_fault;
 
@@ -173,8 +164,6 @@ static int st_nci_i2c_read(struct st_nci_i2c_phy *phy,
skb_put(*skb, len);
memcpy((*skb)->data + ST_NCI_I2C_MIN_SIZE, buf, len);
 
-   I2C_DUMP_SKB("i2c frame read", *skb);
-
return 0;
 }
 
diff --git a/drivers/nfc/st-nci/spi.c b/drivers/nfc/st-nci/spi.c
index bf6643c..cf7ad81 100644
--- a/drivers/nfc/st-nci/spi.c
+++ b/drivers/nfc/st-nci/spi.c
@@ -59,13 +59,6 @@ struct st_nci_spi_phy {
struct st_nci_se_status se_status;
 };
 
-#define SPI_DUMP_SKB(info, skb)\
-do {   \
-   pr_debug("%s:\n", info);\
-   print_hex_dump(KERN_DEBUG, "spi: ", DUMP_PREFIX_OFFSET, \
-  16, 1, (skb)->data, (skb)->len, 0);  \
-} while (0)
-
 static int st_nci_spi_enable(void *phy_id)
 {
struct st_nci_spi_phy *phy = phy_id;
@@ -110,8 +103,6 @@ static int st_nci_spi_write(void *phy_id, struct sk_buff 
*skb)
.len = skb->len,
};
 
-   SPI_DUMP_SKB("st_nci_spi_write", skb);
-
if (phy->ndlc->hard_fault != 0)
return phy->ndlc->hard_fault;
 
@@ -188,8 +179,6 @@ static int st_nci_spi_read(struct st_nci_spi_phy *phy,
skb_put(*skb, len);
memcpy((*skb)->data + ST_NCI_SPI_MIN_SIZE, buf, len);
 
-   SPI_DUMP_SKB("spi frame read", *skb);
-
return 0;
 }
 
-- 
2.1.4

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


[PATCH v2 05/35] nfc: nci: Fix incorrect data chaining when sending data

2015-10-25 Thread Christophe Ricard
When sending HCI data over NCI, cmd information should be present only on
the first packet. Each packet shall be specifically allocated and sent to
the NCI layer.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 net/nfc/nci/hci.c | 19 ---
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/net/nfc/nci/hci.c b/net/nfc/nci/hci.c
index 609f922..bc6b9d5 100644
--- a/net/nfc/nci/hci.c
+++ b/net/nfc/nci/hci.c
@@ -146,18 +146,18 @@ static int nci_hci_send_data(struct nci_dev *ndev, u8 
pipe,
if (!conn_info)
return -EPROTO;
 
-   skb = nci_skb_alloc(ndev, 2 + conn_info->max_pkt_payload_len +
+   i = 0;
+   skb = nci_skb_alloc(ndev, conn_info->max_pkt_payload_len +
NCI_DATA_HDR_SIZE, GFP_KERNEL);
if (!skb)
return -ENOMEM;
 
-   skb_reserve(skb, 2 + NCI_DATA_HDR_SIZE);
+   skb_reserve(skb, NCI_DATA_HDR_SIZE + 2);
*skb_push(skb, 1) = data_type;
 
-   i = 0;
-   len = conn_info->max_pkt_payload_len;
-
do {
+   len = conn_info->max_pkt_payload_len;
+
/* If last packet add NCI_HFP_NO_CHAINING */
if (i + conn_info->max_pkt_payload_len -
(skb->len + 1) >= data_len) {
@@ -177,9 +177,14 @@ static int nci_hci_send_data(struct nci_dev *ndev, u8 pipe,
return r;
 
i += len;
+
if (i < data_len) {
-   skb_trim(skb, 0);
-   skb_pull(skb, len);
+   skb = nci_skb_alloc(ndev, 
conn_info->max_pkt_payload_len +
+   NCI_DATA_HDR_SIZE, GFP_KERNEL);
+   if (!skb)
+   return -ENOMEM;
+
+   skb_reserve(skb, NCI_DATA_HDR_SIZE + 1);
}
} while (i < data_len);
 
-- 
2.1.4

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


[PATCH v2 29/35] nfc: st-nci: Add few code style fixes

2015-10-25 Thread Christophe Ricard
Add some few code style fixes.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/i2c.c | 2 +-
 drivers/nfc/st-nci/se.c  | 2 +-
 net/nfc/nci/hci.c| 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/nfc/st-nci/i2c.c b/drivers/nfc/st-nci/i2c.c
index 172cbc3..2a96f1a 100644
--- a/drivers/nfc/st-nci/i2c.c
+++ b/drivers/nfc/st-nci/i2c.c
@@ -32,7 +32,7 @@
 #define DRIVER_DESC "NCI NFC driver for ST_NCI"
 
 /* ndlc header */
-#define ST_NCI_FRAME_HEADROOM  1
+#define ST_NCI_FRAME_HEADROOM 1
 #define ST_NCI_FRAME_TAILROOM 0
 
 #define ST_NCI_I2C_MIN_SIZE 4   /* PCB(1) + NCI Packet header(3) */
diff --git a/drivers/nfc/st-nci/se.c b/drivers/nfc/st-nci/se.c
index 1cc24b6..dbab722 100644
--- a/drivers/nfc/st-nci/se.c
+++ b/drivers/nfc/st-nci/se.c
@@ -62,7 +62,7 @@ struct st_nci_pipe_info {
 
 #define ST_NCI_EVT_SE_HARD_RESET   0x20
 #define ST_NCI_EVT_TRANSMIT_DATA   0x10
-#define ST_NCI_EVT_WTX_REQUEST 0x11
+#define ST_NCI_EVT_WTX_REQUEST 0x11
 #define ST_NCI_EVT_SE_SOFT_RESET   0x11
 #define ST_NCI_EVT_SE_END_OF_APDU_TRANSFER 0x21
 #define ST_NCI_EVT_HOT_PLUG0x03
diff --git a/net/nfc/nci/hci.c b/net/nfc/nci/hci.c
index 1d6aa5d..984d451 100644
--- a/net/nfc/nci/hci.c
+++ b/net/nfc/nci/hci.c
@@ -405,7 +405,7 @@ static void nci_hci_hcp_message_rx(struct nci_dev *ndev, u8 
pipe,
break;
}
 
-   nci_req_complete(ndev, 0);
+   nci_req_complete(ndev, NCI_STATUS_OK);
 }
 
 static void nci_hci_msg_rx_work(struct work_struct *work)
-- 
2.1.4

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


[PATCH v2 04/35] nfc: st-nci: Fix incorrect spi buffer size

2015-10-25 Thread Christophe Ricard
When sending data over SPI, the maximum expected length is the maximum
nci packet payload + data header size + the frame head room (1 for the
ndlc header) + the frame trail room (0).

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/spi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/nfc/st-nci/spi.c b/drivers/nfc/st-nci/spi.c
index 9a39871..b43f448 100644
--- a/drivers/nfc/st-nci/spi.c
+++ b/drivers/nfc/st-nci/spi.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "st-nci.h"
@@ -94,7 +95,8 @@ static int st_nci_spi_write(void *phy_id, struct sk_buff *skb)
struct st_nci_spi_phy *phy = phy_id;
struct spi_device *dev = phy->spi_dev;
struct sk_buff *skb_rx;
-   u8 buf[ST_NCI_SPI_MAX_SIZE];
+   u8 buf[ST_NCI_SPI_MAX_SIZE + NCI_DATA_HDR_SIZE +
+  ST_NCI_FRAME_HEADROOM + ST_NCI_FRAME_TAILROOM];
struct spi_transfer spi_xfer = {
.tx_buf = skb->data,
.rx_buf = buf,
-- 
2.1.4

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


[PATCH v2 16/35] nfc: st21nfca: Keep st21nfca_gates unchanged in load_session

2015-10-25 Thread Christophe Ricard
We need to keep initial st_nci_gates values in order for
nfc_hci_dev_connect_gates to create and open pipe when necessary.

For example after a firmware update CLF pipes are cleared. Changing pipe
values in st21nfca_gates was causing nfc_hci_dev_connect_gates not using
accurate pipes value.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st21nfca/core.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/nfc/st21nfca/core.c b/drivers/nfc/st21nfca/core.c
index 819a94a..b4451f8 100644
--- a/drivers/nfc/st21nfca/core.c
+++ b/drivers/nfc/st21nfca/core.c
@@ -190,14 +190,14 @@ static int st21nfca_hci_load_session(struct nfc_hci_dev 
*hdev)
if (j < ARRAY_SIZE(st21nfca_gates) &&
st21nfca_gates[j].gate == info->dst_gate_id &&
ST21NFCA_DM_IS_PIPE_OPEN(info->pipe_state)) {
-   st21nfca_gates[j].pipe = pipe_info[2];
+   hdev->init_data.gates[j].pipe = pipe_info[2];
 
hdev->gate2pipe[st21nfca_gates[j].gate] =
-   st21nfca_gates[j].pipe;
-   hdev->pipes[st21nfca_gates[j].pipe].gate =
-   st21nfca_gates[j].gate;
-   hdev->pipes[st21nfca_gates[j].pipe].dest_host =
-   info->src_host_id;
+   pipe_info[2];
+   hdev->pipes[pipe_info[2]].gate =
+   st21nfca_gates[j].gate;
+   hdev->pipes[pipe_info[2]].dest_host =
+   info->src_host_id;
}
kfree_skb(skb_pipe_info);
}
-- 
2.1.4

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


[PATCH v2 33/35] nfc: st-nci: Make sure irq is not already active when powering the device

2015-10-25 Thread Christophe Ricard
Upon some conditions (timing, CLF errors, platform errors...), the irq might
be already active when powering the device.

Add irq_active variable as a guard to avoid kernel warning message

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/i2c.c | 8 +++-
 drivers/nfc/st-nci/spi.c | 8 +++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/nfc/st-nci/i2c.c b/drivers/nfc/st-nci/i2c.c
index 2a96f1a..25e5042 100644
--- a/drivers/nfc/st-nci/i2c.c
+++ b/drivers/nfc/st-nci/i2c.c
@@ -50,6 +50,8 @@ struct st_nci_i2c_phy {
struct i2c_client *i2c_dev;
struct llt_ndlc *ndlc;
 
+   bool irq_active;
+
unsigned int gpio_reset;
unsigned int irq_polarity;
 
@@ -72,8 +74,10 @@ static int st_nci_i2c_enable(void *phy_id)
gpio_set_value(phy->gpio_reset, 1);
usleep_range(8, 85000);
 
-   if (phy->ndlc->powered == 0)
+   if (phy->ndlc->powered == 0 && phy->irq_active == 0) {
enable_irq(phy->i2c_dev->irq);
+   phy->irq_active = true;
+   }
 
return 0;
 }
@@ -83,6 +87,7 @@ static void st_nci_i2c_disable(void *phy_id)
struct st_nci_i2c_phy *phy = phy_id;
 
disable_irq_nosync(phy->i2c_dev->irq);
+   phy->irq_active = false;
 }
 
 /*
@@ -342,6 +347,7 @@ static int st_nci_i2c_probe(struct i2c_client *client,
return r;
}
 
+   phy->irq_active = true;
r = devm_request_threaded_irq(&client->dev, client->irq, NULL,
st_nci_irq_thread_fn,
phy->irq_polarity | IRQF_ONESHOT,
diff --git a/drivers/nfc/st-nci/spi.c b/drivers/nfc/st-nci/spi.c
index 8897203..bf6643c 100644
--- a/drivers/nfc/st-nci/spi.c
+++ b/drivers/nfc/st-nci/spi.c
@@ -51,6 +51,8 @@ struct st_nci_spi_phy {
struct spi_device *spi_dev;
struct llt_ndlc *ndlc;
 
+   bool irq_active;
+
unsigned int gpio_reset;
unsigned int irq_polarity;
 
@@ -73,8 +75,10 @@ static int st_nci_spi_enable(void *phy_id)
gpio_set_value(phy->gpio_reset, 1);
usleep_range(8, 85000);
 
-   if (phy->ndlc->powered == 0)
+   if (phy->ndlc->powered == 0 && phy->irq_active == 0) {
enable_irq(phy->spi_dev->irq);
+   phy->irq_active = true;
+   }
 
return 0;
 }
@@ -84,6 +88,7 @@ static void st_nci_spi_disable(void *phy_id)
struct st_nci_spi_phy *phy = phy_id;
 
disable_irq_nosync(phy->spi_dev->irq);
+   phy->irq_active = false;
 }
 
 /*
@@ -358,6 +363,7 @@ static int st_nci_spi_probe(struct spi_device *dev)
return r;
}
 
+   phy->irq_active = true;
r = devm_request_threaded_irq(&dev->dev, dev->irq, NULL,
st_nci_irq_thread_fn,
phy->irq_polarity | IRQF_ONESHOT,
-- 
2.1.4

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


[PATCH v2 14/35] nfc: st21nfca: Open NFC_HCI_LINK_MGMT_PIPE

2015-10-25 Thread Christophe Ricard
NFC_HCI_LINK_MGMT_PIPE was never open in nfc_hci_load_session.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st21nfca/core.c | 19 +--
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/drivers/nfc/st21nfca/core.c b/drivers/nfc/st21nfca/core.c
index 67d1c27..819a94a 100644
--- a/drivers/nfc/st21nfca/core.c
+++ b/drivers/nfc/st21nfca/core.c
@@ -203,22 +203,13 @@ static int st21nfca_hci_load_session(struct nfc_hci_dev 
*hdev)
}
 
/*
-* 3 gates have a well known pipe ID.
-* They will never appear in the pipe list
+* 3 gates have a well known pipe ID. Only NFC_HCI_LINK_MGMT_GATE
+* is not yet open at this stage.
 */
-   if (skb_pipe_list->len + 3 < ARRAY_SIZE(st21nfca_gates)) {
-   for (i = skb_pipe_list->len + 3;
-   i < ARRAY_SIZE(st21nfca_gates) - 2; i++) {
-   r = nfc_hci_connect_gate(hdev,
-   NFC_HCI_HOST_CONTROLLER_ID,
-   st21nfca_gates[i].gate,
-   st21nfca_gates[i].pipe);
-   if (r < 0)
-   goto free_list;
-   }
-   }
+   r = nfc_hci_connect_gate(hdev, NFC_HCI_HOST_CONTROLLER_ID,
+NFC_HCI_LINK_MGMT_GATE,
+NFC_HCI_LINK_MGMT_PIPE);
 
-free_list:
kfree_skb(skb_pipe_list);
return r;
 }
-- 
2.1.4

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


[PATCH v2 20/35] nfc: st21nfca: Change st21nfca_gates offset when looking for a pipe in the table

2015-10-25 Thread Christophe Ricard
It is useless to start from index 0 when looking for a gate because only
dynamic pipes are retrieved with 
ST21NFCA_DM_GETINFO(ST21NFCA_DM_GETINFO_PIPE_LIST).

The first dynamic pipe is present at index 3.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st21nfca/core.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/nfc/st21nfca/core.c b/drivers/nfc/st21nfca/core.c
index b4451f8..814d8ff4 100644
--- a/drivers/nfc/st21nfca/core.c
+++ b/drivers/nfc/st21nfca/core.c
@@ -85,12 +85,13 @@ static DECLARE_BITMAP(dev_mask, ST21NFCA_NUM_DEVICES);
 
 static struct nfc_hci_gate st21nfca_gates[] = {
{NFC_HCI_ADMIN_GATE, NFC_HCI_ADMIN_PIPE},
+   {NFC_HCI_LINK_MGMT_GATE, NFC_HCI_LINK_MGMT_PIPE},
+   {ST21NFCA_DEVICE_MGNT_GATE, ST21NFCA_DEVICE_MGNT_PIPE},
+
{NFC_HCI_LOOPBACK_GATE, NFC_HCI_INVALID_PIPE},
{NFC_HCI_ID_MGMT_GATE, NFC_HCI_INVALID_PIPE},
-   {NFC_HCI_LINK_MGMT_GATE, NFC_HCI_LINK_MGMT_PIPE},
{NFC_HCI_RF_READER_B_GATE, NFC_HCI_INVALID_PIPE},
{NFC_HCI_RF_READER_A_GATE, NFC_HCI_INVALID_PIPE},
-   {ST21NFCA_DEVICE_MGNT_GATE, ST21NFCA_DEVICE_MGNT_PIPE},
{ST21NFCA_RF_READER_F_GATE, NFC_HCI_INVALID_PIPE},
{ST21NFCA_RF_READER_14443_3_A_GATE, NFC_HCI_INVALID_PIPE},
{ST21NFCA_RF_READER_ISO15693_GATE, NFC_HCI_INVALID_PIPE},
@@ -183,7 +184,7 @@ static int st21nfca_hci_load_session(struct nfc_hci_dev 
*hdev)
continue;
}
 
-   for (j = 0; (j < ARRAY_SIZE(st21nfca_gates)) &&
+   for (j = 3; (j < ARRAY_SIZE(st21nfca_gates)) &&
(st21nfca_gates[j].gate != info->dst_gate_id) ; j++)
;
 
-- 
2.1.4

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


[PATCH v2 02/35] nfc: st-nci: include st-nci.h instead of ndlc.h

2015-10-25 Thread Christophe Ricard
st-nci.h already include ndlc.h.

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/i2c.c  | 2 +-
 drivers/nfc/st-nci/ndlc.c | 1 -
 drivers/nfc/st-nci/spi.c  | 2 +-
 3 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/nfc/st-nci/i2c.c b/drivers/nfc/st-nci/i2c.c
index 707ed2e..02e585f 100644
--- a/drivers/nfc/st-nci/i2c.c
+++ b/drivers/nfc/st-nci/i2c.c
@@ -27,7 +27,7 @@
 #include 
 #include 
 
-#include "ndlc.h"
+#include "st-nci.h"
 
 #define DRIVER_DESC "NCI NFC driver for ST_NCI"
 
diff --git a/drivers/nfc/st-nci/ndlc.c b/drivers/nfc/st-nci/ndlc.c
index d2cf84e..fb50007 100644
--- a/drivers/nfc/st-nci/ndlc.c
+++ b/drivers/nfc/st-nci/ndlc.c
@@ -19,7 +19,6 @@
 #include 
 #include 
 
-#include "ndlc.h"
 #include "st-nci.h"
 
 #define NDLC_TIMER_T1  100
diff --git a/drivers/nfc/st-nci/spi.c b/drivers/nfc/st-nci/spi.c
index 598a58c..9a39871 100644
--- a/drivers/nfc/st-nci/spi.c
+++ b/drivers/nfc/st-nci/spi.c
@@ -27,7 +27,7 @@
 #include 
 #include 
 
-#include "ndlc.h"
+#include "st-nci.h"
 
 #define DRIVER_DESC "NCI NFC driver for ST_NCI"
 
-- 
2.1.4

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


[PATCH v2 03/35] nfc: st21nfca: Align st21nfca driver with other nfc driver

2015-10-25 Thread Christophe Ricard
Align st21nfca driver with or nfc driver:
- Remove st21nfca_ prefix
- Merge st21nfca_se.h, st21nfca_dep.h in st21nfca.h

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st21nfca/Makefile   |2 +-
 drivers/nfc/st21nfca/core.c | 1062 ++
 drivers/nfc/st21nfca/dep.c  |  688 ++
 drivers/nfc/st21nfca/se.c   |  419 ++
 drivers/nfc/st21nfca/st21nfca.c | 1064 ---
 drivers/nfc/st21nfca/st21nfca.h |   98 +++-
 drivers/nfc/st21nfca/st21nfca_dep.c |  689 ---
 drivers/nfc/st21nfca/st21nfca_dep.h |   43 --
 drivers/nfc/st21nfca/st21nfca_se.c  |  420 --
 drivers/nfc/st21nfca/st21nfca_se.h  |   63 ---
 10 files changed, 2249 insertions(+), 2299 deletions(-)
 create mode 100644 drivers/nfc/st21nfca/core.c
 create mode 100644 drivers/nfc/st21nfca/dep.c
 create mode 100644 drivers/nfc/st21nfca/se.c
 delete mode 100644 drivers/nfc/st21nfca/st21nfca.c
 delete mode 100644 drivers/nfc/st21nfca/st21nfca_dep.c
 delete mode 100644 drivers/nfc/st21nfca/st21nfca_dep.h
 delete mode 100644 drivers/nfc/st21nfca/st21nfca_se.c
 delete mode 100644 drivers/nfc/st21nfca/st21nfca_se.h

diff --git a/drivers/nfc/st21nfca/Makefile b/drivers/nfc/st21nfca/Makefile
index 97edab4..82434c3 100644
--- a/drivers/nfc/st21nfca/Makefile
+++ b/drivers/nfc/st21nfca/Makefile
@@ -2,7 +2,7 @@
 # Makefile for ST21NFCA HCI based NFC driver
 #
 
-st21nfca_hci-objs = st21nfca.o st21nfca_dep.o st21nfca_se.o
+st21nfca_hci-objs = core.o dep.o se.o
 obj-$(CONFIG_NFC_ST21NFCA) += st21nfca_hci.o
 
 st21nfca_i2c-objs  = i2c.o
diff --git a/drivers/nfc/st21nfca/core.c b/drivers/nfc/st21nfca/core.c
new file mode 100644
index 000..42f1974
--- /dev/null
+++ b/drivers/nfc/st21nfca/core.c
@@ -0,0 +1,1062 @@
+/*
+ * HCI based Driver for STMicroelectronics NFC Chip
+ *
+ * Copyright (C) 2014  STMicroelectronics SAS. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "st21nfca.h"
+
+#define DRIVER_DESC "HCI NFC driver for ST21NFCA"
+
+#define FULL_VERSION_LEN 3
+
+/* Proprietary gates, events, commands and registers */
+
+/* Commands that apply to all RF readers */
+#define ST21NFCA_RF_READER_CMD_PRESENCE_CHECK  0x30
+
+#define ST21NFCA_RF_READER_ISO15693_GATE   0x12
+#define ST21NFCA_RF_READER_ISO15693_INVENTORY  0x01
+
+/*
+ * Reader gate for communication with contact-less cards using Type A
+ * protocol ISO14443-3 but not compliant with ISO14443-4
+ */
+#define ST21NFCA_RF_READER_14443_3_A_GATE  0x15
+#define ST21NFCA_RF_READER_14443_3_A_UID   0x02
+#define ST21NFCA_RF_READER_14443_3_A_ATQA  0x03
+#define ST21NFCA_RF_READER_14443_3_A_SAK   0x04
+
+#define ST21NFCA_RF_READER_F_DATARATE  0x01
+#define ST21NFCA_RF_READER_F_DATARATE_106  0x01
+#define ST21NFCA_RF_READER_F_DATARATE_212  0x02
+#define ST21NFCA_RF_READER_F_DATARATE_424  0x04
+#define ST21NFCA_RF_READER_F_POL_REQ   0x02
+#define ST21NFCA_RF_READER_F_POL_REQ_DEFAULT   0x
+#define ST21NFCA_RF_READER_F_NFCID20x03
+#define ST21NFCA_RF_READER_F_NFCID10x04
+
+#define ST21NFCA_RF_CARD_F_MODE0x01
+#define ST21NFCA_RF_CARD_F_NFCID2_LIST 0x04
+#define ST21NFCA_RF_CARD_F_NFCID1  0x05
+#define ST21NFCA_RF_CARD_F_SENS_RES0x06
+#define ST21NFCA_RF_CARD_F_SEL_RES 0x07
+#define ST21NFCA_RF_CARD_F_DATARATE0x08
+#define ST21NFCA_RF_CARD_F_DATARATE_212_4240x01
+
+#define ST21NFCA_DEVICE_MGNT_PIPE  0x02
+
+#define ST21NFCA_DM_GETINFO0x13
+#define ST21NFCA_DM_GETINFO_PIPE_LIST  0x02
+#define ST21NFCA_DM_GETINFO_PIPE_INFO  0x01
+#define ST21NFCA_DM_PIPE_CREATED   0x02
+#define ST21NFCA_DM_PIPE_OPEN  0x04
+#define ST21NFCA_DM_RF_ACTIVE  0x80
+#define ST21NFCA_DM_DISCONNECT 0x30
+
+#define ST21NFCA_DM_IS_PIPE_OPEN(p) \
+   ((p & 0x0f) == (ST21NFCA_DM_PIPE_CREATED | ST21NFCA_DM_PIPE_OPEN))
+
+#define ST21NFCA_NFC_MODE  0x03/* NFC_MODE parameter*/
+
+#define ST21NFCA_EVT_HOT_PLUG  0x03
+#define ST21NFCA_EVT_HOT_PLUG_IS_INHIBITED(x) (x->data[0] & 0x80)
+
+#define ST21NFCA_SE_TO_P

[PATCH v2 07/35] nfc: nci: extract pipe value using NCI_HCP_MSG_GET_PIPE

2015-10-25 Thread Christophe Ricard
When receiving data in nci_hci_msg_rx_work, extract pipe value using
NCI_HCP_MSG_GET_PIPE macro.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 net/nfc/nci/hci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/nfc/nci/hci.c b/net/nfc/nci/hci.c
index 73afb47..abe0200 100644
--- a/net/nfc/nci/hci.c
+++ b/net/nfc/nci/hci.c
@@ -400,7 +400,7 @@ static void nci_hci_msg_rx_work(struct work_struct *work)
u8 pipe, type, instruction;
 
while ((skb = skb_dequeue(&hdev->msg_rx_queue)) != NULL) {
-   pipe = skb->data[0];
+   pipe = NCI_HCP_MSG_GET_PIPE(skb->data[0]);
skb_pull(skb, NCI_HCI_HCP_PACKET_HEADER_LEN);
message = (struct nci_hcp_message *)skb->data;
type = NCI_HCP_MSG_GET_TYPE(message->header);
@@ -437,7 +437,7 @@ void nci_hci_data_received_cb(void *context,
 
/* it's the last fragment. Does it need re-aggregation? */
if (skb_queue_len(&ndev->hci_dev->rx_hcp_frags)) {
-   pipe = packet->header & NCI_HCI_FRAGMENT;
+   pipe = NCI_HCP_MSG_GET_PIPE(packet->header);
skb_queue_tail(&ndev->hci_dev->rx_hcp_frags, skb);
 
msg_len = 0;
-- 
2.1.4

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


[PATCH v2 12/35] nfc: st21nfca: Remove hdev->init_data.gates initialization in load_session

2015-10-25 Thread Christophe Ricard
hdev->init_data.gates is already initialized in st21nfca_hci_probe.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st21nfca/core.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/nfc/st21nfca/core.c b/drivers/nfc/st21nfca/core.c
index 42f1974..67d1c27 100644
--- a/drivers/nfc/st21nfca/core.c
+++ b/drivers/nfc/st21nfca/core.c
@@ -218,7 +218,6 @@ static int st21nfca_hci_load_session(struct nfc_hci_dev 
*hdev)
}
}
 
-   memcpy(hdev->init_data.gates, st21nfca_gates, sizeof(st21nfca_gates));
 free_list:
kfree_skb(skb_pipe_list);
return r;
-- 
2.1.4

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


[PATCH v2 19/35] nfc: st-nci: Change st_nci_gates offset when looking for a pipe in the table

2015-10-25 Thread Christophe Ricard
It is useless to start from index 0 when looking for a gate because only
dynamic pipes are retrieved with ST_NCI_DM_GETINFO(ST_NCI_DM_GETINFO_PIPE_LIST).

The first dynamic pipe is present at index 3.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/se.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nfc/st-nci/se.c b/drivers/nfc/st-nci/se.c
index 5d1747d..4c98346 100644
--- a/drivers/nfc/st-nci/se.c
+++ b/drivers/nfc/st-nci/se.c
@@ -228,7 +228,7 @@ int st_nci_hci_load_session(struct nci_dev *ndev)
continue;
}
 
-   for (j = 0; (j < ARRAY_SIZE(st_nci_gates)) &&
+   for (j = 3; (j < ARRAY_SIZE(st_nci_gates)) &&
 (st_nci_gates[j].gate != dm_pipe_info->dst_gate_id); j++)
;
 
-- 
2.1.4

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


[PATCH v2 09/35] nfc: nci: Add a call to nci_hci_clear_all_pipes at HCI initial activation.

2015-10-25 Thread Christophe Ricard
When session_id is filled to ff, the pipe configuration is probably
incorrect.

Signed-off-by: Christophe Ricard 
---
 net/nfc/nci/hci.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/net/nfc/nci/hci.c b/net/nfc/nci/hci.c
index 43d7931..a937bc6 100644
--- a/net/nfc/nci/hci.c
+++ b/net/nfc/nci/hci.c
@@ -701,6 +701,10 @@ int nci_hci_dev_session_init(struct nci_dev *ndev)
/* Restore gate<->pipe table from some proprietary location. */
r = ndev->ops->hci_load_session(ndev);
} else {
+   r = nci_hci_clear_all_pipes(ndev);
+   if (r < 0)
+   goto exit;
+
r = nci_hci_dev_connect_gates(ndev,
  
ndev->hci_dev->init_data.gate_count,
  ndev->hci_dev->init_data.gates);
-- 
2.1.4

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


[PATCH v2 18/35] nfc: st-nci: Add support for NCI_HCI_IDENTITY_MGMT_GATE

2015-10-25 Thread Christophe Ricard
NCI_HCI_IDENTITY_MGMT_GATE might be useful to get information for example
about hardware or firmware version.

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/se.c| 3 +++
 include/net/nfc/nci_core.h | 1 +
 2 files changed, 4 insertions(+)

diff --git a/drivers/nfc/st-nci/se.c b/drivers/nfc/st-nci/se.c
index 11e49a5..5d1747d 100644
--- a/drivers/nfc/st-nci/se.c
+++ b/drivers/nfc/st-nci/se.c
@@ -112,6 +112,9 @@ static struct nci_hci_gate st_nci_gates[] = {
{ST_NCI_DEVICE_MGNT_GATE, ST_NCI_DEVICE_MGNT_PIPE,
ST_NCI_HOST_CONTROLLER_ID},
 
+   {NCI_HCI_IDENTITY_MGMT_GATE, NCI_HCI_INVALID_PIPE,
+   ST_NCI_HOST_CONTROLLER_ID},
+
/* Secure element pipes are created by secure element host */
{ST_NCI_CONNECTIVITY_GATE, NCI_HCI_DO_NOT_OPEN_PIPE,
ST_NCI_HOST_CONTROLLER_ID},
diff --git a/include/net/nfc/nci_core.h b/include/net/nfc/nci_core.h
index b2f2e04..377f3de 100644
--- a/include/net/nfc/nci_core.h
+++ b/include/net/nfc/nci_core.h
@@ -125,6 +125,7 @@ struct nci_conn_info {
 
 /* Gates */
 #define NCI_HCI_ADMIN_GATE 0x00
+#define NCI_HCI_IDENTITY_MGMT_GATE 0x05
 #define NCI_HCI_LINK_MGMT_GATE 0x06
 
 /* Pipes */
-- 
2.1.4

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


[PATCH v2 08/35] nfc: nci: add nci_hci_clear_all_pipes functions

2015-10-25 Thread Christophe Ricard
nci_hci_clear_all_pipes might be use full in some cases for example after
a firmware update.

Signed-off-by: Christophe Ricard 
---
 include/net/nfc/nci_core.h |  1 +
 net/nfc/nci/hci.c  | 15 +++
 2 files changed, 16 insertions(+)

diff --git a/include/net/nfc/nci_core.h b/include/net/nfc/nci_core.h
index d0d0f1e..b2f2e04 100644
--- a/include/net/nfc/nci_core.h
+++ b/include/net/nfc/nci_core.h
@@ -305,6 +305,7 @@ int nci_hci_set_param(struct nci_dev *ndev, u8 gate, u8 idx,
  const u8 *param, size_t param_len);
 int nci_hci_get_param(struct nci_dev *ndev, u8 gate, u8 idx,
  struct sk_buff **skb);
+int nci_hci_clear_all_pipes(struct nci_dev *ndev);
 int nci_hci_dev_session_init(struct nci_dev *ndev);
 
 static inline struct sk_buff *nci_skb_alloc(struct nci_dev *ndev,
diff --git a/net/nfc/nci/hci.c b/net/nfc/nci/hci.c
index abe0200..43d7931 100644
--- a/net/nfc/nci/hci.c
+++ b/net/nfc/nci/hci.c
@@ -70,6 +70,7 @@ struct nci_hcp_packet {
 #define NCI_HCI_ANY_SET_PARAMETER  0x01
 #define NCI_HCI_ANY_GET_PARAMETER  0x02
 #define NCI_HCI_ANY_CLOSE_PIPE 0x04
+#define NCI_HCI_ADM_CLEAR_ALL_PIPE 0x14
 
 #define NCI_HFP_NO_CHAINING0x80
 
@@ -265,6 +266,20 @@ int nci_hci_send_cmd(struct nci_dev *ndev, u8 gate, u8 cmd,
 }
 EXPORT_SYMBOL(nci_hci_send_cmd);
 
+int nci_hci_clear_all_pipes(struct nci_dev *ndev)
+{
+   int r;
+
+   r = nci_hci_send_cmd(ndev, NCI_HCI_ADMIN_GATE,
+NCI_HCI_ADM_CLEAR_ALL_PIPE, NULL, 0, NULL);
+   if (r < 0)
+   return r;
+
+   nci_hci_reset_pipes(ndev->hci_dev);
+   return r;
+}
+EXPORT_SYMBOL(nci_hci_clear_all_pipes);
+
 static void nci_hci_event_received(struct nci_dev *ndev, u8 pipe,
   u8 event, struct sk_buff *skb)
 {
-- 
2.1.4

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


[PATCH v2 13/35] nfc: st-nci: Open NCI_HCI_LINK_MGMT_PIPE

2015-10-25 Thread Christophe Ricard
NCI_HCI_LINK_MGMT_PIPE was never open in st_nci_hci_load_session.

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/se.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/nfc/st-nci/se.c b/drivers/nfc/st-nci/se.c
index 3ffac0e..3522165 100644
--- a/drivers/nfc/st-nci/se.c
+++ b/drivers/nfc/st-nci/se.c
@@ -244,6 +244,14 @@ int st_nci_hci_load_session(struct nci_dev *ndev)
kfree_skb(skb_pipe_info);
}
 
+   /*
+* 3 gates have a well known pipe ID. Only NCI_HCI_LINK_MGMT_GATE
+* is not yet open at this stage.
+*/
+   r = nci_hci_connect_gate(ndev, ST_NCI_HOST_CONTROLLER_ID,
+NCI_HCI_LINK_MGMT_GATE,
+NCI_HCI_LINK_MGMT_PIPE);
+
kfree_skb(skb_pipe_list);
return r;
 }
-- 
2.1.4

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


[PATCH v2 11/35] nfc: st-nci: Remove ndev->hci_dev->init_data.gates initialization in load_session

2015-10-25 Thread Christophe Ricard
ndev->hci_dev->init_data.gates is already initialized in st_nci_hci_network.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/se.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/nfc/st-nci/se.c b/drivers/nfc/st-nci/se.c
index 4acb945..3ffac0e 100644
--- a/drivers/nfc/st-nci/se.c
+++ b/drivers/nfc/st-nci/se.c
@@ -244,9 +244,6 @@ int st_nci_hci_load_session(struct nci_dev *ndev)
kfree_skb(skb_pipe_info);
}
 
-   memcpy(ndev->hci_dev->init_data.gates, st_nci_gates,
-  sizeof(st_nci_gates));
-
kfree_skb(skb_pipe_list);
return r;
 }
-- 
2.1.4

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


[PATCH v2 10/35] nfc: nci: add capability to create pipe on specific gate in nci_hci_connect_gate

2015-10-25 Thread Christophe Ricard
Some gates might be interesting to have their pipes created.
Add in nci_hci_connect_gate a call to nci_hci_create_pipe for every gate
different than NCI_HCI_LINK_MGMT_GATE or NCI_HCI_ADMIN_GATE.

In case of an error when opening a pipe, like in hci layer, delete the pipe
if it was created.

Signed-off-by: Christophe Ricard 
---
 net/nfc/nci/hci.c | 55 ++-
 1 file changed, 54 insertions(+), 1 deletion(-)

diff --git a/net/nfc/nci/hci.c b/net/nfc/nci/hci.c
index a937bc6..1d6aa5d 100644
--- a/net/nfc/nci/hci.c
+++ b/net/nfc/nci/hci.c
@@ -79,6 +79,8 @@ struct nci_hcp_packet {
 #define NCI_EVT_HOT_PLUG   0x03
 
 #define NCI_HCI_ADMIN_PARAM_SESSION_IDENTITY   0x01
+#define NCI_HCI_ADM_CREATE_PIPE0x10
+#define NCI_HCI_ADM_DELETE_PIPE0x11
 
 /* HCP headers */
 #define NCI_HCI_HCP_PACKET_HEADER_LEN  1
@@ -520,6 +522,42 @@ int nci_hci_open_pipe(struct nci_dev *ndev, u8 pipe)
 }
 EXPORT_SYMBOL(nci_hci_open_pipe);
 
+static u8 nci_hci_create_pipe(struct nci_dev *ndev, u8 dest_host,
+ u8 dest_gate, int *result)
+{
+   u8 pipe;
+   struct sk_buff *skb;
+   struct nci_hci_create_pipe_params params;
+   struct nci_hci_create_pipe_resp *resp;
+
+   pr_debug("gate=%d\n", dest_gate);
+
+   params.src_gate = NCI_HCI_ADMIN_GATE;
+   params.dest_host = dest_host;
+   params.dest_gate = dest_gate;
+
+   *result = nci_hci_send_cmd(ndev, NCI_HCI_ADMIN_GATE, 
NCI_HCI_ADM_CREATE_PIPE,
+  (u8 *)¶ms, sizeof(params), &skb);
+   if (*result < 0)
+   return NCI_HCI_INVALID_PIPE;
+
+   resp = (struct nci_hci_create_pipe_resp *)skb->data;
+   pipe = resp->pipe;
+   kfree_skb(skb);
+
+   pr_debug("pipe created=%d\n", pipe);
+
+   return pipe;
+}
+
+static int nci_hci_delete_pipe(struct nci_dev *ndev, u8 pipe)
+{
+   pr_debug("\n");
+
+   return nci_hci_send_cmd(ndev, NCI_HCI_ADMIN_GATE,
+   NCI_HCI_ADM_DELETE_PIPE, &pipe, 1, NULL);
+}
+
 int nci_hci_set_param(struct nci_dev *ndev, u8 gate, u8 idx,
  const u8 *param, size_t param_len)
 {
@@ -611,6 +649,7 @@ EXPORT_SYMBOL(nci_hci_get_param);
 int nci_hci_connect_gate(struct nci_dev *ndev,
 u8 dest_host, u8 dest_gate, u8 pipe)
 {
+   bool pipe_created = false;
int r;
 
if (pipe == NCI_HCI_DO_NOT_OPEN_PIPE)
@@ -629,12 +668,26 @@ int nci_hci_connect_gate(struct nci_dev *ndev,
case NCI_HCI_ADMIN_GATE:
pipe = NCI_HCI_ADMIN_PIPE;
break;
+   default:
+   pipe = nci_hci_create_pipe(ndev, dest_host, dest_gate, &r);
+   if (pipe < 0)
+   return r;
+   pipe_created = true;
+   break;
}
 
 open_pipe:
r = nci_hci_open_pipe(ndev, pipe);
-   if (r < 0)
+   if (r < 0) {
+   if (pipe_created) {
+   if (nci_hci_delete_pipe(ndev, pipe) < 0) {
+   /* TODO: Cannot clean by deleting pipe...
+* -> inconsistent state
+*/
+   }
+   }
return r;
+   }
 
ndev->hci_dev->pipes[pipe].gate = dest_gate;
ndev->hci_dev->pipes[pipe].host = dest_host;
-- 
2.1.4

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


[PATCH v2 21/35] nfc: st-nci: Add support for proprietary commands for factory tests

2015-10-25 Thread Christophe Ricard
Add support for proprietary commands useful mainly for factory testings.
Here is a list:
- FACTORY_MODE: Allow to set the driver into a mode where no secure element
are activated. It does not consider any NFC_ATTR_VENDOR_DATA.
- HCI_CLEAR_ALL_PIPES: Allow to execute a HCI clear all pipes command.
It does not consider any NFC_ATTR_VENDOR_DATA.
- HCI_DM_PUT_DATA: Allow to configure specific CLF registry as for example
RF trimmings or low level drivers configurations (I2C, SPI, SWP).
- HCI_DM_UPDATE_AID: Allow to configure an AID routing into the CLF routing
table following RF technology, CLF mode or protocol.
- HCI_DM_GET_INFO: Allow to retrieve CLF information.
- HCI_DM_GET_DATA: Allow to retrieve CLF configurable data such as low
level drivers configurations or RF trimmings.
- HCI_DM_DIRECT_LOAD: Allow to load a firmware into the CLF. A complete
packet can be more than 8KB.
- HCI_DM_RESET: Allow to run a CLF reset in order to "commit" CLF
configuration changes without CLF power off.
-  HCI_GET_PARAM: Allow to retrieve an HCI CLF parameter (for example the
white list).
- HCI_DM_FIELD_GENERATOR: Allow to generate different kind of RF
technology. When using this command to anti-collision is done.
- HCI_LOOPBACK: Allow to echo a command and test the Dh to CLF
connectivity.
- HCI_DM_VDC_MEASUREMENT_VALUE: Allow to measure the field applied on the
CLF antenna. A value between 0 and 0x0f is returned. 0 is maximum.
- HCI_DM_FWUPD_START: Allow to put CLF into firmware update mode. It is a
specific CLF command as there is no GPIO for this.
- HCI_DM_FWUPD_END:  Allow to complete firmware update.
- HCI_DM_VDC_VALUE_COMPARISON: Allow to compare the field applied on the
CLF antenna to a reference value.
- MANUFACTURER_SPECIFIC: Allow to retrieve manufacturer specific data
received during a NCI_CORE_INIT_CMD.

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/Makefile  |   2 +-
 drivers/nfc/st-nci/core.c|  13 +-
 drivers/nfc/st-nci/se.c  |  29 ++-
 drivers/nfc/st-nci/st-nci.h  |  68 ++
 drivers/nfc/st-nci/vendor_cmds.c | 516 +++
 include/net/nfc/nci_core.h   |   1 +
 6 files changed, 619 insertions(+), 10 deletions(-)
 create mode 100644 drivers/nfc/st-nci/vendor_cmds.c

diff --git a/drivers/nfc/st-nci/Makefile b/drivers/nfc/st-nci/Makefile
index 594c63d..ea40ace 100644
--- a/drivers/nfc/st-nci/Makefile
+++ b/drivers/nfc/st-nci/Makefile
@@ -2,7 +2,7 @@
 # Makefile for ST21NFCB NCI based NFC driver
 #
 
-st-nci-objs = ndlc.o core.o se.o
+st-nci-objs = ndlc.o core.o se.o vendor_cmds.o
 obj-$(CONFIG_NFC_ST_NCI) += st-nci.o
 
 st-nci_i2c-objs = i2c.o
diff --git a/drivers/nfc/st-nci/core.c b/drivers/nfc/st-nci/core.c
index 96997e6..6b083ed 100644
--- a/drivers/nfc/st-nci/core.c
+++ b/drivers/nfc/st-nci/core.c
@@ -152,14 +152,23 @@ int st_nci_probe(struct llt_ndlc *ndlc, int phy_headroom,
 
nci_set_drvdata(ndlc->ndev, info);
 
+   r = st_nci_vendor_cmds_init(ndlc->ndev);
+   if (r) {
+   pr_err("Cannot register proprietary vendor cmds\n");
+   goto err_reg_dev;
+   }
+
r = nci_register_device(ndlc->ndev);
if (r) {
pr_err("Cannot register nfc device to nci core\n");
-   nci_free_device(ndlc->ndev);
-   return r;
+   goto err_reg_dev;
}
 
return st_nci_se_init(ndlc->ndev);
+
+err_reg_dev:
+   nci_free_device(ndlc->ndev);
+   return r;
 }
 EXPORT_SYMBOL_GPL(st_nci_probe);
 
diff --git a/drivers/nfc/st-nci/se.c b/drivers/nfc/st-nci/se.c
index 4c98346..7ec4dba 100644
--- a/drivers/nfc/st-nci/se.c
+++ b/drivers/nfc/st-nci/se.c
@@ -39,7 +39,6 @@ struct st_nci_pipe_info {
 #define ST_NCI_ESE_HOST_ID0xc0
 
 /* Gates */
-#define ST_NCI_DEVICE_MGNT_GATE   0x01
 #define ST_NCI_APDU_READER_GATE   0xf0
 #define ST_NCI_CONNECTIVITY_GATE  0x41
 
@@ -114,6 +113,8 @@ static struct nci_hci_gate st_nci_gates[] = {
 
{NCI_HCI_IDENTITY_MGMT_GATE, NCI_HCI_INVALID_PIPE,
ST_NCI_HOST_CONTROLLER_ID},
+   {NCI_HCI_LOOPBACK_GATE, NCI_HCI_INVALID_PIPE,
+   ST_NCI_HOST_CONTROLLER_ID},
 
/* Secure element pipes are created by secure element host */
{ST_NCI_CONNECTIVITY_GATE, NCI_HCI_DO_NOT_OPEN_PIPE,
@@ -376,8 +377,10 @@ void st_nci_hci_event_received(struct nci_dev *ndev, u8 
pipe,
st_nci_hci_apdu_reader_event_received(ndev, event, skb);
break;
case ST_NCI_CONNECTIVITY_GATE:
-   st_nci_hci_connectivity_event_received(ndev, host, event,
-skb);
+   st_nci_hci_connectivity_event_received(ndev, host, event, skb);
+   break;
+   case NCI_HCI_LOOPBACK_GATE:
+   st_nci_hci_loopback_event_received(ndev, event, skb);
break;
}
 }
@@ -50

[PATCH v2 01/35] nfc: st-nci: Align st-nci driver with other nfc driver

2015-10-25 Thread Christophe Ricard
Align st-nci driver with or nfc driver:
- Remove st-nci_ prefix
- Merge se.h in st-nci.h

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/core.c   |  1 -
 drivers/nfc/st-nci/se.c |  1 -
 drivers/nfc/st-nci/se.h | 61 -
 drivers/nfc/st-nci/st-nci.h | 40 -
 4 files changed, 39 insertions(+), 64 deletions(-)
 delete mode 100644 drivers/nfc/st-nci/se.h

diff --git a/drivers/nfc/st-nci/core.c b/drivers/nfc/st-nci/core.c
index c419d39..96997e6 100644
--- a/drivers/nfc/st-nci/core.c
+++ b/drivers/nfc/st-nci/core.c
@@ -24,7 +24,6 @@
 #include 
 
 #include "st-nci.h"
-#include "st-nci_se.h"
 
 #define DRIVER_DESC "NCI NFC driver for ST_NCI"
 
diff --git a/drivers/nfc/st-nci/se.c b/drivers/nfc/st-nci/se.c
index c742ef6..4acb945 100644
--- a/drivers/nfc/st-nci/se.c
+++ b/drivers/nfc/st-nci/se.c
@@ -23,7 +23,6 @@
 #include 
 
 #include "st-nci.h"
-#include "st-nci_se.h"
 
 struct st_nci_pipe_info {
u8 pipe_state;
diff --git a/drivers/nfc/st-nci/se.h b/drivers/nfc/st-nci/se.h
deleted file mode 100644
index ea66e87..000
--- a/drivers/nfc/st-nci/se.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Secure Element Driver for STMicroelectronics NFC NCI Chip
- *
- * Copyright (C) 2014-2015 STMicroelectronics SAS. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-#ifndef __LOCAL_ST_NCI_SE_H_
-#define __LOCAL_ST_NCI_SE_H_
-
-/*
- * ref ISO7816-3 chap 8.1. the initial character TS is followed by a
- * sequence of at most 32 characters.
- */
-#define ST_NCI_ESE_MAX_LENGTH  33
-#define ST_NCI_HCI_HOST_ID_ESE 0xc0
-
-struct st_nci_se_info {
-   u8 atr[ST_NCI_ESE_MAX_LENGTH];
-   struct completion req_completion;
-
-   struct timer_list bwi_timer;
-   int wt_timeout; /* in msecs */
-   bool bwi_active;
-
-   struct timer_list se_active_timer;
-   bool se_active;
-
-   bool xch_error;
-
-   se_io_cb_t cb;
-   void *cb_context;
-};
-
-int st_nci_se_init(struct nci_dev *ndev);
-void st_nci_se_deinit(struct nci_dev *ndev);
-
-int st_nci_discover_se(struct nci_dev *ndev);
-int st_nci_enable_se(struct nci_dev *ndev, u32 se_idx);
-int st_nci_disable_se(struct nci_dev *ndev, u32 se_idx);
-int st_nci_se_io(struct nci_dev *ndev, u32 se_idx,
-   u8 *apdu, size_t apdu_length,
-   se_io_cb_t cb, void *cb_context);
-int st_nci_hci_load_session(struct nci_dev *ndev);
-void st_nci_hci_event_received(struct nci_dev *ndev, u8 pipe,
-   u8 event, struct sk_buff *skb);
-void st_nci_hci_cmd_received(struct nci_dev *ndev, u8 pipe, u8 cmd,
-   struct sk_buff *skb);
-
-
-#endif /* __LOCAL_ST_NCI_SE_H_ */
diff --git a/drivers/nfc/st-nci/st-nci.h b/drivers/nfc/st-nci/st-nci.h
index 850a239..5d3f4d9 100644
--- a/drivers/nfc/st-nci/st-nci.h
+++ b/drivers/nfc/st-nci/st-nci.h
@@ -19,7 +19,6 @@
 #ifndef __LOCAL_ST_NCI_H_
 #define __LOCAL_ST_NCI_H_
 
-#include "st-nci_se.h"
 #include "ndlc.h"
 
 /* Define private flags: */
@@ -28,6 +27,13 @@
 #define ST_NCI_CORE_PROP0x01
 #define ST_NCI_SET_NFC_MODE 0x02
 
+/*
+ * ref ISO7816-3 chap 8.1. the initial character TS is followed by a
+ * sequence of at most 32 characters.
+ */
+#define ST_NCI_ESE_MAX_LENGTH  33
+#define ST_NCI_HCI_HOST_ID_ESE 0xc0
+
 struct nci_mode_set_cmd {
u8 cmd_type;
u8 mode;
@@ -37,6 +43,23 @@ struct nci_mode_set_rsp {
u8 status;
 } __packed;
 
+struct st_nci_se_info {
+   u8 atr[ST_NCI_ESE_MAX_LENGTH];
+   struct completion req_completion;
+
+   struct timer_list bwi_timer;
+   int wt_timeout; /* in msecs */
+   bool bwi_active;
+
+   struct timer_list se_active_timer;
+   bool se_active;
+
+   bool xch_error;
+
+   se_io_cb_t cb;
+   void *cb_context;
+};
+
 struct st_nci_info {
struct llt_ndlc *ndlc;
unsigned long flags;
@@ -47,4 +70,19 @@ void st_nci_remove(struct nci_dev *ndev);
 int st_nci_probe(struct llt_ndlc *ndlc, int phy_headroom,
int phy_tailroom);
 
+int st_nci_se_init(struct nci_dev *ndev);
+void st_nci_se_deinit(struct nci_dev *ndev);
+
+int st_nci_discover_se(struct nci_dev *ndev);
+int st_nci_enable_se(struct nci_dev *ndev, u32 se_idx);
+int st_nci_disable_se(struct nci_dev *ndev, u32 se_idx);
+int st_

[PATCH v2 00/35] Few fixes and st21nfca/st-nci vendor_cmds support

2015-10-25 Thread Christophe Ricard
Hi Samuel,

Please find in the following patchset severals fixes as well as vendor_cmds 
support
for st21nfca and st-nci.
vendor_cmds includes production test, trimmings & firmware update commands.

v2:
- Propose a more elegant way to switch between NFC target mode (SLEEP, IDLE).
- Remove st21nfca_ and st-nci_ file name prefix.
- Merge st21nfca_xxx.h headers into st21nfca.h. Same for st-nci_xxx.h

Best Regards
Christophe
Christophe Ricard (35):
  nfc: st-nci: Align st-nci driver with other nfc driver
  nfc: st-nci: include st-nci.h instead of ndlc.h
  nfc: st21nfca: Align st21nfca driver with other nfc driver
  nfc: st-nci: Fix incorrect spi buffer size
  nfc: nci: Fix incorrect data chaining when sending data
  nfc: nci: Fix improper management of HCI return code
  nfc: nci: extract pipe value using NCI_HCP_MSG_GET_PIPE
  nfc: nci: add nci_hci_clear_all_pipes functions
  nfc: nci: Add a call to nci_hci_clear_all_pipes at HCI initial
activation.
  nfc: nci: add capability to create pipe on specific gate in
nci_hci_connect_gate
  nfc: st-nci: Remove ndev->hci_dev->init_data.gates initialization in
load_session
  nfc: st21nfca: Remove hdev->init_data.gates initialization in
load_session
  nfc: st-nci: Open NCI_HCI_LINK_MGMT_PIPE
  nfc: st21nfca: Open NFC_HCI_LINK_MGMT_PIPE
  nfc: st-nci: Keep st_nci_gates unchanged in load_session
  nfc: st21nfca: Keep st21nfca_gates unchanged in load_session
  nfc: st-nci: initialize gate_count in st_nci_hci_network_init
  nfc: st-nci: Add support for NCI_HCI_IDENTITY_MGMT_GATE
  nfc: st-nci: Change st_nci_gates offset when looking for a pipe in the
table
  nfc: st21nfca: Change st21nfca_gates offset when looking for a pipe in
the table
  nfc: st-nci: Add support for proprietary commands for factory tests
  nfc: st-nci: Add error messages when an unexpected HCI event occurs
  nfc: netlink: Add missing NFC_ATTR comments
  nfc: st-nci: Add ese-present/uicc-present dts properties
  nfc: st-nci: Increase waiting time between 2 secure element activation
  nfc: st-nci: Fix host_list verification after secure element
activation
  nfc: st21nfca: Fix host_list verification after secure element
activation
  nfc: netlink: Add mode parameter to deactivate_target functions
  nfc: st-nci: Add few code style fixes
  nfc: st21nfca: Add few code style fixes
  nfc: st21nfca: Add support for proprietary commands for factory tests
  nfc: st21nfca: Add error messages when an unexpected HCI event occurs
  nfc: st-nci: Make sure irq is not already active when powering the
device
  nfc: st-nci: remove duplicated skb dump
  nfc: st-nci: Replace st21nfcb by st_nci in makefile

 .../devicetree/bindings/net/nfc/st-nci-i2c.txt |7 +
 .../devicetree/bindings/net/nfc/st-nci-spi.txt |9 +-
 drivers/nfc/st-nci/Makefile|4 +-
 drivers/nfc/st-nci/core.c  |   18 +-
 drivers/nfc/st-nci/i2c.c   |   35 +-
 drivers/nfc/st-nci/ndlc.c  |7 +-
 drivers/nfc/st-nci/ndlc.h  |5 +-
 drivers/nfc/st-nci/se.c|  166 ++-
 drivers/nfc/st-nci/se.h|   61 --
 drivers/nfc/st-nci/spi.c   |   37 +-
 drivers/nfc/st-nci/st-nci.h|  117 ++-
 drivers/nfc/st-nci/vendor_cmds.c   |  516 ++
 drivers/nfc/st21nfca/Makefile  |2 +-
 drivers/nfc/st21nfca/core.c| 1056 +++
 drivers/nfc/st21nfca/dep.c |  689 +
 drivers/nfc/st21nfca/i2c.c |1 +
 drivers/nfc/st21nfca/se.c  |  428 
 drivers/nfc/st21nfca/st21nfca.c| 1064 
 drivers/nfc/st21nfca/st21nfca.h|  148 ++-
 drivers/nfc/st21nfca/st21nfca_dep.c|  689 -
 drivers/nfc/st21nfca/st21nfca_dep.h|   43 -
 drivers/nfc/st21nfca/st21nfca_se.c |  420 
 drivers/nfc/st21nfca/st21nfca_se.h |   63 --
 drivers/nfc/st21nfca/vendor_cmds.c |  370 +++
 include/linux/platform_data/st-nci.h   |2 +
 include/net/nfc/nci_core.h |3 +
 include/net/nfc/nfc.h  |2 +-
 include/uapi/linux/nfc.h   |2 +
 net/nfc/core.c |4 +-
 net/nfc/digital_core.c |3 +-
 net/nfc/hci/core.c |3 +-
 net/nfc/nci/core.c |   15 +-
 net/nfc/nci/hci.c  |  159 ++-
 net/nfc/netlink.c  |2 +-
 net/nfc/nfc.h  |5 +-
 net/nfc/rawsock.c  |3 +-
 36 

Re: [PATCH 18/30] nfc: st-nci: Add support for proprietary commands for factory tests

2015-10-25 Thread Christophe Ricard

Hi Samuel,

I think my last last answer:
"I believe a "complete regardless of the event" we are receiving (on the 
loopback gate) may hide a CLF firmware bug and should not happen...


Are you in favour of hiding a potential bug ?"

Was not so smart from my side.

You are right considering a system should not be locked because of a 
buggy NFC controller.

Also an error message will be enough to notify a potential bug...

I will apply your remark where possible.

Sorry for that.

Best Regards
Christophe

On 24/10/2015 14:19, Christophe Ricard wrote:

Hi Samuel,

On 24/10/2015 08:48, Samuel Ortiz wrote:

Hi Christophe,

Just a couple of nitpicks:

On Tue, Oct 20, 2015 at 11:48:09PM +0200, Christophe Ricard wrote:

diff --git a/drivers/nfc/st-nci/Makefile b/drivers/nfc/st-nci/Makefile
index 348ce76..60e569b 100644
--- a/drivers/nfc/st-nci/Makefile
+++ b/drivers/nfc/st-nci/Makefile
@@ -2,7 +2,7 @@
  # Makefile for ST21NFCB NCI based NFC driver
  #
  -st-nci-objs = ndlc.o core.o st-nci_se.o
+st-nci-objs = ndlc.o core.o st-nci_se.o st-nci_vendor_cmds.o

Please rename that file to vendor_cmds.c.
I pushed a change to rename st-nci_se.c to se.c already, to keep the
file names consistent there.
I think your latest change introduced a build break :(. The log 
message mention also MFC instead of NFC ;).


"In file included from drivers/nfc/st-nci/ndlc.c:23:0:
drivers/nfc/st-nci/st-nci.h:22:23: fatal error: st-nci_se.h: No such 
file or directory

#include "st-nci_se.h""
I will send a fix in the v2 ;).




  obj-$(CONFIG_NFC_ST_NCI) += st-nci.o
st-nci_i2c-objs = i2c.o
diff --git a/drivers/nfc/st-nci/core.c b/drivers/nfc/st-nci/core.c
index c419d39..fd2a5ca 100644
--- a/drivers/nfc/st-nci/core.c
+++ b/drivers/nfc/st-nci/core.c
@@ -25,6 +25,7 @@
#include "st-nci.h"
  #include "st-nci_se.h"
+#include "st-nci_vendor_cmds.h"

Ditto: Please rename it to vendor_cmds.h.

Don't you think it would be better for headers to either:
- merge st-nci_se.h and st-nci_vendor_cmds.h in st-nci.h
- or keep st-nci_ prefix for header files only.
Which option do you prefer ?

I have no concern to remove the st-nci prefix and the st21nfca for .c 
file in their respective directory.


+void st_nci_hci_loopback_event_received(struct nci_dev *ndev, u8 
event,

+struct sk_buff *skb)
+{
+struct st_nci_info *info = nci_get_drvdata(ndev);
+
+switch (event) {
+case ST_NCI_EVT_POST_DATA:
+info->vendor_info.rx_skb = skb;
+
+complete(&info->vendor_info.req_completion);
+break;
+}

Wouldn't it make sense to complete regardless of the event you're
receiving ?
Since you're checking for rx_skb after the completion, it's safe and
would prevent you from being stuck waiting for the right event in the
below routine.
The only reason for receiving a EVT_POST_DATA from the CLF loopback 
gate should come from a

previous EVT_POST_DATA sent from the Device Host.
The loopback gate is a standard hci echo test mechanism.

Also, according to etsi 102 622 and ST implementation, the loopback 
gate only support EVT_POST_DATA.


I believe a "complete regardless of the event" we are receiving (on 
the loopback gate) may hide a CLF firmware bug and should not happen...


Are you in favour of hiding a potential bug ?

[snip]

Best Regards
Christophe


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


Re: [PATCH 18/30] nfc: st-nci: Add support for proprietary commands for factory tests

2015-10-24 Thread Christophe Ricard

Hi Samuel,

On 24/10/2015 08:48, Samuel Ortiz wrote:

Hi Christophe,

Just a couple of nitpicks:

On Tue, Oct 20, 2015 at 11:48:09PM +0200, Christophe Ricard wrote:

diff --git a/drivers/nfc/st-nci/Makefile b/drivers/nfc/st-nci/Makefile
index 348ce76..60e569b 100644
--- a/drivers/nfc/st-nci/Makefile
+++ b/drivers/nfc/st-nci/Makefile
@@ -2,7 +2,7 @@
  # Makefile for ST21NFCB NCI based NFC driver
  #
  
-st-nci-objs = ndlc.o core.o st-nci_se.o

+st-nci-objs = ndlc.o core.o st-nci_se.o st-nci_vendor_cmds.o

Please rename that file to vendor_cmds.c.
I pushed a change to rename st-nci_se.c to se.c already, to keep the
file names consistent there.
I think your latest change introduced a build break :(. The log message 
mention also MFC instead of NFC ;).


"In file included from drivers/nfc/st-nci/ndlc.c:23:0:
drivers/nfc/st-nci/st-nci.h:22:23: fatal error: st-nci_se.h: No such 
file or directory

#include "st-nci_se.h""
I will send a fix in the v2 ;).




  obj-$(CONFIG_NFC_ST_NCI) += st-nci.o
  
  st-nci_i2c-objs = i2c.o

diff --git a/drivers/nfc/st-nci/core.c b/drivers/nfc/st-nci/core.c
index c419d39..fd2a5ca 100644
--- a/drivers/nfc/st-nci/core.c
+++ b/drivers/nfc/st-nci/core.c
@@ -25,6 +25,7 @@
  
  #include "st-nci.h"

  #include "st-nci_se.h"
+#include "st-nci_vendor_cmds.h"

Ditto: Please rename it to vendor_cmds.h.

Don't you think it would be better for headers to either:
- merge st-nci_se.h and st-nci_vendor_cmds.h in st-nci.h
- or keep st-nci_ prefix for header files only.
Which option do you prefer ?

I have no concern to remove the st-nci prefix and the st21nfca for .c 
file in their respective directory.



+void st_nci_hci_loopback_event_received(struct nci_dev *ndev, u8 event,
+   struct sk_buff *skb)
+{
+   struct st_nci_info *info = nci_get_drvdata(ndev);
+
+   switch (event) {
+   case ST_NCI_EVT_POST_DATA:
+   info->vendor_info.rx_skb = skb;
+
+   complete(&info->vendor_info.req_completion);
+   break;
+   }

Wouldn't it make sense to complete regardless of the event you're
receiving ?
Since you're checking for rx_skb after the completion, it's safe and
would prevent you from being stuck waiting for the right event in the
below routine.
The only reason for receiving a EVT_POST_DATA from the CLF loopback gate 
should come from a

previous EVT_POST_DATA sent from the Device Host.
The loopback gate is a standard hci echo test mechanism.

Also, according to etsi 102 622 and ST implementation, the loopback gate 
only support EVT_POST_DATA.


I believe a "complete regardless of the event" we are receiving (on the 
loopback gate) may hide a CLF firmware bug and should not happen...


Are you in favour of hiding a potential bug ?

[snip]

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


[PATCH 02/30] nfc: nci: Fix incorrect data chaining when sending data

2015-10-20 Thread Christophe Ricard
When sending HCI data over NCI, cmd information should be present only on
the first packet. Each packet shall be specifically allocated and sent to
the NCI layer.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 net/nfc/nci/hci.c | 19 ---
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/net/nfc/nci/hci.c b/net/nfc/nci/hci.c
index 609f922..bc6b9d5 100644
--- a/net/nfc/nci/hci.c
+++ b/net/nfc/nci/hci.c
@@ -146,18 +146,18 @@ static int nci_hci_send_data(struct nci_dev *ndev, u8 
pipe,
if (!conn_info)
return -EPROTO;
 
-   skb = nci_skb_alloc(ndev, 2 + conn_info->max_pkt_payload_len +
+   i = 0;
+   skb = nci_skb_alloc(ndev, conn_info->max_pkt_payload_len +
NCI_DATA_HDR_SIZE, GFP_KERNEL);
if (!skb)
return -ENOMEM;
 
-   skb_reserve(skb, 2 + NCI_DATA_HDR_SIZE);
+   skb_reserve(skb, NCI_DATA_HDR_SIZE + 2);
*skb_push(skb, 1) = data_type;
 
-   i = 0;
-   len = conn_info->max_pkt_payload_len;
-
do {
+   len = conn_info->max_pkt_payload_len;
+
/* If last packet add NCI_HFP_NO_CHAINING */
if (i + conn_info->max_pkt_payload_len -
(skb->len + 1) >= data_len) {
@@ -177,9 +177,14 @@ static int nci_hci_send_data(struct nci_dev *ndev, u8 pipe,
return r;
 
i += len;
+
if (i < data_len) {
-   skb_trim(skb, 0);
-   skb_pull(skb, len);
+   skb = nci_skb_alloc(ndev, 
conn_info->max_pkt_payload_len +
+   NCI_DATA_HDR_SIZE, GFP_KERNEL);
+   if (!skb)
+   return -ENOMEM;
+
+   skb_reserve(skb, NCI_DATA_HDR_SIZE + 1);
}
} while (i < data_len);
 
-- 
2.1.4

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


[PATCH 01/30] nfc: st-nci: Fix incorrect spi buffer size

2015-10-20 Thread Christophe Ricard
When sending data over SPI, the maximum expected length is the maximum
nci packet payload + data header size + the frame head room (1 for the
ndlc header) + the frame trail room (0).

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/spi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/nfc/st-nci/spi.c b/drivers/nfc/st-nci/spi.c
index 598a58c..887d308 100644
--- a/drivers/nfc/st-nci/spi.c
+++ b/drivers/nfc/st-nci/spi.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "ndlc.h"
@@ -94,7 +95,8 @@ static int st_nci_spi_write(void *phy_id, struct sk_buff *skb)
struct st_nci_spi_phy *phy = phy_id;
struct spi_device *dev = phy->spi_dev;
struct sk_buff *skb_rx;
-   u8 buf[ST_NCI_SPI_MAX_SIZE];
+   u8 buf[ST_NCI_SPI_MAX_SIZE + NCI_DATA_HDR_SIZE +
+  ST_NCI_FRAME_HEADROOM + ST_NCI_FRAME_TAILROOM];
struct spi_transfer spi_xfer = {
.tx_buf = skb->data,
.rx_buf = buf,
-- 
2.1.4

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


[PATCH 00/30] Few fixes and st21nfca/st-nci vendor_cmds support

2015-10-20 Thread Christophe Ricard
Hi Samuel,

Please find in the following patchset severals fixes as well as vendor_cmds 
support
for st21nfca and st-nci.
vendor_cmds includes production test, trimmings & firmware update commands.

Best Regards
Christophe

Christophe Ricard (30):
  nfc: st-nci: Fix incorrect spi buffer size
  nfc: nci: Fix incorrect data chaining when sending data
  nfc: nci: Fix improper management of HCI return code
  nfc: nci: extract pipe value using NCI_HCP_MSG_GET_PIPE
  nfc: nci: add nci_hci_clear_all_pipes functions
  nfc: nci: Add a call to nci_hci_clear_all_pipes at HCI initial
activation.
  nfc: nci: add capability to create pipe on specific gate in
nci_hci_connect_gate
  nfc: st-nci: Remove ndev->hci_dev->init_data.gates initialization in
load_session
  nfc: st21nfca: Remove hdev->init_data.gates initialization in
load_session
  nfc: st-nci: Open NCI_HCI_LINK_MGMT_PIPE
  nfc: st21nfca: Open NFC_HCI_LINK_MGMT_PIPE
  nfc: st-nci: Keep st_nci_gates unchanged in load_session
  nfc: st21nfca: Keep st21nfca_gates unchanged in load_session
  nfc: st-nci: initialize gate_count in st_nci_hci_network_init
  nfc: st-nci: Add support for NCI_HCI_IDENTITY_MGMT_GATE
  nfc: st-nci: Change st_nci_gates offset when looking for a pipe in the
table
  nfc: st21nfca: Change st21nfca_gates offset when looking for a pipe in
the table
  nfc: st-nci: Add support for proprietary commands for factory tests
  nfc: netlink: Add missing NFC_ATTR comments
  nfc: st-nci: Add ese-present/uicc-present dts properties
  nfc: st-nci: Increase waiting time between 2 secure element activation
  nfc: st-nci: Fix host_list verification after secure element
activation
  nfc: st21nfca: Fix host_list verification after secure element
activation
  nfc: netlink: Add suspend_target handler and nfc_reactivate_target
  nfc: st-nci: Add few code style fixes
  nfc: st21nfca: Add few code style fixes
  nfc: st21nfca: Add support for proprietary commands for factory tests
  nfc: st-nci: Make sure irq is not already active when powering the
device
  nfc: st-nci: remove duplicated skb dump
  nfc: st-nci: Replace st21nfcb by st_nci in makefile

 .../devicetree/bindings/net/nfc/st-nci-i2c.txt |   7 +
 .../devicetree/bindings/net/nfc/st-nci-spi.txt |   9 +-
 drivers/nfc/st-nci/Makefile|   4 +-
 drivers/nfc/st-nci/core.c  |  18 +-
 drivers/nfc/st-nci/i2c.c   |  33 +-
 drivers/nfc/st-nci/ndlc.c  |   7 +-
 drivers/nfc/st-nci/ndlc.h  |   5 +-
 drivers/nfc/st-nci/spi.c   |  35 +-
 drivers/nfc/st-nci/st-nci.h|   7 +-
 drivers/nfc/st-nci/st-nci_se.c | 160 ---
 drivers/nfc/st-nci/st-nci_se.h |  10 +-
 drivers/nfc/st-nci/st-nci_vendor_cmds.c| 516 +
 drivers/nfc/st-nci/st-nci_vendor_cmds.h|  88 
 drivers/nfc/st21nfca/Makefile  |   2 +-
 drivers/nfc/st21nfca/i2c.c |   1 +
 drivers/nfc/st21nfca/st21nfca.c|  45 +-
 drivers/nfc/st21nfca/st21nfca.h|   4 +-
 drivers/nfc/st21nfca/st21nfca_se.c |  11 +-
 drivers/nfc/st21nfca/st21nfca_vendor_cmds.c| 369 +++
 drivers/nfc/st21nfca/st21nfca_vendor_cmds.h|  74 +++
 include/linux/platform_data/st-nci.h   |   2 +
 include/net/nfc/nci_core.h |   3 +
 include/net/nfc/nfc.h  |   2 +
 include/uapi/linux/nfc.h   |   2 +
 net/nfc/core.c |  46 ++
 net/nfc/nci/core.c |  23 +-
 net/nfc/nci/hci.c  | 159 +--
 net/nfc/netlink.c  |   3 +-
 net/nfc/nfc.h  |   2 +
 29 files changed, 1490 insertions(+), 157 deletions(-)
 create mode 100644 drivers/nfc/st-nci/st-nci_vendor_cmds.c
 create mode 100644 drivers/nfc/st-nci/st-nci_vendor_cmds.h
 create mode 100644 drivers/nfc/st21nfca/st21nfca_vendor_cmds.c
 create mode 100644 drivers/nfc/st21nfca/st21nfca_vendor_cmds.h

-- 
2.1.4

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


[PATCH 03/30] nfc: nci: Fix improper management of HCI return code

2015-10-20 Thread Christophe Ricard
When sending HCI data over NCI, HCI return code is part of the NCI data.
In order to get correctly the HCI return code, we assume the NCI
communication is successful and extract the return code for the nci_hci
functions return code.

This is done because nci_to_errno does not match hci return code value.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 net/nfc/nci/hci.c | 60 ---
 1 file changed, 44 insertions(+), 16 deletions(-)

diff --git a/net/nfc/nci/hci.c b/net/nfc/nci/hci.c
index bc6b9d5..73afb47 100644
--- a/net/nfc/nci/hci.c
+++ b/net/nfc/nci/hci.c
@@ -101,6 +101,20 @@ struct nci_hcp_packet {
 #define NCI_HCP_MSG_GET_CMD(header)  (header & 0x3f)
 #define NCI_HCP_MSG_GET_PIPE(header) (header & 0x7f)
 
+static int nci_hci_result_to_errno(u8 result)
+{
+   switch (result) {
+   case NCI_HCI_ANY_OK:
+   return 0;
+   case NCI_HCI_ANY_E_REG_PAR_UNKNOWN:
+   return -EOPNOTSUPP;
+   case NCI_HCI_ANY_E_TIMEOUT:
+   return -ETIME;
+   default:
+   return -1;
+   }
+}
+
 /* HCI core */
 static void nci_hci_reset_pipes(struct nci_hci_dev *hdev)
 {
@@ -217,7 +231,8 @@ int nci_hci_send_cmd(struct nci_dev *ndev, u8 gate, u8 cmd,
 const u8 *param, size_t param_len,
 struct sk_buff **skb)
 {
-   struct nci_conn_info*conn_info;
+   struct nci_hcp_message *message;
+   struct nci_conn_info   *conn_info;
struct nci_data data;
int r;
u8 pipe = ndev->hci_dev->gate2pipe[gate];
@@ -237,9 +252,14 @@ int nci_hci_send_cmd(struct nci_dev *ndev, u8 gate, u8 cmd,
 
r = nci_request(ndev, nci_hci_send_data_req, (unsigned long)&data,
msecs_to_jiffies(NCI_DATA_TIMEOUT));
+   if (r == NCI_STATUS_OK) {
+   message = (struct nci_hcp_message *)conn_info->rx_skb->data;
+   r = 
nci_hci_result_to_errno(NCI_HCP_MSG_GET_CMD(message->header));
+   skb_pull(conn_info->rx_skb, NCI_HCI_HCP_MESSAGE_HEADER_LEN);
 
-   if (r == NCI_STATUS_OK && skb)
-   *skb = conn_info->rx_skb;
+   if (!r && skb)
+   *skb = conn_info->rx_skb;
+   }
 
return r;
 }
@@ -333,9 +353,6 @@ static void nci_hci_resp_received(struct nci_dev *ndev, u8 
pipe,
struct nci_conn_info*conn_info;
u8 status = result;
 
-   if (result != NCI_HCI_ANY_OK)
-   goto exit;
-
conn_info = ndev->hci_dev->conn_info;
if (!conn_info) {
status = NCI_STATUS_REJECTED;
@@ -345,7 +362,7 @@ static void nci_hci_resp_received(struct nci_dev *ndev, u8 
pipe,
conn_info->rx_skb = skb;
 
 exit:
-   nci_req_complete(ndev, status);
+   nci_req_complete(ndev, NCI_STATUS_OK);
 }
 
 /* Receive hcp message for pipe, with type and cmd.
@@ -400,7 +417,7 @@ void nci_hci_data_received_cb(void *context,
 {
struct nci_dev *ndev = (struct nci_dev *)context;
struct nci_hcp_packet *packet;
-   u8 pipe, type, instruction;
+   u8 pipe, type;
struct sk_buff *hcp_skb;
struct sk_buff *frag_skb;
int msg_len;
@@ -439,7 +456,7 @@ void nci_hci_data_received_cb(void *context,
*skb_put(hcp_skb, NCI_HCI_HCP_PACKET_HEADER_LEN) = pipe;
 
skb_queue_walk(&ndev->hci_dev->rx_hcp_frags, frag_skb) {
-  msg_len = frag_skb->len - NCI_HCI_HCP_PACKET_HEADER_LEN;
+   msg_len = frag_skb->len - NCI_HCI_HCP_PACKET_HEADER_LEN;
memcpy(skb_put(hcp_skb, msg_len), frag_skb->data +
   NCI_HCI_HCP_PACKET_HEADER_LEN, msg_len);
}
@@ -457,11 +474,9 @@ void nci_hci_data_received_cb(void *context,
packet = (struct nci_hcp_packet *)hcp_skb->data;
type = NCI_HCP_MSG_GET_TYPE(packet->message.header);
if (type == NCI_HCI_HCP_RESPONSE) {
-   pipe = packet->header;
-   instruction = NCI_HCP_MSG_GET_CMD(packet->message.header);
-   skb_pull(hcp_skb, NCI_HCI_HCP_PACKET_HEADER_LEN +
-NCI_HCI_HCP_MESSAGE_HEADER_LEN);
-   nci_hci_hcp_message_rx(ndev, pipe, type, instruction, hcp_skb);
+   pipe = NCI_HCP_MSG_GET_PIPE(packet->header);
+   skb_pull(hcp_skb, NCI_HCI_HCP_PACKET_HEADER_LEN);
+   nci_hci_hcp_message_rx(ndev, pipe, type, NCI_STATUS_OK, 
hcp_skb);
} else {
skb_queue_tail(&ndev->hci_dev->msg_rx_queue, hcp_skb);
schedule_work(&ndev->hci_dev->msg_rx_work);
@@ -493,6 +508,7 @@ EXPORT_SYMBOL(nci_hci_open_pipe);
 int nci_hci_set_param(struct nci_dev *ndev, u8 gate, u8 idx,
  const u8 *param, size_t param_len)
 {
+   struct nci_hcp_message *mess

[PATCH 08/30] nfc: st-nci: Remove ndev->hci_dev->init_data.gates initialization in load_session

2015-10-20 Thread Christophe Ricard
ndev->hci_dev->init_data.gates is already initialized in st_nci_hci_network.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/st-nci_se.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/nfc/st-nci/st-nci_se.c b/drivers/nfc/st-nci/st-nci_se.c
index c742ef6..15fb0bb 100644
--- a/drivers/nfc/st-nci/st-nci_se.c
+++ b/drivers/nfc/st-nci/st-nci_se.c
@@ -245,9 +245,6 @@ int st_nci_hci_load_session(struct nci_dev *ndev)
kfree_skb(skb_pipe_info);
}
 
-   memcpy(ndev->hci_dev->init_data.gates, st_nci_gates,
-  sizeof(st_nci_gates));
-
kfree_skb(skb_pipe_list);
return r;
 }
-- 
2.1.4

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


[PATCH 10/30] nfc: st-nci: Open NCI_HCI_LINK_MGMT_PIPE

2015-10-20 Thread Christophe Ricard
NCI_HCI_LINK_MGMT_PIPE was never open in st_nci_hci_load_session.

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/st-nci_se.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/nfc/st-nci/st-nci_se.c b/drivers/nfc/st-nci/st-nci_se.c
index 15fb0bb..3ea5384 100644
--- a/drivers/nfc/st-nci/st-nci_se.c
+++ b/drivers/nfc/st-nci/st-nci_se.c
@@ -245,6 +245,14 @@ int st_nci_hci_load_session(struct nci_dev *ndev)
kfree_skb(skb_pipe_info);
}
 
+   /*
+* 3 gates have a well known pipe ID. Only NCI_HCI_LINK_MGMT_GATE
+* is not yet open at this stage.
+*/
+   r = nci_hci_connect_gate(ndev, ST_NCI_HOST_CONTROLLER_ID,
+NCI_HCI_LINK_MGMT_GATE,
+NCI_HCI_LINK_MGMT_PIPE);
+
kfree_skb(skb_pipe_list);
return r;
 }
-- 
2.1.4

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


[PATCH 12/30] nfc: st-nci: Keep st_nci_gates unchanged in load_session

2015-10-20 Thread Christophe Ricard
We need to keep initial st_nci_gates values in order for
nci_hci_dev_connect_gates to create and open pipe when necessary.

For example after a firmware update CLF pipes are cleared. Changing pipe
values in st_nci_gates was causing nci_hci_dev_connect_gates not using
accurate pipes value.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/st-nci_se.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/nfc/st-nci/st-nci_se.c b/drivers/nfc/st-nci/st-nci_se.c
index 3ea5384..2a475ce 100644
--- a/drivers/nfc/st-nci/st-nci_se.c
+++ b/drivers/nfc/st-nci/st-nci_se.c
@@ -233,13 +233,13 @@ int st_nci_hci_load_session(struct nci_dev *ndev)
if (j < ARRAY_SIZE(st_nci_gates) &&
st_nci_gates[j].gate == dm_pipe_info->dst_gate_id &&
ST_NCI_DM_IS_PIPE_OPEN(dm_pipe_info->pipe_state)) {
-   st_nci_gates[j].pipe = pipe_info[2];
+   ndev->hci_dev->init_data.gates[j].pipe = pipe_info[2];
 
ndev->hci_dev->gate2pipe[st_nci_gates[j].gate] =
-   st_nci_gates[j].pipe;
-   ndev->hci_dev->pipes[st_nci_gates[j].pipe].gate =
+   pipe_info[2];
+   ndev->hci_dev->pipes[pipe_info[2]].gate =
st_nci_gates[j].gate;
-   ndev->hci_dev->pipes[st_nci_gates[j].pipe].host =
+   ndev->hci_dev->pipes[pipe_info[2]].host =
dm_pipe_info->src_host_id;
}
kfree_skb(skb_pipe_info);
-- 
2.1.4

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


[PATCH 09/30] nfc: st21nfca: Remove hdev->init_data.gates initialization in load_session

2015-10-20 Thread Christophe Ricard
hdev->init_data.gates is already initialized in st21nfca_hci_probe.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st21nfca/st21nfca.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/nfc/st21nfca/st21nfca.c b/drivers/nfc/st21nfca/st21nfca.c
index 0512865..33e1e8f 100644
--- a/drivers/nfc/st21nfca/st21nfca.c
+++ b/drivers/nfc/st21nfca/st21nfca.c
@@ -220,7 +220,6 @@ static int st21nfca_hci_load_session(struct nfc_hci_dev 
*hdev)
}
}
 
-   memcpy(hdev->init_data.gates, st21nfca_gates, sizeof(st21nfca_gates));
 free_list:
kfree_skb(skb_pipe_list);
return r;
-- 
2.1.4

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


[PATCH 26/30] nfc: st21nfca: Add few code style fixes

2015-10-20 Thread Christophe Ricard
Add a minor code style fixes

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st21nfca/i2c.c  | 1 +
 drivers/nfc/st21nfca/st21nfca.c | 2 --
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/nfc/st21nfca/i2c.c b/drivers/nfc/st21nfca/i2c.c
index b2c914b..84c2cb0 100644
--- a/drivers/nfc/st21nfca/i2c.c
+++ b/drivers/nfc/st21nfca/i2c.c
@@ -94,6 +94,7 @@ struct st21nfca_i2c_phy {
int hard_fault;
struct mutex phy_lock;
 };
+
 static u8 len_seq[] = { 16, 24, 12, 29 };
 static u16 wait_tab[] = { 2, 3, 5, 15, 20, 40};
 
diff --git a/drivers/nfc/st21nfca/st21nfca.c b/drivers/nfc/st21nfca/st21nfca.c
index 0e84ce6..76ef9cf 100644
--- a/drivers/nfc/st21nfca/st21nfca.c
+++ b/drivers/nfc/st21nfca/st21nfca.c
@@ -164,7 +164,6 @@ static int st21nfca_hci_load_session(struct nfc_hci_dev 
*hdev)
r = nfc_hci_send_cmd(hdev, ST21NFCA_DEVICE_MGNT_GATE,
ST21NFCA_DM_GETINFO, pipe_info,
sizeof(pipe_info), &skb_pipe_info);
-
if (r)
continue;
 
@@ -984,7 +983,6 @@ int st21nfca_hci_probe(void *phy_id, struct nfc_phy_ops 
*phy_ops,
 * persistent info to discriminate 2 identical chips
 */
dev_num = find_first_zero_bit(dev_mask, ST21NFCA_NUM_DEVICES);
-
if (dev_num >= ST21NFCA_NUM_DEVICES)
return -ENODEV;
 
-- 
2.1.4

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


[PATCH 30/30] nfc: st-nci: Replace st21nfcb by st_nci in makefile

2015-10-20 Thread Christophe Ricard
Replace 1 missing st21nfcb by st_nci

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nfc/st-nci/Makefile b/drivers/nfc/st-nci/Makefile
index 60e569b..bd74c60 100644
--- a/drivers/nfc/st-nci/Makefile
+++ b/drivers/nfc/st-nci/Makefile
@@ -1,5 +1,5 @@
 #
-# Makefile for ST21NFCB NCI based NFC driver
+# Makefile for ST_NCI NCI based NFC driver
 #
 
 st-nci-objs = ndlc.o core.o st-nci_se.o st-nci_vendor_cmds.o
-- 
2.1.4

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


[PATCH 11/30] nfc: st21nfca: Open NFC_HCI_LINK_MGMT_PIPE

2015-10-20 Thread Christophe Ricard
NFC_HCI_LINK_MGMT_PIPE was never open in nfc_hci_load_session.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st21nfca/st21nfca.c | 19 +--
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/drivers/nfc/st21nfca/st21nfca.c b/drivers/nfc/st21nfca/st21nfca.c
index 33e1e8f..5ff9b33 100644
--- a/drivers/nfc/st21nfca/st21nfca.c
+++ b/drivers/nfc/st21nfca/st21nfca.c
@@ -205,22 +205,13 @@ static int st21nfca_hci_load_session(struct nfc_hci_dev 
*hdev)
}
 
/*
-* 3 gates have a well known pipe ID.
-* They will never appear in the pipe list
+* 3 gates have a well known pipe ID. Only NFC_HCI_LINK_MGMT_GATE
+* is not yet open at this stage.
 */
-   if (skb_pipe_list->len + 3 < ARRAY_SIZE(st21nfca_gates)) {
-   for (i = skb_pipe_list->len + 3;
-   i < ARRAY_SIZE(st21nfca_gates) - 2; i++) {
-   r = nfc_hci_connect_gate(hdev,
-   NFC_HCI_HOST_CONTROLLER_ID,
-   st21nfca_gates[i].gate,
-   st21nfca_gates[i].pipe);
-   if (r < 0)
-   goto free_list;
-   }
-   }
+   r = nfc_hci_connect_gate(hdev, NFC_HCI_HOST_CONTROLLER_ID,
+NFC_HCI_LINK_MGMT_GATE,
+NFC_HCI_LINK_MGMT_PIPE);
 
-free_list:
kfree_skb(skb_pipe_list);
return r;
 }
-- 
2.1.4

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


[PATCH 29/30] nfc: st-nci: remove duplicated skb dump

2015-10-20 Thread Christophe Ricard
Remove SPI_DUMP_SKB and I2C_DUMP_SKB as skb is already dumped in ndlc
layer.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/i2c.c | 11 ---
 drivers/nfc/st-nci/spi.c | 11 ---
 2 files changed, 22 deletions(-)

diff --git a/drivers/nfc/st-nci/i2c.c b/drivers/nfc/st-nci/i2c.c
index 13f5054..3c04f6b 100644
--- a/drivers/nfc/st-nci/i2c.c
+++ b/drivers/nfc/st-nci/i2c.c
@@ -58,13 +58,6 @@ struct st_nci_i2c_phy {
struct st_nci_se_status se_status;
 };
 
-#define I2C_DUMP_SKB(info, skb)\
-do {   \
-   pr_debug("%s:\n", info);\
-   print_hex_dump(KERN_DEBUG, "i2c: ", DUMP_PREFIX_OFFSET, \
-  16, 1, (skb)->data, (skb)->len, 0);  \
-} while (0)
-
 static int st_nci_i2c_enable(void *phy_id)
 {
struct st_nci_i2c_phy *phy = phy_id;
@@ -101,8 +94,6 @@ static int st_nci_i2c_write(void *phy_id, struct sk_buff 
*skb)
struct st_nci_i2c_phy *phy = phy_id;
struct i2c_client *client = phy->i2c_dev;
 
-   I2C_DUMP_SKB("st_nci_i2c_write", skb);
-
if (phy->ndlc->hard_fault != 0)
return phy->ndlc->hard_fault;
 
@@ -173,8 +164,6 @@ static int st_nci_i2c_read(struct st_nci_i2c_phy *phy,
skb_put(*skb, len);
memcpy((*skb)->data + ST_NCI_I2C_MIN_SIZE, buf, len);
 
-   I2C_DUMP_SKB("i2c frame read", *skb);
-
return 0;
 }
 
diff --git a/drivers/nfc/st-nci/spi.c b/drivers/nfc/st-nci/spi.c
index 10404c9..4994f2a 100644
--- a/drivers/nfc/st-nci/spi.c
+++ b/drivers/nfc/st-nci/spi.c
@@ -59,13 +59,6 @@ struct st_nci_spi_phy {
struct st_nci_se_status se_status;
 };
 
-#define SPI_DUMP_SKB(info, skb)\
-do {   \
-   pr_debug("%s:\n", info);\
-   print_hex_dump(KERN_DEBUG, "spi: ", DUMP_PREFIX_OFFSET, \
-  16, 1, (skb)->data, (skb)->len, 0);  \
-} while (0)
-
 static int st_nci_spi_enable(void *phy_id)
 {
struct st_nci_spi_phy *phy = phy_id;
@@ -110,8 +103,6 @@ static int st_nci_spi_write(void *phy_id, struct sk_buff 
*skb)
.len = skb->len,
};
 
-   SPI_DUMP_SKB("st_nci_spi_write", skb);
-
if (phy->ndlc->hard_fault != 0)
return phy->ndlc->hard_fault;
 
@@ -188,8 +179,6 @@ static int st_nci_spi_read(struct st_nci_spi_phy *phy,
skb_put(*skb, len);
memcpy((*skb)->data + ST_NCI_SPI_MIN_SIZE, buf, len);
 
-   SPI_DUMP_SKB("spi frame read", *skb);
-
return 0;
 }
 
-- 
2.1.4

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


[PATCH 05/30] nfc: nci: add nci_hci_clear_all_pipes functions

2015-10-20 Thread Christophe Ricard
nci_hci_clear_all_pipes might be use full in some cases for example after
a firmware update.

Signed-off-by: Christophe Ricard 
---
 include/net/nfc/nci_core.h |  1 +
 net/nfc/nci/hci.c  | 15 +++
 2 files changed, 16 insertions(+)

diff --git a/include/net/nfc/nci_core.h b/include/net/nfc/nci_core.h
index d0d0f1e..b2f2e04 100644
--- a/include/net/nfc/nci_core.h
+++ b/include/net/nfc/nci_core.h
@@ -305,6 +305,7 @@ int nci_hci_set_param(struct nci_dev *ndev, u8 gate, u8 idx,
  const u8 *param, size_t param_len);
 int nci_hci_get_param(struct nci_dev *ndev, u8 gate, u8 idx,
  struct sk_buff **skb);
+int nci_hci_clear_all_pipes(struct nci_dev *ndev);
 int nci_hci_dev_session_init(struct nci_dev *ndev);
 
 static inline struct sk_buff *nci_skb_alloc(struct nci_dev *ndev,
diff --git a/net/nfc/nci/hci.c b/net/nfc/nci/hci.c
index abe0200..e7148cf 100644
--- a/net/nfc/nci/hci.c
+++ b/net/nfc/nci/hci.c
@@ -70,6 +70,7 @@ struct nci_hcp_packet {
 #define NCI_HCI_ANY_SET_PARAMETER  0x01
 #define NCI_HCI_ANY_GET_PARAMETER  0x02
 #define NCI_HCI_ANY_CLOSE_PIPE 0x04
+#define NCI_HCI_ADM_CLEAR_ALL_PIPE 0x14
 
 #define NCI_HFP_NO_CHAINING0x80
 
@@ -265,6 +266,20 @@ int nci_hci_send_cmd(struct nci_dev *ndev, u8 gate, u8 cmd,
 }
 EXPORT_SYMBOL(nci_hci_send_cmd);
 
+int nci_hci_clear_all_pipes(struct nci_dev *ndev)
+{
+   int r;
+
+   r = nci_hci_send_cmd(ndev, NCI_HCI_ADMIN_GATE,
+   NCI_HCI_ADM_CLEAR_ALL_PIPE, NULL, 0, NULL);
+   if (r < 0)
+   return r;
+
+   nci_hci_reset_pipes(ndev->hci_dev);
+   return r;
+}
+EXPORT_SYMBOL(nci_hci_clear_all_pipes);
+
 static void nci_hci_event_received(struct nci_dev *ndev, u8 pipe,
   u8 event, struct sk_buff *skb)
 {
-- 
2.1.4

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


[PATCH 04/30] nfc: nci: extract pipe value using NCI_HCP_MSG_GET_PIPE

2015-10-20 Thread Christophe Ricard
When receiving data in nci_hci_msg_rx_work, extract pipe value using
NCI_HCP_MSG_GET_PIPE macro.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 net/nfc/nci/hci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/nfc/nci/hci.c b/net/nfc/nci/hci.c
index 73afb47..abe0200 100644
--- a/net/nfc/nci/hci.c
+++ b/net/nfc/nci/hci.c
@@ -400,7 +400,7 @@ static void nci_hci_msg_rx_work(struct work_struct *work)
u8 pipe, type, instruction;
 
while ((skb = skb_dequeue(&hdev->msg_rx_queue)) != NULL) {
-   pipe = skb->data[0];
+   pipe = NCI_HCP_MSG_GET_PIPE(skb->data[0]);
skb_pull(skb, NCI_HCI_HCP_PACKET_HEADER_LEN);
message = (struct nci_hcp_message *)skb->data;
type = NCI_HCP_MSG_GET_TYPE(message->header);
@@ -437,7 +437,7 @@ void nci_hci_data_received_cb(void *context,
 
/* it's the last fragment. Does it need re-aggregation? */
if (skb_queue_len(&ndev->hci_dev->rx_hcp_frags)) {
-   pipe = packet->header & NCI_HCI_FRAGMENT;
+   pipe = NCI_HCP_MSG_GET_PIPE(packet->header);
skb_queue_tail(&ndev->hci_dev->rx_hcp_frags, skb);
 
msg_len = 0;
-- 
2.1.4

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


[PATCH 28/30] nfc: st-nci: Make sure irq is not already active when powering the device

2015-10-20 Thread Christophe Ricard
Upon some conditions (timing, CLF errors, platform errors...), the irq might
be already active when powering the device.

Add irq_active variable as a guard to avoid kernel warning message

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/i2c.c | 8 +++-
 drivers/nfc/st-nci/spi.c | 8 +++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/nfc/st-nci/i2c.c b/drivers/nfc/st-nci/i2c.c
index 8b53cdf..13f5054 100644
--- a/drivers/nfc/st-nci/i2c.c
+++ b/drivers/nfc/st-nci/i2c.c
@@ -50,6 +50,8 @@ struct st_nci_i2c_phy {
struct i2c_client *i2c_dev;
struct llt_ndlc *ndlc;
 
+   bool irq_active;
+
unsigned int gpio_reset;
unsigned int irq_polarity;
 
@@ -72,8 +74,10 @@ static int st_nci_i2c_enable(void *phy_id)
gpio_set_value(phy->gpio_reset, 1);
usleep_range(8, 85000);
 
-   if (phy->ndlc->powered == 0)
+   if (phy->ndlc->powered == 0 && phy->irq_active == 0) {
enable_irq(phy->i2c_dev->irq);
+   phy->irq_active = true;
+   }
 
return 0;
 }
@@ -83,6 +87,7 @@ static void st_nci_i2c_disable(void *phy_id)
struct st_nci_i2c_phy *phy = phy_id;
 
disable_irq_nosync(phy->i2c_dev->irq);
+   phy->irq_active = false;
 }
 
 /*
@@ -342,6 +347,7 @@ static int st_nci_i2c_probe(struct i2c_client *client,
return r;
}
 
+   phy->irq_active = true;
r = devm_request_threaded_irq(&client->dev, client->irq, NULL,
st_nci_irq_thread_fn,
phy->irq_polarity | IRQF_ONESHOT,
diff --git a/drivers/nfc/st-nci/spi.c b/drivers/nfc/st-nci/spi.c
index c37ecd4..10404c9 100644
--- a/drivers/nfc/st-nci/spi.c
+++ b/drivers/nfc/st-nci/spi.c
@@ -51,6 +51,8 @@ struct st_nci_spi_phy {
struct spi_device *spi_dev;
struct llt_ndlc *ndlc;
 
+   bool irq_active;
+
unsigned int gpio_reset;
unsigned int irq_polarity;
 
@@ -73,8 +75,10 @@ static int st_nci_spi_enable(void *phy_id)
gpio_set_value(phy->gpio_reset, 1);
usleep_range(8, 85000);
 
-   if (phy->ndlc->powered == 0)
+   if (phy->ndlc->powered == 0 && phy->irq_active == 0) {
enable_irq(phy->spi_dev->irq);
+   phy->irq_active = true;
+   }
 
return 0;
 }
@@ -84,6 +88,7 @@ static void st_nci_spi_disable(void *phy_id)
struct st_nci_spi_phy *phy = phy_id;
 
disable_irq_nosync(phy->spi_dev->irq);
+   phy->irq_active = false;
 }
 
 /*
@@ -358,6 +363,7 @@ static int st_nci_spi_probe(struct spi_device *dev)
return r;
}
 
+   phy->irq_active = true;
r = devm_request_threaded_irq(&dev->dev, dev->irq, NULL,
st_nci_irq_thread_fn,
phy->irq_polarity | IRQF_ONESHOT,
-- 
2.1.4

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


[PATCH 25/30] nfc: st-nci: Add few code style fixes

2015-10-20 Thread Christophe Ricard
Add some few code style fixes.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/i2c.c   | 2 +-
 drivers/nfc/st-nci/st-nci_se.c | 2 +-
 net/nfc/nci/hci.c  | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/nfc/st-nci/i2c.c b/drivers/nfc/st-nci/i2c.c
index a2700a6..8b53cdf 100644
--- a/drivers/nfc/st-nci/i2c.c
+++ b/drivers/nfc/st-nci/i2c.c
@@ -32,7 +32,7 @@
 #define DRIVER_DESC "NCI NFC driver for ST_NCI"
 
 /* ndlc header */
-#define ST_NCI_FRAME_HEADROOM  1
+#define ST_NCI_FRAME_HEADROOM 1
 #define ST_NCI_FRAME_TAILROOM 0
 
 #define ST_NCI_I2C_MIN_SIZE 4   /* PCB(1) + NCI Packet header(3) */
diff --git a/drivers/nfc/st-nci/st-nci_se.c b/drivers/nfc/st-nci/st-nci_se.c
index 8886072..3d874a0 100644
--- a/drivers/nfc/st-nci/st-nci_se.c
+++ b/drivers/nfc/st-nci/st-nci_se.c
@@ -64,7 +64,7 @@ struct st_nci_pipe_info {
 
 #define ST_NCI_EVT_SE_HARD_RESET   0x20
 #define ST_NCI_EVT_TRANSMIT_DATA   0x10
-#define ST_NCI_EVT_WTX_REQUEST 0x11
+#define ST_NCI_EVT_WTX_REQUEST 0x11
 #define ST_NCI_EVT_SE_SOFT_RESET   0x11
 #define ST_NCI_EVT_SE_END_OF_APDU_TRANSFER 0x21
 #define ST_NCI_EVT_HOT_PLUG0x03
diff --git a/net/nfc/nci/hci.c b/net/nfc/nci/hci.c
index 5212ef2..d82fdef 100644
--- a/net/nfc/nci/hci.c
+++ b/net/nfc/nci/hci.c
@@ -405,7 +405,7 @@ static void nci_hci_hcp_message_rx(struct nci_dev *ndev, u8 
pipe,
break;
}
 
-   nci_req_complete(ndev, 0);
+   nci_req_complete(ndev, NCI_STATUS_OK);
 }
 
 static void nci_hci_msg_rx_work(struct work_struct *work)
-- 
2.1.4

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


[PATCH 24/30] nfc: netlink: Add suspend_target handler and nfc_reactivate_target

2015-10-20 Thread Christophe Ricard
In order to manage in a better way the nci poll mode state machine, add
a suspend_target handler. In this way the netlink nfc_genl_activate_target
rely on a new function nfc_reactivate_target calling suspend_target handler
if available (only in nci core).

Signed-off-by: Christophe Ricard 
---
 include/net/nfc/nfc.h |  2 ++
 net/nfc/core.c| 46 ++
 net/nfc/nci/core.c| 23 +++
 net/nfc/netlink.c |  3 +--
 net/nfc/nfc.h |  2 ++
 5 files changed, 70 insertions(+), 6 deletions(-)

diff --git a/include/net/nfc/nfc.h b/include/net/nfc/nfc.h
index 30afc9a..380ab8b 100644
--- a/include/net/nfc/nfc.h
+++ b/include/net/nfc/nfc.h
@@ -67,6 +67,8 @@ struct nfc_ops {
int (*dep_link_down)(struct nfc_dev *dev);
int (*activate_target)(struct nfc_dev *dev, struct nfc_target *target,
   u32 protocol);
+   void (*suspend_target)(struct nfc_dev *dev,
+  struct nfc_target *target);
void (*deactivate_target)(struct nfc_dev *dev,
  struct nfc_target *target);
int (*im_transceive)(struct nfc_dev *dev, struct nfc_target *target,
diff --git a/net/nfc/core.c b/net/nfc/core.c
index cff3f16..70276b6 100644
--- a/net/nfc/core.c
+++ b/net/nfc/core.c
@@ -485,6 +485,52 @@ error:
 }
 
 /**
+ * nfc_reactivate_target - reactivate the target for data exchange
+ *
+ * @dev: The nfc device that found the target
+ * @target_idx: index of the target that must be activated
+ * @protocol: nfc protocol that will be used for data exchange
+ */
+int nfc_reactivate_target(struct nfc_dev *dev, u32 target_idx, u32 protocol)
+{
+   int rc = 0;
+
+   pr_debug("dev_name=%s target_idx=%u\n",
+dev_name(&dev->dev), target_idx);
+
+   device_lock(&dev->dev);
+
+   if (!device_is_registered(&dev->dev)) {
+   rc = -ENODEV;
+   goto error;
+   }
+
+   if (!dev->active_target) {
+   rc = -ENOTCONN;
+   goto error;
+   }
+
+   if (dev->active_target->idx != target_idx) {
+   rc = -ENOTCONN;
+   goto error;
+   }
+
+   if (dev->ops->check_presence)
+   del_timer_sync(&dev->check_pres_timer);
+
+   if (dev->ops->suspend_target)
+   dev->ops->suspend_target(dev, dev->active_target);
+
+   dev->active_target = NULL;
+   device_unlock(&dev->dev);
+
+   return nfc_activate_target(dev, target_idx, protocol);
+error:
+   device_unlock(&dev->dev);
+   return rc;
+}
+
+/**
  * nfc_data_exchange - transceive data
  *
  * @dev: The nfc device that found the target
diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c
index 943889b..b45d6e3 100644
--- a/net/nfc/nci/core.c
+++ b/net/nfc/nci/core.c
@@ -800,8 +800,9 @@ static int nci_activate_target(struct nfc_dev *nfc_dev,
return rc;
 }
 
-static void nci_deactivate_target(struct nfc_dev *nfc_dev,
- struct nfc_target *target)
+static void nci_deactivate_target_mode(struct nfc_dev *nfc_dev,
+  struct nfc_target *target,
+  __u8 mode)
 {
struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
 
@@ -815,12 +816,25 @@ static void nci_deactivate_target(struct nfc_dev *nfc_dev,
ndev->target_active_prot = 0;
 
if (atomic_read(&ndev->state) == NCI_POLL_ACTIVE) {
-   nci_request(ndev, nci_rf_deactivate_req,
-   NCI_DEACTIVATE_TYPE_IDLE_MODE,
+   nci_request(ndev, nci_rf_deactivate_req, mode,
msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT));
}
 }
 
+static void nci_deactivate_target(struct nfc_dev *nfc_dev,
+ struct nfc_target *target)
+{
+   nci_deactivate_target_mode(nfc_dev, target,
+  NCI_DEACTIVATE_TYPE_IDLE_MODE);
+}
+
+static void nci_suspend_target(struct nfc_dev *nfc_dev,
+  struct nfc_target *target)
+{
+   nci_deactivate_target_mode(nfc_dev, target,
+  NCI_DEACTIVATE_TYPE_SLEEP_MODE);
+}
+
 static int nci_dep_link_up(struct nfc_dev *nfc_dev, struct nfc_target *target,
   __u8 comm_mode, __u8 *gb, size_t gb_len)
 {
@@ -979,6 +993,7 @@ static struct nfc_ops nci_nfc_ops = {
.dep_link_up = nci_dep_link_up,
.dep_link_down = nci_dep_link_down,
.activate_target = nci_activate_target,
+   .suspend_target = nci_suspend_target,
.deactivate_target = nci_deactivate_target,
.im_transceive = nci_transceive,
.tm_send = nci_tm_send,
diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c
index 853172c..bb0e098 100644
--- a/net/nfc/netlink.c
+++ b/net/nfc/netlink.c
@@ -8

[PATCH 27/30] nfc: st21nfca: Add support for proprietary commands for factory tests

2015-10-20 Thread Christophe Ricard
Add support for proprietary commands useful mainly for factory testings.
Here is a list:
- FACTORY_MODE: Allow to set the driver into a mode where no secure element
are activated. It does not consider any NFC_ATTR_VENDOR_DATA.
- HCI_CLEAR_ALL_PIPES: Allow to execute a HCI clear all pipes command.
It does not consider any NFC_ATTR_VENDOR_DATA.
- HCI_DM_PUT_DATA: Allow to configure specific CLF registry as for example
RF trimmings or low level drivers configurations (I2C, SPI, SWP).
- HCI_DM_UPDATE_AID: Allow to configure an AID routing into the CLF routing
table following RF technology, CLF mode or protocol.
- HCI_DM_GET_INFO: Allow to retrieve CLF information.
- HCI_DM_GET_DATA: Allow to retrieve CLF configurable data such as low
level drivers configurations or RF trimmings.
- HCI_DM_LOAD: Allow to load a firmware into the CLF. A complete
packet can be more than 8KB.
- HCI_DM_RESET: Allow to run a CLF reset in order to "commit" CLF
configuration changes without CLF power off.
-  HCI_GET_PARAM: Allow to retrieve an HCI CLF parameter (for example the
white list).
- HCI_DM_FIELD_GENERATOR: Allow to generate different kind of RF
technology. When using this command to anti-collision is done.
- HCI_LOOPBACK: Allow to echo a command and test the Dh to CLF
connectivity.

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st21nfca/Makefile   |   2 +-
 drivers/nfc/st21nfca/st21nfca.c |   4 +
 drivers/nfc/st21nfca/st21nfca.h |   4 +-
 drivers/nfc/st21nfca/st21nfca_se.c  |   4 +-
 drivers/nfc/st21nfca/st21nfca_vendor_cmds.c | 369 
 drivers/nfc/st21nfca/st21nfca_vendor_cmds.h |  74 ++
 6 files changed, 454 insertions(+), 3 deletions(-)
 create mode 100644 drivers/nfc/st21nfca/st21nfca_vendor_cmds.c
 create mode 100644 drivers/nfc/st21nfca/st21nfca_vendor_cmds.h

diff --git a/drivers/nfc/st21nfca/Makefile b/drivers/nfc/st21nfca/Makefile
index 97edab4..e817c72 100644
--- a/drivers/nfc/st21nfca/Makefile
+++ b/drivers/nfc/st21nfca/Makefile
@@ -2,7 +2,7 @@
 # Makefile for ST21NFCA HCI based NFC driver
 #
 
-st21nfca_hci-objs = st21nfca.o st21nfca_dep.o st21nfca_se.o
+st21nfca_hci-objs = st21nfca.o st21nfca_dep.o st21nfca_se.o 
st21nfca_vendor_cmds.o
 obj-$(CONFIG_NFC_ST21NFCA) += st21nfca_hci.o
 
 st21nfca_i2c-objs  = i2c.o
diff --git a/drivers/nfc/st21nfca/st21nfca.c b/drivers/nfc/st21nfca/st21nfca.c
index 76ef9cf..bf82459 100644
--- a/drivers/nfc/st21nfca/st21nfca.c
+++ b/drivers/nfc/st21nfca/st21nfca.c
@@ -24,6 +24,7 @@
 #include "st21nfca.h"
 #include "st21nfca_dep.h"
 #include "st21nfca_se.h"
+#include "st21nfca_vendor_cmds.h"
 
 #define DRIVER_DESC "HCI NFC driver for ST21NFCA"
 
@@ -923,6 +924,8 @@ static int st21nfca_hci_event_received(struct nfc_hci_dev 
*hdev, u8 pipe,
event, skb);
case ST21NFCA_APDU_READER_GATE:
return st21nfca_apdu_reader_event_received(hdev, event, skb);
+   case NFC_HCI_LOOPBACK_GATE:
+   return st21nfca_hci_loopback_event_received(hdev, event, skb);
default:
return 1;
}
@@ -1024,6 +1027,7 @@ int st21nfca_hci_probe(void *phy_id, struct nfc_phy_ops 
*phy_ops,
*hdev = info->hdev;
st21nfca_dep_init(info->hdev);
st21nfca_se_init(info->hdev);
+   st21nfca_vendor_cmds_init(info->hdev);
 
return 0;
 
diff --git a/drivers/nfc/st21nfca/st21nfca.h b/drivers/nfc/st21nfca/st21nfca.h
index 15a78d3..070136b 100644
--- a/drivers/nfc/st21nfca/st21nfca.h
+++ b/drivers/nfc/st21nfca/st21nfca.h
@@ -21,6 +21,7 @@
 
 #include "st21nfca_dep.h"
 #include "st21nfca_se.h"
+#include "st21nfca_vendor_cmds.h"
 
 #define HCI_MODE 0
 
@@ -60,7 +61,7 @@ struct st21nfca_se_status {
 int st21nfca_hci_probe(void *phy_id, struct nfc_phy_ops *phy_ops,
   char *llc_name, int phy_headroom, int phy_tailroom,
   int phy_payload, struct nfc_hci_dev **hdev,
-  struct st21nfca_se_status *se_status);
+  struct st21nfca_se_status *se_status);
 void st21nfca_hci_remove(struct nfc_hci_dev *hdev);
 
 enum st21nfca_state {
@@ -85,6 +86,7 @@ struct st21nfca_hci_info {
 
struct st21nfca_dep_info dep_info;
struct st21nfca_se_info se_info;
+   struct st21nfca_vendor_info vendor_info;
 };
 
 /* Reader RF commands */
diff --git a/drivers/nfc/st21nfca/st21nfca_se.c 
b/drivers/nfc/st21nfca/st21nfca_se.c
index 0eb42ef..646c340 100644
--- a/drivers/nfc/st21nfca/st21nfca_se.c
+++ b/drivers/nfc/st21nfca/st21nfca_se.c
@@ -168,6 +168,9 @@ int st21nfca_hci_discover_se(struct nfc_hci_dev *hdev)
struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
int se_count = 0;
 
+   if (test_bit(ST21NFCA_FACTORY_MODE, &hdev->quirks))
+   return 0;
+
if 

[PATCH 07/30] nfc: nci: add capability to create pipe on specific gate in nci_hci_connect_gate

2015-10-20 Thread Christophe Ricard
Some gates might be interesting to have their pipes created.
Add in nci_hci_connect_gate a call to nci_hci_create_pipe for every gate
different than NCI_HCI_LINK_MGMT_GATE or NCI_HCI_ADMIN_GATE.

In case of an error when opening a pipe, like in hci layer, delete the pipe
if it was created.

Signed-off-by: Christophe Ricard 
---
 net/nfc/nci/hci.c | 55 ++-
 1 file changed, 54 insertions(+), 1 deletion(-)

diff --git a/net/nfc/nci/hci.c b/net/nfc/nci/hci.c
index 1b83219..5212ef2 100644
--- a/net/nfc/nci/hci.c
+++ b/net/nfc/nci/hci.c
@@ -79,6 +79,8 @@ struct nci_hcp_packet {
 #define NCI_EVT_HOT_PLUG   0x03
 
 #define NCI_HCI_ADMIN_PARAM_SESSION_IDENTITY   0x01
+#define NCI_HCI_ADM_CREATE_PIPE0x10
+#define NCI_HCI_ADM_DELETE_PIPE0x11
 
 /* HCP headers */
 #define NCI_HCI_HCP_PACKET_HEADER_LEN  1
@@ -520,6 +522,42 @@ int nci_hci_open_pipe(struct nci_dev *ndev, u8 pipe)
 }
 EXPORT_SYMBOL(nci_hci_open_pipe);
 
+static u8 nci_hci_create_pipe(struct nci_dev *ndev, u8 dest_host,
+ u8 dest_gate, int *result)
+{
+   u8 pipe;
+   struct sk_buff *skb;
+   struct nci_hci_create_pipe_params params;
+   struct nci_hci_create_pipe_resp *resp;
+
+   pr_debug("gate=%d\n", dest_gate);
+
+   params.src_gate = NCI_HCI_ADMIN_GATE;
+   params.dest_host = dest_host;
+   params.dest_gate = dest_gate;
+
+   *result = nci_hci_send_cmd(ndev, NCI_HCI_ADMIN_GATE, 
NCI_HCI_ADM_CREATE_PIPE,
+  (u8 *)¶ms, sizeof(params), &skb);
+   if (*result < 0)
+   return NCI_HCI_INVALID_PIPE;
+
+   resp = (struct nci_hci_create_pipe_resp *)skb->data;
+   pipe = resp->pipe;
+   kfree_skb(skb);
+
+   pr_debug("pipe created=%d\n", pipe);
+
+   return pipe;
+}
+
+static int nci_hci_delete_pipe(struct nci_dev *ndev, u8 pipe)
+{
+   pr_debug("\n");
+
+   return nci_hci_send_cmd(ndev, NCI_HCI_ADMIN_GATE,
+   NCI_HCI_ADM_DELETE_PIPE, &pipe, 1, NULL);
+}
+
 int nci_hci_set_param(struct nci_dev *ndev, u8 gate, u8 idx,
  const u8 *param, size_t param_len)
 {
@@ -611,6 +649,7 @@ EXPORT_SYMBOL(nci_hci_get_param);
 int nci_hci_connect_gate(struct nci_dev *ndev,
 u8 dest_host, u8 dest_gate, u8 pipe)
 {
+   bool pipe_created = false;
int r;
 
if (pipe == NCI_HCI_DO_NOT_OPEN_PIPE)
@@ -629,12 +668,26 @@ int nci_hci_connect_gate(struct nci_dev *ndev,
case NCI_HCI_ADMIN_GATE:
pipe = NCI_HCI_ADMIN_PIPE;
break;
+   default:
+   pipe = nci_hci_create_pipe(ndev, dest_host, dest_gate, &r);
+   if (pipe < 0)
+   return r;
+   pipe_created = true;
+   break;
}
 
 open_pipe:
r = nci_hci_open_pipe(ndev, pipe);
-   if (r < 0)
+   if (r < 0) {
+   if (pipe_created) {
+   if (nci_hci_delete_pipe(ndev, pipe) < 0) {
+   /* TODO: Cannot clean by deleting pipe...
+* -> inconsistent state
+*/
+   }
+   }
return r;
+   }
 
ndev->hci_dev->pipes[pipe].gate = dest_gate;
ndev->hci_dev->pipes[pipe].host = dest_host;
-- 
2.1.4

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


[PATCH 22/30] nfc: st-nci: Fix host_list verification after secure element activation

2015-10-20 Thread Christophe Ricard
A secure element can be activated in different order. The host_list is
updated keeping a fixed order: .

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/st-nci_se.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/nfc/st-nci/st-nci_se.c b/drivers/nfc/st-nci/st-nci_se.c
index ee53fc0..8886072 100644
--- a/drivers/nfc/st-nci/st-nci_se.c
+++ b/drivers/nfc/st-nci/st-nci_se.c
@@ -419,7 +419,7 @@ static int st_nci_control_se(struct nci_dev *ndev, u8 
se_idx,
 u8 state)
 {
struct st_nci_info *info = nci_get_drvdata(ndev);
-   int r;
+   int r, i;
struct sk_buff *sk_host_list;
u8 host_id;
 
@@ -466,7 +466,10 @@ static int st_nci_control_se(struct nci_dev *ndev, u8 
se_idx,
if (r != NCI_HCI_ANY_OK)
return r;
 
-   host_id = sk_host_list->data[sk_host_list->len - 1];
+   for (i = 0; i < sk_host_list->len &&
+   sk_host_list->data[i] != se_idx; i++)
+   ;
+   host_id = sk_host_list->data[i];
kfree_skb(sk_host_list);
if (state == ST_NCI_SE_MODE_ON && host_id == se_idx)
return se_idx;
-- 
2.1.4

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


[PATCH 15/30] nfc: st-nci: Add support for NCI_HCI_IDENTITY_MGMT_GATE

2015-10-20 Thread Christophe Ricard
NCI_HCI_IDENTITY_MGMT_GATE might be useful to get information for example
about hardware or firmware version.

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/st-nci_se.c | 3 +++
 include/net/nfc/nci_core.h | 1 +
 2 files changed, 4 insertions(+)

diff --git a/drivers/nfc/st-nci/st-nci_se.c b/drivers/nfc/st-nci/st-nci_se.c
index f5409ab..7b94387 100644
--- a/drivers/nfc/st-nci/st-nci_se.c
+++ b/drivers/nfc/st-nci/st-nci_se.c
@@ -113,6 +113,9 @@ static struct nci_hci_gate st_nci_gates[] = {
{ST_NCI_DEVICE_MGNT_GATE, ST_NCI_DEVICE_MGNT_PIPE,
ST_NCI_HOST_CONTROLLER_ID},
 
+   {NCI_HCI_IDENTITY_MGMT_GATE, NCI_HCI_INVALID_PIPE,
+   ST_NCI_HOST_CONTROLLER_ID},
+
/* Secure element pipes are created by secure element host */
{ST_NCI_CONNECTIVITY_GATE, NCI_HCI_DO_NOT_OPEN_PIPE,
ST_NCI_HOST_CONTROLLER_ID},
diff --git a/include/net/nfc/nci_core.h b/include/net/nfc/nci_core.h
index b2f2e04..377f3de 100644
--- a/include/net/nfc/nci_core.h
+++ b/include/net/nfc/nci_core.h
@@ -125,6 +125,7 @@ struct nci_conn_info {
 
 /* Gates */
 #define NCI_HCI_ADMIN_GATE 0x00
+#define NCI_HCI_IDENTITY_MGMT_GATE 0x05
 #define NCI_HCI_LINK_MGMT_GATE 0x06
 
 /* Pipes */
-- 
2.1.4

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


[PATCH 18/30] nfc: st-nci: Add support for proprietary commands for factory tests

2015-10-20 Thread Christophe Ricard
Add support for proprietary commands useful mainly for factory testings.
Here is a list:
- FACTORY_MODE: Allow to set the driver into a mode where no secure element
are activated. It does not consider any NFC_ATTR_VENDOR_DATA.
- HCI_CLEAR_ALL_PIPES: Allow to execute a HCI clear all pipes command.
It does not consider any NFC_ATTR_VENDOR_DATA.
- HCI_DM_PUT_DATA: Allow to configure specific CLF registry as for example
RF trimmings or low level drivers configurations (I2C, SPI, SWP).
- HCI_DM_UPDATE_AID: Allow to configure an AID routing into the CLF routing
table following RF technology, CLF mode or protocol.
- HCI_DM_GET_INFO: Allow to retrieve CLF information.
- HCI_DM_GET_DATA: Allow to retrieve CLF configurable data such as low
level drivers configurations or RF trimmings.
- HCI_DM_DIRECT_LOAD: Allow to load a firmware into the CLF. A complete
packet can be more than 8KB.
- HCI_DM_RESET: Allow to run a CLF reset in order to "commit" CLF
configuration changes without CLF power off.
-  HCI_GET_PARAM: Allow to retrieve an HCI CLF parameter (for example the
white list).
- HCI_DM_FIELD_GENERATOR: Allow to generate different kind of RF
technology. When using this command to anti-collision is done.
- HCI_LOOPBACK: Allow to echo a command and test the Dh to CLF
connectivity.
- HCI_DM_VDC_MEASUREMENT_VALUE: Allow to measure the field applied on the
CLF antenna. A value between 0 and 0x0f is returned. 0 is maximum.
- HCI_DM_FWUPD_START: Allow to put CLF into firmware update mode. It is a
specific CLF command as there is no GPIO for this.
- HCI_DM_FWUPD_END:  Allow to complete firmware update.
- HCI_DM_VDC_VALUE_COMPARISON: Allow to compare the field applied on the
CLF antenna to a reference value.
- MANUFACTURER_SPECIFIC: Allow to retrieve manufacturer specific data
received during a NCI_CORE_INIT_CMD.

Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/Makefile |   2 +-
 drivers/nfc/st-nci/core.c   |  14 +-
 drivers/nfc/st-nci/st-nci.h |   4 +
 drivers/nfc/st-nci/st-nci_se.c  |  30 +-
 drivers/nfc/st-nci/st-nci_vendor_cmds.c | 516 
 drivers/nfc/st-nci/st-nci_vendor_cmds.h |  88 ++
 include/net/nfc/nci_core.h  |   1 +
 7 files changed, 645 insertions(+), 10 deletions(-)
 create mode 100644 drivers/nfc/st-nci/st-nci_vendor_cmds.c
 create mode 100644 drivers/nfc/st-nci/st-nci_vendor_cmds.h

diff --git a/drivers/nfc/st-nci/Makefile b/drivers/nfc/st-nci/Makefile
index 348ce76..60e569b 100644
--- a/drivers/nfc/st-nci/Makefile
+++ b/drivers/nfc/st-nci/Makefile
@@ -2,7 +2,7 @@
 # Makefile for ST21NFCB NCI based NFC driver
 #
 
-st-nci-objs = ndlc.o core.o st-nci_se.o
+st-nci-objs = ndlc.o core.o st-nci_se.o st-nci_vendor_cmds.o
 obj-$(CONFIG_NFC_ST_NCI) += st-nci.o
 
 st-nci_i2c-objs = i2c.o
diff --git a/drivers/nfc/st-nci/core.c b/drivers/nfc/st-nci/core.c
index c419d39..fd2a5ca 100644
--- a/drivers/nfc/st-nci/core.c
+++ b/drivers/nfc/st-nci/core.c
@@ -25,6 +25,7 @@
 
 #include "st-nci.h"
 #include "st-nci_se.h"
+#include "st-nci_vendor_cmds.h"
 
 #define DRIVER_DESC "NCI NFC driver for ST_NCI"
 
@@ -153,14 +154,23 @@ int st_nci_probe(struct llt_ndlc *ndlc, int phy_headroom,
 
nci_set_drvdata(ndlc->ndev, info);
 
+   r = st_nci_vendor_cmds_init(ndlc->ndev);
+   if (r) {
+   pr_err("Cannot register proprietary vendor cmds\n");
+   goto err_reg_dev;
+   }
+
r = nci_register_device(ndlc->ndev);
if (r) {
pr_err("Cannot register nfc device to nci core\n");
-   nci_free_device(ndlc->ndev);
-   return r;
+   goto err_reg_dev;
}
 
return st_nci_se_init(ndlc->ndev);
+
+err_reg_dev:
+   nci_free_device(ndlc->ndev);
+   return r;
 }
 EXPORT_SYMBOL_GPL(st_nci_probe);
 
diff --git a/drivers/nfc/st-nci/st-nci.h b/drivers/nfc/st-nci/st-nci.h
index 850a239..858e8e6 100644
--- a/drivers/nfc/st-nci/st-nci.h
+++ b/drivers/nfc/st-nci/st-nci.h
@@ -20,6 +20,7 @@
 #define __LOCAL_ST_NCI_H_
 
 #include "st-nci_se.h"
+#include "st-nci_vendor_cmds.h"
 #include "ndlc.h"
 
 /* Define private flags: */
@@ -28,6 +29,8 @@
 #define ST_NCI_CORE_PROP0x01
 #define ST_NCI_SET_NFC_MODE 0x02
 
+#define ST_NCI_DEVICE_MGNT_GATE0x01
+
 struct nci_mode_set_cmd {
u8 cmd_type;
u8 mode;
@@ -41,6 +44,7 @@ struct st_nci_info {
struct llt_ndlc *ndlc;
unsigned long flags;
struct st_nci_se_info se_info;
+   struct st_nci_vendor_info vendor_info;
 };
 
 void st_nci_remove(struct nci_dev *ndev);
diff --git a/drivers/nfc/st-nci/st-nci_se.c b/drivers/nfc/st-nci/st-nci_se.c
index a8ae04e..45eda3e 100644
--- a/drivers/nfc/st-nci/st-nci_se.c
+++ b/drivers/nfc/st-nci/st-nci_se.c
@@ -24,6 +24,7 @@
 
 #include "st-nci.h"
 #inc

[PATCH 16/30] nfc: st-nci: Change st_nci_gates offset when looking for a pipe in the table

2015-10-20 Thread Christophe Ricard
It is useless to start from index 0 when looking for a gate because only
dynamic pipes are retrieved with ST_NCI_DM_GETINFO(ST_NCI_DM_GETINFO_PIPE_LIST).

The first dynamic pipe is present at index 3.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st-nci/st-nci_se.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nfc/st-nci/st-nci_se.c b/drivers/nfc/st-nci/st-nci_se.c
index 7b94387..a8ae04e 100644
--- a/drivers/nfc/st-nci/st-nci_se.c
+++ b/drivers/nfc/st-nci/st-nci_se.c
@@ -229,7 +229,7 @@ int st_nci_hci_load_session(struct nci_dev *ndev)
continue;
}
 
-   for (j = 0; (j < ARRAY_SIZE(st_nci_gates)) &&
+   for (j = 3; (j < ARRAY_SIZE(st_nci_gates)) &&
 (st_nci_gates[j].gate != dm_pipe_info->dst_gate_id); j++)
;
 
-- 
2.1.4

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


[PATCH 17/30] nfc: st21nfca: Change st21nfca_gates offset when looking for a pipe in the table

2015-10-20 Thread Christophe Ricard
It is useless to start from index 0 when looking for a gate because only
dynamic pipes are retrieved with 
ST21NFCA_DM_GETINFO(ST21NFCA_DM_GETINFO_PIPE_LIST).

The first dynamic pipe is present at index 3.

Cc: sta...@vger.kernel.org
Signed-off-by: Christophe Ricard 
---
 drivers/nfc/st21nfca/st21nfca.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/nfc/st21nfca/st21nfca.c b/drivers/nfc/st21nfca/st21nfca.c
index fb0c0ac..0e84ce6 100644
--- a/drivers/nfc/st21nfca/st21nfca.c
+++ b/drivers/nfc/st21nfca/st21nfca.c
@@ -87,12 +87,13 @@ static DECLARE_BITMAP(dev_mask, ST21NFCA_NUM_DEVICES);
 
 static struct nfc_hci_gate st21nfca_gates[] = {
{NFC_HCI_ADMIN_GATE, NFC_HCI_ADMIN_PIPE},
+   {NFC_HCI_LINK_MGMT_GATE, NFC_HCI_LINK_MGMT_PIPE},
+   {ST21NFCA_DEVICE_MGNT_GATE, ST21NFCA_DEVICE_MGNT_PIPE},
+
{NFC_HCI_LOOPBACK_GATE, NFC_HCI_INVALID_PIPE},
{NFC_HCI_ID_MGMT_GATE, NFC_HCI_INVALID_PIPE},
-   {NFC_HCI_LINK_MGMT_GATE, NFC_HCI_LINK_MGMT_PIPE},
{NFC_HCI_RF_READER_B_GATE, NFC_HCI_INVALID_PIPE},
{NFC_HCI_RF_READER_A_GATE, NFC_HCI_INVALID_PIPE},
-   {ST21NFCA_DEVICE_MGNT_GATE, ST21NFCA_DEVICE_MGNT_PIPE},
{ST21NFCA_RF_READER_F_GATE, NFC_HCI_INVALID_PIPE},
{ST21NFCA_RF_READER_14443_3_A_GATE, NFC_HCI_INVALID_PIPE},
{ST21NFCA_RF_READER_ISO15693_GATE, NFC_HCI_INVALID_PIPE},
@@ -185,7 +186,7 @@ static int st21nfca_hci_load_session(struct nfc_hci_dev 
*hdev)
continue;
}
 
-   for (j = 0; (j < ARRAY_SIZE(st21nfca_gates)) &&
+   for (j = 3; (j < ARRAY_SIZE(st21nfca_gates)) &&
(st21nfca_gates[j].gate != info->dst_gate_id) ; j++)
;
 
-- 
2.1.4

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


[PATCH 20/30] nfc: st-nci: Add ese-present/uicc-present dts properties

2015-10-20 Thread Christophe Ricard
In order to align with st21nfca, dts configuration properties ese_present
and uicc_present are made available in st-nci driver.

So far, in early development firmware, because nci_nfcee_mode_set(DISABLE)
was not supported pushed us to try to enable during the secure element
discovery phase.

After several trials on commercial and qualified firmware it appears that
nci_nfcee_mode_set(ENABLE) and nci_nfcee_mode_set(DISABLE) are properly
supported.

Such feature also help us to eventually save some time (~5ms) if only
one secure element is connected.

Signed-off-by: Christophe Ricard 
---
 .../devicetree/bindings/net/nfc/st-nci-i2c.txt |  7 ++
 .../devicetree/bindings/net/nfc/st-nci-spi.txt |  9 +-
 drivers/nfc/st-nci/core.c  |  4 +-
 drivers/nfc/st-nci/i2c.c   | 12 ++-
 drivers/nfc/st-nci/ndlc.c  |  7 +-
 drivers/nfc/st-nci/ndlc.h  |  5 +-
 drivers/nfc/st-nci/spi.c   | 12 ++-
 drivers/nfc/st-nci/st-nci.h|  3 +-
 drivers/nfc/st-nci/st-nci_se.c | 98 ++
 drivers/nfc/st-nci/st-nci_se.h | 10 ++-
 include/linux/platform_data/st-nci.h   |  2 +
 11 files changed, 123 insertions(+), 46 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/nfc/st-nci-i2c.txt 
b/Documentation/devicetree/bindings/net/nfc/st-nci-i2c.txt
index d707588..263732e 100644
--- a/Documentation/devicetree/bindings/net/nfc/st-nci-i2c.txt
+++ b/Documentation/devicetree/bindings/net/nfc/st-nci-i2c.txt
@@ -11,6 +11,10 @@ Required properties:
 Optional SoC Specific Properties:
 - pinctrl-names: Contains only one value - "default".
 - pintctrl-0: Specifies the pin control groups used for this controller.
+- ese-present: Specifies that an ese is physically connected to the nfc
+controller.
+- uicc-present: Specifies that the uicc swp signal can be physically
+connected to the nfc controller.
 
 Example (for ARM-based BeagleBoard xM with ST21NFCB on I2C2):
 
@@ -29,5 +33,8 @@ Example (for ARM-based BeagleBoard xM with ST21NFCB on I2C2):
interrupts = <2 IRQ_TYPE_LEVEL_HIGH>;
 
reset-gpios = <&gpio5 29 GPIO_ACTIVE_HIGH>;
+
+   ese-present;
+   uicc-present;
};
 };
diff --git a/Documentation/devicetree/bindings/net/nfc/st-nci-spi.txt 
b/Documentation/devicetree/bindings/net/nfc/st-nci-spi.txt
index 525681b..711ca85 100644
--- a/Documentation/devicetree/bindings/net/nfc/st-nci-spi.txt
+++ b/Documentation/devicetree/bindings/net/nfc/st-nci-spi.txt
@@ -2,7 +2,7 @@
 
 Required properties:
 - compatible: Should be "st,st21nfcb-spi"
-- spi-max-frequency: Maximum SPI frequency (<= 1000).
+- spi-max-frequency: Maximum SPI frequency (<= 400).
 - interrupt-parent: phandle for the interrupt gpio controller
 - interrupts: GPIO interrupt to which the chip is connected
 - reset-gpios: Output GPIO pin used to reset the ST21NFCB
@@ -10,6 +10,10 @@ Required properties:
 Optional SoC Specific Properties:
 - pinctrl-names: Contains only one value - "default".
 - pintctrl-0: Specifies the pin control groups used for this controller.
+- ese-present: Specifies that an ese is physically connected to the nfc
+controller.
+- uicc-present: Specifies that the uicc swp signal can be physically
+connected to the nfc controller.
 
 Example (for ARM-based BeagleBoard xM with ST21NFCB on SPI4):
 
@@ -27,5 +31,8 @@ Example (for ARM-based BeagleBoard xM with ST21NFCB on SPI4):
interrupts = <2 IRQ_TYPE_EDGE_RISING>;
 
reset-gpios = <&gpio5 29 GPIO_ACTIVE_HIGH>;
+
+   ese-present;
+   uicc-present;
};
 };
diff --git a/drivers/nfc/st-nci/core.c b/drivers/nfc/st-nci/core.c
index fd2a5ca..e88c882 100644
--- a/drivers/nfc/st-nci/core.c
+++ b/drivers/nfc/st-nci/core.c
@@ -125,7 +125,7 @@ static struct nci_ops st_nci_ops = {
 };
 
 int st_nci_probe(struct llt_ndlc *ndlc, int phy_headroom,
-  int phy_tailroom)
+int phy_tailroom, struct st_nci_se_status *se_status)
 {
struct st_nci_info *info;
int r;
@@ -166,7 +166,7 @@ int st_nci_probe(struct llt_ndlc *ndlc, int phy_headroom,
goto err_reg_dev;
}
 
-   return st_nci_se_init(ndlc->ndev);
+   return st_nci_se_init(ndlc->ndev, se_status);
 
 err_reg_dev:
nci_free_device(ndlc->ndev);
diff --git a/drivers/nfc/st-nci/i2c.c b/drivers/nfc/st-nci/i2c.c
index 707ed2e..a2700a6 100644
--- a/drivers/nfc/st-nci/i2c.c
+++ b/drivers/nfc/st-nci/i2c.c
@@ -52,6 +52,8 @@ struct st_nci_i2c_phy {
 
unsigned int gpio_reset;
unsigned int irq_polarity;
+
+   struct st_nci_se_status se_status;
 };
 
 #define I2C_DUMP_SKB(info, skb)\
@@ -245,6 +247,11 @@ static int st_nci_i2c

  1   2   3   4   5   >