qlcnic: bug fixes
Subsystems (2)
cover qlcnic: bug fixes
Hi
Series of 4 bug fixes. Apply them on net-2.6 branch.
-Amit
PATCH 1/1 qlcnic: fix mac learning
In failover bonding case, same mac address can be programmed on other slave function. Fw will delete old entry (original func) associated with that mac address. Need to reporgram mac address, if failover again happen to original function.
--- drivers/net/qlcnic/qlcnic.h | 1 + drivers/net/qlcnic/qlcnic_main.c | 5 +++++ 2 files changed, 6 insertions(+), 0 deletions(-)
drivers/net/qlcnic/qlcnic.h +1 -0
@@ -942,6 +942,7 @@ struct qlcnic_ipaddr {#define QLCNIC_LOOPBACK_TEST 2#define QLCNIC_FILTER_AGE 80 +#define QLCNIC_READD_AGE 20#define QLCNIC_LB_MAX_FILTERS 64struct qlcnic_filter {
drivers/net/qlcnic/qlcnic_main.c +5 -0
@@ -1860,6 +1860,11 @@ qlcnic_send_filter(struct qlcnic_adapter *adapter,hlist_for_each_entry_safe (tmp_fil, tmp_hnode, n, head, fnode) {if (!memcmp (tmp_fil->faddr, &src_addr,ETH_ALEN ) && tmp_fil->vlan_id == vlan_id) { + +if (jiffies > + (QLCNIC_READD_AGE *HZ + tmp_fil->ftime)) +qlcnic_change_filter (adapter, src_addr, vlan_id, + tx_ring); tmp_fil->ftime = jiffies;return ; }
Signature · 1 line
1.6.0.2
PATCH 1/1 qlcnic: reduce RX ring size for nic partition
In reply to Amit Kumar SalechaFrom: Sony Chacko <[email protected]>
For NIC Partition adapter, rcv ring size can be reduce, as physical port is partition-ed.
--- drivers/net/qlcnic/qlcnic.h | 4 ++++ drivers/net/qlcnic/qlcnic_ethtool.c | 23 +++++------------------ drivers/net/qlcnic/qlcnic_main.c | 14 ++++++++++++-- 3 files changed, 21 insertions(+), 20 deletions(-)
drivers/net/qlcnic/qlcnic.h +4 -0
@@ -146,11 +146,13 @@#define MAX_CMD_DESCRIPTORS 1024#define MAX_RCV_DESCRIPTORS_1G 4096#define MAX_RCV_DESCRIPTORS_10G 8192 +#define MAX_RCV_DESCRIPTORS_VF 2048#define MAX_JUMBO_RCV_DESCRIPTORS_1G 512#define MAX_JUMBO_RCV_DESCRIPTORS_10G 1024#define DEFAULT_RCV_DESCRIPTORS_1G 2048#define DEFAULT_RCV_DESCRIPTORS_10G 4096 +#define DEFAULT_RCV_DESCRIPTORS_VF 1024#define MAX_RDS_RINGS 2#define get_next_index (index, length) \
@@ -971,6 +973,8 @@ struct qlcnic_adapter {u16 num_txd;u16 num_rxd;u16 num_jumbo_rxd; +u16 max_rxd; +u16 max_jumbo_rxd;u8 max_rds_rings;u8 max_sds_rings;
drivers/net/qlcnic/qlcnic_ethtool.c +5 -18
@@ -437,14 +437,8 @@ qlcnic_get_ringparam(struct net_device *dev, ring->rx_jumbo_pending = adapter->num_jumbo_rxd; ring->tx_pending = adapter->num_txd; -if (adapter->ahw.port_type ==QLCNIC_GBE ) { - ring->rx_max_pending =MAX_RCV_DESCRIPTORS_1G ; - ring->rx_jumbo_max_pending =MAX_JUMBO_RCV_DESCRIPTORS_1G ; - }else { - ring->rx_max_pending =MAX_RCV_DESCRIPTORS_10G ; - ring->rx_jumbo_max_pending =MAX_JUMBO_RCV_DESCRIPTORS_10G ; - } - + ring->rx_max_pending = adapter->max_rxd; + ring->rx_jumbo_max_pending = adapter->max_jumbo_rxd; ring->tx_max_pending =MAX_CMD_DESCRIPTORS ; ring->rx_mini_max_pending =0 ;
@@ -472,24 +466,17 @@ qlcnic_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ring) {struct qlcnic_adapter *adapter =netdev_priv (dev); -u16 max_rcv_desc =MAX_RCV_DESCRIPTORS_10G ; -u16 max_jumbo_desc =MAX_JUMBO_RCV_DESCRIPTORS_10G ;u16 num_rxd, num_jumbo_rxd, num_txd; -if (ring->rx_mini_pending)return -EOPNOTSUPP ; -if (adapter->ahw.port_type ==QLCNIC_GBE ) { - max_rcv_desc =MAX_RCV_DESCRIPTORS_1G ; - max_jumbo_desc =MAX_JUMBO_RCV_DESCRIPTORS_10G ; - } - num_rxd =qlcnic_validate_ringparam (ring->rx_pending, -MIN_RCV_DESCRIPTORS , max_rcv_desc,"rx" ); +MIN_RCV_DESCRIPTORS , adapter->max_rxd,"rx" ); num_jumbo_rxd =qlcnic_validate_ringparam (ring->rx_jumbo_pending, -MIN_JUMBO_DESCRIPTORS , max_jumbo_desc,"rx jumbo" ); +MIN_JUMBO_DESCRIPTORS , adapter->max_jumbo_rxd, +"rx jumbo" ); num_txd =qlcnic_validate_ringparam (ring->tx_pending,MIN_CMD_DESCRIPTORS ,MAX_CMD_DESCRIPTORS ,"tx" );
drivers/net/qlcnic/qlcnic_main.c +12 -2
@@ -656,13 +656,23 @@ qlcnic_check_options(struct qlcnic_adapter *adapter)dev_info (&pdev->dev,"firmware v%d.%d.%d\n" , fw_major, fw_minor, fw_build); -if (adapter->ahw.port_type ==QLCNIC_XGBE ) { - adapter->num_rxd =DEFAULT_RCV_DESCRIPTORS_10G ; +if (adapter->flags &QLCNIC_ESWITCH_ENABLED ) { + adapter->num_rxd =DEFAULT_RCV_DESCRIPTORS_VF ; + adapter->max_rxd =MAX_RCV_DESCRIPTORS_VF ; + }else { + adapter->num_rxd =DEFAULT_RCV_DESCRIPTORS_10G ; + adapter->max_rxd =MAX_RCV_DESCRIPTORS_10G ; + } + adapter->num_jumbo_rxd =MAX_JUMBO_RCV_DESCRIPTORS_10G ; + adapter->max_jumbo_rxd =MAX_JUMBO_RCV_DESCRIPTORS_10G ; + }else if (adapter->ahw.port_type ==QLCNIC_GBE ) { adapter->num_rxd =DEFAULT_RCV_DESCRIPTORS_1G ; adapter->num_jumbo_rxd =MAX_JUMBO_RCV_DESCRIPTORS_1G ; + adapter->max_jumbo_rxd =MAX_JUMBO_RCV_DESCRIPTORS_1G ; + adapter->max_rxd =MAX_RCV_DESCRIPTORS_1G ; } adapter->msix_supported = !!use_msi_x;
Signature · 1 line
1.6.0.2
PATCH 1/1 qlcnic: define valid vlan id range
In reply to Amit Kumar SalechaFrom: Sony Chacko <[email protected]>
4095 vlan id is reserved and should not be use.
--- drivers/net/qlcnic/qlcnic.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/qlcnic/qlcnic.h +1 -1
@@ -1134,7 +1134,7 @@ struct qlcnic_eswitch {#define MAX_RX_QUEUES 4#define DEFAULT_MAC_LEARN 1 -#define IS_VALID_VLAN (vlan) (vlan >= MIN_VLAN_ID && vlan <= MAX_VLAN_ID) +#define IS_VALID_VLAN (vlan) (vlan >= MIN_VLAN_ID && vlan < MAX_VLAN_ID)#define IS_VALID_BW (bw) (bw >= MIN_BW && bw <= MAX_BW)#define IS_VALID_TX_QUEUES (que) (que > 0 && que <= MAX_TX_QUEUES)#define IS_VALID_RX_QUEUES (que) (que > 0 && que <= MAX_RX_QUEUES)
Signature · 1 line
1.6.0.2
PATCH 1/1 qlcnic: dma address align check
In reply to Amit Kumar SalechaDevice requires tx_hw_cosnumer to be 64 byte aligned. Tx desc size is 64 byte, alloc tx_hw_consumer with tx desc.
--- drivers/net/qlcnic/qlcnic_ctx.c | 35 +++++++++++++++-------------------- 1 files changed, 15 insertions(+), 20 deletions(-)
drivers/net/qlcnic/qlcnic_ctx.c +15 -20
@@ -418,18 +418,9 @@ int qlcnic_alloc_hw_resources(struct qlcnic_adapter *adapter) recv_ctx = &adapter->recv_ctx; tx_ring = adapter->tx_ring; - tx_ring->hw_consumer = (__le32 *)pci_alloc_consistent (pdev,sizeof (u32), - &tx_ring->hw_cons_phys_addr); -if (tx_ring->hw_consumer ==NULL ) { -dev_err (&pdev->dev,"failed to allocate tx consumer\n" ); -return -ENOMEM ; - } - *(tx_ring->hw_consumer) =0 ; -/* cmd desc ring */ - addr =pci_alloc_consistent (pdev,TX_DESC_RINGSIZE (tx_ring), - &tx_ring->phys_addr); - + addr =pci_alloc_consistent (pdev,TX_DESC_RINGSIZE (tx_ring) + +sizeof (u32), &tx_ring->phys_addr);if (addr ==NULL ) {dev_err (&pdev->dev,"failed to allocate tx desc ring\n" ); err = -ENOMEM ;
@@ -437,6 +428,17 @@ int qlcnic_alloc_hw_resources(struct qlcnic_adapter *adapter) } tx_ring->desc_head = (struct cmd_desc_type0 *)addr; + tx_ring->hw_consumer = (__le32 *)(((char *)addr) + +TX_DESC_RINGSIZE (tx_ring)); + tx_ring->hw_cons_phys_addr = (dma_addr_t)(((char *)tx_ring->phys_addr) + +TX_DESC_RINGSIZE (tx_ring)); +if (tx_ring->hw_cons_phys_addr &0x3F ) { +dev_err (&pdev->dev,"Device requires 64 byte aligned dma addr" +". dma_addr=%p\n" , (void *)tx_ring->hw_cons_phys_addr); + err = -ENOMEM ; + goto err_out_free; + } + *(tx_ring->hw_consumer) =0 ;for (ring =0 ; ring < adapter->max_rds_rings; ring++) { rds_ring = &recv_ctx->rds_rings[ring];
@@ -516,19 +518,12 @@ void qlcnic_free_hw_resources(struct qlcnic_adapter *adapter) recv_ctx = &adapter->recv_ctx; tx_ring = adapter->tx_ring; -if (tx_ring->hw_consumer !=NULL ) { -pci_free_consistent (adapter->pdev, -sizeof (u32), - tx_ring->hw_consumer, - tx_ring->hw_cons_phys_addr); - tx_ring->hw_consumer =NULL ; - } -if (tx_ring->desc_head !=NULL ) {pci_free_consistent (adapter->pdev, -TX_DESC_RINGSIZE (tx_ring), +TX_DESC_RINGSIZE (tx_ring) +sizeof (u32), tx_ring->desc_head, tx_ring->phys_addr); tx_ring->desc_head =NULL ; + tx_ring->hw_consumer =NULL ; }for (ring =0 ; ring < adapter->max_rds_rings; ring++) {
Signature · 1 line
1.6.0.2
Re: [PATCH] qlcnic: dma address align check
Quoted 20 lines · Amit Kumar Salecha
Device requires
tx_hw_cosnumerto be 64 byte aligned. Tx desc size is 64 byte, alloctx_hw_consumerwith tx desc.Signed-off-by Amit Kumar Salecha <[email protected]>--- drivers/net/qlcnic/qlcnic_ctx.c | 35 +++++++++++++++-------------------- 1 files changed, 15 insertions(+), 20 deletions(-)drivers/net/qlcnic/qlcnic_ctx.c +0
-4@@ -418,18 +418,9 @@ int qlcnic_alloc_hw_resources(struct qlcnic_adapter *adapter) recv_ctx = &adapter->recv_ctx; tx_ring = adapter->tx_ring; - tx_ring->hw_consumer = (__le32 *)pci_alloc_consistent (pdev,sizeof (u32), - &tx_ring->hw_cons_phys_addr); -if (tx_ring->hw_consumer ==NULL ) { -dev_err (&pdev->dev,"failed to allocate tx consumer\n" );
drivers/net/qlcnic/qlcnic_ctx.c int qlcnic_alloc_hw_resources(struct qlcnic_adapter *adapter) · line 423
Quoted 10 lines
drivers/net/qlcnic/qlcnic_ctx.c +2
-7-return -ENOMEM ; - } - *(tx_ring->hw_consumer) =0 ; -/* cmd desc ring */ - addr =pci_alloc_consistent (pdev,TX_DESC_RINGSIZE (tx_ring), - &tx_ring->phys_addr); - + addr =pci_alloc_consistent (pdev,TX_DESC_RINGSIZE (tx_ring) + +sizeof (u32), &tx_ring->phys_addr);
Wont this use twice memory than before, due to power-of-two allocations ?
Allocating 65536 + 4 bytes gives you 131072 bytes.
RE: [PATCH] qlcnic: dma address align check
Quoted 49 lines
-----Original Message-----
From: Eric Dumazet [mailto:[email protected]]
Sent: Tuesday, October 26, 2010 3:25 PM
To: Amit Salecha
Cc: [email protected]; [email protected]; Ameen Rahman; Anirban Chakraborty
Subject: Re: [PATCH] qlcnic: dma address align checkQuoted 6 lines · Amit Kumar Salecha
Device requires
tx_hw_cosnumerto be 64 byte aligned. Tx desc size is 64 byte, alloctx_hw_consumerwith tx desc.Signed-off-by Amit Kumar Salecha <[email protected]>--- drivers/net/qlcnic/qlcnic_ctx.c | 35 +++++++++++++++--------------------
Review
Quoted 3 lines
1 files changed, 15 insertions(+), 20 deletions(-)(quoted diff) +0
-0
b/drivers/net/qlcnic/qlcnic_ctx.cdrivers/net/qlcnic/qlcnic_ctx.c int qlcnic_alloc_hw_resources(struct
Quoted 4 lines
index 1cdc05d..21c9c28 100644
drivers/net/qlcnic/qlcnic_ctx.c +0
-0@@ -418,18 +418,9 @@ int qlcnic_alloc_hw_resources(struct
qlcnic_adapter*adapter)drivers/net/qlcnic/qlcnic_ctx.c int qlcnic_alloc_hw_resources(struct qlcnic_adapter *adapter)
Quoted 4 lines
drivers/net/qlcnic/qlcnic_ctx.c +0
-1recv_ctx = &adapter->recv_ctx; tx_ring = adapter->tx_ring; - tx_ring->hw_consumer = (__le32 *)pci_alloc_consistent(pdev,sizeof(u32),
drivers/net/qlcnic/qlcnic_ctx.c int qlcnic_alloc_hw_resources(struct qlcnic_adapter *adapter) · line 423
Quoted 13 lines
drivers/net/qlcnic/qlcnic_ctx.c +2
-10- &tx_ring->hw_cons_phys_addr); -if (tx_ring->hw_consumer ==NULL ) { -dev_err (&pdev->dev,"failed to allocate tx consumer\n" ); -return -ENOMEM ; - } - *(tx_ring->hw_consumer) =0 ; -/* cmd desc ring */ - addr =pci_alloc_consistent (pdev,TX_DESC_RINGSIZE (tx_ring), - &tx_ring->phys_addr); - + addr =pci_alloc_consistent (pdev,TX_DESC_RINGSIZE (tx_ring) + +sizeof (u32), &tx_ring->phys_addr);Wont this use twice memory than before, due to power-of-two allocations ?
Quoted 2 lines
Allocating 65536 + 4 bytes gives you 131072 bytes.
Is it ? I am not aware about such calculation.
Is pci_alloc_consistent guarantee to give PAGE align dma address ?
-Amit
RE: [PATCH] qlcnic: dma address align check
Quoted 1 line · Amit Salecha
Is it ? I am not aware about such calculation.
Yes it is
Quoted 1 line
Is
pci_alloc_consistentguarantee to give PAGE align dma address ?
I believe so
By the way, you should use dma_alloc_coherent() instead of pci_alloc_consistent() so that you can use GFP_KERNEL allocations instead of GFP_ATOMIC, it might help in low memory conditions (if you dont hold a spinlock at this point)
If TX_DESC_RINGSIZE(tx_ring) is not a power of two, then yes you could probably add 64 bytes and avoid allocating a full page only for the u32 field ;)
RE: [PATCH] qlcnic: dma address align check
Quoted 10 lines
Quoted 1 line
Is
pci_alloc_consistentguarantee to give PAGE align dma address ?I believe so
By the way, you should use
dma_alloc_coherent()instead ofpci_alloc_consistent()so that you can useGFP_KERNELallocations instead ofGFP_ATOMIC, it might help in low memory conditions (if you dont hold a spinlock at this point)
Quoted 5 lines
If
TX_DESC_RINGSIZE(tx_ring)is not a power of two, then yes you could probably add 64 bytes and avoid allocating a full page only for the u32 field ;)
TX_DESC_RINGSIZE is power of two.
If pci_alloc_consistent guarantee to give PAGE align dma address, then this patch is not required.
Quoted 1 line
PATCH 1/1 tg3: use dma_alloc_coherent() instead of pci_alloc_consistent()
In reply to Eric DumazetQuoted 5 lines · Eric Dumazet
By the way, you should use
dma_alloc_coherent()instead ofpci_alloc_consistent()so that you can useGFP_KERNELallocations instead ofGFP_ATOMIC, it might help in low memory conditions (if you dont hold a spinlock at this point)
tg3 being often used as a reference network driver, I believe we should change its allocations before too many people copy paste suboptimal pci_alloc_consistent() stuff...
Matt, could you please queue this patch and submit it to David when net-next-2.6 reopens ?
Thanks
[PATCH] tg3: use dma_alloc_coherent() instead of pci_alloc_consistent()
Using dma_alloc_coherent() permits to use GFP_KERNEL allocations instead of GFP_ATOMIC ones. Its better when a machine is out of memory, because this allows driver to sleep to get its memory and succeed its init, especially when allocating high order pages.
--- drivers/net/tg3.c | 73 ++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 32 deletions(-)
drivers/net/tg3.c +41 -32
@@ -6339,13 +6339,13 @@ static void tg3_rx_prodring_fini(struct tg3 *tp,kfree (tpr->rx_jmb_buffers); tpr->rx_jmb_buffers =NULL ;if (tpr->rx_std) { -pci_free_consistent (tp->pdev,TG3_RX_STD_RING_BYTES (tp), - tpr->rx_std, tpr->rx_std_mapping); +dma_free_coherent (&tp->pdev->dev,TG3_RX_STD_RING_BYTES (tp), + tpr->rx_std, tpr->rx_std_mapping); tpr->rx_std =NULL ; }if (tpr->rx_jmb) { -pci_free_consistent (tp->pdev,TG3_RX_JMB_RING_BYTES (tp), - tpr->rx_jmb, tpr->rx_jmb_mapping); +dma_free_coherent (&tp->pdev->dev,TG3_RX_JMB_RING_BYTES (tp), + tpr->rx_jmb, tpr->rx_jmb_mapping); tpr->rx_jmb =NULL ; } }
@@ -6358,8 +6358,10 @@ static int tg3_rx_prodring_init(struct tg3 *tp,if (!tpr->rx_std_buffers)return -ENOMEM ; - tpr->rx_std =pci_alloc_consistent (tp->pdev,TG3_RX_STD_RING_BYTES (tp), - &tpr->rx_std_mapping); + tpr->rx_std =dma_alloc_coherent (&tp->pdev->dev, +TG3_RX_STD_RING_BYTES (tp), + &tpr->rx_std_mapping, +GFP_KERNEL );if (!tpr->rx_std) goto err_out;
@@ -6370,9 +6372,10 @@ static int tg3_rx_prodring_init(struct tg3 *tp,if (!tpr->rx_jmb_buffers) goto err_out; - tpr->rx_jmb =pci_alloc_consistent (tp->pdev, -TG3_RX_JMB_RING_BYTES (tp), - &tpr->rx_jmb_mapping); + tpr->rx_jmb =dma_alloc_coherent (&tp->pdev->dev, +TG3_RX_JMB_RING_BYTES (tp), + &tpr->rx_jmb_mapping, +GFP_KERNEL );if (!tpr->rx_jmb) goto err_out; }
@@ -6491,7 +6494,7 @@ static void tg3_free_consistent(struct tg3 *tp)struct tg3_napi *tnapi = &tp->napi[i];if (tnapi->tx_ring) { -pci_free_consistent (tp->pdev,TG3_TX_RING_BYTES , +dma_free_coherent (&tp->pdev->dev,TG3_TX_RING_BYTES , tnapi->tx_ring, tnapi->tx_desc_mapping); tnapi->tx_ring =NULL ; }
@@ -6500,25 +6503,26 @@ static void tg3_free_consistent(struct tg3 *tp) tnapi->tx_buffers =NULL ;if (tnapi->rx_rcb) { -pci_free_consistent (tp->pdev,TG3_RX_RCB_RING_BYTES (tp), - tnapi->rx_rcb, - tnapi->rx_rcb_mapping); +dma_free_coherent (&tp->pdev->dev, +TG3_RX_RCB_RING_BYTES (tp), + tnapi->rx_rcb, + tnapi->rx_rcb_mapping); tnapi->rx_rcb =NULL ; }tg3_rx_prodring_fini (tp, &tnapi->prodring);if (tnapi->hw_status) { -pci_free_consistent (tp->pdev,TG3_HW_STATUS_SIZE , - tnapi->hw_status, - tnapi->status_mapping); +dma_free_coherent (&tp->pdev->dev,TG3_HW_STATUS_SIZE , + tnapi->hw_status, + tnapi->status_mapping); tnapi->hw_status =NULL ; } }if (tp->hw_stats) { -pci_free_consistent (tp->pdev,sizeof (struct tg3_hw_stats ), - tp->hw_stats, tp->stats_mapping); +dma_free_coherent (&tp->pdev->dev,sizeof (struct tg3_hw_stats ), + tp->hw_stats, tp->stats_mapping); tp->hw_stats =NULL ; } }
@@ -6531,9 +6535,10 @@ static int tg3_alloc_consistent(struct tg3 *tp) {int i; - tp->hw_stats =pci_alloc_consistent (tp->pdev, -sizeof (struct tg3_hw_stats ), - &tp->stats_mapping); + tp->hw_stats =dma_alloc_coherent (&tp->pdev->dev, +sizeof (struct tg3_hw_stats ), + &tp->stats_mapping, +GFP_KERNEL );if (!tp->hw_stats) goto err_out;
@@ -6543,9 +6548,10 @@ static int tg3_alloc_consistent(struct tg3 *tp)struct tg3_napi *tnapi = &tp->napi[i];struct tg3_hw_status *sblk; - tnapi->hw_status =pci_alloc_consistent (tp->pdev, -TG3_HW_STATUS_SIZE , - &tnapi->status_mapping); + tnapi->hw_status =dma_alloc_coherent (&tp->pdev->dev, +TG3_HW_STATUS_SIZE , + &tnapi->status_mapping, +GFP_KERNEL );if (!tnapi->hw_status) goto err_out;
@@ -6566,9 +6572,10 @@ static int tg3_alloc_consistent(struct tg3 *tp)if (!tnapi->tx_buffers) goto err_out; - tnapi->tx_ring =pci_alloc_consistent (tp->pdev, -TG3_TX_RING_BYTES , - &tnapi->tx_desc_mapping); + tnapi->tx_ring =dma_alloc_coherent (&tp->pdev->dev, +TG3_TX_RING_BYTES , + &tnapi->tx_desc_mapping, +GFP_KERNEL );if (!tnapi->tx_ring) goto err_out; }
@@ -6601,9 +6608,10 @@ static int tg3_alloc_consistent(struct tg3 *tp)if (!i && (tp->tg3_flags3 &TG3_FLG3_ENABLE_RSS ))continue ; - tnapi->rx_rcb =pci_alloc_consistent (tp->pdev, -TG3_RX_RCB_RING_BYTES (tp), - &tnapi->rx_rcb_mapping); + tnapi->rx_rcb =dma_alloc_coherent (&tp->pdev->dev, +TG3_RX_RCB_RING_BYTES (tp), + &tnapi->rx_rcb_mapping, +GFP_KERNEL );if (!tnapi->rx_rcb) goto err_out;
@@ -14159,7 +14167,8 @@ static int __devinit tg3_test_dma(struct tg3 *tp)u32 *buf, saved_dma_rwctrl;int ret =0 ; - buf =pci_alloc_consistent (tp->pdev,TEST_BUFFER_SIZE , &buf_dma); + buf =dma_alloc_coherent (&tp->pdev->dev,TEST_BUFFER_SIZE , + &buf_dma,GFP_KERNEL );if (!buf) { ret = -ENOMEM ; goto out_nofree;
@@ -14343,7 +14352,7 @@ static int __devinit tg3_test_dma(struct tg3 *tp) } out: -pci_free_consistent (tp->pdev,TEST_BUFFER_SIZE , buf, buf_dma); +dma_free_coherent (&tp->pdev->dev,TEST_BUFFER_SIZE , buf, buf_dma); out_nofree:return ret; }
Re: [PATCH net-next-2.6] tg3: use dma_alloc_coherent() instead of pci_alloc_consistent()
Quoted 8 lines · Eric Dumazet
Le mardi 26 octobre 2010 ?? 12:30 +0200, Eric Dumazet a ??crit :
Quoted 5 lines
By the way, you should use
dma_alloc_coherent()instead ofpci_alloc_consistent()so that you can useGFP_KERNELallocations instead ofGFP_ATOMIC, it might help in low memory conditions (if you dont hold a spinlock at this point)
Quoted 6 lines
tg3 being often used as a reference network driver, I believe we should change its allocations before too many people copy paste suboptimal
pci_alloc_consistent()stuff...Matt, could you please queue this patch and submit it to David when net-next-2.6 reopens ?
Sure. Thanks for the patch.
Quoted 187 lines
Thanks
[PATCH] tg3: use
dma_alloc_coherent()instead ofpci_alloc_consistent()Using
dma_alloc_coherent()permits to useGFP_KERNELallocations instead ofGFP_ATOMICones. Its better when a machine is out of memory, because this allows driver to sleep to get its memory and succeed its init, especially when allocating high order pages.Signed-off-by Eric Dumazet <[email protected]>CC Matt Carlson <[email protected]>CC Michael Chan <[email protected]>--- drivers/net/tg3.c | 73 ++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 32 deletions(-)drivers/net/tg3.c +41
-32@@ -6339,13 +6339,13 @@ static void tg3_rx_prodring_fini(struct tg3 *tp,kfree (tpr->rx_jmb_buffers); tpr->rx_jmb_buffers =NULL ;if (tpr->rx_std) { -pci_free_consistent (tp->pdev,TG3_RX_STD_RING_BYTES (tp), - tpr->rx_std, tpr->rx_std_mapping); +dma_free_coherent (&tp->pdev->dev,TG3_RX_STD_RING_BYTES (tp), + tpr->rx_std, tpr->rx_std_mapping); tpr->rx_std =NULL ; }if (tpr->rx_jmb) { -pci_free_consistent (tp->pdev,TG3_RX_JMB_RING_BYTES (tp), - tpr->rx_jmb, tpr->rx_jmb_mapping); +dma_free_coherent (&tp->pdev->dev,TG3_RX_JMB_RING_BYTES (tp), + tpr->rx_jmb, tpr->rx_jmb_mapping); tpr->rx_jmb =NULL ; } }@@ -6358,8 +6358,10 @@ static int tg3_rx_prodring_init(struct tg3 *tp,if (!tpr->rx_std_buffers)return -ENOMEM ; - tpr->rx_std =pci_alloc_consistent (tp->pdev,TG3_RX_STD_RING_BYTES (tp), - &tpr->rx_std_mapping); + tpr->rx_std =dma_alloc_coherent (&tp->pdev->dev, +TG3_RX_STD_RING_BYTES (tp), + &tpr->rx_std_mapping, +GFP_KERNEL );if (!tpr->rx_std) goto err_out;@@ -6370,9 +6372,10 @@ static int tg3_rx_prodring_init(struct tg3 *tp,if (!tpr->rx_jmb_buffers) goto err_out; - tpr->rx_jmb =pci_alloc_consistent (tp->pdev, -TG3_RX_JMB_RING_BYTES (tp), - &tpr->rx_jmb_mapping); + tpr->rx_jmb =dma_alloc_coherent (&tp->pdev->dev, +TG3_RX_JMB_RING_BYTES (tp), + &tpr->rx_jmb_mapping, +GFP_KERNEL );if (!tpr->rx_jmb) goto err_out; }@@ -6491,7 +6494,7 @@ static void tg3_free_consistent(struct tg3 *tp)struct tg3_napi *tnapi = &tp->napi[i];if (tnapi->tx_ring) { -pci_free_consistent (tp->pdev,TG3_TX_RING_BYTES , +dma_free_coherent (&tp->pdev->dev,TG3_TX_RING_BYTES , tnapi->tx_ring, tnapi->tx_desc_mapping); tnapi->tx_ring =NULL ; }@@ -6500,25 +6503,26 @@ static void tg3_free_consistent(struct tg3 *tp) tnapi->tx_buffers =NULL ;if (tnapi->rx_rcb) { -pci_free_consistent (tp->pdev,TG3_RX_RCB_RING_BYTES (tp), - tnapi->rx_rcb, - tnapi->rx_rcb_mapping); +dma_free_coherent (&tp->pdev->dev, +TG3_RX_RCB_RING_BYTES (tp), + tnapi->rx_rcb, + tnapi->rx_rcb_mapping); tnapi->rx_rcb =NULL ; }tg3_rx_prodring_fini (tp, &tnapi->prodring);if (tnapi->hw_status) { -pci_free_consistent (tp->pdev,TG3_HW_STATUS_SIZE , - tnapi->hw_status, - tnapi->status_mapping); +dma_free_coherent (&tp->pdev->dev,TG3_HW_STATUS_SIZE , + tnapi->hw_status, + tnapi->status_mapping); tnapi->hw_status =NULL ; } }if (tp->hw_stats) { -pci_free_consistent (tp->pdev,sizeof (struct tg3_hw_stats ), - tp->hw_stats, tp->stats_mapping); +dma_free_coherent (&tp->pdev->dev,sizeof (struct tg3_hw_stats ), + tp->hw_stats, tp->stats_mapping); tp->hw_stats =NULL ; } }@@ -6531,9 +6535,10 @@ static int tg3_alloc_consistent(struct tg3 *tp) {int i; - tp->hw_stats =pci_alloc_consistent (tp->pdev, -sizeof (struct tg3_hw_stats ), - &tp->stats_mapping); + tp->hw_stats =dma_alloc_coherent (&tp->pdev->dev, +sizeof (struct tg3_hw_stats ), + &tp->stats_mapping, +GFP_KERNEL );if (!tp->hw_stats) goto err_out;@@ -6543,9 +6548,10 @@ static int tg3_alloc_consistent(struct tg3 *tp)struct tg3_napi *tnapi = &tp->napi[i];struct tg3_hw_status *sblk; - tnapi->hw_status =pci_alloc_consistent (tp->pdev, -TG3_HW_STATUS_SIZE , - &tnapi->status_mapping); + tnapi->hw_status =dma_alloc_coherent (&tp->pdev->dev, +TG3_HW_STATUS_SIZE , + &tnapi->status_mapping, +GFP_KERNEL );if (!tnapi->hw_status) goto err_out;@@ -6566,9 +6572,10 @@ static int tg3_alloc_consistent(struct tg3 *tp)if (!tnapi->tx_buffers) goto err_out; - tnapi->tx_ring =pci_alloc_consistent (tp->pdev, -TG3_TX_RING_BYTES , - &tnapi->tx_desc_mapping); + tnapi->tx_ring =dma_alloc_coherent (&tp->pdev->dev, +TG3_TX_RING_BYTES , + &tnapi->tx_desc_mapping, +GFP_KERNEL );if (!tnapi->tx_ring) goto err_out; }@@ -6601,9 +6608,10 @@ static int tg3_alloc_consistent(struct tg3 *tp)if (!i && (tp->tg3_flags3 &TG3_FLG3_ENABLE_RSS ))continue ; - tnapi->rx_rcb =pci_alloc_consistent (tp->pdev, -TG3_RX_RCB_RING_BYTES (tp), - &tnapi->rx_rcb_mapping); + tnapi->rx_rcb =dma_alloc_coherent (&tp->pdev->dev, +TG3_RX_RCB_RING_BYTES (tp), + &tnapi->rx_rcb_mapping, +GFP_KERNEL );if (!tnapi->rx_rcb) goto err_out;@@ -14159,7 +14167,8 @@ static int __devinit tg3_test_dma(struct tg3 *tp)u32 *buf, saved_dma_rwctrl;int ret =0 ; - buf =pci_alloc_consistent (tp->pdev,TEST_BUFFER_SIZE , &buf_dma); + buf =dma_alloc_coherent (&tp->pdev->dev,TEST_BUFFER_SIZE , + &buf_dma,GFP_KERNEL );if (!buf) { ret = -ENOMEM ; goto out_nofree;@@ -14343,7 +14352,7 @@ static int __devinit tg3_test_dma(struct tg3 *tp) } out: -pci_free_consistent (tp->pdev,TEST_BUFFER_SIZE , buf, buf_dma); +dma_free_coherent (&tp->pdev->dev,TEST_BUFFER_SIZE , buf, buf_dma); out_nofree:return ret; }
David Miller
maintainerFrom: Amit Kumar Salecha <[email protected]>
Date: Tue, 26 Oct 2010 02:37:58 -0700
Quoted 2 lines
Hi
Series of 4 bug fixes. Apply them on net-2.6 branch.
Your patches weren't numbered, making the order I should apply them ambiguous.
Please fix the subject lines and resubmit.
Thank you.