netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 1/5] bnx2: Add PCI ID for 5716S.
@ 2008-11-12 23:10 Michael Chan
  2008-11-12 23:10 ` [PATCH net-next 2/5] bnx2: Restrict WoL support Michael Chan
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Michael Chan @ 2008-11-12 23:10 UTC (permalink / raw)
  To: davem; +Cc: netdev, Michael Chan, Matt Carlson, Benjamin Li

Signed-off-by: Michael Chan <mchan@broadcom.com>
Signed-off-by: Matt Carlson <mcarlson@broadcom.com>
Signed-off-by: Benjamin Li <benli@broadcom.com>
---
 drivers/net/bnx2.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index 51b163a..49ebb50 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -89,6 +89,7 @@ typedef enum {
 	BCM5709,
 	BCM5709S,
 	BCM5716,
+	BCM5716S,
 } board_t;
 
 /* indexed by board_t, above */
@@ -105,6 +106,7 @@ static struct {
 	{ "Broadcom NetXtreme II BCM5709 1000Base-T" },
 	{ "Broadcom NetXtreme II BCM5709 1000Base-SX" },
 	{ "Broadcom NetXtreme II BCM5716 1000Base-T" },
+	{ "Broadcom NetXtreme II BCM5716 1000Base-SX" },
 	};
 
 static DEFINE_PCI_DEVICE_TABLE(bnx2_pci_tbl) = {
@@ -128,6 +130,8 @@ static DEFINE_PCI_DEVICE_TABLE(bnx2_pci_tbl) = {
 	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5709S },
 	{ PCI_VENDOR_ID_BROADCOM, 0x163b,
 	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5716 },
+	{ PCI_VENDOR_ID_BROADCOM, 0x163c,
+	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5716 },
 	{ 0, }
 };
 
-- 
1.5.6.GIT



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net-next 2/5] bnx2: Restrict WoL support.
  2008-11-12 23:10 [PATCH net-next 1/5] bnx2: Add PCI ID for 5716S Michael Chan
@ 2008-11-12 23:10 ` Michael Chan
  2008-11-13  0:01   ` David Miller
  2008-11-12 23:10 ` [PATCH net-next 3/5] bnx2: Set rx buffer water marks based on MTU Michael Chan
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Michael Chan @ 2008-11-12 23:10 UTC (permalink / raw)
  To: davem; +Cc: netdev, Michael Chan, Matt Carlson, Benjamin Li

On some quad-port cards that cannot support WoL on all ports due
to excessive power consumption, the driver needs to restrict WoL
on some ports by checking VAUX_PRESET bit.

Signed-off-by: Michael Chan <mchan@broadcom.com>
Signed-off-by: Matt Carlson <mcarlson@broadcom.com>
Signed-off-by: Benjamin Li <benli@broadcom.com>
---
 drivers/net/bnx2.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index 49ebb50..d28cbce 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -7586,7 +7586,8 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
 
 	if ((CHIP_ID(bp) == CHIP_ID_5708_A0) ||
 	    (CHIP_ID(bp) == CHIP_ID_5708_B0) ||
-	    (CHIP_ID(bp) == CHIP_ID_5708_B1)) {
+	    (CHIP_ID(bp) == CHIP_ID_5708_B1) ||
+	    !(REG_RD(bp, BNX2_PCI_CONFIG_3) & BNX2_PCI_CONFIG_3_VAUX_PRESET)) {
 		bp->flags |= BNX2_FLAG_NO_WOL;
 		bp->wol = 0;
 	}
-- 
1.5.6.GIT



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net-next 3/5] bnx2: Set rx buffer water marks based on MTU.
  2008-11-12 23:10 [PATCH net-next 1/5] bnx2: Add PCI ID for 5716S Michael Chan
  2008-11-12 23:10 ` [PATCH net-next 2/5] bnx2: Restrict WoL support Michael Chan
@ 2008-11-12 23:10 ` Michael Chan
  2008-11-13  0:02   ` David Miller
  2008-11-12 23:10 ` [PATCH net-next 4/5] bnx2: Reorganize timeout constants Michael Chan
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Michael Chan @ 2008-11-12 23:10 UTC (permalink / raw)
  To: davem; +Cc: netdev, Michael Chan, Matt Carlson, Benjamin Li

