aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomas Winkler <tomas.winkler@intel.com>2015-05-07 08:54:06 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2015-05-24 14:15:54 -0400
commit1d3ff76721fbb04e69abe8abbae1a77ed02bd36f (patch)
tree55f02929d9768cf42f71a3dbbf28cce7b28a47b9
parentd4b78c7290dd0aa41596ad527877a6d70bf64110 (diff)
NFC: mei_phy: adjust mei nfc header according the spec
1. mei_nfc_hci_hdr and mei_nfc_hdr are just the same thing so drop one 2. use mei_nfc_hdr structure as the member of the command and the reply instead of replicating all header fields. 3. dump the header for easier debugging Cc: Samuel Ortiz <sameo@linux.intel.com> Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/nfc/mei_phy.c58
1 files changed, 31 insertions, 27 deletions
diff --git a/drivers/nfc/mei_phy.c b/drivers/nfc/mei_phy.c
index 7f1495d649bb..2b77ccf77f81 100644
--- a/drivers/nfc/mei_phy.c
+++ b/drivers/nfc/mei_phy.c
@@ -24,22 +24,22 @@
24 24
25#include "mei_phy.h" 25#include "mei_phy.h"
26 26
27struct mei_nfc_cmd { 27struct mei_nfc_hdr {
28 u8 command; 28 u8 cmd;
29 u8 status; 29 u8 status;
30 u16 req_id; 30 u16 req_id;
31 u32 reserved; 31 u32 reserved;
32 u16 data_size; 32 u16 data_size;
33} __packed;
34
35struct mei_nfc_cmd {
36 struct mei_nfc_hdr hdr;
33 u8 sub_command; 37 u8 sub_command;
34 u8 data[]; 38 u8 data[];
35} __packed; 39} __packed;
36 40
37struct mei_nfc_reply { 41struct mei_nfc_reply {
38 u8 command; 42 struct mei_nfc_hdr hdr;
39 u8 status;
40 u16 req_id;
41 u32 reserved;
42 u16 data_size;
43 u8 sub_command; 43 u8 sub_command;
44 u8 reply_status; 44 u8 reply_status;
45 u8 data[]; 45 u8 data[];
@@ -69,13 +69,6 @@ struct mei_nfc_connect_resp {
69 u16 me_build; 69 u16 me_build;
70} __packed; 70} __packed;
71 71
72struct mei_nfc_hci_hdr {
73 u8 cmd;
74 u8 status;
75 u16 req_id;
76 u32 reserved;
77 u16 data_size;
78} __packed;
79 72
80#define MEI_NFC_CMD_MAINTENANCE 0x00 73#define MEI_NFC_CMD_MAINTENANCE 0x00
81#define MEI_NFC_CMD_HCI_SEND 0x01 74#define MEI_NFC_CMD_HCI_SEND 0x01
@@ -84,9 +77,6 @@ struct mei_nfc_hci_hdr {
84#define MEI_NFC_SUBCMD_CONNECT 0x00 77#define MEI_NFC_SUBCMD_CONNECT 0x00
85#define MEI_NFC_SUBCMD_IF_VERSION 0x01 78#define MEI_NFC_SUBCMD_IF_VERSION 0x01
86 79
87#define MEI_NFC_HEADER_SIZE 10
88
89
90#define MEI_NFC_MAX_READ (MEI_NFC_HEADER_SIZE + MEI_NFC_MAX_HCI_PAYLOAD) 80#define MEI_NFC_MAX_READ (MEI_NFC_HEADER_SIZE + MEI_NFC_MAX_HCI_PAYLOAD)
91 81
92#define MEI_DUMP_SKB_IN(info, skb) \ 82#define MEI_DUMP_SKB_IN(info, skb) \
@@ -103,6 +93,13 @@ do { \
103 16, 1, (skb)->data, (skb)->len, false); \ 93 16, 1, (skb)->data, (skb)->len, false); \
104} while (0) 94} while (0)
105 95
96#define MEI_DUMP_NFC_HDR(info, _hdr) \
97do { \
98 pr_debug("%s:\n", info); \
99 pr_debug("cmd=%02d status=%d req_id=%d rsvd=%d size=%d\n", \
100 (_hdr)->cmd, (_hdr)->status, (_hdr)->req_id, \
101 (_hdr)->reserved, (_hdr)->data_size); \
102} while (0)
106 103
107static int mei_nfc_if_version(struct nfc_mei_phy *phy) 104static int mei_nfc_if_version(struct nfc_mei_phy *phy)
108{ 105{
@@ -116,10 +113,11 @@ static int mei_nfc_if_version(struct nfc_mei_phy *phy)
116 pr_info("%s\n", __func__); 113 pr_info("%s\n", __func__);
117 114
118 memset(&cmd, 0, sizeof(struct mei_nfc_cmd)); 115 memset(&cmd, 0, sizeof(struct mei_nfc_cmd));
119 cmd.command = MEI_NFC_CMD_MAINTENANCE; 116 cmd.hdr.cmd = MEI_NFC_CMD_MAINTENANCE;
120 cmd.data_size = 1; 117 cmd.hdr.data_size = 1;
121 cmd.sub_command = MEI_NFC_SUBCMD_IF_VERSION; 118 cmd.sub_command = MEI_NFC_SUBCMD_IF_VERSION;
122 119
120 MEI_DUMP_NFC_HDR("version", &cmd.hdr);
123 r = mei_cl_send(phy->device, (u8 *)&cmd, sizeof(struct mei_nfc_cmd)); 121 r = mei_cl_send(phy->device, (u8 *)&cmd, sizeof(struct mei_nfc_cmd));
124 if (r < 0) { 122 if (r < 0) {
125 pr_err("Could not send IF version cmd\n"); 123 pr_err("Could not send IF version cmd\n");
@@ -181,12 +179,13 @@ static int mei_nfc_connect(struct nfc_mei_phy *phy)
181 179
182 connect_resp = (struct mei_nfc_connect_resp *)reply->data; 180 connect_resp = (struct mei_nfc_connect_resp *)reply->data;
183 181
184 cmd->command = MEI_NFC_CMD_MAINTENANCE; 182 cmd->hdr.cmd = MEI_NFC_CMD_MAINTENANCE;
185 cmd->data_size = 3; 183 cmd->hdr.data_size = 3;
186 cmd->sub_command = MEI_NFC_SUBCMD_CONNECT; 184 cmd->sub_command = MEI_NFC_SUBCMD_CONNECT;
187 connect->fw_ivn = phy->fw_ivn; 185 connect->fw_ivn = phy->fw_ivn;
188 connect->vendor_id = phy->vendor_id; 186 connect->vendor_id = phy->vendor_id;
189 187
188 MEI_DUMP_NFC_HDR("connect request", &cmd->hdr);
190 r = mei_cl_send(phy->device, (u8 *)cmd, connect_length); 189 r = mei_cl_send(phy->device, (u8 *)cmd, connect_length);
191 if (r < 0) { 190 if (r < 0) {
192 pr_err("Could not send connect cmd %d\n", r); 191 pr_err("Could not send connect cmd %d\n", r);
@@ -200,6 +199,8 @@ static int mei_nfc_connect(struct nfc_mei_phy *phy)
200 goto err; 199 goto err;
201 } 200 }
202 201
202 MEI_DUMP_NFC_HDR("connect reply", &reply->hdr);
203
203 pr_info("IVN 0x%x Vendor ID 0x%x\n", 204 pr_info("IVN 0x%x Vendor ID 0x%x\n",
204 connect_resp->fw_ivn, connect_resp->vendor_id); 205 connect_resp->fw_ivn, connect_resp->vendor_id);
205 206
@@ -218,7 +219,7 @@ err:
218 219
219static int mei_nfc_send(struct nfc_mei_phy *phy, u8 *buf, size_t length) 220static int mei_nfc_send(struct nfc_mei_phy *phy, u8 *buf, size_t length)
220{ 221{
221 struct mei_nfc_hci_hdr *hdr; 222 struct mei_nfc_hdr *hdr;
222 u8 *mei_buf; 223 u8 *mei_buf;
223 int err; 224 int err;
224 225
@@ -227,13 +228,15 @@ static int mei_nfc_send(struct nfc_mei_phy *phy, u8 *buf, size_t length)
227 if (!mei_buf) 228 if (!mei_buf)
228 goto out; 229 goto out;
229 230
230 hdr = (struct mei_nfc_hci_hdr *) mei_buf; 231 hdr = (struct mei_nfc_hdr *)mei_buf;
231 hdr->cmd = MEI_NFC_CMD_HCI_SEND; 232 hdr->cmd = MEI_NFC_CMD_HCI_SEND;
232 hdr->status = 0; 233 hdr->status = 0;
233 hdr->req_id = phy->req_id; 234 hdr->req_id = phy->req_id;
234 hdr->reserved = 0; 235 hdr->reserved = 0;
235 hdr->data_size = length; 236 hdr->data_size = length;
236 237
238 MEI_DUMP_NFC_HDR("send", hdr);
239
237 memcpy(mei_buf + MEI_NFC_HEADER_SIZE, buf, length); 240 memcpy(mei_buf + MEI_NFC_HEADER_SIZE, buf, length);
238 err = mei_cl_send(phy->device, mei_buf, length + MEI_NFC_HEADER_SIZE); 241 err = mei_cl_send(phy->device, mei_buf, length + MEI_NFC_HEADER_SIZE);
239 if (err < 0) 242 if (err < 0)
@@ -272,17 +275,18 @@ static int nfc_mei_phy_write(void *phy_id, struct sk_buff *skb)
272 275
273static int mei_nfc_recv(struct nfc_mei_phy *phy, u8 *buf, size_t length) 276static int mei_nfc_recv(struct nfc_mei_phy *phy, u8 *buf, size_t length)
274{ 277{
275 struct mei_nfc_hci_hdr *hci_hdr; 278 struct mei_nfc_hdr *hdr;
276 int received_length; 279 int received_length;
277 280
278 received_length = mei_cl_recv(phy->device, buf, length); 281 received_length = mei_cl_recv(phy->device, buf, length);
279 if (received_length < 0) 282 if (received_length < 0)
280 return received_length; 283 return received_length;
281 284
282 hci_hdr = (struct mei_nfc_hci_hdr *) buf; 285 hdr = (struct mei_nfc_hdr *) buf;
283 286
284 if (hci_hdr->cmd == MEI_NFC_CMD_HCI_SEND) { 287 MEI_DUMP_NFC_HDR("receive", hdr);
285 phy->recv_req_id = hci_hdr->req_id; 288 if (hdr->cmd == MEI_NFC_CMD_HCI_SEND) {
289 phy->recv_req_id = hdr->req_id;
286 wake_up(&phy->send_wq); 290 wake_up(&phy->send_wq);
287 291
288 return 0; 292 return 0;