Netdev List
 help / color / mirror / Atom feed
From: Ben Hutchings <bhutchings@solarflare.com>
To: David Miller <davem@davemloft.net>
Cc: <netdev@vger.kernel.org>, <linux-net-drivers@solarflare.com>
Subject: [PATCH net-next 19/32] sfc: Make struct efx_special_buffer less special
Date: Thu, 22 Aug 2013 13:55:11 +0100	[thread overview]
Message-ID: <1377176111.1703.24.camel@bwh-desktop.uk.level5networks.com> (raw)
In-Reply-To: <1377175392.1703.5.camel@bwh-desktop.uk.level5networks.com>

On EF10, the firmware is in charge of allocating buffer table entries.
Change struct efx_special_buffer to use a struct efx_buffer member,
so that it can be used with efx_nic_{alloc,free}_buffer() in that
case.

Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
---
 drivers/net/ethernet/sfc/net_driver.h | 47 +++++++++++++++++------------------
 drivers/net/ethernet/sfc/nic.c        | 33 +++++++++++-------------
 2 files changed, 37 insertions(+), 43 deletions(-)

diff --git a/drivers/net/ethernet/sfc/net_driver.h b/drivers/net/ethernet/sfc/net_driver.h
index fb9361f..ea64cd8 100644
--- a/drivers/net/ethernet/sfc/net_driver.h
+++ b/drivers/net/ethernet/sfc/net_driver.h
@@ -93,21 +93,36 @@ struct efx_ptp_data;
 struct efx_self_tests;
 
 /**
- * struct efx_special_buffer - An Efx special buffer
- * @addr: CPU base address of the buffer
+ * struct efx_buffer - A general-purpose DMA buffer
+ * @addr: host base address of the buffer
  * @dma_addr: DMA base address of the buffer
  * @len: Buffer length, in bytes
- * @index: Buffer index within controller;s buffer table
- * @entries: Number of buffer table entries
  *
- * Special buffers are used for the event queues and the TX and RX
- * descriptor queues for each channel.  They are *not* used for the
- * actual transmit and receive buffers.
+ * The NIC uses these buffers for its interrupt status registers and
+ * MAC stats dumps.
  */
