blob: d1c333edd4d2cdb20b3fe304e918ffaf1d6fbb1d [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
Joel Stanley6453c892018-03-29 17:37:51 +11004Subject: [PATCH 2/4] tg3: APE heartbeat changes
Joel Stanleyb8cdd192018-02-20 11:28:06 +10305
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
Joel Stanleya8648732018-02-05 14:12:27 +103032index 8995cfefbfcf..0cbf537c8f6c 100644
Joel Stanleyb8cdd192018-02-20 11:28:06 +103033--- a/drivers/net/ethernet/broadcom/tg3.c
34+++ b/drivers/net/ethernet/broadcom/tg3.c
Joel Stanleya8648732018-02-05 14:12:27 +103035@@ -820,7 +820,7 @@ static int tg3_ape_event_lock(struct tg3 *tp, u32 timeout_us)
Joel Stanleyb8cdd192018-02-20 11:28:06 +103036
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
Joel Stanleya8648732018-02-05 14:12:27 +103044@@ -922,8 +922,8 @@ static int tg3_ape_send_event(struct tg3 *tp, u32 event)
Joel Stanleyb8cdd192018-02-20 11:28:06 +103045 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
Joel Stanleya8648732018-02-05 14:12:27 +103055@@ -946,6 +946,7 @@ static void tg3_ape_driver_state_change(struct tg3 *tp, int kind)
Joel Stanleyb8cdd192018-02-20 11:28:06 +103056
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,
Joel Stanleya8648732018-02-05 14:12:27 +103063@@ -962,13 +963,6 @@ static void tg3_ape_driver_state_change(struct tg3 *tp, int kind)
Joel Stanleyb8cdd192018-02-20 11:28:06 +103064 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,
Joel Stanleya8648732018-02-05 14:12:27 +103077@@ -990,6 +984,18 @@ static void tg3_ape_driver_state_change(struct tg3 *tp, int kind)
Joel Stanleyb8cdd192018-02-20 11:28:06 +103078 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;
Joel Stanleya8648732018-02-05 14:12:27 +103096@@ -7262,6 +7268,7 @@ static int tg3_poll_msix(struct napi_struct *napi, int budget)
Joel Stanleyb8cdd192018-02-20 11:28:06 +103097 }
98 }
99
100+ tg3_send_ape_heartbeat(tp, TG3_APE_HB_INTERVAL << 1);
101 return work_done;
102
103 tx_recovery:
Joel Stanleya8648732018-02-05 14:12:27 +1030104@@ -7344,6 +7351,7 @@ static int tg3_poll(struct napi_struct *napi, int budget)
Joel Stanleyb8cdd192018-02-20 11:28:06 +1030105 }
106 }
107
108+ tg3_send_ape_heartbeat(tp, TG3_APE_HB_INTERVAL << 1);
109 return work_done;
110
111 tx_recovery:
Joel Stanleya8648732018-02-05 14:12:27 +1030112@@ -10732,7 +10740,7 @@ static int tg3_reset_hw(struct tg3 *tp, bool reset_phy)
Joel Stanleyb8cdd192018-02-20 11:28:06 +1030113 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
Joel Stanleya8648732018-02-05 14:12:27 +1030121@@ -11077,6 +11085,9 @@ static void tg3_timer(struct timer_list *t)
Joel Stanleyb8cdd192018-02-20 11:28:06 +1030122 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:
Joel Stanleya8648732018-02-05 14:12:27 +1030131@@ -16636,6 +16647,8 @@ static int tg3_get_invariants(struct tg3 *tp, const struct pci_device_id *ent)
Joel Stanleyb8cdd192018-02-20 11:28:06 +1030132 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
Joel Stanleya8648732018-02-05 14:12:27 +1030141index 1f0271fa7c74..4b9d2906da90 100644
Joel Stanleyb8cdd192018-02-20 11:28:06 +1030142--- a/drivers/net/ethernet/broadcom/tg3.h
143+++ b/drivers/net/ethernet/broadcom/tg3.h
Joel Stanleya8648732018-02-05 14:12:27 +1030144@@ -2499,6 +2499,7 @@
Joel Stanleyb8cdd192018-02-20 11:28:06 +1030145 #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
Joel Stanleya8648732018-02-05 14:12:27 +1030152@@ -3413,6 +3414,10 @@ struct tg3 {
Joel Stanleyb8cdd192018-02-20 11:28:06 +1030153 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