blob: 7f986b5aefe24a996eb9cd2aa8394a55d8820783 [file] [log] [blame]
Joel Stanleyb8cdd192018-02-20 11:28:06 +10301From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2From: Prashant Sreedharan <prashant.sreedharan@broadcom.com>
3Date: Mon, 19 Feb 2018 12:27:04 +0530
4Subject: [PATCH 3/4] tg3: APE heartbeat changes
5
6In ungraceful host shutdown or driver crash case BMC connectivity is
7lost. APE firmware is missing the driver state in this
8case to keep the BMC connectivity alive.
9This patch has below change to address this issue.
10
11Heartbeat mechanism with APE firmware. This heartbeat mechanism
12is needed to notify the APE firmware about driver state.
13
14This patch also has the change in wait time for APE event from
151ms to 20ms as there can be some delay in getting response.
16
17v2: Drop inline keyword as per David suggestion.
18
19Signed-off-by: Prashant Sreedharan <prashant.sreedharan@broadcom.com>
20Signed-off-by: Satish Baddipadige <satish.baddipadige@broadcom.com>
21Signed-off-by: Siva Reddy Kallam <siva.kallam@broadcom.com>
22Acked-by: Michael Chan <michael.chan@broadcom.com>
23Signed-off-by: David S. Miller <davem@davemloft.net>
24(cherry picked from commit 506b0a395f26e52b3f18827e0de1be051acb77ab)
25Signed-off-by: Joel Stanley <joel@jms.id.au>
26---
27 drivers/net/ethernet/broadcom/tg3.c | 35 ++++++++++++++++++++++++-----------
28 drivers/net/ethernet/broadcom/tg3.h | 5 +++++
29 2 files changed, 29 insertions(+), 11 deletions(-)
30
31diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
32index aef3fcf2f5b9..703af1bd196c 100644
33--- a/drivers/net/ethernet/broadcom/tg3.c
34+++ b/drivers/net/ethernet/broadcom/tg3.c
35@@ -818,7 +818,7 @@ static int tg3_ape_event_lock(struct tg3 *tp, u32 timeout_us)
36
37 tg3_ape_unlock(tp, TG3_APE_LOCK_MEM);
38
39- udelay(10);
40+ usleep_range(10, 20);
41 timeout_us -= (timeout_us > 10) ? 10 : timeout_us;
42 }
43
44@@ -920,8 +920,8 @@ static int tg3_ape_send_event(struct tg3 *tp, u32 event)
45 if (!(apedata & APE_FW_STATUS_READY))
46 return -EAGAIN;
47
48- /* Wait for up to 1 millisecond for APE to service previous event. */
49- err = tg3_ape_event_lock(tp, 1000);
50+ /* Wait for up to 20 millisecond for APE to service previous event. */
51+ err = tg3_ape_event_lock(tp, 20000);
52 if (err)
53 return err;
54
55@@ -944,6 +944,7 @@ static void tg3_ape_driver_state_change(struct tg3 *tp, int kind)
56
57 switch (kind) {
58 case RESET_KIND_INIT:
59+ tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_COUNT, tp->ape_hb++);
60 tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG,
61 APE_HOST_SEG_SIG_MAGIC);
62 tg3_ape_write32(tp, TG3_APE_HOST_SEG_LEN,
63@@ -960,13 +961,6 @@ static void tg3_ape_driver_state_change(struct tg3 *tp, int kind)
64 event = APE_EVENT_STATUS_STATE_START;
65 break;
66 case RESET_KIND_SHUTDOWN:
67- /* With the interface we are currently using,
68- * APE does not track driver state. Wiping
69- * out the HOST SEGMENT SIGNATURE forces
70- * the APE to assume OS absent status.
71- */
72- tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, 0x0);
73-
74 if (device_may_wakeup(&tp->pdev->dev) &&
75 tg3_flag(tp, WOL_ENABLE)) {
76 tg3_ape_write32(tp, TG3_APE_HOST_WOL_SPEED,
77@@ -988,6 +982,18 @@ static void tg3_ape_driver_state_change(struct tg3 *tp, int kind)
78 tg3_ape_send_event(tp, event);
79 }
80
81+static void tg3_send_ape_heartbeat(struct tg3 *tp,
82+ unsigned long interval)
83+{
84+ /* Check if hb interval has exceeded */
85+ if (!tg3_flag(tp, ENABLE_APE) ||
86+ time_before(jiffies, tp->ape_hb_jiffies + interval))
87+ return;
88+
89+ tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_COUNT, tp->ape_hb++);
90+ tp->ape_hb_jiffies = jiffies;
91+}
92+
93 static void tg3_disable_ints(struct tg3 *tp)
94 {
95 int i;
96@@ -7260,6 +7266,7 @@ static int tg3_poll_msix(struct napi_struct *napi, int budget)
97 }
98 }
99
100+ tg3_send_ape_heartbeat(tp, TG3_APE_HB_INTERVAL << 1);
101 return work_done;
102
103 tx_recovery:
104@@ -7342,6 +7349,7 @@ static int tg3_poll(struct napi_struct *napi, int budget)
105 }
106 }
107
108+ tg3_send_ape_heartbeat(tp, TG3_APE_HB_INTERVAL << 1);
109 return work_done;
110
111 tx_recovery:
112@@ -10720,7 +10728,7 @@ static int tg3_reset_hw(struct tg3 *tp, bool reset_phy)
113 if (tg3_flag(tp, ENABLE_APE))
114 /* Write our heartbeat update interval to APE. */
115 tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_INT_MS,
116- APE_HOST_HEARTBEAT_INT_DISABLE);
117+ APE_HOST_HEARTBEAT_INT_5SEC);
118
119 tg3_write_sig_post_reset(tp, RESET_KIND_INIT);
120
121@@ -11065,6 +11073,9 @@ static void tg3_timer(unsigned long __opaque)
122 tp->asf_counter = tp->asf_multiplier;
123 }
124
125+ /* Update the APE heartbeat every 5 seconds.*/
126+ tg3_send_ape_heartbeat(tp, TG3_APE_HB_INTERVAL);
127+
128 spin_unlock(&tp->lock);
129
130 restart_timer:
131@@ -16625,6 +16636,8 @@ static int tg3_get_invariants(struct tg3 *tp, const struct pci_device_id *ent)
132 pci_state_reg);
133
134 tg3_ape_lock_init(tp);
135+ tp->ape_hb_interval =
136+ msecs_to_jiffies(APE_HOST_HEARTBEAT_INT_5SEC);
137 }
138
139 /* Set up tp->grc_local_ctrl before calling
140diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
141index c2d02d02d1e6..99578ab2ddad 100644
142--- a/drivers/net/ethernet/broadcom/tg3.h
143+++ b/drivers/net/ethernet/broadcom/tg3.h
144@@ -2494,6 +2494,7 @@
145 #define TG3_APE_LOCK_PHY3 5
146 #define TG3_APE_LOCK_GPIO 7
147
148+#define TG3_APE_HB_INTERVAL (tp->ape_hb_interval)
149 #define TG3_EEPROM_SB_F1R2_MBA_OFF 0x10
150
151
152@@ -3408,6 +3409,10 @@ struct tg3 {
153 struct device *hwmon_dev;
154 bool link_up;
155 bool pcierr_recovery;
156+
157+ u32 ape_hb;
158+ unsigned long ape_hb_interval;
159+ unsigned long ape_hb_jiffies;
160 };
161
162 /* Accessor macros for chip and asic attributes