-struct efx_special_buffer {
+struct efx_buffer {
 	void *addr;
 	dma_addr_t dma_addr;
 	unsigned int len;
+};
+
+/**
+ * struct efx_special_buffer - DMA buffer entered into buffer table
+ * @buf: Standard &struct efx_buffer
+ * @index: Buffer index within controller;s buffer table
+ * @entries: Number of buffer table entries
+ *
+ * The NIC has a buffer table that maps buffers of size %EFX_BUF_SIZE.
+ * Event and descriptor rings are addressed via one or more buffer
+ * table entries (and so can be physically non-contiguous, although we
+ * currently do not take advantage of that).  On Falcon and Siena we
+ * have to take care of allocating and initialising the entries
+ * ourselves.  On later hardware this is managed by the firmware and
+ * @index and @entries are left as 0.
+ */
+struct efx_special_buffer {
+	struct efx_buffer buf;
 	unsigned int index;
 	unsigned int entries;
 };
@@ -325,22 +340,6 @@ struct efx_rx_queue {
 	unsigned int slow_fill_count;
 };
 
-/**
- * struct efx_buffer - An Efx general-purpose buffer
- * @addr: host base address of the buffer
- * @dma_addr: DMA base address of the buffer
- * @len: Buffer length, in bytes
- *
- * The NIC uses these buffers for its interrupt status registers and
- * MAC stats dumps.
- */
-struct efx_buffer {
-	void *addr;
-	dma_addr_t dma_addr;
-	unsigned int len;
-};
-
-
 enum efx_rx_alloc_method {
 	RX_ALLOC_METHOD_AUTO = 0,
 	RX_ALLOC_METHOD_SKB = 1,
diff --git a/drivers/net/ethernet/sfc/nic.c b/drivers/net/ethernet/sfc/nic.c
index efe2773..372891c 100644
--- a/drivers/net/ethernet/sfc/nic.c
+++ b/drivers/net/ethernet/sfc/nic.c
@@ -93,7 +93,7 @@ static inline void efx_write_buf_tbl(struct efx_nic *efx, efx_qword_t *value,
 static inline efx_qword_t *efx_event(struct efx_channel *channel,
 				     unsigned int index)
 {
-	return ((efx_qword_t *) (channel->eventq.addr)) +
+	return ((efx_qword_t *) (channel->eventq.buf.addr)) +
 		(index & channel->eventq_mask);
 }
 
@@ -196,12 +196,12 @@ efx_init_special_buffer(struct efx_nic *efx, struct efx_special_buffer *buffer)
 	dma_addr_t dma_addr;
 	int i;
 
-	EFX_BUG_ON_PARANOID(!buffer->addr);
+	EFX_BUG_ON_PARANOID(!buffer->buf.addr);
 
 	/* Write buffer descriptors to NIC */
 	for (i = 0; i < buffer->entries; i++) {
 		index = buffer->index + i;
-		dma_addr = buffer->dma_addr + (i * EFX_BUF_SIZE);
+		dma_addr = buffer->buf.dma_addr + (i * EFX_BUF_SIZE);
 		netif_dbg(efx, probe, efx->net_dev,
 			  "mapping special buffer %d at %llx\n",
 			  index, (unsigned long long)dma_addr);
@@ -250,13 +250,10 @@ static int efx_alloc_special_buffer(struct efx_nic *efx,
 {
 	len = ALIGN(len, EFX_BUF_SIZE);
 
-	buffer->addr = dma_alloc_coherent(&efx->pci_dev->dev, len,
-					  &buffer->dma_addr, GFP_KERNEL);
-	if (!buffer->addr)
+	if (efx_nic_alloc_buffer(efx, &buffer->buf, len, GFP_KERNEL))
 		return -ENOMEM;
-	buffer->len = len;
 	buffer->entries = len / EFX_BUF_SIZE;
-	BUG_ON(buffer->dma_addr & (EFX_BUF_SIZE - 1));
+	BUG_ON(buffer->buf.dma_addr & (EFX_BUF_SIZE - 1));
 
 	/* Select new buffer ID */
 	buffer->index = efx->next_buffer_table;
@@ -270,8 +267,8 @@ static int efx_alloc_special_buffer(struct efx_nic *efx,
 		  "allocating special buffers %d-%d at %llx+%x "
 		  "(virt %p phys %llx)\n", buffer->index,
 		  buffer->index + buffer->entries - 1,
-		  (u64)buffer->dma_addr, len,
-		  buffer->addr, (u64)virt_to_phys(buffer->addr));
+		  (u64)buffer->buf.dma_addr, len,
+		  buffer->buf.addr, (u64)virt_to_phys(buffer->buf.addr));
 
 	return 0;
 }
@@ -279,19 +276,17 @@ static int efx_alloc_special_buffer(struct efx_nic *efx,
 static void
 efx_free_special_buffer(struct efx_nic *efx, struct efx_special_buffer *buffer)
 {
-	if (!buffer->addr)
+	if (!buffer->buf.addr)
 		return;
 
 	netif_dbg(efx, hw, efx->net_dev,
 		  "deallocating special buffers %d-%d at %llx+%x "
 		  "(virt %p phys %llx)\n", buffer->index,
 		  buffer->index + buffer->entries - 1,
-		  (u64)buffer->dma_addr, buffer->len,
-		  buffer->addr, (u64)virt_to_phys(buffer->addr));
+		  (u64)buffer->buf.dma_addr, buffer->buf.len,
+		  buffer->buf.addr, (u64)virt_to_phys(buffer->buf.addr));
 
-	dma_free_coherent(&efx->pci_dev->dev, buffer->len, buffer->addr,
-			  buffer->dma_addr);
-	buffer->addr = NULL;
+	efx_nic_free_buffer(efx, &buffer->buf);
 	buffer->entries = 0;
 }
 
@@ -335,7 +330,7 @@ void efx_nic_free_buffer(struct efx_nic *efx, struct efx_buffer *buffer)
 static inline efx_qword_t *
 efx_tx_desc(struct efx_tx_queue *tx_queue, unsigned int index)
 {
-	return ((efx_qword_t *) (tx_queue->txd.addr)) + index;
+	return ((efx_qword_t *) (tx_queue->txd.buf.addr)) + index;
 }
 
 /* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
@@ -534,7 +529,7 @@ void efx_nic_remove_tx(struct efx_tx_queue *tx_queue)
 static inline efx_qword_t *
 efx_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
 {
-	return ((efx_qword_t *) (rx_queue->rxd.addr)) + index;
+	return ((efx_qword_t *) (rx_queue->rxd.buf.addr)) + index;
 }
 
 /* This creates an entry in the RX descriptor queue */
@@ -1415,7 +1410,7 @@ void efx_nic_init_eventq(struct efx_channel *channel)
 	efx_init_special_buffer(efx, &channel->eventq);
 
 	/* Fill event queue with all ones (i.e. empty events) */
-	memset(channel->eventq.addr, 0xff, channel->eventq.len);
+	memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len);
 
 	/* Push event queue to card */
 	EFX_POPULATE_OWORD_3(reg,


-- 
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.

  parent reply	other threads:[~2013-08-22 12:55 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-22 12:43 Pull request: sfc-next 2013-08-22 Ben Hutchings
2013-08-22 12:44 ` [PATCH net-next 01/32] sfc: Fix lookup of default RX MAC filters when steered using ethtool Ben Hutchings
2013-08-22 12:44 ` [PATCH net-next 02/32] sfc: const-qualify source pointers for MMIO write functions Ben Hutchings
2013-08-22 12:45 ` [PATCH net-next 03/32] sfc: Use efx_mcdi_mon() to find efx_mcdi_mon structure from efx_nic Ben Hutchings
2013-08-22 12:45 ` [PATCH net-next 04/32] sfc: Move details of a Falcon bug workaround out of ethtool.c Ben Hutchings
2013-08-22 12:46 ` [PATCH net-next 05/32] sfc: Move more Falcon-specific code and definitions into falcon.c Ben Hutchings
2013-08-22 12:46 ` [PATCH net-next 06/32] sfc: Introduce and use MCDI_DECLARE_BUF macro Ben Hutchings
2013-08-22 12:47 ` [PATCH net-next 07/32] sfc: Rationalise MCDI buffer accessors Ben Hutchings
2013-08-22 12:48 ` [PATCH net-next 08/32] sfc: Fill out the set of MCDI accessors Ben Hutchings
2013-08-22 12:48 ` [PATCH net-next 09/32] sfc: Introduce and use MCDI_CTL_SDU_LEN_MAX_V1 macro for Siena-specific code Ben Hutchings
2013-08-22 12:49 ` [PATCH net-next 10/32] sfc: Use proper macros to declare and access MCDI arrays Ben Hutchings
2013-08-22 12:49 ` [PATCH net-next 11/32] sfc: Ensure MCDI buffers, but not lengths, are dword aligned Ben Hutchings
2013-08-22 12:50 ` [PATCH net-next 12/32] sfc: Add and use MCDI_SET_QWORD() and MCDI_SET_ARRAY_QWORD() Ben Hutchings
2013-08-22 12:50 ` [PATCH net-next 13/32] sfc: Move siena_reset_hw() and siena_map_reset_reason() into MCDI module Ben Hutchings
2013-08-22 12:50 ` [PATCH net-next 14/32] sfc: Move efx_mcdi_mac_reconfigure() to siena.c and rename Ben Hutchings
2013-08-22 12:52 ` [PATCH net-next 15/32] sfc: Collect all MCDI port functions into mcdi_port.c Ben Hutchings
2013-08-22 12:53 ` [PATCH net-next 16/32] sfc: Make efx_mcdi_init() call efx_mcdi_handle_assertion() Ben Hutchings
2013-08-22 12:54 ` [PATCH net-next 17/32] sfc: Make MCDI independent of Siena Ben Hutchings
2013-08-22 12:54 ` [PATCH net-next 18/32] sfc: Add GFP flags to efx_nic_alloc_buffer() and make most callers allow blocking Ben Hutchings
2013-08-22 12:55 ` Ben Hutchings [this message]
2013-08-22 12:55 ` [PATCH net-next 20/32] sfc: Rename Falcon-architecture register definitions Ben Hutchings
2013-08-22 12:56 ` [PATCH net-next 21/32] sfc: Remove efx_process_channel_now() Ben Hutchings
2013-08-22 12:57 ` [PATCH net-next 22/32] sfc: Rework IRQ enable/disable Ben Hutchings
2013-08-22 12:59 ` [PATCH net-next 23/32] sfc: Limit scope of a Falcon A1 IRQ workaround Ben Hutchings
2013-08-22 13:00 ` [PATCH net-next 24/32] sfc: Stop RX refill before flushing RX queues Ben Hutchings
2013-08-22 13:00 ` [PATCH net-next 25/32] sfc: Remove bogus call to efx_release_tx_buffers() Ben Hutchings
2013-08-22 13:02 ` [PATCH net-next 26/32] sfc: Refactor queue teardown sequence to allow for EF10 flush behaviour Ben Hutchings
2013-08-22 13:05 ` [PATCH net-next 27/32] sfc: Move and rename Falcon/Siena common NIC operations Ben Hutchings
2013-08-22 13:05 ` [PATCH net-next 28/32] sfc: Translate MCDI error numbers received in events Ben Hutchings
2013-08-22 13:07 ` [PATCH net-next 29/32] sfc: Update MCDI protocol definitions for EF10 Ben Hutchings
2013-08-22 13:09 ` [PATCH net-next 30/32] sfc: Add support for MCDI v2 Ben Hutchings
2013-08-22 13:10 ` [PATCH net-next 31/32] sfc: Fix race in completion handling Ben Hutchings
2013-08-22 13:10 ` [PATCH net-next 32/32] sfc: Update and improve kernel-doc for efx_mcdi_state & efx_mcdi_iface Ben Hutchings
2013-08-22 19:09 ` Pull request: sfc-next 2013-08-22 David Miller
2013-08-22 19:16   ` Ben Hutchings

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=1377176111.1703.24.camel@bwh-desktop.uk.level5networks.com \
    --to=bhutchings@solarflare.com \
    --cc=davem@davemloft.net \
    --cc=linux-net-drivers@solarflare.com \
    --cc=netdev@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