The default rx buffer water marks for XOFF/XON are for 1500 MTU.  At
larger MTUs, these water marks need to be adjusted for effective
flow control.

Signed-off-by: Michael Chan <mchan@broadcom.com>
Signed-off-by: Matt Carlson <mcarlson@broadcom.com>
Signed-off-by: Benjamin Li <benli@broadcom.com>
---
 drivers/net/bnx2.c |   12 ++++++++++--
 drivers/net/bnx2.h |   21 +++++++++++++++++++++
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index d28cbce..a52ffdc 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -4473,7 +4473,7 @@ bnx2_reset_chip(struct bnx2 *bp, u32 reset_code)
 static int
 bnx2_init_chip(struct bnx2 *bp)
 {
-	u32 val;
+	u32 val, mtu;
 	int rc, i;
 
 	/* Make sure the interrupt is not active. */
@@ -4565,11 +4565,19 @@ bnx2_init_chip(struct bnx2 *bp)
 	REG_WR(bp, BNX2_EMAC_BACKOFF_SEED, val);
 
 	/* Program the MTU.  Also include 4 bytes for CRC32. */
-	val = bp->dev->mtu + ETH_HLEN + 4;
+	mtu = bp->dev->mtu;
+	val = mtu + ETH_HLEN + ETH_FCS_LEN;
 	if (val > (MAX_ETHERNET_PACKET_SIZE + 4))
 		val |= BNX2_EMAC_RX_MTU_SIZE_JUMBO_ENA;
 	REG_WR(bp, BNX2_EMAC_RX_MTU_SIZE, val);
 
+	if (mtu < 1500)
+		mtu = 1500;
+
+	bnx2_reg_wr_ind(bp, BNX2_RBUF_CONFIG, BNX2_RBUF_CONFIG_VAL(mtu));
+	bnx2_reg_wr_ind(bp, BNX2_RBUF_CONFIG2, BNX2_RBUF_CONFIG2_VAL(mtu));
+	bnx2_reg_wr_ind(bp, BNX2_RBUF_CONFIG3, BNX2_RBUF_CONFIG3_VAL(mtu));
+
 	for (i = 0; i < BNX2_MAX_MSIX_VEC; i++)
 		bp->bnx2_napi[i].last_status_idx = 0;
 
diff --git a/drivers/net/bnx2.h b/drivers/net/bnx2.h
index 617d953..2b9649a 100644
--- a/drivers/net/bnx2.h
+++ b/drivers/net/bnx2.h
@@ -4199,7 +4199,14 @@ struct l2_fhdr {
 
 #define BNX2_RBUF_CONFIG				0x0020000c
 #define BNX2_RBUF_CONFIG_XOFF_TRIP			 (0x3ffL<<0)
+#define BNX2_RBUF_CONFIG_XOFF_TRIP_VAL(mtu)		 \
+	((((mtu) - 1500) * 31 / 1000) + 54)
 #define BNX2_RBUF_CONFIG_XON_TRIP			 (0x3ffL<<16)
+#define BNX2_RBUF_CONFIG_XON_TRIP_VAL(mtu)		 \
+	((((mtu) - 1500) * 39 / 1000) + 66)
+#define BNX2_RBUF_CONFIG_VAL(mtu)			 \
+	(BNX2_RBUF_CONFIG_XOFF_TRIP_VAL(mtu) |		 \
+	(BNX2_RBUF_CONFIG_XON_TRIP_VAL(mtu) << 16))
 
 #define BNX2_RBUF_FW_BUF_ALLOC				0x00200010
 #define BNX2_RBUF_FW_BUF_ALLOC_VALUE			 (0x1ffL<<7)
@@ -4221,11 +4228,25 @@ struct l2_fhdr {
 
 #define BNX2_RBUF_CONFIG2				0x0020001c
 #define BNX2_RBUF_CONFIG2_MAC_DROP_TRIP			 (0x3ffL<<0)
+#define BNX2_RBUF_CONFIG2_MAC_DROP_TRIP_VAL(mtu)	 \
+	((((mtu) - 1500) * 4 / 1000) + 5)
 #define BNX2_RBUF_CONFIG2_MAC_KEEP_TRIP			 (0x3ffL<<16)
+#define BNX2_RBUF_CONFIG2_MAC_KEEP_TRIP_VAL(mtu)	 \
+	((((mtu) - 1500) * 2 / 100) + 30)
+#define BNX2_RBUF_CONFIG2_VAL(mtu)			 \
+	(BNX2_RBUF_CONFIG2_MAC_DROP_TRIP_VAL(mtu) |	 \
+	(BNX2_RBUF_CONFIG2_MAC_KEEP_TRIP_VAL(mtu) << 16))
 
 #define BNX2_RBUF_CONFIG3				0x00200020
 #define BNX2_RBUF_CONFIG3_CU_DROP_TRIP			 (0x3ffL<<0)
+#define BNX2_RBUF_CONFIG3_CU_DROP_TRIP_VAL(mtu)		 \
+	((((mtu) - 1500) * 12 / 1000) + 18)
 #define BNX2_RBUF_CONFIG3_CU_KEEP_TRIP			 (0x3ffL<<16)
+#define BNX2_RBUF_CONFIG3_CU_KEEP_TRIP_VAL(mtu)		 \
+	((((mtu) - 1500) * 2 / 100) + 30)
+#define BNX2_RBUF_CONFIG3_VAL(mtu)			 \
+	(BNX2_RBUF_CONFIG3_CU_DROP_TRIP_VAL(mtu) |	 \
+	(BNX2_RBUF_CONFIG3_CU_KEEP_TRIP_VAL(mtu) << 16))
 
 #define BNX2_RBUF_PKT_DATA				0x00208000
 #define BNX2_RBUF_CLIST_DATA				0x00210000
-- 
1.5.6.GIT



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net-next 4/5] bnx2: Reorganize timeout constants.
  2008-11-12 23:10 [PATCH net-next 1/5] bnx2: Add PCI ID for 5716S Michael Chan
  2008-11-12 23:10 ` [PATCH net-next 2/5] bnx2: Restrict WoL support Michael Chan
  2008-11-12 23:10 ` [PATCH net-next 3/5] bnx2: Set rx buffer water marks based on MTU Michael Chan
@ 2008-11-12 23:10 ` Michael Chan
  2008-11-12 23:10 ` [PATCH net-next 5/5] bnx2: Update version to 1.8.2 Michael Chan
  2008-11-13  0:01 ` [PATCH net-next 1/5] bnx2: Add PCI ID for 5716S David Miller
  4 siblings, 0 replies; 11+ messages in thread
From: Michael Chan @ 2008-11-12 23:10 UTC (permalink / raw)
  To: davem; +Cc: netdev, Michael Chan, Matt Carlson, Benjamin Li

Move all related timeout constants to the same location.  BNX2
prefix is also added to make them more consistent.

Signed-off-by: Michael Chan <mchan@broadcom.com>
Signed-off-by: Matt Carlson <mcarlson@broadcom.com>
Signed-off-by: Benjamin Li <benli@broadcom.com>
---
 drivers/net/bnx2.c |    8 ++++----
 drivers/net/bnx2.h |   14 +++++++-------
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index a52ffdc..84563b0 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -1656,7 +1656,7 @@ bnx2_setup_serdes_phy(struct bnx2 *bp, u8 port)
 		 * exchanging base pages plus 3 next pages and
 		 * normally completes in about 120 msec.
 		 */
-		bp->current_interval = SERDES_AN_TIMEOUT;
+		bp->current_interval = BNX2_SERDES_AN_TIMEOUT;
 		bp->serdes_an_pending = 1;
 		mod_timer(&bp->timer, jiffies + bp->current_interval);
 	} else {
@@ -2278,7 +2278,7 @@ bnx2_fw_sync(struct bnx2 *bp, u32 msg_data, int ack, int silent)
 		return 0;
 
 	/* wait for an acknowledgement. */
-	for (i = 0; i < (FW_ACK_TIME_OUT_MS / 10); i++) {
+	for (i = 0; i < (BNX2_FW_ACK_TIME_OUT_MS / 10); i++) {
 		msleep(10);
 
 		val = bnx2_shmem_rd(bp, BNX2_FW_MB);
@@ -5705,7 +5705,7 @@ bnx2_5708_serdes_timer(struct bnx2 *bp)
 		bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
 		if (bmcr & BMCR_ANENABLE) {
 			bnx2_enable_forced_2g5(bp);
-			bp->current_interval = SERDES_FORCED_TIMEOUT;
+			bp->current_interval = BNX2_SERDES_FORCED_TIMEOUT;
 		} else {
 			bnx2_disable_forced_2g5(bp);
 			bp->serdes_an_pending = 2;
@@ -6522,7 +6522,7 @@ bnx2_nway_reset(struct net_device *dev)
 
 		spin_lock_bh(&bp->phy_lock);
 
-		bp->current_interval = SERDES_AN_TIMEOUT;
+		bp->current_interval = BNX2_SERDES_AN_TIMEOUT;
 		bp->serdes_an_pending = 1;
 		mod_timer(&bp->timer, jiffies + bp->current_interval);
 	}
diff --git a/drivers/net/bnx2.h b/drivers/net/bnx2.h
index 2b9649a..34ca478 100644
--- a/drivers/net/bnx2.h
+++ b/drivers/net/bnx2.h
@@ -6679,8 +6679,6 @@ struct bnx2_napi {
 	struct bnx2_tx_ring_info	tx_ring;
 };
 
-#define BNX2_TIMER_INTERVAL			HZ
-
 struct bnx2 {
 	/* Fields used in the tx and intr/napi performance paths are grouped */
 	/* together in the beginning of the structure. */
@@ -6728,7 +6726,11 @@ struct bnx2 {
 
 	/* End of fields used in the performance code paths. */
 
-	int			current_interval;
+	unsigned int		current_interval;
+#define BNX2_TIMER_INTERVAL		HZ
+#define BNX2_SERDES_AN_TIMEOUT		(HZ / 3)
+#define BNX2_SERDES_FORCED_TIMEOUT	(HZ / 10)
+
 	struct			timer_list timer;
 	struct work_struct	reset_task;
 
@@ -6860,8 +6862,6 @@ struct bnx2 {
 #define PHY_LOOPBACK		2
 
 	u8			serdes_an_pending;
-#define SERDES_AN_TIMEOUT	(HZ / 3)
-#define SERDES_FORCED_TIMEOUT	(HZ / 10)
 
 	u8			mac_addr[8];
 
@@ -6959,14 +6959,14 @@ struct fw_info {
 /* This value (in milliseconds) determines the frequency of the driver
  * issuing the PULSE message code.  The firmware monitors this periodic
  * pulse to determine when to switch to an OS-absent mode. */
-#define DRV_PULSE_PERIOD_MS                 250
+#define BNX2_DRV_PULSE_PERIOD_MS                 250
 
 /* This value (in milliseconds) determines how long the driver should
  * wait for an acknowledgement from the firmware before timing out.  Once
  * the firmware has timed out, the driver will assume there is no firmware
  * running and there won't be any firmware-driver synchronization during a
  * driver reset. */
-#define FW_ACK_TIME_OUT_MS                  1000
+#define BNX2_FW_ACK_TIME_OUT_MS                  1000
 
 
 #define BNX2_DRV_RESET_SIGNATURE		0x00000000
-- 
1.5.6.GIT



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH net-next 5/5] bnx2: Update version to 1.8.2.
  2008-11-12 23:10 [PATCH net-next 1/5] bnx2: Add PCI ID for 5716S Michael Chan
                   ` (2 preceding siblings ...)
  2008-11-12 23:10 ` [PATCH net-next 4/5] bnx2: Reorganize timeout constants Michael Chan
@ 2008-11-12 23:10 ` Michael Chan
  2008-11-13  0:03   ` David Miller
  2008-11-13  5:49   ` [PATCH] bnx2: bnx2_alloc_rx_mem() should use kmalloc() for small allocations Eric Dumazet
  2008-11-13  0:01 ` [PATCH net-next 1/5] bnx2: Add PCI ID for 5716S David Miller
  4 siblings, 2 replies; 11+ messages in thread
From: Michael Chan @ 2008-11-12 23:10 UTC (permalink / raw)
  To: davem; +Cc: netdev, Michael Chan, Matt Carlson, Benjamin Li

Signed-off-by: Michael Chan <mchan@broadcom.com>
Signed-off-by: Matt Carlson <mcarlson@broadcom.com>
Signed-off-by: Benjamin Li <benli@broadcom.com>
---
 drivers/net/bnx2.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index 84563b0..0853b3c 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -57,8 +57,8 @@
 
 #define DRV_MODULE_NAME		"bnx2"
 #define PFX DRV_MODULE_NAME	": "
-#define DRV_MODULE_VERSION	"1.8.1"
-#define DRV_MODULE_RELDATE	"Oct 7, 2008"
+#define DRV_MODULE_VERSION	"1.8.2"
+#define DRV_MODULE_RELDATE	"Nov 10, 2008"
 
 #define RUN_AT(x) (jiffies + (x))
 
-- 
1.5.6.GIT



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next 1/5] bnx2: Add PCI ID for 5716S.
  2008-11-12 23:10 [PATCH net-next 1/5] bnx2: Add PCI ID for 5716S Michael Chan
                   ` (3 preceding siblings ...)
  2008-11-12 23:10 ` [PATCH net-next 5/5] bnx2: Update version to 1.8.2 Michael Chan
@ 2008-11-13  0:01 ` David Miller
  4 siblings, 0 replies; 11+ messages in thread
From: David Miller @ 2008-11-13  0:01 UTC (permalink / raw)
  To: mchan; +Cc: netdev, mcarlson, benli

From: "Michael Chan" <mchan@broadcom.com>
Date: Wed, 12 Nov 2008 15:10:00 -0800

> Signed-off-by: Michael Chan <mchan@broadcom.com>
> Signed-off-by: Matt Carlson <mcarlson@broadcom.com>
> Signed-off-by: Benjamin Li <benli@broadcom.com>

Applied.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next 2/5] bnx2: Restrict WoL support.
  2008-11-12 23:10 ` [PATCH net-next 2/5] bnx2: Restrict WoL support Michael Chan
@ 2008-11-13  0:01   ` David Miller
  0 siblings, 0 replies; 11+ messages in thread
From: David Miller @ 2008-11-13  0:01 UTC (permalink / raw)
  To: mchan; +Cc: netdev, mcarlson, benli

From: "Michael Chan" <mchan@broadcom.com>
Date: Wed, 12 Nov 2008 15:10:01 -0800

> On some quad-port cards that cannot support WoL on all ports due
> to excessive power consumption, the driver needs to restrict WoL
> on some ports by checking VAUX_PRESET bit.
> 
> Signed-off-by: Michael Chan <mchan@broadcom.com>
> Signed-off-by: Matt Carlson <mcarlson@broadcom.com>
> Signed-off-by: Benjamin Li <benli@broadcom.com>

Applied.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next 3/5] bnx2: Set rx buffer water marks based on MTU.
  2008-11-12 23:10 ` [PATCH net-next 3/5] bnx2: Set rx buffer water marks based on MTU Michael Chan
@ 2008-11-13  0:02   ` David Miller
  0 siblings, 0 replies; 11+ messages in thread
