Skip to content

Commit a10d595

Browse files
Eric Lapuyadelinvjw
authored andcommitted
NFC: Allow HCI driver to pre-open pipes to some gates
Some NFC chips will statically create and open pipes for both standard and proprietary gates. The driver can now pass this information to HCI such that HCI will not attempt to create and open them, but will instead directly use the passed pipe ids. Signed-off-by: Eric Lapuyade <eric.lapuyade@intel.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent eae202a commit a10d595

5 files changed

Lines changed: 47 additions & 37 deletions

File tree

‎drivers/nfc/pn544_hci.c‎

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,22 @@ enum pn544_state {
108108

109109
#define PN544_NFC_WI_MGMT_GATE 0xA1
110110

111-
static u8 pn544_custom_gates[] = {
112-
PN544_SYS_MGMT_GATE,
113-
PN544_SWP_MGMT_GATE,
114-
PN544_POLLING_LOOP_MGMT_GATE,
115-
PN544_NFC_WI_MGMT_GATE,
116-
PN544_RF_READER_F_GATE,
117-
PN544_RF_READER_JEWEL_GATE,
118-
PN544_RF_READER_ISO15693_GATE,
119-
PN544_RF_READER_NFCIP1_INITIATOR_GATE,
120-
PN544_RF_READER_NFCIP1_TARGET_GATE
111+
static struct nfc_hci_gate pn544_gates[] = {
112+
{NFC_HCI_ADMIN_GATE, NFC_HCI_INVALID_PIPE},
113+
{NFC_HCI_LOOPBACK_GATE, NFC_HCI_INVALID_PIPE},
114+
{NFC_HCI_ID_MGMT_GATE, NFC_HCI_INVALID_PIPE},
115+
{NFC_HCI_LINK_MGMT_GATE, NFC_HCI_INVALID_PIPE},
116+
{NFC_HCI_RF_READER_B_GATE, NFC_HCI_INVALID_PIPE},
117+
{NFC_HCI_RF_READER_A_GATE, NFC_HCI_INVALID_PIPE},
118+
{PN544_SYS_MGMT_GATE, NFC_HCI_INVALID_PIPE},
119+
{PN544_SWP_MGMT_GATE, NFC_HCI_INVALID_PIPE},
120+
{PN544_POLLING_LOOP_MGMT_GATE, NFC_HCI_INVALID_PIPE},
121+
{PN544_NFC_WI_MGMT_GATE, NFC_HCI_INVALID_PIPE},
122+
{PN544_RF_READER_F_GATE, NFC_HCI_INVALID_PIPE},
123+
{PN544_RF_READER_JEWEL_GATE, NFC_HCI_INVALID_PIPE},
124+
{PN544_RF_READER_ISO15693_GATE, NFC_HCI_INVALID_PIPE},
125+
{PN544_RF_READER_NFCIP1_INITIATOR_GATE, NFC_HCI_INVALID_PIPE},
126+
{PN544_RF_READER_NFCIP1_TARGET_GATE, NFC_HCI_INVALID_PIPE}
121127
};
122128

123129
/* Largest headroom needed for outgoing custom commands */
@@ -849,10 +855,9 @@ static int __devinit pn544_hci_probe(struct i2c_client *client,
849855
goto err_rti;
850856
}
851857

852-
init_data.gate_count = ARRAY_SIZE(pn544_custom_gates);
858+
init_data.gate_count = ARRAY_SIZE(pn544_gates);
853859

854-
memcpy(init_data.gates, pn544_custom_gates,
855-
ARRAY_SIZE(pn544_custom_gates));
860+
memcpy(init_data.gates, pn544_gates, sizeof(pn544_gates));
856861

857862
/*
858863
* TODO: Session id must include the driver name + some bus addr

‎include/net/nfc/hci.h‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,20 @@ struct nfc_hci_ops {
4444
struct nfc_target *target);
4545
};
4646

47-
#define NFC_HCI_MAX_CUSTOM_GATES 15
47+
/* Pipes */
48+
#define NFC_HCI_INVALID_PIPE 0x80
49+
#define NFC_HCI_LINK_MGMT_PIPE 0x00
50+
#define NFC_HCI_ADMIN_PIPE 0x01
51+
52+
struct nfc_hci_gate {
53+
u8 gate;
54+
u8 pipe;
55+
};
56+
57+
#define NFC_HCI_MAX_CUSTOM_GATES 50
4858
struct nfc_hci_init_data {
4959
u8 gate_count;
50-
u8 gates[NFC_HCI_MAX_CUSTOM_GATES];
60+
struct nfc_hci_gate gates[NFC_HCI_MAX_CUSTOM_GATES];
5161
char session_id[9];
5262
};
5363

@@ -182,7 +192,8 @@ void nfc_hci_event_received(struct nfc_hci_dev *hdev, u8 pipe, u8 event,
182192
void nfc_hci_recv_frame(struct nfc_hci_dev *hdev, struct sk_buff *skb);
183193

184194
/* connecting to gates and sending hci instructions */
185-
int nfc_hci_connect_gate(struct nfc_hci_dev *hdev, u8 dest_host, u8 dest_gate);
195+
int nfc_hci_connect_gate(struct nfc_hci_dev *hdev, u8 dest_host, u8 dest_gate,
196+
u8 pipe);
186197
int nfc_hci_disconnect_gate(struct nfc_hci_dev *hdev, u8 gate);
187198
int nfc_hci_disconnect_all_gates(struct nfc_hci_dev *hdev);
188199
int nfc_hci_get_param(struct nfc_hci_dev *hdev, u8 gate, u8 idx,

‎net/nfc/hci/command.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,9 @@ int nfc_hci_disconnect_all_gates(struct nfc_hci_dev *hdev)
299299
}
300300
EXPORT_SYMBOL(nfc_hci_disconnect_all_gates);
301301

302-
int nfc_hci_connect_gate(struct nfc_hci_dev *hdev, u8 dest_host, u8 dest_gate)
302+
int nfc_hci_connect_gate(struct nfc_hci_dev *hdev, u8 dest_host, u8 dest_gate,
303+
u8 pipe)
303304
{
304-
u8 pipe = NFC_HCI_INVALID_PIPE;
305305
bool pipe_created = false;
306306
int r;
307307

@@ -310,6 +310,9 @@ int nfc_hci_connect_gate(struct nfc_hci_dev *hdev, u8 dest_host, u8 dest_gate)
310310
if (hdev->gate2pipe[dest_gate] != NFC_HCI_INVALID_PIPE)
311311
return -EADDRINUSE;
312312

313+
if (pipe != NFC_HCI_INVALID_PIPE)
314+
goto pipe_is_open;
315+
313316
switch (dest_gate) {
314317
case NFC_HCI_LINK_MGMT_GATE:
315318
pipe = NFC_HCI_LINK_MGMT_PIPE;
@@ -335,6 +338,7 @@ int nfc_hci_connect_gate(struct nfc_hci_dev *hdev, u8 dest_host, u8 dest_gate)
335338
return r;
336339
}
337340

341+
pipe_is_open:
338342
hdev->gate2pipe[dest_gate] = pipe;
339343

340344
return 0;

‎net/nfc/hci/core.c‎

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -315,15 +315,15 @@ static void nfc_hci_cmd_timeout(unsigned long data)
315315
}
316316

317317
static int hci_dev_connect_gates(struct nfc_hci_dev *hdev, u8 gate_count,
318-
u8 gates[])
318+
struct nfc_hci_gate *gates)
319319
{
320320
int r;
321-
u8 *p = gates;
322321
while (gate_count--) {
323-
r = nfc_hci_connect_gate(hdev, NFC_HCI_HOST_CONTROLLER_ID, *p);
322+
r = nfc_hci_connect_gate(hdev, NFC_HCI_HOST_CONTROLLER_ID,
323+
gates->gate, gates->pipe);
324324
if (r < 0)
325325
return r;
326-
p++;
326+
gates++;
327327
}
328328

329329
return 0;
@@ -333,14 +333,13 @@ static int hci_dev_session_init(struct nfc_hci_dev *hdev)
333333
{
334334
struct sk_buff *skb = NULL;
335335
int r;
336-
u8 hci_gates[] = { /* NFC_HCI_ADMIN_GATE MUST be first */
337-
NFC_HCI_ADMIN_GATE, NFC_HCI_LOOPBACK_GATE,
338-
NFC_HCI_ID_MGMT_GATE, NFC_HCI_LINK_MGMT_GATE,
339-
NFC_HCI_RF_READER_B_GATE, NFC_HCI_RF_READER_A_GATE
340-
};
336+
337+
if (hdev->init_data.gates[0].gate != NFC_HCI_ADMIN_GATE)
338+
return -EPROTO;
341339

342340
r = nfc_hci_connect_gate(hdev, NFC_HCI_HOST_CONTROLLER_ID,
343-
NFC_HCI_ADMIN_GATE);
341+
hdev->init_data.gates[0].gate,
342+
hdev->init_data.gates[0].pipe);
344343
if (r < 0)
345344
goto exit;
346345

@@ -368,10 +367,6 @@ static int hci_dev_session_init(struct nfc_hci_dev *hdev)
368367
if (r < 0)
369368
goto exit;
370369

371-
r = hci_dev_connect_gates(hdev, sizeof(hci_gates), hci_gates);
372-
if (r < 0)
373-
goto disconnect_all;
374-
375370
r = hci_dev_connect_gates(hdev, hdev->init_data.gate_count,
376371
hdev->init_data.gates);
377372
if (r < 0)

‎net/nfc/hci/hci.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,4 @@ void nfc_hci_hcp_message_rx(struct nfc_hci_dev *hdev, u8 pipe, u8 type,
132132
#define NFC_HCI_ANY_E_REG_ACCESS_DENIED 0x0a
133133
#define NFC_HCI_ANY_E_PIPE_ACCESS_DENIED 0x0b
134134

135-
/* Pipes */
136-
#define NFC_HCI_INVALID_PIPE 0x80
137-
#define NFC_HCI_LINK_MGMT_PIPE 0x00
138-
#define NFC_HCI_ADMIN_PIPE 0x01
139-
140135
#endif /* __LOCAL_HCI_H */

0 commit comments

Comments
 (0)