History

qed: prevent a fw assert during device shutdown

Device firmware can assert if the device shutdown path in driver encounters an async. events from mfw (processed in qed_mcp_handle_events()) after qed_mcp_unload_req() returns. A call to qed_mcp_unload_req() currently marks the device as inactive and thus stops any new events, but there is a windows where in-flight events might still be received by the driver. To prevent this race condition, atomically set QED_MCP_BYPASS_PROC_BIT in qed_mcp_unload_req() to make sure qed_mcp_handle_events() ignores all events. Wait for any event that might already be in-process to complete by monitoring QED_MCP_IN_PROCESSING_BIT.

Venkata Sudheer Kumar Bhavaraju committed 4 years ago

Commit ca2d5f11 parent 57ea56b3 files · +51 −2Browse files

Unified · Split

3 files
  1. drivers/net/ethernet/qlogic/qed/qed_dev.c +3 −0
  2. drivers/net/ethernet/qlogic/qed/qed_mcp.c +40 −2
  3. drivers/net/ethernet/qlogic/qed/qed_mcp.h +8 −0
drivers/net/ethernet/qlogic/qed/qed_dev.c+3−0
@@ -3098,6 +3098,9 @@ int qed_hw_init(struct qed_dev *cdev, struct qed_hw_init_params *p_params) · 3097 unmodified lines
30983098 continue;
30993099 }
31003100
3101+ /* Some flows may keep variable set */
3102+ p_hwfn->mcp_info->mcp_handling_status = 0;
3103+
31013104 rc = qed_calc_hw_mode(p_hwfn);
31023105 if (rc)
31033106 return rc;
drivers/net/ethernet/qlogic/qed/qed_mcp.c+40−2
@@ -140,7 +140,7 @@ static struct qed_mcp_cmd_elem *qed_mcp_cmd_get_elem(struct qed_hwfn *p_hwfn, · 139 unmodified lines
140140 int qed_mcp_free(struct qed_hwfn *p_hwfn)
141141 {
142142 if (p_hwfn->mcp_info) {
143− struct qed_mcp_cmd_elem *p_cmd_elem, *p_tmp;
143+ struct qed_mcp_cmd_elem *p_cmd_elem = NULL, *p_tmp;
144144
145145 kfree(p_hwfn->mcp_info->mfw_mb_cur);
146146 kfree(p_hwfn->mcp_info->mfw_mb_shadow);
@@ -249,6 +249,7 @@ int qed_mcp_cmd_init(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) · 102 unmodified lines
249249 /* Initialize the MFW spinlock */
250250 spin_lock_init(&p_info->cmd_lock);
251251 spin_lock_init(&p_info->link_lock);
252+ spin_lock_init(&p_info->unload_lock);
252253
253254 INIT_LIST_HEAD(&p_info->cmd_list);
254255
@@ -1095,10 +1096,15 @@ int qed_mcp_load_done(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) · 840 unmodified lines
10951096 return 0;
10961097 }
10971098
1099+#define MFW_COMPLETION_MAX_ITER 5000
1100+#define MFW_COMPLETION_INTERVAL_MS 1
1101+
10981102 int qed_mcp_unload_req(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
10991103 {
11001104 struct qed_mcp_mb_params mb_params;
1105+ u32 cnt = MFW_COMPLETION_MAX_ITER;
11011106 u32 wol_param;
1107+ int rc;
11021108
11031109 switch (p_hwfn->cdev->wol_config) {
11041110 case QED_OV_WOL_DISABLED:
@@ -1121,7 +1127,23 @@ int qed_mcp_unload_req(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) · 16 unmodified lines
11211127 mb_params.param = wol_param;
11221128 mb_params.flags = QED_MB_FLAG_CAN_SLEEP | QED_MB_FLAG_AVOID_BLOCK;
11231129
1124− return qed_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
1130+ spin_lock_bh(&p_hwfn->mcp_info->unload_lock);
1131+ set_bit(QED_MCP_BYPASS_PROC_BIT,
1132+ &p_hwfn->mcp_info->mcp_handling_status);
1133+ spin_unlock_bh(&p_hwfn->mcp_info->unload_lock);
1134+
1135+ rc = qed_mcp_cmd_and_union(p_hwfn, p_ptt, &mb_params);
1136+
1137+ while (test_bit(QED_MCP_IN_PROCESSING_BIT,
1138+ &p_hwfn->mcp_info->mcp_handling_status) && --cnt)
1139+ msleep(MFW_COMPLETION_INTERVAL_MS);
1140+
1141+ if (!cnt)
1142+ DP_NOTICE(p_hwfn,
1143+ "Failed to wait MFW event completion after %d msec\n",
1144+ MFW_COMPLETION_MAX_ITER * MFW_COMPLETION_INTERVAL_MS);
1145+
1146+ return rc;
11251147 }
11261148
11271149 int qed_mcp_unload_done(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
@@ -2021,6 +2043,19 @@ int qed_mcp_handle_events(struct qed_hwfn *p_hwfn, · 893 unmodified lines
20212043 "Msg [%d] - old CMD 0x%02x, new CMD 0x%02x\n",
20222044 i, info->mfw_mb_shadow[i], info->mfw_mb_cur[i]);
20232045
2046+ spin_lock_bh(&p_hwfn->mcp_info->unload_lock);
2047+ if (test_bit(QED_MCP_BYPASS_PROC_BIT,
2048+ &p_hwfn->mcp_info->mcp_handling_status)) {
2049+ spin_unlock_bh(&p_hwfn->mcp_info->unload_lock);
2050+ DP_INFO(p_hwfn,
2051+ "Msg [%d] is bypassed on unload flow\n", i);
2052+ continue;
2053+ }
2054+
2055+ set_bit(QED_MCP_IN_PROCESSING_BIT,
2056+ &p_hwfn->mcp_info->mcp_handling_status);
2057+ spin_unlock_bh(&p_hwfn->mcp_info->unload_lock);
2058+
20242059 switch (i) {
20252060 case MFW_DRV_MSG_LINK_CHANGE:
20262061 qed_mcp_handle_link_change(p_hwfn, p_ptt, false);
@@ -2074,6 +2109,9 @@ int qed_mcp_handle_events(struct qed_hwfn *p_hwfn, · 47 unmodified lines
20742109 DP_INFO(p_hwfn, "Unimplemented MFW message %d\n", i);
20752110 rc = -EINVAL;
20762111 }
2112+
2113+ clear_bit(QED_MCP_IN_PROCESSING_BIT,
2114+ &p_hwfn->mcp_info->mcp_handling_status);
20772115 }
20782116
20792117 /* ACK everything */
drivers/net/ethernet/qlogic/qed/qed_mcp.h+8−0
@@ -788,6 +788,14 @@ struct qed_mcp_info { · 787 unmodified lines
788788
789789 /* S/N for debug data mailbox commands */
790790 atomic_t dbg_data_seq;
791+
792+ /* Spinlock used to sync the flag mcp_handling_status with
793+ * the mfw events handler
794+ */
795+ spinlock_t unload_lock;
796+ unsigned long mcp_handling_status;
797+#define QED_MCP_BYPASS_PROC_BIT 0
798+#define QED_MCP_IN_PROCESSING_BIT 1
791799 };
792800
793801 struct qed_mcp_mb_params {