mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tomas Winkler <tomas.winkler@intel.com>
To: gregkh@linuxfoundation.org
Cc: arnd@arndb.de, linux-kernel@vger.kernel.org,
	Tomas Winkler <tomas.winkler@intel.com>,
	Samuel Ortiz <sameo@linux.intel.com>
Subject: [char-misc-next 09/11] NFC: mei_phy: adjust mei nfc header according the spec
Date: Thu,  7 May 2015 15:54:06 +0300	[thread overview]
Message-ID: <1431003248-3164-9-git-send-email-tomas.winkler@intel.com> (raw)
In-Reply-To: <1431003248-3164-1-git-send-email-tomas.winkler@intel.com>

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>
---
 drivers/nfc/mei_phy.c | 58 +++++++++++++++++++++++++++------------------------
 1 file 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 @@
 
 #include "mei_phy.h"
 
-struct mei_nfc_cmd {
-	u8 command;
+struct mei_nfc_hdr {
+	u8 cmd;
 	u8 status;
 	u16 req_id;
 	u32 reserved;
 	u16 data_size;
+} __packed;
+
+struct mei_nfc_cmd {
+	struct mei_nfc_hdr hdr;
 	u8 sub_command;
 	u8 data[];
 } __packed;
 
 struct mei_nfc_reply {
-	u8 command;
-	u8 status;
-	u16 req_id;
-	u32 reserved;
-	u16 data_size;
+	struct mei_nfc_hdr hdr;
 	u8 sub_command;
 	u8 reply_status;
 	u8 data[];
@@ -69,13 +69,6 @@ struct mei_nfc_connect_resp {
 	u16 me_build;
 } __packed;
 
-struct mei_nfc_hci_hdr {
-	u8 cmd;
-	u8 status;
-	u16 req_id;
-	u32 reserved;
-	u16 data_size;
-} __packed;
 
 #define MEI_NFC_CMD_MAINTENANCE 0x00
 #define MEI_NFC_CMD_HCI_SEND 0x01
@@ -84,9 +77,6 @@ struct mei_nfc_hci_hdr {
 #define MEI_NFC_SUBCMD_CONNECT    0x00
 #define MEI_NFC_SUBCMD_IF_VERSION 0x01
 
-#define MEI_NFC_HEADER_SIZE 10
-
-
 #define MEI_NFC_MAX_READ (MEI_NFC_HEADER_SIZE + MEI_NFC_MAX_HCI_PAYLOAD)
 
 #define MEI_DUMP_SKB_IN(info, skb)				\
@@ -103,6 +93,13 @@ do {								\
 			16, 1, (skb)->data, (skb)->len, false);	\
 } while (0)
 
+#define MEI_DUMP_NFC_HDR(info, _hdr)                                \
+do {                                                                \
+	pr_debug("%s:\n", info);                                    \
+	pr_debug("cmd=%02d status=%d req_id=%d rsvd=%d size=%d\n",  \
+		 (_hdr)->cmd, (_hdr)->status, (_hdr)->req_id,       \
+		 (_hdr)->reserved, (_hdr)->data_size);              \
+} while (0)
 
 static int mei_nfc_if_version(struct nfc_mei_phy *phy)
 {
@@ -116,10 +113,11 @@ static int mei_nfc_if_version(struct nfc_mei_phy *phy)
 	pr_info("%s\n", __func__);
 
 	memset(&cmd, 0, sizeof(struct mei_nfc_cmd));
-	cmd.command = MEI_NFC_CMD_MAINTENANCE;
-	cmd.data_size = 1;
+	cmd.hdr.cmd = MEI_NFC_CMD_MAINTENANCE;
+	cmd.hdr.data_size = 1;
 	cmd.sub_command = MEI_NFC_SUBCMD_IF_VERSION;
 
+	MEI_DUMP_NFC_HDR("version", &cmd.hdr);
 	r = mei_cl_send(phy->device, (u8 *)&cmd, sizeof(struct mei_nfc_cmd));
 	if (r < 0) {
 		pr_err("Could not send IF version cmd\n");
@@ -181,12 +179,13 @@ static int mei_nfc_connect(struct nfc_mei_phy *phy)
 
 	connect_resp = (struct mei_nfc_connect_resp *)reply->data;
 
-	cmd->command = MEI_NFC_CMD_MAINTENANCE;
-	cmd->data_size = 3;
+	cmd->hdr.cmd = MEI_NFC_CMD_MAINTENANCE;
+	cmd->hdr.data_size = 3;
 	cmd->sub_command = MEI_NFC_SUBCMD_CONNECT;
 	connect->fw_ivn = phy->fw_ivn;
 	connect->vendor_id = phy->vendor_id;
 
+	MEI_DUMP_NFC_HDR("connect request", &cmd->hdr);
 	r = mei_cl_send(phy->device, (u8 *)cmd, connect_length);
 	if (r < 0) {
 		pr_err("Could not send connect cmd %d\n", r);
@@ -200,6 +199,8 @@ static int mei_nfc_connect(struct nfc_mei_phy *phy)
 		goto err;
 	}
 
+	MEI_DUMP_NFC_HDR("connect reply", &reply->hdr);
+
 	pr_info("IVN 0x%x Vendor ID 0x%x\n",
 		 connect_resp->fw_ivn, connect_resp->vendor_id);
 
@@ -218,7 +219,7 @@ err:
 
 static int mei_nfc_send(struct nfc_mei_phy *phy, u8 *buf, size_t length)
 {
-	struct mei_nfc_hci_hdr *hdr;
+	struct mei_nfc_hdr *hdr;
 	u8 *mei_buf;
 	int err;
 
@@ -227,13 +228,15 @@ static int mei_nfc_send(struct nfc_mei_phy *phy, u8 *buf, size_t length)
 	if (!mei_buf)
 		goto out;
 
-	hdr = (struct mei_nfc_hci_hdr *) mei_buf;
+	hdr = (struct mei_nfc_hdr *)mei_buf;
 	hdr->cmd = MEI_NFC_CMD_HCI_SEND;
 	hdr->status = 0;
 	hdr->req_id = phy->req_id;
 	hdr->reserved = 0;
 	hdr->data_size = length;
 
+	MEI_DUMP_NFC_HDR("send", hdr);
+
 	memcpy(mei_buf + MEI_NFC_HEADER_SIZE, buf, length);
 	err = mei_cl_send(phy->device, mei_buf, length + MEI_NFC_HEADER_SIZE);
 	if (err < 0)
@@ -272,17 +275,18 @@ static int nfc_mei_phy_write(void *phy_id, struct sk_buff *skb)
 
 static int mei_nfc_recv(struct nfc_mei_phy *phy, u8 *buf, size_t length)
 {
-	struct mei_nfc_hci_hdr *hci_hdr;
+	struct mei_nfc_hdr *hdr;
 	int received_length;
 
 	received_length = mei_cl_recv(phy->device, buf, length);
 	if (received_length < 0)
 		return received_length;
 
-	hci_hdr = (struct mei_nfc_hci_hdr *) buf;
+	hdr = (struct mei_nfc_hdr *) buf;
 
-	if (hci_hdr->cmd == MEI_NFC_CMD_HCI_SEND) {
-		phy->recv_req_id = hci_hdr->req_id;
+	MEI_DUMP_NFC_HDR("receive", hdr);
+	if (hdr->cmd == MEI_NFC_CMD_HCI_SEND) {
+		phy->recv_req_id = hdr->req_id;
 		wake_up(&phy->send_wq);
 
 		return 0;
-- 
2.1.0


  parent reply	other threads:[~2015-05-07 12:55 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-07 12:53 [char-misc-next 01/11] mei: consume flow control on the first chunk of writing Tomas Winkler
2015-05-07 12:53 ` [char-misc-next 02/11] mei: request autosuspend at the end of write Tomas Winkler
2015-05-07 12:54 ` [char-misc-next 03/11] mei: add also write waiting list to runtime pm blockers Tomas Winkler
2015-05-07 12:54 ` [char-misc-next 04/11] uuid: extract macros for assigning raw arrays Tomas Winkler
2015-05-07 12:54 ` [char-misc-next 05/11] mei: bus: report also uuid in module alias Tomas Winkler
2015-05-07 12:54 ` [char-misc-next 06/11] mei: bus: add name and uuid into device attributes Tomas Winkler
2015-05-07 12:54 ` [char-misc-next 07/11] NFC: mei_phy: move all nfc logic from mei driver to nfc Tomas Winkler
2015-05-07 12:54 ` [char-misc-next 08/11] mei: bus: kill mei_cl_ops Tomas Winkler
2015-05-07 12:54 ` Tomas Winkler [this message]
2015-05-07 12:54 ` [char-misc-next 10/11] mei: export mei client device struct to external use Tomas Winkler
2015-05-07 12:54 ` [char-misc-next 11/11] mei: revamp mei bus code Tomas Winkler
2015-05-24 18:19   ` Greg KH
2015-05-24 21:29     ` Winkler, Tomas
2015-05-25  1:46       ` Greg KH
2015-05-25  4:40         ` Winkler, Tomas
2015-05-25 16:20           ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1431003248-3164-9-git-send-email-tomas.winkler@intel.com \
    --to=tomas.winkler@intel.com \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sameo@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®