Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Tomas Winkler and committed by
Greg Kroah-Hartman
1d3ff767 d4b78c72

+31 -27
+31 -27
drivers/nfc/mei_phy.c
··· 24 24 25 25 #include "mei_phy.h" 26 26 27 - struct mei_nfc_cmd { 28 - u8 command; 27 + struct mei_nfc_hdr { 28 + u8 cmd; 29 29 u8 status; 30 30 u16 req_id; 31 31 u32 reserved; 32 32 u16 data_size; 33 + } __packed; 34 + 35 + struct mei_nfc_cmd { 36 + struct mei_nfc_hdr hdr; 33 37 u8 sub_command; 34 38 u8 data[]; 35 39 } __packed; 36 40 37 41 struct mei_nfc_reply { 38 - u8 command; 39 - u8 status; 40 - u16 req_id; 41 - u32 reserved; 42 - u16 data_size; 42 + struct mei_nfc_hdr hdr; 43 43 u8 sub_command; 44 44 u8 reply_status; 45 45 u8 data[]; ··· 69 69 u16 me_build; 70 70 } __packed; 71 71 72 - struct 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 73 #define MEI_NFC_CMD_MAINTENANCE 0x00 81 74 #define MEI_NFC_CMD_HCI_SEND 0x01 ··· 76 83 77 84 #define MEI_NFC_SUBCMD_CONNECT 0x00 78 85 #define MEI_NFC_SUBCMD_IF_VERSION 0x01 79 - 80 - #define MEI_NFC_HEADER_SIZE 10 81 - 82 86 83 87 #define MEI_NFC_MAX_READ (MEI_NFC_HEADER_SIZE + MEI_NFC_MAX_HCI_PAYLOAD) 84 88 ··· 93 103 16, 1, (skb)->data, (skb)->len, false); \ 94 104 } while (0) 95 105 106 + #define MEI_DUMP_NFC_HDR(info, _hdr) \ 107 + do { \ 108 + pr_debug("%s:\n", info); \ 109 + pr_debug("cmd=%02d status=%d req_id=%d rsvd=%d size=%d\n", \ 110 + (_hdr)->cmd, (_hdr)->status, (_hdr)->req_id, \ 111 + (_hdr)->reserved, (_hdr)->data_size); \ 112 + } while (0) 96 113 97 114 static int mei_nfc_if_version(struct nfc_mei_phy *phy) 98 115 { ··· 113 116 pr_info("%s\n", __func__); 114 117 115 118 memset(&cmd, 0, sizeof(struct mei_nfc_cmd)); 116 - cmd.command = MEI_NFC_CMD_MAINTENANCE; 117 - cmd.data_size = 1; 119 + cmd.hdr.cmd = MEI_NFC_CMD_MAINTENANCE; 120 + cmd.hdr.data_size = 1; 118 121 cmd.sub_command = MEI_NFC_SUBCMD_IF_VERSION; 119 122 123 + MEI_DUMP_NFC_HDR("version", &cmd.hdr); 120 124 r = mei_cl_send(phy->device, (u8 *)&cmd, sizeof(struct mei_nfc_cmd)); 121 125 if (r < 0) { 122 126 pr_err("Could not send IF version cmd\n"); ··· 179 181 180 182 connect_resp = (struct mei_nfc_connect_resp *)reply->data; 181 183 182 - cmd->command = MEI_NFC_CMD_MAINTENANCE; 183 - cmd->data_size = 3; 184 + cmd->hdr.cmd = MEI_NFC_CMD_MAINTENANCE; 185 + cmd->hdr.data_size = 3; 184 186 cmd->sub_command = MEI_NFC_SUBCMD_CONNECT; 185 187 connect->fw_ivn = phy->fw_ivn; 186 188 connect->vendor_id = phy->vendor_id; 187 189 190 + MEI_DUMP_NFC_HDR("connect request", &cmd->hdr); 188 191 r = mei_cl_send(phy->device, (u8 *)cmd, connect_length); 189 192 if (r < 0) { 190 193 pr_err("Could not send connect cmd %d\n", r); ··· 198 199 pr_err("Could not read connect response %d\n", r); 199 200 goto err; 200 201 } 202 + 203 + MEI_DUMP_NFC_HDR("connect reply", &reply->hdr); 201 204 202 205 pr_info("IVN 0x%x Vendor ID 0x%x\n", 203 206 connect_resp->fw_ivn, connect_resp->vendor_id); ··· 219 218 220 219 static int mei_nfc_send(struct nfc_mei_phy *phy, u8 *buf, size_t length) 221 220 { 222 - struct mei_nfc_hci_hdr *hdr; 221 + struct mei_nfc_hdr *hdr; 223 222 u8 *mei_buf; 224 223 int err; 225 224 ··· 228 227 if (!mei_buf) 229 228 goto out; 230 229 231 - hdr = (struct mei_nfc_hci_hdr *) mei_buf; 230 + hdr = (struct mei_nfc_hdr *)mei_buf; 232 231 hdr->cmd = MEI_NFC_CMD_HCI_SEND; 233 232 hdr->status = 0; 234 233 hdr->req_id = phy->req_id; 235 234 hdr->reserved = 0; 236 235 hdr->data_size = length; 236 + 237 + MEI_DUMP_NFC_HDR("send", hdr); 237 238 238 239 memcpy(mei_buf + MEI_NFC_HEADER_SIZE, buf, length); 239 240 err = mei_cl_send(phy->device, mei_buf, length + MEI_NFC_HEADER_SIZE); ··· 275 272 276 273 static int mei_nfc_recv(struct nfc_mei_phy *phy, u8 *buf, size_t length) 277 274 { 278 - struct mei_nfc_hci_hdr *hci_hdr; 275 + struct mei_nfc_hdr *hdr; 279 276 int received_length; 280 277 281 278 received_length = mei_cl_recv(phy->device, buf, length); 282 279 if (received_length < 0) 283 280 return received_length; 284 281 285 - hci_hdr = (struct mei_nfc_hci_hdr *) buf; 282 + hdr = (struct mei_nfc_hdr *) buf; 286 283 287 - if (hci_hdr->cmd == MEI_NFC_CMD_HCI_SEND) { 288 - phy->recv_req_id = hci_hdr->req_id; 284 + MEI_DUMP_NFC_HDR("receive", hdr); 285 + if (hdr->cmd == MEI_NFC_CMD_HCI_SEND) { 286 + phy->recv_req_id = hdr->req_id; 289 287 wake_up(&phy->send_wq); 290 288 291 289 return 0;