提交 b6ec895e 编写于 作者: A Alexander Duyck 提交者: Jeff Kirsher

ixgbe: move device pointer into the ring structure

This change is meant to simplify DMA map/unmap by providing a device
pointer. As a result the adapter pointer can be dropped from many of
the calls.
Signed-off-by: NAlexander Duyck <alexander.h.duyck@intel.com>
Tested-by: NRoss Brattain <ross.b.brattain@intel.com>
Signed-off-by: NJeff Kirsher <jeffrey.t.kirsher@intel.com>
上级 84ea2591
...@@ -148,6 +148,7 @@ struct ixgbe_queue_stats { ...@@ -148,6 +148,7 @@ struct ixgbe_queue_stats {
struct ixgbe_ring { struct ixgbe_ring {
void *desc; /* descriptor ring memory */ void *desc; /* descriptor ring memory */
struct device *dev; /* device for DMA mapping */
union { union {
struct ixgbe_tx_buffer *tx_buffer_info; struct ixgbe_tx_buffer *tx_buffer_info;
struct ixgbe_rx_buffer *rx_buffer_info; struct ixgbe_rx_buffer *rx_buffer_info;
...@@ -454,10 +455,10 @@ extern void ixgbe_down(struct ixgbe_adapter *adapter); ...@@ -454,10 +455,10 @@ extern void ixgbe_down(struct ixgbe_adapter *adapter);
extern void ixgbe_reinit_locked(struct ixgbe_adapter *adapter); extern void ixgbe_reinit_locked(struct ixgbe_adapter *adapter);
extern void ixgbe_reset(struct ixgbe_adapter *adapter); extern void ixgbe_reset(struct ixgbe_adapter *adapter);
extern void ixgbe_set_ethtool_ops(struct net_device *netdev); extern void ixgbe_set_ethtool_ops(struct net_device *netdev);
extern int ixgbe_setup_rx_resources(struct ixgbe_adapter *, struct ixgbe_ring *); extern int ixgbe_setup_rx_resources(struct ixgbe_ring *);
extern int ixgbe_setup_tx_resources(struct ixgbe_adapter *, struct ixgbe_ring *); extern int ixgbe_setup_tx_resources(struct ixgbe_ring *);
extern void ixgbe_free_rx_resources(struct ixgbe_adapter *, struct ixgbe_ring *); extern void ixgbe_free_rx_resources(struct ixgbe_ring *);
extern void ixgbe_free_tx_resources(struct ixgbe_adapter *, struct ixgbe_ring *); extern void ixgbe_free_tx_resources(struct ixgbe_ring *);
extern void ixgbe_configure_rx_ring(struct ixgbe_adapter *,struct ixgbe_ring *); extern void ixgbe_configure_rx_ring(struct ixgbe_adapter *,struct ixgbe_ring *);
extern void ixgbe_configure_tx_ring(struct ixgbe_adapter *,struct ixgbe_ring *); extern void ixgbe_configure_tx_ring(struct ixgbe_adapter *,struct ixgbe_ring *);
extern void ixgbe_update_stats(struct ixgbe_adapter *adapter); extern void ixgbe_update_stats(struct ixgbe_adapter *adapter);
...@@ -467,7 +468,7 @@ extern netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *, ...@@ -467,7 +468,7 @@ extern netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *,
struct net_device *, struct net_device *,
struct ixgbe_adapter *, struct ixgbe_adapter *,
struct ixgbe_ring *); struct ixgbe_ring *);
extern void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter *, extern void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *,
struct ixgbe_tx_buffer *); struct ixgbe_tx_buffer *);
extern void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter, extern void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter,
struct ixgbe_ring *rx_ring, struct ixgbe_ring *rx_ring,
......
...@@ -900,13 +900,11 @@ static int ixgbe_set_ringparam(struct net_device *netdev, ...@@ -900,13 +900,11 @@ static int ixgbe_set_ringparam(struct net_device *netdev,
memcpy(&temp_tx_ring[i], adapter->tx_ring[i], memcpy(&temp_tx_ring[i], adapter->tx_ring[i],
sizeof(struct ixgbe_ring)); sizeof(struct ixgbe_ring));
temp_tx_ring[i].count = new_tx_count; temp_tx_ring[i].count = new_tx_count;
err = ixgbe_setup_tx_resources(adapter, err = ixgbe_setup_tx_resources(&temp_tx_ring[i]);
&temp_tx_ring[i]);
if (err) { if (err) {
while (i) { while (i) {
i--; i--;
ixgbe_free_tx_resources(adapter, ixgbe_free_tx_resources(&temp_tx_ring[i]);
&temp_tx_ring[i]);
} }
goto clear_reset; goto clear_reset;
} }
...@@ -925,13 +923,11 @@ static int ixgbe_set_ringparam(struct net_device *netdev, ...@@ -925,13 +923,11 @@ static int ixgbe_set_ringparam(struct net_device *netdev,
memcpy(&temp_rx_ring[i], adapter->rx_ring[i], memcpy(&temp_rx_ring[i], adapter->rx_ring[i],
sizeof(struct ixgbe_ring)); sizeof(struct ixgbe_ring));
temp_rx_ring[i].count = new_rx_count; temp_rx_ring[i].count = new_rx_count;
err = ixgbe_setup_rx_resources(adapter, err = ixgbe_setup_rx_resources(&temp_rx_ring[i]);
&temp_rx_ring[i]);
if (err) { if (err) {
while (i) { while (i) {
i--; i--;
ixgbe_free_rx_resources(adapter, ixgbe_free_rx_resources(&temp_rx_ring[i]);
&temp_rx_ring[i]);
} }
goto err_setup; goto err_setup;
} }
...@@ -946,8 +942,7 @@ static int ixgbe_set_ringparam(struct net_device *netdev, ...@@ -946,8 +942,7 @@ static int ixgbe_set_ringparam(struct net_device *netdev,
/* tx */ /* tx */
if (new_tx_count != adapter->tx_ring_count) { if (new_tx_count != adapter->tx_ring_count) {
for (i = 0; i < adapter->num_tx_queues; i++) { for (i = 0; i < adapter->num_tx_queues; i++) {
ixgbe_free_tx_resources(adapter, ixgbe_free_tx_resources(adapter->tx_ring[i]);
adapter->tx_ring[i]);
memcpy(adapter->tx_ring[i], &temp_tx_ring[i], memcpy(adapter->tx_ring[i], &temp_tx_ring[i],
sizeof(struct ixgbe_ring)); sizeof(struct ixgbe_ring));
} }
...@@ -957,8 +952,7 @@ static int ixgbe_set_ringparam(struct net_device *netdev, ...@@ -957,8 +952,7 @@ static int ixgbe_set_ringparam(struct net_device *netdev,
/* rx */ /* rx */
if (new_rx_count != adapter->rx_ring_count) { if (new_rx_count != adapter->rx_ring_count) {
for (i = 0; i < adapter->num_rx_queues; i++) { for (i = 0; i < adapter->num_rx_queues; i++) {
ixgbe_free_rx_resources(adapter, ixgbe_free_rx_resources(adapter->rx_ring[i]);
adapter->rx_ring[i]);
memcpy(adapter->rx_ring[i], &temp_rx_ring[i], memcpy(adapter->rx_ring[i], &temp_rx_ring[i],
sizeof(struct ixgbe_ring)); sizeof(struct ixgbe_ring));
} }
...@@ -1463,8 +1457,8 @@ static void ixgbe_free_desc_rings(struct ixgbe_adapter *adapter) ...@@ -1463,8 +1457,8 @@ static void ixgbe_free_desc_rings(struct ixgbe_adapter *adapter)
ixgbe_reset(adapter); ixgbe_reset(adapter);
ixgbe_free_tx_resources(adapter, &adapter->test_tx_ring); ixgbe_free_tx_resources(&adapter->test_tx_ring);
ixgbe_free_rx_resources(adapter, &adapter->test_rx_ring); ixgbe_free_rx_resources(&adapter->test_rx_ring);
} }
static int ixgbe_setup_desc_rings(struct ixgbe_adapter *adapter) static int ixgbe_setup_desc_rings(struct ixgbe_adapter *adapter)
...@@ -1478,10 +1472,11 @@ static int ixgbe_setup_desc_rings(struct ixgbe_adapter *adapter) ...@@ -1478,10 +1472,11 @@ static int ixgbe_setup_desc_rings(struct ixgbe_adapter *adapter)
/* Setup Tx descriptor ring and Tx buffers */ /* Setup Tx descriptor ring and Tx buffers */
tx_ring->count = IXGBE_DEFAULT_TXD; tx_ring->count = IXGBE_DEFAULT_TXD;
tx_ring->queue_index = 0; tx_ring->queue_index = 0;
tx_ring->dev = &adapter->pdev->dev;
tx_ring->reg_idx = adapter->tx_ring[0]->reg_idx; tx_ring->reg_idx = adapter->tx_ring[0]->reg_idx;
tx_ring->numa_node = adapter->node; tx_ring->numa_node = adapter->node;
err = ixgbe_setup_tx_resources(adapter, tx_ring); err = ixgbe_setup_tx_resources(tx_ring);
if (err) if (err)
return 1; return 1;
...@@ -1496,11 +1491,12 @@ static int ixgbe_setup_desc_rings(struct ixgbe_adapter *adapter) ...@@ -1496,11 +1491,12 @@ static int ixgbe_setup_desc_rings(struct ixgbe_adapter *adapter)
/* Setup Rx Descriptor ring and Rx buffers */ /* Setup Rx Descriptor ring and Rx buffers */
rx_ring->count = IXGBE_DEFAULT_RXD; rx_ring->count = IXGBE_DEFAULT_RXD;
rx_ring->queue_index = 0; rx_ring->queue_index = 0;
rx_ring->dev = &adapter->pdev->dev;
rx_ring->reg_idx = adapter->rx_ring[0]->reg_idx; rx_ring->reg_idx = adapter->rx_ring[0]->reg_idx;
rx_ring->rx_buf_len = IXGBE_RXBUFFER_2048; rx_ring->rx_buf_len = IXGBE_RXBUFFER_2048;
rx_ring->numa_node = adapter->node; rx_ring->numa_node = adapter->node;
err = ixgbe_setup_rx_resources(adapter, rx_ring); err = ixgbe_setup_rx_resources(rx_ring);
if (err) { if (err) {
ret_val = 4; ret_val = 4;
goto err_nomem; goto err_nomem;
...@@ -1622,7 +1618,7 @@ static u16 ixgbe_clean_test_rings(struct ixgbe_adapter *adapter, ...@@ -1622,7 +1618,7 @@ static u16 ixgbe_clean_test_rings(struct ixgbe_adapter *adapter,
rx_buffer_info = &rx_ring->rx_buffer_info[rx_ntc]; rx_buffer_info = &rx_ring->rx_buffer_info[rx_ntc];
/* unmap Rx buffer, will be remapped by alloc_rx_buffers */ /* unmap Rx buffer, will be remapped by alloc_rx_buffers */
dma_unmap_single(&adapter->pdev->dev, dma_unmap_single(rx_ring->dev,
rx_buffer_info->dma, rx_buffer_info->dma,
bufsz, bufsz,
DMA_FROM_DEVICE); DMA_FROM_DEVICE);
...@@ -1634,7 +1630,7 @@ static u16 ixgbe_clean_test_rings(struct ixgbe_adapter *adapter, ...@@ -1634,7 +1630,7 @@ static u16 ixgbe_clean_test_rings(struct ixgbe_adapter *adapter,
/* unmap buffer on Tx side */ /* unmap buffer on Tx side */
tx_buffer_info = &tx_ring->tx_buffer_info[tx_ntc]; tx_buffer_info = &tx_ring->tx_buffer_info[tx_ntc];
ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info); ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
/* increment Rx/Tx next to clean counters */ /* increment Rx/Tx next to clean counters */
rx_ntc++; rx_ntc++;
......
...@@ -600,18 +600,17 @@ static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, ...@@ -600,18 +600,17 @@ static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
} }
} }
void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter *adapter, void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *tx_ring,
struct ixgbe_tx_buffer struct ixgbe_tx_buffer *tx_buffer_info)
*tx_buffer_info)
{ {
if (tx_buffer_info->dma) { if (tx_buffer_info->dma) {
if (tx_buffer_info->mapped_as_page) if (tx_buffer_info->mapped_as_page)
dma_unmap_page(&adapter->pdev->dev, dma_unmap_page(tx_ring->dev,
tx_buffer_info->dma, tx_buffer_info->dma,
tx_buffer_info->length, tx_buffer_info->length,
DMA_TO_DEVICE); DMA_TO_DEVICE);
else else
dma_unmap_single(&adapter->pdev->dev, dma_unmap_single(tx_ring->dev,
tx_buffer_info->dma, tx_buffer_info->dma,
tx_buffer_info->length, tx_buffer_info->length,
DMA_TO_DEVICE); DMA_TO_DEVICE);
...@@ -764,7 +763,7 @@ static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector, ...@@ -764,7 +763,7 @@ static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
total_packets += tx_buffer_info->gso_segs; total_packets += tx_buffer_info->gso_segs;
} }
ixgbe_unmap_and_free_tx_resource(adapter, ixgbe_unmap_and_free_tx_resource(tx_ring,
tx_buffer_info); tx_buffer_info);
} }
...@@ -1011,7 +1010,6 @@ void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter, ...@@ -1011,7 +1010,6 @@ void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter,
struct ixgbe_ring *rx_ring, struct ixgbe_ring *rx_ring,
u16 cleaned_count) u16 cleaned_count)
{ {
struct pci_dev *pdev = adapter->pdev;
union ixgbe_adv_rx_desc *rx_desc; union ixgbe_adv_rx_desc *rx_desc;
struct ixgbe_rx_buffer *bi; struct ixgbe_rx_buffer *bi;
struct sk_buff *skb; struct sk_buff *skb;
...@@ -1035,11 +1033,11 @@ void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter, ...@@ -1035,11 +1033,11 @@ void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter,
} }
if (!bi->dma) { if (!bi->dma) {
bi->dma = dma_map_single(&pdev->dev, bi->dma = dma_map_single(rx_ring->dev,
skb->data, skb->data,
rx_ring->rx_buf_len, rx_ring->rx_buf_len,
DMA_FROM_DEVICE); DMA_FROM_DEVICE);
if (dma_mapping_error(&pdev->dev, bi->dma)) { if (dma_mapping_error(rx_ring->dev, bi->dma)) {
adapter->alloc_rx_buff_failed++; adapter->alloc_rx_buff_failed++;
bi->dma = 0; bi->dma = 0;
goto no_buffers; goto no_buffers;
...@@ -1058,12 +1056,12 @@ void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter, ...@@ -1058,12 +1056,12 @@ void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter,
if (!bi->page_dma) { if (!bi->page_dma) {
/* use a half page if we're re-using */ /* use a half page if we're re-using */
bi->page_offset ^= PAGE_SIZE / 2; bi->page_offset ^= PAGE_SIZE / 2;
bi->page_dma = dma_map_page(&pdev->dev, bi->page_dma = dma_map_page(rx_ring->dev,
bi->page, bi->page,
bi->page_offset, bi->page_offset,
PAGE_SIZE / 2, PAGE_SIZE / 2,
DMA_FROM_DEVICE); DMA_FROM_DEVICE);
if (dma_mapping_error(&pdev->dev, if (dma_mapping_error(rx_ring->dev,
bi->page_dma)) { bi->page_dma)) {
adapter->alloc_rx_page_failed++; adapter->alloc_rx_page_failed++;
bi->page_dma = 0; bi->page_dma = 0;
...@@ -1151,7 +1149,6 @@ static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, ...@@ -1151,7 +1149,6 @@ static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
int *work_done, int work_to_do) int *work_done, int work_to_do)
{ {
struct ixgbe_adapter *adapter = q_vector->adapter; struct ixgbe_adapter *adapter = q_vector->adapter;
struct pci_dev *pdev = adapter->pdev;
union ixgbe_adv_rx_desc *rx_desc, *next_rxd; union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer; struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
struct sk_buff *skb; struct sk_buff *skb;
...@@ -1208,7 +1205,7 @@ static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, ...@@ -1208,7 +1205,7 @@ static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
IXGBE_RSC_CB(skb)->delay_unmap = true; IXGBE_RSC_CB(skb)->delay_unmap = true;
IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma; IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma;
} else { } else {
dma_unmap_single(&pdev->dev, dma_unmap_single(rx_ring->dev,
rx_buffer_info->dma, rx_buffer_info->dma,
rx_ring->rx_buf_len, rx_ring->rx_buf_len,
DMA_FROM_DEVICE); DMA_FROM_DEVICE);
...@@ -1218,8 +1215,10 @@ static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, ...@@ -1218,8 +1215,10 @@ static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
} }
if (upper_len) { if (upper_len) {
dma_unmap_page(&pdev->dev, rx_buffer_info->page_dma, dma_unmap_page(rx_ring->dev,
PAGE_SIZE / 2, DMA_FROM_DEVICE); rx_buffer_info->page_dma,
PAGE_SIZE / 2,
DMA_FROM_DEVICE);
rx_buffer_info->page_dma = 0; rx_buffer_info->page_dma = 0;
skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
rx_buffer_info->page, rx_buffer_info->page,
...@@ -1262,7 +1261,7 @@ static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, ...@@ -1262,7 +1261,7 @@ static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
&(rx_ring->rsc_count)); &(rx_ring->rsc_count));
if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
if (IXGBE_RSC_CB(skb)->delay_unmap) { if (IXGBE_RSC_CB(skb)->delay_unmap) {
dma_unmap_single(&pdev->dev, dma_unmap_single(rx_ring->dev,
IXGBE_RSC_CB(skb)->dma, IXGBE_RSC_CB(skb)->dma,
rx_ring->rx_buf_len, rx_ring->rx_buf_len,
DMA_FROM_DEVICE); DMA_FROM_DEVICE);
...@@ -3665,15 +3664,13 @@ void ixgbe_reset(struct ixgbe_adapter *adapter) ...@@ -3665,15 +3664,13 @@ void ixgbe_reset(struct ixgbe_adapter *adapter)
/** /**
* ixgbe_clean_rx_ring - Free Rx Buffers per Queue * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
* @adapter: board private structure
* @rx_ring: ring to free buffers from * @rx_ring: ring to free buffers from
**/ **/
static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter, static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
struct ixgbe_ring *rx_ring)
{ {
struct pci_dev *pdev = adapter->pdev; struct device *dev = rx_ring->dev;
unsigned long size; unsigned long size;
unsigned int i; u16 i;
/* ring already cleared, nothing to do */ /* ring already cleared, nothing to do */
if (!rx_ring->rx_buffer_info) if (!rx_ring->rx_buffer_info)
...@@ -3685,7 +3682,7 @@ static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter, ...@@ -3685,7 +3682,7 @@ static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
rx_buffer_info = &rx_ring->rx_buffer_info[i]; rx_buffer_info = &rx_ring->rx_buffer_info[i];
if (rx_buffer_info->dma) { if (rx_buffer_info->dma) {
dma_unmap_single(&pdev->dev, rx_buffer_info->dma, dma_unmap_single(rx_ring->dev, rx_buffer_info->dma,
rx_ring->rx_buf_len, rx_ring->rx_buf_len,
DMA_FROM_DEVICE); DMA_FROM_DEVICE);
rx_buffer_info->dma = 0; rx_buffer_info->dma = 0;
...@@ -3696,7 +3693,7 @@ static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter, ...@@ -3696,7 +3693,7 @@ static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
do { do {
struct sk_buff *this = skb; struct sk_buff *this = skb;
if (IXGBE_RSC_CB(this)->delay_unmap) { if (IXGBE_RSC_CB(this)->delay_unmap) {
dma_unmap_single(&pdev->dev, dma_unmap_single(dev,
IXGBE_RSC_CB(this)->dma, IXGBE_RSC_CB(this)->dma,
rx_ring->rx_buf_len, rx_ring->rx_buf_len,
DMA_FROM_DEVICE); DMA_FROM_DEVICE);
...@@ -3710,7 +3707,7 @@ static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter, ...@@ -3710,7 +3707,7 @@ static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
if (!rx_buffer_info->page) if (!rx_buffer_info->page)
continue; continue;
if (rx_buffer_info->page_dma) { if (rx_buffer_info->page_dma) {
dma_unmap_page(&pdev->dev, rx_buffer_info->page_dma, dma_unmap_page(dev, rx_buffer_info->page_dma,
PAGE_SIZE / 2, DMA_FROM_DEVICE); PAGE_SIZE / 2, DMA_FROM_DEVICE);
rx_buffer_info->page_dma = 0; rx_buffer_info->page_dma = 0;
} }
...@@ -3731,15 +3728,13 @@ static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter, ...@@ -3731,15 +3728,13 @@ static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
/** /**
* ixgbe_clean_tx_ring - Free Tx Buffers * ixgbe_clean_tx_ring - Free Tx Buffers
* @adapter: board private structure
* @tx_ring: ring to be cleaned * @tx_ring: ring to be cleaned
**/ **/
static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter, static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
struct ixgbe_ring *tx_ring)
{ {
struct ixgbe_tx_buffer *tx_buffer_info; struct ixgbe_tx_buffer *tx_buffer_info;
unsigned long size; unsigned long size;
unsigned int i; u16 i;
/* ring already cleared, nothing to do */ /* ring already cleared, nothing to do */
if (!tx_ring->tx_buffer_info) if (!tx_ring->tx_buffer_info)
...@@ -3748,7 +3743,7 @@ static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter, ...@@ -3748,7 +3743,7 @@ static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
/* Free all the Tx ring sk_buffs */ /* Free all the Tx ring sk_buffs */
for (i = 0; i < tx_ring->count; i++) { for (i = 0; i < tx_ring->count; i++) {
tx_buffer_info = &tx_ring->tx_buffer_info[i]; tx_buffer_info = &tx_ring->tx_buffer_info[i];
ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info); ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
} }
size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
...@@ -3770,7 +3765,7 @@ static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) ...@@ -3770,7 +3765,7 @@ static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
int i; int i;
for (i = 0; i < adapter->num_rx_queues; i++) for (i = 0; i < adapter->num_rx_queues; i++)
ixgbe_clean_rx_ring(adapter, adapter->rx_ring[i]); ixgbe_clean_rx_ring(adapter->rx_ring[i]);
} }
/** /**
...@@ -3782,7 +3777,7 @@ static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) ...@@ -3782,7 +3777,7 @@ static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
int i; int i;
for (i = 0; i < adapter->num_tx_queues; i++) for (i = 0; i < adapter->num_tx_queues; i++)
ixgbe_clean_tx_ring(adapter, adapter->tx_ring[i]); ixgbe_clean_tx_ring(adapter->tx_ring[i]);
} }
void ixgbe_down(struct ixgbe_adapter *adapter) void ixgbe_down(struct ixgbe_adapter *adapter)
...@@ -4440,6 +4435,7 @@ static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter) ...@@ -4440,6 +4435,7 @@ static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter) static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
{ {
int i; int i;
int rx_count;
int orig_node = adapter->node; int orig_node = adapter->node;
for (i = 0; i < adapter->num_tx_queues; i++) { for (i = 0; i < adapter->num_tx_queues; i++) {
...@@ -4458,6 +4454,7 @@ static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter) ...@@ -4458,6 +4454,7 @@ static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
goto err_tx_ring_allocation; goto err_tx_ring_allocation;
ring->count = adapter->tx_ring_count; ring->count = adapter->tx_ring_count;
ring->queue_index = i; ring->queue_index = i;
ring->dev = &adapter->pdev->dev;
ring->numa_node = adapter->node; ring->numa_node = adapter->node;
adapter->tx_ring[i] = ring; adapter->tx_ring[i] = ring;
...@@ -4466,6 +4463,7 @@ static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter) ...@@ -4466,6 +4463,7 @@ static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
/* Restore the adapter's original node */ /* Restore the adapter's original node */
adapter->node = orig_node; adapter->node = orig_node;
rx_count = adapter->rx_ring_count;
for (i = 0; i < adapter->num_rx_queues; i++) { for (i = 0; i < adapter->num_rx_queues; i++) {
struct ixgbe_ring *ring = adapter->rx_ring[i]; struct ixgbe_ring *ring = adapter->rx_ring[i];
if (orig_node == -1) { if (orig_node == -1) {
...@@ -4480,8 +4478,9 @@ static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter) ...@@ -4480,8 +4478,9 @@ static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
ring = kzalloc(sizeof(struct ixgbe_ring), GFP_KERNEL); ring = kzalloc(sizeof(struct ixgbe_ring), GFP_KERNEL);
if (!ring) if (!ring)
goto err_rx_ring_allocation; goto err_rx_ring_allocation;
ring->count = adapter->rx_ring_count; ring->count = rx_count;
ring->queue_index = i; ring->queue_index = i;
ring->dev = &adapter->pdev->dev;
ring->numa_node = adapter->node; ring->numa_node = adapter->node;
adapter->rx_ring[i] = ring; adapter->rx_ring[i] = ring;
...@@ -4938,15 +4937,13 @@ static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter) ...@@ -4938,15 +4937,13 @@ static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
/** /**
* ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
* @adapter: board private structure
* @tx_ring: tx descriptor ring (for a specific queue) to setup * @tx_ring: tx descriptor ring (for a specific queue) to setup
* *
* Return 0 on success, negative on failure * Return 0 on success, negative on failure
**/ **/
int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter, int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
struct ixgbe_ring *tx_ring)
{ {
struct pci_dev *pdev = adapter->pdev; struct device *dev = tx_ring->dev;
int size; int size;
size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
...@@ -4961,7 +4958,7 @@ int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter, ...@@ -4961,7 +4958,7 @@ int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
tx_ring->size = ALIGN(tx_ring->size, 4096); tx_ring->size = ALIGN(tx_ring->size, 4096);
tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size, tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
&tx_ring->dma, GFP_KERNEL); &tx_ring->dma, GFP_KERNEL);
if (!tx_ring->desc) if (!tx_ring->desc)
goto err; goto err;
...@@ -4974,7 +4971,7 @@ int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter, ...@@ -4974,7 +4971,7 @@ int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
err: err:
vfree(tx_ring->tx_buffer_info); vfree(tx_ring->tx_buffer_info);
tx_ring->tx_buffer_info = NULL; tx_ring->tx_buffer_info = NULL;
e_err(probe, "Unable to allocate memory for the Tx descriptor ring\n"); dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
return -ENOMEM; return -ENOMEM;
} }
...@@ -4993,7 +4990,7 @@ static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) ...@@ -4993,7 +4990,7 @@ static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
int i, err = 0; int i, err = 0;
for (i = 0; i < adapter->num_tx_queues; i++) { for (i = 0; i < adapter->num_tx_queues; i++) {
err = ixgbe_setup_tx_resources(adapter, adapter->tx_ring[i]); err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
if (!err) if (!err)
continue; continue;
e_err(probe, "Allocation for Tx Queue %u failed\n", i); e_err(probe, "Allocation for Tx Queue %u failed\n", i);
...@@ -5005,48 +5002,41 @@ static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) ...@@ -5005,48 +5002,41 @@ static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
/** /**
* ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
* @adapter: board private structure
* @rx_ring: rx descriptor ring (for a specific queue) to setup * @rx_ring: rx descriptor ring (for a specific queue) to setup
* *
* Returns 0 on success, negative on failure * Returns 0 on success, negative on failure
**/ **/
int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter, int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
struct ixgbe_ring *rx_ring)
{ {
struct pci_dev *pdev = adapter->pdev; struct device *dev = rx_ring->dev;
int size; int size;
size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
rx_ring->rx_buffer_info = vmalloc_node(size, adapter->node); rx_ring->rx_buffer_info = vmalloc_node(size, rx_ring->numa_node);
if (!rx_ring->rx_buffer_info) if (!rx_ring->rx_buffer_info)
rx_ring->rx_buffer_info = vmalloc(size); rx_ring->rx_buffer_info = vmalloc(size);
if (!rx_ring->rx_buffer_info) { if (!rx_ring->rx_buffer_info)
e_err(probe, "vmalloc allocation failed for the Rx " goto err;
"descriptor ring\n");
goto alloc_failed;
}
memset(rx_ring->rx_buffer_info, 0, size); memset(rx_ring->rx_buffer_info, 0, size);
/* Round up to nearest 4K */ /* Round up to nearest 4K */
rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
rx_ring->size = ALIGN(rx_ring->size, 4096); rx_ring->size = ALIGN(rx_ring->size, 4096);
rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size, rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
&rx_ring->dma, GFP_KERNEL); &rx_ring->dma, GFP_KERNEL);
if (!rx_ring->desc) { if (!rx_ring->desc)
e_err(probe, "Memory allocation failed for the Rx " goto err;
"descriptor ring\n");
vfree(rx_ring->rx_buffer_info);
goto alloc_failed;
}
rx_ring->next_to_clean = 0; rx_ring->next_to_clean = 0;
rx_ring->next_to_use = 0; rx_ring->next_to_use = 0;
return 0; return 0;
err:
alloc_failed: vfree(rx_ring->rx_buffer_info);
rx_ring->rx_buffer_info = NULL;
dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
return -ENOMEM; return -ENOMEM;
} }
...@@ -5060,13 +5050,12 @@ int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter, ...@@ -5060,13 +5050,12 @@ int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
* *
* Return 0 on success, negative on failure * Return 0 on success, negative on failure
**/ **/
static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
{ {
int i, err = 0; int i, err = 0;
for (i = 0; i < adapter->num_rx_queues; i++) { for (i = 0; i < adapter->num_rx_queues; i++) {
err = ixgbe_setup_rx_resources(adapter, adapter->rx_ring[i]); err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
if (!err) if (!err)
continue; continue;
e_err(probe, "Allocation for Rx Queue %u failed\n", i); e_err(probe, "Allocation for Rx Queue %u failed\n", i);
...@@ -5078,23 +5067,23 @@ static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) ...@@ -5078,23 +5067,23 @@ static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
/** /**
* ixgbe_free_tx_resources - Free Tx Resources per Queue * ixgbe_free_tx_resources - Free Tx Resources per Queue
* @adapter: board private structure
* @tx_ring: Tx descriptor ring for a specific queue * @tx_ring: Tx descriptor ring for a specific queue
* *
* Free all transmit software resources * Free all transmit software resources
**/ **/
void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter, void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
struct ixgbe_ring *tx_ring)
{ {
struct pci_dev *pdev = adapter->pdev; ixgbe_clean_tx_ring(tx_ring);
ixgbe_clean_tx_ring(adapter, tx_ring);
vfree(tx_ring->tx_buffer_info); vfree(tx_ring->tx_buffer_info);
tx_ring->tx_buffer_info = NULL; tx_ring->tx_buffer_info = NULL;
dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc, /* if not set, then don't free */
tx_ring->dma); if (!tx_ring->desc)
return;
dma_free_coherent(tx_ring->dev, tx_ring->size,
tx_ring->desc, tx_ring->dma);
tx_ring->desc = NULL; tx_ring->desc = NULL;
} }
...@@ -5111,28 +5100,28 @@ static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) ...@@ -5111,28 +5100,28 @@ static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
for (i = 0; i < adapter->num_tx_queues; i++) for (i = 0; i < adapter->num_tx_queues; i++)
if (adapter->tx_ring[i]->desc) if (adapter->tx_ring[i]->desc)
ixgbe_free_tx_resources(adapter, adapter->tx_ring[i]); ixgbe_free_tx_resources(adapter->tx_ring[i]);
} }
/** /**
* ixgbe_free_rx_resources - Free Rx Resources * ixgbe_free_rx_resources - Free Rx Resources
* @adapter: board private structure
* @rx_ring: ring to clean the resources from * @rx_ring: ring to clean the resources from
* *
* Free all receive software resources * Free all receive software resources
**/ **/
void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter, void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
struct ixgbe_ring *rx_ring)
{ {
struct pci_dev *pdev = adapter->pdev; ixgbe_clean_rx_ring(rx_ring);
ixgbe_clean_rx_ring(adapter, rx_ring);
vfree(rx_ring->rx_buffer_info); vfree(rx_ring->rx_buffer_info);
rx_ring->rx_buffer_info = NULL; rx_ring->rx_buffer_info = NULL;
dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc, /* if not set, then don't free */
rx_ring->dma); if (!rx_ring->desc)
return;
dma_free_coherent(rx_ring->dev, rx_ring->size,
rx_ring->desc, rx_ring->dma);
rx_ring->desc = NULL; rx_ring->desc = NULL;
} }
...@@ -5149,7 +5138,7 @@ static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) ...@@ -5149,7 +5138,7 @@ static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
for (i = 0; i < adapter->num_rx_queues; i++) for (i = 0; i < adapter->num_rx_queues; i++)
if (adapter->rx_ring[i]->desc) if (adapter->rx_ring[i]->desc)
ixgbe_free_rx_resources(adapter, adapter->rx_ring[i]); ixgbe_free_rx_resources(adapter->rx_ring[i]);
} }
/** /**
...@@ -5985,7 +5974,7 @@ static int ixgbe_tx_map(struct ixgbe_adapter *adapter, ...@@ -5985,7 +5974,7 @@ static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
struct sk_buff *skb, u32 tx_flags, struct sk_buff *skb, u32 tx_flags,
unsigned int first, const u8 hdr_len) unsigned int first, const u8 hdr_len)
{ {
struct pci_dev *pdev = adapter->pdev; struct device *dev = tx_ring->dev;
struct ixgbe_tx_buffer *tx_buffer_info; struct ixgbe_tx_buffer *tx_buffer_info;
unsigned int len; unsigned int len;
unsigned int total = skb->len; unsigned int total = skb->len;
...@@ -6008,10 +5997,10 @@ static int ixgbe_tx_map(struct ixgbe_adapter *adapter, ...@@ -6008,10 +5997,10 @@ static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
tx_buffer_info->length = size; tx_buffer_info->length = size;
tx_buffer_info->mapped_as_page = false; tx_buffer_info->mapped_as_page = false;
tx_buffer_info->dma = dma_map_single(&pdev->dev, tx_buffer_info->dma = dma_map_single(dev,
skb->data + offset, skb->data + offset,
size, DMA_TO_DEVICE); size, DMA_TO_DEVICE);
if (dma_mapping_error(&pdev->dev, tx_buffer_info->dma)) if (dma_mapping_error(dev, tx_buffer_info->dma))
goto dma_error; goto dma_error;
tx_buffer_info->time_stamp = jiffies; tx_buffer_info->time_stamp = jiffies;
tx_buffer_info->next_to_watch = i; tx_buffer_info->next_to_watch = i;
...@@ -6044,12 +6033,12 @@ static int ixgbe_tx_map(struct ixgbe_adapter *adapter, ...@@ -6044,12 +6033,12 @@ static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
tx_buffer_info->length = size; tx_buffer_info->length = size;
tx_buffer_info->dma = dma_map_page(&adapter->pdev->dev, tx_buffer_info->dma = dma_map_page(dev,
frag->page, frag->page,
offset, size, offset, size,
DMA_TO_DEVICE); DMA_TO_DEVICE);
tx_buffer_info->mapped_as_page = true; tx_buffer_info->mapped_as_page = true;
if (dma_mapping_error(&pdev->dev, tx_buffer_info->dma)) if (dma_mapping_error(dev, tx_buffer_info->dma))
goto dma_error; goto dma_error;
tx_buffer_info->time_stamp = jiffies; tx_buffer_info->time_stamp = jiffies;
tx_buffer_info->next_to_watch = i; tx_buffer_info->next_to_watch = i;
...@@ -6097,7 +6086,7 @@ static int ixgbe_tx_map(struct ixgbe_adapter *adapter, ...@@ -6097,7 +6086,7 @@ static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
i += tx_ring->count; i += tx_ring->count;
i--; i--;
tx_buffer_info = &tx_ring->tx_buffer_info[i]; tx_buffer_info = &tx_ring->tx_buffer_info[i];
ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info); ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
} }
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册