linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mike Rapoport <mike@compulab.co.il>
To: libertas-dev@lists.infradead.org
Cc: linux-wireless@vger.kernel.org
Subject: [PATCH] libertas: add abilty to set DMA buffers alignmnet for SPI interface in compile time
Date: Tue, 03 Feb 2009 09:04:17 +0200	[thread overview]
Message-ID: <4987EC71.6070808@compulab.co.il> (raw)

Different SPI controllers pose different alignment requirements on DMAable
buffers. It's possible to alter the SPI controller driver to use it's own
properly aligned buffers for DMA and copy the data it gets from the client
into these buffers. However, this approach also impacts overall performance.
Adding ability to set DMA buffers alignment for SPI interface in compile
time prevents unnecessary memcpy calls.

Signed-off-by: Mike Rapoport <mike@compulab.co.il>
---
 drivers/net/wireless/Kconfig           |   10 ++++++++++
 drivers/net/wireless/libertas/if_spi.c |   27 ++++++++++++++++-----------
 2 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/drivers/net/wireless/Kconfig b/drivers/net/wireless/Kconfig
index fe819a7..3bbb7b2 100644
--- a/drivers/net/wireless/Kconfig
+++ b/drivers/net/wireless/Kconfig
@@ -157,6 +157,16 @@ config LIBERTAS_SPI
 	---help---
 	  A driver for Marvell Libertas 8686 SPI devices.

+config LIBERTAS_SPI_DMA_ALIGN
+	int "DMA buffers alignment for SPI interface"
+	depends on LIBERTAS_SPI
+	default 4 if !ARCH_PXA
+	default 8 if ARCH_PXA
+	---help---
+	  Different SPI controllers pose different alignment
+	  requirements on DMAable buffers. Allow proper setting of
+	  this value in compile-time.
+
 config LIBERTAS_DEBUG
 	bool "Enable full debugging output in the Libertas module."
 	depends on LIBERTAS
diff --git a/drivers/net/wireless/libertas/if_spi.c b/drivers/net/wireless/libertas/if_spi.c
index 07311e7..3499948 100644
--- a/drivers/net/wireless/libertas/if_spi.c
+++ b/drivers/net/wireless/libertas/if_spi.c
@@ -33,10 +33,12 @@
 #include "dev.h"
 #include "if_spi.h"

+#define DMA_ALIGN CONFIG_LIBERTAS_SPI_DMA_ALIGN
+
 struct if_spi_packet {
-	struct list_head		list;
-	u16				blen;
-	u8				buffer[0] __attribute__((aligned(4)));
+	struct list_head	list;
+	u16			blen;
+	u8			buffer[0] __attribute__((aligned(DMA_ALIGN)));
 };

 struct if_spi_card {
@@ -73,7 +75,7 @@ struct if_spi_card {
 	struct semaphore		spi_ready;
 	struct semaphore		spi_thread_terminated;

-	u8				cmd_buffer[IF_SPI_CMD_BUF_SIZE];
+	u8				cmd_buffer[IF_SPI_CMD_BUF_SIZE] __attribute__((aligned(DMA_ALIGN)));

 	/* A buffer of incoming packets from libertas core.
 	 * Since we can't sleep in hw_host_to_card, we have to buffer
@@ -665,10 +667,13 @@ static int if_spi_c2h_cmd(struct if_spi_card *card)
 	BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE < LBS_CMD_BUFFER_SIZE);
 	BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE < LBS_UPLD_SIZE);

-	/* It's just annoying if the buffer size isn't a multiple of 4, because
-	 * then we might have len <  IF_SPI_CMD_BUF_SIZE but
-	 * ALIGN(len, 4) > IF_SPI_CMD_BUF_SIZE */
-	BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE % 4 != 0);
+	/*
+	 * It's just annoying if the buffer size isn't a multiple of
+	 * DMA_ALIGN, because then we might have
+	 * len < IF_SPI_CMD_BUF_SIZE but
+	 * ALIGN(len, DMA_ALIGN) > IF_SPI_CMD_BUF_SIZE
+	 */
+	BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE % DMA_ALIGN != 0);

 	lbs_deb_enter(LBS_DEB_SPI);

@@ -691,7 +696,7 @@ static int if_spi_c2h_cmd(struct if_spi_card *card)

 	/* Read the data from the WLAN module into our command buffer */
 	err = spu_read(card, IF_SPI_CMD_RDWRPORT_REG,
-				card->cmd_buffer, ALIGN(len, 4));
+				card->cmd_buffer, ALIGN(len, DMA_ALIGN));
 	if (err)
 		goto out;

@@ -747,7 +752,7 @@ static int if_spi_c2h_data(struct if_spi_card *card)
 	data = skb_put(skb, len);

 	/* Read the data from the WLAN module into our skb... */
-	err = spu_read(card, IF_SPI_DATA_RDWRPORT_REG, data, ALIGN(len, 4));
+	err = spu_read(card, IF_SPI_DATA_RDWRPORT_REG, data, ALIGN(len, DMA_ALIGN));
 	if (err)
 		goto free_skb;

@@ -940,7 +945,7 @@ static int if_spi_host_to_card(struct lbs_private *priv,
 		err = -EINVAL;
 		goto out;
 	}
-	blen = ALIGN(nb, 4);
+	blen = ALIGN(nb, DMA_ALIGN);
 	packet = kzalloc(sizeof(struct if_spi_packet) + blen, GFP_ATOMIC);
 	if (!packet) {
 		err = -ENOMEM;
-- 
1.5.6.4


-- 
Sincerely yours,
Mike.


             reply	other threads:[~2009-02-03  7:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-03  7:04 Mike Rapoport [this message]
2009-02-03 15:47 ` [PATCH] libertas: add abilty to set DMA buffers alignmnet for SPI interface in compile time Dan Williams
2009-02-03 16:17   ` Andrey Yurovsky
2009-02-03 16:37     ` Dan Williams
2009-02-04 14:51       ` Mike Rapoport

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=4987EC71.6070808@compulab.co.il \
    --to=mike@compulab.co.il \
    --cc=libertas-dev@lists.infradead.org \
    --cc=linux-wireless@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).