Joel Stanley | b8cdd19 | 2018-02-20 11:28:06 +1030 | [diff] [blame] | 1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | From: Prashant Sreedharan <prashant.sreedharan@broadcom.com> |
| 3 | Date: Mon, 19 Feb 2018 12:27:04 +0530 |
Joel Stanley | 6453c89 | 2018-03-29 17:37:51 +1100 | [diff] [blame^] | 4 | Subject: [PATCH 2/4] tg3: APE heartbeat changes |
Joel Stanley | b8cdd19 | 2018-02-20 11:28:06 +1030 | [diff] [blame] | 5 | |
| 6 | In ungraceful host shutdown or driver crash case BMC connectivity is |
| 7 | lost. APE firmware is missing the driver state in this |
| 8 | case to keep the BMC connectivity alive. |
| 9 | This patch has below change to address this issue. |
| 10 | |
| 11 | Heartbeat mechanism with APE firmware. This heartbeat mechanism |
| 12 | is needed to notify the APE firmware about driver state. |
| 13 | |
| 14 | This patch also has the change in wait time for APE event from |
| 15 | 1ms to 20ms as there can be some delay in getting response. |
| 16 | |
| 17 | v2: Drop inline keyword as per David suggestion. |
| 18 | |
| 19 | Signed-off-by: Prashant Sreedharan <prashant.sreedharan@broadcom.com> |
| 20 | Signed-off-by: Satish Baddipadige <satish.baddipadige@broadcom.com> |
| 21 | Signed-off-by: Siva Reddy Kallam <siva.kallam@broadcom.com> |
| 22 | Acked-by: Michael Chan <michael.chan@broadcom.com> |
| 23 | Signed-off-by: David S. Miller <davem@davemloft.net> |
| 24 | (cherry picked from commit 506b0a395f26e52b3f18827e0de1be051acb77ab) |
| 25 | Signed-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 | |
| 31 | diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c |
Joel Stanley | a864873 | 2018-02-05 14:12:27 +1030 | [diff] [blame] | 32 | index 8995cfefbfcf..0cbf537c8f6c 100644 |
Joel Stanley | b8cdd19 | 2018-02-20 11:28:06 +1030 | [diff] [blame] | 33 | --- a/drivers/net/ethernet/broadcom/tg3.c |
| 34 | +++ b/drivers/net/ethernet/broadcom/tg3.c |
Joel Stanley | a864873 | 2018-02-05 14:12:27 +1030 | [diff] [blame] | 35 | @@ -820,7 +820,7 @@ static int tg3_ape_event_lock(struct tg3 *tp, u32 timeout_us) |
Joel Stanley | b8cdd19 | 2018-02-20 11:28:06 +1030 | [diff] [blame] | 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 | |
Joel Stanley | a864873 | 2018-02-05 14:12:27 +1030 | [diff] [blame] | 44 | @@ -922,8 +922,8 @@ static int tg3_ape_send_event(struct tg3 *tp, u32 event) |
Joel Stanley | b8cdd19 | 2018-02-20 11:28:06 +1030 | [diff] [blame] | 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 | |
Joel Stanley | a864873 | 2018-02-05 14:12:27 +1030 | [diff] [blame] | 55 | @@ -946,6 +946,7 @@ static void tg3_ape_driver_state_change(struct tg3 *tp, int kind) |
Joel Stanley | b8cdd19 | 2018-02-20 11:28:06 +1030 | [diff] [blame] | 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, |
Joel Stanley | a864873 | 2018-02-05 14:12:27 +1030 | [diff] [blame] | 63 | @@ -962,13 +963,6 @@ static void tg3_ape_driver_state_change(struct tg3 *tp, int kind) |
Joel Stanley | b8cdd19 | 2018-02-20 11:28:06 +1030 | [diff] [blame] | 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, |
Joel Stanley | a864873 | 2018-02-05 14:12:27 +1030 | [diff] [blame] | 77 | @@ -990,6 +984,18 @@ static void tg3_ape_driver_state_change(struct tg3 *tp, int kind) |
Joel Stanley | b8cdd19 | 2018-02-20 11:28:06 +1030 | [diff] [blame] | 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; |
Joel Stanley | a864873 | 2018-02-05 14:12:27 +1030 | [diff] [blame] | 96 | @@ -7262,6 +7268,7 @@ static int tg3_poll_msix(struct napi_struct *napi, int budget) |
Joel Stanley | b8cdd19 | 2018-02-20 11:28:06 +1030 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | |
| 100 | + tg3_send_ape_heartbeat(tp, TG3_APE_HB_INTERVAL << 1); |
| 101 | return work_done; |
| 102 | |
| 103 | tx_recovery: |
Joel Stanley | a864873 | 2018-02-05 14:12:27 +1030 | [diff] [blame] | 104 | @@ -7344,6 +7351,7 @@ static int tg3_poll(struct napi_struct *napi, int budget) |
Joel Stanley | b8cdd19 | 2018-02-20 11:28:06 +1030 | [diff] [blame] | 105 | } |
| 106 | } |
| 107 | |
| 108 | + tg3_send_ape_heartbeat(tp, TG3_APE_HB_INTERVAL << 1); |
| 109 | return work_done; |
| 110 | |
| 111 | tx_recovery: |
Joel Stanley | a864873 | 2018-02-05 14:12:27 +1030 | [diff] [blame] | 112 | @@ -10732,7 +10740,7 @@ static int tg3_reset_hw(struct tg3 *tp, bool reset_phy) |
Joel Stanley | b8cdd19 | 2018-02-20 11:28:06 +1030 | [diff] [blame] | 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 | |
Joel Stanley | a864873 | 2018-02-05 14:12:27 +1030 | [diff] [blame] | 121 | @@ -11077,6 +11085,9 @@ static void tg3_timer(struct timer_list *t) |
Joel Stanley | b8cdd19 | 2018-02-20 11:28:06 +1030 | [diff] [blame] | 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: |
Joel Stanley | a864873 | 2018-02-05 14:12:27 +1030 | [diff] [blame] | 131 | @@ -16636,6 +16647,8 @@ static int tg3_get_invariants(struct tg3 *tp, const struct pci_device_id *ent) |
Joel Stanley | b8cdd19 | 2018-02-20 11:28:06 +1030 | [diff] [blame] | 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 |
| 140 | diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h |
Joel Stanley | a864873 | 2018-02-05 14:12:27 +1030 | [diff] [blame] | 141 | index 1f0271fa7c74..4b9d2906da90 100644 |
Joel Stanley | b8cdd19 | 2018-02-20 11:28:06 +1030 | [diff] [blame] | 142 | --- a/drivers/net/ethernet/broadcom/tg3.h |
| 143 | +++ b/drivers/net/ethernet/broadcom/tg3.h |
Joel Stanley | a864873 | 2018-02-05 14:12:27 +1030 | [diff] [blame] | 144 | @@ -2499,6 +2499,7 @@ |
Joel Stanley | b8cdd19 | 2018-02-20 11:28:06 +1030 | [diff] [blame] | 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 | |
Joel Stanley | a864873 | 2018-02-05 14:12:27 +1030 | [diff] [blame] | 152 | @@ -3413,6 +3414,10 @@ struct tg3 { |
Joel Stanley | b8cdd19 | 2018-02-20 11:28:06 +1030 | [diff] [blame] | 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 |