From: David Miller @ 2008-11-13  0:02 UTC (permalink / raw)
  To: mchan; +Cc: netdev, mcarlson, benli

From: "Michael Chan" <mchan@broadcom.com>
Date: Wed, 12 Nov 2008 15:10:02 -0800

> The default rx buffer water marks for XOFF/XON are for 1500 MTU.  At
> larger MTUs, these water marks need to be adjusted for effective
> flow control.
> 
> Signed-off-by: Michael Chan <mchan@broadcom.com>
> Signed-off-by: Matt Carlson <mcarlson@broadcom.com>
> Signed-off-by: Benjamin Li <benli@broadcom.com>

Applied.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH net-next 5/5] bnx2: Update version to 1.8.2.
  2008-11-12 23:10 ` [PATCH net-next 5/5] bnx2: Update version to 1.8.2 Michael Chan
@ 2008-11-13  0:03   ` David Miller
  2008-11-13  5:49   ` [PATCH] bnx2: bnx2_alloc_rx_mem() should use kmalloc() for small allocations Eric Dumazet
  1 sibling, 0 replies; 11+ messages in thread
From: David Miller @ 2008-11-13  0:03 UTC (permalink / raw)
  To: mchan; +Cc: netdev, mcarlson, benli

From: "Michael Chan" <mchan@broadcom.com>
Date: Wed, 12 Nov 2008 15:10:04 -0800

> Signed-off-by: Michael Chan <mchan@broadcom.com>
> Signed-off-by: Matt Carlson <mcarlson@broadcom.com>
> Signed-off-by: Benjamin Li <benli@broadcom.com>

Also applied, thanks Michael.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH]  bnx2: bnx2_alloc_rx_mem() should use kmalloc() for small allocations
  2008-11-12 23:10 ` [PATCH net-next 5/5] bnx2: Update version to 1.8.2 Michael Chan
  2008-11-13  0:03   ` David Miller
@ 2008-11-13  5:49   ` Eric Dumazet
  2008-11-13  6:49     ` David Miller
  1 sibling, 1 reply; 11+ messages in thread
From: Eric Dumazet @ 2008-11-13  5:49 UTC (permalink / raw)
  To: Michael Chan; +Cc: davem, netdev, Matt Carlson, Benjamin Li

[-- Attachment #1: Type: text/plain, Size: 825 bytes --]

Hi all

# grep bnx2 /proc/vmallocinfo
0xf8218000-0xf821a000    8192 bnx2_alloc_rx_mem+0x33/0x310 pages=1 vmalloc
0xf821b000-0xf821d000    8192 bnx2_alloc_rx_mem+0x33/0x310 pages=1 vmalloc
0xf8220000-0xf8234000   81920 bnx2_init_board+0x104/0xae0 phys=f6000000 ioremap
0xf8240000-0xf8254000   81920 bnx2_init_board+0x104/0xae0 phys=fa000000 ioremap


Any chance bnx2_alloc_rx_mem doesnt use vmalloc() to allocate less than a page of memory ?

Thank you

[PATCH] bnx2: bnx2_alloc_rx_mem() should use kmalloc() for small allocations

Add two helper functions to allocate and free memory, using kzalloc() or vmalloc()
depending of the size of the allocation

Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
---
 drivers/net/bnx2.c |   36 +++++++++++++++++++++++++-----------
 1 files changed, 25 insertions(+), 11 deletions(-)

[-- Attachment #2: bnx2.patch --]
[-- Type: text/plain, Size: 2038 bytes --]

diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index 0853b3c..93c8256 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -523,6 +523,24 @@ bnx2_free_tx_mem(struct bnx2 *bp)
 	}
 }
 
+static void *
+bnx2_alloc_kmem(size_t sz)
+{
+	if (sz <= PAGE_SIZE)
+		return kzalloc(sz, GFP_KERNEL);
+	else
+		return 	__vmalloc(sz, GFP_KERNEL | __GFP_ZERO, PAGE_KERNEL);
+}
+
+static void
+bnx2_free_kmem(void *ptr, size_t sz)
+{
+	if (sz <= PAGE_SIZE)
+		kfree(ptr);
+	else
+		vfree(ptr);
+}
+
 static void
 bnx2_free_rx_mem(struct bnx2 *bp)
 {
@@ -541,7 +559,8 @@ bnx2_free_rx_mem(struct bnx2 *bp)
 			rxr->rx_desc_ring[j] = NULL;
 		}
 		if (rxr->rx_buf_ring)
-			vfree(rxr->rx_buf_ring);
+			bnx2_free_kmem(rxr->rx_buf_ring,
+				       SW_RXBD_RING_SIZE * bp->rx_max_ring);
 		rxr->rx_buf_ring = NULL;
 
 		for (j = 0; j < bp->rx_max_pg_ring; j++) {
@@ -552,7 +571,8 @@ bnx2_free_rx_mem(struct bnx2 *bp)
 			rxr->rx_pg_desc_ring[i] = NULL;
 		}
 		if (rxr->rx_pg_ring)
-			vfree(rxr->rx_pg_ring);
+			bnx2_free_kmem(rxr->rx_pg_ring,
+				       SW_RXPG_RING_SIZE * bp->rx_max_pg_ring);
 		rxr->rx_pg_ring = NULL;
 	}
 }
@@ -590,13 +610,10 @@ bnx2_alloc_rx_mem(struct bnx2 *bp)
 		int j;
 
 		rxr->rx_buf_ring =
-			vmalloc(SW_RXBD_RING_SIZE * bp->rx_max_ring);
+			bnx2_alloc_kmem(SW_RXBD_RING_SIZE * bp->rx_max_ring);
 		if (rxr->rx_buf_ring == NULL)
 			return -ENOMEM;
 
-		memset(rxr->rx_buf_ring, 0,
-		       SW_RXBD_RING_SIZE * bp->rx_max_ring);
-
 		for (j = 0; j < bp->rx_max_ring; j++) {
 			rxr->rx_desc_ring[j] =
 				pci_alloc_consistent(bp->pdev, RXBD_RING_SIZE,
@@ -607,13 +624,10 @@ bnx2_alloc_rx_mem(struct bnx2 *bp)
 		}
 
 		if (bp->rx_pg_ring_size) {
-			rxr->rx_pg_ring = vmalloc(SW_RXPG_RING_SIZE *
-						  bp->rx_max_pg_ring);
+			rxr->rx_pg_ring = bnx2_alloc_kmem(SW_RXPG_RING_SIZE *
+							  bp->rx_max_pg_ring);
 			if (rxr->rx_pg_ring == NULL)
 				return -ENOMEM;
-
-			memset(rxr->rx_pg_ring, 0, SW_RXPG_RING_SIZE *
-			       bp->rx_max_pg_ring);
 		}
 
 		for (j = 0; j < bp->rx_max_pg_ring; j++) {

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH] bnx2: bnx2_alloc_rx_mem() should use kmalloc() for small allocations
  2008-11-13  5:49   ` [PATCH] bnx2: bnx2_alloc_rx_mem() should use kmalloc() for small allocations Eric Dumazet
@ 2008-11-13  6:49     ` David Miller
  0 siblings, 0 replies; 11+ messages in thread
From: David Miller @ 2008-11-13  6:49 UTC (permalink / raw)
  To: dada1; +Cc: mchan, netdev, mcarlson, benli

From: Eric Dumazet <dada1@cosmosbay.com>
Date: Thu, 13 Nov 2008 06:49:14 +0100

> Any chance bnx2_alloc_rx_mem doesnt use vmalloc() to allocate less
> than a page of memory ?
>
> [PATCH] bnx2: bnx2_alloc_rx_mem() should use kmalloc() for small allocations

Eric, I've seen (and used) this idiom enough times that I think
it deserves a generic construct somewhere instead of replicating
this sequence over and over again.

Don't you agree? :-)

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2008-11-13  6:49 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-12 23:10 [PATCH net-next 1/5] bnx2: Add PCI ID for 5716S Michael Chan
2008-11-12 23:10 ` [PATCH net-next 2/5] bnx2: Restrict WoL support Michael Chan
2008-11-13  0:01   ` David Miller
2008-11-12 23:10 ` [PATCH net-next 3/5] bnx2: Set rx buffer water marks based on MTU Michael Chan
2008-11-13  0:02   ` David Miller
2008-11-12 23:10 ` [PATCH net-next 4/5] bnx2: Reorganize timeout constants Michael Chan
2008-11-12 23:10 ` [PATCH net-next 5/5] bnx2: Update version to 1.8.2 Michael Chan
2008-11-13  0:03   ` David Miller
2008-11-13  5:49   ` [PATCH] bnx2: bnx2_alloc_rx_mem() should use kmalloc() for small allocations Eric Dumazet
2008-11-13  6:49     ` David Miller
2008-11-13  0:01 ` [PATCH net-next 1/5] bnx2: Add PCI ID for 5716S David Miller

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).