ionic: Don't send reset commands if FW isn't running

It's possible the FW is already shutting down while the driver is being
removed and/or when the driver is going through reset. This can cause
unexpected/unnecessary errors to be printed:

eth0: DEV_CMD IONIC_CMD_PORT_RESET (12) error, IONIC_RC_ERROR (29) failed
eth1: DEV_CMD IONIC_CMD_RESET (3) error, IONIC_RC_ERROR (29) failed

Fix this by checking the FW status register before issuing the reset
commands.

Also, since err may not be assigned in ionic_port_reset(), assign it a
default value of 0, and remove an unnecessary log message.

Fixes: fbfb803153 ("ionic: Add hardware init and device commands")
Signed-off-by: Brett Creeley <brett@pensando.io>
Signed-off-by: Shannon Nelson <snelson@pensando.io>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Brett Creeley 2022-01-24 10:53:00 -08:00 коммит произвёл David S. Miller
Родитель e6958cefb9
Коммит b8fd0271da
3 изменённых файлов: 23 добавлений и 13 удалений

Просмотреть файл

@ -136,6 +136,16 @@ int ionic_dev_setup(struct ionic *ionic)
} }
/* Devcmd Interface */ /* Devcmd Interface */
bool ionic_is_fw_running(struct ionic_dev *idev)
{
u8 fw_status = ioread8(&idev->dev_info_regs->fw_status);
/* firmware is useful only if the running bit is set and
* fw_status != 0xff (bad PCI read)
*/
return (fw_status != 0xff) && (fw_status & IONIC_FW_STS_F_RUNNING);
}
int ionic_heartbeat_check(struct ionic *ionic) int ionic_heartbeat_check(struct ionic *ionic)
{ {
struct ionic_dev *idev = &ionic->idev; struct ionic_dev *idev = &ionic->idev;
@ -159,13 +169,10 @@ do_check_time:
goto do_check_time; goto do_check_time;
} }
/* firmware is useful only if the running bit is set and
* fw_status != 0xff (bad PCI read)
* If fw_status is not ready don't bother with the generation.
*/
fw_status = ioread8(&idev->dev_info_regs->fw_status); fw_status = ioread8(&idev->dev_info_regs->fw_status);
if (fw_status == 0xff || !(fw_status & IONIC_FW_STS_F_RUNNING)) { /* If fw_status is not ready don't bother with the generation */
if (!ionic_is_fw_running(idev)) {
fw_status_ready = false; fw_status_ready = false;
} else { } else {
fw_generation = fw_status & IONIC_FW_STS_F_GENERATION; fw_generation = fw_status & IONIC_FW_STS_F_GENERATION;

Просмотреть файл

@ -353,5 +353,6 @@ void ionic_q_rewind(struct ionic_queue *q, struct ionic_desc_info *start);
void ionic_q_service(struct ionic_queue *q, struct ionic_cq_info *cq_info, void ionic_q_service(struct ionic_queue *q, struct ionic_cq_info *cq_info,
unsigned int stop_index); unsigned int stop_index);
int ionic_heartbeat_check(struct ionic *ionic); int ionic_heartbeat_check(struct ionic *ionic);
bool ionic_is_fw_running(struct ionic_dev *idev);
#endif /* _IONIC_DEV_H_ */ #endif /* _IONIC_DEV_H_ */

Просмотреть файл

@ -540,6 +540,9 @@ int ionic_reset(struct ionic *ionic)
struct ionic_dev *idev = &ionic->idev; struct ionic_dev *idev = &ionic->idev;
int err; int err;
if (!ionic_is_fw_running(idev))
return 0;
mutex_lock(&ionic->dev_cmd_lock); mutex_lock(&ionic->dev_cmd_lock);
ionic_dev_cmd_reset(idev); ionic_dev_cmd_reset(idev);
err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT); err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT);
@ -612,15 +615,17 @@ int ionic_port_init(struct ionic *ionic)
int ionic_port_reset(struct ionic *ionic) int ionic_port_reset(struct ionic *ionic)
{ {
struct ionic_dev *idev = &ionic->idev; struct ionic_dev *idev = &ionic->idev;
int err; int err = 0;
if (!idev->port_info) if (!idev->port_info)
return 0; return 0;
if (ionic_is_fw_running(idev)) {
mutex_lock(&ionic->dev_cmd_lock); mutex_lock(&ionic->dev_cmd_lock);
ionic_dev_cmd_port_reset(idev); ionic_dev_cmd_port_reset(idev);
err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT); err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT);
mutex_unlock(&ionic->dev_cmd_lock); mutex_unlock(&ionic->dev_cmd_lock);
}
dma_free_coherent(ionic->dev, idev->port_info_sz, dma_free_coherent(ionic->dev, idev->port_info_sz,
idev->port_info, idev->port_info_pa); idev->port_info, idev->port_info_pa);
@ -628,9 +633,6 @@ int ionic_port_reset(struct ionic *ionic)
idev->port_info = NULL; idev->port_info = NULL;
idev->port_info_pa = 0; idev->port_info_pa = 0;
if (err)
dev_err(ionic->dev, "Failed to reset port\n");
return err; return err;
} }