aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Ricard <christophe.ricard@gmail.com>2015-01-26 19:18:12 -0500
committerSamuel Ortiz <sameo@linux.intel.com>2015-01-27 17:39:32 -0500
commit118278f20aa89efe45fa1e2b1829f198d557f8fe (patch)
treeedac7f90f582e3c29f13290a016f12b0068a4ff2
parentfda7a49cb991e9da15f5955d1ea292f8ec74f27a (diff)
NFC: hci: Add pipes table to reference them with a tuple {gate, host}
In order to keep host source information on specific hci event (such as evt_connectivity or evt_transaction) and because 2 pipes can be connected to the same gate, it is necessary to add a table referencing every pipe with a {gate, host} tuple. Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
-rw-r--r--include/net/nfc/hci.h13
-rw-r--r--net/nfc/hci/command.c6
-rw-r--r--net/nfc/hci/core.c36
3 files changed, 47 insertions, 8 deletions
diff --git a/include/net/nfc/hci.h b/include/net/nfc/hci.h
index 031c0be9fb32..5570f4a316d1 100644
--- a/include/net/nfc/hci.h
+++ b/include/net/nfc/hci.h
@@ -63,8 +63,10 @@ struct nfc_hci_ops {
63}; 63};
64 64
65/* Pipes */ 65/* Pipes */
66#define NFC_HCI_INVALID_PIPE 0x80
67#define NFC_HCI_DO_NOT_CREATE_PIPE 0x81 66#define NFC_HCI_DO_NOT_CREATE_PIPE 0x81
67#define NFC_HCI_INVALID_PIPE 0x80
68#define NFC_HCI_INVALID_GATE 0xFF
69#define NFC_HCI_INVALID_HOST 0x80
68#define NFC_HCI_LINK_MGMT_PIPE 0x00 70#define NFC_HCI_LINK_MGMT_PIPE 0x00
69#define NFC_HCI_ADMIN_PIPE 0x01 71#define NFC_HCI_ADMIN_PIPE 0x01
70 72
@@ -73,7 +75,13 @@ struct nfc_hci_gate {
73 u8 pipe; 75 u8 pipe;
74}; 76};
75 77
78struct nfc_hci_pipe {
79 u8 gate;
80 u8 dest_host;
81};
82
76#define NFC_HCI_MAX_CUSTOM_GATES 50 83#define NFC_HCI_MAX_CUSTOM_GATES 50
84#define NFC_HCI_MAX_PIPES 127
77struct nfc_hci_init_data { 85struct nfc_hci_init_data {
78 u8 gate_count; 86 u8 gate_count;
79 struct nfc_hci_gate gates[NFC_HCI_MAX_CUSTOM_GATES]; 87 struct nfc_hci_gate gates[NFC_HCI_MAX_CUSTOM_GATES];
@@ -125,6 +133,7 @@ struct nfc_hci_dev {
125 void *clientdata; 133 void *clientdata;
126 134
127 u8 gate2pipe[NFC_HCI_MAX_GATES]; 135 u8 gate2pipe[NFC_HCI_MAX_GATES];
136 struct nfc_hci_pipe pipes[NFC_HCI_MAX_PIPES];
128 137
129 u8 sw_romlib; 138 u8 sw_romlib;
130 u8 sw_patch; 139 u8 sw_patch;
@@ -167,6 +176,8 @@ void *nfc_hci_get_clientdata(struct nfc_hci_dev *hdev);
167void nfc_hci_driver_failure(struct nfc_hci_dev *hdev, int err); 176void nfc_hci_driver_failure(struct nfc_hci_dev *hdev, int err);
168 177
169int nfc_hci_result_to_errno(u8 result); 178int nfc_hci_result_to_errno(u8 result);
179void nfc_hci_reset_pipes(struct nfc_hci_dev *dev);
180void nfc_hci_reset_pipes_per_host(struct nfc_hci_dev *hdev, u8 host);
170 181
171/* Host IDs */ 182/* Host IDs */
172#define NFC_HCI_HOST_CONTROLLER_ID 0x00 183#define NFC_HCI_HOST_CONTROLLER_ID 0x00
diff --git a/net/nfc/hci/command.c b/net/nfc/hci/command.c
index 91df487aa0a9..9acf586c98d4 100644
--- a/net/nfc/hci/command.c
+++ b/net/nfc/hci/command.c
@@ -331,7 +331,7 @@ int nfc_hci_disconnect_all_gates(struct nfc_hci_dev *hdev)
331 if (r < 0) 331 if (r < 0)
332 return r; 332 return r;
333 333
334 memset(hdev->gate2pipe, NFC_HCI_INVALID_PIPE, sizeof(hdev->gate2pipe)); 334 nfc_hci_reset_pipes(hdev);
335 335
336 return 0; 336 return 0;
337} 337}
@@ -345,7 +345,7 @@ int nfc_hci_connect_gate(struct nfc_hci_dev *hdev, u8 dest_host, u8 dest_gate,
345 345
346 pr_debug("\n"); 346 pr_debug("\n");
347 347
348 if (hdev->gate2pipe[dest_gate] == NFC_HCI_DO_NOT_CREATE_PIPE) 348 if (pipe == NFC_HCI_DO_NOT_CREATE_PIPE)
349 return 0; 349 return 0;
350 350
351 if (hdev->gate2pipe[dest_gate] != NFC_HCI_INVALID_PIPE) 351 if (hdev->gate2pipe[dest_gate] != NFC_HCI_INVALID_PIPE)
@@ -380,6 +380,8 @@ open_pipe:
380 return r; 380 return r;
381 } 381 }
382 382
383 hdev->pipes[pipe].gate = dest_gate;
384 hdev->pipes[pipe].dest_host = dest_host;
383 hdev->gate2pipe[dest_gate] = pipe; 385 hdev->gate2pipe[dest_gate] = pipe;
384 386
385 return 0; 387 return 0;
diff --git a/net/nfc/hci/core.c b/net/nfc/hci/core.c
index 12a9a4b956d2..8f8abfed7f65 100644
--- a/net/nfc/hci/core.c
+++ b/net/nfc/hci/core.c
@@ -46,6 +46,32 @@ int nfc_hci_result_to_errno(u8 result)
46} 46}
47EXPORT_SYMBOL(nfc_hci_result_to_errno); 47EXPORT_SYMBOL(nfc_hci_result_to_errno);
48 48
49void nfc_hci_reset_pipes(struct nfc_hci_dev *hdev)
50{
51 int i = 0;
52
53 for (i = 0; i < NFC_HCI_MAX_PIPES; i++) {
54 hdev->pipes[i].gate = NFC_HCI_INVALID_GATE;
55 hdev->pipes[i].dest_host = NFC_HCI_INVALID_HOST;
56 }
57 memset(hdev->gate2pipe, NFC_HCI_INVALID_PIPE, sizeof(hdev->gate2pipe));
58}
59EXPORT_SYMBOL(nfc_hci_reset_pipes);
60
61void nfc_hci_reset_pipes_per_host(struct nfc_hci_dev *hdev, u8 host)
62{
63 int i = 0;
64
65 for (i = 0; i < NFC_HCI_MAX_PIPES; i++) {
66 if (hdev->pipes[i].dest_host != host)
67 continue;
68
69 hdev->pipes[i].gate = NFC_HCI_INVALID_GATE;
70 hdev->pipes[i].dest_host = NFC_HCI_INVALID_HOST;
71 }
72}
73EXPORT_SYMBOL(nfc_hci_reset_pipes_per_host);
74
49static void nfc_hci_msg_tx_work(struct work_struct *work) 75static void nfc_hci_msg_tx_work(struct work_struct *work)
50{ 76{
51 struct nfc_hci_dev *hdev = container_of(work, struct nfc_hci_dev, 77 struct nfc_hci_dev *hdev = container_of(work, struct nfc_hci_dev,
@@ -168,7 +194,7 @@ void nfc_hci_cmd_received(struct nfc_hci_dev *hdev, u8 pipe, u8 cmd,
168 struct sk_buff *skb) 194 struct sk_buff *skb)
169{ 195{
170 int r = 0; 196 int r = 0;
171 u8 gate = nfc_hci_pipe2gate(hdev, pipe); 197 u8 gate = hdev->pipes[pipe].gate;
172 u8 local_gate, new_pipe; 198 u8 local_gate, new_pipe;
173 u8 gate_opened = 0x00; 199 u8 gate_opened = 0x00;
174 200
@@ -330,9 +356,9 @@ void nfc_hci_event_received(struct nfc_hci_dev *hdev, u8 pipe, u8 event,
330 struct sk_buff *skb) 356 struct sk_buff *skb)
331{ 357{
332 int r = 0; 358 int r = 0;
333 u8 gate = nfc_hci_pipe2gate(hdev, pipe); 359 u8 gate = hdev->pipes[pipe].gate;
334 360
335 if (gate == 0xff) { 361 if (gate == NFC_HCI_INVALID_GATE) {
336 pr_err("Discarded event %x to unopened pipe %x\n", event, pipe); 362 pr_err("Discarded event %x to unopened pipe %x\n", event, pipe);
337 goto exit; 363 goto exit;
338 } 364 }
@@ -573,7 +599,7 @@ static int hci_dev_down(struct nfc_dev *nfc_dev)
573 if (hdev->ops->close) 599 if (hdev->ops->close)
574 hdev->ops->close(hdev); 600 hdev->ops->close(hdev);
575 601
576 memset(hdev->gate2pipe, NFC_HCI_INVALID_PIPE, sizeof(hdev->gate2pipe)); 602 nfc_hci_reset_pipes(hdev);
577 603
578 return 0; 604 return 0;
579} 605}
@@ -932,7 +958,7 @@ struct nfc_hci_dev *nfc_hci_allocate_device(struct nfc_hci_ops *ops,
932 958
933 nfc_set_drvdata(hdev->ndev, hdev); 959 nfc_set_drvdata(hdev->ndev, hdev);
934 960
935 memset(hdev->gate2pipe, NFC_HCI_INVALID_PIPE, sizeof(hdev->gate2pipe)); 961 nfc_hci_reset_pipes(hdev);
936 962
937 hdev->quirks = quirks; 963 hdev->quirks = quirks;
938 964