diff options
author | Ben Hutchings <bhutchings@solarflare.com> | 2012-09-18 19:31:42 -0400 |
---|---|---|
committer | Ben Hutchings <bhutchings@solarflare.com> | 2013-08-21 14:44:04 -0400 |
commit | caa7558655d5ae1997c6d52f87b59f8ec6f2c3af (patch) | |
tree | 0afd2dc9de7551c6e3e3f9c7f2cd8cf4cb90f1ff | |
parent | 0d19a540beb78493cd5acb7428760af0dc1ea154 (diff) |
sfc: Make struct efx_special_buffer less special
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>
-rw-r--r-- | drivers/net/ethernet/sfc/net_driver.h | 47 | ||||
-rw-r--r-- | 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 fb9361f384de..ea64cd8aa6fa 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; | |||
93 | struct efx_self_tests; | 93 | struct efx_self_tests; |
94 | 94 | ||
95 | /** | 95 | /** |
96 | * struct efx_special_buffer - An Efx special buffer | 96 | * struct efx_buffer - A general-purpose DMA buffer |
97 | * @addr: CPU base address of the buffer | 97 | * @addr: host base address of the buffer |
98 | * @dma_addr: DMA base address of the buffer | 98 | * @dma_addr: DMA base address of the buffer |
99 | * @len: Buffer length, in bytes | 99 | * @len: Buffer length, in bytes |
100 | * @index: Buffer index within controller;s buffer table | ||
101 | * @entries: Number of buffer table entries | ||
102 | * | 100 | * |
103 | * Special buffers are used for the event queues and the TX and RX | 101 | * The NIC uses these buffers for its interrupt status registers and |
104 | * descriptor queues for each channel. They are *not* used for the | 102 | * MAC stats dumps. |
105 | * actual transmit and receive buffers. | ||
106 | */ | 103 | */ |
107 | struct efx_special_buffer { | 104 | struct efx_buffer { |
108 | void *addr; | 105 | void *addr; |
109 | dma_addr_t dma_addr; | 106 | dma_addr_t dma_addr; |
110 | unsigned int len; | 107 | unsigned int len; |
108 | }; | ||
109 | |||
110 | /** | ||
111 | * struct efx_special_buffer - DMA buffer entered into buffer table | ||
112 | * @buf: Standard &struct efx_buffer | ||
113 | * @index: Buffer index within controller;s buffer table | ||
114 | * @entries: Number of buffer table entries | ||
115 | * | ||
116 | * The NIC has a buffer table that maps buffers of size %EFX_BUF_SIZE. | ||
117 | * Event and descriptor rings are addressed via one or more buffer | ||
118 | * table entries (and so can be physically non-contiguous, although we | ||
119 | * currently do not take advantage of that). On Falcon and Siena we | ||
120 | * have to take care of allocating and initialising the entries | ||
121 | * ourselves. On later hardware this is managed by the firmware and | ||
122 | * @index and @entries are left as 0. | ||
123 | */ | ||
124 | struct efx_special_buffer { | ||
125 | struct efx_buffer buf; | ||
111 | unsigned int index; | 126 | unsigned int index; |
112 | unsigned int entries; | 127 | unsigned int entries; |
113 | }; | 128 | }; |
@@ -325,22 +340,6 @@ struct efx_rx_queue { | |||
325 | unsigned int slow_fill_count; | 340 | unsigned int slow_fill_count; |
326 | }; | 341 | }; |
327 | 342 | ||
328 | /** | ||
329 | * struct efx_buffer - An Efx general-purpose buffer | ||
330 | * @addr: host base address of the buffer | ||
331 | * @dma_addr: DMA base address of the buffer | ||
332 | * @len: Buffer length, in bytes | ||
333 | * | ||
334 | * The NIC uses these buffers for its interrupt status registers and | ||
335 | * MAC stats dumps. | ||
336 | */ | ||
337 | struct efx_buffer { | ||
338 | void *addr; | ||
339 | dma_addr_t dma_addr; | ||
340 | unsigned int len; | ||
341 | }; | ||
342 | |||
343 | |||
344 | enum efx_rx_alloc_method { | 343 | enum efx_rx_alloc_method { |
345 | RX_ALLOC_METHOD_AUTO = 0, | 344 | RX_ALLOC_METHOD_AUTO = 0, |
346 | RX_ALLOC_METHOD_SKB = 1, | 345 | RX_ALLOC_METHOD_SKB = 1, |
diff --git a/drivers/net/ethernet/sfc/nic.c b/drivers/net/ethernet/sfc/nic.c index efe27738b18e..372891c5f846 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, | |||
93 | static inline efx_qword_t *efx_event(struct efx_channel *channel, | 93 | static inline efx_qword_t *efx_event(struct efx_channel *channel, |
94 | unsigned int index) | 94 | unsigned int index) |
95 | { | 95 | { |
96 | return ((efx_qword_t *) (channel->eventq.addr)) + | 96 | return ((efx_qword_t *) (channel->eventq.buf.addr)) + |
97 | (index & channel->eventq_mask); | 97 | (index & channel->eventq_mask); |
98 | } | 98 | } |
99 | 99 | ||
@@ -196,12 +196,12 @@ efx_init_special_buffer(struct efx_nic *efx, struct efx_special_buffer *buffer) | |||
196 | dma_addr_t dma_addr; | 196 | dma_addr_t dma_addr; |
197 | int i; | 197 | int i; |
198 | 198 | ||
199 | EFX_BUG_ON_PARANOID(!buffer->addr); | 199 | EFX_BUG_ON_PARANOID(!buffer->buf.addr); |
200 | 200 | ||
201 | /* Write buffer descriptors to NIC */ | 201 | /* Write buffer descriptors to NIC */ |
202 | for (i = 0; i < buffer->entries; i++) { | 202 | for (i = 0; i < buffer->entries; i++) { |
203 | index = buffer->index + i; | 203 | index = buffer->index + i; |
204 | dma_addr = buffer->dma_addr + (i * EFX_BUF_SIZE); | 204 | dma_addr = buffer->buf.dma_addr + (i * EFX_BUF_SIZE); |
205 | netif_dbg(efx, probe, efx->net_dev, | 205 | netif_dbg(efx, probe, efx->net_dev, |
206 | "mapping special buffer %d at %llx\n", | 206 | "mapping special buffer %d at %llx\n", |
207 | index, (unsigned long long)dma_addr); | 207 | index, (unsigned long long)dma_addr); |
@@ -250,13 +250,10 @@ static int efx_alloc_special_buffer(struct efx_nic *efx, | |||
250 | { | 250 | { |
251 | len = ALIGN(len, EFX_BUF_SIZE); | 251 | len = ALIGN(len, EFX_BUF_SIZE); |
252 | 252 | ||
253 | buffer->addr = dma_alloc_coherent(&efx->pci_dev->dev, len, | 253 | if (efx_nic_alloc_buffer(efx, &buffer->buf, len, GFP_KERNEL)) |
254 | &buffer->dma_addr, GFP_KERNEL); | ||
255 | if (!buffer->addr) | ||
256 | return -ENOMEM; | 254 | return -ENOMEM; |
257 | buffer->len = len; | ||
258 | buffer->entries = len / EFX_BUF_SIZE; | 255 | buffer->entries = len / EFX_BUF_SIZE; |
259 | BUG_ON(buffer->dma_addr & (EFX_BUF_SIZE - 1)); | 256 | BUG_ON(buffer->buf.dma_addr & (EFX_BUF_SIZE - 1)); |
260 | 257 | ||
261 | /* Select new buffer ID */ | 258 | /* Select new buffer ID */ |
262 | buffer->index = efx->next_buffer_table; | 259 | buffer->index = efx->next_buffer_table; |
@@ -270,8 +267,8 @@ static int efx_alloc_special_buffer(struct efx_nic *efx, | |||
270 | "allocating special buffers %d-%d at %llx+%x " | 267 | "allocating special buffers %d-%d at %llx+%x " |
271 | "(virt %p phys %llx)\n", buffer->index, | 268 | "(virt %p phys %llx)\n", buffer->index, |
272 | buffer->index + buffer->entries - 1, | 269 | buffer->index + buffer->entries - 1, |
273 | (u64)buffer->dma_addr, len, | 270 | (u64)buffer->buf.dma_addr, len, |
274 | buffer->addr, (u64)virt_to_phys(buffer->addr)); | 271 | buffer->buf.addr, (u64)virt_to_phys(buffer->buf.addr)); |
275 | 272 | ||
276 | return 0; | 273 | return 0; |
277 | } | 274 | } |
@@ -279,19 +276,17 @@ static int efx_alloc_special_buffer(struct efx_nic *efx, | |||
279 | static void | 276 | static void |
280 | efx_free_special_buffer(struct efx_nic *efx, struct efx_special_buffer *buffer) | 277 | efx_free_special_buffer(struct efx_nic *efx, struct efx_special_buffer *buffer) |
281 | { | 278 | { |
282 | if (!buffer->addr) | 279 | if (!buffer->buf.addr) |
283 | return; | 280 | return; |
284 | 281 | ||
285 | netif_dbg(efx, hw, efx->net_dev, | 282 | netif_dbg(efx, hw, efx->net_dev, |
286 | "deallocating special buffers %d-%d at %llx+%x " | 283 | "deallocating special buffers %d-%d at %llx+%x " |
287 | "(virt %p phys %llx)\n", buffer->index, | 284 | "(virt %p phys %llx)\n", buffer->index, |
288 | buffer->index + buffer->entries - 1, | 285 | buffer->index + buffer->entries - 1, |
289 | (u64)buffer->dma_addr, buffer->len, | 286 | (u64)buffer->buf.dma_addr, buffer->buf.len, |
290 | buffer->addr, (u64)virt_to_phys(buffer->addr)); | 287 | buffer->buf.addr, (u64)virt_to_phys(buffer->buf.addr)); |
291 | 288 | ||
292 | dma_free_coherent(&efx->pci_dev->dev, buffer->len, buffer->addr, | 289 | efx_nic_free_buffer(efx, &buffer->buf); |
293 | buffer->dma_addr); | ||
294 | buffer->addr = NULL; | ||
295 | buffer->entries = 0; | 290 | buffer->entries = 0; |
296 | } | 291 | } |
297 | 292 | ||
@@ -335,7 +330,7 @@ void efx_nic_free_buffer(struct efx_nic *efx, struct efx_buffer *buffer) | |||
335 | static inline efx_qword_t * | 330 | static inline efx_qword_t * |
336 | efx_tx_desc(struct efx_tx_queue *tx_queue, unsigned int index) | 331 | efx_tx_desc(struct efx_tx_queue *tx_queue, unsigned int index) |
337 | { | 332 | { |
338 | return ((efx_qword_t *) (tx_queue->txd.addr)) + index; | 333 | return ((efx_qword_t *) (tx_queue->txd.buf.addr)) + index; |
339 | } | 334 | } |
340 | 335 | ||
341 | /* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */ | 336 | /* 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) | |||
534 | static inline efx_qword_t * | 529 | static inline efx_qword_t * |
535 | efx_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index) | 530 | efx_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index) |
536 | { | 531 | { |
537 | return ((efx_qword_t *) (rx_queue->rxd.addr)) + index; | 532 | return ((efx_qword_t *) (rx_queue->rxd.buf.addr)) + index; |
538 | } | 533 | } |
539 | 534 | ||
540 | /* This creates an entry in the RX descriptor queue */ | 535 | /* This creates an entry in the RX descriptor queue */ |
@@ -1415,7 +1410,7 @@ void efx_nic_init_eventq(struct efx_channel *channel) | |||
1415 | efx_init_special_buffer(efx, &channel->eventq); | 1410 | efx_init_special_buffer(efx, &channel->eventq); |
1416 | 1411 | ||
1417 | /* Fill event queue with all ones (i.e. empty events) */ | 1412 | /* Fill event queue with all ones (i.e. empty events) */ |
1418 | memset(channel->eventq.addr, 0xff, channel->eventq.len); | 1413 | memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len); |
1419 | 1414 | ||
1420 | /* Push event queue to card */ | 1415 | /* Push event queue to card */ |
1421 | EFX_POPULATE_OWORD_3(reg, | 1416 | EFX_POPULATE_OWORD_3(reg, |