Commit 22d4aae5 authored by Eric Lapuyade's avatar Eric Lapuyade Committed by Samuel Ortiz

NFC: NCI: nci_spi_recv_frame() now returns (not forward) the read frame

Previously, nci_spi_recv_frame() would directly transmit incoming frames
to the NCI Core. However, it turns out that some NFC NCI Chips will add
additional proprietary headers that must be handled/removed before NCI
Core gets a chance to handle the frame. With this modification, the chip
phy or driver are now responsible to transmit incoming frames to NCI
Core after proper treatment, and NCI SPI becomes a driver helper instead
of sitting between the NFC driver and NCI Core.

As a general rule in NFC, *_recv_frame() APIs are used to deliver an
incoming frame to an upper layer. To better suit the actual purpose of
nci_spi_recv_frame(), and go along with its nci_spi_send()
counterpart, the function is renamed to nci_spi_read()

The skb is returned as the function result
Signed-off-by: default avatarEric Lapuyade <eric.lapuyade@intel.com>
Signed-off-by: default avatarSamuel Ortiz <sameo@linux.intel.com>
parent a4ada6ca
...@@ -233,6 +233,6 @@ struct nci_spi *nci_spi_allocate_spi(struct spi_device *spi, ...@@ -233,6 +233,6 @@ struct nci_spi *nci_spi_allocate_spi(struct spi_device *spi,
u8 acknowledge_mode, unsigned int delay, u8 acknowledge_mode, unsigned int delay,
struct nci_dev *ndev); struct nci_dev *ndev);
int nci_spi_send(struct nci_spi *nspi, struct sk_buff *skb); int nci_spi_send(struct nci_spi *nspi, struct sk_buff *skb);
int nci_spi_recv_frame(struct nci_spi *nspi); struct sk_buff *nci_spi_read(struct nci_spi *nspi);
#endif /* __NCI_CORE_H */ #endif /* __NCI_CORE_H */
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#include <linux/export.h> #include <linux/export.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <linux/crc-ccitt.h> #include <linux/crc-ccitt.h>
#include <linux/nfc.h>
#include <net/nfc/nci_core.h> #include <net/nfc/nci_core.h>
#define NCI_SPI_ACK_SHIFT 6 #define NCI_SPI_ACK_SHIFT 6
...@@ -164,7 +163,7 @@ static int send_acknowledge(struct nci_spi *nspi, u8 acknowledge) ...@@ -164,7 +163,7 @@ static int send_acknowledge(struct nci_spi *nspi, u8 acknowledge)
return ret; return ret;
} }
static struct sk_buff *__nci_spi_recv_frame(struct nci_spi *nspi) static struct sk_buff *__nci_spi_read(struct nci_spi *nspi)
{ {
struct sk_buff *skb; struct sk_buff *skb;
struct spi_message m; struct spi_message m;
...@@ -258,7 +257,7 @@ static u8 nci_spi_get_ack(struct sk_buff *skb) ...@@ -258,7 +257,7 @@ static u8 nci_spi_get_ack(struct sk_buff *skb)
} }
/** /**
* nci_spi_recv_frame - receive frame from NCI SPI drivers * nci_spi_read - read frame from NCI SPI drivers
* *
* @nspi: The nci spi * @nspi: The nci spi
* Context: can sleep * Context: can sleep
...@@ -266,21 +265,18 @@ static u8 nci_spi_get_ack(struct sk_buff *skb) ...@@ -266,21 +265,18 @@ static u8 nci_spi_get_ack(struct sk_buff *skb)
* This call may only be used from a context that may sleep. The sleep * This call may only be used from a context that may sleep. The sleep
* is non-interruptible, and has no timeout. * is non-interruptible, and has no timeout.
* *
* It returns zero on success, else a negative error code. * It returns an allocated skb containing the frame on success, or NULL.
*/ */
int nci_spi_recv_frame(struct nci_spi *nspi) struct sk_buff *nci_spi_read(struct nci_spi *nspi)
{ {
struct sk_buff *skb; struct sk_buff *skb;
int ret = 0;
nspi->ops->deassert_int(nspi); nspi->ops->deassert_int(nspi);
/* Retrieve frame from SPI */ /* Retrieve frame from SPI */
skb = __nci_spi_recv_frame(nspi); skb = __nci_spi_read(nspi);
if (!skb) { if (!skb)
ret = -EIO;
goto done; goto done;
}
if (nspi->acknowledge_mode == NCI_SPI_CRC_ENABLED) { if (nspi->acknowledge_mode == NCI_SPI_CRC_ENABLED) {
if (!nci_spi_check_crc(skb)) { if (!nci_spi_check_crc(skb)) {
...@@ -299,20 +295,18 @@ int nci_spi_recv_frame(struct nci_spi *nspi) ...@@ -299,20 +295,18 @@ int nci_spi_recv_frame(struct nci_spi *nspi)
/* If there is no payload (ACK/NACK only frame), /* If there is no payload (ACK/NACK only frame),
* free the socket buffer * free the socket buffer
*/ */
if (skb->len == 0) { if (!skb->len) {
kfree_skb(skb); kfree_skb(skb);
skb = NULL;
goto done; goto done;
} }
if (nspi->acknowledge_mode == NCI_SPI_CRC_ENABLED) if (nspi->acknowledge_mode == NCI_SPI_CRC_ENABLED)
send_acknowledge(nspi, ACKNOWLEDGE_ACK); send_acknowledge(nspi, ACKNOWLEDGE_ACK);
/* Forward skb to NCI core layer */
ret = nci_recv_frame(nspi->ndev, skb);
done: done:
nspi->ops->assert_int(nspi); nspi->ops->assert_int(nspi);
return ret; return skb;
} }
EXPORT_SYMBOL_GPL(nci_spi_recv_frame); EXPORT_SYMBOL_GPL(nci_spi_read);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment