linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: Justin Forbes <jmforbes@linuxtx.org>,
	Zwane Mwaikambo <zwane@arm.linux.org.uk>,
	"Theodore Ts'o" <tytso@mit.edu>,
	Randy Dunlap <rdunlap@xenotime.net>,
	Dave Jones <davej@redhat.com>,
	Chuck Wolber <chuckw@quantumlinux.com>,
	Chris Wedgwood <reviews@ml.cw.f00f.org>,
	Michael Krufky <mkrufky@linuxtv.org>,
	Chuck Ebbert <cebbert@redhat.com>,
	Domenico Andreoli <cavokz@gmail.com>, Willy Tarreau <w@1wt.eu>,
	Rodrigo Rubira Branco <rbranco@la.checkpoint.com>,
	Jake Edge <jake@lwn.net>, Eugene Teo <eteo@redhat.com>,
	torvalds@linux-foundation.org, akpm@linux-foundation.org,
	alan@lxorguk.ukuu.org.uk, Matt Carlson <mcarlson@broadcom.com>,
	Michael Chan <mchan@broadcom.com>,
	"David S. Miller" <davem@davemloft.net>
Subject: [patch 36/42] tg3: Fix firmware event timeouts
Date: Wed, 3 Sep 2008 10:26:40 -0700	[thread overview]
Message-ID: <20080903172640.GK7731@suse.de> (raw)
In-Reply-To: <20080903172447.GA7731@suse.de>

[-- Attachment #1: tg3-fix-firmware-event-timeouts.patch --]
[-- Type: text/plain, Size: 4736 bytes --]


2.6.26-stable review patch.  If anyone has any objections, please let us know.

------------------

From: Matt Carlson <mcarlson@broadcom.com>

patch 4ba526ced990f4d61ee8d65fe8a6f0745e8e455c upstream

The git commit 7c5026aa9b81dd45df8d3f4e0be73e485976a8b6 ("tg3: Add
link state reporting to UMP firmware") introduced code that waits for
previous firmware events to be serviced before attempting to submit a
new event.  Unfortunately that patch contained a bug that cause the
driver to wait 2.5 seconds, rather than 2.5 milliseconds as intended.
This patch fixes that bug.

This bug revealed that not all firmware versions service driver events
though.  Since we do not know which versions of the firmware do and don't
service these events, the driver needs some way to minimize the effects
of the delay.  This patch solves the problem by recording a jiffies
timestamp when it submits an event to the hardware.  If the jiffies
counter shows that 2.5 milliseconds have already passed, a wait is not
needed and the driver can proceed to submit a new event.

Signed-off-by: Matt Carlson <mcarlson@broadcom.com>
Signed-off-by: Michael Chan <mchan@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 drivers/net/tg3.c |   53 +++++++++++++++++++++++++++++++++++++----------------
 drivers/net/tg3.h |    3 +++
 2 files changed, 40 insertions(+), 16 deletions(-)

--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -1672,15 +1672,43 @@ static int tg3_set_power_state(struct tg
 }
 
 /* tp->lock is held. */
+static inline void tg3_generate_fw_event(struct tg3 *tp)
+{
+	u32 val;
+
+	val = tr32(GRC_RX_CPU_EVENT);
+	val |= GRC_RX_CPU_DRIVER_EVENT;
+	tw32_f(GRC_RX_CPU_EVENT, val);
+
+	tp->last_event_jiffies = jiffies;
+}
+
+#define TG3_FW_EVENT_TIMEOUT_USEC 2500
+
+/* tp->lock is held. */
 static void tg3_wait_for_event_ack(struct tg3 *tp)
 {
 	int i;
+	unsigned int delay_cnt;
+	long time_remain;
+
+	/* If enough time has passed, no wait is necessary. */
+	time_remain = (long)(tp->last_event_jiffies + 1 +
+		      usecs_to_jiffies(TG3_FW_EVENT_TIMEOUT_USEC)) -
+		      (long)jiffies;
+	if (time_remain < 0)
+		return;
+
+	/* Check if we can shorten the wait time. */
+	delay_cnt = jiffies_to_usecs(time_remain);
+	if (delay_cnt > TG3_FW_EVENT_TIMEOUT_USEC)
+		delay_cnt = TG3_FW_EVENT_TIMEOUT_USEC;
+	delay_cnt = (delay_cnt >> 3) + 1;
 
-	/* Wait for up to 2.5 milliseconds */
-	for (i = 0; i < 250000; i++) {
+	for (i = 0; i < delay_cnt; i++) {
 		if (!(tr32(GRC_RX_CPU_EVENT) & GRC_RX_CPU_DRIVER_EVENT))
 			break;
-		udelay(10);
+		udelay(8);
 	}
 }
 
@@ -1729,9 +1757,7 @@ static void tg3_ump_link_report(struct t
 		val = 0;
 	tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 12, val);
 
-	val = tr32(GRC_RX_CPU_EVENT);
-	val |= GRC_RX_CPU_DRIVER_EVENT;
-	tw32_f(GRC_RX_CPU_EVENT, val);
+	tg3_generate_fw_event(tp);
 }
 
 static void tg3_link_report(struct tg3 *tp)
@@ -5565,6 +5591,7 @@ static int tg3_chip_reset(struct tg3 *tp
 		tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg);
 		if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
 			tp->tg3_flags |= TG3_FLAG_ENABLE_ASF;
+			tp->last_event_jiffies = jiffies;
 			if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
 				tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE;
 		}
@@ -5578,15 +5605,12 @@ static void tg3_stop_fw(struct tg3 *tp)
 {
 	if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) &&
 	   !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) {
-		u32 val;
-
 		/* Wait for RX cpu to ACK the previous event. */
 		tg3_wait_for_event_ack(tp);
 
 		tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW);
-		val = tr32(GRC_RX_CPU_EVENT);
-		val |= GRC_RX_CPU_DRIVER_EVENT;
-		tw32(GRC_RX_CPU_EVENT, val);
+
+		tg3_generate_fw_event(tp);
 
 		/* Wait for RX cpu to ACK this event. */
 		tg3_wait_for_event_ack(tp);
@@ -7477,8 +7501,6 @@ static void tg3_timer(unsigned long __op
 	 */
 	if (!--tp->asf_counter) {
 		if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
-			u32 val;
-
 			tg3_wait_for_event_ack(tp);
 
 			tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX,
@@ -7486,9 +7508,8 @@ static void tg3_timer(unsigned long __op
 			tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4);
 			/* 5 seconds timeout */
 			tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, 5);
-			val = tr32(GRC_RX_CPU_EVENT);
-			val |= GRC_RX_CPU_DRIVER_EVENT;
-			tw32_f(GRC_RX_CPU_EVENT, val);
+
+			tg3_generate_fw_event(tp);
 		}
 		tp->asf_counter = tp->asf_multiplier;
 	}
--- a/drivers/net/tg3.h
+++ b/drivers/net/tg3.h
@@ -2404,7 +2404,10 @@ struct tg3 {
 	struct tg3_ethtool_stats	estats;
 	struct tg3_ethtool_stats	estats_prev;
 
+	union {
 	unsigned long			phy_crc_errors;
+	unsigned long			last_event_jiffies;
+	};
 
 	u32				rx_offset;
 	u32				tg3_flags;

-- 

  parent reply	other threads:[~2008-09-03 17:45 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20080903171927.534216229@mini.kroah.org>
2008-09-03 17:24 ` [patch 00/42] 2.6.26-stable review Greg KH
2008-09-03 17:25   ` [patch 01/42] cramfs: fix named-pipe handling Greg KH
2008-09-03 17:25   ` [patch 02/42] PCI: fix reference leak in pci_get_dev_by_id() Greg KH
2008-09-03 17:25   ` [patch 03/42] eeepc-laptop: fix use after free Greg KH
2008-09-03 17:25   ` [patch 04/42] fbdefio: add set_page_dirty handler to deferred IO FB Greg KH
2008-09-03 17:25   ` [patch 05/42] binfmt_misc: fix false -ENOEXEC when coupled with other binary handlers Greg KH
2008-09-03 17:25   ` [patch 06/42] USB: cdc-acm: dont unlock acm->mutex on error path Greg KH
2008-09-03 17:25   ` [patch 07/42] x86: work around MTRR mask setting Greg KH
2008-09-03 17:25   ` [patch 08/42] x86: fix "kernel wont boot on a Cyrix MediaGXm (Geode)" Greg KH
2008-09-03 17:25   ` [patch 09/42] S390 dasd: fix data size for PSF/PRSSD command Greg KH
2008-09-03 17:25   ` [patch 10/42] ALSA: oxygen: prevent muting of nonexistent AC97 controls Greg KH
2008-09-03 17:25   ` [patch 11/42] bio: fix __bio_copy_iov() handling of bio->bv_len Greg KH
2008-09-03 17:25   ` [patch 12/42] bio: fix bio_copy_kern() " Greg KH
2008-09-03 17:25   ` [patch 13/42] forcedeth: fix checksum flag Greg KH
2008-09-03 17:25   ` [patch 14/42] atl1: disable TSO by default Greg KH
2008-09-03 17:25   ` [patch 15/42] cifs: fix O_APPEND on directio mounts Greg KH
2008-09-03 17:25   ` [patch 16/42] drivers/char/random.c: fix a race which can lead to a bogus BUG() Greg KH
2008-09-03 17:25   ` [patch 17/42] rtc_time_to_tm: fix signed/unsigned arithmetic Greg KH
2008-09-03 17:25   ` [patch 18/42] 8250: improve workaround for UARTs that dont re-assert THRE correctly Greg KH
2008-09-03 17:25   ` [patch 19/42] mm: make setup_zone_migrate_reserve() aware of overlapping nodes Greg KH
2008-09-03 17:25   ` [patch 20/42] AX.25: Fix sysctl registration if !CONFIG_AX25_DAMA_SLAVE Greg KH
2008-09-03 17:26   ` [patch 21/42] ipv6: Fix OOPS, ip -f inet6 route get fec0::1, linux-2.6.26, ip6_route_output, rt6_fill_node+0x175 Greg KH
2008-09-03 17:26   ` [patch 22/42] netns: Add network namespace argument to rt6_fill_node() and ipv6_dev_get_saddr() Greg KH
2008-09-03 17:26   ` [patch 23/42] pkt_sched: Fix return value corruption in HTB and TBF Greg KH
2008-09-03 17:26   ` [patch 24/42] pkt_sched: Fix actions referencing Greg KH
2008-09-03 17:26   ` [patch 25/42] udp: Drop socket lock for encapsulated packets Greg KH
2008-09-03 17:26   ` [patch 26/42] sctp: fix potential panics in the SCTP-AUTH API Greg KH
2008-09-03 17:26   ` [patch 27/42] sctp: add verification checks to SCTP_AUTH_KEY option Greg KH
2008-09-03 17:26   ` [patch 28/42] sch_prio: Fix nla_parse_nested_compat() regression Greg KH
2008-09-03 17:26   ` [patch 29/42] net: Unbreak userspace which includes linux/mroute.h Greg KH
2008-09-03 19:16     ` Stefan Lippers-Hollmann
2008-09-03 21:16       ` David Miller
2008-09-03 17:26   ` [patch 30/42] sctp: correct bounds check in sctp_setsockopt_auth_key Greg KH
2008-09-03 17:26   ` [patch 31/42] sctp: fix random memory dereference with SCTP_HMAC_IDENT option Greg KH
2008-09-03 17:26   ` [patch 32/42] ipsec: Fix deadlock in xfrm_state management Greg KH
2008-09-03 17:26   ` [patch 33/42] sparc64: Fix overshoot in nid_range() Greg KH
2008-09-03 17:26   ` [patch 34/42] sparc64: Fix cmdline_memory_size handling bugs Greg KH
2008-09-03 17:26   ` [patch 35/42] crypto: authenc - Avoid using clobbered request pointer Greg KH
2008-09-03 17:26   ` Greg KH [this message]
2008-09-03 17:26   ` [patch 37/42] r8169: balance pci_map / pci_unmap pair Greg KH
2008-09-03 17:26   ` [patch 38/42] sunrpc: fix possible overrun on read of /proc/sys/sunrpc/transports Greg KH
2008-09-03 17:26   ` [patch 39/42] nfsd: fix buffer overrun decoding NFSv4 acl Greg KH
2008-09-03 17:26   ` [patch 40/42] x86: work around MTRR mask setting, v2 Greg KH
2008-09-03 17:26   ` [patch 41/42] KVM: MMU: Fix torn shadow pte Greg KH
2008-09-03 17:26   ` [patch 42/42] sata_mv: dont issue two DMA commands concurrently Greg KH
2008-09-04  2:39   ` [patch 00/42] 2.6.26-stable review Henrique de Moraes Holschuh
2008-09-04 12:21     ` Andi Kleen
2008-09-04 12:28       ` Milan Broz
2008-09-04 13:58         ` Andi Kleen
2008-09-12 14:22     ` Pavel Machek
2008-09-12 15:37       ` Andi Kleen
2008-09-12 19:46         ` Henrique de Moraes Holschuh
2008-09-13 16:56           ` Pavel Machek

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=20080903172640.GK7731@suse.de \
    --to=gregkh@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=cavokz@gmail.com \
    --cc=cebbert@redhat.com \
    --cc=chuckw@quantumlinux.com \
    --cc=davej@redhat.com \
    --cc=davem@davemloft.net \
    --cc=eteo@redhat.com \
    --cc=jake@lwn.net \
    --cc=jmforbes@linuxtx.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcarlson@broadcom.com \
    --cc=mchan@broadcom.com \
    --cc=mkrufky@linuxtv.org \
    --cc=rbranco@la.checkpoint.com \
    --cc=rdunlap@xenotime.net \
    --cc=reviews@ml.cw.f00f.org \
    --cc=stable@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=tytso@mit.edu \
    --cc=w@1wt.eu \
    --cc=zwane@arm.linux.org.uk \
    /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;
as well as URLs for NNTP newsgroup(s).