Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'bnxt_en-health-and-error-recovery'

Michael Chan says:

====================
bnxt_en: health and error recovery.

This patchset implements adapter health and error recovery. The status
is reported through several devlink reporters and the driver will
initiate and complete the recovery process using the devlink infrastructure.

v2: Added 4 patches at the beginning of the patchset to clean up error code
handling related to firmware messages and to convert to use standard
error codes.

Removed the dropping of rtnl_lock in bnxt_close().

Broke up the patches some more for better patch organization and
future bisection.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+1174 -250
+781 -107
drivers/net/ethernet/broadcom/bnxt/bnxt.c
··· 254 254 ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED, 255 255 ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE, 256 256 ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE, 257 + ASYNC_EVENT_CMPL_EVENT_ID_RESET_NOTIFY, 258 + ASYNC_EVENT_CMPL_EVENT_ID_ERROR_RECOVERY, 257 259 }; 258 260 259 261 static struct workqueue_struct *bnxt_pf_wq; ··· 1140 1138 return 0; 1141 1139 } 1142 1140 1141 + static void bnxt_queue_fw_reset_work(struct bnxt *bp, unsigned long delay) 1142 + { 1143 + if (BNXT_PF(bp)) 1144 + queue_delayed_work(bnxt_pf_wq, &bp->fw_reset_task, delay); 1145 + else 1146 + schedule_delayed_work(&bp->fw_reset_task, delay); 1147 + } 1148 + 1143 1149 static void bnxt_queue_sp_work(struct bnxt *bp) 1144 1150 { 1145 1151 if (BNXT_PF(bp)) ··· 1906 1896 return bnxt_rx_pkt(bp, cpr, raw_cons, event); 1907 1897 } 1908 1898 1899 + u32 bnxt_fw_health_readl(struct bnxt *bp, int reg_idx) 1900 + { 1901 + struct bnxt_fw_health *fw_health = bp->fw_health; 1902 + u32 reg = fw_health->regs[reg_idx]; 1903 + u32 reg_type, reg_off, val = 0; 1904 + 1905 + reg_type = BNXT_FW_HEALTH_REG_TYPE(reg); 1906 + reg_off = BNXT_FW_HEALTH_REG_OFF(reg); 1907 + switch (reg_type) { 1908 + case BNXT_FW_HEALTH_REG_TYPE_CFG: 1909 + pci_read_config_dword(bp->pdev, reg_off, &val); 1910 + break; 1911 + case BNXT_FW_HEALTH_REG_TYPE_GRC: 1912 + reg_off = fw_health->mapped_regs[reg_idx]; 1913 + /* fall through */ 1914 + case BNXT_FW_HEALTH_REG_TYPE_BAR0: 1915 + val = readl(bp->bar0 + reg_off); 1916 + break; 1917 + case BNXT_FW_HEALTH_REG_TYPE_BAR1: 1918 + val = readl(bp->bar1 + reg_off); 1919 + break; 1920 + } 1921 + if (reg_idx == BNXT_FW_RESET_INPROG_REG) 1922 + val &= fw_health->fw_reset_inprog_reg_mask; 1923 + return val; 1924 + } 1925 + 1909 1926 #define BNXT_GET_EVENT_PORT(data) \ 1910 1927 ((data) & \ 1911 1928 ASYNC_EVENT_CMPL_PORT_CONN_NOT_ALLOWED_EVENT_DATA1_PORT_ID_MASK) ··· 1988 1951 goto async_event_process_exit; 1989 1952 set_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event); 1990 1953 break; 1954 + case ASYNC_EVENT_CMPL_EVENT_ID_RESET_NOTIFY: { 1955 + u32 data1 = le32_to_cpu(cmpl->event_data1); 1956 + 1957 + bp->fw_reset_timestamp = jiffies; 1958 + bp->fw_reset_min_dsecs = cmpl->timestamp_lo; 1959 + if (!bp->fw_reset_min_dsecs) 1960 + bp->fw_reset_min_dsecs = BNXT_DFLT_FW_RST_MIN_DSECS; 1961 + bp->fw_reset_max_dsecs = le16_to_cpu(cmpl->timestamp_hi); 1962 + if (!bp->fw_reset_max_dsecs) 1963 + bp->fw_reset_max_dsecs = BNXT_DFLT_FW_RST_MAX_DSECS; 1964 + if (EVENT_DATA1_RESET_NOTIFY_FATAL(data1)) { 1965 + netdev_warn(bp->dev, "Firmware fatal reset event received\n"); 1966 + set_bit(BNXT_STATE_FW_FATAL_COND, &bp->state); 1967 + } else { 1968 + netdev_warn(bp->dev, "Firmware non-fatal reset event received, max wait time %d msec\n", 1969 + bp->fw_reset_max_dsecs * 100); 1970 + } 1971 + set_bit(BNXT_FW_RESET_NOTIFY_SP_EVENT, &bp->sp_event); 1972 + break; 1973 + } 1974 + case ASYNC_EVENT_CMPL_EVENT_ID_ERROR_RECOVERY: { 1975 + struct bnxt_fw_health *fw_health = bp->fw_health; 1976 + u32 data1 = le32_to_cpu(cmpl->event_data1); 1977 + 1978 + if (!fw_health) 1979 + goto async_event_process_exit; 1980 + 1981 + fw_health->enabled = EVENT_DATA1_RECOVERY_ENABLED(data1); 1982 + fw_health->master = EVENT_DATA1_RECOVERY_MASTER_FUNC(data1); 1983 + if (!fw_health->enabled) 1984 + break; 1985 + 1986 + if (netif_msg_drv(bp)) 1987 + netdev_info(bp->dev, "Error recovery info: error recovery[%d], master[%d], reset count[0x%x], health status: 0x%x\n", 1988 + fw_health->enabled, fw_health->master, 1989 + bnxt_fw_health_readl(bp, 1990 + BNXT_FW_RESET_CNT_REG), 1991 + bnxt_fw_health_readl(bp, 1992 + BNXT_FW_HEALTH_REG)); 1993 + fw_health->tmr_multiplier = 1994 + DIV_ROUND_UP(fw_health->polling_dsecs * HZ, 1995 + bp->current_interval * 10); 1996 + fw_health->tmr_counter = fw_health->tmr_multiplier; 1997 + fw_health->last_fw_heartbeat = 1998 + bnxt_fw_health_readl(bp, BNXT_FW_HEARTBEAT_REG); 1999 + fw_health->last_fw_reset_cnt = 2000 + bnxt_fw_health_readl(bp, BNXT_FW_RESET_CNT_REG); 2001 + goto async_event_process_exit; 2002 + } 1991 2003 default: 1992 2004 goto async_event_process_exit; 1993 2005 } ··· 3641 3555 { 3642 3556 struct pci_dev *pdev = bp->pdev; 3643 3557 3558 + if (bp->hwrm_cmd_kong_resp_addr) 3559 + return 0; 3560 + 3644 3561 bp->hwrm_cmd_kong_resp_addr = 3645 3562 dma_alloc_coherent(&pdev->dev, PAGE_SIZE, 3646 3563 &bp->hwrm_cmd_kong_resp_dma_addr, ··· 3682 3593 static int bnxt_alloc_hwrm_short_cmd_req(struct bnxt *bp) 3683 3594 { 3684 3595 struct pci_dev *pdev = bp->pdev; 3596 + 3597 + if (bp->hwrm_short_cmd_req_addr) 3598 + return 0; 3685 3599 3686 3600 bp->hwrm_short_cmd_req_addr = 3687 3601 dma_alloc_coherent(&pdev->dev, bp->hwrm_max_ext_req_len, ··· 4140 4048 req->resp_addr = cpu_to_le64(bp->hwrm_cmd_resp_dma_addr); 4141 4049 } 4142 4050 4051 + static int bnxt_hwrm_to_stderr(u32 hwrm_err) 4052 + { 4053 + switch (hwrm_err) { 4054 + case HWRM_ERR_CODE_SUCCESS: 4055 + return 0; 4056 + case HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED: 4057 + return -EACCES; 4058 + case HWRM_ERR_CODE_RESOURCE_ALLOC_ERROR: 4059 + return -ENOSPC; 4060 + case HWRM_ERR_CODE_INVALID_PARAMS: 4061 + case HWRM_ERR_CODE_INVALID_FLAGS: 4062 + case HWRM_ERR_CODE_INVALID_ENABLES: 4063 + case HWRM_ERR_CODE_UNSUPPORTED_TLV: 4064 + case HWRM_ERR_CODE_UNSUPPORTED_OPTION_ERR: 4065 + return -EINVAL; 4066 + case HWRM_ERR_CODE_NO_BUFFER: 4067 + return -ENOMEM; 4068 + case HWRM_ERR_CODE_HOT_RESET_PROGRESS: 4069 + return -EAGAIN; 4070 + case HWRM_ERR_CODE_CMD_NOT_SUPPORTED: 4071 + return -EOPNOTSUPP; 4072 + default: 4073 + return -EIO; 4074 + } 4075 + } 4076 + 4143 4077 static int bnxt_hwrm_do_send_msg(struct bnxt *bp, void *msg, u32 msg_len, 4144 4078 int timeout, bool silent) 4145 4079 { ··· 4182 4064 u8 *resp_addr = (u8 *)bp->hwrm_cmd_resp_addr; 4183 4065 u32 bar_offset = BNXT_GRCPF_REG_CHIMP_COMM; 4184 4066 u16 dst = BNXT_HWRM_CHNL_CHIMP; 4067 + 4068 + if (test_bit(BNXT_STATE_FW_FATAL_COND, &bp->state)) 4069 + return -EBUSY; 4185 4070 4186 4071 if (msg_len > BNXT_HWRM_MAX_REQ_LEN) { 4187 4072 if (msg_len > bp->hwrm_max_ext_req_len || ··· 4250 4129 /* Ring channel doorbell */ 4251 4130 writel(1, bp->bar0 + doorbell_offset); 4252 4131 4132 + if (!pci_is_enabled(bp->pdev)) 4133 + return 0; 4134 + 4253 4135 if (!timeout) 4254 4136 timeout = DFLT_HWRM_CMD_TIMEOUT; 4255 4137 /* convert timeout to usec */ ··· 4284 4160 } 4285 4161 4286 4162 if (bp->hwrm_intr_seq_id != (u16)~seq_id) { 4287 - netdev_err(bp->dev, "Resp cmpl intr err msg: 0x%x\n", 4288 - le16_to_cpu(req->req_type)); 4289 - return -1; 4163 + if (!silent) 4164 + netdev_err(bp->dev, "Resp cmpl intr err msg: 0x%x\n", 4165 + le16_to_cpu(req->req_type)); 4166 + return -EBUSY; 4290 4167 } 4291 4168 len = (le32_to_cpu(*resp_len) & HWRM_RESP_LEN_MASK) >> 4292 4169 HWRM_RESP_LEN_SFT; ··· 4311 4186 } 4312 4187 4313 4188 if (i >= tmo_count) { 4314 - netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d\n", 4315 - HWRM_TOTAL_TIMEOUT(i), 4316 - le16_to_cpu(req->req_type), 4317 - le16_to_cpu(req->seq_id), len); 4318 - return -1; 4189 + if (!silent) 4190 + netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d\n", 4191 + HWRM_TOTAL_TIMEOUT(i), 4192 + le16_to_cpu(req->req_type), 4193 + le16_to_cpu(req->seq_id), len); 4194 + return -EBUSY; 4319 4195 } 4320 4196 4321 4197 /* Last byte of resp contains valid bit */ ··· 4330 4204 } 4331 4205 4332 4206 if (j >= HWRM_VALID_BIT_DELAY_USEC) { 4333 - netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d v:%d\n", 4334 - HWRM_TOTAL_TIMEOUT(i), 4335 - le16_to_cpu(req->req_type), 4336 - le16_to_cpu(req->seq_id), len, *valid); 4337 - return -1; 4207 + if (!silent) 4208 + netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d v:%d\n", 4209 + HWRM_TOTAL_TIMEOUT(i), 4210 + le16_to_cpu(req->req_type), 4211 + le16_to_cpu(req->seq_id), len, 4212 + *valid); 4213 + return -EBUSY; 4338 4214 } 4339 4215 } 4340 4216 ··· 4350 4222 netdev_err(bp->dev, "hwrm req_type 0x%x seq id 0x%x error 0x%x\n", 4351 4223 le16_to_cpu(resp->req_type), 4352 4224 le16_to_cpu(resp->seq_id), rc); 4353 - return rc; 4225 + return bnxt_hwrm_to_stderr(rc); 4354 4226 } 4355 4227 4356 4228 int _hwrm_send_message(struct bnxt *bp, void *msg, u32 msg_len, int timeout) ··· 4399 4271 cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD); 4400 4272 4401 4273 memset(async_events_bmap, 0, sizeof(async_events_bmap)); 4402 - for (i = 0; i < ARRAY_SIZE(bnxt_async_events_arr); i++) 4403 - __set_bit(bnxt_async_events_arr[i], async_events_bmap); 4274 + for (i = 0; i < ARRAY_SIZE(bnxt_async_events_arr); i++) { 4275 + u16 event_id = bnxt_async_events_arr[i]; 4404 4276 4277 + if (event_id == ASYNC_EVENT_CMPL_EVENT_ID_ERROR_RECOVERY && 4278 + !(bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY)) 4279 + continue; 4280 + __set_bit(bnxt_async_events_arr[i], async_events_bmap); 4281 + } 4405 4282 if (bmap && bmap_size) { 4406 4283 for (i = 0; i < bmap_size; i++) { 4407 4284 if (test_bit(i, bmap)) ··· 4424 4291 { 4425 4292 struct hwrm_func_drv_rgtr_output *resp = bp->hwrm_cmd_resp_addr; 4426 4293 struct hwrm_func_drv_rgtr_input req = {0}; 4294 + u32 flags; 4427 4295 int rc; 4428 4296 4429 4297 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1); ··· 4434 4300 FUNC_DRV_RGTR_REQ_ENABLES_VER); 4435 4301 4436 4302 req.os_type = cpu_to_le16(FUNC_DRV_RGTR_REQ_OS_TYPE_LINUX); 4437 - req.flags = cpu_to_le32(FUNC_DRV_RGTR_REQ_FLAGS_16BIT_VER_MODE); 4303 + flags = FUNC_DRV_RGTR_REQ_FLAGS_16BIT_VER_MODE | 4304 + FUNC_DRV_RGTR_REQ_FLAGS_HOT_RESET_SUPPORT; 4305 + if (bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY) 4306 + flags |= FUNC_DRV_RGTR_REQ_FLAGS_ERROR_RECOVERY_SUPPORT; 4307 + req.flags = cpu_to_le32(flags); 4438 4308 req.ver_maj_8b = DRV_VER_MAJ; 4439 4309 req.ver_min_8b = DRV_VER_MIN; 4440 4310 req.ver_upd_8b = DRV_VER_UPD; ··· 4473 4335 4474 4336 mutex_lock(&bp->hwrm_cmd_lock); 4475 4337 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 4476 - if (rc) 4477 - rc = -EIO; 4478 - else if (resp->flags & 4479 - cpu_to_le32(FUNC_DRV_RGTR_RESP_FLAGS_IF_CHANGE_SUPPORTED)) 4338 + if (!rc && (resp->flags & 4339 + cpu_to_le32(FUNC_DRV_RGTR_RESP_FLAGS_IF_CHANGE_SUPPORTED))) 4480 4340 bp->fw_cap |= BNXT_FW_CAP_IF_CHANGE; 4481 4341 mutex_unlock(&bp->hwrm_cmd_lock); 4482 4342 return rc; ··· 4897 4761 } 4898 4762 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 4899 4763 if (rc) 4900 - return -EIO; 4764 + return rc; 4901 4765 } 4902 4766 return 0; 4903 4767 } ··· 5060 4924 cpu_to_le32(bp->vnic_info[vnic_id].fw_vnic_id); 5061 4925 5062 4926 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 5063 - if (rc) 5064 - return rc; 5065 4927 bp->vnic_info[vnic_id].fw_vnic_id = INVALID_HW_RING_ID; 5066 4928 } 5067 4929 return rc; ··· 5120 4986 int rc; 5121 4987 5122 4988 bp->hw_ring_stats_size = sizeof(struct ctx_hw_stats); 4989 + bp->flags &= ~(BNXT_FLAG_NEW_RSS_CAP | BNXT_FLAG_ROCE_MIRROR_CAP); 5123 4990 if (bp->hwrm_spec_code < 0x10600) 5124 4991 return 0; 5125 4992 ··· 5199 5064 5200 5065 rc = _hwrm_send_message(bp, &req, sizeof(req), 5201 5066 HWRM_CMD_TIMEOUT); 5202 - if (rc) 5203 - break; 5204 5067 bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID; 5205 5068 } 5206 5069 mutex_unlock(&bp->hwrm_cmd_lock); ··· 5517 5384 struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr; 5518 5385 u16 error_code; 5519 5386 5387 + if (test_bit(BNXT_STATE_FW_FATAL_COND, &bp->state)) 5388 + return 0; 5389 + 5520 5390 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_FREE, cmpl_ring_id, -1); 5521 5391 req.ring_type = ring_type; 5522 5392 req.ring_id = cpu_to_le16(ring->fw_ring_id); ··· 5657 5521 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 5658 5522 if (rc) { 5659 5523 mutex_unlock(&bp->hwrm_cmd_lock); 5660 - return -EIO; 5524 + return rc; 5661 5525 } 5662 5526 5663 5527 hw_resc->resv_tx_rings = le16_to_cpu(resp->alloc_tx_rings); ··· 5821 5685 5822 5686 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 5823 5687 if (rc) 5824 - return -ENOMEM; 5688 + return rc; 5825 5689 5826 5690 if (bp->hwrm_spec_code < 0x10601) 5827 5691 bp->hw_resc.resv_tx_rings = tx_rings; ··· 5846 5710 cp_rings, stats, vnics); 5847 5711 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 5848 5712 if (rc) 5849 - return -ENOMEM; 5713 + return rc; 5850 5714 5851 5715 rc = bnxt_hwrm_get_rings(bp); 5852 5716 return rc; ··· 6027 5891 6028 5892 req.flags = cpu_to_le32(flags); 6029 5893 rc = hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 6030 - if (rc) 6031 - return -ENOMEM; 6032 - return 0; 5894 + return rc; 6033 5895 } 6034 5896 6035 5897 static int bnxt_hwrm_check_pf_rings(struct bnxt *bp, int tx_rings, int rx_rings, ··· 6055 5921 6056 5922 req.flags = cpu_to_le32(flags); 6057 5923 rc = hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 6058 - if (rc) 6059 - return -ENOMEM; 6060 - return 0; 5924 + return rc; 6061 5925 } 6062 5926 6063 5927 static int bnxt_hwrm_check_rings(struct bnxt *bp, int tx_rings, int rx_rings, ··· 6317 6185 6318 6186 rc = _hwrm_send_message(bp, &req, sizeof(req), 6319 6187 HWRM_CMD_TIMEOUT); 6320 - if (rc) 6321 - break; 6322 6188 6323 6189 cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID; 6324 6190 } ··· 6378 6248 struct bnxt_vf_info *vf = &bp->vf; 6379 6249 6380 6250 vf->vlan = le16_to_cpu(resp->vlan) & VLAN_VID_MASK; 6251 + } else { 6252 + bp->pf.registered_vfs = le16_to_cpu(resp->registered_vfs); 6381 6253 } 6382 6254 #endif 6383 6255 flags = le16_to_cpu(resp->flags); ··· 6615 6483 } 6616 6484 req.flags = cpu_to_le32(flags); 6617 6485 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 6618 - if (rc) 6619 - rc = -EIO; 6620 6486 return rc; 6621 6487 } 6622 6488 ··· 6876 6746 mutex_lock(&bp->hwrm_cmd_lock); 6877 6747 rc = _hwrm_send_message_silent(bp, &req, sizeof(req), 6878 6748 HWRM_CMD_TIMEOUT); 6879 - if (rc) { 6880 - rc = -EIO; 6749 + if (rc) 6881 6750 goto hwrm_func_resc_qcaps_exit; 6882 - } 6883 6751 6884 6752 hw_resc->max_tx_sch_inputs = le16_to_cpu(resp->max_tx_scheduler_inputs); 6885 6753 if (!all) ··· 6945 6817 bp->fw_cap |= BNXT_FW_CAP_PCIE_STATS_SUPPORTED; 6946 6818 if (flags & FUNC_QCAPS_RESP_FLAGS_EXT_STATS_SUPPORTED) 6947 6819 bp->fw_cap |= BNXT_FW_CAP_EXT_STATS_SUPPORTED; 6820 + if (flags & FUNC_QCAPS_RESP_FLAGS_ERROR_RECOVERY_CAPABLE) 6821 + bp->fw_cap |= BNXT_FW_CAP_ERROR_RECOVERY; 6948 6822 6949 6823 bp->tx_push_thresh = 0; 6950 6824 if (flags & FUNC_QCAPS_RESP_FLAGS_PUSH_MODE_SUPPORTED) ··· 6978 6848 pf->max_tx_wm_flows = le32_to_cpu(resp->max_tx_wm_flows); 6979 6849 pf->max_rx_em_flows = le32_to_cpu(resp->max_rx_em_flows); 6980 6850 pf->max_rx_wm_flows = le32_to_cpu(resp->max_rx_wm_flows); 6851 + bp->flags &= ~BNXT_FLAG_WOL_CAP; 6981 6852 if (flags & FUNC_QCAPS_RESP_FLAGS_WOL_MAGICPKT_SUPPORTED) 6982 6853 bp->flags |= BNXT_FLAG_WOL_CAP; 6983 6854 } else { ··· 7048 6917 return rc; 7049 6918 } 7050 6919 6920 + static int bnxt_map_fw_health_regs(struct bnxt *bp) 6921 + { 6922 + struct bnxt_fw_health *fw_health = bp->fw_health; 6923 + u32 reg_base = 0xffffffff; 6924 + int i; 6925 + 6926 + /* Only pre-map the monitoring GRC registers using window 3 */ 6927 + for (i = 0; i < 4; i++) { 6928 + u32 reg = fw_health->regs[i]; 6929 + 6930 + if (BNXT_FW_HEALTH_REG_TYPE(reg) != BNXT_FW_HEALTH_REG_TYPE_GRC) 6931 + continue; 6932 + if (reg_base == 0xffffffff) 6933 + reg_base = reg & BNXT_GRC_BASE_MASK; 6934 + if ((reg & BNXT_GRC_BASE_MASK) != reg_base) 6935 + return -ERANGE; 6936 + fw_health->mapped_regs[i] = BNXT_FW_HEALTH_WIN_BASE + 6937 + (reg & BNXT_GRC_OFFSET_MASK); 6938 + } 6939 + if (reg_base == 0xffffffff) 6940 + return 0; 6941 + 6942 + writel(reg_base, bp->bar0 + BNXT_GRCPF_REG_WINDOW_BASE_OUT + 6943 + BNXT_FW_HEALTH_WIN_MAP_OFF); 6944 + return 0; 6945 + } 6946 + 6947 + static int bnxt_hwrm_error_recovery_qcfg(struct bnxt *bp) 6948 + { 6949 + struct hwrm_error_recovery_qcfg_output *resp = bp->hwrm_cmd_resp_addr; 6950 + struct bnxt_fw_health *fw_health = bp->fw_health; 6951 + struct hwrm_error_recovery_qcfg_input req = {0}; 6952 + int rc, i; 6953 + 6954 + if (!(bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY)) 6955 + return 0; 6956 + 6957 + bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_ERROR_RECOVERY_QCFG, -1, -1); 6958 + mutex_lock(&bp->hwrm_cmd_lock); 6959 + rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 6960 + if (rc) 6961 + goto err_recovery_out; 6962 + if (!fw_health) { 6963 + fw_health = kzalloc(sizeof(*fw_health), GFP_KERNEL); 6964 + bp->fw_health = fw_health; 6965 + if (!fw_health) { 6966 + rc = -ENOMEM; 6967 + goto err_recovery_out; 6968 + } 6969 + } 6970 + fw_health->flags = le32_to_cpu(resp->flags); 6971 + if ((fw_health->flags & ERROR_RECOVERY_QCFG_RESP_FLAGS_CO_CPU) && 6972 + !(bp->fw_cap & BNXT_FW_CAP_KONG_MB_CHNL)) { 6973 + rc = -EINVAL; 6974 + goto err_recovery_out; 6975 + } 6976 + fw_health->polling_dsecs = le32_to_cpu(resp->driver_polling_freq); 6977 + fw_health->master_func_wait_dsecs = 6978 + le32_to_cpu(resp->master_func_wait_period); 6979 + fw_health->normal_func_wait_dsecs = 6980 + le32_to_cpu(resp->normal_func_wait_period); 6981 + fw_health->post_reset_wait_dsecs = 6982 + le32_to_cpu(resp->master_func_wait_period_after_reset); 6983 + fw_health->post_reset_max_wait_dsecs = 6984 + le32_to_cpu(resp->max_bailout_time_after_reset); 6985 + fw_health->regs[BNXT_FW_HEALTH_REG] = 6986 + le32_to_cpu(resp->fw_health_status_reg); 6987 + fw_health->regs[BNXT_FW_HEARTBEAT_REG] = 6988 + le32_to_cpu(resp->fw_heartbeat_reg); 6989 + fw_health->regs[BNXT_FW_RESET_CNT_REG] = 6990 + le32_to_cpu(resp->fw_reset_cnt_reg); 6991 + fw_health->regs[BNXT_FW_RESET_INPROG_REG] = 6992 + le32_to_cpu(resp->reset_inprogress_reg); 6993 + fw_health->fw_reset_inprog_reg_mask = 6994 + le32_to_cpu(resp->reset_inprogress_reg_mask); 6995 + fw_health->fw_reset_seq_cnt = resp->reg_array_cnt; 6996 + if (fw_health->fw_reset_seq_cnt >= 16) { 6997 + rc = -EINVAL; 6998 + goto err_recovery_out; 6999 + } 7000 + for (i = 0; i < fw_health->fw_reset_seq_cnt; i++) { 7001 + fw_health->fw_reset_seq_regs[i] = 7002 + le32_to_cpu(resp->reset_reg[i]); 7003 + fw_health->fw_reset_seq_vals[i] = 7004 + le32_to_cpu(resp->reset_reg_val[i]); 7005 + fw_health->fw_reset_seq_delay_msec[i] = 7006 + resp->delay_after_reset[i]; 7007 + } 7008 + err_recovery_out: 7009 + mutex_unlock(&bp->hwrm_cmd_lock); 7010 + if (!rc) 7011 + rc = bnxt_map_fw_health_regs(bp); 7012 + if (rc) 7013 + bp->fw_cap &= ~BNXT_FW_CAP_ERROR_RECOVERY; 7014 + return rc; 7015 + } 7016 + 7051 7017 static int bnxt_hwrm_func_reset(struct bnxt *bp) 7052 7018 { 7053 7019 struct hwrm_func_reset_input req = {0}; ··· 7204 6976 return rc; 7205 6977 } 7206 6978 7207 - static int bnxt_hwrm_ver_get(struct bnxt *bp) 6979 + static int __bnxt_hwrm_ver_get(struct bnxt *bp, bool silent) 7208 6980 { 7209 - int rc; 7210 6981 struct hwrm_ver_get_input req = {0}; 7211 - struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr; 7212 - u32 dev_caps_cfg; 6982 + int rc; 7213 6983 7214 - bp->hwrm_max_req_len = HWRM_MAX_REQ_LEN; 7215 6984 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VER_GET, -1, -1); 7216 6985 req.hwrm_intf_maj = HWRM_VERSION_MAJOR; 7217 6986 req.hwrm_intf_min = HWRM_VERSION_MINOR; 7218 6987 req.hwrm_intf_upd = HWRM_VERSION_UPDATE; 6988 + 6989 + rc = bnxt_hwrm_do_send_msg(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT, 6990 + silent); 6991 + return rc; 6992 + } 6993 + 6994 + static int bnxt_hwrm_ver_get(struct bnxt *bp) 6995 + { 6996 + struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr; 6997 + u32 dev_caps_cfg; 6998 + int rc; 6999 + 7000 + bp->hwrm_max_req_len = HWRM_MAX_REQ_LEN; 7219 7001 mutex_lock(&bp->hwrm_cmd_lock); 7220 - rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 7002 + rc = __bnxt_hwrm_ver_get(bp, false); 7221 7003 if (rc) 7222 7004 goto hwrm_ver_get_exit; 7223 7005 ··· 7430 7192 7431 7193 if (set_tpa) 7432 7194 tpa_flags = bp->flags & BNXT_FLAG_TPA; 7195 + else if (test_bit(BNXT_STATE_FW_FATAL_COND, &bp->state)) 7196 + return 0; 7433 7197 for (i = 0; i < bp->nr_vnics; i++) { 7434 7198 rc = bnxt_hwrm_vnic_set_tpa(bp, i, tpa_flags); 7435 7199 if (rc) { ··· 7497 7257 else 7498 7258 return -EINVAL; 7499 7259 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 7500 - if (rc) 7501 - rc = -EIO; 7502 7260 return rc; 7503 7261 } 7504 7262 ··· 7516 7278 req.options = FUNC_CFG_REQ_OPTIONS_CACHE_LINESIZE_SIZE_128; 7517 7279 7518 7280 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 7519 - if (rc) 7520 - rc = -EIO; 7521 7281 return rc; 7522 7282 } 7523 7283 ··· 8398 8162 struct hwrm_port_phy_qcaps_output *resp = bp->hwrm_cmd_resp_addr; 8399 8163 struct bnxt_link_info *link_info = &bp->link_info; 8400 8164 8165 + bp->flags &= ~BNXT_FLAG_EEE_CAP; 8166 + if (bp->test_info) 8167 + bp->test_info->flags &= ~BNXT_TEST_FL_EXT_LPBK; 8401 8168 if (bp->hwrm_spec_code < 0x10201) 8402 8169 return 0; 8403 8170 ··· 8722 8483 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 8723 8484 } 8724 8485 8486 + static int bnxt_fw_init_one(struct bnxt *bp); 8487 + 8725 8488 static int bnxt_hwrm_if_change(struct bnxt *bp, bool up) 8726 8489 { 8727 8490 struct hwrm_func_drv_if_change_output *resp = bp->hwrm_cmd_resp_addr; 8728 8491 struct hwrm_func_drv_if_change_input req = {0}; 8729 - bool resc_reinit = false; 8492 + bool resc_reinit = false, fw_reset = false; 8493 + u32 flags = 0; 8730 8494 int rc; 8731 8495 8732 8496 if (!(bp->fw_cap & BNXT_FW_CAP_IF_CHANGE)) ··· 8740 8498 req.flags = cpu_to_le32(FUNC_DRV_IF_CHANGE_REQ_FLAGS_UP); 8741 8499 mutex_lock(&bp->hwrm_cmd_lock); 8742 8500 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 8743 - if (!rc && (resp->flags & 8744 - cpu_to_le32(FUNC_DRV_IF_CHANGE_RESP_FLAGS_RESC_CHANGE))) 8745 - resc_reinit = true; 8501 + if (!rc) 8502 + flags = le32_to_cpu(resp->flags); 8746 8503 mutex_unlock(&bp->hwrm_cmd_lock); 8504 + if (rc) 8505 + return rc; 8747 8506 8748 - if (up && resc_reinit && BNXT_NEW_RM(bp)) { 8749 - struct bnxt_hw_resc *hw_resc = &bp->hw_resc; 8507 + if (!up) 8508 + return 0; 8750 8509 8751 - rc = bnxt_hwrm_func_resc_qcaps(bp, true); 8752 - hw_resc->resv_cp_rings = 0; 8753 - hw_resc->resv_stat_ctxs = 0; 8754 - hw_resc->resv_irqs = 0; 8755 - hw_resc->resv_tx_rings = 0; 8756 - hw_resc->resv_rx_rings = 0; 8757 - hw_resc->resv_hw_ring_grps = 0; 8758 - hw_resc->resv_vnics = 0; 8759 - bp->tx_nr_rings = 0; 8760 - bp->rx_nr_rings = 0; 8510 + if (flags & FUNC_DRV_IF_CHANGE_RESP_FLAGS_RESC_CHANGE) 8511 + resc_reinit = true; 8512 + if (flags & FUNC_DRV_IF_CHANGE_RESP_FLAGS_HOT_FW_RESET_DONE) 8513 + fw_reset = true; 8514 + 8515 + if (test_bit(BNXT_STATE_IN_FW_RESET, &bp->state) && !fw_reset) { 8516 + netdev_err(bp->dev, "RESET_DONE not set during FW reset.\n"); 8517 + return -ENODEV; 8761 8518 } 8762 - return rc; 8519 + if (resc_reinit || fw_reset) { 8520 + if (fw_reset) { 8521 + rc = bnxt_fw_init_one(bp); 8522 + if (rc) { 8523 + set_bit(BNXT_STATE_ABORT_ERR, &bp->state); 8524 + return rc; 8525 + } 8526 + bnxt_clear_int_mode(bp); 8527 + rc = bnxt_init_int_mode(bp); 8528 + if (rc) { 8529 + netdev_err(bp->dev, "init int mode failed\n"); 8530 + return rc; 8531 + } 8532 + set_bit(BNXT_STATE_FW_RESET_DET, &bp->state); 8533 + } 8534 + if (BNXT_NEW_RM(bp)) { 8535 + struct bnxt_hw_resc *hw_resc = &bp->hw_resc; 8536 + 8537 + rc = bnxt_hwrm_func_resc_qcaps(bp, true); 8538 + hw_resc->resv_cp_rings = 0; 8539 + hw_resc->resv_stat_ctxs = 0; 8540 + hw_resc->resv_irqs = 0; 8541 + hw_resc->resv_tx_rings = 0; 8542 + hw_resc->resv_rx_rings = 0; 8543 + hw_resc->resv_hw_ring_grps = 0; 8544 + hw_resc->resv_vnics = 0; 8545 + if (!fw_reset) { 8546 + bp->tx_nr_rings = 0; 8547 + bp->rx_nr_rings = 0; 8548 + } 8549 + } 8550 + } 8551 + return 0; 8763 8552 } 8764 8553 8765 8554 static int bnxt_hwrm_port_led_qcaps(struct bnxt *bp) ··· 8800 8527 struct bnxt_pf_info *pf = &bp->pf; 8801 8528 int rc; 8802 8529 8530 + bp->num_leds = 0; 8803 8531 if (BNXT_VF(bp) || bp->hwrm_spec_code < 0x10601) 8804 8532 return 0; 8805 8533 ··· 8895 8621 { 8896 8622 u16 handle = 0; 8897 8623 8624 + bp->wol = 0; 8898 8625 if (!BNXT_PF(bp) || !(bp->flags & BNXT_FLAG_WOL_CAP)) 8899 8626 return; 8900 8627 ··· 8941 8666 static void bnxt_hwmon_open(struct bnxt *bp) 8942 8667 { 8943 8668 struct pci_dev *pdev = bp->pdev; 8669 + 8670 + if (bp->hwmon_dev) 8671 + return; 8944 8672 8945 8673 bp->hwmon_dev = hwmon_device_register_with_groups(&pdev->dev, 8946 8674 DRV_MODULE_NAME, bp, ··· 9210 8932 struct bnxt *bp = netdev_priv(dev); 9211 8933 int rc; 9212 8934 9213 - bnxt_hwrm_if_change(bp, true); 9214 - rc = __bnxt_open_nic(bp, true, true); 9215 - if (rc) 9216 - bnxt_hwrm_if_change(bp, false); 8935 + if (test_bit(BNXT_STATE_ABORT_ERR, &bp->state)) { 8936 + netdev_err(bp->dev, "A previous firmware reset did not complete, aborting\n"); 8937 + return -ENODEV; 8938 + } 9217 8939 9218 - bnxt_hwmon_open(bp); 8940 + rc = bnxt_hwrm_if_change(bp, true); 8941 + if (rc) 8942 + return rc; 8943 + rc = __bnxt_open_nic(bp, true, true); 8944 + if (rc) { 8945 + bnxt_hwrm_if_change(bp, false); 8946 + } else { 8947 + if (test_and_clear_bit(BNXT_STATE_FW_RESET_DET, &bp->state) && 8948 + BNXT_PF(bp)) { 8949 + struct bnxt_pf_info *pf = &bp->pf; 8950 + int n = pf->active_vfs; 8951 + 8952 + if (n) 8953 + bnxt_cfg_hw_sriov(bp, &n, true); 8954 + } 8955 + bnxt_hwmon_open(bp); 8956 + } 9219 8957 9220 8958 return rc; 9221 8959 } ··· 9268 8974 bnxt_debug_dev_exit(bp); 9269 8975 bnxt_disable_napi(bp); 9270 8976 del_timer_sync(&bp->timer); 8977 + if (test_bit(BNXT_STATE_IN_FW_RESET, &bp->state) && 8978 + pci_is_enabled(bp->pdev)) 8979 + pci_disable_device(bp->pdev); 8980 + 9271 8981 bnxt_free_skbs(bp); 9272 8982 9273 8983 /* Save ring stats before shutdown */ ··· 9287 8989 int bnxt_close_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init) 9288 8990 { 9289 8991 int rc = 0; 8992 + 8993 + if (test_bit(BNXT_STATE_IN_FW_RESET, &bp->state)) { 8994 + /* If we get here, it means firmware reset is in progress 8995 + * while we are trying to close. We can safely proceed with 8996 + * the close because we are holding rtnl_lock(). Some firmware 8997 + * messages may fail as we proceed to close. We set the 8998 + * ABORT_ERR flag here so that the FW reset thread will later 8999 + * abort when it gets the rtnl_lock() and sees the flag. 9000 + */ 9001 + netdev_warn(bp->dev, "FW reset in progress during close, FW reset will be aborted\n"); 9002 + set_bit(BNXT_STATE_ABORT_ERR, &bp->state); 9003 + } 9290 9004 9291 9005 #ifdef CONFIG_BNXT_SRIOV 9292 9006 if (bp->sriov_cfg) { ··· 9941 9631 bnxt_queue_sp_work(bp); 9942 9632 } 9943 9633 9634 + static void bnxt_fw_health_check(struct bnxt *bp) 9635 + { 9636 + struct bnxt_fw_health *fw_health = bp->fw_health; 9637 + u32 val; 9638 + 9639 + if (!fw_health || !fw_health->enabled || 9640 + test_bit(BNXT_STATE_IN_FW_RESET, &bp->state)) 9641 + return; 9642 + 9643 + if (fw_health->tmr_counter) { 9644 + fw_health->tmr_counter--; 9645 + return; 9646 + } 9647 + 9648 + val = bnxt_fw_health_readl(bp, BNXT_FW_HEARTBEAT_REG); 9649 + if (val == fw_health->last_fw_heartbeat) 9650 + goto fw_reset; 9651 + 9652 + fw_health->last_fw_heartbeat = val; 9653 + 9654 + val = bnxt_fw_health_readl(bp, BNXT_FW_RESET_CNT_REG); 9655 + if (val != fw_health->last_fw_reset_cnt) 9656 + goto fw_reset; 9657 + 9658 + fw_health->tmr_counter = fw_health->tmr_multiplier; 9659 + return; 9660 + 9661 + fw_reset: 9662 + set_bit(BNXT_FW_EXCEPTION_SP_EVENT, &bp->sp_event); 9663 + bnxt_queue_sp_work(bp); 9664 + } 9665 + 9944 9666 static void bnxt_timer(struct timer_list *t) 9945 9667 { 9946 9668 struct bnxt *bp = from_timer(bp, t, timer); ··· 9983 9641 9984 9642 if (atomic_read(&bp->intr_sem) != 0) 9985 9643 goto bnxt_restart_timer; 9644 + 9645 + if (bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY) 9646 + bnxt_fw_health_check(bp); 9986 9647 9987 9648 if (bp->link_info.link_up && (bp->flags & BNXT_FLAG_PORT_STATS) && 9988 9649 bp->stats_coal_ticks) { ··· 10039 9694 bnxt_rtnl_lock_sp(bp); 10040 9695 if (test_bit(BNXT_STATE_OPEN, &bp->state)) 10041 9696 bnxt_reset_task(bp, silent); 9697 + bnxt_rtnl_unlock_sp(bp); 9698 + } 9699 + 9700 + static void bnxt_fw_reset_close(struct bnxt *bp) 9701 + { 9702 + __bnxt_close_nic(bp, true, false); 9703 + bnxt_ulp_irq_stop(bp); 9704 + bnxt_clear_int_mode(bp); 9705 + bnxt_hwrm_func_drv_unrgtr(bp); 9706 + bnxt_free_ctx_mem(bp); 9707 + kfree(bp->ctx); 9708 + bp->ctx = NULL; 9709 + } 9710 + 9711 + static bool is_bnxt_fw_ok(struct bnxt *bp) 9712 + { 9713 + struct bnxt_fw_health *fw_health = bp->fw_health; 9714 + bool no_heartbeat = false, has_reset = false; 9715 + u32 val; 9716 + 9717 + val = bnxt_fw_health_readl(bp, BNXT_FW_HEARTBEAT_REG); 9718 + if (val == fw_health->last_fw_heartbeat) 9719 + no_heartbeat = true; 9720 + 9721 + val = bnxt_fw_health_readl(bp, BNXT_FW_RESET_CNT_REG); 9722 + if (val != fw_health->last_fw_reset_cnt) 9723 + has_reset = true; 9724 + 9725 + if (!no_heartbeat && has_reset) 9726 + return true; 9727 + 9728 + return false; 9729 + } 9730 + 9731 + /* rtnl_lock is acquired before calling this function */ 9732 + static void bnxt_force_fw_reset(struct bnxt *bp) 9733 + { 9734 + struct bnxt_fw_health *fw_health = bp->fw_health; 9735 + u32 wait_dsecs; 9736 + 9737 + if (!test_bit(BNXT_STATE_OPEN, &bp->state) || 9738 + test_bit(BNXT_STATE_IN_FW_RESET, &bp->state)) 9739 + return; 9740 + 9741 + set_bit(BNXT_STATE_IN_FW_RESET, &bp->state); 9742 + bnxt_fw_reset_close(bp); 9743 + wait_dsecs = fw_health->master_func_wait_dsecs; 9744 + if (fw_health->master) { 9745 + if (fw_health->flags & ERROR_RECOVERY_QCFG_RESP_FLAGS_CO_CPU) 9746 + wait_dsecs = 0; 9747 + bp->fw_reset_state = BNXT_FW_RESET_STATE_RESET_FW; 9748 + } else { 9749 + bp->fw_reset_timestamp = jiffies + wait_dsecs * HZ / 10; 9750 + wait_dsecs = fw_health->normal_func_wait_dsecs; 9751 + bp->fw_reset_state = BNXT_FW_RESET_STATE_ENABLE_DEV; 9752 + } 9753 + bp->fw_reset_max_dsecs = fw_health->post_reset_max_wait_dsecs; 9754 + bnxt_queue_fw_reset_work(bp, wait_dsecs * HZ / 10); 9755 + } 9756 + 9757 + void bnxt_fw_exception(struct bnxt *bp) 9758 + { 9759 + set_bit(BNXT_STATE_FW_FATAL_COND, &bp->state); 9760 + bnxt_rtnl_lock_sp(bp); 9761 + bnxt_force_fw_reset(bp); 9762 + bnxt_rtnl_unlock_sp(bp); 9763 + } 9764 + 9765 + void bnxt_fw_reset(struct bnxt *bp) 9766 + { 9767 + int rc; 9768 + 9769 + bnxt_rtnl_lock_sp(bp); 9770 + if (test_bit(BNXT_STATE_OPEN, &bp->state) && 9771 + !test_bit(BNXT_STATE_IN_FW_RESET, &bp->state)) { 9772 + set_bit(BNXT_STATE_IN_FW_RESET, &bp->state); 9773 + if (BNXT_PF(bp) && bp->pf.active_vfs && 9774 + !test_bit(BNXT_STATE_FW_FATAL_COND, &bp->state)) { 9775 + rc = bnxt_hwrm_func_qcfg(bp); 9776 + if (rc) { 9777 + netdev_err(bp->dev, "Firmware reset aborted, first func_qcfg cmd failed, rc = %d\n", 9778 + rc); 9779 + clear_bit(BNXT_STATE_IN_FW_RESET, &bp->state); 9780 + dev_close(bp->dev); 9781 + goto fw_reset_exit; 9782 + } 9783 + if (bp->pf.registered_vfs || bp->sriov_cfg) { 9784 + u16 vf_tmo_dsecs = bp->pf.registered_vfs * 10; 9785 + 9786 + if (bp->fw_reset_max_dsecs < vf_tmo_dsecs) 9787 + bp->fw_reset_max_dsecs = vf_tmo_dsecs; 9788 + bp->fw_reset_state = 9789 + BNXT_FW_RESET_STATE_POLL_VF; 9790 + bnxt_queue_fw_reset_work(bp, HZ / 10); 9791 + goto fw_reset_exit; 9792 + } 9793 + } 9794 + bnxt_fw_reset_close(bp); 9795 + bp->fw_reset_state = BNXT_FW_RESET_STATE_ENABLE_DEV; 9796 + bnxt_queue_fw_reset_work(bp, bp->fw_reset_min_dsecs * HZ / 10); 9797 + } 9798 + fw_reset_exit: 10042 9799 bnxt_rtnl_unlock_sp(bp); 10043 9800 } 10044 9801 ··· 10273 9826 10274 9827 if (test_and_clear_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event)) 10275 9828 bnxt_reset(bp, true); 9829 + 9830 + if (test_and_clear_bit(BNXT_FW_RESET_NOTIFY_SP_EVENT, &bp->sp_event)) 9831 + bnxt_devlink_health_report(bp, BNXT_FW_RESET_NOTIFY_SP_EVENT); 9832 + 9833 + if (test_and_clear_bit(BNXT_FW_EXCEPTION_SP_EVENT, &bp->sp_event)) { 9834 + if (!is_bnxt_fw_ok(bp)) 9835 + bnxt_devlink_health_report(bp, 9836 + BNXT_FW_EXCEPTION_SP_EVENT); 9837 + } 10276 9838 10277 9839 smp_mb__before_atomic(); 10278 9840 clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state); ··· 10423 9967 netdev_warn(bp->dev, "hwrm query adv flow mgnt failure rc: %d\n", 10424 9968 rc); 10425 9969 9970 + rc = bnxt_hwrm_error_recovery_qcfg(bp); 9971 + if (rc) 9972 + netdev_warn(bp->dev, "hwrm query error recovery failure rc: %d\n", 9973 + rc); 9974 + 10426 9975 rc = bnxt_hwrm_func_drv_rgtr(bp); 10427 9976 if (rc) 10428 9977 return -ENODEV; ··· 10442 9981 bnxt_ethtool_init(bp); 10443 9982 bnxt_dcb_init(bp); 10444 9983 return 0; 9984 + } 9985 + 9986 + static void bnxt_set_dflt_rss_hash_type(struct bnxt *bp) 9987 + { 9988 + bp->flags &= ~BNXT_FLAG_UDP_RSS_CAP; 9989 + bp->rss_hash_cfg = VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4 | 9990 + VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4 | 9991 + VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6 | 9992 + VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6; 9993 + if (BNXT_CHIP_P4(bp) && bp->hwrm_spec_code >= 0x10501) { 9994 + bp->flags |= BNXT_FLAG_UDP_RSS_CAP; 9995 + bp->rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4 | 9996 + VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6; 9997 + } 9998 + } 9999 + 10000 + static void bnxt_set_dflt_rfs(struct bnxt *bp) 10001 + { 10002 + struct net_device *dev = bp->dev; 10003 + 10004 + dev->hw_features &= ~NETIF_F_NTUPLE; 10005 + dev->features &= ~NETIF_F_NTUPLE; 10006 + bp->flags &= ~BNXT_FLAG_RFS; 10007 + if (bnxt_rfs_supported(bp)) { 10008 + dev->hw_features |= NETIF_F_NTUPLE; 10009 + if (bnxt_rfs_capable(bp)) { 10010 + bp->flags |= BNXT_FLAG_RFS; 10011 + dev->features |= NETIF_F_NTUPLE; 10012 + } 10013 + } 10014 + } 10015 + 10016 + static void bnxt_fw_init_one_p3(struct bnxt *bp) 10017 + { 10018 + struct pci_dev *pdev = bp->pdev; 10019 + 10020 + bnxt_set_dflt_rss_hash_type(bp); 10021 + bnxt_set_dflt_rfs(bp); 10022 + 10023 + bnxt_get_wol_settings(bp); 10024 + if (bp->flags & BNXT_FLAG_WOL_CAP) 10025 + device_set_wakeup_enable(&pdev->dev, bp->wol); 10026 + else 10027 + device_set_wakeup_capable(&pdev->dev, false); 10028 + 10029 + bnxt_hwrm_set_cache_line_size(bp, cache_line_size()); 10030 + bnxt_hwrm_coal_params_qcaps(bp); 10031 + } 10032 + 10033 + static int bnxt_fw_init_one(struct bnxt *bp) 10034 + { 10035 + int rc; 10036 + 10037 + rc = bnxt_fw_init_one_p1(bp); 10038 + if (rc) { 10039 + netdev_err(bp->dev, "Firmware init phase 1 failed\n"); 10040 + return rc; 10041 + } 10042 + rc = bnxt_fw_init_one_p2(bp); 10043 + if (rc) { 10044 + netdev_err(bp->dev, "Firmware init phase 2 failed\n"); 10045 + return rc; 10046 + } 10047 + rc = bnxt_approve_mac(bp, bp->dev->dev_addr, false); 10048 + if (rc) 10049 + return rc; 10050 + bnxt_fw_init_one_p3(bp); 10051 + return 0; 10052 + } 10053 + 10054 + static void bnxt_fw_reset_writel(struct bnxt *bp, int reg_idx) 10055 + { 10056 + struct bnxt_fw_health *fw_health = bp->fw_health; 10057 + u32 reg = fw_health->fw_reset_seq_regs[reg_idx]; 10058 + u32 val = fw_health->fw_reset_seq_vals[reg_idx]; 10059 + u32 reg_type, reg_off, delay_msecs; 10060 + 10061 + delay_msecs = fw_health->fw_reset_seq_delay_msec[reg_idx]; 10062 + reg_type = BNXT_FW_HEALTH_REG_TYPE(reg); 10063 + reg_off = BNXT_FW_HEALTH_REG_OFF(reg); 10064 + switch (reg_type) { 10065 + case BNXT_FW_HEALTH_REG_TYPE_CFG: 10066 + pci_write_config_dword(bp->pdev, reg_off, val); 10067 + break; 10068 + case BNXT_FW_HEALTH_REG_TYPE_GRC: 10069 + writel(reg_off & BNXT_GRC_BASE_MASK, 10070 + bp->bar0 + BNXT_GRCPF_REG_WINDOW_BASE_OUT + 4); 10071 + reg_off = (reg_off & BNXT_GRC_OFFSET_MASK) + 0x2000; 10072 + /* fall through */ 10073 + case BNXT_FW_HEALTH_REG_TYPE_BAR0: 10074 + writel(val, bp->bar0 + reg_off); 10075 + break; 10076 + case BNXT_FW_HEALTH_REG_TYPE_BAR1: 10077 + writel(val, bp->bar1 + reg_off); 10078 + break; 10079 + } 10080 + if (delay_msecs) { 10081 + pci_read_config_dword(bp->pdev, 0, &val); 10082 + msleep(delay_msecs); 10083 + } 10084 + } 10085 + 10086 + static void bnxt_reset_all(struct bnxt *bp) 10087 + { 10088 + struct bnxt_fw_health *fw_health = bp->fw_health; 10089 + int i; 10090 + 10091 + if (fw_health->flags & ERROR_RECOVERY_QCFG_RESP_FLAGS_HOST) { 10092 + for (i = 0; i < fw_health->fw_reset_seq_cnt; i++) 10093 + bnxt_fw_reset_writel(bp, i); 10094 + } else if (fw_health->flags & ERROR_RECOVERY_QCFG_RESP_FLAGS_CO_CPU) { 10095 + struct hwrm_fw_reset_input req = {0}; 10096 + int rc; 10097 + 10098 + bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_RESET, -1, -1); 10099 + req.resp_addr = cpu_to_le64(bp->hwrm_cmd_kong_resp_dma_addr); 10100 + req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_CHIP; 10101 + req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTASAP; 10102 + req.flags = FW_RESET_REQ_FLAGS_RESET_GRACEFUL; 10103 + rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 10104 + if (rc) 10105 + netdev_warn(bp->dev, "Unable to reset FW rc=%d\n", rc); 10106 + } 10107 + bp->fw_reset_timestamp = jiffies; 10108 + } 10109 + 10110 + static void bnxt_fw_reset_task(struct work_struct *work) 10111 + { 10112 + struct bnxt *bp = container_of(work, struct bnxt, fw_reset_task.work); 10113 + int rc; 10114 + 10115 + if (!test_bit(BNXT_STATE_IN_FW_RESET, &bp->state)) { 10116 + netdev_err(bp->dev, "bnxt_fw_reset_task() called when not in fw reset mode!\n"); 10117 + return; 10118 + } 10119 + 10120 + switch (bp->fw_reset_state) { 10121 + case BNXT_FW_RESET_STATE_POLL_VF: 10122 + rc = bnxt_hwrm_func_qcfg(bp); 10123 + if (rc) { 10124 + netdev_err(bp->dev, "Firmware reset aborted, subsequent func_qcfg cmd failed, rc = %d, %d msecs since reset timestamp\n", 10125 + rc, jiffies_to_msecs(jiffies - 10126 + bp->fw_reset_timestamp)); 10127 + goto fw_reset_abort; 10128 + } 10129 + if (bp->pf.registered_vfs || bp->sriov_cfg) { 10130 + if (time_after(jiffies, bp->fw_reset_timestamp + 10131 + (bp->fw_reset_max_dsecs * HZ / 10))) { 10132 + clear_bit(BNXT_STATE_IN_FW_RESET, &bp->state); 10133 + bp->fw_reset_state = 0; 10134 + netdev_err(bp->dev, "Firmware reset aborted, %d VFs still registered, sriov_cfg %d\n", 10135 + bp->pf.registered_vfs, 10136 + bp->sriov_cfg); 10137 + return; 10138 + } 10139 + bnxt_queue_fw_reset_work(bp, HZ / 10); 10140 + return; 10141 + } 10142 + bp->fw_reset_timestamp = jiffies; 10143 + rtnl_lock(); 10144 + bnxt_fw_reset_close(bp); 10145 + bp->fw_reset_state = BNXT_FW_RESET_STATE_ENABLE_DEV; 10146 + rtnl_unlock(); 10147 + bnxt_queue_fw_reset_work(bp, bp->fw_reset_min_dsecs * HZ / 10); 10148 + return; 10149 + case BNXT_FW_RESET_STATE_RESET_FW: { 10150 + u32 wait_dsecs = bp->fw_health->post_reset_wait_dsecs; 10151 + 10152 + bnxt_reset_all(bp); 10153 + bp->fw_reset_state = BNXT_FW_RESET_STATE_ENABLE_DEV; 10154 + bnxt_queue_fw_reset_work(bp, wait_dsecs * HZ / 10); 10155 + return; 10156 + } 10157 + case BNXT_FW_RESET_STATE_ENABLE_DEV: 10158 + if (test_bit(BNXT_STATE_FW_FATAL_COND, &bp->state) && 10159 + bp->fw_health) { 10160 + u32 val; 10161 + 10162 + val = bnxt_fw_health_readl(bp, 10163 + BNXT_FW_RESET_INPROG_REG); 10164 + if (val) 10165 + netdev_warn(bp->dev, "FW reset inprog %x after min wait time.\n", 10166 + val); 10167 + } 10168 + clear_bit(BNXT_STATE_FW_FATAL_COND, &bp->state); 10169 + if (pci_enable_device(bp->pdev)) { 10170 + netdev_err(bp->dev, "Cannot re-enable PCI device\n"); 10171 + goto fw_reset_abort; 10172 + } 10173 + pci_set_master(bp->pdev); 10174 + bp->fw_reset_state = BNXT_FW_RESET_STATE_POLL_FW; 10175 + /* fall through */ 10176 + case BNXT_FW_RESET_STATE_POLL_FW: 10177 + bp->hwrm_cmd_timeout = SHORT_HWRM_CMD_TIMEOUT; 10178 + rc = __bnxt_hwrm_ver_get(bp, true); 10179 + if (rc) { 10180 + if (time_after(jiffies, bp->fw_reset_timestamp + 10181 + (bp->fw_reset_max_dsecs * HZ / 10))) { 10182 + netdev_err(bp->dev, "Firmware reset aborted\n"); 10183 + goto fw_reset_abort; 10184 + } 10185 + bnxt_queue_fw_reset_work(bp, HZ / 5); 10186 + return; 10187 + } 10188 + bp->hwrm_cmd_timeout = DFLT_HWRM_CMD_TIMEOUT; 10189 + bp->fw_reset_state = BNXT_FW_RESET_STATE_OPENING; 10190 + /* fall through */ 10191 + case BNXT_FW_RESET_STATE_OPENING: 10192 + while (!rtnl_trylock()) { 10193 + bnxt_queue_fw_reset_work(bp, HZ / 10); 10194 + return; 10195 + } 10196 + rc = bnxt_open(bp->dev); 10197 + if (rc) { 10198 + netdev_err(bp->dev, "bnxt_open_nic() failed\n"); 10199 + clear_bit(BNXT_STATE_IN_FW_RESET, &bp->state); 10200 + dev_close(bp->dev); 10201 + } 10202 + bnxt_ulp_irq_restart(bp, rc); 10203 + rtnl_unlock(); 10204 + 10205 + bp->fw_reset_state = 0; 10206 + /* Make sure fw_reset_state is 0 before clearing the flag */ 10207 + smp_mb__before_atomic(); 10208 + clear_bit(BNXT_STATE_IN_FW_RESET, &bp->state); 10209 + break; 10210 + } 10211 + return; 10212 + 10213 + fw_reset_abort: 10214 + clear_bit(BNXT_STATE_IN_FW_RESET, &bp->state); 10215 + bp->fw_reset_state = 0; 10216 + rtnl_lock(); 10217 + dev_close(bp->dev); 10218 + rtnl_unlock(); 10445 10219 } 10446 10220 10447 10221 static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev) ··· 10741 10045 pci_enable_pcie_error_reporting(pdev); 10742 10046 10743 10047 INIT_WORK(&bp->sp_task, bnxt_sp_task); 10048 + INIT_DELAYED_WORK(&bp->fw_reset_task, bnxt_fw_reset_task); 10744 10049 10745 10050 spin_lock_init(&bp->ntp_fltr_lock); 10746 10051 #if BITS_PER_LONG == 32 ··· 11285 10588 free_netdev(dev); 11286 10589 } 11287 10590 11288 - static int bnxt_probe_phy(struct bnxt *bp) 10591 + static int bnxt_probe_phy(struct bnxt *bp, bool fw_dflt) 11289 10592 { 11290 10593 int rc = 0; 11291 10594 struct bnxt_link_info *link_info = &bp->link_info; ··· 11296 10599 rc); 11297 10600 return rc; 11298 10601 } 11299 - mutex_init(&bp->link_lock); 11300 - 11301 10602 rc = bnxt_update_link(bp, false); 11302 10603 if (rc) { 11303 10604 netdev_err(bp->dev, "Probe phy can't update link (rc: %x)\n", ··· 11308 10613 */ 11309 10614 if (link_info->auto_link_speeds && !link_info->support_auto_speeds) 11310 10615 link_info->support_auto_speeds = link_info->support_speeds; 10616 + 10617 + if (!fw_dflt) 10618 + return 0; 11311 10619 11312 10620 /*initialize the ethool setting copy with NVM settings */ 11313 10621 if (BNXT_AUTO_MODE(link_info->auto_mode)) { ··· 11332 10634 link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH; 11333 10635 else 11334 10636 link_info->req_flow_ctrl = link_info->force_pause_setting; 11335 - return rc; 10637 + return 0; 11336 10638 } 11337 10639 11338 10640 static int bnxt_get_max_irq(struct pci_dev *pdev) ··· 11636 10938 goto init_err_pci_clean; 11637 10939 11638 10940 mutex_init(&bp->hwrm_cmd_lock); 10941 + mutex_init(&bp->link_lock); 11639 10942 11640 10943 rc = bnxt_fw_init_one_p1(bp); 11641 10944 if (rc) ··· 11712 11013 dev->min_mtu = ETH_ZLEN; 11713 11014 dev->max_mtu = bp->max_mtu; 11714 11015 11715 - rc = bnxt_probe_phy(bp); 11016 + rc = bnxt_probe_phy(bp, true); 11716 11017 if (rc) 11717 11018 goto init_err_pci_clean; 11718 11019 ··· 11726 11027 goto init_err_pci_clean; 11727 11028 } 11728 11029 11729 - /* Default RSS hash cfg. */ 11730 - bp->rss_hash_cfg = VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4 | 11731 - VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4 | 11732 - VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6 | 11733 - VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6; 11734 - if (BNXT_CHIP_P4(bp) && bp->hwrm_spec_code >= 0x10501) { 11735 - bp->flags |= BNXT_FLAG_UDP_RSS_CAP; 11736 - bp->rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4 | 11737 - VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6; 11738 - } 11739 - 11740 - if (bnxt_rfs_supported(bp)) { 11741 - dev->hw_features |= NETIF_F_NTUPLE; 11742 - if (bnxt_rfs_capable(bp)) { 11743 - bp->flags |= BNXT_FLAG_RFS; 11744 - dev->features |= NETIF_F_NTUPLE; 11745 - } 11746 - } 11030 + bnxt_fw_init_one_p3(bp); 11747 11031 11748 11032 if (dev->hw_features & NETIF_F_HW_VLAN_CTAG_RX) 11749 11033 bp->flags |= BNXT_FLAG_STRIP_VLAN; ··· 11739 11057 * limited MSIX, so we re-initialize the TX rings per TC. 11740 11058 */ 11741 11059 bp->tx_nr_rings_per_tc = bp->tx_nr_rings; 11742 - 11743 - bnxt_get_wol_settings(bp); 11744 - if (bp->flags & BNXT_FLAG_WOL_CAP) 11745 - device_set_wakeup_enable(&pdev->dev, bp->wol); 11746 - else 11747 - device_set_wakeup_capable(&pdev->dev, false); 11748 - 11749 - bnxt_hwrm_set_cache_line_size(bp, cache_line_size()); 11750 - 11751 - bnxt_hwrm_coal_params_qcaps(bp); 11752 11060 11753 11061 if (BNXT_PF(bp)) { 11754 11062 if (!bnxt_pf_wq) { ··· 11776 11104 bnxt_free_ctx_mem(bp); 11777 11105 kfree(bp->ctx); 11778 11106 bp->ctx = NULL; 11107 + kfree(bp->fw_health); 11108 + bp->fw_health = NULL; 11779 11109 bnxt_cleanup_pci(bp); 11780 11110 11781 11111 init_err_free:
+91
drivers/net/ethernet/broadcom/bnxt/bnxt.h
··· 472 472 ((le32_to_cpu((rx_tpa_end_ext)->rx_tpa_end_cmp_dup_acks) & \ 473 473 RX_TPA_END_CMP_AGG_BUFS_P5) >> RX_TPA_END_CMP_AGG_BUFS_SHIFT_P5) 474 474 475 + #define EVENT_DATA1_RESET_NOTIFY_FATAL(data1) \ 476 + (((data1) & \ 477 + ASYNC_EVENT_CMPL_RESET_NOTIFY_EVENT_DATA1_REASON_CODE_MASK) ==\ 478 + ASYNC_EVENT_CMPL_RESET_NOTIFY_EVENT_DATA1_REASON_CODE_FW_EXCEPTION_FATAL) 479 + 480 + #define EVENT_DATA1_RECOVERY_MASTER_FUNC(data1) \ 481 + !!((data1) & \ 482 + ASYNC_EVENT_CMPL_ERROR_RECOVERY_EVENT_DATA1_FLAGS_MASTER_FUNC) 483 + 484 + #define EVENT_DATA1_RECOVERY_ENABLED(data1) \ 485 + !!((data1) & \ 486 + ASYNC_EVENT_CMPL_ERROR_RECOVERY_EVENT_DATA1_FLAGS_RECOVERY_ENABLED) 487 + 475 488 struct nqe_cn { 476 489 __le16 type; 477 490 #define NQ_CN_TYPE_MASK 0x3fUL ··· 645 632 #define BNXT_HWRM_MAX_REQ_LEN (bp->hwrm_max_req_len) 646 633 #define BNXT_HWRM_SHORT_REQ_LEN sizeof(struct hwrm_short_input) 647 634 #define DFLT_HWRM_CMD_TIMEOUT 500 635 + #define SHORT_HWRM_CMD_TIMEOUT 20 648 636 #define HWRM_CMD_TIMEOUT (bp->hwrm_cmd_timeout) 649 637 #define HWRM_RESET_TIMEOUT ((HWRM_CMD_TIMEOUT) * 4) 650 638 #define HWRM_RESP_ERR_CODE_MASK 0xffff ··· 1072 1058 u8 mac_addr[ETH_ALEN]; 1073 1059 u32 first_vf_id; 1074 1060 u16 active_vfs; 1061 + u16 registered_vfs; 1075 1062 u16 max_vfs; 1076 1063 u32 max_encap_records; 1077 1064 u32 max_decap_records; ··· 1232 1217 #define BNXT_GRCPF_REG_KONG_COMM 0xA00 1233 1218 #define BNXT_GRCPF_REG_KONG_COMM_TRIGGER 0xB00 1234 1219 1220 + #define BNXT_GRC_BASE_MASK 0xfffff000 1221 + #define BNXT_GRC_OFFSET_MASK 0x00000ffc 1222 + 1235 1223 struct bnxt_tc_flow_stats { 1236 1224 u64 packets; 1237 1225 u64 bytes; ··· 1350 1332 struct bnxt_ctx_pg_info tim_mem; 1351 1333 struct bnxt_ctx_pg_info *tqm_mem[9]; 1352 1334 }; 1335 + 1336 + struct bnxt_fw_health { 1337 + u32 flags; 1338 + u32 polling_dsecs; 1339 + u32 master_func_wait_dsecs; 1340 + u32 normal_func_wait_dsecs; 1341 + u32 post_reset_wait_dsecs; 1342 + u32 post_reset_max_wait_dsecs; 1343 + u32 regs[4]; 1344 + u32 mapped_regs[4]; 1345 + #define BNXT_FW_HEALTH_REG 0 1346 + #define BNXT_FW_HEARTBEAT_REG 1 1347 + #define BNXT_FW_RESET_CNT_REG 2 1348 + #define BNXT_FW_RESET_INPROG_REG 3 1349 + u32 fw_reset_inprog_reg_mask; 1350 + u32 last_fw_heartbeat; 1351 + u32 last_fw_reset_cnt; 1352 + u8 enabled:1; 1353 + u8 master:1; 1354 + u8 tmr_multiplier; 1355 + u8 tmr_counter; 1356 + u8 fw_reset_seq_cnt; 1357 + u32 fw_reset_seq_regs[16]; 1358 + u32 fw_reset_seq_vals[16]; 1359 + u32 fw_reset_seq_delay_msec[16]; 1360 + struct devlink_health_reporter *fw_reporter; 1361 + struct devlink_health_reporter *fw_reset_reporter; 1362 + struct devlink_health_reporter *fw_fatal_reporter; 1363 + }; 1364 + 1365 + struct bnxt_fw_reporter_ctx { 1366 + unsigned long sp_event; 1367 + }; 1368 + 1369 + #define BNXT_FW_HEALTH_REG_TYPE_MASK 3 1370 + #define BNXT_FW_HEALTH_REG_TYPE_CFG 0 1371 + #define BNXT_FW_HEALTH_REG_TYPE_GRC 1 1372 + #define BNXT_FW_HEALTH_REG_TYPE_BAR0 2 1373 + #define BNXT_FW_HEALTH_REG_TYPE_BAR1 3 1374 + 1375 + #define BNXT_FW_HEALTH_REG_TYPE(reg) ((reg) & BNXT_FW_HEALTH_REG_TYPE_MASK) 1376 + #define BNXT_FW_HEALTH_REG_OFF(reg) ((reg) & ~BNXT_FW_HEALTH_REG_TYPE_MASK) 1377 + 1378 + #define BNXT_FW_HEALTH_WIN_BASE 0x3000 1379 + #define BNXT_FW_HEALTH_WIN_MAP_OFF 8 1380 + 1381 + #define BNXT_FW_STATUS_HEALTHY 0x8000 1353 1382 1354 1383 struct bnxt { 1355 1384 void __iomem *bar0; ··· 1620 1555 #define BNXT_STATE_OPEN 0 1621 1556 #define BNXT_STATE_IN_SP_TASK 1 1622 1557 #define BNXT_STATE_READ_STATS 2 1558 + #define BNXT_STATE_FW_RESET_DET 3 1559 + #define BNXT_STATE_IN_FW_RESET 4 1560 + #define BNXT_STATE_ABORT_ERR 5 1561 + #define BNXT_STATE_FW_FATAL_COND 6 1623 1562 1624 1563 struct bnxt_irq *irq_tbl; 1625 1564 int total_irqs; ··· 1648 1579 #define BNXT_FW_CAP_KONG_MB_CHNL 0x00000080 1649 1580 #define BNXT_FW_CAP_OVS_64BIT_HANDLE 0x00000400 1650 1581 #define BNXT_FW_CAP_TRUSTED_VF 0x00000800 1582 + #define BNXT_FW_CAP_ERROR_RECOVERY 0x00002000 1651 1583 #define BNXT_FW_CAP_PKG_VER 0x00004000 1652 1584 #define BNXT_FW_CAP_CFA_ADV_FLOW 0x00008000 1653 1585 #define BNXT_FW_CAP_CFA_RFS_RING_TBL_IDX 0x00010000 ··· 1733 1663 #define BNXT_FLOW_STATS_SP_EVENT 15 1734 1664 #define BNXT_UPDATE_PHY_SP_EVENT 16 1735 1665 #define BNXT_RING_COAL_NOW_SP_EVENT 17 1666 + #define BNXT_FW_RESET_NOTIFY_SP_EVENT 18 1667 + #define BNXT_FW_EXCEPTION_SP_EVENT 19 1668 + 1669 + struct delayed_work fw_reset_task; 1670 + int fw_reset_state; 1671 + #define BNXT_FW_RESET_STATE_POLL_VF 1 1672 + #define BNXT_FW_RESET_STATE_RESET_FW 2 1673 + #define BNXT_FW_RESET_STATE_ENABLE_DEV 3 1674 + #define BNXT_FW_RESET_STATE_POLL_FW 4 1675 + #define BNXT_FW_RESET_STATE_OPENING 5 1676 + 1677 + u16 fw_reset_min_dsecs; 1678 + #define BNXT_DFLT_FW_RST_MIN_DSECS 20 1679 + u16 fw_reset_max_dsecs; 1680 + #define BNXT_DFLT_FW_RST_MAX_DSECS 60 1681 + unsigned long fw_reset_timestamp; 1682 + 1683 + struct bnxt_fw_health *fw_health; 1736 1684 1737 1685 struct bnxt_hw_resc hw_resc; 1738 1686 struct bnxt_pf_info pf; ··· 1956 1868 int bnxt_alloc_rx_data(struct bnxt *bp, struct bnxt_rx_ring_info *rxr, 1957 1869 u16 prod, gfp_t gfp); 1958 1870 void bnxt_reuse_rx_data(struct bnxt_rx_ring_info *rxr, u16 cons, void *data); 1871 + u32 bnxt_fw_health_readl(struct bnxt *bp, int reg_idx); 1959 1872 void bnxt_set_tpa_flags(struct bnxt *bp); 1960 1873 void bnxt_set_ring_params(struct bnxt *); 1961 1874 int bnxt_set_rx_skb_mode(struct bnxt *bp, bool page_mode); ··· 1989 1900 int bnxt_half_open_nic(struct bnxt *bp); 1990 1901 void bnxt_half_close_nic(struct bnxt *bp); 1991 1902 int bnxt_close_nic(struct bnxt *, bool, bool); 1903 + void bnxt_fw_exception(struct bnxt *bp); 1904 + void bnxt_fw_reset(struct bnxt *bp); 1992 1905 int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs, 1993 1906 int tx_xdp); 1994 1907 int bnxt_setup_mq_tc(struct net_device *dev, u8 tc);
+2 -4
drivers/net/ethernet/broadcom/bnxt/bnxt_dcb.c
··· 377 377 set.data_len = cpu_to_le16(sizeof(*data) + sizeof(*fw_app) * n); 378 378 set.hdr_cnt = 1; 379 379 rc = hwrm_send_message(bp, &set, sizeof(set), HWRM_CMD_TIMEOUT); 380 - if (rc) 381 - rc = -EIO; 382 380 383 381 set_app_exit: 384 382 dma_free_coherent(&bp->pdev->dev, data_len, data, mapping); ··· 389 391 struct hwrm_queue_dscp_qcaps_input req = {0}; 390 392 int rc; 391 393 394 + bp->max_dscp_value = 0; 392 395 if (bp->hwrm_spec_code < 0x10800 || BNXT_VF(bp)) 393 396 return 0; 394 397 ··· 432 433 dscp2pri->pri = app->priority; 433 434 req.entry_cnt = cpu_to_le16(1); 434 435 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 435 - if (rc) 436 - rc = -EIO; 437 436 dma_free_coherent(&bp->pdev->dev, sizeof(*dscp2pri), dscp2pri, 438 437 mapping); 439 438 return rc; ··· 719 722 720 723 void bnxt_dcb_init(struct bnxt *bp) 721 724 { 725 + bp->dcbx_cap = 0; 722 726 if (bp->hwrm_spec_code < 0x10501) 723 727 return; 724 728
+191 -6
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c
··· 15 15 #include "bnxt_vfr.h" 16 16 #include "bnxt_devlink.h" 17 17 18 + static int bnxt_fw_reporter_diagnose(struct devlink_health_reporter *reporter, 19 + struct devlink_fmsg *fmsg) 20 + { 21 + struct bnxt *bp = devlink_health_reporter_priv(reporter); 22 + struct bnxt_fw_health *health = bp->fw_health; 23 + u32 val, health_status; 24 + int rc; 25 + 26 + if (!health || test_bit(BNXT_STATE_IN_FW_RESET, &bp->state)) 27 + return 0; 28 + 29 + val = bnxt_fw_health_readl(bp, BNXT_FW_HEALTH_REG); 30 + health_status = val & 0xffff; 31 + 32 + if (health_status == BNXT_FW_STATUS_HEALTHY) { 33 + rc = devlink_fmsg_string_pair_put(fmsg, "FW status", 34 + "Healthy;"); 35 + if (rc) 36 + return rc; 37 + } else if (health_status < BNXT_FW_STATUS_HEALTHY) { 38 + rc = devlink_fmsg_string_pair_put(fmsg, "FW status", 39 + "Not yet completed initialization;"); 40 + if (rc) 41 + return rc; 42 + } else if (health_status > BNXT_FW_STATUS_HEALTHY) { 43 + rc = devlink_fmsg_string_pair_put(fmsg, "FW status", 44 + "Encountered fatal error and cannot recover;"); 45 + if (rc) 46 + return rc; 47 + } 48 + 49 + if (val >> 16) { 50 + rc = devlink_fmsg_u32_pair_put(fmsg, "Error", val >> 16); 51 + if (rc) 52 + return rc; 53 + } 54 + 55 + val = bnxt_fw_health_readl(bp, BNXT_FW_RESET_CNT_REG); 56 + rc = devlink_fmsg_u32_pair_put(fmsg, "Reset count", val); 57 + if (rc) 58 + return rc; 59 + 60 + return 0; 61 + } 62 + 63 + static const struct devlink_health_reporter_ops bnxt_dl_fw_reporter_ops = { 64 + .name = "fw", 65 + .diagnose = bnxt_fw_reporter_diagnose, 66 + }; 67 + 68 + static int bnxt_fw_reset_recover(struct devlink_health_reporter *reporter, 69 + void *priv_ctx) 70 + { 71 + struct bnxt *bp = devlink_health_reporter_priv(reporter); 72 + 73 + if (!priv_ctx) 74 + return -EOPNOTSUPP; 75 + 76 + bnxt_fw_reset(bp); 77 + return 0; 78 + } 79 + 80 + static const 81 + struct devlink_health_reporter_ops bnxt_dl_fw_reset_reporter_ops = { 82 + .name = "fw_reset", 83 + .recover = bnxt_fw_reset_recover, 84 + }; 85 + 86 + static int bnxt_fw_fatal_recover(struct devlink_health_reporter *reporter, 87 + void *priv_ctx) 88 + { 89 + struct bnxt *bp = devlink_health_reporter_priv(reporter); 90 + struct bnxt_fw_reporter_ctx *fw_reporter_ctx = priv_ctx; 91 + unsigned long event; 92 + 93 + if (!priv_ctx) 94 + return -EOPNOTSUPP; 95 + 96 + event = fw_reporter_ctx->sp_event; 97 + if (event == BNXT_FW_RESET_NOTIFY_SP_EVENT) 98 + bnxt_fw_reset(bp); 99 + else if (event == BNXT_FW_EXCEPTION_SP_EVENT) 100 + bnxt_fw_exception(bp); 101 + 102 + return 0; 103 + } 104 + 105 + static const 106 + struct devlink_health_reporter_ops bnxt_dl_fw_fatal_reporter_ops = { 107 + .name = "fw_fatal", 108 + .recover = bnxt_fw_fatal_recover, 109 + }; 110 + 111 + static void bnxt_dl_fw_reporters_create(struct bnxt *bp) 112 + { 113 + struct bnxt_fw_health *health = bp->fw_health; 114 + 115 + if (!health) 116 + return; 117 + 118 + health->fw_reporter = 119 + devlink_health_reporter_create(bp->dl, &bnxt_dl_fw_reporter_ops, 120 + 0, false, bp); 121 + if (IS_ERR(health->fw_reporter)) { 122 + netdev_warn(bp->dev, "Failed to create FW health reporter, rc = %ld\n", 123 + PTR_ERR(health->fw_reporter)); 124 + health->fw_reporter = NULL; 125 + } 126 + 127 + health->fw_reset_reporter = 128 + devlink_health_reporter_create(bp->dl, 129 + &bnxt_dl_fw_reset_reporter_ops, 130 + 0, true, bp); 131 + if (IS_ERR(health->fw_reset_reporter)) { 132 + netdev_warn(bp->dev, "Failed to create FW fatal health reporter, rc = %ld\n", 133 + PTR_ERR(health->fw_reset_reporter)); 134 + health->fw_reset_reporter = NULL; 135 + } 136 + 137 + health->fw_fatal_reporter = 138 + devlink_health_reporter_create(bp->dl, 139 + &bnxt_dl_fw_fatal_reporter_ops, 140 + 0, true, bp); 141 + if (IS_ERR(health->fw_fatal_reporter)) { 142 + netdev_warn(bp->dev, "Failed to create FW fatal health reporter, rc = %ld\n", 143 + PTR_ERR(health->fw_fatal_reporter)); 144 + health->fw_fatal_reporter = NULL; 145 + } 146 + } 147 + 148 + static void bnxt_dl_fw_reporters_destroy(struct bnxt *bp) 149 + { 150 + struct bnxt_fw_health *health = bp->fw_health; 151 + 152 + if (!health) 153 + return; 154 + 155 + if (health->fw_reporter) 156 + devlink_health_reporter_destroy(health->fw_reporter); 157 + 158 + if (health->fw_reset_reporter) 159 + devlink_health_reporter_destroy(health->fw_reset_reporter); 160 + 161 + if (health->fw_fatal_reporter) 162 + devlink_health_reporter_destroy(health->fw_fatal_reporter); 163 + } 164 + 165 + void bnxt_devlink_health_report(struct bnxt *bp, unsigned long event) 166 + { 167 + struct bnxt_fw_health *fw_health = bp->fw_health; 168 + struct bnxt_fw_reporter_ctx fw_reporter_ctx; 169 + 170 + if (!fw_health) 171 + return; 172 + 173 + fw_reporter_ctx.sp_event = event; 174 + switch (event) { 175 + case BNXT_FW_RESET_NOTIFY_SP_EVENT: 176 + if (test_bit(BNXT_STATE_FW_FATAL_COND, &bp->state)) { 177 + if (!fw_health->fw_fatal_reporter) 178 + return; 179 + 180 + devlink_health_report(fw_health->fw_fatal_reporter, 181 + "FW fatal async event received", 182 + &fw_reporter_ctx); 183 + return; 184 + } 185 + if (!fw_health->fw_reset_reporter) 186 + return; 187 + 188 + devlink_health_report(fw_health->fw_reset_reporter, 189 + "FW non-fatal reset event received", 190 + &fw_reporter_ctx); 191 + return; 192 + 193 + case BNXT_FW_EXCEPTION_SP_EVENT: 194 + if (!fw_health->fw_fatal_reporter) 195 + return; 196 + 197 + devlink_health_report(fw_health->fw_fatal_reporter, 198 + "FW fatal error reported", 199 + &fw_reporter_ctx); 200 + return; 201 + } 202 + } 203 + 18 204 static const struct devlink_ops bnxt_dl_ops = { 19 205 #ifdef CONFIG_BNXT_SRIOV 20 206 .eswitch_mode_set = bnxt_dl_eswitch_mode_set, ··· 295 109 memcpy(buf, data_addr, bytesize); 296 110 297 111 dma_free_coherent(&bp->pdev->dev, bytesize, data_addr, data_dma_addr); 298 - if (rc == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) { 112 + if (rc == -EACCES) 299 113 netdev_err(bp->dev, "PF does not have admin privileges to modify NVM config\n"); 300 - return -EACCES; 301 - } else if (rc) { 302 - return -EIO; 303 - } 304 - return 0; 114 + return rc; 305 115 } 306 116 307 117 static int bnxt_dl_nvm_param_get(struct devlink *dl, u32 id, ··· 433 251 434 252 devlink_params_publish(dl); 435 253 254 + bnxt_dl_fw_reporters_create(bp); 255 + 436 256 return 0; 437 257 438 258 err_dl_port_unreg: ··· 457 273 if (!dl) 458 274 return; 459 275 276 + bnxt_dl_fw_reporters_destroy(bp); 460 277 devlink_port_params_unregister(&bp->dl_port, bnxt_dl_port_params, 461 278 ARRAY_SIZE(bnxt_dl_port_params)); 462 279 devlink_port_unregister(&bp->dl_port);
+1
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.h
··· 55 55 u16 num_bits; 56 56 }; 57 57 58 + void bnxt_devlink_health_report(struct bnxt *bp, unsigned long event); 58 59 int bnxt_dl_register(struct bnxt *bp); 59 60 void bnxt_dl_unregister(struct bnxt *bp); 60 61
+15 -24
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c
··· 1699 1699 return bp->link_info.link_up; 1700 1700 } 1701 1701 1702 + static void bnxt_print_admin_err(struct bnxt *bp) 1703 + { 1704 + netdev_info(bp->dev, "PF does not have admin privileges to flash or reset the device\n"); 1705 + } 1706 + 1702 1707 static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal, 1703 1708 u16 ext, u16 *index, u32 *item_length, 1704 1709 u32 *data_length); ··· 1743 1738 rc = hwrm_send_message(bp, &req, sizeof(req), FLASH_NVRAM_TIMEOUT); 1744 1739 dma_free_coherent(&bp->pdev->dev, data_len, kmem, dma_handle); 1745 1740 1746 - if (rc == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) { 1747 - netdev_info(dev, 1748 - "PF does not have admin privileges to flash the device\n"); 1749 - rc = -EACCES; 1750 - } else if (rc) { 1751 - rc = -EIO; 1752 - } 1741 + if (rc == -EACCES) 1742 + bnxt_print_admin_err(bp); 1753 1743 return rc; 1754 1744 } 1755 1745 ··· 1794 1794 } 1795 1795 1796 1796 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 1797 - if (rc == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) { 1798 - netdev_info(dev, 1799 - "PF does not have admin privileges to reset the device\n"); 1800 - rc = -EACCES; 1801 - } else if (rc) { 1802 - rc = -EIO; 1803 - } 1797 + if (rc == -EACCES) 1798 + bnxt_print_admin_err(bp); 1804 1799 return rc; 1805 1800 } 1806 1801 ··· 2090 2095 flash_pkg_exit: 2091 2096 mutex_unlock(&bp->hwrm_cmd_lock); 2092 2097 err_exit: 2093 - if (hwrm_err == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) { 2094 - netdev_info(dev, 2095 - "PF does not have admin privileges to flash the device\n"); 2096 - rc = -EACCES; 2097 - } else if (hwrm_err) { 2098 - rc = -EOPNOTSUPP; 2099 - } 2098 + if (hwrm_err == -EACCES) 2099 + bnxt_print_admin_err(bp); 2100 2100 return rc; 2101 2101 } 2102 2102 ··· 2630 2640 led_cfg->led_group_id = bp->leds[i].led_group_id; 2631 2641 } 2632 2642 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 2633 - if (rc) 2634 - rc = -EIO; 2635 2643 return rc; 2636 2644 } 2637 2645 ··· 3350 3362 if (!(bp->fw_cap & BNXT_FW_CAP_PKG_VER)) 3351 3363 bnxt_get_pkgver(dev); 3352 3364 3365 + bp->num_tests = 0; 3353 3366 if (bp->hwrm_spec_code < 0x10704 || !BNXT_SINGLE_PF(bp)) 3354 3367 return; 3355 3368 ··· 3360 3371 if (rc) 3361 3372 goto ethtool_init_exit; 3362 3373 3363 - test_info = kzalloc(sizeof(*bp->test_info), GFP_KERNEL); 3374 + test_info = bp->test_info; 3375 + if (!test_info) 3376 + test_info = kzalloc(sizeof(*bp->test_info), GFP_KERNEL); 3364 3377 if (!test_info) 3365 3378 goto ethtool_init_exit; 3366 3379
+89 -92
drivers/net/ethernet/broadcom/bnxt/bnxt_sriov.c
··· 25 25 static int bnxt_hwrm_fwd_async_event_cmpl(struct bnxt *bp, 26 26 struct bnxt_vf_info *vf, u16 event_id) 27 27 { 28 - struct hwrm_fwd_async_event_cmpl_output *resp = bp->hwrm_cmd_resp_addr; 29 28 struct hwrm_fwd_async_event_cmpl_input req = {0}; 30 29 struct hwrm_async_event_cmpl *async_cmpl; 31 30 int rc = 0; ··· 39 40 async_cmpl->type = cpu_to_le16(ASYNC_EVENT_CMPL_TYPE_HWRM_ASYNC_EVENT); 40 41 async_cmpl->event_id = cpu_to_le16(event_id); 41 42 42 - mutex_lock(&bp->hwrm_cmd_lock); 43 - rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 44 - 45 - if (rc) { 43 + rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 44 + if (rc) 46 45 netdev_err(bp->dev, "hwrm_fwd_async_event_cmpl failed. rc:%d\n", 47 46 rc); 48 - goto fwd_async_event_cmpl_exit; 49 - } 50 - 51 - if (resp->error_code) { 52 - netdev_err(bp->dev, "hwrm_fwd_async_event_cmpl error %d\n", 53 - resp->error_code); 54 - rc = -1; 55 - } 56 - 57 - fwd_async_event_cmpl_exit: 58 - mutex_unlock(&bp->hwrm_cmd_lock); 59 47 return rc; 60 48 } 61 49 ··· 119 133 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 120 134 if (rc) { 121 135 mutex_unlock(&bp->hwrm_cmd_lock); 122 - return -EIO; 136 + return rc; 123 137 } 124 138 vf->func_qcfg_flags = le16_to_cpu(resp->flags); 125 139 mutex_unlock(&bp->hwrm_cmd_lock); ··· 150 164 else 151 165 req.flags = cpu_to_le32(FUNC_CFG_REQ_FLAGS_TRUSTED_VF_DISABLE); 152 166 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 153 - if (rc) 154 - return -EIO; 155 - return 0; 167 + return rc; 156 168 } 157 169 158 170 int bnxt_set_vf_trust(struct net_device *dev, int vf_id, bool trusted) ··· 470 486 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 471 487 } 472 488 489 + /* Caller holds bp->hwrm_cmd_lock mutex lock */ 490 + static void __bnxt_set_vf_params(struct bnxt *bp, int vf_id) 491 + { 492 + struct hwrm_func_cfg_input req = {0}; 493 + struct bnxt_vf_info *vf; 494 + 495 + vf = &bp->pf.vf[vf_id]; 496 + bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1); 497 + req.fid = cpu_to_le16(vf->fw_fid); 498 + req.flags = cpu_to_le32(vf->func_flags); 499 + 500 + if (is_valid_ether_addr(vf->mac_addr)) { 501 + req.enables |= cpu_to_le32(FUNC_CFG_REQ_ENABLES_DFLT_MAC_ADDR); 502 + memcpy(req.dflt_mac_addr, vf->mac_addr, ETH_ALEN); 503 + } 504 + if (vf->vlan) { 505 + req.enables |= cpu_to_le32(FUNC_CFG_REQ_ENABLES_DFLT_VLAN); 506 + req.dflt_vlan = cpu_to_le16(vf->vlan); 507 + } 508 + if (vf->max_tx_rate) { 509 + req.enables |= cpu_to_le32(FUNC_CFG_REQ_ENABLES_MAX_BW); 510 + req.max_bw = cpu_to_le32(vf->max_tx_rate); 511 + #ifdef HAVE_IFLA_TX_RATE 512 + req.enables |= cpu_to_le32(FUNC_CFG_REQ_ENABLES_MIN_BW); 513 + req.min_bw = cpu_to_le32(vf->min_tx_rate); 514 + #endif 515 + } 516 + if (vf->flags & BNXT_VF_TRUST) 517 + req.flags |= cpu_to_le32(FUNC_CFG_REQ_FLAGS_TRUSTED_VF_ENABLE); 518 + 519 + _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 520 + } 521 + 473 522 /* Only called by PF to reserve resources for VFs, returns actual number of 474 523 * VFs configured, or < 0 on error. 475 524 */ 476 - static int bnxt_hwrm_func_vf_resc_cfg(struct bnxt *bp, int num_vfs) 525 + static int bnxt_hwrm_func_vf_resc_cfg(struct bnxt *bp, int num_vfs, bool reset) 477 526 { 478 527 struct hwrm_func_vf_resource_cfg_input req = {0}; 479 528 struct bnxt_hw_resc *hw_resc = &bp->hw_resc; ··· 578 561 579 562 mutex_lock(&bp->hwrm_cmd_lock); 580 563 for (i = 0; i < num_vfs; i++) { 564 + if (reset) 565 + __bnxt_set_vf_params(bp, i); 566 + 581 567 req.vf_id = cpu_to_le16(pf->first_vf_id + i); 582 568 rc = _hwrm_send_message(bp, &req, sizeof(req), 583 569 HWRM_CMD_TIMEOUT); 584 - if (rc) { 585 - rc = -ENOMEM; 570 + if (rc) 586 571 break; 587 - } 588 572 pf->active_vfs = i + 1; 589 573 pf->vf[i].fw_fid = pf->first_vf_id + i; 590 574 } ··· 682 664 total_vf_tx_rings += vf_tx_rsvd; 683 665 } 684 666 mutex_unlock(&bp->hwrm_cmd_lock); 685 - if (rc) 686 - rc = -ENOMEM; 687 667 if (pf->active_vfs) { 688 668 hw_resc->max_tx_rings -= total_vf_tx_rings; 689 669 hw_resc->max_rx_rings -= vf_rx_rings * num_vfs; ··· 695 679 return rc; 696 680 } 697 681 698 - static int bnxt_func_cfg(struct bnxt *bp, int num_vfs) 682 + static int bnxt_func_cfg(struct bnxt *bp, int num_vfs, bool reset) 699 683 { 700 684 if (BNXT_NEW_RM(bp)) 701 - return bnxt_hwrm_func_vf_resc_cfg(bp, num_vfs); 685 + return bnxt_hwrm_func_vf_resc_cfg(bp, num_vfs, reset); 702 686 else 703 687 return bnxt_hwrm_func_cfg(bp, num_vfs); 688 + } 689 + 690 + int bnxt_cfg_hw_sriov(struct bnxt *bp, int *num_vfs, bool reset) 691 + { 692 + int rc; 693 + 694 + /* Register buffers for VFs */ 695 + rc = bnxt_hwrm_func_buf_rgtr(bp); 696 + if (rc) 697 + return rc; 698 + 699 + /* Reserve resources for VFs */ 700 + rc = bnxt_func_cfg(bp, *num_vfs, reset); 701 + if (rc != *num_vfs) { 702 + if (rc <= 0) { 703 + netdev_warn(bp->dev, "Unable to reserve resources for SRIOV.\n"); 704 + *num_vfs = 0; 705 + return rc; 706 + } 707 + netdev_warn(bp->dev, "Only able to reserve resources for %d VFs.\n", 708 + rc); 709 + *num_vfs = rc; 710 + } 711 + 712 + bnxt_ulp_sriov_cfg(bp, *num_vfs); 713 + return 0; 704 714 } 705 715 706 716 static int bnxt_sriov_enable(struct bnxt *bp, int *num_vfs) ··· 794 752 if (rc) 795 753 goto err_out1; 796 754 797 - /* Reserve resources for VFs */ 798 - rc = bnxt_func_cfg(bp, *num_vfs); 799 - if (rc != *num_vfs) { 800 - if (rc <= 0) { 801 - netdev_warn(bp->dev, "Unable to reserve resources for SRIOV.\n"); 802 - *num_vfs = 0; 803 - goto err_out2; 804 - } 805 - netdev_warn(bp->dev, "Only able to reserve resources for %d VFs.\n", rc); 806 - *num_vfs = rc; 807 - } 808 - 809 - /* Register buffers for VFs */ 810 - rc = bnxt_hwrm_func_buf_rgtr(bp); 755 + rc = bnxt_cfg_hw_sriov(bp, num_vfs, false); 811 756 if (rc) 812 757 goto err_out2; 813 - 814 - bnxt_ulp_sriov_cfg(bp, *num_vfs); 815 758 816 759 rc = pci_enable_sriov(bp->pdev, *num_vfs); 817 760 if (rc) ··· 864 837 rtnl_unlock(); 865 838 return 0; 866 839 } 840 + if (test_bit(BNXT_STATE_IN_FW_RESET, &bp->state)) { 841 + netdev_warn(dev, "Reject SRIOV config request when FW reset is in progress\n"); 842 + rtnl_unlock(); 843 + return 0; 844 + } 867 845 bp->sriov_cfg = true; 868 846 rtnl_unlock(); 869 847 ··· 902 870 { 903 871 int rc = 0; 904 872 struct hwrm_fwd_resp_input req = {0}; 905 - struct hwrm_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr; 906 873 907 874 if (BNXT_FWD_RESP_SIZE_ERR(msg_size)) 908 875 return -EINVAL; ··· 916 885 req.encap_resp_cmpl_ring = encap_resp_cpr; 917 886 memcpy(req.encap_resp, encap_resp, msg_size); 918 887 919 - mutex_lock(&bp->hwrm_cmd_lock); 920 - rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 921 - 922 - if (rc) { 888 + rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 889 + if (rc) 923 890 netdev_err(bp->dev, "hwrm_fwd_resp failed. rc:%d\n", rc); 924 - goto fwd_resp_exit; 925 - } 926 - 927 - if (resp->error_code) { 928 - netdev_err(bp->dev, "hwrm_fwd_resp error %d\n", 929 - resp->error_code); 930 - rc = -1; 931 - } 932 - 933 - fwd_resp_exit: 934 - mutex_unlock(&bp->hwrm_cmd_lock); 935 891 return rc; 936 892 } 937 893 ··· 927 909 { 928 910 int rc = 0; 929 911 struct hwrm_reject_fwd_resp_input req = {0}; 930 - struct hwrm_reject_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr; 931 912 932 913 if (BNXT_REJ_FWD_RESP_SIZE_ERR(msg_size)) 933 914 return -EINVAL; ··· 937 920 req.encap_resp_target_id = cpu_to_le16(vf->fw_fid); 938 921 memcpy(req.encap_request, vf->hwrm_cmd_req_addr, msg_size); 939 922 940 - mutex_lock(&bp->hwrm_cmd_lock); 941 - rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 942 - 943 - if (rc) { 923 + rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 924 + if (rc) 944 925 netdev_err(bp->dev, "hwrm_fwd_err_resp failed. rc:%d\n", rc); 945 - goto fwd_err_resp_exit; 946 - } 947 - 948 - if (resp->error_code) { 949 - netdev_err(bp->dev, "hwrm_fwd_err_resp error %d\n", 950 - resp->error_code); 951 - rc = -1; 952 - } 953 - 954 - fwd_err_resp_exit: 955 - mutex_unlock(&bp->hwrm_cmd_lock); 956 926 return rc; 957 927 } 958 928 ··· 948 944 { 949 945 int rc = 0; 950 946 struct hwrm_exec_fwd_resp_input req = {0}; 951 - struct hwrm_exec_fwd_resp_output *resp = bp->hwrm_cmd_resp_addr; 952 947 953 948 if (BNXT_EXEC_FWD_RESP_SIZE_ERR(msg_size)) 954 949 return -EINVAL; ··· 958 955 req.encap_resp_target_id = cpu_to_le16(vf->fw_fid); 959 956 memcpy(req.encap_request, vf->hwrm_cmd_req_addr, msg_size); 960 957 961 - mutex_lock(&bp->hwrm_cmd_lock); 962 - rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 963 - 964 - if (rc) { 958 + rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); 959 + if (rc) 965 960 netdev_err(bp->dev, "hwrm_exec_fw_resp failed. rc:%d\n", rc); 966 - goto exec_fwd_resp_exit; 967 - } 968 - 969 - if (resp->error_code) { 970 - netdev_err(bp->dev, "hwrm_exec_fw_resp error %d\n", 971 - resp->error_code); 972 - rc = -1; 973 - } 974 - 975 - exec_fwd_resp_exit: 976 - mutex_unlock(&bp->hwrm_cmd_lock); 977 961 return rc; 978 962 } 979 963 ··· 1179 1189 return 0; 1180 1190 } 1181 1191 #else 1192 + 1193 + int bnxt_cfg_hw_sriov(struct bnxt *bp, int *num_vfs, bool reset) 1194 + { 1195 + if (*num_vfs) 1196 + return -EOPNOTSUPP; 1197 + return 0; 1198 + } 1182 1199 1183 1200 void bnxt_sriov_disable(struct bnxt *bp) 1184 1201 {
+1
drivers/net/ethernet/broadcom/bnxt/bnxt_sriov.h
··· 36 36 int bnxt_set_vf_spoofchk(struct net_device *, int, bool); 37 37 int bnxt_set_vf_trust(struct net_device *dev, int vf_id, bool trust); 38 38 int bnxt_sriov_configure(struct pci_dev *pdev, int num_vfs); 39 + int bnxt_cfg_hw_sriov(struct bnxt *bp, int *num_vfs, bool reset); 39 40 void bnxt_sriov_disable(struct bnxt *); 40 41 void bnxt_hwrm_exec_fwd_req(struct bnxt *); 41 42 void bnxt_update_vf_mac(struct bnxt *);
-17
drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c
··· 319 319 if (rc) 320 320 netdev_info(bp->dev, "%s: Error rc=%d", __func__, rc); 321 321 322 - if (rc) 323 - rc = -EIO; 324 322 return rc; 325 323 } 326 324 ··· 513 515 } 514 516 } 515 517 mutex_unlock(&bp->hwrm_cmd_lock); 516 - 517 - if (rc == HWRM_ERR_CODE_RESOURCE_ALLOC_ERROR) 518 - rc = -ENOSPC; 519 - else if (rc) 520 - rc = -EIO; 521 518 return rc; 522 519 } 523 520 ··· 584 591 } 585 592 mutex_unlock(&bp->hwrm_cmd_lock); 586 593 587 - if (rc) 588 - rc = -EIO; 589 594 return rc; 590 595 } 591 596 ··· 600 609 if (rc) 601 610 netdev_info(bp->dev, "%s: Error rc=%d", __func__, rc); 602 611 603 - if (rc) 604 - rc = -EIO; 605 612 return rc; 606 613 } 607 614 ··· 649 660 } 650 661 mutex_unlock(&bp->hwrm_cmd_lock); 651 662 652 - if (rc) 653 - rc = -EIO; 654 663 return rc; 655 664 } 656 665 ··· 665 678 if (rc) 666 679 netdev_info(bp->dev, "%s: Error rc=%d", __func__, rc); 667 680 668 - if (rc) 669 - rc = -EIO; 670 681 return rc; 671 682 } 672 683 ··· 1442 1457 } 1443 1458 mutex_unlock(&bp->hwrm_cmd_lock); 1444 1459 1445 - if (rc) 1446 - rc = -EIO; 1447 1460 return rc; 1448 1461 } 1449 1462
+3
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c
··· 226 226 struct input *req; 227 227 int rc; 228 228 229 + if (ulp_id != BNXT_ROCE_ULP && bp->fw_reset_state) 230 + return -EBUSY; 231 + 229 232 mutex_lock(&bp->hwrm_cmd_lock); 230 233 req = fw_msg->msg; 231 234 req->resp_addr = cpu_to_le64(bp->hwrm_cmd_resp_dma_addr);