Frederic Danis | 8a00a61 | 2013-05-29 15:35:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 Intel Corporation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms and conditions of the GNU General Public License, |
| 6 | * version 2, as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along with |
| 14 | * this program; if not, write to the Free Software Foundation, Inc., |
| 15 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 16 | * |
| 17 | */ |
| 18 | |
| 19 | #define pr_fmt(fmt) "nci_spi: %s: " fmt, __func__ |
| 20 | |
| 21 | #include <linux/export.h> |
| 22 | #include <linux/spi/spi.h> |
Frederic Danis | ee9596d | 2013-05-29 15:35:03 +0200 | [diff] [blame] | 23 | #include <linux/crc-ccitt.h> |
Frederic Danis | 8a00a61 | 2013-05-29 15:35:02 +0200 | [diff] [blame] | 24 | #include <net/nfc/nci_core.h> |
| 25 | |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 26 | #define NCI_SPI_ACK_SHIFT 6 |
| 27 | #define NCI_SPI_MSB_PAYLOAD_MASK 0x3F |
Frederic Danis | 8a00a61 | 2013-05-29 15:35:02 +0200 | [diff] [blame] | 28 | |
Frederic Danis | ee9596d | 2013-05-29 15:35:03 +0200 | [diff] [blame] | 29 | #define NCI_SPI_SEND_TIMEOUT (NCI_CMD_TIMEOUT > NCI_DATA_TIMEOUT ? \ |
| 30 | NCI_CMD_TIMEOUT : NCI_DATA_TIMEOUT) |
| 31 | |
| 32 | #define NCI_SPI_DIRECT_WRITE 0x01 |
| 33 | #define NCI_SPI_DIRECT_READ 0x02 |
| 34 | |
| 35 | #define ACKNOWLEDGE_NONE 0 |
| 36 | #define ACKNOWLEDGE_ACK 1 |
| 37 | #define ACKNOWLEDGE_NACK 2 |
| 38 | |
| 39 | #define CRC_INIT 0xFFFF |
| 40 | |
Eric Lapuyade | 2bed278 | 2013-09-23 17:56:43 +0200 | [diff] [blame] | 41 | static int __nci_spi_send(struct nci_spi *nspi, struct sk_buff *skb, |
| 42 | int cs_change) |
Frederic Danis | ee9596d | 2013-05-29 15:35:03 +0200 | [diff] [blame] | 43 | { |
| 44 | struct spi_message m; |
| 45 | struct spi_transfer t; |
| 46 | |
Eric Lapuyade | a4ada6c | 2013-09-23 18:02:43 +0200 | [diff] [blame] | 47 | memset(&t, 0, sizeof(struct spi_transfer)); |
Eric Lapuyade | 2bed278 | 2013-09-23 17:56:43 +0200 | [diff] [blame] | 48 | /* a NULL skb means we just want the SPI chip select line to raise */ |
| 49 | if (skb) { |
| 50 | t.tx_buf = skb->data; |
| 51 | t.len = skb->len; |
| 52 | } else { |
| 53 | /* still set tx_buf non NULL to make the driver happy */ |
| 54 | t.tx_buf = &t; |
| 55 | t.len = 0; |
| 56 | } |
| 57 | t.cs_change = cs_change; |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 58 | t.delay_usecs = nspi->xfer_udelay; |
Frederic Danis | ee9596d | 2013-05-29 15:35:03 +0200 | [diff] [blame] | 59 | |
| 60 | spi_message_init(&m); |
| 61 | spi_message_add_tail(&t, &m); |
| 62 | |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 63 | return spi_sync(nspi->spi, &m); |
Frederic Danis | ee9596d | 2013-05-29 15:35:03 +0200 | [diff] [blame] | 64 | } |
| 65 | |
Eric Lapuyade | 2bed278 | 2013-09-23 17:56:43 +0200 | [diff] [blame] | 66 | int nci_spi_send(struct nci_spi *nspi, |
| 67 | struct completion *write_handshake_completion, |
| 68 | struct sk_buff *skb) |
Frederic Danis | 8a00a61 | 2013-05-29 15:35:02 +0200 | [diff] [blame] | 69 | { |
Frederic Danis | ee9596d | 2013-05-29 15:35:03 +0200 | [diff] [blame] | 70 | unsigned int payload_len = skb->len; |
| 71 | unsigned char *hdr; |
| 72 | int ret; |
| 73 | long completion_rc; |
| 74 | |
Frederic Danis | ee9596d | 2013-05-29 15:35:03 +0200 | [diff] [blame] | 75 | /* add the NCI SPI header to the start of the buffer */ |
| 76 | hdr = skb_push(skb, NCI_SPI_HDR_LEN); |
| 77 | hdr[0] = NCI_SPI_DIRECT_WRITE; |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 78 | hdr[1] = nspi->acknowledge_mode; |
Frederic Danis | ee9596d | 2013-05-29 15:35:03 +0200 | [diff] [blame] | 79 | hdr[2] = payload_len >> 8; |
| 80 | hdr[3] = payload_len & 0xFF; |
| 81 | |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 82 | if (nspi->acknowledge_mode == NCI_SPI_CRC_ENABLED) { |
Frederic Danis | ee9596d | 2013-05-29 15:35:03 +0200 | [diff] [blame] | 83 | u16 crc; |
| 84 | |
| 85 | crc = crc_ccitt(CRC_INIT, skb->data, skb->len); |
| 86 | *skb_put(skb, 1) = crc >> 8; |
| 87 | *skb_put(skb, 1) = crc & 0xFF; |
| 88 | } |
| 89 | |
Eric Lapuyade | 2bed278 | 2013-09-23 17:56:43 +0200 | [diff] [blame] | 90 | if (write_handshake_completion) { |
| 91 | /* Trick SPI driver to raise chip select */ |
| 92 | ret = __nci_spi_send(nspi, NULL, 1); |
| 93 | if (ret) |
| 94 | goto done; |
Frederic Danis | ee9596d | 2013-05-29 15:35:03 +0200 | [diff] [blame] | 95 | |
Eric Lapuyade | 2bed278 | 2013-09-23 17:56:43 +0200 | [diff] [blame] | 96 | /* wait for NFC chip hardware handshake to complete */ |
| 97 | if (wait_for_completion_timeout(write_handshake_completion, |
| 98 | msecs_to_jiffies(1000)) == 0) { |
| 99 | ret = -ETIME; |
| 100 | goto done; |
| 101 | } |
| 102 | } |
Frederic Danis | ee9596d | 2013-05-29 15:35:03 +0200 | [diff] [blame] | 103 | |
Eric Lapuyade | 2bed278 | 2013-09-23 17:56:43 +0200 | [diff] [blame] | 104 | ret = __nci_spi_send(nspi, skb, 0); |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 105 | if (ret != 0 || nspi->acknowledge_mode == NCI_SPI_CRC_DISABLED) |
Frederic Danis | ee9596d | 2013-05-29 15:35:03 +0200 | [diff] [blame] | 106 | goto done; |
| 107 | |
Axel Lin | 9bec44b | 2014-02-13 13:25:48 +0800 | [diff] [blame] | 108 | reinit_completion(&nspi->req_completion); |
Eric Lapuyade | d593751 | 2013-09-02 12:35:39 +0200 | [diff] [blame] | 109 | completion_rc = wait_for_completion_interruptible_timeout( |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 110 | &nspi->req_completion, |
Eric Lapuyade | d593751 | 2013-09-02 12:35:39 +0200 | [diff] [blame] | 111 | NCI_SPI_SEND_TIMEOUT); |
Frederic Danis | ee9596d | 2013-05-29 15:35:03 +0200 | [diff] [blame] | 112 | |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 113 | if (completion_rc <= 0 || nspi->req_result == ACKNOWLEDGE_NACK) |
Frederic Danis | ee9596d | 2013-05-29 15:35:03 +0200 | [diff] [blame] | 114 | ret = -EIO; |
| 115 | |
| 116 | done: |
Eric Lapuyade | 2bed278 | 2013-09-23 17:56:43 +0200 | [diff] [blame] | 117 | kfree_skb(skb); |
| 118 | |
Frederic Danis | ee9596d | 2013-05-29 15:35:03 +0200 | [diff] [blame] | 119 | return ret; |
Frederic Danis | 8a00a61 | 2013-05-29 15:35:02 +0200 | [diff] [blame] | 120 | } |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 121 | EXPORT_SYMBOL_GPL(nci_spi_send); |
Frederic Danis | 8a00a61 | 2013-05-29 15:35:02 +0200 | [diff] [blame] | 122 | |
| 123 | /* ---- Interface to NCI SPI drivers ---- */ |
| 124 | |
| 125 | /** |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 126 | * nci_spi_allocate_spi - allocate a new nci spi |
Frederic Danis | 8a00a61 | 2013-05-29 15:35:02 +0200 | [diff] [blame] | 127 | * |
| 128 | * @spi: SPI device |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 129 | * @acknowledge_mode: Acknowledge mode used by the NFC device |
Frederic Danis | 8a00a61 | 2013-05-29 15:35:02 +0200 | [diff] [blame] | 130 | * @delay: delay between transactions in us |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 131 | * @ndev: nci dev to send incoming nci frames to |
Frederic Danis | 8a00a61 | 2013-05-29 15:35:02 +0200 | [diff] [blame] | 132 | */ |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 133 | struct nci_spi *nci_spi_allocate_spi(struct spi_device *spi, |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 134 | u8 acknowledge_mode, unsigned int delay, |
| 135 | struct nci_dev *ndev) |
Frederic Danis | 8a00a61 | 2013-05-29 15:35:02 +0200 | [diff] [blame] | 136 | { |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 137 | struct nci_spi *nspi; |
Frederic Danis | 8a00a61 | 2013-05-29 15:35:02 +0200 | [diff] [blame] | 138 | |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 139 | nspi = devm_kzalloc(&spi->dev, sizeof(struct nci_spi), GFP_KERNEL); |
| 140 | if (!nspi) |
Frederic Danis | 8a00a61 | 2013-05-29 15:35:02 +0200 | [diff] [blame] | 141 | return NULL; |
| 142 | |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 143 | nspi->acknowledge_mode = acknowledge_mode; |
| 144 | nspi->xfer_udelay = delay; |
Frederic Danis | 8a00a61 | 2013-05-29 15:35:02 +0200 | [diff] [blame] | 145 | |
Eric Lapuyade | 645d508 | 2013-09-19 16:52:06 +0200 | [diff] [blame] | 146 | nspi->spi = spi; |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 147 | nspi->ndev = ndev; |
Axel Lin | 9bec44b | 2014-02-13 13:25:48 +0800 | [diff] [blame] | 148 | init_completion(&nspi->req_completion); |
Frederic Danis | 8a00a61 | 2013-05-29 15:35:02 +0200 | [diff] [blame] | 149 | |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 150 | return nspi; |
Frederic Danis | 8a00a61 | 2013-05-29 15:35:02 +0200 | [diff] [blame] | 151 | } |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 152 | EXPORT_SYMBOL_GPL(nci_spi_allocate_spi); |
Frederic Danis | 8a00a61 | 2013-05-29 15:35:02 +0200 | [diff] [blame] | 153 | |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 154 | static int send_acknowledge(struct nci_spi *nspi, u8 acknowledge) |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 155 | { |
| 156 | struct sk_buff *skb; |
| 157 | unsigned char *hdr; |
| 158 | u16 crc; |
| 159 | int ret; |
| 160 | |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 161 | skb = nci_skb_alloc(nspi->ndev, 0, GFP_KERNEL); |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 162 | |
| 163 | /* add the NCI SPI header to the start of the buffer */ |
| 164 | hdr = skb_push(skb, NCI_SPI_HDR_LEN); |
| 165 | hdr[0] = NCI_SPI_DIRECT_WRITE; |
| 166 | hdr[1] = NCI_SPI_CRC_ENABLED; |
| 167 | hdr[2] = acknowledge << NCI_SPI_ACK_SHIFT; |
| 168 | hdr[3] = 0; |
| 169 | |
| 170 | crc = crc_ccitt(CRC_INIT, skb->data, skb->len); |
| 171 | *skb_put(skb, 1) = crc >> 8; |
| 172 | *skb_put(skb, 1) = crc & 0xFF; |
| 173 | |
Eric Lapuyade | 2bed278 | 2013-09-23 17:56:43 +0200 | [diff] [blame] | 174 | ret = __nci_spi_send(nspi, skb, 0); |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 175 | |
| 176 | kfree_skb(skb); |
| 177 | |
| 178 | return ret; |
| 179 | } |
| 180 | |
Eric Lapuyade | 22d4aae | 2013-09-23 17:56:31 +0200 | [diff] [blame] | 181 | static struct sk_buff *__nci_spi_read(struct nci_spi *nspi) |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 182 | { |
| 183 | struct sk_buff *skb; |
| 184 | struct spi_message m; |
| 185 | unsigned char req[2], resp_hdr[2]; |
| 186 | struct spi_transfer tx, rx; |
| 187 | unsigned short rx_len = 0; |
| 188 | int ret; |
| 189 | |
| 190 | spi_message_init(&m); |
Eric Lapuyade | a4ada6c | 2013-09-23 18:02:43 +0200 | [diff] [blame] | 191 | |
| 192 | memset(&tx, 0, sizeof(struct spi_transfer)); |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 193 | req[0] = NCI_SPI_DIRECT_READ; |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 194 | req[1] = nspi->acknowledge_mode; |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 195 | tx.tx_buf = req; |
| 196 | tx.len = 2; |
| 197 | tx.cs_change = 0; |
| 198 | spi_message_add_tail(&tx, &m); |
Eric Lapuyade | a4ada6c | 2013-09-23 18:02:43 +0200 | [diff] [blame] | 199 | |
| 200 | memset(&rx, 0, sizeof(struct spi_transfer)); |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 201 | rx.rx_buf = resp_hdr; |
| 202 | rx.len = 2; |
| 203 | rx.cs_change = 1; |
| 204 | spi_message_add_tail(&rx, &m); |
Eric Lapuyade | a4ada6c | 2013-09-23 18:02:43 +0200 | [diff] [blame] | 205 | |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 206 | ret = spi_sync(nspi->spi, &m); |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 207 | if (ret) |
| 208 | return NULL; |
| 209 | |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 210 | if (nspi->acknowledge_mode == NCI_SPI_CRC_ENABLED) |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 211 | rx_len = ((resp_hdr[0] & NCI_SPI_MSB_PAYLOAD_MASK) << 8) + |
| 212 | resp_hdr[1] + NCI_SPI_CRC_LEN; |
| 213 | else |
| 214 | rx_len = (resp_hdr[0] << 8) | resp_hdr[1]; |
| 215 | |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 216 | skb = nci_skb_alloc(nspi->ndev, rx_len, GFP_KERNEL); |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 217 | if (!skb) |
| 218 | return NULL; |
| 219 | |
| 220 | spi_message_init(&m); |
Eric Lapuyade | a4ada6c | 2013-09-23 18:02:43 +0200 | [diff] [blame] | 221 | |
| 222 | memset(&rx, 0, sizeof(struct spi_transfer)); |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 223 | rx.rx_buf = skb_put(skb, rx_len); |
| 224 | rx.len = rx_len; |
| 225 | rx.cs_change = 0; |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 226 | rx.delay_usecs = nspi->xfer_udelay; |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 227 | spi_message_add_tail(&rx, &m); |
Eric Lapuyade | a4ada6c | 2013-09-23 18:02:43 +0200 | [diff] [blame] | 228 | |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 229 | ret = spi_sync(nspi->spi, &m); |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 230 | if (ret) |
| 231 | goto receive_error; |
| 232 | |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 233 | if (nspi->acknowledge_mode == NCI_SPI_CRC_ENABLED) { |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 234 | *skb_push(skb, 1) = resp_hdr[1]; |
| 235 | *skb_push(skb, 1) = resp_hdr[0]; |
| 236 | } |
| 237 | |
| 238 | return skb; |
| 239 | |
| 240 | receive_error: |
| 241 | kfree_skb(skb); |
| 242 | |
| 243 | return NULL; |
| 244 | } |
| 245 | |
| 246 | static int nci_spi_check_crc(struct sk_buff *skb) |
| 247 | { |
| 248 | u16 crc_data = (skb->data[skb->len - 2] << 8) | |
| 249 | skb->data[skb->len - 1]; |
| 250 | int ret; |
| 251 | |
| 252 | ret = (crc_ccitt(CRC_INIT, skb->data, skb->len - NCI_SPI_CRC_LEN) |
| 253 | == crc_data); |
| 254 | |
| 255 | skb_trim(skb, skb->len - NCI_SPI_CRC_LEN); |
| 256 | |
| 257 | return ret; |
| 258 | } |
| 259 | |
| 260 | static u8 nci_spi_get_ack(struct sk_buff *skb) |
| 261 | { |
| 262 | u8 ret; |
| 263 | |
| 264 | ret = skb->data[0] >> NCI_SPI_ACK_SHIFT; |
| 265 | |
| 266 | /* Remove NFCC part of the header: ACK, NACK and MSB payload len */ |
| 267 | skb_pull(skb, 2); |
| 268 | |
| 269 | return ret; |
| 270 | } |
| 271 | |
| 272 | /** |
Eric Lapuyade | 22d4aae | 2013-09-23 17:56:31 +0200 | [diff] [blame] | 273 | * nci_spi_read - read frame from NCI SPI drivers |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 274 | * |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 275 | * @nspi: The nci spi |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 276 | * Context: can sleep |
| 277 | * |
| 278 | * This call may only be used from a context that may sleep. The sleep |
| 279 | * is non-interruptible, and has no timeout. |
| 280 | * |
Eric Lapuyade | 22d4aae | 2013-09-23 17:56:31 +0200 | [diff] [blame] | 281 | * It returns an allocated skb containing the frame on success, or NULL. |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 282 | */ |
Eric Lapuyade | 22d4aae | 2013-09-23 17:56:31 +0200 | [diff] [blame] | 283 | struct sk_buff *nci_spi_read(struct nci_spi *nspi) |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 284 | { |
| 285 | struct sk_buff *skb; |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 286 | |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 287 | /* Retrieve frame from SPI */ |
Eric Lapuyade | 22d4aae | 2013-09-23 17:56:31 +0200 | [diff] [blame] | 288 | skb = __nci_spi_read(nspi); |
| 289 | if (!skb) |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 290 | goto done; |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 291 | |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 292 | if (nspi->acknowledge_mode == NCI_SPI_CRC_ENABLED) { |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 293 | if (!nci_spi_check_crc(skb)) { |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 294 | send_acknowledge(nspi, ACKNOWLEDGE_NACK); |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 295 | goto done; |
| 296 | } |
| 297 | |
| 298 | /* In case of acknowledged mode: if ACK or NACK received, |
| 299 | * unblock completion of latest frame sent. |
| 300 | */ |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 301 | nspi->req_result = nci_spi_get_ack(skb); |
| 302 | if (nspi->req_result) |
| 303 | complete(&nspi->req_completion); |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | /* If there is no payload (ACK/NACK only frame), |
| 307 | * free the socket buffer |
| 308 | */ |
Eric Lapuyade | 22d4aae | 2013-09-23 17:56:31 +0200 | [diff] [blame] | 309 | if (!skb->len) { |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 310 | kfree_skb(skb); |
Eric Lapuyade | 22d4aae | 2013-09-23 17:56:31 +0200 | [diff] [blame] | 311 | skb = NULL; |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 312 | goto done; |
| 313 | } |
| 314 | |
Eric Lapuyade | fa544ff | 2013-09-05 11:02:21 +0200 | [diff] [blame] | 315 | if (nspi->acknowledge_mode == NCI_SPI_CRC_ENABLED) |
| 316 | send_acknowledge(nspi, ACKNOWLEDGE_ACK); |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 317 | |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 318 | done: |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 319 | |
Eric Lapuyade | 22d4aae | 2013-09-23 17:56:31 +0200 | [diff] [blame] | 320 | return skb; |
Frederic Danis | 391d8a2 | 2013-05-29 15:35:04 +0200 | [diff] [blame] | 321 | } |
Eric Lapuyade | 22d4aae | 2013-09-23 17:56:31 +0200 | [diff] [blame] | 322 | EXPORT_SYMBOL_GPL(nci_spi_read); |